summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/nvidia/chromeos/cros_gpio.c52
-rw-r--r--lib/vbexport/misc.c18
2 files changed, 17 insertions, 53 deletions
diff --git a/board/nvidia/chromeos/cros_gpio.c b/board/nvidia/chromeos/cros_gpio.c
index 9be80dd7168..1aed5319c94 100644
--- a/board/nvidia/chromeos/cros_gpio.c
+++ b/board/nvidia/chromeos/cros_gpio.c
@@ -22,24 +22,12 @@
DECLARE_GLOBAL_DATA_PTR;
-struct cros_gpio {
- char *name;
- int default_value;
-};
-
-/*
- * This list provides names matching the dts files and the default value that
- * the gpio should take. If the gpio is strictly required, use
- * FDT_GPIO_NONE to fail out on the gpio functions. To use a default value
- * for a gpio (in the case where it's not specified in the dts file), fill in
- * a 1 or 0 in the default value field.
- */
-static struct cros_gpio gpios[CROS_GPIO_MAX_GPIO] = {
- { "write-protect-switch", FDT_GPIO_NONE },
- { "recovery-switch", FDT_GPIO_NONE },
- { "developer-switch", FDT_GPIO_NONE },
- { "lid-switch", 1 },
- { "power-switch", 0 },
+static char *gpio_name[CROS_GPIO_MAX_GPIO] = {
+ "write-protect-switch",
+ "recovery-switch",
+ "developer-switch",
+ "lid-switch",
+ "power-switch",
};
static int g_config_node = -1;
@@ -55,18 +43,8 @@ int misc_init_r(void)
return -1;
for (i = 0; i < CROS_GPIO_MAX_GPIO; i++) {
- if (fdt_decode_gpio(gd->blob, config_node, gpios[i].name,
- &gs)) {
- /*
- * If the gpio has a default value (ie. not required,
- * just ignore it)
- */
- if (gpios[i].default_value == FDT_GPIO_NONE)
- return -1;
- else
- continue;
- }
- fdt_setup_gpio(&gs);
+ if (!fdt_decode_gpio(gd->blob, config_node, gpio_name[i], &gs))
+ fdt_setup_gpio(&gs);
}
/*
@@ -96,18 +74,8 @@ int cros_gpio_fetch(enum cros_gpio_index index, cros_gpio_t *gpio)
assert(g_config_node >= 0);
assert(index >= 0 && index < CROS_GPIO_MAX_GPIO);
- if (fdt_decode_gpio(gd->blob, g_config_node, gpios[index].name, &gs)) {
- if (gpios[index].default_value == FDT_GPIO_NONE) {
- VBDEBUG(PREFIX "fail to decode gpio: %d\n", index);
- return -1;
- } else {
- gpio->index = -1;
- gpio->port = -1;
- gpio->polarity = CROS_GPIO_ACTIVE_HIGH;
- gpio->value = gpios[index].default_value;
- return 0;
- }
- }
+ if (fdt_decode_gpio(gd->blob, g_config_node, gpio_name[index], &gs))
+ return -1;
gpio->index = index;
gpio->port = gs.gpio;
diff --git a/lib/vbexport/misc.c b/lib/vbexport/misc.c
index 6af3bb4b625..925d64d9413 100644
--- a/lib/vbexport/misc.c
+++ b/lib/vbexport/misc.c
@@ -21,24 +21,20 @@ uint32_t VbExIsShutdownRequested(void)
{
cros_gpio_t lidsw, pwrsw;
- if (cros_gpio_fetch(CROS_GPIO_LIDSW, &lidsw) ||
- cros_gpio_fetch(CROS_GPIO_PWRSW, &pwrsw)) {
- VBDEBUG(PREFIX "Failed to fetch GPIO!\n");
- /* still return 0, No-Shutdown-Requested */
- return 0;
- }
-
/* if lid is NOT OPEN */
- if (!lidsw.value) {
+ if (!cros_gpio_fetch(CROS_GPIO_LIDSW, &lidsw) && !lidsw.value) {
VBDEBUG(PREFIX "Lid-closed is detected.\n");
return 1;
}
-
- if (pwrsw.value) {
+ /* if power switch is pressed */
+ if (!cros_gpio_fetch(CROS_GPIO_PWRSW, &pwrsw) && pwrsw.value) {
VBDEBUG(PREFIX "Power-key-pressed is detected.\n");
return 1;
}
-
+ /*
+ * Either the gpios don't exist, or the lid is up and and power button
+ * is not pressed. No-Shutdown-Requested.
+ */
return 0;
}