Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: typec: tcpm: not sink vbus if operational current is 0mA
@ 2023-06-30 10:56 Xu Yang
  2023-07-31  8:56 ` Xu Yang
  2023-07-31 13:33 ` Heikki Krogerus
  0 siblings, 2 replies; 5+ messages in thread
From: Xu Yang @ 2023-06-30 10:56 UTC (permalink / raw)
  To: linux, heikki.krogerus; +Cc: gregkh, linux-imx, linux-usb, jun.li, xu.yang_2

PD3.0 Spec 6.4.1.3.1 said:
For a Sink requiring no power from the Source, the Voltage (B19…10)
Shall be set to 5V and the Operational Current Shall be set to 0mA.

Therefore, we can keep sink path closed if the operational current of
the first fixed PDO is 0mA.

Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 829d75ebab42..4f7e4c50e847 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -4301,7 +4301,12 @@ static void run_state_machine(struct tcpm_port *port)
 			if (port->slow_charger_loop && (current_lim > PD_P_SNK_STDBY_MW / 5))
 				current_lim = PD_P_SNK_STDBY_MW / 5;
 			tcpm_set_current_limit(port, current_lim, 5000);
-			tcpm_set_charge(port, true);
+
+			if (pdo_max_current(port->snk_pdo[0]))
+				tcpm_set_charge(port, true);
+			else
+				tcpm_log(port, "Not require power from Source");
+
 			if (!port->pd_supported)
 				tcpm_set_state(port, SNK_READY, 0);
 			else
@@ -4582,7 +4587,10 @@ static void run_state_machine(struct tcpm_port *port)
 			tcpm_set_current_limit(port,
 					       tcpm_get_current_limit(port),
 					       5000);
-			tcpm_set_charge(port, true);
+			if (pdo_max_current(port->snk_pdo[0]))
+				tcpm_set_charge(port, true);
+			else
+				tcpm_log(port, "Not require power from Source");
 		}
 		if (port->ams == HARD_RESET)
 			tcpm_ams_finish(port);
-- 
2.34.1


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

* RE: [PATCH] usb: typec: tcpm: not sink vbus if operational current is 0mA
  2023-06-30 10:56 [PATCH] usb: typec: tcpm: not sink vbus if operational current is 0mA Xu Yang
@ 2023-07-31  8:56 ` Xu Yang
  2023-07-31 13:33 ` Heikki Krogerus
  1 sibling, 0 replies; 5+ messages in thread
From: Xu Yang @ 2023-07-31  8:56 UTC (permalink / raw)
  To: linux@roeck-us.net, heikki.krogerus@linux.intel.com
  Cc: gregkh@linuxfoundation.org, dl-linux-imx,
	linux-usb@vger.kernel.org, Jun Li


> -----Original Message-----
> From: Xu Yang
> Sent: Friday, June 30, 2023 6:53 PM
> To: linux@roeck-us.net; heikki.krogerus@linux.intel.com
> Cc: gregkh@linuxfoundation.org; dl-linux-imx <linux-imx@nxp.com>; linux-usb@vger.kernel.org; Jun Li <jun.li@nxp.com>;
> Xu Yang <xu.yang_2@nxp.com>
> Subject: [PATCH] usb: typec: tcpm: not sink vbus if operational current is 0mA
> 
> PD3.0 Spec 6.4.1.3.1 said:
> For a Sink requiring no power from the Source, the Voltage (B19…10)
> Shall be set to 5V and the Operational Current Shall be set to 0mA.
> 
> Therefore, we can keep sink path closed if the operational current of
> the first fixed PDO is 0mA.
> 
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
>  drivers/usb/typec/tcpm/tcpm.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 829d75ebab42..4f7e4c50e847 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -4301,7 +4301,12 @@ static void run_state_machine(struct tcpm_port *port)
>  			if (port->slow_charger_loop && (current_lim > PD_P_SNK_STDBY_MW / 5))
>  				current_lim = PD_P_SNK_STDBY_MW / 5;
>  			tcpm_set_current_limit(port, current_lim, 5000);
> -			tcpm_set_charge(port, true);
> +
> +			if (pdo_max_current(port->snk_pdo[0]))
> +				tcpm_set_charge(port, true);
> +			else
> +				tcpm_log(port, "Not require power from Source");
> +
>  			if (!port->pd_supported)
>  				tcpm_set_state(port, SNK_READY, 0);
>  			else
> @@ -4582,7 +4587,10 @@ static void run_state_machine(struct tcpm_port *port)
>  			tcpm_set_current_limit(port,
>  					       tcpm_get_current_limit(port),
>  					       5000);
> -			tcpm_set_charge(port, true);
> +			if (pdo_max_current(port->snk_pdo[0]))
> +				tcpm_set_charge(port, true);
> +			else
> +				tcpm_log(port, "Not require power from Source");
>  		}
>  		if (port->ams == HARD_RESET)
>  			tcpm_ams_finish(port);
> --
> 2.34.1

A gentle ping.


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

* Re: [PATCH] usb: typec: tcpm: not sink vbus if operational current is 0mA
  2023-06-30 10:56 [PATCH] usb: typec: tcpm: not sink vbus if operational current is 0mA Xu Yang
  2023-07-31  8:56 ` Xu Yang
@ 2023-07-31 13:33 ` Heikki Krogerus
  2023-07-31 13:42   ` Guenter Roeck
  1 sibling, 1 reply; 5+ messages in thread
From: Heikki Krogerus @ 2023-07-31 13:33 UTC (permalink / raw)
  To: Xu Yang; +Cc: linux, gregkh, linux-imx, linux-usb, jun.li

Hi,

I'm sorry to keep you waiting.

On Fri, Jun 30, 2023 at 06:56:56PM +0800, Xu Yang wrote:
> PD3.0 Spec 6.4.1.3.1 said:
> For a Sink requiring no power from the Source, the Voltage (B19…10)
> Shall be set to 5V and the Operational Current Shall be set to 0mA.
> 
> Therefore, we can keep sink path closed if the operational current of
> the first fixed PDO is 0mA.
> 
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
>  drivers/usb/typec/tcpm/tcpm.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 829d75ebab42..4f7e4c50e847 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -4301,7 +4301,12 @@ static void run_state_machine(struct tcpm_port *port)
>  			if (port->slow_charger_loop && (current_lim > PD_P_SNK_STDBY_MW / 5))
>  				current_lim = PD_P_SNK_STDBY_MW / 5;
>  			tcpm_set_current_limit(port, current_lim, 5000);
> -			tcpm_set_charge(port, true);
> +
> +			if (pdo_max_current(port->snk_pdo[0]))
> +				tcpm_set_charge(port, true);
> +			else
> +				tcpm_log(port, "Not require power from Source");
> +
>  			if (!port->pd_supported)
>  				tcpm_set_state(port, SNK_READY, 0);
>  			else
> @@ -4582,7 +4587,10 @@ static void run_state_machine(struct tcpm_port *port)
>  			tcpm_set_current_limit(port,
>  					       tcpm_get_current_limit(port),
>  					       5000);
> -			tcpm_set_charge(port, true);
> +			if (pdo_max_current(port->snk_pdo[0]))
> +				tcpm_set_charge(port, true);
> +			else
> +				tcpm_log(port, "Not require power from Source");

Shouldn't you still always call tcpm_set_charge()?

        tcpm_set_charge(port, pdo_max_current(port->snk_pdo[0]));

I think we need to wait for comments from Guenter. I don't know this
driver well enough.

thanks,

-- 
heikki

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

* Re: [PATCH] usb: typec: tcpm: not sink vbus if operational current is 0mA
  2023-07-31 13:33 ` Heikki Krogerus
@ 2023-07-31 13:42   ` Guenter Roeck
  2023-08-01  2:17     ` [EXT] " Xu Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2023-07-31 13:42 UTC (permalink / raw)
  To: Heikki Krogerus, Xu Yang; +Cc: gregkh, linux-imx, linux-usb, jun.li

On 7/31/23 06:33, Heikki Krogerus wrote:
> Hi,
> 
> I'm sorry to keep you waiting.
> 
> On Fri, Jun 30, 2023 at 06:56:56PM +0800, Xu Yang wrote:
>> PD3.0 Spec 6.4.1.3.1 said:
>> For a Sink requiring no power from the Source, the Voltage (B19…10)
>> Shall be set to 5V and the Operational Current Shall be set to 0mA.
>>
>> Therefore, we can keep sink path closed if the operational current of
>> the first fixed PDO is 0mA.
>>
>> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
>> ---
>>   drivers/usb/typec/tcpm/tcpm.c | 12 ++++++++++--
>>   1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
>> index 829d75ebab42..4f7e4c50e847 100644
>> --- a/drivers/usb/typec/tcpm/tcpm.c
>> +++ b/drivers/usb/typec/tcpm/tcpm.c
>> @@ -4301,7 +4301,12 @@ static void run_state_machine(struct tcpm_port *port)
>>   			if (port->slow_charger_loop && (current_lim > PD_P_SNK_STDBY_MW / 5))
>>   				current_lim = PD_P_SNK_STDBY_MW / 5;
>>   			tcpm_set_current_limit(port, current_lim, 5000);
>> -			tcpm_set_charge(port, true);
>> +
>> +			if (pdo_max_current(port->snk_pdo[0]))
>> +				tcpm_set_charge(port, true);
>> +			else
>> +				tcpm_log(port, "Not require power from Source");
>> +
>>   			if (!port->pd_supported)
>>   				tcpm_set_state(port, SNK_READY, 0);
>>   			else
>> @@ -4582,7 +4587,10 @@ static void run_state_machine(struct tcpm_port *port)
>>   			tcpm_set_current_limit(port,
>>   					       tcpm_get_current_limit(port),
>>   					       5000);
>> -			tcpm_set_charge(port, true);
>> +			if (pdo_max_current(port->snk_pdo[0]))
>> +				tcpm_set_charge(port, true);
>> +			else
>> +				tcpm_log(port, "Not require power from Source");
> 
> Shouldn't you still always call tcpm_set_charge()?
> 
>          tcpm_set_charge(port, pdo_max_current(port->snk_pdo[0]));
> 

I think so, something like
	tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0]));

Guenter

> I think we need to wait for comments from Guenter. I don't know this
> driver well enough.
> 
> thanks,
> 


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

* RE: [EXT] Re: [PATCH] usb: typec: tcpm: not sink vbus if operational current is 0mA
  2023-07-31 13:42   ` Guenter Roeck
@ 2023-08-01  2:17     ` Xu Yang
  0 siblings, 0 replies; 5+ messages in thread
From: Xu Yang @ 2023-08-01  2:17 UTC (permalink / raw)
  To: Guenter Roeck, Heikki Krogerus
  Cc: gregkh@linuxfoundation.org, dl-linux-imx,
	linux-usb@vger.kernel.org, Jun Li

Hi Heikki and Guenter,

> On 7/31/23 06:33, Heikki Krogerus wrote:
> > Hi,
> >
> > I'm sorry to keep you waiting.
> >
> > On Fri, Jun 30, 2023 at 06:56:56PM +0800, Xu Yang wrote:
> >> PD3.0 Spec 6.4.1.3.1 said:
> >> For a Sink requiring no power from the Source, the Voltage (B19…10)
> >> Shall be set to 5V and the Operational Current Shall be set to 0mA.
> >>
> >> Therefore, we can keep sink path closed if the operational current of
> >> the first fixed PDO is 0mA.
> >>
> >> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> >> ---
> >>   drivers/usb/typec/tcpm/tcpm.c | 12 ++++++++++--
> >>   1 file changed, 10 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> >> index 829d75ebab42..4f7e4c50e847 100644
> >> --- a/drivers/usb/typec/tcpm/tcpm.c
> >> +++ b/drivers/usb/typec/tcpm/tcpm.c
> >> @@ -4301,7 +4301,12 @@ static void run_state_machine(struct tcpm_port *port)
> >>                      if (port->slow_charger_loop && (current_lim > PD_P_SNK_STDBY_MW / 5))
> >>                              current_lim = PD_P_SNK_STDBY_MW / 5;
> >>                      tcpm_set_current_limit(port, current_lim, 5000);
> >> -                    tcpm_set_charge(port, true);
> >> +
> >> +                    if (pdo_max_current(port->snk_pdo[0]))
> >> +                            tcpm_set_charge(port, true);
> >> +                    else
> >> +                            tcpm_log(port, "Not require power from Source");
> >> +
> >>                      if (!port->pd_supported)
> >>                              tcpm_set_state(port, SNK_READY, 0);
> >>                      else
> >> @@ -4582,7 +4587,10 @@ static void run_state_machine(struct tcpm_port *port)
> >>                      tcpm_set_current_limit(port,
> >>                                             tcpm_get_current_limit(port),
> >>                                             5000);
> >> -                    tcpm_set_charge(port, true);
> >> +                    if (pdo_max_current(port->snk_pdo[0]))
> >> +                            tcpm_set_charge(port, true);
> >> +                    else
> >> +                            tcpm_log(port, "Not require power from Source");
> >
> > Shouldn't you still always call tcpm_set_charge()?
> >
> >          tcpm_set_charge(port, pdo_max_current(port->snk_pdo[0]));
> >
> 
> I think so, something like
>         tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0]));

I assume the sink path is already closed before tcpm_set_charge(). But
this way of handling is also okay for me. Will send out v2 later.

Thanks,
Xu Yang

> 
> Guenter
> 
> > I think we need to wait for comments from Guenter. I don't know this
> > driver well enough.
> >
> > thanks,
> >


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

end of thread, other threads:[~2023-08-01  2:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-30 10:56 [PATCH] usb: typec: tcpm: not sink vbus if operational current is 0mA Xu Yang
2023-07-31  8:56 ` Xu Yang
2023-07-31 13:33 ` Heikki Krogerus
2023-07-31 13:42   ` Guenter Roeck
2023-08-01  2:17     ` [EXT] " Xu Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox