uboot-mediatek: fix factory/reset button
[openwrt/staging/dedeckeh.git] / package / boot / uboot-mediatek / patches / 303-mt7986-generic-reset-button-ignore-env.patch
1 --- a/board/mediatek/mt7986/mt7986_rfb.c
2 +++ b/board/mediatek/mt7986/mt7986_rfb.c
3 @@ -6,9 +6,16 @@
4
5 #include <common.h>
6 #include <config.h>
7 +#include <dm.h>
8 +#include <button.h>
9 #include <env.h>
10 #include <init.h>
11 #include <asm/global_data.h>
12 +#include <linux/delay.h>
13 +
14 +#ifndef CONFIG_RESET_BUTTON_LABEL
15 +#define CONFIG_RESET_BUTTON_LABEL "reset"
16 +#endif
17
18 #include <mtd.h>
19 #include <linux/mtd/mtd.h>
20 @@ -24,7 +31,22 @@ int board_init(void)
21
22 int board_late_init(void)
23 {
24 - gd->env_valid = 1; //to load environment variable from persistent store
25 + struct udevice *dev;
26 +
27 + gd->env_valid = ENV_VALID;
28 + if (!button_get_by_label(CONFIG_RESET_BUTTON_LABEL, &dev)) {
29 + puts("reset button found\n");
30 +#ifdef CONFIG_RESET_BUTTON_SETTLE_DELAY
31 + if (CONFIG_RESET_BUTTON_SETTLE_DELAY > 0) {
32 + button_get_state(dev);
33 + mdelay(CONFIG_RESET_BUTTON_SETTLE_DELAY);
34 + }
35 +#endif
36 + if (button_get_state(dev) == BUTTON_ON) {
37 + puts("button pushed, resetting environment\n");
38 + gd->env_valid = ENV_INVALID;
39 + }
40 + }
41 env_relocate();
42 return 0;
43 }