diff options
author | Michael Walle <michael@walle.cc> | 2022-08-17 22:38:04 +0300 |
---|---|---|
committer | Stefan Roese <sr@denx.de> | 2022-08-23 13:40:06 +0300 |
commit | 7c9bd92eeaa1ad4abacd5bd64fea20f75bc3d1e5 (patch) | |
tree | cd7e7fdb3955fd322acaa829d1a3a884654ba382 /board/buffalo/lsxl | |
parent | aa088beac3aca0dd9b40f60b0b1e5ab1c6bae471 (diff) | |
download | u-boot-7c9bd92eeaa1ad4abacd5bd64fea20f75bc3d1e5.tar.xz |
board: lsxl: convert to DM_GPIO
Use the new mvebu GPIO driver and convert all the function calls to the
former kirkwood GPIO driver. This means that we are now using the LED
uclass and the regulator uclass. Unfortunately, the GPIO LED doesn't
offer a blinking method. Thus we are now stuck with solid on and off
states, which makes debugging a bit harder. Also, there is no GPIO fan
driver for now.
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'board/buffalo/lsxl')
-rw-r--r-- | board/buffalo/lsxl/lsxl.c | 140 |
1 files changed, 86 insertions, 54 deletions
diff --git a/board/buffalo/lsxl/lsxl.c b/board/buffalo/lsxl/lsxl.c index 7fab5fbe44..6a866b5470 100644 --- a/board/buffalo/lsxl/lsxl.c +++ b/board/buffalo/lsxl/lsxl.c @@ -9,16 +9,18 @@ #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" @@ -118,48 +120,43 @@ int board_early_init_f(void) 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; } } @@ -169,32 +166,56 @@ int board_init(void) /* 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) @@ -203,7 +224,7 @@ 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); } } @@ -231,17 +252,24 @@ static void rescue_mode(void) 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; } } @@ -250,6 +278,10 @@ static void check_push_button(void) erase_environment(); else if (i >= 10) force_rescue_mode = true; + + return; +err: + printf("error in %s\n", __func__); } int board_early_init_r(void) @@ -279,6 +311,6 @@ void show_boot_progress(int progress) if (progress == -BOOTSTAGE_ID_NET_LOADED) return; - set_led(LED_ALARM_BLINKING); + set_led(LSXL_LED_ALARM); } #endif |