New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Battery protection and fn-lock support #8
Comments
@nekr0z can you please try the newly updated module? I've added battery protection, fn-lock. I still need to find a way of distinguishing if a laptop supports these features or not. |
I'd love to, but I'm on Debian (kernel 4.19), and this is very much my production laptop, so simply wiping the system and getting fresh Arch is not something I'd consider. You may have just tempted me to give compiling 5.0 a try, but I have never done it all from scratch (I usually rely on packages to patch and recompile kernel), so I need some time to figure it all out. |
@nekr0z you could try booting from usb. As long as you're using kernel >= 5.0 you should be good. |
Ok, 5.0.2 is already in Debian experimental, why not give it a try while I'm at it... Sweet Discordia, touchpad patching again!.. Alright, ready. Aaaaaand... here we go!
Am I missing something? Because after |
Instead try
Don't install! |
You meant huawei-wmi.ko, right?
Nothing. |
Yeah my bad. What about dmesg, do you get any output? |
|
Could you try this and see if you get any messages in dmesg. |
Yep.
Mic led started working immediately. Fn-lock state can be read and is accurate (althought can't be written, do you support some way of setting these variables too?) |
Great! You need root to write into these files.
Aha! I see why. In your model, these data are off (location wise) by one byte. Idk how this would be handled correctly. But setting these values should work. setting it to 0-100 disables protection. |
Setting them to 0-100 indeed disables protection. Setting them to any other value pair does nothing at all. |
Oh! I see why. It's the same problem because the driver gets the current thresholds values before it updates them. This is there because the driver uses two sysfs attributes (files) to control the thresholds. But the way WMI controls these values in Huawei laptops is using one method passing both low and high values. I will change it from two attributes to one containing both low and high thresholds and work on a workaround of retrieving the correct values from WMI. |
Keep me posted, I'll be glad to test. And thank you so much for the mic led! (and I guess thanks for moving me to kernel 5, too ;-) Do you envision any way to eventually make it possible to set those values as non-privileged user? You might have already checked up my crude attempt on UI, and that currently requires a lot of hoop-jumping that is not too much user-friendly... |
I like that! You could also create a very simple UI, along with sys applet, that access those values under /sys. You could use a udev rule to change the permission of these values so that a particular group ex. |
That will definitely be my next step as soon as you get battery protection settings sorted out and "API" stabilized.
I like it. A separate group, like
Totally. No, the udev+group approach is much more sane. And IMHO the group needs to be something separate, not general things like |
@aymanbagabas I just wanted to check this "by the book", your solution to change values using:
Always throws me an invalid argument with "tee" as shown here:
|
I've updated the driver hopefully it resolves this issue. Please take your time testing it while monitoring
Bear in mind that I've combined the two attributes responsible for charging into one. |
@aymanbagabas At least for my device, it seems to be working. Micmute led still doesn't turn on/off (in case the fix in #7 is included in this update) FN Lock State I can confirm works perfectly fine with both 0 and 1 values. I was in 100% and set the threshold to 0-80, I'm plugged in but discharging, I will keep playing with the values and see if anything doesn't work as intended. if it helps you at all, here is the dmesg of when I loaded the driver:
|
@aymanbagabas First of all, on MateBook 13 it works. I mean, everything works as expected. Tested fnlock, tested various thresholds. I hope these lengthy dmesg outputs I see appearing upon every interaction (both gets and sets) are just for debugging and will be switched off in release, right?
But no, no errors or warnings in dmesg. Great work, you're awesome! |
So I played with some values. 0-80= still keeps discharging below 80 If doing ranges like 70-90, 40-70 and so on (which I believe is how they were presented in PC Manager) is the intended use case, then yes, it is working as intended no problem. hope I could be of help! Thank you for your hard work! |
Of course! There just there for debugging. Mainly to see returned buffer from bios since each model has a different implementation. |
The thing is, setting the thresholds to 0-100 disables it so I would assume that it's not working because you have your low value set to 0. Try 1-80 and see if anything changes. Generally, avoid setting the low value to 0 and high to 100. |
@aymanbagabas just tried 1-80, it indeed works. |
I updated my UI applet to work with the new |
By the way, there's one thing I've been noticing; I'm not sure where this bug is rooted. Every time I set fnlock state, no matter on or off (either by setting register directly, or by Huawei-WMI interface), my keyboard layout switching stops working, and I need to reapply settings in KDE again (I believe KDE relies on |
@nekr0z I'm more than happy to test the applet, but I notice the script it is based on (according to the readme) is not the solution discussed here, I take it is just outdated, would it be possible for you to explain me how to actually get it working? Would you also mind telling me what do you mean by keyboard layout switching and how you do it? I'm also on KDE and I can check if my installation also suffers from it. |
I'm writing a readme update right now, will have new readme and new packaged release packaged in 10-15 minutes ;)
It's the thing you do when you need to type in languages that don't use latin letters (such as Hebrew, Chinese, Russian etc). In this case you usually have several (well, at least two, for your language and English) keyboard modes (called 'layouts') and some hotkey to switch between them (most common are I found that toggling Fn-Lock messes with layouts system, making it impossible to switch layouts until I go to settings (where everything looks just fine), change something, change it back again and "Apply". |
I have my layout switch set to |
KDE is a little different in that it has two separate systems for layout changing. One is KDE proper, and that one sets CapsLock as you described, another one is I believe somewhat rooted in X.org ways of handling this, and that one automatically remaps CapsLock behaviour to Shift+CapsLock if CapsLock is used for layout switching (the same as in the good old days ten years ago when we set all this behaviour somewhere in xorg.conf). Anyway, both these systems occasionally lose layout switching altogether, and that is definitely connected with Fn-Lock switching in some way, but I have yet to nail it down to reproduce reliably. |
@nekr0z So there is an edge case I just stumbled on after I used your applet. I just noticed that on my model setting the battery to 0-100 doesn't particularly set the thresholds. Remember the 0xc0 that corresponds to the mode being on/off. That's what it's doing in my model. Matebook D is not affected, it actually sets whatever values given even if they were off limit which is kinda interesting. Here is the code from DSDT
When it gets 0-100, it doesn't set the thresholds values, instead it turns it off. Notice STCP & SOCP are low/high thresholds. I guess a workaround for this is to check the values if they're this case 0-100, it sets 0 and 100 in two separate calls. This would eliminate the problem of getting low/high values even though it's disabled. |
What the applet is currently doing is interpret 0-x (where x<=100) as protection off, and setting 0-100 when asked to switch the protection off. Is this sane behaviour for this edge case, or is there something I need to change? |
Exactly, 0-100 is sane behavior. But with my machine, 0-100 doesn't change the thresholds, it switches the protection off. My workaround was to set the thresholds to 0-0 before setting it to 0-100. But for some reason, this doesn't work unless I have a delay between the two functions. The first call to the function gets ignored it might be something with scheduling, I have to dig in more. |
Yeah, from what you say it looks like it should better be handled by the driver. Alternatively, you could add some marker for your model in Keep me posted one way or the other, and keep up awesome work! |
That's probably what's happening, according to this.
Used |
|
Yeah that's supposed to be wmi_mutex
Edit: actually that line is redundant and not needed.
…On Sat, Apr 27, 2019, 2:10 AM Evgeny Kuznetsov ***@***.***> wrote:
huawei-wmi.c:530:14: error: ‘cmd_mutex’ undeclared (first use in this function); did you mean ‘wmi_mutex’?
mutex_init(&cmd_mutex);
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAYKJ3CFWN7EFY35R24MUBDPSPU6RANCNFSM4HGYQTGA>
.
|
With that line removed it compiles and works. The only caveat I see is that setting battery protection to OFF takes some time (but happens eventually), so that the applet updates BP status (top of the menu) before it is set, so it's displaying it wrong. Do you have a guesstimate of how long a delay is generally expected, so I could put a |
I don’t have an estimated time but I would say 500ms to 1s is more than enough since reading the file many times generates a lot of interrupts. That’s actually the problem the driver has with this case. You could read the status only once when the applet is accessed. |
I'd rather not generate reads every time applet is accessed (and it is not trivial with the library I use anyway), so I'll go the |
Did some testing, never got thresholds 0-100 set in under 850 ms, so 900 ms interval it is. Commit in |
That's actually a problem. The driver should be able to handle multiple calls simultaneously without skipping any call. I'll work on implementing some sort of a wait queue for any call with a short delay after each call. The applet shouldn't worry about any delays because that's the driver's responsibility. |
Makes sense. I'll revert the commit as soon as you sort it out, leave it in for now just in case you don't. You've done impressive work anyway, I think I'm speaking for all the community when I say I admire it. |
Thank you! I wouldn't get this far if it wasn't for you guys. |
@nekr0z please try this one. The driver now has a Turning BP off always has a delay. Now when you think about it, the user would not stay and watch the values get updated in the file. In this case, a short delay wouldn't matter and is not noticeable. So the way I see it with the applet is to get the status once the user accesses the applet. Once an item is clicked, the menu should disappear and a command is executed. So the applet would get the status only once at the beginning. |
Yes, I got the idea several comments ago. The problem is the library I'm using for system tray is a very basic one and doesn't have appletClick events, only itemClick ones.
That's for sets, not gets, right? Because what I'm seeing is
That |
@aymanbagabas Just wanted to make things clear: while obviously disturbing, this issue is far from being a show-stopper, and I have already implemented a workaround in the applet, so if that's the only thing stopping you from making a release, just table it ;) |
I'm trying to get around this using a different/simpler approach. The kernel API has an EmbeddedController API, I'm trying to use that instead of the dirty |
You obviously know these things much deeper than I do, so go ahead and do your magic whichever way you deem proper! ;) |
So I've come to conclude that the driver should be as simple as possible. This means no workqueues, waitqueues, or anything else. This problem only happens with my model (MACH-WX9), right? Still setting it to 0-100 disables BP but it doesn't set these values. This could be fixed using driver quirks which is not implemented yet. Or a possible route is to patch DSDT table but that's not really a solution. Right now, I'll open a new issue for that one and close this since these features are implemented in Thank you for your awesome work @nekr0z @wasakakero |
@aymanbagabas Awesome work, thank you again! I think I'll make waiting for changes to be reported back optional in the applet, so that it can be switched on with a command line flag, since the code is in there anyway. I'll keep following you work in case changes to the applet need to be made in future, and of course feel free to ping me if you need any testing or anything. |
Using Windows Huawei PC Manager, you can enable features like battery protection and reversing the behavior of Fn. These features are 'obviously' missing on Linux. I'm working on integrating these to the driver using WMI calls.
Using WMI is easier than controlling these features using ACPI/EC since most of these devices has the same WMI device driver.
So far, I've seen repetitions when it comes to using WMI calls to control Fn-lock, battery protection/thresholds, and mic led in multiple models including:
I haven't seen that on the older model Matebook X (2017). DSDT/SSDT tables for other models are welcome!
The text was updated successfully, but these errors were encountered: