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.

Dependency Surface

Detected Declarations

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

Implementation Notes