From patchwork Tue Dec 1 08:35:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 335407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B97E7C64E8A for ; Tue, 1 Dec 2020 08:36:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D057206D8 for ; Tue, 1 Dec 2020 08:36:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727355AbgLAIgU (ORCPT ); Tue, 1 Dec 2020 03:36:20 -0500 Received: from mail.v3.sk ([167.172.186.51]:58906 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728623AbgLAIgT (ORCPT ); Tue, 1 Dec 2020 03:36:19 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 5FC03DF9A4; Tue, 1 Dec 2020 08:32:41 +0000 (UTC) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id A8YI1WmixClB; Tue, 1 Dec 2020 08:32:40 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id B74CBE06C5; Tue, 1 Dec 2020 08:32:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id FsgvZzSA60k2; Tue, 1 Dec 2020 08:32:40 +0000 (UTC) Received: from localhost (unknown [109.183.109.54]) by zimbra.v3.sk (Postfix) with ESMTPSA id 799DADF9A4; Tue, 1 Dec 2020 08:32:40 +0000 (UTC) From: Lubomir Rintel To: Dmitry Torokhov Cc: Pavel Machek , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Lubomir Rintel , Rob Herring Subject: [PATCH v4 1/2] dt-bindings: input: Add Dell Wyse 3020 Power Button binding Date: Tue, 1 Dec 2020 09:35:32 +0100 Message-Id: <20201201083533.1724287-2-lkundrak@v3.sk> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201201083533.1724287-1-lkundrak@v3.sk> References: <20201201083533.1724287-1-lkundrak@v3.sk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add binding document for the Dell Wyse 3020 a.k.a. "Ariel" Power Button. Signed-off-by: Lubomir Rintel Reviewed-by: Rob Herring --- Changes since v3: (Based on warnings from Rob's validation bot) - Specify additionalProperties: false - Allow using spi-max-frequency property Changes since v1: - Collect Rob's R-b .../bindings/input/ariel-pwrbutton.yaml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/ariel-pwrbutton.yaml diff --git a/Documentation/devicetree/bindings/input/ariel-pwrbutton.yaml b/Documentation/devicetree/bindings/input/ariel-pwrbutton.yaml new file mode 100644 index 0000000000000..b4ad829d73838 --- /dev/null +++ b/Documentation/devicetree/bindings/input/ariel-pwrbutton.yaml @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/ariel-pwrbutton.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Dell Wyse 3020 a.k.a. "Ariel" Power Button + +maintainers: + - Lubomir Rintel + +description: | + The ENE Embedded Controller on the Ariel board has an interface to the + SPI bus that is capable of sending keyboard and mouse data. A single + power button is attached to it. This binding describes this + configuration. + +allOf: + - $ref: input.yaml# + +properties: + compatible: + items: + - const: dell,wyse-ariel-ec-input + - const: ene,kb3930-input + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + spi-max-frequency: true + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include + + spi { + #address-cells = <1>; + #size-cells = <0>; + + power-button@0 { + compatible = "dell,wyse-ariel-ec-input", "ene,kb3930-input"; + reg = <0>; + interrupt-parent = <&gpio>; + interrupts = <60 IRQ_TYPE_EDGE_RISING>; + spi-max-frequency = <33000000>; + }; + }; From patchwork Tue Dec 1 08:35:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 336270 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A6F0C83012 for ; Tue, 1 Dec 2020 08:36:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02F34206D8 for ; Tue, 1 Dec 2020 08:36:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728818AbgLAIgZ (ORCPT ); Tue, 1 Dec 2020 03:36:25 -0500 Received: from mail.v3.sk ([167.172.186.51]:58918 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728665AbgLAIgU (ORCPT ); Tue, 1 Dec 2020 03:36:20 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id D7FFCE06C5; Tue, 1 Dec 2020 08:32:41 +0000 (UTC) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id pWwvYZfdq-kO; Tue, 1 Dec 2020 08:32:41 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 1FCACE0713; Tue, 1 Dec 2020 08:32:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id h4mu0GBuk84I; Tue, 1 Dec 2020 08:32:41 +0000 (UTC) Received: from localhost (unknown [109.183.109.54]) by zimbra.v3.sk (Postfix) with ESMTPSA id DC594DF9A4; Tue, 1 Dec 2020 08:32:40 +0000 (UTC) From: Lubomir Rintel To: Dmitry Torokhov Cc: Pavel Machek , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Lubomir Rintel Subject: [PATCH v4 2/2] Input: add driver for power button on Dell Wyse 3020 Date: Tue, 1 Dec 2020 09:35:33 +0100 Message-Id: <20201201083533.1724287-3-lkundrak@v3.sk> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201201083533.1724287-1-lkundrak@v3.sk> References: <20201201083533.1724287-1-lkundrak@v3.sk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This adds support for the power button attached to the Embedded Controller on a Dell Wyse 3020 "Ariel" board. The Embedded Controller's SPI interface is actually capable sending and receiving the PS/2 keyboard and mouse protocol data, which looks like a good fit for a serio driver. Howerver, I don't know of any machines where this is actually used. My board only has a single power button and no way to connect an actual keyboard or a mouse. Using the atkbd driver with serio would be an overkill and would be inconvenient for the userspace. Therefore this driver registers an input device that is only capable of reporting the power button presses and releases. Signed-off-by: Lubomir Rintel --- Changes since v2: (All by the suggestions of Dmitry Torokhov. Thank you Dmitry!) - Add more includes - Make ariel_pwrbutton.msg_counter not a bitfield - Include an error code in error message when ec_input_read() fails in the interrupt handler. - Return from the interrupt handler from a single point. - Remove a forgotten debug statement. - s/ret/error/ - Return -EINVAL instead of -ENXIO when the IRQ line is not specified. - Don't hardcode rising edge trigger, rely on DT instead - Remove a banner print at the end of probe(). Changes since v1: - Do away bitfields in order to be endian independent drivers/input/misc/Kconfig | 11 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/ariel-pwrbutton.c | 169 +++++++++++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 drivers/input/misc/ariel-pwrbutton.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 362e8a01980cd..e7bb572e15182 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -73,6 +73,17 @@ config INPUT_AD714X_SPI To compile this driver as a module, choose M here: the module will be called ad714x-spi. +config INPUT_ARIEL_PWRBUTTON + tristate "Dell Wyse 3020 Power Button Driver" + depends on SPI + depends on MACH_MMP3_DT || COMPILE_TEST + help + Say Y to enable support for reporting power button status on + on Dell Wyse 3020 ("Ariel") thin client. + + To compile this driver as a module, choose M here: the module + will be called ariel-pwrbutton. + config INPUT_ARIZONA_HAPTICS tristate "Arizona haptics support" depends on MFD_ARIZONA && SND_SOC diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index a48e5f2d859d4..062cea9f181c9 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_INPUT_ADXL34X) += adxl34x.o obj-$(CONFIG_INPUT_ADXL34X_I2C) += adxl34x-i2c.o obj-$(CONFIG_INPUT_ADXL34X_SPI) += adxl34x-spi.o obj-$(CONFIG_INPUT_APANEL) += apanel.o +obj-$(CONFIG_INPUT_ARIEL_PWRBUTTON) += ariel-pwrbutton.o obj-$(CONFIG_INPUT_ARIZONA_HAPTICS) += arizona-haptics.o obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o diff --git a/drivers/input/misc/ariel-pwrbutton.c b/drivers/input/misc/ariel-pwrbutton.c new file mode 100644 index 0000000000000..eda86ab552b9c --- /dev/null +++ b/drivers/input/misc/ariel-pwrbutton.c @@ -0,0 +1,169 @@ +// SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-or-later +/* + * Dell Wyse 3020 a.k.a. "Ariel" Power Button Driver + * + * Copyright (C) 2020 Lubomir Rintel + */ + +#include +#include +#include +#include +#include +#include +#include + +#define RESP_COUNTER(response) (response.header & 0x3) +#define RESP_SIZE(response) ((response.header >> 2) & 0x3) +#define RESP_TYPE(response) ((response.header >> 4) & 0xf) + +struct ec_input_response { + u8 reserved; + u8 header; + u8 data[3]; +} __packed; + +struct ariel_pwrbutton { + struct spi_device *client; + struct input_dev *input; + u8 msg_counter; +}; + +static int ec_input_read(struct ariel_pwrbutton *priv, + struct ec_input_response *response) +{ + u8 read_request[] = { 0x00, 0x5a, 0xa5, 0x00, 0x00 }; + struct spi_device *spi = priv->client; + struct spi_transfer t = { + .tx_buf = read_request, + .rx_buf = response, + .len = sizeof(read_request), + }; + + compiletime_assert(sizeof(read_request) == sizeof(*response), + "SPI xfer request/response size mismatch"); + + return spi_sync_transfer(spi, &t, 1); +} + +static irqreturn_t ec_input_interrupt(int irq, void *dev_id) +{ + struct ariel_pwrbutton *priv = dev_id; + struct spi_device *spi = priv->client; + struct ec_input_response response; + int error; + int i; + + error = ec_input_read(priv, &response); + if (error < 0) { + dev_err(&spi->dev, "EC read failed: %d\n", error); + goto out; + } + + if (priv->msg_counter == RESP_COUNTER(response)) { + dev_warn(&spi->dev, "No new data to read?\n"); + goto out; + } + + priv->msg_counter = RESP_COUNTER(response); + + if (RESP_TYPE(response) != 0x3 && RESP_TYPE(response) != 0xc) { + dev_dbg(&spi->dev, "Ignoring message that's not kbd data\n"); + goto out; + } + + for (i = 0; i < RESP_SIZE(response); i++) { + switch (response.data[i]) { + case 0x74: + input_report_key(priv->input, KEY_POWER, 1); + input_sync(priv->input); + break; + case 0xf4: + input_report_key(priv->input, KEY_POWER, 0); + input_sync(priv->input); + break; + default: + dev_dbg(&spi->dev, "Unknown scan code: %02x\n", + response.data[i]); + } + } + +out: + return IRQ_HANDLED; +} + +static int ariel_pwrbutton_probe(struct spi_device *spi) +{ + struct ec_input_response response; + struct ariel_pwrbutton *priv; + int error; + + if (!spi->irq) { + dev_err(&spi->dev, "Missing IRQ.\n"); + return -EINVAL; + } + + priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->client = spi; + spi_set_drvdata(spi, priv); + + priv->input = devm_input_allocate_device(&spi->dev); + if (!priv->input) + return -ENOMEM; + priv->input->name = "Power Button"; + priv->input->dev.parent = &spi->dev; + input_set_capability(priv->input, EV_KEY, KEY_POWER); + error = input_register_device(priv->input); + if (error) { + dev_err(&spi->dev, "error registering input device: %d\n", error); + return error; + } + + error = ec_input_read(priv, &response); + if (error < 0) { + dev_err(&spi->dev, "EC read failed: %d\n", error); + return error; + } + priv->msg_counter = RESP_COUNTER(response); + + error = devm_request_threaded_irq(&spi->dev, spi->irq, NULL, + ec_input_interrupt, + IRQF_ONESHOT, + "Ariel EC Input", priv); + + if (error) { + dev_err(&spi->dev, "Failed to request IRQ %d: %d\n", + spi->irq, error); + return error; + } + + return 0; +} + +static const struct of_device_id ariel_pwrbutton_of_match[] = { + { .compatible = "dell,wyse-ariel-ec-input" }, + { } +}; +MODULE_DEVICE_TABLE(of, ariel_pwrbutton_of_match); + +static const struct spi_device_id ariel_pwrbutton_id_table[] = { + { "wyse-ariel-ec-input", 0 }, + {} +}; +MODULE_DEVICE_TABLE(spi, ariel_pwrbutton_id_table); + +static struct spi_driver ariel_pwrbutton_driver = { + .driver = { + .name = "dell-wyse-ariel-ec-input", + .of_match_table = ariel_pwrbutton_of_match, + }, + .probe = ariel_pwrbutton_probe, +}; +module_spi_driver(ariel_pwrbutton_driver); + +MODULE_AUTHOR("Lubomir Rintel "); +MODULE_DESCRIPTION("Dell Wyse 3020 Power Button Input Driver"); +MODULE_LICENSE("Dual BSD/GPL");