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

Daniel Gorsulowski Daniel.Gorsulowski at esd.eu
Thu May 14 10:51:23 CEST 2009


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

Adding configuration items CONFIG_AT91_LED and CONFIG_CMD_LED
enables the command.
Moreover the GPIO Pins have to be defined by CONFIG_GPIO_LEDS
See doc/README.LED for detailed information.

Usage:
led [LED_number] [on|off]

Signed-off-by: Daniel Gorsulowski <Daniel.Gorsulowski at esd.eu>
---
 cpu/arm926ejs/at91/Makefile     |    1 +
 cpu/arm926ejs/at91/cmd_led.c    |   60 +++++++++++++++++++++++++++++++++++++++
 cpu/arm926ejs/at91/led.c        |   29 +++++++++++++++++++
 doc/README.LED                  |   40 ++++++++++++++++++++++++++
 include/asm-arm/arch-at91/led.h |   42 +++++++++++++++++++++++++++
 5 files changed, 172 insertions(+), 0 deletions(-)
 create mode 100644 cpu/arm926ejs/at91/cmd_led.c
 create mode 100644 include/asm-arm/arch-at91/led.h

diff --git a/cpu/arm926ejs/at91/Makefile b/cpu/arm926ejs/at91/Makefile
index e300d97..adfd192 100644
--- a/cpu/arm926ejs/at91/Makefile
+++ b/cpu/arm926ejs/at91/Makefile
@@ -54,6 +54,7 @@ ifdef CONFIG_AT91SAM9RL
 COBJS-y				+= at91sam9rl_serial.o
 COBJS-$(CONFIG_HAS_DATAFLASH)	+= at91sam9rl_spi.o
 endif
+COBJS-$(CONFIG_CMD_LED)		+= cmd_led.o
 COBJS-$(CONFIG_AT91_LED)	+= led.o
 COBJS-y += clock.o
 COBJS-y += cpu.o
diff --git a/cpu/arm926ejs/at91/cmd_led.c b/cpu/arm926ejs/at91/cmd_led.c
new file mode 100644
index 0000000..45d634b
--- /dev/null
+++ b/cpu/arm926ejs/at91/cmd_led.c
@@ -0,0 +1,60 @@
+/*
+ * (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[])
+{
+	ulong led_nr;
+	unsigned on;
+
+	/* Validate arguments */
+	led_nr = simple_strtoul(argv[1], NULL, 10);
+	if (led_nr > CONFIG_LED_MAX) {
+		printf("Usage:\n%s\n", cmdtp->usage);
+		return 1;
+	}
+
+	if (strcmp(argv[2], "off") == 0) {
+		on = 1;
+	} else if (strcmp(argv[2], "on") == 0) {
+		on = 0;
+	} else {
+		printf("Usage:\n%s\n", cmdtp->usage);
+		return 1;
+	}
+
+	user_led(led_nr - 1, on);
+
+	return 0;
+}
+
+U_BOOT_CMD(
+	led, 3, 1, do_led,
+	"[LED_number] [on|off]",
+	"[LED_number] [on|off] turns LED on/off"
+);
diff --git a/cpu/arm926ejs/at91/led.c b/cpu/arm926ejs/at91/led.c
index be68f59..b41a7c4 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,31 @@
 #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 user_led(ulong led_nr, unsigned on)
+{
+	at91_set_gpio_value(leds[led_nr], on);
+}
+
+#endif /* CONFIG_AT91_LED */
+
 #ifdef CONFIG_RED_LED
 void red_LED_on(void)
 {
diff --git a/doc/README.LED b/doc/README.LED
index 1221177..06a741e 100644
--- a/doc/README.LED
+++ b/doc/README.LED
@@ -76,3 +76,43 @@ TBD : Describe older board dependent macros similar to what is done for
 CONFIG_TQM8xxL.
 
 TBD : Describe general support via asm/status_led.h
+
+
+GPIO LEDs
+========================================
+
+GPIO LEDs are presently only supported by at91.
+this README describes the usage of the GPIO LED API.
+
+The API is defined by the include file include/asm-arm/arch-at91/led.h
+
+The first step is to define CONFIG_AT91_LED, CONFIG_LED_MAX and CONFIG_GPIO_LEDS
+in the board config file.
+I.e.:
+	/* LED */
+	#define CONFIG_AT91_LED
+	#define CONFIG_LED_MAX				ARRAY_SIZE(leds)
+	#define CONFIG_GPIO_LEDS	{				\
+							AT91_PIN_PB8,	\
+							AT91_PIN_PB7	\
+					}
+
+The second step is to initialize the Peripheral Clock Controller and the GPIO
+pins in the vendor specific board code.
+I.e.:
+	#ifdef CONFIG_AT91_LED
+		/* Enable clock */
+		at91_sys_write(AT91_PMC_PCER,	1 << AT91SAM9263_ID_PIOB |
+						1 << AT91SAM9263_ID_PIOCDE);
+
+		/* Initialize GPIO pins */
+		int i;
+		for(i = 0; i < CONFIG_LED_MAX; i++) {
+			at91_set_gpio_output(leds[i], 1);
+			at91_set_gpio_value(leds[i], 1);
+		}
+	#endif
+
+Now a new command "led" will be available in the U-Boot console.
+Usage:
+led [LED_number] [on|off]
diff --git a/include/asm-arm/arch-at91/led.h b/include/asm-arm/arch-at91/led.h
new file mode 100644
index 0000000..f55cb56
--- /dev/null
+++ b/include/asm-arm/arch-at91/led.h
@@ -0,0 +1,42 @@
+/*
+ * (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
+
+/*
+ * GPIO LEDs API
+ */
+
+#include <asm/arch/gpio.h>
+
+static long leds[] = CONFIG_GPIO_LEDS;
+
+#ifndef __ASSEMBLY__
+extern void user_led(ulong led_nr, unsigned on);
+#else
+	.extern user_led
+#endif
+
+#endif /* __ASM_ARCH_LED_H */
-- 
1.6.1



More information about the U-Boot mailing list