diff mbox

[v6,12/15] usb: typec: tcpm: set cc for drp toggling attach

Message ID 1527475967-15201-13-git-send-email-jun.li@nxp.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jun Li May 28, 2018, 2:52 a.m. UTC
In case of drp toggling, we may need set correct cc value for role control
after attach as it may never been set.

Signed-off-by: Li Jun <jun.li@nxp.com>
---
 drivers/usb/typec/tcpm.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Heikki Krogerus June 11, 2018, 12:29 p.m. UTC | #1
On Mon, May 28, 2018 at 10:52:44AM +0800, Li Jun wrote:
> In case of drp toggling, we may need set correct cc value for role control
> after attach as it may never been set.

Is this something that should be considered as a fix?

> Signed-off-by: Li Jun <jun.li@nxp.com>
> ---
>  drivers/usb/typec/tcpm.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
> index d885bff..98ea916 100644
> --- a/drivers/usb/typec/tcpm.c
> +++ b/drivers/usb/typec/tcpm.c
> @@ -2599,6 +2599,7 @@ static void tcpm_reset_port(struct tcpm_port *port)
>  	tcpm_set_attached_state(port, false);
>  	port->try_src_count = 0;
>  	port->try_snk_count = 0;
> +	port->cc_req = TYPEC_CC_OPEN;
>  	port->supply_voltage = 0;
>  	port->current_limit = 0;
>  	port->usb_type = POWER_SUPPLY_USB_TYPE_C;
> @@ -2831,6 +2832,8 @@ static void run_state_machine(struct tcpm_port *port)
>  		break;
>  
>  	case SRC_ATTACHED:
> +		if (port->cc_req == TYPEC_CC_OPEN)
> +			tcpm_set_cc(port, tcpm_rp_cc(port));
>  		ret = tcpm_src_attach(port);
>  		tcpm_set_state(port, SRC_UNATTACHED,
>  			       ret < 0 ? 0 : PD_T_PS_SOURCE_ON);
> @@ -3004,6 +3007,8 @@ static void run_state_machine(struct tcpm_port *port)
>  		tcpm_set_state(port, SNK_UNATTACHED, PD_T_PD_DEBOUNCE);
>  		break;
>  	case SNK_ATTACHED:
> +		if (port->cc_req == TYPEC_CC_OPEN)
> +			tcpm_set_cc(port, TYPEC_CC_RD);
>  		ret = tcpm_snk_attach(port);
>  		if (ret < 0)
>  			tcpm_set_state(port, SNK_UNATTACHED, 0);
Guenter Roeck June 11, 2018, 1:35 p.m. UTC | #2
On 06/11/2018 05:29 AM, Heikki Krogerus wrote:
> On Mon, May 28, 2018 at 10:52:44AM +0800, Li Jun wrote:
>> In case of drp toggling, we may need set correct cc value for role control
>> after attach as it may never been set.
> 
> Is this something that should be considered as a fix?
> 

The problem with this patch is that it hides a problem. CC should have been set
by the time a port reaches the attached state. The patch means that there is
a state machine path where this does not happen. I'd rather understand that
path and fix the problem where it happens.

Guenter

>> Signed-off-by: Li Jun <jun.li@nxp.com>
>> ---
>>   drivers/usb/typec/tcpm.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
>> index d885bff..98ea916 100644
>> --- a/drivers/usb/typec/tcpm.c
>> +++ b/drivers/usb/typec/tcpm.c
>> @@ -2599,6 +2599,7 @@ static void tcpm_reset_port(struct tcpm_port *port)
>>   	tcpm_set_attached_state(port, false);
>>   	port->try_src_count = 0;
>>   	port->try_snk_count = 0;
>> +	port->cc_req = TYPEC_CC_OPEN;
>>   	port->supply_voltage = 0;
>>   	port->current_limit = 0;
>>   	port->usb_type = POWER_SUPPLY_USB_TYPE_C;
>> @@ -2831,6 +2832,8 @@ static void run_state_machine(struct tcpm_port *port)
>>   		break;
>>   
>>   	case SRC_ATTACHED:
>> +		if (port->cc_req == TYPEC_CC_OPEN)
>> +			tcpm_set_cc(port, tcpm_rp_cc(port));
>>   		ret = tcpm_src_attach(port);
>>   		tcpm_set_state(port, SRC_UNATTACHED,
>>   			       ret < 0 ? 0 : PD_T_PS_SOURCE_ON);
>> @@ -3004,6 +3007,8 @@ static void run_state_machine(struct tcpm_port *port)
>>   		tcpm_set_state(port, SNK_UNATTACHED, PD_T_PD_DEBOUNCE);
>>   		break;
>>   	case SNK_ATTACHED:
>> +		if (port->cc_req == TYPEC_CC_OPEN)
>> +			tcpm_set_cc(port, TYPEC_CC_RD);
>>   		ret = tcpm_snk_attach(port);
>>   		if (ret < 0)
>>   			tcpm_set_state(port, SNK_UNATTACHED, 0);
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jun Li June 13, 2018, 11:06 a.m. UTC | #3
SGksDQo+IC0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tDQo+IEZyb206IEd1ZW50ZXIgUm9lY2sg
W21haWx0bzpncm9lY2s3QGdtYWlsLmNvbV0gT24gQmVoYWxmIE9mIEd1ZW50ZXIgUm9lY2sNCj4g
U2VudDogMjAxOOW5tDbmnIgxMeaXpSAyMTozNQ0KPiBUbzogSGVpa2tpIEtyb2dlcnVzIDxoZWlr
a2kua3JvZ2VydXNAbGludXguaW50ZWwuY29tPjsgSnVuIExpIDxqdW4ubGlAbnhwLmNvbT4NCj4g
Q2M6IHJvYmgrZHRAa2VybmVsLm9yZzsgZ3JlZ2toQGxpbnV4Zm91bmRhdGlvbi5vcmc7IGN3MDAu
Y2hvaUBzYW1zdW5nLmNvbTsNCj4gYS5oYWpkYUBzYW1zdW5nLmNvbTsgc2h1ZmFuX2xlZUByaWNo
dGVrLmNvbTsgUGV0ZXIgQ2hlbg0KPiA8cGV0ZXIuY2hlbkBueHAuY29tPjsgZ2Fyc2lsdmFAZW1i
ZWRkZWRvci5jb207IGdzb21sb0BnbWFpbC5jb207DQo+IGxpbnV4LXVzYkB2Z2VyLmtlcm5lbC5v
cmc7IGRldmljZXRyZWVAdmdlci5rZXJuZWwub3JnOyBkbC1saW51eC1pbXgNCj4gPGxpbnV4LWlt
eEBueHAuY29tPg0KPiBTdWJqZWN0OiBSZTogW1BBVENIIHY2IDEyLzE1XSB1c2I6IHR5cGVjOiB0
Y3BtOiBzZXQgY2MgZm9yIG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ZXRfc3RhdGUocG9ydCwgU05LX1VOQVRUQUNIRUQsDQo+IFBEX1RfUERfREVCT1VO
Q0UpOw0KPiA+PiAgIAkJYnJlYWs7DQo+ID4+ICAgCWNhc2UgU05LX0FUVEFDSEVEOg0KPiA+PiAr
CQlpZiAocG9ydC0+Y2NfcmVxID09IFRZUEVDX0NDX09QRU4pDQo+ID4+ICsJCQl0Y3BtX3NldF9j
Yyhwb3J0LCBUWVBFQ19DQ19SRCk7DQo+ID4+ICAgCQlyZXQgPSB0Y3BtX3Nua19hdHRhY2gocG9y
dCk7DQo+ID4+ICAgCQlpZiAocmV0IDwgMCkNCj4gPj4gICAJCQl0Y3BtX3NldF9zdGF0ZShwb3J0
LCBTTktfVU5BVFRBQ0hFRCwgMCk7DQo+ID4NCg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jun Li June 13, 2018, 11:14 a.m. UTC | #4
Hi
> -----Original Message-----

> From: Jun Li

> Sent: 2018年6月13日 19:07

> To: Guenter Roeck <linux@roeck-us.net>; Heikki Krogerus

> <heikki.krogerus@linux.intel.com>; shufan_lee@richtek.com

> Cc: robh+dt@kernel.org; gregkh@linuxfoundation.org; cw00.choi@samsung.com;

> a.hajda@samsung.com; Peter Chen <peter.chen@nxp.com>;

> garsilva@embeddedor.com; gsomlo@gmail.com; linux-usb@vger.kernel.org;

> devicetree@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>

> Subject: RE: [PATCH v6 12/15] usb: typec: tcpm: set cc for drp toggling attach

> 

> Hi,

> > -----Original Message-----

> > From: Guenter Roeck [mailto:groeck7@gmail.com] On Behalf Of Guenter

> > Roeck

> > Sent: 2018年6月11日 21:35

> > To: Heikki Krogerus <heikki.krogerus@linux.intel.com>; Jun Li

> > <jun.li@nxp.com>

> > Cc: robh+dt@kernel.org; gregkh@linuxfoundation.org;

> > cw00.choi@samsung.com; a.hajda@samsung.com; shufan_lee@richtek.com;

> > Peter Chen <peter.chen@nxp.com>; garsilva@embeddedor.com;

> > gsomlo@gmail.com; linux-usb@vger.kernel.org;

> > devicetree@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>

> > Subject: Re: [PATCH v6 12/15] usb: typec: tcpm: set cc for drp

> > toggling attach

> >

> > On 06/11/2018 05:29 AM, Heikki Krogerus wrote:

> > > On Mon, May 28, 2018 at 10:52:44AM +0800, Li Jun wrote:

> > >> In case of drp toggling, we may need set correct cc value for role

> > >> control after attach as it may never been set.

> > >

> > > Is this something that should be considered as a fix?

> > >

> >

> > The problem with this patch is that it hides a problem. CC should have

> > been set by the time a port reaches the attached state. The patch

> > means that there is a state machine path where this does not happen.

> > I'd rather understand that path and fix the problem where it happens.

> 

> Here is my previous explanation about this state machine path[1]

> 

> [1]https://www.spinics.net/lists/linux-usb/msg167467.html

> 

> The physical CC line state is correct, just the Role Control register value may

> mismatch on some(e.g. shufan's) HW, if the common change in tcpm is not the

> right way, I have to ask shufan to try resolve this in his custom rt1711h driver.

> 

> I understand the concern of setting cc at attached state is late, should be done

> before that, how about I move this in cc_change like below:

> 

> @@ -3492,10 +3492,13 @@ static void _tcpm_cc_change(struct tcpm_port *port,

> enum typec_cc_status cc1,

>         switch (port->state) {

>         case DRP_TOGGLING:

>                 if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) ||

> -                   tcpm_port_is_source(port))

> +                   tcpm_port_is_source(port)) {

> +                       tcpm_set_cc(port, tcpm_rp_cc(port));

>                         tcpm_set_state(port, SRC_ATTACH_WAIT, 0);

> -               else if (tcpm_port_is_sink(port))

> +               } else if (tcpm_port_is_sink(port)) {

> +                       if (port->cc_req == TYPEC_CC_OPEN)


Sorry, here should be:

+               } else if (tcpm_port_is_sink(port)) {
+                       tcpm_set_cc(port, TYPEC_CC_RD);
                        tcpm_set_state(port, SNK_ATTACH_WAIT, 0);
+               }
>                         tcpm_set_state(port, SNK_ATTACH_WAIT, 0);

> +               }

>                 break;

>         case SRC_UNATTACHED:

>         case ACC_UNATTACHED:

> 

> thanks

> Li Jun

> 

> >

> > Guenter

> >

> > >> Signed-off-by: Li Jun <jun.li@nxp.com>

> > >> ---

> > >>   drivers/usb/typec/tcpm.c | 5 +++++

> > >>   1 file changed, 5 insertions(+)

> > >>

> > >> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c

> > >> index d885bff..98ea916 100644

> > >> --- a/drivers/usb/typec/tcpm.c

> > >> +++ b/drivers/usb/typec/tcpm.c

> > >> @@ -2599,6 +2599,7 @@ static void tcpm_reset_port(struct tcpm_port

> *port)

> > >>   	tcpm_set_attached_state(port, false);

> > >>   	port->try_src_count = 0;

> > >>   	port->try_snk_count = 0;

> > >> +	port->cc_req = TYPEC_CC_OPEN;

> > >>   	port->supply_voltage = 0;

> > >>   	port->current_limit = 0;

> > >>   	port->usb_type = POWER_SUPPLY_USB_TYPE_C; @@ -2831,6 +2832,8

> > @@

> > >> static void run_state_machine(struct tcpm_port *port)

> > >>   		break;

> > >>

> > >>   	case SRC_ATTACHED:

> > >> +		if (port->cc_req == TYPEC_CC_OPEN)

> > >> +			tcpm_set_cc(port, tcpm_rp_cc(port));

> > >>   		ret = tcpm_src_attach(port);

> > >>   		tcpm_set_state(port, SRC_UNATTACHED,

> > >>   			       ret < 0 ? 0 : PD_T_PS_SOURCE_ON); @@ -3004,6

> > +3007,8 @@

> > >> static void run_state_machine(struct tcpm_port *port)

> > >>   		tcpm_set_state(port, SNK_UNATTACHED,

> > PD_T_PD_DEBOUNCE);

> > >>   		break;

> > >>   	case SNK_ATTACHED:

> > >> +		if (port->cc_req == TYPEC_CC_OPEN)

> > >> +			tcpm_set_cc(port, TYPEC_CC_RD);

> > >>   		ret = tcpm_snk_attach(port);

> > >>   		if (ret < 0)

> > >>   			tcpm_set_state(port, SNK_UNATTACHED, 0);

> > >
diff mbox

Patch

diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
index d885bff..98ea916 100644
--- a/drivers/usb/typec/tcpm.c
+++ b/drivers/usb/typec/tcpm.c
@@ -2599,6 +2599,7 @@  static void tcpm_reset_port(struct tcpm_port *port)
 	tcpm_set_attached_state(port, false);
 	port->try_src_count = 0;
 	port->try_snk_count = 0;
+	port->cc_req = TYPEC_CC_OPEN;
 	port->supply_voltage = 0;
 	port->current_limit = 0;
 	port->usb_type = POWER_SUPPLY_USB_TYPE_C;
@@ -2831,6 +2832,8 @@  static void run_state_machine(struct tcpm_port *port)
 		break;
 
 	case SRC_ATTACHED:
+		if (port->cc_req == TYPEC_CC_OPEN)
+			tcpm_set_cc(port, tcpm_rp_cc(port));
 		ret = tcpm_src_attach(port);
 		tcpm_set_state(port, SRC_UNATTACHED,
 			       ret < 0 ? 0 : PD_T_PS_SOURCE_ON);
@@ -3004,6 +3007,8 @@  static void run_state_machine(struct tcpm_port *port)
 		tcpm_set_state(port, SNK_UNATTACHED, PD_T_PD_DEBOUNCE);
 		break;
 	case SNK_ATTACHED:
+		if (port->cc_req == TYPEC_CC_OPEN)
+			tcpm_set_cc(port, TYPEC_CC_RD);
 		ret = tcpm_snk_attach(port);
 		if (ret < 0)
 			tcpm_set_state(port, SNK_UNATTACHED, 0);