Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009 Wind River Systems, Inc. |
| 3 | * Tom Rix <Tom.Rix@windriver.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of |
| 8 | * the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 18 | * MA 02111-1307 USA |
| 19 | */ |
| 20 | #include <common.h> |
| 21 | #include <status_led.h> |
| 22 | #include <asm/arch/cpu.h> |
| 23 | #include <asm/io.h> |
| 24 | #include <asm/arch/sys_proto.h> |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 25 | #include <asm/gpio.h> |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 26 | |
| 27 | static unsigned int saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF}; |
| 28 | |
| 29 | /* |
| 30 | * GPIO LEDs |
| 31 | * 173 red |
| 32 | * 154 blue |
| 33 | * 61 blue2 |
| 34 | */ |
| 35 | #define ZOOM2_LED_RED 173 |
| 36 | #define ZOOM2_LED_BLUE 154 |
| 37 | #define ZOOM2_LED_BLUE2 61 |
| 38 | |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 39 | void red_led_off(void) |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 40 | { |
| 41 | /* red */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 42 | if (!gpio_request(ZOOM2_LED_RED, "")) { |
| 43 | gpio_direction_output(ZOOM2_LED_RED, 0); |
| 44 | gpio_set_value(ZOOM2_LED_RED, 0); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 45 | } |
| 46 | saved_state[STATUS_LED_RED] = STATUS_LED_OFF; |
| 47 | } |
| 48 | |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 49 | void blue_led_off(void) |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 50 | { |
| 51 | /* blue */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 52 | if (!gpio_request(ZOOM2_LED_BLUE, "")) { |
| 53 | gpio_direction_output(ZOOM2_LED_BLUE, 0); |
| 54 | gpio_set_value(ZOOM2_LED_BLUE, 0); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /* blue 2 */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 58 | if (!gpio_request(ZOOM2_LED_BLUE2, "")) { |
| 59 | gpio_direction_output(ZOOM2_LED_BLUE2, 0); |
| 60 | gpio_set_value(ZOOM2_LED_BLUE2, 0); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 61 | } |
| 62 | saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF; |
| 63 | } |
| 64 | |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 65 | void red_led_on(void) |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 66 | { |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 67 | blue_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 68 | |
| 69 | /* red */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 70 | if (!gpio_request(ZOOM2_LED_RED, "")) { |
| 71 | gpio_direction_output(ZOOM2_LED_RED, 0); |
| 72 | gpio_set_value(ZOOM2_LED_RED, 1); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 73 | } |
| 74 | saved_state[STATUS_LED_RED] = STATUS_LED_ON; |
| 75 | } |
| 76 | |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 77 | void blue_led_on(void) |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 78 | { |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 79 | red_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 80 | |
| 81 | /* blue */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 82 | if (!gpio_request(ZOOM2_LED_BLUE, "")) { |
| 83 | gpio_direction_output(ZOOM2_LED_BLUE, 0); |
| 84 | gpio_set_value(ZOOM2_LED_BLUE, 1); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* blue 2 */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 88 | if (!gpio_request(ZOOM2_LED_BLUE2, "")) { |
| 89 | gpio_direction_output(ZOOM2_LED_BLUE2, 0); |
| 90 | gpio_set_value(ZOOM2_LED_BLUE2, 1); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | saved_state[STATUS_LED_BLUE] = STATUS_LED_ON; |
| 94 | } |
| 95 | |
| 96 | void __led_init (led_id_t mask, int state) |
| 97 | { |
| 98 | __led_set (mask, state); |
| 99 | } |
| 100 | |
| 101 | void __led_toggle (led_id_t mask) |
| 102 | { |
| 103 | if (STATUS_LED_BLUE == mask) { |
| 104 | if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE]) |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 105 | blue_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 106 | else |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 107 | blue_led_on(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 108 | } else if (STATUS_LED_RED == mask) { |
| 109 | if (STATUS_LED_ON == saved_state[STATUS_LED_RED]) |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 110 | red_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 111 | else |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 112 | red_led_on(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | void __led_set (led_id_t mask, int state) |
| 117 | { |
| 118 | if (STATUS_LED_BLUE == mask) { |
| 119 | if (STATUS_LED_ON == state) |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 120 | blue_led_on(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 121 | else |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 122 | blue_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 123 | } else if (STATUS_LED_RED == mask) { |
| 124 | if (STATUS_LED_ON == state) |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 125 | red_led_on(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 126 | else |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 127 | red_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 128 | } |
| 129 | } |