hwmon: (isl28022) Fix current reading calculation
According to the ISL28022 datasheet, bit15 of the current register is representing -32768. Fix the calculation to properly handle this bit, ensuring correct measurements for negative values. Signed-off-by: Yikai Tsai <yikai.tsai.wiwynn@gmail.com> Link: https://lore.kernel.org/r/20250519084055.3787-2-yikai.tsai.wiwynn@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>pull/1285/head
parent
0ddce55490
commit
b2446a16db
|
|
@ -154,6 +154,7 @@ static int isl28022_read_current(struct device *dev, u32 attr, long *val)
|
|||
struct isl28022_data *data = dev_get_drvdata(dev);
|
||||
unsigned int regval;
|
||||
int err;
|
||||
u16 sign_bit;
|
||||
|
||||
switch (attr) {
|
||||
case hwmon_curr_input:
|
||||
|
|
@ -161,8 +162,9 @@ static int isl28022_read_current(struct device *dev, u32 attr, long *val)
|
|||
ISL28022_REG_CURRENT, ®val);
|
||||
if (err < 0)
|
||||
return err;
|
||||
*val = ((long)regval * 1250L * (long)data->gain) /
|
||||
(long)data->shunt;
|
||||
sign_bit = (regval >> 15) & 0x01;
|
||||
*val = (((long)(((u16)regval) & 0x7FFF) - (sign_bit * 32768)) *
|
||||
1250L * (long)data->gain) / (long)data->shunt;
|
||||
break;
|
||||
default:
|
||||
return -EOPNOTSUPP;
|
||||
|
|
|
|||
Loading…
Reference in New Issue