blob: 89b8dd3c3c1ee015be657b27372bc5c2176cc634 [file] [log] [blame]
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -04001/*
2 * Copyright (c) 2010 Texas Instruments, Inc.
3 * Jason Kridner <jkridner@beagleboard.org>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -04006 */
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 Premi7b3dc822011-09-08 10:51:01 -040012#include <asm/gpio.h>
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040013
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040014/* GPIO pins for the LEDs */
Jason Kridner0ccb8772011-04-19 10:55:26 -050015#define BEAGLE_LED_USR0 150
16#define BEAGLE_LED_USR1 149
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040017
18#ifdef STATUS_LED_GREEN
Jason Kridneraff0aa82011-09-04 14:40:16 -040019void green_led_off(void)
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040020{
21 __led_set (STATUS_LED_GREEN, 0);
22}
23
Jason Kridneraff0aa82011-09-04 14:40:16 -040024void green_led_on(void)
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040025{
26 __led_set (STATUS_LED_GREEN, 1);
27}
28#endif
29
30void __led_init (led_id_t mask, int state)
31{
32 __led_set (mask, state);
33}
34
35void __led_toggle (led_id_t mask)
36{
Joel A Fernandes26bd9182011-08-11 23:16:53 -050037 int state, toggle_gpio = 0;
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040038#ifdef STATUS_LED_BIT
Joel A Fernandes26bd9182011-08-11 23:16:53 -050039 if (!toggle_gpio && STATUS_LED_BIT & mask)
40 toggle_gpio = BEAGLE_LED_USR0;
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040041#endif
42#ifdef STATUS_LED_BIT1
Joel A Fernandes26bd9182011-08-11 23:16:53 -050043 if (!toggle_gpio && STATUS_LED_BIT1 & mask)
44 toggle_gpio = BEAGLE_LED_USR1;
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040045#endif
Joel A Fernandes26bd9182011-08-11 23:16:53 -050046 if (toggle_gpio) {
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040047 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 Fernandes26bd9182011-08-11 23:16:53 -050051 }
52 }
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040053}
54
55void __led_set (led_id_t mask, int state)
56{
57#ifdef STATUS_LED_BIT
58 if (STATUS_LED_BIT & mask) {
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040059 if (!gpio_request(BEAGLE_LED_USR0, "")) {
60 gpio_direction_output(BEAGLE_LED_USR0, 0);
61 gpio_set_value(BEAGLE_LED_USR0, state);
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040062 }
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040063 }
64#endif
65#ifdef STATUS_LED_BIT1
66 if (STATUS_LED_BIT1 & mask) {
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040067 if (!gpio_request(BEAGLE_LED_USR1, "")) {
68 gpio_direction_output(BEAGLE_LED_USR1, 0);
69 gpio_set_value(BEAGLE_LED_USR1, state);
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040070 }
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040071 }
72#endif
73}