blob: 61447291854fb0ae047972679bf50607331cae35 [file] [log] [blame]
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +01001/*
2 * Copyright (C) 2010, 2009 Matthias Kaehlcke <matthias@kaehlcke.net>
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +01005 */
6
7#include <asm/io.h>
8#include <asm/arch/ep93xx.h>
9#include <config.h>
10#include <status_led.h>
11
12static uint8_t saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF};
13static uint32_t gpio_pin[2] = {1 << STATUS_LED_GREEN,
14 1 << STATUS_LED_RED};
15
16inline 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
24inline 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
Jason Kridneraff0aa82011-09-04 14:40:16 -040032void red_led_on(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010033{
34 switch_LED_on(STATUS_LED_RED);
35}
36
Jason Kridneraff0aa82011-09-04 14:40:16 -040037void red_led_off(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010038{
39 switch_LED_off(STATUS_LED_RED);
40}
41
Jason Kridneraff0aa82011-09-04 14:40:16 -040042void green_led_on(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010043{
44 switch_LED_on(STATUS_LED_GREEN);
45}
46
Jason Kridneraff0aa82011-09-04 14:40:16 -040047void green_led_off(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010048{
49 switch_LED_off(STATUS_LED_GREEN);
50}
51
52void __led_init(led_id_t mask, int state)
53{
54 __led_set(mask, state);
55}
56
57void __led_toggle(led_id_t mask)
58{
59 if (STATUS_LED_RED == mask) {
60 if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
Jason Kridneraff0aa82011-09-04 14:40:16 -040061 red_led_off();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010062 else
Jason Kridneraff0aa82011-09-04 14:40:16 -040063 red_led_on();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010064 } else if (STATUS_LED_GREEN == mask) {
65 if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
Jason Kridneraff0aa82011-09-04 14:40:16 -040066 green_led_off();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010067 else
Jason Kridneraff0aa82011-09-04 14:40:16 -040068 green_led_on();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010069 }
70}
71
72void __led_set(led_id_t mask, int state)
73{
74 if (STATUS_LED_RED == mask) {
75 if (STATUS_LED_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -040076 red_led_on();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010077 else
Jason Kridneraff0aa82011-09-04 14:40:16 -040078 red_led_off();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010079 } else if (STATUS_LED_GREEN == mask) {
80 if (STATUS_LED_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -040081 green_led_on();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010082 else
Jason Kridneraff0aa82011-09-04 14:40:16 -040083 green_led_off();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010084 }
85}