diff mbox

[U-Boot,1/2] ep93xx leds: remove arrays in data section

Message ID 676d5729204f4fba02730fd8db55e4fb433fedb5.1265920498.git.rubini@unipv.it
State Not Applicable
Delegated to: Albert ARIBAUD
Headers show

Commit Message

Alessandro Rubini Feb. 11, 2010, 8:46 p.m. UTC
This code is used at early boot, and using arrays for status
generates references to RAM addresses that are not working.
The patch avoids such structures using a preprocessor macro and
by reading status from hardware in the toggle function.
Meanwhile, inline functions are turned to static to save code space.

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Acked-by: Matthias Kaehlcke <matthias@kaehlcke.net>
---
 cpu/arm920t/ep93xx/led.c |   29 +++++++++--------------------
 1 files changed, 9 insertions(+), 20 deletions(-)
diff mbox

Patch

diff --git a/cpu/arm920t/ep93xx/led.c b/cpu/arm920t/ep93xx/led.c
index 7e2c897..8b2df04 100644
--- a/cpu/arm920t/ep93xx/led.c
+++ b/cpu/arm920t/ep93xx/led.c
@@ -25,24 +25,21 @@ 
 #include <config.h>
 #include <status_led.h>
 
-static uint8_t saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF};
-static uint32_t gpio_pin[2] = {1 << STATUS_LED_GREEN,
-			       1 << STATUS_LED_RED};
+/* We can't use arrays in data segment at early boot, but we know n is 0-1 */
+#define GPIO_PIN(n) (1 << (n))
 
-inline void switch_LED_on(uint8_t led)
+static inline void switch_LED_on(uint8_t led)
 {
 	register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
 
-	writel(readl(&gpio->pedr) | gpio_pin[led], &gpio->pedr);
-	saved_state[led] = STATUS_LED_ON;
+	writel(readl(&gpio->pedr) | GPIO_PIN(led), &gpio->pedr);
 }
 
-inline void switch_LED_off(uint8_t led)
+static inline void switch_LED_off(uint8_t led)
 {
 	register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
 
-	writel(readl(&gpio->pedr) & ~gpio_pin[led], &gpio->pedr);
-	saved_state[led] = STATUS_LED_OFF;
+	writel(readl(&gpio->pedr) & ~GPIO_PIN(led), &gpio->pedr);
 }
 
 void red_LED_on(void)
@@ -72,17 +69,9 @@  void __led_init(led_id_t mask, int state)
 
 void __led_toggle(led_id_t mask)
 {
-	if (STATUS_LED_RED == mask) {
-		if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
-			red_LED_off();
-		else
-			red_LED_on();
-	} else if (STATUS_LED_GREEN == mask) {
-		if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
-			green_LED_off();
-		else
-			green_LED_on();
-	}
+	register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
+
+	writel(readl(&gpio->pedr) ^ GPIO_PIN(mask), &gpio->pedr);
 }
 
 void __led_set(led_id_t mask, int state)