mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Werner Sembach <wse@tuxedocomputers.com>
To: Armin Wolf <W_Armin@gmx.de>,
	hansg@kernel.org, ilpo.jarvinen@linux.intel.com
Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] platform/x86: uniwill-laptop: Properly initialize charging threshold
Date: Fri, 10 Apr 2026 22:26:36 +0200	[thread overview]
Message-ID: <4a9f1a03-f209-4f24-b59c-e93c595958a0@tuxedocomputers.com> (raw)
In-Reply-To: <f8dc0729-5fec-4c28-8233-1a80ce1fe2f9@gmx.de>


Am 10.04.26 um 19:27 schrieb Armin Wolf:
> Am 09.04.26 um 00:59 schrieb Werner Sembach:
>
>>
>> Am 06.04.26 um 21:36 schrieb Armin Wolf:
>>> The EC might initialize the charge threshold with 0 to signal that
>>> said threshold is uninitialized. Detect this and replace said value
>>> with 100 to signal the EC that we want to take control of battery
>>> charging. Also set the threshold to 100 if the EC-provided value
>>> is invalid.
>>>
>>> Fixes: d050479693bb ("platform/x86: Add Uniwill laptop driver")
>>> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
>>> ---
>>>   drivers/platform/x86/uniwill/uniwill-acpi.c | 28 ++++++++++++++++++++-
>>>   1 file changed, 27 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/platform/x86/uniwill/uniwill-acpi.c 
>>> b/drivers/platform/x86/uniwill/uniwill-acpi.c
>>> index faade4cf08be..8f16c94221aa 100644
>>> --- a/drivers/platform/x86/uniwill/uniwill-acpi.c
>>> +++ b/drivers/platform/x86/uniwill/uniwill-acpi.c
>>> @@ -1404,7 +1404,12 @@ static int uniwill_get_property(struct power_supply 
>>> *psy, const struct power_sup
>>>           if (ret < 0)
>>>               return ret;
>>>   -        val->intval = clamp_val(FIELD_GET(CHARGE_CTRL_MASK, regval), 0, 
>>> 100);
>>> +        regval = FIELD_GET(CHARGE_CTRL_MASK, regval);
>>> +        if (!regval)
>> personal preference: explicitly compair to the uninitialized-value "0" with 
>> == for better readability, but don't know if that is the normal coding style 
>> for the kernel
>
> Hi,
>
> AFAIK the default kernel coding style encourages people to write NULL/0 checks 
> as !value. However i am not sure
> if this only applies to NULL checks. Ilpo, what is your preference in this case?
ok
>
>>> +            val->intval = 100;
>>> +        else
>>> +            val->intval = min(regval, 100);
>>> +
>> We silently correct invalid values here. Wouldn't it be better to detect that 
>> something is off?
>
> The ACPI code on my device suggests that values equal to or larger than 100 
> will be interpreted as
> "charging limit is disabled", so i think we should replicate this assumption 
> inside the driver.

ok

then:

Reviewed-by: Werner Sembach <wse@tuxedocomputers.com>

>
> Thanks,
> Armin Wolf
>
>>>           return 0;
>>>       default:
>>>           return -EINVAL;
>>> @@ -1499,11 +1504,32 @@ static int uniwill_remove_battery(struct 
>>> power_supply *battery, struct acpi_batt
>>>     static int uniwill_battery_init(struct uniwill_data *data)
>>>   {
>>> +    unsigned int value, threshold;
>>>       int ret;
>>>         if (!uniwill_device_supports(data, UNIWILL_FEATURE_BATTERY))
>>>           return 0;
>>>   +    ret = regmap_read(data->regmap, EC_ADDR_CHARGE_CTRL, &value);
>>> +    if (ret < 0)
>>> +        return ret;
>>> +
>>> +    /*
>>> +     * The charge control threshold might be initialized with 0 by
>>> +     * the EC to signal that said threshold is uninitialized. We thus
>>> +     * need to replace this value with 100 to signal that we want to
>>> +     * take control of battery charging. For the sake of completeness
>>> +     * we also set the charging threshold to 100 if the EC-provided
>>> +     * value is invalid.
>>> +     */
>>> +    threshold = FIELD_GET(CHARGE_CTRL_MASK, value);
>>> +    if (threshold == 0 || threshold > 100) {
>>> +        FIELD_MODIFY(CHARGE_CTRL_MASK, &value, 100);
>>> +        ret = regmap_write(data->regmap, EC_ADDR_CHARGE_CTRL, value);
>>> +        if (ret < 0)
>>> +            return ret;
>>> +    }
>>> +
>>>       ret = devm_mutex_init(data->dev, &data->battery_lock);
>>>       if (ret < 0)
>>>           return ret;

  reply	other threads:[~2026-04-10 20:26 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-06 19:36 [PATCH 0/6] platform/x86: uniwill-laptop: Charging-related improvements Armin Wolf
2026-04-06 19:36 ` [PATCH 1/6] platform/x86: uniwill-laptop: Properly initialize charging threshold Armin Wolf
2026-04-08 22:59   ` Werner Sembach
2026-04-10 17:27     ` Armin Wolf
2026-04-10 20:26       ` Werner Sembach [this message]
2026-04-06 19:36 ` [PATCH 2/6] platform/x86: uniwill-laptop: Accept charging threshold of 0 Armin Wolf
2026-04-08 23:01   ` Werner Sembach
2026-04-06 19:36 ` [PATCH 3/6] platform/x86: uniwill-laptop: Fix behavior of "force" module param Armin Wolf
2026-04-08 23:08   ` Werner Sembach
2026-04-10 17:32     ` Armin Wolf
2026-04-10 20:30       ` Werner Sembach
2026-04-10 21:45         ` Armin Wolf
2026-04-06 19:36 ` [PATCH 4/6] platform/x86: uniwill-laptop: Rework FN lock/super key suspend handling Armin Wolf
2026-04-10 15:30   ` Werner Sembach
2026-04-10 17:33     ` Armin Wolf
2026-04-06 19:36 ` [PATCH 5/6] platform/x86: uniwill-laptop: Mark EC_ADDR_OEM_4 as volatile Armin Wolf
2026-04-10 15:35   ` Werner Sembach
2026-04-06 19:36 ` [PATCH 6/6] platform/x86: uniwill-laptop: Add support for battery charge modes Armin Wolf
2026-04-10 16:53   ` Werner Sembach
2026-04-10 17:53     ` Armin Wolf
2026-04-10 20:24       ` Werner Sembach
2026-04-10 21:47         ` Armin Wolf

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=4a9f1a03-f209-4f24-b59c-e93c595958a0@tuxedocomputers.com \
    --to=wse@tuxedocomputers.com \
    --cc=W_Armin@gmx.de \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /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®