drivers/iio/adc/max34408.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/max34408.c
Extension
.c
Size
7146 bytes
Lines
278
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 max34408_data {
	struct regmap *regmap;
	struct device *dev;
	struct mutex lock;
	u32 input_rsense[4];
};

static const struct regmap_config max34408_regmap_config = {
	.reg_bits	= 8,
	.val_bits	= 8,
	.max_register	= MAX34408_DCWW_REG,
};

struct max34408_adc_model_data {
	const char *model_name;
	const struct iio_chan_spec *channels;
	const int num_channels;
};

#define MAX34008_CHANNEL(_index, _address)			\
	{							\
		.type = IIO_CURRENT,				\
		.info_mask_separate	= BIT(IIO_CHAN_INFO_RAW) | \
					  BIT(IIO_CHAN_INFO_SCALE) | \
					  BIT(IIO_CHAN_INFO_OFFSET), \
		.channel = (_index),				\
		.address = (_address),				\
		.indexed = 1,					\
	}

static const struct iio_chan_spec max34408_channels[] = {
	MAX34008_CHANNEL(0, MAX34408_ADC1_REG),
	MAX34008_CHANNEL(1, MAX34408_ADC2_REG),
};

static const struct iio_chan_spec max34409_channels[] = {
	MAX34008_CHANNEL(0, MAX34408_ADC1_REG),
	MAX34008_CHANNEL(1, MAX34408_ADC2_REG),
	MAX34008_CHANNEL(2, MAX34409_ADC3_REG),
	MAX34008_CHANNEL(3, MAX34409_ADC4_REG),
};

static int max34408_read_adc_avg(struct max34408_data *max34408,
				 const struct iio_chan_spec *chan, int *val)
{
	unsigned int ctrl;
	int rc;

	guard(mutex)(&max34408->lock);
	rc = regmap_read(max34408->regmap, MAX34408_CONTROL_REG, (u32 *)&ctrl);
	if (rc)
		return rc;

	/* set averaging (0b100) default values*/
	rc = regmap_write(max34408->regmap, MAX34408_CONTROL_REG,
			  MAX34408_DEFAULT_AVG);
	if (rc) {
		dev_err(max34408->dev,
			"Error (%d) writing control register\n", rc);
		return rc;
	}

	rc = regmap_read(max34408->regmap, chan->address, val);
	if (rc)
		return rc;

	/* back to old values */
	rc = regmap_write(max34408->regmap, MAX34408_CONTROL_REG, ctrl);
	if (rc)
		dev_err(max34408->dev,
			"Error (%d) writing control register\n", rc);

	return rc;
}

static int max34408_read_raw(struct iio_dev *indio_dev,
			     struct iio_chan_spec const *chan,
			     int *val, int *val2, long mask)
{
	struct max34408_data *max34408 = iio_priv(indio_dev);
	int rc;

	switch (mask) {
	case IIO_CHAN_INFO_RAW:
		rc = max34408_read_adc_avg(max34408, chan, val);
		if (rc)
			return rc;
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SCALE:
		/*

Annotation

Implementation Notes