Bug 229120 - [acpi_ibm] [patch] Add support for newer Thinkpad models with id LEN0268
Summary: [acpi_ibm] [patch] Add support for newer Thinkpad models with id LEN0268
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 11.0-STABLE
Hardware: amd64 Any
: --- Affects Many People
Assignee: freebsd-acpi mailing list
Keywords: patch
Depends on:
Reported: 2018-06-18 18:16 UTC by Ali Abdallah
Modified: 2019-02-07 09:43 UTC (History)
8 users (show)

See Also:

Support newer thinkpads with LEN0268 id (2.58 KB, patch)
2018-06-18 18:16 UTC, Ali Abdallah
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ali Abdallah 2018-06-18 18:16:19 UTC
Created attachment 194370 [details]
Support newer thinkpads with LEN0268 id

The attached patch adds support for newer Thinkpad models. The patch has been tested on a Thinkpad T480, but should work on other models as well.
Comment 1 Poul-Henning Kamp freebsd_committer 2018-08-07 08:48:04 UTC
I tried this patch on my T480 running r336962.

I have not tried the event handling, but the sysctl variables do not seem to report reality (mute, lcd_brightness, thinklight etc...)
Comment 2 Ali Abdallah 2018-08-09 09:11:33 UTC
- Thinklight is reported by the firmware to be present, but turning it on does nothing, probably is a reminiscence of old good Thinkpads! BTW, it behaves the same under Linux.
- lcd_brightness is assumed to be controllable by the driver (the patch does not change that). For instance it fails already to control the brightness on my corebooted x230. This can be adjusted. 
- Sound mute works fine for me. However, mic mute does not mute the microphone, it does only turn on its led. On Linux, if you mute the microphone via the sound card driver, it checks if there is a thinkpad_set_led registered function (by the thinkpad_acpi), and it does turn off/on the mic led for you. 

Event handling works fine for me.

The acpi_ibm driver is clearly unmaintained on FreeBSD. I can make a lot of improvements to it, but unfortunately I have no access to its repository, and going with patches takes ages...
Comment 3 Poul-Henning Kamp freebsd_committer 2018-08-10 06:40:45 UTC
Improvements are most welcome, and yeah, we're a bit slow on the tickets thing, I'll try to keep an eye on it though, seeing that I have a T480 now :-)
Comment 4 Matías Pizarro 2018-11-24 13:55:45 UTC
Hi Ali,

FYI, I included your patch on top of stable/12 and rololed out this kernel on my T480. You can see what I rolled out at https://github.com/rebost/freebsd/tree/feature/acpi_ibm


Sadly, both Fn buttons and sysctl modification via console have no effect.

Neither are the values reported by sysctl dev.acpi_ibm correct

If there is anything I can do to help you fix this, just let me know. Thanks for what you have already done.

All the best,

-- matías

mpizarro@lenovo01:/usr/src $ sudo sysctl dev.acpi_ibm
dev.acpi_ibm.0.handlerevents: NONE
dev.acpi_ibm.0.mic_led: 0
dev.acpi_ibm.0.fan: 1
dev.acpi_ibm.0.fan_level: 0
dev.acpi_ibm.0.fan_speed: 0
dev.acpi_ibm.0.wlan: 1
dev.acpi_ibm.0.bluetooth: 0
dev.acpi_ibm.0.thinklight: 0
dev.acpi_ibm.0.mute: 0
dev.acpi_ibm.0.volume: 0
dev.acpi_ibm.0.lcd_brightness: 0
dev.acpi_ibm.0.hotkey: 2
dev.acpi_ibm.0.eventmask: -5
dev.acpi_ibm.0.events: 1
dev.acpi_ibm.0.availmask: 4294967291
dev.acpi_ibm.0.initialmask: 2056
dev.acpi_ibm.0.%parent: acpi0
dev.acpi_ibm.0.%pnpinfo: _HID=LEN0268 _UID=0
dev.acpi_ibm.0.%location: handle=\_SB_.PCI0.LPCB.EC__.HKEY
dev.acpi_ibm.0.%driver: acpi_ibm
dev.acpi_ibm.0.%desc: IBM ThinkPad ACPI Extras

mpizarro@lenovo01:/usr/src $ sudo sysctl dev.acpi_ibm.0.thinklight=1
dev.acpi_ibm.0.thinklight: 0 -> 0

mpizarro@lenovo01:/usr/src $ sudo sysctl dev.acpi_ibm.0.lcd_brightness=7
dev.acpi_ibm.0.lcd_brightness: 6 -> 7

mpizarro@lenovo01:/usr/src $ sudo sysctl dev.acpi_ibm.0.lcd_brightness=8
dev.acpi_ibm.0.lcd_brightness: 7
sysctl: dev.acpi_ibm.0.lcd_brightness=8: Invalid argument
Comment 5 Ali Abdallah 2018-12-10 13:55:06 UTC
Hi Matías,

The Fn buttons never changed the brightness automatically (even on old already supported Thinkpad models), instead it sends a userspace event to devctl, that is populated by devd. The user typically runs a devd action to change the brightness, and my patch does not change that, see man(4) acpi_ibm. 

Instead, with the patch applied now you get devd events for FN-brightness up/down.

!system=ACPI subsystem=IBM type=\_SB_.PCI0.LPCB.EC__.HKEY notify=0x10
!system=ACPI subsystem=IBM type=\_SB_.PCI0.LPCB.EC__.HKEY notify=0x11

then you can, via a devd action, change the brightness using for example hw.acpi.video.lcd0.brightness. Other keys, which did not work without the patch, now send devd events, such as FN-Wireless, FN-Mic. 

For the brightness part, yes I think something should be done to make the  dev.acpi_ibm.0.lcd_brightness syscalls work again, will post here any progress.
Comment 6 Matías Pizarro 2018-12-10 22:09:12 UTC
Hi Ali,

Thanks for the clarifications and all your great work, that's definitely something I can build upon.
Comment 7 Bojan Petrovic 2019-01-05 12:06:19 UTC
Hi, I applied your patch to CURRENT (r342776) on a T480.

- The Fn + keys from F4 to F12, TAB, p, 4 and MENU send events to devd.
- dev.acpi_ibm.0.mute state reflects the state of F1 LED
- dev.acpi_ibm.0.fan can actually be used to turn the fan on and off
- dev.acpi_ibm.0.fan_speed seems to be measuring fan speed correctly
- dev.acpi_ibm.0.mic_led works as you described.

Thanks for your work, let me know if I can help with this patch in any way.
Comment 8 Diego Casati 2019-01-15 05:53:49 UTC
Hi Ali -

I've applied on a ThinkPad X1 Yoga 2nd gen on 12 RELEASE. 

Can confirm the same information as Bojan.

Awesome work ! Happy to test more as you go along.

Comment 9 Alexey Dokuchaev freebsd_committer 2019-01-22 06:25:24 UTC
(In reply to Ali Abdallah from comment #2)
> The acpi_ibm driver is clearly unmaintained on FreeBSD.  I can make a lot of
> improvements to it, but unfortunately I have no access to its repository, and
> going with patches takes ages...
Unfortunately, most if not all acpi_XXX(4) drivers are unmaintained; FreeBSD definitely needs people like you to help in this area, one of our weakest.  Going with patches (if they are good) would only last until you'd be punished with commit bit for your great work. :-)  Until then, I'm sure existing src committers would gladly help to expedite your patches.