diff options
author | Tom Wai-Hong Tam <waihong@chromium.org> | 2011-07-21 19:31:41 +0800 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2011-08-29 10:59:07 -0700 |
commit | fe7509357ee3974557fc19f7a7a47197327dd876 (patch) | |
tree | ffe44e1bced83aa6192afb7cbadbeaacfa614480 /lib | |
parent | 889e854df63823a1ed8881447f3b9ab2d40170b3 (diff) |
CHROMIUM: Implement VbExIsShutdownRequested() function and its test.
The check condition is either:
* a user has pressed the power button;
* a user has closed the lid.
BUG=chromium-os:17180,chrome-os-partner:4738
TEST=build without error, run "vbexport_test isshutdown",
or boot recovery mode on Aebl
--- When I pressed the power key, see the messages ---
misc: Power-key-pressed is detected.
VbDisplayScreen(0, 0)
VbDisplayScreenFromGBB(): screen 0 not in the GBB
VbSelectAndLoadKernel() returning 1
Returned 0x1
main: Failed to select and load kernel!
--- When I closed the lid, see the messages ---
misc: Lid-closed is detected.
VbDisplayScreen(0, 0)
VbDisplayScreenFromGBB(): screen 0 not in the GBB
VbSelectAndLoadKernel() returning 1
Returned 0x1
main: Failed to select and load kernel!
Change-Id: Ia003187215c0327b0246592404d13bab668cd323
Reviewed-on: http://gerrit.chromium.org/gerrit/4486
Tested-by: Tom Wai-Hong Tam <waihong@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vbexport/misc.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/lib/vbexport/misc.c b/lib/vbexport/misc.c index 301e63dcea..cab7a4c449 100644 --- a/lib/vbexport/misc.c +++ b/lib/vbexport/misc.c @@ -9,15 +9,36 @@ */ #include <common.h> - -/* Import the header files from vboot_reference. */ +#include <chromeos/common.h> +#include <chromeos/cros_gpio.h> #include <vboot_api.h> +#define PREFIX "misc: " + +DECLARE_GLOBAL_DATA_PTR; + uint32_t VbExIsShutdownRequested(void) { - /* - * TODO(waihong@chromium.org) Detect the power button pressed or - * the lib closed. - */ + void *fdt_ptr = (void *)gd->blob; + cros_gpio_t lidsw, pwrsw; + + if (cros_gpio_fetch(CROS_GPIO_LIDSW, fdt_ptr, &lidsw) || + cros_gpio_fetch(CROS_GPIO_PWRSW, fdt_ptr, &pwrsw)) { + VBDEBUG(PREFIX "Failed to fetch GPIO!\n"); + /* still return 0, No-Shutdown-Requested */ + return 0; + } + + /* if lid is NOT OPEN */ + if (!lidsw.value) { + VBDEBUG(PREFIX "Lid-closed is detected.\n"); + return 1; + } + + if (pwrsw.value) { + VBDEBUG(PREFIX "Power-key-pressed is detected.\n"); + return 1; + } + return 0; } |