From patchwork Wed Apr 10 20:20:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894713 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 9F16117E1 for ; Wed, 10 Apr 2019 20:21:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70A2D28B9C for ; Wed, 10 Apr 2019 20:21:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EBA828C2B; Wed, 10 Apr 2019 20:21:04 +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=ham 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 EFF5E28B9C for ; Wed, 10 Apr 2019 20:21:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726093AbfDJUVD (ORCPT ); Wed, 10 Apr 2019 16:21:03 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54426 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726022AbfDJUVD (ORCPT ); Wed, 10 Apr 2019 16:21:03 -0400 Received: by mail-wm1-f67.google.com with SMTP id c1so3973310wml.4; Wed, 10 Apr 2019 13:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=9qGS43LXuN/3IxIfwnAzCcj/kwmX0C+pVvSGJunHK78=; b=n30UhWj6LoOOuHY0cP5OhLA9BvThyzrmlh9QjixIpFToR829skm92QLfCyXjBNY6KD +C5pjIfLazqrOlh22zm+RSS/TPz6E8b3EHd4fySycJv1wMMek2oRPYMENs8GoRxpL/vf Nw6U0VDvMiO2uRMUwMjiLiYs+/SXajQni22g1YyWhBxEP2SS4R/4271K01C3+nyWZwZo nzLe1jqFlZjGu+HqpEEab4nEzzgBFUHes6kzgazh2QgcBLQ55DYbLsx9e+SwZW//zL8m R3B1XWnMx8woep3ufuh2uf49CM1HYrhaIkIhbAtuglAED7UnwjskfQmZdrkI/Hs7GF2J bxrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=9qGS43LXuN/3IxIfwnAzCcj/kwmX0C+pVvSGJunHK78=; b=Xlw47MEb0uWI2slQ4R7OvSjMaKqRnof0tN7O2yP9rH4/arILxYtVBqu3Bgst5cDGOe rnqJ/p6Auf2AW8p8U7ICWihkOOHZuwDrAh2/cB5E1TKzPwTg8gGSqjjpUn9PtW8bVFAg MnJ+DyNXPEEg5dbS8V5zvo418GXr5hB9JOE9esQTrN3M5lXJuaTLykXn1UqLx190epmO moG9VaS2vvUEgKTVOBEt46pxtin6dYWLvqFELjsUet1yyII61ICJOI9e6o6TJDLi+/eT CWDFcUHXmA3x6P8XFvH4VO9z6mhPbzPUDgu9B/sntL9uWWts4t903C3wlwdw35e/iPnP g33A== X-Gm-Message-State: APjAAAUWe+mA2GDWasi1Vp1+EU3FHN8vcnT5qhOVuvPAzBumhIqKIMxI mHcT+RQc++FMZsI4M3ySLeSRlFq78M8= X-Google-Smtp-Source: APXvYqyAkDPF3s04NCSosZH96XKV95dR68r+yxOlMr5GDgzmv+3YQGXKbkDApH0vKJTP47mb+lZnWA== X-Received: by 2002:a1c:6a0d:: with SMTP id f13mr4202982wmc.76.1554927661252; Wed, 10 Apr 2019 13:21:01 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id x205sm4965130wmg.9.2019.04.10.13.20.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:21:00 -0700 (PDT) Subject: [PATCH 01/11] platform/x86: asus-wmi: Fix hwmon device cleanup From: Yurii Pavlovskyi To: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake Cc: acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: Date: Wed, 10 Apr 2019 22:20:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The asus-wmi driver does not clean up the hwmon device on exit or error. To reproduce the bug, repeat rmmod, insmod to verify that device number /sys/devices/platform/asus-nb-wmi/hwmon/hwmon?? grows every time. Add pointer to the device in module state and call cleanup on error. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-wmi.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index ee1fa93708ec..6b736a9375ef 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -145,6 +145,7 @@ struct asus_wmi { struct input_dev *inputdev; struct backlight_device *backlight_device; + struct device *hwmon_device; struct platform_device *platform_device; struct led_classdev wlan_led; @@ -1432,9 +1433,19 @@ static int asus_wmi_hwmon_init(struct asus_wmi *asus) pr_err("Could not register asus hwmon device\n"); return PTR_ERR(hwmon); } + + asus->hwmon_device = hwmon; return 0; } +static void asus_wmi_hwmon_exit(struct asus_wmi *asus) +{ + if (asus->hwmon_device) { + asus_hwmon_fan_set_auto(asus); + hwmon_device_unregister(asus->hwmon_device); + } +} + /* * Backlight */ @@ -2157,6 +2168,7 @@ static int asus_wmi_add(struct platform_device *pdev) fail_rfkill: asus_wmi_led_exit(asus); fail_leds: + asus_wmi_hwmon_exit(asus); fail_hwmon: asus_wmi_input_exit(asus); fail_input: @@ -2178,7 +2190,7 @@ static int asus_wmi_remove(struct platform_device *device) asus_wmi_rfkill_exit(asus); asus_wmi_debugfs_exit(asus); asus_wmi_platform_exit(asus); - asus_hwmon_fan_set_auto(asus); + asus_wmi_hwmon_exit(asus); kfree(asus); return 0; From patchwork Wed Apr 10 20:26:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894731 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 1EC4D17E1 for ; Wed, 10 Apr 2019 20:26:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 033B028B93 for ; Wed, 10 Apr 2019 20:26:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB95228B97; Wed, 10 Apr 2019 20:26:08 +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=ham 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 9A2F528B9C for ; Wed, 10 Apr 2019 20:26:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726022AbfDJU0I (ORCPT ); Wed, 10 Apr 2019 16:26:08 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:39062 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbfDJU0I (ORCPT ); Wed, 10 Apr 2019 16:26:08 -0400 Received: by mail-wr1-f65.google.com with SMTP id j9so4462675wrn.6; Wed, 10 Apr 2019 13:26:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=c74an1N8vqjPR+tBHKM9QsMZCuPGywpJNb17jah04RY=; b=I383xd53gF1HGUKsFkdVLss6GTwdle2eBElhsy4gpwUnQXMA4GQad1tlsY9WD5GDFG cHmzqQHtjelTd2STdHvmrqoFVIUoNWCoscay/aiguSiIS++fRIL42D4kD78aTSHRD714 iwOPK3lML9u+JedTcK7SQShEXA4GXiHlCQyVRXagTV48K1r86wxVh1U9rihDTt/1djgP JbWHj5BgJwTZutFSjG41ID+9Y24iJxQ8puBGBpXLAtW61NC9j9ZyHDClPH7A+Htl8bdl BABzMd9ySR6OAud6mtaXV5V1o8EdR07HPqYXNke9PbVFPZejvk1RyBNXwnPLXiGyEyTP Krsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=c74an1N8vqjPR+tBHKM9QsMZCuPGywpJNb17jah04RY=; b=ZSCSAjNsEp3cEMgTv6UaAVI9xWmkhaxKPQLTt+UNa967ytYojMqbRge+EEY4jyo4N0 eng4LgZE11Hs48yYG7Rah49xGaIRGz+MZrAi+x9hr8uYHVCJjEkEBFIPEDgEE0dVnu0n Se3jkIw2YovaGdBkh8Rt8RJZHFgiSG+ctk558XapGX6QCLyo96RHolYhw9uKZP1SjEhh /DBFedDs/lOmAprmvKunuZi3o+HAvvRB1zvptMoy6JPOsUxo/TOjy3ZIFHw9lWflvOk0 csGhfKzyRz+hN8e90j2cDBIu1XyQGM6TrWEA+VYHDKne1z0YgQkBj6e/ubrh+ZYEn0x1 cOoA== X-Gm-Message-State: APjAAAVjoH1d0knnziwTwylWyyINNZtxMwjZmtCdp5eK9qemqGRMa1Ag E/QuW8mXpXGyFwCvtN1hTk6KZNLNE3E= X-Google-Smtp-Source: APXvYqz/ewPlOSuzw9yeytKJ/vWCS0xBg0ZYw79iCwjZmUIqIB3rkyAsBJehuA97JnvNFLPDC2hyrQ== X-Received: by 2002:adf:ce8c:: with SMTP id r12mr9636261wrn.60.1554927966222; Wed, 10 Apr 2019 13:26:06 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id f1sm2352905wml.28.2019.04.10.13.26.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:26:05 -0700 (PDT) Subject: [PATCH 02/11] platform/x86: asus-wmi: Fix preserving keyboard, backlight intensity on load From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <93e5f5b1-1453-54da-2183-2c846397d928@gmail.com> Date: Wed, 10 Apr 2019 22:26:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The error code and return value are mixed up. The intensity is always set to 0 on load as kbd_led_read returns either 0 or negative value. To reproduce set backlight to maximum, reload driver and try to increase it using keyboard hotkey, the intensity will drop as a result. Correct the implementation. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-wmi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 6b736a9375ef..0fbb947b07c4 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -591,8 +591,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus) goto error; } - led_val = kbd_led_read(asus, NULL, NULL); - if (led_val >= 0) { + if (!kbd_led_read(asus, &led_val, NULL)) { asus->kbd_led_wk = led_val; asus->kbd_led.name = "asus::kbd_backlight"; asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED; From patchwork Wed Apr 10 20:27:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894745 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 89AA117E1 for ; Wed, 10 Apr 2019 20:27:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 699AA28B8A for ; Wed, 10 Apr 2019 20:27:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A51528B92; Wed, 10 Apr 2019 20:27:44 +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=ham 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 DF7DB28B8A for ; Wed, 10 Apr 2019 20:27:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726022AbfDJU1n (ORCPT ); Wed, 10 Apr 2019 16:27:43 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46564 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbfDJU1n (ORCPT ); Wed, 10 Apr 2019 16:27:43 -0400 Received: by mail-wr1-f65.google.com with SMTP id t17so4415800wrw.13; Wed, 10 Apr 2019 13:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=sKemZIGXOLnXPFb232HtWCAbGcZYU1oZG05+t8UDDMk=; b=RWqPVkji8y28EF5i03pUDGTDGa4Jk440s0R8PIH8kgKUgt1OQHKc+pPV/1yxdsT7yG /gJRKmugrXQR6lsUZom/JBYLG8fOD1Xj8/v4LDD+fgl8VWONjck5EImZ/tgyPf0xugKS LMUPAHt5rdYGt9+86n82hJkVTdoDmH1nMG1k/6ULmhkI3TACoVgznwAMFzlf3BxQ7XB6 wd2atpTm1iBWEsRvhD1uxXs8YYeuanO/jY9dbxLBw/Grw4DJ2Fw2rE+y8zJ8ewi31qOR whTgr7lBFyajZFMGVooAZdHrH25rLjkJGP8aVm8Mvo8W9LoOd7mQ25OasQVCev8ECPHY xqDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=sKemZIGXOLnXPFb232HtWCAbGcZYU1oZG05+t8UDDMk=; b=JLWc6wvxFno8/WdQXu+xhTpZczy8oRTFYztAZgUKdadrn7voKM/gNqvOTR6mnWEPU/ xHaLbS4y++RTf2hW6ep1/JrchKUmEOOKX5kRYQaGtTGMMudCD2Hjl9XKM6/zOZQAjwQn lq25X8oSe5gcljEZy3d7XRe/pM/QYgeEjYdz7V2MEbdSt2CRI4DLQBf8BI2Pxemjtr/u H5IOVN/1Td5QIj4HdC/Ett8RwARs/E/YlmFDJxRp2uu6WuPFEFA65UXO3CaYuv2DJnlX HiChkZ3880NTfxbwSaCIHY5qokSVP8VKjWZn2zYSJHpCsPnyy1Hhc5B5U0dXbYGAW5ok 5Z+Q== X-Gm-Message-State: APjAAAULOAS9cuMm44DIzGGDFKmVxq4oDF77IdMcoBF1fRxO0hEPjPaP PhbFURi7p0BVVSCx/GYBlNFO40Fja7k= X-Google-Smtp-Source: APXvYqzgx1xwMm/AnrvLzoY9lPLWc50SriYZ99zEd5f7mTaFGX5y2HUeq3abpciLHnx1sY28U2N2nA== X-Received: by 2002:adf:e692:: with SMTP id r18mr24884899wrm.231.1554928061031; Wed, 10 Apr 2019 13:27:41 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id f128sm4193746wme.28.2019.04.10.13.27.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:27:40 -0700 (PDT) Subject: [PATCH 03/11] platform/x86: asus-wmi: Increase input buffer size of WMI methods From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: Date: Wed, 10 Apr 2019 22:27:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The asus-nb-wmi driver is matched by WMI alias but fails to load on TUF Gaming series laptops producing multiple ACPI errors in kernel log. Patch was tested on TUF Gaming FX505GM and older K54C model. The input buffer for WMI method invocation size is 2 dwords, whereas 3 are expected by this model. FX505GM: .. Method (WMNB, 3, Serialized) { P8XH (Zero, 0x11) CreateDWordField (Arg2, Zero, IIA0) CreateDWordField (Arg2, 0x04, IIA1) CreateDWordField (Arg2, 0x08, IIA2) Local0 = (Arg1 & 0xFFFFFFFF) ... Compare with older K54C: ... Method (WMNB, 3, NotSerialized) { CreateDWordField (Arg2, 0x00, IIA0) CreateDWordField (Arg2, 0x04, IIA1) Local0 = (Arg1 & 0xFFFFFFFF) ... Increase buffer size to 3 dwords. No negative consequences of this change are expected, as input buffer size is not verified. The original function is replaced by a wrapper for a new method passing value 0 for the last parameter. The new function will be used to control RGB keyboard backlight. Signed-off-by: Yurii Pavlovskyi --- One of current kernel errors: ACPI BIOS Error (bug): AE_AML_BUFFER_LIMIT, Field [IIA2] at bit offset/ length 64/32 exceeds size of target Buffer (64 bits) (20190215/dsopcode-203) [ 4528.573948] No Local Variables are initialized for Method [WMNB] [ 4528.573949] Initialized Arguments for Method [WMNB]: (3 arguments defined for method invocation) [ 4528.573950] Arg0: 00000000bd1bea5a Integer 0000000000000000 [ 4528.573952] Arg1: 00000000d414dc53 Integer 000000004E464741 [ 4528.573954] Arg2: 00000000fcefea4b Buffer(8) F0 95 08 00 00 00 00 00 [ 4528.573959] ACPI Error: Aborting method \_SB.ATKD.WMNB due to previous error (AE_AML_BUFFER_LIMIT) (20190215/psparse-531) [ 4528.686425] asus-nb-wmi: probe of asus-nb-wmi failed with error -5 --- drivers/platform/x86/asus-wmi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 0fbb947b07c4..cfccfc0b8c2f 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -95,6 +95,7 @@ static bool ashs_present(void) struct bios_args { u32 arg0; u32 arg1; + u32 arg2; /* At least TUF Gaming series uses 3 dword input buffer. */ } __packed; /* @@ -220,11 +221,13 @@ static void asus_wmi_input_exit(struct asus_wmi *asus) asus->inputdev = NULL; } -int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval) +static int asus_wmi_evaluate_method_3dw(u32 method_id, u32 arg0, u32 arg1, + u32 arg2, u32 *retval) { struct bios_args args = { .arg0 = arg0, .arg1 = arg1, + .arg2 = arg2 }; struct acpi_buffer input = { (acpi_size) sizeof(args), &args }; struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; @@ -256,6 +259,11 @@ int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval) return 0; } + +int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval) +{ + return asus_wmi_evaluate_method_3dw(method_id, arg0, arg1, 0, retval); +} EXPORT_SYMBOL_GPL(asus_wmi_evaluate_method); static int asus_wmi_evaluate_method_agfn(const struct acpi_buffer args) From patchwork Wed Apr 10 20:28:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894755 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 B813A17E0 for ; Wed, 10 Apr 2019 20:28:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C49128B2C for ; Wed, 10 Apr 2019 20:28:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9064528B8A; Wed, 10 Apr 2019 20:28:46 +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=ham 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 0CE7828B2C for ; Wed, 10 Apr 2019 20:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726073AbfDJU2p (ORCPT ); Wed, 10 Apr 2019 16:28:45 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39550 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbfDJU2p (ORCPT ); Wed, 10 Apr 2019 16:28:45 -0400 Received: by mail-wm1-f67.google.com with SMTP id n25so3992075wmk.4; Wed, 10 Apr 2019 13:28:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=9Hmq52yvJQx/5jP7bZfxBWJsPaTflswfLZ+HbiCE+bo=; b=KlcStyX9ZhwXzaTle/9oXOkD4p15X6cPxyyNJJseOrvcPohh1RXGudPtm1rGPjCogu zWzqYzacKtruirLAbXhTfCVW89mCP8L/yX0N1j/dI0Ci1mG9+uJqHsEKTnaOfOqAC0R5 A4D9LwQW0VwNm7UpGAAvxfvaM0OObzcbY4kMj4aX+/WNgMxuCS9JpYyslRsRL5p9pP7Q pdJyApxoJ42BIXqDfQQFzwBAHPLGR8TiddzJMqYACmIE3GZX8mlkvYSQwtMtSqRv5I5g pMCqJir3yvK7othX1F9XavQOt017LIRxrg3nkGbWkmMHHey+iCR9+A41hMwAMWdrfM/n ZXsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=9Hmq52yvJQx/5jP7bZfxBWJsPaTflswfLZ+HbiCE+bo=; b=TCQVEqGlMvfMFWN0n+96D1NYHT9cPOPwJAe6Oao+S0jylEKt40XO+1SZVeVXV1PmUr 420EcktZ/jt+FvbXEB75nB9eV8qToESVvcC0UF64IYZmSgLAetKMfuFZftIlaEefhCyJ HewrD4oZ7hafRQjTN23sgJEF4QLgneByvaNuGQVcRSsGPoTa2DRnYKwOuzBI0cAAj3jU aibQoLcA3A2XiaAMfbdwHngdZTEijMwK/tXdYjjLQZc15INh2dcavbF8XExlo8FFw6oX EwiYKAHng1aCE0XADEL2I9St6/3818C+fV+v59F9vy4Xt4VvwX1yMZ+d0wubSEqOIJs8 4lHQ== X-Gm-Message-State: APjAAAU+B55SvgYahlMTMNo+UolpJCiv0H8FB8THVCgColyojO2d2WK1 lE6nxBADFO+kXbmJqOBxs1bfhIcRJ9g= X-Google-Smtp-Source: APXvYqyu64j4LIImPjf31lAHc5AJ6q6FkKL+783ny4u/0W7ByD6fQUziQXCzEO05QNy2GbZ5X0U8Og== X-Received: by 2002:a1c:1d49:: with SMTP id d70mr4159285wmd.36.1554928122475; Wed, 10 Apr 2019 13:28:42 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id g13sm2511169wmh.11.2019.04.10.13.28.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:28:41 -0700 (PDT) Subject: [PATCH 04/11] platform/x86: asus-wmi: Add quirk to force DSTS WMI method detection From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: Date: Wed, 10 Apr 2019 22:28:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The DSTS method detection fails, as nothing is returned if method is not defined in WMNB. As a result the control of keyboard backlight is not functional for TUF Gaming series laptops (at the time the only functionality of the driver on this model implemented with WMI methods). Patch was tested on a newer TUF Gaming FX505GM and older K54C model. FX505GM: Method (WMNB, 3, Serialized) { ... If ((Local0 == 0x53545344)) { ... Return (Zero) } ... // No return } K54C: Method (WMNB, 3, Serialized) { ... If ((Local0 == 0x53545344)) { ... Return (0x02) } ... Return (0xFFFFFFFE) } The non-existing method ASUS_WMI_METHODID_DSTS=0x53544344 (actually it is DCTS in little endian ASCII) is selected in asus->dsts. One way to fix this would be to call both for every known device ID until some answers - this would increase module load time. Another option is to check some device that is known to exist on every model - none known at the time. Last option, which is implemented, is to check for presence of the ASUS7000 device in ACPI tree (it is a dummy device), which is the condition used for loading the vendor driver for this model. This might not fix every affected model ever produced, but it likely does not introduce any regressions. The patch introduces a quirk that is enabled when ASUS7000 is found. Scope (_SB) { Device (ATK) { Name (_HID, "ASUS7000") // _HID: Hardware ID } } Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-nb-wmi.c | 5 +++++ drivers/platform/x86/asus-wmi.c | 16 +++++++++++++--- drivers/platform/x86/asus-wmi.h | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/asus-nb-wmi.c b/drivers/platform/x86/asus-nb-wmi.c index b6f2ff95c3ed..cc5f0765a8d9 100644 --- a/drivers/platform/x86/asus-nb-wmi.c +++ b/drivers/platform/x86/asus-nb-wmi.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "asus-wmi.h" @@ -434,6 +435,10 @@ static void asus_nb_wmi_quirks(struct asus_wmi_driver *driver) } pr_info("Using i8042 filter function for receiving events\n"); } + + if (acpi_dev_found("ASUS7000")) { + driver->quirks->force_dsts = true; + } } static const struct key_entry asus_nb_wmi_keymap[] = { diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index cfccfc0b8c2f..58890d87d50c 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -24,7 +24,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#define PR KBUILD_MODNAME ": " #include #include @@ -1885,11 +1885,21 @@ static int asus_wmi_platform_init(struct asus_wmi *asus) * Note, on most Eeepc, there is no way to check if a method exist * or note, while on notebooks, they returns 0xFFFFFFFE on failure, * but once again, SPEC may probably be used for that kind of things. + * + * Additionally at least TUF Gaming series laptops return 0 for unknown + * methods, so the detection in this way is not possible and method must + * be forced. Likely the presence of ACPI device ASUS7000 indicates + * this. */ - if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS, 0, 0, NULL)) + if (asus->driver->quirks->force_dsts) { + pr_info(PR "DSTS method forced\n"); + asus->dsts_id = ASUS_WMI_METHODID_DSTS2; + } else if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS, + 0, 0, NULL)) { asus->dsts_id = ASUS_WMI_METHODID_DSTS; - else + } else { asus->dsts_id = ASUS_WMI_METHODID_DSTS2; + } /* CWAP allow to define the behavior of the Fn+F2 key, * this method doesn't seems to be present on Eee PCs */ diff --git a/drivers/platform/x86/asus-wmi.h b/drivers/platform/x86/asus-wmi.h index 6c1311f4b04d..94056da02fde 100644 --- a/drivers/platform/x86/asus-wmi.h +++ b/drivers/platform/x86/asus-wmi.h @@ -54,6 +54,11 @@ struct quirk_entry { */ int no_display_toggle; u32 xusb2pr; + /** + * Force DSTS instead of DSCS and skip detection. Useful if WMNB + * returns nothing on unknown method call. + */ + bool force_dsts; bool (*i8042_filter)(unsigned char data, unsigned char str, struct serio *serio); From patchwork Wed Apr 10 20:29:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894757 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 CCFA517E0 for ; Wed, 10 Apr 2019 20:29:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD19A288FD for ; Wed, 10 Apr 2019 20:29:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E16F28998; Wed, 10 Apr 2019 20:29:37 +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=ham 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 D6620288FD for ; Wed, 10 Apr 2019 20:29:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726536AbfDJU3g (ORCPT ); Wed, 10 Apr 2019 16:29:36 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36909 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726118AbfDJU3g (ORCPT ); Wed, 10 Apr 2019 16:29:36 -0400 Received: by mail-wm1-f66.google.com with SMTP id v14so4005642wmf.2; Wed, 10 Apr 2019 13:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=edbqvC5ISJb/a1nvB+Du32vNFh0jCyJ1iWtGNjm6Nlw=; b=ZkcIrXgHRqBxZ27Gj+fr/XLY7e1+dvGcuCmNw2JcNtKRygNJRLMi7EX2VbqmhS5mbX oYVKrEtJ+ai/KOVkygnK5+6larTykMJjYLda3EEKVE8LsYt423NiE0pW2J8smcqE419+ V7V4TFItYkVjBkyhnDCT0AzEeUTMV6Qgrdedgk0tCX6thMZ9b52foTs18CwKygzV567j 0dKbbktOUWJc7bZ/J6E3aqQ6BX2xIg+NfgO81xOsMO37v/cMtuiP3TA1SA/F7X2G/bID SUukm8xtmelA3GBMvXZ2pmk/L3SUSXTCY90tlBZOfYfaOxQu/Ub3hkZXGCBLt1aTWIb5 zVQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=edbqvC5ISJb/a1nvB+Du32vNFh0jCyJ1iWtGNjm6Nlw=; b=W5oLe5sGcvhQNuwbttR1zi+ajyymO2J3yge+X/xeOsj585T3BmpT75CzzwfoSyBEKH kv6cOgAcMhK1JoHbTYtEl8c6zKF7DOp2NSlCEXVef6l8IPLg1SBwPmadh7xavxxqIkMp VDwU8N+w0RQhKAf1Fo594/5Fwjvb+CORvYoQdLLSxkjghOM+YfysNGwTVIAKxqUXlNTu cUsjHMD/7s36aaUp0eMaev3j/tqtKGUX/LlXxPslqs5HYGkDvjOPVKBXV+xbdzLV0JB5 NHm39E4KoYSEe0yDVk/FyTauvYi4UOGc9+MCt/yY8XSfEKV1iVzk0LgrVlxtLK/O4csE K7aQ== X-Gm-Message-State: APjAAAW2ApWhhjmGth10XENZOEsBMvLOyCy2pfu1KfIWJdel+BJKmrqS r0sjUv4PWa6OKcVpu+i83JT08iDTBCA= X-Google-Smtp-Source: APXvYqxPNnL9jgjku0buCLoxa/B2BJXFzUqX26QIJu4VyTmsW7kycVF9/xg4Jjymob/VrG+MS0Km1A== X-Received: by 2002:a05:600c:ca:: with SMTP id u10mr4189500wmm.122.1554928173516; Wed, 10 Apr 2019 13:29:33 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id x21sm29493817wrd.45.2019.04.10.13.29.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:29:32 -0700 (PDT) Subject: [PATCH 05/11] platform/x86: asus-wmi: Support queued WMI event codes From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <777027ac-921e-ee37-493e-974b49242d18@gmail.com> Date: Wed, 10 Apr 2019 22:29:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Event codes are expected to be polled from a queue on at least some models. The WMI event codes are pushed into queue based on circular buffer. After INIT method is called ACPI code is allowed to push events into this buffer the INIT method can not be reverted. If the module is unloaded and an event (such as hotkey press) gets emitted before inserting it back the events get processed delayed by one or, if the queue overflows, additionally delayed by about 3 seconds. Patch was tested on a newer TUF Gaming FX505GM and older K54C model. FX505GM Device (ATKD) { .. Name (ATKQ, Package (0x10) { 0xFFFFFFFF, .. } Method (IANQ, 1, Serialized) { If ((AQNO >= 0x10)) { Local0 = 0x64 While ((Local0 && (AQNO >= 0x10))) { Local0-- Sleep (0x0A) } ... .. AQTI++ AQTI &= 0x0F ATKQ [AQTI] = Arg0 ... } Method (GANQ, 0, Serialized) { .. If (AQNO) { ... Local0 = DerefOf (ATKQ [AQHI]) AQHI++ AQHI &= 0x0F Return (Local0) } Return (One) } This code is almost identical to K54C, which does return Ones on empty queue. K54C: Method (GANQ, 0, Serialized) { If (AQNO) { ... Return (Local0) } Return (Ones) } The fix flushes the old key codes out of the queue on load and after receiving event the queue is read until either ..FFFF or 1 is encountered. It might be considered a minor issue and no normal user would likely to observe this (there is little reason unloading the driver), but it does significantly frustrate a developer who is unlucky enough to encounter this. Introduce functionality for flushing and processing queued codes, which is enabled via quirk flag for ASUS7000. It might be considered if it is reasonable to enable it everywhere (might introduce regressions) or always try to flush the queue on module load and try to detect if this quirk is present in the future. This patch limits the effect to the specific hardware defined by ASUS7000 device that is used for driver detection by vendor driver of Fx505. The fallback is also implemented in case initial flush fails. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-nb-wmi.c | 1 + drivers/platform/x86/asus-wmi.c | 122 ++++++++++++++++++++++------- drivers/platform/x86/asus-wmi.h | 2 + 3 files changed, 97 insertions(+), 28 deletions(-) diff --git a/drivers/platform/x86/asus-nb-wmi.c b/drivers/platform/x86/asus-nb-wmi.c index cc5f0765a8d9..357d273ed336 100644 --- a/drivers/platform/x86/asus-nb-wmi.c +++ b/drivers/platform/x86/asus-nb-wmi.c @@ -438,6 +438,7 @@ static void asus_nb_wmi_quirks(struct asus_wmi_driver *driver) if (acpi_dev_found("ASUS7000")) { driver->quirks->force_dsts = true; + driver->quirks->wmi_event_queue = true; } } diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 58890d87d50c..e0a710c64dea 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -80,6 +80,12 @@ MODULE_LICENSE("GPL"); #define USB_INTEL_XUSB2PR 0xD0 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 +#define WMI_EVENT_QUEUE_SIZE 0x10 +#define WMI_EVENT_QUEUE_END 0x1 +#define WMI_EVENT_MASK 0xFFFF +/* The event value is always the same. */ +#define WMI_EVENT_VALUE 0xFF + static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; static bool ashs_present(void) @@ -143,6 +149,7 @@ struct asus_wmi { int dsts_id; int spec; int sfun; + bool wmi_event_queue; struct input_dev *inputdev; struct backlight_device *backlight_device; @@ -1637,77 +1644,126 @@ static int is_display_toggle(int code) return 0; } -static void asus_wmi_notify(u32 value, void *context) +static int asus_poll_wmi_event(u32 value) { - struct asus_wmi *asus = context; - struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *obj; acpi_status status; - int code; - int orig_code; - unsigned int key_value = 1; - bool autorelease = 1; + int code = -EIO; - status = wmi_get_event_data(value, &response); - if (status != AE_OK) { - pr_err("bad event status 0x%x\n", status); - return; + status = wmi_get_event_data(value, &output); + if (ACPI_FAILURE(status)) { + pr_warn(PR "Failed to get WMI event code: %s\n", + acpi_format_exception(status)); + return code; } - obj = (union acpi_object *)response.pointer; + obj = (union acpi_object *)output.pointer; - if (!obj || obj->type != ACPI_TYPE_INTEGER) - goto exit; + if (obj && obj->type == ACPI_TYPE_INTEGER) + code = (int)(obj->integer.value & WMI_EVENT_MASK); + + kfree(obj); + return code; +} + +static void asus_wmi_handle_notify(int code, struct asus_wmi *asus) +{ + int orig_code; + unsigned int key_value = 1; + bool autorelease = 1; - code = obj->integer.value; orig_code = code; if (asus->driver->key_filter) { asus->driver->key_filter(asus->driver, &code, &key_value, &autorelease); if (code == ASUS_WMI_KEY_IGNORE) - goto exit; + return; } if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) code = ASUS_WMI_BRN_UP; - else if (code >= NOTIFY_BRNDOWN_MIN && - code <= NOTIFY_BRNDOWN_MAX) + else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) code = ASUS_WMI_BRN_DOWN; if (code == ASUS_WMI_BRN_DOWN || code == ASUS_WMI_BRN_UP) { if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { asus_wmi_backlight_notify(asus, orig_code); - goto exit; + return; } } if (code == NOTIFY_KBD_BRTUP) { kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1); - goto exit; + return; } if (code == NOTIFY_KBD_BRTDWN) { kbd_led_set_by_kbd(asus, asus->kbd_led_wk - 1); - goto exit; + return; } if (code == NOTIFY_KBD_BRTTOGGLE) { if (asus->kbd_led_wk == asus->kbd_led.max_brightness) kbd_led_set_by_kbd(asus, 0); else kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1); - goto exit; + return; } - if (is_display_toggle(code) && - asus->driver->quirks->no_display_toggle) - goto exit; + if (is_display_toggle(code) && asus->driver->quirks->no_display_toggle) + return; if (!sparse_keymap_report_event(asus->inputdev, code, key_value, autorelease)) pr_info("Unknown key %x pressed\n", code); +} -exit: - kfree(obj); +static void asus_wmi_notify(u32 value, void *context) +{ + struct asus_wmi *asus = context; + int code; + int i; + + for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) { + code = asus_poll_wmi_event(value); + + if (code < 0) { + pr_warn(PR "Failed to get event code: 0x%x\n", code); + return; + } + + if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK) + return; + + asus_wmi_handle_notify(code, asus); + + if (!asus->wmi_event_queue) + return; + } + + pr_warn(PR "Failed to process event queue, last code: 0x%x\n", code); +} + +static int asus_wmi_notify_queue_flush(struct asus_wmi *asus) +{ + int code; + int i; + + for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) { + code = asus_poll_wmi_event(WMI_EVENT_VALUE); + + if (code < 0) { + pr_warn(PR "Failed to poll event during flush: %d\n", + code); + return code; + } + + if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK) + return 0; + } + + pr_warn(PR "Failed to flush event queue\n"); + return -EIO; } /* @@ -2159,8 +2215,18 @@ static int asus_wmi_add(struct platform_device *pdev) err = asus_wmi_backlight_init(asus); if (err && err != -ENODEV) goto fail_backlight; - } else + } else { err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, 2, NULL); + } + + /** Try to initialize queue and fallback if it fails. */ + if (asus->driver->quirks->wmi_event_queue) { + err = asus_wmi_notify_queue_flush(asus); + if (err) + asus->driver->quirks->wmi_event_queue = false; + else + pr_info(PR "WMI event queue enabled\n"); + } status = wmi_install_notify_handler(asus->driver->event_guid, asus_wmi_notify, asus); diff --git a/drivers/platform/x86/asus-wmi.h b/drivers/platform/x86/asus-wmi.h index 94056da02fde..1248658d6442 100644 --- a/drivers/platform/x86/asus-wmi.h +++ b/drivers/platform/x86/asus-wmi.h @@ -54,6 +54,8 @@ struct quirk_entry { */ int no_display_toggle; u32 xusb2pr; + /* Multiple event codes can be queued in buffer. */ + bool wmi_event_queue; /** * Force DSTS instead of DSCS and skip detection. Useful if WMNB * returns nothing on unknown method call. From patchwork Wed Apr 10 20:30:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894761 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 839F317E0 for ; Wed, 10 Apr 2019 20:30:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67D7728B97 for ; Wed, 10 Apr 2019 20:30:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C65E28B9B; Wed, 10 Apr 2019 20:30:36 +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=ham 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 0729F28BA9 for ; Wed, 10 Apr 2019 20:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726448AbfDJUaa (ORCPT ); Wed, 10 Apr 2019 16:30:30 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36724 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726096AbfDJUaa (ORCPT ); Wed, 10 Apr 2019 16:30:30 -0400 Received: by mail-wr1-f68.google.com with SMTP id y13so4498187wrd.3; Wed, 10 Apr 2019 13:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=4uFFVBqY+BLq6hdKHC/8AnbyjQkZjE6sJfMEtU4xltw=; b=R8TL2KYFAdLZnOvrC7PrR14OtdFzwYPa6JvG2Z+89kXW8n9IefTsZFo2+CHyLqwyBw L9HIeTu+tYPUg7jWvoLgIPZHixO2J6yq4t/VmHkD2TlfjQmgQDPsnCxsrP1/NCCr612D BEaM297XPIN5xr4OGvaLOF+59SGa1phsbuvjZ14Q0s+q9VF1pqAbMAhlpxoNJcA0Vxdp vs6nIHjAEmy9UBebwjh+wOiofaNW6dsqctQ2fxlN52zr4cZ4N5m2NxpKV4i/xaxU82hd XaMKaoSSOOcyvT1wnXCsd2PM0gQq64ii/ZlxwaaP/kKUAGvsj3Z/o7UOzMfX4OVuUvSy Zu1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4uFFVBqY+BLq6hdKHC/8AnbyjQkZjE6sJfMEtU4xltw=; b=EX1jxZDc/a11KuH5EXmQbF/Lg1jjcmWT0LrCZ/zbDJDylGHN8ApVKwxRnR+mnxm/Su yCGj0w+iFVvb5HFgTuB0qxfPt2bh9kA/QG166Dki/fS7It0KWnlcoaHo9DglTR/h7tle 3nSbah02/7GXIO+DOnqpeGpV4hydZ7h0q271SUFKttdqtJAsbMkfuh+9YlL2rcn0LyIK X8B6AfUKg1qnyhuI/jc6RhyE+9vtgYOEZ2Rt3oCpbpn3h5m3gV7dyYRn0AaQrr6iVWNL cbXa40LgT7YlYSPA//ym4PxkuekndYEeFRuiewb6YSbnMT/NN7z1cdHD0MbgqFHTwxu6 WqEQ== X-Gm-Message-State: APjAAAWYk0nuRAleUbmIy0Uw8gOqdfTvG/a/cshbwKXM1jmsOI66W0Gt SuFTuoqJIJ0ukXRzWbFJaXiFM1/dnpE= X-Google-Smtp-Source: APXvYqzE7azqAU/LTA13tcnscNfx9PbZyGafp4jOazNDTsEy9ewKohAX7WHFUF9737a72ha2P4tlSw== X-Received: by 2002:a5d:400c:: with SMTP id n12mr27481524wrp.31.1554928228644; Wed, 10 Apr 2019 13:30:28 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id i18sm33749662wrm.7.2019.04.10.13.30.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:30:28 -0700 (PDT) Subject: [PATCH 06/11] platform/x86: asus-nb-wmi: Add microphone mute key code From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: Date: Wed, 10 Apr 2019 22:30:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The microphone mute key that is present on FX505GM laptop and possibly others is missing from sparse keymap. Add the missing code. Also comment on the fan mode switch key that has the same code as the already used key. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-nb-wmi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/asus-nb-wmi.c b/drivers/platform/x86/asus-nb-wmi.c index 357d273ed336..39cf447198a9 100644 --- a/drivers/platform/x86/asus-nb-wmi.c +++ b/drivers/platform/x86/asus-nb-wmi.c @@ -474,6 +474,7 @@ static const struct key_entry asus_nb_wmi_keymap[] = { { KE_KEY, 0x6B, { KEY_TOUCHPAD_TOGGLE } }, { KE_IGNORE, 0x6E, }, /* Low Battery notification */ { KE_KEY, 0x7a, { KEY_ALS_TOGGLE } }, /* Ambient Light Sensor Toggle */ + { KE_KEY, 0x7c, { KEY_MICMUTE } }, { KE_KEY, 0x7D, { KEY_BLUETOOTH } }, /* Bluetooth Enable */ { KE_KEY, 0x7E, { KEY_BLUETOOTH } }, /* Bluetooth Disable */ { KE_KEY, 0x82, { KEY_CAMERA } }, @@ -488,7 +489,7 @@ static const struct key_entry asus_nb_wmi_keymap[] = { { KE_KEY, 0x92, { KEY_SWITCHVIDEOMODE } }, /* SDSP CRT + TV + DVI */ { KE_KEY, 0x93, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + CRT + TV + DVI */ { KE_KEY, 0x95, { KEY_MEDIA } }, - { KE_KEY, 0x99, { KEY_PHONE } }, + { KE_KEY, 0x99, { KEY_PHONE } }, /* Conflicts with fan mode switch */ { KE_KEY, 0xA0, { KEY_SWITCHVIDEOMODE } }, /* SDSP HDMI only */ { KE_KEY, 0xA1, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + HDMI */ { KE_KEY, 0xA2, { KEY_SWITCHVIDEOMODE } }, /* SDSP CRT + HDMI */ From patchwork Wed Apr 10 20:31:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894763 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 6A9451515 for ; Wed, 10 Apr 2019 20:31:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F0E428B91 for ; Wed, 10 Apr 2019 20:31:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4380128C00; Wed, 10 Apr 2019 20:31:41 +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=ham 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 78DCF28C03 for ; Wed, 10 Apr 2019 20:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726093AbfDJUbk (ORCPT ); Wed, 10 Apr 2019 16:31:40 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55920 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbfDJUbj (ORCPT ); Wed, 10 Apr 2019 16:31:39 -0400 Received: by mail-wm1-f65.google.com with SMTP id o25so3998908wmf.5; Wed, 10 Apr 2019 13:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=BaaVZ2QVpoe+imPNuDOah2SZLBIpVXWP6D7DIlgBEhM=; b=dDB7yzBZN5yVttirCq8wB5K6V7ViN+awlgg0rTzqdPWI0hg0HfPSXn9QdbtECbKsgM 3nDvu11xULWSeXShacE0DHmnS4vi61g4yAL46vCAqKmxTPzItKeL4hRHhtmYPjm8Qlvr MGSuygvLxYqX7K/M736t67nz8YvdKHF11P9YbcXQRcIcOk+fR2ix51mMJWVSpbXG9IIJ PPhFPh0ufS6QFKSFxHEZqJi4veBGUZ0+DwMc7OoU6EmkNk4+tMdiyRSzyjLIXmOF/Uli nwM0xytxd+SpXgwCCK6LmIcyBMS1w5w3AAVBLbsGb8tsF1MZw2HfvwdLvmHTmbIYe2Mk Wi7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=BaaVZ2QVpoe+imPNuDOah2SZLBIpVXWP6D7DIlgBEhM=; b=PSJjGqNKPSaa3M5XuC8ktEw9OvO2dQq99dRtUiNS6vxvMaQjw4r/bnGfNZTE/HzniX j26GESnqoC0pwtDw6L0pARpxB8Vm8lJywXEJh53BP9gKyLFRuyh9enDoYbUzfrvZx22q KtbZZG5GcCSqA0arb7HUgE1bkUYvUrVwky/c6acihNV0EKjEk4f7JUvTdhPcMAtBiWbu rg1b5Fw4EwpX5zNOx9Du6puJZfRwc0n1+gGdYub9++yE2uwuYVmy9hhMFmkn38MuDF9F ioqZmu0as+nQPpdkiioQWOOiHcwntecazmpphNPjrqj+XAYVBAqsBfuq0gKm6BjS+Wud /kkg== X-Gm-Message-State: APjAAAUK95EvLBkeiiN4St895OCYm+utESPho2Vl3JcZcHl7SDaTz7KE K62Y87I1c/U3aUWKL9B9ZvpPwyeAwcc= X-Google-Smtp-Source: APXvYqyFzcqUl+NAwQBsbg4fxxnQtwWB7dvXPN9DARb7YgzHFN0h/3GKFFPYjjLP5XnMMeCOBMxkeg== X-Received: by 2002:a1c:6455:: with SMTP id y82mr3911070wmb.104.1554928296871; Wed, 10 Apr 2019 13:31:36 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id z140sm8928067wmc.27.2019.04.10.13.31.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:31:36 -0700 (PDT) Subject: [PATCH 07/11] platform/x86: asus-wmi: Organize code into sections From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <300d9410-1de5-a4ab-a55a-378ec8c4d5b9@gmail.com> Date: Wed, 10 Apr 2019 22:31:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver has grown (and will more) pretty big which makes it hard to navigate and understand. Add uniform comments to the code and ensure that it is sorted into logical sections. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-wmi.c | 94 ++++++++++++++++----------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index e0a710c64dea..b9a6dc224e08 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -191,6 +191,8 @@ struct asus_wmi { struct asus_wmi_driver *driver; }; +/* Input **********************************************************************/ + static int asus_wmi_input_init(struct asus_wmi *asus) { int err; @@ -228,6 +230,8 @@ static void asus_wmi_input_exit(struct asus_wmi *asus) asus->inputdev = NULL; } +/* WMI ************************************************************************/ + static int asus_wmi_evaluate_method_3dw(u32 method_id, u32 arg0, u32 arg1, u32 arg2, u32 *retval) { @@ -246,7 +250,7 @@ static int asus_wmi_evaluate_method_3dw(u32 method_id, u32 arg0, u32 arg1, &input, &output); if (ACPI_FAILURE(status)) - goto exit; + return -EIO; obj = (union acpi_object *)output.pointer; if (obj && obj->type == ACPI_TYPE_INTEGER) @@ -257,10 +261,6 @@ static int asus_wmi_evaluate_method_3dw(u32 method_id, u32 arg0, u32 arg1, kfree(obj); -exit: - if (ACPI_FAILURE(status)) - return -EIO; - if (tmp == ASUS_WMI_UNSUPPORTED_METHOD) return -ENODEV; @@ -344,9 +344,8 @@ static int asus_wmi_get_devstate_simple(struct asus_wmi *asus, u32 dev_id) ASUS_WMI_DSTS_STATUS_BIT); } -/* - * LEDs - */ +/* LEDs ***********************************************************************/ + /* * These functions actually update the LED's, and are called from a * workqueue. By doing this as separate work rather than when the LED @@ -656,6 +655,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus) return rv; } +/* RF *************************************************************************/ /* * PCI hotplug (for wlan rfkill) @@ -1078,6 +1078,8 @@ static int asus_wmi_rfkill_init(struct asus_wmi *asus) return result; } +/* Quirks *********************************************************************/ + static void asus_wmi_set_xusb2pr(struct asus_wmi *asus) { struct pci_dev *xhci_pdev; @@ -1110,9 +1112,8 @@ static void asus_wmi_set_als(void) asus_wmi_set_devstate(ASUS_WMI_DEVID_ALS_ENABLE, 1, NULL); } -/* - * Hwmon device - */ +/* Hwmon device ***************************************************************/ + static int asus_hwmon_agfn_fan_speed_read(struct asus_wmi *asus, int fan, int *speed) { @@ -1388,7 +1389,6 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj, else if (attr == &dev_attr_temp1_input.attr) dev_id = ASUS_WMI_DEVID_THERMAL_CTRL; - if (attr == &dev_attr_fan1_input.attr || attr == &dev_attr_fan1_label.attr || attr == &dev_attr_pwm1.attr @@ -1460,9 +1460,27 @@ static void asus_wmi_hwmon_exit(struct asus_wmi *asus) } } -/* - * Backlight - */ +static int asus_wmi_fan_init(struct asus_wmi *asus) +{ + int status; + + asus->asus_hwmon_pwm = -1; + asus->asus_hwmon_num_fans = -1; + asus->asus_hwmon_fan_manual_mode = false; + + status = asus_hwmon_get_fan_number(asus, &asus->asus_hwmon_num_fans); + if (status) { + asus->asus_hwmon_num_fans = 0; + pr_warn("Could not determine number of fans: %d\n", status); + return -ENXIO; + } + + pr_info("Number of fans: %d\n", asus->asus_hwmon_num_fans); + return 0; +} + +/* Backlight ******************************************************************/ + static int read_backlight_power(struct asus_wmi *asus) { int ret; @@ -1644,6 +1662,8 @@ static int is_display_toggle(int code) return 0; } +/* WMI events *****************************************************************/ + static int asus_poll_wmi_event(u32 value) { struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; @@ -1766,9 +1786,8 @@ static int asus_wmi_notify_queue_flush(struct asus_wmi *asus) return -EIO; } -/* - * Sys helpers - */ +/* Sysfs **********************************************************************/ + static int parse_arg(const char *buf, unsigned long count, int *val) { if (!count) @@ -1907,9 +1926,8 @@ static int asus_wmi_sysfs_init(struct platform_device *device) return sysfs_create_group(&device->dev.kobj, &platform_attribute_group); } -/* - * Platform device - */ +/* Platform device ************************************************************/ + static int asus_wmi_platform_init(struct asus_wmi *asus) { int rv; @@ -1971,9 +1989,8 @@ static void asus_wmi_platform_exit(struct asus_wmi *asus) asus_wmi_sysfs_exit(asus->platform_device); } -/* - * debugfs - */ +/* debugfs ********************************************************************/ + struct asus_wmi_debugfs_node { struct asus_wmi *asus; char *name; @@ -2120,28 +2137,8 @@ static int asus_wmi_debugfs_init(struct asus_wmi *asus) return -ENOMEM; } -static int asus_wmi_fan_init(struct asus_wmi *asus) -{ - int status; - - asus->asus_hwmon_pwm = -1; - asus->asus_hwmon_num_fans = -1; - asus->asus_hwmon_fan_manual_mode = false; - - status = asus_hwmon_get_fan_number(asus, &asus->asus_hwmon_num_fans); - if (status) { - asus->asus_hwmon_num_fans = 0; - pr_warn("Could not determine number of fans: %d\n", status); - return -ENXIO; - } - - pr_info("Number of fans: %d\n", asus->asus_hwmon_num_fans); - return 0; -} +/* Init / exit ****************************************************************/ -/* - * WMI Driver - */ static int asus_wmi_add(struct platform_device *pdev) { struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver); @@ -2279,9 +2276,8 @@ static int asus_wmi_remove(struct platform_device *device) return 0; } -/* - * Platform driver - hibernate/resume callbacks - */ +/* Platform driver - hibernate/resume callbacks *******************************/ + static int asus_hotk_thaw(struct device *device) { struct asus_wmi *asus = dev_get_drvdata(device); @@ -2353,6 +2349,8 @@ static const struct dev_pm_ops asus_pm_ops = { .resume = asus_hotk_resume, }; +/* Registration ***************************************************************/ + static int asus_wmi_probe(struct platform_device *pdev) { struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver); From patchwork Wed Apr 10 20:32:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894765 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 C715817E0 for ; Wed, 10 Apr 2019 20:32:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA80828B8E for ; Wed, 10 Apr 2019 20:32:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EFAF28C2A; Wed, 10 Apr 2019 20:32:32 +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=ham 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 36B6D28C27 for ; Wed, 10 Apr 2019 20:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726041AbfDJUcb (ORCPT ); Wed, 10 Apr 2019 16:32:31 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37673 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbfDJUcb (ORCPT ); Wed, 10 Apr 2019 16:32:31 -0400 Received: by mail-wr1-f66.google.com with SMTP id w10so4487340wrm.4; Wed, 10 Apr 2019 13:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=tcR4SQD/Dnitpphmo0Ew8bryddr84Vmt+X3uV843Su4=; b=en5Oe4H8r3utt/vhJKQPUjaIr82lb8fRQF0lkqcaLHPESZjOPBxeqE8htMvd05Pkbx 8CUCLU2wsxR2CTICP/A5yfCRpdwIM2Pu84wvN5d/NHltQ7uJYb6ik+SkUuKpHETse5Zw mUFEylWLFZSquskTzhNGdkVgwIBlUSB+spwJ7oWppEyT+wiHgRMEooVQ6J/9Z5bOz59V d7BXM1/e4ek1ABMiEHP1pQBA/Nh1cGk/PLnFbCsXlPUD+3z7dRE/jBb7BI72Z9zNW7oP uxziNDQOv89fHArP6CL5A/WAdXJDU+w+7Eq70duaTl00DZd55CvhRImhlnaNHFYbnC4T T63g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=tcR4SQD/Dnitpphmo0Ew8bryddr84Vmt+X3uV843Su4=; b=HXxPvbbIa8IqJTFr6XLn9CJ5KBqbOamkxE+XpYbzJ1JLprT+QtcfCD4o+NaPQjkD/q DIk27E7Dae3ww1gltYd4cMFSqKFdAkzTCdZc/Yd9J85zZezvetM8vENu5C70dzK/AzgO TwHG/Ee46r16YcV2im7vz+wzZ5HvMgpW56X34Tcx1A0EMF0+aaEiNVgu1eorf2Q9XIN5 0JT4aJo1WXQFy2zGrdF2mt/0+i0fmltbJvucBV/VTpZxTWLcLS2esIYEj4l90FijqGIP uJeG8YJROAlDI0NlmztLNDKeMw49QZ0yw+6sqbWOW+My421if+njRFhV57ml5W0VjZS8 0fnQ== X-Gm-Message-State: APjAAAVbSz0k5K+uINsR2qb503nUcaZyjqUUjwf8l0EEpsbeEHOZwAx4 Zz5v84VBCHaujJpX/xg1qZoxoRvMpBg= X-Google-Smtp-Source: APXvYqz99ImHy8X4gHBs030K48khLugxOWFe9/9+CqrbxZxxYq2ElD8ognp2gHoZ3aAeE+0BwWPSRQ== X-Received: by 2002:adf:97c5:: with SMTP id t5mr11023159wrb.252.1554928349386; Wed, 10 Apr 2019 13:32:29 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id w9sm8517883wmi.0.2019.04.10.13.32.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:32:28 -0700 (PDT) Subject: [PATCH 08/11] platform/x86: asus-wmi: Enhance detection of thermal data From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <91702752-5e6d-43c8-5b41-a52a34b10d26@gmail.com> Date: Wed, 10 Apr 2019 22:32:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The obviously wrong value 1 for temperature device ID in this driver is returned by at least some devices, including TUF Gaming series laptops, instead of 0 as expected previously. Observable effect is that a temp1_input in hwmon reads temperature near absolute zero. * Consider 0.1 K as erroneous value in addition to 0 K. * Refactor detection of thermal input availability to a separate function. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-wmi.c | 46 ++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index b9a6dc224e08..175ecd5b7c51 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -176,6 +176,7 @@ struct asus_wmi { struct asus_rfkill gps; struct asus_rfkill uwb; + bool asus_hwmon_thermal_available; bool asus_hwmon_fan_manual_mode; int asus_hwmon_num_fans; int asus_hwmon_pwm; @@ -1373,6 +1374,32 @@ static struct attribute *hwmon_attributes[] = { NULL }; +static int asus_hwmon_check_thermal_available(struct asus_wmi *asus) +{ + u32 value = ASUS_WMI_UNSUPPORTED_METHOD; + int err; + + asus->asus_hwmon_thermal_available = false; + err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_THERMAL_CTRL, &value); + + if (err < 0) { + if (err == -ENODEV) + return 0; + + return err; + } + + /* + * If the temperature value in deci-Kelvin is near the absolute + * zero temperature, something is clearly wrong. + */ + if (!value || value == 1) + return 0; + + asus->asus_hwmon_thermal_available = true; + return 0; +} + static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj, struct attribute *attr, int idx) { @@ -1386,8 +1413,6 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj, if (attr == &dev_attr_pwm1.attr) dev_id = ASUS_WMI_DEVID_FAN_CTRL; - else if (attr == &dev_attr_temp1_input.attr) - dev_id = ASUS_WMI_DEVID_THERMAL_CTRL; if (attr == &dev_attr_fan1_input.attr || attr == &dev_attr_fan1_label.attr @@ -1412,15 +1437,13 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj, * - reverved bits are non-zero * - sfun and presence bit are not set */ - if (value == ASUS_WMI_UNSUPPORTED_METHOD || value & 0xFFF80000 + if (value == ASUS_WMI_UNSUPPORTED_METHOD || (value & 0xFFF80000) || (!asus->sfun && !(value & ASUS_WMI_DSTS_PRESENCE_BIT))) ok = false; else ok = fan_attr <= asus->asus_hwmon_num_fans; - } else if (dev_id == ASUS_WMI_DEVID_THERMAL_CTRL) { - /* If value is zero, something is clearly wrong */ - if (!value) - ok = false; + } else if (attr == &dev_attr_temp1_input.attr) { + ok = asus->asus_hwmon_thermal_available; } else if (fan_attr <= asus->asus_hwmon_num_fans && fan_attr != -1) { ok = true; } else { @@ -1476,6 +1499,15 @@ static int asus_wmi_fan_init(struct asus_wmi *asus) } pr_info("Number of fans: %d\n", asus->asus_hwmon_num_fans); + + status = asus_hwmon_check_thermal_available(asus); + if (status) { + pr_warn("Could not check if thermal available: %d\n", status); + return -ENXIO; + } + + pr_info(PR "Thermal available: %d\n", + asus->asus_hwmon_thermal_available); return 0; } From patchwork Wed Apr 10 20:33:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894767 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 CB0621515 for ; Wed, 10 Apr 2019 20:33:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFAA428C30 for ; Wed, 10 Apr 2019 20:33:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3CFD28C3D; Wed, 10 Apr 2019 20:33:50 +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=ham 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 6C68428C30 for ; Wed, 10 Apr 2019 20:33:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726118AbfDJUds (ORCPT ); Wed, 10 Apr 2019 16:33:48 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40072 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726041AbfDJUds (ORCPT ); Wed, 10 Apr 2019 16:33:48 -0400 Received: by mail-wr1-f65.google.com with SMTP id h4so4470478wre.7; Wed, 10 Apr 2019 13:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=17+Zb0tFvLstNXdXytSAZOMd7eiVluWqqZ8neMRtJ/o=; b=FThqCqnhV+jDtzWO+848ORE40FOoa+LprrGtvQv+3rsQDwvUi0XDzLYm6x5WgYU+CP BN8SST8jGFXNwyA5V0F53eSmbArb3t6lXC5TzKA7BOA4mNKTG443M89JAwSFar/mNlRM XzcbFG7YLAFaKoJWMebjCsibg3vhKKt69hIkwAH8HRBNgqAH3A0SXYpQUhMAjIz8G4CQ OEIlIKyhoHWSWbZny1AOwtJ6YALBflAOGrGnKZCOh9IIxwnD2keURk5X4t6v5K1VBb/A tku2dM+HNSIzhqqmGH9wbTqaDdeeVPu2ZV06S1kgBioYZsyUgy8j/3MnHmoZaxHlXWuH VAkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=17+Zb0tFvLstNXdXytSAZOMd7eiVluWqqZ8neMRtJ/o=; b=uRFV194ogQpjKCibC+yu7PnwGx7ymzE1TMhYHfPkBudmSE5BmyH0Rqh8Q0vsO5yO0c /Y4hGPnfb1tUq+QAmZMBJ5s1H4LjJr/Lgt9K90A/RP6g0Lvl1uFUz3jcXXgcrKUepxwF aKM+pu1E38pP90f7y1MFETZbJiccxh2NdwxRqyADbUgUc0tN5PyXo7ovMfdfBscHN5qM cU049c4yVhbFPpDGx6yX675+I5oi7qYdkzGrQI7+9qZ/Symp17Z6edDYIAZbI3f3WOZq mu5+1ndgjd0+JLiIE2sx2eT66gV1pDz+bSO8wfHEKebXZt5Ox+u2k/Jv0PORlpymj7O0 TdXw== X-Gm-Message-State: APjAAAWyC+WY+GtLHAYdZXjfGc9Gy0KEfiA83FimNbeGsXmuq5iDXAO8 nWc12zrFGBz07zNK8cwSHK6bVijv0EA= X-Google-Smtp-Source: APXvYqyU2bNBCqAVCgq1X0T1TCZe5Go8XKc+UNc1DS/Tnk2JZXG4GR6gUXQLyZfWfvDRO30y6cbI2Q== X-Received: by 2002:adf:e610:: with SMTP id p16mr28091176wrm.64.1554928425203; Wed, 10 Apr 2019 13:33:45 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id a126sm2664507wmh.4.2019.04.10.13.33.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:33:44 -0700 (PDT) Subject: [PATCH 09/11] platform/x86: asus-wmi: Control RGB keyboard backlight From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org References: Message-ID: Date: Wed, 10 Apr 2019 22:33:42 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The WMI exposes two methods for controlling RGB keyboard backlight which allow to control: * RGB components in range 00 - ff, * Switch between 4 effects, * Switch between 3 effect speed modes, * Separately enable the backlight on boot, in awake state (after driver load), in sleep mode, and probably in something called shutdown mode (no observable effects of enabling it are known so far). The configuration should be written to several sysfs parameter buffers which are then written via WMI by writing either 1 or 2 to the "kbbl_set" parameter. When reading the buffers the last written value is returned. If the 2 is written to "kbbl_set", the parameters will be reset on reboot (temporary mode), 1 is permanent mode, parameters are retained. The calls use new 3-dword input buffer method call. The functionality is only enabled if corresponding DSTS methods return exact valid values. The following script demonstrates usage: echo Red [00 - ff] echo 33 > /sys/devices/platform/asus-nb-wmi/kbbl/kbbl_red echo Green [00 - ff] echo ff > /sys/devices/platform/asus-nb-wmi/kbbl/kbbl_green echo Blue [00 - ff] echo 0 > /sys/devices/platform/asus-nb-wmi/kbbl/kbbl_blue echo Mode: 0 - static color, 1 - blink, 2 - rainbow, 3 - strobe echo 0 > /sys/devices/platform/asus-nb-wmi/kbbl/kbbl_mode echo Speed for modes 1 and 2: 0 - slow, 1 - medium, 2 - fast echo 0 > /sys/devices/platform/asus-nb-wmi/kbbl/kbbl_speed echo Enable: 02 - on boot, before module load, 08 - awake, 20 - sleep, echo 2a or ff to set all echo 2a > /sys/devices/platform/asus-nb-wmi/kbbl/kbbl_flags echo Save: 1 - permanently, 2 - temporarily, reset after reboot echo 1 > /sys/devices/platform/asus-nb-wmi/kbbl/kbbl_set Signed-off-by: Yurii Pavlovskyi --- .../ABI/testing/sysfs-platform-asus-wmi | 61 ++++ drivers/platform/x86/asus-wmi.c | 329 ++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 2 + 3 files changed, 392 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 019e1e29370e..300a40519695 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -36,3 +36,64 @@ KernelVersion: 3.5 Contact: "AceLan Kao" Description: Resume on lid open. 1 means on, 0 means off. + +What: /sys/devices/platform//kbbl/kbbl_red +Date: Apr 2019 +KernelVersion: 5.1 +Contact: "Yurii Pavlovskyi" +Description: + RGB keyboard backlight red component: 00 .. ff. + +What: /sys/devices/platform//kbbl/kbbl_green +Date: Apr 2019 +KernelVersion: 5.1 +Contact: "Yurii Pavlovskyi" +Description: + RGB keyboard backlight green component: 00 .. ff. + +What: /sys/devices/platform//kbbl/kbbl_blue +Date: Apr 2019 +KernelVersion: 5.1 +Contact: "Yurii Pavlovskyi" +Description: + RGB keyboard backlight blue component: 00 .. ff. + +What: /sys/devices/platform//kbbl/kbbl_mode +Date: Apr 2019 +KernelVersion: 5.1 +Contact: "Yurii Pavlovskyi" +Description: + RGB keyboard backlight mode: + * 0 - static color, + * 1 - blink, + * 2 - rainbow, + * 3 - strobe. + +What: /sys/devices/platform//kbbl/kbbl_speed +Date: Apr 2019 +KernelVersion: 5.1 +Contact: "Yurii Pavlovskyi" +Description: + RGB keyboard backlight speed for modes 1 and 2: + * 0 - slow, + * 1 - medium, + * 2 - fast. + +What: /sys/devices/platform//kbbl/kbbl_flags +Date: Apr 2019 +KernelVersion: 5.1 +Contact: "Yurii Pavlovskyi" +Description: + RGB keyboard backlight enable flags (2a to enable everything), OR of: + * 02 - on boot (until module load), + * 08 - awake, + * 20 - sleep. + +What: /sys/devices/platform//kbbl/kbbl_set +Date: Apr 2019 +KernelVersion: 5.1 +Contact: "Yurii Pavlovskyi" +Description: + Write changed RGB keyboard backlight parameters: + * 1 - permanently, + * 2 - temporarily. diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 175ecd5b7c51..f4323a57f22f 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -145,6 +145,21 @@ struct asus_rfkill { u32 dev_id; }; +struct asus_kbbl_rgb { + u8 kbbl_red; + u8 kbbl_green; + u8 kbbl_blue; + u8 kbbl_mode; + u8 kbbl_speed; + + u8 kbbl_set_red; + u8 kbbl_set_green; + u8 kbbl_set_blue; + u8 kbbl_set_mode; + u8 kbbl_set_speed; + u8 kbbl_set_flags; +}; + struct asus_wmi { int dsts_id; int spec; @@ -181,6 +196,9 @@ struct asus_wmi { int asus_hwmon_num_fans; int asus_hwmon_pwm; + bool kbbl_rgb_available; + struct asus_kbbl_rgb kbbl_rgb; + struct hotplug_slot hotplug_slot; struct mutex hotplug_lock; struct mutex wmi_lock; @@ -656,6 +674,310 @@ static int asus_wmi_led_init(struct asus_wmi *asus) return rv; } +/* RGB keyboard backlight *****************************************************/ + +static ssize_t show_u8(u8 value, char *buf) +{ + return scnprintf(buf, PAGE_SIZE, "%02x\n", value); +} + +static ssize_t store_u8(u8 *value, const char *buf, int count) +{ + int err; + u8 result; + + err = kstrtou8(buf, 16, &result); + if (err < 0) { + pr_warn(PR "Trying to store invalid value\n"); + return err; + } + + *value = result; + + return count; +} + +static ssize_t kbbl_red_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return show_u8(asus->kbbl_rgb.kbbl_red, buf); +} + +static ssize_t kbbl_red_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return store_u8(&asus->kbbl_rgb.kbbl_set_red, buf, count); +} + +static ssize_t kbbl_green_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return show_u8(asus->kbbl_rgb.kbbl_green, buf); +} + +static ssize_t kbbl_green_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return store_u8(&asus->kbbl_rgb.kbbl_set_green, buf, count); +} + +static ssize_t kbbl_blue_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return show_u8(asus->kbbl_rgb.kbbl_blue, buf); +} + +static ssize_t kbbl_blue_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return store_u8(&asus->kbbl_rgb.kbbl_set_blue, buf, count); +} + +static ssize_t kbbl_mode_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return show_u8(asus->kbbl_rgb.kbbl_mode, buf); +} + +static ssize_t kbbl_mode_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return store_u8(&asus->kbbl_rgb.kbbl_set_mode, buf, count); +} + +static ssize_t kbbl_speed_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return show_u8(asus->kbbl_rgb.kbbl_speed, buf); +} + +static ssize_t kbbl_speed_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return store_u8(&asus->kbbl_rgb.kbbl_set_speed, buf, count); +} + +static ssize_t kbbl_flags_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return show_u8(asus->kbbl_rgb.kbbl_set_flags, buf); +} + +static ssize_t kbbl_flags_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return store_u8(&asus->kbbl_rgb.kbbl_set_flags, buf, count); +} + +static ssize_t kbbl_set_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return scnprintf(buf, PAGE_SIZE, + "Write to configure RGB keyboard backlight\n"); +} + +static int kbbl_rgb_write(struct asus_wmi *asus, int persistent) +{ + int err; + u32 retval; + u8 speed_byte; + u8 mode_byte; + u8 speed; + u8 mode; + + speed = asus->kbbl_rgb.kbbl_set_speed; + switch (speed) { + case 0: + default: + speed_byte = 0xe1; // slow + speed = 0; + break; + case 1: + speed_byte = 0xeb; // medium + break; + case 2: + speed_byte = 0xf5; // fast + break; + } + + mode = asus->kbbl_rgb.kbbl_set_mode; + switch (mode) { + case 0: + default: + mode_byte = 0x00; // static color + mode = 0; + break; + case 1: + mode_byte = 0x01; // blink + break; + case 2: + mode_byte = 0x02; // rainbow + break; + case 3: + mode_byte = 0x0a; // strobe + break; + } + + err = asus_wmi_evaluate_method_3dw(ASUS_WMI_METHODID_DEVS, + ASUS_WMI_DEVID_KBD_RGB, + (persistent ? 0xb4 : 0xb3) | + (mode_byte << 8) | + (asus->kbbl_rgb.kbbl_set_red << 16) | + (asus->kbbl_rgb.kbbl_set_green << 24), + (asus->kbbl_rgb.kbbl_set_blue) | + (speed_byte << 8), &retval); + if (err) { + pr_warn(PR "RGB keyboard device 1, write error: %d\n", err); + return err; + } + + if (retval != 1) { + pr_warn(PR "RGB keyboard device 1, write error (retval): %x\n", + retval); + return -EIO; + } + + err = asus_wmi_evaluate_method_3dw(ASUS_WMI_METHODID_DEVS, + ASUS_WMI_DEVID_KBD_RGB2, + (0xbd) | + (asus->kbbl_rgb.kbbl_set_flags << 16) | + (persistent ? 0x0100 : 0x0000), 0, &retval); + if (err) { + pr_warn(PR "RGB keyboard device 2, write error: %d\n", err); + return err; + } + + if (retval != 1) { + pr_warn(PR "RGB keyboard device 2, write error (retval): %x\n", + retval); + return -EIO; + } + + asus->kbbl_rgb.kbbl_red = asus->kbbl_rgb.kbbl_set_red; + asus->kbbl_rgb.kbbl_green = asus->kbbl_rgb.kbbl_set_green; + asus->kbbl_rgb.kbbl_blue = asus->kbbl_rgb.kbbl_set_blue; + asus->kbbl_rgb.kbbl_mode = mode; + asus->kbbl_rgb.kbbl_speed = speed; + + return 0; +} + +static ssize_t kbbl_set_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + u8 value; + struct asus_wmi *asus; + int result; + + asus = dev_get_drvdata(dev); + result = store_u8(&value, buf, count); + if (result < 0) + return result; + + if (value == 1) + kbbl_rgb_write(asus, 1); + else if (value == 2) + kbbl_rgb_write(asus, 0); + + return count; +} + +/* RGB values: 00 .. ff */ +static DEVICE_ATTR_RW(kbbl_red); +static DEVICE_ATTR_RW(kbbl_green); +static DEVICE_ATTR_RW(kbbl_blue); + +/* Color modes: 0 - static color, 1 - blink, 2 - rainbow, 3 - strobe */ +static DEVICE_ATTR_RW(kbbl_mode); + +/* Speed for modes 1 and 2: 0 - slow, 1 - medium, 2 - fast */ +static DEVICE_ATTR_RW(kbbl_speed); + +/* + * Enable: 02 - on boot (until module load) | 08 - awake | 20 - sleep + * (2a or ff to enable everything) + * + * Logically 80 would be shutdown, but no visible effects of this option + * were observed so far + */ +static DEVICE_ATTR_RW(kbbl_flags); + +/* Write data: 1 - permanently, 2 - temporarily (reset after reboot) */ +static DEVICE_ATTR_RW(kbbl_set); + +static struct attribute *rgbkb_sysfs_attributes[] = { + &dev_attr_kbbl_red.attr, + &dev_attr_kbbl_green.attr, + &dev_attr_kbbl_blue.attr, + &dev_attr_kbbl_mode.attr, + &dev_attr_kbbl_speed.attr, + &dev_attr_kbbl_flags.attr, + &dev_attr_kbbl_set.attr, + NULL, +}; + +static const struct attribute_group kbbl_attribute_group = { + .name = "kbbl", + .attrs = rgbkb_sysfs_attributes +}; + +static int kbbl_rgb_init(struct asus_wmi *asus) +{ + int err; + + err = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_KBD_RGB); + if (err) { + if (err == -ENODEV) + return 0; + else + return err; + } + + err = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_KBD_RGB2); + if (err) { + if (err == -ENODEV) + return 0; + else + return err; + } + + asus->kbbl_rgb_available = true; + return sysfs_create_group(&asus->platform_device->dev.kobj, + &kbbl_attribute_group); +} + +static void kbbl_rgb_exit(struct asus_wmi *asus) +{ + if (asus->kbbl_rgb_available) { + sysfs_remove_group(&asus->platform_device->dev.kobj, + &kbbl_attribute_group); + } +} + /* RF *************************************************************************/ /* @@ -2212,6 +2534,10 @@ static int asus_wmi_add(struct platform_device *pdev) if (err) goto fail_leds; + err = kbbl_rgb_init(asus); + if (err) + goto fail_rgbkb; + asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WLAN, &result); if (result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT)) asus->driver->wlan_ctrl_by_user = 1; @@ -2278,6 +2604,8 @@ static int asus_wmi_add(struct platform_device *pdev) fail_backlight: asus_wmi_rfkill_exit(asus); fail_rfkill: + kbbl_rgb_exit(asus); +fail_rgbkb: asus_wmi_led_exit(asus); fail_leds: asus_wmi_hwmon_exit(asus); @@ -2299,6 +2627,7 @@ static int asus_wmi_remove(struct platform_device *device) asus_wmi_backlight_exit(asus); asus_wmi_input_exit(asus); asus_wmi_led_exit(asus); + kbbl_rgb_exit(asus); asus_wmi_rfkill_exit(asus); asus_wmi_debugfs_exit(asus); asus_wmi_platform_exit(asus); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 53dfc2541960..25b7b653e6d2 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -57,6 +57,8 @@ #define ASUS_WMI_DEVID_KBD_BACKLIGHT 0x00050021 #define ASUS_WMI_DEVID_LIGHT_SENSOR 0x00050022 /* ?? */ #define ASUS_WMI_DEVID_LIGHTBAR 0x00050025 +#define ASUS_WMI_DEVID_KBD_RGB 0x00100056 +#define ASUS_WMI_DEVID_KBD_RGB2 0x00100057 /* Misc */ #define ASUS_WMI_DEVID_CAMERA 0x00060013 From patchwork Wed Apr 10 20:34:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894769 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 60C7317E0 for ; Wed, 10 Apr 2019 20:35:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FF3B28B8A for ; Wed, 10 Apr 2019 20:35:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E09528B92; Wed, 10 Apr 2019 20:35:03 +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=ham 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 056A61FF65 for ; Wed, 10 Apr 2019 20:35:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726118AbfDJUfB (ORCPT ); Wed, 10 Apr 2019 16:35:01 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42472 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726073AbfDJUfB (ORCPT ); Wed, 10 Apr 2019 16:35:01 -0400 Received: by mail-wr1-f66.google.com with SMTP id g3so4457206wrx.9; Wed, 10 Apr 2019 13:34:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=DXmq4rOhoJkt2ygJQZHYXKb1PmCMroqPazzDspQIMRM=; b=PeHxf7E3LZWRqdrvju/yPWujB2Yfy5sMVF4tR3Nc45xsBqBVAneBe3HOgMNPNdoT/y y2T24APnMeazC6E5/j9x1hj2Snna49Pp9P5rRLkHHZg6iRviQzrDd5qv5EDKXMyXfZTd UF4XpfTsVzAhVfqAyAX3CM2YjTgTjxQTuPXxxswr+LtVUmswH8wlf2Bctgb3B7tkNFJ5 EjH6SkECHk5wZPoCAryV7yFhzqktbsxMSWQftb9F8zabp2pelWAz+OLAjXjLdvgSIwo/ Ff/KNnWHX8Eq3xTbIgniqiy4LdEQa8sTmf8V3GwOsDf32tF0Cp+dlylcbHj7bBOl9s+v iEcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DXmq4rOhoJkt2ygJQZHYXKb1PmCMroqPazzDspQIMRM=; b=KeQmE4JG2DTsDF+V35Xas/12BdpV2Rdj9sGqTMrRRgXBIhiX6fAlIA6XVZCZCn6auI 981KoDf0lrzfA42OAMoCSP8wNg08OBGLPMlfg5H3SCWd7mRzD3ZQ4DGSH7nbAbS5W/6s SaHgc4aseFc4ZCr+I3o+MsBmxrzbSfzbyNPN6V+/d9Maala9OhbCz15YwIeupcbYCMOW +kVkKBMeDJmlXowbZSf1R1CgW7jJlsLrIu22PEjYyfvAFnQmPyJ7Mp6QATdqHvZAaykD S+UUwtu8PgSolK+ytHgUHe83QLxZ4/n2bPJJW2JzXl6ytmt9YdZ/QIi/UaeBV8ybBA1h Dslg== X-Gm-Message-State: APjAAAWqSTavcuKvpaS+/P1C2MpFdJ/4h5SbjcfrkKgaXleDTUobd5Ym H1/+y4O8gqgRGbItFlXUPdPM+WxQev0= X-Google-Smtp-Source: APXvYqxOASx5eN962+pD8VAREDCL001yexKK58sOGVv9w4Xfc0BsEf0zJp29tjcVA2Qw3oIybok7UA== X-Received: by 2002:adf:f309:: with SMTP id i9mr5556658wro.258.1554928498525; Wed, 10 Apr 2019 13:34:58 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id r30sm116924513wrr.46.2019.04.10.13.34.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:34:57 -0700 (PDT) Subject: [PATCH 10/11] platform/x86: asus-wmi: Switch fan boost mode From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org References: Message-ID: <72b3e0aa-d53a-8a82-1505-f4f00aa2bb46@gmail.com> Date: Wed, 10 Apr 2019 22:34:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The WMI exposes a write-only device ID where three modes can be switched on some laptops (TUF Gaming FX505GM). There is a hotkey combination Fn-F5 that does have a fan icon which is designed to toggle between these 3 modes. Add a SysFS entry that reads the last written value and updates value in WMI on write and a hotkey handler that toggles the modes. The corresponding DEVS device handler does obviously take 3 possible argument values. Method (SFBM, 1, NotSerialized) { If ((Arg0 == Zero) { .. } If ((Arg0 == One)) { .. } If ((Arg0 == 0x02)) { .. } } ... // DEVS If ((IIA0 == 0x00110018)) { SFBM (IIA1) Return (One) } * 0x00 - is normal, * 0x01 - is obviously turbo by the amount of noise, might be useful to avoid CPU frequency throttling on high load, * 0x02 - the meaning is unknown at the time as modes are not named in the vendor documentation, but it does look like a quiet mode as CPU temperature does increase about 10 degrees on maximum load. Signed-off-by: Yurii Pavlovskyi --- .../ABI/testing/sysfs-platform-asus-wmi | 10 ++ drivers/platform/x86/asus-wmi.c | 119 ++++++++++++++++-- include/linux/platform_data/x86/asus-wmi.h | 1 + 3 files changed, 117 insertions(+), 13 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 300a40519695..2b3184e297a7 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -97,3 +97,13 @@ Description: Write changed RGB keyboard backlight parameters: * 1 - permanently, * 2 - temporarily. + +What: /sys/devices/platform//fan_mode +Date: Apr 2019 +KernelVersion: 5.1 +Contact: "Yurii Pavlovskyi" +Description: + Fan boost mode: + * 0 - normal, + * 1 - turbo, + * 2 - quiet? diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index f4323a57f22f..941c628945ac 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -69,6 +69,7 @@ MODULE_LICENSE("GPL"); #define NOTIFY_KBD_BRTUP 0xc4 #define NOTIFY_KBD_BRTDWN 0xc5 #define NOTIFY_KBD_BRTTOGGLE 0xc7 +#define NOTIFY_KBD_FBM 0x99 #define ASUS_FAN_DESC "cpu_fan" #define ASUS_FAN_MFUN 0x13 @@ -77,6 +78,8 @@ MODULE_LICENSE("GPL"); #define ASUS_FAN_CTRL_MANUAL 1 #define ASUS_FAN_CTRL_AUTO 2 +#define ASUS_FAN_MODE_COUNT 3 + #define USB_INTEL_XUSB2PR 0xD0 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 @@ -196,6 +199,9 @@ struct asus_wmi { int asus_hwmon_num_fans; int asus_hwmon_pwm; + bool fan_mode_available; + u8 fan_mode; + bool kbbl_rgb_available; struct asus_kbbl_rgb kbbl_rgb; @@ -1833,6 +1839,87 @@ static int asus_wmi_fan_init(struct asus_wmi *asus) return 0; } +/* Fan mode *******************************************************************/ + +static int fan_mode_check_present(struct asus_wmi *asus) +{ + u32 result; + int err; + + asus->fan_mode_available = false; + + err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_MODE, &result); + if (err) { + if (err == -ENODEV) + return 0; + else + return err; + } + + if (result & ASUS_WMI_DSTS_PRESENCE_BIT) + asus->fan_mode_available = true; + + return 0; +} + +static int fan_mode_write(struct asus_wmi *asus) +{ + int err; + u8 value; + u32 retval; + + value = asus->fan_mode % ASUS_FAN_MODE_COUNT; + pr_info(PR "Set fan mode: %u\n", value); + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_FAN_MODE, value, &retval); + + if (err) { + pr_warn(PR "Failed to set fan mode: %d\n", err); + return err; + } + + if (retval != 1) { + pr_warn(PR "Failed to set fan mode (retval): 0x%x\n", retval); + return -EIO; + } + + return 0; +} + +static int fan_mode_switch_next(struct asus_wmi *asus) +{ + asus->fan_mode = (asus->fan_mode + 1) % ASUS_FAN_MODE_COUNT; + return fan_mode_write(asus); +} + +static ssize_t fan_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + + return show_u8(asus->fan_mode, buf); +} + +static ssize_t fan_mode_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int result; + u8 new_mode; + + struct asus_wmi *asus = dev_get_drvdata(dev); + + result = store_u8(&new_mode, buf, count); + if (result < 0) + return result; + + asus->fan_mode = new_mode % ASUS_FAN_MODE_COUNT; + fan_mode_write(asus); + + return result; +} + +// Fan mode: 0 - normal, 1 - turbo, 2 - quiet? +static DEVICE_ATTR_RW(fan_mode); + /* Backlight ******************************************************************/ static int read_backlight_power(struct asus_wmi *asus) @@ -2084,6 +2171,9 @@ static void asus_wmi_handle_notify(int code, struct asus_wmi *asus) return; } + if (asus->fan_mode_available && code == NOTIFY_KBD_FBM) + fan_mode_switch_next(asus); + if (is_display_toggle(code) && asus->driver->quirks->no_display_toggle) return; @@ -2237,6 +2327,7 @@ static struct attribute *platform_attributes[] = { &dev_attr_touchpad.attr, &dev_attr_lid_resume.attr, &dev_attr_als_enable.attr, + &dev_attr_fan_mode.attr, NULL }; @@ -2258,6 +2349,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, devid = ASUS_WMI_DEVID_LID_RESUME; else if (attr == &dev_attr_als_enable.attr) devid = ASUS_WMI_DEVID_ALS_ENABLE; + else if (attr == &dev_attr_fan_mode.attr) + ok = asus->fan_mode_available; if (devid != -1) ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0); @@ -2282,7 +2375,7 @@ static int asus_wmi_sysfs_init(struct platform_device *device) /* Platform device ************************************************************/ -static int asus_wmi_platform_init(struct asus_wmi *asus) +static void asus_wmi_platform_init(struct asus_wmi *asus) { int rv; @@ -2334,13 +2427,6 @@ static int asus_wmi_platform_init(struct asus_wmi *asus) if (asus->driver->quirks->wapf >= 0) asus_wmi_set_devstate(ASUS_WMI_DEVID_CWAP, asus->driver->quirks->wapf, NULL); - - return asus_wmi_sysfs_init(asus->platform_device); -} - -static void asus_wmi_platform_exit(struct asus_wmi *asus) -{ - asus_wmi_sysfs_exit(asus->platform_device); } /* debugfs ********************************************************************/ @@ -2515,9 +2601,15 @@ static int asus_wmi_add(struct platform_device *pdev) if (wdrv->detect_quirks) wdrv->detect_quirks(asus->driver); - err = asus_wmi_platform_init(asus); + asus_wmi_platform_init(asus); + + err = fan_mode_check_present(asus); if (err) - goto fail_platform; + goto fail_fan_mode; + + err = asus_wmi_sysfs_init(asus->platform_device); + if (err) + goto fail_sysfs; err = asus_wmi_input_init(asus); if (err) @@ -2612,8 +2704,9 @@ static int asus_wmi_add(struct platform_device *pdev) fail_hwmon: asus_wmi_input_exit(asus); fail_input: - asus_wmi_platform_exit(asus); -fail_platform: + asus_wmi_sysfs_exit(asus->platform_device); +fail_sysfs: +fail_fan_mode: kfree(asus); return err; } @@ -2630,7 +2723,7 @@ static int asus_wmi_remove(struct platform_device *device) kbbl_rgb_exit(asus); asus_wmi_rfkill_exit(asus); asus_wmi_debugfs_exit(asus); - asus_wmi_platform_exit(asus); + asus_wmi_sysfs_exit(asus->platform_device); asus_wmi_hwmon_exit(asus); kfree(asus); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 25b7b653e6d2..0f3654b7b8a8 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -59,6 +59,7 @@ #define ASUS_WMI_DEVID_LIGHTBAR 0x00050025 #define ASUS_WMI_DEVID_KBD_RGB 0x00100056 #define ASUS_WMI_DEVID_KBD_RGB2 0x00100057 +#define ASUS_WMI_DEVID_FAN_MODE 0x00110018 /* Misc */ #define ASUS_WMI_DEVID_CAMERA 0x00060013 From patchwork Wed Apr 10 20:36:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10894773 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 1F3FC13B5 for ; Wed, 10 Apr 2019 20:36:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0529828B64 for ; Wed, 10 Apr 2019 20:36:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED8EE28B91; Wed, 10 Apr 2019 20:36:25 +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=ham 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 A483328B64 for ; Wed, 10 Apr 2019 20:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726215AbfDJUgZ (ORCPT ); Wed, 10 Apr 2019 16:36:25 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39939 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726022AbfDJUgY (ORCPT ); Wed, 10 Apr 2019 16:36:24 -0400 Received: by mail-wm1-f67.google.com with SMTP id z24so4036949wmi.5; Wed, 10 Apr 2019 13:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=pGlr5Dlh1tSgxgSU4dDk/Ypsv74j1Q+Y8/FEbJrbcgg=; b=PZM2dYrFi598aOf60gQg+zDRoJTpXvrT/0VOSz5WkInLLq0d9aCOwpk8aZoA/eMMbf vyfKOeAcTBai9ij9BfiFsJiT3mFduMq1sLn85SJPcCBpLd/MpsXXpgVRFkpYq+URvqtu cTQz3DxuK3ry0YtxVVkZQmUsny/yubKwYTVhDUHjyp6UH7OTMUGIWHwy0dY5Im+Y39qJ W8iQZMGZ89VL1ozLoJZZUz8suHAJN5fZM1NzWbHJSYSiQel5tBOMLK0Qmqplk9wzLEIy iqygP7q9MseN2/PIdpgjjgeZzD7rJp81LXmKt/n/S6S12V/4Gypeex0ZgVLPv9fij0Hz PMuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=pGlr5Dlh1tSgxgSU4dDk/Ypsv74j1Q+Y8/FEbJrbcgg=; b=ayl7ncwXpq0aWgyIX7OMNB6ukMVUXU2BAWIROCnshMXH8HGDK6Esz8GTPnZgZo6NCF jeV/T6jShbFlda795hl79871UuocHBSIxb2gJSI8pXf8dGTnlPtc71Dvd65/RGZD2bJc 5RXZ/TZcKjXed+bL6jPC9qqc9ISMvB/T0brI4D5b07prsF7UVCmMnrgRJ5EkDsYAwRPi 4yYyh38nsQQ/tdhh7bZe6wxTjDPQB6g7F2tYg0oDm0neep9a2qTQ3C1shO6lLE1CFX2e UOpn96TISXxwVsm/gx1XZNsryj6J6uzxttl0U8qf9J71jpDbn8qllPhS43EOo/+sSXhx G57A== X-Gm-Message-State: APjAAAU4QWyVMIxQmgc8BooWSER/TltfCV+RsB+KbwrR3V4Z+uU8aNYz urMI44vLTBd/D2GU0o50cj69YSVRTL0= X-Google-Smtp-Source: APXvYqwG3BUw8uM1I53XMiF/TClXiQD++LP8AIEbCln84W42PMi5ZyHfvGnnhxD99S68x2yhMexN9Q== X-Received: by 2002:a05:600c:c4:: with SMTP id u4mr4248632wmm.80.1554928582643; Wed, 10 Apr 2019 13:36:22 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id b204sm4974956wmh.29.2019.04.10.13.36.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 13:36:22 -0700 (PDT) Subject: [PATCH 11/11] platform/x86: asus-wmi: Do not disable keyboard backlight on unload From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <2b130755-87bb-b7a5-939b-4d0ebd69af68@gmail.com> Date: Wed, 10 Apr 2019 22:36:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The keyboard backlight is disabled when module is unloaded as it is exposed as LED device. Change this behavior to ignore setting 0 brightness when the ledclass device is unloading. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-wmi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 941c628945ac..a0ffdd99eae2 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -475,6 +475,10 @@ static void do_kbd_led_set(struct led_classdev *led_cdev, int value) static void kbd_led_set(struct led_classdev *led_cdev, enum led_brightness value) { + /* Prevent disabling keyboard backlight on module unregister */ + if (led_cdev->flags & LED_UNREGISTERING) + return; + do_kbd_led_set(led_cdev, value); }