[U-Boot] [PATCH v2 6/6] cmd_led: Add support for inverted BIT leds

Otavio Salvador otavio at ossystems.com.br
Sat Sep 28 21:19:25 CEST 2013


Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
---
Changes in v2: None

 common/cmd_led.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/common/cmd_led.c b/common/cmd_led.c
index c48603c..d541f2f 100644
--- a/common/cmd_led.c
+++ b/common/cmd_led.c
@@ -18,6 +18,7 @@
 struct led_tbl_s {
 	char		*string;	/* String for use in the command */
 	led_id_t	mask;		/* Mask used for calling __led_set() */
+	int		invert;	/* Is the LED inverted? */
 	void		(*off)(void);	/* Optional function for turning LED off */
 	void		(*on)(void);	/* Optional function for turning LED on */
 	void		(*toggle)(void);/* Optional function for toggling LED */
@@ -28,31 +29,31 @@ typedef struct led_tbl_s led_tbl_t;
 static const led_tbl_t led_commands[] = {
 #ifdef CONFIG_BOARD_SPECIFIC_LED
 #ifdef STATUS_LED_BIT
-	{ "0", STATUS_LED_BIT, NULL, NULL, NULL },
+	{ "0", STATUS_LED_BIT, STATUS_LED_INVERT, NULL, NULL, NULL },
 #endif
 #ifdef STATUS_LED_BIT1
-	{ "1", STATUS_LED_BIT1, NULL, NULL, NULL },
+	{ "1", STATUS_LED_BIT1, STATUS_LED_INVERT1, NULL, NULL, NULL },
 #endif
 #ifdef STATUS_LED_BIT2
-	{ "2", STATUS_LED_BIT2, NULL, NULL, NULL },
+	{ "2", STATUS_LED_BIT2, STATUS_LED_INVERT2, NULL, NULL, NULL },
 #endif
 #ifdef STATUS_LED_BIT3
-	{ "3", STATUS_LED_BIT3, NULL, NULL, NULL },
+	{ "3", STATUS_LED_BIT3, STATUS_LED_INVERT3, NULL, NULL, NULL },
 #endif
 #endif
 #ifdef STATUS_LED_GREEN
-	{ "green", STATUS_LED_GREEN, green_led_off, green_led_on, NULL },
+	{ "green", STATUS_LED_GREEN, 0, green_led_off, green_led_on, NULL },
 #endif
 #ifdef STATUS_LED_YELLOW
-	{ "yellow", STATUS_LED_YELLOW, yellow_led_off, yellow_led_on, NULL },
+	{ "yellow", STATUS_LED_YELLOW, 0, yellow_led_off, yellow_led_on, NULL },
 #endif
 #ifdef STATUS_LED_RED
-	{ "red", STATUS_LED_RED, red_led_off, red_led_on, NULL },
+	{ "red", STATUS_LED_RED, 0, red_led_off, red_led_on, NULL },
 #endif
 #ifdef STATUS_LED_BLUE
-	{ "blue", STATUS_LED_BLUE, blue_led_off, blue_led_on, NULL },
+	{ "blue", STATUS_LED_BLUE, 0, blue_led_off, blue_led_on, NULL },
 #endif
-	{ NULL, 0, NULL, NULL, NULL }
+	{ NULL, 0, 0, NULL, NULL, NULL }
 };
 
 enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE };
@@ -95,14 +96,18 @@ int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 					led_commands[i].on();
 				else
 					__led_set(led_commands[i].mask,
-							  STATUS_LED_ON);
+							  (led_commands[i].invert
+							   ? STATUS_LED_OFF
+							   : STATUS_LED_ON));
 				break;
 			case LED_OFF:
 				if (led_commands[i].off)
 					led_commands[i].off();
 				else
 					__led_set(led_commands[i].mask,
-							  STATUS_LED_OFF);
+							  (led_commands[i].invert
+							   ? STATUS_LED_ON
+							   : STATUS_LED_OFF));
 				break;
 			case LED_TOGGLE:
 				if (led_commands[i].toggle)
-- 
1.8.4.rc3



More information about the U-Boot mailing list