xref: /openbmc/u-boot/board/ti/beagle/led.c (revision 5994e8b6)
1 /*
2  * Copyright (c) 2010 Texas Instruments, Inc.
3  * Jason Kridner <jkridner@beagleboard.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 #include <common.h>
8 #include <status_led.h>
9 #include <asm/arch/cpu.h>
10 #include <asm/io.h>
11 #include <asm/arch/sys_proto.h>
12 #include <asm/gpio.h>
13 
14 /* GPIO pins for the LEDs */
15 #define BEAGLE_LED_USR0	150
16 #define BEAGLE_LED_USR1	149
17 
18 #ifdef CONFIG_LED_STATUS_GREEN
19 void green_led_off(void)
20 {
21 	__led_set(CONFIG_LED_STATUS_GREEN, 0);
22 }
23 
24 void green_led_on(void)
25 {
26 	__led_set(CONFIG_LED_STATUS_GREEN, 1);
27 }
28 #endif
29 
30 static int get_led_gpio(led_id_t mask)
31 {
32 #ifdef CONFIG_LED_STATUS0
33 	if (CONFIG_LED_STATUS_BIT & mask)
34 		return BEAGLE_LED_USR0;
35 #endif
36 #ifdef CONFIG_LED_STATUS1
37 	if (CONFIG_LED_STATUS_BIT1 & mask)
38 		return BEAGLE_LED_USR1;
39 #endif
40 
41 	return 0;
42 }
43 
44 void __led_init (led_id_t mask, int state)
45 {
46 	int toggle_gpio;
47 
48 	toggle_gpio = get_led_gpio(mask);
49 
50 	if (toggle_gpio && !gpio_request(toggle_gpio, "led"))
51 		__led_set(mask, state);
52 }
53 
54 void __led_toggle (led_id_t mask)
55 {
56 	int state, toggle_gpio;
57 
58 	toggle_gpio = get_led_gpio(mask);
59 	if (toggle_gpio) {
60 		state = gpio_get_value(toggle_gpio);
61 		gpio_direction_output(toggle_gpio, !state);
62 	}
63 }
64 
65 void __led_set (led_id_t mask, int state)
66 {
67 	int toggle_gpio;
68 
69 	toggle_gpio = get_led_gpio(mask);
70 	if (toggle_gpio)
71 		gpio_direction_output(toggle_gpio, state);
72 }
73