#include <common.h>
#include <bootstage.h>
+#include <button.h>
#include <command.h>
#include <env.h>
#include <init.h>
+#include <led.h>
+#include <power/regulator.h>
#include <spi.h>
#include <spi_flash.h>
-#include <asm/arch/soc.h>
#include <asm/arch/cpu.h>
#include <asm/arch/mpp.h>
-#include <asm/arch/gpio.h>
#include <asm/global_data.h>
+#include <asm/io.h>
#include <linux/delay.h>
#include "lsxl.h"
return 0;
}
-#define LED_OFF 0
-#define LED_ALARM_ON 1
-#define LED_ALARM_BLINKING 2
-#define LED_POWER_ON 3
-#define LED_POWER_BLINKING 4
-#define LED_INFO_ON 5
-#define LED_INFO_BLINKING 6
+enum {
+ LSXL_LED_OFF,
+ LSXL_LED_ALARM,
+ LSXL_LED_POWER,
+ LSXL_LED_INFO,
+};
-static void __set_led(int blink_alarm, int blink_info, int blink_power,
- int value_alarm, int value_info, int value_power)
+static void __set_led(int alarm, int info, int power)
{
- kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm);
- kw_gpio_set_blink(GPIO_INFO_LED, blink_info);
- kw_gpio_set_blink(GPIO_POWER_LED, blink_power);
- kw_gpio_set_value(GPIO_ALARM_LED, value_alarm);
- kw_gpio_set_value(GPIO_INFO_LED, value_info);
- kw_gpio_set_value(GPIO_POWER_LED, value_power);
+ struct udevice *led;
+ int ret;
+
+ ret = led_get_by_label("lsxl:red:alarm", &led);
+ if (!ret)
+ led_set_state(led, alarm);
+ ret = led_get_by_label("lsxl:amber:info", &led);
+ if (!ret)
+ led_set_state(led, info);
+ ret = led_get_by_label("lsxl:blue:power", &led);
+ if (!ret)
+ led_set_state(led, power);
}
static void set_led(int state)
{
switch (state) {
- case LED_OFF:
- __set_led(0, 0, 0, 1, 1, 1);
+ case LSXL_LED_OFF:
+ __set_led(0, 0, 0);
break;
- case LED_ALARM_ON:
- __set_led(0, 0, 0, 0, 1, 1);
+ case LSXL_LED_ALARM:
+ __set_led(1, 0, 0);
break;
- case LED_ALARM_BLINKING:
- __set_led(1, 0, 0, 1, 1, 1);
+ case LSXL_LED_INFO:
+ __set_led(0, 1, 0);
break;
- case LED_INFO_ON:
- __set_led(0, 0, 0, 1, 0, 1);
- break;
- case LED_INFO_BLINKING:
- __set_led(0, 1, 0, 1, 1, 1);
- break;
- case LED_POWER_ON:
- __set_led(0, 0, 0, 1, 1, 0);
- break;
- case LED_POWER_BLINKING:
- __set_led(0, 0, 1, 1, 1, 1);
+ case LSXL_LED_POWER:
+ __set_led(0, 0, 1);
break;
}
}
/* address of boot parameters */
gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
- set_led(LED_POWER_BLINKING);
+ set_led(LSXL_LED_POWER);
return 0;
}
static void check_power_switch(void)
{
- if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
- /* turn off fan, HDD and USB power */
- kw_gpio_set_value(GPIO_HDD_POWER, 0);
- kw_gpio_set_value(GPIO_USB_VBUS, 0);
- kw_gpio_set_value(GPIO_FAN_HIGH, 1);
- kw_gpio_set_value(GPIO_FAN_LOW, 1);
- set_led(LED_OFF);
+ struct udevice *power_button, *hdd_power, *usb_power;
+ int ret;
+
+ ret = button_get_by_label("Power-on Switch", &power_button);
+ if (ret)
+ goto err;
+
+ ret = regulator_get_by_platname("HDD Power", &hdd_power);
+ if (ret)
+ goto err;
+
+ ret = regulator_get_by_platname("USB Power", &usb_power);
+ if (ret)
+ goto err;
+
+ if (button_get_state(power_button) == BUTTON_OFF) {
+ ret = regulator_set_enable(hdd_power, false);
+ if (ret)
+ goto err;
+ ret = regulator_set_enable(usb_power, false);
+ if (ret)
+ goto err;
+ /* TODO: fan off */
+ set_led(LSXL_LED_OFF);
/* loop until released */
- while (kw_gpio_get_value(GPIO_POWER_SWITCH))
+ while (button_get_state(power_button) == BUTTON_OFF)
;
/* turn power on again */
- kw_gpio_set_value(GPIO_HDD_POWER, 1);
- kw_gpio_set_value(GPIO_USB_VBUS, 1);
- kw_gpio_set_value(GPIO_FAN_HIGH, 0);
- kw_gpio_set_value(GPIO_FAN_LOW, 0);
- set_led(LED_POWER_BLINKING);
- }
+ ret = regulator_set_enable(hdd_power, true);
+ if (ret)
+ goto err;
+ ret = regulator_set_enable(usb_power, true);
+ if (ret)
+ goto err;
+ /* TODO: fan on */
+ set_led(LSXL_LED_POWER);
+ };
+
+ return;
+err:
+ printf("error in %s\n", __func__);
}
void check_enetaddr(void)
if (!eth_env_get_enetaddr("ethaddr", enetaddr)) {
/* signal unset/invalid ethaddr to user */
- set_led(LED_INFO_BLINKING);
+ set_led(LSXL_LED_INFO);
}
}
static void check_push_button(void)
{
+ struct udevice *func_button;
int i = 0;
- while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) {
+ int ret;
+
+ ret = button_get_by_label("Function Button", &func_button);
+ if (ret)
+ goto err;
+
+ while (button_get_state(func_button) == BUTTON_ON) {
udelay(100000);
i++;
if (i == 10)
- set_led(LED_INFO_ON);
+ set_led(LSXL_LED_INFO);
if (i >= 100) {
- set_led(LED_INFO_BLINKING);
+ set_led(LSXL_LED_ALARM);
break;
}
}
erase_environment();
else if (i >= 10)
force_rescue_mode = true;
+
+ return;
+err:
+ printf("error in %s\n", __func__);
}
int board_early_init_r(void)
if (progress == -BOOTSTAGE_ID_NET_LOADED)
return;
- set_led(LED_ALARM_BLINKING);
+ set_led(LSXL_LED_ALARM);
}
#endif