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] = {CONFIG_LED_STATUS_OFF, CONFIG_LED_STATUS_OFF};
13 static uint32_t gpio_pin[2] = {1 << CONFIG_LED_STATUS_GREEN,
14 1 << CONFIG_LED_STATUS_RED};
15
switch_LED_on(uint8_t led)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] = CONFIG_LED_STATUS_ON;
22 }
23
switch_LED_off(uint8_t led)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] = CONFIG_LED_STATUS_OFF;
30 }
31
red_led_on(void)32 void red_led_on(void)
33 {
34 switch_LED_on(CONFIG_LED_STATUS_RED);
35 }
36
red_led_off(void)37 void red_led_off(void)
38 {
39 switch_LED_off(CONFIG_LED_STATUS_RED);
40 }
41
green_led_on(void)42 void green_led_on(void)
43 {
44 switch_LED_on(CONFIG_LED_STATUS_GREEN);
45 }
46
green_led_off(void)47 void green_led_off(void)
48 {
49 switch_LED_off(CONFIG_LED_STATUS_GREEN);
50 }
51
__led_init(led_id_t mask,int state)52 void __led_init(led_id_t mask, int state)
53 {
54 __led_set(mask, state);
55 }
56
__led_toggle(led_id_t mask)57 void __led_toggle(led_id_t mask)
58 {
59 if (CONFIG_LED_STATUS_RED == mask) {
60 if (CONFIG_LED_STATUS_ON == saved_state[CONFIG_LED_STATUS_RED])
61 red_led_off();
62 else
63 red_led_on();
64 } else if (CONFIG_LED_STATUS_GREEN == mask) {
65 if (CONFIG_LED_STATUS_ON ==
66 saved_state[CONFIG_LED_STATUS_GREEN])
67 green_led_off();
68 else
69 green_led_on();
70 }
71 }
72
__led_set(led_id_t mask,int state)73 void __led_set(led_id_t mask, int state)
74 {
75 if (CONFIG_LED_STATUS_RED == mask) {
76 if (CONFIG_LED_STATUS_ON == state)
77 red_led_on();
78 else
79 red_led_off();
80 } else if (CONFIG_LED_STATUS_GREEN == mask) {
81 if (CONFIG_LED_STATUS_ON == state)
82 green_led_on();
83 else
84 green_led_off();
85 }
86 }
87