linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>, linux-input@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
	Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH 1/5] Input: gpio-keys: Support getting descriptors from board
Date: Fri, 24 Nov 2017 10:30:41 +0100	[thread overview]
Message-ID: <20171124093045.5961-2-linus.walleij@linaro.org> (raw)
In-Reply-To: <20171124093045.5961-1-linus.walleij@linaro.org>

There are any number of board files in the kernel providing
keys/pushbuttons/switches using simple GPIO. In order to
transfer these smoothly to use GPIO descriptors with
descriptor tables in the board files and no static GPIO
numbers, we need to accept that the board files provide
named GPIOs associated with the GPIO chip device.

Luckily gpio_keys of both polled and interrupt-enabled
type will optionally pass a "desc" field which we can use
as the name of the GPIO to look up and request a GPIO
line for a certain key defined in a per-board descriptor
lookup table.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/input/keyboard/gpio_keys.c        | 14 +++++++++++++-
 drivers/input/keyboard/gpio_keys_polled.c | 10 ++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 87e613dc33b8..420262a4fd54 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -520,7 +520,9 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
 	} else if (gpio_is_valid(button->gpio)) {
 		/*
 		 * Legacy GPIO number, so request the GPIO here and
-		 * convert it to descriptor.
+		 * convert it to descriptor. This code goes away once
+		 * we convert all old board files to provide descriptor
+		 * tables.
 		 */
 		unsigned flags = GPIOF_IN;
 
@@ -537,6 +539,16 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
 		bdata->gpiod = gpio_to_desc(button->gpio);
 		if (!bdata->gpiod)
 			return -EINVAL;
+	} else {
+		/*
+		 * Try to look up from the descriptor table, includes
+		 * letting gpiolib handle inversion semantics. This is
+		 * optional since we have interrupt-only keys as well.
+		 */
+		bdata->gpiod = devm_gpiod_get_optional(dev, desc,
+						       GPIOD_IN);
+		if (IS_ERR(bdata->gpiod))
+			return PTR_ERR(bdata->gpiod);
 	}
 
 	if (bdata->gpiod) {
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
index edc7262103b9..1bc428a7edea 100644
--- a/drivers/input/keyboard/gpio_keys_polled.c
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -342,6 +342,16 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
 					button->gpio);
 				return -EINVAL;
 			}
+		} else {
+			/*
+			 * Try to look up from the descriptor table, includes
+			 * letting gpiolib handle inversion semantics.
+			 */
+			bdata->gpiod = devm_gpiod_get_optional(dev,
+							       button->desc,
+							       GPIOD_IN);
+			if (IS_ERR(bdata->gpiod))
+				return PTR_ERR(bdata->gpiod);
 		}
 
 		bdata->last_state = -1;
-- 
2.14.3


  reply	other threads:[~2017-11-24  9:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-24  9:30 [PATCH 0/5] Make gpio_keys accept board descriptors Linus Walleij
2017-11-24  9:30 ` Linus Walleij [this message]
2017-11-24  9:30 ` [PATCH 2/5] gpio: pca953x: Name the gpiochip after the I2C address Linus Walleij
2017-11-24 14:26   ` Andrew Lunn
2017-11-30 14:45     ` Linus Walleij
2017-11-24  9:30 ` [PATCH 3/5] ARM: davinci: Switch DA850EVM to use GPIO descriptors Linus Walleij
2017-11-24  9:30 ` [PATCH 4/5] ARM: imx: Give all GPIO chips a unique name Linus Walleij
2017-11-24  9:30 ` [PATCH 5/5] ARM: imx: Use GPIO descriptors for gpio_keys Linus Walleij
2017-11-25 23:33 ` [PATCH 0/5] Make gpio_keys accept board descriptors Dmitry Torokhov
2017-11-30 15:44   ` Linus Walleij
2020-08-26 13:20   ` Linus Walleij
2020-08-26 14:35     ` Heikki Krogerus
2020-08-26 16:12       ` Dmitry Torokhov
2020-08-26 23:31         ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171124093045.5961-2-linus.walleij@linaro.org \
    --to=linus.walleij@linaro.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).