2 * (C) Copyright 2000-2002 Wolfgang Denk, DENX Software Engineering, wd@denx.de
3 * (C) Copyright 2003 Martin Winistoerfer, martinwinistoerfer@gmx.ch.
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,
27 * Discription: Blink a board led to show boot progress. Led's
28 * are connected via the MIOS module.
33 #include <status_led.h>
35 #ifdef CONFIG_STATUS_LED
44 led_dev_t led_dev[] = {
50 #if defined(STATUS_LED_BIT1)
57 #if defined(STATUS_LED_BIT2)
64 #if defined(STATUS_LED_BIT3)
73 #define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
75 static int status_led_init_done = 0;
77 static void status_led_init (void)
79 volatile immap_t *immr = (immap_t *)CFG_IMMR;
82 for (i=0; i<MAX_LED_DEV; ++i) {
83 led_dev_t *ld = &led_dev[i];
85 immr->STATUS_LED_DIR = STATUS_LED_BIT;
87 #if (STATUS_LED_ACTIVE == 0)
88 if (ld->state == STATUS_LED_ON)
89 immr->STATUS_LED_DAT &= ~(ld->mask);
91 immr->STATUS_LED_DAT |= ld->mask ;
93 if (ld->state == STATUS_LED_ON)
94 immr->STATUS_LED_DAT |= ld->mask ;
96 immr->STATUS_LED_DAT &= ~(ld->mask);
100 status_led_init_done = 1;
103 void status_led_tick (ulong timestamp)
105 volatile immap_t *immr = (immap_t *)CFG_IMMR;
108 if (!status_led_init_done)
111 for (i=0; i<MAX_LED_DEV; ++i) {
112 led_dev_t *ld = &led_dev[i];
114 if (ld->state != STATUS_LED_BLINKING)
117 if (++(ld->cnt) >= ld->period) {
118 immr->STATUS_LED_DAT ^= ld->mask;
119 ld->cnt -= ld->period;
124 void status_led_set (int led, int state)
126 volatile immap_t *immr = (immap_t *)CFG_IMMR;
129 if (led < 0 || led >= MAX_LED_DEV)
132 if (!status_led_init_done)
140 case STATUS_LED_BLINKING:
141 ld->cnt = 0; /* always start with full period */
142 /* fall through */ /* always start with LED _ON_ */
144 #if (STATUS_LED_ACTIVE == 0)
145 immr->STATUS_LED_DAT &= ~(ld->mask);
147 immr->STATUS_LED_DAT |= ld->mask ;
151 #if (STATUS_LED_ACTIVE == 0)
152 immr->STATUS_LED_DAT |= ld->mask ;
154 immr->STATUS_LED_DAT &= ~(ld->mask);
161 #endif /* CONFIG_STATUS_LED */