xref: /openbmc/u-boot/arch/arm/cpu/arm920t/ep93xx/led.c (revision e9c847c3)
1 /*
2  * Copyright (C) 2010, 2009 Matthias Kaehlcke <matthias@kaehlcke.net>
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <asm/io.h>
8 #include <asm/arch/ep93xx.h>
9 #include <config.h>
10 #include <status_led.h>
11 
12 static uint8_t saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF};
13 static uint32_t gpio_pin[2] = {1 << STATUS_LED_GREEN,
14 			       1 << STATUS_LED_RED};
15 
16 static inline void switch_LED_on(uint8_t led)
17 {
18 	register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
19 
20 	writel(readl(&gpio->pedr) | gpio_pin[led], &gpio->pedr);
21 	saved_state[led] = STATUS_LED_ON;
22 }
23 
24 static inline void switch_LED_off(uint8_t led)
25 {
26 	register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
27 
28 	writel(readl(&gpio->pedr) & ~gpio_pin[led], &gpio->pedr);
29 	saved_state[led] = STATUS_LED_OFF;
30 }
31 
32 void red_led_on(void)
33 {
34 	switch_LED_on(STATUS_LED_RED);
35 }
36 
37 void red_led_off(void)
38 {
39 	switch_LED_off(STATUS_LED_RED);
40 }
41 
42 void green_led_on(void)
43 {
44 	switch_LED_on(STATUS_LED_GREEN);
45 }
46 
47 void green_led_off(void)
48 {
49 	switch_LED_off(STATUS_LED_GREEN);
50 }
51 
52 void __led_init(led_id_t mask, int state)
53 {
54 	__led_set(mask, state);
55 }
56 
57 void __led_toggle(led_id_t mask)
58 {
59 	if (STATUS_LED_RED == mask) {
60 		if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
61 			red_led_off();
62 		else
63 			red_led_on();
64 	} else if (STATUS_LED_GREEN == mask) {
65 		if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
66 			green_led_off();
67 		else
68 			green_led_on();
69 	}
70 }
71 
72 void __led_set(led_id_t mask, int state)
73 {
74 	if (STATUS_LED_RED == mask) {
75 		if (STATUS_LED_ON == state)
76 			red_led_on();
77 		else
78 			red_led_off();
79 	} else if (STATUS_LED_GREEN == mask) {
80 		if (STATUS_LED_ON == state)
81 			green_led_on();
82 		else
83 			green_led_off();
84 	}
85 }
86