From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/2] led-gpio: use gpio_request and gpio_free
Date: Wed, 26 Dec 2012 17:33:56 +0100 [thread overview]
Message-ID: <1356539636-12782-2-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1356539636-12782-1-git-send-email-plagnioj@jcrosoft.com>
So we can ensure a gpio is not used for something else
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
drivers/led/led-gpio.c | 67 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 63 insertions(+), 4 deletions(-)
diff --git a/drivers/led/led-gpio.c b/drivers/led/led-gpio.c
index c78ef9e..08dc9ba 100644
--- a/drivers/led/led-gpio.c
+++ b/drivers/led/led-gpio.c
@@ -19,7 +19,7 @@
*/
#include <common.h>
#include <led.h>
-#include <asm/gpio.h>
+#include <gpio.h>
static void led_gpio_set(struct led *led, unsigned int value)
{
@@ -37,10 +37,21 @@ static void led_gpio_set(struct led *led, unsigned int value)
*/
int led_gpio_register(struct gpio_led *led)
{
+ int ret;
+ char *name = led->led.name;
+
+ ret = gpio_request(led->gpio, name ? name : "led");
+ if (ret)
+ return ret;
+
led->led.set = led_gpio_set;
led->led.max_value = 1;
- return led_register(&led->led);
+ ret = led_register(&led->led);
+ if (ret)
+ gpio_free(led->gpio);
+
+ return ret;
}
/**
@@ -83,10 +94,31 @@ static void led_gpio_bicolor_set(struct led *led, unsigned int value)
*/
int led_gpio_bicolor_register(struct gpio_bicolor_led *led)
{
+ int ret;
+ char *name = led->led.name;
+
+ ret = gpio_request(led->gpio_c0, name ? name : "led_c0");
+ if (ret)
+ return ret;
+
+ ret = gpio_request(led->gpio_c1, name ? name : "led_c1");
+ if (ret)
+ goto err_gpio_c0;
+
led->led.set = led_gpio_bicolor_set;
led->led.max_value = 2;
- return led_register(&led->led);
+ ret = led_register(&led->led);
+ if (ret)
+ goto err_gpio_c1;
+
+ return 0;
+
+err_gpio_c1:
+ gpio_free(led->gpio_c1);
+err_gpio_c0:
+ gpio_free(led->gpio_c0);
+ return ret;
}
/**
@@ -120,10 +152,37 @@ static void led_gpio_rgb_set(struct led *led, unsigned int value)
*/
int led_gpio_rgb_register(struct gpio_rgb_led *led)
{
+ int ret;
+ char *name = led->led.name;
+
+ ret = gpio_request(led->gpio_r, name ? name : "led_r");
+ if (ret)
+ return ret;
+
+ ret = gpio_request(led->gpio_g, name ? name : "led_g");
+ if (ret)
+ goto err_gpio_r;
+
+ ret = gpio_request(led->gpio_b, name ? name : "led_b");
+ if (ret)
+ goto err_gpio_g;
+
led->led.set = led_gpio_rgb_set;
led->led.max_value = 7;
- return led_register(&led->led);
+ ret = led_register(&led->led);
+ if (ret)
+ goto err_gpio_b;
+
+ return 0;
+
+err_gpio_b:
+ gpio_free(led->gpio_b);
+err_gpio_g:
+ gpio_free(led->gpio_g);
+err_gpio_r:
+ gpio_free(led->gpio_r);
+ return ret;
}
/**
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-12-26 16:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-26 16:33 [PATCH 1/2] at91sam9x5ek: switch heartbeat to d2 (pioD21) Jean-Christophe PLAGNIOL-VILLARD
2012-12-26 16:33 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-01-02 10:06 ` Sascha Hauer
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=1356539636-12782-2-git-send-email-plagnioj@jcrosoft.com \
--to=plagnioj@jcrosoft.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