Skip to content

Commit

Permalink
failsafe: rework button detection implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Shiji Yang <[email protected]>
  • Loading branch information
DragonBluep committed May 2, 2023
1 parent 0f0fc2d commit ba4c45b
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 284 deletions.
117 changes: 0 additions & 117 deletions arch/mips/mach-mt7621/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,123 +62,6 @@ config BOARD_MT7621_NAND_TEMPLATE

endchoice

menu "MT7621 GPIO Pin Mapping"
depends on MACH_MT7621

config MT7621_SYS_LED
bool "Enable System LED"
default y
config MT7621_SYS_LED_PIN
int "System LED GPIO Pin Number"
depends on MT7621_SYS_LED
config MT7621_SYS_LED_LEVEL
int "System LED Trigger Level"
depends on MT7621_SYS_LED
default 0
range 0 1
help
0:low 1:high

config MT7621_PWR_LED
bool "Enable Power LED"
default n
config MT7621_PWR_LED_PIN
int "Power LED GPIO Pin Number"
depends on MT7621_PWR_LED
config MT7621_PWR_LED_LEVEL
int "Power LED Trigger Level"
depends on MT7621_PWR_LED
default 0
range 0 1

config MT7621_EXTRA_GPIO1
bool "Enable Init Extra GPIO 1"
default n
config MT7621_EXTRA_GPIO1_PIN
int "Extra GPIO 1 Pin Number"
depends on MT7621_EXTRA_GPIO1
config MT7621_EXTRA_GPIO1_LEVEL
int "Extra GPIO 1 Default Level"
depends on MT7621_EXTRA_GPIO1
default 1
range 0 1

config MT7621_EXTRA_GPIO2
bool "Enable Init Extra GPIO 2"
default n
config MT7621_EXTRA_GPIO2_PIN
int "Extra GPIO 2 Pin Number"
depends on MT7621_EXTRA_GPIO2
config MT7621_EXTRA_GPIO2_LEVEL
int "Extra GPIO 2 Default Level"
depends on MT7621_EXTRA_GPIO2
default 1
range 0 1

config MT7621_EXTRA_GPIO3
bool "Enable Init Extra GPIO 3"
default n
config MT7621_EXTRA_GPIO3_PIN
int "Extra GPIO 3 Pin Number"
depends on MT7621_EXTRA_GPIO3
config MT7621_EXTRA_GPIO3_LEVEL
int "Extra GPIO 3 Default Level"
depends on MT7621_EXTRA_GPIO3
default 1
range 0 1

config MT7621_EXTRA_GPIO4
bool "Enable Init Extra GPIO 4"
default n
config MT7621_EXTRA_GPIO4_PIN
int "Extra GPIO 4 Pin Number"
depends on MT7621_EXTRA_GPIO4
config MT7621_EXTRA_GPIO4_LEVEL
int "Extra GPIO 4 Default Level"
depends on MT7621_EXTRA_GPIO4
default 1
range 0 1

config MT7621_EXTRA_GPIO5
bool "Enable Init Extra GPIO 5"
default n
config MT7621_EXTRA_GPIO5_PIN
int "Extra GPIO 5 Pin Number"
depends on MT7621_EXTRA_GPIO5
config MT7621_EXTRA_GPIO5_LEVEL
int "Extra GPIO 5 Default Level"
depends on MT7621_EXTRA_GPIO5
default 1
range 0 1

config MT7621_RST_BTN
bool "Enable Reset Button"
default y
config MT7621_RST_BTN_PIN
int "Reset Button GPIO Pin Number"
depends on MT7621_RST_BTN
config MT7621_RST_BTN_LEVEL
int "Reset Button Trigger Level"
depends on MT7621_RST_BTN
default 0
range 0 1
help
0:low 1:high

config MT7621_WPS_BTN
bool "Enable WPS Button"
default n
config MT7621_WPS_BTN_PIN
int "WPS Button GPIO Pin Number"
depends on MT7621_WPS_BTN
config MT7621_WPS_BTN_LEVEL
int "WPS Button Trigger Level"
depends on MT7621_WPS_BTN
default 0
range 0 1

endmenu

config SPL_ALIGN_TO
hex "SPL alignment size"
default 0x10000 if SPI_BOOT
Expand Down
1 change: 0 additions & 1 deletion board/ralink/common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ endif
ifndef CONFIG_SPL_BUILD
obj-y += cmd_mtkupgrade.o
obj-y += cmd_mtkautoboot.o
obj-y += gpio.o
obj-$(CONFIG_MTK_DUAL_IMAGE_SUPPORT) += dual_image.o
endif
30 changes: 25 additions & 5 deletions board/ralink/common/cmd_mtkautoboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include <common.h>
#include "gpio.h"
#include <asm-generic/gpio.h>

struct mtk_bootmenu_entry {
const char *desc;
Expand Down Expand Up @@ -40,12 +40,32 @@ static int do_mtkautoboot(cmd_tbl_t *cmdtp, int flag, int argc,
const char *delay_str;
u32 delay = CONFIG_MTKAUTOBOOT_DELAY;

#ifdef CONFIG_WEBUI_FAILSAFE_ON_BUTTON
if (mt7621_is_reset_pressed()) {
printf("Enter Failsafe Mode by Press Reset Button!\n");
#ifdef CONFIG_FAILSAFE_ON_BUTTON
for (i = 0; i < 5; i++) {
if (gpio_get_value(MT7621_BUTTON_RESET) != 0)
break;

mdelay(100);
#ifdef MT7621_LED_STATUS1
gpio_direction_output(MT7621_LED_STATUS1, 1);
#endif // MT7621_LED_STATUS1
#ifdef MT7621_LED_STATUS2
gpio_direction_output(MT7621_LED_STATUS2, 0);
#endif // MT7621_LED_STATUS2
mdelay(100);
#ifdef MT7621_LED_STATUS1
gpio_direction_output(MT7621_LED_STATUS1, 0);
#endif // MT7621_LED_STATUS1
#ifdef MT7621_LED_STATUS2
gpio_direction_output(MT7621_LED_STATUS2, 1);
#endif // MT7621_LED_STATUS2
}

if (i == 5) {
printf("Enter web failsafe mode by pressing reset button\n");
run_command("httpd", 0);
}
#endif // CONFIG_WEBUI_FAILSAFE_ON_BUTTON
#endif // CONFIG_FAILSAFE_ON_BUTTON

for (i = 0; i < ARRAY_SIZE(bootmenu_entries); i++) {
snprintf(key, sizeof(key), "bootmenu_%d", i);
Expand Down
151 changes: 0 additions & 151 deletions board/ralink/common/gpio.c

This file was deleted.

7 changes: 0 additions & 7 deletions board/ralink/common/gpio.h

This file was deleted.

38 changes: 38 additions & 0 deletions board/ralink/mt7621_nand_rfb/mt7621_nand_rfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <debug_uart.h>
#include <asm/spl.h>
#include <asm/io.h>
#include <asm-generic/gpio.h>
#include <nand.h>
#include <linux/mtd/mtd.h>
#include <mach/mt7621_regs.h>
Expand All @@ -22,6 +23,43 @@
static int nmbm_usable;
#endif

static inline int gpio_output_init(unsigned gpio, int value, const char *label)
{
int ret;

ret = gpio_request(gpio, label);
if (ret && ret != -EBUSY) {
printf("gpio: requesting pin %u failed\n", gpio);
return -1;
}

gpio_direction_output(gpio, value);

return 0;
}

static inline int gpio_input_init(unsigned gpio, const char *label)
{
int ret;

ret = gpio_request(gpio, label);
if (ret && ret != -EBUSY) {
printf("gpio: requesting pin %u failed\n", gpio);
return -1;
}

gpio_direction_input(gpio);

return 0;
}

#ifdef CONFIG_LAST_STAGE_INIT
int last_stage_init(void)
{
return 0;
}
#endif // CONFIG_LAST_STAGE_INIT

#ifdef CONFIG_DEBUG_UART_BOARD_INIT
void board_debug_uart_init(void)
{
Expand Down
Loading

0 comments on commit ba4c45b

Please sign in to comment.