mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
To: turbinebmw <turbine.bmw@gmail.com>,
	Sebastian Reichel <sre@kernel.org>,
	linux-pm@vger.kernel.org
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Val Packett <val@packett.cool>,
	Fenglin Wu <fenglin.wu@oss.qualcomm.com>
Subject: Re: [PATCH] power: supply: qcom_battmgr: treat a start threshold of 0 as none
Date: Wed, 2 Dec 2026 12:10:25 +0100	[thread overview]
Message-ID: <6ea8c987-c1d1-4f6f-bce0-835384692498@oss.qualcomm.com> (raw)
In-Reply-To: <20261128012449.323479-1-turbine.bmw@gmail.com>

On 11/28/26 2:24 AM, turbinebmw wrote:
> From: Brandon Williams <turbine.bmw@gmail.com>
> 
> UPower turns a charge limit off by writing 0 to
> charge_control_start_threshold and 100 to charge_control_end_threshold.
> Since commit 8809980fdc8a ("power: supply: qcom_battmgr: clamp charge
> control thresholds") the driver raises the 0 to
> CHARGE_CTRL_START_THR_MIN, so the firmware is told to charge to 100%
> but resume only below 50%. A battery that the limit had stopped at its
> end threshold, say 80%, then stays at "Not charging" until it drains
> below 50%, and turning the limit off appears to do nothing.
> 
> Disabling charge control through the request's enable bit was tried
> and reverted, as the firmware did not behave as expected with it.
> Instead, take a start threshold of 0 to mean that there is none: keep
> the end threshold and use the smallest step, CHARGE_CTRL_DELTA_SOC, so
> that charging resumes as soon as the level drops below it. The start
> sent to the firmware stays within [50, 95], as the end threshold is at
> least 55. The start is remembered as 0, so a following end threshold
> write keeps the small step, whichever order userspace writes them in.
> 
> Tested on a Microsoft Surface Pro 11 (X1E80100) with UPower 1.91.5: with
> the battery held at 80% on a 75-80 window, turning the limit off set
> 95-100 and the battery charged at once; turning it back on restored
> 75-80.
> 
> Link: https://gitlab.freedesktop.org/upower/upower/-/issues/327
> Fixes: 8809980fdc8a ("power: supply: qcom_battmgr: clamp charge control thresholds")
> Cc: Val Packett <val@packett.cool>
> Cc: Fenglin Wu <fenglin.wu@oss.qualcomm.com>
> Cc: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> Assisted-by: Claude:claude-opus-5-5

This tag is deprecated, checkpatch should have pointed that out

> Signed-off-by: Brandon Williams <turbine.bmw@gmail.com>
> ---
> Based on sre/linux-power-supply for-next. Hardware-tested as a backport
> to 7.3.6 (the same logic laid out with a goto, on top of a local change
> that returns the request status like ffce9bb777f2); a userspace harness
> running both versions' setters over 120000 random threshold writes gave
> identical firmware requests and sysfs values. Compile-tested with W=1.
> 
> This keeps the 50% floor Fenglin explained in the thread on Val's series
> and does not use the enable bit, whose removal is 8e8856396b54.
> 
>  drivers/power/supply/qcom_battmgr.c | 43 +++++++++++++++++++----------
>  1 file changed, 29 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
> index 0789303..45bd1ff 100644
> --- a/drivers/power/supply/qcom_battmgr.c
> +++ b/drivers/power/supply/qcom_battmgr.c
> @@ -762,21 +762,36 @@ static int qcom_battmgr_set_charge_start_threshold(struct qcom_battmgr *battmgr,
>  	u32 target_soc, delta_soc;
>  	int ret;
>  
> -	start_soc = clamp(start_soc, CHARGE_CTRL_START_THR_MIN, CHARGE_CTRL_START_THR_MAX);
> -
> -	/*
> -	 * If the new start threshold is larger than the old end threshold,
> -	 * move the end threshold one step (DELTA_SOC) after the new start
> -	 * threshold.
> -	 */
> -	if (start_soc > battmgr->info.charge_ctrl_end) {
> -		target_soc = start_soc + CHARGE_CTRL_DELTA_SOC;
> -		target_soc = min_t(u32, target_soc, CHARGE_CTRL_END_THR_MAX);
> -		delta_soc = target_soc - start_soc;
> -		delta_soc = min_t(u32, delta_soc, CHARGE_CTRL_DELTA_SOC);
> +	if (start_soc <= 0) {

From Documentation/ABI/testing/sysfs-class-power:

What:           /sys/class/power_supply/<supply_name>/charge_control_start_threshold
Date:           April 2019
Contact:        linux-pm@vger.kernel.org
Description:
                Represents a battery percentage level, below which charging will
                begin.

                Access: Read, Write
                Valid values: 0 - 100 (percent)

so let's test for if start_soc == 0


> +		/*
> +		 * A start threshold of 0 means there is none: charging resumes
> +		 * as soon as the level drops below the end threshold. Userspace
> +		 * writes it, with an end threshold of 100, to turn the limit
> +		 * off. Use the smallest step below the end threshold, which
> +		 * keeps the start within the firmware's range, and remember 0
> +		 * so that a following end threshold write keeps that step.
> +		 */

Opus is of course very chatty, please drop the comments

Konrad

      reply	other threads:[~2026-12-02 11:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  1:24 turbinebmw
2026-12-02 11:10 ` Konrad Dybcio [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6ea8c987-c1d1-4f6f-bce0-835384692498@oss.qualcomm.com \
    --to=konrad.dybcio@oss.qualcomm.com \
    --cc=fenglin.wu@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=turbine.bmw@gmail.com \
    --cc=val@packett.cool \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®