blob: 434cffbd26844bfe5b6948c3e8a0c225eec5d0f6 [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>
Eric Benard5affc632011-06-06 22:48:28 +000031#include <asm/io.h>
Tom Rix799a05b2009-09-27 11:10:09 -050032
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{
Eric Benard5affc632011-06-06 22:48:28 +000038 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Eric Benard083d32f2011-04-03 06:35:54 +000039
Tom Rix799a05b2009-09-27 11:10:09 -050040 /* Enable clock */
Eric Benard5affc632011-06-06 22:48:28 +000041 writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
Tom Rix799a05b2009-09-27 11:10:09 -050042
Eric Benard083d32f2011-04-03 06:35:54 +000043 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 Rix799a05b2009-09-27 11:10:09 -050047
Eric Benard083d32f2011-04-03 06:35:54 +000048 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 Rix799a05b2009-09-27 11:10:09 -050052}
53
Jason Kridneraff0aa82011-09-04 14:40:16 -040054void red_led_off(void)
Tom Rix799a05b2009-09-27 11:10:09 -050055{
Eric Benard083d32f2011-04-03 06:35:54 +000056 at91_set_pio_value(CONFIG_RED_LED, 1);
Tom Rix799a05b2009-09-27 11:10:09 -050057 saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
58}
59
Jason Kridneraff0aa82011-09-04 14:40:16 -040060void green_led_off(void)
Tom Rix799a05b2009-09-27 11:10:09 -050061{
Eric Benard083d32f2011-04-03 06:35:54 +000062 at91_set_pio_value(CONFIG_GREEN_LED, 1);
Tom Rix799a05b2009-09-27 11:10:09 -050063 saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF;
64}
65
Jason Kridneraff0aa82011-09-04 14:40:16 -040066void yellow_led_off(void)
Tom Rix799a05b2009-09-27 11:10:09 -050067{
Eric Benard083d32f2011-04-03 06:35:54 +000068 at91_set_pio_value(CONFIG_YELLOW_LED, 1);
Tom Rix799a05b2009-09-27 11:10:09 -050069 saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF;
70}
71
Jason Kridneraff0aa82011-09-04 14:40:16 -040072void blue_led_off(void)
Tom Rix799a05b2009-09-27 11:10:09 -050073{
Eric Benard083d32f2011-04-03 06:35:54 +000074 at91_set_pio_value(CONFIG_BLUE_LED, 1);
Tom Rix799a05b2009-09-27 11:10:09 -050075 saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF;
76}
77
Jason Kridneraff0aa82011-09-04 14:40:16 -040078void red_led_on(void)
Tom Rix799a05b2009-09-27 11:10:09 -050079{
Eric Benard083d32f2011-04-03 06:35:54 +000080 at91_set_pio_value(CONFIG_RED_LED, 0);
Tom Rix799a05b2009-09-27 11:10:09 -050081 saved_state[STATUS_LED_RED] = STATUS_LED_ON;
82}
83
Jason Kridneraff0aa82011-09-04 14:40:16 -040084void green_led_on(void)
Tom Rix799a05b2009-09-27 11:10:09 -050085{
Eric Benard083d32f2011-04-03 06:35:54 +000086 at91_set_pio_value(CONFIG_GREEN_LED, 0);
Tom Rix799a05b2009-09-27 11:10:09 -050087 saved_state[STATUS_LED_GREEN] = STATUS_LED_ON;
88}
89
Jason Kridneraff0aa82011-09-04 14:40:16 -040090void yellow_led_on(void)
Tom Rix799a05b2009-09-27 11:10:09 -050091{
Eric Benard083d32f2011-04-03 06:35:54 +000092 at91_set_pio_value(CONFIG_YELLOW_LED, 0);
Tom Rix799a05b2009-09-27 11:10:09 -050093 saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON;
94}
95
Jason Kridneraff0aa82011-09-04 14:40:16 -040096void blue_led_on(void)
Tom Rix799a05b2009-09-27 11:10:09 -050097{
Eric Benard083d32f2011-04-03 06:35:54 +000098 at91_set_pio_value(CONFIG_BLUE_LED, 0);
Tom Rix799a05b2009-09-27 11:10:09 -050099 saved_state[STATUS_LED_BLUE] = STATUS_LED_ON;
100}
101
102void __led_init(led_id_t mask, int state)
103{
104 __led_set(mask, state);
105}
106
107void __led_toggle(led_id_t mask)
108{
109 if (STATUS_LED_BLUE == mask) {
110 if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE])
Jason Kridneraff0aa82011-09-04 14:40:16 -0400111 blue_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500112 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400113 blue_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500114 } else if (STATUS_LED_RED == mask) {
115 if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
Jason Kridneraff0aa82011-09-04 14:40:16 -0400116 red_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500117 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400118 red_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500119 } else if (STATUS_LED_GREEN == mask) {
120 if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
Jason Kridneraff0aa82011-09-04 14:40:16 -0400121 green_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500122 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400123 green_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500124 } else if (STATUS_LED_YELLOW == mask) {
125 if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW])
Jason Kridneraff0aa82011-09-04 14:40:16 -0400126 yellow_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500127 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400128 yellow_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500129 }
130}
131
132void __led_set(led_id_t mask, int state)
133{
134 if (STATUS_LED_BLUE == mask) {
135 if (STATUS_LED_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -0400136 blue_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500137 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400138 blue_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500139 } else if (STATUS_LED_RED == mask) {
140 if (STATUS_LED_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -0400141 red_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500142 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400143 red_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500144 } else if (STATUS_LED_GREEN == mask) {
145 if (STATUS_LED_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -0400146 green_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500147 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400148 green_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500149 } else if (STATUS_LED_YELLOW == mask) {
150 if (STATUS_LED_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -0400151 yellow_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500152 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400153 yellow_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500154 }
155}