From 0547e60e94dcf1666697694f8be39c0efbb0149e Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Wed, 23 Nov 2022 09:51:35 +0800 Subject: [PATCH 1/2] define led env name in dts Signed-off-by: Jianhui Zhao --- uboot-mtk-20220606/arch/arm/dts/gl-mt2500.dts | 3 ++ uboot-mtk-20220606/arch/arm/dts/gl-mt3000.dts | 3 ++ uboot-mtk-20220606/cmd/glbtn.c | 43 +++++++++++++++---- uboot-mtk-20220606/failsafe/failsafe.c | 10 +++-- uboot-mtk-20220606/net/httpd.c | 6 ++- 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/uboot-mtk-20220606/arch/arm/dts/gl-mt2500.dts b/uboot-mtk-20220606/arch/arm/dts/gl-mt2500.dts index 67c3ae341..a9983f84b 100755 --- a/uboot-mtk-20220606/arch/arm/dts/gl-mt2500.dts +++ b/uboot-mtk-20220606/arch/arm/dts/gl-mt2500.dts @@ -24,6 +24,9 @@ environment { lu = "mtkupgrade fip uboot-gl-mt2500.bin"; lf = "mtkupgrade fw openwrt-gl-mt2500.bin"; + blink_led = "blue:run"; + system_led = "white:system"; + gpio_usb_power = "12"; }; }; diff --git a/uboot-mtk-20220606/arch/arm/dts/gl-mt3000.dts b/uboot-mtk-20220606/arch/arm/dts/gl-mt3000.dts index ece197a92..e9cf56931 100644 --- a/uboot-mtk-20220606/arch/arm/dts/gl-mt3000.dts +++ b/uboot-mtk-20220606/arch/arm/dts/gl-mt3000.dts @@ -24,6 +24,9 @@ environment { lu = "mtkupgrade fip uboot-gl-mt3000.bin"; lf = "mtkupgrade fw openwrt-gl-mt3000.bin"; + blink_led = "blue:run"; + system_led = "white:system"; + gpio_usb_power = "12"; }; }; diff --git a/uboot-mtk-20220606/cmd/glbtn.c b/uboot-mtk-20220606/cmd/glbtn.c index 12f838cab..d250fd88d 100644 --- a/uboot-mtk-20220606/cmd/glbtn.c +++ b/uboot-mtk-20220606/cmd/glbtn.c @@ -6,10 +6,35 @@ static struct poller_async led_p; +void led_control(const char *cmd, const char *name, const char *arg) +{ + const char *led = env_get(name); + char buf[128]; + + if (!led) + return; + + sprintf(buf, "%s %s %s", cmd, led, arg); + + run_command(buf, 0); +} + +static void usb_power_clr(void) +{ + const char *num = env_get("gpio_usb_power"); + char buf[128]; + + if (!num) + return; + + sprintf(buf, "gpio clear %s", num); + run_command(buf, 0); +} + static void led_action_post(void *arg) { - run_command("ledblink blue:run 0", 0); - run_command("led blue:run on", 0); + led_control("ledblink", "blink_led", "0"); + led_control("led", "blink_led", "on"); } static int do_glbtn(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -19,8 +44,10 @@ static int do_glbtn(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[ struct udevice *dev; ulong ts; - run_command("ledblink blue:run 250", 0); - run_command("gpio clear 12", 0); + led_control("ledblink", "blink_led", "250"); + + usb_power_clr(); + ret = button_get_by_label(button_label, &dev); if (ret) { printf("Button '%s' not found (err=%d)\n", button_label, ret); @@ -33,7 +60,7 @@ static int do_glbtn(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[ return CMD_RET_SUCCESS; } - run_command("ledblink blue:run 500", 0); + led_control("ledblink", "blink_led", "500"); printf("RESET button is pressed for: %2d second(s)", counter++); @@ -50,13 +77,13 @@ static int do_glbtn(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[ printf("\n"); - run_command("ledblink blue:run 0", 0); + led_control("ledblink", "blink_led", "0"); if (counter == 6) { - run_command("led white:system on", 0); + led_control("led", "system_led", "on"); run_command("httpd", 0); } else { - run_command("led blue:run on", 0); + led_control("ledblink", "blink_led", "0"); } return CMD_RET_SUCCESS; diff --git a/uboot-mtk-20220606/failsafe/failsafe.c b/uboot-mtk-20220606/failsafe/failsafe.c index 91c463e9d..976f446cb 100644 --- a/uboot-mtk-20220606/failsafe/failsafe.c +++ b/uboot-mtk-20220606/failsafe/failsafe.c @@ -18,6 +18,8 @@ #include "fs.h" +void led_control(const char *cmd, const char *name, const char *arg); + enum { FW_TYPE_GPT, FW_TYPE_BL2, @@ -70,7 +72,7 @@ static int write_firmware_failsafe(size_t data_addr, uint32_t data_size) { int r; - run_command("ledblink blue:run 100", 0); + led_control("ledblink", "blink_led", "100"); switch (fw_type) { #ifdef CONFIG_MT7981_BOOTMENU_EMMC @@ -94,7 +96,7 @@ static int write_firmware_failsafe(size_t data_addr, uint32_t data_size) break; } - run_command("ledblink blue:run 0", 0); + led_control("ledblink", "blink_led", "0"); return r; } @@ -293,8 +295,8 @@ static void result_handler(enum httpd_uri_handler_status status, /* invalidate upload identifier */ upload_data_id = rand(); - run_command("led blue:run on", 0); - run_command("led white:system off", 0); + led_control("led", "blink_led", "on"); + led_control("led", "system_led", "off"); if (!st->ret) response->data = "success"; diff --git a/uboot-mtk-20220606/net/httpd.c b/uboot-mtk-20220606/net/httpd.c index fc8c4f0ef..51ee9695f 100644 --- a/uboot-mtk-20220606/net/httpd.c +++ b/uboot-mtk-20220606/net/httpd.c @@ -16,6 +16,8 @@ #include #include +void led_control(const char *cmd, const char *name, const char *arg); + struct httpd_instance { struct list_head node; @@ -641,7 +643,7 @@ static int httpd_handle_request(struct httpd_instance *inst, free(boundary); } - run_command("ledblink blue:run 0", 0); + led_control("ledblink", "blink_led", "0"); /* call uri handler */ assert((size_t) req->urih->cb > CONFIG_SYS_SDRAM_BASE); @@ -684,7 +686,7 @@ static void httpd_rx(struct httpd_instance *inst, struct tcb_cb_data *cbd) u8 sip[4]; if (pdata->status == HTTPD_S_NEW) { - run_command("ledblink blue:run 100", 0); + led_control("ledblink", "blink_led", "100"); memcpy(sip, &cbd->sip, 4); debug("New connection from %d.%d.%d.%d:%d\n", From 16180c28926fb38c0a85efe90d4811660d38969a Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Wed, 23 Nov 2022 10:53:27 +0800 Subject: [PATCH 2/2] support define multiple gpio power in dts Signed-off-by: Jianhui Zhao --- uboot-mtk-20220606/arch/arm/dts/gl-mt2500.dts | 7 +++--- uboot-mtk-20220606/arch/arm/dts/gl-mt3000.dts | 7 +++--- uboot-mtk-20220606/cmd/glbtn.c | 25 +++++++++++++------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/uboot-mtk-20220606/arch/arm/dts/gl-mt2500.dts b/uboot-mtk-20220606/arch/arm/dts/gl-mt2500.dts index a9983f84b..56cef5dab 100755 --- a/uboot-mtk-20220606/arch/arm/dts/gl-mt2500.dts +++ b/uboot-mtk-20220606/arch/arm/dts/gl-mt2500.dts @@ -21,12 +21,13 @@ config { bootcmd = "mtkboardboot"; + blink_led = "blue:run"; + system_led = "white:system"; + gpio_power_clr = <12>; + environment { lu = "mtkupgrade fip uboot-gl-mt2500.bin"; lf = "mtkupgrade fw openwrt-gl-mt2500.bin"; - blink_led = "blue:run"; - system_led = "white:system"; - gpio_usb_power = "12"; }; }; diff --git a/uboot-mtk-20220606/arch/arm/dts/gl-mt3000.dts b/uboot-mtk-20220606/arch/arm/dts/gl-mt3000.dts index e9cf56931..4d633e456 100644 --- a/uboot-mtk-20220606/arch/arm/dts/gl-mt3000.dts +++ b/uboot-mtk-20220606/arch/arm/dts/gl-mt3000.dts @@ -21,12 +21,13 @@ config { bootcmd = "mtkboardboot"; + blink_led = "blue:run"; + system_led = "white:system"; + gpio_power_clr = <12>; + environment { lu = "mtkupgrade fip uboot-gl-mt3000.bin"; lf = "mtkupgrade fw openwrt-gl-mt3000.bin"; - blink_led = "blue:run"; - system_led = "white:system"; - gpio_usb_power = "12"; }; }; diff --git a/uboot-mtk-20220606/cmd/glbtn.c b/uboot-mtk-20220606/cmd/glbtn.c index d250fd88d..2e0b6c53f 100644 --- a/uboot-mtk-20220606/cmd/glbtn.c +++ b/uboot-mtk-20220606/cmd/glbtn.c @@ -3,12 +3,13 @@ #include #include #include +#include static struct poller_async led_p; void led_control(const char *cmd, const char *name, const char *arg) { - const char *led = env_get(name); + const char *led = ofnode_conf_read_str(name); char buf[128]; if (!led) @@ -19,16 +20,24 @@ void led_control(const char *cmd, const char *name, const char *arg) run_command(buf, 0); } -static void usb_power_clr(void) +static void gpio_power_clr(void) { - const char *num = env_get("gpio_usb_power"); - char buf[128]; + ofnode node = ofnode_path("/config"); + char cmd[128]; + const u32 *val; + int size, i; - if (!num) + if (!ofnode_valid(node)) return; - sprintf(buf, "gpio clear %s", num); - run_command(buf, 0); + val = ofnode_read_prop(node, "gpio_power_clr", &size); + if (!val) + return; + + for (i = 0; i < size / 4; i++) { + sprintf(cmd, "gpio clear %u", fdt32_to_cpu(val[i])); + run_command(cmd, 0); + } } static void led_action_post(void *arg) @@ -46,7 +55,7 @@ static int do_glbtn(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[ led_control("ledblink", "blink_led", "250"); - usb_power_clr(); + gpio_power_clr(); ret = button_get_by_label(button_label, &dev); if (ret) {