blob: 30b8b93da5a78a19e4ba80a956361515661467d7 [file] [log] [blame]
Jason Kridner70d8c942011-04-18 17:23:35 -04001/*
2 * Copyright (c) 2010 Texas Instruments, Inc.
3 * Jason Kridner <jkridner@beagleboard.org>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Jason Kridner70d8c942011-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 Premi84c3b632011-09-08 10:51:01 -040012#include <asm/gpio.h>
Jason Kridner70d8c942011-04-18 17:23:35 -040013
Jason Kridner70d8c942011-04-18 17:23:35 -040014/* GPIO pins for the LEDs */
Jason Kridnerf87824e2011-04-19 10:55:26 -050015#define BEAGLE_LED_USR0 150
16#define BEAGLE_LED_USR1 149
Jason Kridner70d8c942011-04-18 17:23:35 -040017
Uri Mashiach2d8d1902017-01-19 10:51:45 +020018#ifdef CONFIG_LED_STATUS_GREEN
Jason Kridner2d3be7c2011-09-04 14:40:16 -040019void green_led_off(void)
Jason Kridner70d8c942011-04-18 17:23:35 -040020{
Uri Mashiach2d8d1902017-01-19 10:51:45 +020021 __led_set(CONFIG_LED_STATUS_GREEN, 0);
Jason Kridner70d8c942011-04-18 17:23:35 -040022}
23
Jason Kridner2d3be7c2011-09-04 14:40:16 -040024void green_led_on(void)
Jason Kridner70d8c942011-04-18 17:23:35 -040025{
Uri Mashiach2d8d1902017-01-19 10:51:45 +020026 __led_set(CONFIG_LED_STATUS_GREEN, 1);
Jason Kridner70d8c942011-04-18 17:23:35 -040027}
28#endif
29
Simon Glassb3f4ca12014-10-22 21:37:15 -060030static int get_led_gpio(led_id_t mask)
31{
Uri Mashiach2d8d1902017-01-19 10:51:45 +020032#ifdef CONFIG_LED_STATUS0
33 if (CONFIG_LED_STATUS_BIT & mask)
Simon Glassb3f4ca12014-10-22 21:37:15 -060034 return BEAGLE_LED_USR0;
35#endif
Uri Mashiach2d8d1902017-01-19 10:51:45 +020036#ifdef CONFIG_LED_STATUS1
37 if (CONFIG_LED_STATUS_BIT1 & mask)
Simon Glassb3f4ca12014-10-22 21:37:15 -060038 return BEAGLE_LED_USR1;
39#endif
40
41 return 0;
42}
43
Jason Kridner70d8c942011-04-18 17:23:35 -040044void __led_init (led_id_t mask, int state)
45{
Simon Glassb3f4ca12014-10-22 21:37:15 -060046 int toggle_gpio;
47
48 toggle_gpio = get_led_gpio(mask);
49
50 if (toggle_gpio && !gpio_request(toggle_gpio, "led"))
51 __led_set(mask, state);
Jason Kridner70d8c942011-04-18 17:23:35 -040052}
53
54void __led_toggle (led_id_t mask)
55{
Simon Glassb3f4ca12014-10-22 21:37:15 -060056 int state, toggle_gpio;
57
58 toggle_gpio = get_led_gpio(mask);
Joel A Fernandesb8bc8972011-08-11 23:16:53 -050059 if (toggle_gpio) {
Simon Glassb3f4ca12014-10-22 21:37:15 -060060 state = gpio_get_value(toggle_gpio);
61 gpio_direction_output(toggle_gpio, !state);
Joel A Fernandesb8bc8972011-08-11 23:16:53 -050062 }
Jason Kridner70d8c942011-04-18 17:23:35 -040063}
64
65void __led_set (led_id_t mask, int state)
66{
Simon Glassb3f4ca12014-10-22 21:37:15 -060067 int toggle_gpio;
68
69 toggle_gpio = get_led_gpio(mask);
70 if (toggle_gpio)
71 gpio_direction_output(toggle_gpio, state);
Jason Kridner70d8c942011-04-18 17:23:35 -040072}