blob: 197b4da5f06f0901474db3306151ce638f3214c7 [file] [log] [blame]
Markus Hubig2399ef72012-08-07 17:43:23 +02001/*
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 * (C) Copyright 2012
8 * Markus Hubig <mhubig@imko.de>
9 * IMKO GmbH <www.imko.de>
10 *
11 * See file CREDITS for list of people who contributed to this
12 * project.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
28 */
29
30#include <common.h>
31#include <asm/io.h>
32#include <asm/arch/gpio.h>
33#include <asm/arch/at91_pmc.h>
34#include <status_led.h>
35
36static unsigned int saved_state[3] = {STATUS_LED_OFF,
37 STATUS_LED_OFF, STATUS_LED_OFF};
38
39void coloured_LED_init(void)
40{
41 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
42
43 /* Enable the clock */
44 writel(ATMEL_ID_PIOC, &pmc->pcer);
45
46 at91_set_gpio_output(CONFIG_RED_LED, 1);
47 at91_set_gpio_output(CONFIG_GREEN_LED, 1);
48 at91_set_gpio_output(CONFIG_YELLOW_LED, 1);
49
50 at91_set_gpio_value(CONFIG_RED_LED, 0);
51 at91_set_gpio_value(CONFIG_GREEN_LED, 1);
52 at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
53}
54
55void red_led_on(void)
56{
57 at91_set_gpio_value(CONFIG_RED_LED, 1);
58 saved_state[STATUS_LED_RED] = STATUS_LED_ON;
59}
60
61void red_led_off(void)
62{
63 at91_set_gpio_value(CONFIG_RED_LED, 0);
64 saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
65}
66
67void green_led_on(void)
68{
69 at91_set_gpio_value(CONFIG_GREEN_LED, 1);
70 saved_state[STATUS_LED_GREEN] = STATUS_LED_ON;
71}
72
73void green_led_off(void)
74{
75 at91_set_gpio_value(CONFIG_GREEN_LED, 0);
76 saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF;
77}
78
79void yellow_led_on(void)
80{
81 at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
82 saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON;
83}
84
85void yellow_led_off(void)
86{
87 at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
88 saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF;
89}
90
91void __led_init(led_id_t mask, int state)
92{
93 __led_set(mask, state);
94}
95
96void __led_toggle(led_id_t mask)
97{
98 if (STATUS_LED_RED == mask) {
99 if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
100 red_led_off();
101 else
102 red_led_on();
103
104 } else if (STATUS_LED_GREEN == mask) {
105 if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
106 green_led_off();
107 else
108 green_led_on();
109
110 } else if (STATUS_LED_YELLOW == mask) {
111 if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW])
112 yellow_led_off();
113 else
114 yellow_led_on();
115 }
116}
117
118void __led_set(led_id_t mask, int state)
119{
120 if (STATUS_LED_RED == mask) {
121 if (STATUS_LED_ON == state)
122 red_led_on();
123 else
124 red_led_off();
125
126 } else if (STATUS_LED_GREEN == mask) {
127 if (STATUS_LED_ON == state)
128 green_led_on();
129 else
130 green_led_off();
131
132 } else if (STATUS_LED_YELLOW == mask) {
133 if (STATUS_LED_ON == state)
134 yellow_led_on();
135 else
136 yellow_led_off();
137 }
138}