drivers/iio/adc/ad4851.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/ad4851.c
Extension
.c
Size
32375 bytes
Lines
1318
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 ad4851_scale {
	unsigned int scale_val;
	u8 reg_val;
};

static const struct ad4851_scale ad4851_scale_table_unipolar[] = {
	{ 2500, 0x0 },
	{ 5000, 0x2 },
	{ 6250, 0x4 },
	{ 10000, 0x6 },
	{ 12500, 0x8 },
	{ 20000, 0xA },
	{ 25000, 0xC },
	{ 40000, 0xE },
};

static const struct ad4851_scale ad4851_scale_table_bipolar[] = {
	{ 5000, 0x1 },
	{ 10000, 0x3 },
	{ 12500, 0x5 },
	{ 20000, 0x7 },
	{ 25000, 0x9 },
	{ 40000, 0xB },
	{ 50000, 0xD },
	{ 80000, 0xF },
};

static const unsigned int ad4851_scale_avail_unipolar[] = {
	2500,
	5000,
	6250,
	10000,
	12500,
	20000,
	25000,
	40000,
};

static const unsigned int ad4851_scale_avail_bipolar[] = {
	5000,
	10000,
	12500,
	20000,
	25000,
	40000,
	50000,
	80000,
};

struct ad4851_chip_info {
	const char *name;
	unsigned int product_id;
	int num_scales;
	unsigned long max_sample_rate_hz;
	unsigned int resolution;
	unsigned int max_channels;
	int (*parse_channels)(struct iio_dev *indio_dev);
};

enum {
	AD4851_SCAN_TYPE_NORMAL,
	AD4851_SCAN_TYPE_RESOLUTION_BOOST,
};

struct ad4851_state {
	struct spi_device *spi;
	struct pwm_device *cnv;
	struct iio_backend *back;
	/*
	 * Synchronize access to members the of driver state, and ensure
	 * atomicity of consecutive regmap operations.
	 */
	struct mutex lock;
	struct regmap *regmap;
	const struct ad4851_chip_info *info;
	struct gpio_desc *pd_gpio;
	bool resolution_boost_enabled;
	unsigned long cnv_trigger_rate_hz;
	unsigned int osr;
	bool vrefbuf_en;
	bool vrefio_en;
	bool bipolar_ch[AD4851_MAX_CH_NR];
	unsigned int scales_unipolar[AD4841_MAX_SCALE_AVAIL][2];
	unsigned int scales_bipolar[AD4841_MAX_SCALE_AVAIL][2];
};

static int ad4851_reg_access(struct iio_dev *indio_dev,
			     unsigned int reg,
			     unsigned int writeval,
			     unsigned int *readval)

Annotation

Implementation Notes