nrhw20: add reset button fucntionality

This commit is contained in:
Rene Straub 2018-03-15 12:07:26 +01:00
parent c94710b8c3
commit f735627eca
1 changed files with 89 additions and 91 deletions

View File

@ -397,101 +397,11 @@ err_free_gpio:
#endif
#if !defined(CONFIG_SPL_BUILD)
/* TODO: Redesign to use PMIC input */
static int check_reset_button(void)
{
#if 0
int counter = 0;
int ret;
ret = gpio_request(NETBIRD_GPIO_RESET_BUTTON, "reset button");
if (ret < 0) {
printf("Unable to request reset button gpio\n");
return -1;
}
ret = gpio_direction_input(NETBIRD_GPIO_RESET_BUTTON);
if (ret < 0) {
printf("Unable to set reset button as input\n");
return -1;
}
/* Check if reset button is pressed for at least 2 seconds ≃ ~5s */
do {
if (gpio_get_value(NETBIRD_GPIO_RESET_BUTTON) != 0) break;
udelay(100000); /* 100ms */
counter++;
if (counter==20) {/* Indicate factory reset threshold */
gpio_set_value(NETBIRD_GPIO_LED_A, 0);
gpio_set_value(NETBIRD_GPIO_LED_B, 0);
udelay(400000); /* 400ms */
/* let LED blink up once */
gpio_set_value(NETBIRD_GPIO_LED_A, 1);
gpio_set_value(NETBIRD_GPIO_LED_B, 1);
udelay(400000); /* 400ms */
gpio_set_value(NETBIRD_GPIO_LED_A, 0);
gpio_set_value(NETBIRD_GPIO_LED_B, 0);
} else if (counter==120) { /* Indicate recovery boot threshold */
/* let LED blink up twice */
gpio_set_value(NETBIRD_GPIO_LED_A, 1);
gpio_set_value(NETBIRD_GPIO_LED_B, 1);
udelay(400000); /* 400ms */
gpio_set_value(NETBIRD_GPIO_LED_A, 0);
gpio_set_value(NETBIRD_GPIO_LED_B, 0);
udelay(400000); /* 400ms */
gpio_set_value(NETBIRD_GPIO_LED_A, 1);
gpio_set_value(NETBIRD_GPIO_LED_B, 1);
udelay(400000); /* 400ms */
gpio_set_value(NETBIRD_GPIO_LED_A, 0);
gpio_set_value(NETBIRD_GPIO_LED_B, 0);
}
} while (counter<120);
if (counter < 20) return 0; /* Don't do anything for duration < 2s */
if (counter < 120) /* Do factory reset for duration between ~5s and ~15s */
{
char new_bootargs[512];
char *bootargs = getenv("bootargs");
if (bootargs==0) bootargs="";
printf("Do factory reset during boot...\n");
strncpy(new_bootargs, bootargs, sizeof(new_bootargs));
strncat(new_bootargs, " factory-reset", sizeof(new_bootargs));
setenv("bootargs", new_bootargs);
printf("bootargs = %s\n", new_bootargs);
return 1;
} else { /* Boot into recovery for duration > 15s */
/* set consoledev to external port */
setenv("consoledev", "ttyS1");
printf("Booting recovery image...\n");
/* Set bootcmd to run recovery */
setenv("bootcmd", "run recovery");
return 0;
}
return 0;
#else
return 0;
#endif
}
#endif
/* TODO: Create DA9063 Accessor Module */
#define CONFIG_PMIC_I2C_BUS 0
#define CONFIG_PMIC_I2C_ADDR 0x58 /* Pages 0 and 1, Pages 2 and 3 -> 0x59 */
#define PMIC_REG_STATUS_A 0x01 /* Status of ON_KEY, WAKE, COMP1V2, DVC */
#define PMIC_REG_GPIO_MODE0_7 0x1D /* Control register for GPIOs 0..7 */
#define PMIC_REG_GPIO_MODE8_15 0x1E /* Control register for GPIOs 8..15 */
@ -877,6 +787,94 @@ static void shield_init(void)
}
#endif
#if !defined(CONFIG_SPL_BUILD)
static bool get_button_state(void)
{
u8 state = 0x00;
(void)da9093_get_reg(PMIC_REG_STATUS_A, &state);
return (state & 0x01) == 0x01;
}
static void blink_led(void)
{
const int pulse_width = 400*1000; /* 400ms */
/* Assumes green status LED is on */
udelay(pulse_width);
set_status_led(0, 0);
udelay(pulse_width);
set_status_led(0, 1);
}
static int check_reset_button(void)
{
int counter = 0;
/* Check how long button is pressed */
do {
if (!get_button_state())
break;
udelay(100*1000); /* 100ms */
counter += 100;
if (counter == 2000) {
/* Indicate factory reset threshold */
blink_led();
}
else if (counter == 12000) {
/* Indicate recovery boot threshold */
blink_led();
blink_led();
}
} while (counter < 12000);
/* Don't do anything for duration < 2s */
if (counter < 2000)
return 0;
/* Do factory reset for duration between ~5s and ~15s */
if (counter < 12000)
{
char new_bootargs[512];
char *bootargs = getenv("bootargs");
if (bootargs == 0) bootargs="";
printf("Do factory reset during boot...\n");
strncpy(new_bootargs, bootargs, sizeof(new_bootargs));
strncat(new_bootargs, " factory-reset", sizeof(new_bootargs));
setenv("bootargs", new_bootargs);
printf("bootargs = %s\n", new_bootargs);
return 1;
}
/* Boot into recovery for duration > 15s */
else
{
/* set consoledev to external port */
/* setenv("consoledev", "ttyS1"); */
printf("Booting recovery image...\n");
/* Set bootcmd to run recovery */
setenv("bootcmd", "run recovery");
return 0;
}
return 0;
}
#endif
int board_late_init(void)
{
#if !defined(CONFIG_SPL_BUILD)