diff options
-rw-r--r-- | chip/g/idle.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/chip/g/idle.c b/chip/g/idle.c index dc003d3eef..1686474ba9 100644 --- a/chip/g/idle.c +++ b/chip/g/idle.c @@ -12,13 +12,17 @@ /* What to do when we're just waiting */ static enum { - IDLE_WFI, /* default */ + DONT_KNOW, + IDLE_WFI, IDLE_SLEEP, IDLE_DEEP_SLEEP, NUM_CHOICES } idle_action; +#define IDLE_DEFAULT IDLE_SLEEP + static const char const *idle_name[] = { + "invalid", "wfi", "sleep", "deep sleep", @@ -31,7 +35,7 @@ static int command_idle(int argc, char **argv) if (argc > 1) { c = tolower(argv[1][0]); - for (i = 0; i < ARRAY_SIZE(idle_name); i++) + for (i = 1; i < ARRAY_SIZE(idle_name); i++) if (idle_name[i][0] == c) { idle_action = i; break; @@ -129,10 +133,17 @@ void __idle(void) { int sleep_ok, sleep_delay_passed; - /* Preserved across soft reboots, but not hard */ + /* + * This register is preserved across soft reboots, but not hard. It + * defaults to zero, which is how we can tell whether this is the + * preserved value or not. We only need to remember it because we might + * change it with the console command. + */ idle_action = GREG32(PMU, PWRDN_SCRATCH17); - if (idle_action >= NUM_CHOICES) - idle_action = IDLE_WFI; + if (idle_action == DONT_KNOW || idle_action >= NUM_CHOICES) { + idle_action = IDLE_DEFAULT; + GREG32(PMU, PWRDN_SCRATCH17) = idle_action; + } while (1) { |