drivers/iio/adc/twl6030-gpadc.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/twl6030-gpadc.c
Extension
.c
Size
25577 bytes
Lines
1022
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 twl6030_chnl_calib {
	s32 gain;
	s32 gain_error;
	s32 offset_error;
};

/**
 * struct twl6030_ideal_code - GPADC calibration parameters
 * GPADC is calibrated in two points: close to the beginning and
 * to the and of the measurable input range
 *
 * @channel:	channel number
 * @code1:	ideal code for the input at the beginning
 * @code2:	ideal code for at the end of the range
 * @volt1:	voltage input at the beginning(low voltage)
 * @volt2:	voltage input at the end(high voltage)
 */
struct twl6030_ideal_code {
	int channel;
	u16 code1;
	u16 code2;
	u16 volt1;
	u16 volt2;
};

struct twl6030_gpadc_data;

/**
 * struct twl6030_gpadc_platform_data - platform specific data
 * @nchannels:		number of GPADC channels
 * @iio_channels:	iio channels
 * @ideal:		pointer to calibration parameters
 * @start_conversion:	pointer to ADC start conversion function
 * @channel_to_reg:	pointer to ADC function to convert channel to
 *			register address for reading conversion result
 * @calibrate:		pointer to calibration function
 */
struct twl6030_gpadc_platform_data {
	const int nchannels;
	const struct iio_chan_spec *iio_channels;
	const struct twl6030_ideal_code *ideal;
	int (*start_conversion)(int channel);
	u8 (*channel_to_reg)(int channel);
	int (*calibrate)(struct twl6030_gpadc_data *gpadc);
};

/**
 * struct twl6030_gpadc_data - GPADC data
 * @dev:		device pointer
 * @lock:		mutual exclusion lock for the structure
 * @irq_complete:	completion to signal end of conversion
 * @twl6030_cal_tbl:	pointer to calibration data for each
 *			channel with gain error and offset
 * @pdata:		pointer to device specific data
 */
struct twl6030_gpadc_data {
	struct device	*dev;
	struct mutex	lock;
	struct completion	irq_complete;
	struct twl6030_chnl_calib	*twl6030_cal_tbl;
	const struct twl6030_gpadc_platform_data *pdata;
};

/*
 * channels 11, 12, 13, 15 and 16 have no calibration data
 * calibration offset is same for channels 1, 3, 4, 5
 *
 * The data is taken from GPADC_TRIM registers description.
 * GPADC_TRIM registers keep difference between the code measured
 * at volt1 and volt2 input voltages and corresponding code1 and code2
 */
static const struct twl6030_ideal_code
	twl6030_ideal[TWL6030_GPADC_USED_CHANNELS] = {
	[0] = { /* ch 0, external, battery type, resistor value */
		.channel = 0,
		.code1 = 116,
		.code2 = 745,
		.volt1 = 141,
		.volt2 = 910,
	},
	[1] = { /* ch 1, external, battery temperature, NTC resistor value */
		.channel = 1,
		.code1 = 82,
		.code2 = 900,
		.volt1 = 100,
		.volt2 = 1100,
	},
	[2] = { /* ch 2, external, audio accessory/general purpose */
		.channel = 2,
		.code1 = 55,

Annotation

Implementation Notes