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: 146071 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp194928ljw; Thu, 6 Sep 2018 00:59:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYt5cQXhdQ15aHq+llxq1O6rZMwEcfgkd00CYz5Oup0WWA38mtMzYhTpS232wGqZ/hsLWDX X-Received: by 2002:a17:902:f096:: with SMTP id go22mr1504862plb.183.1536220773461; Thu, 06 Sep 2018 00:59:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536220773; cv=none; d=google.com; s=arc-20160816; b=dEa0fofgBdPBbSavIJsMIsuIqXzDWTvmdPABphAtyk+OHAMLLQgPiTkfkZ02IwdOwc X052HF0maoIMYyLct7k4V1XVM/w205teEppbFbwu+4118OuJLxqVn6Y79MsEAmM0C+mw jgOph7HWQYsF0PeLGFwLQWX6jEHvTs/vaTdOppEvRa04oRNAWtS7Cg5Snyb1kbZswOXK VzzT5hBQaG66J9tnglmQz7FqM4M6qBlXaPgN7Woh4qCAbib2PclDHfxun9fbXh8oJ6Yf t8pwatKVviUyUbd/jh6uWG+ek6mQPeCd4DcDNgvN2Zhs6Aws7GDsLCNGNv262DjlVCcW yt6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=4P//Bhy39oDN7JIcuMYrXLtTeFqfAaKbP7iuSwlqE0k=; b=KY93pnoj+NCisCR/0ntYepxMOUxWpey6y7cpq9DScnt+UDknggV9pHPa3N4mdUyGE2 kIC1MSaucQlc6gRXDHj3M9QPl4K+O7YuxOhxqUAIxd1w8B+WnnCpZ1tjdD5m4WWUZW3b CmqFi+dMVR0VGGhJDhuY2W9BhBQVTyUq4VrQD2niLlg3xucyjkpR9N/EaJKNN1dvUykx ho6AmAs0GiWPlI3cwmIMvGXdJimT1hNiNlKDgoSqE43a7avAW4MMcQmv0R9N3DR6ETwn mRhLp69nlk+s4sfj+Gjr+D6b+k4Mu0f9JTrS3lEXknuFTpHNORH/0T+MtD8oCh7mdBz8 vOwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JRAFOiMA; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20-v6si4596262pgj.535.2018.09.06.00.59.33; Thu, 06 Sep 2018 00:59:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JRAFOiMA; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728018AbeIFMd1 (ORCPT + 5 others); Thu, 6 Sep 2018 08:33:27 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:37946 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728056AbeIFMd1 (ORCPT ); Thu, 6 Sep 2018 08:33:27 -0400 Received: by mail-lj1-f196.google.com with SMTP id p6-v6so8531871ljc.5 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=pPozCuqQZnO92EGxqWmq8Bfk1oJIOPy+L1YDLRWp3+1AN0kv59LDsg46qbIjTBAOXd HRGelsE0pusLBsahJ7mzOcN/+fODZqBUxZTNpij9xiPK0+aIWrY9YjzpJkfvKgZX9K8f iTZFCs8mbcS7v8GlzWmZg0Mt9smiqUCCEWe2rz8llJu5xSSl2hLH9rfXUfHOh52piH3g YT/9WKIe/cyxLOPiT83aUtFyFQrQCZIRhDM39sCJ0lA42mEc0Y3GUeia5+TChQt3GWsx C2ESSc+N4E/gk0zIBUPcyh8QT84wOqN6x3iyKhTb8qPBo3eNuen7DIq1Rlbf04szmuSE ddBg== X-Gm-Message-State: APzg51A/dQwunJzdtB2A4uQhfjIjWpY31bL1WRv4xKYT0t3q0uxlEGBE s6Kae0W5vTtDIt8Eeel1OmrOmw== 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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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(-) -- 2.17.1 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: 146069 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp194811ljw; Thu, 6 Sep 2018 00:59:23 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaeR0Dw8+204fv/LcHeJo9OqIfjG6HRiY1Thh9jvNh7cwYCT1Y2/McdqaTornay6sVxSws+ X-Received: by 2002:a63:4306:: with SMTP id q6-v6mr1527821pga.181.1536220762919; Thu, 06 Sep 2018 00:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536220762; cv=none; d=google.com; s=arc-20160816; b=h/CNlHftV2/J00C6mL1LuVHp7Li2c7wx+amdFRz3Mtedb7rJSkuBY5X8a6sIXBb2pr lwLT3xCftiotcIPEunBrr8grnyRqb0cYFfFBE8Fmj1MwN780nXRhXLeLUOVg3tFJf3xe FfVHt2fU9UEKwTuuYRBZayPrOoeyBKOUynDMNVSzTFfO0EDQVUJ+0Koda+wiRVaWDW+V nJw3w6e6bfeFYrGf3/MsIm7XGxpgbaTE7hmz6rZ6VHiG/I0gW62ycla2a6CPbxACwP65 c3WOsUrpmDbUKHTj0OYcLPrx9uEyIzphoAszkOYrGWgEisZP1vHhATtctAxW0HekL0t8 OnLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=g6txyK8o4x08RKCFZhnsAtEHfb0e8GRkllRjW843LzE=; b=IrbEIgYGQCJidoJy9oAyL6eYCetatFYyAX+zbtEpsI3okk3IqNmaxKXZhIxoSBt9xw fELKLIDJuv2U4dOk65Duby0ROmJWmjyq/ABkfZyMawt33JsBFjWqnZd+z9jTHgc2g7KM ww9Ysk6jwdGUPzE7CaNQ53cYmmnckV7GbtSYxuZU4QDI8xn01svYCvtpzohK2OdDSdWw MdiOuOlQCt4EeSoFBGGwK3u/EDXSPHIeRHmHvavjnKielx7066aR6sNod8xfybo5q21S 5v7CU13ex+7DOpRMsBAxUNH7Dl8PjFUwwSW4khSyiYw0oCwiqIsCOmMOFVex72IDqjiy CoLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hVP9S6Ko; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e125-v6si4343914pgc.424.2018.09.06.00.59.22; Thu, 06 Sep 2018 00:59:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hVP9S6Ko; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728109AbeIFMdc (ORCPT + 5 others); Thu, 6 Sep 2018 08:33:32 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39627 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728103AbeIFMdb (ORCPT ); Thu, 6 Sep 2018 08:33:31 -0400 Received: by mail-lj1-f196.google.com with SMTP id l15-v6so8507711lji.6 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=Dg1xFWqk7oHLQ/HQG8LHK2XXNILSOkCzjmkjoz8OfpzXPe8chJ8rf4sZEgw+W8C9eX olFHB0YRrm9IsBoEQ3LBk9qfyDfwwDfmsxQ2r9c6I7MdP0W03csg6iLgiq4TKvZ03uZ3 Q23BXHmLx5DapB+pqN5UpMEVn9V4WPyLJHNkgJ7SsSglQE/sSlx0y4S9sQqJLKH/nr3Q gx+iJk+oxs1uB6Vo9c1Xbae1F25kdAsjTvhJ+DZbNyPaQTwz9dPBrrW/giL3fKFq+ohz d8jEjpLmlGxM1W5UE428kjHGQeIazLXmXnfFwbKs4HSc/nG3DaNHGcOREWavMkdCx6QJ 3YcA== X-Gm-Message-State: APzg51Aa0L+C2PIyxiYCrtRDeR1ENSha8aF2fVdXls6Jb8rwq070wvWl TycYF27x1haIlwM4lrSsOhzeig== 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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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(-) -- 2.17.1 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: 146070 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp194842ljw; Thu, 6 Sep 2018 00:59:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaNpRJTQWTxgah1V4ojR7sWsFnXqVSTkkEnp8iDVleSkTdYA9VjeD3BazAlhgLLSRz+RUZW X-Received: by 2002:a63:df04:: with SMTP id u4-v6mr1560661pgg.434.1536220766195; Thu, 06 Sep 2018 00:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536220766; cv=none; d=google.com; s=arc-20160816; b=WR3RbB1rQ9Rux6Kt/UpuyFpiRDKRlfxxEq3dRBeE+2yF79Nh2dv1p97pVTefav+dpi mMN6fMEkpdrJAxzx09KXJijBHkUNVsQ69k7LiCaqw2zapb7xWjgqbX+q8Edkv8c4MfmJ GNT9Ev+RhtBmdeRo1EI7zRvnq1jg/3ddT1936bOEHhtlqFfNIRGDG+C2fyoIFRSD7YjG je3akYTellW88cixgrSb+K78ZbaUqaFhRDfgGmMjD7A6mEVmk6joj+H9tKj3SDm5da6H dEqrNMfCfIqOqoPd3ZakmA9lchdd2c5pnJnaRr7i2e3Ya1RLmImY7eucFd/PHpugvNJr 5pwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=4rWgSaidxSf3WayfOVM6Uc0/KOIGkkaRLG+kNBpbt+8=; b=J3A63c9/pQ4LNCaFn3fEvuQ8FAcPvuet2RHkNnrJ7TVDb0NXig4DMNs0H/kWBCf1CW Zzb6+xOYujYnpkjoCT9UYD7MNdwpwohPyrxsH98YFntUFStec+rDBSflag+L3Tg0SGnP lYwvj4N3tktdMQzTfkkS1+XnbYDCAzHkYYdwdalaL4TnvGmkIlBwpNf43XCGdclgud7f Ze4P0uBwmXkx1ScJm2ZN+6QN3Z5p6HMTmtuUYtS2w3nW12MWNnoTtaAmpIeR6pmpz8L+ 9Cd1pIyGBtfQQ4wN3SUNOynyt6LITOFXEQ1Rt4X4jDJIKQ9EwFtERK7E5IXRq9nX4GI3 xXeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BTWiyIAV; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20-v6si4596262pgj.535.2018.09.06.00.59.25; Thu, 06 Sep 2018 00:59:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BTWiyIAV; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728133AbeIFMdf (ORCPT + 5 others); Thu, 6 Sep 2018 08:33:35 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:43660 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728099AbeIFMdf (ORCPT ); Thu, 6 Sep 2018 08:33:35 -0400 Received: by mail-lj1-f193.google.com with SMTP id m84-v6so8481124lje.10 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=rGceKQPCW7GDGB0oKoCxX2iUcTJ1gG/VCxd4zj+UbPezdsL8b2NCBMZxPiqmM88i6J A++LQXhoebPNv/JrTtQRsCICTwPU+I97BMqTYKWa9SBFS8H34jp8rKQ2vz2fVNogV83g GoSx6ijnWiZKtuCI0dJaVGQwKlpv8LNL7Bl4GnnDmLGqQF10Lixr3vUFHOCB533EB11U rsU8Y84wDRooZiKjq5EMI/MnsaaOX98GFIUak97KlYuCyUi1oqj52SP2XrFnOvQq040a kHgZLGagaF9ZtRrHIkUArZ3a8bdKSrSuqSAKz9a9YJs01HJmLak1lGGPPJ+Xr9mbrRKo WBCw== X-Gm-Message-State: APzg51BRERc3fhWU0+ncyFnEFgQtc7bzIkVL4MiLzVDuGaokEKaURKt0 FkNnjQ6RhbLJcYouEbqKI3SPcw== 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-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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(+) -- 2.17.1 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(); }