Skip to content

Commit 63fb21a

Browse files
committed
hwmon: (ina2xx) Use shunt voltage to calculate current
Since the shunt voltage and the current register report the same values when the chip is calibrated, we can calculate the current directly from the shunt voltage without relying on chip calibration. With this change, the current register is no longer accessed. Its register address is only used to indicate if reading or writing current or shunt voltage is desired when accessing registers. Reviewed-by: Tzung-Bi Shih <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 4d5c2d9 commit 63fb21a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/hwmon/ina2xx.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ static int ina2xx_curr_read(struct device *dev, u32 attr, long *val)
480480
{
481481
struct ina2xx_data *data = dev_get_drvdata(dev);
482482
struct regmap *regmap = data->regmap;
483+
unsigned int regval;
484+
int ret;
483485

484486
/*
485487
* While the chips supported by this driver do not directly support
@@ -492,7 +494,17 @@ static int ina2xx_curr_read(struct device *dev, u32 attr, long *val)
492494
*/
493495
switch (attr) {
494496
case hwmon_curr_input:
495-
return ina2xx_read_init(dev, INA2XX_CURRENT, val);
497+
/*
498+
* Since the shunt voltage and the current register report the
499+
* same values when the chip is calibrated, we can calculate
500+
* the current directly from the shunt voltage without relying
501+
* on chip calibration.
502+
*/
503+
ret = regmap_read(regmap, INA2XX_SHUNT_VOLTAGE, &regval);
504+
if (ret)
505+
return ret;
506+
*val = ina2xx_get_value(data, INA2XX_CURRENT, regval);
507+
return 0;
496508
case hwmon_curr_lcrit:
497509
return ina226_alert_limit_read(data, INA226_SHUNT_UNDER_VOLTAGE_MASK,
498510
INA2XX_CURRENT, val);

0 commit comments

Comments
 (0)