From patchwork Thu Nov 1 00:21:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= X-Patchwork-Id: 10663423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9113E14BD for ; Thu, 1 Nov 2018 00:21:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 767222BA7B for ; Thu, 1 Nov 2018 00:21:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 651502BB82; Thu, 1 Nov 2018 00:21:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5C702BA7B for ; Thu, 1 Nov 2018 00:21:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725999AbeKAJWO (ORCPT ); Thu, 1 Nov 2018 05:22:14 -0400 Received: from mail-ed1-f54.google.com ([209.85.208.54]:38832 "EHLO mail-ed1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbeKAJWN (ORCPT ); Thu, 1 Nov 2018 05:22:13 -0400 Received: by mail-ed1-f54.google.com with SMTP id c1-v6so15185540ede.5; Wed, 31 Oct 2018 17:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7RD1SEGi1002teKqjOAkkLcBBNLPRJx6v1rhE378itw=; b=VKCXQp+JSP5JkUn9poH1ZGCyWNuoibzLPWJB8aa3ReRHXuPVQ99xOW4s/8wnDHGrOR QB9gJ5KfwooWX7pdUuwnhIeQwclW+qZKSYbcPRl2VVkn/mMiwMdltQLzGLyblrM4J5bj PhXC9A8WUm18mNg1kHwhPJOmzCjiqgNKOQZCS5pzAKzXIwtPbqLhutg5CngOxXJ3YEpn ABjTScwpcufRZSK0nTN1IU+4ZS+oz3x6glcDP1Awl+74GoYD1qkjcBzxm288HlDuaWj9 KUeF97JJ3Gdetbjmhrz7udZpOir+rto45O+Ch9A/REkLtTMn1oeHcBYuy+tCDoI4hhh0 3L+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7RD1SEGi1002teKqjOAkkLcBBNLPRJx6v1rhE378itw=; b=GVGGJ0DnR4WtKJQNMY98ye4xB6qq908p9I/e95hk6YvpK7lt1R+uxQH8lUc2cfFTP1 mhTKgEYn9m3wRFPwaPbHQy3t+UYw6r82wACesTDvUHlr9QPs90LcLOZoGXi4YTPA8dPh JYlBKZRArXxSbkklVO8lHtWGJEDuvb+ecIzAgwMEPsHXv2MHEFPBqlMFbZ9eB0/Rseql uD7ufxYWVVPj17RdSGJkQh/M49VI+1MyslbWNH/SuFq767NH5VSI94LAPnq8h217qLzh mIv0pmrkn70jpXMDjxxLMcdBtf9pZg8yBMGAyu26LWvtBntvtzpI7Tkqxh7MCokdCov5 r29g== X-Gm-Message-State: AGRZ1gLZNlSg+T758tV3FSByvgQWyiWkvYifxmZ+0arOPJ7aeCx3gK4+ VPeClBS4Nkm/KLTJUSLJiAg= X-Google-Smtp-Source: AJdET5cae026X1H3fzsluf/uSUEd0+rkKeLOmzScFQHO3t57W6QQfDHWk1HuLX0VUuj4lheYS176sA== X-Received: by 2002:a17:906:e287:: with SMTP id gg7-v6mr2852356ejb.128.1541031699397; Wed, 31 Oct 2018 17:21:39 -0700 (PDT) Received: from kiddo.lan ([2601:602:9400:bc9f::a3c]) by smtp.gmail.com with ESMTPSA id b9-v6sm2981468ejd.3.2018.10.31.17.21.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 17:21:38 -0700 (PDT) From: " =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= " X-Google-Original-From: =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= To: Corentin Chary , Darren Hart , Andy Shevchenko , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org Cc: hadess@hadess.net, Dmitry Torokhov , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux@endlessm.com, =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= Subject: [PATCH 0/3] Fix display off hotkey on Asus machines Date: Wed, 31 Oct 2018 17:21:25 -0700 Message-Id: <20181101002128.28884-1-jprvita@endlessm.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-)