drivers/hwmon/ina209.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/ina209.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/ina209.c- Extension
.c- Size
- 17135 bytes
- Lines
- 599
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/init.hlinux/err.hlinux/slab.hlinux/bug.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.h
Detected Declarations
struct ina209_datafunction ina209_from_regfunction ina209_to_regfunction ina209_interval_from_regfunction ina209_reg_from_intervalfunction ina209_interval_storefunction ina209_interval_showfunction ina209_history_storefunction ina209_value_storefunction ina209_value_showfunction ina209_alarm_showfunction ina209_restore_conffunction ina209_init_clientfunction ina209_probefunction ina209_remove
Annotated Snippet
struct ina209_data {
struct i2c_client *client;
struct mutex update_lock;
bool valid;
unsigned long last_updated; /* in jiffies */
u16 regs[INA209_REGISTERS]; /* All chip registers */
u16 config_orig; /* Original configuration */
u16 calibration_orig; /* Original calibration */
u16 update_interval;
};
static struct ina209_data *ina209_update_device(struct device *dev)
{
struct ina209_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
struct ina209_data *ret = data;
s32 val;
int i;
mutex_lock(&data->update_lock);
if (!data->valid ||
time_after(jiffies, data->last_updated + data->update_interval)) {
for (i = 0; i < ARRAY_SIZE(data->regs); i++) {
val = i2c_smbus_read_word_swapped(client, i);
if (val < 0) {
ret = ERR_PTR(val);
goto abort;
}
data->regs[i] = val;
}
data->last_updated = jiffies;
data->valid = true;
}
abort:
mutex_unlock(&data->update_lock);
return ret;
}
/*
* Read a value from a device register and convert it to the
* appropriate sysfs units
*/
static long ina209_from_reg(const u8 reg, const u16 val)
{
switch (reg) {
case INA209_SHUNT_VOLTAGE:
case INA209_SHUNT_VOLTAGE_POS_PEAK:
case INA209_SHUNT_VOLTAGE_NEG_PEAK:
case INA209_SHUNT_VOLTAGE_POS_WARN:
case INA209_SHUNT_VOLTAGE_NEG_WARN:
/* LSB=10 uV. Convert to mV. */
return DIV_ROUND_CLOSEST((s16)val, 100);
case INA209_BUS_VOLTAGE:
case INA209_BUS_VOLTAGE_MAX_PEAK:
case INA209_BUS_VOLTAGE_MIN_PEAK:
case INA209_BUS_VOLTAGE_OVER_WARN:
case INA209_BUS_VOLTAGE_UNDER_WARN:
case INA209_BUS_VOLTAGE_OVER_LIMIT:
case INA209_BUS_VOLTAGE_UNDER_LIMIT:
/* LSB=4 mV, last 3 bits unused */
return (val >> 3) * 4;
case INA209_CRITICAL_DAC_POS:
/* LSB=1 mV, in the upper 8 bits */
return val >> 8;
case INA209_CRITICAL_DAC_NEG:
/* LSB=1 mV, in the upper 8 bits */
return -1 * (val >> 8);
case INA209_POWER:
case INA209_POWER_PEAK:
case INA209_POWER_WARN:
case INA209_POWER_OVER_LIMIT:
/* LSB=20 mW. Convert to uW */
return val * 20 * 1000L;
case INA209_CURRENT:
/* LSB=1 mA (selected). Is in mA */
return (s16)val;
}
/* programmer goofed */
WARN_ON_ONCE(1);
return 0;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/init.h`, `linux/err.h`, `linux/slab.h`, `linux/bug.h`, `linux/i2c.h`, `linux/hwmon.h`.
- Detected declarations: `struct ina209_data`, `function ina209_from_reg`, `function ina209_to_reg`, `function ina209_interval_from_reg`, `function ina209_reg_from_interval`, `function ina209_interval_store`, `function ina209_interval_show`, `function ina209_history_store`, `function ina209_value_store`, `function ina209_value_show`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.