drivers/iio/adc/mt6359-auxadc.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/mt6359-auxadc.c
Extension
.c
Size
32521 bytes
Lines
910
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 mt6359_auxadc {
	struct device *dev;
	struct regmap *regmap;
	const struct mtk_pmic_auxadc_info *chip_info;
	struct mutex lock;
	bool timed_out;
};

/**
 * struct mtk_pmic_auxadc_chan - PMIC AUXADC channel data
 * @req_idx:       Request register number
 * @req_mask:      Bitmask to activate a channel
 * @rdy_idx:       Readiness register number
 * @rdy_mask:      Bitmask to determine channel readiness
 * @ext_sel_idx:   PMIC GPIO channel register number
 * @ext_sel_ch:    PMIC GPIO number
 * @ext_sel_pu:    PMIC GPIO channel pullup resistor selector
 * @num_samples:   Number of AUXADC samples for averaging
 * @r_ratio:       Resistance ratio fractional
 */
struct mtk_pmic_auxadc_chan {
	u8 req_idx;
	u16 req_mask;
	u8 rdy_idx;
	u16 rdy_mask;
	s8 ext_sel_idx;
	u8 ext_sel_ch;
	u8 ext_sel_pu;
	u16 num_samples;
	struct u8_fract r_ratio;
};

/**
 * struct mtk_pmic_auxadc_info - PMIC specific chip info
 * @model_name:     PMIC model name
 * @channels:       IIO specification of ADC channels
 * @num_channels:   Number of ADC channels
 * @desc:           PMIC AUXADC channel data
 * @regs:           List of PMIC specific registers
 * @sec_unlock_key: Security unlock key for HK_TOP writes
 * @vref_mV:        AUXADC Reference Voltage (VREF) in millivolts
 * @imp_adc_num:    ADC channel for battery impedance readings
 * @is_spmi:        Defines whether this PMIC communicates over SPMI
 * @no_reset:       If true, this PMIC does not support ADC reset
 * @read_imp:       Callback to read impedance channels
 */
struct mtk_pmic_auxadc_info {
	const char *model_name;
	const struct iio_chan_spec *channels;
	u8 num_channels;
	const struct mtk_pmic_auxadc_chan *desc;
	const u16 *regs;
	u16 sec_unlock_key;
	u32 vref_mV;
	u8 imp_adc_num;
	bool is_spmi;
	bool no_reset;
	int (*read_imp)(struct mt6359_auxadc *adc_dev,
			const struct iio_chan_spec *chan, int *vbat, int *ibat);
};

#define MTK_PMIC_ADC_EXT_CHAN(_ch_idx, _req_idx, _req_bit, _rdy_idx, _rdy_bit,	\
			      _ext_sel_idx, _ext_sel_ch, _ext_sel_pu,		\
			      _samples, _rnum, _rdiv)				\
	[PMIC_AUXADC_CHAN_##_ch_idx] = {					\
		.req_idx = _req_idx,						\
		.req_mask = BIT(_req_bit),					\
		.rdy_idx = _rdy_idx,						\
		.rdy_mask = BIT(_rdy_bit),					\
		.ext_sel_idx = _ext_sel_idx,					\
		.ext_sel_ch = _ext_sel_ch,					\
		.ext_sel_pu = _ext_sel_pu,					\
		.num_samples = _samples,					\
		.r_ratio = { _rnum, _rdiv }					\
	}

#define MTK_PMIC_ADC_CHAN(_ch_idx, _req_idx, _req_bit, _rdy_idx, _rdy_bit,	\
			  _samples, _rnum, _rdiv)				\
	MTK_PMIC_ADC_EXT_CHAN(_ch_idx, _req_idx, _req_bit, _rdy_idx, _rdy_bit,	\
			      -1, 0, 0, _samples, _rnum, _rdiv)

#define MTK_PMIC_IIO_CHAN(_model, _name, _ch_idx, _adc_idx, _nbits, _ch_type)	\
{										\
	.type = _ch_type,							\
	.channel = _model##_AUXADC_##_ch_idx,					\
	.address = _adc_idx,							\
	.scan_index = PMIC_AUXADC_CHAN_##_ch_idx,				\
	.datasheet_name = __stringify(_name),					\
	.scan_type =  {								\
		.sign = 'u',							\

Annotation

Implementation Notes