2010-04-30 03:34:14 +00:00
|
|
|
/*
|
|
|
|
* Status LED driver based on GPIO access conventions of Linux
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
|
2010-06-09 05:32:46 +00:00
|
|
|
* Licensed under the GPL-2 or later.
|
2010-04-30 03:34:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <status_led.h>
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
|
2023-01-10 16:19:45 +00:00
|
|
|
#ifndef CFG_GPIO_LED_INVERTED_TABLE
|
|
|
|
#define CFG_GPIO_LED_INVERTED_TABLE {}
|
2013-11-07 23:03:52 +00:00
|
|
|
#endif
|
|
|
|
|
2023-01-10 16:19:45 +00:00
|
|
|
static led_id_t gpio_led_inv[] = CFG_GPIO_LED_INVERTED_TABLE;
|
2013-11-07 23:03:52 +00:00
|
|
|
|
|
|
|
static int gpio_led_gpio_value(led_id_t mask, int state)
|
|
|
|
{
|
2017-01-19 08:51:45 +00:00
|
|
|
int i, gpio_value = (state == CONFIG_LED_STATUS_ON);
|
2013-11-07 23:03:52 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(gpio_led_inv); i++) {
|
|
|
|
if (gpio_led_inv[i] == mask)
|
|
|
|
gpio_value = !gpio_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gpio_value;
|
|
|
|
}
|
|
|
|
|
2010-04-30 03:34:14 +00:00
|
|
|
void __led_init(led_id_t mask, int state)
|
|
|
|
{
|
2013-11-07 23:03:52 +00:00
|
|
|
int gpio_value;
|
|
|
|
|
2013-11-07 23:03:51 +00:00
|
|
|
if (gpio_request(mask, "gpio_led") != 0) {
|
|
|
|
printf("%s: failed requesting GPIO%lu!\n", __func__, mask);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-07 23:03:52 +00:00
|
|
|
gpio_value = gpio_led_gpio_value(mask, state);
|
|
|
|
gpio_direction_output(mask, gpio_value);
|
2010-04-30 03:34:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __led_set(led_id_t mask, int state)
|
|
|
|
{
|
2013-11-07 23:03:52 +00:00
|
|
|
int gpio_value = gpio_led_gpio_value(mask, state);
|
|
|
|
|
|
|
|
gpio_set_value(mask, gpio_value);
|
2010-04-30 03:34:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __led_toggle(led_id_t mask)
|
|
|
|
{
|
|
|
|
gpio_set_value(mask, !gpio_get_value(mask));
|
|
|
|
}
|
2015-08-21 13:13:20 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_GPIO_LED_STUBS
|
|
|
|
|
|
|
|
/* 'generic' override of colored LED stubs, to use GPIO functions instead */
|
|
|
|
|
2017-01-19 08:51:45 +00:00
|
|
|
#ifdef CONFIG_LED_STATUS_RED
|
2015-08-21 13:13:20 +00:00
|
|
|
void red_led_on(void)
|
|
|
|
{
|
2017-01-19 08:51:45 +00:00
|
|
|
__led_set(CONFIG_LED_STATUS_RED, CONFIG_LED_STATUS_ON);
|
2015-08-21 13:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void red_led_off(void)
|
|
|
|
{
|
2017-01-19 08:51:45 +00:00
|
|
|
__led_set(CONFIG_LED_STATUS_RED, CONFIG_LED_STATUS_OFF);
|
2015-08-21 13:13:20 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-19 08:51:45 +00:00
|
|
|
#ifdef CONFIG_LED_STATUS_GREEN
|
2015-08-21 13:13:20 +00:00
|
|
|
void green_led_on(void)
|
|
|
|
{
|
2017-01-19 08:51:45 +00:00
|
|
|
__led_set(CONFIG_LED_STATUS_GREEN, CONFIG_LED_STATUS_ON);
|
2015-08-21 13:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void green_led_off(void)
|
|
|
|
{
|
2017-01-19 08:51:45 +00:00
|
|
|
__led_set(CONFIG_LED_STATUS_GREEN, CONFIG_LED_STATUS_OFF);
|
2015-08-21 13:13:20 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-19 08:51:45 +00:00
|
|
|
#ifdef CONFIG_LED_STATUS_YELLOW
|
2015-08-21 13:13:20 +00:00
|
|
|
void yellow_led_on(void)
|
|
|
|
{
|
2017-01-19 08:51:45 +00:00
|
|
|
__led_set(CONFIG_LED_STATUS_YELLOW, CONFIG_LED_STATUS_ON);
|
2015-08-21 13:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void yellow_led_off(void)
|
|
|
|
{
|
2017-01-19 08:51:45 +00:00
|
|
|
__led_set(CONFIG_LED_STATUS_YELLOW, CONFIG_LED_STATUS_OFF);
|
2015-08-21 13:13:20 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-19 08:51:45 +00:00
|
|
|
#ifdef CONFIG_LED_STATUS_BLUE
|
2015-08-21 13:13:20 +00:00
|
|
|
void blue_led_on(void)
|
|
|
|
{
|
2017-01-19 08:51:45 +00:00
|
|
|
__led_set(CONFIG_LED_STATUS_BLUE, CONFIG_LED_STATUS_ON);
|
2015-08-21 13:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void blue_led_off(void)
|
|
|
|
{
|
2017-01-19 08:51:45 +00:00
|
|
|
__led_set(CONFIG_LED_STATUS_BLUE, CONFIG_LED_STATUS_OFF);
|
2015-08-21 13:13:20 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_GPIO_LED_STUBS */
|