linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation
@ 2019-01-30  3:13 Kyle Tso
  2019-01-30 10:39 ` Adam Thomson
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Kyle Tso @ 2019-01-30  3:13 UTC (permalink / raw)
  To: linux, heikki.krogerus, gregkh
  Cc: badhri, Adam.Thomson.Opensource, linux-usb, linux-kernel, Kyle Tso

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 <kyletso@google.com>
---
 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);
 	}
-- 
2.20.1.495.gaa96b0ce6b-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation
  2019-01-30  3:13 [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation Kyle Tso
@ 2019-01-30 10:39 ` Adam Thomson
  2019-01-30 17:12 ` Guenter Roeck
  2019-01-31  7:31 ` Heikki Krogerus
  2 siblings, 0 replies; 6+ messages in thread
From: Adam Thomson @ 2019-01-30 10:39 UTC (permalink / raw)
  To: Kyle Tso, linux, heikki.krogerus, gregkh
  Cc: badhri, Adam Thomson, linux-usb, linux-kernel

On 30 January 2019 03:14, Kyle Tso wrote:

> 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 <kyletso@google.com>

I'd be interested to see how many Sources go off-piste like that with a more
unusual PPS range, especially when the default fixed is 5V, and they're required
to support one of the defined PPS ranges which will start at 3.3V. Not sure what
this might gain you. However, spec says it's possible so:

Reviewed-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>

> ---
>  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);
>  	}
> --
> 2.20.1.495.gaa96b0ce6b-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation
  2019-01-30  3:13 [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation Kyle Tso
  2019-01-30 10:39 ` Adam Thomson
@ 2019-01-30 17:12 ` Guenter Roeck
  2019-01-31  7:31 ` Heikki Krogerus
  2 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2019-01-30 17:12 UTC (permalink / raw)
  To: Kyle Tso
  Cc: heikki.krogerus, gregkh, badhri, Adam.Thomson.Opensource,
	linux-usb, linux-kernel

On Wed, Jan 30, 2019 at 11:13:53AM +0800, Kyle Tso wrote:
> 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 <kyletso@google.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  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);
>  	}
> -- 
> 2.20.1.495.gaa96b0ce6b-goog
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation
  2019-01-30  3:13 [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation Kyle Tso
  2019-01-30 10:39 ` Adam Thomson
  2019-01-30 17:12 ` Guenter Roeck
@ 2019-01-31  7:31 ` Heikki Krogerus
  2019-01-31  8:01   ` Greg KH
  2 siblings, 1 reply; 6+ messages in thread
From: Heikki Krogerus @ 2019-01-31  7:31 UTC (permalink / raw)
  To: Kyle Tso
  Cc: linux, gregkh, badhri, Adam.Thomson.Opensource, linux-usb, linux-kernel

On Wed, Jan 30, 2019 at 11:13:53AM +0800, Kyle Tso wrote:
> 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 <kyletso@google.com>

Fixes: c710d0bb76ff0 ("usb: typec: tcpm: Extend the matching rules on PPS APDO selection")
Cc: stable...

Right? In any case:

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  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);
>  	}
> -- 
> 2.20.1.495.gaa96b0ce6b-goog

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation
  2019-01-31  7:31 ` Heikki Krogerus
@ 2019-01-31  8:01   ` Greg KH
  2019-01-31  8:46     ` Heikki Krogerus
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2019-01-31  8:01 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Kyle Tso, linux, badhri, Adam.Thomson.Opensource, linux-usb,
	linux-kernel

On Thu, Jan 31, 2019 at 09:31:25AM +0200, Heikki Krogerus wrote:
> On Wed, Jan 30, 2019 at 11:13:53AM +0800, Kyle Tso wrote:
> > 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 <kyletso@google.com>
> 
> Fixes: c710d0bb76ff0 ("usb: typec: tcpm: Extend the matching rules on PPS APDO selection")
> Cc: stable...

No need for stable, as c710d0bb76ff ("usb: typec: tcpm: Extend the
matching rules on PPS APDO selection") only showed up in 5.0-rc1.

Note, no need for the extra digit on your sha1 listing, here's the
recommended way to show this:
	git show -s --abbrev-commit --abbrev=12 --pretty=format:"%h (\"%s\")%n"

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation
  2019-01-31  8:01   ` Greg KH
@ 2019-01-31  8:46     ` Heikki Krogerus
  0 siblings, 0 replies; 6+ messages in thread
From: Heikki Krogerus @ 2019-01-31  8:46 UTC (permalink / raw)
  To: Greg KH
  Cc: Kyle Tso, linux, badhri, Adam.Thomson.Opensource, linux-usb,
	linux-kernel

On Thu, Jan 31, 2019 at 09:01:00AM +0100, Greg KH wrote:
> On Thu, Jan 31, 2019 at 09:31:25AM +0200, Heikki Krogerus wrote:
> > On Wed, Jan 30, 2019 at 11:13:53AM +0800, Kyle Tso wrote:
> > > 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 <kyletso@google.com>
> > 
> > Fixes: c710d0bb76ff0 ("usb: typec: tcpm: Extend the matching rules on PPS APDO selection")
> > Cc: stable...
> 
> No need for stable, as c710d0bb76ff ("usb: typec: tcpm: Extend the
> matching rules on PPS APDO selection") only showed up in 5.0-rc1.
> 
> Note, no need for the extra digit on your sha1 listing, here's the
> recommended way to show this:
> 	git show -s --abbrev-commit --abbrev=12 --pretty=format:"%h (\"%s\")%n"

OK. Thanks for the hint!

Cheers,

-- 
heikki

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-01-31  8:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-30  3:13 [PATCH] usb: typec: tcpm: Correct the PPS out_volt calculation Kyle Tso
2019-01-30 10:39 ` Adam Thomson
2019-01-30 17:12 ` Guenter Roeck
2019-01-31  7:31 ` Heikki Krogerus
2019-01-31  8:01   ` Greg KH
2019-01-31  8:46     ` Heikki Krogerus

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).