blob: e21c0169db7160843d49e3ce885c9e5a85ded99d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -04002/*
3 * Copyright (c) 2010 Texas Instruments, Inc.
4 * Jason Kridner <jkridner@beagleboard.org>
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -04005 */
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 Premi7b3dc822011-09-08 10:51:01 -040011#include <asm/gpio.h>
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040012
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040013/* GPIO pins for the LEDs */
Jason Kridner0ccb8772011-04-19 10:55:26 -050014#define BEAGLE_LED_USR0 150
15#define BEAGLE_LED_USR1 149
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040016
Uri Mashiach4892d392017-01-19 10:51:45 +020017#ifdef CONFIG_LED_STATUS_GREEN
Jason Kridneraff0aa82011-09-04 14:40:16 -040018void green_led_off(void)
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040019{
Uri Mashiach4892d392017-01-19 10:51:45 +020020 __led_set(CONFIG_LED_STATUS_GREEN, 0);
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040021}
22
Jason Kridneraff0aa82011-09-04 14:40:16 -040023void green_led_on(void)
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040024{
Uri Mashiach4892d392017-01-19 10:51:45 +020025 __led_set(CONFIG_LED_STATUS_GREEN, 1);
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040026}
27#endif
28
Simon Glassbc0f4ea2014-10-22 21:37:15 -060029static int get_led_gpio(led_id_t mask)
30{
Uri Mashiach4892d392017-01-19 10:51:45 +020031#ifdef CONFIG_LED_STATUS0
32 if (CONFIG_LED_STATUS_BIT & mask)
Simon Glassbc0f4ea2014-10-22 21:37:15 -060033 return BEAGLE_LED_USR0;
34#endif
Uri Mashiach4892d392017-01-19 10:51:45 +020035#ifdef CONFIG_LED_STATUS1
36 if (CONFIG_LED_STATUS_BIT1 & mask)
Simon Glassbc0f4ea2014-10-22 21:37:15 -060037 return BEAGLE_LED_USR1;
38#endif
39
40 return 0;
41}
42
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040043void __led_init (led_id_t mask, int state)
44{
Simon Glassbc0f4ea2014-10-22 21:37:15 -060045 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 Kridnerc3ef8bc2011-04-18 17:23:35 -040051}
52
53void __led_toggle (led_id_t mask)
54{
Simon Glassbc0f4ea2014-10-22 21:37:15 -060055 int state, toggle_gpio;
56
57 toggle_gpio = get_led_gpio(mask);
Joel A Fernandes26bd9182011-08-11 23:16:53 -050058 if (toggle_gpio) {
Simon Glassbc0f4ea2014-10-22 21:37:15 -060059 state = gpio_get_value(toggle_gpio);
60 gpio_direction_output(toggle_gpio, !state);
Joel A Fernandes26bd9182011-08-11 23:16:53 -050061 }
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040062}
63
64void __led_set (led_id_t mask, int state)
65{
Simon Glassbc0f4ea2014-10-22 21:37:15 -060066 int toggle_gpio;
67
68 toggle_gpio = get_led_gpio(mask);
69 if (toggle_gpio)
70 gpio_direction_output(toggle_gpio, state);
Jason Kridnerc3ef8bc2011-04-18 17:23:35 -040071}