drivers/iio/adc/ti-ads1018.c

Source file repositories/reference/linux-study-clean/drivers/iio/adc/ti-ads1018.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/ti-ads1018.c
Extension
.c
Size
20187 bytes
Lines
740
Domain
Driver Families
Bucket
drivers/iio
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ads1018_chan_data {
	u8 pga_mode;
	u8 data_rate_mode;
};

struct ads1018_chip_info {
	const char *name;
	const struct iio_chan_spec *channels;
	unsigned long num_channels;

	/* IIO_VAL_INT */
	const u32 *data_rate_mode_to_hz;
	unsigned long num_data_rate_mode_to_hz;

	/*
	 * Let `res` be the chip's resolution and `fsr` (millivolts) be the
	 * full-scale range corresponding to the PGA mode given by the array
	 * index. Then, the gain is calculated using the following formula:
	 *
	 *     gain = |fsr| / 2^(res - 1)
	 *
	 * This value then has to be represented in IIO_VAL_INT_PLUS_NANO
	 * format. For example if:
	 *
	 *     gain = 6144 / 2^(16 - 1) = 0.1875
	 *
	 * ...then the formatted value is:
	 *
	 *     { 0, 187500000 }
	 */
	const u32 pga_mode_to_gain[ADS1018_NUM_PGA_MODES][2];

	/* IIO_VAL_INT_PLUS_MICRO */
	const u32 temp_scale[2];
};

struct ads1018 {
	struct spi_device *spi;
	struct iio_trigger *indio_trig;

	struct gpio_desc *drdy_gpiod;
	int drdy_irq;

	struct ads1018_chan_data chan_data[ADS1018_CHANNELS_MAX];
	const struct ads1018_chip_info *chip_info;

	struct spi_message msg_read;
	struct spi_transfer xfer;
	__be16 tx_buf[2] __aligned(IIO_DMA_MINALIGN);
	__be16 rx_buf[2];
};

#define ADS1018_VOLT_DIFF_CHAN(_index, _chan, _chan2, _realbits) {		\
	.type = IIO_VOLTAGE,							\
	.channel = _chan,							\
	.channel2 = _chan2,							\
	.scan_index = _index,							\
	.scan_type = {								\
		.sign = 's',							\
		.realbits = _realbits,						\
		.storagebits = 16,						\
		.shift = 16 - _realbits,					\
		.endianness = IIO_BE,						\
	},									\
	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |				\
			      BIT(IIO_CHAN_INFO_SCALE) |			\
			      BIT(IIO_CHAN_INFO_SAMP_FREQ),			\
	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE),		\
	.info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),	\
	.indexed = true,							\
	.differential = true,							\
}

#define ADS1018_VOLT_CHAN(_index, _chan, _realbits) {				\
	.type = IIO_VOLTAGE,							\
	.channel = _chan,							\
	.scan_index = _index,							\
	.scan_type = {								\
		.sign = 's',							\
		.realbits = _realbits,						\
		.storagebits = 16,						\
		.shift = 16 - _realbits,					\
		.endianness = IIO_BE,						\
	},									\
	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |				\
			      BIT(IIO_CHAN_INFO_SCALE) |			\
			      BIT(IIO_CHAN_INFO_SAMP_FREQ),			\
	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SCALE),		\
	.info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),	\
	.indexed = true,							\

Annotation

Implementation Notes