1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * Copyright (C) 2010, 2009 Matthias Kaehlcke <matthias@kaehlcke.net> 4 */ 5 6#include <asm/io.h> 7#include <asm/arch/ep93xx.h> 8#include <config.h> 9#include <status_led.h> 10 11static uint8_t saved_state[2] = {CONFIG_LED_STATUS_OFF, CONFIG_LED_STATUS_OFF}; 12static uint32_t gpio_pin[2] = {1 << CONFIG_LED_STATUS_GREEN, 13 1 << CONFIG_LED_STATUS_RED}; 14 15static inline void switch_LED_on(uint8_t led) 16{ 17 register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE; 18 19 writel(readl(&gpio->pedr) | gpio_pin[led], &gpio->pedr); 20 saved_state[led] = CONFIG_LED_STATUS_ON; 21} 22 23static inline void switch_LED_off(uint8_t led) 24{ 25 register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE; 26 27 writel(readl(&gpio->pedr) & ~gpio_pin[led], &gpio->pedr); 28 saved_state[led] = CONFIG_LED_STATUS_OFF; 29} 30 31void red_led_on(void) 32{ 33 switch_LED_on(CONFIG_LED_STATUS_RED); 34} 35 36void red_led_off(void) 37{ 38 switch_LED_off(CONFIG_LED_STATUS_RED); 39} 40 41void green_led_on(void) 42{ 43 switch_LED_on(CONFIG_LED_STATUS_GREEN); 44} 45 46void green_led_off(void) 47{ 48 switch_LED_off(CONFIG_LED_STATUS_GREEN); 49} 50 51void __led_init(led_id_t mask, int state) 52{ 53 __led_set(mask, state); 54} 55 56void __led_toggle(led_id_t mask) 57{ 58 if (CONFIG_LED_STATUS_RED == mask) { 59 if (CONFIG_LED_STATUS_ON == saved_state[CONFIG_LED_STATUS_RED]) 60 red_led_off(); 61 else 62 red_led_on(); 63 } else if (CONFIG_LED_STATUS_GREEN == mask) { 64 if (CONFIG_LED_STATUS_ON == 65 saved_state[CONFIG_LED_STATUS_GREEN]) 66 green_led_off(); 67 else 68 green_led_on(); 69 } 70} 71 72void __led_set(led_id_t mask, int state) 73{ 74 if (CONFIG_LED_STATUS_RED == mask) { 75 if (CONFIG_LED_STATUS_ON == state) 76 red_led_on(); 77 else 78 red_led_off(); 79 } else if (CONFIG_LED_STATUS_GREEN == mask) { 80 if (CONFIG_LED_STATUS_ON == state) 81 green_led_on(); 82 else 83 green_led_off(); 84 } 85} 86