summaryrefslogtreecommitdiffstats
path: root/drivers/led
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-11-16 21:17:23 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2012-11-19 11:25:55 +0100
commit06e641353e8304c033c05de95da64af5656b2ec2 (patch)
treee9a1605055d51e7814435c7a200254b4852e927c /drivers/led
parentcc37eb4a4de76a5f5f26613b73e83edf56b8ef1f (diff)
downloadbarebox-06e641353e8304c033c05de95da64af5656b2ec2.tar.gz
barebox-06e641353e8304c033c05de95da64af5656b2ec2.tar.xz
led-gpio: add bicolor led support
those led can have 2 colors but one at a time otherwise they are black Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/led')
-rw-r--r--drivers/led/Kconfig4
-rw-r--r--drivers/led/led-gpio.c47
2 files changed, 51 insertions, 0 deletions
diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
index 106093b722..8ca6ab8e44 100644
--- a/drivers/led/Kconfig
+++ b/drivers/led/Kconfig
@@ -11,6 +11,10 @@ config LED_GPIO_RGB
bool "gpio rgb LED support"
depends on LED_GPIO
+config LED_GPIO_BICOLOR
+ bool "gpio bicolor LED support"
+ depends on LED_GPIO
+
config LED_TRIGGERS
select POLLER
bool "LED triggers support"
diff --git a/drivers/led/led-gpio.c b/drivers/led/led-gpio.c
index 711146b012..c78ef9e1cb 100644
--- a/drivers/led/led-gpio.c
+++ b/drivers/led/led-gpio.c
@@ -52,6 +52,53 @@ void led_gpio_unregister(struct gpio_led *led)
led_unregister(&led->led);
}
+#ifdef CONFIG_LED_GPIO_BICOLOR
+static void led_gpio_bicolor_set(struct led *led, unsigned int value)
+{
+ struct gpio_bicolor_led *bi = container_of(led, struct gpio_bicolor_led, led);
+ int al = bi->active_low;
+
+ switch (value) {
+ case 0:
+ gpio_direction_output(bi->gpio_c0, al);
+ gpio_direction_output(bi->gpio_c1, al);
+ break;
+ case 1:
+ gpio_direction_output(bi->gpio_c0, !al);
+ gpio_direction_output(bi->gpio_c1, al);
+ break;
+ case 2:
+ gpio_direction_output(bi->gpio_c0, al);
+ gpio_direction_output(bi->gpio_c1, !al);
+ break;
+ }
+}
+
+/**
+ * led_gpio_bicolor_register - register three gpios as a bicolor LED
+ * @param led The gpio bicolor LED
+ *
+ * This function registers three gpios as a bicolor LED. led->gpio[rg]
+ * should be initialized to the gpios to control.
+ */
+int led_gpio_bicolor_register(struct gpio_bicolor_led *led)
+{
+ led->led.set = led_gpio_bicolor_set;
+ led->led.max_value = 2;
+
+ return led_register(&led->led);
+}
+
+/**
+ * led_gpio_bicolor_unregister - remove a gpio controlled bicolor LED from the framework
+ * @param led The gpio LED
+ */
+void led_gpio_bicolor_unregister(struct gpio_bicolor_led *led)
+{
+ led_unregister(&led->led);
+}
+#endif
+
#ifdef CONFIG_LED_GPIO_RGB
static void led_gpio_rgb_set(struct led *led, unsigned int value)