linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Valerio Riedel <hvr@gnu.org>
To: linux-input@vger.kernel.org
Cc: Paul Sokolovsky <pmiscml@gmail.com>,
	Philipp Zabel <philipp.zabel@gmail.com>,
	Dmitry Torokhov <dtor@mail.ru>, Philip Blundell <philb@gnu.org>
Subject: [PATCH,RFC] Input: gpio-keys - request and configure GPIOs
Date: Fri, 16 Nov 2007 12:33:50 +0100	[thread overview]
Message-ID: <1195212830-9137-1-git-send-email-hvr@gnu.org> (raw)

Currently, gpio_keys.c assumes the GPIOs to be already properly configured;
this patch changes gpio-keys to perform explicit calls to gpio_request() and
gpio_configure_input().

This matches the behaviour of leds-gpio.

Cc: Paul Sokolovsky <pmiscml@gmail.com>
Cc: Philipp Zabel <philipp.zabel@gmail.com>
Cc: Dmitry Torokhov <dtor@mail.ru>
Cc: Philip Blundell <philb@gnu.org>
---
btw, I'm unsure whether the '?:' operator is allowed in kernel source;
but since I found quite a bit of occurences throughout the kernel source
(including gpio_keys.c), I assume it's tolerated... :-)

 drivers/input/keyboard/gpio_keys.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 3eddf52..445265c 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -75,9 +75,26 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 	for (i = 0; i < pdata->nbuttons; i++) {
 		struct gpio_keys_button *button = &pdata->buttons[i];
-		int irq = gpio_to_irq(button->gpio);
+		int irq;
 		unsigned int type = button->type ?: EV_KEY;
 
+		error = gpio_request(button->gpio, button->desc ?: "gpio_keys");
+		if (error < 0) {
+			pr_err("gpio-keys: failed to request GPIO %d,"
+				" error %d\n", button->gpio, error);
+			goto fail;
+		}
+
+		error = gpio_direction_input(button->gpio);
+		if (error < 0) {
+			pr_err("gpio-keys: failed to configure input"
+				" direction for GPIO %d, error %d\n",
+				button->gpio, error);
+			gpio_free(button->gpio);
+			goto fail;
+		}
+
+		irq = gpio_to_irq(button->gpio);
 		if (irq < 0) {
 			error = irq;
 			printk(KERN_ERR
@@ -85,6 +102,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 				"Unable to get irq number for GPIO %d,"
 				"error %d\n",
 				button->gpio, error);
+			gpio_free(button->gpio);
 			goto fail;
 		}
 
@@ -97,6 +115,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 			printk(KERN_ERR
 				"gpio-keys: Unable to claim irq %d; error %d\n",
 				irq, error);
+			gpio_free(button->gpio);
 			goto fail;
 		}
 
@@ -119,8 +138,10 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	return 0;
 
  fail:
-	while (--i >= 0)
+	while (--i >= 0) {
 		free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev);
+		gpio_free(pdata->buttons[i].gpio);
+	}
 
 	platform_set_drvdata(pdev, NULL);
 	input_free_device(input);
@@ -139,6 +160,7 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
 	for (i = 0; i < pdata->nbuttons; i++) {
 		int irq = gpio_to_irq(pdata->buttons[i].gpio);
 		free_irq(irq, pdev);
+		gpio_free(pdata->buttons[i].gpio);
 	}
 
 	input_unregister_device(input);
-- 
1.5.3.4


             reply	other threads:[~2007-11-16 11:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-16 11:33 Herbert Valerio Riedel [this message]
2007-11-16 11:50 ` [PATCH,RFC] Input: gpio-keys - request and configure GPIOs Herbert Valerio Riedel
2007-11-16 13:38 ` Dmitry Torokhov
2007-11-16 14:02   ` pHilipp Zabel
2007-11-16 14:15     ` Herbert Valerio Riedel
2007-11-16 14:09   ` Herbert Valerio Riedel
2007-11-16 14:19     ` pHilipp Zabel
2007-11-21 17:13       ` Herbert Valerio Riedel
2007-11-21 19:44         ` Dmitry Torokhov

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=1195212830-9137-1-git-send-email-hvr@gnu.org \
    --to=hvr@gnu.org \
    --cc=dtor@mail.ru \
    --cc=linux-input@vger.kernel.org \
    --cc=philb@gnu.org \
    --cc=philipp.zabel@gmail.com \
    --cc=pmiscml@gmail.com \
    /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).