[U-Boot] [PATCH 1/1] at91: Add command to control up to 3 GPIO LEDs from the console

Daniel Gorsulowski Daniel.Gorsulowski at esd.eu
Wed May 6 16:21:09 CEST 2009


This patch allows any at91 board, implementing the GPIO LED API,
to control the LEDs from the console.

led [ 1 | 2 | 3 | all ]  [ on | off ]

Adding configuration items CONFIG_AT91_LED and CONFIG_CMD_LED
enables the command.
Moreover the GPIO Pins have to be defined by CONFIG_USER1_LED ...
CONFIG_USER3_LED.
---
 common/Makefile                 |    1 +
 common/cmd_led.c                |   86 +++++++++++++++++++++++++++++++++++++++
 cpu/arm926ejs/at91/led.c        |   79 +++++++++++++++++++++++++++++++++++
 include/asm-arm/arch-at91/led.h |   52 +++++++++++++++++++++++
 4 files changed, 218 insertions(+), 0 deletions(-)
 create mode 100644 common/cmd_led.c
 create mode 100644 include/asm-arm/arch-at91/led.h

diff --git a/common/Makefile b/common/Makefile
index b9f4ca7..e0f571c 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -103,6 +103,7 @@ COBJS-$(CONFIG_CMD_IMMAP) += cmd_immap.o
 COBJS-$(CONFIG_CMD_IRQ) += cmd_irq.o
 COBJS-$(CONFIG_CMD_ITEST) += cmd_itest.o
 COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.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
diff --git a/common/cmd_led.c b/common/cmd_led.c
new file mode 100644
index 0000000..f914d2d
--- /dev/null
+++ b/common/cmd_led.c
@@ -0,0 +1,86 @@
+/*
+ * (C) Copyright 2008
+ * Ulf Samuelsson <ulf.samuelsson at atmel.com>
+ *
+ * (C) Copyright 2009
+ * Daniel Gorsulowski <daniel.gorsulowski at esd.eu>
+ * esd electronic system design gmbh <www.esd.eu>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <asm/arch/led.h>
+
+int do_led(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+	int led;
+
+	/* Validate arguments */
+	if ((argc != 3)) {
+		printf("Usage:\n%s\n", cmdtp->usage);
+		return 1;
+	}
+	if (strcmp(argv[1], "1") == 0) {
+		led = (1 << 0);
+	} else if (strcmp(argv[1], "2") == 0) {
+		led = (1 << 1);
+	} else if (strcmp(argv[1], "3") == 0) {
+		led = (1 << 2);
+	} else if (strcmp(argv[1], "all") == 0) {
+		led = 31;
+	} else {
+		printf ("Usage:\n%s\n", cmdtp->usage);
+		return 1;
+	}
+
+	if (strcmp(argv[2], "off") == 0) {
+#ifdef CONFIG_USER1_LED
+		if(led & 1) user1_led_off();
+#endif
+#ifdef CONFIG_USER2_LED
+		if(led & 2) user2_led_off();
+#endif
+#ifdef CONFIG_USER3_LED
+		if(led & 4) user3_led_off();
+#endif
+	} else if (strcmp(argv[2], "on") == 0) {
+#ifdef CONFIG_USER1_LED
+		if(led & 1) user1_led_on();
+#endif
+#ifdef CONFIG_USER2_LED
+		if(led & 2) user2_led_on();
+#endif
+#ifdef CONFIG_USER3_LED
+		if(led & 4) user3_led_on();
+#endif
+	} else {
+		printf ("Usage:\n%s\n", cmdtp->usage);
+		return 1;
+	}
+	return 0;
+}
+
+U_BOOT_CMD(
+	led, 3, 1, do_led,
+	"[1|2|3|all] [on|off]",
+	"[1|2|3|all] [on|off] sets/clears led 1,2,3"
+);
diff --git a/cpu/arm926ejs/at91/led.c b/cpu/arm926ejs/at91/led.c
index be68f59..46a74fe 100644
--- a/cpu/arm926ejs/at91/led.c
+++ b/cpu/arm926ejs/at91/led.c
@@ -3,6 +3,10 @@
  * Stelian Pop <stelian.pop at leadtechdesign.com>
  * Lead Tech Design <www.leadtechdesign.com>
  *
+ * (C) Copyright 2009
+ * Daniel Gorsulowski <daniel.gorsulowski at esd.eu>
+ * esd electronic system design gmbh <www.esd.eu>
+ *
  * See file CREDITS for list of people who contributed to this
  * project.
  *
@@ -27,6 +31,81 @@
 #include <asm/arch/gpio.h>
 #include <asm/arch/io.h>
 
+#ifdef CONFIG_AT91_LED
+
+#if defined(CONFIG_AT91RM9200)
+#include <asm/arch/at91rm9200.h>
+#elif defined(CONFIG_AT91SAM9260) || defined(CONFIG_AT91SAM9G20)
+#include <asm/arch/at91sam9260.h>
+#elif defined(CONFIG_AT91SAM9261)
+#include <asm/arch/at91sam9261.h>
+#elif defined(CONFIG_AT91SAM9263)
+#include <asm/arch/at91sam9263.h>
+#elif defined(CONFIG_AT91SAM9RL)
+#include <asm/arch/at91sam9rl.h>
+#elif defined(CONFIG_AT91CAP9)
+#include <asm/arch/at91cap9.h>
+#endif
+
+#include <asm/arch/led.h>
+
+void at91_led_init(void)
+{
+	/* Enable clock */
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_PIOB |
+				      1 << AT91SAM9263_ID_PIOCDE);
+
+#ifdef CONFIG_USER1_LED
+	at91_set_gpio_output(CONFIG_USER1_LED, 1);
+	at91_set_gpio_value(CONFIG_USER1_LED, 1);
+#endif
+#ifdef CONFIG_USER2_LED
+	at91_set_gpio_output(CONFIG_USER2_LED, 1);
+	at91_set_gpio_value(CONFIG_USER2_LED, 1);
+#endif
+#ifdef CONFIG_USER3_LED
+	at91_set_gpio_output(CONFIG_USER3_LED, 1);
+	at91_set_gpio_value(CONFIG_USER3_LED, 1);
+#endif
+}
+#ifdef CONFIG_USER1_LED
+void user1_led_on(void)
+{
+	at91_set_gpio_value(CONFIG_USER1_LED, 0);
+}
+
+void user1_led_off(void)
+{
+	at91_set_gpio_value(CONFIG_USER1_LED, 1);
+}
+#endif
+
+#ifdef CONFIG_USER2_LED
+void user2_led_on(void)
+{
+	at91_set_gpio_value(CONFIG_USER2_LED, 0);
+}
+
+void user2_led_off(void)
+{
+	at91_set_gpio_value(CONFIG_USER2_LED, 1);
+}
+#endif
+
+#ifdef CONFIG_USER3_LED
+void user3_led_on(void)
+{
+	at91_set_gpio_value(CONFIG_USER3_LED, 0);
+}
+
+void user3_led_off(void)
+{
+	at91_set_gpio_value(CONFIG_USER3_LED, 1);
+}
+#endif
+
+#endif /* CONFIG_AT91_LED */
+
 #ifdef CONFIG_RED_LED
 void red_LED_on(void)
 {
diff --git a/include/asm-arm/arch-at91/led.h b/include/asm-arm/arch-at91/led.h
new file mode 100644
index 0000000..878b2cf
--- /dev/null
+++ b/include/asm-arm/arch-at91/led.h
@@ -0,0 +1,52 @@
+/*
+ * (C) Copyright 2000-2004
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * (C) Copyright 2009
+ * Daniel Gorsulowski <daniel.gorsulowski at esd.eu>
+ * esd electronic system design gmbh <www.esd.eu>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __ASM_ARCH_LED_H
+#define __ASM_ARCH_LED_H
+
+/*
+ * User LEDs API
+ */
+#ifndef	__ASSEMBLY__
+extern void	at91_led_init(void);
+extern void	user1_led_on(void);
+extern void	user1_led_off(void);
+extern void	user2_led_on(void);
+extern void	user2_led_off(void);
+extern void	user3_led_on(void);
+extern void	user3_led_off(void);
+#else
+	.extern at91_led_init
+	.extern user1_led_on
+	.extern user1_led_off
+	.extern user2_led_on
+	.extern user2_led_off
+	.extern user3_led_on
+	.extern user3_led_off
+#endif
+
+#endif /* __ASM_ARCH_LED_H */
-- 
1.6.1



More information about the U-Boot mailing list