blob: 3e95727d798309bf9125f5d0f722334174062b3b [file] [log] [blame]
Thomas Chou3e6b86b2010-04-30 11:34:14 +08001/*
2 * Status LED driver based on GPIO access conventions of Linux
3 *
4 * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
Thomas Chouec3b4982010-06-09 13:32:46 +08005 * Licensed under the GPL-2 or later.
Thomas Chou3e6b86b2010-04-30 11:34:14 +08006 */
7
8#include <common.h>
9#include <status_led.h>
10#include <asm/gpio.h>
11
Igor Grinberg9dfdcdf2013-11-08 01:03:52 +020012#ifndef CONFIG_GPIO_LED_INVERTED_TABLE
13#define CONFIG_GPIO_LED_INVERTED_TABLE {}
14#endif
15
16static led_id_t gpio_led_inv[] = CONFIG_GPIO_LED_INVERTED_TABLE;
17
18static int gpio_led_gpio_value(led_id_t mask, int state)
19{
20 int i, gpio_value = (state == STATUS_LED_ON);
21
22 for (i = 0; i < ARRAY_SIZE(gpio_led_inv); i++) {
23 if (gpio_led_inv[i] == mask)
24 gpio_value = !gpio_value;
25 }
26
27 return gpio_value;
28}
29
Thomas Chou3e6b86b2010-04-30 11:34:14 +080030void __led_init(led_id_t mask, int state)
31{
Igor Grinberg9dfdcdf2013-11-08 01:03:52 +020032 int gpio_value;
33
Igor Grinberg6516f812013-11-08 01:03:51 +020034 if (gpio_request(mask, "gpio_led") != 0) {
35 printf("%s: failed requesting GPIO%lu!\n", __func__, mask);
36 return;
37 }
38
Igor Grinberg9dfdcdf2013-11-08 01:03:52 +020039 gpio_value = gpio_led_gpio_value(mask, state);
40 gpio_direction_output(mask, gpio_value);
Thomas Chou3e6b86b2010-04-30 11:34:14 +080041}
42
43void __led_set(led_id_t mask, int state)
44{
Igor Grinberg9dfdcdf2013-11-08 01:03:52 +020045 int gpio_value = gpio_led_gpio_value(mask, state);
46
47 gpio_set_value(mask, gpio_value);
Thomas Chou3e6b86b2010-04-30 11:34:14 +080048}
49
50void __led_toggle(led_id_t mask)
51{
52 gpio_set_value(mask, !gpio_get_value(mask));
53}