drivers/iio/adc/ina2xx-adc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/ina2xx-adc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/ina2xx-adc.c- Extension
.c- Size
- 29083 bytes
- Lines
- 1134
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/i2c.hlinux/iio/iio.hlinux/iio/buffer.hlinux/iio/kfifo_buf.hlinux/iio/sysfs.hlinux/kthread.hlinux/module.hlinux/of.hlinux/regmap.hlinux/sched/task.hlinux/util_macros.h
Detected Declarations
struct ina2xx_configstruct ina2xx_chip_infoenum ina2xx_idsfunction ina2xx_is_writeable_regfunction ina2xx_is_volatile_regfunction is_signed_regfunction ina2xx_read_rawfunction ina226_set_averagefunction ina226_set_int_time_vbusfunction ina226_set_int_time_vshuntfunction ina219_lookup_int_timefunction ina219_set_int_time_vbusfunction ina219_set_int_time_vshuntfunction ina219_set_vbus_range_denomfunction ina219_set_vshunt_pga_gainfunction ina2xx_read_availfunction ina2xx_write_rawfunction ina2xx_allow_async_readout_showfunction ina2xx_allow_async_readout_storefunction datasheetfunction set_shunt_resistorfunction ina2xx_shunt_resistor_showfunction ina2xx_shunt_resistor_storefunction BITfunction ina2xx_conversion_readyfunction ina2xx_work_bufferfunction ina2xx_capture_threadfunction ina2xx_buffer_enablefunction ina2xx_buffer_disablefunction ina2xx_debug_regfunction ina2xx_initfunction ina2xx_probefunction ina2xx_remove
Annotated Snippet
struct ina2xx_config {
const char *name;
u16 config_default;
int calibration_value;
int shunt_voltage_lsb; /* nV */
int bus_voltage_shift; /* position of lsb */
int bus_voltage_lsb; /* uV */
/* fixed relation between current and power lsb, uW/uA */
int power_lsb_factor;
enum ina2xx_ids chip_id;
};
struct ina2xx_chip_info {
struct regmap *regmap;
struct task_struct *task;
const struct ina2xx_config *config;
struct mutex state_lock;
unsigned int shunt_resistor_uohm;
int avg;
int int_time_vbus; /* Bus voltage integration time uS */
int int_time_vshunt; /* Shunt voltage integration time uS */
int range_vbus; /* Bus voltage maximum in V */
int pga_gain_vshunt; /* Shunt voltage PGA gain */
bool allow_async_readout;
/* data buffer needs space for channel data and timestamp */
struct {
u16 chan[4];
aligned_s64 ts;
} scan;
};
static const struct ina2xx_config ina2xx_config[] = {
[ina219] = {
.name = "ina219",
.config_default = INA219_CONFIG_DEFAULT,
.calibration_value = 4096,
.shunt_voltage_lsb = 10000,
.bus_voltage_shift = INA219_BUS_VOLTAGE_SHIFT,
.bus_voltage_lsb = 4000,
.power_lsb_factor = 20,
.chip_id = ina219,
},
[ina226] = {
.name = "ina226",
.config_default = INA226_CONFIG_DEFAULT,
.calibration_value = 2048,
.shunt_voltage_lsb = 2500,
.bus_voltage_shift = 0,
.bus_voltage_lsb = 1250,
.power_lsb_factor = 25,
.chip_id = ina226,
},
[ina236] = {
.name = "ina236",
.config_default = INA226_CONFIG_DEFAULT,
.calibration_value = 2048,
.shunt_voltage_lsb = 2500,
.bus_voltage_shift = 0,
.bus_voltage_lsb = 1600,
.power_lsb_factor = 32,
.chip_id = ina236,
},
};
static int ina2xx_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
int ret;
struct ina2xx_chip_info *chip = iio_priv(indio_dev);
unsigned int regval;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = regmap_read(chip->regmap, chan->address, ®val);
if (ret)
return ret;
if (is_signed_reg(chan->address))
*val = (s16) regval;
else
*val = regval;
if (chan->address == INA2XX_BUS_VOLTAGE)
*val >>= chip->config->bus_voltage_shift;
return IIO_VAL_INT;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
*val = chip->avg;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/i2c.h`, `linux/iio/iio.h`, `linux/iio/buffer.h`, `linux/iio/kfifo_buf.h`, `linux/iio/sysfs.h`, `linux/kthread.h`, `linux/module.h`.
- Detected declarations: `struct ina2xx_config`, `struct ina2xx_chip_info`, `enum ina2xx_ids`, `function ina2xx_is_writeable_reg`, `function ina2xx_is_volatile_reg`, `function is_signed_reg`, `function ina2xx_read_raw`, `function ina226_set_average`, `function ina226_set_int_time_vbus`, `function ina226_set_int_time_vshunt`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.