Skip to contentSkip to conversation

Corrected LED name match finding avoiding extraneous Usage printouts

PATCH New Joel A Fernandes 2 participants 9 messages Aug 16, 2011 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 Corrected LED name match finding avoiding extraneous Usage printouts

From: Jason Kridner <[email protected]>

---
 common/cmd_led.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
common/cmd_led.c +3 -2
index c53195f..8b46848 100644
@@ -83,7 +83,7 @@ int str_onoff (char *var)
 
 int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-	int state, i;
+	int state, i, match = 0;
 
 	/* Validate arguments */
 	if ((argc != 3)) {
@@ -98,6 +98,7 @@ int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	for (i = 0; led_commands[i].string; i++) {
 		if ((strcmp("all", argv[1]) == 0) ||
 		    (strcmp(led_commands[i].string, argv[1]) == 0)) {
+		    	match = 1;
 			if (led_commands[i].on) {
 				if (state) {
 					led_commands[i].on();
@@ -112,7 +113,7 @@ int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	}
 
 	/* If we ran out of matches, print Usage */
-	if (!led_commands[i].string && !(strcmp("all", argv[1]) == 0)) {
+	if (!match) {
 		return cmd_usage(cmdtp);
 	}
 
Signature · 1 line
1.7.1
#1 lore raw

PATCH 2/7 BeagleBoard: fix LED 0/1 in driver

From: Jason Kridner <[email protected]>

Fixed USR0/USR1 to be LED 0/1 respectively

---
 board/ti/beagle/led.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
board/ti/beagle/led.c +2 -2
index 08f95a0..d3de51f 100644
@@ -27,8 +27,8 @@
 static unsigned int saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF};
 
 /* GPIO pins for the LEDs */
-#define BEAGLE_LED_USR0	149
-#define BEAGLE_LED_USR1	150
+#define BEAGLE_LED_USR0	150
+#define BEAGLE_LED_USR1	149
 
 #ifdef STATUS_LED_GREEN
 void green_LED_off (void)
Signature · 1 line
1.7.1
#2 lore raw

PATCH 3/7 led: added cmd_led to Makefile

In reply to Joel A Fernandes

From: Jason Kridner <[email protected]>

Addition of cmd_led into the Makefile wasn't included in the patch applied to u-boot-ti.

---
 common/Makefile |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
common/Makefile +1 -0
index 224b7cc..7445ccc 100644
@@ -107,6 +107,7 @@ COBJS-$(CONFIG_CMD_ITEST) += cmd_itest.o
 COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o
 COBJS-$(CONFIG_CMD_CRAMFS) += cmd_cramfs.o
 COBJS-$(CONFIG_CMD_LDRINFO) += cmd_ldrinfo.o
+COBJS-$(CONFIG_CMD_LED) += cmd_led.o
 COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o
 COBJS-y += cmd_load.o
 COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o
Signature · 1 line
1.7.1
#3 lore raw

PATCH 4/7 led: correct off/on locations in structure

In reply to Joel A Fernandes

From: Jason Kridner <[email protected]>

Although the initialization should probably be done with names, the existing implementation has these structures filled in the opposite order.

---
 common/cmd_led.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
common/cmd_led.c +2 -2
index 8b46848..d14dd5a 100644
@@ -34,8 +34,8 @@
 struct led_tbl_s {
 	char		*string;	/* String for use in the command */
 	led_id_t	mask;		/* Mask used for calling __led_set() */
-	void		(*on)(void);	/* Optional fucntion for turning LED on */
-	void		(*off)(void);	/* Optional fucntion for turning LED on */
+	void		(*off)(void);	/* Optional function for turning LED off */
+	void		(*on)(void);	/* Optional function for turning LED on */
 };
 
 typedef struct led_tbl_s led_tbl_t;
Signature · 1 line
1.7.1
#4 lore raw

PATCH 5/7 led: Fixed setting of STATUS_LED_BIT1 when led_name is 'all'

In reply to Joel A Fernandes

Fix for only one led getting set or reset when the led_name is 'all'

Previous discussion:
http://lists.denx.de/pipermail/u-boot/2011-May/093068.html

---
 common/cmd_led.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
common/cmd_led.c +3 -1
index d14dd5a..d3a8450 100644
@@ -108,7 +108,9 @@ int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			} else {
 				__led_set(led_commands[i].mask, state);
 			}
-			break;
+			/* Need to set only 1 led if led_name wasn't 'all' */
+			if(strcmp("all", argv[1]) != 0)
+				break;
 		}
 	}
 
Signature · 1 line
1.7.1
#5 lore raw

PATCH 5/7 led: Fixed setting of STATUS_LED_BIT1 when led_name is 'all'

Hello.

Quoted 16 lines · Joel A Fernandes

Fix for only one led getting set or reset when the led_name is 'all'

Previous discussion:
http://lists.denx.de/pipermail/u-boot/2011-May/093068.html

---
  common/cmd_led.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
common/cmd_led.c +0 -0
index d14dd5a..d3a8450 100644

common/cmd_led.c int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 112

Quoted 6 lines
common/cmd_led.c +2 -1
@@ -108,7 +108,9 @@ int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  			} else {
  				__led_set(led_commands[i].mask, state);
  			}
-			break;
+			/* Need to set only 1 led if led_name wasn't 'all' */
+			if(strcmp("all", argv[1]) != 0)

There should be space after *if* -- run patches thry checkpatch.pl.

WBR, Sergei

#6 lore raw

PATCH 5/7 led: Fixed setting of STATUS_LED_BIT1 when led_name is 'all'

Quoted 6 lines · Sergei Shtylyov

Hello.

Quoted 1 line · Joel A Fernandes

Fix for only one led getting set or reset when the led_name is 'all'

Hi, Thanks for pointing that out. Should I have to re-send the entire patch series or just patches that need a correction?

Thanks!

#7 lore raw

PATCH 6/7 OMAP3: Add function to get state of a GPIO output

In reply to Joel A Fernandes

Read directly from OMAP24XX_GPIO_DATAOUT to get the output state of the GPIO pin

---
 arch/arm/cpu/armv7/omap3/gpio.c        |   20 ++++++++++++++++++++
 arch/arm/include/asm/arch-omap3/gpio.h |    2 ++
 2 files changed, 22 insertions(+), 0 deletions(-)
arch/arm/cpu/armv7/omap3/gpio.c +20 -0
index aeb6066..c8bb551 100644
@@ -160,6 +160,26 @@ int omap_get_gpio_datain(int gpio)
 			& (1 << get_gpio_index(gpio))) != 0;
 }
 
+int omap_get_gpio_dataout(int gpio)
+{
+	struct gpio_bank *bank;
+	void *reg;
+
+	if (check_gpio(gpio) < 0)
+		return -EINVAL;
+	bank = get_gpio_bank(gpio);
+	reg = bank->base;
+	switch (bank->method) {
+	case METHOD_GPIO_24XX:
+		reg += OMAP24XX_GPIO_DATAOUT;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return (__raw_readl(reg)
+			& (1 << get_gpio_index(gpio))) != 0;
+}
+
 static void _reset_gpio(struct gpio_bank *bank, int gpio)
 {
 	_set_gpio_direction(bank, get_gpio_index(gpio), 1);
arch/arm/include/asm/arch-omap3/gpio.h +2 -0
index 30f633c..81615bc 100644
@@ -82,5 +82,7 @@ void omap_set_gpio_direction(int gpio, int is_input);
 void omap_set_gpio_dataout(int gpio, int enable);
 /* Get the value of a gpio input */
 int omap_get_gpio_datain(int gpio);
+/* Get the value of a gpio output */
+int omap_get_gpio_dataout(int gpio);
 
 #endif /* _GPIO_H_ */
Signature · 1 line
1.7.1
#8 lore raw

PATCH 7/7 led: Remove state-saving of led for toggle functionality and add toggle option to led command

In reply to Joel A Fernandes

* Read the led output state from GPIO instead saving state in memory when it is [re]set
* Added a toggle option to the led command

Previous discussion:
http://lists.denx.de/pipermail/u-boot/2011-May/093068.html

---
 board/ti/beagle/led.c |   28 ++++++++-----------
 common/cmd_led.c      |   69 ++++++++++++++++++++++++++++++------------------
 2 files changed, 55 insertions(+), 42 deletions(-)
board/ti/beagle/led.c +12 -16
index d3de51f..9e65932 100644
@@ -24,8 +24,6 @@
 #include <asm/arch/sys_proto.h>
 #include <asm/arch/gpio.h>
 
-static unsigned int saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF};
-
 /* GPIO pins for the LEDs */
 #define BEAGLE_LED_USR0	150
 #define BEAGLE_LED_USR1	149
@@ -49,22 +47,22 @@ void __led_init (led_id_t mask, int state)
 
 void __led_toggle (led_id_t mask)
 {
+	int state, toggle_gpio = 0;
 #ifdef STATUS_LED_BIT
-	if (STATUS_LED_BIT & mask) {
-		if (STATUS_LED_ON == saved_state[0])
-			__led_set(STATUS_LED_BIT, 0);
-		else
-			__led_set(STATUS_LED_BIT, 1);
-	}
+	if (!toggle_gpio && STATUS_LED_BIT & mask)
+		toggle_gpio = BEAGLE_LED_USR0;
 #endif
 #ifdef STATUS_LED_BIT1
-	if (STATUS_LED_BIT1 & mask) {
-		if (STATUS_LED_ON == saved_state[1])
-			__led_set(STATUS_LED_BIT1, 0);
-		else
-			__led_set(STATUS_LED_BIT1, 1);
-	}
+	if (!toggle_gpio && STATUS_LED_BIT1 & mask)
+		toggle_gpio = BEAGLE_LED_USR1;
 #endif
+	if(toggle_gpio) {
+		if (!omap_request_gpio(toggle_gpio)) {
+			omap_set_gpio_direction(toggle_gpio, 0);
+			state = omap_get_gpio_dataout(toggle_gpio);
+			omap_set_gpio_dataout(toggle_gpio, !state);
+		}
+	}
 }
 
 void __led_set (led_id_t mask, int state)
@@ -75,7 +73,6 @@ void __led_set (led_id_t mask, int state)
 			omap_set_gpio_direction(BEAGLE_LED_USR0, 0);
 			omap_set_gpio_dataout(BEAGLE_LED_USR0, state);
 		}
-		saved_state[0] = state;
 	}
 #endif
 #ifdef STATUS_LED_BIT1
@@ -84,7 +81,6 @@ void __led_set (led_id_t mask, int state)
 			omap_set_gpio_direction(BEAGLE_LED_USR1, 0);
 			omap_set_gpio_dataout(BEAGLE_LED_USR1, state);
 		}
-		saved_state[1] = state;
 	}
 #endif
 }
common/cmd_led.c +43 -26

125 lines not on this page · raw message

Signature · 1 line
1.7.1