Message ID | 20180222172136.GA20773@lenoch (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
Hi, On Thu, Feb 22, 2018 at 06:21:36PM +0100, Ladislav Michl wrote: > Temperature is measured in tenths of degree Celsius. > > Fixes: 085bc24d1553 ("Add LTC2941/LTC2943 Battery Gauge Driver") > Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Thanks, applying to power-supply's fixes branch. > Notes: > - I was unable to find first version of this driver. Leaked changelog > in the first commit states: "v2: Fix units of measurement: uV, uA > and centidegrees", but even documentation commit > 588bd5918baca940a52802045f3b388358dc6917 from 2013 clearly states > tenths of degree Celsius. This is also what UPower expects. > - Looking at other drivers is even more confusing, but let's not > try to save universe at the moment. Perhaps one thing is worth > fixing with respect to lord Kelvin: There is no "degree Kelvin" > as bq27xxx_battery.c tries to convice us. Yes, people often get the units wrong (i.e. using mV instead of uV) :( -- Sebastian > drivers/power/supply/ltc2941-battery-gauge.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c > index 9360faca7026..4f129bb4c972 100644 > --- a/drivers/power/supply/ltc2941-battery-gauge.c > +++ b/drivers/power/supply/ltc2941-battery-gauge.c > @@ -341,15 +341,15 @@ static int ltc294x_get_temperature(const struct ltc294x_info *info, int *val) > > if (info->id == LTC2942_ID) { > reg = LTC2942_REG_TEMPERATURE_MSB; > - value = 60000; /* Full-scale is 600 Kelvin */ > + value = 6000; /* Full-scale is 600 Kelvin */ > } else { > reg = LTC2943_REG_TEMPERATURE_MSB; > - value = 51000; /* Full-scale is 510 Kelvin */ > + value = 5100; /* Full-scale is 510 Kelvin */ > } > ret = ltc294x_read_regs(info->client, reg, &datar[0], 2); > value *= (datar[0] << 8) | datar[1]; > - /* Convert to centidegrees */ > - *val = value / 0xFFFF - 27215; > + /* Convert to tenths of degree Celsius */ > + *val = value / 0xFFFF - 2722; > return ret; > } > > -- > 2.16.1 >
diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c index 9360faca7026..4f129bb4c972 100644 --- a/drivers/power/supply/ltc2941-battery-gauge.c +++ b/drivers/power/supply/ltc2941-battery-gauge.c @@ -341,15 +341,15 @@ static int ltc294x_get_temperature(const struct ltc294x_info *info, int *val) if (info->id == LTC2942_ID) { reg = LTC2942_REG_TEMPERATURE_MSB; - value = 60000; /* Full-scale is 600 Kelvin */ + value = 6000; /* Full-scale is 600 Kelvin */ } else { reg = LTC2943_REG_TEMPERATURE_MSB; - value = 51000; /* Full-scale is 510 Kelvin */ + value = 5100; /* Full-scale is 510 Kelvin */ } ret = ltc294x_read_regs(info->client, reg, &datar[0], 2); value *= (datar[0] << 8) | datar[1]; - /* Convert to centidegrees */ - *val = value / 0xFFFF - 27215; + /* Convert to tenths of degree Celsius */ + *val = value / 0xFFFF - 2722; return ret; }
Temperature is measured in tenths of degree Celsius. Fixes: 085bc24d1553 ("Add LTC2941/LTC2943 Battery Gauge Driver") Signed-off-by: Ladislav Michl <ladis@linux-mips.org> --- Notes: - I was unable to find first version of this driver. Leaked changelog in the first commit states: "v2: Fix units of measurement: uV, uA and centidegrees", but even documentation commit 588bd5918baca940a52802045f3b388358dc6917 from 2013 clearly states tenths of degree Celsius. This is also what UPower expects. - Looking at other drivers is even more confusing, but let's not try to save universe at the moment. Perhaps one thing is worth fixing with respect to lord Kelvin: There is no "degree Kelvin" as bq27xxx_battery.c tries to convice us. drivers/power/supply/ltc2941-battery-gauge.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)