From 5e2409745d28ca3bdf59b167ae5afdd491a10ddc Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Fri, 5 Dec 2014 19:22:30 -0800 Subject: [PATCH] pd: change power request based on if active charge port When we receive source capabilities packet from a source, if we are already the active charging port, then we know we can request max power, otherwise request vSafe5V. Normally, when you first attach a charger, the port won't already be the active charge port when we receive source cap. But, if we already have a power contract with a source and the source sends us new source capabilities, then this comes in to play. BUG=chrome-os-partner:34168 BRANCH=samus TEST=test with plankton. when you press the 5/12/20 V buttons on plankton it changes the source capabilites of plankton and sends a new source cap packet to samus. thus, without this change, when you press one of the buttons twice, the second button press causes us to negotiate to vSafe5V instead of the max power. with this change, the requested power stays constant when plankton re-issues source capabilities. Change-Id: I3cc1e6b109117566f59de07762fd1af9adec05bf Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/233753 Reviewed-by: Shawn Nematbakhsh Reviewed-by: Vincent Palatin --- common/usb_pd_protocol.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index e20d2c21cb..30d729052d 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -868,7 +868,12 @@ static void handle_data_request(int port, uint16_t head, pd_store_src_cap(port, cnt, payload); /* src cap 0 should be fixed PDO */ pd_update_pdo_flags(port, payload[0]); - pd_send_request_msg(port, PD_REQUEST_MIN); +#ifdef CONFIG_CHARGE_MANAGER + if (charge_manager_get_active_charge_port() == port) + pd_send_request_msg(port, PD_REQUEST_MAX); + else +#endif + pd_send_request_msg(port, PD_REQUEST_MIN); } break; #endif /* CONFIG_USB_PD_DUAL_ROLE */