3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <status_led.h>
29 * The purpose of this code is to signal the operational status of a
30 * target which usually boots over the network; while running in
31 * PCBoot, a status LED is blinking. As soon as a valid BOOTP reply
32 * message has been received, the LED is turned off. The Linux
33 * kernel, once it is running, will start blinking the LED again,
34 * with another frequency.
37 /* ------------------------------------------------------------------------- */
39 #ifdef CONFIG_STATUS_LED
48 led_dev_t led_dev[] = {
54 #if defined(STATUS_LED_BIT1)
61 #if defined(STATUS_LED_BIT2)
68 #if defined(STATUS_LED_BIT3)
77 #define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
79 static int status_led_init_done = 0;
81 static void status_led_init (void)
83 volatile immap_t *immr = (immap_t *)CFG_IMMR;
86 for (i=0; i<MAX_LED_DEV; ++i) {
87 led_dev_t *ld = &led_dev[i];
89 immr->STATUS_LED_PAR &= ~(ld->mask);
91 immr->STATUS_LED_ODR &= ~(ld->mask);
93 #if (STATUS_LED_ACTIVE == 0)
94 if (ld->state == STATUS_LED_ON)
95 immr->STATUS_LED_DAT &= ~(ld->mask);
97 immr->STATUS_LED_DAT |= ld->mask ;
99 if (ld->state == STATUS_LED_ON)
100 immr->STATUS_LED_DAT |= ld->mask ;
102 immr->STATUS_LED_DAT &= ~(ld->mask);
104 immr->STATUS_LED_DIR |= ld->mask ;
107 status_led_init_done = 1;
110 void status_led_tick (ulong timestamp)
112 volatile immap_t *immr = (immap_t *)CFG_IMMR;
115 if (!status_led_init_done)
118 for (i=0; i<MAX_LED_DEV; ++i) {
119 led_dev_t *ld = &led_dev[i];
121 if (ld->state != STATUS_LED_BLINKING)
124 if (++(ld->cnt) >= ld->period) {
125 immr->STATUS_LED_DAT ^= ld->mask;
126 ld->cnt -= ld->period;
131 void status_led_set (int led, int state)
133 volatile immap_t *immr = (immap_t *)CFG_IMMR;
136 if (led < 0 || led >= MAX_LED_DEV)
139 if (!status_led_init_done)
147 case STATUS_LED_BLINKING:
148 ld->cnt = 0; /* always start with full period */
149 /* fall through */ /* always start with LED _ON_ */
151 #if (STATUS_LED_ACTIVE == 0)
152 immr->STATUS_LED_DAT &= ~(ld->mask);
154 immr->STATUS_LED_DAT |= ld->mask ;
158 #if (STATUS_LED_ACTIVE == 0)
159 immr->STATUS_LED_DAT |= ld->mask ;
161 immr->STATUS_LED_DAT &= ~(ld->mask);
168 #endif /* CONFIG_STATUS_LED */