linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Fix some defects related Type-C TCPM
@ 2023-03-20 10:07 Frank Wang
  2023-03-20 10:07 ` [PATCH v2 1/3] usb: typec: tcpm: fix cc role at port reset Frank Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Frank Wang @ 2023-03-20 10:07 UTC (permalink / raw)
  To: linux, heikki.krogerus, gregkh, heiko
  Cc: linux-usb, linux-kernel, linux-rockchip, huangtao, william.wu,
	jianwei.zheng, yubing.zhang, wmc, Frank Wang

This series fix some defects of TCPM like port reset error, SVIDs
discover error and etc.

Tested on Rockchip EVB board integrated with FUSB302 or HUSB311 Type-C
controller.

Changes in v2:
 - Make some tweaking based on Guenter and Heikki's comments for [PATCH 1/3] and [PATCH 2/3].
 - Abandon [PATCH 4/4] in v1.

Frank Wang (3):
  usb: typec: tcpm: fix cc role at port reset
  usb: typec: tcpm: fix multiple times discover svids error
  usb: typec: tcpm: add get max power support

 drivers/usb/typec/tcpm/tcpm.c | 43 +++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

-- 
2.17.1


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

* [PATCH v2 1/3] usb: typec: tcpm: fix cc role at port reset
  2023-03-20 10:07 [PATCH v2 0/3] Fix some defects related Type-C TCPM Frank Wang
@ 2023-03-20 10:07 ` Frank Wang
  2023-04-25  3:01   ` Frank Wang
  2023-03-20 10:07 ` [RESEND PATCH v2 2/3] usb: typec: tcpm: fix multiple times discover svids error Frank Wang
  2023-03-20 10:07 ` [PATCH v2 3/3] usb: typec: tcpm: add get max power support Frank Wang
  2 siblings, 1 reply; 9+ messages in thread
From: Frank Wang @ 2023-03-20 10:07 UTC (permalink / raw)
  To: linux, heikki.krogerus, gregkh, heiko
  Cc: linux-usb, linux-kernel, linux-rockchip, huangtao, william.wu,
	jianwei.zheng, yubing.zhang, wmc, Frank Wang

In the current implementation, the tcpm set CC1/CC2 role to open when
it do port reset would cause the VBUS removed by the Type-C partner.

This sets CC1/CC2 according to the default state of port to fix it.

Signed-off-by: Frank Wang <frank.wang@rock-chips.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 a0d943d785800..56782dd05e2ec 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -4851,7 +4851,8 @@ static void run_state_machine(struct tcpm_port *port)
 		break;
 	case PORT_RESET:
 		tcpm_reset_port(port);
-		tcpm_set_cc(port, TYPEC_CC_OPEN);
+		tcpm_set_cc(port, tcpm_default_state(port) == SNK_UNATTACHED ?
+			    TYPEC_CC_RD : tcpm_rp_cc(port));
 		tcpm_set_state(port, PORT_RESET_WAIT_OFF,
 			       PD_T_ERROR_RECOVERY);
 		break;
-- 
2.17.1


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

* [RESEND PATCH v2 2/3] usb: typec: tcpm: fix multiple times discover svids error
  2023-03-20 10:07 [PATCH v2 0/3] Fix some defects related Type-C TCPM Frank Wang
  2023-03-20 10:07 ` [PATCH v2 1/3] usb: typec: tcpm: fix cc role at port reset Frank Wang
@ 2023-03-20 10:07 ` Frank Wang
  2023-03-20 10:07 ` [PATCH v2 3/3] usb: typec: tcpm: add get max power support Frank Wang
  2 siblings, 0 replies; 9+ messages in thread
From: Frank Wang @ 2023-03-20 10:07 UTC (permalink / raw)
  To: linux, heikki.krogerus, gregkh, heiko
  Cc: linux-usb, linux-kernel, linux-rockchip, huangtao, william.wu,
	jianwei.zheng, yubing.zhang, wmc, Frank Wang

PD3.0 Spec 6.4.4.3.2 say that only Responder supports 12 or more SVIDs,
the Discover SVIDs Command Shall be executed multiple times until a
Discover SVIDs VDO is returned ending either with a SVID value of
0x0000 in the last part of the last VDO or with a VDO containing two
SVIDs with values of 0x0000.

In the current implementation, if the last VDO does not find that the
Discover SVIDs Command would be executed multiple times even if the
Responder SVIDs are less than 12, and we found some odd dockers just
meet this case. So fix it.

Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 56782dd05e2ec..13830b5e2d09f 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -1515,7 +1515,21 @@ static bool svdm_consume_svids(struct tcpm_port *port, const u32 *p, int cnt)
 		pmdata->svids[pmdata->nsvids++] = svid;
 		tcpm_log(port, "SVID %d: 0x%x", pmdata->nsvids, svid);
 	}
-	return true;
+
+	/*
+	 * PD3.0 Spec 6.4.4.3.2: The SVIDs are returned 2 per VDO (see Table
+	 * 6-43), and can be returned maximum 6 VDOs per response (see Figure
+	 * 6-19). If the Respondersupports 12 or more SVID then the Discover
+	 * SVIDs Command Shall be executed multiple times until a Discover
+	 * SVIDs VDO is returned ending either with a SVID value of 0x0000 in
+	 * the last part of the last VDO or with a VDO containing two SVIDs
+	 * with values of 0x0000.
+	 *
+	 * However, some odd dockers support SVIDs less than 12 but without
+	 * 0x0000 in the last VDO, so we need to break the Discover SVIDs
+	 * request and return false here.
+	 */
+	return cnt == 7;
 abort:
 	tcpm_log(port, "SVID_DISCOVERY_MAX(%d) too low!", SVID_DISCOVERY_MAX);
 	return false;
-- 
2.17.1


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

* [PATCH v2 3/3] usb: typec: tcpm: add get max power support
  2023-03-20 10:07 [PATCH v2 0/3] Fix some defects related Type-C TCPM Frank Wang
  2023-03-20 10:07 ` [PATCH v2 1/3] usb: typec: tcpm: fix cc role at port reset Frank Wang
  2023-03-20 10:07 ` [RESEND PATCH v2 2/3] usb: typec: tcpm: fix multiple times discover svids error Frank Wang
@ 2023-03-20 10:07 ` Frank Wang
  2023-03-20 20:31   ` Sebastian Reichel
  2 siblings, 1 reply; 9+ messages in thread
From: Frank Wang @ 2023-03-20 10:07 UTC (permalink / raw)
  To: linux, heikki.krogerus, gregkh, heiko
  Cc: linux-usb, linux-kernel, linux-rockchip, huangtao, william.wu,
	jianwei.zheng, yubing.zhang, wmc, Frank Wang

Traverse fixed pdos to calculate the maximum power that the charger
can provide, and it can be get by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT
property.

Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 13830b5e2d09f..d6ad3cdf9e4af 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -6320,6 +6320,27 @@ static int tcpm_psy_get_current_now(struct tcpm_port *port,
 	return 0;
 }
 
+static int tcpm_psy_get_input_power_limit(struct tcpm_port *port,
+					  union power_supply_propval *val)
+{
+	unsigned int src_mv, src_ma, max_src_mw = 0;
+	unsigned int i, tmp;
+
+	for (i = 0; i < port->nr_source_caps; i++) {
+		u32 pdo = port->source_caps[i];
+
+		if (pdo_type(pdo) == PDO_TYPE_FIXED) {
+			src_mv = pdo_fixed_voltage(pdo);
+			src_ma = pdo_max_current(pdo);
+			tmp = src_mv * src_ma / 1000;
+			max_src_mw = tmp > max_src_mw ? tmp : max_src_mw;
+		}
+	}
+
+	val->intval = max_src_mw;
+	return 0;
+}
+
 static int tcpm_psy_get_prop(struct power_supply *psy,
 			     enum power_supply_property psp,
 			     union power_supply_propval *val)
@@ -6349,6 +6370,9 @@ static int tcpm_psy_get_prop(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 		ret = tcpm_psy_get_current_now(port, val);
 		break;
+	case POWER_SUPPLY_PROP_INPUT_POWER_LIMIT:
+		tcpm_psy_get_input_power_limit(port, val);
+		break;
 	default:
 		ret = -EINVAL;
 		break;
-- 
2.17.1


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

* Re: [PATCH v2 3/3] usb: typec: tcpm: add get max power support
  2023-03-20 10:07 ` [PATCH v2 3/3] usb: typec: tcpm: add get max power support Frank Wang
@ 2023-03-20 20:31   ` Sebastian Reichel
  2023-03-21  1:32     ` Frank Wang
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Reichel @ 2023-03-20 20:31 UTC (permalink / raw)
  To: Frank Wang
  Cc: linux, heikki.krogerus, gregkh, heiko, linux-usb, linux-kernel,
	linux-rockchip, huangtao, william.wu, jianwei.zheng,
	yubing.zhang, wmc

[-- Attachment #1: Type: text/plain, Size: 1895 bytes --]

Hi,

On Mon, Mar 20, 2023 at 06:07:11PM +0800, Frank Wang wrote:
> Traverse fixed pdos to calculate the maximum power that the charger
> can provide, and it can be get by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT
> property.
> 
> Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
> ---
>  drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 13830b5e2d09f..d6ad3cdf9e4af 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -6320,6 +6320,27 @@ static int tcpm_psy_get_current_now(struct tcpm_port *port,
>  	return 0;
>  }
>  
> +static int tcpm_psy_get_input_power_limit(struct tcpm_port *port,
> +					  union power_supply_propval *val)
> +{
> +	unsigned int src_mv, src_ma, max_src_mw = 0;
> +	unsigned int i, tmp;
> +
> +	for (i = 0; i < port->nr_source_caps; i++) {
> +		u32 pdo = port->source_caps[i];
> +
> +		if (pdo_type(pdo) == PDO_TYPE_FIXED) {
> +			src_mv = pdo_fixed_voltage(pdo);
> +			src_ma = pdo_max_current(pdo);
> +			tmp = src_mv * src_ma / 1000;
> +			max_src_mw = tmp > max_src_mw ? tmp : max_src_mw;
> +		}
> +	}
> +
> +	val->intval = max_src_mw;

The power-supply subsystem expects Microwatts and not Milliwatts.

-- Sebastian

> +	return 0;
> +}
> +
>  static int tcpm_psy_get_prop(struct power_supply *psy,
>  			     enum power_supply_property psp,
>  			     union power_supply_propval *val)
> @@ -6349,6 +6370,9 @@ static int tcpm_psy_get_prop(struct power_supply *psy,
>  	case POWER_SUPPLY_PROP_CURRENT_NOW:
>  		ret = tcpm_psy_get_current_now(port, val);
>  		break;
> +	case POWER_SUPPLY_PROP_INPUT_POWER_LIMIT:
> +		tcpm_psy_get_input_power_limit(port, val);
> +		break;
>  	default:
>  		ret = -EINVAL;
>  		break;
> -- 
> 2.17.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 3/3] usb: typec: tcpm: add get max power support
  2023-03-20 20:31   ` Sebastian Reichel
@ 2023-03-21  1:32     ` Frank Wang
  2023-03-21  5:00       ` Sebastian Reichel
  0 siblings, 1 reply; 9+ messages in thread
From: Frank Wang @ 2023-03-21  1:32 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux, heikki.krogerus, gregkh, heiko, linux-usb, linux-kernel,
	linux-rockchip, huangtao, william.wu, jianwei.zheng,
	yubing.zhang, wmc

Hi Sebastian,

On 2023/3/21 4:31, Sebastian Reichel wrote:
> Hi,
>
> On Mon, Mar 20, 2023 at 06:07:11PM +0800, Frank Wang wrote:
>> Traverse fixed pdos to calculate the maximum power that the charger
>> can provide, and it can be get by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT
>> property.
>>
>> Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
>> ---
>>   drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++
>>   1 file changed, 24 insertions(+)
>>
>> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
>> index 13830b5e2d09f..d6ad3cdf9e4af 100644
>> --- a/drivers/usb/typec/tcpm/tcpm.c
>> +++ b/drivers/usb/typec/tcpm/tcpm.c
>> @@ -6320,6 +6320,27 @@ static int tcpm_psy_get_current_now(struct tcpm_port *port,
>>   	return 0;
>>   }
>>   
>> +static int tcpm_psy_get_input_power_limit(struct tcpm_port *port,
>> +					  union power_supply_propval *val)
>> +{
>> +	unsigned int src_mv, src_ma, max_src_mw = 0;
>> +	unsigned int i, tmp;
>> +
>> +	for (i = 0; i < port->nr_source_caps; i++) {
>> +		u32 pdo = port->source_caps[i];
>> +
>> +		if (pdo_type(pdo) == PDO_TYPE_FIXED) {
>> +			src_mv = pdo_fixed_voltage(pdo);
>> +			src_ma = pdo_max_current(pdo);
>> +			tmp = src_mv * src_ma / 1000;
>> +			max_src_mw = tmp > max_src_mw ? tmp : max_src_mw;
>> +		}
>> +	}
>> +
>> +	val->intval = max_src_mw;
> The power-supply subsystem expects Microwatts and not Milliwatts.

Yes, but I see the 'power_supply_propval' member 'intval' is an integer 
type, I worry about it may be overflowed that uses Microwatts.


BR.
Frank

> -- Sebastian
>
>> +	return 0;
>> +}
>> +
>>   static int tcpm_psy_get_prop(struct power_supply *psy,
>>   			     enum power_supply_property psp,
>>   			     union power_supply_propval *val)
>> @@ -6349,6 +6370,9 @@ static int tcpm_psy_get_prop(struct power_supply *psy,
>>   	case POWER_SUPPLY_PROP_CURRENT_NOW:
>>   		ret = tcpm_psy_get_current_now(port, val);
>>   		break;
>> +	case POWER_SUPPLY_PROP_INPUT_POWER_LIMIT:
>> +		tcpm_psy_get_input_power_limit(port, val);
>> +		break;
>>   	default:
>>   		ret = -EINVAL;
>>   		break;
>> -- 
>> 2.17.1
>>


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

* Re: [PATCH v2 3/3] usb: typec: tcpm: add get max power support
  2023-03-21  1:32     ` Frank Wang
@ 2023-03-21  5:00       ` Sebastian Reichel
  2023-03-21  9:54         ` Frank Wang
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Reichel @ 2023-03-21  5:00 UTC (permalink / raw)
  To: Frank Wang
  Cc: linux, heikki.krogerus, gregkh, heiko, linux-usb, linux-kernel,
	linux-rockchip, huangtao, william.wu, jianwei.zheng,
	yubing.zhang, wmc

[-- Attachment #1: Type: text/plain, Size: 2388 bytes --]

Hi,

On Tue, Mar 21, 2023 at 09:32:53AM +0800, Frank Wang wrote:
> On 2023/3/21 4:31, Sebastian Reichel wrote:
> > On Mon, Mar 20, 2023 at 06:07:11PM +0800, Frank Wang wrote:
> > > Traverse fixed pdos to calculate the maximum power that the charger
> > > can provide, and it can be get by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT
> > > property.
> > > 
> > > Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
> > > ---
> > >   drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++
> > >   1 file changed, 24 insertions(+)
> > > 
> > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> > > index 13830b5e2d09f..d6ad3cdf9e4af 100644
> > > --- a/drivers/usb/typec/tcpm/tcpm.c
> > > +++ b/drivers/usb/typec/tcpm/tcpm.c
> > > @@ -6320,6 +6320,27 @@ static int tcpm_psy_get_current_now(struct tcpm_port *port,
> > >   	return 0;
> > >   }
> > > +static int tcpm_psy_get_input_power_limit(struct tcpm_port *port,
> > > +					  union power_supply_propval *val)
> > > +{
> > > +	unsigned int src_mv, src_ma, max_src_mw = 0;
> > > +	unsigned int i, tmp;
> > > +
> > > +	for (i = 0; i < port->nr_source_caps; i++) {
> > > +		u32 pdo = port->source_caps[i];
> > > +
> > > +		if (pdo_type(pdo) == PDO_TYPE_FIXED) {
> > > +			src_mv = pdo_fixed_voltage(pdo);
> > > +			src_ma = pdo_max_current(pdo);
> > > +			tmp = src_mv * src_ma / 1000;
> > > +			max_src_mw = tmp > max_src_mw ? tmp : max_src_mw;
> > > +		}
> > > +	}
> > > +
> > > +	val->intval = max_src_mw;
> > The power-supply subsystem expects Microwatts and not Milliwatts.
> 
> Yes, but I see the 'power_supply_propval' member 'intval' is an integer
> type, I worry about it may be overflowed that uses Microwatts.

Data being encoded in Microwatts is part of the ABI. The data
you are supplying will be interpreted in µW. If you submit your
data in mW it is basically always wrong even without an overflow.

Now regarding the overflow: A signed int can store 2^31 bit, so
2,147,483,648 µW = 2147 W. Looking at your code you effectively
calculate Microwatts in an unsigned int and then divide by 1000.
Since the intermediate value (before dividing by 1000) needs to be
stored you gain only one bit. That raises the question: Why do you
expect data to be between 2147 W and 4294 W when the latest released
USB PD spec allows 5A@48V = 240W?

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 3/3] usb: typec: tcpm: add get max power support
  2023-03-21  5:00       ` Sebastian Reichel
@ 2023-03-21  9:54         ` Frank Wang
  0 siblings, 0 replies; 9+ messages in thread
From: Frank Wang @ 2023-03-21  9:54 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux, heikki.krogerus, gregkh, heiko, linux-usb, linux-kernel,
	linux-rockchip, huangtao, william.wu, jianwei.zheng,
	yubing.zhang, wmc

Hi Sebastian,

On 2023/3/21 13:00, Sebastian Reichel wrote:
> Hi,
>
> On Tue, Mar 21, 2023 at 09:32:53AM +0800, Frank Wang wrote:
>> On 2023/3/21 4:31, Sebastian Reichel wrote:
>>> On Mon, Mar 20, 2023 at 06:07:11PM +0800, Frank Wang wrote:
>>>> Traverse fixed pdos to calculate the maximum power that the charger
>>>> can provide, and it can be get by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT
>>>> property.
>>>>
>>>> Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
>>>> ---
>>>>    drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++
>>>>    1 file changed, 24 insertions(+)
>>>>
>>>> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
>>>> index 13830b5e2d09f..d6ad3cdf9e4af 100644
>>>> --- a/drivers/usb/typec/tcpm/tcpm.c
>>>> +++ b/drivers/usb/typec/tcpm/tcpm.c
>>>> @@ -6320,6 +6320,27 @@ static int tcpm_psy_get_current_now(struct tcpm_port *port,
>>>>    	return 0;
>>>>    }
>>>> +static int tcpm_psy_get_input_power_limit(struct tcpm_port *port,
>>>> +					  union power_supply_propval *val)
>>>> +{
>>>> +	unsigned int src_mv, src_ma, max_src_mw = 0;
>>>> +	unsigned int i, tmp;
>>>> +
>>>> +	for (i = 0; i < port->nr_source_caps; i++) {
>>>> +		u32 pdo = port->source_caps[i];
>>>> +
>>>> +		if (pdo_type(pdo) == PDO_TYPE_FIXED) {
>>>> +			src_mv = pdo_fixed_voltage(pdo);
>>>> +			src_ma = pdo_max_current(pdo);
>>>> +			tmp = src_mv * src_ma / 1000;
>>>> +			max_src_mw = tmp > max_src_mw ? tmp : max_src_mw;
>>>> +		}
>>>> +	}
>>>> +
>>>> +	val->intval = max_src_mw;
>>> The power-supply subsystem expects Microwatts and not Milliwatts.
>> Yes, but I see the 'power_supply_propval' member 'intval' is an integer
>> type, I worry about it may be overflowed that uses Microwatts.
> Data being encoded in Microwatts is part of the ABI. The data
> you are supplying will be interpreted in µW. If you submit your
> data in mW it is basically always wrong even without an overflow.
>
> Now regarding the overflow: A signed int can store 2^31 bit, so
> 2,147,483,648 µW = 2147 W. Looking at your code you effectively
> calculate Microwatts in an unsigned int and then divide by 1000.
> Since the intermediate value (before dividing by 1000) needs to be
> stored you gain only one bit. That raises the question: Why do you
> expect data to be between 2147 W and 4294 W when the latest released
> USB PD spec allows 5A@48V = 240W?
>
> -- Sebastian

Okay, got it, I shall delete conversion codes ( divide by 1000 ) in the 
next version.


BR.
Frank

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

* Re: [PATCH v2 1/3] usb: typec: tcpm: fix cc role at port reset
  2023-03-20 10:07 ` [PATCH v2 1/3] usb: typec: tcpm: fix cc role at port reset Frank Wang
@ 2023-04-25  3:01   ` Frank Wang
  0 siblings, 0 replies; 9+ messages in thread
From: Frank Wang @ 2023-04-25  3:01 UTC (permalink / raw)
  To: linux, heikki.krogerus, gregkh
  Cc: linux-usb, linux-kernel, linux-rockchip, huangtao, william.wu,
	jianwei.zheng, yubing.zhang, wmc, heiko

Hi Guenter and Heikki,

On 2023/3/20 18:07, Frank Wang wrote:
> In the current implementation, the tcpm set CC1/CC2 role to open when
> it do port reset would cause the VBUS removed by the Type-C partner.
>
> This sets CC1/CC2 according to the default state of port to fix it.
>
> Signed-off-by: Frank Wang <frank.wang@rock-chips.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 a0d943d785800..56782dd05e2ec 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -4851,7 +4851,8 @@ static void run_state_machine(struct tcpm_port *port)
>   		break;
>   	case PORT_RESET:
>   		tcpm_reset_port(port);
> -		tcpm_set_cc(port, TYPEC_CC_OPEN);
> +		tcpm_set_cc(port, tcpm_default_state(port) == SNK_UNATTACHED ?
> +			    TYPEC_CC_RD : tcpm_rp_cc(port));
>   		tcpm_set_state(port, PORT_RESET_WAIT_OFF,
>   			       PD_T_ERROR_RECOVERY);
>   		break;

Can you help to review this patch again?

BR.
Frank

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

end of thread, other threads:[~2023-04-25  3:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20 10:07 [PATCH v2 0/3] Fix some defects related Type-C TCPM Frank Wang
2023-03-20 10:07 ` [PATCH v2 1/3] usb: typec: tcpm: fix cc role at port reset Frank Wang
2023-04-25  3:01   ` Frank Wang
2023-03-20 10:07 ` [RESEND PATCH v2 2/3] usb: typec: tcpm: fix multiple times discover svids error Frank Wang
2023-03-20 10:07 ` [PATCH v2 3/3] usb: typec: tcpm: add get max power support Frank Wang
2023-03-20 20:31   ` Sebastian Reichel
2023-03-21  1:32     ` Frank Wang
2023-03-21  5:00       ` Sebastian Reichel
2023-03-21  9:54         ` Frank Wang

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