From patchwork Wed Jan 30 03:13:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 10787613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A98376C2 for ; Wed, 30 Jan 2019 03:14:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B0582D1E4 for ; Wed, 30 Jan 2019 03:14:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B3932D1E8; Wed, 30 Jan 2019 03:14:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20DFF2D1E4 for ; Wed, 30 Jan 2019 03:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729986AbfA3DOd (ORCPT ); Tue, 29 Jan 2019 22:14:33 -0500 Received: from mail-qk1-f201.google.com ([209.85.222.201]:50948 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727672AbfA3DOd (ORCPT ); Tue, 29 Jan 2019 22:14:33 -0500 Received: by mail-qk1-f201.google.com with SMTP id x125so23829371qka.17 for ; Tue, 29 Jan 2019 19:14:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=O3pIKEgprI/dyamSyKpdbIBNGvXWdN0U7O3IxM7kDl0=; b=l8TjODhzqqskj+pg62gWaQkMtEoyx0eQSL9NvHv+2xOAvhhaPe6gQV8Vf80vbjwcxP 4Uff2rV87tAhUEMNaGw9WlMPv5FglxhJ9hmLcCUg3SCFyHIin5jNSYTc9bEjYHNhxnfS UdWhwbB8iH2rB/GemV//6TaSyjUIR/TKGwqkIeCGHtdYZbQIX9PKieeHsxCMxuVvWDYH zC2jyOw3t1tJe0vLRnA+LHEKiSHEGO4U8ZDkuH82wJSQ6E8rsy9wsuPY0SCgnDb68fu5 Jo9q5mfVvR5zXGwpHi7qcalwFEOIF1K8b5W0ijdkqsgWOw5jODry6wMMcYuxKzGd+h6N Tojw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=O3pIKEgprI/dyamSyKpdbIBNGvXWdN0U7O3IxM7kDl0=; b=Rx3uYpsf7svnib+y60DLjCYNlLlOc5vwSjf4BK8hLeUinFfKXABkVj3/VeSNKxCHvp Wzjld3tr42xpTg0kR/HM58MV6DmetxSE/Phbbv3SkHF60al06uAqRVaVImoM0dwa4nkB zn5U4qMTISPFtprH/RRdQP5TCkPzhhxxmvIMsW8wgwNZLsI21Y0w/reUbnmStPlPV3TI BlZ6i5asSQiWT7n/AZGwlY0moUH4zyvlFTi8Pr8QtKxAHRzif7s3zxAUWcbWdr+k5Z5T Dd2LszgXqQr+HQQG/CnFNTjX2zEx5dXzDHDSldRE6Av16I9zScOllVWSRs+JlMelw0ll TNiw== X-Gm-Message-State: AHQUAuYF6ar/koDOxUW16gwIasC7MdYtTotztVOO/EW1u5L2HtsmZXo0 YaU/R0ciGcx4UhT2sIbYsKgxxhDIuv7l X-Google-Smtp-Source: AHgI3IaaaRkX4e9Fh9I7UTUwoKS6/qooIGNA7zRQa4s7o8HZD2Qifx11EXx+SCK+/+SABgsWd9rol4khEkbp X-Received: by 2002:a37:e40e:: with SMTP id y14mr4837145qkf.38.1548818072686; Tue, 29 Jan 2019 19:14:32 -0800 (PST) Date: Wed, 30 Jan 2019 11:13:53 +0800 Message-Id: <20190130031353.100228-1-kyletso@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1.495.gaa96b0ce6b-goog Subject: [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation From: Kyle Tso To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, Adam.Thomson.Opensource@diasemi.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When Sink negotiates PPS, the voltage range of selected PPS APDO might not cover the previous voltage (out_volt). If the previous out_volt is lower than the new min_volt, the output voltage in RDO might be set to an invalid value. For instance, supposed that the previous voltage is 5V, and the new voltage range in the APDO is 7V-12V. Then the output voltage in the RDO should not be set to 5V which is lower than the possible min_volt 7V. Fix this by choosing the maximal value between the previous voltage and the new min_volt first. And ensure that this value will not exceed the new max_volt. The new out_volt will fall within the new voltage range while being the closest value compared to the previous out_volt. Signed-off-by: Kyle Tso Reviewed-by: Adam Thomson Reviewed-by: Guenter Roeck Reviewed-by: Heikki Krogerus --- drivers/usb/typec/tcpm/tcpm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index f1d3e54210df..8f2af348bda5 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -2297,7 +2297,8 @@ static unsigned int tcpm_pd_select_pps_apdo(struct tcpm_port *port) pdo_pps_apdo_max_voltage(snk)); port->pps_data.max_curr = min_pps_apdo_current(src, snk); port->pps_data.out_volt = min(port->pps_data.max_volt, - port->pps_data.out_volt); + max(port->pps_data.min_volt, + port->pps_data.out_volt)); port->pps_data.op_curr = min(port->pps_data.max_curr, port->pps_data.op_curr); }