Markus Hubig | 2399ef7 | 2012-08-07 17:43:23 +0200 | [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 | * |
| 7 | * (C) Copyright 2012 |
| 8 | * Markus Hubig <mhubig@imko.de> |
| 9 | * IMKO GmbH <www.imko.de> |
| 10 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 11 | * SPDX-License-Identifier: GPL-2.0+ |
Markus Hubig | 2399ef7 | 2012-08-07 17:43:23 +0200 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/gpio.h> |
| 17 | #include <asm/arch/at91_pmc.h> |
| 18 | #include <status_led.h> |
| 19 | |
| 20 | static unsigned int saved_state[3] = {STATUS_LED_OFF, |
| 21 | STATUS_LED_OFF, STATUS_LED_OFF}; |
| 22 | |
| 23 | void coloured_LED_init(void) |
| 24 | { |
| 25 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 26 | |
| 27 | /* Enable the clock */ |
| 28 | writel(ATMEL_ID_PIOC, &pmc->pcer); |
| 29 | |
| 30 | at91_set_gpio_output(CONFIG_RED_LED, 1); |
| 31 | at91_set_gpio_output(CONFIG_GREEN_LED, 1); |
| 32 | at91_set_gpio_output(CONFIG_YELLOW_LED, 1); |
| 33 | |
| 34 | at91_set_gpio_value(CONFIG_RED_LED, 0); |
| 35 | at91_set_gpio_value(CONFIG_GREEN_LED, 1); |
| 36 | at91_set_gpio_value(CONFIG_YELLOW_LED, 0); |
| 37 | } |
| 38 | |
| 39 | void red_led_on(void) |
| 40 | { |
| 41 | at91_set_gpio_value(CONFIG_RED_LED, 1); |
| 42 | saved_state[STATUS_LED_RED] = STATUS_LED_ON; |
| 43 | } |
| 44 | |
| 45 | void red_led_off(void) |
| 46 | { |
| 47 | at91_set_gpio_value(CONFIG_RED_LED, 0); |
| 48 | saved_state[STATUS_LED_RED] = STATUS_LED_OFF; |
| 49 | } |
| 50 | |
| 51 | void green_led_on(void) |
| 52 | { |
| 53 | at91_set_gpio_value(CONFIG_GREEN_LED, 1); |
| 54 | saved_state[STATUS_LED_GREEN] = STATUS_LED_ON; |
| 55 | } |
| 56 | |
| 57 | void green_led_off(void) |
| 58 | { |
| 59 | at91_set_gpio_value(CONFIG_GREEN_LED, 0); |
| 60 | saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF; |
| 61 | } |
| 62 | |
| 63 | void yellow_led_on(void) |
| 64 | { |
| 65 | at91_set_gpio_value(CONFIG_YELLOW_LED, 1); |
| 66 | saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON; |
| 67 | } |
| 68 | |
| 69 | void yellow_led_off(void) |
| 70 | { |
| 71 | at91_set_gpio_value(CONFIG_YELLOW_LED, 0); |
| 72 | saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF; |
| 73 | } |
| 74 | |
| 75 | void __led_init(led_id_t mask, int state) |
| 76 | { |
| 77 | __led_set(mask, state); |
| 78 | } |
| 79 | |
| 80 | void __led_toggle(led_id_t mask) |
| 81 | { |
| 82 | if (STATUS_LED_RED == mask) { |
| 83 | if (STATUS_LED_ON == saved_state[STATUS_LED_RED]) |
| 84 | red_led_off(); |
| 85 | else |
| 86 | red_led_on(); |
| 87 | |
| 88 | } else if (STATUS_LED_GREEN == mask) { |
| 89 | if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN]) |
| 90 | green_led_off(); |
| 91 | else |
| 92 | green_led_on(); |
| 93 | |
| 94 | } else if (STATUS_LED_YELLOW == mask) { |
| 95 | if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW]) |
| 96 | yellow_led_off(); |
| 97 | else |
| 98 | yellow_led_on(); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | void __led_set(led_id_t mask, int state) |
| 103 | { |
| 104 | if (STATUS_LED_RED == mask) { |
| 105 | if (STATUS_LED_ON == state) |
| 106 | red_led_on(); |
| 107 | else |
| 108 | red_led_off(); |
| 109 | |
| 110 | } else if (STATUS_LED_GREEN == mask) { |
| 111 | if (STATUS_LED_ON == state) |
| 112 | green_led_on(); |
| 113 | else |
| 114 | green_led_off(); |
| 115 | |
| 116 | } else if (STATUS_LED_YELLOW == mask) { |
| 117 | if (STATUS_LED_ON == state) |
| 118 | yellow_led_on(); |
| 119 | else |
| 120 | yellow_led_off(); |
| 121 | } |
| 122 | } |