All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Dooks <ben@simtec.co.uk>
To: linux-input@vger.kernel.org
Cc: Simtec Linux Team <linux@simtec.co.uk>
Subject: [patch 3/3] gpio_keys: seperate individual button setup to make code neater
Date: Tue, 10 Nov 2009 22:59:40 +0000	[thread overview]
Message-ID: <20091110230002.856861720@fluff.org.uk> (raw)
In-Reply-To: 20091110225937.922379610@fluff.org.uk

[-- Attachment #1: simtec/ready/gpio-buttons-make-probe-neater.patch --]
[-- Type: text/plain, Size: 3656 bytes --]

Move the code that deals with setting up each individual button out into
a new function to reduce the indentation and allow us to common up some
of the error recovery code.

Signed-off-by: Ben Dooks <ben@simtec.co.uk>
Signed-off-by: Simtec Linux Team <linux@simtec.co.uk>

---
 drivers/input/keyboard/gpio_keys.c |   93 +++++++++++++++++++++----------------
 1 file changed, 53 insertions(+), 40 deletions(-)

Index: b/drivers/input/keyboard/gpio_keys.c
===================================================================
--- a/drivers/input/keyboard/gpio_keys.c	2009-11-09 16:48:27.000000000 +0000
+++ b/drivers/input/keyboard/gpio_keys.c	2009-11-09 16:49:06.000000000 +0000
@@ -73,6 +73,57 @@ static irqreturn_t gpio_keys_isr(int irq
 	return IRQ_HANDLED;
 }
 
+static int __devinit gpio_keys_setup_key(struct device *dev,
+					 struct gpio_button_data *bdata,
+					 struct gpio_keys_button *button)
+{
+	char *desc = button->desc ? button->desc : "gpio_keys";
+	int irq, error;
+
+	setup_timer(&bdata->timer, gpio_keys_timer, (unsigned long)bdata);
+	INIT_WORK(&bdata->work, gpio_keys_report_event);
+
+	error = gpio_request(button->gpio, desc);
+	if (error < 0) {
+		dev_err(dev, "failed to request GPIO %d, error %d\n",
+			button->gpio, error);
+		goto fail2;
+	}
+
+	error = gpio_direction_input(button->gpio);
+	if (error < 0) {
+		dev_err(dev, "failed to configure"
+			" direction for GPIO %d, error %d\n",
+			button->gpio, error);
+		goto fail3;
+	}
+
+	irq = gpio_to_irq(button->gpio);
+	if (irq < 0) {
+		error = irq;
+		dev_err(dev, "Unable to get irq number for GPIO %d, error %d\n",
+			button->gpio, error);
+		goto fail3;
+	}
+
+	error = request_irq(irq, gpio_keys_isr,
+			    IRQF_SHARED |
+			    IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+			    desc, bdata);
+	if (error) {
+		dev_err(dev, "Unable to claim irq %d; error %d\n",
+			irq, error);
+		goto fail3;
+	}
+
+	return 0;
+
+fail3:
+	gpio_free(button->gpio);
+fail2:
+	return error;
+}
+
 static int __devinit gpio_keys_probe(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
@@ -112,52 +163,14 @@ static int __devinit gpio_keys_probe(str
 	for (i = 0; i < pdata->nbuttons; i++) {
 		struct gpio_keys_button *button = &pdata->buttons[i];
 		struct gpio_button_data *bdata = &ddata->data[i];
-		int irq;
 		unsigned int type = button->type ?: EV_KEY;
 
 		bdata->input = input;
 		bdata->button = button;
-		setup_timer(&bdata->timer,
-			    gpio_keys_timer, (unsigned long)bdata);
-		INIT_WORK(&bdata->work, gpio_keys_report_event);
-
-		error = gpio_request(button->gpio, button->desc ?: "gpio_keys");
-		if (error < 0) {
-			dev_err(dev, "failed to request GPIO %d, error %d\n",
-				button->gpio, error);
-			goto fail2;
-		}
-
-		error = gpio_direction_input(button->gpio);
-		if (error < 0) {
-			dev_err(dev, "failed to configure"
-				" direction for GPIO %d, error %d\n",
-				button->gpio, error);
-			gpio_free(button->gpio);
-			goto fail2;
-		}
 
-		irq = gpio_to_irq(button->gpio);
-		if (irq < 0) {
-			error = irq;
-			dev_err(dev, "Unable to get irq number "
-				"for GPIO %d, error %d\n",
-				button->gpio, error);
-			gpio_free(button->gpio);
+		error = gpio_keys_setup_key(dev, bdata, button);
+		if (error)
 			goto fail2;
-		}
-
-		error = request_irq(irq, gpio_keys_isr,
-				    IRQF_SHARED |
-				    IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
-				    button->desc ? button->desc : "gpio_keys",
-				    bdata);
-		if (error) {
-			dev_err(dev, "Unable to claim irq %d; error %d\n",
-				irq, error);
-			gpio_free(button->gpio);
-			goto fail2;
-		}
 
 		if (button->wakeup)
 			wakeup = 1;


  parent reply	other threads:[~2009-11-10 22:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-10 22:59 [patch 0/3] gpio_keys driver updates Ben Dooks
2009-11-10 22:59 ` [patch 1/3] gpio_keys: use dev_ macros to report information Ben Dooks
2009-11-10 22:59 ` [patch 2/3] gpio_keys: use <linux/gpio.h> instead of <asm/gpio.h> Ben Dooks
2009-11-10 22:59 ` Ben Dooks [this message]
2009-11-11  5:08 ` [patch 0/3] gpio_keys driver updates 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=20091110230002.856861720@fluff.org.uk \
    --to=ben@simtec.co.uk \
    --cc=linux-input@vger.kernel.org \
    --cc=linux@simtec.co.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.