blob: 862663acbab5a3f505e130ce64d3e0f2479713d8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +01002/*
3 * Copyright (C) 2010, 2009 Matthias Kaehlcke <matthias@kaehlcke.net>
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +01004 */
5
6#include <asm/io.h>
7#include <asm/arch/ep93xx.h>
8#include <config.h>
9#include <status_led.h>
10
Uri Mashiach4892d392017-01-19 10:51:45 +020011static uint8_t saved_state[2] = {CONFIG_LED_STATUS_OFF, CONFIG_LED_STATUS_OFF};
12static uint32_t gpio_pin[2] = {1 << CONFIG_LED_STATUS_GREEN,
13 1 << CONFIG_LED_STATUS_RED};
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010014
Tom Rinicedfdb02015-11-28 08:04:43 -050015static inline void switch_LED_on(uint8_t led)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010016{
17 register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
18
19 writel(readl(&gpio->pedr) | gpio_pin[led], &gpio->pedr);
Uri Mashiach4892d392017-01-19 10:51:45 +020020 saved_state[led] = CONFIG_LED_STATUS_ON;
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010021}
22
Tom Rinicedfdb02015-11-28 08:04:43 -050023static inline void switch_LED_off(uint8_t led)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010024{
25 register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
26
27 writel(readl(&gpio->pedr) & ~gpio_pin[led], &gpio->pedr);
Uri Mashiach4892d392017-01-19 10:51:45 +020028 saved_state[led] = CONFIG_LED_STATUS_OFF;
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010029}
30
Jason Kridneraff0aa82011-09-04 14:40:16 -040031void red_led_on(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010032{
Uri Mashiach4892d392017-01-19 10:51:45 +020033 switch_LED_on(CONFIG_LED_STATUS_RED);
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010034}
35
Jason Kridneraff0aa82011-09-04 14:40:16 -040036void red_led_off(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010037{
Uri Mashiach4892d392017-01-19 10:51:45 +020038 switch_LED_off(CONFIG_LED_STATUS_RED);
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010039}
40
Jason Kridneraff0aa82011-09-04 14:40:16 -040041void green_led_on(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010042{
Uri Mashiach4892d392017-01-19 10:51:45 +020043 switch_LED_on(CONFIG_LED_STATUS_GREEN);
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010044}
45
Jason Kridneraff0aa82011-09-04 14:40:16 -040046void green_led_off(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010047{
Uri Mashiach4892d392017-01-19 10:51:45 +020048 switch_LED_off(CONFIG_LED_STATUS_GREEN);
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010049}
50
51void __led_init(led_id_t mask, int state)
52{
53 __led_set(mask, state);
54}
55
56void __led_toggle(led_id_t mask)
57{
Uri Mashiach4892d392017-01-19 10:51:45 +020058 if (CONFIG_LED_STATUS_RED == mask) {
59 if (CONFIG_LED_STATUS_ON == saved_state[CONFIG_LED_STATUS_RED])
Jason Kridneraff0aa82011-09-04 14:40:16 -040060 red_led_off();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010061 else
Jason Kridneraff0aa82011-09-04 14:40:16 -040062 red_led_on();
Uri Mashiach4892d392017-01-19 10:51:45 +020063 } else if (CONFIG_LED_STATUS_GREEN == mask) {
64 if (CONFIG_LED_STATUS_ON ==
65 saved_state[CONFIG_LED_STATUS_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{
Uri Mashiach4892d392017-01-19 10:51:45 +020074 if (CONFIG_LED_STATUS_RED == mask) {
75 if (CONFIG_LED_STATUS_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();
Uri Mashiach4892d392017-01-19 10:51:45 +020079 } else if (CONFIG_LED_STATUS_GREEN == mask) {
80 if (CONFIG_LED_STATUS_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}