From: Kyle Tso <kyletso@google.com>
To: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Cc: "linux@roeck-us.net" <linux@roeck-us.net>,
"heikki.krogerus@linux.intel.com"
<heikki.krogerus@linux.intel.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"badhri@google.com" <badhri@google.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] usb: typec: tcpm: Extend the matching rules on PPS APDO selection
Date: Mon, 17 Dec 2018 20:45:10 +0800 [thread overview]
Message-ID: <CAGZ6i=1jC0e1gkh6nmDS2y4SE3op0pZ+RPAgExfmfnBJkcFWCw@mail.gmail.com> (raw)
In-Reply-To: <HE1PR1001MB1002719044E56D116949E2AE80BC0@HE1PR1001MB1002.EURPRD10.PROD.OUTLOOK.COM>
On Mon, Dec 17, 2018 at 8:23 PM Adam Thomson
<Adam.Thomson.Opensource@diasemi.com> wrote:
>
> On 17 December 2018 02:48, Kyle Tso wrote:
>
> > Current matching rules ensure that the voltage range of selected Source
> > Capability is entirely within the range defined in one of the Sink Capabilities. This
> > is reasonable but not practical because Sink may not support wide range of
> > voltage when sinking power while Source could advertise its capabilities in
> > raletively wider range. For example, a Source PDO advertising 3.3V-11V@3A (9V
>
> relatively
>
noted!
Thanks for the correction. I will fix this in the next patch.
> > Prog of Fixed Nominal Voltage) will not be selected if the Sink requires 5V-
> > 12V@3A PPS power. However, the Sink could work well if the requested voltage
> > range in RDOs is 5V-11V@3A.
> >
> > Currently accepted:
> > |--------- source -----|
> > |----------- sink ---------------|
> >
> > Currently not accepted:
> > |--------- source -----|
> > |----------- sink ---------------|
> >
> > |--------- source -----|
> > |----------- sink ---------------|
> >
> > |--------- source -----------------|
> > |------ sink -------|
> >
> > To improve the usability, change the matching rules to what listed
> > below:
> > a. The Source PDO is selectable if any portion of the voltage range
> > overlaps one of the Sink PDO's voltage range.
> > b. The maximum operational voltage will be the lower one between the
> > selected Source PDO and the matching Sink PDO.
> > c. The maximum power will be the maximum operational voltage times the
> > maximum current defined in the selected Source PDO d. Select the Source PDO
> > with the highest maximum power
> >
> > Signed-off-by: Kyle Tso <kyletso@google.com>
> >
> > ---
> > Changelog since v1:
> > - updated the commit message as suggested by Guenter Roeck <linux@roeck-
> > us.net>
> > ---
> > drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++------------
> > 1 file changed, 17 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> > index 3620efee2688..3001df7bd602 100644
> > --- a/drivers/usb/typec/tcpm/tcpm.c
> > +++ b/drivers/usb/typec/tcpm/tcpm.c
> > @@ -2213,7 +2213,8 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
> > tcpm_port *port)
> > unsigned int i, j, max_mw = 0, max_mv = 0;
> > unsigned int min_src_mv, max_src_mv, src_ma, src_mw;
> > unsigned int min_snk_mv, max_snk_mv;
> > - u32 pdo;
> > + unsigned int max_op_mv;
> > + u32 pdo, src, snk;
> > unsigned int src_pdo = 0, snk_pdo = 0;
> >
> > /*
> > @@ -2263,16 +2264,18 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
> > tcpm_port *port)
> > continue;
> > }
> >
> > - if (max_src_mv <= max_snk_mv &&
> > - min_src_mv >= min_snk_mv) {
> > + if (min_src_mv <= max_snk_mv &&
> > + max_src_mv >= min_snk_mv) {
> > + max_op_mv = min(max_src_mv,
> > max_snk_mv);
> > + src_mw = (max_op_mv * src_ma) / 1000;
> > /* Prefer higher voltages if available */
> > if ((src_mw == max_mw &&
> > - min_src_mv > max_mv) ||
> > + max_op_mv > max_mv) ||
> > src_mw > max_mw) {
>
> Sorry I didn't raise this before, but came to mind this morning when I was
> considering your updates again. What happens if the Source validly provides two
> PPS APDOs, for example:
>
> 3.3V - 11V, 3A (9V programmable)
> 3.3V - 16V, 3A (15V programmable)
>
> and the sink APDO is:
>
> 5V - 9V, 3A
>
> I think the code here will now select the higher range (15V programmable) as it
> gives a larger power output value, even if the sink can only support a voltage
> that's far smaller. I really don't think this is correct. *If* you are going to
> allow selection of PPS APDOs that provide a larger voltage range than the Sink
> can actually cope with, then I think you should at least select the lower of
> those advertised which fulfils the needs of the Sink.
Source:
3.3V - 11V, 3A (9V programmable)
3.3V - 16V, 3A (15V programmable)
Sink
5V - 9V, 3A
In this case, the Sink will select "3.3V - 11V, 3A (9V programmable)"
because the
"max_op_mv" when dealing with both Source Cap will be the same.
See line#2269, "max_op_mv" will be limited by "max_snk_mv" which is 9V.
And in line#2273, "max_op_mv" (of the second src_cap) fails the check
because "max_mv", which is equal to the "max_op_mv" of the previous src_cap,
is the same as it.
2267 if (min_src_mv <= max_snk_mv &&
2268 max_src_mv >= min_snk_mv) {
2269 max_op_mv = min(max_src_mv,
max_snk_mv);
2270 src_mw = (max_op_mv * src_ma) / 1000;
2271 /* Prefer higher voltages if
available */
2272 if ((src_mw == max_mw &&
2273 max_op_mv > max_mv) ||
2274 src_mw > max_mw) {
2275 src_pdo = i;
2276 snk_pdo = j;
2277 max_mw = src_mw;
2278 max_mv = max_op_mv;
2279 }
2280 }
>
> > src_pdo = i;
> > snk_pdo = j;
> > max_mw = src_mw;
> > - max_mv = max_src_mv;
> > + max_mv = max_op_mv;
> > }
> > }
> > }
> > @@ -2285,14 +2288,16 @@ static unsigned int tcpm_pd_select_pps_apdo(struct
> > tcpm_port *port)
> > }
> >
> > if (src_pdo) {
> > - pdo = port->source_caps[src_pdo];
> > -
> > - port->pps_data.min_volt = pdo_pps_apdo_min_voltage(pdo);
> > - port->pps_data.max_volt = pdo_pps_apdo_max_voltage(pdo);
> > - port->pps_data.max_curr =
> > - min_pps_apdo_current(pdo, port->snk_pdo[snk_pdo]);
> > + src = port->source_caps[src_pdo];
> > + snk = port->snk_pdo[snk_pdo];
> > +
> > + port->pps_data.min_volt =
> > max(pdo_pps_apdo_min_voltage(src),
> > + pdo_pps_apdo_min_voltage(snk));
> > + port->pps_data.max_volt =
> > min(pdo_pps_apdo_max_voltage(src),
> > + pdo_pps_apdo_max_voltage(snk));
> > + port->pps_data.max_curr = min_pps_apdo_current(src, snk);
> > port->pps_data.out_volt =
> > - min(pdo_pps_apdo_max_voltage(pdo), port-
> > >pps_data.out_volt);
> > + min(port->pps_data.max_volt, port-
> > >pps_data.out_volt);
> > port->pps_data.op_curr =
> > min(port->pps_data.max_curr, port->pps_data.op_curr);
> > }
> > --
> > 2.20.0.405.gbc1bbc6f85-goog
>
next prev parent reply other threads:[~2018-12-17 12:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-17 2:48 [PATCH] usb: typec: tcpm: Extend the matching rules on PPS APDO selection Kyle Tso
2018-12-17 2:57 ` Guenter Roeck
2018-12-17 11:35 ` Heikki Krogerus
2018-12-17 12:29 ` Kyle Tso
2018-12-17 12:23 ` Adam Thomson
2018-12-17 12:45 ` Kyle Tso [this message]
2018-12-17 13:17 ` Kyle Tso
2018-12-17 13:27 ` Adam Thomson
-- strict thread matches above, loose matches on Subject: below --
2018-12-06 3:02 Kyle Tso
2018-12-06 17:56 ` Guenter Roeck
2018-12-12 1:38 ` Kyle Tso
2018-12-07 15:44 ` Heikki Krogerus
2018-12-10 9:01 ` Adam Thomson
2018-12-10 11:36 ` Adam Thomson
2018-12-12 2:46 ` Kyle Tso
2018-12-12 10:15 ` Adam Thomson
2018-12-13 11:04 ` Kyle Tso
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='CAGZ6i=1jC0e1gkh6nmDS2y4SE3op0pZ+RPAgExfmfnBJkcFWCw@mail.gmail.com' \
--to=kyletso@google.com \
--cc=Adam.Thomson.Opensource@diasemi.com \
--cc=badhri@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).