Patchwork [U-Boot,7/7] cmd_led: Add support for inverted BIT leds

login
register
mail settings
Submitter Otavio Salvador
Date Sept. 28, 2013, 3:24 a.m.
Message ID <1380338659-7896-7-git-send-email-otavio@ossystems.com.br>
Download mbox | patch
Permalink /patch/278710/
State Superseded
Headers show

Comments

Otavio Salvador - Sept. 28, 2013, 3:24 a.m.
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 common/cmd_led.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

Patch

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)