xref: /openbmc/u-boot/board/ti/beagle/led.c (revision 6c0bf27d)
1 /*
2  * Copyright (c) 2010 Texas Instruments, Inc.
3  * Jason Kridner <jkridner@beagleboard.org>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA
19  */
20 #include <common.h>
21 #include <status_led.h>
22 #include <asm/arch/cpu.h>
23 #include <asm/io.h>
24 #include <asm/arch/sys_proto.h>
25 #include <asm/arch/gpio.h>
26 
27 static unsigned int saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF};
28 
29 /* GPIO pins for the LEDs */
30 #define BEAGLE_LED_USR0	149
31 #define BEAGLE_LED_USR1	150
32 
33 #ifdef STATUS_LED_GREEN
34 void green_LED_off (void)
35 {
36 	__led_set (STATUS_LED_GREEN, 0);
37 }
38 
39 void green_LED_on (void)
40 {
41 	__led_set (STATUS_LED_GREEN, 1);
42 }
43 #endif
44 
45 void __led_init (led_id_t mask, int state)
46 {
47 	__led_set (mask, state);
48 }
49 
50 void __led_toggle (led_id_t mask)
51 {
52 #ifdef STATUS_LED_BIT
53 	if (STATUS_LED_BIT & mask) {
54 		if (STATUS_LED_ON == saved_state[0])
55 			__led_set(STATUS_LED_BIT, 0);
56 		else
57 			__led_set(STATUS_LED_BIT, 1);
58 	}
59 #endif
60 #ifdef STATUS_LED_BIT1
61 	if (STATUS_LED_BIT1 & mask) {
62 		if (STATUS_LED_ON == saved_state[1])
63 			__led_set(STATUS_LED_BIT1, 0);
64 		else
65 			__led_set(STATUS_LED_BIT1, 1);
66 	}
67 #endif
68 }
69 
70 void __led_set (led_id_t mask, int state)
71 {
72 #ifdef STATUS_LED_BIT
73 	if (STATUS_LED_BIT & mask) {
74 		if (!omap_request_gpio(BEAGLE_LED_USR0)) {
75 			omap_set_gpio_direction(BEAGLE_LED_USR0, 0);
76 			omap_set_gpio_dataout(BEAGLE_LED_USR0, state);
77 		}
78 		saved_state[0] = state;
79 	}
80 #endif
81 #ifdef STATUS_LED_BIT1
82 	if (STATUS_LED_BIT1 & mask) {
83 		if (!omap_request_gpio(BEAGLE_LED_USR1)) {
84 			omap_set_gpio_direction(BEAGLE_LED_USR1, 0);
85 			omap_set_gpio_dataout(BEAGLE_LED_USR1, state);
86 		}
87 		saved_state[1] = state;
88 	}
89 #endif
90 }
91