From patchwork Sun Mar 15 15:11:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Arthur D." X-Patchwork-Id: 11439163 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 143DE14E5 for ; Sun, 15 Mar 2020 15:14:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DEBA720578 for ; Sun, 15 Mar 2020 15:14:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VAXmvyDi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728671AbgCOPO2 (ORCPT ); Sun, 15 Mar 2020 11:14:28 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43224 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728658AbgCOPO2 (ORCPT ); Sun, 15 Mar 2020 11:14:28 -0400 Received: by mail-wr1-f66.google.com with SMTP id b2so11826674wrj.10; Sun, 15 Mar 2020 08:14:25 -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; bh=MCtPpHnUbydv9gcw0m5qsMshS01Auq8Za00j3T9ln10=; b=VAXmvyDi77W2Q1ICz57RRn9OooContTpvFuwFXdLyFsV+gH/8nfbTsBQk7QXuxdpMR g37LQlcZxxX/BhGbFezAmOpwcfC8E52sks00cHKgzVUs+ZK+AskMGiG/9w4Ha80Y9NBn dRlHRBjozyrWIZvNG+rWU5joHdfFuEElYNPy9hS5Zi885twQ3MPSZaXF1vuu7wDSfYdX 7tUBd6bIuiAgzfkQSBe4JwnV7wvrBHHhaz3/hYQCpnFiTsb+k2Ol3MUzz0tO6VtcmGFG kcPZ85x0JkbY4aEFBmsMcZMrcZtBaN6awgWR8AxKJKQ//tYVxT25/exqWyuA5kmsUXIg 3cZg== 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=MCtPpHnUbydv9gcw0m5qsMshS01Auq8Za00j3T9ln10=; b=OwvkG/T46q5DdELwuaPEvT9PIxczy9byThexqd4A+gqLC6v8b7GZW49eu4/UJoqIaU 2tUgWx/x3bmh4hUHvPUu04UxZa2btbqbSB80OeMoQtogkpGBFYVAVDCocqRZS0s18u8C /1/UqKza5J5ichjJsrdX5eCh3FLe37Au14oeBFGPbpxQB4qHQc/27auAnJwmQrX2cAIz TNvpWJ3N9zV9DgBwJxu44VeeOIQJjrUcjpdISm+P7qk4VjCoP4M7/H0ZgXH7kX7qru/8 jZypWN5Q2wLy4bRC3h+omkPG6j76DNex0pWJWfHvbBXv2yPFYV8uFciQfVa4YmJ2rjOL 10Fw== X-Gm-Message-State: ANhLgQ2cPYoaaz17+Nnw8du9Ie0lhM7OqfxVsrt0y6x7DMzSJ0OZxF+b CVUppE/GdsHxBx83jsNHQAR2tq3mTKUbVw== X-Google-Smtp-Source: ADFU+vsvRZlztZYro9pFbHgdix1uzOzFmaeWXNUe0McqWXPLmj5Srb0UbuHH+HUXfxTELoEWuq5Rqw== X-Received: by 2002:a5d:498b:: with SMTP id r11mr5109680wrq.368.1584285265069; Sun, 15 Mar 2020 08:14:25 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:24 -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 01/15] power: supply: cpcap-battery: Fix battery full status reporting Date: Sun, 15 Mar 2020 18:11:52 +0300 Message-Id: <20200315151206.30909-1-spinal.by@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Don't report that the battery is fully charged if the charging current exceeds 100 mA. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index d7b3234ec264..34a9dbcd1a23 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -408,7 +408,8 @@ static bool cpcap_battery_full(struct cpcap_battery_ddata *ddata) struct cpcap_battery_state_data *state = cpcap_battery_latest(ddata); if (state->voltage >= - (ddata->config.bat.constant_charge_voltage_max_uv - 18000)) + (ddata->config.bat.constant_charge_voltage_max_uv - 18000) && + state->current_ua > -100000) return true; return false; 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 D." X-Patchwork-Id: 11439167 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E129714B4 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 BD7AF20739 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:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Arthur D." X-Patchwork-Id: 11439173 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 68CA014E5 for ; Sun, 15 Mar 2020 15:14:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4864A20663 for ; Sun, 15 Mar 2020 15:14:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R3+gKzwK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728730AbgCOPOi (ORCPT ); Sun, 15 Mar 2020 11:14:38 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35621 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728678AbgCOPOh (ORCPT ); Sun, 15 Mar 2020 11:14:37 -0400 Received: by mail-wr1-f65.google.com with SMTP id d5so17741879wrc.2; Sun, 15 Mar 2020 08:14:36 -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=Kd7pvZkdhxqfRhkmXixEY9mGa6jMzVWdflnEm/bgK9Q=; b=R3+gKzwKuIigXkPbp2TuGXz2LSZ0TUoFUb0Dd+JOTx+fkQgRpjEG4tCzbdzLJZE5UO 9PaWZwsKkeV0/SAexS5nKq05noDaibO3UboEdCBWPz5r9NFbJuDGpTFXXDKj34OMVoKV uZ7QYdArNbgODVggqcSDZIvX1xy0CNpRYm+XYV0AM3vq5rUCzZSklPZu9f1wokSXz8mj l27Lky2d3LshlHgo5c4fyz5nP3KKtcDzBaTI+oTdnTpV5bkseZYa1XClSsk8yBemzar+ LLDyfkQR2QJUTiyKecl7tJcGV1/d/+YcflwovQBMI0A2CU3roci3f9NQwYrDthvGVGZc WYjw== 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=Kd7pvZkdhxqfRhkmXixEY9mGa6jMzVWdflnEm/bgK9Q=; b=IV5R5ZC4FfyRhk52bvFvdXPmHwbm5xEIwuN4pnrXpzTUS/qYmoghbTHcr1sbMAXvOH xmlOsLzJbGuJUWGPsriM/kenhongIl0eEFzhUNn68xKHFeEG2JRO63fg1V/uZHcvS2fm NUkv6/9GxtQGLgT0mREQXAX9+81oAMfGI0dXflXaE52iYvyENBH0KiNu6D8HuxHoIu9e LNmToc+PAOy/a9Z6Px4ReP3pdlTcpuWCL+lRQhqFtqvYEd6AKGxtoobEGhaJk2xaqP4k M36ZKvJjZYDAxObswpY4tqo74MIHvv04ljyaaashOLgGtA8w0RuATkBdkDRJ0e14ciJC xlmA== X-Gm-Message-State: ANhLgQ0bfDnyWJKY/sam6TjyrZ6Yyjh22EY/K+WzgvDfHxZbwL5aPwWz shZWsjG5hz0ML3ipN9QJuzo= X-Google-Smtp-Source: ADFU+vs/FiZYdm4c+CV3Ph+UKXhDch+CPOehl/ViKihfr+y13UTRxv3auMAg/LCtMyU/Azet7fbDCA== X-Received: by 2002:a5d:5710:: with SMTP id a16mr31269869wrv.5.1584285275739; Sun, 15 Mar 2020 08:14:35 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:35 -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 03/15] power: supply: cpcap-battery: Fix battery low status reporting Date: Sun, 15 Mar 2020 18:11:54 +0300 Message-Id: <20200315151206.30909-3-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 we hit battery low once, we should stick on reporting it until the charger is connected. This way low->counter_uah will be updated properly, and that will allow us to get more accurate charge_full value. 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 52f03a2662a5..8a58ad943960 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -421,11 +421,14 @@ static bool cpcap_battery_full(struct cpcap_battery_ddata *ddata) 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 && state->voltage <= 3300000) - return true; + if (state->current_ua > 0 && (state->voltage <= 3300000 || is_low)) + is_low = true; + else + is_low = false; - return false; + return is_low; } static int cpcap_battery_update_status(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 D." X-Patchwork-Id: 11439177 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2720159A 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 D1E24206BE 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:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Arthur D." X-Patchwork-Id: 11439179 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A3DA14B4 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 09E57206BE 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="NxHtwUAv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728764AbgCOPOl (ORCPT ); Sun, 15 Mar 2020 11:14:41 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42263 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728738AbgCOPOl (ORCPT ); Sun, 15 Mar 2020 11:14:41 -0400 Received: by mail-wr1-f65.google.com with SMTP id v11so18078756wrm.9; Sun, 15 Mar 2020 08:14:38 -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=Szi3g7vWC5eovfWdznQDDs/l63PuCiAXPnlfpsPCp9k=; b=NxHtwUAv5sVwIHTKzLvr3hMJa+t/g+wNKgxYVHhZRSOExE3JjxUBfGNwmJ0qdd5+Vx ckgongkUVeLENSAZ3kXZLr5wrYqgsfVJfGCiw3KVBUn5Vu1yY5r7faIg0YdF8efA93p2 ogxPnKO4EelGqkJSr3spqt5uFzfp/Rud+sGdEgfrMuY+yIQ4zRkO+WJH6g0d3xSyg/Qo LSuKzfl84X7ViHVUGVIp+va/PBKoheqsIlPFrSlJpz+U3dt+Qo/vhcrqNZ5YxXWQCJJV TD7HLUGY0M16ZD6FpECneH2LuK5wHyUb+KFwpXKtQ79dUsvCUZw7077kdGlM0tz7P4S2 hHOw== 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=Szi3g7vWC5eovfWdznQDDs/l63PuCiAXPnlfpsPCp9k=; b=f4i348iis0GHpwjyY1gVYSmwFKKXY0bv56bBflu2g6mHY3/04aLO4PHmARCx3aZP0l vX5BrOiuEKOuf6sBgE8iRJLs/GJRHGkqszd6bOvVMkseAW19GGeUAsUq0yoN0BsGFrh3 sgSLi+1gELl0CTxVKlOxuk0gdakz0WvjxxY0OBZbL1dvLtbq3sdZN1TpQp3QbqbHaWqw 9LuYQH1Vxg2I9hGW80OLF8YzukoXtYIx/WYee8Uo86Ge6iq1bWtqHhpnVjwZfovkI4cZ ZPMiOORnPnaCyfmWErFVArSde9lbSkoRlvbmCiXTK4hkcQv/cyT5cIooMb2IZrCBr87v hxaQ== X-Gm-Message-State: ANhLgQ1CyB5/dZAo9ySLQ4bEGbT7Zz2XEyluJlsXhVcxVbfseUsqHDh0 jUofVR000V1cqh/geTq4De8= X-Google-Smtp-Source: ADFU+vsK1r0R32+VHrtus+wpgVaP+Lp8cLkCk3Z58IJoroB0mkZ1HTbTZjXvlky+gvAxL1tHtlZGlw== X-Received: by 2002:adf:eed2:: with SMTP id a18mr30330784wrp.59.1584285278008; Sun, 15 Mar 2020 08:14:38 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:37 -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 05/15] power: supply: cpcap-battery: Add charge_now property Date: Sun, 15 Mar 2020 18:11:56 +0300 Message-Id: <20200315151206.30909-5-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 Add charge_now property. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 43e39485a617..db1b519e87c6 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -532,6 +532,7 @@ static enum power_supply_property cpcap_battery_props[] = { POWER_SUPPLY_PROP_CURRENT_AVG, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_CHARGE_FULL, + POWER_SUPPLY_PROP_CHARGE_NOW, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, POWER_SUPPLY_PROP_CHARGE_COUNTER, POWER_SUPPLY_PROP_POWER_NOW, @@ -651,6 +652,12 @@ 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_NOW: + low = cpcap_battery_get_lowest(ddata); + if (!low->voltage) + return -ENODATA; + val->intval = low->counter_uah - latest->counter_uah; + break; case POWER_SUPPLY_PROP_CHARGE_FULL: if (!ddata->charge_full) return -ENODATA; 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 D." X-Patchwork-Id: 11439183 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23DEE14E5 for ; Sun, 15 Mar 2020 15:14:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 03BBB206B1 for ; Sun, 15 Mar 2020 15:14:43 +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:11:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Arthur D." X-Patchwork-Id: 11439187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8245A14B4 for ; Sun, 15 Mar 2020 15:14:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5852B20663 for ; Sun, 15 Mar 2020 15:14:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gOdMIEdc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728769AbgCOPOm (ORCPT ); Sun, 15 Mar 2020 11:14:42 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42269 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728678AbgCOPOm (ORCPT ); Sun, 15 Mar 2020 11:14:42 -0400 Received: by mail-wr1-f68.google.com with SMTP id v11so18078850wrm.9; Sun, 15 Mar 2020 08:14:41 -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=XdkapQL+yBOybxGhePAhyn5C5HK16exdBokBiPplJoM=; b=gOdMIEdcRD6QOopL0Afs77sac4j9vlxRA9ihE7AHZF/iGfnsBPDNhlm2Imxm/msA80 kjp8L2k7gIVg4oT5iZkEkIWJPzE5yTtCPYSB3YncdBiAn7qPWUoIpihiLRvd76eXIdiv 6P2Opotuuw0+hVgPjIUXjN3piSOmWduW/yKG1KR27qX8Enm3MCYHtETWFTufhu8B5n// eZQtRxVm2vjUZmH9js9/eqxlbJwRbDfzDUVy7FS6GbNC5PGqKy7oNGDVico4AI/Rltif kgrEZPKhP866u94Nw8vMNLh1UIlv3JQgiTF3KjnbB7uEwXH0KZta5mzoZnrcRYxLMoOL pPag== 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=XdkapQL+yBOybxGhePAhyn5C5HK16exdBokBiPplJoM=; b=fSvT0PxI+JGeWI6VpNft06SBpewZJ+3uPwwgx3UWzYrdHbBQO1fFE6kgXsuqyKzdat g1aHK3dQfffug6/YsnpVEBbMt79DLsieBr/DyCQwtD3lcuhpt3fLQgaDJTK5xv69Svit xveGrwdT4Aksn6smqRkiERD2ZubGsxyC/+BUuWMWNFsuXD2fLjOUgjYpjOC6ieOlM8rP 5c4qxyxRVZ8Enqu0lS6RX9mstYpx9ZdnAPYE+OEGvcyft8vaNH/e8uWosyaol/89Px1y xw6kzpE5KB/A97xp6qipiH7EW4exBygLYbndtvrcqyKX0lUlOq9XqM/KcZRqNA9pikAL SQoQ== X-Gm-Message-State: ANhLgQ3CZV5Ba6eoKxQIo4L1YQcQp0IcUXAr8CGX5/cXLzm0GuF2L5ja TvA7zSRrYE3XBcFmaB4WH8I= X-Google-Smtp-Source: ADFU+vulIJLGWZsnPgFBLWyFsQK9ORzdCgo4lIzw5GzDG5Mc3K5LOM+cWr9z04wXjDiJyPVe22ZFrA== X-Received: by 2002:a5d:5545:: with SMTP id g5mr13929668wrw.290.1584285280336; Sun, 15 Mar 2020 08:14:40 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:39 -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 07/15] power: supply: cpcap-battery: Rewrite capacity reporting Date: Sun, 15 Mar 2020 18:11:58 +0300 Message-Id: <20200315151206.30909-7-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 * Return -ENODATA instead of confusing rough values * Calculate percentage using charge_full value provided Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 669ed1513201..f712a3bda315 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -573,10 +573,10 @@ static int cpcap_battery_get_property(struct power_supply *psy, union power_supply_propval *val) { struct cpcap_battery_ddata *ddata = power_supply_get_drvdata(psy); - struct cpcap_battery_state_data *latest, *previous, *low, *high; + struct cpcap_battery_state_data *latest, *previous, *low; u32 sample; s32 accumulator; - int cached, delta, est; + int cached; s64 tmp; cached = cpcap_battery_update_status(ddata); @@ -654,25 +654,12 @@ static int cpcap_battery_get_property(struct power_supply *psy, val->intval = div64_s64(tmp, 100); break; case POWER_SUPPLY_PROP_CAPACITY: - est = cpcap_battery_get_rough_percentage(ddata); - high = cpcap_battery_get_highest(ddata); - if (high->voltage) { - delta = latest->counter_uah - high->counter_uah; - val->intval = (ddata->config.info.charge_full_design - - delta) * 100; - val->intval /= ddata->config.info.charge_full_design; - delta = abs(val->intval - est); - break; - } low = cpcap_battery_get_lowest(ddata); - if (low->voltage) { - delta = low->counter_uah - latest->counter_uah; - val->intval = (delta * 100) / - ddata->config.info.charge_full_design; - delta = abs(val->intval - est); - break; - } - val->intval = est; + if (!low->voltage || !ddata->charge_full) + return -ENODATA; + val->intval = (low->counter_uah - + latest->counter_uah) * 100; + val->intval /= ddata->charge_full; break; case POWER_SUPPLY_PROP_CAPACITY_LEVEL: val->intval = cpcap_battery_get_rough_capacity(ddata); From patchwork Sun Mar 15 15:11:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Arthur D." X-Patchwork-Id: 11439191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53E1C14B4 for ; Sun, 15 Mar 2020 15:14:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3344320663 for ; Sun, 15 Mar 2020 15:14:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l9/1t307" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728773AbgCOPOn (ORCPT ); Sun, 15 Mar 2020 11:14:43 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41620 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728745AbgCOPOn (ORCPT ); Sun, 15 Mar 2020 11:14:43 -0400 Received: by mail-wr1-f68.google.com with SMTP id f11so1284769wrp.8; Sun, 15 Mar 2020 08:14:42 -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=Nw9EpIfztqsWhJ/JuEKjzVHKAstJZGt97qEhfNdT50k=; b=l9/1t3072/UUbHY49oThk6ocSHP6SXo9e29Yd0jL96PHiEjmdTTet05ZjlmCDpZpcl hazic516JrOuFJxg4Yrx3U3eth2E0WGnYdX6H98KJhkdvlablAFz/UpC66L2wKaQjZEg L8hzBuBVOXdAz5jX+MMASZRmlcJJtZ+oQ8bBbWBBbIvLDw1QO7iCzDw6iYPZtHJ7xBU/ 7ho1dEV7Bdcp7w71R7fzKEerV9uejhE3iFt5nht5CIb/pMeDy/JYeYrgRHPIchluaTzK nvZbM5YrsOjxX7h2u55wzBJ86yBhdbMvAvr3O+QRiuBIpjknMt8hYiNuN6AijFv5kA5N qqGQ== 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=Nw9EpIfztqsWhJ/JuEKjzVHKAstJZGt97qEhfNdT50k=; b=n4IGQryH/ZNCjxjISgr2Il4X/j6KYrr0PZqoAY90ZII8KZ2Cxc99kmddujH0Rl64o9 6DSZwnM7TL0wxYL9KshB7Lo8IxqLG/T1kaqdQj4cEmqDkYUIl73pCFYZCiPN+WWsKN7f vPThMfenqbVjSCP3MauOSTOmlBWFgOciUYNdOArOsKgwfoFHPb72uoBD/gguq3TH1yOL MdNLw5aQRmlIzMnNuTDbzDNGNWwEeLTbVWygIRbdXXLikgNV52gXezDnrzTitkAqzghB aWY13nV6rzAgnbMCaZTeJg6inueZMn1G9TUUjN48bn/KmMH10K112UFhbsVOvy/v5mzY KHhw== X-Gm-Message-State: ANhLgQ0oHOYgWj9cUPHS9bK4xlfkL/ZliD2KvZPSA9Ob7eqTPAUy1nAI jkiNZvMZEF5jyIjX8Le25iQ= X-Google-Smtp-Source: ADFU+vvpNoYbMggMfVam9rNXtEJjIPNyBboiRZP3i2QGNAQ0Ea5cf+35iVViGMKjEjPHHaHKz29nlA== X-Received: by 2002:a5d:6282:: with SMTP id k2mr26161882wru.401.1584285281491; Sun, 15 Mar 2020 08:14:41 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:40 -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 08/15] power: supply: cpcap-battery: Get rid of rough capacity percentage Date: Sun, 15 Mar 2020 18:11:59 +0300 Message-Id: <20200315151206.30909-8-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 Get rid of rough capacity percentage. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 46 +++++++++--------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index f712a3bda315..2f4c6669c37d 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -142,24 +142,22 @@ struct cpcap_battery_ddata { struct cpcap_battery_capacity { int capacity; int voltage; - int percentage; }; -#define CPCAP_CAP(l, v, p) \ +#define CPCAP_CAP(l, v) \ { \ .capacity = (l), \ .voltage = (v), \ - .percentage = (p), \ }, /* Pessimistic battery capacity mapping before high or low value is seen */ static const struct cpcap_battery_capacity cpcap_battery_cap[] = { - CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN, 0, 0) - CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL, 3100000, 0) - CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_LOW, 3300000, 2) - CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_NORMAL, 3700000, 50) - CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_HIGH, 4000000, 75) - CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_FULL, 4200000 - 18000, 100) + CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN, 0) + CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL, 3100000) + CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_LOW, 3300000) + CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_NORMAL, 3700000) + CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_HIGH, 4000000) + CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_FULL, 4200000 - 18000) }; #define CPCAP_NO_BATTERY -400 @@ -503,8 +501,7 @@ static int cpcap_battery_update_status(struct cpcap_battery_ddata *ddata) return 0; } -static void cpcap_battery_get_rough(struct cpcap_battery_ddata *ddata, - int *level, int *percentage) +static int cpcap_battery_get_capacity_level(struct cpcap_battery_ddata *ddata) { struct cpcap_battery_state_data *latest; const struct cpcap_battery_capacity *cap = NULL; @@ -520,30 +517,9 @@ static void cpcap_battery_get_rough(struct cpcap_battery_ddata *ddata, } if (!cap) - return; - - if (level) - *level = cap->capacity; - if (percentage) - *percentage = cap->percentage; -} - -static int cpcap_battery_get_rough_capacity(struct cpcap_battery_ddata *ddata) -{ - int capacity = 0; - - cpcap_battery_get_rough(ddata, &capacity, NULL); - - return capacity; -} - -static int cpcap_battery_get_rough_percentage(struct cpcap_battery_ddata *ddata) -{ - int percentage = 0; - - cpcap_battery_get_rough(ddata, NULL, &percentage); + return 0; - return percentage; + return cap->capacity; } static enum power_supply_property cpcap_battery_props[] = { @@ -662,7 +638,7 @@ static int cpcap_battery_get_property(struct power_supply *psy, val->intval /= ddata->charge_full; break; case POWER_SUPPLY_PROP_CAPACITY_LEVEL: - val->intval = cpcap_battery_get_rough_capacity(ddata); + val->intval = cpcap_battery_get_capacity_level(ddata); break; case POWER_SUPPLY_PROP_CHARGE_NOW: low = cpcap_battery_get_lowest(ddata); 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 D." X-Patchwork-Id: 11439195 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF81514E5 for ; Sun, 15 Mar 2020 15:14:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CEDBC20578 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 D." X-Patchwork-Id: 11439199 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E66E214B4 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 C5DFB206E9 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:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Arthur D." X-Patchwork-Id: 11439203 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE3C914E5 for ; Sun, 15 Mar 2020 15:14:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9239620578 for ; Sun, 15 Mar 2020 15:14:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JiJyJXqZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728745AbgCOPOq (ORCPT ); Sun, 15 Mar 2020 11:14:46 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35638 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728678AbgCOPOq (ORCPT ); Sun, 15 Mar 2020 11:14:46 -0400 Received: by mail-wr1-f65.google.com with SMTP id d5so17742196wrc.2; Sun, 15 Mar 2020 08:14:45 -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=fOEz6aZDrZFHHHa5AM3closKBpa5Nsq+Hwyn3tGe+Lw=; b=JiJyJXqZ32FusFx8+3ZU7Xr93OLwjb0MgoHiGl+r1V9HoHvpHsK3Up9YTzjIUH38aw yfTWDD3G/o5IJ+CRLe5IQwuu6NaRppPMuZmlHWMUOnnMG2r+USqfOi6K1r8hjdI0ybEm 4SF1b07LIuZm7PMTDG0y54iFbyNNUwSIG/st2Lu4EkAflDCydseqLgyE6F659fPWXfgx z8smGCKkRr4+KRMVqSKDvD+LfUq32Z6kio1sWRly3W7t1txptdfBCG775z8dg7MVfyDe 6dCr7CLs/6Q7ByETbivSyzpLMvYMUKFPJe9Pj688HSnecXNf+1qiWH6QxyGjcQIlOKpD tR6Q== 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=fOEz6aZDrZFHHHa5AM3closKBpa5Nsq+Hwyn3tGe+Lw=; b=C3P9DzfQIDC2w/sSiKMIYqXUQXsKsE/5zd75I3gcpnBSqNjwr8M9t7OMgq0oppy1ms t3BDLa+jPQJ8LPhVNc6g5mk9P4o+dOrjsN5wtUKTkK5ga7BpF8rNJYSBHKqGUPRYOaZJ QXOJHhGrKCER10sR4IUCr3G8M72vZaJvcK6xKLCNUBdog7uLrj4SeB4D00GeUU9gN1R/ zulRPfwNGRWh434IPmmQLKt1CHqZ1fQzIhqmEzbSv7mb/YYwzA5KbHYAty1nuzHCYZjn y0Ix0ogwQBLXYDgoVY6gzTiUoZk8Ses2k69sRBqMcnZLwYWVQmlnpEhu2Oykmh2Il5Ee Sz8A== X-Gm-Message-State: ANhLgQ3EHSF+HKO9tZh9E/SoiKK2ApBXrmquKMkeVQA1J5rESwxAnkCE POcEix5VYidF+A43Qdv65Qk= X-Google-Smtp-Source: ADFU+vu8emjyc30P+CNeBZzNm2q+Vs5G3iN3yO3IGNBjlGUxX2/LIocbc3RSR3ISZSwQMZee0fSGdw== X-Received: by 2002:adf:f3c1:: with SMTP id g1mr14057038wrp.129.1584285285030; Sun, 15 Mar 2020 08:14:45 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:44 -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 11/15] power: supply: cpcap-battery: Rename properties, variables and functions Date: Sun, 15 Mar 2020 18:12:02 +0300 Message-Id: <20200315151206.30909-11-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 This is a preparation for the following change which will stabilize battery full charge value when calibrating. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 75 ++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 6205a5e43a32..66ea1a718e02 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -110,8 +110,8 @@ struct cpcap_coulomb_counter_data { enum cpcap_battery_state { CPCAP_BATTERY_STATE_PREVIOUS, CPCAP_BATTERY_STATE_LATEST, - CPCAP_BATTERY_STATE_LOW, - CPCAP_BATTERY_STATE_HIGH, + CPCAP_BATTERY_STATE_EMPTY, + CPCAP_BATTERY_STATE_FULL, CPCAP_BATTERY_STATE_NR, }; @@ -185,15 +185,15 @@ cpcap_battery_previous(struct cpcap_battery_ddata *ddata) } static struct cpcap_battery_state_data * -cpcap_battery_get_lowest(struct cpcap_battery_ddata *ddata) +cpcap_battery_get_empty(struct cpcap_battery_ddata *ddata) { - return cpcap_battery_get_state(ddata, CPCAP_BATTERY_STATE_LOW); + return cpcap_battery_get_state(ddata, CPCAP_BATTERY_STATE_EMPTY); } static struct cpcap_battery_state_data * -cpcap_battery_get_highest(struct cpcap_battery_ddata *ddata) +cpcap_battery_get_full(struct cpcap_battery_ddata *ddata) { - return cpcap_battery_get_state(ddata, CPCAP_BATTERY_STATE_HIGH); + return cpcap_battery_get_state(ddata, CPCAP_BATTERY_STATE_FULL); } static int cpcap_charger_battery_temperature(struct cpcap_battery_ddata *ddata, @@ -436,7 +436,8 @@ 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, *low, *high; + struct cpcap_battery_state_data state, *latest, *previous, + *empty, *full; ktime_t now; int error; @@ -466,39 +467,39 @@ static int cpcap_battery_update_status(struct cpcap_battery_ddata *ddata) memcpy(latest, &state, sizeof(*latest)); if (cpcap_battery_full(ddata)) { - high = cpcap_battery_get_highest(ddata); - /* Update highest charge seen? */ - 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) + full = cpcap_battery_get_full(ddata); + /* Update full state value? */ + if (latest->counter_uah <= full->counter_uah || + !full->voltage) { + memcpy(full, latest, sizeof(*full)); + + empty = cpcap_battery_get_empty(ddata); + if (empty->voltage && empty->voltage != -1) ddata->charge_full = - low->counter_uah - high->counter_uah; + empty->counter_uah - full->counter_uah; else if (ddata->charge_full) { /* Initialize with user provided data */ - low->counter_uah = - high->counter_uah + ddata->charge_full; + empty->counter_uah = + full->counter_uah + ddata->charge_full; /* Mark it as initialized */ - low->voltage = -1; + empty->voltage = -1; } } } else if (cpcap_battery_low(ddata)) { - low = cpcap_battery_get_lowest(ddata); - /* Update lowest charge seen? */ - if (latest->counter_uah >= low->counter_uah || - !low->voltage) { - memcpy(low, latest, sizeof(*low)); - - high = cpcap_battery_get_highest(ddata); - if (high->voltage) + empty = cpcap_battery_get_empty(ddata); + /* Update empty state value? */ + if (latest->counter_uah >= empty->counter_uah || + !empty->voltage) { + memcpy(empty, latest, sizeof(*empty)); + + full = cpcap_battery_get_full(ddata); + if (full->voltage) ddata->charge_full = - low->counter_uah - high->counter_uah; + empty->counter_uah - full->counter_uah; else if (ddata->charge_full) /* Initialize with user provided data */ - high->counter_uah = - low->counter_uah - ddata->charge_full; + full->counter_uah = + empty->counter_uah - ddata->charge_full; } } @@ -553,7 +554,7 @@ static int cpcap_battery_get_property(struct power_supply *psy, union power_supply_propval *val) { struct cpcap_battery_ddata *ddata = power_supply_get_drvdata(psy); - struct cpcap_battery_state_data *latest, *previous, *low; + struct cpcap_battery_state_data *latest, *previous, *empty; u32 sample; s32 accumulator; int cached; @@ -634,10 +635,10 @@ static int cpcap_battery_get_property(struct power_supply *psy, val->intval = div64_s64(tmp, 100); break; case POWER_SUPPLY_PROP_CAPACITY: - low = cpcap_battery_get_lowest(ddata); - if (!low->voltage || !ddata->charge_full) + empty = cpcap_battery_get_empty(ddata); + if (!empty->voltage || !ddata->charge_full) return -ENODATA; - val->intval = (low->counter_uah - + val->intval = (empty->counter_uah - latest->counter_uah) * 100; val->intval /= ddata->charge_full; break; @@ -645,10 +646,10 @@ static int cpcap_battery_get_property(struct power_supply *psy, val->intval = cpcap_battery_get_capacity_level(ddata); break; case POWER_SUPPLY_PROP_CHARGE_NOW: - low = cpcap_battery_get_lowest(ddata); - if (!low->voltage) + empty = cpcap_battery_get_empty(ddata); + if (!empty->voltage) return -ENODATA; - val->intval = low->counter_uah - latest->counter_uah; + val->intval = empty->counter_uah - latest->counter_uah; break; case POWER_SUPPLY_PROP_CHARGE_FULL: if (!ddata->charge_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 D." X-Patchwork-Id: 11439209 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6850B159A 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 47A5820722 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:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Arthur D." X-Patchwork-Id: 11439211 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C71014E5 for ; Sun, 15 Mar 2020 15:14:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D121206BE for ; Sun, 15 Mar 2020 15:14:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R9izYlv9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728678AbgCOPOt (ORCPT ); Sun, 15 Mar 2020 11:14:49 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55835 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728665AbgCOPOt (ORCPT ); Sun, 15 Mar 2020 11:14:49 -0400 Received: by mail-wm1-f65.google.com with SMTP id 6so14919198wmi.5; Sun, 15 Mar 2020 08:14:48 -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=eVPxIoZo/vKodsHN/qS4/fBJ4w5+dc7DuMJbCteKrrM=; b=R9izYlv93M4b3lcNWWP+qtEpqqYGfPQl8nQ1uKin/exVlDcFnhvePq6zVFkrxJQMeZ hKvt/TPkaae7PXKmjOn5w8Dd0agqCfJX2tiAH/utVu1XPGQ3gD6ZGGDFh1rKBOT2AuW7 DRw98ywRqrZYgNu1/Z4enfdgoHan3a/zMQwre5/chvsZ6OjPeZ6u0SsJlDpVMQPHyvfg zKVnyuw/+TY8IktDLh7RR53AP8C0i2npGuIz4ifx+JQI8+nhzN8go5cAXskQJCsMbuIa yP+x6BqfyJrkEbrKC3SXlzxlcIwzuCogxvojDIaIGFxzN8QPDgngWybkETrxN9HQWQGp GcQA== 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=eVPxIoZo/vKodsHN/qS4/fBJ4w5+dc7DuMJbCteKrrM=; b=A5Vrb6qRwgCAYEADGQQGxWj2jSTaqn1NB0g83xHbprx69H+tlaeqhaitCn/mqxrMVz QaKInOSjIpVugHdJaDB1s5GHFbpv3CBqXoZtoCZP9NXiQ2TSCRn7lMRTWXDS7fJ+2V7n +WNTgDmAC2jlOu7Lg8HjncawjuU05hQmmf/9sGZtvchOEfugaKgm2rjYhOTCIUv6MrZ+ 31zdoT0cBno5etuzl7taDQk4qiumH7YiDMMFXEWyIAAEUs0FfNPFZAB7MC6iHuwRL5Vb UshDxjvwIPeheJtCsQp7WZIkiJvrL2Eqm/T5tjG5RU7nT188A2oUtn14ZGhuw/zxI1Tm A2oQ== X-Gm-Message-State: ANhLgQ12rib3kZIj9TI2qt3CUJP5XSC8L0CcDzr0+ZZ7p6z00z8juIUs ZPrFNd6jVhwGgXg0I2cIMqI= X-Google-Smtp-Source: ADFU+vvUw8RmrHntFQcgB/ZgXAXUDdh8nfGN0fbBpRQAwOJAOEIrpqpCviJcRW0SNCmkWU3rQjJWxg== X-Received: by 2002:a7b:c75a:: with SMTP id w26mr4866555wmk.2.1584285287723; Sun, 15 Mar 2020 08:14:47 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:47 -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 13/15] power: supply: cpcap-battery: Fine tune end of charge current Date: Sun, 15 Mar 2020 18:12:04 +0300 Message-Id: <20200315151206.30909-13-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 For some reason the charger device gets disconnected prior we have 100 mA current. Set the fully charged state detection current to 112 mA. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 517acdfa6009..938117638983 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -411,10 +411,10 @@ static bool cpcap_battery_full(struct cpcap_battery_ddata *ddata) (ddata->config.bat.constant_charge_voltage_max_uv - 18000)) { is_full = false; } else if (is_full) { - if (state->current_ua < -150000) + if (state->current_ua < -170000) is_full = false; - } else if (state->current_ua >= -150000 && - cpcap_battery_cc_get_avg_current(ddata) >= -100000) { + } else if (state->current_ua >= -170000 && + cpcap_battery_cc_get_avg_current(ddata) >= -112000) { is_full = true; } 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 D." X-Patchwork-Id: 11439217 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5699159A 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 944B520578 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; } } From patchwork Sun Mar 15 15:12:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Arthur D." X-Patchwork-Id: 11439221 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BCBB159A for ; Sun, 15 Mar 2020 15:14:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7BEAD206B1 for ; Sun, 15 Mar 2020 15:14:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XiJtWJVX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728796AbgCOPOx (ORCPT ); Sun, 15 Mar 2020 11:14:53 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40651 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728789AbgCOPOx (ORCPT ); Sun, 15 Mar 2020 11:14:53 -0400 Received: by mail-wm1-f67.google.com with SMTP id z12so6081763wmf.5; Sun, 15 Mar 2020 08:14:50 -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=YohDd/F61lZ9cpzSoLOwuZMoRWWt6P3Yq9P3ddNnkbo=; b=XiJtWJVXYzhft5hDCOjhW/SzT2EOuK4lmRfZet718rPEO3v0tNPBa4rxcc6pUa1Zzj ykbYktbuy78pbILvJ27jfnTjxXNIijF22xzNmZU0rVB+EE9b+v0ovURXkZtIMLseI2RF CBiZ+OGLADQLVsUfKW+MVbazd7AZue0hrS60MnBTM6hdRpNHUHe1x8iQH8i9ODvcXKC+ FTmx2VHuilVu/bITGxxj5AFXb4HlRwepTQjOZra0YeJa5V2Q/m3ELW9idoyy65z9B4BB Dcf5d/z/4UrRuP65CsAjKO6G8j1n3GkGoc42wtLeA2ld9+luGXZVvEZVTmIKVO9z0znC coww== 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=YohDd/F61lZ9cpzSoLOwuZMoRWWt6P3Yq9P3ddNnkbo=; b=a62PavIFqGl4G/sh89hqXpQ3+PL8SUe90Z7Y2wz0i7VXRM3bYzrHSGr++jo7tsHtDZ zGIwQMKhYjncfJgaYJQN0OkPU3tyiS70II1ZE591cryI0ZBqDwS1WmLp1K57G/wzMOgY mMrCaY6AIVPME7cw9nDU6M6+oChVPZ0kYEdQdgLDw+2YMlkgfdDPqXwDtudG5EC+IUx/ i7BsW7qj27Gxgz8FglDwijX8bkLI90wTryxeKy1Vmc+BbSz/51kBjKAo6FutafDd0KqJ KYS+pFfHXl0CJUqDCTNe01iHfIPiMyh7ioFxMbqIDpnC/puKFFiznDck25zrRjOpjgNW l8wA== X-Gm-Message-State: ANhLgQ32NhTxm4T7zWSEMjC4PhOLuTVjPd0g99D07Ts9oksRqpQjIcp7 zCJ8Smo5dmaxZWJwKP1XBIc= X-Google-Smtp-Source: ADFU+vtyBVa7ztI9TPGIZx3lv0hyXvP/N0b9ZzvgYmJ+acAwYmOdf+X/RTUOT+/RfO2qUx/Ty67hXg== X-Received: by 2002:a1c:2b44:: with SMTP id r65mr21901486wmr.72.1584285290262; Sun, 15 Mar 2020 08:14:50 -0700 (PDT) Received: from supervisor.net28 ([46.53.248.79]) by smtp.gmail.com with ESMTPSA id i67sm67746869wri.50.2020.03.15.08.14.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 08:14:49 -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 15/15] power: supply: cpcap-battery: Add rounding to capacity reporting Date: Sun, 15 Mar 2020 18:12:06 +0300 Message-Id: <20200315151206.30909-15-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 Add rounding to capacity reporting. Signed-off-by: Arthur Demchenkov --- drivers/power/supply/cpcap-battery.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 4e872bd36ccf..b16848cfb58c 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -627,7 +627,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; + /* (ddata->charge_full / 200) is needed for rounding */ + val->intval = empty->counter_uah - latest->counter_uah + + ddata->charge_full / 200; val->intval = clamp(val->intval, 0, ddata->charge_full); val->intval = val->intval * 100 / ddata->charge_full; break;