summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2012-05-02 19:03:35 -0700
committerSimon Glass <sjg@chromium.org>2012-05-14 09:12:50 -0700
commit55898c8b4b14521bf6c188a7d7e034a9b1ae7b35 (patch)
treeba483a9ee72092c613fe00ae1ebea44c39306ef6
parentfddbc9edc4bd0f62493c81cfd7e3a22d6277ba39 (diff)
downloadchrome-ec-55898c8b4b14521bf6c188a7d7e034a9b1ae7b35.tar.gz
daisy: Deal with no-timeout explicity in wait_in_signal()
This function accepts a timeout value of -1, so add a comment to that effect. Also make it deal with this explicitly since the current function seems to return prematurely in that case. BUG=chrome-os-partner:9424 TEST=very ad-hoc: 1. build and boot on daisy, flash U-Boot with USB using 'cros_bundle_firmware -w usb', inserting daisy USB cable when it says 'Reseting board via servo...' 2. Press cold reset, then power on, see that it powers on 3. Then hold power-on for 8 seconds and see that it power off 4. XPSHOLD function not tested yet Change-Id: I01bd81997836333ca33e61d48823e8ff41034d5f Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--common/gaia_power.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/common/gaia_power.c b/common/gaia_power.c
index 58fa0e68cf..31ad6a767c 100644
--- a/common/gaia_power.c
+++ b/common/gaia_power.c
@@ -43,26 +43,33 @@ static int ap_on;
static int force_signal = -1;
static int force_value;
-/* Wait for GPIO "signal" to reach level "value".
+/*
+ * Wait for GPIO "signal" to reach level "value".
* Returns EC_ERROR_TIMEOUT if timeout before reaching the desired state.
+ *
+ * @param signal Signal to watch
+ * @param value Value to watch for
+ * @param timeout Timeout in microseconds from now, or -1 to wait forever
+ * @return 0 if signal did change to required value, EC_ERROR_TIMEOUT if we
+ * timed out first.
*/
static int wait_in_signal(enum gpio_signal signal, int value, int timeout)
{
timestamp_t deadline;
timestamp_t now = get_time();
- if (timeout < 0)
- deadline.le.hi = 0xffffffff;
- else
- deadline.val = now.val + timeout;
+ deadline.val = now.val + timeout;
while (((force_signal != signal) || (force_value != value)) &&
- gpio_get_level(signal) != value) {
+ gpio_get_level(signal) != value) {
now = get_time();
- if ((now.val >= deadline.val) ||
- (task_wait_event(deadline.val - now.val) ==
- TASK_EVENT_TIMER)) {
- CPRINTF("Timeout waiting for GPIO %d\n", signal);
+ if (timeout < 0) {
+ task_wait_event(-1);
+ } else if (timestamp_expired(deadline, &now) ||
+ (task_wait_event(deadline.val - now.val) ==
+ TASK_EVENT_TIMER)) {
+ CPRINTF("Timeout waiting for GPIO %d/%s\n", signal,
+ gpio_get_name(signal));
return EC_ERROR_TIMEOUT;
}
}