TLP icon indicating copy to clipboard operation
TLP copied to clipboard

Battery care support for Acer laptops - how to re-engineer?

Open wojpawlik opened this issue 3 years ago • 32 comments

I own Acer SF314-43. What tools can I use to investigate how Acer Care Center communicates with hardware?

wojpawlik avatar Nov 06 '21 17:11 wojpawlik

I have no idea, but I leave it open here, in case someone who reads here knows it.

linrunner avatar Nov 07 '21 16:11 linrunner

@wojpawlik Hey, I have the exact same laptop! I'm running a windows/void linux dualboot and I have a curious observation to report. I limited the battery charging threshold to 80% using the acer care center and it works exactly as advertised on windows. But somehow, this setting persists even when running linux! So now, the battery stops charging at 80 even inside linux. Acer care center is just a normal windows program but strangely its setting survives across different operating systems just as if it were a bios setting.

It would be great if this gets working in tlp so people won't have to set up a dualboot just to limit the battery charge percentage. Here's hoping someone figures this one out. Good luck folks!

dxvsh avatar Feb 28 '22 13:02 dxvsh

Just to chime in, @dxmuses. Setting a battery charging limit in the Acer Care Center and then booting into linux worked for me as well. But at some time, it just stopped charging even when it was below 80%. This was actually really annoying since windows wanted to update and did not boot because my battery was below 25%, but I also couldn't charge it. So this method can actually be sort of "dangerous". Another reason that getting it to work in TLP would be nice.

Bartvelp avatar Mar 01 '22 10:03 Bartvelp

@Bartvelp That sounds rough. Sorry if I landed you in some trouble! In my case though, I've had this setting turned on for about a week now and its been working fine between linux and windows so far. There could be so many variations between your setup and mine that its hard to pinpoint what could be causing this strange behavior [eg: might be a different (bios/kernel/windows version/some other setting?)].

But you're totally right, it'd be much safer and cleaner to have this working in tlp. Someday, I hope!

dxvsh avatar Mar 01 '22 12:03 dxvsh

Hi guys, I have an Acer Nitro 5. I would really need the plugin for this laptop. I hope someone can figure out how to do this.

balthier82 avatar Mar 03 '22 06:03 balthier82

Please save your declarations of wanting to have. They do nothing at all here in the issue. One of you Acer owners has to go and program a corresponding extension of the kernel driver. Writing the plugin is then trivial.

linrunner avatar Mar 06 '22 11:03 linrunner

Please save your declarations of wanting to have. They do nothing at all here in the issue. One of you Acer owners has to go and program a corresponding extension of the kernel driver. Writing the plugin is then trivial.

I have implemented an experimental kernel driver for Acer's WMI battery control interface. So far I have only tested it on a Swift 3, but I would expect that Acer uses the same interface on other laptops as well. If you give it a try, please let me know if it works on your system.

frederik-h avatar Jun 03 '22 04:06 frederik-h

@frederik-h Great. It's nice when the light appears at the end of the tunnel. I suggest you include a note in your driver documentation about the percentage where charging stops when health mode is active. I will need the value for the TLP docs as well.

Are you planning to submit the driver for the mainline kernel?

linrunner avatar Jun 03 '22 06:06 linrunner

@frederik-h Great. It's nice when the light appears at the end of the tunnel. I suggest you include a note in your driver documentation about the percentage where charging stops when health mode is active. I will need the value for the TLP docs as well.

I will add it. It stops at 79% on my system. I could not find any methods to modify this threshold. From the Acer Care Center screenshots and documentation that I have seen, I assume that the threshold is fixed. I have no Windows installation to verify the actual settings that are available in the Care Center.

Are you planning to submit the driver for the mainline kernel?

Yes, but it would be great to test it on some more systems beforehand. I am also a bit unsure if it wouldn't be better to offer the settings separately for all batteries found in the system. The WMI methods take the battery index as an argument, but all invocations of this method that I could find in the Care Center binaries seemed to call it for the first battery only. Hence, I decided to implement it like this as well.

frederik-h avatar Jun 03 '22 08:06 frederik-h

Yes, but it would be great to test it on some more systems beforehand.

Just tested it out on a Acer Aspire 5 A515-45G-R5A1, works like a charm.

I will add it. It stops at 79% on my system. I could not find any methods to modify this threshold. From the Acer Care Center screenshots and documentation that I have seen, I assume that the threshold is fixed. I have no Windows installation to verify the actual settings that are available in the Care Center.

Stops at 79% for me as well. I do have a windows install and can confirm the battery care toggle is modified when toggling using your kernel driver. There is no way to modify the threshold in Acer Care Center, as you already mentioned.

Thanks for your work @frederik-h , I am interested as to how you reverse engineered the care center, any plans on disclosing that?

Bartvelp avatar Jun 05 '22 11:06 Bartvelp

OK. I assume the charge threshold is 80% and the 79% is due to rounding.

Edit: confirmed by this Acer support article.

linrunner avatar Jun 05 '22 16:06 linrunner

Yes, but it would be great to test it on some more systems beforehand.

Just tested it out on a Acer Aspire 5 A515-45G-R5A1, works like a charm.

I will add it. It stops at 79% on my system. I could not find any methods to modify this threshold. From the Acer Care Center screenshots and documentation that I have seen, I assume that the threshold is fixed. I have no Windows installation to verify the actual settings that are available in the Care Center.

Stops at 79% for me as well. I do have a windows install and can confirm the battery care toggle is modified when toggling using your kernel driver. There is no way to modify the threshold in Acer Care Center, as you already mentioned.

Thanks for your work @frederik-h , [...]

Thanks for the feedback @Bartvelp and @linrunner!

I am interested as to how you reverse engineered the care center, any plans on disclosing that?

There exists some useful information to get you started with WMI driver developement: This old LWN article and this Ubuntu Wiki page. There you will learn that, in order to control some of the features of your laptop, you want to understand what's inside the MOF buffer in the APCI DSDT tables. The article and the wiki page claim that those binary buffers cannot be decompiled, but fortunately this is not/no longer true: You can use the bmfdec tool to decompile the buffers on Linux. I fear that I cannot share the decompiled MOF files for copyright reasons. Decompiling the MOF will provide you with interesting information about the available WMI methods, events etc.. This way I found WMI methods that looked promising, but it still was not clear how to call the methods correctly. I noticed that the Acer Care Center is a .Net application and .Net code can usually by decompiled to a quite readable form. I used ilspy which can be build with .Net Core on linux (the command line part of it) to decompile the libraries and executables. This way I learned about the correct way to call the WMI methods.

frederik-h avatar Jun 06 '22 18:06 frederik-h

The WMI methods take the battery index as an argument, but all invocations of this method that I could find in the Care Center binaries seemed to call it for the first battery only. Hence, I decided to implement it like this as well.

@frederik-h : On other laptops with a fixed threshold, it seems to apply to all batteries. For Lenovo Non-ThinkPads, LG, Samsung and Sony I just assumed so when creating their plugins, see BC Vendor Specifics. Apart from ThinkPads, devices with multiple batteries seem to be quite rare anyway.

Btw: how can I check for an Acer laptop: probing for the /sys/devices/platform/acer-wmi/ directory?

linrunner avatar Jun 07 '22 08:06 linrunner

The WMI methods take the battery index as an argument, but all invocations of this method that I could find in the Care Center binaries seemed to call it for the first battery only. Hence, I decided to implement it like this as well.

@frederik-h : On other laptops with a fixed threshold, it seems to apply to all batteries. For Lenovo Non-ThinkPads, LG, Samsung and Sony I just assumed so when creating their plugins, see BC Vendor Specifics. Apart from ThinkPads, devices with multiple batteries seem to be quite rare anyway.

Thanks, this confirms that I probably do not need to worry about this now.

Btw: how can I check for an Acer laptop: probing for the /sys/devices/platform/acer-wmi/ directory?

Do you mean in general or with the goal of using the sysfs interface provided by this driver? In the latter case, I would suggest to probe for the /sys/bus/wmi/drivers/acer-wmi-battery/health_mode directly. There are certainly Acer laptops out there which do not provide the battery charge limit.

frederik-h avatar Jun 07 '22 19:06 frederik-h

@frederik-h : I would like to first detect if it is an Acer (to load the plugin) and then if health mode is present (e.g. for display in tlp-stat -b).

Have you thought about adding the functionality to acer-wmi instead of creating your own driver?

linrunner avatar Jun 08 '22 05:06 linrunner

I'm getting make[1]: *** /lib/modules/5.17.9-300.fc36.x86_64/build: No such file or directory. Stop. when trying to build the module on Fedora 36, despite having kernel-headers installed.

wojpawlik avatar Jun 08 '22 14:06 wojpawlik

@frederik-h : I would like to first detect if it is an Acer (to load the plugin) and then if health mode is present (e.g. for display in tlp-stat -b).

Right, probing for the acer-wmi directory seems reasonable to me then, although the module seems (according to the comments and quirks-handling in its source) to support some laptops by other vendors as well.

Have you thought about adding the functionality to acer-wmi instead of creating your own driver?

Yes, but I have implemented it for myself in the first place and doing a standalone module seemed easier to me. Since there is some interest in the module, I will try to upstream it time permits. If it will be necessary to integrate it into acer-wmi, this should be easily possible, given how simple the module is. One potential advantage is that sysfs files could live under the same path as the other Acer-related files.

frederik-h avatar Jun 09 '22 06:06 frederik-h

@frederik-h : To be honest, I don't really want to release the Acer plugin until the feature is in the mainline kernel. Otherwise, too much support for the external kernel module ends up here (see https://github.com/linrunner/TLP/issues/596#issuecomment-1150020853). I've had this experience with ThinkPads for > 10 years and I'm not going to have that again.

I'll think about it :).

linrunner avatar Jun 09 '22 16:06 linrunner

If you give it a try, please let me know if it works on your system.

Thanks @frederik-h, the driver is working on my Acer Aspire 1 A114-33-C4FF, stops as well at 79%. Tested on Manjaro (5.15.60-1).

MatteoGalletta avatar Aug 13 '22 19:08 MatteoGalletta

I confirm the driver stopping the charging at 79% on Acer Swift SF314-43. Any plans on upstreaming?

wojpawlik avatar Aug 20 '22 14:08 wojpawlik

@frederik-h the driver works well on my Acer Nitro 5, AN515-44. Stops charging at 79%.

Sasikuttan2163 avatar Sep 09 '22 10:09 Sasikuttan2163

On Acer Aspire 7 running linux 5.19.7-1-MANJARO, I am getting permission denied error

sudo echo 1 > /sys/bus/wmi/drivers/acer-wmi-battery/health_mode
zsh: permission denied: /sys/bus/wmi/drivers/acer-wmi-battery/health_mode

re-ynd avatar Sep 17 '22 14:09 re-ynd

On Acer Aspire 7 running linux 5.19.7-1-MANJARO, I am getting permission denied error

sudo echo 1 > /sys/bus/wmi/drivers/acer-wmi-battery/health_mode
zsh: permission denied: /sys/bus/wmi/drivers/acer-wmi-battery/health_mode

It's not related to the script itself, I faced this problem before and it's related to the shell sudo behaviour, check this

MatteoGalletta avatar Sep 17 '22 14:09 MatteoGalletta

Ah perfect! That was dumb on my part. Thanks! It works on Acer Aspire 7 running 5.19.7-1-MANJARO.

re-ynd avatar Sep 17 '22 15:09 re-ynd

@frederik-h thank you, also working on Acer Predator Helios 300 (2021 model)

tarruda avatar Sep 20 '22 12:09 tarruda

I tried this on an Aspire 5 A515-45 and a Swift 1 SF113-31.

echo 1 > /sys/bus/wmi/drivers/acer-wmi-battery/health_mode does not give an error, but cat /sys/bus/wmi/drivers/acer-wmi-battery/health_mode returns 0 (before and after the echo).

So I suppose it doesn't work. But as this device has never seen Windows, therefore I cannot tell if the hardware is supposed to support this (cannot check using "Acer Care Center").

mnlipp avatar Nov 13 '22 11:11 mnlipp

I tried this on an Aspire 5 A515-45 and a Swift 1 SF113-31.

echo 1 > /sys/bus/wmi/drivers/acer-wmi-battery/health_mode does not give an error, but cat /sys/bus/wmi/drivers/acer-wmi-battery/health_mode returns 0 (before and after the echo).

So I suppose it doesn't work. But as this device has never seen Windows, therefore I cannot tell if the hardware is supposed to support this (cannot check using "Acer Care Center").

I have opened issue frederik-h/acer-wmi-battery#9 for further discussion on this.

frederik-h avatar Nov 14 '22 06:11 frederik-h

@frederik-h Tried it on Acer Extensa EX215-22-R2H8. Since my OS is Windows (and for some unknown reasons battery care cannot be enabled on my machine here) I've booted into Ubuntu 20.04 from USB stick and enabled health mode with your module. After booting back into Windows the battery discharged to 80% and is still there. Thank you!

Dmivaka avatar Dec 14 '22 22:12 Dmivaka

Worked like a charm on Acer Aspire A315-23G

PedroVNasc avatar Mar 03 '23 11:03 PedroVNasc

I'm getting make[1]: *** /lib/modules/5.17.9-300.fc36.x86_64/build: No such file or directory. Stop. when trying to build the module on Fedora 36, despite having kernel-headers installed.

I had the same issue because I installed the kernel-devel package from dnf, which was for another kernel version. I got the correct version from here where you first have to find your kernel, for you that would be 5.17.9-300.fc36, and then the correct devel, installing that should fix that issue.

If you have secure boot enabled you'll also encounter an issue related to keys, which you can read more about here , I haven't gotten to solving that myself yet.

Vinz-S avatar Aug 09 '23 22:08 Vinz-S