From patchwork Thu Feb 22 17:21:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 10236019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0E20360349 for ; Thu, 22 Feb 2018 17:23:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D4EA2903C for ; Thu, 22 Feb 2018 17:23:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AED6290A9; Thu, 22 Feb 2018 17:23:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C02F294A2 for ; Thu, 22 Feb 2018 17:21:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933319AbeBVRVl (ORCPT ); Thu, 22 Feb 2018 12:21:41 -0500 Received: from eddie.linux-mips.org ([148.251.95.138]:42278 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933210AbeBVRVj (ORCPT ); Thu, 22 Feb 2018 12:21:39 -0500 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23994583AbeBVRVhZDVGL (ORCPT ); Thu, 22 Feb 2018 18:21:37 +0100 Date: Thu, 22 Feb 2018 18:21:36 +0100 From: Ladislav Michl To: linux-pm@vger.kernel.org Cc: Sebastian Reichel , Mike Looijmans , Dragos Bogdan Subject: [PATCH] power: supply: ltc2941-battery-gauge: Fix temperature units Message-ID: <20180222172136.GA20773@lenoch> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Temperature is measured in tenths of degree Celsius. Fixes: 085bc24d1553 ("Add LTC2941/LTC2943 Battery Gauge Driver") Signed-off-by: Ladislav Michl --- 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(-) 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; }