blob: 0cfe0a69fbc0a100d26e8a1fee510ff217f06557 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Tom Rix799a05b2009-09-27 11:10:09 -05008 */
9
10#include <common.h>
11#include <status_led.h>
12#include <asm/arch/at91sam9260.h>
13#include <asm/arch/at91_pmc.h>
14#include <asm/arch/gpio.h>
Eric Benard5affc632011-06-06 22:48:28 +000015#include <asm/io.h>
Tom Rix799a05b2009-09-27 11:10:09 -050016
17static unsigned int saved_state[4] = {STATUS_LED_OFF, STATUS_LED_OFF,
18 STATUS_LED_OFF, STATUS_LED_OFF};
19
20void coloured_LED_init(void)
21{
Eric Benard5affc632011-06-06 22:48:28 +000022 at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
Eric Benard083d32f2011-04-03 06:35:54 +000023
Tom Rix799a05b2009-09-27 11:10:09 -050024 /* Enable clock */
Eric Benard5affc632011-06-06 22:48:28 +000025 writel(1 << ATMEL_ID_PIOC, &pmc->pcer);
Tom Rix799a05b2009-09-27 11:10:09 -050026
Eric Benard083d32f2011-04-03 06:35:54 +000027 at91_set_pio_output(CONFIG_RED_LED, 1);
28 at91_set_pio_output(CONFIG_GREEN_LED, 1);
29 at91_set_pio_output(CONFIG_YELLOW_LED, 1);
30 at91_set_pio_output(CONFIG_BLUE_LED, 1);
Tom Rix799a05b2009-09-27 11:10:09 -050031
Eric Benard083d32f2011-04-03 06:35:54 +000032 at91_set_pio_value(CONFIG_RED_LED, 1);
33 at91_set_pio_value(CONFIG_GREEN_LED, 1);
34 at91_set_pio_value(CONFIG_YELLOW_LED, 1);
35 at91_set_pio_value(CONFIG_BLUE_LED, 1);
Tom Rix799a05b2009-09-27 11:10:09 -050036}
37
Jason Kridneraff0aa82011-09-04 14:40:16 -040038void red_led_off(void)
Tom Rix799a05b2009-09-27 11:10:09 -050039{
Eric Benard083d32f2011-04-03 06:35:54 +000040 at91_set_pio_value(CONFIG_RED_LED, 1);
Tom Rix799a05b2009-09-27 11:10:09 -050041 saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
42}
43
Jason Kridneraff0aa82011-09-04 14:40:16 -040044void green_led_off(void)
Tom Rix799a05b2009-09-27 11:10:09 -050045{
Eric Benard083d32f2011-04-03 06:35:54 +000046 at91_set_pio_value(CONFIG_GREEN_LED, 1);
Tom Rix799a05b2009-09-27 11:10:09 -050047 saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF;
48}
49
Jason Kridneraff0aa82011-09-04 14:40:16 -040050void yellow_led_off(void)
Tom Rix799a05b2009-09-27 11:10:09 -050051{
Eric Benard083d32f2011-04-03 06:35:54 +000052 at91_set_pio_value(CONFIG_YELLOW_LED, 1);
Tom Rix799a05b2009-09-27 11:10:09 -050053 saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF;
54}
55
Jason Kridneraff0aa82011-09-04 14:40:16 -040056void blue_led_off(void)
Tom Rix799a05b2009-09-27 11:10:09 -050057{
Eric Benard083d32f2011-04-03 06:35:54 +000058 at91_set_pio_value(CONFIG_BLUE_LED, 1);
Tom Rix799a05b2009-09-27 11:10:09 -050059 saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF;
60}
61
Jason Kridneraff0aa82011-09-04 14:40:16 -040062void red_led_on(void)
Tom Rix799a05b2009-09-27 11:10:09 -050063{
Eric Benard083d32f2011-04-03 06:35:54 +000064 at91_set_pio_value(CONFIG_RED_LED, 0);
Tom Rix799a05b2009-09-27 11:10:09 -050065 saved_state[STATUS_LED_RED] = STATUS_LED_ON;
66}
67
Jason Kridneraff0aa82011-09-04 14:40:16 -040068void green_led_on(void)
Tom Rix799a05b2009-09-27 11:10:09 -050069{
Eric Benard083d32f2011-04-03 06:35:54 +000070 at91_set_pio_value(CONFIG_GREEN_LED, 0);
Tom Rix799a05b2009-09-27 11:10:09 -050071 saved_state[STATUS_LED_GREEN] = STATUS_LED_ON;
72}
73
Jason Kridneraff0aa82011-09-04 14:40:16 -040074void yellow_led_on(void)
Tom Rix799a05b2009-09-27 11:10:09 -050075{
Eric Benard083d32f2011-04-03 06:35:54 +000076 at91_set_pio_value(CONFIG_YELLOW_LED, 0);
Tom Rix799a05b2009-09-27 11:10:09 -050077 saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON;
78}
79
Jason Kridneraff0aa82011-09-04 14:40:16 -040080void blue_led_on(void)
Tom Rix799a05b2009-09-27 11:10:09 -050081{
Eric Benard083d32f2011-04-03 06:35:54 +000082 at91_set_pio_value(CONFIG_BLUE_LED, 0);
Tom Rix799a05b2009-09-27 11:10:09 -050083 saved_state[STATUS_LED_BLUE] = STATUS_LED_ON;
84}
85
86void __led_init(led_id_t mask, int state)
87{
88 __led_set(mask, state);
89}
90
91void __led_toggle(led_id_t mask)
92{
93 if (STATUS_LED_BLUE == mask) {
94 if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE])
Jason Kridneraff0aa82011-09-04 14:40:16 -040095 blue_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -050096 else
Jason Kridneraff0aa82011-09-04 14:40:16 -040097 blue_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -050098 } else if (STATUS_LED_RED == mask) {
99 if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
Jason Kridneraff0aa82011-09-04 14:40:16 -0400100 red_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500101 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400102 red_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500103 } else if (STATUS_LED_GREEN == mask) {
104 if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
Jason Kridneraff0aa82011-09-04 14:40:16 -0400105 green_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500106 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400107 green_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500108 } else if (STATUS_LED_YELLOW == mask) {
109 if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW])
Jason Kridneraff0aa82011-09-04 14:40:16 -0400110 yellow_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500111 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400112 yellow_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500113 }
114}
115
116void __led_set(led_id_t mask, int state)
117{
118 if (STATUS_LED_BLUE == mask) {
119 if (STATUS_LED_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -0400120 blue_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500121 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400122 blue_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500123 } else if (STATUS_LED_RED == mask) {
124 if (STATUS_LED_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -0400125 red_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500126 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400127 red_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500128 } else if (STATUS_LED_GREEN == mask) {
129 if (STATUS_LED_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -0400130 green_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500131 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400132 green_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500133 } else if (STATUS_LED_YELLOW == mask) {
134 if (STATUS_LED_ON == state)
Jason Kridneraff0aa82011-09-04 14:40:16 -0400135 yellow_led_on();
Tom Rix799a05b2009-09-27 11:10:09 -0500136 else
Jason Kridneraff0aa82011-09-04 14:40:16 -0400137 yellow_led_off();
Tom Rix799a05b2009-09-27 11:10:09 -0500138 }
139}