Thomas Chou | 3e6b86b | 2010-04-30 11:34:14 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Status LED driver based on GPIO access conventions of Linux |
| 3 | * |
| 4 | * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw> |
Thomas Chou | ec3b498 | 2010-06-09 13:32:46 +0800 | [diff] [blame] | 5 | * Licensed under the GPL-2 or later. |
Thomas Chou | 3e6b86b | 2010-04-30 11:34:14 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <status_led.h> |
| 10 | #include <asm/gpio.h> |
| 11 | |
Thomas Chou | 3e6b86b | 2010-04-30 11:34:14 +0800 | [diff] [blame] | 12 | void __led_init(led_id_t mask, int state) |
| 13 | { |
Igor Grinberg | 6516f81 | 2013-11-08 01:03:51 +0200 | [diff] [blame^] | 14 | if (gpio_request(mask, "gpio_led") != 0) { |
| 15 | printf("%s: failed requesting GPIO%lu!\n", __func__, mask); |
| 16 | return; |
| 17 | } |
| 18 | |
Thomas Chou | ec3b498 | 2010-06-09 13:32:46 +0800 | [diff] [blame] | 19 | gpio_direction_output(mask, state == STATUS_LED_ON); |
Thomas Chou | 3e6b86b | 2010-04-30 11:34:14 +0800 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | void __led_set(led_id_t mask, int state) |
| 23 | { |
Thomas Chou | ec3b498 | 2010-06-09 13:32:46 +0800 | [diff] [blame] | 24 | gpio_set_value(mask, state == STATUS_LED_ON); |
Thomas Chou | 3e6b86b | 2010-04-30 11:34:14 +0800 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | void __led_toggle(led_id_t mask) |
| 28 | { |
| 29 | gpio_set_value(mask, !gpio_get_value(mask)); |
| 30 | } |