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.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/cleanup.hlinux/init.hlinux/i2c.hlinux/module.hlinux/mod_devicetable.hlinux/property.hlinux/regmap.hlinux/iio/iio.hlinux/iio/types.h
Detected Declarations
struct max34408_datastruct max34408_adc_model_datafunction max34408_read_adc_avgfunction max34408_read_rawfunction max34408_probefunction device_for_each_child_node
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
- Immediate include surface: `linux/bitfield.h`, `linux/cleanup.h`, `linux/init.h`, `linux/i2c.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/property.h`, `linux/regmap.h`.
- Detected declarations: `struct max34408_data`, `struct max34408_adc_model_data`, `function max34408_read_adc_avg`, `function max34408_read_raw`, `function max34408_probe`, `function device_for_each_child_node`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.