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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
| 8 | #include <status_led.h> |
| 9 | #include <asm/arch/cpu.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/sys_proto.h> |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 12 | #include <asm/gpio.h> |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 13 | |
| 14 | static unsigned int saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF}; |
| 15 | |
| 16 | /* |
| 17 | * GPIO LEDs |
| 18 | * 173 red |
| 19 | * 154 blue |
| 20 | * 61 blue2 |
| 21 | */ |
| 22 | #define ZOOM2_LED_RED 173 |
| 23 | #define ZOOM2_LED_BLUE 154 |
| 24 | #define ZOOM2_LED_BLUE2 61 |
| 25 | |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 26 | void red_led_off(void) |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 27 | { |
| 28 | /* red */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 29 | if (!gpio_request(ZOOM2_LED_RED, "")) { |
| 30 | gpio_direction_output(ZOOM2_LED_RED, 0); |
| 31 | gpio_set_value(ZOOM2_LED_RED, 0); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 32 | } |
| 33 | saved_state[STATUS_LED_RED] = STATUS_LED_OFF; |
| 34 | } |
| 35 | |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 36 | void blue_led_off(void) |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 37 | { |
| 38 | /* blue */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 39 | if (!gpio_request(ZOOM2_LED_BLUE, "")) { |
| 40 | gpio_direction_output(ZOOM2_LED_BLUE, 0); |
| 41 | gpio_set_value(ZOOM2_LED_BLUE, 0); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /* blue 2 */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 45 | if (!gpio_request(ZOOM2_LED_BLUE2, "")) { |
| 46 | gpio_direction_output(ZOOM2_LED_BLUE2, 0); |
| 47 | gpio_set_value(ZOOM2_LED_BLUE2, 0); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 48 | } |
| 49 | saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF; |
| 50 | } |
| 51 | |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 52 | void red_led_on(void) |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 53 | { |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 54 | blue_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 55 | |
| 56 | /* red */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 57 | if (!gpio_request(ZOOM2_LED_RED, "")) { |
| 58 | gpio_direction_output(ZOOM2_LED_RED, 0); |
| 59 | gpio_set_value(ZOOM2_LED_RED, 1); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 60 | } |
| 61 | saved_state[STATUS_LED_RED] = STATUS_LED_ON; |
| 62 | } |
| 63 | |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 64 | void blue_led_on(void) |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 65 | { |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 66 | red_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 67 | |
| 68 | /* blue */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 69 | if (!gpio_request(ZOOM2_LED_BLUE, "")) { |
| 70 | gpio_direction_output(ZOOM2_LED_BLUE, 0); |
| 71 | gpio_set_value(ZOOM2_LED_BLUE, 1); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /* blue 2 */ |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 75 | if (!gpio_request(ZOOM2_LED_BLUE2, "")) { |
| 76 | gpio_direction_output(ZOOM2_LED_BLUE2, 0); |
| 77 | gpio_set_value(ZOOM2_LED_BLUE2, 1); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | saved_state[STATUS_LED_BLUE] = STATUS_LED_ON; |
| 81 | } |
| 82 | |
| 83 | void __led_init (led_id_t mask, int state) |
| 84 | { |
| 85 | __led_set (mask, state); |
| 86 | } |
| 87 | |
| 88 | void __led_toggle (led_id_t mask) |
| 89 | { |
| 90 | if (STATUS_LED_BLUE == mask) { |
| 91 | if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE]) |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 92 | blue_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 93 | else |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 94 | blue_led_on(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 95 | } else if (STATUS_LED_RED == mask) { |
| 96 | if (STATUS_LED_ON == saved_state[STATUS_LED_RED]) |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 97 | red_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 98 | else |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 99 | red_led_on(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
| 103 | void __led_set (led_id_t mask, int state) |
| 104 | { |
| 105 | if (STATUS_LED_BLUE == mask) { |
| 106 | if (STATUS_LED_ON == state) |
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 |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 109 | blue_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 110 | } else if (STATUS_LED_RED == mask) { |
| 111 | if (STATUS_LED_ON == state) |
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 | else |
Jason Kridner | 2d3be7c | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 114 | red_led_off(); |
Tom Rix | 83ae698 | 2009-05-31 12:44:39 +0200 | [diff] [blame] | 115 | } |
| 116 | } |