drivers/thermal/qcom/qcom-spmi-adc-tm5.c

Source file repositories/reference/linux-study-clean/drivers/thermal/qcom/qcom-spmi-adc-tm5.c

File Facts

System
Linux kernel
Corpus path
drivers/thermal/qcom/qcom-spmi-adc-tm5.c
Extension
.c
Size
29153 bytes
Lines
1072
Domain
Driver Families
Bucket
drivers/thermal
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 adc_tm5_data {
	const u32 full_scale_code_volt;
	unsigned int *decimation;
	unsigned int *hw_settle;
	int (*disable_channel)(struct adc_tm5_channel *channel);
	int (*configure)(struct adc_tm5_channel *channel, int low, int high);
	irqreturn_t (*isr)(int irq, void *data);
	int (*init)(struct adc_tm5_chip *chip);
	char *irq_name;
	int gen;
};

/**
 * struct adc_tm5_channel - ADC Thermal Monitoring channel data.
 * @channel: channel number.
 * @adc_channel: corresponding ADC channel number.
 * @cal_method: calibration method.
 * @prescale: channel scaling performed on the input signal.
 * @hw_settle_time: the time between AMUX being configured and the
 *	start of conversion.
 * @decimation: sampling rate supported for the channel.
 * @avg_samples: ability to provide single result from the ADC
 *	that is an average of multiple measurements.
 * @high_thr_en: channel upper voltage threshold enable state.
 * @low_thr_en: channel lower voltage threshold enable state.
 * @meas_en: recurring measurement enable state
 * @iio: IIO channel instance used by this channel.
 * @chip: ADC TM chip instance.
 * @tzd: thermal zone device used by this channel.
 */
struct adc_tm5_channel {
	unsigned int		channel;
	unsigned int		adc_channel;
	enum adc_tm5_cal_method	cal_method;
	unsigned int		prescale;
	unsigned int		hw_settle_time;
	unsigned int		decimation;	/* For Gen2 ADC_TM */
	unsigned int		avg_samples;	/* For Gen2 ADC_TM */
	bool			high_thr_en;	/* For Gen2 ADC_TM */
	bool			low_thr_en;	/* For Gen2 ADC_TM */
	bool			meas_en;	/* For Gen2 ADC_TM */
	struct iio_channel	*iio;
	struct adc_tm5_chip	*chip;
	struct thermal_zone_device *tzd;
};

/**
 * struct adc_tm5_chip - ADC Thermal Monitoring properties
 * @regmap: SPMI ADC5 Thermal Monitoring  peripheral register map field.
 * @dev: SPMI ADC5 device.
 * @data: software configuration data.
 * @channels: array of ADC TM channel data.
 * @nchannels: amount of channels defined/allocated
 * @decimation: sampling rate supported for the channel.
 *      Applies to all channels, used only on Gen1 ADC_TM.
 * @avg_samples: ability to provide single result from the ADC
 *      that is an average of multiple measurements. Applies to all
 *      channels, used only on Gen1 ADC_TM.
 * @base: base address of TM registers.
 * @adc_mutex_lock: ADC_TM mutex lock, used only on Gen2 ADC_TM.
 *      It is used to ensure only one ADC channel configuration
 *      is done at a time using the shared set of configuration
 *      registers.
 */
struct adc_tm5_chip {
	struct regmap		*regmap;
	struct device		*dev;
	const struct adc_tm5_data	*data;
	struct adc_tm5_channel	*channels;
	unsigned int		nchannels;
	unsigned int		decimation;
	unsigned int		avg_samples;
	u16			base;
	struct mutex		adc_mutex_lock;
};

static int adc_tm5_read(struct adc_tm5_chip *adc_tm, u16 offset, u8 *data, int len)
{
	return regmap_bulk_read(adc_tm->regmap, adc_tm->base + offset, data, len);
}

static int adc_tm5_write(struct adc_tm5_chip *adc_tm, u16 offset, u8 *data, int len)
{
	return regmap_bulk_write(adc_tm->regmap, adc_tm->base + offset, data, len);
}

static int adc_tm5_reg_update(struct adc_tm5_chip *adc_tm, u16 offset, u8 mask, u8 val)
{
	return regmap_write_bits(adc_tm->regmap, adc_tm->base + offset, mask, val);
}

Annotation

Implementation Notes