X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=sidebyside;f=board%2Fti%2Fbeagle%2Fled.c;h=a913a4c84aa624453138ce0ad6fa8180db61fc1b;hb=1e4b45c8f753f4523b8f60d3ce4191b6116966c0;hp=d3de51f2f5007e98cb37ae16b44ef51998db16d4;hpb=f87824efddf3d09d6bb2f01663170f5d7107fd62;p=oweals%2Fu-boot.git diff --git a/board/ti/beagle/led.c b/board/ti/beagle/led.c index d3de51f2f5..a913a4c84a 100644 --- a/board/ti/beagle/led.c +++ b/board/ti/beagle/led.c @@ -2,89 +2,71 @@ * Copyright (c) 2010 Texas Instruments, Inc. * Jason Kridner * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ #include #include #include #include #include -#include - -static unsigned int saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF}; +#include /* GPIO pins for the LEDs */ #define BEAGLE_LED_USR0 150 #define BEAGLE_LED_USR1 149 #ifdef STATUS_LED_GREEN -void green_LED_off (void) +void green_led_off(void) { __led_set (STATUS_LED_GREEN, 0); } -void green_LED_on (void) +void green_led_on(void) { __led_set (STATUS_LED_GREEN, 1); } #endif +static int get_led_gpio(led_id_t mask) +{ +#ifdef STATUS_LED_BIT + if (STATUS_LED_BIT & mask) + return BEAGLE_LED_USR0; +#endif +#ifdef STATUS_LED_BIT1 + if (STATUS_LED_BIT1 & mask) + return BEAGLE_LED_USR1; +#endif + + return 0; +} + void __led_init (led_id_t mask, int state) { - __led_set (mask, state); + int toggle_gpio; + + toggle_gpio = get_led_gpio(mask); + + if (toggle_gpio && !gpio_request(toggle_gpio, "led")) + __led_set(mask, state); } void __led_toggle (led_id_t mask) { -#ifdef STATUS_LED_BIT - if (STATUS_LED_BIT & mask) { - if (STATUS_LED_ON == saved_state[0]) - __led_set(STATUS_LED_BIT, 0); - else - __led_set(STATUS_LED_BIT, 1); - } -#endif -#ifdef STATUS_LED_BIT1 - if (STATUS_LED_BIT1 & mask) { - if (STATUS_LED_ON == saved_state[1]) - __led_set(STATUS_LED_BIT1, 0); - else - __led_set(STATUS_LED_BIT1, 1); + int state, toggle_gpio; + + toggle_gpio = get_led_gpio(mask); + if (toggle_gpio) { + state = gpio_get_value(toggle_gpio); + gpio_direction_output(toggle_gpio, !state); } -#endif } void __led_set (led_id_t mask, int state) { -#ifdef STATUS_LED_BIT - if (STATUS_LED_BIT & mask) { - if (!omap_request_gpio(BEAGLE_LED_USR0)) { - omap_set_gpio_direction(BEAGLE_LED_USR0, 0); - omap_set_gpio_dataout(BEAGLE_LED_USR0, state); - } - saved_state[0] = state; - } -#endif -#ifdef STATUS_LED_BIT1 - if (STATUS_LED_BIT1 & mask) { - if (!omap_request_gpio(BEAGLE_LED_USR1)) { - omap_set_gpio_direction(BEAGLE_LED_USR1, 0); - omap_set_gpio_dataout(BEAGLE_LED_USR1, state); - } - saved_state[1] = state; - } -#endif + int toggle_gpio; + + toggle_gpio = get_led_gpio(mask); + if (toggle_gpio) + gpio_direction_output(toggle_gpio, state); }