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