]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
platform/x86: uniwill-laptop: Accept charging threshold of 0
authorArmin Wolf <W_Armin@gmx.de>
Tue, 12 May 2026 23:21:39 +0000 (01:21 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 1 Jun 2026 15:54:49 +0000 (17:54 +0200)
[ Upstream commit c16a4823cc60a32b891f7a148bb30c0f51d12cf4 ]

The power supply sysfs ABI states that:

Not all hardware is capable of setting this to an arbitrary
percentage. Drivers will round written values to the nearest
supported value. Reading back the value will show the actual
threshold set by the driver.

The driver currently violates this ABI by rejecting a charging
threshold of 0. Fix this by clamping this value to 1.

Fixes: d050479693bb ("platform/x86: Add Uniwill laptop driver")
Reviewed-by: Werner Sembach <wse@tuxedocomputers.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Link: https://patch.msgid.link/20260512232145.329260-3-W_Armin@gmx.de
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/platform/x86/uniwill/uniwill-acpi.c

index 4b491fe8bdea4538a451fc23f934d7acfb517c5d..07951e01b43db4c43c7c4ebd5cafa0a80af41cd8 100644 (file)
@@ -1265,11 +1265,11 @@ static int uniwill_set_property(struct power_supply *psy, const struct power_sup
 
        switch (psp) {
        case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD:
-               if (val->intval < 1 || val->intval > 100)
+               if (val->intval < 0 || val->intval > 100)
                        return -EINVAL;
 
                return regmap_update_bits(data->regmap, EC_ADDR_CHARGE_CTRL, CHARGE_CTRL_MASK,
-                                         val->intval);
+                                         max(val->intval, 1));
        default:
                return -EINVAL;
        }