Page MenuHomeFreeBSD

Support post-2015 Lenovo models in acpi_ibm / support keyboard backlight (also led(4)) / support micmute led(4)
Needs ReviewPublic

Authored by grembo on Jan 29 2018, 2:22 AM.

Details

Summary

More recent Lenovos like the T460s, T470s, T560s etc.
provide new hotkeys ids (LEN0268 instead of LEN0068)
and a newer version of the HKEY interface (0x200
instead of 0x100, as provided over the MHKV function).

This change allows detection and initialization of these
machines. It doesn't add support for the lenovo adaptive
keyboard, but allows this as a future change.

Tested on a T470s, some of the features work, e.g.
key events for most fn+Fx combinations over devd
and mute sound/detect mute. Other features
like lcd_brightness don't work, but are supported
over acpi_video anyway.

This also adds support for controlling the keyboard backlight found in newer lenovo models,
including support for the led(4) interface.

Test Plan
kldload acpi_ibm
# try various features...

sysctl dev.acpi_ibm.0.kbd_backlight=2
morse -l "SOS" >/dev/led/kbd_backlight
sysctl dev.acpi_ibm.0.kbd_backlight_ledon=2

sysctl dev.acpi_ibm.0.micmute_led=1
sysctl dev.acpi_ibm.0.micmute_led=2
morse -l "SOS" >/dev/led/micmute
echo "0" >/dev/led/micmute

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 14954
Build 15066: arc lint + arc unit

Event Timeline

grembo created this revision.Jan 29 2018, 2:22 AM
grembo updated this revision to Diff 38655.EditedJan 30 2018, 1:22 AM

Add support for controlling the keyboard backlight found in newer lenovo models.

Backlight can be read/set using

dev.acpi_ibm.0.kbd_backlight

Support the led(4) interface to control the keyboard
backlight

/dev/led/kbd_backlight

Backlight levels to be applied by on and off states when using the led
interface can be configured by setting

dev.acpi_ibm.0.kbd_backlight_ledoff
dev.acpi_ibm.0.kbd_backlight_ledon

Example use:

echo "f1" >/dev/led/kbd_backlight
echo "1" >/dev/led/kbd_backlight 
echo "0" >/dev/led/kbd_backlight
grembo retitled this revision from Support post-2015 Lenovo models in acpi_ibm to Support post-2015 Lenovo models in acpi_ibm / support keyboard backlight (also led(4)).Jan 30 2018, 1:25 AM
grembo edited the summary of this revision. (Show Details)
grembo edited the test plan for this revision. (Show Details)

Please note that man page changes are pending, but will be added to the review before committing any changes.

mmokhi added a subscriber: mmokhi.Feb 2 2018, 12:15 PM
freebsd_textmail.me accepted this revision.EditedFeb 3 2018, 6:19 PM

I've tested the patch on a Lenovo x260 and according to the testplan. It works nicely.

Tested interfaces:
dev.acpi_ibm.0.kbd_backlight_ledoff {0,1,2}
dev.acpi_ibm.0.kbd_backlight_ledon {0,1,2}
dev.acpi_ibm.0.kbd_backlight {0,1,2}
/dev/led/kbd_backlight {0,1}

This revision is now accepted and ready to land.Feb 3 2018, 6:19 PM

Looks and works OK for old (0x100 protocol) ThinkPad.
No new regression on my T420. (Known-not-working and dangerous functions like suspend/resume are untested.)
Not marking as "Accepted" as I don't have newer ThinkPads having 0x200 protocol and no knowledges for 0x200 protocol.
So I just reviewed and tested fallback (to 0x100 protocol) codes.

No regression on an old (0x100 protocol) ThinkPad S440 (produced around 2013). Only volume, keyboard backlight and Pause Fn keys were working before the patch and still do.

grembo edited the summary of this revision. (Show Details)Feb 9 2018, 11:21 AM
grembo edited the test plan for this revision. (Show Details)
grembo updated this revision to Diff 39085.

Add support for controlling micmute LED

This revision now requires review to proceed.Feb 9 2018, 11:21 AM
grembo retitled this revision from Support post-2015 Lenovo models in acpi_ibm / support keyboard backlight (also led(4)) to Support post-2015 Lenovo models in acpi_ibm / support keyboard backlight (also led(4)) / support micmute led(4).Feb 9 2018, 11:23 AM
grembo edited the test plan for this revision. (Show Details)
grembo edited the test plan for this revision. (Show Details)

I'll test this on old and hopefully new thinkpads

sys/dev/acpi_support/acpi_ibm.c
1021

extra whitespace here

1028

and here

No regressions observed on my Thinkpad X220 with this change.
Changing dev.acpi_ibm.0.volume has no effect, but did not work before either.

Testing with this change on X260 (LEN0068, MHKV 0x0200 AFAICT) I see warnings like:

# sysctl dev.acpi_ibm.0.kbd_backlight=0
ACPI Warning: \_SB.PCI0.LPC.EC.HKEY.MLCG: Insufficient arguments - Caller passed 0, method requires 1 (20180209/nsarguments-383)
ACPI Warning: \_SB.PCI0.LPC.EC.HKEY.MLCG: Insufficient arguments - Caller passed 0, method requires 1 (20180209/nsarguments-383)
dev.acpi_ibm.0.kbd_backlight: 1ACPI Warning: \_SB.PCI0.LPC.EC.HKEY.MLCG: Insufficient arguments - Caller passed 0, method requires 1 (20180209/nsarguments-383)
 -> ACPI Warning: \_SB.PCI0.LPC.EC.HKEY.MLCG: Insufficient arguments - Caller passed 0, method requires 1 (20180209/nsarguments-383)
ACPI Warning: \_SB.PCI0.LPC.EC.HKEY.MLCG: Insufficient arguments - Caller passed 0, method requires 1 (20180209/nsarguments-383)
0
#

Keyboard backlight control works despite the warnings. I haven't tested this machine on an unpatched kernel. echo 1 > /dev/led/micmute has no effect.

sys/dev/acpi_support/acpi_ibm.c
557

s/MKHV/MHKV/

Testing with this change on X260 (LEN0068, MHKV 0x0200 AFAICT) I see warnings like:

# sysctl dev.acpi_ibm.0.kbd_backlight=0
ACPI Warning: \_SB.PCI0.LPC.EC.HKEY.MLCG: Insufficient arguments - Caller passed 0, method requires 1 (20180209/nsarguments-383)
ACPI Warning: \_SB.PCI0.LPC.EC.HKEY.MLCG: Insufficient arguments - Caller passed 0, method requires 1 (20180209/nsarguments-383)
dev.acpi_ibm.0.kbd_backlight: 1ACPI Warning: \_SB.PCI0.LPC.EC.HKEY.MLCG: Insufficient arguments - Caller passed 0, method requires 1 (20180209/nsarguments-383)
 -> ACPI Warning: \_SB.PCI0.LPC.EC.HKEY.MLCG: Insufficient arguments - Caller passed 0, method requires 1 (20180209/nsarguments-383)
ACPI Warning: \_SB.PCI0.LPC.EC.HKEY.MLCG: Insufficient arguments - Caller passed 0, method requires 1 (20180209/nsarguments-383)
0
#

Keyboard backlight control works despite the warnings. I haven't tested this machine on an unpatched kernel. echo 1 > /dev/led/micmute has no effect.

@emaste Thanks for testing, that's quite interesting. Could you please send me your DSDT (acpidump -dt | gzip -c9 > foo.asl.gz)?

On my T470S the following commands work (I changed LPCB to LPC, as this seems to be correct on your machine), maybe you could test those too to verify:

kldload acpi_call
# mute sound
/usr/local/sbin/acpi_call -p \\_SB.PCI0.LPC.EC.HKEY.SSMS -i1
# set mic led (on F4 on my machine, i2 == on, i3 == blink)
/usr/local/sbin/acpi_call -p \\_SB.PCI0.LPC.EC.HKEY.MMTS -i2
# set keyboard backlight
/usr/local/sbin/acpi_call -p \\_SB.PCI0.LPC.EC.HKEY.MLCS -i2

Also, it would be interesting to see the output of

# get kbd backlight level
/usr/local/sbin/acpi_call -p \\_SB.PCI0.LPC.EC.HKEY.MLCG
# as your machine probably complains about that one, try this
/usr/local/sbin/acpi_call -p \\_SB.PCI0.LPC.EC.HKEY.MLCG -i1
grembo marked 3 inline comments as done.Feb 11 2018, 11:35 AM
grembo updated this revision to Diff 39173.

Fix typo and extra whitespace

Here's the acpidump -dt:

I'm just booting this machine off a FreeBSD image on a USB stick and don't have any packages on here at the moment, but will try to test with acpi_call at some point.

miwi added a subscriber: miwi.Nov 2 2018, 7:23 AM

Quick info, this works also fine on t480 (2018 model), btw this patch needs a rebase after rev: 300421 and rev: 335304.

lme added a subscriber: lme.Jan 15 2019, 4:04 PM
lme added a comment.Jan 15 2019, 4:07 PM

/* Old pre-0x100 versions of the hkey interface (MHKV)

  • take no parameter to determine the hotkey mask. Newer models
  • (post-2015, like T460, T470s, Carbon X1) take one integer parameter

Does that mean that this patch also adds support for older keyboard LEDs like on the T430 / X230?

pi added a subscriber: pi.Apr 24 2019, 6:37 PM
seanc added a subscriber: seanc.Apr 27 2019, 6:16 PM

Can someone summarize what's preventing this patch from being committed?

grembo added a comment.May 2 2019, 7:16 PM

Can someone summarize what's preventing this patch from being committed?

@seanc It's been a while... so basically I hacked this together (I don't think I ever managed to get the man page changes into review or even done). It works totally fine on my T470S, but if I remember correctly something was wrong with detecting if certain features are supported - my suspicion was that @emaste's Lenovo provided an ACPI function with the same name, but different parameters.

In other words: This works, but it sometimes detects a feature where it shouldn't be, which also leads to (harmless) error messages. We could still commit it, I'm happy to write some documentation. We can then refine it for older models based on input from users.

There's Bugzilla PR 229120 ("Add support for newer Thinkpad models with id LEN0268") and a commit rS346647 which overlaps with this patch.