From patchwork Sun Jun 30 05:41:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11024173 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 7EB20112C for ; Sun, 30 Jun 2019 05:41:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D720286EE for ; Sun, 30 Jun 2019 05:41:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EA2128765; Sun, 30 Jun 2019 05:41:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4686B286EE for ; Sun, 30 Jun 2019 05:41:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726599AbfF3Fl3 (ORCPT ); Sun, 30 Jun 2019 01:41:29 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:41827 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725959AbfF3Fl3 (ORCPT ); Sun, 30 Jun 2019 01:41:29 -0400 Received: by mail-vs1-f66.google.com with SMTP id 2so6745293vso.8; Sat, 29 Jun 2019 22:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=df8HZ1GC9xOAmz5J1hSYCy+taJAv5J2Wpa+VxaLhh1Y=; b=tOAXaniq5JK92eAo4mvDn9Vl4LFpLvqTWv4qJ8jZ+7jsx3KhCTePu06gbaKs7V6MgI A5Z4Yo3leKLoqZTgYpXWhQETy9DxJpQjVgaF0Y7E1M8gpQ28HgMtj1TQR2E3rkmDJGtj +jxqzixcs/mFqH8mDLL4J+PlrHRUVF9x5b5OzE8FAFQjriTpgVNJ7SbGltyyazkyCNyv O72+KQiB4SDFEr/38EzWDNlB9A+LDxQ8p26I00a8RwKgWSolYqQRwd2hqPXN5nK1emRz dizNLE2RSMn7ZgD6pKCHY/Nxmcoqj3al40AMEYe45cBfQV6YwWL6LW5f+bLy51j/DDHq 8slA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=df8HZ1GC9xOAmz5J1hSYCy+taJAv5J2Wpa+VxaLhh1Y=; b=B6nZqC+r+hM7GZyigqVlQCXPza/g8FyrbstHqEwggh+JqGe444cGWjfTKmvph0EZFn v2m4oEUIbv1LkZFfOatK12FpH9BBofOcDJeTrwC7/B2i/hJsZmV8RvtbM/M46+KZ9JrL CT9rripqI/FuTn3edDuqOneuYEra5xr58vJL9rjkrOLGYRNfvj+kPIL0gl56lVxlh16u 6CxnE/Q8GWV7T8WoiFYoX7AC95upFFxe9svbFtVexSF8H7ioAorNc6uHnACUgRiGt6tK SdoUu/mEZN37pzhRjzVqVYkMo8uCEIlkm5R/rGFY3HTCxEsw3QTZ/Zo3q1Re3MxAG5yV M7zA== X-Gm-Message-State: APjAAAXRG4cby8/FvBNJXjHPWMyQ+0AnUl/xeeNk/rvOnlajZa/Te7Xk LVJ1Sr6G/EitNjqzbeNB9A== X-Google-Smtp-Source: APXvYqwJsrLcbzha/wqICM9mdlRLeUxbBmb9KHkFsRv6GEMQFbkF6080wk05pCUqHumpRowuy9ITNw== X-Received: by 2002:a67:fb02:: with SMTP id d2mr10868712vsr.207.1561873288288; Sat, 29 Jun 2019 22:41:28 -0700 (PDT) Received: from localhost.localdomain ([2601:902:c200:6512:37bd:d695:3a39:ceb9]) by smtp.gmail.com with ESMTPSA id r136sm1926676vke.46.2019.06.29.22.41.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 29 Jun 2019 22:41:27 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ayman.bagabas@gmail.com Subject: [RFC 1/9] platform/x86: huawei-wmi: Rename guid and driver name Date: Sun, 30 Jun 2019 01:41:00 -0400 Message-Id: <20190630054108.19205-2-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190630054108.19205-1-ayman.bagabas@gmail.com> References: <20190630054108.19205-1-ayman.bagabas@gmail.com> MIME-Version: 1.0 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 Use WMI device UID, AMW0 has a UID of HWMI. WMI0 is the device name and doesn't have a UID so keep it as it is. Change module description to reflect the upcoming changes. Signed-off-by: Ayman Bagabas --- drivers/platform/x86/huawei-wmi.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index 52fcac5b393a..a1159850a16c 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Huawei WMI hotkeys + * Huawei WMI laptop extras driver * * Copyright (C) 2018 Ayman Bagabas */ @@ -15,10 +15,12 @@ /* * Huawei WMI GUIDs */ -#define WMI0_EVENT_GUID "59142400-C6A3-40fa-BADB-8A2652834100" -#define AMW0_EVENT_GUID "ABBC0F5C-8EA1-11D1-A000-C90629100000" +#define HWMI_EVENT_GUID "ABBC0F5C-8EA1-11D1-A000-C90629100000" +/* Legacy GUIDs */ #define WMI0_EXPENSIVE_GUID "39142400-C6A3-40fa-BADB-8A2652834100" +#define WMI0_EVENT_GUID "59142400-C6A3-40fa-BADB-8A2652834100" + struct huawei_wmi_priv { struct input_dev *idev; @@ -37,7 +39,7 @@ static const struct key_entry huawei_wmi_keymap[] = { { KE_KEY, 0x289, { KEY_WLAN } }, // Huawei |M| key { KE_KEY, 0x28a, { KEY_CONFIG } }, - // Keyboard backlight + // Keyboard backlit { KE_IGNORE, 0x293, { KEY_KBDILLUMTOGGLE } }, { KE_IGNORE, 0x294, { KEY_KBDILLUMUP } }, { KE_IGNORE, 0x295, { KEY_KBDILLUMUP } }, @@ -186,7 +188,7 @@ static int huawei_wmi_probe(struct wmi_device *wdev) static const struct wmi_device_id huawei_wmi_id_table[] = { { .guid_string = WMI0_EVENT_GUID }, - { .guid_string = AMW0_EVENT_GUID }, + { .guid_string = HWMI_EVENT_GUID }, { } }; @@ -203,5 +205,5 @@ module_wmi_driver(huawei_wmi_driver); MODULE_DEVICE_TABLE(wmi, huawei_wmi_id_table); MODULE_AUTHOR("Ayman Bagabas "); -MODULE_DESCRIPTION("Huawei WMI hotkeys"); +MODULE_DESCRIPTION("Huawei WMI laptop extras driver"); MODULE_LICENSE("GPL v2"); From patchwork Sun Jun 30 05:41:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11024175 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 38322112C for ; Sun, 30 Jun 2019 05:41:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29138286EE for ; Sun, 30 Jun 2019 05:41:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CC7928765; Sun, 30 Jun 2019 05:41:35 +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 66FFB286EE for ; Sun, 30 Jun 2019 05:41:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbfF3Fld (ORCPT ); Sun, 30 Jun 2019 01:41:33 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:40187 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725959AbfF3Fld (ORCPT ); Sun, 30 Jun 2019 01:41:33 -0400 Received: by mail-vs1-f67.google.com with SMTP id a186so6754913vsd.7; Sat, 29 Jun 2019 22:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QfQ7zt4ue0d5+MuKHGtuF9dNlgHqd2O2zESfTSx+XfI=; b=tfm41T5CVYsCgLrEYbcEjkVe2f5DxffEK8IGPk/l8m2aPzPrEyfOLTMNWXTuBlF+g4 ymPt872OMiKX9gfqnVgUpAls5shlL1FHYf38YEw/5KJGcfixzeJ5gTgS7JvMMA6dFpak U/xYXR6PhosfH9C0syGgVpvx7svuB0hr1HF/Mv6/Anvf79Opu3+7TfkkQXV7ktjXHbfy OAS4/q3AMMux3bv3kXsxv6UB59+lIxVKPYTa7h+y5pbebezo1JxvhAlq97LKPQDdWj6N DHGC1VheRfro5pwANBwxAKtneA36617ZrO+9HMdFfvvRQF71pnzEiZgYsr7JmT5lExzm ND8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QfQ7zt4ue0d5+MuKHGtuF9dNlgHqd2O2zESfTSx+XfI=; b=Y2d4+JTPePpCqgmdtWGXI2HJY8TQCSxCfGOtWq3nmpoxf6Wht403ykPNq6Agz+o5Qd ExolFhPFu2MBwmQAspEKcZMxSO8+JnHhiZ8O3KRfF9nsXQkSeAdPr15xoNhDlqze1x0+ F7IUkrT6dC2jBuN2sBMNfao1Qp7wJOhjL4UuA3659tSlVDf8Lz9Hdx0EKig9m08iiZ+Y jKFQc4NR1l473lvkuv74wiM4rCSs8e+wJ0mOppzTpM2J2ZziiGQmT8kkVIR0VzaNQYxT GQRdxXRtC1ttUdVMsHSXTUci4NDhQu/y9xrBgMpv6lGdIeRqaiZvcW4T7TcFhQluqOvN 1ytQ== X-Gm-Message-State: APjAAAVQd6C9/8Pb/8dq4UXVhFC1YQtPEUwaqZZCZTn6DevV2VKZl9tK MpCVIjhwf/ryzsRcAeRu7g== X-Google-Smtp-Source: APXvYqwu7+v6qg1XZ7YJKwpWFDsuUWY5BP6N8hH+ojyutn+eGOGSFfxddkhEh68wXXZUJ7bWPEJAdQ== X-Received: by 2002:a67:cd9a:: with SMTP id r26mr10903718vsl.152.1561873291840; Sat, 29 Jun 2019 22:41:31 -0700 (PDT) Received: from localhost.localdomain ([2601:902:c200:6512:37bd:d695:3a39:ceb9]) by smtp.gmail.com with ESMTPSA id r136sm1926676vke.46.2019.06.29.22.41.31 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 29 Jun 2019 22:41:31 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ayman.bagabas@gmail.com Subject: [RFC 2/9] platform/x86: huawei-wmi: Move to platform driver Date: Sun, 30 Jun 2019 01:41:01 -0400 Message-Id: <20190630054108.19205-3-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190630054108.19205-1-ayman.bagabas@gmail.com> References: <20190630054108.19205-1-ayman.bagabas@gmail.com> MIME-Version: 1.0 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 Move from WMI driver to platform driver. This move is necessary since the driver is no longer a hotkeys driver only. Platform driver makes it easier for users to access sysfs attributes under (i.e. /sys/devices/platform/huawei-wmi) compared to wmi driver. Signed-off-by: Ayman Bagabas --- Do you think we should stick to wmi driver especially after "platform/x86: wmi: add context pointer field to struct wmi_device_id" https://patchwork.kernel.org/patch/10963421/ which is basically was my issue with wmi driver where there wasn't a way to distinguish what wmi device is associated with which guid. I believe that platform driver is more suitable for this since it has grown from just a hotkeys driver and users can access sysfs of this easily with platform driver. What do you think? drivers/platform/x86/huawei-wmi.c | 152 +++++++++++++++++++++--------- 1 file changed, 110 insertions(+), 42 deletions(-) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index a1159850a16c..12cae450fc1f 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -10,6 +10,7 @@ #include #include #include +#include #include /* @@ -23,12 +24,15 @@ struct huawei_wmi_priv { - struct input_dev *idev; + struct input_dev *idev[2]; struct led_classdev cdev; acpi_handle handle; char *acpi_method; + struct platform_device *pdev; }; +struct platform_device *huawei_wmi_pdev; + static const struct key_entry huawei_wmi_keymap[] = { { KE_KEY, 0x281, { KEY_BRIGHTNESSDOWN } }, { KE_KEY, 0x282, { KEY_BRIGHTNESSUP } }, @@ -46,6 +50,8 @@ static const struct key_entry huawei_wmi_keymap[] = { { KE_END, 0 } }; +/* LEDs */ + static int huawei_wmi_micmute_led_set(struct led_classdev *led_cdev, enum led_brightness brightness) { @@ -77,9 +83,9 @@ static int huawei_wmi_micmute_led_set(struct led_classdev *led_cdev, return 0; } -static int huawei_wmi_leds_setup(struct wmi_device *wdev) +static int huawei_wmi_leds_setup(struct device *dev) { - struct huawei_wmi_priv *priv = dev_get_drvdata(&wdev->dev); + struct huawei_wmi_priv *priv = dev_get_drvdata(dev); priv->handle = ec_get_handle(); if (!priv->handle) @@ -97,15 +103,16 @@ static int huawei_wmi_leds_setup(struct wmi_device *wdev) priv->cdev.brightness_set_blocking = huawei_wmi_micmute_led_set; priv->cdev.default_trigger = "audio-micmute"; priv->cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE); - priv->cdev.dev = &wdev->dev; + priv->cdev.dev = dev; priv->cdev.flags = LED_CORE_SUSPENDRESUME; - return devm_led_classdev_register(&wdev->dev, &priv->cdev); + return devm_led_classdev_register(dev, &priv->cdev); } -static void huawei_wmi_process_key(struct wmi_device *wdev, int code) +/* Input */ + +static void huawei_wmi_process_key(struct input_dev *idev, int code) { - struct huawei_wmi_priv *priv = dev_get_drvdata(&wdev->dev); const struct key_entry *key; /* @@ -129,81 +136,142 @@ static void huawei_wmi_process_key(struct wmi_device *wdev, int code) kfree(response.pointer); } - key = sparse_keymap_entry_from_scancode(priv->idev, code); + key = sparse_keymap_entry_from_scancode(idev, code); if (!key) { - dev_info(&wdev->dev, "Unknown key pressed, code: 0x%04x\n", code); + dev_info(&idev->dev, "Unknown key pressed, code: 0x%04x\n", code); return; } - sparse_keymap_report_entry(priv->idev, key, 1, true); + sparse_keymap_report_entry(idev, key, 1, true); } -static void huawei_wmi_notify(struct wmi_device *wdev, - union acpi_object *obj) +static void huawei_wmi_input_notify(u32 value, void *context) { - if (obj->type == ACPI_TYPE_INTEGER) - huawei_wmi_process_key(wdev, obj->integer.value); + struct input_dev *idev = (struct input_dev *)context; + struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *obj; + acpi_status status; + + status = wmi_get_event_data(value, &response); + if (ACPI_FAILURE(status)) { + dev_err(&idev->dev, "Unable to get event data\n"); + return; + } + + obj = (union acpi_object *)response.pointer; + if (obj && obj->type == ACPI_TYPE_INTEGER) + huawei_wmi_process_key(idev, obj->integer.value); else - dev_info(&wdev->dev, "Bad response type %d\n", obj->type); + dev_err(&idev->dev, "Bad response type\n"); + + kfree(response.pointer); } -static int huawei_wmi_input_setup(struct wmi_device *wdev) +static int huawei_wmi_input_setup(struct device *dev, + struct input_dev **idev) { - struct huawei_wmi_priv *priv = dev_get_drvdata(&wdev->dev); int err; - priv->idev = devm_input_allocate_device(&wdev->dev); - if (!priv->idev) + *idev = devm_input_allocate_device(dev); + if (!*idev) return -ENOMEM; - priv->idev->name = "Huawei WMI hotkeys"; - priv->idev->phys = "wmi/input0"; - priv->idev->id.bustype = BUS_HOST; - priv->idev->dev.parent = &wdev->dev; + (*idev)->name = "Huawei WMI hotkeys"; + (*idev)->phys = "wmi/input0"; + (*idev)->id.bustype = BUS_HOST; + (*idev)->dev.parent = dev; - err = sparse_keymap_setup(priv->idev, huawei_wmi_keymap, NULL); + err = sparse_keymap_setup(*idev, huawei_wmi_keymap, NULL); if (err) return err; - return input_register_device(priv->idev); + return input_register_device(*idev); } -static int huawei_wmi_probe(struct wmi_device *wdev) +/* Huawei driver */ + +static int huawei_wmi_probe(struct platform_device *pdev) { struct huawei_wmi_priv *priv; int err; - priv = devm_kzalloc(&wdev->dev, sizeof(struct huawei_wmi_priv), GFP_KERNEL); + priv = devm_kzalloc(&pdev->dev, sizeof(struct huawei_wmi_priv), GFP_KERNEL); if (!priv) return -ENOMEM; - dev_set_drvdata(&wdev->dev, priv); + priv->pdev = pdev; + dev_set_drvdata(&pdev->dev, priv); + + if (wmi_has_guid(WMI0_EVENT_GUID)) { + err = huawei_wmi_input_setup(&pdev->dev, &priv->idev[0]) || + wmi_install_notify_handler(WMI0_EVENT_GUID, + huawei_wmi_input_notify, priv->idev[0]); + if (err) { + dev_err(&pdev->dev, "Failed to setup input device\n"); + return err; + } + } - err = huawei_wmi_input_setup(wdev); - if (err) - return err; + if (wmi_has_guid(HWMI_EVENT_GUID)) { + err = huawei_wmi_input_setup(&pdev->dev, &priv->idev[1]) || + wmi_install_notify_handler(HWMI_EVENT_GUID, + huawei_wmi_input_notify, priv->idev[1]); + if (err) { + dev_err(&pdev->dev, "Failed to setup input device\n"); + return err; + } + } - return huawei_wmi_leds_setup(wdev); + return huawei_wmi_leds_setup(&pdev->dev); } -static const struct wmi_device_id huawei_wmi_id_table[] = { - { .guid_string = WMI0_EVENT_GUID }, - { .guid_string = HWMI_EVENT_GUID }, - { } -}; +static int huawei_wmi_remove(struct platform_device *pdev) +{ + if (wmi_has_guid(WMI0_EVENT_GUID)) + wmi_remove_notify_handler(WMI0_EVENT_GUID); + + if (wmi_has_guid(HWMI_EVENT_GUID)) + wmi_remove_notify_handler(HWMI_EVENT_GUID); -static struct wmi_driver huawei_wmi_driver = { + return 0; +} + +static struct platform_driver huawei_wmi_driver = { .driver = { .name = "huawei-wmi", }, - .id_table = huawei_wmi_id_table, .probe = huawei_wmi_probe, - .notify = huawei_wmi_notify, + .remove = huawei_wmi_remove, }; -module_wmi_driver(huawei_wmi_driver); +static __init int huawei_wmi_init(void) +{ + int err; + + err = platform_driver_register(&huawei_wmi_driver); + if (err) + return err; + + huawei_wmi_pdev = platform_device_register_simple("huawei-wmi", -1, NULL, 0); + if (IS_ERR(huawei_wmi_pdev)) { + platform_driver_unregister(&huawei_wmi_driver); + return PTR_ERR(huawei_wmi_pdev); + } + + return 0; +} + +static __exit void huawei_wmi_exit(void) +{ + platform_device_unregister(huawei_wmi_pdev); + platform_driver_unregister(&huawei_wmi_driver); +} + +module_init(huawei_wmi_init); +module_exit(huawei_wmi_exit); -MODULE_DEVICE_TABLE(wmi, huawei_wmi_id_table); +MODULE_ALIAS("wmi:"WMI0_EVENT_GUID); +MODULE_ALIAS("wmi:"HWMI_EVENT_GUID); MODULE_AUTHOR("Ayman Bagabas "); MODULE_DESCRIPTION("Huawei WMI laptop extras driver"); MODULE_LICENSE("GPL v2"); From patchwork Sun Jun 30 05:41:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11024189 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 0E7AD112C for ; Sun, 30 Jun 2019 05:42:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00067286EE for ; Sun, 30 Jun 2019 05:42:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7D0028765; Sun, 30 Jun 2019 05:42:06 +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 6430B286EE for ; Sun, 30 Jun 2019 05:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726691AbfF3Flh (ORCPT ); Sun, 30 Jun 2019 01:41:37 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:44636 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726678AbfF3Flg (ORCPT ); Sun, 30 Jun 2019 01:41:36 -0400 Received: by mail-vs1-f67.google.com with SMTP id v129so6713129vsb.11; Sat, 29 Jun 2019 22:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kdPbODA0z2TZ5tYy71TYwrIsVN8PGj8ecEakmSP6UzE=; b=OCWj05AkY2RKsFE5SNjS+CPe4S2AEw2yAn4kKEVdJCq0ZqB2OA1Kg8Pn+nqw47/V5K Dct9L+5joOhtBynfVpousAIlYu6Rr/OcRIh1Flskl5u4CEqCyav9IWukfhda04tAUEh8 95NlApNSWCAjQsvV1W2bwMiqDhrPXfNc9H8PPebMOkvh1/0hUJ1KZ+GcNAlltiFn1/tm NP7DaQmQ5MhWPEXQL6nuUiTIrxYd3Z+k2yGTdrzBcZaSEUJN/p3dH/l53egLwKxMSAEZ iFSpFEd5Xm7x6B62+Pr5kkx4Jlors/BR2faJI+fmbXmkNmi3mwU/XxXfBt+DmRfEmF5Z I3gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kdPbODA0z2TZ5tYy71TYwrIsVN8PGj8ecEakmSP6UzE=; b=dEcxXqr1mGW6Ce+4LbrJ68MYjEa2clOBnyE4rem7aZ2cgsLIwzkaxuG/uHArosWtXv KqwSoIMFdVKiOnaT6Z7iaZsBNXOiCmFtH3FabfzuHOJnzCzZqYApv38rpn+JhylxgzkK h5LSUbRA39A2WNkoiwraPDW1zBJfo+n7GDIDGhe/P/Te2WnqGQCIHdpqrBKH6tzdbF99 6Gj5EHpvSVWNAaclqkcqGAmnlx5FRNanym/+vVXKymDXAdIbv5hVYG/AhDG0Xwv3n88r BifoYm85xkz9m5RTmxUwMNTJk7QqOHUinQ+OqqGcDAUbIHbC20UjcgdrYDXwivarV64b 4n/w== X-Gm-Message-State: APjAAAVVu9B+s4X5w/PuijjUfLmV9MtQJ2TOR+0Ai3zJyT661xEIXdLg M9EbdWzZdRtaii+TsfwX6q4SJlfRaQ== X-Google-Smtp-Source: APXvYqxVcxS3c2jmSWFZuWGvdC+pBCSZmzkJJ8oAsoyKtehe4IvFrMZih2OqW7/oxLKGbl1dNa/N0Q== X-Received: by 2002:a67:9946:: with SMTP id b67mr11038017vse.37.1561873294998; Sat, 29 Jun 2019 22:41:34 -0700 (PDT) Received: from localhost.localdomain ([2601:902:c200:6512:37bd:d695:3a39:ceb9]) by smtp.gmail.com with ESMTPSA id r136sm1926676vke.46.2019.06.29.22.41.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 29 Jun 2019 22:41:34 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ayman.bagabas@gmail.com Subject: [RFC 3/9] platform/x86: huawei-wmi: Implement huawei wmi management interface Date: Sun, 30 Jun 2019 01:41:02 -0400 Message-Id: <20190630054108.19205-4-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190630054108.19205-1-ayman.bagabas@gmail.com> References: <20190630054108.19205-1-ayman.bagabas@gmail.com> MIME-Version: 1.0 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 Huawei Matebook laptops come with a WMI management interface that can control various aspects of the device. This interface is also found on the old Matebook X released in 2017. Implement basic functionality of this interface along with supported command IDs that are implemented in this series. Signed-off-by: Ayman Bagabas --- drivers/platform/x86/huawei-wmi.c | 130 ++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index 12cae450fc1f..27520b0f8956 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -10,24 +10,36 @@ #include #include #include +#include #include #include /* * Huawei WMI GUIDs */ +#define HWMI_METHOD_GUID "ABBC0F5B-8EA1-11D1-A000-C90629100000" #define HWMI_EVENT_GUID "ABBC0F5C-8EA1-11D1-A000-C90629100000" /* Legacy GUIDs */ #define WMI0_EXPENSIVE_GUID "39142400-C6A3-40fa-BADB-8A2652834100" #define WMI0_EVENT_GUID "59142400-C6A3-40fa-BADB-8A2652834100" +/* HWMI commands */ + +enum { + BATTERY_THRESH_GET = 0x00001103, /* \GBTT */ + BATTERY_THRESH_SET = 0x00001003, /* \SBTT */ + FN_LOCK_GET = 0x00000604, /* \GFRS */ + FN_LOCK_SET = 0x00000704, /* \SFRS */ + MICMUTE_LED_SET = 0x00000b04, /* \SMLS */ +}; struct huawei_wmi_priv { struct input_dev *idev[2]; struct led_classdev cdev; acpi_handle handle; char *acpi_method; + struct mutex wmi_lock; struct platform_device *pdev; }; @@ -50,6 +62,116 @@ static const struct key_entry huawei_wmi_keymap[] = { { KE_END, 0 } }; +/* Utils */ + +static int huawei_wmi_call(struct device *dev, struct acpi_buffer *in, + struct acpi_buffer *out) +{ + struct huawei_wmi_priv *priv = dev_get_drvdata(dev); + acpi_status status; + + mutex_lock(&priv->wmi_lock); + status = wmi_evaluate_method(HWMI_METHOD_GUID, 0, 1, in, out); + mutex_unlock(&priv->wmi_lock); + if (ACPI_FAILURE(status)) { + dev_err(dev, "Failed to evaluate wmi method\n"); + return -ENODEV; + } + + return 0; +} + +/* HWMI takes a 64 bit input and returns either a package with 2 buffers, one of + * 4 bytes and the other of 256 bytes, or one buffer of size 0x104 (260) bytes. + * The first 4 bytes are ignored, we ignore the first 4 bytes buffer if we got a + * package, or skip the first 4 if a buffer of 0x104 is used. The first byte of + * the remaining 0x100 sized buffer has the return status of every call. In case + * the return status is non-zero, we return -ENODEV but still copy the returned + * buffer to the given buffer parameter (buf). + */ +static int huawei_wmi_cmd(struct device *dev, u64 arg, u8 *buf, size_t buflen) +{ + struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_buffer in; + union acpi_object *obj; + size_t len; + int err, i; + + in.length = sizeof(arg); + in.pointer = &arg; + + /* Some models require calling HWMI twice to execute a command. We evaluate + * HWMI and if we get a non-zero return status we evaluate it again. + */ + for (i = 0; i < 2; i++) { + err = huawei_wmi_call(dev, &in, &out); + if (err) + goto fail_cmd; + + obj = out.pointer; + if (!obj) { + err = -EIO; + goto fail_cmd; + } + + switch (obj->type) { + /* Models that implement both "legacy" and HWMI tend to return a 0x104 + * sized buffer instead of a package of 0x4 and 0x100 buffers. + */ + case ACPI_TYPE_BUFFER: + if (obj->buffer.length == 0x104) { + // Skip the first 4 bytes. + obj->buffer.pointer += 4; + len = 0x100; + } else { + dev_err(dev, "Bad buffer length, got %d\n", obj->buffer.length); + err = -EIO; + goto fail_cmd; + } + + break; + /* HWMI returns a package with 2 buffer elements, one of 4 bytes and the + * other is 256 bytes. + */ + case ACPI_TYPE_PACKAGE: + if (obj->package.count != 2) { + dev_err(dev, "Bad package count, got %d\n", obj->package.count); + err = -EIO; + goto fail_cmd; + } + + obj = &obj->package.elements[1]; + if (obj->type != ACPI_TYPE_BUFFER) { + dev_err(dev, "Bad package element type, got %d\n", obj->type); + err = -EIO; + goto fail_cmd; + } + len = obj->buffer.length; + + break; + /* Shouldn't get here! */ + default: + dev_err(dev, "Unexpected obj type, got: %d\n", obj->type); + err = -EIO; + goto fail_cmd; + } + + if (!*obj->buffer.pointer) + break; + } + + err = (*obj->buffer.pointer) ? -ENODEV : 0; + + if (buf) { + len = min(buflen, len); + memcpy(buf, obj->buffer.pointer, len); + } + +fail_cmd: + kfree(out.pointer); + return err; +} + /* LEDs */ static int huawei_wmi_micmute_led_set(struct led_classdev *led_cdev, @@ -222,6 +344,10 @@ static int huawei_wmi_probe(struct platform_device *pdev) } } + if (wmi_has_guid(HWMI_METHOD_GUID)) { + mutex_init(&priv->wmi_lock); + } + return huawei_wmi_leds_setup(&pdev->dev); } @@ -233,6 +359,9 @@ static int huawei_wmi_remove(struct platform_device *pdev) if (wmi_has_guid(HWMI_EVENT_GUID)) wmi_remove_notify_handler(HWMI_EVENT_GUID); + if (wmi_has_guid(HWMI_METHOD_GUID)) { + } + return 0; } @@ -272,6 +401,7 @@ module_exit(huawei_wmi_exit); MODULE_ALIAS("wmi:"WMI0_EVENT_GUID); MODULE_ALIAS("wmi:"HWMI_EVENT_GUID); +MODULE_ALIAS("wmi:"HWMI_METHOD_GUID); MODULE_AUTHOR("Ayman Bagabas "); MODULE_DESCRIPTION("Huawei WMI laptop extras driver"); MODULE_LICENSE("GPL v2"); From patchwork Sun Jun 30 05:41:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11024177 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 8CF49112C for ; Sun, 30 Jun 2019 05:41:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DC532871C for ; Sun, 30 Jun 2019 05:41:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7212928789; Sun, 30 Jun 2019 05:41:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 037B42871C for ; Sun, 30 Jun 2019 05:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726738AbfF3Fli (ORCPT ); Sun, 30 Jun 2019 01:41:38 -0400 Received: from mail-ua1-f68.google.com ([209.85.222.68]:34514 "EHLO mail-ua1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726711AbfF3Fli (ORCPT ); Sun, 30 Jun 2019 01:41:38 -0400 Received: by mail-ua1-f68.google.com with SMTP id c4so3804539uad.1; Sat, 29 Jun 2019 22:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5j3IO2fR8dGnJJ8Bw7OG2mF2AzsT5n4q6VZYnXcfGiQ=; b=jKrCJ0TVooJHi5QtAxAP4XXnEcrlDfVsQjhUvs/Bscwtj1ekGeu1yniJez589G6TRd LJmX6n4p0ZVhGBZHMmUszrPnBANpDADN+wX2KYOg7J9GU2DQorFeBzgsh8X/vAGnsC/b d6cCdD4ES25sikbVAU3OfTCP1cF+VbT71TwLb04eRbVHOlXYMhdRTdk8p3DoFz0XLZXD myhoSz/Jb2j7MlbouCiCvuQQE+T5dp1rQzq8zbC4/+yboLYFS3eW3ie9ErPjblYMeONM r4QWaEdM6HOnKscnMD9IvOVlwPuV3A8AXikWQCIb0aUuH63xCOyQU0dm0Y3KXJeO4pXs axDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5j3IO2fR8dGnJJ8Bw7OG2mF2AzsT5n4q6VZYnXcfGiQ=; b=QvnTEFwoY7o2fFCD6FJevBwupdKT2cy1a+FHWldTxLM3wnTMH5WqZvv7TnW4pgWXwj pjyN8NiN6M2ZREaTLPubrJxEsOPji475EBwGA1ApftaqlJn3Im7MXeJBpM0VAso0pjvQ 5zvi2BZt7TO+pDHvlwOE16czHZUpASYpULjtvxzCAvkuY2izc4i5LGQpMprIGJINTydp ARsOrPuFR7tm+E9zsOqbXjv8yIBADC6lYGgdJSL/KikKhLWyFHUgz6OeWa6+q7qOthCt bAmfQCwM1Cdpn3f+k2VIc3BJ0HS/0DfCgONilOsvsEDC7CaREk8U9tnhcBCTQ4bZN43i Obuw== X-Gm-Message-State: APjAAAXvlGYRJrHoPUypHMEKMXZqy3z/vqKvtMpyKcV2sCaqURs3UBpm ugI4GfzRZAarJEWO8zt/CQ== X-Google-Smtp-Source: APXvYqy35onY5fRiWtGb2iVB4/MUqm6vOP2+g6/JLxHApc1OVYj+wkIDkqbTS2v73bIHtCe8Pcaoew== X-Received: by 2002:ab0:60ad:: with SMTP id f13mr10564584uam.129.1561873297607; Sat, 29 Jun 2019 22:41:37 -0700 (PDT) Received: from localhost.localdomain ([2601:902:c200:6512:37bd:d695:3a39:ceb9]) by smtp.gmail.com with ESMTPSA id r136sm1926676vke.46.2019.06.29.22.41.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 29 Jun 2019 22:41:37 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ayman.bagabas@gmail.com Subject: [RFC 4/9] platform/x86: huawei-wmi: Add quirks and module parameters Date: Sun, 30 Jun 2019 01:41:03 -0400 Message-Id: <20190630054108.19205-5-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190630054108.19205-1-ayman.bagabas@gmail.com> References: <20190630054108.19205-1-ayman.bagabas@gmail.com> MIME-Version: 1.0 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 Introduce quirks and module parameters. 3 quirks are added: 1. Fixes reporting brightness keys twice since it's already handled by acpi-video. 2. Some models need a short delay when setting battery thresholds to prevent a race condition when two processes read/write. 3. Matebook X (2017) handles micmute led through the "legacy" interface which is not currently implemented. Use ACPI EC method to control this led. 2 module parameters are added to enable this short delay and/or report brightness keys through this driver. Signed-off-by: Ayman Bagabas --- drivers/platform/x86/huawei-wmi.c | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index 27520b0f8956..8f918138053a 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -34,6 +35,14 @@ enum { MICMUTE_LED_SET = 0x00000b04, /* \SMLS */ }; +struct quirk_entry { + bool battery_sleep; + bool ec_micmute; + bool report_brightness; +}; + +static struct quirk_entry *quirks; + struct huawei_wmi_priv { struct input_dev *idev[2]; struct led_classdev cdev; @@ -62,6 +71,58 @@ static const struct key_entry huawei_wmi_keymap[] = { { KE_END, 0 } }; +static bool battery_sleep; +static bool report_brightness; + +module_param(battery_sleep, bool, 0444); +MODULE_PARM_DESC(battery_sleep, + "Delay after setting battery charging thresholds."); +module_param(report_brightness, bool, 0444); +MODULE_PARM_DESC(report_brightness, + "Report brightness keys."); + +/* Quirks */ + +static int __init dmi_matched(const struct dmi_system_id *dmi) +{ + quirks = dmi->driver_data; + return 1; +} + +static struct quirk_entry quirk_unknown = { +}; + +static struct quirk_entry quirk_battery_sleep = { + .battery_sleep = true, +}; + +static struct quirk_entry quirk_matebook_x = { + .ec_micmute = true, + .report_brightness = true, +}; + +static const struct dmi_system_id huawei_quirks[] = { + { + .callback = dmi_matched, + .ident = "Huawei MACH-WX9", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HUAWEI"), + DMI_MATCH(DMI_PRODUCT_NAME, "MACH-WX9"), + }, + .driver_data = &quirk_battery_sleep + }, + { + .callback = dmi_matched, + .ident = "Huawei MateBook X", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HUAWEI"), + DMI_MATCH(DMI_PRODUCT_NAME, "HUAWEI MateBook X") + }, + .driver_data = &quirk_matebook_x + }, + { } +}; + /* Utils */ static int huawei_wmi_call(struct device *dev, struct acpi_buffer *in, @@ -264,6 +325,11 @@ static void huawei_wmi_process_key(struct input_dev *idev, int code) return; } + if (quirks && !quirks->report_brightness && + (key->sw.code == KEY_BRIGHTNESSDOWN || + key->sw.code == KEY_BRIGHTNESSUP)) + return; + sparse_keymap_report_entry(idev, key, 1, true); } @@ -377,6 +443,11 @@ static __init int huawei_wmi_init(void) { int err; + quirks = &quirk_unknown; + dmi_check_system(huawei_quirks); + quirks->battery_sleep |= battery_sleep; + quirks->report_brightness |= report_brightness; + err = platform_driver_register(&huawei_wmi_driver); if (err) return err; From patchwork Sun Jun 30 05:41:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11024187 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 F38A0138D for ; Sun, 30 Jun 2019 05:42:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4DFF286EE for ; Sun, 30 Jun 2019 05:42:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D989D28765; Sun, 30 Jun 2019 05:42: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 69452286EE for ; Sun, 30 Jun 2019 05:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726811AbfF3Flo (ORCPT ); Sun, 30 Jun 2019 01:41:44 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:46373 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726711AbfF3Fln (ORCPT ); Sun, 30 Jun 2019 01:41:43 -0400 Received: by mail-vs1-f67.google.com with SMTP id l125so6723218vsl.13; Sat, 29 Jun 2019 22:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qZ9bQ4qlIvn0nmi3/fOq2/nuJUUiXRlbGalFjI3uA7I=; b=MJFvM45dSjeXQnIwgGChPqc4FraiBlk+gI9fp7jI8CBRA73+ZssYzngmHfnLilOpnE shixoE/eoDN/4fRgXOqNDjLu1sbxLAFUM9hPLLxWa+veRZUPI1PvJJDqQ984NR8EztKY +HJ0fsrQlwyZ7X9tK1IqCY4PG6dussZwiRgxI21ab1CXYBfM9oGbGM8dJ3ajETQ4wsPk dMp2IZOdJ1fhP3rJXWvvscEnbqV2CIUQhfwA+VXQRNc1m2pbjQ3LER1cHZJMlOID0VMp RorLT60EuDiJPyuC1xiynE3DrcU6qeiA25PCGrH+0TSvWoGBfO20A9z7PghDXyI5Q07s jvuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qZ9bQ4qlIvn0nmi3/fOq2/nuJUUiXRlbGalFjI3uA7I=; b=YLUH1qzQW8dphStthDHPueGmZmiz3ekn3y8pxoweppVbpajFVHEQuhKLCgrJujbxKP MHkx2SrXH/McgR/a6GjfZwIhKnsL3QI0ITFNF6G1HmWVtTIT0xbwF6qZA2X8a+5GBoOc Ox+7MY8rr9kyNuvl3aVZWURXTJ08+/XQdj0cx+Zhicc5R2P2shYKRHhcPlnGbKFmDd3z cZB+E+RlZ7ExWrvfmMPHHABrI0DjfjRruLGpamIDXD9AD8r00J9AAG2Y2d9eMKpQmsVT K6pvTiheitc+x1ECGussFWGslgf4Y5aVCfVhFjkMcTWogMt8qGRol/JwVbz3wsZKByj8 41BA== X-Gm-Message-State: APjAAAUCBLdqlBSkH0q0HnyR8GZVHYjCdutUDf5p+UJrzEsIa+tc0HXf sjSb1Uxd8gahNgkTSseJmA== X-Google-Smtp-Source: APXvYqzcsnxe1ixaVvXGxui+zIBMylqPDrCwwR84fAUxX2R7ER30T4/9RM55EcjLobAyizJTve4yrQ== X-Received: by 2002:a67:2586:: with SMTP id l128mr10987147vsl.52.1561873301726; Sat, 29 Jun 2019 22:41:41 -0700 (PDT) Received: from localhost.localdomain ([2601:902:c200:6512:37bd:d695:3a39:ceb9]) by smtp.gmail.com with ESMTPSA id r136sm1926676vke.46.2019.06.29.22.41.41 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 29 Jun 2019 22:41:41 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ayman.bagabas@gmail.com Subject: [RFC 5/9] platform/x86: huawei-wmi: Control micmute led through wmi interface Date: Sun, 30 Jun 2019 01:41:04 -0400 Message-Id: <20190630054108.19205-6-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190630054108.19205-1-ayman.bagabas@gmail.com> References: <20190630054108.19205-1-ayman.bagabas@gmail.com> MIME-Version: 1.0 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 Now that huawei WMI management interface is implemented, micmute LED can be controlled easily through this interface. Exception is the Matebook X (2017) which continue to uses ACPI EC method to control the LED. This model can control the LED through the legacy WMI interface which is not implemented ATM. Signed-off-by: Ayman Bagabas --- drivers/platform/x86/huawei-wmi.c | 86 ++++++++++++++++++------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index 8f918138053a..9013a05d2832 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -46,8 +46,6 @@ static struct quirk_entry *quirks; struct huawei_wmi_priv { struct input_dev *idev[2]; struct led_classdev cdev; - acpi_handle handle; - char *acpi_method; struct mutex wmi_lock; struct platform_device *pdev; }; @@ -238,49 +236,57 @@ static int huawei_wmi_cmd(struct device *dev, u64 arg, u8 *buf, size_t buflen) static int huawei_wmi_micmute_led_set(struct led_classdev *led_cdev, enum led_brightness brightness) { - struct huawei_wmi_priv *priv = dev_get_drvdata(led_cdev->dev->parent); - acpi_status status; - union acpi_object args[3]; - struct acpi_object_list arg_list = { - .pointer = args, - .count = ARRAY_SIZE(args), - }; - - args[0].type = args[1].type = args[2].type = ACPI_TYPE_INTEGER; - args[1].integer.value = 0x04; - - if (strcmp(priv->acpi_method, "SPIN") == 0) { - args[0].integer.value = 0; - args[2].integer.value = brightness ? 1 : 0; - } else if (strcmp(priv->acpi_method, "WPIN") == 0) { - args[0].integer.value = 1; - args[2].integer.value = brightness ? 0 : 1; + /* This is a workaround until the "legacy" interface is implemented. */ + if (quirks && quirks->ec_micmute) { + char *acpi_method; + acpi_handle handle; + acpi_status status; + union acpi_object args[3]; + struct acpi_object_list arg_list = { + .pointer = args, + .count = ARRAY_SIZE(args), + }; + + handle = ec_get_handle(); + if (!handle) { + dev_err(led_cdev->dev->parent, "Failed to get EC handle\n"); + return -ENODEV; + } + + args[0].type = args[1].type = args[2].type = ACPI_TYPE_INTEGER; + args[1].integer.value = 0x04; + + if (acpi_has_method(handle, "SPIN")) { + acpi_method = "SPIN"; + args[0].integer.value = 0; + args[2].integer.value = brightness ? 1 : 0; + } else if (acpi_has_method(handle, "WPIN")) { + acpi_method = "WPIN"; + args[0].integer.value = 1; + args[2].integer.value = brightness ? 0 : 1; + } else { + return -ENODEV; + } + + status = acpi_evaluate_object(handle, acpi_method, &arg_list, NULL); + if (ACPI_FAILURE(status)) + return -ENODEV; + + return 0; } else { - return -EINVAL; - } + u8 arg[8]; - status = acpi_evaluate_object(priv->handle, priv->acpi_method, &arg_list, NULL); - if (ACPI_FAILURE(status)) - return -ENXIO; + *(u64 *)arg = MICMUTE_LED_SET; + arg[2] = brightness; - return 0; + return huawei_wmi_cmd(led_cdev->dev->parent, *(u64 *)arg, NULL, NULL); + } } static int huawei_wmi_leds_setup(struct device *dev) { struct huawei_wmi_priv *priv = dev_get_drvdata(dev); - priv->handle = ec_get_handle(); - if (!priv->handle) - return 0; - - if (acpi_has_method(priv->handle, "SPIN")) - priv->acpi_method = "SPIN"; - else if (acpi_has_method(priv->handle, "WPIN")) - priv->acpi_method = "WPIN"; - else - return 0; - priv->cdev.name = "platform::micmute"; priv->cdev.max_brightness = 1; priv->cdev.brightness_set_blocking = huawei_wmi_micmute_led_set; @@ -412,9 +418,15 @@ static int huawei_wmi_probe(struct platform_device *pdev) if (wmi_has_guid(HWMI_METHOD_GUID)) { mutex_init(&priv->wmi_lock); + + err = huawei_wmi_leds_setup(&pdev->dev); + if (err) { + dev_err(&pdev->dev, "Failed to setup leds\n"); + return err; + } } - return huawei_wmi_leds_setup(&pdev->dev); + return 0; } static int huawei_wmi_remove(struct platform_device *pdev) From patchwork Sun Jun 30 05:41:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11024179 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 D234D138D for ; Sun, 30 Jun 2019 05:41:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1A502871C for ; Sun, 30 Jun 2019 05:41:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B600E28789; Sun, 30 Jun 2019 05:41:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 440862871C for ; Sun, 30 Jun 2019 05:41:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbfF3Flq (ORCPT ); Sun, 30 Jun 2019 01:41:46 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:35280 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726835AbfF3Flq (ORCPT ); Sun, 30 Jun 2019 01:41:46 -0400 Received: by mail-vs1-f66.google.com with SMTP id u124so6771800vsu.2; Sat, 29 Jun 2019 22:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4B7kxSwn+Y6/oG1SY2GzSzP2SB2pWwxeXqv90tBjdMY=; b=jCc/vC1XqzTYIFNeJfM/xeE3xOwQ43DZyhJWvaRpGAefwxg7mFzCB2/F4gYPskEc7k TKBo97FfcMCg6ah+8sRGm+Vz/UEqVxxtr4E2g11zgjYV7vuamluSpMbJksdyYd46vHFg el4fE0oOQy2cAQ6f58Sh/HbLqIiIaAxbo6RgOeElW199IF4R4xiVwQ/GGqRLjlmhthzj oBOVjyMLuBrUR7rS4Das8pvWHsIvZX+hCugET3XLVdH0h9FSK0B9JiS6Iw9b0HBDKfIN mK1rBYodTxMdaRV6yznyau0ue9wSc6nUGwsnnfl2U2HYUclf/XSi2iMbk5ZqWh3rmCrG e2lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4B7kxSwn+Y6/oG1SY2GzSzP2SB2pWwxeXqv90tBjdMY=; b=fX6QWob78iha66KOrjSRA+/LYHqJ33JYjtZ40Y8SDV2ZperLTdm9n/wiC1/M7tApKH v6KF20ZuGgMjkI7P6/yJeJfJsUJVQLfp9AqC3ie9t1TCkn+XcRhy8IgoXIixhpQoKiOo VqDj8c1LotqDY9RPtXBkq3qDB2y7vOKxSnqiTxdLTm8iO1xs/z2JW0vg0HiJIbsimzZj LMG79e9v7omounH5g5aADvzrde2Oh2ZyfiePKoCR3tpbm2kx1/JrQ7a4DSAIAlmeNQAF bVD1LVGiVaTvgRrtHtcOILXVrHGlQmuaUoH4LF6qkOW1flE28/h0uH+ISBtGlSPYakQK Djrg== X-Gm-Message-State: APjAAAVxZ697v+H2RUSmeECkS5RsA0kgeGdEtVkt24TEC/BkKYe62Cb6 X9fxueZZdfgv3w2ENC+vdQ== X-Google-Smtp-Source: APXvYqy3rCNaSwyeTCXNaqDdY1SOY79rL80DZeQ70j6ZYXaa54tCdbKImmJ1pA6ER3VS20XW9nHORg== X-Received: by 2002:a67:eb93:: with SMTP id e19mr11128489vso.208.1561873304884; Sat, 29 Jun 2019 22:41:44 -0700 (PDT) Received: from localhost.localdomain ([2601:902:c200:6512:37bd:d695:3a39:ceb9]) by smtp.gmail.com with ESMTPSA id r136sm1926676vke.46.2019.06.29.22.41.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 29 Jun 2019 22:41:44 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ayman.bagabas@gmail.com Subject: [RFC 6/9] platform/x86: huawei-wmi: Add battery charging thresholds Date: Sun, 30 Jun 2019 01:41:05 -0400 Message-Id: <20190630054108.19205-7-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190630054108.19205-1-ayman.bagabas@gmail.com> References: <20190630054108.19205-1-ayman.bagabas@gmail.com> MIME-Version: 1.0 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 Implement battery charging thresholds functionality to be used with sysfs interface support that is implemented in this series. Setting battery charging thresholds can introduce a race condition where two are trying to read/write values from/to EC memory. Even though a mutex is used, this doesn't guarantee that these values will make it to EC so a blocking sleep is necessary. This sleep is enforced on the MACH-WX9 model since turning off battery protection using (0,100) doesn't change the values in the EC memory, instead it only disables the protection. So a workaround is to set the thresholds to (0,0) before setting it to (0,100). This will ensure that we update these values in EC memory and then turning it off with (0,100). Thus, the msleep(1000). Signed-off-by: Ayman Bagabas --- In huawei_wmi_battery_get and later in huawei_wmi_fn_lock_get, 256 bytes buffer is allocated dynamically on the stack. Now I know this is discouraged, should it be changed to use kmalloc? drivers/platform/x86/huawei-wmi.c | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index 9013a05d2832..da3986cd0428 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -46,6 +47,7 @@ static struct quirk_entry *quirks; struct huawei_wmi_priv { struct input_dev *idev[2]; struct led_classdev cdev; + struct mutex battery_lock; struct mutex wmi_lock; struct platform_device *pdev; }; @@ -298,6 +300,57 @@ static int huawei_wmi_leds_setup(struct device *dev) return devm_led_classdev_register(dev, &priv->cdev); } +/* Battery protection */ + +static int huawei_wmi_battery_get(struct device *dev, int *low, int *high) +{ + struct huawei_wmi_priv *priv = dev_get_drvdata(dev); + u8 ret[0x100]; + int err, i; + + mutex_lock(&priv->battery_lock); + err = huawei_wmi_cmd(dev, BATTERY_THRESH_GET, ret, 0x100); + mutex_unlock(&priv->battery_lock); + if (err) + return err; + + /* Find the last two non-zero values. Return status is ignored. */ + i = 0x100; + do { + *low = ret[i-1]; + *high = ret[i]; + } while (i > 2 && !ret[i--]); + + return 0; +} + +static int huawei_wmi_battery_set(struct device *dev, int low, int high) +{ + struct huawei_wmi_priv *priv = dev_get_drvdata(dev); + u8 arg[8]; + int err; + + *(u64 *)arg = BATTERY_THRESH_SET; + arg[2] = low; + arg[3] = high; + + /* This is an edge case were some models turn battery protection + * off without changing their thresholds values. We clear the + * values before turning off protection. Sometimes we need a sleep delay to + * make sure these values make their way to EC memory. + */ + if (low == 0 && high == 100) + huawei_wmi_battery_set(dev, 0, 0); + + mutex_lock(&priv->battery_lock); + err = huawei_wmi_cmd(dev, *(u64 *)arg, NULL, NULL); + if (quirks && quirks->battery_sleep) + msleep(1000); + mutex_unlock(&priv->battery_lock); + + return err; +} + /* Input */ static void huawei_wmi_process_key(struct input_dev *idev, int code) @@ -418,6 +471,7 @@ static int huawei_wmi_probe(struct platform_device *pdev) if (wmi_has_guid(HWMI_METHOD_GUID)) { mutex_init(&priv->wmi_lock); + mutex_init(&priv->battery_lock); err = huawei_wmi_leds_setup(&pdev->dev); if (err) { From patchwork Sun Jun 30 05:41:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11024181 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 122F5138D for ; Sun, 30 Jun 2019 05:41:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 027BD286EE for ; Sun, 30 Jun 2019 05:41:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAC4328765; Sun, 30 Jun 2019 05:41:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=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 9B76C2871C for ; Sun, 30 Jun 2019 05:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726917AbfF3Flt (ORCPT ); Sun, 30 Jun 2019 01:41:49 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:34435 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726884AbfF3Fls (ORCPT ); Sun, 30 Jun 2019 01:41:48 -0400 Received: by mail-vs1-f66.google.com with SMTP id q64so6764128vsd.1; Sat, 29 Jun 2019 22:41:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YmPyHZ8dDaGq4wOOYUfRrP02saBuikUQohVrtGbVNIQ=; b=oDsbwwHbK68Ni8qTmaH83d6uoBN2aaEfFMv3CNPeT20QpwXOzPAtvHUFSGXXWIBinQ drXSxr2afFIEyF9fdJobBO9C9/XY7p+RKWYJebkrUUao7v1pYWK6cEbAeTWdaMmw1TjO 7pXdyMObIPh7+z1KDbtIPjZgx30RYW+QuYWrgrn+FTUWVrWttYz6iPAqSxsa7DlFyy4J FI7/1ZU9iS/NyAI29RCpnRJ2xhlsK9aXPm9UcplfmY/xroLbTxq/9PCqnJR0ygSrqQrn YIcMMus5Js6QE1kmPEz3yZTl+v475JwuJj3BhHWbTzhCB+8eGHrANVh51PglnHr/YjrO R6zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YmPyHZ8dDaGq4wOOYUfRrP02saBuikUQohVrtGbVNIQ=; b=Z0KJfc2DcCU8cDI5/jzV/umFCK02/KgeqpamN9z0zwZJBfiAFcuaYsEnhgOEIIj4XZ ZhViLI7jXTqmDbYBLHcWFB5+b+nGTqsbxr4gc+91cFKs5l1j1w2goCkPn4SjGnjway8f hDlSMcvazD93uUPaZFszGI1SRediPBQknbqDqwKN5QCf9R+bAt9Qhzl2Ha6r/YlAF0xC 8g+JYTMJCtKzPpOFcbadxp82HhU4e+HJjq/e7fZZg1Frikxyj4uzIfGaacUcP/h2VYAt uYTWDmxnKlObgkQaK2K7fvKlIVzyKnnhbMEic59jcCYnfYJ43TWJUvcv77a/mbD+l1Pp pzHg== X-Gm-Message-State: APjAAAV4w2ASVvSRDBTf1TDCH+/szBBkOXtdeLjp8+lfn8b7EXrx2t8Q cZbUf0TGtfeMILAI96u67KSwtecjfg== X-Google-Smtp-Source: APXvYqz0OAK6Iu1jTdoJ+PWbEyVH33gAs/NHtWPY5wn2SejRysO4MQZWdB4YY56ysD8HkLYZPH9zZA== X-Received: by 2002:a67:f492:: with SMTP id o18mr10727937vsn.62.1561873307328; Sat, 29 Jun 2019 22:41:47 -0700 (PDT) Received: from localhost.localdomain ([2601:902:c200:6512:37bd:d695:3a39:ceb9]) by smtp.gmail.com with ESMTPSA id r136sm1926676vke.46.2019.06.29.22.41.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 29 Jun 2019 22:41:47 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ayman.bagabas@gmail.com Subject: [RFC 7/9] platform/x86: huawei-wmi: Add fn-lock support Date: Sun, 30 Jun 2019 01:41:06 -0400 Message-Id: <20190630054108.19205-8-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190630054108.19205-1-ayman.bagabas@gmail.com> References: <20190630054108.19205-1-ayman.bagabas@gmail.com> MIME-Version: 1.0 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 Huawei Matebook laptops uses Fn key and toggle to access F1-F12 keys. Along with that, there is this feature called fn-lock that inverts the behavior of this Fn key. Implement the basic functionality of this feature to be used later by sysfs interface support introduced in this series. Signed-off-by: Ayman Bagabas --- drivers/platform/x86/huawei-wmi.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index da3986cd0428..4159e10bda26 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -351,6 +351,36 @@ static int huawei_wmi_battery_set(struct device *dev, int low, int high) return err; } +/* Fn lock */ + +static int huawei_wmi_fn_lock_get(struct device *dev, int *on) +{ + u8 ret[0x100] = { 0 }; + int err, i; + + err = huawei_wmi_cmd(dev, FN_LOCK_GET, ret, 0x100); + if (err) + return err; + + /* Find the first non-zero value. Return status is ignored. */ + i = 1; + do { + *on = ret[i] - 1; // -1 undefined, 0 off, 1 on. + } while (i < 0x100 && !ret[i++]); + + return 0; +} + +static int huawei_wmi_fn_lock_set(struct device *dev, int on) +{ + u8 arg[8]; + + *(u64 *)arg = FN_LOCK_SET; + arg[2] = on + 1; // 0 undefined, 1 off, 2 on. + + return huawei_wmi_cmd(dev, *(u64 *)arg, NULL, NULL); +} + /* Input */ static void huawei_wmi_process_key(struct input_dev *idev, int code) From patchwork Sun Jun 30 05:41:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11024185 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 D44B1138D for ; Sun, 30 Jun 2019 05:42:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C4D51286EE for ; Sun, 30 Jun 2019 05:42:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B95CE28765; Sun, 30 Jun 2019 05:42:02 +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 58FFD286EE for ; Sun, 30 Jun 2019 05:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726968AbfF3Flw (ORCPT ); Sun, 30 Jun 2019 01:41:52 -0400 Received: from mail-vs1-f65.google.com ([209.85.217.65]:41847 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726961AbfF3Flv (ORCPT ); Sun, 30 Jun 2019 01:41:51 -0400 Received: by mail-vs1-f65.google.com with SMTP id 2so6745600vso.8; Sat, 29 Jun 2019 22:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tCO4bB5RG1i1zaVkyEc6qftvnA4HN0QLB0O4PI95vVE=; b=Claumc/bSvhmkaPdNUpy8Taf8SARFzxVzvtqYvLmkI2NV4GXM7R2dyhMyHEtq8F+3m QA8a7r0Y7kNbRP70KFXgC57/X6IZIIN888k9nUAFdeEMPV0PpZbW0w1j0kGx8VU7Qvjc P3GUvKFI/gNV2B3ZkzRHvvKlG04vjmtZbuXb8dtK1rYHrssFUw+icgJMQY+prnr13obe fXFSrmsaOccryExTJS+mUzMrgqEhW7gkUrGQlNLI+grA1aMu2aodYNQjvqytvvndPorM OI/DkstzT1a2KCgggq2ZWuRIX6suDZUvj+vY7Nl4wbh64fR//iRSEDFKHl71+/qUeMIm ligA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tCO4bB5RG1i1zaVkyEc6qftvnA4HN0QLB0O4PI95vVE=; b=fStxABud1fY0kReOIXkS+1UibCUSydnelDW0JPKQLuXyJwpFyfqf5WQLCzT5J9rBye 36CrOVggVp+D8//uAqJy8CixFAgNeWESmswGD2sUnwN4L8y2l/nQSrvjtOStdIAhqQ20 w442F3v8PnJPkeNYhtUQJZ/zh88ZoxLybd5E/z1EGZd+JmYjFlQhv+4upCUQO1U9nsVS lN5POixLKTveUwTJwRNYFMDo6tpG/Sdi4OfPKG0urWOygGHuDoqEF+gBDC8cNTCiCVNZ aJN+G7+tuRjtIahCDbKqyXSL1iB7/wpfplnZP3sQMwXKR1BtO0CLHoP+u0oOE9EhbqFC Y5pQ== X-Gm-Message-State: APjAAAXiRPBG/cimFre9Q2u/RWQHJAITIc9WV52M84AGw1xpavNx9wfT uGoTkk2P+aWaQ/MiTtoE3A== X-Google-Smtp-Source: APXvYqxzpzthH1VQv9WA2DronCje4ZVLbcQZRCXt43nVNtNZmb/vNqpgGZ88zd8CfHLPLKS4sSUTmg== X-Received: by 2002:a67:887:: with SMTP id 129mr11361418vsi.82.1561873309837; Sat, 29 Jun 2019 22:41:49 -0700 (PDT) Received: from localhost.localdomain ([2601:902:c200:6512:37bd:d695:3a39:ceb9]) by smtp.gmail.com with ESMTPSA id r136sm1926676vke.46.2019.06.29.22.41.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 29 Jun 2019 22:41:49 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ayman.bagabas@gmail.com Subject: [RFC 8/9] platform/x86: huawei-wmi: Add sysfs interface support Date: Sun, 30 Jun 2019 01:41:07 -0400 Message-Id: <20190630054108.19205-9-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190630054108.19205-1-ayman.bagabas@gmail.com> References: <20190630054108.19205-1-ayman.bagabas@gmail.com> MIME-Version: 1.0 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 sysfs interface to enable the use of battery charging thresholds and fn-lock support introduced in this series. Signed-off-by: Ayman Bagabas --- drivers/platform/x86/huawei-wmi.c | 82 +++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index 4159e10bda26..f7041fb71026 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -14,6 +14,7 @@ #include #include #include +#include #include /* @@ -381,6 +382,80 @@ static int huawei_wmi_fn_lock_set(struct device *dev, int on) return huawei_wmi_cmd(dev, *(u64 *)arg, NULL, NULL); } +/* sysfs */ + +static ssize_t charge_thresholds_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int err, low, high; + + err = huawei_wmi_battery_get(dev, &low, &high); + if (err) + return err; + + return sprintf(buf, "%d %d\n", low, high); +} + +static ssize_t charge_thresholds_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + int low, high, err; + + if (sscanf(buf, "%d %d", &low, &high) != 2 || + low < 0 || high > 100 || + low > high) + return -EINVAL; + + err = huawei_wmi_battery_set(dev, low, high); + if (err) + return err; + + return size; +} + +static ssize_t fn_lock_state_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int err, on; + + err = huawei_wmi_fn_lock_get(dev, &on); + if (err) + return err; + + return sprintf(buf, "%d\n", on); +} + +static ssize_t fn_lock_state_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + int on, err; + + if (kstrtoint(buf, 10, &on) || + on < 0 || on > 1) + return -EINVAL; + + err = huawei_wmi_fn_lock_set(dev, on); + if (err) + return err; + + return size; +} + +static DEVICE_ATTR_RW(charge_thresholds); +static DEVICE_ATTR_RW(fn_lock_state); + +static struct attribute *huawei_wmi_attrs[] = { + &dev_attr_charge_thresholds.attr, + &dev_attr_fn_lock_state.attr, + NULL +}; + +ATTRIBUTE_GROUPS(huawei_wmi); + /* Input */ static void huawei_wmi_process_key(struct input_dev *idev, int code) @@ -508,6 +583,12 @@ static int huawei_wmi_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to setup leds\n"); return err; } + + err = sysfs_create_groups(&pdev->dev.kobj, huawei_wmi_groups); + if (err) { + dev_err(&pdev->dev, "Failed to create sysfs interface\n"); + return err; + } } return 0; @@ -522,6 +603,7 @@ static int huawei_wmi_remove(struct platform_device *pdev) wmi_remove_notify_handler(HWMI_EVENT_GUID); if (wmi_has_guid(HWMI_METHOD_GUID)) { + sysfs_remove_groups(&pdev->dev.kobj, huawei_wmi_groups); } return 0; From patchwork Sun Jun 30 05:41:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11024183 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 A77F9112C for ; Sun, 30 Jun 2019 05:41:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96C9A286EE for ; Sun, 30 Jun 2019 05:41:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8902128765; Sun, 30 Jun 2019 05:41:57 +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 F0C0B286EE for ; Sun, 30 Jun 2019 05:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726961AbfF3Fl4 (ORCPT ); Sun, 30 Jun 2019 01:41:56 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:37688 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726987AbfF3Fly (ORCPT ); Sun, 30 Jun 2019 01:41:54 -0400 Received: by mail-vs1-f67.google.com with SMTP id v6so6753958vsq.4; Sat, 29 Jun 2019 22:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xl+sNzEYPOT1ywDx++7Y8OIBlzLDJkDBqJnWrBIwwq4=; b=VLwQij/5g9C/PdlQUUixCzBA5oWa+mF0QzRFXvolDQhd9b4fzUbA8S+K+WPbVOfw6A zPieR4mcq6SHGGfSytiUfpULKdXk5xxHcpZ0EiCqjEms5bSrkaXVPEogz1oJLrLm03ov TLI0hI8cKII+OrLcXnH+++wzyeyZ+Wsmbim64fPJ+25pmlcV0TiyHx9HkTozFafgnmPq 5Bn/QK1Ug75bzYSzqjGLzi7DNd8pdbS27nykQEsEqSeRxb0pOFmYxTfoybHuxwTB6wev C9+AhVZLwc29xbiKEK2FurTzqtqP9G7N6KNu5ipbHVuZDMy+BERUlSzDjpod1di/OVCq 8F3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xl+sNzEYPOT1ywDx++7Y8OIBlzLDJkDBqJnWrBIwwq4=; b=SVrq3dWFQyNxku2NfZOQgBO76PfzAwDAUMBy6RjhNCaxtI6QL6r3WM/1/zq/M4C7Pq WNjm3OW32a++XK+fjJMEqPWlwcSAl8ygtn2C5B05iRamVCb5xNEqK7LL9C5DycxSyDc+ T5BslyY4yroFenqoCAZ2HY3l22DuibNbyPRzri5XKXo59eItpT+03m15nogbarT+Gv54 DHlD6+KQ4eBVD1+HTI4Bpg0ATfl2du41qZENBPcDqYh/S2NW2Sim0zUA+S4qVyOwe8s4 3GlWkOfVCESDDbo688GWiKcrMKcu1p5qItDSYsrkFnEpM7yYB6g2T5CNRSndIi2SGn/r EOlA== X-Gm-Message-State: APjAAAWK7RM11AST5QbLPVbMR9K23j4YC95jOrerDmkmqqFBNYUkU0i2 Ud7owMXv9ZK8EIIcgovDnA== X-Google-Smtp-Source: APXvYqw+m1w37rCVm7BL+BsPXDgUeQT2G6vzl51WTL+AHq47lrmWTcVqc3ZqcC626cPZXpqToacBWA== X-Received: by 2002:a67:d993:: with SMTP id u19mr3419960vsj.0.1561873313257; Sat, 29 Jun 2019 22:41:53 -0700 (PDT) Received: from localhost.localdomain ([2601:902:c200:6512:37bd:d695:3a39:ceb9]) by smtp.gmail.com with ESMTPSA id r136sm1926676vke.46.2019.06.29.22.41.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 29 Jun 2019 22:41:52 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ayman.bagabas@gmail.com Subject: [RFC 9/9] platform/x86: huawei-wmi: Add debugfs support Date: Sun, 30 Jun 2019 01:41:08 -0400 Message-Id: <20190630054108.19205-10-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190630054108.19205-1-ayman.bagabas@gmail.com> References: <20190630054108.19205-1-ayman.bagabas@gmail.com> MIME-Version: 1.0 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 debugfs interface that can be used to call the WMI management interface function. The WMI interface takes a 64 bit integer and returns 256-260 bytes buffer. This debugfs interface creates two files, one stores a 64 bit int and the other calls the WMI interface and dumps out the returned buffer. Signed-off-by: Ayman Bagabas --- drivers/platform/x86/huawei-wmi.c | 98 +++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index f7041fb71026..bdca8bd76c8c 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -45,7 +46,13 @@ struct quirk_entry { static struct quirk_entry *quirks; +struct huawei_wmi_debug { + struct dentry *root; + u64 arg; +}; + struct huawei_wmi_priv { + struct huawei_wmi_debug debug; struct input_dev *idev[2]; struct led_classdev cdev; struct mutex battery_lock; @@ -456,6 +463,94 @@ static struct attribute *huawei_wmi_attrs[] = { ATTRIBUTE_GROUPS(huawei_wmi); +/* debugfs */ + +static void huawei_wmi_debugfs_call_dump(struct seq_file *m, void *data, + union acpi_object *obj) +{ + struct huawei_wmi_priv *priv = m->private; + int i; + + switch (obj->type) { + case ACPI_TYPE_INTEGER: + seq_printf(m, "0x%llx", obj->integer.value); + break; + case ACPI_TYPE_STRING: + seq_printf(m, "\"%*s\"", obj->string.length, obj->string.pointer); + break; + case ACPI_TYPE_BUFFER: + seq_puts(m, "{"); + for (i = 0; i < obj->buffer.length; i++) { + seq_printf(m, "0x%02x", obj->buffer.pointer[i]); + if (i < obj->buffer.length - 1) + seq_puts(m, ","); + } + seq_puts(m, "}"); + break; + case ACPI_TYPE_PACKAGE: + seq_puts(m, "["); + for (i = 0; i < obj->package.count; i++) { + huawei_wmi_debugfs_call_dump(m, priv, &obj->package.elements[i]); + if (i < obj->package.count - 1) + seq_puts(m, ","); + } + seq_puts(m, "]"); + break; + default: + dev_err(&priv->pdev->dev, "Unexpected obj type, got %d\n", obj->type); + return; + } +} + +static int huawei_wmi_debugfs_call_show(struct seq_file *m, void *data) +{ + struct huawei_wmi_priv *priv = m->private; + struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_buffer in; + union acpi_object *obj; + int err; + + in.length = sizeof(u64); + in.pointer = &priv->debug.arg; + + err = huawei_wmi_call(&priv->pdev->dev, &in, &out); + if (err) + return err; + + obj = out.pointer; + if (!obj) { + err = -EIO; + goto fail_debugfs_call; + } + + huawei_wmi_debugfs_call_dump(m, priv, obj); + +fail_debugfs_call: + kfree(out.pointer); + return err; +} + +DEFINE_SHOW_ATTRIBUTE(huawei_wmi_debugfs_call); + +static void huawei_wmi_debugfs_exit(struct device *dev) +{ + struct huawei_wmi_priv *priv = dev_get_drvdata(dev); + + debugfs_remove_recursive(priv->debug.root); +} + +static void huawei_wmi_debugfs_setup(struct device *dev) +{ + struct huawei_wmi_priv *priv = dev_get_drvdata(dev); + + priv->debug.root = debugfs_create_dir("huawei-wmi", NULL); + + debugfs_create_x64("arg", 0644, priv->debug.root, + &priv->debug.arg); + debugfs_create_file("call", 0400, + priv->debug.root, priv, &huawei_wmi_debugfs_call_fops); +} + /* Input */ static void huawei_wmi_process_key(struct input_dev *idev, int code) @@ -589,6 +684,8 @@ static int huawei_wmi_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to create sysfs interface\n"); return err; } + + huawei_wmi_debugfs_setup(&pdev->dev); } return 0; @@ -603,6 +700,7 @@ static int huawei_wmi_remove(struct platform_device *pdev) wmi_remove_notify_handler(HWMI_EVENT_GUID); if (wmi_has_guid(HWMI_METHOD_GUID)) { + huawei_wmi_debugfs_exit(&pdev->dev); sysfs_remove_groups(&pdev->dev.kobj, huawei_wmi_groups); }