summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/cmd_vbexport_test.c11
-rw-r--r--lib/vbexport/misc.c33
2 files changed, 38 insertions, 6 deletions
diff --git a/common/cmd_vbexport_test.c b/common/cmd_vbexport_test.c
index 72389170ac..e05f6f012e 100644
--- a/common/cmd_vbexport_test.c
+++ b/common/cmd_vbexport_test.c
@@ -460,6 +460,14 @@ static int do_vbexport_test_display(
return ret;
}
+static int do_vbexport_test_isshutdown(
+ cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ VbExDebug("Shutdown requested? %s\n",
+ VbExIsShutdownRequested() ? "Yes" : "No");
+ return 0;
+}
+
static int do_vbexport_test_all(
cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
@@ -473,6 +481,7 @@ static int do_vbexport_test_all(
ret |= do_vbexport_test_nvrw(cmdtp, flag, argc, argv);
ret |= do_vbexport_test_key(cmdtp, flag, argc, argv);
ret |= do_vbexport_test_display(cmdtp, flag, argc, argv);
+ ret |= do_vbexport_test_isshutdown(cmdtp, flag, argc, argv);
if (!ret)
VbExDebug("All tests passed!\n");
return ret;
@@ -491,6 +500,7 @@ static cmd_tbl_t cmd_vbexport_test_sub[] = {
U_BOOT_CMD_MKENT(nvclear, 0, 1, do_vbexport_test_nvclear, "", ""),
U_BOOT_CMD_MKENT(key, 0, 1, do_vbexport_test_key, "", ""),
U_BOOT_CMD_MKENT(display, 0, 1, do_vbexport_test_display, "", ""),
+ U_BOOT_CMD_MKENT(isshutdown, 0, 1, do_vbexport_test_isshutdown, "", ""),
};
static int do_vbexport_test(
@@ -525,5 +535,6 @@ U_BOOT_CMD(vbexport_test, CONFIG_SYS_MAXARGS, 1, do_vbexport_test,
"vbexport_test nvrw - test the nvstorage read and write functions\n"
"vbexport_test key - test the keyboard read function\n"
"vbexport_test display - test the display related functions\n"
+ "vbexport_test isshutdown - check if shutdown requested\n"
);
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;
}