From patchwork Wed Feb 28 01:21:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Harvey X-Patchwork-Id: 10246487 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 9FFD860212 for ; Wed, 28 Feb 2018 01:23:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F6CD28B38 for ; Wed, 28 Feb 2018 01:23:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83C8B28B44; Wed, 28 Feb 2018 01:23:21 +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 C308B28B38 for ; Wed, 28 Feb 2018 01:23:20 +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=g0Pz8N0b/CKKfa06zqW4fUp/dpq8zpT2dw4OyXqvCD8=; b=MNqyTQw3vLF34TJa3DIfzWENH1 KU/8/i7XNsN8PpuGI1A94E1IAJG4M1Lso0ip1tgTME6XmJlOalHIRAVgrj4FzyheibcqGFHvcJOZf wJ/Z0NyzI4x+Cx7VzdNIPh6VcO9z2jlBsll5ybo0ifzMgf5neiPlNfyxO+Iq4jA2T7vJ/jaNFssy5 V9TtVP3xkmE3yjBtTUhOGeuZfNHMXXHCXRLUk6xfWHmgQzzTwqTjhj2E1VX7tetEZh/A1MBmP+6wd 5/5jku4yS2lOjEQx2rONVxv18lKCre9GHwYld/ur1JT6PYR/T94/1/DvNoctxFI+UP7k/o7WaMvmS xes0jUNQ==; 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 1eqqSf-0005g6-MA; Wed, 28 Feb 2018 01:23:13 +0000 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqqRQ-0004z7-0R for linux-arm-kernel@lists.infradead.org; Wed, 28 Feb 2018 01:22:01 +0000 Received: by mail-pl0-x243.google.com with SMTP id c11-v6so530540plo.0 for ; Tue, 27 Feb 2018 17:21:48 -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=AxKABqsxYuZzs5P3lZkDa/tCX1cZTCKARGbwnmLQay0=; b=io1bJoU1PT4zU/lWVa6CYBpS4njyIWqVUOwYV3FrkFPqY55PcJ/MMWnx7rVBwhb8yC foMPxw0sC0KEw/bM6YLp528yCs9jO1lLHm/ihun+UACGvszSR6uMiWIUE+6lBKrTaaak WgQYBeOdmEdNak97vHnH8eGXM492RDXoDsnVOuLk9QcKRdYEfufPCXL/J5x+Xh5ZZx7q 2Ff8UiHkBtkO03FHw9GxGHJBuMVr/2RLgT19HdKEP8l9iQv/nXirI5AZyccevy7eCKWA VcpRxJ0Eqmg72rlipVrpzCHryQ3ja98aDVQSp7wLKHrh1zVW71Xu0ZjXZKl1qEgvhisr FyDw== 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=AxKABqsxYuZzs5P3lZkDa/tCX1cZTCKARGbwnmLQay0=; b=qzU7Yc1sQ/1cfqWO+0S9C9e5XQmv2h5CoHM72WUpz3MLK82q5pisuBR+3KQmWFEUBu /qSJvHBdPDBfxkw/FVSUTnDZYdSBDg8rixcR6womQLjzd0TIYt2Ci7WfJC3rNx0BkH1L DnkA3aa6x1clZ1MocuUOFW2ZvrPzNNZMSwL0S1Ps0w7mtB7gp7QRlcLgeCl9LgrBtOwh 3ViKRiHyDgqu3yn73HoWldn9lhfxsuAENGm6ZS2upQiP0x7jwOdfje/CX5QGwEVYqNGB KB4X+o01s3pV/v5io+Tty+/TrBwCuTm7RY7lbEAHn4GWw+CwTSLTVA65SVuWHyqTedCT eFsA== X-Gm-Message-State: APf1xPAZLEboLDo+yjMrFF16qyVDgF0kBdVynvSEGa0wuoZvvAks5QDu wtZXk6oMHqZNpjqtnLs9byXjxA== X-Google-Smtp-Source: AH8x22680wNfLWnoTl3kzE7gBm6BDd1//pvwlLmLCAGRmBbQ037dA2+lSfV3FDoiPYGLvKsMAeO42A== X-Received: by 2002:a17:902:a512:: with SMTP id s18-v6mr16035805plq.296.1519780908224; Tue, 27 Feb 2018 17:21:48 -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 o82sm559297pfj.163.2018.02.27.17.21.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 17:21:47 -0800 (PST) From: Tim Harvey To: Lee Jones , Rob Herring , Mark Rutland , Mark Brown , Dmitry Torokhov Subject: [RFC 4/4] input: misc: Add Gateworks System Controller support Date: Tue, 27 Feb 2018 17:21:14 -0800 Message-Id: <1519780874-8558-5-git-send-email-tharvey@gateworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519780874-8558-1-git-send-email-tharvey@gateworks.com> References: <1519780874-8558-1-git-send-email-tharvey@gateworks.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180227_172156_138867_58B29B83 X-CRM114-Status: GOOD ( 21.04 ) 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. Signed-off-by: Tim Harvey --- drivers/input/misc/Kconfig | 6 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/gsc-input.c | 196 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 drivers/input/misc/gsc-input.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 9f082a3..3d18a0e 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -117,6 +117,12 @@ 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 + Say Y here if you want Gateworks System Controller input support. + 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..7cf217c --- /dev/null +++ b/drivers/input/misc/gsc-input.c @@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Gateworks Corporation + */ +#define DEBUG + +#include +#include +#include +#include +#include +#include + +#include + +struct gsc_irq { + unsigned int irq; + const char *name; + unsigned int virq; +}; + +static struct gsc_irq gsc_irqs[] = { + { GSC_IRQ_PB, "button" }, + { GSC_IRQ_KEY_ERASED, "key-erased" }, + { GSC_IRQ_EEPROM_WP, "eeprom-wp" }, + { GSC_IRQ_TAMPER, "tamper" }, + { GSC_IRQ_SWITCH_HOLD, "button-held" }, +}; + +struct gsc_input_info { + struct device *dev; + struct gsc_dev *gsc; + struct input_dev *input; + + int irq; + struct work_struct irq_work; + struct mutex mutex; +}; + +static void gsc_input_irq_work(struct work_struct *work) +{ + struct gsc_input_info *info = container_of(work, struct gsc_input_info, + irq_work); + struct gsc_dev *gsc = info->gsc; + int i, ret = 0; + int key, sts; + struct gsc_irq *gsc_irq = NULL; + + dev_dbg(gsc->dev, "%s irq%d\n", __func__, info->irq); + mutex_lock(&info->mutex); + + for (i = 0; i < ARRAY_SIZE(gsc_irqs);i++) + if (info->irq == gsc_irqs[i].virq) + gsc_irq = &gsc_irqs[i]; + if (!gsc_irq) { + dev_err(info->dev, "interrupt: irq%d occurred\n", info->irq); + mutex_unlock(&info->mutex); + return; + } + + ret = regmap_read(info->gsc->regmap, GSC_IRQ_STATUS, &sts); + if (ret) { + dev_err(info->dev, "failed to read status register\n"); + mutex_unlock(&info->mutex); + return; + } + + key = -1; + switch (gsc_irq->virq) { + case GSC_IRQ_PB: + key = BTN_0; + break; + case GSC_IRQ_KEY_ERASED: + key = BTN_1; + break; + case GSC_IRQ_EEPROM_WP: + key = BTN_2; + break; + case GSC_IRQ_GPIO: + key = BTN_3; + break; + case GSC_IRQ_TAMPER: + key = BTN_4; + break; + case GSC_IRQ_SWITCH_HOLD: + key = BTN_5; + break; + } + + if (key != -1) { + dev_dbg(&info->input->dev, "bit%d: key=0x%03x %s\n", + gsc_irq->virq, key, gsc_irq->name); + input_report_key(info->input, key, 1); + input_report_key(info->input, key, 0); + input_sync(info->input); + } + + mutex_unlock(&info->mutex); +} + +static irqreturn_t gsc_input_irq(int irq, void *data) +{ + struct gsc_input_info *info = data; + + dev_dbg(info->gsc->dev, "%s irq%d\n", __func__, irq); + info->irq = irq; + schedule_work(&info->irq_work); + + return IRQ_HANDLED; +} + +static int gsc_input_probe(struct platform_device *pdev) +{ + struct gsc_dev *gsc = dev_get_drvdata(pdev->dev.parent); + struct gsc_input_info *info; + struct input_dev *input; + int ret, i; + + dev_dbg(&pdev->dev, "%s\n", __func__); + info = devm_kzalloc(&pdev->dev, sizeof(struct gsc_input_info), + GFP_KERNEL); + if (!info) + return -ENOMEM; + info->dev = &pdev->dev; + info->gsc = gsc; + + /* Register input device */ + input = devm_input_allocate_device(&pdev->dev); + if (!input) { + dev_err(&pdev->dev, "Can't allocate input device\n"); + return -ENOMEM; + } + info->input = input; + + input->name = KBUILD_MODNAME; + input->dev.parent = &pdev->dev; + + input_set_capability(input, EV_KEY, BTN_0); /* button */ + input_set_capability(input, EV_KEY, BTN_1); /* key erased */ + input_set_capability(input, EV_KEY, BTN_2); /* ee wp */ + input_set_capability(input, EV_KEY, BTN_3); /* gpio */ + input_set_capability(input, EV_KEY, BTN_4); /* tamper */ + input_set_capability(input, EV_KEY, BTN_5); /* button held */ + + ret = input_register_device(input); + if (ret < 0) { + dev_err(&pdev->dev, "Can't register input device: %d\n", ret); + return ret; + } + + platform_set_drvdata(pdev, gsc); + mutex_init(&info->mutex); + INIT_WORK(&info->irq_work, gsc_input_irq_work); + + /* Support irq domain */ + for (i = 0; i < ARRAY_SIZE(gsc_irqs); i++) { + struct gsc_irq *gsc_irq = &gsc_irqs[i]; + int virq; + + virq = regmap_irq_get_virq(gsc->irq_chip_data, gsc_irq->irq); + if (virq <= 0) + return -EINVAL; + gsc_irq->virq = virq; + + ret = devm_request_threaded_irq(&pdev->dev, virq, NULL, + gsc_input_irq, 0, + gsc_irq->name, info); + if (ret) { + dev_err(&pdev->dev, + "failed: irq request (IRQ: %d, error: %d\n)", + gsc_irq->irq, 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");