summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Paul <seanpaul@chromium.org>2011-10-17 13:50:25 -0400
committerSean Paul <seanpaul@chromium.org>2011-10-17 12:31:10 -0700
commit78c42c6a7987169b67248efe27239d6389ca4c69 (patch)
treed3a0221ebe6d0f0b39ec2450a77507a2dc574415
parent644f14b121f76d55267e1fc6930a02c6cc10c26d (diff)
CHROMIUM: Clean up cros gpio code
This CL simplifies how cros gpios are handled by moving the required logic out of cros_gpio.c and into the application logic. This means that cros_gpio.c assumes that none of the gpios are required, and just returns an error when fetch is called. It's up to the caller of fetch to determine whether or not they should ignore the error or act upon it. BUG=chromium-os:21700 TEST=Tested on asymptote, ensured gpio access worked as expected. Change-Id: Ief3f1915026bfe981d345b9cc4709fef19edc7bf Signed-off-by: Sean Paul <seanpaul@chromium.org> Reviewed-on: http://gerrit.chromium.org/gerrit/10174 Reviewed-by: Simon Glass <sjg@chromium.org>
-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;
}