drivers/hwmon/ina2xx.c

Source file repositories/reference/linux-study-clean/drivers/hwmon/ina2xx.c

File Facts

System
Linux kernel
Corpus path
drivers/hwmon/ina2xx.c
Extension
.c
Size
27549 bytes
Lines
1066
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ina2xx_config {
	u16 config_default;
	bool has_alerts;	/* chip supports alerts and limits */
	bool has_ishunt;	/* chip has internal shunt resistor */
	bool has_power_average;	/* chip supports average power */
	bool has_update_interval;
	int calibration_value;
	int shunt_div;
	int shunt_voltage_shift;
	int bus_voltage_shift;
	int bus_voltage_lsb;	/* uV */
	int power_lsb_factor;
	int current_shift;
};

struct ina2xx_data {
	const struct ina2xx_config *config;
	enum ina2xx_ids chip;

	long rshunt;
	long current_lsb_uA;
	long power_lsb_uW;
	struct regmap *regmap;
	struct i2c_client *client;
};

static const struct ina2xx_config ina2xx_config[] = {
	[ina219] = {
		.config_default = INA219_CONFIG_DEFAULT,
		.calibration_value = 4096,
		.shunt_div = 100,
		.shunt_voltage_shift = 0,
		.bus_voltage_shift = 3,
		.bus_voltage_lsb = 4000,
		.power_lsb_factor = 20,
		.has_alerts = false,
		.has_ishunt = false,
		.has_power_average = false,
		.current_shift = 0,
		.has_update_interval = false,
	},
	[ina226] = {
		.config_default = INA226_CONFIG_DEFAULT,
		.calibration_value = 2048,
		.shunt_div = 400,
		.shunt_voltage_shift = 0,
		.bus_voltage_shift = 0,
		.bus_voltage_lsb = 1250,
		.power_lsb_factor = 25,
		.has_alerts = true,
		.has_ishunt = false,
		.has_power_average = false,
		.current_shift = 0,
		.has_update_interval = true,
	},
	[ina234] = {
		.config_default = INA226_CONFIG_DEFAULT,
		.calibration_value = 2048,
		.shunt_div = 25, /* 2.5 µV/LSB raw ADC reading from INA2XX_SHUNT_VOLTAGE */
		.shunt_voltage_shift = 4,
		.bus_voltage_shift = 4,
		.bus_voltage_lsb = 25600,
		.power_lsb_factor = 32,
		.has_alerts = true,
		.has_ishunt = false,
		.has_power_average = false,
		.current_shift = 4,
		.has_update_interval = true,
	},
	[ina260] = {
		.config_default = INA260_CONFIG_DEFAULT,
		.shunt_div = 400,
		.shunt_voltage_shift = 0,
		.bus_voltage_shift = 0,
		.bus_voltage_lsb = 1250,
		.power_lsb_factor = 8,
		.has_alerts = true,
		.has_ishunt = true,
		.has_power_average = false,
		.current_shift = 0,
		.has_update_interval = true,
	},
	[sy24655] = {
		.config_default = SY24655_CONFIG_DEFAULT,
		.calibration_value = 4096,
		.shunt_div = 400,
		.shunt_voltage_shift = 0,
		.bus_voltage_shift = 0,
		.bus_voltage_lsb = 1250,
		.power_lsb_factor = 25,

Annotation

Implementation Notes