drivers/hwmon/ina238.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/ina238.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/ina238.c- Extension
.c- Size
- 28740 bytes
- Lines
- 1049
- 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.
- 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/bitops.hlinux/err.hlinux/hwmon.hlinux/i2c.hlinux/init.hlinux/kernel.hlinux/module.hlinux/of.hlinux/regmap.hlinux/util_macros.h
Detected Declarations
struct ina238_configstruct ina238_dataenum ina238_idsfunction ina238_read_reg24function ina238_read_reg40function ina238_read_field_s20function ina228_read_voltagefunction ina238_reg_to_interval_usfunction ina238_samplesfunction fieldsfunction ina238_write_conv_timefunction ina238_read_chipfunction ina238_write_chipfunction ina238_read_infunction ina238_write_infunction __ina238_read_currfunction ina238_read_currfunction ina238_write_currfunction ina238_read_powerfunction ina238_write_power_maxfunction ina238_temp_from_regfunction ina238_read_tempfunction ina238_temp_to_regfunction ina238_write_temp_maxfunction ina238_read_energyfunction ina238_readfunction ina238_writefunction ina238_is_visiblefunction ina238_probe
Annotated Snippet
struct ina238_config {
bool has_20bit_voltage_current; /* vshunt, vbus and current are 20-bit fields */
bool has_power_highest; /* chip detection power peak */
bool has_energy; /* chip detection energy */
u8 temp_resolution; /* temperature register resolution in bit */
u16 config_default; /* Power-on default state */
u32 power_calculate_factor; /* fixed parameter for power calculation, from datasheet */
u32 bus_voltage_lsb; /* bus voltage LSB, in nV */
int current_lsb; /* current LSB, in uA */
const u16 *conv_time; /* conversion time lookup table */
};
struct ina238_data {
const struct ina238_config *config;
struct i2c_client *client;
struct regmap *regmap;
u32 rshunt;
int gain;
u32 voltage_lsb[2]; /* shunt, bus voltage LSB, in nV */
int current_lsb; /* current LSB, in uA */
int power_lsb; /* power LSB, in uW */
int energy_lsb; /* energy LSB, in uJ */
u16 adc_config; /* cached ADC_CONFIG register value */
};
static const struct ina238_config ina238_config[] = {
[ina228] = {
.has_20bit_voltage_current = true,
.has_energy = true,
.has_power_highest = false,
.power_calculate_factor = 20,
.config_default = INA238_CONFIG_DEFAULT,
.bus_voltage_lsb = INA238_BUS_VOLTAGE_LSB,
.temp_resolution = 16,
.conv_time = ina238_conv_time,
},
[ina237] = {
.has_20bit_voltage_current = false,
.has_energy = false,
.has_power_highest = false,
.power_calculate_factor = 20,
.config_default = INA238_CONFIG_DEFAULT,
.bus_voltage_lsb = INA238_BUS_VOLTAGE_LSB,
.temp_resolution = 12,
.conv_time = ina238_conv_time,
},
[ina238] = {
.has_20bit_voltage_current = false,
.has_energy = false,
.has_power_highest = false,
.power_calculate_factor = 20,
.config_default = INA238_CONFIG_DEFAULT,
.bus_voltage_lsb = INA238_BUS_VOLTAGE_LSB,
.temp_resolution = 12,
.conv_time = ina238_conv_time,
},
[ina700] = {
.has_20bit_voltage_current = false,
.has_energy = true,
.has_power_highest = false,
.power_calculate_factor = 20,
.config_default = INA238_CONFIG_DEFAULT,
.bus_voltage_lsb = INA238_BUS_VOLTAGE_LSB,
.temp_resolution = 12,
.current_lsb = 480,
.conv_time = ina238_conv_time,
},
[ina780] = {
.has_20bit_voltage_current = false,
.has_energy = true,
.has_power_highest = false,
.power_calculate_factor = 20,
.config_default = INA238_CONFIG_DEFAULT,
.bus_voltage_lsb = INA238_BUS_VOLTAGE_LSB,
.temp_resolution = 12,
.current_lsb = 2400,
.conv_time = ina238_conv_time,
},
[sq52206] = {
.has_20bit_voltage_current = false,
.has_energy = true,
.has_power_highest = true,
.power_calculate_factor = 24,
.config_default = SQ52206_CONFIG_DEFAULT,
.bus_voltage_lsb = SQ52206_BUS_VOLTAGE_LSB,
.temp_resolution = 16,
.conv_time = sq52206_conv_time,
},
};
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/err.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct ina238_config`, `struct ina238_data`, `enum ina238_ids`, `function ina238_read_reg24`, `function ina238_read_reg40`, `function ina238_read_field_s20`, `function ina228_read_voltage`, `function ina238_reg_to_interval_us`, `function ina238_samples`, `function fields`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.