All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jun Li <jun.li@nxp.com>
To: hdegoede@redhat.com, linux@roeck-us.net, heikki.krogerus@linux.intel.com
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-imx@nxp.com
Subject: [RFC] usb: typec: tcpm: remove operating_snk_mw for rdo
Date: Tue, 17 Apr 2018 14:01:48 +0800	[thread overview]
Message-ID: <1523944908-8350-1-git-send-email-jun.li@nxp.com> (raw)

This patch is a further update for rdo based on [1], which
removed max_snk_ma/mv/mw but kept operating_snk_mw.
operating_snk_mw is only used to judge capability mismatch,
per PD spec, we can achieve this via compare the selected
source PDO and matching sink PDO, also after patch [1], we
don't limit the PDO matching between the same type, so the
rdo operating and max current/power calculation should be
updated accordingly.

[1]https://patchwork.kernel.org/patch/10342299/

Signed-off-by: Li Jun <jun.li@nxp.com>
---
 drivers/usb/typec/tcpm.c | 52 ++++++++++++++++++++++++++++++------------------
 1 file changed, 33 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
index 27192083..0be04b3 100644
--- a/drivers/usb/typec/tcpm.c
+++ b/drivers/usb/typec/tcpm.c
@@ -1854,28 +1854,42 @@ static int tcpm_pd_build_request(struct tcpm_port *port, u32 *rdo)
 	else
 		mv = pdo_min_voltage(pdo);
 
-	/* Select maximum available current within the sink pdo's limit */
-	if (type == PDO_TYPE_BATT) {
-		mw = min_power(pdo, matching_snk_pdo);
-		ma = 1000 * mw / mv;
-	} else {
-		ma = min_current(pdo, matching_snk_pdo);
-		mw = ma * mv / 1000;
-	}
-
 	flags = RDO_USB_COMM | RDO_NO_SUSPEND;
 
-	/* Set mismatch bit if offered power is less than operating power */
-	max_ma = ma;
-	max_mw = mw;
-	if (mw < port->operating_snk_mw) {
-		flags |= RDO_CAP_MISMATCH;
-		if (type == PDO_TYPE_BATT &&
-		    (pdo_max_power(matching_snk_pdo) > pdo_max_power(pdo)))
-			max_mw = pdo_max_power(matching_snk_pdo);
-		else if (pdo_max_current(matching_snk_pdo) >
-			 pdo_max_current(pdo))
+	switch (type) {
+	case PDO_TYPE_FIXED:
+	case PDO_TYPE_VAR:
+		if (pdo_type(matching_snk_pdo) == PDO_TYPE_BATT)
+			max_ma = pdo_max_power(matching_snk_pdo) * 1000 / mv;
+		else
 			max_ma = pdo_max_current(matching_snk_pdo);
+
+		if (max_ma > pdo_max_current(pdo)) {
+			flags |= RDO_CAP_MISMATCH;
+			ma = pdo_max_current(pdo);
+		} else {
+			ma = max_ma;
+		}
+		break;
+	case PDO_TYPE_BATT:
+		if (pdo_type(matching_snk_pdo) == PDO_TYPE_BATT)
+			max_mw = pdo_max_power(matching_snk_pdo);
+		else
+			max_mw = pdo_max_current(matching_snk_pdo) *
+				 pdo_min_voltage(matching_snk_pdo) /
+				 1000;
+
+		if (max_mw > pdo_max_power(pdo)) {
+			flags |= RDO_CAP_MISMATCH;
+			mw = pdo_max_power(pdo);
+		} else {
+			mw = max_mw;
+		}
+
+		ma = mw * 1000 / mv;
+		break;
+	default:
+		break;
 	}
 
 	tcpm_log(port, "cc=%d cc1=%d cc2=%d vbus=%d vconn=%s polarity=%d",

             reply	other threads:[~2018-04-17  6:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-17  6:01 Jun Li [this message]
2018-04-18 11:40 [RFC] usb: typec: tcpm: remove operating_snk_mw for rdo Hans de Goede
2018-04-20  9:18 Jun Li
2018-04-20  9:20 Hans de Goede
2018-04-20 10:51 Jun Li
2018-04-20 12:49 Hans de Goede
2018-04-20 14:13 Guenter Roeck
2018-04-20 15:22 Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1523944908-8350-1-git-send-email-jun.li@nxp.com \
    --to=jun.li@nxp.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.