Linux USB
 help / color / mirror / Atom feed
* [PATCH v2] usb: typec: tcpm: not sink vbus if operational current is 0mA
@ 2023-08-01  7:01 Xu Yang
  2023-08-02 10:57 ` Heikki Krogerus
  2023-08-02 13:57 ` Guenter Roeck
  0 siblings, 2 replies; 3+ messages in thread
From: Xu Yang @ 2023-08-01  7:01 UTC (permalink / raw)
  To: linux, heikki.krogerus, gregkh; +Cc: linux-usb, linux-imx, jun.li

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>

---
Changes in v2:
  - also call tcpm_set_charge() when charge is false as suggested from
    Heikki and Guenter.
---
 drivers/usb/typec/tcpm/tcpm.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 829d75ebab42..d999e6984fea 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -4301,7 +4301,9 @@ 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);
+			/* Not sink vbus if operational current is 0mA */
+			tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0]));
+
 			if (!port->pd_supported)
 				tcpm_set_state(port, SNK_READY, 0);
 			else
@@ -4582,7 +4584,8 @@ 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);
+			/* Not sink vbus if operational current is 0mA */
+			tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0]));
 		}
 		if (port->ams == HARD_RESET)
 			tcpm_ams_finish(port);
-- 
2.34.1


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

* Re: [PATCH v2] usb: typec: tcpm: not sink vbus if operational current is 0mA
  2023-08-01  7:01 [PATCH v2] usb: typec: tcpm: not sink vbus if operational current is 0mA Xu Yang
@ 2023-08-02 10:57 ` Heikki Krogerus
  2023-08-02 13:57 ` Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2023-08-02 10:57 UTC (permalink / raw)
  To: Xu Yang; +Cc: linux, gregkh, linux-usb, linux-imx, jun.li

On Tue, Aug 01, 2023 at 03:01:10PM +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>

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

> ---
> Changes in v2:
>   - also call tcpm_set_charge() when charge is false as suggested from
>     Heikki and Guenter.
> ---
>  drivers/usb/typec/tcpm/tcpm.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 829d75ebab42..d999e6984fea 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -4301,7 +4301,9 @@ 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);
> +			/* Not sink vbus if operational current is 0mA */
> +			tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0]));
> +
>  			if (!port->pd_supported)
>  				tcpm_set_state(port, SNK_READY, 0);
>  			else
> @@ -4582,7 +4584,8 @@ 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);
> +			/* Not sink vbus if operational current is 0mA */
> +			tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0]));
>  		}
>  		if (port->ams == HARD_RESET)
>  			tcpm_ams_finish(port);
> -- 
> 2.34.1

-- 
heikki

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

* Re: [PATCH v2] usb: typec: tcpm: not sink vbus if operational current is 0mA
  2023-08-01  7:01 [PATCH v2] usb: typec: tcpm: not sink vbus if operational current is 0mA Xu Yang
  2023-08-02 10:57 ` Heikki Krogerus
@ 2023-08-02 13:57 ` Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2023-08-02 13:57 UTC (permalink / raw)
  To: Xu Yang, heikki.krogerus, gregkh; +Cc: linux-usb, linux-imx, jun.li

On 8/1/23 00:01, 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>

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

> 
> ---
> Changes in v2:
>    - also call tcpm_set_charge() when charge is false as suggested from
>      Heikki and Guenter.
> ---
>   drivers/usb/typec/tcpm/tcpm.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 829d75ebab42..d999e6984fea 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -4301,7 +4301,9 @@ 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);
> +			/* Not sink vbus if operational current is 0mA */
> +			tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0]));
> +
>   			if (!port->pd_supported)
>   				tcpm_set_state(port, SNK_READY, 0);
>   			else
> @@ -4582,7 +4584,8 @@ 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);
> +			/* Not sink vbus if operational current is 0mA */
> +			tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0]));
>   		}
>   		if (port->ams == HARD_RESET)
>   			tcpm_ams_finish(port);


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

end of thread, other threads:[~2023-08-02 13:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-01  7:01 [PATCH v2] usb: typec: tcpm: not sink vbus if operational current is 0mA Xu Yang
2023-08-02 10:57 ` Heikki Krogerus
2023-08-02 13:57 ` Guenter Roeck

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