From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS 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 31F2FC4332B for ; Sat, 21 Mar 2020 22:21:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 102E520870 for ; Sat, 21 Mar 2020 22:21:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728113AbgCUWVN (ORCPT ); Sat, 21 Mar 2020 18:21:13 -0400 Received: from muru.com ([72.249.23.125]:32912 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727258AbgCUWVN (ORCPT ); Sat, 21 Mar 2020 18:21:13 -0400 Received: from atomide.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTPS id 953FC810E; Sat, 21 Mar 2020 22:21:58 +0000 (UTC) Date: Sat, 21 Mar 2020 15:21:08 -0700 From: Tony Lindgren To: "Arthur D." Cc: Merlijn Wajer , Pavel Machek , sre@kernel.org, linux-pm@vger.kernel.org, linux-omap@vger.kernel.org Subject: Re: [PATCH 06/15] power: supply: cpcap-battery: Initialize with user provided data Message-ID: <20200321222108.GX37466@atomide.com> References: <20200315151206.30909-1-spinal.by@gmail.com> <20200315151206.30909-6-spinal.by@gmail.com> <20200321145405.GW37466@atomide.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org * Arthur D. [200321 22:09]: > Hi. > > > Hmm I'm getting -EINVAL when I do echo 1600000 > charge_now but yet the > > value does get updated? > > Hm. I'm getting "Permission denied" when trying to do this. > Anyway, charge_now value is not supposed to be initialized by the user. > Only charge_full should be writable. Sorry I meant writing to charge_full :) Anyways, looks like echo -n works with no errors: # echo 1305000 > charge_full bash: echo: write error: Invalid argument # echo -n 1305000 > charge_full > > And I'm still not seeing capacity show up after that though even with > > full battery.. I think we should be able to calculate it if either a > > high or > > low value has been seen? > > There are two steps needed to calibrate the battery: to hit the "fully > charged" > state and to hit "battery empty" state. When the both states were hit the > driver > will initialize charge_full value. And it will start reporting correct > charge_now > and capacity (battery charge percentage) values. Hmm OK. So far no luck triggering that though. > Once the charge_full value is calculated it's recommended to be saved by the > user > to a permanent storage between reboots. > > Saving/restoring the value can be done in init scripts. > > For saving the calibration value just use the command like: > cat /sys/class/power_supply/battery/charge_full > /battery_cf > > To restore (after device reboot or power on): > cat /battery_cf > /sys/class/power_supply/battery/charge_full OK > This will allow the kernel to do fast calibration. I.e. you will > only need to fully charge _OR_ fully discharge the battery to start > seeing correct charge_now and capacity values. OK > > Also, we should have the driver default to using the charge_full_design > > value if nothing is written from userspace and we see a high or low > > value. > > I'd prefer to have charge_full value undefined until the battery is > calibrated. > This way the userspace can estimate current battery capacity using voltage > as a > fallback for uncalibrated battery. The voltage estimation will be way more > accurate than having charge_full = charge_full_design on pretty old Droid 4 > batteries. For example, my battery after calibration has about 1000 mAh, > while charge_full_design is 1740000. OK > > Maybe some pessimistic estimate could be used instead of just using > > charge_full_design if no value is initialized from the userspace? > > Something like (charge_full_design / 4) * 3 maybe? > > It's better to rely on voltage estimated percentage. > In Maemo Leste we patched upower to use the following formula, which gives > pretty > good results: > > percentage = (voltage - voltage_empty) / (voltage_full - voltage_empty) * > 100 > > Actually, the formula we use is a bit more complicated. OK > If you're curious, here's how it's actually done: > https://github.com/maemo-leste/upower/blob/master/src/linux/up-device-supply.c#L756 Thanks, I'll give the calibration another try. Maybe I did not wait low enough, I think I went down to 3.3V. Regards, Tony