From patchwork Tue Jan 15 10:32:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10764269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CBD313B4 for ; Tue, 15 Jan 2019 10:33:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8074D2B8EC for ; Tue, 15 Jan 2019 10:33:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 745AC2B929; Tue, 15 Jan 2019 10:33:21 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 221752B8EC for ; Tue, 15 Jan 2019 10:33:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728781AbfAOKdU (ORCPT ); Tue, 15 Jan 2019 05:33:20 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43279 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728347AbfAOKdU (ORCPT ); Tue, 15 Jan 2019 05:33:20 -0500 Received: by mail-pf1-f194.google.com with SMTP id w73so1110591pfk.10 for ; Tue, 15 Jan 2019 02:33:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=+/pZ0dv7/TrWKuI+u0mzefBEqQY+i72QxuOgn/qV09M=; b=V2YFQgeO9AiPLYV38d75wisXsQIpYGe3qcgzWdbSM1k2YkPw4Otq0pEkHmGWqWUdfi doKRbzXKTsW5UzDJSaddrSaBuc7fIsr0Qh+McMqpZ6ZPhv3S7Zm0v2/w0RBJmJ/ng530 mTyTuXCwLcan9QL1pUhizD3ECoRGpPO/1vH7g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+/pZ0dv7/TrWKuI+u0mzefBEqQY+i72QxuOgn/qV09M=; b=PqLiMAEokbLIvOhbtinX7EEkYsN+zu6YS1Rhk5WK4astKHGB3iPeLmWIDxAVn85P+5 BotkD5mWSp0XjnSuPrtScTkE6XcHY53jD6bFGPMfxHSZGKJpJxbpq2f1eOGOnyW/juws b5Or3dyo1ZAcQ34Fg1za5GUeyKzDaPWyx2SAFqhKivncpDDSw/YOxnDeMVZUvLHAcPU1 YMZYCGYzwspPb6Pr+7dUai0gVdb7viKwn6pV0/tBa/TUjK6YDaIx8ms+ju9l716eLTf8 nV84bVEPnXgtgAgBUVX9EJ0Rts7SvgZzygF+0hCTz+qsLgcp+rGRnBGb9STa1k8JeF1r nrpQ== X-Gm-Message-State: AJcUukfS4D4rWjHYcLbKneAaH6Gf/+0nwi9Hc4vAVOfjpgmsR0+0PzF8 aGBgPtQ1CCUaUJSSfdy0vCAwgw== X-Google-Smtp-Source: ALg8bN5b9xnbSVkceqQdiHXO7eQhHuqmqXejKbxaNDs4F6q8XIhKODGGcIAZsFyXRlUkadb7MNuYpw== X-Received: by 2002:a63:eb52:: with SMTP id b18mr3123202pgk.213.1547548398856; Tue, 15 Jan 2019 02:33:18 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id d13sm5073957pfd.58.2019.01.15.02.33.15 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Jan 2019 02:33:18 -0800 (PST) From: Baolin Wang To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, broonie@kernel.org, zhang.lyra@gmail.com, orsonzhai@gmail.com Subject: [PATCH 1/4] dt-bindings: power: sc27xx: Add one IIO channel to read charge voltage Date: Tue, 15 Jan 2019 18:32:34 +0800 Message-Id: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 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 Add one IIO channel named "charge_vol" to read the charge voltage for the SC27XX fuel gauge controller. Signed-off-by: Baolin Wang Reviewed-by: Rob Herring --- .../devicetree/bindings/power/supply/sc27xx-fg.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/power/supply/sc27xx-fg.txt b/Documentation/devicetree/bindings/power/supply/sc27xx-fg.txt index fc35ac5..0a5705b 100644 --- a/Documentation/devicetree/bindings/power/supply/sc27xx-fg.txt +++ b/Documentation/devicetree/bindings/power/supply/sc27xx-fg.txt @@ -9,8 +9,8 @@ Required properties: "sprd,sc2731-fgu". - reg: The address offset of fuel gauge unit. - battery-detect-gpios: GPIO for battery detection. -- io-channels: Specify the IIO ADC channel to get temperature. -- io-channel-names: Should be "bat-temp". +- io-channels: Specify the IIO ADC channels to get temperature and charge voltage. +- io-channel-names: Should be "bat-temp" or "charge-vol". - nvmem-cells: A phandle to the calibration cells provided by eFuse device. - nvmem-cell-names: Should be "fgu_calib". - monitored-battery: Phandle of battery characteristics devicetree node. @@ -47,8 +47,8 @@ Example: compatible = "sprd,sc2731-fgu"; reg = <0xa00>; battery-detect-gpios = <&pmic_eic 9 GPIO_ACTIVE_HIGH>; - io-channels = <&pmic_adc 5>; - io-channel-names = "bat-temp"; + io-channels = <&pmic_adc 5>, <&pmic_adc 14>; + io-channel-names = "bat-temp", "charge-vol"; nvmem-cells = <&fgu_calib>; nvmem-cell-names = "fgu_calib"; monitored-battery = <&bat>; From patchwork Tue Jan 15 10:32:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10764275 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CF85139A for ; Tue, 15 Jan 2019 10:33:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16C182B0F2 for ; Tue, 15 Jan 2019 10:33:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07BE82B0E0; Tue, 15 Jan 2019 10:33:47 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 90F182B8FB for ; Tue, 15 Jan 2019 10:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728868AbfAOKdY (ORCPT ); Tue, 15 Jan 2019 05:33:24 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:38525 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728856AbfAOKdX (ORCPT ); Tue, 15 Jan 2019 05:33:23 -0500 Received: by mail-pg1-f194.google.com with SMTP id g189so1076369pgc.5 for ; Tue, 15 Jan 2019 02:33:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=z+FEdKv7SOmZhEaX0R5BmbcCjlQ5jY9He3y4lwTJ11k=; b=fbSRwjQ/EGE0uRRDVnqryJ62/1KLUb9050Vx0WaPWP2IPPZzpgcicvYwGhus6ms83/ vqYWn8nBZ+gzWOuID2hqv5KFzW4Y1f+twpifDBtDoNro7yv/Zq4ZL+SLk9eqsfDghryP b5VC9jSegvUeY5dgh731OrZL/5KfF1Lt7NzyQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=z+FEdKv7SOmZhEaX0R5BmbcCjlQ5jY9He3y4lwTJ11k=; b=iCWaP/hQ5EuNQyYUIlbBNlBjghPi+fxynwg92jtO9XQxodtHUR6oQUJQzKuRFZxsSi 3FG8JSfls5wYBgWhw2Qe94SKXZOzb44wpL16uViA+hH1xvRjhn9gs16s9juBHQH6ux5D 285lGttoym0HgtCaoorfciAogyIOVjjv964Pb04h2PEHqwsiCwzbsPMQgfULOkmbQCgV ue3QDSqJJKMydHqF+Q7Pr/luH1tJhjxZKSsMW/JhWBM2AlCMBfi8xwEDRrVoe8ksX95h lPkntjm4ETW5fX3tcQ0U+MerNNjx3EpiPRaibpdN24pqDLkXhSWedsVfsfEy5EhMyn+A qkuw== X-Gm-Message-State: AJcUukdYxIOXqAhUBp61AUorWZl/o8tWiIxMD96z4AsBIJN4zcfyqcHD LN49+CRvtzwwg6fJK18V1unUDg== X-Google-Smtp-Source: ALg8bN7aQ7UMWqARv8+lFsHSZ+pvlDvq9V5qRH0fxi7L1fUlCtn/k7M0UOlGvcrKwX/sPIAIICtHpw== X-Received: by 2002:a62:7e13:: with SMTP id z19mr3316400pfc.94.1547548402337; Tue, 15 Jan 2019 02:33:22 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id d13sm5073957pfd.58.2019.01.15.02.33.19 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Jan 2019 02:33:21 -0800 (PST) From: Baolin Wang To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, broonie@kernel.org, zhang.lyra@gmail.com, orsonzhai@gmail.com Subject: [PATCH 2/4] power: supply: sc27xx: Add one property to read charge voltage Date: Tue, 15 Jan 2019 18:32:35 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> References: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> In-Reply-To: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> References: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> 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 Add POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE property to get charge voltage sampling by ADC controller, which is used to validate if the charge voltage is in normal range or not in charger manager. Signed-off-by: Baolin Wang --- drivers/power/supply/sc27xx_fuel_gauge.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c index 76da189..4926b8a 100644 --- a/drivers/power/supply/sc27xx_fuel_gauge.c +++ b/drivers/power/supply/sc27xx_fuel_gauge.c @@ -72,6 +72,7 @@ * @lock: protect the structure * @gpiod: GPIO for battery detection * @channel: IIO channel to get battery temperature + * @charge_chan: IIO channel to get charge voltage * @internal_resist: the battery internal resistance in mOhm * @total_cap: the total capacity of the battery in mAh * @init_cap: the initial capacity of the battery in mAh @@ -92,6 +93,7 @@ struct sc27xx_fgu_data { struct mutex lock; struct gpio_desc *gpiod; struct iio_channel *channel; + struct iio_channel *charge_chan; bool bat_present; int internal_resist; int total_cap; @@ -391,6 +393,18 @@ static int sc27xx_fgu_get_vbat_ocv(struct sc27xx_fgu_data *data, int *val) return 0; } +static int sc27xx_fgu_get_charge_vol(struct sc27xx_fgu_data *data, int *val) +{ + int ret, vol; + + ret = iio_read_channel_processed(data->charge_chan, &vol); + if (ret < 0) + return ret; + + *val = vol * 1000; + return 0; +} + static int sc27xx_fgu_get_temp(struct sc27xx_fgu_data *data, int *temp) { return iio_read_channel_processed(data->channel, temp); @@ -502,6 +516,14 @@ static int sc27xx_fgu_get_property(struct power_supply *psy, val->intval = value; break; + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: + ret = sc27xx_fgu_get_charge_vol(data, &value); + if (ret) + goto error; + + val->intval = value; + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: case POWER_SUPPLY_PROP_CURRENT_AVG: ret = sc27xx_fgu_get_current(data, &value); @@ -567,6 +589,7 @@ static int sc27xx_fgu_property_is_writeable(struct power_supply *psy, POWER_SUPPLY_PROP_VOLTAGE_OCV, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_CURRENT_AVG, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, }; static const struct power_supply_desc sc27xx_fgu_desc = { @@ -907,6 +930,12 @@ static int sc27xx_fgu_probe(struct platform_device *pdev) return PTR_ERR(data->channel); } + data->charge_chan = devm_iio_channel_get(&pdev->dev, "charge-vol"); + if (IS_ERR(data->charge_chan)) { + dev_err(&pdev->dev, "failed to get charge IIO channel\n"); + return PTR_ERR(data->charge_chan); + } + data->gpiod = devm_gpiod_get(&pdev->dev, "bat-detect", GPIOD_IN); if (IS_ERR(data->gpiod)) { dev_err(&pdev->dev, "failed to get battery detection GPIO\n"); From patchwork Tue Jan 15 10:32:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10764271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 50E2A13B4 for ; Tue, 15 Jan 2019 10:33:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 403C52B8FB for ; Tue, 15 Jan 2019 10:33:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 341EB2B96E; Tue, 15 Jan 2019 10:33:29 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 DDE8D2B8FB for ; Tue, 15 Jan 2019 10:33:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728894AbfAOKd1 (ORCPT ); Tue, 15 Jan 2019 05:33:27 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45337 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728879AbfAOKd1 (ORCPT ); Tue, 15 Jan 2019 05:33:27 -0500 Received: by mail-pg1-f195.google.com with SMTP id y4so1060189pgc.12 for ; Tue, 15 Jan 2019 02:33:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=dIyDlEhPk6JnUTXfldKLOjRO3WNV6b65BdAvK6H2ezc=; b=Idvhwjz2PCwfeCZlSfS8wWCImer2VupTl79ttniFdOy/ZB+YEuNAmrmVyyOmLkGq5D Dbv4rSDwlCtVk8Wt4wFSUwU1syU1szrBgfKGEKjXxsamyu1A3shEmeS0zJmYZ5W+RXBO OPZ7nV14PuHpDqoOPmRq9qwe8Gk6ATLWBL6CY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=dIyDlEhPk6JnUTXfldKLOjRO3WNV6b65BdAvK6H2ezc=; b=mmH3ANQwElmk0OZELg5q7UyfkRYNE0Vk7wbZg6324prxykYHpf0KuRH0sIJmuWrlcK zVUBcwLiqnWmH4jA872BOKGf3Xy+ejl0+V0fghcZciiCnmZ7iVsJad7qLvJQj7cjxilg fUG69+J40nK/X+GC+jZOsJ1ZWr/wY24ixWVk1Hr8B/1nB48J7vmrpAJ7VeLUHjBpvYCv e3pYqwyjHMBUQY+lZg32ENvlBMPd4djwTKQQM1NKImQvtEwC3+RLXK+vqQSXgM11a74o qdYgwwIaFl+60IdQPDKw7KGRlQoyr9xRNcOYJrqgT4WxdsCG5e+C+Z1A8CVTS2A76Yxj yYTQ== X-Gm-Message-State: AJcUukfmSYKyqE+vuALWMnHCQhIN9mgV6VTPR8ic57+7vgWXAjp8AoKz C0ImYhjTBESpz7vgo8Z9JHqWWw== X-Google-Smtp-Source: ALg8bN5tPJ802wXKib0Xc/vXXsEVgz30eEx1kURE+RGxE654JSqnBiMyHcJwhhMu4sFSNmONVL88SQ== X-Received: by 2002:a62:cf02:: with SMTP id b2mr3364348pfg.183.1547548406698; Tue, 15 Jan 2019 02:33:26 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id d13sm5073957pfd.58.2019.01.15.02.33.22 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Jan 2019 02:33:25 -0800 (PST) From: Baolin Wang To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, broonie@kernel.org, zhang.lyra@gmail.com, orsonzhai@gmail.com Subject: [PATCH 3/4] power: supply: sc27xx: Fix the incorrect formula when converting capacity to coulomb counter Date: Tue, 15 Jan 2019 18:32:36 +0800 Message-Id: <7d23781552d6ff1fe6bbabfc56cbbb04d807fffa.1547544142.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> References: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> In-Reply-To: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> References: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> 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 We should multiply the calibrated current data (cur_1000ma_adc) when converting current capacity (mAh) to coulomb counter, which can get an accurate coulomb counter from the fuel gauge controller. Signed-off-by: Baolin Wang --- drivers/power/supply/sc27xx_fuel_gauge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c index 4926b8a..ea1349f 100644 --- a/drivers/power/supply/sc27xx_fuel_gauge.c +++ b/drivers/power/supply/sc27xx_fuel_gauge.c @@ -731,7 +731,7 @@ static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity) * Convert current capacity (mAh) to coulomb counter according to the * formula: 1 mAh =3.6 coulomb. */ - return DIV_ROUND_CLOSEST(cur_cap * 36, 10); + return DIV_ROUND_CLOSEST(cur_cap * 36 * data->cur_1000ma_adc, 10); } static int sc27xx_fgu_calibration(struct sc27xx_fgu_data *data) From patchwork Tue Jan 15 10:32:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10764273 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35C8613B4 for ; Tue, 15 Jan 2019 10:33:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 239A72B8FB for ; Tue, 15 Jan 2019 10:33:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 170AA2B952; Tue, 15 Jan 2019 10:33:44 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 965E22B8FB for ; Tue, 15 Jan 2019 10:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728931AbfAOKdl (ORCPT ); Tue, 15 Jan 2019 05:33:41 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:45904 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728925AbfAOKdc (ORCPT ); Tue, 15 Jan 2019 05:33:32 -0500 Received: by mail-pl1-f193.google.com with SMTP id a14so1081750plm.12 for ; Tue, 15 Jan 2019 02:33:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=gfsjcoK5+n5u8rdyVSCIiowp3BqnWBKCmYbY+r0pFqo=; b=NjalyehonmSD9f1XkR4NT52PJKvEiK+haOiYekDryzxm6wrHaHgYPGssUgy5RnbI+c 7E2jxPO/HlDbaNi8KYCw6/fEqL8aI7xmSFTo2CuSv0zZEg/RnPuiTfhPB05xN2TzxVwI 2+8U/2UEm/wbrBLy/cAYfcY9EC/97mPdi/ibU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=gfsjcoK5+n5u8rdyVSCIiowp3BqnWBKCmYbY+r0pFqo=; b=dvYbH95a9MFaJJwvVuwTvPYa7YgKYbK7LFidJ/PUqpCshO7FloD+KvID9RrLU+FHt/ HwTQJJ3gA9S+HLmgNIbfry14q2skavZYCKLPsuntF2xT0o37o2ZIaSJpdoe/Q/ngYf2M Rlvx285Nznmk5hCLZB2keLw7jjboc/nIrWvPW+sb+Yu1amovs64wYDLUVuyloZYOY+pl TTsxt6QmaJ+tsW8jLwMBxCFXywYQCBPSQgjQGl+6l2v0Xjm5B1skL88MN6QURqcLwfaT bcRWfndH2P7M4jhPW3/WXGLarzc1tfe2fW5XrnCGusFmN+FpCmpUGLnTeV1ivibeX/b1 1fLw== X-Gm-Message-State: AJcUuke7jVv3MshVdiFwR+RX1fAa3GGcjBDd4VAuvBXwTQm7eaS0JXB9 aNgjobvaZOeaoGUC1KiaA87kVw== X-Google-Smtp-Source: ALg8bN4OopI8AkedXthOvA9gAZJmqUIZOMaddwqcZBZBl4IMX905n3P7WxheBQ6/XrO/3TCt+bi5Qw== X-Received: by 2002:a17:902:bd46:: with SMTP id b6mr3323046plx.231.1547548411565; Tue, 15 Jan 2019 02:33:31 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id d13sm5073957pfd.58.2019.01.15.02.33.26 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Jan 2019 02:33:30 -0800 (PST) From: Baolin Wang To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, broonie@kernel.org, zhang.lyra@gmail.com, orsonzhai@gmail.com Subject: [PATCH 4/4] power: supply: sc27xx: Fix capacity saving function Date: Tue, 15 Jan 2019 18:32:37 +0800 Message-Id: <30327406bfd6aa0559e48b766c87c6845fe059af.1547544142.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> References: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> In-Reply-To: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> References: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> 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 From: Yuanjiang Yu We found sometimes we can not get the saving capacity to initialize the battery capacity, the reason is the user area registers are put on power always-on region, so we need delay some time to wait until values are updated successfully. Moreover we also should clear the USER_AREA_CLEAR register after setting the USER_AREA_SET register, otherwise we can not save the values in the USER_AREA_SET register. Signed-off-by: Yuanjiang Yu Signed-off-by: Baolin Wang --- drivers/power/supply/sc27xx_fuel_gauge.c | 64 +++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c index ea1349f..24895cc 100644 --- a/drivers/power/supply/sc27xx_fuel_gauge.c +++ b/drivers/power/supply/sc27xx_fuel_gauge.c @@ -171,10 +171,37 @@ static int sc27xx_fgu_save_boot_mode(struct sc27xx_fgu_data *data, if (ret) return ret; + /* + * Since the user area registers are put on power always-on region, + * then these registers changing time will be a little long. Thus + * here we should delay 200us to wait until values are updated + * successfully according to the datasheet. + */ + udelay(200); + + ret = regmap_update_bits(data->regmap, + data->base + SC27XX_FGU_USER_AREA_SET, + SC27XX_FGU_MODE_AREA_MASK, + boot_mode << SC27XX_FGU_MODE_AREA_SHIFT); + if (ret) + return ret; + + /* + * Since the user area registers are put on power always-on region, + * then these registers changing time will be a little long. Thus + * here we should delay 200us to wait until values are updated + * successfully according to the datasheet. + */ + udelay(200); + + /* + * According to the datasheet, we should set the USER_AREA_CLEAR to 0 to + * make the user area data available, otherwise we can not save the user + * area data. + */ return regmap_update_bits(data->regmap, - data->base + SC27XX_FGU_USER_AREA_SET, - SC27XX_FGU_MODE_AREA_MASK, - boot_mode << SC27XX_FGU_MODE_AREA_SHIFT); + data->base + SC27XX_FGU_USER_AREA_CLEAR, + SC27XX_FGU_MODE_AREA_MASK, 0); } static int sc27xx_fgu_save_last_cap(struct sc27xx_fgu_data *data, int cap) @@ -188,9 +215,36 @@ static int sc27xx_fgu_save_last_cap(struct sc27xx_fgu_data *data, int cap) if (ret) return ret; + /* + * Since the user area registers are put on power always-on region, + * then these registers changing time will be a little long. Thus + * here we should delay 200us to wait until values are updated + * successfully according to the datasheet. + */ + udelay(200); + + ret = regmap_update_bits(data->regmap, + data->base + SC27XX_FGU_USER_AREA_SET, + SC27XX_FGU_CAP_AREA_MASK, cap); + if (ret) + return ret; + + /* + * Since the user area registers are put on power always-on region, + * then these registers changing time will be a little long. Thus + * here we should delay 200us to wait until values are updated + * successfully according to the datasheet. + */ + udelay(200); + + /* + * According to the datasheet, we should set the USER_AREA_CLEAR to 0 to + * make the user area data available, otherwise we can not save the user + * area data. + */ return regmap_update_bits(data->regmap, - data->base + SC27XX_FGU_USER_AREA_SET, - SC27XX_FGU_CAP_AREA_MASK, cap); + data->base + SC27XX_FGU_USER_AREA_CLEAR, + SC27XX_FGU_CAP_AREA_MASK, 0); } static int sc27xx_fgu_read_last_cap(struct sc27xx_fgu_data *data, int *cap)