diff mbox

[U-Boot,3/5] siemens: add led cmd for flexible LED control

Message ID 1398355077-6661-4-git-send-email-samuel.egli@siemens.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Samuel Egli April 24, 2014, 3:57 p.m. UTC
* remove setting LED in user button function.
   We want to decouple reading user button and setting LED. This
   two things need to be done independently.

 * led cmd can be used to control LEDs that are defined in board file
   having a led cmd, one can easily set LEDs in u-boot shell. For
   example bootcmd can be extended to disable status LED before
   loading kernel.

Signed-off-by: Samuel Egli <samuel.egli@siemens.com>
Cc: Roger Meier <r.meier@siemens.com>
Cc: Heiko Schocher <hs@denx.de>
Cc: Wolfgang Denk <wd@denx.de>
---
 board/siemens/common/board.c |   46 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 6 deletions(-)

Comments

Tom Rini May 14, 2014, 1:35 a.m. UTC | #1
On Thu, Apr 24, 2014 at 05:57:54PM +0200, Egli, Samuel wrote:

> * remove setting LED in user button function.
>    We want to decouple reading user button and setting LED. This
>    two things need to be done independently.
> 
>  * led cmd can be used to control LEDs that are defined in board file
>    having a led cmd, one can easily set LEDs in u-boot shell. For
>    example bootcmd can be extended to disable status LED before
>    loading kernel.
> 
> Signed-off-by: Samuel Egli <samuel.egli@siemens.com>
> Cc: Roger Meier <r.meier@siemens.com>
> Cc: Heiko Schocher <hs@denx.de>
> Cc: Wolfgang Denk <wd@denx.de>

Applied to u-boot-ti/master, thanks!
diff mbox

Patch

diff --git a/board/siemens/common/board.c b/board/siemens/common/board.c
index 7e8731b..2782bcc 100644
--- a/board/siemens/common/board.c
+++ b/board/siemens/common/board.c
@@ -128,12 +128,6 @@  do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		button = 0;
 
 	gpio_free(gpio);
-	if (!button) {
-		/* LED0 - RED=1: GPIO2_0 2*32 = 64 */
-		gpio_request(BOARD_DFU_BUTTON_LED, "");
-		gpio_direction_output(BOARD_DFU_BUTTON_LED, 1);
-		gpio_set_value(BOARD_DFU_BUTTON_LED, 1);
-	}
 
 	return button;
 }
@@ -144,6 +138,46 @@  U_BOOT_CMD(
 	""
 );
 #endif
+/*
+ * This command sets led
+ * Input -	name of led
+ *		value of led
+ * Returns -	1 if input does not match
+ *		0 if led was set
+ */
+static int
+do_setled(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	int gpio = 0;
+	if (argc != 3)
+		goto exit;
+#if defined(BOARD_STATUS_LED)
+	if (!strcmp(argv[1], "stat"))
+		gpio = BOARD_STATUS_LED;
+#endif
+#if defined(BOARD_DFU_BUTTON_LED)
+	if (!strcmp(argv[1], "dfu"))
+		gpio = BOARD_DFU_BUTTON_LED;
+#endif
+	/* If argument does not mach exit */
+	if (gpio == 0)
+		goto exit;
+	gpio_request(gpio, "");
+	gpio_direction_output(gpio, 1);
+	if (!strcmp(argv[2], "1"))
+		gpio_set_value(gpio, 1);
+	else
+		gpio_set_value(gpio, 0);
+	return 0;
+exit:
+	return 1;
+}
+
+U_BOOT_CMD(
+	led, CONFIG_SYS_MAXARGS, 2, do_setled,
+	"Set led on or off",
+	"dfu val - set dfu led\nled stat val - set status led"
+);
 
 static int
 do_usertestwdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])