Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2010 Texas Instruments, Inc. |
| 4 | * Jason Kridner <jkridner@beagleboard.org> |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 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> |
Sanjeev Premi | 7b3dc82 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 11 | #include <asm/gpio.h> |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 12 | |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 13 | /* GPIO pins for the LEDs */ |
Jason Kridner | 0ccb877 | 2011-04-19 10:55:26 -0500 | [diff] [blame] | 14 | #define BEAGLE_LED_USR0 150 |
| 15 | #define BEAGLE_LED_USR1 149 |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 16 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 17 | #ifdef CONFIG_LED_STATUS_GREEN |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 18 | void green_led_off(void) |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 19 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 20 | __led_set(CONFIG_LED_STATUS_GREEN, 0); |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 21 | } |
| 22 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 23 | void green_led_on(void) |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 24 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 25 | __led_set(CONFIG_LED_STATUS_GREEN, 1); |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 26 | } |
| 27 | #endif |
| 28 | |
Simon Glass | bc0f4ea | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 29 | static int get_led_gpio(led_id_t mask) |
| 30 | { |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 31 | #ifdef CONFIG_LED_STATUS0 |
| 32 | if (CONFIG_LED_STATUS_BIT & mask) |
Simon Glass | bc0f4ea | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 33 | return BEAGLE_LED_USR0; |
| 34 | #endif |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 35 | #ifdef CONFIG_LED_STATUS1 |
| 36 | if (CONFIG_LED_STATUS_BIT1 & mask) |
Simon Glass | bc0f4ea | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 37 | return BEAGLE_LED_USR1; |
| 38 | #endif |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 43 | void __led_init (led_id_t mask, int state) |
| 44 | { |
Simon Glass | bc0f4ea | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 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); |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void __led_toggle (led_id_t mask) |
| 54 | { |
Simon Glass | bc0f4ea | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 55 | int state, toggle_gpio; |
| 56 | |
| 57 | toggle_gpio = get_led_gpio(mask); |
Joel A Fernandes | 26bd918 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 58 | if (toggle_gpio) { |
Simon Glass | bc0f4ea | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 59 | state = gpio_get_value(toggle_gpio); |
| 60 | gpio_direction_output(toggle_gpio, !state); |
Joel A Fernandes | 26bd918 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 61 | } |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void __led_set (led_id_t mask, int state) |
| 65 | { |
Simon Glass | bc0f4ea | 2014-10-22 21:37:15 -0600 | [diff] [blame] | 66 | int toggle_gpio; |
| 67 | |
| 68 | toggle_gpio = get_led_gpio(mask); |
| 69 | if (toggle_gpio) |
| 70 | gpio_direction_output(toggle_gpio, state); |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 71 | } |