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