From patchwork Tue Sep 29 02:32:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Azael Avalos X-Patchwork-Id: 7282171 Return-Path: X-Original-To: patchwork-platform-driver-x86@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BA8F09F36A for ; Tue, 29 Sep 2015 02:32:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8665A20709 for ; Tue, 29 Sep 2015 02:32:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2403E20705 for ; Tue, 29 Sep 2015 02:32:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932195AbbI2Cck (ORCPT ); Mon, 28 Sep 2015 22:32:40 -0400 Received: from mail-oi0-f48.google.com ([209.85.218.48]:35933 "EHLO mail-oi0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932191AbbI2Ccj (ORCPT ); Mon, 28 Sep 2015 22:32:39 -0400 Received: by oibi136 with SMTP id i136so101399160oib.3; Mon, 28 Sep 2015 19:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=jyBrZK3utiY7kn1Eu6jEjne61YWRlcUetV7N/9njMtU=; b=h5ekhxxYaFTXgSCQdJdIuasCJrDgkNMUdg53KSC6u6RtO3jcxSw3qJfsFcztHhvMCa efQjnA5a12flsNkQPKdiDzSKugSg+iEtdadKOqFw/TghirysGrDV71xvvB8FgzhvdSop PK1DYf5dThGpSR8G0gVlrTu4MhW/Pgs8qSX43KsX5fA1rVmEAi8ig6My3BAWLpcCO8GC iWNJbkkT1//a9SzQ8EVOJZKJnMv1T4nqyGybcBcJHSNwFOOltAzUnqZRDqZHl9CCy+FA 8ym7teS9Xvgjslz25unvpXl2F9zwDnSTk0kvIq+lsNo3okqic/PLSfzJS3sP6d2jUKNZ hFgA== X-Received: by 10.202.214.133 with SMTP id n127mr12389954oig.52.1443493958850; Mon, 28 Sep 2015 19:32:38 -0700 (PDT) Received: from Shakuras.scurra.org (148-240-211-215.ftth.dynamic.axtel.net. [148.240.211.215]) by smtp.gmail.com with ESMTPSA id w8sm10342614oec.7.2015.09.28.19.32.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Sep 2015 19:32:37 -0700 (PDT) From: Azael Avalos To: Darren Hart , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Azael Avalos Subject: [PATCH v4] platform/x86: Toshiba WMI Hotkey Driver Date: Mon, 28 Sep 2015 20:32:28 -0600 Message-Id: <1443493948-2643-1-git-send-email-coproscefalo@gmail.com> X-Mailer: git-send-email 2.5.1 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Toshiba laptops that feature WMI events for hotkeys were left unsupported by the toshiba_acpi driver, however, commit a88bc06e5aec ("toshiba_acpi: Avoid registering input device on WMI event laptops") added hardware support for such laptops, but the hotkeys are not handled there. This driver adds support for hotkey monitoring on certain Toshiba laptops that manage the hotkeys via WMI events instead of the Toshiba Configuration Interface (TCI). The toshiba_acpi driver and this one can co-exist, as this only takes care of hotkeys, while the proper takes care of hardware related stuff. Currently the driver is under the EXPERIMENTAL flag, as the keymap and the notify function are incomplete (due to lack of hardware to test). Signed-off-by: Azael Avalos --- Changes since v3: - Fixed Makefile entry, CONFIG_TOSHIBA_HAPS was doubled instead of one of them being CONFIG_TOSHIBA_WMI (this should fix the kbuild errors reported) Changes since v2: - Fixed typo in patch and Kconfig description as well as in a comment Changes since v1: - Changed the printed log level of the ACPI event type value from info to debug - Make the input_dev struct declaration static MAINTAINERS | 6 ++ drivers/platform/x86/Kconfig | 18 +++++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/toshiba-wmi.c | 138 +++++++++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 drivers/platform/x86/toshiba-wmi.c diff --git a/MAINTAINERS b/MAINTAINERS index 884d398..07f4446 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10318,6 +10318,12 @@ L: platform-driver-x86@vger.kernel.org S: Maintained F: drivers/platform/x86/toshiba_haps.c +TOSHIBA WMI HOTKEYS DRIVER +M: Azael Avalos +L: platform-driver-x86@vger.kernel.org +S: Maintained +F: drivers/platform/x86/toshiba-wmi.c + TOSHIBA SMM DRIVER M: Jonathan Buzzard W: http://www.buzzard.org.uk/toshiba/ diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index c69bb70..242b5d8 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -700,6 +700,24 @@ config TOSHIBA_HAPS If you have a recent Toshiba laptop with a built-in accelerometer device, say Y. +config TOSHIBA_WMI + tristate "Toshiba WMI Hotkeys Driver (EXPERIMENTAL)" + default n + depends on ACPI_WMI + depends on INPUT + select INPUT_SPARSEKMAP + ---help--- + This driver adds hotkey monitoring support to some Toshiba models + that manage the hotkeys via WMI events. + + WARNING: This driver is incomplete as it lacks a proper keymap and the + *notify function only prints the ACPI event type value. Be warned that + you will need to provide some information if you have a Toshiba model + with WMI event hotkeys and want to help with the develpment of this + driver. + + If you have a WMI-based hotkeys Toshiba laptop, say Y or M here. + config ACPI_CMPC tristate "CMPC Laptop Extras" depends on X86 && ACPI diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index ada5128..3ca78a3 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o obj-$(CONFIG_TOSHIBA_BT_RFKILL) += toshiba_bluetooth.o obj-$(CONFIG_TOSHIBA_HAPS) += toshiba_haps.o +obj-$(CONFIG_TOSHIBA_WMI) += toshiba-wmi.o obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o obj-$(CONFIG_INTEL_SCU_IPC_UTIL) += intel_scu_ipcutil.o obj-$(CONFIG_INTEL_MFLD_THERMAL) += intel_mid_thermal.o diff --git a/drivers/platform/x86/toshiba-wmi.c b/drivers/platform/x86/toshiba-wmi.c new file mode 100644 index 0000000..feac457 --- /dev/null +++ b/drivers/platform/x86/toshiba-wmi.c @@ -0,0 +1,138 @@ +/* + * toshiba_wmi.c - Toshiba WMI Hotkey Driver + * + * Copyright (C) 2015 Azael Avalos + * + * 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. + * + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include + +MODULE_AUTHOR("Azael Avalos"); +MODULE_DESCRIPTION("Toshiba WMI Hotkey Driver"); +MODULE_LICENSE("GPL"); + +#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100" + +MODULE_ALIAS("wmi:"TOSHIBA_WMI_EVENT_GUID); + +static struct input_dev *toshiba_wmi_input_dev; + +static const struct key_entry toshiba_wmi_keymap[] __initconst = { + /* TODO: Add keymap values once found... */ + /*{ KE_KEY, 0x00, { KEY_ } },*/ + { KE_END, 0 } +}; + +static void toshiba_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("Bad event status 0x%x\n", status); + return; + } + + obj = (union acpi_object *)response.pointer; + if (!obj) + return; + + /* TODO: Add proper checks once we have data */ + pr_debug("Unknown event received, obj type %x\n", obj->type); + + kfree(response.pointer); +} + +static int __init toshiba_wmi_input_setup(void) +{ + acpi_status status; + int err; + + toshiba_wmi_input_dev = input_allocate_device(); + if (!toshiba_wmi_input_dev) + return -ENOMEM; + + toshiba_wmi_input_dev->name = "Toshiba WMI hotkeys"; + toshiba_wmi_input_dev->phys = "wmi/input0"; + toshiba_wmi_input_dev->id.bustype = BUS_HOST; + + err = sparse_keymap_setup(toshiba_wmi_input_dev, + toshiba_wmi_keymap, NULL); + if (err) + goto err_free_dev; + + status = wmi_install_notify_handler(TOSHIBA_WMI_EVENT_GUID, + toshiba_wmi_notify, NULL); + if (ACPI_FAILURE(status)) { + err = -EIO; + goto err_free_keymap; + } + + err = input_register_device(toshiba_wmi_input_dev); + if (err) + goto err_remove_notifier; + + return 0; + + err_remove_notifier: + wmi_remove_notify_handler(TOSHIBA_WMI_EVENT_GUID); + err_free_keymap: + sparse_keymap_free(toshiba_wmi_input_dev); + err_free_dev: + input_free_device(toshiba_wmi_input_dev); + return err; +} + +static void toshiba_wmi_input_destroy(void) +{ + wmi_remove_notify_handler(TOSHIBA_WMI_EVENT_GUID); + sparse_keymap_free(toshiba_wmi_input_dev); + input_unregister_device(toshiba_wmi_input_dev); +} + +static int __init toshiba_wmi_init(void) +{ + int ret; + + if (!wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) + return -ENODEV; + + ret = toshiba_wmi_input_setup(); + if (ret) { + pr_err("Failed to setup input device\n"); + return ret; + } + + pr_info("Toshiba WMI Hotkey Driver\n"); + + return 0; +} + +static void __exit toshiba_wmi_exit(void) +{ + if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) + toshiba_wmi_input_destroy(); +} + +module_init(toshiba_wmi_init); +module_exit(toshiba_wmi_exit);