blob: 402fa3a7bc960f70d93374cd885b5f20623a4afd [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
Uri Mashiach4892d392017-01-19 10:51:45 +020012static uint8_t saved_state[2] = {CONFIG_LED_STATUS_OFF, CONFIG_LED_STATUS_OFF};
13static uint32_t gpio_pin[2] = {1 << CONFIG_LED_STATUS_GREEN,
14 1 << CONFIG_LED_STATUS_RED};
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010015
Tom Rinicedfdb02015-11-28 08:04:43 -050016static inline void switch_LED_on(uint8_t led)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010017{
18 register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
19
20 writel(readl(&gpio->pedr) | gpio_pin[led], &gpio->pedr);
Uri Mashiach4892d392017-01-19 10:51:45 +020021 saved_state[led] = CONFIG_LED_STATUS_ON;
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010022}
23
Tom Rinicedfdb02015-11-28 08:04:43 -050024static inline void switch_LED_off(uint8_t led)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010025{
26 register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
27
28 writel(readl(&gpio->pedr) & ~gpio_pin[led], &gpio->pedr);
Uri Mashiach4892d392017-01-19 10:51:45 +020029 saved_state[led] = CONFIG_LED_STATUS_OFF;
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010030}
31
Jason Kridneraff0aa82011-09-04 14:40:16 -040032void red_led_on(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010033{
Uri Mashiach4892d392017-01-19 10:51:45 +020034 switch_LED_on(CONFIG_LED_STATUS_RED);
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010035}
36
Jason Kridneraff0aa82011-09-04 14:40:16 -040037void red_led_off(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010038{
Uri Mashiach4892d392017-01-19 10:51:45 +020039 switch_LED_off(CONFIG_LED_STATUS_RED);
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010040}
41
Jason Kridneraff0aa82011-09-04 14:40:16 -040042void green_led_on(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010043{
Uri Mashiach4892d392017-01-19 10:51:45 +020044 switch_LED_on(CONFIG_LED_STATUS_GREEN);
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010045}
46
Jason Kridneraff0aa82011-09-04 14:40:16 -040047void green_led_off(void)
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010048{
Uri Mashiach4892d392017-01-19 10:51:45 +020049 switch_LED_off(CONFIG_LED_STATUS_GREEN);
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010050}
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{
Uri Mashiach4892d392017-01-19 10:51:45 +020059 if (CONFIG_LED_STATUS_RED == mask) {
60 if (CONFIG_LED_STATUS_ON == saved_state[CONFIG_LED_STATUS_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();
Uri Mashiach4892d392017-01-19 10:51:45 +020064 } else if (CONFIG_LED_STATUS_GREEN == mask) {
65 if (CONFIG_LED_STATUS_ON ==
66 saved_state[CONFIG_LED_STATUS_GREEN])
Jason Kridneraff0aa82011-09-04 14:40:16 -040067 green_led_off();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010068 else
Jason Kridneraff0aa82011-09-04 14:40:16 -040069 green_led_on();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010070 }
71}
72
73void __led_set(led_id_t mask, int state)
74{
Uri Mashiach4892d392017-01-19 10:51:45 +020075 if (CONFIG_LED_STATUS_RED == mask) {
76 if (CONFIG_LED_STATUS_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -040077 red_led_on();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010078 else
Jason Kridneraff0aa82011-09-04 14:40:16 -040079 red_led_off();
Uri Mashiach4892d392017-01-19 10:51:45 +020080 } else if (CONFIG_LED_STATUS_GREEN == mask) {
81 if (CONFIG_LED_STATUS_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -040082 green_led_on();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010083 else
Jason Kridneraff0aa82011-09-04 14:40:16 -040084 green_led_off();
Matthias Kaehlcke195dbd12010-02-01 21:29:39 +010085 }
86}