From patchwork Thu Sep 6 07:59:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10589983 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 69217920 for ; Thu, 6 Sep 2018 07:59:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CA472A4B5 for ; Thu, 6 Sep 2018 07:59:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 408C02A503; Thu, 6 Sep 2018 07:59:34 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 999402A4B5 for ; Thu, 6 Sep 2018 07:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728093AbeIFMdn (ORCPT ); Thu, 6 Sep 2018 08:33:43 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:42864 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728059AbeIFMd1 (ORCPT ); Thu, 6 Sep 2018 08:33:27 -0400 Received: by mail-lj1-f194.google.com with SMTP id f1-v6so8490295ljc.9 for ; Thu, 06 Sep 2018 00:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4P//Bhy39oDN7JIcuMYrXLtTeFqfAaKbP7iuSwlqE0k=; b=JRAFOiMAMouw4bAhDl80ErHqgQvb4IxCj06DM3WyjRo5DPWYZ0SoX0fZT1QMdJ1GM+ MQ4PxmervVu1fiJzFbbvAPxIK+abXlARM4AU8rGXrkkVsTC3DnoOoUKCYm83l86bI7Hl wmswj3s+PZRq0o0toxJtxowWUAFwaVdA8cKXY= 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=4P//Bhy39oDN7JIcuMYrXLtTeFqfAaKbP7iuSwlqE0k=; b=CRxjdKF2km49q5Z4ivEXN4VOB8FTLqEfk9p7HNNZlHB8DP5MQYtxLLxnbsRZH4hqd1 o+e2XrOHZd9/bjWAAhBNCJ2b/dGaJEp43qhxM4Dc3gYik684za7uGX0FPz1vJLBMsk68 Yc31Y8Tr5zOrMB5Hy5umqr2C0RG+Sv7o/pUoUlQ6i2bVfbihgEDHFgJfHtS1Bh3fw/P6 6oci85Zus3F8Y1XMStrUyjyjB5U14UUC47zyZqmPMhnBLC99wzYCHTO/K+IeR6/XG6bg 1WReC1w5jzanA4764GgivPL/PH0e9J7+W2RBdX6bDwon+7FXkjcbpXk+dBwXKTkcMkVQ xnGQ== X-Gm-Message-State: APzg51CMDQIpKp1iaWTabBDwVqMM3X4sqZ1uno3vgtF5BS3Xn/dOrrzk Mze1T6eN+Pio4OLT+BVo1BuwxA== X-Google-Smtp-Source: ANB0VdZiJDCYfGeS+lOq/i+9S+E12S6FUlao4xdVzi3zqjMDNfO63l8fxjdhLEpXFmp8V7FG1BBu/Q== X-Received: by 2002:a2e:21d5:: with SMTP id h82-v6mr1023422lji.46.1536220753580; Thu, 06 Sep 2018 00:59:13 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id f129-v6sm690869lff.37.2018.09.06.00.59.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Sep 2018 00:59:12 -0700 (PDT) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Andy Shevchenko , "Rafael J . Wysocki" , Sakari Ailus , Linus Walleij Subject: [PATCH 1/3] gpio: fwnode: Obtains descs from machine tables Date: Thu, 6 Sep 2018 09:59:00 +0200 Message-Id: <20180906075902.31240-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180906075902.31240-1-linus.walleij@linaro.org> References: <20180906075902.31240-1-linus.walleij@linaro.org> 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 In some cases, such as the input gpio_keys code, we want to just call devm_fwnode_get_gpiod_from_child() and not worry about whether the GPIO descriptor is coming from DT or ACPI. To get rid of legacy hard-coded global GPIO numbers we also need to be able to look up GPIOs from machine GPIO descriptor tables. This patch fixes this by using machine tables as a fallback. Since the machine tables are flat and have no concept such as "children" as DT or ACPI has, we simply convert the child to an index in request order. In these few legacy use cases, only the children have GPIO descriptors assigned, the parent does not, so it should be safe to assume that we can represent the children as index 0..N of the parent "gpios" property in machine tables. As these pass the rest of the per-key configuration as an array in the struct gpio_keys_platform_data buttons array, it is natural for users to define the descriptor with an index when converting to machine GPIO descriptor tables. Since the board files have no concept of any "firmware node" we need to pass the device down from the devm_fwnode_*() calls so we can use the device name to locate the descriptor look-up tables, so we wrap fwnode_get_named_gpiod into fwnode_get_named_gpiod_dev() where current users that are DT-only or ACPI-only can pass NULL if they like. Cc: Dmitry Torokhov Cc: Andy Shevchenko Cc: Rafael J. Wysocki Cc: Sakari Ailus Signed-off-by: Linus Walleij --- drivers/gpio/devres.c | 4 +-- drivers/gpio/gpiolib.c | 47 +++++++++++++++++++++++++---------- include/linux/gpio/consumer.h | 19 +++++++++++--- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c index e82cc763633c..48464eafc670 100644 --- a/drivers/gpio/devres.c +++ b/drivers/gpio/devres.c @@ -206,8 +206,8 @@ struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, snprintf(prop_name, sizeof(prop_name), "%s", gpio_suffixes[i]); - desc = fwnode_get_named_gpiod(child, prop_name, index, flags, - label); + desc = fwnode_get_named_gpiod_dev(dev, child, prop_name, index, + flags, label); if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) break; } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e8f8a1999393..501ddcd9c86f 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3994,7 +3994,8 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, EXPORT_SYMBOL(gpiod_get_from_of_node); /** - * fwnode_get_named_gpiod - obtain a GPIO from firmware node + * fwnode_get_named_gpiod_dev - obtain a GPIO from firmware node + * @dev: corresponding device, may be NULL for DT and ACPI * @fwnode: handle of the firmware node * @propname: name of the firmware property representing the GPIO * @index: index of the GPIO to obtain for the consumer @@ -4002,7 +4003,7 @@ EXPORT_SYMBOL(gpiod_get_from_of_node); * @label: label to attach to the requested GPIO * * This function can be used for drivers that get their configuration - * from opaque firmware. + * from opaque firmware or machine descriptors in board files. * * The function properly finds the corresponding GPIO using whatever is the * underlying firmware interface and then makes sure that the GPIO @@ -4012,20 +4013,19 @@ EXPORT_SYMBOL(gpiod_get_from_of_node); * On successful request the GPIO pin is configured in accordance with * provided @dflags. * - * In case of error an ERR_PTR() is returned. + * In case of error an ERR_PTR() is returned. -ENOENT is returned if + * no GPIO descriptor can be located in DT, ACPI or board file tables. */ -struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, - const char *propname, int index, - enum gpiod_flags dflags, - const char *label) +struct gpio_desc *fwnode_get_named_gpiod_dev(struct device *dev, + struct fwnode_handle *fwnode, + const char *propname, int index, + enum gpiod_flags dflags, + const char *label) { struct gpio_desc *desc = ERR_PTR(-ENODEV); - unsigned long lflags = 0; + enum gpio_lookup_flags lflags = 0; int ret; - if (!fwnode) - return ERR_PTR(-EINVAL); - if (is_of_node(fwnode)) { desc = gpiod_get_from_of_node(to_of_node(fwnode), propname, index, @@ -4043,9 +4043,30 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, if (info.polarity == GPIO_ACTIVE_LOW) lflags |= GPIO_ACTIVE_LOW; + } else { + desc = gpiod_find(dev, propname, index, &lflags); + if (IS_ERR(desc)) + return desc; + /* + * This is a special case. This happens when you try + * to look up more than one child node from + * fwnode_get_*_from_child(): the boardfile tables + * do not have hierarchy or children, they are flat. + * To get out of this without having to reinvent a + * complex datastructure for board files, we convert + * the child to an index by simply trying the next + * descriptor index until we get something not busy + * (already requested) or -ENOENT. + */ + while (test_bit(FLAG_REQUESTED, &desc->flags)) { + index++; + desc = gpiod_find(dev, propname, index, + &lflags); + if (IS_ERR(desc)) + return desc; + } } - /* Currently only ACPI takes this path */ ret = gpiod_request(desc, label); if (ret) return ERR_PTR(ret); @@ -4058,7 +4079,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, return desc; } -EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod); +EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod_dev); /** * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 21ddbe440030..6ddb62a70f4a 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -157,10 +157,21 @@ struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, const char *propname, int index, enum gpiod_flags dflags, const char *label); -struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, - const char *propname, int index, - enum gpiod_flags dflags, - const char *label); +struct gpio_desc *fwnode_get_named_gpiod_dev(struct device *dev, + struct fwnode_handle *fwnode, + const char *propname, int index, + enum gpiod_flags dflags, + const char *label); +static inline struct gpio_desc *fwnode_get_named_gpiod( + struct fwnode_handle *fwnode, + const char *propname, int index, + enum gpiod_flags dflags, + const char *label) +{ + /* Just a wrapper calling the former for device NULL */ + return fwnode_get_named_gpiod_dev(NULL, fwnode, propname, index, + dflags, label); +} struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, const char *con_id, int index, struct fwnode_handle *child, From patchwork Thu Sep 6 07:59:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10589979 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 DC5826CB for ; Thu, 6 Sep 2018 07:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C199E2A3A5 for ; Thu, 6 Sep 2018 07:59:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4C642A4E9; Thu, 6 Sep 2018 07:59:23 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 45F2B2A4B5 for ; Thu, 6 Sep 2018 07:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728094AbeIFMdc (ORCPT ); Thu, 6 Sep 2018 08:33:32 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:34155 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728109AbeIFMdb (ORCPT ); Thu, 6 Sep 2018 08:33:31 -0400 Received: by mail-lj1-f196.google.com with SMTP id f8-v6so8546752ljk.1 for ; Thu, 06 Sep 2018 00:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=g6txyK8o4x08RKCFZhnsAtEHfb0e8GRkllRjW843LzE=; b=hVP9S6Ko2zpWExobKJOwU+ctnG8ackVNZhXfYkz/H35rBNTQtaoHKcu6ebRpRuusei y4rCKd4wqrh0akFwfSK8cACDKYVK3zIkCg4pwIPsruiTBlwBcpn2SDgz8qvHWUIhODON TIDKEcCM3MCHgvt3baOouY5u8jQu339ucix/s= 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=g6txyK8o4x08RKCFZhnsAtEHfb0e8GRkllRjW843LzE=; b=rq4RCxtFWei1zWhiWR5nUGTBqABirRRbGvs0CJH7zJF26vtBKb9ZmzRT7ut6Ac3zQ7 lNqufcemGB8uj0pOhCNgRNHFo5ApzxJpC91vjnwofOMezM5WvSpfaMAfdb9dxilvSeoj aLV/jyObbP4BZ8ohIyyUnMQLH3fzJJ5qOX5f2pvHqXOkTuMbWs8Yzm7m3jgQxGh7kCiW tKldxsvM/m40IJXNTuhm9gnyPKKYu44qmieXIBNWfVch3srDYj8PmPJ1EAgOjhxSmsVg ZbOYCTP87Kt9fUPfCAWcpbAxrTHbnxlX1dAR6IVmnAcKZzpPG0VUsxdXH3Zp01ODE8ZE bZRQ== X-Gm-Message-State: APzg51AC0Kb8DneOUGw0eGgyh3Z9o/Al5Q8QUBAf3QJXrgO3BJ2G+pFN Vl5DI5edU6GI7p8e+gdEEprV6w== X-Google-Smtp-Source: ANB0VdYGyhczQ13O7u7FS2yt5gOgN4hgg6HVw607EJq183gzKdEN5kzNgaPcEQSe808RMAF67OzrSQ== X-Received: by 2002:a2e:712:: with SMTP id 18-v6mr1074946ljh.101.1536220758595; Thu, 06 Sep 2018 00:59:18 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id f129-v6sm690869lff.37.2018.09.06.00.59.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Sep 2018 00:59:17 -0700 (PDT) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Andy Shevchenko , "Rafael J . Wysocki" , Sakari Ailus , Linus Walleij Subject: [PATCH 2/3] Input: gpio_keys - always try fwnode first Date: Thu, 6 Sep 2018 09:59:01 +0200 Message-Id: <20180906075902.31240-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180906075902.31240-1-linus.walleij@linaro.org> References: <20180906075902.31240-1-linus.walleij@linaro.org> 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 This makes the gpio_keys input driver try fwnode first when looking up GPIO descriptors, even if no fwnode was passed. With the changes to the gpiolib, if NULL us passed as fwnode, the gpiolib will attempt to look up the GPIO descriptor from the machine descriptor tables. Cc: Dmitry Torokhov Cc: Andy Shevchenko Cc: Rafael J. Wysocki Cc: Sakari Ailus Signed-off-by: Linus Walleij --- Dmitry: I'm looking for your ACK if you agree with this approach overall so I can apply this with the changes to gpiolib to the GPIO tree. --- drivers/input/keyboard/gpio_keys.c | 47 ++++++++++++++++++------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 492a971b95b5..eef2dcbc9185 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -499,25 +499,34 @@ static int gpio_keys_setup_key(struct platform_device *pdev, bdata->button = button; spin_lock_init(&bdata->lock); - if (child) { - bdata->gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL, - child, - GPIOD_IN, - desc); - if (IS_ERR(bdata->gpiod)) { - error = PTR_ERR(bdata->gpiod); - if (error == -ENOENT) { - /* - * GPIO is optional, we may be dealing with - * purely interrupt-driven setup. - */ - bdata->gpiod = NULL; - } else { - if (error != -EPROBE_DEFER) - dev_err(dev, "failed to get gpio: %d\n", - error); - return error; - } + /* + * We try this first as it will find GPIOs even from board + * files if properly done. + */ + bdata->gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL, + child, + GPIOD_IN, + desc); + /* + * If we have a valid fwnode and this lookup fails, we need + * to give up. Otherwise we try to use the GPIO from the + * platform data. + */ + if (!IS_ERR(bdata->gpiod)) { + /* All is good */ + } else if (child) { + error = PTR_ERR(bdata->gpiod); + if (error == -ENOENT) { + /* + * GPIO is optional, we may be dealing with + * purely interrupt-driven setup. + */ + bdata->gpiod = NULL; + } else { + if (error != -EPROBE_DEFER) + dev_err(dev, "failed to get gpio: %d\n", + error); + return error; } } else if (gpio_is_valid(button->gpio)) { /* From patchwork Thu Sep 6 07:59:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10589981 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 DA7E36CB for ; Thu, 6 Sep 2018 07:59:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEEB92A3A5 for ; Thu, 6 Sep 2018 07:59:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2C6E2A4E9; Thu, 6 Sep 2018 07:59:26 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 5224D2A3A5 for ; Thu, 6 Sep 2018 07:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728134AbeIFMdf (ORCPT ); Thu, 6 Sep 2018 08:33:35 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:45897 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728132AbeIFMdf (ORCPT ); Thu, 6 Sep 2018 08:33:35 -0400 Received: by mail-lj1-f194.google.com with SMTP id u83-v6so8480321lje.12 for ; Thu, 06 Sep 2018 00:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4rWgSaidxSf3WayfOVM6Uc0/KOIGkkaRLG+kNBpbt+8=; b=BTWiyIAVLKPz7OOytYqjIwPROlzbZI43HX9lN1kjn12lclV+kHCegmq7IQ21dZs7u8 fWwARusR9XbosMav4pQjOtglLVd78u/ny06q9u+nXkXhZo86sc9i10EUEs63gpV8dZeT uFisOE8Db9ngAl6FWs+pbX5g9k2C/npi+B7KQ= 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=4rWgSaidxSf3WayfOVM6Uc0/KOIGkkaRLG+kNBpbt+8=; b=Y0IJq34RfONiZ+ztRaBDpTpSiCfmhOPKeIJMDYsJ+sMWgSAWz+MfKYObAxMcZ4Dccz TdtTLLhbXYE22qOOhcH7I1lQzz+OZ/O7GoXtFxF4o0JsRlnUa9DllzRj+NgBAVHDCGow BEPxe9rDVY5caSuc9UAO83+c56RLKODePytil9K7gXw/KsW3CNz3RTYLW8gtO4pWXnK3 SCU/e/bbYi908LoXHzvTD9/XN1XS2VQVlRkHtQ4c6GYfOYDSOgNnurZHnXPU9QO51gJt 6dDuV7SIXMAa8vdYmJ76zGjSaU1c66GXqTTZlOQqk5Z3+eL5qFzD/o64eDjjAYjih6MD 0auQ== X-Gm-Message-State: APzg51CGgroPpLEEINIEsffah1vobTldpuWIIB47a8s4JayM/bA1GFGy R3yuxyO1TZH/HmsTwEM5ctA+/A== X-Google-Smtp-Source: ANB0VdbecuqwMcmTpS7IqvbnHw4lKCCp4QKgVqK46qQDxymO4O1jdxjFyINnZ1SpWasyFu0P5/daqQ== X-Received: by 2002:a2e:54b:: with SMTP id 72-v6mr1094050ljf.152.1536220762153; Thu, 06 Sep 2018 00:59:22 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id f129-v6sm690869lff.37.2018.09.06.00.59.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Sep 2018 00:59:20 -0700 (PDT) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Andy Shevchenko , "Rafael J . Wysocki" , Sakari Ailus , Linus Walleij Subject: [PATCH 3/3] RFC: ARM: simone: Hacked in keys Date: Thu, 6 Sep 2018 09:59:02 +0200 Message-Id: <20180906075902.31240-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180906075902.31240-1-linus.walleij@linaro.org> References: <20180906075902.31240-1-linus.walleij@linaro.org> 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 This serves as an illustration of how to use the gpio-keys in boardfiles with just a machine GPIO descriptor table. It is a hack for the joystick connector on the entirely boardfile-based SIM.ONE. It will probably not be applied. Cc: Dmitry Torokhov Cc: Andy Shevchenko Cc: Rafael J. Wysocki Cc: Sakari Ailus Signed-off-by: Linus Walleij --- arch/arm/mach-ep93xx/simone.c | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/arch/arm/mach-ep93xx/simone.c b/arch/arm/mach-ep93xx/simone.c index 41aa57581356..a3c3020da850 100644 --- a/arch/arm/mach-ep93xx/simone.c +++ b/arch/arm/mach-ep93xx/simone.c @@ -24,7 +24,10 @@ #include #include #include +#include #include +#include +#include #include #include @@ -34,6 +37,51 @@ #include "soc.h" +static struct gpio_keys_button simone_buttons[] = { + { + .code = KEY_ENTER, + .type = EV_KEY, + .active_low = 1, + .desc = "enter", + }, + { + .code = KEY_UP, + .type = EV_KEY, + .active_low = 1, + .desc = "up", + }, + { + .code = KEY_LEFT, + .type = EV_KEY, + .active_low = 1, + .desc = "left", + }, +}; + +static struct gpio_keys_platform_data simone_keys_pdata = { + .buttons = simone_buttons, + .nbuttons = ARRAY_SIZE(simone_buttons), + .rep = 0, +}; + +static struct gpiod_lookup_table simone_keys_gpiod_table = { + .dev_id = "gpio-keys", + .table = { + /* Use local offsets on gpiochip/port "B" */ + GPIO_LOOKUP_IDX("B", 0, "gpios", 0, GPIO_ACTIVE_LOW), + GPIO_LOOKUP_IDX("B", 1, "gpios", 1, GPIO_ACTIVE_LOW), + GPIO_LOOKUP_IDX("B", 2, "gpios", 2, GPIO_ACTIVE_LOW), + }, +}; + +static struct platform_device simone_keys_device = { + .name = "gpio-keys", + .id = -1, + .dev = { + .platform_data = &simone_keys_pdata, + }, +}; + static struct ep93xx_eth_data __initdata simone_eth_data = { .phy_id = 1, }; @@ -107,6 +155,8 @@ static void __init simone_init_machine(void) ARRAY_SIZE(simone_i2c_board_info)); ep93xx_register_spi(&simone_spi_info, simone_spi_devices, ARRAY_SIZE(simone_spi_devices)); + gpiod_add_lookup_table(&simone_keys_gpiod_table); + platform_device_register(&simone_keys_device); simone_register_audio(); }