From patchwork Sat Jul 20 15:05:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maximilian Luz X-Patchwork-Id: 11050923 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 2D97B746 for ; Sat, 20 Jul 2019 15:05:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1703328685 for ; Sat, 20 Jul 2019 15:05:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07B4D28710; Sat, 20 Jul 2019 15:05: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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,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 836B328685 for ; Sat, 20 Jul 2019 15:05:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728685AbfGTPFx (ORCPT ); Sat, 20 Jul 2019 11:05:53 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51383 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725858AbfGTPFx (ORCPT ); Sat, 20 Jul 2019 11:05:53 -0400 Received: by mail-wm1-f68.google.com with SMTP id 207so31260073wma.1; Sat, 20 Jul 2019 08:05:52 -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=CV+Src3/orFKmofk/Bya8jyXlTvi8zmBrxoWLjvYSfI=; b=hhxE17yVzKLBLnFzf0VxZa6fJwT7cliGJCTmbHqhudf0UPUFigeJx+zzCJWLUgK9h7 SH+TdoF0bE3tAf2QS9bfntCs2gt/LKWj1o5DaXnQlJQSGrUHV7Ey5af9J+rk57KLGW4B /u0g3MxyMFkREm1EDb05FQJhJnvIIfV0QqUz1qRlNgCx2y73AT/dGBl50wEOAXDHIo1q +oQFPXG4mLzr2l2bCbWfppHO9BwW1e62W7tis6RcGjBURjVFLu087uphOpwfkIeJyP1t y+G7aC+W4oWBW2KjqakpxUK2KYaa0T5vEaM0d1VlgEMpBjm3BtbXlj35YGmkwjvPuMZo yMqQ== 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=CV+Src3/orFKmofk/Bya8jyXlTvi8zmBrxoWLjvYSfI=; b=i3Uuq/pkuFFRZLR9+SIyiL9UTl1sUcOEd47dB1yTytrLSkVfWSJqD8XU19ub1K+DZ3 sg5do7hlY9oVKU40xBbSA4mF1y3n/JoKk3LPblg/dx/7Wq1wCKDE2miZcsS3ffQQxp0n GNGF87DeF8NVH2i/JwxPfaHe/vcHIWear5wqWlO89ehdr9HonR84hFQ6tChuakD5eQUO IeitZqPSdhP8nXDUbGzsBewqyBwv03idyt0saxjklndN56IfnR+ha19I22YcAL+UVZDi QJXg0kD+r2nKVvETWZ1lQyk6AIWGcokzQnGt+ujYFzyHIS+3EJEHsD0Bj0fmEuuDnEaN N53w== X-Gm-Message-State: APjAAAWSkgpxCPYdV0WR8szWtJdnr2jWqPvGZvAx/tfR6eb5KIYMGS1C F+blCvcuPcl8tjlb2w8CLGkFzN3+ X-Google-Smtp-Source: APXvYqzDCAUdGiwhcq7a+eDYDondHZIONZwCKxPrnHcUJaOKbxvuzgT1mSgOJ2HNwibBKLpUGDAiCQ== X-Received: by 2002:a1c:4d05:: with SMTP id o5mr51815738wmh.129.1563635151402; Sat, 20 Jul 2019 08:05:51 -0700 (PDT) Received: from xws.fritz.box (pD9EA3BA8.dip0.t-ipconnect.de. [217.234.59.168]) by smtp.gmail.com with ESMTPSA id g8sm38326864wme.20.2019.07.20.08.05.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 20 Jul 2019 08:05:50 -0700 (PDT) From: Maximilian Luz Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, platform-driver-x86@vger.kernel.org, Dmitry Torokhov , Hans de Goede , Chen Yu , Darren Hart , Andy Shevchenko , Benjamin Tissoires , Maximilian Luz Subject: [PATCH v3 1/2] platform/x86: surfacepro3_button: Fix device check Date: Sat, 20 Jul 2019 17:05:10 +0200 Message-Id: <20190720150511.95076-2-luzmaximilian@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190720150511.95076-1-luzmaximilian@gmail.com> References: <20190720150511.95076-1-luzmaximilian@gmail.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Do not use the surfacepro3_button driver on newer Microsoft Surface models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th and possibly future generations) use the same device as the Surface Pro 4 to represent their volume and power buttons (MSHW0040), but their actual implementation is significantly different. This patch ensures that the surfacepro3_button driver is only used on the Pro 3 and 4 models, allowing a different driver to bind on other models. Signed-off-by: Maximilian Luz Acked-by: Andy Shevchenko Acked-by: Chen Yu --- drivers/platform/x86/surfacepro3_button.c | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/platform/x86/surfacepro3_button.c b/drivers/platform/x86/surfacepro3_button.c index 47c6d000465a..ec515223f654 100644 --- a/drivers/platform/x86/surfacepro3_button.c +++ b/drivers/platform/x86/surfacepro3_button.c @@ -20,6 +20,12 @@ #define SURFACE_BUTTON_OBJ_NAME "VGBI" #define SURFACE_BUTTON_DEVICE_NAME "Surface Pro 3/4 Buttons" +#define MSHW0040_DSM_REVISION 0x01 +#define MSHW0040_DSM_GET_OMPR 0x02 // get OEM Platform Revision +static const guid_t MSHW0040_DSM_UUID = + GUID_INIT(0x6fd05c69, 0xcde3, 0x49f4, 0x95, 0xed, 0xab, 0x16, 0x65, + 0x49, 0x80, 0x35); + #define SURFACE_BUTTON_NOTIFY_TABLET_MODE 0xc8 #define SURFACE_BUTTON_NOTIFY_PRESS_POWER 0xc6 @@ -142,6 +148,44 @@ static int surface_button_resume(struct device *dev) } #endif +/* + * Surface Pro 4 and Surface Book 2 / Surface Pro 2017 use the same device + * ID (MSHW0040) for the power/volume buttons. Make sure this is the right + * device by checking for the _DSM method and OEM Platform Revision. + * + * Returns true if the driver should bind to this device, i.e. the device is + * either MSWH0028 (Pro 3) or MSHW0040 on a Pro 4 or Book 1. + */ +static bool surface_button_check_MSHW0040(struct acpi_device *dev) +{ + acpi_handle handle = dev->handle; + union acpi_object *result; + u64 oem_platform_rev = 0; // valid revisions are nonzero + + // get OEM platform revision + result = acpi_evaluate_dsm_typed(handle, &MSHW0040_DSM_UUID, + MSHW0040_DSM_REVISION, + MSHW0040_DSM_GET_OMPR, + NULL, ACPI_TYPE_INTEGER); + + /* + * If evaluating the _DSM fails, the method is not present. This means + * that we have either MSHW0028 or MSHW0040 on Pro 4 or Book 1, so we + * should use this driver. We use revision 0 indicating it is + * unavailable. + */ + + if (result) { + oem_platform_rev = result->integer.value; + ACPI_FREE(result); + } + + dev_dbg(&dev->dev, "OEM Platform Revision %llu\n", oem_platform_rev); + + return oem_platform_rev == 0; +} + + static int surface_button_add(struct acpi_device *device) { struct surface_button *button; @@ -154,6 +198,9 @@ static int surface_button_add(struct acpi_device *device) strlen(SURFACE_BUTTON_OBJ_NAME))) return -ENODEV; + if (!surface_button_check_MSHW0040(device)) + return -ENODEV; + button = kzalloc(sizeof(struct surface_button), GFP_KERNEL); if (!button) return -ENOMEM; From patchwork Sat Jul 20 15:05:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maximilian Luz X-Patchwork-Id: 11050929 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 8DF321580 for ; Sat, 20 Jul 2019 15:06:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E86328521 for ; Sat, 20 Jul 2019 15:06:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71CF22871E; Sat, 20 Jul 2019 15:06: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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable 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 E32A028685 for ; Sat, 20 Jul 2019 15:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728703AbfGTPF6 (ORCPT ); Sat, 20 Jul 2019 11:05:58 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39265 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725858AbfGTPF6 (ORCPT ); Sat, 20 Jul 2019 11:05:58 -0400 Received: by mail-wm1-f68.google.com with SMTP id u25so21133282wmc.4; Sat, 20 Jul 2019 08:05:55 -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=e2/FC1aBpR9e3Ryt4WCIvoHF0DRkbD2VdF6iOoH5nEw=; b=mh/Ugh5T5kLxaED2zERQdPrlECyXs1c0QzjAb5vSlITnafoZbY4T0qFkeqXupj3vVN meCED6I5TQJLMITYn7dMEDsqsquEuoHaLcd4IIR1B5XlYThYpsurbNaYxVmvBmhR1Xd+ yda2XL2sWicegcWOi/pdsHCf0IPdIoO0izNS07hRcnrlf4k1sxfKoJ93XOnRtzCU5xkT rxIu8wG2XSHvO5BasGli3y3X4AP3KDgpo8XnJN227VV0SesRA8np9dFFFzYLau3tdYOp V8H8U3NVngHiq7MTZuX3PS/DXEpAjJe5KzVkndGh6xAcnAouJ/szIk5pUy30+Q6UfSOH ZANw== 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=e2/FC1aBpR9e3Ryt4WCIvoHF0DRkbD2VdF6iOoH5nEw=; b=kAwv78GrmLRrAhGiCr5WvW+uNSvskyegFGIRFTLV9rUkkqxRnATdGkkb9gPC+gW+7V QZgkfY5QJs+5UphrMoWBINm5RST/h73a0fyJ6xgBeTAsK/X/xpccdV328pHbkFSBqmEG F3eWoHNDb7IA96c+NoFs4G9KdQBpNg8doIIRV6xi4Tpd35824q0/tDMAX4ROKnXSPD6I 9xDR/xfU1G/HU7Orqqj/iXH/3E1pKFguT4h1cKEgNfQqzELFHZ7md9Rs33t9jEUpVlbA YYq6Zk6amu6XZPb2JIPT0N0GwU7kI6ZjhEJbxHFK74adTQMtYRrGBgRCGE929mKtVPl6 cooQ== X-Gm-Message-State: APjAAAXWLF0Xm4DQmjxLdn/tAjuLtGikzAmd7UtfggmyJ2+IWbFeoMTt eHVks564ETDBIU3FpkBoPkqVlw4G X-Google-Smtp-Source: APXvYqyaJipV+CBALWy/vODWU4XLjaUcLb4VQr/m16R63XKsni7TgltqM9PngYw5nM0xMNh/9j+Vfg== X-Received: by 2002:a7b:c247:: with SMTP id b7mr56046610wmj.13.1563635154308; Sat, 20 Jul 2019 08:05:54 -0700 (PDT) Received: from xws.fritz.box (pD9EA3BA8.dip0.t-ipconnect.de. [217.234.59.168]) by smtp.gmail.com with ESMTPSA id g8sm38326864wme.20.2019.07.20.08.05.53 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 20 Jul 2019 08:05:53 -0700 (PDT) From: Maximilian Luz Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, platform-driver-x86@vger.kernel.org, Dmitry Torokhov , Hans de Goede , Chen Yu , Darren Hart , Andy Shevchenko , Benjamin Tissoires , Maximilian Luz Subject: [PATCH v3 2/2] Input: soc_button_array - Add support for newer surface devices Date: Sat, 20 Jul 2019 17:05:11 +0200 Message-Id: <20190720150511.95076-3-luzmaximilian@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190720150511.95076-1-luzmaximilian@gmail.com> References: <20190720150511.95076-1-luzmaximilian@gmail.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Power and volume button support for 5th and 6th generation Microsoft Surface devices via soc_button_array. Note that these devices use the same MSHW0040 device as on the Surface Pro 4, however the implementation is different (GPIOs vs. ACPI notifications). Thus some checking is required to ensure we only load this driver on the correct devices. Signed-off-by: Maximilian Luz Signed-off-by: Maximilian Luz Signed-off-by: Dmitry Torokhov --- drivers/input/misc/Kconfig | 6 +- drivers/input/misc/soc_button_array.c | 141 +++++++++++++++++++++++--- 2 files changed, 131 insertions(+), 16 deletions(-) diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index d07c1eb15aa6..7d9ae394e597 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -813,10 +813,10 @@ config INPUT_IDEAPAD_SLIDEBAR config INPUT_SOC_BUTTON_ARRAY tristate "Windows-compatible SoC Button Array" - depends on KEYBOARD_GPIO + depends on KEYBOARD_GPIO && ACPI help - Say Y here if you have a SoC-based tablet that originally - runs Windows 8. + Say Y here if you have a SoC-based tablet that originally runs + Windows 8 or a Microsoft Surface Book 2, Pro 5, Laptop 1 or later. To compile this driver as a module, choose M here: the module will be called soc_button_array. diff --git a/drivers/input/misc/soc_button_array.c b/drivers/input/misc/soc_button_array.c index 5e59f8e57f8e..4d5150bebeef 100644 --- a/drivers/input/misc/soc_button_array.c +++ b/drivers/input/misc/soc_button_array.c @@ -25,6 +25,17 @@ struct soc_button_info { bool wakeup; }; +/** + * struct soc_device_data - driver data for different device types + * @button_info: specifications of buttons, if NULL specification is assumed to + * be present in _DSD + * @check: device-specific check (NULL means all will be accepted) + */ +struct soc_device_data { + struct soc_button_info *button_info; + int (*check)(struct device *dev); +}; + /* * Some of the buttons like volume up/down are auto repeat, while others * are not. To support both, we register two platform devices, and put @@ -87,8 +98,13 @@ soc_button_device_create(struct platform_device *pdev, continue; gpio = soc_button_lookup_gpio(&pdev->dev, info->acpi_index); - if (!gpio_is_valid(gpio)) + if (gpio < 0 && gpio != -ENOENT) { + error = gpio; + goto err_free_mem; + } else if (!gpio_is_valid(gpio)) { + /* Skip GPIO if not present */ continue; + } gpio_keys[n_buttons].type = info->event_type; gpio_keys[n_buttons].code = info->event_code; @@ -310,6 +326,7 @@ static int soc_button_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; const struct acpi_device_id *id; + struct soc_device_data *device_data; struct soc_button_info *button_info; struct soc_button_data *priv; struct platform_device *pd; @@ -320,18 +337,20 @@ static int soc_button_probe(struct platform_device *pdev) if (!id) return -ENODEV; - if (!id->driver_data) { + device_data = (struct soc_device_data *)id->driver_data; + if (device_data && device_data->check) { + error = device_data->check(dev); + if (error) + return error; + } + + if (device_data && device_data->button_info) { + button_info = (struct soc_button_info *) + device_data->button_info; + } else { button_info = soc_button_get_button_info(dev); if (IS_ERR(button_info)) return PTR_ERR(button_info); - } else { - button_info = (struct soc_button_info *)id->driver_data; - } - - error = gpiod_count(dev, NULL); - if (error < 0) { - dev_dbg(dev, "no GPIO attached, ignoring...\n"); - return -ENODEV; } priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); @@ -357,12 +376,32 @@ static int soc_button_probe(struct platform_device *pdev) if (!priv->children[0] && !priv->children[1]) return -ENODEV; - if (!id->driver_data) + if (!device_data || !device_data->button_info) devm_kfree(dev, button_info); return 0; } + +static int soc_device_check_generic(struct device *dev) +{ + int gpios; + + gpios = gpiod_count(dev, NULL); + if (gpios < 0) { + dev_dbg(dev, "no GPIO attached, ignoring...\n"); + return -ENODEV; + } + + return 0; +} + +static struct soc_device_data soc_device_ACPI0011 = { + .button_info = NULL, + .check = soc_device_check_generic, +}; + + /* * Definition of buttons on the tablet. The ACPI index of each button * is defined in section 2.8.7.2 of "Windows ACPI Design Guide for SoC @@ -377,9 +416,85 @@ static struct soc_button_info soc_button_PNP0C40[] = { { } }; +static struct soc_device_data soc_device_PNP0C40 = { + .button_info = soc_button_PNP0C40, + .check = soc_device_check_generic, +}; + + +/* + * Special device check for Surface Book 2 and Surface Pro (2017). + * Both, the Surface Pro 4 (surfacepro3_button.c) and the above mentioned + * devices use MSHW0040 for power and volume buttons, however the way they + * have to be addressed differs. Make sure that we only load this drivers + * for the correct devices by checking the OEM Platform Revision provided by + * the _DSM method. + */ +#define MSHW0040_DSM_REVISION 0x01 +#define MSHW0040_DSM_GET_OMPR 0x02 // get OEM Platform Revision +static const guid_t MSHW0040_DSM_UUID = + GUID_INIT(0x6fd05c69, 0xcde3, 0x49f4, 0x95, 0xed, 0xab, 0x16, 0x65, + 0x49, 0x80, 0x35); + +static int soc_device_check_MSHW0040(struct device *dev) +{ + acpi_handle handle = ACPI_HANDLE(dev); + union acpi_object *result; + u64 oem_platform_rev = 0; // valid revisions are nonzero + int gpios; + + // get OEM platform revision + result = acpi_evaluate_dsm_typed(handle, &MSHW0040_DSM_UUID, + MSHW0040_DSM_REVISION, + MSHW0040_DSM_GET_OMPR, NULL, + ACPI_TYPE_INTEGER); + + if (result) { + oem_platform_rev = result->integer.value; + ACPI_FREE(result); + } + + /* + * If the revision is zero here, the _DSM evaluation has failed. This + * indicates that we have a Pro 4 or Book 1 and this driver should not + * be used. + */ + if (oem_platform_rev == 0) + return -ENODEV; + + dev_dbg(dev, "OEM Platform Revision %llu\n", oem_platform_rev); + + gpios = gpiod_count(dev, NULL); + if (gpios < 0) + return -ENODEV; + + return 0; +} + +/* + * Button infos for Microsoft Surface Book 2 and Surface Pro (2017). + * Obtained from DSDT/testing. + */ +static struct soc_button_info soc_button_MSHW0040[] = { + { "power", 0, EV_KEY, KEY_POWER, false, true }, + { "volume_up", 2, EV_KEY, KEY_VOLUMEUP, true, false }, + { "volume_down", 4, EV_KEY, KEY_VOLUMEDOWN, true, false }, + { } +}; + +static struct soc_device_data soc_device_MSHW0040 = { + .button_info = soc_button_MSHW0040, + .check = soc_device_check_MSHW0040, +}; + + static const struct acpi_device_id soc_button_acpi_match[] = { - { "PNP0C40", (unsigned long)soc_button_PNP0C40 }, - { "ACPI0011", 0 }, + { "PNP0C40", (unsigned long)&soc_device_PNP0C40 }, + { "ACPI0011", (unsigned long)&soc_device_ACPI0011 }, + + /* Microsoft Surface Devices (5th and 6th generation) */ + { "MSHW0040", (unsigned long)&soc_device_MSHW0040 }, + { } };