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