uboot-mediatek: fix factory/reset button
U-Boot commit ea6fdc13595 ("dm: button: add support for linux_code in
button-gpio.c driver") makes it mandatory to specify linux,code for all
buttons. As that broke handling of the reset button in U-Boot with the
update to U-Boot 2023.04, add linux,code for all butons.
Reported-by: @DragonBluep
Fixes: 50f7c5af4a ("uboot-mediatek: update to v2023.04")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
			
			
This commit is contained in:
		| @@ -17,7 +17,7 @@ | ||||
|   | ||||
|  #include <mtd.h> | ||||
|  #include <linux/mtd/mtd.h> | ||||
| @@ -25,7 +32,19 @@ int board_init(void) | ||||
| @@ -25,7 +32,22 @@ int board_init(void) | ||||
|   | ||||
|  int board_late_init(void) | ||||
|  { | ||||
| @@ -27,7 +27,10 @@ | ||||
| +	if (!button_get_by_label(CONFIG_RESET_BUTTON_LABEL, &dev)) { | ||||
| +		puts("reset button found\n"); | ||||
| +#ifdef CONFIG_RESET_BUTTON_SETTLE_DELAY | ||||
| +		mdelay(CONFIG_RESET_BUTTON_SETTLE_DELAY); | ||||
| +		if (CONFIG_RESET_BUTTON_SETTLE_DELAY > 0) { | ||||
| +			button_get_state(dev); | ||||
| +			mdelay(CONFIG_RESET_BUTTON_SETTLE_DELAY); | ||||
| +		} | ||||
| +#endif | ||||
| +		if (button_get_state(dev) == BUTTON_ON) { | ||||
| +			puts("button pushed, resetting environment\n"); | ||||
| @@ -40,7 +43,7 @@ | ||||
|  } | ||||
| --- a/arch/arm/mach-mediatek/Kconfig | ||||
| +++ b/arch/arm/mach-mediatek/Kconfig | ||||
| @@ -140,4 +140,8 @@ config MTK_BROM_HEADER_INFO | ||||
| @@ -140,4 +140,11 @@ config MTK_BROM_HEADER_INFO | ||||
|   | ||||
|  source "board/mediatek/mt7629/Kconfig" | ||||
|   | ||||
| @@ -48,4 +51,7 @@ | ||||
| +	string "Button to trigger factory reset" | ||||
| +	default "reset" | ||||
| + | ||||
| +config RESET_BUTTON_SETTLE_DELAY | ||||
| +	int "Delay to wait for button to settle" | ||||
| +	default 0 | ||||
|  endif | ||||
|   | ||||
| @@ -18,7 +18,7 @@ | ||||
|   | ||||
|  DECLARE_GLOBAL_DATA_PTR; | ||||
|   | ||||
| @@ -41,3 +50,22 @@ int mmc_get_env_dev(void) | ||||
| @@ -41,3 +50,25 @@ int mmc_get_env_dev(void) | ||||
|  	return mmc_get_boot_dev(); | ||||
|  } | ||||
|  #endif | ||||
| @@ -30,7 +30,10 @@ | ||||
| +	if (!button_get_by_label(CONFIG_RESET_BUTTON_LABEL, &dev)) { | ||||
| +		puts("reset button found\n"); | ||||
| +#ifdef CONFIG_RESET_BUTTON_SETTLE_DELAY | ||||
| +		mdelay(CONFIG_RESET_BUTTON_SETTLE_DELAY); | ||||
| +		if (CONFIG_RESET_BUTTON_SETTLE_DELAY > 0) { | ||||
| +			button_get_state(dev); | ||||
| +			mdelay(CONFIG_RESET_BUTTON_SETTLE_DELAY); | ||||
| +		} | ||||
| +#endif | ||||
| +		if (button_get_state(dev) == BUTTON_ON) { | ||||
| +			puts("button pushed, resetting environment\n"); | ||||
|   | ||||
| @@ -17,7 +17,7 @@ | ||||
|   | ||||
|  #include <mtd.h> | ||||
|  #include <linux/mtd/mtd.h> | ||||
| @@ -24,7 +31,19 @@ int board_init(void) | ||||
| @@ -24,7 +31,22 @@ int board_init(void) | ||||
|   | ||||
|  int board_late_init(void) | ||||
|  { | ||||
| @@ -28,7 +28,10 @@ | ||||
| +	if (!button_get_by_label(CONFIG_RESET_BUTTON_LABEL, &dev)) { | ||||
| +		puts("reset button found\n"); | ||||
| +#ifdef CONFIG_RESET_BUTTON_SETTLE_DELAY | ||||
| +		mdelay(CONFIG_RESET_BUTTON_SETTLE_DELAY); | ||||
| +		if (CONFIG_RESET_BUTTON_SETTLE_DELAY > 0) { | ||||
| +			button_get_state(dev); | ||||
| +			mdelay(CONFIG_RESET_BUTTON_SETTLE_DELAY); | ||||
| +		} | ||||
| +#endif | ||||
| +		if (button_get_state(dev) == BUTTON_ON) { | ||||
| +			puts("button pushed, resetting environment\n"); | ||||
|   | ||||
| @@ -213,7 +213,15 @@ | ||||
| +_set_bmf=setenv _set_bmf ; setenv bootmenu_${_menu_next} "Reset all settings to factory defaults.=run reset_factory ; reset" ; setenv _menu_next | ||||
| --- a/arch/arm/dts/mt7623n-bananapi-bpi-r2.dts | ||||
| +++ b/arch/arm/dts/mt7623n-bananapi-bpi-r2.dts | ||||
| @@ -66,6 +66,15 @@ | ||||
| @@ -6,6 +6,7 @@ | ||||
|   */ | ||||
|   | ||||
|  /dts-v1/; | ||||
| +#include <dt-bindings/input/linux-event-codes.h> | ||||
|  #include "mt7623.dtsi" | ||||
|  #include "mt7623-u-boot.dtsi" | ||||
|   | ||||
| @@ -66,6 +67,16 @@ | ||||
|  			default-state = "off"; | ||||
|  		}; | ||||
|  	}; | ||||
| @@ -224,6 +232,7 @@ | ||||
| +		factory { | ||||
| +			label = "factory"; | ||||
| +			gpios = <&gpio 256 GPIO_ACTIVE_LOW>; | ||||
| +			linux,code = <KEY_RESTART>; | ||||
| +		}; | ||||
| +	}; | ||||
|  }; | ||||
|   | ||||
| @@ -191,3 +191,52 @@ | ||||
| +_update_bootdev=setenv _update_bootdev ; setenv bootargs "$console root=/dev/mmcblk0p65" | ||||
| +_switch_to_menu=setenv _switch_to_menu ; setenv bootdelay 3 ; setenv bootmenu_delay 3 ; setenv bootmenu_0 $bootmenu_0d ; setenv bootmenu_0d ; run _bootmenu_update_title | ||||
| +_bootmenu_update_title=setenv _bootmenu_update_title ; setenv bootmenu_title "$bootmenu_title                [33m$ver[0m" | ||||
| --- a/arch/arm/dts/mt7623a-unielec-u7623-02-emmc.dts | ||||
| +++ b/arch/arm/dts/mt7623a-unielec-u7623-02-emmc.dts | ||||
| @@ -6,6 +6,7 @@ | ||||
|   */ | ||||
|   | ||||
|  /dts-v1/; | ||||
| +#include <dt-bindings/input/linux-event-codes.h> | ||||
|  #include "mt7623.dtsi" | ||||
|  #include "mt7623-u-boot.dtsi" | ||||
|   | ||||
| @@ -50,6 +51,18 @@ | ||||
|  		regulator-always-on; | ||||
|  	}; | ||||
|   | ||||
| +	gpio-keys { | ||||
| +		compatible = "gpio-keys"; | ||||
| +		pinctrl-names = "default"; | ||||
| +		pinctrl-0 = <&key_pins_a>; | ||||
| + | ||||
| +		factory { | ||||
| +			label = "factory"; | ||||
| +			gpios = <&gpio 256 GPIO_ACTIVE_LOW>; | ||||
| +			linux,code = <KEY_RESTART>; | ||||
| +		}; | ||||
| +	}; | ||||
| + | ||||
|  	leds { | ||||
|  		compatible = "gpio-leds"; | ||||
|   | ||||
| @@ -109,6 +122,19 @@ | ||||
|  		}; | ||||
|  	}; | ||||
|   | ||||
| +	key_pins_a: keys-alt { | ||||
| +		mux { | ||||
| +			function = "gpio"; | ||||
| +			groups = "msdc3"; | ||||
| +		}; | ||||
| + | ||||
| +		conf { | ||||
| +			pins = "MSDC0E_DAT0", "MSDC0E_DAT1"; | ||||
| +			input-enable; | ||||
| +			bias-pull-up; | ||||
| +		}; | ||||
| +	}; | ||||
| + | ||||
|  	mmc0_pins_default: mmc0default { | ||||
|  		mux { | ||||
|  			function = "msdc"; | ||||
|   | ||||
| @@ -1,6 +1,14 @@ | ||||
| --- a/arch/arm/dts/mt7622-bananapi-bpi-r64.dts | ||||
| +++ b/arch/arm/dts/mt7622-bananapi-bpi-r64.dts | ||||
| @@ -20,6 +20,7 @@ | ||||
| @@ -5,6 +5,7 @@ | ||||
|   */ | ||||
|   | ||||
|  /dts-v1/; | ||||
| +#include <dt-bindings/input/linux-event-codes.h> | ||||
|  #include "mt7622.dtsi" | ||||
|  #include "mt7622-u-boot.dtsi" | ||||
|   | ||||
| @@ -20,6 +21,7 @@ | ||||
|   | ||||
|  	aliases { | ||||
|  		spi0 = &snfi; | ||||
| @@ -8,7 +16,7 @@ | ||||
|  	}; | ||||
|   | ||||
|  	memory@40000000 { | ||||
| @@ -27,6 +28,42 @@ | ||||
| @@ -27,6 +29,44 @@ | ||||
|  		reg = <0x40000000 0x40000000>; | ||||
|  	}; | ||||
|   | ||||
| @@ -18,11 +26,13 @@ | ||||
| +		reset { | ||||
| +			label = "reset"; | ||||
| +			gpios = <&gpio 0 GPIO_ACTIVE_LOW>; | ||||
| +			linux,code = <KEY_RESTART>; | ||||
| +		}; | ||||
| + | ||||
| +		wps { | ||||
| +			label = "wps"; | ||||
| +			gpios = <&gpio 102 GPIO_ACTIVE_LOW>; | ||||
| +			linux,code = <KEY_WPS_BUTTON>; | ||||
| +		}; | ||||
| +	}; | ||||
| + | ||||
| @@ -51,7 +61,7 @@ | ||||
|  	reg_1p8v: regulator-1p8v { | ||||
|  		compatible = "regulator-fixed"; | ||||
|  		regulator-name = "fixed-1.8V"; | ||||
| @@ -182,6 +219,7 @@ | ||||
| @@ -182,6 +222,7 @@ | ||||
|  }; | ||||
|   | ||||
|  &uart0 { | ||||
| @@ -59,7 +69,7 @@ | ||||
|  	status = "okay"; | ||||
|  }; | ||||
|   | ||||
| @@ -197,7 +235,7 @@ | ||||
| @@ -197,7 +238,7 @@ | ||||
|  	status = "okay"; | ||||
|  	bus-width = <8>; | ||||
|  	max-frequency = <50000000>; | ||||
| @@ -68,7 +78,7 @@ | ||||
|  	vmmc-supply = <®_3p3v>; | ||||
|  	vqmmc-supply = <®_3p3v>; | ||||
|  	non-removable; | ||||
| @@ -208,7 +246,7 @@ | ||||
| @@ -208,7 +249,7 @@ | ||||
|  	pinctrl-0 = <&mmc1_pins_default>; | ||||
|  	status = "okay"; | ||||
|  	bus-width = <4>; | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| --- a/arch/arm/dts/mt7622-bananapi-bpi-r64.dts | ||||
| +++ b/arch/arm/dts/mt7622-bananapi-bpi-r64.dts | ||||
| @@ -19,7 +19,7 @@ | ||||
| @@ -20,7 +20,7 @@ | ||||
|  	}; | ||||
|   | ||||
|  	aliases { | ||||
| @@ -9,7 +9,7 @@ | ||||
|  		ethernet0 = ð | ||||
|  	}; | ||||
|   | ||||
| @@ -205,17 +205,11 @@ | ||||
| @@ -208,17 +208,11 @@ | ||||
|  	}; | ||||
|  }; | ||||
|   | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| --- a/arch/arm/dts/mt7623n-bananapi-bpi-r2.dts | ||||
| +++ b/arch/arm/dts/mt7623n-bananapi-bpi-r2.dts | ||||
| @@ -50,19 +50,19 @@ | ||||
| @@ -51,19 +51,19 @@ | ||||
|   | ||||
|  		blue { | ||||
|  			label = "bpi-r2:pio:blue"; | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| --- a/arch/arm/dts/mt7623n-bananapi-bpi-r2.dts | ||||
| +++ b/arch/arm/dts/mt7623n-bananapi-bpi-r2.dts | ||||
| @@ -243,6 +243,7 @@ | ||||
| @@ -245,6 +245,7 @@ | ||||
|  &uart0 { | ||||
|  	pinctrl-names = "default"; | ||||
|  	pinctrl-0 = <&uart0_pins_a>; | ||||
|   | ||||
| @@ -144,7 +144,7 @@ | ||||
| +CONFIG_USB_STORAGE=y | ||||
| --- /dev/null | ||||
| +++ b/arch/arm/dts/mt7622-linksys-e8450-ubi.dts | ||||
| @@ -0,0 +1,194 @@ | ||||
| @@ -0,0 +1,197 @@ | ||||
| +// SPDX-License-Identifier: GPL-2.0 | ||||
| +/* | ||||
| + * Copyright (c) 2019 MediaTek Inc. | ||||
| @@ -152,6 +152,7 @@ | ||||
| + */ | ||||
| + | ||||
| +/dts-v1/; | ||||
| +#include <dt-bindings/input/linux-event-codes.h> | ||||
| +#include "mt7622.dtsi" | ||||
| +#include "mt7622-u-boot.dtsi" | ||||
| + | ||||
| @@ -175,11 +176,13 @@ | ||||
| +		factory { | ||||
| +			label = "reset"; | ||||
| +			gpios = <&gpio 0 GPIO_ACTIVE_LOW>; | ||||
| +			linux,code = <KEY_RESTART>; | ||||
| +		}; | ||||
| + | ||||
| +		wps { | ||||
| +			label = "wps"; | ||||
| +			gpios = <&gpio 102 GPIO_ACTIVE_LOW>; | ||||
| +			linux,code = <KEY_WPS_BUTTON>; | ||||
| +		}; | ||||
| +	}; | ||||
| + | ||||
|   | ||||
| @@ -158,6 +158,7 @@ | ||||
| + */ | ||||
| + | ||||
| +/dts-v1/; | ||||
| +#include <dt-bindings/input/linux-event-codes.h> | ||||
| +#include "mt7622.dtsi" | ||||
| +#include "mt7622-u-boot.dtsi" | ||||
| + | ||||
| @@ -178,12 +179,11 @@ | ||||
| + | ||||
| +	gpio-keys { | ||||
| +		compatible = "gpio-keys"; | ||||
| +		u-boot,dm-pre-reloc; | ||||
| + | ||||
| +		reset { | ||||
| +			label = "reset"; | ||||
| +			gpios = <&gpio 62 GPIO_ACTIVE_LOW>; | ||||
| +			u-boot,dm-pre-reloc; | ||||
| +			linux,code = <KEY_RESTART>; | ||||
| +		}; | ||||
| +	}; | ||||
| + | ||||
|   | ||||
| @@ -851,7 +851,7 @@ | ||||
| + | ||||
| --- /dev/null | ||||
| +++ b/arch/arm/dts/mt7986a-bpi-r3-sd.dts | ||||
| @@ -0,0 +1,270 @@ | ||||
| @@ -0,0 +1,272 @@ | ||||
| +// SPDX-License-Identifier: GPL-2.0 | ||||
| +/* | ||||
| + * Copyright (c) 2021 MediaTek Inc. | ||||
| @@ -859,6 +859,7 @@ | ||||
| + */ | ||||
| + | ||||
| +/dts-v1/; | ||||
| +#include <dt-bindings/input/linux-event-codes.h> | ||||
| +#include "mt7986.dtsi" | ||||
| +#include <dt-bindings/gpio/gpio.h> | ||||
| + | ||||
| @@ -893,6 +894,7 @@ | ||||
| +		wps { | ||||
| +			label = "reset"; | ||||
| +			gpios = <&gpio 10 GPIO_ACTIVE_LOW>; | ||||
| +			linux,code = <KEY_RESTART>; | ||||
| +		}; | ||||
| +	}; | ||||
| + | ||||
|   | ||||
| @@ -183,7 +183,7 @@ | ||||
| +CONFIG_SERVERIP="192.168.1.254" | ||||
| --- /dev/null | ||||
| +++ b/arch/arm/dts/mt7986a-xiaomi_redmi-ax6000.dts | ||||
| @@ -0,0 +1,153 @@ | ||||
| @@ -0,0 +1,156 @@ | ||||
| +// SPDX-License-Identifier: GPL-2.0 | ||||
| +/* | ||||
| + * Copyright (c) 2021 MediaTek Inc. | ||||
| @@ -191,6 +191,7 @@ | ||||
| + */ | ||||
| + | ||||
| +/dts-v1/; | ||||
| +#include <dt-bindings/input/linux-event-codes.h> | ||||
| +#include "mt7986.dtsi" | ||||
| +#include <dt-bindings/gpio/gpio.h> | ||||
| + | ||||
| @@ -210,10 +211,12 @@ | ||||
| +		factory { | ||||
| +			label = "reset"; | ||||
| +			gpios = <&gpio 9 GPIO_ACTIVE_LOW>; | ||||
| +			linux,code = <KEY_RESTART>; | ||||
| +		}; | ||||
| +		mesh { | ||||
| +			label = "mesh"; | ||||
| +			gpios = <&gpio 10 GPIO_ACTIVE_LOW>; | ||||
| +			linux,code = <KEY_WPS_BUTTON>; | ||||
| +		}; | ||||
| +	}; | ||||
| +}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Daniel Golle
					Daniel Golle