drivers/iio/adc/ti-ads7950.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/ti-ads7950.c
Extension
.c
Size
19984 bytes
Lines
728
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 ti_ads7950_state {
	struct spi_device	*spi;
	struct spi_transfer	ring_xfer;
	struct spi_transfer	scan_single_xfer[3];
	struct spi_message	ring_msg;
	struct spi_message	scan_single_msg;

	/* Lock to protect the spi xfer buffers */
	struct mutex		slock;
	struct gpio_chip	chip;

	struct regulator	*reg;
	unsigned int		vref_mv;

	/*
	 * Bitmask of lower 7 bits used for configuration
	 * These bits only can be written when TI_ADS7950_CR_WRITE
	 * is set, otherwise it retains its original state.
	 * [0-3] GPIO signal
	 * [4]   Set following frame to return GPIO signal values
	 * [5]   Powers down device
	 * [6]   Sets Vref range1(2.5v) or range2(5v)
	 *
	 * Bits present on Manual/Auto1/Auto2 commands
	 */
	unsigned int		cmd_settings_bitmask;

	/*
	 * Bitmask of GPIO command
	 * [0-3] GPIO direction
	 * [4-6] Different GPIO alarm mode configurations
	 * [7]   GPIO 2 as device range input
	 * [8]   GPIO 3 as device power down input
	 * [9]   Reset all registers
	 * [10-11] N/A
	 */
	unsigned int		gpio_cmd_settings_bitmask;

	/*
	 * DMA (thus cache coherency maintenance) may require the
	 * transfer buffers to live in their own cache lines.
	 */
	u16 rx_buf[TI_ADS7950_MAX_CHAN + 2] __aligned(IIO_DMA_MINALIGN);
	u16 tx_buf[TI_ADS7950_MAX_CHAN + 2];
	u16 single_tx;
	u16 single_rx;

};

struct ti_ads7950_chip_info {
	const struct iio_chan_spec *channels;
	unsigned int num_channels;
};

#define TI_ADS7950_V_CHAN(index, bits)				\
{								\
	.type = IIO_VOLTAGE,					\
	.indexed = 1,						\
	.channel = index,					\
	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),		\
	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),	\
	.address = index,					\
	.datasheet_name = "CH##index",				\
	.scan_index = index,					\
	.scan_type = {						\
		.sign = 'u',					\
		.realbits = bits,				\
		.storagebits = 16,				\
		.shift = 12 - (bits),				\
		.endianness = IIO_CPU,				\
	},							\
}

#define DECLARE_TI_ADS7950_4_CHANNELS(name, bits) \
const struct iio_chan_spec name ## _channels[] = { \
	TI_ADS7950_V_CHAN(0, bits), \
	TI_ADS7950_V_CHAN(1, bits), \
	TI_ADS7950_V_CHAN(2, bits), \
	TI_ADS7950_V_CHAN(3, bits), \
	IIO_CHAN_SOFT_TIMESTAMP(4), \
}

#define DECLARE_TI_ADS7950_8_CHANNELS(name, bits) \
const struct iio_chan_spec name ## _channels[] = { \
	TI_ADS7950_V_CHAN(0, bits), \
	TI_ADS7950_V_CHAN(1, bits), \
	TI_ADS7950_V_CHAN(2, bits), \
	TI_ADS7950_V_CHAN(3, bits), \
	TI_ADS7950_V_CHAN(4, bits), \
	TI_ADS7950_V_CHAN(5, bits), \

Annotation

Implementation Notes