drivers/iio/adc/ti-ads1015.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/ti-ads1015.c
Extension
.c
Size
31502 bytes
Lines
1162
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 ads1015_chip_data {
	struct iio_chan_spec const	*channels;
	int				num_channels;
	const struct iio_info		*info;
	const int			*data_rate;
	const int			data_rate_len;
	const int			*scale;
	const int			scale_len;
	bool				has_comparator;
};

enum ads1015_channels {
	ADS1015_AIN0_AIN1 = 0,
	ADS1015_AIN0_AIN3,
	ADS1015_AIN1_AIN3,
	ADS1015_AIN2_AIN3,
	ADS1015_AIN0,
	ADS1015_AIN1,
	ADS1015_AIN2,
	ADS1015_AIN3,
	ADS1015_TIMESTAMP,
};

static const int ads1015_data_rate[] = {
	128, 250, 490, 920, 1600, 2400, 3300, 3300
};

static const int ads1115_data_rate[] = {
	8, 16, 32, 64, 128, 250, 475, 860
};

/*
 * Translation from PGA bits to full-scale positive and negative input voltage
 * range in mV
 */
static const int ads1015_fullscale_range[] = {
	6144, 4096, 2048, 1024, 512, 256, 256, 256
};

static const int ads1015_scale[] = {	/* 12bit ADC */
	256, 11,
	512, 11,
	1024, 11,
	2048, 11,
	4096, 11,
	6144, 11
};

static const int ads1115_scale[] = {	/* 16bit ADC */
	256, 15,
	512, 15,
	1024, 15,
	2048, 15,
	4096, 15,
	6144, 15
};

/*
 * Translation from COMP_QUE field value to the number of successive readings
 * exceed the threshold values before an interrupt is generated
 */
static const int ads1015_comp_queue[] = { 1, 2, 4 };

static const struct iio_event_spec ads1015_events[] = {
	{
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_RISING,
		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
				BIT(IIO_EV_INFO_ENABLE),
	}, {
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_FALLING,
		.mask_separate = BIT(IIO_EV_INFO_VALUE),
	}, {
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_EITHER,
		.mask_separate = BIT(IIO_EV_INFO_ENABLE) |
				BIT(IIO_EV_INFO_PERIOD),
	},
};

/*
 * Compile-time check whether _fitbits can accommodate up to _testbits
 * bits. Returns _fitbits on success, fails to compile otherwise.
 *
 * The test works such that it multiplies constant _fitbits by constant
 * double-negation of size of a non-empty structure, i.e. it multiplies
 * constant _fitbits by constant 1 in each successful compilation case.
 * The non-empty structure may contain C11 _Static_assert(), make use of
 * this and place the kernel variant of static assert in there, so that

Annotation

Implementation Notes