blob: e73543bb12736e2a3052b45f9d6a810480cea541 [file] [log] [blame]
Tom Rix799a05b2009-09-27 11:10:09 -05001/*
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>
31#include <asm/arch/io.h>
32
33static unsigned int saved_state[4] = {STATUS_LED_OFF, STATUS_LED_OFF,
34 STATUS_LED_OFF, STATUS_LED_OFF};
35
36void coloured_LED_init(void)
37{
38 /* Enable clock */
39 at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9260_ID_PIOC);
40
41 at91_set_gpio_output(CONFIG_RED_LED, 1);
42 at91_set_gpio_output(CONFIG_GREEN_LED, 1);
43 at91_set_gpio_output(CONFIG_YELLOW_LED, 1);
44 at91_set_gpio_output(CONFIG_BLUE_LED, 1);
45
46 at91_set_gpio_value(CONFIG_RED_LED, 1);
47 at91_set_gpio_value(CONFIG_GREEN_LED, 1);
48 at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
49 at91_set_gpio_value(CONFIG_BLUE_LED, 1);
50}
51
52void red_LED_off(void)
53{
54 at91_set_gpio_value(CONFIG_RED_LED, 1);
55 saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
56}
57
58void green_LED_off(void)
59{
60 at91_set_gpio_value(CONFIG_GREEN_LED, 1);
61 saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF;
62}
63
64void yellow_LED_off(void)
65{
66 at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
67 saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF;
68}
69
70void blue_LED_off(void)
71{
72 at91_set_gpio_value(CONFIG_BLUE_LED, 1);
73 saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF;
74}
75
76void red_LED_on(void)
77{
78 at91_set_gpio_value(CONFIG_RED_LED, 0);
79 saved_state[STATUS_LED_RED] = STATUS_LED_ON;
80}
81
82void green_LED_on(void)
83{
84 at91_set_gpio_value(CONFIG_GREEN_LED, 0);
85 saved_state[STATUS_LED_GREEN] = STATUS_LED_ON;
86}
87
88void yellow_LED_on(void)
89{
90 at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
91 saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON;
92}
93
94void blue_LED_on(void)
95{
96 at91_set_gpio_value(CONFIG_BLUE_LED, 0);
97 saved_state[STATUS_LED_BLUE] = STATUS_LED_ON;
98}
99
100void __led_init(led_id_t mask, int state)
101{
102 __led_set(mask, state);
103}
104
105void __led_toggle(led_id_t mask)
106{
107 if (STATUS_LED_BLUE == mask) {
108 if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE])
109 blue_LED_off();
110 else
111 blue_LED_on();
112 } else if (STATUS_LED_RED == mask) {
113 if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
114 red_LED_off();
115 else
116 red_LED_on();
117 } else if (STATUS_LED_GREEN == mask) {
118 if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
119 green_LED_off();
120 else
121 green_LED_on();
122 } else if (STATUS_LED_YELLOW == mask) {
123 if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW])
124 yellow_LED_off();
125 else
126 yellow_LED_on();
127 }
128}
129
130void __led_set(led_id_t mask, int state)
131{
132 if (STATUS_LED_BLUE == mask) {
133 if (STATUS_LED_ON == state)
134 blue_LED_on();
135 else
136 blue_LED_off();
137 } else if (STATUS_LED_RED == mask) {
138 if (STATUS_LED_ON == state)
139 red_LED_on();
140 else
141 red_LED_off();
142 } else if (STATUS_LED_GREEN == mask) {
143 if (STATUS_LED_ON == state)
144 green_LED_on();
145 else
146 green_LED_off();
147 } else if (STATUS_LED_YELLOW == mask) {
148 if (STATUS_LED_ON == state)
149 yellow_LED_on();
150 else
151 yellow_LED_off();
152 }
153}