All of lore.kernel.org
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@ingics.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Ray Jui <rjui@broadcom.com>, Alexandre Courbot <gnurou@gmail.com>,
	bcm-kernel-feedback-list@broadcom.com,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>
Subject: [RFT][PATCH 1/2] gpio: bcm-kona: Return error if requesting an already taken gpio
Date: Fri, 10 Apr 2015 09:28:45 +0800	[thread overview]
Message-ID: <1428629325.5384.1.camel@phoenix> (raw)

If a gpio is already taken, .gpio_request should return error.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/gpio/gpio-bcm-kona.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c
index b164ce8..632352d 100644
--- a/drivers/gpio/gpio-bcm-kona.c
+++ b/drivers/gpio/gpio-bcm-kona.c
@@ -106,7 +106,7 @@ static void bcm_kona_gpio_lock_gpio(struct bcm_kona_gpio *kona_gpio,
 	spin_unlock_irqrestore(&kona_gpio->lock, flags);
 }
 
-static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
+static int bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
 					unsigned gpio)
 {
 	u32 val;
@@ -116,10 +116,17 @@ static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
 	spin_lock_irqsave(&kona_gpio->lock, flags);
 
 	val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id));
+	if (!(val & BIT(gpio))) {
+		spin_unlock_irqrestore(&kona_gpio->lock, flags);
+		return -EBUSY;
+	}
+
 	val &= ~BIT(gpio);
 	bcm_kona_gpio_write_lock_regs(kona_gpio->reg_base, bank_id, val);
 
 	spin_unlock_irqrestore(&kona_gpio->lock, flags);
+
+	return 0;
 }
 
 static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value)
@@ -185,8 +192,7 @@ static int bcm_kona_gpio_request(struct gpio_chip *chip, unsigned gpio)
 {
 	struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip);
 
-	bcm_kona_gpio_unlock_gpio(kona_gpio, gpio);
-	return 0;
+	return bcm_kona_gpio_unlock_gpio(kona_gpio, gpio);
 }
 
 static void bcm_kona_gpio_free(struct gpio_chip *chip, unsigned gpio)
-- 
1.9.1




             reply	other threads:[~2015-04-10  1:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-10  1:28 Axel Lin [this message]
2015-04-10  1:30 ` [RFT][PATCH 2/2] gpio: bcm-kona: Implement get_direction callback Axel Lin
2015-04-10 16:13   ` Ray Jui
2015-04-10 23:13     ` Axel Lin
2015-04-13  4:15       ` Ray Jui
2015-04-10 16:05 ` [RFT][PATCH 1/2] gpio: bcm-kona: Return error if requesting an already taken gpio Ray Jui
2015-04-10 23:01   ` Axel Lin

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=1428629325.5384.1.camel@phoenix \
    --to=axel.lin@ingics.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=gnurou@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=rjui@broadcom.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 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.