]>
Commit | Line | Data |
---|---|---|
23b80982 TR |
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> | |
95d50e5c | 31 | #include <asm/io.h> |
23b80982 TR |
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 | { | |
95d50e5c | 38 | at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC; |
c2b2a07e | 39 | |
23b80982 | 40 | /* Enable clock */ |
95d50e5c | 41 | writel(1 << ATMEL_ID_PIOC, &pmc->pcer); |
23b80982 | 42 | |
c2b2a07e EB |
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); | |
23b80982 | 47 | |
c2b2a07e EB |
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); | |
23b80982 TR |
52 | } |
53 | ||
54 | void red_LED_off(void) | |
55 | { | |
c2b2a07e | 56 | at91_set_pio_value(CONFIG_RED_LED, 1); |
23b80982 TR |
57 | saved_state[STATUS_LED_RED] = STATUS_LED_OFF; |
58 | } | |
59 | ||
60 | void green_LED_off(void) | |
61 | { | |
c2b2a07e | 62 | at91_set_pio_value(CONFIG_GREEN_LED, 1); |
23b80982 TR |
63 | saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF; |
64 | } | |
65 | ||
66 | void yellow_LED_off(void) | |
67 | { | |
c2b2a07e | 68 | at91_set_pio_value(CONFIG_YELLOW_LED, 1); |
23b80982 TR |
69 | saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF; |
70 | } | |
71 | ||
72 | void blue_LED_off(void) | |
73 | { | |
c2b2a07e | 74 | at91_set_pio_value(CONFIG_BLUE_LED, 1); |
23b80982 TR |
75 | saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF; |
76 | } | |
77 | ||
78 | void red_LED_on(void) | |
79 | { | |
c2b2a07e | 80 | at91_set_pio_value(CONFIG_RED_LED, 0); |
23b80982 TR |
81 | saved_state[STATUS_LED_RED] = STATUS_LED_ON; |
82 | } | |
83 | ||
84 | void green_LED_on(void) | |
85 | { | |
c2b2a07e | 86 | at91_set_pio_value(CONFIG_GREEN_LED, 0); |
23b80982 TR |
87 | saved_state[STATUS_LED_GREEN] = STATUS_LED_ON; |
88 | } | |
89 | ||
90 | void yellow_LED_on(void) | |
91 | { | |
c2b2a07e | 92 | at91_set_pio_value(CONFIG_YELLOW_LED, 0); |
23b80982 TR |
93 | saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON; |
94 | } | |
95 | ||
96 | void blue_LED_on(void) | |
97 | { | |
c2b2a07e | 98 | at91_set_pio_value(CONFIG_BLUE_LED, 0); |
23b80982 TR |
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]) | |
111 | blue_LED_off(); | |
112 | else | |
113 | blue_LED_on(); | |
114 | } else if (STATUS_LED_RED == mask) { | |
115 | if (STATUS_LED_ON == saved_state[STATUS_LED_RED]) | |
116 | red_LED_off(); | |
117 | else | |
118 | red_LED_on(); | |
119 | } else if (STATUS_LED_GREEN == mask) { | |
120 | if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN]) | |
121 | green_LED_off(); | |
122 | else | |
123 | green_LED_on(); | |
124 | } else if (STATUS_LED_YELLOW == mask) { | |
125 | if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW]) | |
126 | yellow_LED_off(); | |
127 | else | |
128 | yellow_LED_on(); | |
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) | |
136 | blue_LED_on(); | |
137 | else | |
138 | blue_LED_off(); | |
139 | } else if (STATUS_LED_RED == mask) { | |
140 | if (STATUS_LED_ON == state) | |
141 | red_LED_on(); | |
142 | else | |
143 | red_LED_off(); | |
144 | } else if (STATUS_LED_GREEN == mask) { | |
145 | if (STATUS_LED_ON == state) | |
146 | green_LED_on(); | |
147 | else | |
148 | green_LED_off(); | |
149 | } else if (STATUS_LED_YELLOW == mask) { | |
150 | if (STATUS_LED_ON == state) | |
151 | yellow_LED_on(); | |
152 | else | |
153 | yellow_LED_off(); | |
154 | } | |
155 | } |