From patchwork Tue May 14 18:50:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943607 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 BEE8B1390 for ; Tue, 14 May 2019 18:50:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADF4B2880B for ; Tue, 14 May 2019 18:50:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC2AD288EA; Tue, 14 May 2019 18:50:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48CCB2890A for ; Tue, 14 May 2019 18:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726528AbfENSug (ORCPT ); Tue, 14 May 2019 14:50:36 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43405 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbfENSuf (ORCPT ); Tue, 14 May 2019 14:50:35 -0400 Received: by mail-wr1-f66.google.com with SMTP id r4so20351526wro.10; Tue, 14 May 2019 11:50:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=QahSchxTBIWvI+J0jeWN31ISJjvI737a7ggT3tukSCc=; b=bi+Vyf31V5rZkxtQ6SBt1edDB9wu533w8hjLnqyJ3p1zpQ5Lqc7IKc3FhHuJeLbLdZ NCp68XJfyHfb+C5gRySGeesutkds2cgY+3YAkUUHKhclwevOp7AR5nOl+1sORsFWV6UC jyE0w81jcpwfi0GaFpJhtFlsqGpXlKknojjF/Ewehjs7nAyqLzL0nzQzRTnSYQdbkwOV cT+A4pDjTEDrJwXH7a+yBZK0ztlkWbXONMkg+dM6yzOFIEMR5/eJLZFgOQ4McqdvUjyF BZw40fh0pC10bSqFxNXkSyYS+Ib05f5ff5bm0tssHIJ07m8BkIGKTj/JjZKdTblsyJu1 ILng== 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=QahSchxTBIWvI+J0jeWN31ISJjvI737a7ggT3tukSCc=; b=j7J6sy01SKm6CA1PkuJHCQySFsr4NjU4JdQSYog/3X+HESRzqyKoAEN0fhm6BaNre2 Dl9WCW/09ZMioSX+n3+whowaEw3K9IMpRmPyitDTxvt3SSMohILwsnAZ/Iyw3eqmyINg dTW84yjaE34gst+phJBq3le7NAp796ICZkgSeJZCyThDbK0bsmLWQfFz2QFd/JlnTsFk ghPUMa9DUz3dt7fdzniQUwEtJkZWWqLRe3NLuJbMsy4fwW6R2887IOLB+zzEWXryjMKH jnxhhIzTOrFDFe0cx/Zx6PFx5OaN0WGhbx0R8kaUxwsghrphK6bxRKlbTTELu36G1ayE kV9A== X-Gm-Message-State: APjAAAXPpIsdGKhowu6e1yEntJ0kQmaDeSxU+/IAUv3zGLoVN1MzpKof NNwTNlTWtMk1fcSIbzRfVe3QqcpY X-Google-Smtp-Source: APXvYqzO2xlinDEk0pB6UN1QnjwARAPwp7hPExd3lViuV1pxpwF8F61asqnlTQu+c8ziwjGohtU93A== X-Received: by 2002:a5d:6710:: with SMTP id o16mr20610564wru.173.1557859833462; Tue, 14 May 2019 11:50:33 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id i25sm6049372wmb.46.2019.05.14.11.50.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 11:50:32 -0700 (PDT) Subject: [PATCH v4 01/13] platform/x86: asus-wmi: Fix hwmon device cleanup From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: Date: Tue, 14 May 2019 20:50:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Daniel Drake --- 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 f94691615881..62567766bdfb 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -1428,11 +1428,12 @@ __ATTRIBUTE_GROUPS(hwmon_attribute); static int asus_wmi_hwmon_init(struct asus_wmi *asus) { + struct device *dev = &asus->platform_device->dev; 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(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 Tue May 14 18:51:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943613 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 E457C1395 for ; Tue, 14 May 2019 18:51:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D379328869 for ; Tue, 14 May 2019 18:51:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D160328939; Tue, 14 May 2019 18:51: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 7450F2893A for ; Tue, 14 May 2019 18:51:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727603AbfENSvf (ORCPT ); Tue, 14 May 2019 14:51:35 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46941 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727568AbfENSvf (ORCPT ); Tue, 14 May 2019 14:51:35 -0400 Received: by mail-wr1-f68.google.com with SMTP id r7so2546810wrr.13; Tue, 14 May 2019 11:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=d6lio4FUKP4hIMj/LmCQXh9/Jwu24a67v0ySJSmb6ow=; b=pT4KgdoiSi1Cc2C8OLXNPnPsmZvr2g3z+jcZqt5z0LqHYaRWIGmXSmv+hH70+1QPhR rJmUeMrlFq29bkMBHV0u1HNDGh+wtG1wJPB3LS/8QY0TuUQviRA0DDYjzfI3Ii7ISjbc vmVfgvKEfYCrUHw1R8XNjO8GGzUOzN7HwZ7RVRC5kRpMDIOpz0uchKrNzAwVP0RtdwzP 0UJHP4xMC099mJCRpSj+1gaDex+vS0Sd+vRXq5FfgtPSbGPDQMOhGmj8nx0+7Aa7BRI6 wv1IHdhh74mNdJruSSQazbhW28wfzdPNI8bN9wLjOrxgoV8O+gvNh2Pakl+jUYuQpLlR i0nA== 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=d6lio4FUKP4hIMj/LmCQXh9/Jwu24a67v0ySJSmb6ow=; b=JQLF+kCZL8q4Fedwe/oiUJdKd2ojqW09QdF33oIF2djdYi4Fj323ylJHaI8X4MwAz8 jFCHF+loc1dzsGHQSTMKznrO418DDnmsSdCQI0xK8Sse+kuQeUZUnMqHSAHzgQpi9NE/ 4ExGqPkdEiLB3Y+UbBSjs+bIiH0RbLN+SZy+suTQrWk+LH4FqxpJ5ksLAPS+0OyX/iC2 LAu04ZnaGetTCE7c4wcf/zB7a+n6dbJ1Vshi0vwMReHKPOjonlokMkSzCmjHFoNJMoeA hhMX5B6sAshSaw7qHdg6XdRLfLxYwSZsNIwltTxnmlNTsrKBpxBQnc2K65GpHS75xFmo vM1A== X-Gm-Message-State: APjAAAVZPoFV39YdQu12gS1LyykGpyismfaKdF2C3Il9UljKAhEnOkCk Wk4HH+n0Ak/gfzlT9PtJ+HPfr3XG X-Google-Smtp-Source: APXvYqzWOeFcKQIQMFm7pqGeA3nLxmR8p68Jpnm7CnQtPAVWAMMO3ceMq753pkbhsao7tUCEA+tG5A== X-Received: by 2002:adf:ce88:: with SMTP id r8mr1325371wrn.191.1557859893270; Tue, 14 May 2019 11:51:33 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id 34sm16442360wre.32.2019.05.14.11.51.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 11:51:32 -0700 (PDT) Subject: [PATCH v4 02/13] platform/x86: asus-wmi: Fix preserving keyboard backlight intensity on load From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <40403d07-293a-62a1-e0e9-ad6a2ba84844@gmail.com> Date: Tue, 14 May 2019 20:51:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The error code and return value are mixed up. The intensity is always set to 0 on load as kbd_led_read returns either 0 or negative value. To reproduce set backlight to maximum, reload driver and try to increase it using keyboard hotkey, the intensity will drop as a result. Correct the implementation. Signed-off-by: Yurii Pavlovskyi Reviewed-by: Daniel Drake --- 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 62567766bdfb..84d7fc6f941c 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -595,8 +595,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 Tue May 14 18:54:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943615 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 9105B6C5 for ; Tue, 14 May 2019 18:54:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DBDC200CB for ; Tue, 14 May 2019 18:54:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 705DD28727; Tue, 14 May 2019 18:54:58 +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 07B89200CB for ; Tue, 14 May 2019 18:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727689AbfENSy5 (ORCPT ); Tue, 14 May 2019 14:54:57 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41474 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727262AbfENSy5 (ORCPT ); Tue, 14 May 2019 14:54:57 -0400 Received: by mail-wr1-f67.google.com with SMTP id d12so20348764wrm.8; Tue, 14 May 2019 11:54:55 -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=1Vtv8vjo+k0fYAQaZ6ozljyJomIPXdJKSl6iEIq/F3I=; b=ZB9BiPN3mcV8aYqzXsJCUdohCAJcs08wznHfJLne6ytAI+7YW66CB4j1QAr2ejeI24 ExZL6IRV+C9NnawmAZlpIK/w+So5zGRd6VfHyDgkMG1gDIi1O/9Wil+w9MaUBQUwaMDm YxZDEcBtjD/rBBahOKUssDBN8r6QwXdvtgal8m0fK+Oda3fQb/DX6d33LuxI/f84JUbR NpsTXTXY1+v2ehlxiFq3SCLUQdeHumdqOYZ9IkCKWB7lVKFOvRLh9oHOCL8q2JhRjdIy 7cjVS//GqEo3uZBcPcdZPtPh4rbydR3cGLI9okWOED7gY+DK/TBV4jbEdpZI/qx2/Aak 8XKQ== 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=1Vtv8vjo+k0fYAQaZ6ozljyJomIPXdJKSl6iEIq/F3I=; b=YraSFOM3ruQDYKtXncObjgYGc3nI35eHPCuJNDNRy50ucI65UkNaOUQ8sZ6R9duza7 hTTHMTia9g4eWXfFOdxqIH5wTSkDn0iaSr9sKkLrLu6Vuepkumb22A/xjHguVzCDrqr3 v4GOsM9ROpZHP1C9kzFZlaxQ8QWhZzFKTCvaABlZv/ngwMlq9yn1BWruYrAXmzq2vdvf L7bQyZltuwtoR9SYrsmxgGDkpM9iuGyIwYjBplqNrfDCNI+XwEyp8okmmxRK5dqI209F eaobenUkQ0jxB/LuOm1IxUTARuIH//AqUH3w/aUvNLEUTFxkvRKpH457UNfLT2vKCveF QJcg== X-Gm-Message-State: APjAAAVXTP99DOJ0EkUgqd1NRP5j+B+o2Dmqbxb1tNGuXwURSykmsKHA op33O1R2JfSl4mc+uVSkEQa+yeBW X-Google-Smtp-Source: APXvYqwmzaWet/cwInE/bAm/HtJVcfbTml8/21zp+y0sovf2T8Cf+yRxZPqzQ9qNOVGsGvEv61ZE3g== X-Received: by 2002:a5d:6145:: with SMTP id y5mr12600574wrt.96.1557860095100; Tue, 14 May 2019 11:54:55 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id a6sm14168275wrp.49.2019.05.14.11.54.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 11:54:54 -0700 (PDT) Subject: [PATCH v4 03/13] platform/x86: asus-wmi: Increase input buffer size of WMI methods From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <4613f54b-b6ba-c9ad-15ca-e43d440b9f63@gmail.com> Date: Tue, 14 May 2019 20:54:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The asus-nb-wmi driver is matched by WMI alias but fails to load on TUF Gaming series laptops producing multiple ACPI errors in 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 Reviewed-by: Daniel Drake --- 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 84d7fc6f941c..6b35c1f00a3e 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -98,6 +98,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; /* @@ -224,11 +225,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_method3(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 }; @@ -260,6 +263,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_method3(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 Tue May 14 18:59:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943617 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 108626C5 for ; Tue, 14 May 2019 18:59:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 005612872E for ; Tue, 14 May 2019 18:59:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4E5128857; Tue, 14 May 2019 18:59:07 +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 801862872E for ; Tue, 14 May 2019 18:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727548AbfENS7H (ORCPT ); Tue, 14 May 2019 14:59:07 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43155 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727262AbfENS7G (ORCPT ); Tue, 14 May 2019 14:59:06 -0400 Received: by mail-wr1-f67.google.com with SMTP id r4so20375019wro.10; Tue, 14 May 2019 11:59:05 -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=l9E2Hq9FLPs2R4k3v/109yiHwcmV7e1E97gP56BV7Ws=; b=mMV13v3wYp7MeJP+JJbIIY9J6fwAq5WmMBPxNmmbBlBB6Gx3ZC8fn0Cmnri+Qjcxtm EokZn6N8kNv7Qf7Kdul4pCvvg3/+Sp3BN6P+AAzp3cvdxVoYU8ZWsPK3kv+j55Taj7Cs ZV9TFVy3CQEz4mUxB4WZmjSEtsu6U7OzTfHkdk3UJB0u8YnVw+mzcHk60MM4x3bFsgHs ad2t43pqUV0H6qK2Y2xJlQqDlmYrGzZTLYf67VZt+4ALoQUfyWEb4/v1CkRSi1S9v+vp q0xFR+SeYEl5DkZqLm60J1G0AD9QhtMpQFp6xGDH2IQearc0BqsxXTbPyzB2aH5V9H7r VY8w== 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=l9E2Hq9FLPs2R4k3v/109yiHwcmV7e1E97gP56BV7Ws=; b=Vt+Rcr7fGjysIF5Lr8eeFipUMGepA+IOB+ua9QExwIR6P3Q/W0uJA+L3pTVv5D5uxB lgNkW5kZ9zM5DTDscIBdV12SgAGAOXSSarsNECakMyoieP4W5+YvJFAs7FIMOhfqT22b tIeJ2XG27B/81yPWOwjIgwiphOaVfGTGQVukG4keipanbh4Fizf3M02iS2Ia5gS6IRFf N0Yg4IzZuRiD+kvFO7+HF2amhOcOJikmtKzqM6wKzXpnhO2dQk1Iqy35Pzvv38eCVJ+n nIu6z2nd91a/fCu030QygOTC+dWEtUue+TcaB3TStKmBKyjAWYPmbIWrvKQkTgbHUxq5 88IQ== X-Gm-Message-State: APjAAAXrFR5iNb498+L7jJapN6AFc8i5vFO9SGcP5sSbqx+pZNoHNlEV c0UEFDVAwktLqxnihdEHcpeqsrS41So= X-Google-Smtp-Source: APXvYqzIpS1v0F/fkPzu9k6g5HPhj2GoIeXfiNytHKhzM2h5jQ8M+SL7ngEBeIHCh1hOz0DT6t1diw== X-Received: by 2002:a5d:4f88:: with SMTP id d8mr4370508wru.34.1557860344753; Tue, 14 May 2019 11:59:04 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id a15sm23035106wru.88.2019.05.14.11.59.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 11:59:04 -0700 (PDT) Subject: [PATCH v4 04/13] platform/x86: wmi: Add function to get _UID of WMI device From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , 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: Message-ID: <35811fe2-7aac-aa3c-46dc-2bef515b0f47@gmail.com> Date: Tue, 14 May 2019 20:59:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a new function to acpi.h / wmi.c that returns _UID of the ACPI WMI device. For example, it returns "ATK" for the following declaration in DSDT: Device (ATKD) { Name (_HID, "PNP0C14" /* Windows Management Instrumentation Device */) // _HID: Hardware ID Name (_UID, "ATK") // _UID: Unique ID .. 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 returned for a specific ACPI device that declares the given GUID, to which it is also mapped by other methods of wmi module. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/wmi.c | 19 +++++++++++++++++++ include/linux/acpi.h | 1 + 2 files changed, 20 insertions(+) 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 */ From patchwork Tue May 14 19:00:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943621 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 BDD966C5 for ; Tue, 14 May 2019 19:00:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAFF8288A7 for ; Tue, 14 May 2019 19:00:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AEDE288B2; Tue, 14 May 2019 19:00: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 A2D33288A7 for ; Tue, 14 May 2019 19:00:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727548AbfENTAi (ORCPT ); Tue, 14 May 2019 15:00:38 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36880 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfENTAh (ORCPT ); Tue, 14 May 2019 15:00:37 -0400 Received: by mail-wm1-f66.google.com with SMTP id 7so174648wmo.2; Tue, 14 May 2019 12:00:35 -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=9JYN5xzhocSIglmrjAdysDK4dh65giGpdMAvsJFJJPY=; b=bnw4+f4VuntzkI+xNK+UL5Y9TBkyQNyV2rFO1J/BdlRVHAFJUmJw5p4avlkaTep9zw yzZvHk60Zeujrjmm5sWJhh5K7b+by/BSGaZ+zp+xZTkWw27JIS1a5UHs/o1Ne1K9Xypm drZOSQTaYc2P2d0mPE0jGbvbSZ+EmENDDrg3yN4dpHEv+xFFY5ny3HhGBikLqUfrv9ZW wHByoUYVIXJfd16ZmlBzMKNp5wNgbKC9dRiO8EoPbuVbXqDgZF2eCx3lIAG+rmI/IbkI LaqcqeOvN//hllIJ/6cCIddIoIdfU26lGIf13bGgxTeZlYdsb/lSu+Qs0TRkqaf2QsDw unyw== 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=9JYN5xzhocSIglmrjAdysDK4dh65giGpdMAvsJFJJPY=; b=cr5dR9LlghqwUYAbsR4kVtHzYLXb1tk9Dxacx0RMYjVBtqkruKy3S8ptxXR56/eghf Z8yBMlprnx28Rf/BEVrXmUSsk5t37JHbKLLNgndRNr9kYARt+QX9ciJJyQByUHQ92jrY 1r9wj8gO93EAl0lmIzWc30Jf2k1GaWLbRYNHr4p6X0YGL6uIZeSJywOthXaWsCGm0jOu H7s1y1fPraY1w2pMicw4AY1GgC9rSsopdLQhsZAgA+jptTqng78E0t1dfGAUhHpKVr9R oozKb196Wu0k2BfR48Ke4dAiktRboVW7uuz27IJ7+hma9TjGYSeHpIvVO7OxuK5mtDQv E/9A== X-Gm-Message-State: APjAAAVgxGdOHqWFOlCB7nlL850ADhWaf6UklYQDXknINDWkDFY6F05H 0VOQDhcYMooMGhV4hh3/5crLJ//zwpA= X-Google-Smtp-Source: APXvYqwH6CnDSNclbIqoYhw2TUiwGx48ELojPYaEp/66QlUy6nqSg2Sbws0ZyFLMiYqUvI+EBIB3HA== X-Received: by 2002:a1c:ca0b:: with SMTP id a11mr20885165wmg.52.1557860434790; Tue, 14 May 2019 12:00:34 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id l14sm16996166wrt.57.2019.05.14.12.00.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:00:34 -0700 (PDT) Subject: [PATCH v4 05/13] platform/x86: asus-wmi: Improve DSTS WMI method ID detection From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org References: Message-ID: <34f49a73-a556-9e5a-fa07-938d43ac6225@gmail.com> Date: Tue, 14 May 2019 21:00:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The DSTS method detection 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 detection based on _UID of the WMI device 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]. DSDT examples: FX505GM (_UID ATK): Method (WMNB, 3, Serialized) { ... If ((Local0 == 0x53545344)) { ... Return (Zero) } ... // No return } K54C (_UID ATK): Method (WMNB, 3, Serialized) { ... If ((Local0 == 0x53545344)) { ... Return (0x02) } ... Return (0xFFFFFFFE) } [1] Link: https://lkml.org/lkml/2019/4/11/322 Signed-off-by: Yurii Pavlovskyi Suggested-by: Daniel Drake --- Depends on the previous patch in the series that adds method to wmi module. --- drivers/hid/hid-asus.c | 2 +- drivers/platform/x86/asus-wmi.c | 23 +++++++++++++++++++--- include/linux/platform_data/x86/asus-wmi.h | 4 ++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 336aeaed1159..1d01fe23ca0c 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -396,7 +396,7 @@ static bool asus_kbd_wmi_led_control_present(struct hid_device *hdev) if (!IS_ENABLED(CONFIG_ASUS_WMI)) return false; - ret = asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS2, + ret = asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS, ASUS_WMI_DEVID_KBD_BACKLIGHT, 0, &value); hid_dbg(hdev, "WMI backlight check: rc %d value %x", ret, value); if (ret) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 6b35c1f00a3e..5bdb4ffdbee3 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -83,6 +83,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) @@ -1874,6 +1876,8 @@ static int asus_wmi_sysfs_init(struct platform_device *device) */ static int asus_wmi_platform_init(struct asus_wmi *asus) { + struct device *dev = &asus->platform_device->dev; + char *wmi_uid; int rv; /* INIT enable hotkeys on some models */ @@ -1903,11 +1907,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)) { + dev_info(dev, "Detected ASUSWMI, use DCTS\n"); + asus->dsts_id = ASUS_WMI_METHODID_DCTS; + } else { + dev_info(dev, "Detected %s, not ASUSWMI, use DSTS\n", wmi_uid); asus->dsts_id = ASUS_WMI_METHODID_DSTS; - else - asus->dsts_id = ASUS_WMI_METHODID_DSTS2; + } /* CWAP allow to define the behavior of the Fn+F2 key, * this method doesn't seems to be present on Eee PCs */ diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index bfba245636a7..0668f76df921 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_DCTS 0x53544344 /* Device status (DCTS) */ +#define ASUS_WMI_METHODID_DSTS 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 Tue May 14 19:01:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943625 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 5677592A for ; Tue, 14 May 2019 19:01:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4525D288A7 for ; Tue, 14 May 2019 19:01:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 384B8288AD; Tue, 14 May 2019 19:01:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9451288A7 for ; Tue, 14 May 2019 19:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727548AbfENTBb (ORCPT ); Tue, 14 May 2019 15:01:31 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55977 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfENTBb (ORCPT ); Tue, 14 May 2019 15:01:31 -0400 Received: by mail-wm1-f68.google.com with SMTP id x64so170338wmb.5; Tue, 14 May 2019 12:01: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=yKJtRNLjUlsE2AHcVMIA1x07TU3dSlb+s1DhsyS3+wE=; b=iJPtOyESOdvx9dnZIhnOoGHJy0PYv+xOrJEg5/QfqQuGBvfiuepkt7Zu3dmXEA58Ef wpq1aXA5AEYjRQpu/i4NjYlMZ9x+9+Ukzlo5f4OgIfnOAHjyjIeODV2zSqCqvqH6xZrg Gdqa/Bm73NZli+seeDAvdqDYYCGoZ9WpwN5gGYwIZYiVQDPUNkM0lCGXbEk0pLZTDDzb 8oC9Sb6myG8oYripgTZUJUZGEGHYqLrB8pk73D2SkxP3PxGWuT+NhTkAjQBJXnmauN8/ 8QHY8svdTpYIGrvb3K/qe+cuSeT6M/wgUIslnm8mDNadJ7peGWUNyQhdMAxtt0oONvOw Vh8A== 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=yKJtRNLjUlsE2AHcVMIA1x07TU3dSlb+s1DhsyS3+wE=; b=IlDr1gaUp+vSZ/CQMEtORuqOMhxgc80sumWr+EVywfoYFwVL7mhb7FM3P5xKJvf4/9 zLkLa/A9l17xsUoH4oeJDOZ0nIGIA0+RZjWTwqWGk8+oCDn3cuEicBZM9WQ2xoANNhkY 49WTzwCii6UbB83yH9k6mNfb6A02Z3Sa0s+oi6Jhl4pTcqpO1Qsma+Jn7rfYdKxzQpda 7H6FB+Tis4SebGOWBKTzBxHGZXRCp9jIPlCLZZan/V4FEmP86iG23qdDOdWjn9niqbYR Cs5riSiunhRb3BVJy1SGaSpGKlmX9qjNfFq+Tf/JITzdb7MJ6ap6sWmDxfTvy7Cclo9q l8zA== X-Gm-Message-State: APjAAAXVF5LfMAxc8vxTqeODi+j6kFh5jkCtLYEp9JDWiJEwH19+NXjX 5GrbB9lEUnfZTDmHGWzjZ0A7Vocr X-Google-Smtp-Source: APXvYqzoxI6X6dueMRlGpARdmg4YhJtdbP6LCeRQwDtlyNLOa+h3wXxUIh03CMQvg25fem92RzzWhw== X-Received: by 2002:a1c:3c2:: with SMTP id 185mr3024200wmd.91.1557860487478; Tue, 14 May 2019 12:01:27 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id z13sm2565466wrw.42.2019.05.14.12.01.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:01:27 -0700 (PDT) Subject: [PATCH v4 06/13] platform/x86: asus-wmi: Refactor WMI event handling From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <6a62a746-6c0d-e786-1edc-febbfc083a64@gmail.com> Date: Tue, 14 May 2019 21:01:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Refactor WMI event handling into separate functions for getting the event code and handling the retrieved event code as a preparation for introduction of WMI event queue support. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-wmi.c | 66 +++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 5bdb4ffdbee3..ed7c7857012e 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -85,6 +85,8 @@ MODULE_LICENSE("GPL"); #define ASUS_ACPI_UID_ASUSWMI "ASUSWMI" +#define WMI_EVENT_MASK 0xFFFF + static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; static bool ashs_present(void) @@ -1651,83 +1653,99 @@ static void asus_wmi_fnlock_update(struct asus_wmi *asus) asus_wmi_set_devstate(ASUS_WMI_DEVID_FNLOCK, mode, NULL); } -static void asus_wmi_notify(u32 value, void *context) +static int asus_wmi_get_event_code(u32 value) { - struct asus_wmi *asus = context; struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *obj; acpi_status status; int code; - int orig_code; - unsigned int key_value = 1; - bool autorelease = 1; status = wmi_get_event_data(value, &response); - if (status != AE_OK) { - pr_err("bad event status 0x%x\n", status); - return; + if (ACPI_FAILURE(status)) { + pr_warn("Failed to get WMI notify code: %s\n", + acpi_format_exception(status)); + return -EIO; } obj = (union acpi_object *)response.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); + else + code = -EIO; + + kfree(obj); + return code; +} + +static void asus_wmi_handle_event_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 (code == NOTIFY_FNLOCK_TOGGLE) { asus->fnlock_locked = !asus->fnlock_locked; asus_wmi_fnlock_update(asus); - 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 = asus_wmi_get_event_code(value); + + if (code < 0) { + pr_warn("Failed to get notify code: %d\n", code); + return; + } + + asus_wmi_handle_event_code(code, asus); } /* From patchwork Tue May 14 19:02:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943627 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 77C0E6C5 for ; Tue, 14 May 2019 19:02:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 660D3288AE for ; Tue, 14 May 2019 19:02:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59FD2288B3; Tue, 14 May 2019 19:02:16 +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 BE7C9288B2 for ; Tue, 14 May 2019 19:02:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726349AbfENTCP (ORCPT ); Tue, 14 May 2019 15:02:15 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:56033 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfENTCP (ORCPT ); Tue, 14 May 2019 15:02:15 -0400 Received: by mail-wm1-f66.google.com with SMTP id x64so172192wmb.5; Tue, 14 May 2019 12:02:13 -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=yo7r101M/AfD1g31icOMjiH0I9ZSoHBETrIltxCtNy4=; b=SIjr/wdI6ImlsC3Ym/HqbCUPgnsObWp08uipt+z/0srX76WkSr2CmXs/4WtqlWmIYK l1DiIQiHhMkxbkHU67euMNpyZkb3Aw4wiJcApBTmvq3PYXGngfxHlaZO947iqLKJa4qA w6EUg82NwnqyA4Gw8F6uCA4zp+LiHuHgfaC+w8NxSMeeKHoIhlPXhIr1kW9+YqTmDgTV rGlI5F4Sx+eGFbmkKbYC5stgNZxl6lBot5yMe4Odhi53DcUNQDJquVgDRTDy6ryRYKva PUvs0YOrOYWR8TD7bwFc1EXmWTmtiIUgm81DVMg6CnOWQtitXGa/yRrOB/cJuoAx+X/j RtdA== 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=yo7r101M/AfD1g31icOMjiH0I9ZSoHBETrIltxCtNy4=; b=t9hT3E7j6xBWoH0IoaBLb7EgI4Myp9XA90dJ970/thfURz3RYOTbi0S4u6ubqsnfPk 1FNauWQNlNTs7nyC2G8eVXLGkUiYo4uXuCT82JGq2Nw2d5vB6NxC8hzR2M8hnNA3KG9n 9/NOAMFXwpKttXZu8H/jBqY9jiItv3b2T0kQnzhEvowt16HpEz85CfMTFLEa1foiadNB a3U27jkvRMM8PC2cWyQTbpUp0Hl1WWLh2JR9CRt5bPc477Iu6k1xoCLXbiNitlJ+pdbt KPjAG/FKLFgMLe6oQjVMpZGoRvbHqMwnzGiDYuOTp9AZRBuVho4Eu/hfRpl0bhRAxpTI pw/Q== X-Gm-Message-State: APjAAAXwC/zTUUf2D7oJAvtWJlR/OdEGiXgi/yCikC9Jq9EPWCdLYe6S X1SUUBE5OTFn+gSDcT2Sw3/tWHUh X-Google-Smtp-Source: APXvYqwBTi+w1H14QtYdDtcOgFsjKTaPN+cyurLUgUQorZWiqttRAdXnyzll0OFdMV4WlniIHv3FYw== X-Received: by 2002:a1c:e708:: with SMTP id e8mr10536926wmh.11.1557860532250; Tue, 14 May 2019 12:02:12 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id j131sm6406569wmb.9.2019.05.14.12.02.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:02:11 -0700 (PDT) Subject: [PATCH v4 07/13] platform/x86: asus-wmi: Support WMI event queue From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <28b9a17e-fb23-5277-4f65-26cae9f2837f@gmail.com> Date: Tue, 14 May 2019 21:02:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Event codes are expected to be 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] Link: https://lkml.org/lkml/2019/4/12/104 Signed-off-by: Yurii Pavlovskyi Suggested-by: Daniel Drake --- drivers/platform/x86/asus-wmi.c | 73 ++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index ed7c7857012e..7bfac06abae4 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -84,6 +84,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 #define WMI_EVENT_MASK 0xFFFF @@ -150,6 +157,7 @@ struct asus_wmi { int dsts_id; int spec; int sfun; + bool wmi_event_queue; struct input_dev *inputdev; struct backlight_device *backlight_device; @@ -1738,14 +1746,52 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus) static void asus_wmi_notify(u32 value, void *context) { struct asus_wmi *asus = context; - int code = asus_wmi_get_event_code(value); + int code; + int i; - if (code < 0) { - pr_warn("Failed to get notify code: %d\n", code); - return; + for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) { + code = asus_wmi_get_event_code(value); + + if (code < 0) { + pr_warn("Failed to get notify code: %d\n", code); + return; + } + + if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK) + return; + + asus_wmi_handle_event_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; } - asus_wmi_handle_event_code(code, asus); + 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_event_code(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; } /* @@ -1944,6 +1990,23 @@ static int asus_wmi_platform_init(struct asus_wmi *asus) asus->dsts_id = ASUS_WMI_METHODID_DSTS; } + /* + * 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)) { + dev_info(dev, "Detected ATK, enable event queue\n"); + + if (!asus_wmi_notify_queue_flush(asus)) + 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) From patchwork Tue May 14 19:02:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943629 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 2DEB66C5 for ; Tue, 14 May 2019 19:03:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D51B288AE for ; Tue, 14 May 2019 19:03:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11303288B3; Tue, 14 May 2019 19:03:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85CFD288AE for ; Tue, 14 May 2019 19:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727603AbfENTDD (ORCPT ); Tue, 14 May 2019 15:03:03 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:44610 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfENTDC (ORCPT ); Tue, 14 May 2019 15:03:02 -0400 Received: by mail-wr1-f66.google.com with SMTP id c5so20371410wrs.11; Tue, 14 May 2019 12:03:01 -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=Y1ofVraaip9a2gjL9BqnHJ5ZBKJEU70Pu4axWdX0F7QOTlWl7Uq8HgRnVn3Dli4Z0K 7ZNmeq6FMC/bZxJPQqR4zVw6lzJKDfAljqqDWdMh4IZafU/gjmBRJJuFHHn4R7KPYBjU 1XdqD7IocbNWLut35NzgF5NoRtkC4IZLcAEVASsYEIFXMJX3bXf1n8zc8efxZ8WT6zCI E0qh1P1lU8Q7EHmQRVbaJ0boruY+0wOvN8T+hns4nAMmR/6UtM/+wPuhtMwF9VESaeLY Xisw6dE2kGcj0ThixD3UzRdlMBW2k6nowE5IGs8LfaAQcNEYcUMt2zWu6ncFErxq8N8b iRzQ== 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=CZv8iab8/QVat+7tuFgi7qEeKiHIhPeh4Mb8Q3lwHfhvCWDUj7TQ08X1qLG3dLcB6A czEa0IrfGHpy1+q7rnzpGNjb4QoOgr/5NZmQW9wN9rb//tmAalnwrXnaiTH8x7dqMkza BLi1Wq+d7b75FqeUv94dUhJnoWtc/7siadkxuC71SbJbATucwhbMZ6I6wmY68ZdXkRxM 7BMD8uyCSbGBcWhs5QKZlmEWHx5i8/ObcDIbyM/h+In8YdVt4Yg8t8wAU81+BjT7jOMR NDHEvrLgtTtQ1n20wR/eDqWWhqULaqwIq3ItXpdlyMVq85qzcbhFnnVyfyi9fSNJXSOz ZRRw== X-Gm-Message-State: APjAAAUS2NetfXGMjZOC2sesCr8tG9DDVCzsK2WRKPwdP7W4jCMdaz+K bZzPxwf1jjRGor7f4NmVIFJllYFp X-Google-Smtp-Source: APXvYqxXcfcnla7n8+Hj+Aa1XQSznK4g6YR6aBmJXl+hY3aYW7XYrHTGEPxJ6gvsBNCl1XRsTuf+fw== X-Received: by 2002:adf:8043:: with SMTP id 61mr13618256wrk.47.1557860580863; Tue, 14 May 2019 12:03:00 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id u9sm4967312wmd.14.2019.05.14.12.02.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:03:00 -0700 (PDT) Subject: [PATCH v4 08/13] platform/x86: asus-nb-wmi: Add microphone mute key code From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: Date: Tue, 14 May 2019 21:02:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US 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 Tue May 14 19:03:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943631 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 A71276C5 for ; Tue, 14 May 2019 19:03:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95AF2288B2 for ; Tue, 14 May 2019 19:03:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8862D288B9; Tue, 14 May 2019 19:03:58 +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 3AF59288B2 for ; Tue, 14 May 2019 19:03:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726525AbfENTD5 (ORCPT ); Tue, 14 May 2019 15:03:57 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:54182 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfENTD5 (ORCPT ); Tue, 14 May 2019 15:03:57 -0400 Received: by mail-wm1-f66.google.com with SMTP id 198so186149wme.3; Tue, 14 May 2019 12:03:55 -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=sYVFDe3XqiJYZ+Tuzea4frhnmRETpX1L6lMup8xZtl4=; b=Fk3l+KWqIIZwCrXmXQw/HBB3jC+TlCkRV1reTLvun1PUrOnB7zdmo8Ou5HysPsE8Sx UQUwsTPMDVj4C74rilPIyn6TLodnbCnyn/C0xaCg1s1eTv17MIfJTbnfm1VKN4s5Vor0 jnsoCvjMMMk1NxVmRGYU5i0bo7f6xbgqWHFpcXd0JHxR5frVSA/gVZlDUNrKOoP7687x q7TVwTHy0vz2JBwRQ6p3N3WIPgnwHZ3Fb47cHmsP00yPhhm8jAkWy1fSeiTN7uXncxFR jfsiqXrEKCrr06TSKlt4cokIokIDSrtfinGxMq3XN5mVP3adCl+r//B9MfcLK3034BSu YZuA== 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=sYVFDe3XqiJYZ+Tuzea4frhnmRETpX1L6lMup8xZtl4=; b=D75rEJMqDh29+7f626yPbdhfuckQiA816oE7bTBaw0pArY3NugARIOmaUmok1wIUJt u7H5UKIztBq4ICc40spHLZE1qs/dLnHFbjDSV5aS0qsdjoXylYZyJ+NlqVRNhgAY493j Cdfr2ppf3ZczrivytK90VYFRqIdcJ9mRX5UMBTvopN0hWYb5o/u0NQmb1XygFHhCEZWw Ngfw82V33yH0IyLSanD6vVzKsFHKFzcDeGNNF5Ne3ESxgs/M/IDtM/uQsxK04TXvS2N+ T1BofN98kmKpNhd4xvl6XvLhfpa/RiV+iDXu2P+3Nn1ACT13WTVZz3w01MUZSMkRlbSi KOUg== X-Gm-Message-State: APjAAAVFlZlzGFG7FUfcCc2piZ62QZ0k0Ybwt8yLLK+Ii96OFEwus0MU /wu6C2uG/VKbqhO8uEtz8GMDyhPm X-Google-Smtp-Source: APXvYqyX0XNMs0j6zQtvmRM5tuqM0jYm2QFJfJx+fzJ9g3rwQQRpJBojJeR+Q/sFDCgqkEnfDi2PJg== X-Received: by 2002:a1c:9d0f:: with SMTP id g15mr21128730wme.97.1557860634659; Tue, 14 May 2019 12:03:54 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id 15sm3999650wmg.36.2019.05.14.12.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:03:54 -0700 (PDT) Subject: [PATCH v4 09/13] platform/x86: asus-wmi: Refactor error handling From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <18233d8b-0724-f0c7-2931-def225bd650c@gmail.com> Date: Tue, 14 May 2019 21:03:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove exit label as it is only used once from the point in code where no cleanup is required and return can be called immediately. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-wmi.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 7bfac06abae4..090a00af4017 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -255,7 +255,7 @@ static int asus_wmi_evaluate_method3(u32 method_id, &input, &output); if (ACPI_FAILURE(status)) - goto exit; + return -EIO; obj = (union acpi_object *)output.pointer; if (obj && obj->type == ACPI_TYPE_INTEGER) @@ -266,10 +266,6 @@ static int asus_wmi_evaluate_method3(u32 method_id, kfree(obj); -exit: - if (ACPI_FAILURE(status)) - return -EIO; - if (tmp == ASUS_WMI_UNSUPPORTED_METHOD) return -ENODEV; From patchwork Tue May 14 19:04:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943635 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 B98216C5 for ; Tue, 14 May 2019 19:05:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8C8D28712 for ; Tue, 14 May 2019 19:05:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A00C287BB; Tue, 14 May 2019 19:05:00 +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 F190728712 for ; Tue, 14 May 2019 19:04:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727695AbfENTEy (ORCPT ); Tue, 14 May 2019 15:04:54 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34662 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfENTEx (ORCPT ); Tue, 14 May 2019 15:04:53 -0400 Received: by mail-wr1-f68.google.com with SMTP id f8so22587wrt.1; Tue, 14 May 2019 12:04:51 -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=CGGKxWzCjGjLD3yIJGbckhYKgkACoCZzEyygAEOtw4U=; b=WanPv09yYpjsOoDNKQ/yR66DAhsDJQ1jJy3yp/Cb3LVPT2UwKjPi7OrbcUkTH3Xj0R 0sl6cAYx8hvuo1AqWH0+5o+/pxnYPhynGqexzftchESvwMTjtIkVTAaHF4wYwiBsRanY gF8A9vJBnYoeFjNuVJRMhlw/Hc493LC24pwrP8U+tRMI2NcVhESdm46pS2TyS4OH01LZ wdnClfcZ+yEDyNS3otKLkAUjaau2dq6XuthXT0Dc2qOPALOiLgq2xchj8F/yxPvJFJUA 3Roe4YfjwijZN8tNYUQ88DD93GQRgop+kfcgyb6nI8ivRGRYo2m8oAz6Mn07FbB/SSgw 6GRg== 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=CGGKxWzCjGjLD3yIJGbckhYKgkACoCZzEyygAEOtw4U=; b=I5IvP4Vw4ECx8nbd9PqTlxUU16Bz1Cj9zXyHRNt7J1p6ayuiylSsqgstDpbVVmUuwf Vc/IbUKRjCVoW1MgnfLcRepKK9lBVlL56RQV4NTKDVxBOO0014B46Tv9LZiq0Z9Nr0A+ 3bW+jUGNvY65kuYBwXUw1KNSe61CYTIdPtFPb0k86zMGCiymfS0XyAyw3I/vN3DuRcpf Lu6Y/+NuNxXztwY36ayH0mr63J/bVURTBVWTNhlqmvnsrwSz1/FecktPZsGntXFJEJgF pYX02tnOritai3HAyF659UYhWh8lMJ9NP+h2hHVndr8Uz9dHx2vGnwyLHNv3acSoNnEQ mtMA== X-Gm-Message-State: APjAAAVTCCTwx5hLviX4cY9vJK+2gMeC1nT5KORqnSDRcOLq2alCpVXf ZhKB84a0YDGngQ/SP1eM2lhB7pHa X-Google-Smtp-Source: APXvYqzCa8t16ENhUMwee6cVnxgPEW/zY1GFfnPC/skO5VefUG8+TM3j/V9LvhLemaEGlERcRIrUsw== X-Received: by 2002:adf:e8d2:: with SMTP id k18mr16033174wrn.329.1557860690815; Tue, 14 May 2019 12:04:50 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id o4sm4498916wmc.38.2019.05.14.12.04.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:04:50 -0700 (PDT) Subject: [PATCH v4 10/13] platform/x86: asus-wmi: Organize code into sections From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <9634285d-df3c-f927-6f1c-e9d43c45bc37@gmail.com> Date: Tue, 14 May 2019 21:04:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver has grown 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 | 89 +++++++++++++++++---------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 090a00af4017..bd9eb00f3a27 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -200,6 +200,8 @@ struct asus_wmi { struct asus_wmi_driver *driver; }; +/* Input **********************************************************************/ + static int asus_wmi_input_init(struct asus_wmi *asus) { int err; @@ -237,6 +239,8 @@ static void asus_wmi_input_exit(struct asus_wmi *asus) asus->inputdev = NULL; } +/* WMI ************************************************************************/ + static int asus_wmi_evaluate_method3(u32 method_id, u32 arg0, u32 arg1, u32 arg2, u32 *retval) { @@ -349,9 +353,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 @@ -661,6 +664,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus) return rv; } +/* RF *************************************************************************/ /* * PCI hotplug (for wlan rfkill) @@ -1083,6 +1087,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; @@ -1115,9 +1121,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) { @@ -1456,9 +1461,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; @@ -1640,6 +1663,8 @@ static int is_display_toggle(int code) return 0; } +/* Fn-lock ********************************************************************/ + static bool asus_wmi_has_fnlock_key(struct asus_wmi *asus) { u32 result; @@ -1657,6 +1682,8 @@ static void asus_wmi_fnlock_update(struct asus_wmi *asus) asus_wmi_set_devstate(ASUS_WMI_DEVID_FNLOCK, mode, NULL); } +/* WMI events *****************************************************************/ + static int asus_wmi_get_event_code(u32 value) { struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; @@ -1790,9 +1817,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) @@ -1931,9 +1957,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) { struct device *dev = &asus->platform_device->dev; @@ -2017,9 +2042,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; @@ -2166,28 +2190,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; +/* Init / exit ****************************************************************/ - 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; -} - -/* - * WMI Driver - */ static int asus_wmi_add(struct platform_device *pdev) { struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver); @@ -2319,9 +2323,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); @@ -2397,6 +2400,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 Tue May 14 19:05:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943637 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 564EB6C5 for ; Tue, 14 May 2019 19:06:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F2482839C for ; Tue, 14 May 2019 19:06:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EAE12884B; Tue, 14 May 2019 19:06:05 +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 0A88F28866 for ; Tue, 14 May 2019 19:05:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726997AbfENTFv (ORCPT ); Tue, 14 May 2019 15:05:51 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:32885 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfENTFv (ORCPT ); Tue, 14 May 2019 15:05:51 -0400 Received: by mail-wr1-f67.google.com with SMTP id d9so30407wrx.0; Tue, 14 May 2019 12:05:50 -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=9pfI3srMSByRODiYcZr4ZtqF03RJNVK9yMTlRMMaTfQ=; b=pKmnvzEB/YevalzL3D4GOPHycFYANAZx8DsdP7qscjQC8l9kIKvTzSREC8owpzMwcW viucoLH1r0jh/MncSEpmVVSQSPJqar1kPsVer1xylbvQQRxdaVrmiea+A5oasrcEjlBf WyuxhM9ej+EflZqlGtHl8Fme1VoVdoAwRABgHaoAqNGzqRda0pkk+CODW4/OJmFBUVbW aqYmMut1d4Hv/xV4L2VYVKuNu7WQ55BfoK0PfSjudxhSD5zC1TJ//saw3c4I8Bh07VnU sf+HBQs0y0cqQUQRiva1yYWsvN/Om8XMdaiwRLzIyI7IgcMxZiu2VSIFNldqMEZQNaQ9 71HQ== 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=9pfI3srMSByRODiYcZr4ZtqF03RJNVK9yMTlRMMaTfQ=; b=rhw63wD+EyXWhQcGt7NPXhXastXfDm3QZ2+0YUbOo1QbQ/zDshk9EVv51U6rohJg/a ud3HGfxY2eaFtB9Hgsh9DdqkaQdJEcyLB9Rkoy6YLCqRjrLEQKSpNxi1z1wd/8hkCkBG 3Vq/nKdgCr8FX1PoK/AjSuIc4VE9k4TiXB7LZDqsiEC2wvR+3LNrnjhdY1SV3sfsBUzI 0+4kFe1WuqSHqRVA6Af1GqS6gT3oA43dDEprOE3bFCnjvTAOHtzVKz/y8Td3wNlTFsyg Yz43b/Q/T1R5vH42EjWBvYGq/emsk4Vh3o+VqVoPTL4S9L1pa3klY7S1LbGLGiUquhCT ipGQ== X-Gm-Message-State: APjAAAWPqxguxC2Dr5cjYy+QxOw7yL9fLwlP0f45EfyIDCEnROdINh9c aqXdi2+9UhaN91vMoUypmue3NnVW X-Google-Smtp-Source: APXvYqwwaILkvlFnNKLGMYnZtPK7bU9k+Ym3LnugsCnNJ/JoamOttTiPRE49z/Ea9+psKnWxXW4Adw== X-Received: by 2002:a5d:53c6:: with SMTP id a6mr21892400wrw.232.1557860749292; Tue, 14 May 2019 12:05:49 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id n2sm30109774wra.89.2019.05.14.12.05.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:05:48 -0700 (PDT) Subject: [PATCH v4 11/13] platform/x86: asus-wmi: Enhance detection of thermal data From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: Date: Tue, 14 May 2019 21:05:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The obviously wrong value 1 for temperature device ID in this driver is returned by at least some devices, including TUF Gaming series laptops, instead of 0 as expected previously. Observable effect is that a temp1_input in hwmon reads temperature near absolute zero. Consider 0.1 K an erroneous value in addition to 0 K. Signed-off-by: Yurii Pavlovskyi --- drivers/platform/x86/asus-wmi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index bd9eb00f3a27..ffb4e2530ea4 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -1428,8 +1428,11 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj, 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) + /* + * If the temperature value in deci-Kelvin is near the absolute + * zero temperature, something is clearly wrong + */ + if (value == 0 || value == 1) ok = false; } else if (fan_attr <= asus->asus_hwmon_num_fans && fan_attr != -1) { ok = true; From patchwork Tue May 14 19:07:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943639 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 13B461398 for ; Tue, 14 May 2019 19:07:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 037552839C for ; Tue, 14 May 2019 19:07:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB7C4288AE; Tue, 14 May 2019 19:07: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 315C62839C for ; Tue, 14 May 2019 19:07:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727687AbfENTHM (ORCPT ); Tue, 14 May 2019 15:07:12 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:36356 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727499AbfENTHM (ORCPT ); Tue, 14 May 2019 15:07:12 -0400 Received: by mail-wm1-f67.google.com with SMTP id j187so193726wmj.1; Tue, 14 May 2019 12:07: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=ksXG33XxCM/tWPchkEzcUcVLZ+fHjEE9qZ9P8OtNNeE=; b=cKp/T5W71pJ9ubcx5yMJAn2g7GoS2YuN5ETkcmTnVk/Hl2sBTpUBfg696KZo7r9vLX r9XMyNi/EIe+/pjLoNgCudtvRLbdwW3NireVEZVT4Kaoe+gIDhqyrQ0sS6nC+5I/U9EI IhenExgrST/HE7QCzd0JkDg2TViIWX75KQPOMpO+R3CyZeXGTV5Z40DNNGsEIp52FiDg /HH0O2ju1VDjOEsPHgJxK7kpIhfTztC9sl/RWaRCjrfKh9YPtUC+IyzChuF0IqfDbJyP CC5cl2LOtFTWVW1vAzGBi9nhEpexaK8hMISoj4JcVSGIYff4m8i3jDUEbFdQZj3oeIxP 8mWA== 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=ksXG33XxCM/tWPchkEzcUcVLZ+fHjEE9qZ9P8OtNNeE=; b=DxvS9f59x/JgusStoXMtJxwt8ZvGhsRKyDqmt5l3eiF+ISV4SQwyycSJW91f6vEb2u oX8sTCcJXjjcWNmY8z5Jba4JRwOMO3hT5v/uyYI/CxaxUjhoq2pv52dW1MvKSdTiyvvB eFjAUGm53/xHcTA34HDpnCjQnrQ27DDttvVDqQsCqdWRsIxY5P5Zczw/ujcwOjDsdCT5 lokqR5oSYPnfS8QyQDwI5JR8z3fyvxO4tlX2iWW1NLXvhVKbSqZJ1rIpYy1gOkjz/X1q 9wPBYRcwkY3BKZhp9QI4FkNB1KqgiBcXlMAMzKDgNPy5ERBXqnom0kKmBvNHW6NEDfDd T2cA== X-Gm-Message-State: APjAAAVldPQvuN86yqOQ/VUvfkhSf+69TNampcffwvKHSJmm6ks0pka2 9BQ8ZjkLARuOFM/vGlF3UWtjMi6Q X-Google-Smtp-Source: APXvYqy/WzojXzvDr2bS9B8cKeu817HQTBhTTU7gbXAnwwEPVJvZaI4uef4EYe9+1cW89gksBeg9gg== X-Received: by 2002:a7b:c4d1:: with SMTP id g17mr11698396wmk.103.1557860829105; Tue, 14 May 2019 12:07:09 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id c6sm4305668wmb.21.2019.05.14.12.07.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:07:08 -0700 (PDT) Subject: [PATCH v4 12/13] platform/x86: asus-wmi: Switch fan boost mode From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org References: Message-ID: <6f651bf4-cf3d-2ba5-fe11-85c45d2f111d@gmail.com> Date: Tue, 14 May 2019 21:07:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The WMI exposes a write-only device ID where up to three fan 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 this capability 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] Link: 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 | 151 +++++++++++++++++- include/linux/platform_data/x86/asus-wmi.h | 1 + 3 files changed, 154 insertions(+), 8 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 019e1e29370e..87ae5cc983bf 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -36,3 +36,13 @@ KernelVersion: 3.5 Contact: "AceLan Kao" Description: Resume on lid open. 1 means on, 0 means off. + +What: /sys/devices/platform//fan_mode +Date: Apr 2019 +KernelVersion: 5.2 +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 ffb4e2530ea4..feb8d72fc3c5 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -70,6 +70,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_WMI_FNLOCK_BIOS_DISABLED BIT(0) @@ -80,6 +81,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 @@ -187,6 +195,10 @@ struct asus_wmi { int asus_hwmon_num_fans; int asus_hwmon_pwm; + bool fan_mode_available; + u8 fan_mode_mask; + u8 fan_mode; + struct hotplug_slot hotplug_slot; struct mutex hotplug_lock; struct mutex wmi_lock; @@ -1483,6 +1495,116 @@ 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 scnprintf(buf, PAGE_SIZE, "%d\n", asus->fan_mode); +} + +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 = kstrtou8(buf, 10, &new_mode); + if (result < 0) { + pr_warn("Trying to store invalid value\n"); + 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) @@ -1761,6 +1883,11 @@ static void asus_wmi_handle_event_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; @@ -1917,6 +2044,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 }; @@ -1938,6 +2066,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); @@ -2037,12 +2167,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 ********************************************************************/ @@ -2221,6 +2346,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; @@ -2302,7 +2435,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; @@ -2319,7 +2454,7 @@ static int asus_wmi_remove(struct platform_device *device) asus_wmi_led_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 0668f76df921..8551156b8dca 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -57,6 +57,7 @@ #define ASUS_WMI_DEVID_KBD_BACKLIGHT 0x00050021 #define ASUS_WMI_DEVID_LIGHT_SENSOR 0x00050022 /* ?? */ #define ASUS_WMI_DEVID_LIGHTBAR 0x00050025 +#define ASUS_WMI_DEVID_FAN_MODE 0x00110018 /* Misc */ #define ASUS_WMI_DEVID_CAMERA 0x00060013 From patchwork Tue May 14 19:07:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yurii Pavlovskyi X-Patchwork-Id: 10943641 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 490C11398 for ; Tue, 14 May 2019 19:07:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37AE12839C for ; Tue, 14 May 2019 19:07:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 295D9288AE; Tue, 14 May 2019 19:07:51 +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 D1CA72839C for ; Tue, 14 May 2019 19:07:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726605AbfENTHu (ORCPT ); Tue, 14 May 2019 15:07:50 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:39663 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfENTHu (ORCPT ); Tue, 14 May 2019 15:07:50 -0400 Received: by mail-wr1-f67.google.com with SMTP id w8so3711wrl.6; Tue, 14 May 2019 12:07:49 -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=qn66etOm0a5xQIu8htrI+8Q6SfvX5qKGBW8UZZdluKk=; b=raj+jxF5DpoWv0GMlZ/X5zUnAPvykosrsBJkIlHOqdz4SUaPZBnm6lBXUKaRUh4Bcx lOZJfQG6N659pdZCfUEt+Yj/LpBw437H8sDocWFs3AQmWR9v/FawHzhYfUzs/ElLqk24 AmN9AR8dCVTjIuGwjGC7wfOJi83TF9QfpyOlYO6f6tTX43kaOj70okkEHc8saNDaXGZE FMFAqum02glaCx+RahB1Szcsc9rlMuvVWzfHPPsaprdup8HaSjcxbBXXOtatFYYUIS67 6YEfQm8N8tMZtnMIcBaelFo9Oup8a14RKFB3Y8NFL3tUfOiI5drO1CpDtBx0iUV9e4Zj +ZHA== 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=qn66etOm0a5xQIu8htrI+8Q6SfvX5qKGBW8UZZdluKk=; b=YFarpzPzI7sk5Zw11b1FMEssJ9Vrs6NAXcvccmxEzUcFn91L5Yhv4kyrpxd+OWZL3u +xaHdR5rJFr0BxbpNji+GdFA1hO3V0QAWM0nrQl2UptwQOX/PKJncMOV9/jLYTYCtua1 LoVz6NLMMVzP1M8VBfQpWnT5jiBufJGiFR44QsuASWeXZ+nn+tS6d5+oLVElocIC7ERT oEkxPc5G+FDKjZUL0SfjsiPsZ+5wC5tknfXlnA3xrgnfCbNT/S1OqfqusVFjFwFG5oAi e6VPJd4mNlaRmhhBtyxRkHXFI6pjVIpHcTBJ6c4UKg0WYbzPa/ZM1+zvGrtx3Z5L5hRL drJQ== X-Gm-Message-State: APjAAAVbzWawOxUwkOxljQ/7fjbey0SC0mEp1jfV5t8rE0YrZoceNJRT 03gzliZNc75M0eQe85gqh03SUszC X-Google-Smtp-Source: APXvYqz9xlF4iNQcDCI1K1xUJwfzrXCi5cK9zKh/z3ZFsrO0zb/o14rfJTi4oRzv1JsDJRRkXAA74A== X-Received: by 2002:adf:ef83:: with SMTP id d3mr10350000wro.253.1557860868811; Tue, 14 May 2019 12:07:48 -0700 (PDT) Received: from [192.168.20.141] ([194.99.104.18]) by smtp.gmail.com with ESMTPSA id o4sm5650291wmo.20.2019.05.14.12.07.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:07:48 -0700 (PDT) Subject: [PATCH v4 13/13] platform/x86: asus-wmi: Do not disable keyboard backlight on unloading From: Yurii Pavlovskyi Cc: Corentin Chary , Darren Hart , Andy Shevchenko , Daniel Drake , Chris Chiu , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org References: Message-ID: <8b24b62b-4271-1010-ca5f-2974088b1857@gmail.com> Date: Tue, 14 May 2019 21:07:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US To: unlisted-recipients:; (no To-header on input) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The keyboard backlight is 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 feb8d72fc3c5..0c330d6a5871 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -471,6 +471,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); }