Fix display off hotkey on Asus machines
cover Fix display off hotkey on Asus machines
Asus laptops have a hotkey function on the F7 key to turn the display backlight OFF, labeled with a screen with a X inside, as shown on
https://dlcdnimgs.asus.com/websites/global/products/Xep1ZcSY8dyWXK11/images/keyboard.png
This hotkey worked on very few Asus models, where the EC acts on the backlight and input events are generated only to notify userspace of the backlight status. On these machines the first hotkey press turns the display backlight OFF and notifies the OS with 0x34, which asus-nb-wmi forwards to userspace as KEY_DISPLAY_OFF, and a second press turns it back ON and notifies the OS with 0x33, which asus-nb-wmi forwards to userspace as KEY_DISPLAYTOGGLE. No other keys turn the display backlight back ON, but their input is forwarded normally to the application under focus.
But for the majority of models, the EC actually does not act on the backlight and we simply get a 0x33 notification every time the key is pressed, or alternating values of 0x33 / 0x34. We have confirmed this behavior on the following models: E203NAS, GL553VE, X441NC, X441UVK, X541UVK, X555DG, X555UB, X555UQ, X560UD, X570ZD and X705FD, and the DSDT on these machines and the working one (only confirmed on N552VW) is the same for the query involved here.
After trying to get information from Asus for quite some time on how this works on Windows, we finally recently got a contact that was able to give us a definitive answer and a specification for this feature. According this contact the 0x33 / 0x34 is an old behavior and all newer machines should only be notifying the OS with 0x35 instead, as newer ECs don't control the backlight anymore. When a 0x35 notification is received the OS should act on the display backlight. From the spec (machine-translated from Chinese):
1.4 Fn+F7
Function introduction
After the user presses Fn + F7, the screen will be closed through the Windows API. The user will immediately open the screen with the mouse and keyboard.
The API used can be found in the Sample URL:
https://code.msdn.microsoft.com/windowsdesktop/Coalescable-Timer-Sample-d9da954c
BIOS implementation
Increase Notify code
LCD On: 0x33 (display OSD)
LCD Off: 0x34 (display OSD)
LCD Switch: 0x35 (using API switch)
The behavior on Windows with the ATKACPI driver from Asus installed matches what is described above, with the hotkey turning OFF the backlight of all connected displays with a fading effect, and any cursor input or key press turning the backlight back ON. The key press or cursor input is passed through to the application under focus or under the cursor.
With this information from the spec, a simple analysis of the DSDT (pasted on the first commit of this series) shows that in order to have the firmware notify the OS with 0x35 and have the OS act on the backlight, we need to call WMNB(ASUS_WMI_DEVID_BACKLIGHT==0x00050011, 2) on the _WDG device. Then we can simply map that scan code to the appropriate key code in the driver.
In include/uapi/linux/input-event-codes.h KEY_DISPLAY_OFF is defined as "display device to off state", but it is not actually handled by userspace on a GNOME+Xorg stack. There are also KEY_SCREENSAVER and KEY_SCREENLOCK / KEY_COFFEE. The former seems to be ignored by userspace as well (and its value is higher than 255 so it can't be handled by Xorg IIUC), and the later is mapped to XF86ScreenSaver by Xorg and triggers the lock screen action on GNOME. KEY_SCREENLOCK seems to be what closest matches the behavior described above in a Xorg world. I am not sure if any of this changes with Wayland, so any clarifications in that regard would be greatly appreciated.
João Paulo Rechi Vita (3):
asus-wmi: Tell the EC the OS will handle the display off hotkey
asus-nb-wmi: Map 0x35 to KEY_SCREENLOCK
asus-nb-wmi: Drop mapping of 0x33 and 0x34 scan codes
drivers/platform/x86/asus-nb-wmi.c | 3 +-- drivers/platform/x86/asus-wmi.c | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.19.1
PATCH 1/3 asus-wmi: Tell the EC the OS will handle the display off hotkey
In the past, Asus firmwares would change the panel backlight directly through the EC when the display off hotkey (Fn+F7) was pressed, and only notify the OS of such change, with 0x33 when the LCD was ON and 0x34 when the LCD was OFF. These are currently mapped to KEY_DISPLAYTOGGLE and KEY_DISPLAY_OFF, respectively.
Most recently the EC on Asus most machines lost ability to toggle the LCD backlight directly, but unless the OS informs the firmware it is going to handle the display toggle hotkey events, the firmware still tries change the brightness through the EC, to no effect. The end result is a long list (at Endless we counted 11) of Asus laptop models where the display toggle hotkey does not perform any action. Our firmware engineers contacts at Asus were surprised that there were still machines out there with the old behavior.
Calling WMNB(ASUS_WMI_DEVID_BACKLIGHT==0x00050011, 2) on the _WDG device tells the firmware that it should let the OS handle the display toggle event, in which case it will simply notify the OS of a key press with 0x35, as shown by the DSDT excerpts bellow.
Scope (_SB)
{
(...)
Device (ATKD)
{
(...)
Name (_WDG, Buffer (0x28)
{
/* 0000 */ 0xD0, 0x5E, 0x84, 0x97, 0x6D, 0x4E, 0xDE, 0x11,
/* 0008 */ 0x8A, 0x39, 0x08, 0x00, 0x20, 0x0C, 0x9A, 0x66,
/* 0010 */ 0x4E, 0x42, 0x01, 0x02, 0x35, 0xBB, 0x3C, 0x0B,
/* 0018 */ 0xC2, 0xE3, 0xED, 0x45, 0x91, 0xC2, 0x4C, 0x5A,
/* 0020 */ 0x6D, 0x19, 0x5D, 0x1C, 0xFF, 0x00, 0x01, 0x08
})
Method (WMNB, 3, Serialized)
{
CreateDWordField (Arg2, Zero, IIA0)
CreateDWordField (Arg2, 0x04, IIA1)
Local0 = (Arg1 & 0xFFFFFFFF)
(...)
If ((Local0 == 0x53564544))
{
(...)
If ((IIA0 == 0x00050011))
{
If ((IIA1 == 0x02))
{
^^PCI0.SBRG.EC0.SPIN (0x72, One)
^^PCI0.SBRG.EC0.BLCT = One
}
Return (One)
}
}
(...)
}
(...)
}
(...) }
(...)
Scope (_SB.PCI0.SBRG.EC0)
{
(...)
Name (BLCT, Zero)
(...)
Method (_Q10, 0, NotSerialized) // _Qxx: EC Query
{
If ((BLCT == Zero))
{
Local0 = One
Local0 = RPIN (0x72)
Local0 ^= One
SPIN (0x72, Local0)
If (ATKP)
{
Local0 = (0x34 - Local0)
^^^^ATKD.IANE (Local0)
}
}
ElseIf ((BLCT == One))
{
If (ATKP)
{
^^^^ATKD.IANE (0x35)
}
}
}
(...)}
--- drivers/platform/x86/asus-wmi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +2 -1
@@ -2150,7 +2150,8 @@ static int asus_wmi_add(struct platform_device *pdev) err =asus_wmi_backlight_init (asus);if (err && err != -ENODEV ) goto fail_backlight; - } + }else + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_BACKLIGHT ,2 ,NULL ); status =wmi_install_notify_handler (asus->driver->event_guid, asus_wmi_notify, asus);
Signature · 1 line
2.19.1
PATCH 2/3 asus-nb-wmi: Map 0x35 to KEY_SCREENLOCK
In reply to João Paulo Rechi VitaWhen the OS registers to handle events from the display off hotkey the EC will send a notification with 0x35 for every key press, independent of the backlight state.
The behavior of this key on Windows, with the ATKACPI driver from Asus installed, is turning off the backlight of all connected displays with a fading effect, and any cursor input or key press turning the backlight back on. The key press or cursor input that wakes up the display is also passed through to the application under the cursor or under focus.
The key that matches this behavior the closest is KEY_SCREENLOCK.
--- drivers/platform/x86/asus-nb-wmi.c | 1 + 1 file changed, 1 insertion(+)
drivers/platform/x86/asus-nb-wmi.c +1 -0
@@ -444,6 +444,7 @@ static const struct key_entry asus_nb_wmi_keymap[] = { { KE_KEY, 0x32, { KEY_MUTE } }, { KE_KEY, 0x33, { KEY_DISPLAYTOGGLE } }, /* LCD on */ { KE_KEY, 0x34, { KEY_DISPLAY_OFF } }, /* LCD off */ + { KE_KEY, 0x35, { KEY_SCREENLOCK } }, { KE_KEY, 0x40, { KEY_PREVIOUSSONG } }, { KE_KEY, 0x41, { KEY_NEXTSONG } }, { KE_KEY, 0x43, { KEY_STOPCD } }, /* Stop/Eject */
Signature · 1 line
2.19.1
PATCH 3/3 asus-nb-wmi: Drop mapping of 0x33 and 0x34 scan codes
In reply to João Paulo Rechi VitaAccording to Asus firmware engineers, the meaning of these codes is only to notify the OS that the screen brightness has been turned on/off by the EC. This does not match the meaning of KEY_DISPLAYTOGGLE / KEY_DISPLAY_OFF, where userspace is expected to change the display brightness.
--- drivers/platform/x86/asus-nb-wmi.c | 2 -- 1 file changed, 2 deletions(-)
drivers/platform/x86/asus-nb-wmi.c +0 -2
@@ -442,8 +442,6 @@ static const struct key_entry asus_nb_wmi_keymap[] = { { KE_KEY, 0x30, { KEY_VOLUMEUP } }, { KE_KEY, 0x31, { KEY_VOLUMEDOWN } }, { KE_KEY, 0x32, { KEY_MUTE } }, - { KE_KEY, 0x33, { KEY_DISPLAYTOGGLE } }, /* LCD on */ - { KE_KEY, 0x34, { KEY_DISPLAY_OFF } }, /* LCD off */ { KE_KEY, 0x35, { KEY_SCREENLOCK } }, { KE_KEY, 0x40, { KEY_PREVIOUSSONG } }, { KE_KEY, 0x41, { KEY_NEXTSONG } },
Signature · 1 line
2.19.1
Quoted 60 lines · João Paulo Rechi Vita
Asus laptops have a hotkey function on the F7 key to turn the display backlight OFF, labeled with a screen with a X inside, as shown on
https://dlcdnimgs.asus.com/websites/global/products/Xep1ZcSY8dyWXK11/images/keyboard.pngThis hotkey worked on very few Asus models, where the EC acts on the backlight and input events are generated only to notify userspace of the backlight status. On these machines the first hotkey press turns the display backlight OFF and notifies the OS with
0x34, which asus-nb-wmi forwards to userspace asKEY_DISPLAY_OFF, and a second press turns it back ON and notifies the OS with0x33, which asus-nb-wmi forwards to userspace asKEY_DISPLAYTOGGLE. No other keys turn the display backlight back ON, but their input is forwarded normally to the application under focus.But for the majority of models, the EC actually does not act on the backlight and we simply get a
0x33notification every time the key is pressed, or alternating values of0x33/0x34. We have confirmed this behavior on the following models: E203NAS, GL553VE, X441NC, X441UVK, X541UVK, X555DG, X555UB, X555UQ, X560UD, X570ZD and X705FD, and the DSDT on these machines and the working one (only confirmed on N552VW) is the same for the query involved here.After trying to get information from Asus for quite some time on how this works on Windows, we finally recently got a contact that was able to give us a definitive answer and a specification for this feature. According this contact the
0x33/0x34is an old behavior and all newer machines should only be notifying the OS with0x35instead, as newer ECs don't control the backlight anymore. When a0x35notification is received the OS should act on the display backlight. From the spec (machine-translated from Chinese):1.4 Fn+F7
Function introductionAfter the user presses Fn + F7, the screen will be closed through the Windows API. The user will immediately open the screen with the mouse and keyboard.
The API used can be found in the Sample URL:
https://code.msdn.microsoft.com/windowsdesktop/Coalescable-Timer-Sample-d9da954c
BIOS implementation
Increase Notify code
LCD On:0x33(display OSD)
LCD Off:0x34(display OSD)
LCD Switch:0x35(using API switch)The behavior on Windows with the ATKACPI driver from Asus installed matches what is described above, with the hotkey turning OFF the backlight of all connected displays with a fading effect, and any cursor input or key press turning the backlight back ON. The key press or cursor input is passed through to the application under focus or under the cursor.
With this information from the spec, a simple analysis of the DSDT (pasted on the first commit of this series) shows that in order to have the firmware notify the OS with
0x35and have the OS act on the backlight, we need to callWMNB(ASUS_WMI_DEVID_BACKLIGHT==0x00050011, 2)on the_WDGdevice. Then we can simply map that scan code to the appropriate key code in the driver.
Quoted 11 lines
In
include/uapi/linux/input-event-codes.hKEY_DISPLAY_OFFis defined as "display device to off state", but it is not actually handled by userspace on a GNOME+Xorg stack. There are alsoKEY_SCREENSAVERandKEY_SCREENLOCK/KEY_COFFEE. The former seems to be ignored by userspace as well (and its value is higher than 255 so it can't be handled by Xorg IIUC), and the later is mapped to XF86ScreenSaver by Xorg and triggers the lock screen action on GNOME.KEY_SCREENLOCKseems to be what closest matches the behavior described above in a Xorg world. I am not sure if any of this changes with Wayland, so any clarifications in that regard would be greatly appreciated.
Pushed to my review and testing queue, thanks!
Quoted 12 lines
João Paulo Rechi Vita (3):
asus-wmi: Tell the EC the OS will handle the display off hotkey
asus-nb-wmi: Map0x35toKEY_SCREENLOCK
asus-nb-wmi: Drop mapping of0x33and0x34scan codesdrivers/platform/x86/asus-nb-wmi.c | 3 +-- drivers/platform/x86/asus-wmi.c | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-)--
2.19.1
Signature · 2 lines
With Best Regards, Andy Shevchenko