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