mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH v3 2/4] gpiolib: add gpio_request_{in,out}put support
Date: Fri,  1 Feb 2013 22:22:19 +0400	[thread overview]
Message-ID: <1359742941-30516-3-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1359742941-30516-1-git-send-email-antonynpavlov@gmail.com>

gpio_request() followed by gpio_direction_{in,out}put
is a gpio usage pattern (e.g. the similar functions
are used in a ARM boards code).

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 drivers/gpio/gpio.c |   40 ++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   13 +++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/drivers/gpio/gpio.c b/drivers/gpio/gpio.c
index d37f5a0..c0c66ae 100644
--- a/drivers/gpio/gpio.c
+++ b/drivers/gpio/gpio.c
@@ -47,6 +47,46 @@ int gpio_request(unsigned gpio, const char *label)
 	return 0;
 }
 
+int gpio_request_input(unsigned gpio, const char *label)
+{
+	int ret;
+
+	ret = gpio_request(gpio, label);
+	if (ret) {
+		pr_err("can't request gpio %d as %s (%d)\n",
+			gpio, label, ret);
+		return ret;
+	}
+
+	ret = gpio_direction_input(gpio);
+	if (ret) {
+		pr_err("can't configure gpio %d (%s) as input (%d)\n",
+			gpio, label, ret);
+	}
+
+	return ret;
+}
+
+int gpio_request_output(unsigned gpio, const char *label, int value)
+{
+	int ret;
+
+	ret = gpio_request(gpio, label);
+	if (ret) {
+		pr_err("can't request gpio %d as %s (%d)\n",
+			gpio, label, ret);
+		return ret;
+	}
+
+	ret = gpio_direction_output(gpio, value);
+	if (ret) {
+		pr_err("can't configure gpio %d (%s) as output (%d)\n",
+			gpio, label, ret);
+	}
+
+	return ret;
+}
+
 void gpio_free(unsigned gpio)
 {
 	struct gpio_info *gi = &gpio_desc[gpio];
diff --git a/include/gpio.h b/include/gpio.h
index 794d959..309c1c5 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -9,11 +9,24 @@ static inline int gpio_request(unsigned gpio, const char *label)
 	return 0;
 }
 
+static inline int gpio_request_input(unsigned gpio, const char *label)
+{
+	return 0;
+}
+
+static inline int gpio_request_output(unsigned gpio, const char *label,
+		int value)
+{
+	return 0;
+}
+
 static inline void gpio_free(unsigned gpio)
 {
 }
 #else
 int gpio_request(unsigned gpio, const char *label);
+int gpio_request_input(unsigned gpio, const char *label);
+int gpio_request_output(unsigned gpio, const char *label, int value);
 void gpio_free(unsigned gpio);
 #endif
 
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2013-02-01 18:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-01 18:22 [PATCH v3 0/4] " Antony Pavlov
2013-02-01 18:22 ` [PATCH v3 1/4] gpiolib: fix whitespaces Antony Pavlov
2013-02-01 18:22 ` Antony Pavlov [this message]
2013-02-01 18:26   ` [PATCH v3 2/4] gpiolib: add gpio_request_{in,out}put support Jean-Christophe PLAGNIOL-VILLARD
2013-02-01 19:23     ` Antony Pavlov
2013-02-01 18:22 ` [PATCH v3 3/4] at91sam9*: use gpio_request_output() Antony Pavlov
2013-02-01 18:22 ` [PATCH v3 4/4] animeo_ip: use gpio_request_input() Antony Pavlov

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=1359742941-30516-3-git-send-email-antonynpavlov@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.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