Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010, 2009 Matthias Kaehlcke <matthias@kaehlcke.net> |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <asm/io.h> |
| 7 | #include <asm/arch/ep93xx.h> |
| 8 | #include <config.h> |
| 9 | #include <status_led.h> |
| 10 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 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}; |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 14 | |
Tom Rini | cedfdb0 | 2015-11-28 08:04:43 -0500 | [diff] [blame] | 15 | static inline void switch_LED_on(uint8_t led) |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 16 | { |
| 17 | register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE; |
| 18 | |
| 19 | writel(readl(&gpio->pedr) | gpio_pin[led], &gpio->pedr); |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 20 | saved_state[led] = CONFIG_LED_STATUS_ON; |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 21 | } |
| 22 | |
Tom Rini | cedfdb0 | 2015-11-28 08:04:43 -0500 | [diff] [blame] | 23 | static inline void switch_LED_off(uint8_t led) |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 24 | { |
| 25 | register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE; |
| 26 | |
| 27 | writel(readl(&gpio->pedr) & ~gpio_pin[led], &gpio->pedr); |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 28 | saved_state[led] = CONFIG_LED_STATUS_OFF; |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 29 | } |
| 30 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 31 | void red_led_on(void) |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 32 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 33 | switch_LED_on(CONFIG_LED_STATUS_RED); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 34 | } |
| 35 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 36 | void red_led_off(void) |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 37 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 38 | switch_LED_off(CONFIG_LED_STATUS_RED); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 41 | void green_led_on(void) |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 42 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 43 | switch_LED_on(CONFIG_LED_STATUS_GREEN); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 46 | void green_led_off(void) |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 47 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 48 | switch_LED_off(CONFIG_LED_STATUS_GREEN); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void __led_init(led_id_t mask, int state) |
| 52 | { |
| 53 | __led_set(mask, state); |
| 54 | } |
| 55 | |
| 56 | void __led_toggle(led_id_t mask) |
| 57 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 58 | if (CONFIG_LED_STATUS_RED == mask) { |
| 59 | if (CONFIG_LED_STATUS_ON == saved_state[CONFIG_LED_STATUS_RED]) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 60 | red_led_off(); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 61 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 62 | red_led_on(); |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 63 | } else if (CONFIG_LED_STATUS_GREEN == mask) { |
| 64 | if (CONFIG_LED_STATUS_ON == |
| 65 | saved_state[CONFIG_LED_STATUS_GREEN]) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 66 | green_led_off(); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 67 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 68 | green_led_on(); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | void __led_set(led_id_t mask, int state) |
| 73 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 74 | if (CONFIG_LED_STATUS_RED == mask) { |
| 75 | if (CONFIG_LED_STATUS_ON == state) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 76 | red_led_on(); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 77 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 78 | red_led_off(); |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 79 | } else if (CONFIG_LED_STATUS_GREEN == mask) { |
| 80 | if (CONFIG_LED_STATUS_ON == state) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 81 | green_led_on(); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 82 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 83 | green_led_off(); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 84 | } |
| 85 | } |