From patchwork Wed Nov 25 04:44:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Krzyszkowiak X-Patchwork-Id: 11930371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 335FBC6379D for ; Wed, 25 Nov 2020 04:45:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D68A9208B8 for ; Wed, 25 Nov 2020 04:45:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727988AbgKYEpT (ORCPT ); Tue, 24 Nov 2020 23:45:19 -0500 Received: from comms.puri.sm ([159.203.221.185]:48000 "EHLO comms.puri.sm" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726985AbgKYEpT (ORCPT ); Tue, 24 Nov 2020 23:45:19 -0500 Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id 0560AE0141; Tue, 24 Nov 2020 20:44:49 -0800 (PST) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id d2T0OxrIJYPM; Tue, 24 Nov 2020 20:44:47 -0800 (PST) From: Sebastian Krzyszkowiak To: Sebastian Reichel Cc: Geordan Neukum , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@puri.sm Subject: [PATCH 1/4] power: max17042_battery: Fix current_{avg,now} hiding with no current sense Date: Wed, 25 Nov 2020 05:44:44 +0100 Message-ID: <2264396.HPVdm0XNkV@pliszka> Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When current sense is disabled, max17042_no_current_sense_psy_desc gets used which ignores two last properties from the list. Fixes: 21b01cc879cc ("power: supply: max17042_battery: Add support for the TTE_NOW prop") Signed-off-by: Sebastian Krzyszkowiak --- drivers/power/supply/max17042_battery.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index f284547913d6..2e9672fe4df1 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -85,9 +85,10 @@ static enum power_supply_property max17042_battery_props[] = { POWER_SUPPLY_PROP_TEMP_MAX, POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_SCOPE, + POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, + // these two have to be at the end on the list POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_CURRENT_AVG, - POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, }; static int max17042_get_temperature(struct max17042_chip *chip, int *temp) From patchwork Wed Nov 25 04:46:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Krzyszkowiak X-Patchwork-Id: 11930373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9824DC5519F for ; Wed, 25 Nov 2020 04:46:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38165208B8 for ; Wed, 25 Nov 2020 04:46:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726991AbgKYEqV (ORCPT ); Tue, 24 Nov 2020 23:46:21 -0500 Received: from comms.puri.sm ([159.203.221.185]:48066 "EHLO comms.puri.sm" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbgKYEqV (ORCPT ); Tue, 24 Nov 2020 23:46:21 -0500 Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id 37F43E0399; Tue, 24 Nov 2020 20:46:21 -0800 (PST) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t2ineu87QF7d; Tue, 24 Nov 2020 20:46:20 -0800 (PST) From: Sebastian Krzyszkowiak To: Sebastian Reichel Cc: Geordan Neukum , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@puri.sm Subject: [PATCH 2/4] power: max17042_battery: Improve accuracy of current_now and current_avg readings Date: Wed, 25 Nov 2020 05:46:17 +0100 Message-ID: <4526762.6nKOPmpm47@pliszka> In-Reply-To: <2264396.HPVdm0XNkV@pliszka> References: <2264396.HPVdm0XNkV@pliszka> Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Dividing 1562500 by r_sns value usually doesn't result in an integer. Signed-off-by: Sebastian Krzyszkowiak --- drivers/power/supply/max17042_battery.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index 2e9672fe4df1..86adccb0f32d 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -395,8 +395,8 @@ static int max17042_get_property(struct power_supply *psy, if (ret < 0) return ret; - val->intval = sign_extend32(data, 15); - val->intval *= 1562500 / chip->pdata->r_sns; + data64 = sign_extend64(data, 15) * 1562500ll; + val->intval = div_s64(data64, chip->pdata->r_sns); } else { return -EINVAL; } @@ -407,8 +407,8 @@ static int max17042_get_property(struct power_supply *psy, if (ret < 0) return ret; - val->intval = sign_extend32(data, 15); - val->intval *= 1562500 / chip->pdata->r_sns; + data64 = sign_extend64(data, 15) * 1562500ll; + val->intval = div_s64(data64, chip->pdata->r_sns); } else { return -EINVAL; } From patchwork Wed Nov 25 04:47:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Krzyszkowiak X-Patchwork-Id: 11930375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B14A9C5519F for ; Wed, 25 Nov 2020 04:47:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 611A3208B8 for ; Wed, 25 Nov 2020 04:47:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726860AbgKYErJ (ORCPT ); Tue, 24 Nov 2020 23:47:09 -0500 Received: from comms.puri.sm ([159.203.221.185]:48106 "EHLO comms.puri.sm" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbgKYErJ (ORCPT ); Tue, 24 Nov 2020 23:47:09 -0500 Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id 3FDC3E0399; Tue, 24 Nov 2020 20:47:09 -0800 (PST) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oYTaweB7_C_3; Tue, 24 Nov 2020 20:47:08 -0800 (PST) From: Sebastian Krzyszkowiak To: Sebastian Reichel Cc: Geordan Neukum , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@puri.sm Subject: [PATCH 3/4] power: max17042_battery: Take r_sns value into account in charge_counter Date: Wed, 25 Nov 2020 05:47:04 +0100 Message-ID: <146027451.poJRWWCWiI@pliszka> In-Reply-To: <2264396.HPVdm0XNkV@pliszka> References: <2264396.HPVdm0XNkV@pliszka> Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The default r_sns value was hardcoded there, so let's change it to the actually configured one. Signed-off-by: Sebastian Krzyszkowiak --- drivers/power/supply/max17042_battery.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index 86adccb0f32d..26f6f89eb648 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -354,7 +354,8 @@ static int max17042_get_property(struct power_supply *psy, if (ret < 0) return ret; - val->intval = data * 1000 / 2; + data64 = sign_extend64(data, 15) * 5000000ll; + val->intval = div_s64(data64, chip->pdata->r_sns); break; case POWER_SUPPLY_PROP_TEMP: ret = max17042_get_temperature(chip, &val->intval); From patchwork Wed Nov 25 04:48:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Krzyszkowiak X-Patchwork-Id: 11930377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1306BC63777 for ; Wed, 25 Nov 2020 04:49:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C14B220B80 for ; Wed, 25 Nov 2020 04:49:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727353AbgKYEtE (ORCPT ); Tue, 24 Nov 2020 23:49:04 -0500 Received: from comms.puri.sm ([159.203.221.185]:48258 "EHLO comms.puri.sm" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727285AbgKYEtE (ORCPT ); Tue, 24 Nov 2020 23:49:04 -0500 Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id 0BECBE0399; Tue, 24 Nov 2020 20:48:34 -0800 (PST) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id W_YMHONlpVnG; Tue, 24 Nov 2020 20:48:33 -0800 (PST) From: Sebastian Krzyszkowiak To: Sebastian Reichel Cc: Geordan Neukum , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@puri.sm Subject: [PATCH 4/4] power: max17042_battery: Export charge termination current property Date: Wed, 25 Nov 2020 05:48:30 +0100 Message-ID: <3900768.gxICSWkFWK@pliszka> In-Reply-To: <2264396.HPVdm0XNkV@pliszka> References: <2264396.HPVdm0XNkV@pliszka> Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The value is there, so let's export it. Signed-off-by: Sebastian Krzyszkowiak --- drivers/power/supply/max17042_battery.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index 26f6f89eb648..79d4b5988360 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -78,6 +78,7 @@ static enum power_supply_property max17042_battery_props[] = { POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_CHARGE_NOW, POWER_SUPPLY_PROP_CHARGE_COUNTER, + POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, POWER_SUPPLY_PROP_TEMP, POWER_SUPPLY_PROP_TEMP_ALERT_MIN, POWER_SUPPLY_PROP_TEMP_ALERT_MAX, @@ -414,6 +415,14 @@ static int max17042_get_property(struct power_supply *psy, return -EINVAL; } break; + case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: + ret = regmap_read(map, MAX17042_ICHGTerm, &data); + if (ret < 0) + return ret; + + data64 = data * 1562500ll; + val->intval = div_s64(data64, chip->pdata->r_sns); + break; case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: ret = regmap_read(map, MAX17042_TTE, &data); if (ret < 0)