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 | |
| 12 | static uint8_t saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF}; |
| 13 | static uint32_t gpio_pin[2] = {1 << STATUS_LED_GREEN, |
| 14 | 1 << STATUS_LED_RED}; |
| 15 | |
| 16 | inline 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 | |
| 24 | inline 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 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 | { |
| 34 | switch_LED_on(STATUS_LED_RED); |
| 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 | { |
| 39 | switch_LED_off(STATUS_LED_RED); |
| 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 | { |
| 44 | switch_LED_on(STATUS_LED_GREEN); |
| 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 | { |
| 49 | switch_LED_off(STATUS_LED_GREEN); |
| 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 | { |
| 59 | if (STATUS_LED_RED == mask) { |
| 60 | if (STATUS_LED_ON == saved_state[STATUS_LED_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(); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 64 | } else if (STATUS_LED_GREEN == mask) { |
| 65 | if (STATUS_LED_ON == saved_state[STATUS_LED_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 | { |
| 74 | if (STATUS_LED_RED == mask) { |
| 75 | if (STATUS_LED_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(); |
Matthias Kaehlcke | 195dbd1 | 2010-02-01 21:29:39 +0100 | [diff] [blame] | 79 | } else if (STATUS_LED_GREEN == mask) { |
| 80 | if (STATUS_LED_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 | } |