diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2016-03-14 13:52:37 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-03-14 20:11:28 -0700 |
commit | 395a2840040d9688b49b4c30ebee9daa7e0abe8b (patch) | |
tree | 8b359bbf9d911c9fb89dfeeb84634a317dee9da0 | |
parent | 1f74a45132d539756c0c6566898c15e92becf0b8 (diff) | |
download | chrome-ec-395a2840040d9688b49b4c30ebee9daa7e0abe8b.tar.gz |
pd: Add error handling for pd_send_request_msg()
If we have already completed negotiation as a sink and
pd_send_request_msg() fails, issue a soft reset so we don't remain
indefinitely at our previously negotiated voltage.
BUG=chrome-os-partner:50346
BRANCH=glados
TEST=Manual on chell. Attach zinger to port 1, then attach zinger to
port 2. Verify that port 1 negotiated to 20V. Detach port 1 and verify
port 2 successfully negotiates to 20V and begins charging.
Change-Id: I4f8ff9a1e3ef49858f6ae5c3ccb5b5d4d847e2d1
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/332642
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | common/usb_pd_protocol.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 50b629c055..d903831d6f 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -571,7 +571,11 @@ static void pd_store_src_cap(int port, int cnt, uint32_t *src_caps) pd_src_caps[port][i] = *src_caps++; } -static void pd_send_request_msg(int port, int always_send_request) +/* + * Request desired charge voltage from source. + * Returns EC_SUCCESS on success or non-zero on failure. + */ +static int pd_send_request_msg(int port, int always_send_request) { uint32_t rdo, curr_limit, supply_voltage; int res; @@ -606,11 +610,11 @@ static void pd_send_request_msg(int port, int always_send_request) * If fail to choose voltage, do nothing, let source re-send * source cap */ - return; + return -1; /* Don't re-request the same voltage */ if (!always_send_request && pd[port].prev_request_mv == supply_voltage) - return; + return EC_SUCCESS; CPRINTF("Req C%d [%d] %dmV %dmA", port, RDO_POS(rdo), supply_voltage, curr_limit); @@ -622,9 +626,10 @@ static void pd_send_request_msg(int port, int always_send_request) pd[port].supply_voltage = supply_voltage; pd[port].prev_request_mv = supply_voltage; res = send_request(port, rdo); - if (res >= 0) - set_state(port, PD_STATE_SNK_REQUESTED); - /* If fail send request, do nothing, let source re-send source cap */ + if (res < 0) + return res; + set_state(port, PD_STATE_SNK_REQUESTED); + return EC_SUCCESS; } #endif @@ -708,6 +713,7 @@ static void handle_data_request(int port, uint16_t head, pd_process_source_cap(port, pd_src_cap_cnt[port], pd_src_caps[port]); + /* Source will resend source cap on failure */ pd_send_request_msg(port, 1); } break; @@ -2231,7 +2237,8 @@ void pd_task(void) /* Check for new power to request */ if (pd[port].new_power_request) { - pd_send_request_msg(port, 0); + if (pd_send_request_msg(port, 0) != EC_SUCCESS) + set_state(port, PD_STATE_SOFT_RESET); break; } |