From patchwork Wed Oct 31 15:56:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 10662863 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 612E114DE for ; Wed, 31 Oct 2018 15:56:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D6582AC58 for ; Wed, 31 Oct 2018 15:56:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 414A32AC7B; Wed, 31 Oct 2018 15:56:52 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,MIME_BASE64_TEXT, 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 12FAD2AC58 for ; Wed, 31 Oct 2018 15:56:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729655AbeKAAzZ (ORCPT ); Wed, 31 Oct 2018 20:55:25 -0400 Received: from mail-yb1-f171.google.com ([209.85.219.171]:44504 "EHLO mail-yb1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729613AbeKAAzZ (ORCPT ); Wed, 31 Oct 2018 20:55:25 -0400 Received: by mail-yb1-f171.google.com with SMTP id p144-v6so6819067yba.11; Wed, 31 Oct 2018 08:56:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:mime-version; bh=kUCbMxRNWBQJbpbUv5Cs/R+fOEF1Qg7PTWELdcgvsoM=; b=PfBfb5+eA0j3l5Jy0o5cr/Jej1H0ovD1kKif/FKl6OG7MCBE+zXC2s8wQvO+LVvHoz gnVywfnzRwk+5pCHVYzPkhmoF+4KnK32mZzMR1zfnRAqhpiI7xBBwC3WAruMOlkVDI35 zt3L4ztdH/oT7vzKERj+FQ6ASOgdk9hfbjRoVTDeybqx2bRwV6V6Hs5rCAhi4jR39rRQ 90iWRypuSw7P2btQxGlDNnzkuTy6uUk6xcGUiIJ3koLnXPahIsA46KVCidU7qn1YA8NY 5K+leds47akVVLLrcDPKL/3q79Bu+bsgwzJUBH27dO7+AaCMpba3qkUs9xp2e6QKgq/H QYlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:mime-version; bh=kUCbMxRNWBQJbpbUv5Cs/R+fOEF1Qg7PTWELdcgvsoM=; b=q7VmkL3+i/q7zbWJzqLJAlwjdqBJFXFu+5n2afQN2MwzN1rUgNq5ccDs4xJZsB1XBE UlHKbi2RpXo2vt2bKF+YgmgiU0qjymRffDiY4jbqNz8BQstKTv6cgsI2Iz8xnjozDhMb u/TtR5lTUCFhawkVhNi0AN2fWdIyBahjf5pVBMSqldS8R05t5vq8WhAZncpPHE5pxHjh dpjRVyDS1GNEq6HXGbD8BKt2sJY6YKiWNBQhssSW5MfkuhGmiW/2C5p4UHbEURyiJUjE U+pyY3iRB+eLOQRXRvkRD9oNn4QX6Eb/XkGF1oM6JBSpu6qD4KqyXJ6ouIzat+Y/sBiC d5ZA== X-Gm-Message-State: AGRZ1gLA2oM8sR9ndI2LGSQgAKovzAMcfAE26jYoycpIf4uTk5nLpdXU gt27ujJ8nyBvTZpJbBknIg== X-Google-Smtp-Source: AJdET5eIa3/EpZLG33UsABfNGr9IomGa74QmTWCwQoDCDmGwUTeMmo0B3saxGCqotOFnDPDcG1x5vQ== X-Received: by 2002:a25:bb4a:: with SMTP id b10-v6mr3727002ybk.396.1541001407682; Wed, 31 Oct 2018 08:56:47 -0700 (PDT) Received: from 960 ([130.254.104.55]) by smtp.gmail.com with ESMTPSA id r5-v6sm10861941ywr.80.2018.10.31.08.56.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 08:56:46 -0700 (PDT) Message-ID: Subject: [PATCH] x86: add support for Huawei WMI hotkeys. From: ayman.bagabas@gmail.com To: dvhart@infradead.org, andy@infradead.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: Ayman Bagabas Date: Wed, 31 Oct 2018 11:56:46 -0400 X-Mailer: Evolution 3.28.5 (3.28.5-1.fc28) 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 From bc069762e7e86dd3ab39e55d7b145deb85884dec Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 31 Oct 2018 11:24:43 -0400 Subject: [PATCH 1/3] x86: add support for Huawei WMI hotkeys. This driver adds support for missing hotkeys on some Huawei laptops. Currently, only Huawei Matebook X Pro is supported. The driver recognizes the following keys: brightness keys, micmute, wlan, and Huawei special key. The brightness keys are ignored since they work out of the box. Signed-off-by: Ayman Bagabas --- drivers/platform/x86/Kconfig | 13 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/huawei_wmi.c | 225 ++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+) create mode 100644 drivers/platform/x86/huawei_wmi.c diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 0c1aa6c314f5..c6813981e45c 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -1229,6 +1229,19 @@ config I2C_MULTI_INSTANTIATE To compile this driver as a module, choose M here: the module will be called i2c-multi-instantiate. +config HUAWEI_LAPTOP + tristate "Huawei WMI hotkeys driver" + depends on ACPI + depends on ACPI_WMI + depends on INPUT + select INPUT_SPARSEKMAP + help + This driver provides support for Huawei WMI hotkeys. + It enables the missing keys and adds support to micmute + led found on these laptops.q + Supported devices are: + - Matebook X Pro + endif # X86_PLATFORM_DEVICES config PMC_ATOM diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index e6d1becf81ce..5984354e18ff 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_ACERHDF) += acerhdf.o obj-$(CONFIG_HP_ACCEL) += hp_accel.o obj-$(CONFIG_HP_WIRELESS) += hp-wireless.o obj-$(CONFIG_HP_WMI) += hp-wmi.o +obj-$(CONFIG_HUAWEI_LAPTOP) += huawei_wmi.o obj-$(CONFIG_AMILO_RFKILL) += amilo-rfkill.o obj-$(CONFIG_GPD_POCKET_FAN) += gpd-pocket-fan.o obj-$(CONFIG_TC1100_WMI) += tc1100-wmi.o diff --git a/drivers/platform/x86/huawei_wmi.c b/drivers/platform/x86/huawei_wmi.c new file mode 100644 index 000000000000..a430ff860929 --- /dev/null +++ b/drivers/platform/x86/huawei_wmi.c @@ -0,0 +1,225 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Huawei WMI Hotkeys Driver + * + * Copyright (C) 2018 Ayman Bagabas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +MODULE_AUTHOR("Ayman Bagabas "); +MODULE_DESCRIPTION("Huawei WMI hotkeys"); +MODULE_LICENSE("GPL"); + +#define DEVICE_NAME "huawei" +#define MODULE_NAME DEVICE_NAME"_wmi" + +/* + * Huawei WMI Devices GUIDs + */ +#define AMW0_GUID "ABBC0F5B-8EA1-11D1-A000-C90629100000" // \_SB.AMW0 + +/* + * Huawei WMI Events GUIDs + */ +#define EVENT_GUID "ABBC0F5C-8EA1-11D1-A000-C90629100000" + +MODULE_ALIAS("wmi:"AMW0_GUID); +MODULE_ALIAS("wmi:"EVENT_GUID); + +enum { + MICMUTE_LED_ON = 0x00010B04, + MICMUTE_LED_OFF = 0x00000B04, +}; + +static const struct key_entry huawei_wmi_keymap[] __initconst = { + { KE_IGNORE, 0x281, { KEY_BRIGHTNESSDOWN } }, + { KE_IGNORE, 0x282, { KEY_BRIGHTNESSUP } }, + { KE_IGNORE, 0x283, { KEY_KBDILLUMTOGGLE } }, + { KE_KEY, 0x287, { KEY_MICMUTE } }, + { KE_KEY, 0x289, { KEY_WLAN } }, + // Huawei |M| button + { KE_KEY, 0x28a, { KEY_PROG1 } }, + { KE_END, 0 } +}; + +struct huawei_wmi_device { + struct input_dev *inputdev; +}; +static struct huawei_wmi_device *wmi_device; + +int huawei_wmi_micmute_led_set(bool on) +{ + u32 args = (on) ? MICMUTE_LED_ON : MICMUTE_LED_OFF; + struct acpi_buffer input = { (acpi_size)sizeof(args), &args }; + acpi_status status; + + status = wmi_evaluate_method(AMW0_GUID, 0, 1, &input, NULL); + if (ACPI_FAILURE(status)) + return status; + + return 0; +} +EXPORT_SYMBOL_GPL(huawei_wmi_micmute_led_set); + +static void huawei_wmi_process_key(struct input_dev *input_dev, int code) +{ + const struct key_entry *key; + + key = sparse_keymap_entry_from_scancode(input_dev, code); + + if (!key) { + pr_info("%s: Unknown key pressed, code: 0x%04x\n", + MODULE_NAME, code); + return; + } + + sparse_keymap_report_entry(input_dev, key, 1, true); +} + +static void huawei_wmi_notify(u32 value, void *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)) { + pr_err("%s: Bad event status 0x%x\n", + MODULE_NAME, status); + return; + } + + obj = (union acpi_object *)response.pointer; + + if (!obj) + return; + + if (obj->type == ACPI_TYPE_INTEGER) + huawei_wmi_process_key(wmi_device->inputdev, + obj->integer.value); + else + pr_info("%s: Unknown response received %d\n", + MODULE_NAME, obj->type); + + kfree(response.pointer); +} + +static int huawei_input_init(void) +{ + acpi_status status; + int err; + + wmi_device->inputdev = input_allocate_device(); + if (!wmi_device->inputdev) + return -ENOMEM; + + wmi_device->inputdev->name = "Huawei WMI hotkeys"; + wmi_device->inputdev->phys = "wmi/input0"; + wmi_device->inputdev->id.bustype = BUS_HOST; + + err = sparse_keymap_setup(wmi_device->inputdev, + huawei_wmi_keymap, NULL); + if (err) + goto err_free_dev; + + status = wmi_install_notify_handler(EVENT_GUID, + huawei_wmi_notify, + NULL); + + if (ACPI_FAILURE(status)) { + err = -EIO; + goto err_free_dev; + } + + err = input_register_device(wmi_device->inputdev); + if (err) + goto err_remove_notifier; + + return 0; + + +err_remove_notifier: + wmi_remove_notify_handler(EVENT_GUID); +err_free_dev: + input_free_device(wmi_device->inputdev); + return err; +} + +static void huawei_input_exit(void) +{ + wmi_remove_notify_handler(EVENT_GUID); + input_unregister_device(wmi_device->inputdev); +} + +static int __init huawei_wmi_setup(void) +{ + int err; + + wmi_device = kmalloc(sizeof(struct huawei_wmi_device), GFP_KERNEL); + if (!wmi_device) + return -ENOMEM; + + err = huawei_input_init(); + if (err) + goto err_input; + + return 0; + +err_input: + return err; +} + +static void huawei_wmi_destroy(void) +{ + huawei_input_exit(); + kfree(wmi_device); +} + +static int __init huawei_wmi_init(void) +{ + int err; + + if (!wmi_has_guid(EVENT_GUID)) { + pr_warn("%s: No known WMI GUID found\n", MODULE_NAME); + return -ENODEV; + } + + err = huawei_wmi_setup(); + if (err) { + pr_err("%s: Failed to setup device\n", MODULE_NAME); + return err; + } + + return 0; +} + +static void __exit huawei_wmi_exit(void) +{ + huawei_wmi_destroy(); + pr_debug("%s: Driver unloaded successfully\n", MODULE_NAME); +} + +module_init(huawei_wmi_init); +module_exit(huawei_wmi_exit); -- 2.17.2