drivers/iio/addac/ad74413r.c

Source file repositories/reference/linux-study-clean/drivers/iio/addac/ad74413r.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/addac/ad74413r.c
Extension
.c
Size
38947 bytes
Lines
1533
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 ad74413r_chip_info {
	const char	*name;
	bool		hart_support;
};

struct ad74413r_channel_config {
	u32		func;
	u32		drive_strength;
	bool		gpo_comparator;
	bool		initialized;
};

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

struct ad74413r_state {
	struct ad74413r_channel_config	channel_configs[AD74413R_CHANNEL_MAX];
	unsigned int			gpo_gpio_offsets[AD74413R_CHANNEL_MAX];
	unsigned int			comp_gpio_offsets[AD74413R_CHANNEL_MAX];
	struct gpio_chip		gpo_gpiochip;
	struct gpio_chip		comp_gpiochip;
	struct completion		adc_data_completion;
	unsigned int			num_gpo_gpios;
	unsigned int			num_comparator_gpios;
	u32				sense_resistor_ohms;
	int				refin_reg_uv;
	/*
	 * Synchronize consecutive operations when doing a one-shot
	 * conversion and when updating the ADC samples SPI message.
	 */
	struct mutex			lock;

	const struct ad74413r_chip_info	*chip_info;
	struct spi_device		*spi;
	struct regmap			*regmap;
	struct device			*dev;
	struct iio_trigger		*trig;

	size_t			adc_active_channels;
	struct spi_message	adc_samples_msg;
	struct spi_transfer	adc_samples_xfer[AD74413R_CHANNEL_MAX + 1];

	/*
	 * DMA (thus cache coherency maintenance) may require the
	 * transfer buffers to live in their own cache lines.
	 */
	struct {
		u8 rx_buf[AD74413R_FRAME_SIZE * AD74413R_CHANNEL_MAX];
		aligned_s64 timestamp;
	} adc_samples_buf __aligned(IIO_DMA_MINALIGN);

	u8	adc_samples_tx_buf[AD74413R_FRAME_SIZE * AD74413R_CHANNEL_MAX];
	u8	reg_tx_buf[AD74413R_FRAME_SIZE];
	u8	reg_rx_buf[AD74413R_FRAME_SIZE];
};

#define AD74413R_REG_NOP		0x00

#define AD74413R_REG_CH_FUNC_SETUP_X(x)	(0x01 + (x))
#define AD74413R_CH_FUNC_SETUP_MASK	GENMASK(3, 0)

#define AD74413R_REG_ADC_CONFIG_X(x)		(0x05 + (x))
#define AD74413R_ADC_CONFIG_RANGE_MASK		GENMASK(7, 5)
#define AD74413R_ADC_CONFIG_REJECTION_MASK	GENMASK(4, 3)
#define AD74413R_ADC_CONFIG_CH_200K_TO_GND	BIT(2)
#define AD74413R_ADC_RANGE_10V			0b000
#define AD74413R_ADC_RANGE_2P5V_EXT_POW		0b001
#define AD74413R_ADC_RANGE_2P5V_INT_POW		0b010
#define AD74413R_ADC_RANGE_5V_BI_DIR		0b011
#define AD74413R_ADC_REJECTION_50_60		0b00
#define AD74413R_ADC_REJECTION_NONE		0b01
#define AD74413R_ADC_REJECTION_50_60_HART	0b10
#define AD74413R_ADC_REJECTION_HART		0b11

#define AD74413R_REG_DIN_CONFIG_X(x)	(0x09 + (x))
#define AD74413R_DIN_DEBOUNCE_MASK	GENMASK(4, 0)
#define AD74413R_DIN_DEBOUNCE_LEN	BIT(5)
#define AD74413R_DIN_SINK_MASK		GENMASK(9, 6)

#define AD74413R_REG_DAC_CODE_X(x)	(0x16 + (x))
#define AD74413R_DAC_CODE_MAX		GENMASK(12, 0)
#define AD74413R_DAC_VOLTAGE_MAX	11000

#define AD74413R_REG_GPO_PAR_DATA		0x0d
#define AD74413R_REG_GPO_CONFIG_X(x)		(0x0e + (x))
#define AD74413R_GPO_CONFIG_DATA_MASK	BIT(3)
#define AD74413R_GPO_CONFIG_SELECT_MASK		GENMASK(2, 0)
#define AD74413R_GPO_CONFIG_100K_PULL_DOWN	0b000

Annotation

Implementation Notes