Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009 Wind River Systems, Inc. |
| 3 | * Tom Rix <Tom.Rix@windriver.com> |
| 4 | * (C) Copyright 2009 |
| 5 | * Eric Benard <eric@eukrea.com> |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <status_led.h> |
| 28 | #include <asm/arch/at91sam9260.h> |
| 29 | #include <asm/arch/at91_pmc.h> |
| 30 | #include <asm/arch/gpio.h> |
Eric Benard | 5affc63 | 2011-06-06 22:48:28 +0000 | [diff] [blame] | 31 | #include <asm/io.h> |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 32 | |
| 33 | static unsigned int saved_state[4] = {STATUS_LED_OFF, STATUS_LED_OFF, |
| 34 | STATUS_LED_OFF, STATUS_LED_OFF}; |
| 35 | |
| 36 | void coloured_LED_init(void) |
| 37 | { |
Eric Benard | 5affc63 | 2011-06-06 22:48:28 +0000 | [diff] [blame] | 38 | at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC; |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 39 | |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 40 | /* Enable clock */ |
Eric Benard | 5affc63 | 2011-06-06 22:48:28 +0000 | [diff] [blame] | 41 | writel(1 << ATMEL_ID_PIOC, &pmc->pcer); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 42 | |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 43 | at91_set_pio_output(CONFIG_RED_LED, 1); |
| 44 | at91_set_pio_output(CONFIG_GREEN_LED, 1); |
| 45 | at91_set_pio_output(CONFIG_YELLOW_LED, 1); |
| 46 | at91_set_pio_output(CONFIG_BLUE_LED, 1); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 47 | |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 48 | at91_set_pio_value(CONFIG_RED_LED, 1); |
| 49 | at91_set_pio_value(CONFIG_GREEN_LED, 1); |
| 50 | at91_set_pio_value(CONFIG_YELLOW_LED, 1); |
| 51 | at91_set_pio_value(CONFIG_BLUE_LED, 1); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 52 | } |
| 53 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 54 | void red_led_off(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 55 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 56 | at91_set_pio_value(CONFIG_RED_LED, 1); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 57 | saved_state[STATUS_LED_RED] = STATUS_LED_OFF; |
| 58 | } |
| 59 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 60 | void green_led_off(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 61 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 62 | at91_set_pio_value(CONFIG_GREEN_LED, 1); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 63 | saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF; |
| 64 | } |
| 65 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 66 | void yellow_led_off(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 67 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 68 | at91_set_pio_value(CONFIG_YELLOW_LED, 1); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 69 | saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF; |
| 70 | } |
| 71 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 72 | void blue_led_off(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 73 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 74 | at91_set_pio_value(CONFIG_BLUE_LED, 1); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 75 | saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF; |
| 76 | } |
| 77 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 78 | void red_led_on(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 79 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 80 | at91_set_pio_value(CONFIG_RED_LED, 0); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 81 | saved_state[STATUS_LED_RED] = STATUS_LED_ON; |
| 82 | } |
| 83 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 84 | void green_led_on(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 85 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 86 | at91_set_pio_value(CONFIG_GREEN_LED, 0); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 87 | saved_state[STATUS_LED_GREEN] = STATUS_LED_ON; |
| 88 | } |
| 89 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 90 | void yellow_led_on(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 91 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 92 | at91_set_pio_value(CONFIG_YELLOW_LED, 0); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 93 | saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON; |
| 94 | } |
| 95 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 96 | void blue_led_on(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 97 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 98 | at91_set_pio_value(CONFIG_BLUE_LED, 0); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 99 | saved_state[STATUS_LED_BLUE] = STATUS_LED_ON; |
| 100 | } |
| 101 | |
| 102 | void __led_init(led_id_t mask, int state) |
| 103 | { |
| 104 | __led_set(mask, state); |
| 105 | } |
| 106 | |
| 107 | void __led_toggle(led_id_t mask) |
| 108 | { |
| 109 | if (STATUS_LED_BLUE == mask) { |
| 110 | if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE]) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 111 | blue_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 112 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 113 | blue_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 114 | } else if (STATUS_LED_RED == mask) { |
| 115 | if (STATUS_LED_ON == saved_state[STATUS_LED_RED]) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 116 | red_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 117 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 118 | red_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 119 | } else if (STATUS_LED_GREEN == mask) { |
| 120 | if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN]) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 121 | green_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 122 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 123 | green_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 124 | } else if (STATUS_LED_YELLOW == mask) { |
| 125 | if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW]) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 126 | yellow_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 127 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 128 | yellow_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
| 132 | void __led_set(led_id_t mask, int state) |
| 133 | { |
| 134 | if (STATUS_LED_BLUE == mask) { |
| 135 | if (STATUS_LED_ON == state) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 136 | blue_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 137 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 138 | blue_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 139 | } else if (STATUS_LED_RED == mask) { |
| 140 | if (STATUS_LED_ON == state) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 141 | red_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 142 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 143 | red_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 144 | } else if (STATUS_LED_GREEN == mask) { |
| 145 | if (STATUS_LED_ON == state) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 146 | green_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 147 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 148 | green_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 149 | } else if (STATUS_LED_YELLOW == mask) { |
| 150 | if (STATUS_LED_ON == state) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 151 | yellow_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 152 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 153 | yellow_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 154 | } |
| 155 | } |