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