From 21ba1207aceb74f63124f1e2e87e1c4c31831318 Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Wed, 10 Aug 2016 21:57:11 -0700 Subject: [PATCH] usb: pd: Always request maximum available current from PDO Currently when selecting a PDO the request object is specifying 900mA as the operating current, which is suboptimal if the supply is capable of more. Instead, simply request for the maximum available. In the case where a PDO does not meet the minimum current, set the capability mismatch flag and indicate the required amount via the maximum field in the request. Change-Id: I521059ab1c1d95df95fdede84512e73c5d9b2329 Signed-off-by: Jack Pham --- drivers/usb/pd/policy_engine.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/usb/pd/policy_engine.c b/drivers/usb/pd/policy_engine.c index 7bc6b5340dd7..42ebc60089ba 100644 --- a/drivers/usb/pd/policy_engine.c +++ b/drivers/usb/pd/policy_engine.c @@ -240,9 +240,6 @@ static void *usbpd_ipc_log; static int min_sink_current = 900; module_param(min_sink_current, int, S_IRUSR | S_IWUSR); -static int max_sink_current = 3000; -module_param(max_sink_current, int, S_IRUSR | S_IWUSR); - static const u32 default_src_caps[] = { 0x36019096 }; /* VSafe5V @ 1.5A */ static const u32 default_snk_caps[] = { 0x2601905A, /* 5V @ 900mA */ @@ -406,8 +403,8 @@ static int pd_send_msg(struct usbpd *pd, u8 hdr_type, const u32 *data, static int pd_select_pdo(struct usbpd *pd, int pdo_pos) { - int curr = min_sink_current; - int max_current = max_sink_current; + int curr; + int max_current; bool mismatch = false; u32 pdo = pd->received_pdos[pdo_pos - 1]; @@ -417,18 +414,19 @@ static int pd_select_pdo(struct usbpd *pd, int pdo_pos) return -ENOTSUPP; } + curr = max_current = PD_SRC_PDO_FIXED_MAX_CURR(pdo) * 10; + /* * Check if the PDO has enough current, otherwise set the * Capability Mismatch flag */ - if ((PD_SRC_PDO_FIXED_MAX_CURR(pdo) * 10) < curr) { + if (curr < min_sink_current) { mismatch = true; - max_current = curr; - curr = PD_SRC_PDO_FIXED_MAX_CURR(pdo) * 10; + max_current = min_sink_current; } pd->requested_voltage = PD_SRC_PDO_FIXED_VOLTAGE(pdo) * 50 * 1000; - pd->requested_current = max_current; + pd->requested_current = curr; pd->requested_pdo = pdo_pos; pd->rdo = PD_RDO_FIXED(pdo_pos, 0, mismatch, 1, 1, curr / 10, max_current / 10);