Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 8 | */ |
| 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 Benard | 5affc63 | 2011-06-06 22:48:28 +0000 | [diff] [blame] | 15 | #include <asm/io.h> |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 16 | |
| 17 | static unsigned int saved_state[4] = {STATUS_LED_OFF, STATUS_LED_OFF, |
| 18 | STATUS_LED_OFF, STATUS_LED_OFF}; |
| 19 | |
| 20 | void coloured_LED_init(void) |
| 21 | { |
Eric Benard | 5affc63 | 2011-06-06 22:48:28 +0000 | [diff] [blame] | 22 | at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC; |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 23 | |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 24 | /* Enable clock */ |
Eric Benard | 5affc63 | 2011-06-06 22:48:28 +0000 | [diff] [blame] | 25 | writel(1 << ATMEL_ID_PIOC, &pmc->pcer); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 26 | |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 27 | 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 Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 31 | |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 32 | 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 Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 36 | } |
| 37 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 38 | void red_led_off(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 39 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 40 | at91_set_pio_value(CONFIG_RED_LED, 1); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 41 | saved_state[STATUS_LED_RED] = STATUS_LED_OFF; |
| 42 | } |
| 43 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 44 | void green_led_off(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 45 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 46 | at91_set_pio_value(CONFIG_GREEN_LED, 1); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 47 | saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF; |
| 48 | } |
| 49 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 50 | void yellow_led_off(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 51 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 52 | at91_set_pio_value(CONFIG_YELLOW_LED, 1); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 53 | saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF; |
| 54 | } |
| 55 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 56 | void blue_led_off(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 57 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 58 | at91_set_pio_value(CONFIG_BLUE_LED, 1); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 59 | saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF; |
| 60 | } |
| 61 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 62 | void red_led_on(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 63 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 64 | at91_set_pio_value(CONFIG_RED_LED, 0); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 65 | saved_state[STATUS_LED_RED] = STATUS_LED_ON; |
| 66 | } |
| 67 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 68 | void green_led_on(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 69 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 70 | at91_set_pio_value(CONFIG_GREEN_LED, 0); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 71 | saved_state[STATUS_LED_GREEN] = STATUS_LED_ON; |
| 72 | } |
| 73 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 74 | void yellow_led_on(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 75 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 76 | at91_set_pio_value(CONFIG_YELLOW_LED, 0); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 77 | saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON; |
| 78 | } |
| 79 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 80 | void blue_led_on(void) |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 81 | { |
Eric Benard | 083d32f | 2011-04-03 06:35:54 +0000 | [diff] [blame] | 82 | at91_set_pio_value(CONFIG_BLUE_LED, 0); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 83 | saved_state[STATUS_LED_BLUE] = STATUS_LED_ON; |
| 84 | } |
| 85 | |
| 86 | void __led_init(led_id_t mask, int state) |
| 87 | { |
| 88 | __led_set(mask, state); |
| 89 | } |
| 90 | |
| 91 | void __led_toggle(led_id_t mask) |
| 92 | { |
| 93 | if (STATUS_LED_BLUE == mask) { |
| 94 | if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE]) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 95 | blue_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 96 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 97 | blue_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 98 | } else if (STATUS_LED_RED == mask) { |
| 99 | if (STATUS_LED_ON == saved_state[STATUS_LED_RED]) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 100 | red_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 101 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 102 | red_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 103 | } else if (STATUS_LED_GREEN == mask) { |
| 104 | if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN]) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 105 | green_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 106 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 107 | green_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 108 | } else if (STATUS_LED_YELLOW == mask) { |
| 109 | if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW]) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 110 | yellow_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 111 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 112 | yellow_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | void __led_set(led_id_t mask, int state) |
| 117 | { |
| 118 | if (STATUS_LED_BLUE == mask) { |
| 119 | if (STATUS_LED_ON == state) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 120 | blue_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 121 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 122 | blue_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 123 | } else if (STATUS_LED_RED == mask) { |
| 124 | if (STATUS_LED_ON == state) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 125 | red_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 126 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 127 | red_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 128 | } else if (STATUS_LED_GREEN == mask) { |
| 129 | if (STATUS_LED_ON == state) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 130 | green_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 131 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 132 | green_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 133 | } else if (STATUS_LED_YELLOW == mask) { |
| 134 | if (STATUS_LED_ON == state) |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 135 | yellow_led_on(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 136 | else |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 137 | yellow_led_off(); |
Tom Rix | 799a05b | 2009-09-27 11:10:09 -0500 | [diff] [blame] | 138 | } |
| 139 | } |