public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] at91: Add command to control GPIO LEDs from the console
@ 2009-05-14  8:51 Daniel Gorsulowski
  2009-05-22 23:33 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Gorsulowski @ 2009-05-14  8:51 UTC (permalink / raw)
  To: u-boot

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@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@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@leadtechdesign.com>
  * Lead Tech Design <www.leadtechdesign.com>
  *
+ * (C) Copyright 2009
+ * Daniel Gorsulowski <daniel.gorsulowski@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@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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] at91: Add command to control GPIO LEDs from the console
  2009-05-14  8:51 [U-Boot] [PATCH] at91: Add command to control GPIO LEDs from the console Daniel Gorsulowski
@ 2009-05-22 23:33 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 2+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2009-05-22 23:33 UTC (permalink / raw)
  To: u-boot

On 10:51 Thu 14 May     , Daniel Gorsulowski wrote:
> 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]
why create a new led API?

the best way will be to extent the current collor led api by using something
like this

why create a new led API?

the best way will be to extent the current collor led api by using something
like this

#define LED_RED		0
#define LED_GREEN	1
#define LED_YELLOW	2
#define LED_BLUE	3

.macro led_red_off
	ldr	r0, =LED_RED
	mov	r1, #0
	bl	led_on_off
.endm

.macro led_red_on
	ldr	r0, =LED_RED
	mov	r1, #1
	bl	led_on_off
.endm

.macro led_green_off
	ldr	r0, =LED_GREEN
	mov	r1, #0
	bl	led_on_off
.endm

.macro led_green_on
	ldr	r0, =LED_GREN
	mov	r1, #1
	bl	led_on_off
.endm

.macro led_yellow_off
	ldr	r0, =LED_YELLOW
	mov	r1, #0
	bl	led_on_off
.endm

.macro led_yellow_on
	ldr	r0, =LED_YELLOW
	mov	r1, #1
	bl	led_on_off
.endm

.macro led_blue_off
	ldr	r0, =LED_BLUE
	mov	r1, #0
	bl	led_on_off
.endm

.macro led_blue_on
	ldr	r0, =LED_BLUE
	mov	r1, #1
	bl	led_on_off
.endm

and we need to keep the coloured led name and number
and if needed extendit as done for the zoom2

and please do not do it only for at91

Best Regards,
J.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-05-22 23:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-14  8:51 [U-Boot] [PATCH] at91: Add command to control GPIO LEDs from the console Daniel Gorsulowski
2009-05-22 23:33 ` Jean-Christophe PLAGNIOL-VILLARD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox