Skip to contentSkip to conversation

platform/x86: asus-wmi: do not enforce a battery charge threshold

PATCH In review Denis Benato 5 participants 13 messages Mar 4 – Mar 24

Subsystems (2)
lore
Share & tools
lore

Denis Benato

author maintainer
#0 lore raw

PATCH 1/1 platform/x86: asus-wmi: do not enforce a battery charge threshold

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +8 -5
index 6ba49bd375df..dc330a8ee2f2 100644
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
 						 struct device_attribute *attr,
 						 char *buf)
 {
-	return sysfs_emit(buf, "%d\n", charge_end_threshold);
+	if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
+		return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+	return -ENODATA;
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
 		return -ENODEV;
 
 	/* The charge threshold is only reset when the system is power cycled,
-	 * and we can't get the current threshold so let set it to 100% when
-	 * a battery is added.
+	 * and we can't read the current threshold, however the majority of
+	 * platforms retains it, therefore signal the threshold as unknown
+	 * until user explicitly sets it to a new value.
 	 */
-	asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-	charge_end_threshold = 100;
+	charge_end_threshold = -1;
 
 	return 0;
 }
Signature · 1 line
2.53.0
#1 lore raw
Quoted 4 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery

*unsolicited. But I would rephrase to using this causes the device to reset its limits on boot, which might have been set by e.g. windows so if userspace is not aware to restore them, this causes a functionality degradation. This is the case with the current implementation by KDE.

Quoted 15 lines

charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +0 -0
index 6ba49bd375df..dc330a8ee2f2 100644

drivers/platform/x86/asus-wmi.c static ssize_t charge_control_end_threshold_show(struct device *device, · line 1563

Quoted 8 lines
drivers/platform/x86/asus-wmi.c +4 -1
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
                                                 struct device_attribute *attr,
                                                 char *buf)
 {
-       return sysfs_emit(buf, "%d\n", charge_end_threshold);
+       if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
+               return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+       return -ENODATA;

Please verify this does not cause KDE to display a warning and block modifying the energy consumption. If it does as has been my experience, communicate with KDE devs or Gnome (if it has a similar issue) and block this from merging until there is a solution from their side.

Returning an error from this function when there is proper function is a slight ABI change compared to current drivers that implement this method.

Thanks,
Antheas

Quoted 23 lines
drivers/platform/x86/asus-wmi.c +4 -5
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
                return -ENODEV;
 
        /* The charge threshold is only reset when the system is power cycled,
-        * and we can't get the current threshold so let set it to 100% when
-        * a battery is added.
+        * and we can't read the current threshold, however the majority of
+        * platforms retains it, therefore signal the threshold as unknown
+        * until user explicitly sets it to a new value.
         */
-       asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-       charge_end_threshold = 100;
+       charge_end_threshold = -1;
 
        return 0;
 }
--

2.53.0

author maintainer
#2 lore raw
Quoted 29 lines · Antheas Kapenekakis
Quoted 3 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery

*unsolicited. But I would rephrase to using this causes the device to reset its limits on boot, which might have been set by e.g. windows so if userspace is not aware to restore them, this causes a functionality degradation. This is the case with the current implementation by KDE.

Quoted 20 lines

charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +1 -1
index 6ba49bd375df..dc330a8ee2f2 100644
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
                                                 struct device_attribute *attr,
                                                 char *buf)
 {
-       return sysfs_emit(buf, "%d\n", charge_end_threshold);
+       if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
Quoted 8 lines

drivers/platform/x86/asus-wmi.c static ssize_t charge_control_end_threshold_show(struct device *device, · line 1563

Quoted 3 lines
drivers/platform/x86/asus-wmi.c +3 -0
+               return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+       return -ENODATA;

Please verify this does not cause KDE to display a warning and block modifying the energy consumption. If it does as has been my experience, communicate with KDE devs or Gnome (if it has a similar issue) and block this from merging until there is a solution from their side.

KDE doesn't yet allow to modify that value as upower is not picking up batteries with only end_threshold by default. Discussion is ongoing:

https://gitlab.freedesktop.org/upower/upower/-/merge_requests/308

since it has never worked there is nothing to break.

Quoted 30 lines

Returning an error from this function when there is proper function is a slight ABI change compared to current drivers that implement this method.

Thanks,
Antheas

Quoted 23 lines
drivers/platform/x86/asus-wmi.c +4 -5
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
                return -ENODEV;
 
        /* The charge threshold is only reset when the system is power cycled,
-        * and we can't get the current threshold so let set it to 100% when
-        * a battery is added.
+        * and we can't read the current threshold, however the majority of
+        * platforms retains it, therefore signal the threshold as unknown
+        * until user explicitly sets it to a new value.
         */
-       asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-       charge_end_threshold = 100;
+       charge_end_threshold = -1;
 
        return 0;
 }
--

2.53.0

#3 lore raw
Quoted 40 lines · Denis Benato
Quoted 29 lines · Antheas Kapenekakis
Quoted 3 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery

*unsolicited. But I would rephrase to using this causes the device to reset its limits on boot, which might have been set by e.g. windows so if userspace is not aware to restore them, this causes a functionality degradation. This is the case with the current implementation by KDE.

Quoted 20 lines

charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +1 -1
index 6ba49bd375df..dc330a8ee2f2 100644
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
                                                 struct device_attribute *attr,
                                                 char *buf)
 {
-       return sysfs_emit(buf, "%d\n", charge_end_threshold);
+       if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
Quoted 8 lines

drivers/platform/x86/asus-wmi.c static ssize_t charge_control_end_threshold_show(struct device *device, · line 1563

Quoted 3 lines
drivers/platform/x86/asus-wmi.c +3 -0
+               return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+       return -ENODATA;

Please verify this does not cause KDE to display a warning and block modifying the energy consumption. If it does as has been my experience, communicate with KDE devs or Gnome (if it has a similar issue) and block this from merging until there is a solution from their side.

Quoted 4 lines

KDE doesn't yet allow to modify that value as upower is not picking up batteries with only end_threshold by default. Discussion is ongoing:

https://gitlab.freedesktop.org/upower/upower/-/merge_requests/308

I have tested this exact patch you posted on my Z13 last November. KDE does pick it up and display a warning.

Which is why I settled with sending a fake 100 value instead and never upstreamed it.

Antheas

Quoted 32 lines

since it has never worked there is nothing to break.

Quoted 30 lines

Returning an error from this function when there is proper function is a slight ABI change compared to current drivers that implement this method.

Thanks,
Antheas

Quoted 23 lines
drivers/platform/x86/asus-wmi.c +4 -5
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
                return -ENODEV;
 
        /* The charge threshold is only reset when the system is power cycled,
-        * and we can't get the current threshold so let set it to 100% when
-        * a battery is added.
+        * and we can't read the current threshold, however the majority of
+        * platforms retains it, therefore signal the threshold as unknown
+        * until user explicitly sets it to a new value.
         */
-       asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-       charge_end_threshold = 100;
+       charge_end_threshold = -1;
 
        return 0;
 }
--

2.53.0

#4 lore raw
Quoted 45 lines · Antheas Kapenekakis
Quoted 43 lines · Denis Benato
Quoted 29 lines · Antheas Kapenekakis
Quoted 3 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery

*unsolicited. But I would rephrase to using this causes the device to reset its limits on boot, which might have been set by e.g. windows so if userspace is not aware to restore them, this causes a functionality degradation. This is the case with the current implementation by KDE.

Quoted 20 lines

charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +1 -1
index 6ba49bd375df..dc330a8ee2f2 100644
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
                                                 struct device_attribute *attr,
                                                 char *buf)
 {
-       return sysfs_emit(buf, "%d\n", charge_end_threshold);
+       if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
Quoted 8 lines

drivers/platform/x86/asus-wmi.c static ssize_t charge_control_end_threshold_show(struct device *device, · line 1563

Quoted 3 lines
drivers/platform/x86/asus-wmi.c +3 -0
+               return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+       return -ENODATA;

Please verify this does not cause KDE to display a warning and block modifying the energy consumption. If it does as has been my experience, communicate with KDE devs or Gnome (if it has a similar issue) and block this from merging until there is a solution from their side.

KDE doesn't yet allow to modify that value as upower is not picking up batteries with only end_threshold by default. Discussion is ongoing:

Quoted 7 lines
Quoted 1 line

https://gitlab.freedesktop.org/upower/upower/-/merge_requests/308

I have tested this exact patch you posted on my Z13 last November. KDE does pick it up and display a warning.

Which is why I settled with sending a fake 100 value instead and never upstreamed it.

*to be clear here I did EIO, not EDATA so this might be handled differently.

Quoted 34 lines

Antheas

Quoted 32 lines

since it has never worked there is nothing to break.

Quoted 30 lines

Returning an error from this function when there is proper function is a slight ABI change compared to current drivers that implement this method.

Thanks,
Antheas

Quoted 23 lines
drivers/platform/x86/asus-wmi.c +4 -5
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
                return -ENODEV;
 
        /* The charge threshold is only reset when the system is power cycled,
-        * and we can't get the current threshold so let set it to 100% when
-        * a battery is added.
+        * and we can't read the current threshold, however the majority of
+        * platforms retains it, therefore signal the threshold as unknown
+        * until user explicitly sets it to a new value.
         */
-       asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-       charge_end_threshold = 100;
+       charge_end_threshold = -1;
 
        return 0;
 }
--

2.53.0

author maintainer
#5 lore raw
In reply to Antheas Kapenekakis
Quoted 40 lines · Antheas Kapenekakis
Quoted 39 lines · Denis Benato
Quoted 37 lines · Antheas Kapenekakis
Quoted 3 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery

*unsolicited. But I would rephrase to using this causes the device to reset its limits on boot, which might have been set by e.g. windows so if userspace is not aware to restore them, this causes a functionality degradation. This is the case with the current implementation by KDE.

Quoted 15 lines

charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +0 -0
index 6ba49bd375df..dc330a8ee2f2 100644

drivers/platform/x86/asus-wmi.c static ssize_t charge_control_end_threshold_show(struct device *device, · line 1563

Quoted 8 lines
drivers/platform/x86/asus-wmi.c +4 -1
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
                                                 struct device_attribute *attr,
                                                 char *buf)
 {
-       return sysfs_emit(buf, "%d\n", charge_end_threshold);
+       if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
+               return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+       return -ENODATA;

Please verify this does not cause KDE to display a warning and block modifying the energy consumption. If it does as has been my experience, communicate with KDE devs or Gnome (if it has a similar issue) and block this from merging until there is a solution from their side.

Quoted 6 lines
Quoted 4 lines

KDE doesn't yet allow to modify that value as upower is not picking up batteries with only end_threshold by default. Discussion is ongoing:

https://gitlab.freedesktop.org/upower/upower/-/merge_requests/308

I have tested this exact patch you posted on my Z13 last November. KDE does pick it up and display a warning.

Displaying a warning about the current limit not being recognised is what is expected and correct behavior, not an ABI change: software isn't breaking.

You talked about setting (as in writing) the limit and that, as of now (at least in KDE) is not possible.

There already exists widely in use software that changes the battery level when started setting it to the previous value, so that warning is not to be seen; moreover said class of software is going to earn a new entry so I don't see any problem here.

Perhaps Ilpo has some more insights on the matter.

In addition to that, after the removal from the kernel of acpi_platform asus-wmi ABI are going to change anyway, regardless of what I do.

Quoted 36 lines

Which is why I settled with sending a fake 100 value instead and never upstreamed it.

Antheas

Quoted 31 lines

since it has never worked there is nothing to break.

Quoted 30 lines

Returning an error from this function when there is proper function is a slight ABI change compared to current drivers that implement this method.

Thanks,
Antheas

Quoted 23 lines
drivers/platform/x86/asus-wmi.c +4 -5
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
                return -ENODEV;
 
        /* The charge threshold is only reset when the system is power cycled,
-        * and we can't get the current threshold so let set it to 100% when
-        * a battery is added.
+        * and we can't read the current threshold, however the majority of
+        * platforms retains it, therefore signal the threshold as unknown
+        * until user explicitly sets it to a new value.
         */
-       asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-       charge_end_threshold = 100;
+       charge_end_threshold = -1;
 
        return 0;
 }
--

2.53.0

#6 lore raw
Quoted 46 lines · Denis Benato
Quoted 43 lines · Antheas Kapenekakis
Quoted 42 lines · Denis Benato
Quoted 29 lines · Antheas Kapenekakis
Quoted 3 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery

*unsolicited. But I would rephrase to using this causes the device to reset its limits on boot, which might have been set by e.g. windows so if userspace is not aware to restore them, this causes a functionality degradation. This is the case with the current implementation by KDE.

Quoted 20 lines

charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +1 -1
index 6ba49bd375df..dc330a8ee2f2 100644
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
                                                 struct device_attribute *attr,
                                                 char *buf)
 {
-       return sysfs_emit(buf, "%d\n", charge_end_threshold);
+       if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
Quoted 8 lines

drivers/platform/x86/asus-wmi.c static ssize_t charge_control_end_threshold_show(struct device *device, · line 1563

Quoted 3 lines
drivers/platform/x86/asus-wmi.c +3 -0
+               return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+       return -ENODATA;

Please verify this does not cause KDE to display a warning and block modifying the energy consumption. If it does as has been my experience, communicate with KDE devs or Gnome (if it has a similar issue) and block this from merging until there is a solution from their side.

KDE doesn't yet allow to modify that value as upower is not picking up batteries with only end_threshold by default. Discussion is ongoing:

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

https://gitlab.freedesktop.org/upower/upower/-/merge_requests/308

I have tested this exact patch you posted on my Z13 last November. KDE does pick it up and display a warning.

Displaying a warning about the current limit not being recognised is what is expected and correct behavior, not an ABI change: software isn't breaking.

You talked about setting (as in writing) the limit and that, as of now (at least in KDE) is not possible.

This is not true. Powerdevil supports the Asus driver and has done so for at least a year.

The setting is under "Power Management -> Advanced Power Settings". On mainline it works properly but resets after every reboot due to this bug.

With your patch applied, at least with -ENODATA there is no error. KDE defaults to 50%. So perhaps this could be doable to merge, -EIO made it fail. If you verify Gnome works properly or just does not support battery limits, but actually verify it mind you, this should be good to merge.

Antheas

Antheas

Quoted 46 lines

There already exists widely in use software that changes the battery level when started setting it to the previous value, so that warning is not to be seen; moreover said class of software is going to earn a new entry so I don't see any problem here.

Perhaps Ilpo has some more insights on the matter.

In addition to that, after the removal from the kernel of acpi_platform asus-wmi ABI are going to change anyway, regardless of what I do.

Quoted 36 lines

Which is why I settled with sending a fake 100 value instead and never upstreamed it.

Antheas

Quoted 31 lines

since it has never worked there is nothing to break.

Quoted 30 lines

Returning an error from this function when there is proper function is a slight ABI change compared to current drivers that implement this method.

Thanks,
Antheas

Quoted 23 lines
drivers/platform/x86/asus-wmi.c +4 -5
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
                return -ENODEV;
 
        /* The charge threshold is only reset when the system is power cycled,
-        * and we can't get the current threshold so let set it to 100% when
-        * a battery is added.
+        * and we can't read the current threshold, however the majority of
+        * platforms retains it, therefore signal the threshold as unknown
+        * until user explicitly sets it to a new value.
         */
-       asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-       charge_end_threshold = 100;
+       charge_end_threshold = -1;
 
        return 0;
 }
--

2.53.0

#7 lore raw
Quoted 51 lines · Antheas Kapenekakis
Quoted 50 lines · Denis Benato
Quoted 39 lines · Antheas Kapenekakis
Quoted 38 lines · Denis Benato
Quoted 37 lines · Antheas Kapenekakis
Quoted 3 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery

*unsolicited. But I would rephrase to using this causes the device to reset its limits on boot, which might have been set by e.g. windows so if userspace is not aware to restore them, this causes a functionality degradation. This is the case with the current implementation by KDE.

Quoted 15 lines

charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +0 -0
index 6ba49bd375df..dc330a8ee2f2 100644

drivers/platform/x86/asus-wmi.c static ssize_t charge_control_end_threshold_show(struct device *device, · line 1563

Quoted 8 lines
drivers/platform/x86/asus-wmi.c +4 -1
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
                                                 struct device_attribute *attr,
                                                 char *buf)
 {
-       return sysfs_emit(buf, "%d\n", charge_end_threshold);
+       if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
+               return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+       return -ENODATA;

Please verify this does not cause KDE to display a warning and block modifying the energy consumption. If it does as has been my experience, communicate with KDE devs or Gnome (if it has a similar issue) and block this from merging until there is a solution from their side.

Quoted 6 lines
Quoted 4 lines

KDE doesn't yet allow to modify that value as upower is not picking up batteries with only end_threshold by default. Discussion is ongoing:

https://gitlab.freedesktop.org/upower/upower/-/merge_requests/308

I have tested this exact patch you posted on my Z13 last November. KDE does pick it up and display a warning.

Displaying a warning about the current limit not being recognised is what is expected and correct behavior, not an ABI change: software isn't breaking.

Quoted 8 lines
Quoted 2 lines

You talked about setting (as in writing) the limit and that, as of now (at least in KDE) is not possible.

This is not true. Powerdevil supports the Asus driver and has done so for at least a year.

The setting is under "Power Management -> Advanced Power Settings". On mainline it works properly but resets after every reboot due to this bug.

I never noticed it... Interesting... well thank you.

Quoted 5 lines

With your patch applied, at least with -ENODATA there is no error. KDE defaults to 50%. So perhaps this could be doable to merge, -EIO made it fail. If you verify Gnome works properly or just does not support battery limits, but actually verify it mind you, this should be good to merge.

Alright I will test gnome and cosmic and will let you know. Thanks for covering KDE!

Quoted 50 lines

Antheas

Antheas

Quoted 45 lines

There already exists widely in use software that changes the battery level when started setting it to the previous value, so that warning is not to be seen; moreover said class of software is going to earn a new entry so I don't see any problem here.

Perhaps Ilpo has some more insights on the matter.

In addition to that, after the removal from the kernel of acpi_platform asus-wmi ABI are going to change anyway, regardless of what I do.

Quoted 36 lines

Which is why I settled with sending a fake 100 value instead and never upstreamed it.

Antheas

Quoted 31 lines

since it has never worked there is nothing to break.

Quoted 30 lines

Returning an error from this function when there is proper function is a slight ABI change compared to current drivers that implement this method.

Thanks,
Antheas

Quoted 23 lines
drivers/platform/x86/asus-wmi.c +4 -5
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
                return -ENODEV;
 
        /* The charge threshold is only reset when the system is power cycled,
-        * and we can't get the current threshold so let set it to 100% when
-        * a battery is added.
+        * and we can't read the current threshold, however the majority of
+        * platforms retains it, therefore signal the threshold as unknown
+        * until user explicitly sets it to a new value.
         */
-       asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-       charge_end_threshold = 100;
+       charge_end_threshold = -1;
 
        return 0;
 }
--

2.53.0

author maintainer
#8 lore raw
Quoted 61 lines · Denis Benato
Quoted 50 lines · Antheas Kapenekakis
Quoted 49 lines · Denis Benato
Quoted 39 lines · Antheas Kapenekakis
Quoted 38 lines · Denis Benato
Quoted 37 lines · Antheas Kapenekakis
Quoted 3 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery

*unsolicited. But I would rephrase to using this causes the device to reset its limits on boot, which might have been set by e.g. windows so if userspace is not aware to restore them, this causes a functionality degradation. This is the case with the current implementation by KDE.

Quoted 15 lines

charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +0 -0
index 6ba49bd375df..dc330a8ee2f2 100644

drivers/platform/x86/asus-wmi.c static ssize_t charge_control_end_threshold_show(struct device *device, · line 1563

Quoted 8 lines
drivers/platform/x86/asus-wmi.c +4 -1
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
                                                 struct device_attribute *attr,
                                                 char *buf)
 {
-       return sysfs_emit(buf, "%d\n", charge_end_threshold);
+       if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
+               return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+       return -ENODATA;

Please verify this does not cause KDE to display a warning and block modifying the energy consumption. If it does as has been my experience, communicate with KDE devs or Gnome (if it has a similar issue) and block this from merging until there is a solution from their side.

Quoted 6 lines
Quoted 4 lines

KDE doesn't yet allow to modify that value as upower is not picking up batteries with only end_threshold by default. Discussion is ongoing:

https://gitlab.freedesktop.org/upower/upower/-/merge_requests/308

I have tested this exact patch you posted on my Z13 last November. KDE does pick it up and display a warning.

Displaying a warning about the current limit not being recognised is what is expected and correct behavior, not an ABI change: software isn't breaking.

Quoted 8 lines
Quoted 2 lines

You talked about setting (as in writing) the limit and that, as of now (at least in KDE) is not possible.

This is not true. Powerdevil supports the Asus driver and has done so for at least a year.

The setting is under "Power Management -> Advanced Power Settings". On mainline it works properly but resets after every reboot due to this bug.

I never noticed it... Interesting... well thank you.

Quoted 7 lines
Quoted 5 lines

With your patch applied, at least with -ENODATA there is no error. KDE defaults to 50%. So perhaps this could be doable to merge, -EIO made it fail. If you verify Gnome works properly or just does not support battery limits, but actually verify it mind you, this should be good to merge.

Alright I will test gnome and cosmic and will let you know. Thanks for covering KDE!

I don't see anything bad. Both gnome and cosmic reports the current charge level.

Quoted 50 lines
Quoted 50 lines

Antheas

Antheas

Quoted 45 lines

There already exists widely in use software that changes the battery level when started setting it to the previous value, so that warning is not to be seen; moreover said class of software is going to earn a new entry so I don't see any problem here.

Perhaps Ilpo has some more insights on the matter.

In addition to that, after the removal from the kernel of acpi_platform asus-wmi ABI are going to change anyway, regardless of what I do.

Quoted 36 lines

Which is why I settled with sending a fake 100 value instead and never upstreamed it.

Antheas

Quoted 31 lines

since it has never worked there is nothing to break.

Quoted 30 lines

Returning an error from this function when there is proper function is a slight ABI change compared to current drivers that implement this method.

Thanks,
Antheas

Quoted 23 lines
drivers/platform/x86/asus-wmi.c +4 -5
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
                return -ENODEV;
 
        /* The charge threshold is only reset when the system is power cycled,
-        * and we can't get the current threshold so let set it to 100% when
-        * a battery is added.
+        * and we can't read the current threshold, however the majority of
+        * platforms retains it, therefore signal the threshold as unknown
+        * until user explicitly sets it to a new value.
         */
-       asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-       charge_end_threshold = 100;
+       charge_end_threshold = -1;
 
        return 0;
 }
--

2.53.0

#9 lore raw
Quoted 69 lines · Denis Benato
Quoted 66 lines · Denis Benato
Quoted 50 lines · Antheas Kapenekakis
Quoted 49 lines · Denis Benato
Quoted 39 lines · Antheas Kapenekakis
Quoted 38 lines · Denis Benato
Quoted 37 lines · Antheas Kapenekakis
Quoted 3 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery

*unsolicited. But I would rephrase to using this causes the device to reset its limits on boot, which might have been set by e.g. windows so if userspace is not aware to restore them, this causes a functionality degradation. This is the case with the current implementation by KDE.

Quoted 15 lines

charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +0 -0
index 6ba49bd375df..dc330a8ee2f2 100644

drivers/platform/x86/asus-wmi.c static ssize_t charge_control_end_threshold_show(struct device *device, · line 1563

Quoted 8 lines
drivers/platform/x86/asus-wmi.c +4 -1
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
                                                 struct device_attribute *attr,
                                                 char *buf)
 {
-       return sysfs_emit(buf, "%d\n", charge_end_threshold);
+       if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
+               return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+       return -ENODATA;

Please verify this does not cause KDE to display a warning and block modifying the energy consumption. If it does as has been my experience, communicate with KDE devs or Gnome (if it has a similar issue) and block this from merging until there is a solution from their side.

Quoted 6 lines
Quoted 4 lines

KDE doesn't yet allow to modify that value as upower is not picking up batteries with only end_threshold by default. Discussion is ongoing:

https://gitlab.freedesktop.org/upower/upower/-/merge_requests/308

I have tested this exact patch you posted on my Z13 last November. KDE does pick it up and display a warning.

Displaying a warning about the current limit not being recognised is what is expected and correct behavior, not an ABI change: software isn't breaking.

Quoted 8 lines
Quoted 2 lines

You talked about setting (as in writing) the limit and that, as of now (at least in KDE) is not possible.

This is not true. Powerdevil supports the Asus driver and has done so for at least a year.

The setting is under "Power Management -> Advanced Power Settings". On mainline it works properly but resets after every reboot due to this bug.

I never noticed it... Interesting... well thank you.

Quoted 5 lines

With your patch applied, at least with -ENODATA there is no error. KDE defaults to 50%. So perhaps this could be doable to merge, -EIO made it fail. If you verify Gnome works properly or just does not support battery limits, but actually verify it mind you, this should be good to merge.

Quoted 4 lines
Quoted 2 lines

Alright I will test gnome and cosmic and will let you know. Thanks for covering KDE!

I don't see anything bad. Both gnome and cosmic reports the current charge level.

Great,
fine by me to merge

Best,
Antheas

Quoted 51 lines
Quoted 50 lines
Quoted 50 lines

Antheas

Antheas

Quoted 45 lines

There already exists widely in use software that changes the battery level when started setting it to the previous value, so that warning is not to be seen; moreover said class of software is going to earn a new entry so I don't see any problem here.

Perhaps Ilpo has some more insights on the matter.

In addition to that, after the removal from the kernel of acpi_platform asus-wmi ABI are going to change anyway, regardless of what I do.

Quoted 36 lines

Which is why I settled with sending a fake 100 value instead and never upstreamed it.

Antheas

Quoted 31 lines

since it has never worked there is nothing to break.

Quoted 30 lines

Returning an error from this function when there is proper function is a slight ABI change compared to current drivers that implement this method.

Thanks,
Antheas

Quoted 23 lines
drivers/platform/x86/asus-wmi.c +4 -5
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
                return -ENODEV;
 
        /* The charge threshold is only reset when the system is power cycled,
-        * and we can't get the current threshold so let set it to 100% when
-        * a battery is added.
+        * and we can't read the current threshold, however the majority of
+        * platforms retains it, therefore signal the threshold as unknown
+        * until user explicitly sets it to a new value.
         */
-       asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-       charge_end_threshold = 100;
+       charge_end_threshold = -1;
 
        return 0;
 }
--

2.53.0

maintainer
#10 lore raw
In reply to Denis Benato
Quoted 3 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery

unsolicited

I'll deal with this while merging. If nothing else comes up, no need to send v2 just because of it (I'm just sending this to remind myself).

--
i.

Quoted 43 lines

charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

---
 drivers/platform/x86/asus-wmi.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +8 -5
index 6ba49bd375df..dc330a8ee2f2 100644
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
 						 struct device_attribute *attr,
 						 char *buf)
 {
-	return sysfs_emit(buf, "%d\n", charge_end_threshold);
+	if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
+		return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+	return -ENODATA;
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
 		return -ENODEV;
 
 	/* The charge threshold is only reset when the system is power cycled,
-	 * and we can't get the current threshold so let set it to 100% when
-	 * a battery is added.
+	 * and we can't read the current threshold, however the majority of
+	 * platforms retains it, therefore signal the threshold as unknown
+	 * until user explicitly sets it to a new value.
 	 */
-	asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-	charge_end_threshold = 100;
+	charge_end_threshold = -1;
 
 	return 0;
 }
Reviewed-by on v1 1/1
#11 lore raw
In reply to Denis Benato
Quoted 9 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

Hi Denis,

LGTM.

- Derek

Quoted 36 lines

---
drivers/platform/x86/asus-wmi.c | 13 ++++++++-----

1 file changed, 8 insertions(+), 5 deletions(-)
drivers/platform/x86/asus-wmi.c +8 -5
index 6ba49bd375df..dc330a8ee2f2 100644
@@ -1557,7 +1557,10 @@ static ssize_t charge_control_end_threshold_show(struct device *device,
 						 struct device_attribute *attr,
 						 char *buf)
 {
-	return sysfs_emit(buf, "%d\n", charge_end_threshold);
+	if ((charge_end_threshold >= 0) && (charge_end_threshold <= 100))
+		return sysfs_emit(buf, "%d\n", charge_end_threshold);
+
+	return -ENODATA;
 }
 
 static DEVICE_ATTR_RW(charge_control_end_threshold);
@@ -1580,11 +1583,11 @@ static int asus_wmi_battery_add(struct power_supply *battery, struct acpi_batter
 		return -ENODEV;
 
 	/* The charge threshold is only reset when the system is power cycled,
-	 * and we can't get the current threshold so let set it to 100% when
-	 * a battery is added.
+	 * and we can't read the current threshold, however the majority of
+	 * platforms retains it, therefore signal the threshold as unknown
+	 * until user explicitly sets it to a new value.
 	 */
-	asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
-	charge_end_threshold = 100;
+	charge_end_threshold = -1;
 
 	return 0;
 }
maintainer
#12 lore raw
In reply to Denis Benato
Quoted 8 lines · Denis Benato

Users are complaining for the battery limit being reset at 100% during the boot process while the general consensus appears to not apply unsolecited hardware changes, therefore stop resetting the battery charge limit at boot and return -ENODATA on charge_end_threshold to signal for an unknown limit.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86: asus-wmi: do not enforce a battery charge threshold

      commit: 186bf9031666602d61b40832181b6b6fdc3ba4dc

--
i.