From patchwork Sun Mar 15 15:11:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Demchenkov X-Patchwork-Id: 212581 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 8D24FC10DCE for ; Sun, 15 Mar 2020 15:14:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 63150206BE for ; Sun, 15 Mar 2020 15:14:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PiC2BcFi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728687AbgCOPOh (ORCPT ); Sun, 15 Mar 2020 11:14:37 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37302 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728658AbgCOPOh (ORCPT ); Sun, 15 Mar 2020 11:14:37 -0400 Received: by mail-wr1-f66.google.com with SMTP id 6so18060836wre.4; Sun, 15 Mar 2020 08:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=05qXy//GL7EBGHN41xTmsALDVVzrAy8aFFqqDu1cw9g=; b=PiC2BcFiqeHwllVFc15FrrV9KZqXDRjERBN69qJQy4b3+ohcCElxGkjr/Mu2c7Ogrz 3yfdP42f1Wlu8MQj4rOV6DYRDLFUTA8n1DjAJ7p4EeATsbkluUt1z2DDJfw89TZ0xIbe ojgoitqbNXhdGsypAwIQrlgbsPS2vRQ7dR+9g4G9C8AK1ywBjGED0fMivuE7C7heVAlV CFpNaIM3Zw/FrulvyNnn5CPpvblRvhulRwZT3zdcp341bZc8+tMu4h+MpAEuPrchrXjW IM9MfltR5ahDrkyqUdrAenj3HHCvpAFIG+Tx6yXoy88mbVeotSwqhn3bjDVqF8Q56aLc ebyQ== 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; bh=05qXy//GL7EBGHN41xTmsALDVVzrAy8aFFqqDu1cw9g=; b=tk8R8XtFoeGkovY+a9T4C79lKxwb+eaeCmGjkXsxu9W64xpA0mZ8gdChcwhMXiR6Vw o8IIwsucjlr6HJbxIbjRy0zOAd1n5aIRbRHLdtFKHYbI99yCCvnRGLY8L603Vo5DoYGq Mwb2vEcB/SQqL3tuojo1EfGMU6tmL3yFhd7R01cP4m+V24qSMf7HtEFb28/mwgROhW0h Vs8HUlMj1tcQpq2u1kxnaNTA2WZXlUUxRiECepb9AIwwRtpxgUP1th/EvVjK57aUCDon qfQPxi2sYApHBww09tWUt9S2zMidWqiswBpLslTeZoDnlU5ZQTo+X04gH6UFBUW8Hj0j crlQ== X-Gm-Message-State: ANhLgQ2OcgSLZev56JGb3pAn+jjo7fPuGvDjeDiRaFo+WCHA0PufMYYw GJYy2+uDMqOzzT5Y7lY6N94z+xlhNc/92Q== X-Google-Smtp-Source: ADFU+vsSj1tTt3gEgBPMl2oio7uHJGBcHx3+s2zeuZgPvvp6JSnFKctxTRC/xSfIVZ+pJgcTC3Et1A== X-Received: by 2002:adf:8165:: with SMTP id 92mr6569995wrm.217.1584285274609; Sun, 15 Mar 2020 08:14:34 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:34 -0700 (PDT) From: Arthur Demchenkov To: Tony Lindgren , Merlijn Wajer , Pavel Machek , sre@kernel.org, linux-pm@vger.kernel.org, linux-omap@vger.kernel.org Cc: Arthur Demchenkov Subject: [PATCH 02/15] power: supply: cpcap-battery: Improve battery full status detection Date: Sun, 15 Mar 2020 18:11:53 +0300 Message-Id: <20200315151206.30909-2-spinal.by@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200315151206.30909-1-spinal.by@gmail.com> References: <20200315151206.30909-1-spinal.by@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org If the battery status is detected as full for the charging current that doesn't exceed 100 mA, it will then be reported as full for charging currents in the range of 100-150 mA. This is needed because charge_current value has a spread. We don't use avg_current here because it can trigger wrong battery full status on charger connected event. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 34a9dbcd1a23..52f03a2662a5 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -406,13 +406,16 @@ static int cpcap_battery_cc_get_avg_current(struct cpcap_battery_ddata *ddata) static bool cpcap_battery_full(struct cpcap_battery_ddata *ddata) { struct cpcap_battery_state_data *state = cpcap_battery_latest(ddata); + static bool is_full; if (state->voltage >= (ddata->config.bat.constant_charge_voltage_max_uv - 18000) && - state->current_ua > -100000) - return true; + state->current_ua > (is_full ? -150000 : -100000)) + is_full = true; + else + is_full = false; - return false; + return is_full; } static bool cpcap_battery_low(struct cpcap_battery_ddata *ddata) From patchwork Sun Mar 15 15:11:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arthur Demchenkov X-Patchwork-Id: 212580 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 B6D78C4CECE for ; Sun, 15 Mar 2020 15:14:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 906EC206EB for ; Sun, 15 Mar 2020 15:14:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cr9RIVOP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728746AbgCOPOk (ORCPT ); Sun, 15 Mar 2020 11:14:40 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44582 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728678AbgCOPOk (ORCPT ); Sun, 15 Mar 2020 11:14:40 -0400 Received: by mail-wr1-f67.google.com with SMTP id y2so2582776wrn.11; Sun, 15 Mar 2020 08:14:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lb85Vsp0xUlVkHp+V++9SA5TEfJMXw1OCLYxxoW6Ha4=; b=cr9RIVOP5EB1gguj9gEVaQgSDQ/aA0weBFNRCuZq2T1b79wbfZr5LHAVD4dXu/RAA0 TJ7SSWMrAIUBB6sSDPPurKOnzdkne5uALRIYiQmfQVvvMx1PvpNXIE9D4aeX/WI8x2fL Er2JnjwBTj1hAHVkoIL7/RgweEPxAccOefAQN0Z20v/k+8Q62udc1zXskOd0GyqlxGxz GIkQdcEjPyDMi0L+1v6TMeHW87Rcd2zei4WKpu2bmrS3uHG+WMoP6tA8c6AW5yy6FPIi belLK7Z0bCajx4sB7mXk81qkO7AFsSsuYkUHQKUbV5H7aRZpbPJIXtEulM8q1kYoKHKI y5YQ== 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:mime-version:content-transfer-encoding; bh=lb85Vsp0xUlVkHp+V++9SA5TEfJMXw1OCLYxxoW6Ha4=; b=pqfWVWFtNJaryk3KVs7AlUzBWF1WBiR8c/ghT5rFishSnd8NHT2Z0WKTf8fWPWR0fR 2+ApAS/XnfuG1FWgBxUdzUW5ApERKnIIp1z21sVVj2AGit8WNkikKAwOqz+I6SZnDmiJ 4/l0BZm3aqq2s4NQ6ylRwlHTwP7ypJhF5NBvdt2lByr2f+ARFbexf/heswFAwUu01yCw UGS9N8Xq8tseRruA+HRc4Gpn1Z64ZzQS/v1kAi37OeHGlIvpiyzxP5UvqUePSzr/gDrB BGMArssO1gBZiCGND9YabCkc/XWurMQsvv8AvCEQNZ3OsU3jB/EjJ1kAkZ4LVSBLoroW YYhw== X-Gm-Message-State: ANhLgQ0pUHCpwFwreM0gpuAhQ7ITxrmZtmQ/3PHeziJXnFeGqTy4njlz /l02sluvzscKHYROP1yqxJ4= X-Google-Smtp-Source: ADFU+vvOXCXQsewsdReWIDsFQYGgiVVJcPj/m6HKcXQ9fGUIMCG6zAzoOph+e4FC5xuQNiEF8W5AmA== X-Received: by 2002:a5d:6aca:: with SMTP id u10mr28706221wrw.99.1584285276876; Sun, 15 Mar 2020 08:14:36 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:36 -0700 (PDT) From: Arthur Demchenkov To: Tony Lindgren , Merlijn Wajer , Pavel Machek , sre@kernel.org, linux-pm@vger.kernel.org, linux-omap@vger.kernel.org Cc: Arthur Demchenkov Subject: [PATCH 04/15] power: supply: cpcap-battery: Add charge_full property Date: Sun, 15 Mar 2020 18:11:55 +0300 Message-Id: <20200315151206.30909-4-spinal.by@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200315151206.30909-1-spinal.by@gmail.com> References: <20200315151206.30909-1-spinal.by@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add charge_full property. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 8a58ad943960..43e39485a617 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -134,6 +134,7 @@ struct cpcap_battery_ddata { struct cpcap_battery_state_data state[CPCAP_BATTERY_STATE_NR]; u32 cc_lsb; /* μAms per LSB */ atomic_t active; + int charge_full; int status; u16 vendor; }; @@ -530,6 +531,7 @@ static enum power_supply_property cpcap_battery_props[] = { POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, POWER_SUPPLY_PROP_CURRENT_AVG, POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, POWER_SUPPLY_PROP_CHARGE_COUNTER, POWER_SUPPLY_PROP_POWER_NOW, @@ -649,6 +651,11 @@ static int cpcap_battery_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CAPACITY_LEVEL: val->intval = cpcap_battery_get_rough_capacity(ddata); break; + case POWER_SUPPLY_PROP_CHARGE_FULL: + if (!ddata->charge_full) + return -ENODATA; + val->intval = ddata->charge_full; + break; case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: val->intval = ddata->config.info.charge_full_design; break; @@ -710,6 +717,15 @@ static int cpcap_battery_set_property(struct power_supply *psy, ddata->config.bat.constant_charge_voltage_max_uv = val->intval; return cpcap_battery_update_charger(ddata, val->intval); + case POWER_SUPPLY_PROP_CHARGE_FULL: + if (val->intval < 0) + return -EINVAL; + if (val->intval > ddata->config.info.charge_full_design) + return -EINVAL; + + ddata->charge_full = val->intval; + + return 0; default: return -EINVAL; } @@ -722,6 +738,7 @@ static int cpcap_battery_property_is_writeable(struct power_supply *psy, { switch (psp) { case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: + case POWER_SUPPLY_PROP_CHARGE_FULL: return 1; default: return 0; From patchwork Sun Mar 15 15:11:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Demchenkov X-Patchwork-Id: 212579 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 E5B86C5ACC0 for ; Sun, 15 Mar 2020 15:14:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF58D2073C for ; Sun, 15 Mar 2020 15:14:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZrLPgwFd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728738AbgCOPOl (ORCPT ); Sun, 15 Mar 2020 11:14:41 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39882 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728745AbgCOPOl (ORCPT ); Sun, 15 Mar 2020 11:14:41 -0400 Received: by mail-wr1-f66.google.com with SMTP id r15so18080809wrx.6; Sun, 15 Mar 2020 08:14:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x/WyZRIq4+b0pwp83cJG0lNJFv0mIkL8qj75+kmAOTc=; b=ZrLPgwFdNJd74irDBRduDCjvW25Jx0CnkV13zS6Uk4duWuv6UQkoTaekN48Gb23eaN rdkYnZPjmhAy12nihMVKDFfifyQNpVtpaRz5OoQ0uC8a4EyjVO6e8+xARSo+vXr9TuuV W2vg6KqnfVzfYIvlb8d0rk+4ddChgJyel6L7p4w9tMdbdGkCsB8as7NMpD9l6StxMp5v 8Ngw2csKd38dtIuYa5urnuyJCUA3eSe+DMP74jjg/TrFswOGB7OANjz7X0NvsS3bY15G OMq4L2e/SgRiGBEszha9qjHfVTbg7BE7OcLvxMLY5ba08pBrgvRwYVbrU8tJQ7iN5ZuR V7DA== 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; bh=x/WyZRIq4+b0pwp83cJG0lNJFv0mIkL8qj75+kmAOTc=; b=EBiVwf7mAwxFEenCuvnJd7nVDawou1ZDUVEpUx+IvUQ6GFWjGtHTZs42dQscaeDAUH iXe2BPFOGXNXxMOBuubSEFjghJ33DGooT8ck6JM3rKwZFjkwQiagNNOWaseZfVMr8lxA F34FM6FG501xbGcQVEfQgtePsRvj0/sYt02tv0nVBOEYz9G8w2trdsI2re4NZWma918w wPrxYTp2epPWBW9iF2UT8pHEVHtRnjw94Glu5KlDBCVLMfG8W+nb/O90qwy7U6mXy3Db H31VexZmCpoC0FY8s8PRLx98IjxNx+h6UaHmmcwmK3l5DkaddMxa1OrJ+FRcLVL2vEiD HL7A== X-Gm-Message-State: ANhLgQ3mYiQaBJl9x74ZPCs4Uq65s0tuzfH978nhfBwezawkBwHmklxZ 6wwV94ovG40hr2lUzsSS2AE= X-Google-Smtp-Source: ADFU+vs09v3JkFbt/v5CIkmn8NyAUmTurKgd6Hng8MJhCWT8/36Ri8LORDMIRYKi0VwSS+egNFO0KQ== X-Received: by 2002:a5d:490e:: with SMTP id x14mr6684953wrq.58.1584285279192; Sun, 15 Mar 2020 08:14:39 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:38 -0700 (PDT) From: Arthur Demchenkov To: Tony Lindgren , Merlijn Wajer , Pavel Machek , sre@kernel.org, linux-pm@vger.kernel.org, linux-omap@vger.kernel.org Cc: Arthur Demchenkov Subject: [PATCH 06/15] power: supply: cpcap-battery: Initialize with user provided data Date: Sun, 15 Mar 2020 18:11:57 +0300 Message-Id: <20200315151206.30909-6-spinal.by@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200315151206.30909-1-spinal.by@gmail.com> References: <20200315151206.30909-1-spinal.by@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org If the user provides us with charge_full value (which it could save in a permanent storage between reboots), initialize low and high counter_uah with calculated values. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 39 +++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index db1b519e87c6..669ed1513201 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -434,7 +434,7 @@ static bool cpcap_battery_low(struct cpcap_battery_ddata *ddata) static int cpcap_battery_update_status(struct cpcap_battery_ddata *ddata) { - struct cpcap_battery_state_data state, *latest, *previous, *tmp; + struct cpcap_battery_state_data state, *latest, *previous, *low, *high; ktime_t now; int error; @@ -464,15 +464,40 @@ static int cpcap_battery_update_status(struct cpcap_battery_ddata *ddata) memcpy(latest, &state, sizeof(*latest)); if (cpcap_battery_full(ddata)) { - tmp = cpcap_battery_get_highest(ddata); + high = cpcap_battery_get_highest(ddata); /* Update highest charge seen? */ - if (latest->counter_uah <= tmp->counter_uah) - memcpy(tmp, latest, sizeof(*tmp)); + if (latest->counter_uah <= high->counter_uah || + !high->voltage) { + memcpy(high, latest, sizeof(*high)); + + low = cpcap_battery_get_lowest(ddata); + if (low->voltage && low->voltage != -1) + ddata->charge_full = + low->counter_uah - high->counter_uah; + else if (ddata->charge_full) { + /* Initialize with user provided data */ + low->counter_uah = + high->counter_uah + ddata->charge_full; + /* Mark it as initialized */ + low->voltage = -1; + } + } } else if (cpcap_battery_low(ddata)) { - tmp = cpcap_battery_get_lowest(ddata); + low = cpcap_battery_get_lowest(ddata); /* Update lowest charge seen? */ - if (latest->counter_uah >= tmp->counter_uah) - memcpy(tmp, latest, sizeof(*tmp)); + if (latest->counter_uah >= low->counter_uah || + !low->voltage) { + memcpy(low, latest, sizeof(*low)); + + high = cpcap_battery_get_highest(ddata); + if (high->voltage) + ddata->charge_full = + low->counter_uah - high->counter_uah; + else if (ddata->charge_full) + /* Initialize with user provided data */ + high->counter_uah = + low->counter_uah - ddata->charge_full; + } } return 0; From patchwork Sun Mar 15 15:12:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Demchenkov X-Patchwork-Id: 212578 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 032F9C2BB1D for ; Sun, 15 Mar 2020 15:14:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF2E8206BE for ; Sun, 15 Mar 2020 15:14:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ePEUSzNM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728776AbgCOPOp (ORCPT ); Sun, 15 Mar 2020 11:14:45 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34318 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728678AbgCOPOp (ORCPT ); Sun, 15 Mar 2020 11:14:45 -0400 Received: by mail-wr1-f66.google.com with SMTP id z15so18051605wrl.1; Sun, 15 Mar 2020 08:14:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ztqdauPgBR6/jJXcC/G4eAbGw7jHbgKj5fkmHyJg9TM=; b=ePEUSzNMcY5d70nvKQ3K/OTrIlZZVKG+mZEFxdQTqlJ2ZsPDq8xz4OAVNZRpqn9fuu OHBCZagBPP3buzt9EhAtKG3GnYDJV5+jPrJGjr5YlP0LenPPJZhxaIB/zlzYTC/TTjHy dRZonpKDnREyiGnEion6Loyfurq4LdGvfI+JlBu47LeLIvbMEpuzYVHw6K+xfKXdPX/c IF6w+479uPEzdJM/E3P3zw9t8GKh6xVtvo5ka+x0oro6GNDOrNnRJBq+yfAZyXK4AAsK yTmjBLD+0OnJ9Rkbc42kRAOjfYZ4K9JCfZ9+FcuPRB+90+6AgycQAWDxNxicK7QIz5uy Xw+Q== 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; bh=ztqdauPgBR6/jJXcC/G4eAbGw7jHbgKj5fkmHyJg9TM=; b=F+/BAjc9jjX2To6KYLHqKGVdCZmmkCbWldtvsEiWLm4+e0gOdFrWoo9m4bbe8Vlj6U YfB1SFuy3CZNJ4kDNdjQxlBy1cXkXJsDk++U/Ak2DRcmteBd65c0Vl/YzVRn1iNy1zWu LsZgSxehlfNpsvB4hxjwVKlLnZ39GqvJ5T+thm7vQUHlifG5Wv+5dLzOxQKo/XBxY4n1 VFy4ec6BytxZzahT+vdTLB1hg5LLivRZwEtyZ6hgahkVc4M6UkGRFUstp5+6F1sPQMqT eEQ8wVzMniP7hfjVAqQz/EWZEkpLFLun44jkXH5FEzyvC7aXvMIKMQFdZeKElP4NqQGM knCg== X-Gm-Message-State: ANhLgQ2ayWW175igyUv3eKkoSUsxYXHCUbEVUbtrZ77zTkNXAajUhxFb n3SY12zCxjERdRCT2BawEbM= X-Google-Smtp-Source: ADFU+vvb3D9ekjFjtfjVelRtkTOOQvYVEtp3zqKRYT1UH6nvLnSQPSKmNJvziiEvJLJLryZ3y0eOmA== X-Received: by 2002:a5d:4cc6:: with SMTP id c6mr29734006wrt.30.1584285282838; Sun, 15 Mar 2020 08:14:42 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:42 -0700 (PDT) From: Arthur Demchenkov To: Tony Lindgren , Merlijn Wajer , Pavel Machek , sre@kernel.org, linux-pm@vger.kernel.org, linux-omap@vger.kernel.org Cc: Arthur Demchenkov Subject: [PATCH 09/15] power: supply: cpcap-battery: Increse low voltage bound Date: Sun, 15 Mar 2020 18:12:00 +0300 Message-Id: <20200315151206.30909-9-spinal.by@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200315151206.30909-1-spinal.by@gmail.com> References: <20200315151206.30909-1-spinal.by@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Thus, the user will have more time to start charging when calibrating the charge_full value. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 2f4c6669c37d..da6138df2117 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -422,7 +422,7 @@ static bool cpcap_battery_low(struct cpcap_battery_ddata *ddata) struct cpcap_battery_state_data *state = cpcap_battery_latest(ddata); static bool is_low; - if (state->current_ua > 0 && (state->voltage <= 3300000 || is_low)) + if (state->current_ua > 0 && (state->voltage <= 3350000 || is_low)) is_low = true; else is_low = false; From patchwork Sun Mar 15 15:12:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Demchenkov X-Patchwork-Id: 212577 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 EA483C5ACC0 for ; Sun, 15 Mar 2020 15:14:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C38CC206BE for ; Sun, 15 Mar 2020 15:14:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z50RIKP1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728780AbgCOPOq (ORCPT ); Sun, 15 Mar 2020 11:14:46 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46961 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728745AbgCOPOq (ORCPT ); Sun, 15 Mar 2020 11:14:46 -0400 Received: by mail-wr1-f65.google.com with SMTP id w16so1638017wrv.13; Sun, 15 Mar 2020 08:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=I6wXAlJbWmH6uTZMni2idP4m1tsWk4quBIdgxNLZSbM=; b=Z50RIKP1iXqzNSYIITq4BMB+5uKGR3lvTTHqorU1KIkxaRXFxkwRuC1oh+llcvP+Yo 4sES990ZN1hHkjpT1Dg1asTQsBO8L8vqwlQO37Arp+I3KoOcWe7TNTwnFmFz9JgRnAKt He3ze8DMnALdhgalRGSXpE3atKdy5Ye37PjT0HaUWAJJX1xJ9uDvysOzxfFydZ8Zz2RU 1gbUGVMgBKdyUN9RhNeHiyFo7oc656X7gTSdTHN/dxUzEcSczrhves06WPApQi06gZRc txJuCmYFdtt2HH0aX5wiaN3MR1J8OF7cdgJvt7iP1nz6UynIL1h1iUkFseLRM2ALYg/N NoPQ== 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; bh=I6wXAlJbWmH6uTZMni2idP4m1tsWk4quBIdgxNLZSbM=; b=fSamb8bqjtlTU31vGbEAnhi2LnJN0IKkZd32ukwAPHdKATC0PU1k+O1hQT/bhBUjmR pyK1RsRz0EZUtFE6V9NadAcQ4rmLEqUwl6IYSmfHLtoTNr8INoj8uAjjg/RCJAxoZ+Jl ZtAz8X2GY5DYll34MjgeEDLPzkOvtXAWIKECCaOnDb4g2C86nrPRXTyUCgGJMHpRnDPn EPsww0tXe9vtxAOFY/6W7i7jNFE284iU4T/y3I36zWsKvixNxvoYQmAarxPZs5U/oAMq 9fSME0HpoPgV879yW3GH+qd/CEWV+jNqponrnOTMYlhJq/uNl1KXJqNDcOh9fZN3205p vziw== X-Gm-Message-State: ANhLgQ0ICoak96fUuwRvfa1bP2P7pGfOvZO6bbRjQ23mYuSPW/J25TM8 FvHx5slZPabmbbOgPjBOleY= X-Google-Smtp-Source: ADFU+vv+GLi0Ojit+1OnNLAprCPxACmAocFiko3TYXnjq+nd5PVcdlJrYmcqACcZXKyBWIjEz6gMeA== X-Received: by 2002:a5d:4682:: with SMTP id u2mr13868401wrq.399.1584285283969; Sun, 15 Mar 2020 08:14:43 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:43 -0700 (PDT) From: Arthur Demchenkov To: Tony Lindgren , Merlijn Wajer , Pavel Machek , sre@kernel.org, linux-pm@vger.kernel.org, linux-omap@vger.kernel.org Cc: Arthur Demchenkov Subject: [PATCH 10/15] power: supply: cpcap-battery: Improve full status reporting Date: Sun, 15 Mar 2020 18:12:01 +0300 Message-Id: <20200315151206.30909-10-spinal.by@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200315151206.30909-1-spinal.by@gmail.com> References: <20200315151206.30909-1-spinal.by@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use average current when detecting the fully charged state Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index da6138df2117..6205a5e43a32 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -407,12 +407,16 @@ static bool cpcap_battery_full(struct cpcap_battery_ddata *ddata) struct cpcap_battery_state_data *state = cpcap_battery_latest(ddata); static bool is_full; - if (state->voltage >= - (ddata->config.bat.constant_charge_voltage_max_uv - 18000) && - state->current_ua > (is_full ? -150000 : -100000)) - is_full = true; - else + if (state->voltage < + (ddata->config.bat.constant_charge_voltage_max_uv - 18000)) { is_full = false; + } else if (is_full) { + if (state->current_ua < -150000) + is_full = false; + } else if (state->current_ua >= -150000 && + cpcap_battery_cc_get_avg_current(ddata) >= -100000) { + is_full = true; + } return is_full; } From patchwork Sun Mar 15 15:12:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Demchenkov X-Patchwork-Id: 212576 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 6AEA4C5ACC1 for ; Sun, 15 Mar 2020 15:14:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43918206B1 for ; Sun, 15 Mar 2020 15:14:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dV3MGRtd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728786AbgCOPOs (ORCPT ); Sun, 15 Mar 2020 11:14:48 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:33259 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728678AbgCOPOs (ORCPT ); Sun, 15 Mar 2020 11:14:48 -0400 Received: by mail-wm1-f67.google.com with SMTP id r7so11459200wmg.0; Sun, 15 Mar 2020 08:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LGa9XEWZMhEoDRa47mK7TK3lt95mt5tdXrfwlGeJG80=; b=dV3MGRtdBX7aV53hQXzH3oSrN/MU+PyFfA2h5sOYUy/Uh/dAn5U6pICCNIF9oZIkMz VWnn2UEUgO4sdyrr01upGHO/V+9O9Cw5+pwgRc0ngxEzJxHXYELExIGkIoJ0i5fp4SOO m31KUhiBjkO/jLbgjfmBTf/jiJ6Krn367nZeR4xVqpgnli/6Z2cwmka3DSTfwk2AQRvs FTXqH3DzyMG4ulfqSquUlc5P6HPGzJhNu0sz62Y++aTsiV1hydoCQ2l4xYhiS3x8QqHL PpLlvW2igZwTxSEPQdihDGVaz7tWs8ZccSCWXq1IXTJhSx8LHrTnwl9P6YBrnP7stgD3 DhCQ== 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; bh=LGa9XEWZMhEoDRa47mK7TK3lt95mt5tdXrfwlGeJG80=; b=dE9gaQmw1sGNz54zm0CnvkSN3WoeBb24taBXT45KIJl5uVY1YB4iEr4xZ3LHIa72N7 uknuqrHV5ELc/YuC77tmMEtrHwAAap7Xi5Rb7GCI0zBWrVBOERSncZ+QO7z1PZrelb8n TWRkWjbH+TwNJ/mPJc1j/53AOA1weTAyk48KxpNoKVyGpb62d9IKRUY/sLr6UjvfJp4Q FJj/Sez5Hlk3wFUzZZfgarJihhtc06b3rbwxcfjmdPMqSiSGZ1i/6/YJKTpHSY9o51AI NWGpNiq9eynL/YsHRQj714U1B0YWuX+eMahsylVrto5nRlG5Co+wnKezZt+dfxwNM212 gsow== X-Gm-Message-State: ANhLgQ1d8UQtS5o5Vdi/Rl6Q/gyfbrelnvR6tUJtrrEDVicxTDjS4r4g Biw7rYeiDmVNFGBN/MgShnQ= X-Google-Smtp-Source: ADFU+vtFLZjnsh5uhh0CF57nC0sQeFklQRD/6ueYBTaTtlvakrexgUWnHCfv+pwL9r05kQsGiegl6Q== X-Received: by 2002:a1c:2e4d:: with SMTP id u74mr8833448wmu.89.1584285286473; Sun, 15 Mar 2020 08:14:46 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:45 -0700 (PDT) From: Arthur Demchenkov To: Tony Lindgren , Merlijn Wajer , Pavel Machek , sre@kernel.org, linux-pm@vger.kernel.org, linux-omap@vger.kernel.org Cc: Arthur Demchenkov Subject: [PATCH 12/15] power: supply: cpcap-battery: stabilize charge_full value Date: Sun, 15 Mar 2020 18:12:03 +0300 Message-Id: <20200315151206.30909-12-spinal.by@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200315151206.30909-1-spinal.by@gmail.com> References: <20200315151206.30909-1-spinal.by@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org It will not grow after the battery met "fully charged" state. This is needed because of how constant voltage charging works. If we want "fully charged" state to be reported in a user expected manner we are forced to do it when the charging current is low enough, but not a zero value. So, we report "battery full" when the charging current is as low as 100 mA. But the actual charging continues until the user disconnects the charger. It means that a few mAh will be added to the reported charge_full value, which the user shouldn't see. With that purpose we clamp the charge_now value to not exceed charge_full. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 66ea1a718e02..517acdfa6009 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -469,15 +469,15 @@ static int cpcap_battery_update_status(struct cpcap_battery_ddata *ddata) if (cpcap_battery_full(ddata)) { full = cpcap_battery_get_full(ddata); /* Update full state value? */ - if (latest->counter_uah <= full->counter_uah || - !full->voltage) { + if (!full->voltage) { memcpy(full, latest, sizeof(*full)); empty = cpcap_battery_get_empty(ddata); - if (empty->voltage && empty->voltage != -1) + if (empty->voltage) { ddata->charge_full = empty->counter_uah - full->counter_uah; - else if (ddata->charge_full) { + empty->voltage = -1; + } else if (ddata->charge_full) { /* Initialize with user provided data */ empty->counter_uah = full->counter_uah + ddata->charge_full; @@ -488,18 +488,15 @@ static int cpcap_battery_update_status(struct cpcap_battery_ddata *ddata) } else if (cpcap_battery_low(ddata)) { empty = cpcap_battery_get_empty(ddata); /* Update empty state value? */ - if (latest->counter_uah >= empty->counter_uah || - !empty->voltage) { + if (!empty->voltage || empty->voltage == -1) { memcpy(empty, latest, sizeof(*empty)); full = cpcap_battery_get_full(ddata); - if (full->voltage) + if (full->voltage) { ddata->charge_full = empty->counter_uah - full->counter_uah; - else if (ddata->charge_full) - /* Initialize with user provided data */ - full->counter_uah = - empty->counter_uah - ddata->charge_full; + full->voltage = 0; + } } } @@ -638,9 +635,9 @@ static int cpcap_battery_get_property(struct power_supply *psy, empty = cpcap_battery_get_empty(ddata); if (!empty->voltage || !ddata->charge_full) return -ENODATA; - val->intval = (empty->counter_uah - - latest->counter_uah) * 100; - val->intval /= ddata->charge_full; + val->intval = empty->counter_uah - latest->counter_uah; + val->intval = clamp(val->intval, 0, ddata->charge_full); + val->intval = val->intval * 100 / ddata->charge_full; break; case POWER_SUPPLY_PROP_CAPACITY_LEVEL: val->intval = cpcap_battery_get_capacity_level(ddata); @@ -650,6 +647,10 @@ static int cpcap_battery_get_property(struct power_supply *psy, if (!empty->voltage) return -ENODATA; val->intval = empty->counter_uah - latest->counter_uah; + if (val->intval < 0) + val->intval = 0; + else if (ddata->charge_full && ddata->charge_full < val->intval) + val->intval = ddata->charge_full; break; case POWER_SUPPLY_PROP_CHARGE_FULL: if (!ddata->charge_full) From patchwork Sun Mar 15 15:12:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Demchenkov X-Patchwork-Id: 212575 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 BC9CCC10DCE for ; Sun, 15 Mar 2020 15:14:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9556A20663 for ; Sun, 15 Mar 2020 15:14:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XV1kVB5I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728793AbgCOPOx (ORCPT ); Sun, 15 Mar 2020 11:14:53 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50947 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728665AbgCOPOw (ORCPT ); Sun, 15 Mar 2020 11:14:52 -0400 Received: by mail-wm1-f68.google.com with SMTP id a5so14921907wmb.0; Sun, 15 Mar 2020 08:14:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KTmBMMe4KbD8WN5NJMbIUdKcNvEYuvy6jdxWIP8QH9U=; b=XV1kVB5ILnqZP9cflLPsvoZwjvOlv383myLoyryJCL7zMMDuIRYJmlNKt1j61jWb+F VljtuQaxFvUmC704l8r8QB84O25OScRUuhLNu6U5yyQo3k2oXubwkzjFgtPYjPtrDZxN +w6zf+1ea8BmbwUsID9Uz3Lh73+OVd7agesR9viTS5qnknIC37y8H40/ez0PQ+aFpB6O 3XH9X5L6KVMhIvnx00WaW00E2o2IGSvm+UZhYY2RKcmH/NuL0qEt61MGbdb21JuTMKOY jxUlYx5ktSDy9/bRByoBwIc6Pfv8458EGCkGIE1IDVo4enaRonGcYGv67fEh6+JwJ8xo PxpQ== 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; bh=KTmBMMe4KbD8WN5NJMbIUdKcNvEYuvy6jdxWIP8QH9U=; b=epxZ4CRQFSVd+j2tjDrhrvLZy/o+hoAr5Ze0pYRu6CAQtb6TBNPHZkFvBOfxZlbVt3 gC/CYAfPNHHffzdPLuyRy4wwBdi73RMJTUIC9r72EmpEn4fwhQCBYeDlJ7lSEDpVtg2S Ihp8iq1nbSm0iMVw4EAtLg0Snrfg9G5Qk8uSzofPzZH/rGZCC2E0BEeQb66AsefcTeum P68dNKb2tMB5xOF65D+qnk5o2PBY3vE7aicPfxT4wRqUTE8pcaxE47iw29TYqrSfk2HG 0Egij269EYRG27xWTdcDYhoduETekIiHkpOddzMyzdsdD39spW9/Ud9kqSi63iVEosek 49ew== X-Gm-Message-State: ANhLgQ3MrRCl5rAI5UM7f4KIphfUAmDj6jBv0atOdw6vvOXyuu92Tems /J/hPEYtz4CXHGPX1oQ51v8= X-Google-Smtp-Source: ADFU+vtlldQZUUaRXlo4mMqCnDaHgDok7CohEmMvGdHPuEc33x2Q5LarXEZk6egs47ZwUH+winnFkg== X-Received: by 2002:a1c:80d3:: with SMTP id b202mr8231655wmd.16.1584285288830; Sun, 15 Mar 2020 08:14:48 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:48 -0700 (PDT) From: Arthur Demchenkov To: Tony Lindgren , Merlijn Wajer , Pavel Machek , sre@kernel.org, linux-pm@vger.kernel.org, linux-omap@vger.kernel.org Cc: Arthur Demchenkov Subject: [PATCH 14/15] power: supply: cpcap-battery: Make it behave like bq27200 Date: Sun, 15 Mar 2020 18:12:05 +0300 Message-Id: <20200315151206.30909-14-spinal.by@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200315151206.30909-1-spinal.by@gmail.com> References: <20200315151206.30909-1-spinal.by@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Now we begin to update the charge_now value immediately after connecting or disconnecting the charger. No more hidden mAh buffer when the battery is fully charged or discharged. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 44 +++++++++++++++--------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 938117638983..4e872bd36ccf 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -468,35 +468,27 @@ static int cpcap_battery_update_status(struct cpcap_battery_ddata *ddata) if (cpcap_battery_full(ddata)) { full = cpcap_battery_get_full(ddata); - /* Update full state value? */ - if (!full->voltage) { - memcpy(full, latest, sizeof(*full)); - - empty = cpcap_battery_get_empty(ddata); - if (empty->voltage) { - ddata->charge_full = - empty->counter_uah - full->counter_uah; - empty->voltage = -1; - } else if (ddata->charge_full) { - /* Initialize with user provided data */ - empty->counter_uah = - full->counter_uah + ddata->charge_full; - /* Mark it as initialized */ - empty->voltage = -1; - } + memcpy(full, latest, sizeof(*full)); + + empty = cpcap_battery_get_empty(ddata); + if (empty->voltage && empty->voltage != -1) { + empty->voltage = -1; + ddata->charge_full = + empty->counter_uah - full->counter_uah; + } else if (ddata->charge_full) { + empty->voltage = -1; + empty->counter_uah = + full->counter_uah + ddata->charge_full; } } else if (cpcap_battery_low(ddata)) { empty = cpcap_battery_get_empty(ddata); - /* Update empty state value? */ - if (!empty->voltage || empty->voltage == -1) { - memcpy(empty, latest, sizeof(*empty)); - - full = cpcap_battery_get_full(ddata); - if (full->voltage) { - ddata->charge_full = - empty->counter_uah - full->counter_uah; - full->voltage = 0; - } + memcpy(empty, latest, sizeof(*empty)); + + full = cpcap_battery_get_full(ddata); + if (full->voltage) { + full->voltage = 0; + ddata->charge_full = + empty->counter_uah - full->counter_uah; } }