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 | |
| 18 | #ifdef STATUS_LED_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 | { |
| 21 | __led_set (STATUS_LED_GREEN, 0); |
| 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 | { |
| 26 | __led_set (STATUS_LED_GREEN, 1); |
| 27 | } |
| 28 | #endif |
| 29 | |
| 30 | void __led_init (led_id_t mask, int state) |
| 31 | { |
| 32 | __led_set (mask, state); |
| 33 | } |
| 34 | |
| 35 | void __led_toggle (led_id_t mask) |
| 36 | { |
Joel A Fernandes | b8bc897 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 37 | int state, toggle_gpio = 0; |
Jason Kridner | 70d8c94 | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 38 | #ifdef STATUS_LED_BIT |
Joel A Fernandes | b8bc897 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 39 | if (!toggle_gpio && STATUS_LED_BIT & mask) |
| 40 | toggle_gpio = BEAGLE_LED_USR0; |
Jason Kridner | 70d8c94 | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 41 | #endif |
| 42 | #ifdef STATUS_LED_BIT1 |
Joel A Fernandes | b8bc897 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 43 | if (!toggle_gpio && STATUS_LED_BIT1 & mask) |
| 44 | toggle_gpio = BEAGLE_LED_USR1; |
Jason Kridner | 70d8c94 | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 45 | #endif |
Joel A Fernandes | b8bc897 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 46 | if (toggle_gpio) { |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 47 | if (!gpio_request(toggle_gpio, "")) { |
| 48 | gpio_direction_output(toggle_gpio, 0); |
| 49 | state = gpio_get_value(toggle_gpio); |
| 50 | gpio_set_value(toggle_gpio, !state); |
Joel A Fernandes | b8bc897 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 51 | } |
| 52 | } |
Jason Kridner | 70d8c94 | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void __led_set (led_id_t mask, int state) |
| 56 | { |
| 57 | #ifdef STATUS_LED_BIT |
| 58 | if (STATUS_LED_BIT & mask) { |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 59 | if (!gpio_request(BEAGLE_LED_USR0, "")) { |
| 60 | gpio_direction_output(BEAGLE_LED_USR0, 0); |
| 61 | gpio_set_value(BEAGLE_LED_USR0, state); |
Jason Kridner | 70d8c94 | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 62 | } |
Jason Kridner | 70d8c94 | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 63 | } |
| 64 | #endif |
| 65 | #ifdef STATUS_LED_BIT1 |
| 66 | if (STATUS_LED_BIT1 & mask) { |
Sanjeev Premi | 84c3b63 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 67 | if (!gpio_request(BEAGLE_LED_USR1, "")) { |
| 68 | gpio_direction_output(BEAGLE_LED_USR1, 0); |
| 69 | gpio_set_value(BEAGLE_LED_USR1, state); |
Jason Kridner | 70d8c94 | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 70 | } |
Jason Kridner | 70d8c94 | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 71 | } |
| 72 | #endif |
| 73 | } |