From patchwork Mon Mar 5 22:02:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Harvey X-Patchwork-Id: 10260003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 71D2A60365 for ; Mon, 5 Mar 2018 22:04:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D4EA28883 for ; Mon, 5 Mar 2018 22:04:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51DE228CB4; Mon, 5 Mar 2018 22:04:11 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BC03328883 for ; Mon, 5 Mar 2018 22:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=fNpKChSyOzSxho/VF0CsgJOvJxqGFaVPO0LNl/lRWy0=; b=fxvyq1lQY1r1Zlc1G8dVT8wEi2 1s/uXhO9ZvL2x1KHwZT22V8xaMeqHuTz24tlKkiToHIB5dTS3mg6IJWIWW9oON4FQg9tjq8yD7xKx 21EXijwK1Ilk2RwYwCd2Lw7/6J2i3UHlT6ppOKOLSAssoxMXQfXeOXfXjdckhFFUm8Jbf7c/bU9rF 7bGP2eRH/38mHErNnsKRjAJ7DfXq/Jr0Ui68gx++dbKZu1BbYTZFr8HsYwgm42bKWdNlsSQPLufmD eFFJbj0rV2JrCX9mFN5F2VVaN2n3uncrbZsMHjplarhDtpNrv1A5qE+e9C6/YSlwFrF8wthU751bK FCW8uOsg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1esyDC-0005Fg-0w; Mon, 05 Mar 2018 22:04:02 +0000 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1esyCZ-0004wE-Gg for linux-arm-kernel@lists.infradead.org; Mon, 05 Mar 2018 22:03:28 +0000 Received: by mail-pf0-x243.google.com with SMTP id a16so7837898pfn.9 for ; Mon, 05 Mar 2018 14:03:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gateworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RERTYT+CMvDrq/N0quXylyg5hG63sFSP7BCw+SJmWX8=; b=lhWQbmqac/O8Y/as/H1jn1zPCGmYszbZT555wLRYVqWs3wzSJCjhVJrLHhwW9bAUfW str3xXscm1A2QNr2q8Kti+tdAkfvEj8YcGhag9rGHxD5JaN8sICGmgVy0Jdxz+ZcHdIq hofPladYMh+PTMZRAwXpmpN38uFrgf1ZeJj9vpJ6Y2YRnA4cyqGlQpzrIyU/K8VfJsNZ p/SfY+VLLfNdOmYlndvT8c6mtZC13B0sqfaHSz7/awtAz2Ksq61fqBGVg779k4FC8Txz VpoT4coYCznt4nn0L165B0EkiMLbBcCW2aWtWd+mubPjXS/ztgE2FR5iaHmsBMDIsdQW x52A== 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; bh=RERTYT+CMvDrq/N0quXylyg5hG63sFSP7BCw+SJmWX8=; b=W0Ir60iOo8kiTfL1o3tFMzKvQVhU8hIfzNF+A5cb0EX4NS7HjApA0mPUQecsW3rX22 m38LJ38qNmeKnted5e7EKcioD2u3lpGqfGO945YbBRxoQzjXHYiOyLPCA5R1Pq8HVwqV 3eaCQr2YYjl6736DKyudTClS7FoM7ACY0wTnmrIr6K49ppqI2icoZKjutsaJoWhQ/IU2 AqkH2UZQGwvyyDkxKzLDKnpzJw+qb0G0TR9YSq046tHm0WPgZJHc8/gmsho4TfJKM0hu gOQqM0OchTPzkfapENKYs7+N9Sce673VOeJi0H6eJd/tv/G0KTHkQU6c6r8ujG6zI580 vQ8Q== X-Gm-Message-State: APf1xPDWb0FZ0MLGeH9NGalc7/v3TK7ePTBHBdkQnMP4NrOTCtX6D/bR +1WXnlSR4V0UMEiRpYJlNUvD/g== X-Google-Smtp-Source: AG47ELsXv+J3zUufUP4fZI/HkjzexEEUo9d1RPlf+f0gnAL33d+u1c5HhjYrh+kw3KqufIFDOxi2Uw== X-Received: by 10.101.87.132 with SMTP id b4mr13079377pgr.282.1520287399974; Mon, 05 Mar 2018 14:03:19 -0800 (PST) Received: from tharvey.pdc.gateworks.com (68-189-91-139.static.snlo.ca.charter.com. [68.189.91.139]) by smtp.gmail.com with ESMTPSA id q66sm26999313pfi.95.2018.03.05.14.03.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Mar 2018 14:03:19 -0800 (PST) From: Tim Harvey To: Lee Jones , Rob Herring , Mark Rutland , Mark Brown , Dmitry Torokhov Subject: [PATCH v2 4/4] input: misc: Add Gateworks System Controller support Date: Mon, 5 Mar 2018 14:02:41 -0800 Message-Id: <1520287361-12569-5-git-send-email-tharvey@gateworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520287361-12569-1-git-send-email-tharvey@gateworks.com> References: <1520287361-12569-1-git-send-email-tharvey@gateworks.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180305_140323_803818_65B83287 X-CRM114-Status: GOOD ( 23.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-input@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for dispatching Linux Input events for the various interrupts the Gateworks System Controller provides. Cc: Dmitry Torokhov Signed-off-by: Tim Harvey --- v2: - reword Kconfig - revise license comment block - remove unnecessary read of status register - remove unnecessary setting of input->dev.parent - use dt bindings for irq to keycode mapping - add support for platform-data - remove work-queue drivers/input/misc/Kconfig | 9 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/gsc-input.c | 180 ++++++++++++++++++++++++++++++++ include/linux/platform_data/gsc_input.h | 30 ++++++ 4 files changed, 220 insertions(+) create mode 100644 drivers/input/misc/gsc-input.c create mode 100644 include/linux/platform_data/gsc_input.h diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 9f082a3..e05f4fe 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -117,6 +117,15 @@ config INPUT_E3X0_BUTTON To compile this driver as a module, choose M here: the module will be called e3x0_button. +config INPUT_GSC + tristate "Gateworks System Controller input support" + depends on MFD_GSC + help + Support GSC events as Linux input events. + + To compile this driver as a module, choose M here: the + module will be called gsc_input. + config INPUT_PCSPKR tristate "PC Speaker support" depends on PCSPKR_PLATFORM diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 4b6118d..969debe 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_INPUT_GP2A) += gp2ap002a00f.o obj-$(CONFIG_INPUT_GPIO_BEEPER) += gpio-beeper.o obj-$(CONFIG_INPUT_GPIO_TILT_POLLED) += gpio_tilt_polled.o obj-$(CONFIG_INPUT_GPIO_DECODER) += gpio_decoder.o +obj-$(CONFIG_INPUT_GSC) += gsc-input.o obj-$(CONFIG_INPUT_HISI_POWERKEY) += hisi_powerkey.o obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o obj-$(CONFIG_INPUT_IMS_PCU) += ims-pcu.o diff --git a/drivers/input/misc/gsc-input.c b/drivers/input/misc/gsc-input.c new file mode 100644 index 0000000..27b5e93 --- /dev/null +++ b/drivers/input/misc/gsc-input.c @@ -0,0 +1,180 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (C) 2018 Gateworks Corporation + * + * This driver dispatches Linux input events for GSC interrupt events + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +struct gsc_input_button_priv { + struct input_dev *input; + const struct gsc_input_button *button; +}; + +struct gsc_input_data { + struct gsc_dev *gsc; + struct gsc_input_platform_data *pdata; + struct input_dev *input; + struct gsc_input_button_priv *buttons; + int nbuttons; + unsigned int irqs[]; +#if 0 + int irq; + struct work_struct irq_work; + struct mutex mutex; +#endif +}; + +static irqreturn_t gsc_input_irq(int irq, void *data) +{ + const struct gsc_input_button_priv *button_priv = data; + struct input_dev *input = button_priv->input; + + dev_dbg(&input->dev, "irq%d code=%d\n", irq, button_priv->button->code); + input_report_key(input, button_priv->button->code, 1); + input_sync(input); + input_report_key(input, button_priv->button->code, 0); + input_sync(input); + + return IRQ_HANDLED; +} + +static struct gsc_input_platform_data * +gsc_input_get_devtree_pdata(struct device *dev) +{ + struct gsc_input_platform_data *pdata; + struct fwnode_handle *child; + struct gsc_input_button *button; + int nbuttons; + + nbuttons = device_get_child_node_count(dev); + dev_dbg(dev, "buttons=%d\n", nbuttons); + if (nbuttons == 0) + return ERR_PTR(-ENODEV); + + pdata = devm_kzalloc(dev, + sizeof(*pdata) + nbuttons * sizeof(*button), + GFP_KERNEL); + if (!pdata) + return ERR_PTR(-ENOMEM); + + button = (struct gsc_input_button *)(pdata + 1); + pdata->buttons = button; + pdata->nbuttons = nbuttons; + + device_property_read_string(dev, "label", &pdata->name); + + device_for_each_child_node(dev, child) { + if (is_of_node(child)) + button->irq = irq_of_parse_and_map(to_of_node(child), + 0); + if (fwnode_property_read_u32(child, "linux,code", + &button->code)) { + dev_err(dev, "Button without keycode\n"); + fwnode_handle_put(child); + return ERR_PTR(-EINVAL); + } + fwnode_property_read_string(child, "label", &button->desc); + button++; + } + + return pdata; +} + +static int gsc_input_probe(struct platform_device *pdev) +{ + struct gsc_dev *gsc = dev_get_drvdata(pdev->dev.parent); + struct device *dev = &pdev->dev; + struct gsc_input_platform_data *pdata = dev_get_platdata(dev); + struct gsc_input_data *input; + int i, ret; + + if (!pdata) { + pdata = gsc_input_get_devtree_pdata(dev); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + } + + input = devm_kzalloc(dev, sizeof(*input), GFP_KERNEL); + if (!input) + return -ENOMEM; + input->gsc = gsc; + input->pdata = pdata; + + input->buttons = devm_kzalloc(dev, pdata->nbuttons * + sizeof(struct gsc_input_button_priv), + GFP_KERNEL); + if (!input->buttons) + return -ENOMEM; + + /* Register input device */ + input->input = devm_input_allocate_device(dev); + if (!input->input) { + dev_err(dev, "Can't allocate input device\n"); + return -ENOMEM; + } + input->input->name = pdata->name ? : pdev->name; + + platform_set_drvdata(pdev, gsc); + + for (i = 0; i < pdata->nbuttons; i++) { + const struct gsc_input_button *button = &pdata->buttons[i]; + struct gsc_input_button_priv *button_priv = &input->buttons[i]; + + button_priv = &input->buttons[i]; + button_priv->button = &pdata->buttons[i]; + button_priv->input = input->input; + input_set_capability(input->input, EV_KEY, button->code); + + ret = devm_request_threaded_irq(dev, button->irq, NULL, + gsc_input_irq, 0, + button->desc, + button_priv); + if (ret) { + dev_err(dev, "irq%d request failed: %d\n)", button->irq, + ret); + return ret; + } + dev_dbg(dev, "button: irq%d/%d code=%d %s\n", + button->irq - pdata->buttons[0].irq, + button->irq, + button->code, button->desc); + } + + ret = input_register_device(input->input); + if (ret < 0) { + dev_err(dev, "Can't register input device: %d\n", ret); + return ret; + } + + return 0; +} + +static const struct of_device_id gsc_input_dt_ids[] = { + { .compatible = "gw,gsc-input", }, + {} +}; + +static struct platform_driver gsc_input_driver = { + .driver = { + .name = KBUILD_MODNAME, + .of_match_table = gsc_input_dt_ids, + }, + .probe = gsc_input_probe, +}; + +module_platform_driver(gsc_input_driver); + +MODULE_AUTHOR("Tim Harvey "); +MODULE_DESCRIPTION("GSC input driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/platform_data/gsc_input.h b/include/linux/platform_data/gsc_input.h new file mode 100644 index 0000000..1a34284 --- /dev/null +++ b/include/linux/platform_data/gsc_input.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _GSC_INPUT_H +#define _GSC_INPUT_H + +/** + * struct gsc_input_button - configuration parameters + * @code: input event code (KEY_*, SW_*) + * @irq: irq index + * @desc: name of interrupt + */ +struct gsc_input_button { + unsigned int irq; + unsigned int code; + const char *desc; +}; + +/** + * struct gsc_input_platform_data - platform data for gsc_input driver + * @buttons: pointer to array of gsc_input_button structures + * describing buttons mapped to interrupt events + * @nbuttons: number of elements in @buttons array + * @name: input device name + */ +struct gsc_input_platform_data { + const struct gsc_input_button *buttons; + int nbuttons; + const char *name; +}; + +#endif