Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Texas Instruments, Inc. |
| 3 | * Jason Kridner <jkridner@beagleboard.org> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of |
| 8 | * the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 18 | * MA 02111-1307 USA |
| 19 | */ |
| 20 | #include <common.h> |
| 21 | #include <status_led.h> |
| 22 | #include <asm/arch/cpu.h> |
| 23 | #include <asm/io.h> |
| 24 | #include <asm/arch/sys_proto.h> |
Sanjeev Premi | 7b3dc82 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 25 | #include <asm/gpio.h> |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 26 | |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 27 | /* GPIO pins for the LEDs */ |
Jason Kridner | 0ccb877 | 2011-04-19 10:55:26 -0500 | [diff] [blame] | 28 | #define BEAGLE_LED_USR0 150 |
| 29 | #define BEAGLE_LED_USR1 149 |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 30 | |
| 31 | #ifdef STATUS_LED_GREEN |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 32 | void green_led_off(void) |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 33 | { |
| 34 | __led_set (STATUS_LED_GREEN, 0); |
| 35 | } |
| 36 | |
Jason Kridner | aff0aa8 | 2011-09-04 14:40:16 -0400 | [diff] [blame] | 37 | void green_led_on(void) |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 38 | { |
| 39 | __led_set (STATUS_LED_GREEN, 1); |
| 40 | } |
| 41 | #endif |
| 42 | |
| 43 | void __led_init (led_id_t mask, int state) |
| 44 | { |
| 45 | __led_set (mask, state); |
| 46 | } |
| 47 | |
| 48 | void __led_toggle (led_id_t mask) |
| 49 | { |
Joel A Fernandes | 26bd918 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 50 | int state, toggle_gpio = 0; |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 51 | #ifdef STATUS_LED_BIT |
Joel A Fernandes | 26bd918 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 52 | if (!toggle_gpio && STATUS_LED_BIT & mask) |
| 53 | toggle_gpio = BEAGLE_LED_USR0; |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 54 | #endif |
| 55 | #ifdef STATUS_LED_BIT1 |
Joel A Fernandes | 26bd918 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 56 | if (!toggle_gpio && STATUS_LED_BIT1 & mask) |
| 57 | toggle_gpio = BEAGLE_LED_USR1; |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 58 | #endif |
Joel A Fernandes | 26bd918 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 59 | if (toggle_gpio) { |
Sanjeev Premi | 7b3dc82 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 60 | if (!gpio_request(toggle_gpio, "")) { |
| 61 | gpio_direction_output(toggle_gpio, 0); |
| 62 | state = gpio_get_value(toggle_gpio); |
| 63 | gpio_set_value(toggle_gpio, !state); |
Joel A Fernandes | 26bd918 | 2011-08-11 23:16:53 -0500 | [diff] [blame] | 64 | } |
| 65 | } |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void __led_set (led_id_t mask, int state) |
| 69 | { |
| 70 | #ifdef STATUS_LED_BIT |
| 71 | if (STATUS_LED_BIT & mask) { |
Sanjeev Premi | 7b3dc82 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 72 | if (!gpio_request(BEAGLE_LED_USR0, "")) { |
| 73 | gpio_direction_output(BEAGLE_LED_USR0, 0); |
| 74 | gpio_set_value(BEAGLE_LED_USR0, state); |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 75 | } |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 76 | } |
| 77 | #endif |
| 78 | #ifdef STATUS_LED_BIT1 |
| 79 | if (STATUS_LED_BIT1 & mask) { |
Sanjeev Premi | 7b3dc82 | 2011-09-08 10:51:01 -0400 | [diff] [blame] | 80 | if (!gpio_request(BEAGLE_LED_USR1, "")) { |
| 81 | gpio_direction_output(BEAGLE_LED_USR1, 0); |
| 82 | gpio_set_value(BEAGLE_LED_USR1, state); |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 83 | } |
Jason Kridner | c3ef8bc | 2011-04-18 17:23:35 -0400 | [diff] [blame] | 84 | } |
| 85 | #endif |
| 86 | } |