From patchwork Fri Apr 19 10:00: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: 10909553 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 D202613B5 for ; Fri, 19 Apr 2019 19:01:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5C7828DF6 for ; Fri, 19 Apr 2019 19:01:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9D3F28DF9; Fri, 19 Apr 2019 19:01:55 +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 685CA28DF6 for ; Fri, 19 Apr 2019 19:01:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727208AbfDSTBz (ORCPT ); Fri, 19 Apr 2019 15:01:55 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34043 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726417AbfDSTBy (ORCPT ); Fri, 19 Apr 2019 15:01:54 -0400 Received: by mail-wm1-f66.google.com with SMTP id r186so9503643wmf.1; Fri, 19 Apr 2019 12:01:53 -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=e43rnkErijS0HX8VnoEMm69iTL9eHGIel9JB6xut5yQ=; b=V/KTcZ4vKIXT5VQdeglg+jbSYX3ZxI9SIuHRgsZYIQ9t4divxvjoMLyx5BHaR1t6q8 qEa56Jb0vXNydN//t2eQKRs/W1OSr07YKl4U04Jz0MOhlZV3W9bb4MdWIi9dKsdknJkY c1HLsBlRTYi7jB2ZbZLdnIPbWUdyFSCahB2zzoY1lxzAOscTsUiN9WyX/bihx/Kl3zyg uHlDNe3uU+6XO5Ytc3W5jfygr2mDLOYr1Tw0iiSJhq3BqtAqPyRISN6xD9NC2JsNPB5e Vjt49BAFzdHuiCe/SqNmL3wwBy5WX++YbBGxBE2gVJGHP0KqIDJy8O54HwuOkXNARfqb DUHQ== 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=e43rnkErijS0HX8VnoEMm69iTL9eHGIel9JB6xut5yQ=; b=C5Br/n1HII5G6sHowqtwnsjkysxEQdPXlIEPjL3EGanUKJomDsqBkoqgsDEj8AbYlv LAB2vldxuNJQwKPvFmJpjONOSliE5D5rqvltpffkE4Bv/58HEChUF7uZHEdaqPTt6DVt XhIsy1nSkFQQePo1dNY4NGdco2PcA7f5pixf4dvs+xaLNpcLn1n6tAQvyTFOvKnWlyXr jU98gKf7Xqmjf9sFw0R1+zUwQG+fBjf/Ll5epaUfGlvDEg6xIt+nO29CuMUHRnsVkQBF rB0oVo0/d/JoGkwrAEUxFJ40tdGmAdLrxDustjIP7Lfz5tk9ST8JqBBxiLI4Pr0VoPsq ohFg== X-Gm-Message-State: APjAAAUbmiOnbh9cQAyK0ugNQnevAH6asRO5twZax71DUjM08w9bcEoM hRG7WfXuVsMTZNQXfcRRQ3flbMma8l8= X-Google-Smtp-Source: APXvYqzVwNNsJ9brH0zo781KU4mRIZBQx7GHfoUAPIkiuuR/SMfY3jGRSPc6LOzkzoGaHKdHlaohTA== X-Received: by 2002:a05:600c:2293:: with SMTP id 19mr2011184wmf.77.1555668041719; Fri, 19 Apr 2019 03:00:41 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id r18sm7259631wme.18.2019.04.19.03.00.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:00:41 -0700 (PDT) Subject: [PATCH v3 01/11] platform/x86: asus-wmi: Fix hwmon device cleanup 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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: Date: Fri, 19 Apr 2019 12:00: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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 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. Replace call for registering device with devm_* version that unregisters it automatically. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-wmi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index ee1fa93708ec..d865eb95054c 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -1425,9 +1425,10 @@ static int asus_wmi_hwmon_init(struct asus_wmi *asus) { struct device *hwmon; - hwmon = hwmon_device_register_with_groups(&asus->platform_device->dev, - "asus", asus, - hwmon_attribute_groups); + hwmon = devm_hwmon_device_register_with_groups( + &asus->platform_device->dev, "asus", asus, + hwmon_attribute_groups); + if (IS_ERR(hwmon)) { pr_err("Could not register asus hwmon device\n"); return PTR_ERR(hwmon); From patchwork Fri Apr 19 10:03:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10909559 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 AA74814DB for ; Fri, 19 Apr 2019 19:06:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D7E028DFA for ; Fri, 19 Apr 2019 19:06:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91D7F28DFC; Fri, 19 Apr 2019 19:06:56 +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 80FD428DFA for ; Fri, 19 Apr 2019 19:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726417AbfDSTDT (ORCPT ); Fri, 19 Apr 2019 15:03:19 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42412 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728999AbfDSTDM (ORCPT ); Fri, 19 Apr 2019 15:03:12 -0400 Received: by mail-wr1-f65.google.com with SMTP id g3so7924094wrx.9; Fri, 19 Apr 2019 12:03:11 -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=D5OOA2KesAQE4cCxLou/+hQFW5UG2WDyvZfR5JDwzZ8=; b=Wdv7JA/P/PvqD30VTsPVeHTZ99kGlcdLPHsamBmqU36Qfj9B25WWbfM9KHGVIkiNqn JtiyGWch+0XpldJgdIRlpZTCWRhUTg/S3sndYJm1PZofEZ+RcTIb+9wYIOZtPBrPfqQq ZbowP14LkHCeWT8r1ruNB0+XPG/4SmoH8Q71IMLIYHGWd0VY26QNbP98DRay4gCmfpgt R5KPC5HCQjx/kZhzgWbzgwReM++iTnPR1Aun9gzvEh9twpZX5BP4qdiHRS/zg1CeP6F/ 3pag1QISUUsxIgruBJKsboSLS4EbALC+MGjUVT+m6BxIwtGuNdf8coW30mwRFxgwgq1+ I9Sw== 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=D5OOA2KesAQE4cCxLou/+hQFW5UG2WDyvZfR5JDwzZ8=; b=qaPAPlPt9fxGQM+70KEI6tVpNLUSoCSISBvpuxKxh9tFEClXJBezc+gIPjMMQz7Vn7 PGhu7jF7Yt0eBRyPWMYQ87duR2antomZrN1N3aAXZ5qM/RMHJH3IkVUoYxt0mJr9Nm0G fef8G9GjipywDW9r4Dwj2nKwvHd1t2jMU1mkOEU+R3fQJ4lTQBf1EqbO/S4NxprlOJoR RiRDUkXDuwv4PZ6ccPmDJvc9cFquprJouyFSSK2kUMp6cVGxoxchqSUxRtKyAdM6/MzQ crSyRa2Kt6rCSM1Hi3s7vxdpu/lLnxNREIAW/a8xbswPwS3QlOdhizpXoWo/zJMmbVKS 867g== X-Gm-Message-State: APjAAAVUPj2WmMFa7dmuNYpJmWY4N9ezeIFISLlKWwMQNUZRscbVtQMK QVVZZ/DK9k/xERMIrg7UPrlBoVCu67I= X-Google-Smtp-Source: APXvYqw7UQCebd+9C2FW6+rrosqpCDixDfKZRM0dsvPXDnu1o1JrdkdP9ofhnUR/aN4x4NEp9xKTAQ== X-Received: by 2002:a5d:6a0b:: with SMTP id m11mr2265479wru.290.1555668225822; Fri, 19 Apr 2019 03:03:45 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id t76sm6070105wmt.8.2019.04.19.03.03.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:03:45 -0700 (PDT) Subject: [PATCH v3 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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: <83ca4d6b-523a-5c89-1f0e-7103e5c5923b@gmail.com> Date: Fri, 19 Apr 2019 12:03:43 +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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 d865eb95054c..731ffd382426 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -590,8 +590,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 Fri Apr 19 10:05:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10909549 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 896F91515 for ; Fri, 19 Apr 2019 19:00:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C00628DF5 for ; Fri, 19 Apr 2019 19:00:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E1B028DF8; Fri, 19 Apr 2019 19:00:31 +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 028C728DF5 for ; Fri, 19 Apr 2019 19:00:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726887AbfDSTAa (ORCPT ); Fri, 19 Apr 2019 15:00:30 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35387 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbfDSTAa (ORCPT ); Fri, 19 Apr 2019 15:00:30 -0400 Received: by mail-wr1-f66.google.com with SMTP id o12so4618713wrn.2; Fri, 19 Apr 2019 12:00:28 -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=hdkM2PeCiev4S3ru1KHFjlia2CRlV+k0hRdgNzdbShg=; b=tN/neoFGL4skwW+u09oN463qm9IBjVisDo/xSAZhHUMgGGye11EEcmQPGuovj4xybg spbcIqFYarHMI1U3VAx1ENNC7494mbwIOJbpVQVVOVEElRr/ZsNpaPgaCPdyHwe6OODs 9iRoGIaoLNxTfHSBbtTEBUqppxXj4FXYa38UvwH2i1iGHp5QdW+OfO6RRvFgSRJfzTRu t286uLQI9L05IQyDqo7YRnUJvMnDZc4q578uZv6/HlJobNqfHEWbsNrXiEWL7RxjF2+U +NTeu3V+pLhkjp7v582mL1h9sjxMYG/27uqe7Y+1iWn7bnQzQDDl3fIzzsdJ7NIKtGJf zp8A== 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=hdkM2PeCiev4S3ru1KHFjlia2CRlV+k0hRdgNzdbShg=; b=gHw9LWB9PWDIpDYzIQhbIPcjbIuYsbxm0ZGJwhqJYbvMqUjdTpfei6s69l5j1EMgi2 eI/ApKtAifnnmovhcMpscEid+SLqychX1Ev11mY0pPfjDFOWV1WepYfY/66LVLW0vR7N GdabQdoa/0CyypsqjlvxsgGvx5ninH9EuLcvbvmHCyts8fGMzWkRDzryU9XqaUR4Fm6a Mzx2TjGs8d67lIWdvS0HRygXR2DN7ftJTTchNP00yYJfZyhj7p1ezHRP/coL/sXf8EUu 1zONO83IrHiiekga56T/21XVDvvCK4gAbv/PvWNaFv/3Ee9nHIZj/CJxJPIFC4E6n/CM eLvg== X-Gm-Message-State: APjAAAXDRAaCV4apCmSMg0CBujahPn/Mdjs+D+lTOZa7eB9TOjv8kxS6 itsAcCvQHGNugR0zd1gEl6kO71dV2iQ= X-Google-Smtp-Source: APXvYqy01l9XvWn+F15sy1PBImGX3j6d+eK+HRwX6rDlzGFgyR4xc3LNmbt/pzond21+dpp5xFVIGg== X-Received: by 2002:a5d:670b:: with SMTP id o11mr2247692wru.125.1555668323277; Fri, 19 Apr 2019 03:05:23 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id v184sm6245151wma.6.2019.04.19.03.05.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:05:22 -0700 (PDT) Subject: [PATCH v3 03/11] platform/x86: asus-wmi: Increase the 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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: <5e1a56c3-0448-a648-e331-a2e1d0421b56@gmail.com> Date: Fri, 19 Apr 2019 12:05:20 +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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 the kernel log. 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 the 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 731ffd382426..ba04737ece0d 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; /* @@ -219,11 +220,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 }; @@ -255,6 +258,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 Fri Apr 19 10:08: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: 10909657 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 719B917E0 for ; Fri, 19 Apr 2019 19:22:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6325228E06 for ; Fri, 19 Apr 2019 19:22:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5770C28E09; Fri, 19 Apr 2019 19:22:47 +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 13D6328E08 for ; Fri, 19 Apr 2019 19:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727446AbfDSTWl (ORCPT ); Fri, 19 Apr 2019 15:22:41 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41996 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725961AbfDSTWl (ORCPT ); Fri, 19 Apr 2019 15:22:41 -0400 Received: by mail-wr1-f66.google.com with SMTP id g3so7970240wrx.9; Fri, 19 Apr 2019 12:22:39 -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=aWiOpzoih8P2zX+H0CMzWeC9G0Zyx8X6cZpjbuz2CHM=; b=qKt64H4uIUbMQxhPnhUwsr9lw5EJai5WJsQzLB0A5bwEDnHDt7P5ZFalGP+4RoKbV1 tgF7J2sHs50sNsqxIowQD3l6FXF+VMZrlhgIdrvrgPyL49FNz9zUBlAobB9wwfJ8KSKN bJMohohQtKGjLe74C7nekPkcjJ3udR8jpxk2Yh+77NSxjeSxAM/mqB8wVpQNHjZRus4U 2+U1y4UwCMWMytoBBvKmEJop1EWLGzKmsC8HddPUMbwsBaMQBXdS/FzKMllsfQnT9RQO 2hF1N/ZYJEFzzC2sw8Lmwe02GZ/Q8SUnTes5zKUqPhkuaWmf9n6I8FwWtnFqCr2wHVcs sXGQ== 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=aWiOpzoih8P2zX+H0CMzWeC9G0Zyx8X6cZpjbuz2CHM=; b=W0H/AfJltn3BRPH3/v1KposC1CuwEX2WnAiVFOgIk4bDs72lWh/RKFjeajbsPegoGi agFT+NSWA0GrOkhgiaDWLO2Wr5K7YgWl+9S3n3m0zF1cQo8fMMJqcBzojFe6V2HJRtyz bsotOfFhnfkUVjGxpbxiWnNnp9fu/+vZ+S5yrxva7LaJ02JuxeT/Iib2QrFIx+4eTMaI R+cV9UFMyhOixcTUfnIcZvkC2XASipUTVmrAQe9T48cXSqslCPrYT7g/RQk1J/D0ZiIF j660PBQYdvggfqwtJUhpKQhfU0GmIuG+KYE+TMCtR2HizwVKXUTDa7diCfcN0j4PR5HV zxuw== X-Gm-Message-State: APjAAAXAZFvXgYhioramyrA5DhR9OM17x4s0Zt1b5czFxfYa9gl/ZOMk cZ9MyXMV9bzSi0xWFjfJD8b1gzBWVxI= X-Google-Smtp-Source: APXvYqxs7K0QTwv3BMhZ+/amjo++D65Dzg5KcAnCuUDFPp41mc1D6ecby1zBJxzEpj2iPupk9nUVGA== X-Received: by 2002:adf:ed49:: with SMTP id u9mr2279461wro.305.1555668525212; Fri, 19 Apr 2019 03:08:45 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id t15sm3745317wrx.22.2019.04.19.03.08.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:08:44 -0700 (PDT) Subject: [PATCH v3 04/11] platform/x86: asus-wmi: Improve DSTS WMI method ID 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, "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org References: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: Date: Fri, 19 Apr 2019 12:08: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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 mistakenly selects DCTS instead of DSTS if nothing is returned when the method ID is not defined in WMNB. As a result, the control of keyboard backlight is not functional for TUF Gaming series laptops. Implement another detection method instead. There is evidence that DCTS is handled by ACPI WMI devices that have _UID ASUSWMI, whereas none of the devices without ASUSWMI respond to DCTS and DSTS is used instead [1]. To check the _UID a new method is added to wmi.h / wmi.c. It returns _UID of the ACPI WMI device that declares WMI object with given GUID. Generally, it is possible that multiple PNP0C14 ACPI devices are present in the system as mentioned in the commit message of commit bff431e49ff5 ("ACPI: WMI: Add ACPI-WMI mapping driver"). Therefore the _UID is checked for given GUID that maps to a specific ACPI device, to which it is also mapped by other methods of wmi module. DSDT examples: FX505GM: Method (WMNB, 3, Serialized) { ... If ((Local0 == 0x53545344)) { ... Return (Zero) } ... // No return } K54C: Method (WMNB, 3, Serialized) { ... If ((Local0 == 0x53545344)) { ... Return (0x02) } ... Return (0xFFFFFFFE) } [1] https://lkml.org/lkml/2019/4/11/322 Signed-off-by: Yurii Pavlovskyi Suggested-by: Daniel Drake --- drivers/platform/x86/asus-wmi.c | 20 ++++++++++++++++++-- drivers/platform/x86/wmi.c | 19 +++++++++++++++++++ include/linux/acpi.h | 1 + include/linux/platform_data/x86/asus-wmi.h | 4 ++-- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index ba04737ece0d..266d0eda5476 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -80,6 +80,8 @@ MODULE_LICENSE("GPL"); #define USB_INTEL_XUSB2PR 0xD0 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 +#define ASUS_ACPI_UID_ASUSWMI "ASUSWMI" + static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; static bool ashs_present(void) @@ -1847,6 +1849,7 @@ static int asus_wmi_sysfs_init(struct platform_device *device) static int asus_wmi_platform_init(struct asus_wmi *asus) { int rv; + char *wmi_uid; /* INIT enable hotkeys on some models */ if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_INIT, 0, 0, &rv)) @@ -1875,11 +1878,24 @@ 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 nothing for + * unknown methods, so the detection in this way is not possible. + * + * There is strong indication that only ACPI WMI devices that have _UID + * equal to "ASUSWMI" use DCTS whereas those with "ATK" use DSTS. */ - if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS, 0, 0, NULL)) + wmi_uid = wmi_get_acpi_device_uid(ASUS_WMI_MGMT_GUID); + if (!wmi_uid) + return -ENODEV; + + if (!strcmp(wmi_uid, ASUS_ACPI_UID_ASUSWMI)) { + pr_info("Detected ASUSWMI, use DCTS\n"); asus->dsts_id = ASUS_WMI_METHODID_DSTS; - else + } else { + pr_info("Detected %s, not ASUSWMI, use DSTS\n", wmi_uid); 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/wmi.c b/drivers/platform/x86/wmi.c index 7b26b6ccf1a0..b08ffb769cbe 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -635,6 +635,25 @@ bool wmi_has_guid(const char *guid_string) } EXPORT_SYMBOL_GPL(wmi_has_guid); +/** + * wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines GUID + * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba + * + * Find the _UID of ACPI device associated with this WMI GUID. + * + * Return: The ACPI _UID field value or NULL if the WMI GUID was not found + */ +char *wmi_get_acpi_device_uid(const char *guid_string) +{ + struct wmi_block *wblock = NULL; + + if (!find_guid(guid_string, &wblock)) + return NULL; + + return acpi_device_uid(wblock->acpi_device); +} +EXPORT_SYMBOL_GPL(wmi_get_acpi_device_uid); + static struct wmi_block *dev_to_wblock(struct device *dev) { return container_of(dev, struct wmi_block, dev.dev); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index d5dcebd7aad3..d31c7fd66f97 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -376,6 +376,7 @@ extern acpi_status wmi_install_notify_handler(const char *guid, extern acpi_status wmi_remove_notify_handler(const char *guid); extern acpi_status wmi_get_event_data(u32 event, struct acpi_buffer *out); extern bool wmi_has_guid(const char *guid); +extern char *wmi_get_acpi_device_uid(const char *guid); #endif /* CONFIG_ACPI_WMI */ diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 53dfc2541960..a5fe7e68944b 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -18,8 +18,8 @@ #define ASUS_WMI_METHODID_GDSP 0x50534447 /* Get DiSPlay output */ #define ASUS_WMI_METHODID_DEVP 0x50564544 /* DEVice Policy */ #define ASUS_WMI_METHODID_OSVR 0x5256534F /* OS VeRsion */ -#define ASUS_WMI_METHODID_DSTS 0x53544344 /* Device STatuS */ -#define ASUS_WMI_METHODID_DSTS2 0x53545344 /* Device STatuS #2*/ +#define ASUS_WMI_METHODID_DSTS 0x53544344 /* Device STatuS (DCTS) */ +#define ASUS_WMI_METHODID_DSTS2 0x53545344 /* Device STatuS (DSTS) */ #define ASUS_WMI_METHODID_BSTS 0x53545342 /* Bios STatuS ? */ #define ASUS_WMI_METHODID_DEVS 0x53564544 /* DEVice Set */ #define ASUS_WMI_METHODID_CFVS 0x53564643 /* CPU Frequency Volt Set */ From patchwork Fri Apr 19 10:10:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10909505 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 02843922 for ; Fri, 19 Apr 2019 18:47:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E73CC28DCD for ; Fri, 19 Apr 2019 18:47:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB2A328DCE; Fri, 19 Apr 2019 18:47:17 +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 22BE128DCF for ; Fri, 19 Apr 2019 18:47:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728462AbfDSSrJ (ORCPT ); Fri, 19 Apr 2019 14:47:09 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:33979 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727706AbfDSSrJ (ORCPT ); Fri, 19 Apr 2019 14:47:09 -0400 Received: by mail-wm1-f67.google.com with SMTP id r186so9485436wmf.1; Fri, 19 Apr 2019 11:47:07 -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=9GOWv/O3l597N/qj/ikOGyIb8Gy6jzCldfYlQgtg5H0=; b=riuXydw94ehoRb/fU1dhiDapPonMwPK1yQTfksbKk5crfupxSIMWKdG9aEUzC8NEGu Ap6Zyxzv/trOPtq9AeMjdgw3owuMYj/4cqg9ezcCdG9qDJdJyjBeZKSKKlwgclL+xhiP rl2Skk3bc+5asIWYgCEAWyRHacvp7akWV/UEfDGeUCejnT4NnzHKKn8/WrC0/16RtBf1 nUj2ryxrnaqlSZ8i80n9Kby7eQIq5NYaZrMzRbD5s5/Fwz2RTtpM6MrlCAmK3vGY883v iGPCAvXufozjg8H4yd2G0sCn2gT8hanPHnwDuO6HxcvGS2f8ZomkvNJPXAKdlog2W63O tq3g== 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=9GOWv/O3l597N/qj/ikOGyIb8Gy6jzCldfYlQgtg5H0=; b=UP1uQ474XTAcwj9jcoMM6cRIT6d+q9yAkJ2bHA++9VLrMvK4FYfS2XHs688OHasfKA 5s54V17ZuTX7Nf5hXJtuJr2mm5KVhxMSU94ZZx00L9xQeXFIUQTDCPOL9+AF7cJL1Zlz JPb3KiiCdTIM4lfMLCvj8hJZMJJO5uSRTkQBTAh0pJvqmGMRNAe0jCztuUx3XxREcGim qQrWJwST37Q1f/CAKB6c8FXmYLzP/STFhYYdLKEZ5CZzDfWDFANv7FZhyx4V/ohhF8ab LbHUA0JVW7YyjL3K5L8+0UYxn5SgDkK+w60USw54AQDB5BXbxaMYl2q4UoKFZ6KZP86L 1nJg== X-Gm-Message-State: APjAAAVJlrd5Mwxz0zAl+lRHcJwo9a3nAlUUkGXPEHShSeXsA87esH0e zj0TdQFWpI/bAH2rjklk7StGmwjlXS0= X-Google-Smtp-Source: APXvYqx+K/FodaJbr3QHnqVg/SuYWsxZEhCORfo/J8xllg65hcY0+P2rZiXNL/HL4mPXUlzCSTb7YQ== X-Received: by 2002:a1c:b088:: with SMTP id z130mr2063429wme.5.1555668635618; Fri, 19 Apr 2019 03:10:35 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id a126sm3698342wmh.4.2019.04.19.03.10.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:10:35 -0700 (PDT) Subject: [PATCH v3 05/11] platform/x86: asus-wmi: Support WMI event queue 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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: <22dc9bfe-af2f-7ea9-e5bc-95647d5411a8@gmail.com> Date: Fri, 19 Apr 2019 12:10:32 +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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 retrieved from a queue on at least some models. Specifically, very likely the ACPI WMI devices with _UID ATK are queued whereas those with ASUSWMI are not [1]. The WMI event codes are pushed into a circular buffer queue. After the INIT method is called, ACPI code is allowed to push events into this buffer. The INIT method cannot 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. It might be considered a minor issue and no normal user would likely observe this (there is little reason unloading the driver), but it does significantly frustrate a developer who is unlucky enough to encounter this. Therefore, the fallback to unqueued behavior occurs whenever something unexpected happens. The fix flushes the old key codes out of the queue on load. After receiving event the queue is read until either ..FFFF or 1 is encountered. Also as noted in [1] it is checked whether notify code is equal to 0xFF before enabling queue processing in WMI notify handler. DSDT examples: 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) } [1] https://lkml.org/lkml/2019/4/12/104 Signed-off-by: Yurii Pavlovskyi Suggested-by: Daniel Drake --- drivers/platform/x86/asus-wmi.c | 136 +++++++++++++++++++++++++------- 1 file changed, 108 insertions(+), 28 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 266d0eda5476..f782dac4cbe7 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -81,6 +81,13 @@ MODULE_LICENSE("GPL"); #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 #define ASUS_ACPI_UID_ASUSWMI "ASUSWMI" +#define ASUS_ACPI_UID_ATK "ATK" + +#define WMI_EVENT_QUEUE_SIZE 0x10 +#define WMI_EVENT_QUEUE_END 0x1 +#define WMI_EVENT_MASK 0xFFFF +/* The WMI hotkey event value is always the same. */ +#define WMI_EVENT_VALUE_ATK 0xFF static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; @@ -145,6 +152,7 @@ struct asus_wmi { int dsts_id; int spec; int sfun; + bool wmi_event_queue; struct input_dev *inputdev; struct backlight_device *backlight_device; @@ -1629,77 +1637,129 @@ static int is_display_toggle(int code) return 0; } -static void asus_wmi_notify(u32 value, void *context) +static int asus_wmi_get_next_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("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_code(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_wmi_get_next_event(value); + + if (code < 0) { + pr_warn("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(code, asus); + + /* + * Double check that queue is present: + * ATK (with queue) uses 0xff, ASUSWMI (without) 0xd2. + */ + if (!asus->wmi_event_queue || value != WMI_EVENT_VALUE_ATK) + return; + } + + pr_warn("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_wmi_get_next_event(WMI_EVENT_VALUE_ATK); + + if (code < 0) { + pr_warn("Failed to get event during flush: %d\n", code); + return code; + } + + if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK) + return 0; + } + + pr_warn("Failed to flush event queue\n"); + return -EIO; } /* @@ -1850,6 +1910,7 @@ static int asus_wmi_platform_init(struct asus_wmi *asus) { int rv; char *wmi_uid; + int err; /* INIT enable hotkeys on some models */ if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_INIT, 0, 0, &rv)) @@ -1897,6 +1958,24 @@ static int asus_wmi_platform_init(struct asus_wmi *asus) asus->dsts_id = ASUS_WMI_METHODID_DSTS2; } + /* + * Some devices can have multiple event codes stored in a queue before + * the module load if it was unloaded intermittently after calling + * the INIT method (enables event handling). The WMI notify handler is + * expected to retrieve all event codes until a retrieved code equals + * queue end marker (One or Ones). Old codes are flushed from the queue + * upon module load. Not enabling this when it should be has minimal + * visible impact so fall back if anything goes wrong. + */ + wmi_uid = wmi_get_acpi_device_uid(asus->driver->event_guid); + if (wmi_uid && !strcmp(wmi_uid, ASUS_ACPI_UID_ATK)) { + pr_info("Detected ATK, enable event queue\n"); + + err = asus_wmi_notify_queue_flush(asus); + if (!err) + asus->wmi_event_queue = true; + } + /* CWAP allow to define the behavior of the Fn+F2 key, * this method doesn't seems to be present on Eee PCs */ if (asus->driver->quirks->wapf >= 0) @@ -2155,8 +2234,9 @@ 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); + } status = wmi_install_notify_handler(asus->driver->event_guid, asus_wmi_notify, asus); From patchwork Fri Apr 19 10:11:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10909561 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 48C4C14DB for ; Fri, 19 Apr 2019 19:07:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3ADE628DFA for ; Fri, 19 Apr 2019 19:07:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DD4A28DFC; Fri, 19 Apr 2019 19:07:18 +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 BF80028DFA for ; Fri, 19 Apr 2019 19:07:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726336AbfDSTHR (ORCPT ); Fri, 19 Apr 2019 15:07:17 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40673 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727267AbfDSTHR (ORCPT ); Fri, 19 Apr 2019 15:07:17 -0400 Received: by mail-wr1-f65.google.com with SMTP id h4so7945315wre.7; Fri, 19 Apr 2019 12:07:15 -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=BK+hMQZhbc01flr8GR70aSzxt77OZF9p21PsIdL24yQ=; b=Sx7Zd1DLOo8hWgAsVsWBEFYxGJ+IXXaZr0PLYzzRRCQXJ5JeAwNRUdfFhAC26v4Fyz 5zmFj00NwG/77nthJEY6t7pYt/IaRgMc6VnBqDuEq/bzrj3Rb+3ey6gHTk6XBPZgIyPD yRxzNHQ9sEkCHkMghSYSKmO6j+JLq1holWnksi1TAZk7GQKz8kxL1kqlVVGQmlMNuCtS uck2v2limBP8lqH/ZD+67qyjPgclF1ndHLFMVKKO8vLQIee/2D5OxcONZLQDnElitV9w 80Hw5yRTtE0nwBdv1sCZ9LBZS8OVTfhAaeRDfd+OKe1NltnyO/dXh4t+h+qHQMwgfZrZ +iQA== 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=BK+hMQZhbc01flr8GR70aSzxt77OZF9p21PsIdL24yQ=; b=qvHsBiijj2CPkiAnxJT30XzWNeBBTSoQsTM20alWmZyJqkGeZSP5GGMPZUSZW8vyQm UTlS85nZeetSecEC8dlGwAX/qSK/asZDEPovLWU5HkHx7RPjyglJkmzZf4QbCb/+K3+s QdyOYFG1qbeaZTCiI+FG5QPJtQRH/nYm+OR8MQ1Wm6SixaBh+TObCTM+ZiJv4pyS6NrM 8gdCgyfthurjidHJjNDTIoJMAENkS6+GptGWMesHy2HrjjWcZdCyQJyvytebYsXgWPBd 6pnUEcwtknugAOi9zwmKTAvpnatL4ndjeOjE8GwHjq6Rtvb/y2FD2mcWIZEMiJVitoyE lUyA== X-Gm-Message-State: APjAAAUBC9Yd2k3eVC/WfpoYmkXKvXyJe5A6oItuNqeyD6IgS1aJm+po ont149O51+3AeFmem9TumNsar462uls= X-Google-Smtp-Source: APXvYqzmbJn0qxXoGUnseuwmlY339mJox3Bzk9jmKHxmC6rhGfq0VwFaEAohsbCt/unMcwdeDKV55Q== X-Received: by 2002:adf:f78c:: with SMTP id q12mr2349078wrp.172.1555668700232; Fri, 19 Apr 2019 03:11:40 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id x5sm3680563wru.12.2019.04.19.03.11.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:11:39 -0700 (PDT) Subject: [PATCH v3 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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: <27f68b4c-69bf-2129-955e-3a686848fe32@gmail.com> Date: Fri, 19 Apr 2019 12:11:37 +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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 is missing from sparse keymap. It is present on FX505GM and possibly other laptops. Add the missing code. Also, comment on the fan mode switch key, which 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 b6f2ff95c3ed..d2399ce0b3cd 100644 --- a/drivers/platform/x86/asus-nb-wmi.c +++ b/drivers/platform/x86/asus-nb-wmi.c @@ -468,6 +468,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 } }, @@ -482,7 +483,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 Fri Apr 19 10:12:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10909545 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 298D317E0 for ; Fri, 19 Apr 2019 18:55:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B41F28A16 for ; Fri, 19 Apr 2019 18:55:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D84D28DF5; Fri, 19 Apr 2019 18:55:43 +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 64DE628A16 for ; Fri, 19 Apr 2019 18:55:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726617AbfDSSzl (ORCPT ); Fri, 19 Apr 2019 14:55:41 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39591 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726172AbfDSSzl (ORCPT ); Fri, 19 Apr 2019 14:55:41 -0400 Received: by mail-wr1-f68.google.com with SMTP id j9so7921977wrn.6; Fri, 19 Apr 2019 11:55:39 -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=I3dd98omRXec5fhk5/RnYCCTGikhhFY2HueNh1URl4w=; b=RmNVyqKV+YOwTpRkAQjSBZXx8RDltuVS78IIPGOhYDbi1MxMGphL/iOlAiDwQFW7ct +Qc2y7uRcc0Y1qQncaDkTa1GjjYJ25D81Sop0e9jhPLuvYAnxz2jQt/BSzmWykBeyoC2 Mha1Qi3fx+TC4xQVLKEDs6NMgvROigiV+Ux/czhBgppm81mQNTa28g3Cm3e5oLRJVdN0 Cf7i5kB2MGO3ZFwzigdJrgGjhby0BuubJhSsz94cULM1uCzq3QfYLCNZxNyXHI/F7zC7 M/iCzKDPtmOq7IW7MxaVg36S7sTsE2XboFdCKug+OcG3KZZ+E3snxt8Kt+SatDnyC+aT PxGQ== 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=I3dd98omRXec5fhk5/RnYCCTGikhhFY2HueNh1URl4w=; b=rc3IM+OBRXa+3B5rURx8x18ckQj3lDtIHWYw/ZhobERQ3JjZ5DUADRQa0PxrhzhsJI EOwOsRLlxWDeEIdMomR4Y9wdDp5HrZDfvOWnG9Bxovw6nsotOG2Itn/ONS/gPeeOsgfW dTP03vBJ5JwZsrfBtDnmgaPJK+TfUojqUVACuUr7ph8KUqnNoytptbeXjVbQa/e0dgRK WRmf4THuEwAcyszQnDYriLoTpg3SblPtytC4QzI6TBlMZLKNYTN5kZGAASDqVM6oo0M0 vxsBXAj5OaZaRP822DH4yiAAMCYCQUKZN65b2dYRgva+EzFW3p5+X2L3Y8Hsm/Mw4Wnn wf9Q== X-Gm-Message-State: APjAAAWdwd7N7ORKjZVENSLLbO2jiEAu2EVduXn+J78vRIF6Hj84BBlj oHDk8E5gaacprMfQIXSBqbTCKpdtxw0= X-Google-Smtp-Source: APXvYqzA+Hdc1G3g+9brljf2582Z4HHUnhSfzdIc1i/Au4kF8SIasjUMSoShPc3H1Gl0syLldLUChg== X-Received: by 2002:adf:cd83:: with SMTP id q3mr2230532wrj.228.1555668734131; Fri, 19 Apr 2019 03:12:14 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id o6sm5786455wre.60.2019.04.19.03.12.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:12:13 -0700 (PDT) Subject: [PATCH v3 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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: <9a4351a5-ab04-2ebb-9961-1c50dda9800d@gmail.com> Date: Fri, 19 Apr 2019 12:12:11 +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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 pretty big and will grow more, 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 f782dac4cbe7..e69e55635afb 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -193,6 +193,8 @@ struct asus_wmi { struct asus_wmi_driver *driver; }; +/* Input **********************************************************************/ + static int asus_wmi_input_init(struct asus_wmi *asus) { int err; @@ -230,6 +232,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) { @@ -248,7 +252,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) @@ -259,10 +263,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; @@ -346,9 +346,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 @@ -658,6 +657,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus) return rv; } +/* RF *************************************************************************/ /* * PCI hotplug (for wlan rfkill) @@ -1080,6 +1080,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; @@ -1112,9 +1114,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) { @@ -1390,7 +1391,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 @@ -1453,9 +1453,27 @@ static int asus_wmi_hwmon_init(struct asus_wmi *asus) return 0; } -/* - * 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; @@ -1637,6 +1655,8 @@ static int is_display_toggle(int code) return 0; } +/* WMI events *****************************************************************/ + static int asus_wmi_get_next_event(u32 value) { struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; @@ -1762,9 +1782,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) @@ -1903,9 +1922,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; @@ -1990,9 +2008,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; @@ -2139,28 +2156,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); @@ -2288,9 +2285,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); @@ -2362,6 +2358,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 Fri Apr 19 10:12:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10909665 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 667DE17E0 for ; Fri, 19 Apr 2019 19:24:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 572F428CE0 for ; Fri, 19 Apr 2019 19:24:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AED728E06; Fri, 19 Apr 2019 19:24:13 +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 C8F1D28CE0 for ; Fri, 19 Apr 2019 19:24:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726164AbfDSTYM (ORCPT ); Fri, 19 Apr 2019 15:24:12 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35176 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726103AbfDSTYL (ORCPT ); Fri, 19 Apr 2019 15:24:11 -0400 Received: by mail-wr1-f65.google.com with SMTP id o12so4673758wrn.2; Fri, 19 Apr 2019 12:24:10 -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=nbmr2w5/0wlcA5OCIjXqH8b8jg348eXwm/j8E2b8gwc=; b=VGEbQhHcqcHmqC/N8ddol3NVQo48qPjGNaykxHoA4RKKNNRzsTAzYsZyWbH4mHTPI3 xrcv9qJ/UNrwNYLszIr9UbGFcJK9XY+OGm2GZN4kc5zHrzg9DpoHVB+RH0gp8ggvxHY7 BIG8SkaukMJGT1xaI5WcWDkcClN4XQ2ZnAWmJa5ZDVHCr7VDDKGiKZmlDLUgfVtBzSfI pn9n7hP90sbBE3cYYFZ8+YBDduHJ6L58PdLeEwL9bwkb0z1buKUFpNfnpgbVpIaeUhOJ mv3pHHkYc5BO/2ESoD5RBSqmP9U38G4FH2ei5bRsV2frkL+UVVf21dguFsLh3w5Wafrg QY9g== 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=nbmr2w5/0wlcA5OCIjXqH8b8jg348eXwm/j8E2b8gwc=; b=A8ODlamfvjgZiGe2pcfN9rDo7BeUIirkOpQtX2hOUJdH2sQwGGtuoKuHBUrr+BRRh2 7nQGQqcoEw7OU/o8DwbY9S2vJMGGemJdw7HMq6XR662h5HHNGuIxlx0jBEVG+8t8ugrW wYaLcaUhvFPYBVzDaE8HJKjxYzgwbtD/lEPy/tnk4V3BwvrlXZha5kjXkJDPGVHv4ezG pFfwZqgzBzPMiWSGtA4Nufia/KuDT6khC+azBOYLIlvVkOZoIGzA1ZNfKhrx8sNCbhr9 KulTFlSJ20qIs+qFDTqRSlywmlZ5UehmD6JfcR/IW2MZTjrnY+Vb3aAT5PQr1Vn1+BHH FhtA== X-Gm-Message-State: APjAAAVfOJfaLSOG8mLm9wkFV5E3VZ/+TPx1E4dnsBzFZZM0Ktx14Hry xTngmwRFchjGI1yfEF+LXuGtUfvnCuI= X-Google-Smtp-Source: APXvYqxTeIkY6HrtLXqdLaB04RltJhEunJXx+hreNyqXWksrxaf1qtJS2B5bSfRSkQ4zBxxnz3r2rQ== X-Received: by 2002:adf:ed90:: with SMTP id c16mr2292654wro.74.1555668770298; Fri, 19 Apr 2019 03:12:50 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id j3sm5710118wre.51.2019.04.19.03.12.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:12:49 -0700 (PDT) Subject: [PATCH v3 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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: <7595c4f0-3dbb-2fe5-4daf-4b9a266f67d7@gmail.com> Date: Fri, 19 Apr 2019 12:12:47 +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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 an 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 | 45 ++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index e69e55635afb..1b8272374660 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -178,6 +178,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; @@ -1375,6 +1376,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) { @@ -1388,8 +1415,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 @@ -1414,15 +1439,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 { @@ -1469,6 +1492,14 @@ 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("Thermal available: %d\n", asus->asus_hwmon_thermal_available); return 0; } From patchwork Fri Apr 19 10:14:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10909281 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 30E35922 for ; Fri, 19 Apr 2019 18:23:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23CC428DB3 for ; Fri, 19 Apr 2019 18:23:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17C5F28DBA; Fri, 19 Apr 2019 18:23:40 +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 0612628DB3 for ; Fri, 19 Apr 2019 18:23:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727318AbfDSSXi (ORCPT ); Fri, 19 Apr 2019 14:23:38 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35348 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727216AbfDSSXi (ORCPT ); Fri, 19 Apr 2019 14:23:38 -0400 Received: by mail-wm1-f65.google.com with SMTP id y197so7194528wmd.0; Fri, 19 Apr 2019 11:23:36 -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=P+G/cM1XMdFmr7nxXY8x7jLLrqykm5jiI0k+mkReemo=; b=ICphFjJ4rPYMTZ5aMn+G0o00FRP64fYiKNxU2uUcPMI01eR7dYlrsnhoqYedI2jnsJ MCMiShLnRtGuG9Qn8BBN80xOOVL15efRdcczRWw+JUumCn7WsDaZ0Uw+uyWWUi/eM/tu C76+VMSOWdd31AcBpoaV2AuWkMlvrkRGJC6C8zhC6qFKIQU+m41StFjCJODO0xl82ekH X/fCdOdj4aIDYK7edqqrFYP9BtNiwf3VZTlX/L5nSFHpoHjDmXr2mPXj0UEwGo8cj5+Q qN/RLmI1ylMxyhxQQatCkWJrigCoN3BKan5eY0Pi2Auj/cc1XBuodErHSezqyi0IG5id sTiA== 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=P+G/cM1XMdFmr7nxXY8x7jLLrqykm5jiI0k+mkReemo=; b=lz1IhOFMJ6IcEhUoEv/x8dyepaaOQQIkFUL+RfnVh8uES/A2RZpKCqxvFTFCrx6QUs 9W+J/CqwU1Ssw9p9X6MM0uIy85p2Xj/HT4aefpp+fUeT1hbQSdb/FQFuDG0vVzKXbvk0 rmpfXnUtKIzXhRGzfvCEuc15AOJ72DyPXLqAp3hIbkaKgfeqCC5trl88VtSvfnyVGNz8 0XF/nqED8pnkyJqQTRiYqI0ZUNUBx9jzHzykPqw2ZWQa8Kvr4wgTQTkN3SaKEZLjNfdL OrudO59Tw4UbnDmfi8JTj/39aALKP32A3nK4IwlquJBmNAkt/ylMpOJvTUu8FD5ShYiP sPKg== X-Gm-Message-State: APjAAAWXcg9WvhB0vBxs10QtNye3iy8CzX/XYSwT4M2aeMq7L6daEasZ qluQ/uh0uJOGlJVT95uqOjxf9Z5GFUc= X-Google-Smtp-Source: APXvYqyN+qOIGiVXQS+Y8h1VqEqzcxF+rwcnV3nPDMhH4JbPGYhJwhwnC7XRXiHUgrgtLgghZDfjHw== X-Received: by 2002:a1c:6587:: with SMTP id z129mr2070015wmb.84.1555668872696; Fri, 19 Apr 2019 03:14:32 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id t17sm3345222wrr.26.2019.04.19.03.14.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:14:32 -0700 (PDT) Subject: [PATCH v3 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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: Date: Fri, 19 Apr 2019 12:14:29 +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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 allows controlling: * RGB components in range 00 - ff, * Switch between 4 effects, * Switch between 3 effect speed modes, * Separately enable the backlight on boot, in the 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 - breathing, 2 - color cycle, 3 - strobing 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 | 331 ++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 2 + 3 files changed, 394 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 019e1e29370e..1cc54d5e3e10 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 - breathing, + * 2 - color cycle, + * 3 - strobing. + +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 1b8272374660..0a32079336d8 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -148,6 +148,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; @@ -183,6 +198,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; @@ -658,6 +676,312 @@ 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("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; // breathing + break; + case 2: + mode_byte = 0x02; // color cycle + break; + case 3: + mode_byte = 0x0a; // strobing + 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("RGB keyboard device 1, write error: %d\n", err); + return err; + } + + if (retval != 1) { + pr_warn("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("RGB keyboard device 2, write error: %d\n", err); + return err; + } + + if (retval != 1) { + pr_warn("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 - breathing, 2 - color cycle, 3 - strobing + */ +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 *************************************************************************/ /* @@ -2230,6 +2554,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; @@ -2287,6 +2615,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: fail_hwmon: @@ -2307,6 +2637,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 a5fe7e68944b..c8c6e939e196 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 Fri Apr 19 10:15:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10909703 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 C311A14DB for ; Fri, 19 Apr 2019 19:49:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1CA728C46 for ; Fri, 19 Apr 2019 19:49:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5AF328C54; Fri, 19 Apr 2019 19:49:14 +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 790D228C46 for ; Fri, 19 Apr 2019 19:49:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727914AbfDSTtH (ORCPT ); Fri, 19 Apr 2019 15:49:07 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50221 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725839AbfDSTtG (ORCPT ); Fri, 19 Apr 2019 15:49:06 -0400 Received: by mail-wm1-f68.google.com with SMTP id z11so7294869wmi.0; Fri, 19 Apr 2019 12:49:04 -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=aJB9vZEivpTYcxe60Rw8TV3c7mATmB3KiJeMZf8AEvs=; b=R1oZfadI5D5jjZhwD5ag2OTCMfSJN6oA89fYGjdqBFMhTmADHFzNtPCX9FuvXWN34r T/FKoKVtnJ/eiauMpzTq0/NfjqDAatmjmqSVhyW0c8vdqOqqLOQfMIcuyExAJ/GfWoCU u62qAkRQL0PLbLRkplIaKxlcVObhzka83AOX84X9ZXovK5TRNblM1WJ+cULhRpsGSRRn 8d3tM+otxZaaoin8yei3yLvxzknR0PGXt6WEMT2NzDVoVHavHce0Ru1QTkrLvPxazhnj my0H701I+AQO7+uWY7Xdyj4KQpDBm0lG5pY6v7Vn+1i4J7Z0lNi31/gBYub2BhfQiuNf oHLQ== 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=aJB9vZEivpTYcxe60Rw8TV3c7mATmB3KiJeMZf8AEvs=; b=bSSjNC4VfwGDbJ8i0/rOL4aSfq4kku9IrruIFKWlX1OAn+XccKMDU3kNz1kP6LVWg/ PtORPc/ZSgaWVSywYJy0h9tuGo1y7OK1BlY0X5YRphiGILvE/C2xV0a2mUXEl143IgkP OgrzGSYKsR8+2BITudmuweDDbEC/BO6S+UNdzHU8YesmoVmqHVkpSYsNdZu88x1fFfg/ Cv6QM3PCtmt17GsBBx+HNUeCaBhGDmkR3Wx4rHiXf5/YWRPc/hvJ8HzXiEnM5Wro1tqY UZQGx9SSjtR9gNHgfy9/GIYNpWFLB3J10PSG5IfGbjlEH2pej3i+KJwMlxwYkLrvKgGk /aEw== X-Gm-Message-State: APjAAAXdYHk1VEB2i32tQ/jKdhu4ejfdYJZ4SVZLNomw+WcPlCFHA3JB K3gZSv+rY0dxPbGKt09WdatknqnqeuM= X-Google-Smtp-Source: APXvYqxGNWum+wkHzsDzSv5OqK3N+NQlfFiLVOm34MfLXY9Y42FHzEXmj+JAkaVBuqPXBUcA2q6z3Q== X-Received: by 2002:a1c:4844:: with SMTP id v65mr2126039wma.139.1555668948629; Fri, 19 Apr 2019 03:15:48 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id f16sm2697805wru.19.2019.04.19.03.15.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:15:47 -0700 (PDT) Subject: [PATCH v3 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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: Date: Fri, 19 Apr 2019 12:15:45 +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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 up to three fan modes 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 fan modes. The DSTS of the device ID returns information about the presence of the device and the presence of each of the two additional fan modes as a bitmask (0x01 - overboost present, 0x02 - silent present) [1]. 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 taking into account their availability according to DSTS. Modes: * 0x00 - normal or balanced, * 0x01 - overboost, increased fan RPM, * 0x02 - silent, decreased fan RPM [1] https://lkml.org/lkml/2019/4/12/110 Signed-off-by: Yurii Pavlovskyi Suggested-by: Daniel Drake --- .../ABI/testing/sysfs-platform-asus-wmi | 10 ++ drivers/platform/x86/asus-wmi.c | 149 +++++++++++++++++- include/linux/platform_data/x86/asus-wmi.h | 1 + 3 files changed, 152 insertions(+), 8 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 1cc54d5e3e10..6f396c4eabdc 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 - overboost, + * 2 - silent diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 0a32079336d8..7974283b7b12 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,13 @@ MODULE_LICENSE("GPL"); #define ASUS_FAN_CTRL_MANUAL 1 #define ASUS_FAN_CTRL_AUTO 2 +#define ASUS_FAN_MODE_NORMAL 0 +#define ASUS_FAN_MODE_OVERBOOST 1 +#define ASUS_FAN_MODE_OVERBOOST_MASK 0x01 +#define ASUS_FAN_MODE_SILENT 2 +#define ASUS_FAN_MODE_SILENT_MASK 0x02 +#define ASUS_FAN_MODES_MASK 0x03 + #define USB_INTEL_XUSB2PR 0xD0 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 @@ -198,6 +206,10 @@ struct asus_wmi { int asus_hwmon_num_fans; int asus_hwmon_pwm; + bool fan_mode_available; + u8 fan_mode_mask; + u8 fan_mode; + bool kbbl_rgb_available; struct asus_kbbl_rgb kbbl_rgb; @@ -1827,6 +1839,114 @@ 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) && + (result & ASUS_FAN_MODES_MASK)) { + asus->fan_mode_available = true; + asus->fan_mode_mask = result & ASUS_FAN_MODES_MASK; + } + + return 0; +} + +static int fan_mode_write(struct asus_wmi *asus) +{ + int err; + u8 value; + u32 retval; + + value = asus->fan_mode; + + pr_info("Set fan mode: %u\n", value); + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_FAN_MODE, value, &retval); + + if (err) { + pr_warn("Failed to set fan mode: %d\n", err); + return err; + } + + if (retval != 1) { + pr_warn("Failed to set fan mode (retval): 0x%x\n", retval); + return -EIO; + } + + return 0; +} + +static int fan_mode_switch_next(struct asus_wmi *asus) +{ + if (asus->fan_mode == ASUS_FAN_MODE_NORMAL) { + if (asus->fan_mode_mask & ASUS_FAN_MODE_OVERBOOST_MASK) + asus->fan_mode = ASUS_FAN_MODE_OVERBOOST; + else if (asus->fan_mode_mask & ASUS_FAN_MODE_SILENT_MASK) + asus->fan_mode = ASUS_FAN_MODE_SILENT; + } else if (asus->fan_mode == ASUS_FAN_MODE_OVERBOOST) { + if (asus->fan_mode_mask & ASUS_FAN_MODE_SILENT_MASK) + asus->fan_mode = ASUS_FAN_MODE_SILENT; + else + asus->fan_mode = ASUS_FAN_MODE_NORMAL; + } else { + asus->fan_mode = ASUS_FAN_MODE_NORMAL; + } + + 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; + + if (new_mode == ASUS_FAN_MODE_OVERBOOST) { + if (!(asus->fan_mode_mask & ASUS_FAN_MODE_OVERBOOST_MASK)) + return -EINVAL; + } else if (new_mode == ASUS_FAN_MODE_SILENT) { + if (!(asus->fan_mode_mask & ASUS_FAN_MODE_SILENT_MASK)) + return -EINVAL; + } else if (new_mode != ASUS_FAN_MODE_NORMAL) { + return -EINVAL; + } + + asus->fan_mode = new_mode; + fan_mode_write(asus); + + return result; +} + +// Fan mode: 0 - normal, 1 - overboost, 2 - silent +static DEVICE_ATTR_RW(fan_mode); + /* Backlight ******************************************************************/ static int read_backlight_power(struct asus_wmi *asus) @@ -2078,6 +2198,11 @@ static void asus_wmi_handle_notify_code(int code, struct asus_wmi *asus) return; } + if (asus->fan_mode_available && code == NOTIFY_KBD_FBM) { + fan_mode_switch_next(asus); + return; + } + if (is_display_toggle(code) && asus->driver->quirks->no_display_toggle) return; @@ -2234,6 +2359,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 }; @@ -2255,6 +2381,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); @@ -2355,12 +2483,7 @@ static int asus_wmi_platform_init(struct asus_wmi *asus) 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); + return 0; } /* debugfs ********************************************************************/ @@ -2539,6 +2662,14 @@ static int asus_wmi_add(struct platform_device *pdev) if (err) goto fail_platform; + err = fan_mode_check_present(asus); + if (err) + 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) goto fail_input; @@ -2622,7 +2753,9 @@ static int asus_wmi_add(struct platform_device *pdev) fail_hwmon: asus_wmi_input_exit(asus); fail_input: - asus_wmi_platform_exit(asus); + asus_wmi_sysfs_exit(asus->platform_device); +fail_sysfs: +fail_fan_mode: fail_platform: kfree(asus); return err; @@ -2640,7 +2773,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_hwmon_fan_set_auto(asus); kfree(asus); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index c8c6e939e196..fdf5839f64ad 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 Fri Apr 19 10:16:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10909551 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 DFB9813B5 for ; Fri, 19 Apr 2019 19:00:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1F9B28DF5 for ; Fri, 19 Apr 2019 19:00:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5BBD28DF8; Fri, 19 Apr 2019 19:00:47 +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 7B95C28DF5 for ; Fri, 19 Apr 2019 19:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728650AbfDSTAr (ORCPT ); Fri, 19 Apr 2019 15:00:47 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50961 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbfDSTAq (ORCPT ); Fri, 19 Apr 2019 15:00:46 -0400 Received: by mail-wm1-f68.google.com with SMTP id z11so7193034wmi.0; Fri, 19 Apr 2019 12:00:45 -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=wY7FVhtjfagAidOrJm9x0WSuPKmvLohsMLLrTTn97gI=; b=ta9g6PpvMoZqw2BBFCY5VJd/jbckvzV6Mz4KtmWqrMei5MZXSTndvZEV5s7R9oAGdZ u3Q0OPLV/xaQVCNUHAEDEsNBlBq/76snot7CHy1rCpxcqa1k2QWiNChazhLb40D8xPXm omSQR3hTrk1OsUERfDgjOwgfoeiBoQ67GFEd+Y4xwfub/sEeJAjmDW/n0mDQNs29ZcxH 1QsDEZcl9WbInna5uOAr6oFVfDyuvdsHNJM4N7n+z3KjetfpwXHqOckvwG1cqyo17xy3 qIV4auvl2NQBNmYezxhLApVjIwQCGhy+JsOP4ndQKsVmiLbYhYD188w9VIoMhrNKYCTp fM0w== 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=wY7FVhtjfagAidOrJm9x0WSuPKmvLohsMLLrTTn97gI=; b=QHt5sOBEVt2zl+/ObtI03M+nARxcAKwKFHxDm0h2WNDNM31Yxik1AXfUvuXUDFDIEw Vwpmr5hk4+THbtgHkHjn6Eo+JuhVjxsRS0kQdYVx8gSieDPEsKQKBkIwX2TbhnKX5OPv GReMjV6DHkDY/MzH2KYgcoPm4eoG5wcJZ1Gc4bCB78PDihs/Hd8VDIy/1XpczKEyzgMK R+0y4Ew3uFPmdhjJw99Sj1ErdPfFTuxeNdM2rgIoCS3GGXe2L116za/WeC2zJpt5SYVD zkzWfn6Bcvrq3qBem6JTclRopcmFdSILY0wpJ+2VOitAjy+EdjC4hqNHj3+6iUoc4KGb C0PQ== X-Gm-Message-State: APjAAAW79AM99ek7FrraIU4cUTwvKNhQ4FQ0XfmqyZMbjgmH29iKwAWH DUnk1lb2eydk62/RGuhg+9jF5uBzIFU= X-Google-Smtp-Source: APXvYqx2pLCoKh2KSmlGbzzBTINR5OjkrDAttKAH7VuU6MWKYlKDKSDYPlTUup6RvCmqc+VrpnzEKw== X-Received: by 2002:a1c:6356:: with SMTP id x83mr2084900wmb.147.1555668996331; Fri, 19 Apr 2019 03:16:36 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id y17sm3008773wma.8.2019.04.19.03.16.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 03:16:35 -0700 (PDT) Subject: [PATCH v3 11/11] platform/x86: asus-wmi: Do not disable keyboard backlight on unloading 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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> Message-ID: Date: Fri, 19 Apr 2019 12:16:33 +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: <7acd57fe-604a-a96a-4ca2-a25bc88d6405@gmail.com> 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 automatically disabled when the module is unloaded as it is exposed as a ledclass device. Change this behavior to ignore setting brightness when the device is in unloading state. 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 7974283b7b12..02c9639bf54f 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -483,6 +483,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); }