usb: typec: tcpm: set correct data role for non-DRD
Subsystems (3)
PATCH 2/2 usb: typec: tcpm: set correct data role for non-DRD
From: Li Jun <[email protected]>
Since the typec port data role is separated from power role, so check the port data capability when setting data role.
--- drivers/usb/typec/tcpm/tcpm.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +17 -7
@@ -780,7 +780,7 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached, enum typec_role role, enum typec_data_role data) {enum typec_orientation orientation; -enum usb_role usb_role; +enum usb_role usb_role =USB_ROLE_NONE ;int ret;if (port->polarity ==TYPEC_POLARITY_CC1 )
@@ -788,10 +788,20 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached,else orientation =TYPEC_ORIENTATION_REVERSE ; -if (data ==TYPEC_HOST ) - usb_role =USB_ROLE_HOST ; -else - usb_role =USB_ROLE_DEVICE ; +if (port->typec_caps.data ==TYPEC_PORT_DRD ) { +if (data ==TYPEC_HOST ) + usb_role =USB_ROLE_HOST ; +else + usb_role =USB_ROLE_DEVICE ; + }else if (port->typec_caps.data ==TYPEC_PORT_DFP ) { +if (data ==TYPEC_HOST ) + usb_role =USB_ROLE_HOST ; + data =TYPEC_HOST ; + }else { +if (data ==TYPEC_DEVICE ) + usb_role =USB_ROLE_DEVICE ; + data =TYPEC_DEVICE ; + } ret =tcpm_mux_set (port,TYPEC_STATE_USB , usb_role, orientation);if (ret <0 )
@@ -1817,7 +1827,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,tcpm_set_state (port,SOFT_RESET ,0 );break ;case PD_CTRL_DR_SWAP : -if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->typec_caps.data !=TYPEC_PORT_DRD ) {tcpm_queue_message (port,PD_MSG_CTRL_REJECT );break ; }
@@ -3969,7 +3979,7 @@ static int tcpm_dr_set(struct typec_port *p, enum typec_data_role data)mutex_lock (&port->swap_lock);mutex_lock (&port->lock); -if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->typec_caps.data !=TYPEC_PORT_DRD ) { ret = -EINVAL ; goto port_unlock; }
Signature · 1 line
2.7.4
Heikki Krogerus
maintainerHi Jun,
Where's the 1/2 of this series?
Quoted 30 lines · Jun Li
From: Li Jun <[email protected]>
Since the typec port data role is separated from power role, so check the port data capability when setting data role.
Signed-off-by Li Jun <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)drivers/usb/typec/tcpm/tcpm.c +1
-4@@ -780,7 +780,7 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached, enum typec_role role, enum typec_data_role data) {enum typec_orientation orientation; -enum usb_role usb_role; +enum usb_role usb_role =USB_ROLE_NONE ;int ret;if (port->polarity ==TYPEC_POLARITY_CC1 )@@ -788,10 +788,20 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached,else orientation =TYPEC_ORIENTATION_REVERSE ; -if (data ==TYPEC_HOST ) - usb_role =USB_ROLE_HOST ; -else
drivers/usb/typec/tcpm/tcpm.c static int tcpm_set_roles(struct tcpm_port *port, bool attached, · line 799
Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +9
-1- usb_role =USB_ROLE_DEVICE ; +if (port->typec_caps.data ==TYPEC_PORT_DRD ) { +if (data ==TYPEC_HOST ) + usb_role =USB_ROLE_HOST ; +else + usb_role =USB_ROLE_DEVICE ; + }else if (port->typec_caps.data ==TYPEC_PORT_DFP ) { +if (data ==TYPEC_HOST ) + usb_role =USB_ROLE_HOST ; + data =TYPEC_HOST ;
So if data != host, tcpc is told that data == host, but the mux is set to USB_ROLE_NONE. So why tcpc needs to think the role is host in that case?
Shouldn't this function actually return error if the port is DFP only, and TYPEC_DEVICE is requested?
Quoted 28 lines
drivers/usb/typec/tcpm/tcpm.c +7
-2+ }else { +if (data ==TYPEC_DEVICE ) + usb_role =USB_ROLE_DEVICE ; + data =TYPEC_DEVICE ; + } ret =tcpm_mux_set (port,TYPEC_STATE_USB , usb_role, orientation);if (ret <0 )@@ -1817,7 +1827,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,tcpm_set_state (port,SOFT_RESET ,0 );break ;case PD_CTRL_DR_SWAP : -if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->typec_caps.data !=TYPEC_PORT_DRD ) {tcpm_queue_message (port,PD_MSG_CTRL_REJECT );break ; }@@ -3969,7 +3979,7 @@ static int tcpm_dr_set(struct typec_port *p, enum typec_data_role data)mutex_lock (&port->swap_lock);mutex_lock (&port->lock); -if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->typec_caps.data !=TYPEC_PORT_DRD ) { ret = -EINVAL ; goto port_unlock; }Signature · 1 line
2.7.4
thanks,
Signature · 1 line
heikki
Quoted 10 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: 2020年1月9日 19:52
To: Jun Li <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] usb: typec: tcpm: set correct data role for non-DRD
Quoted 3 lines
Hi Jun,
Where's the 1/2 of this series?
1/2 patch is for controller driver change, so not TO or CC you in mail list. Will pay attention this to avoid confuse.
Quoted 29 lines · Jun Li
drivers/usb/typec/tcpm/tcpm.c static int tcpm_set_roles(struct tcpm_port *port,
Quoted 15 lines
From: Li Jun <[email protected]>
Since the typec port data role is separated from power role, so check the port data capability when setting data role.
Signed-off-by Li Jun <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)(quoted diff) +0
-0
b/drivers/usb/typec/tcpm/tcpm.cindex 56fc356..1f0d82e 100644drivers/usb/typec/tcpm/tcpm.c +0
-0@@ -780,7 +780,7 @@ static int tcpm_set_roles(struct tcpm_port *port,bool attached,
Quoted 11 lines
drivers/usb/typec/tcpm/tcpm.c +1
-1enum typec_role role, enum typec_data_role data) {enum typec_orientation orientation; -enum usb_role usb_role; +enum usb_role usb_role =USB_ROLE_NONE ;int ret; if (port->polarity == TYPEC_POLARITY_CC1) @@ -788,10 +788,20 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached,drivers/usb/typec/tcpm/tcpm.c +0
-0else orientation =TYPEC_ORIENTATION_REVERSE ;
Quoted 16 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_set_roles(struct tcpm_port *port, bool attached, · line 799
Quoted 13 lines
drivers/usb/typec/tcpm/tcpm.c +9
-4-if (data ==TYPEC_HOST ) - usb_role =USB_ROLE_HOST ; -else - usb_role =USB_ROLE_DEVICE ; +if (port->typec_caps.data ==TYPEC_PORT_DRD ) { +if (data ==TYPEC_HOST ) + usb_role =USB_ROLE_HOST ; +else + usb_role =USB_ROLE_DEVICE ; + }else if (port->typec_caps.data ==TYPEC_PORT_DFP ) { +if (data ==TYPEC_HOST ) + usb_role =USB_ROLE_HOST ; + data =TYPEC_HOST ;So if data != host, tcpc is told that data == host, but the mux is set to
USB_ROLE_NONE. So why tcpc needs to think the role is host in that case?
enum usb_role {
USB_ROLE_NONE,
USB_ROLE_HOST,
USB_ROLE_DEVICE,
};
enum typec_data_role {
TYPEC_DEVICE,
TYPEC_HOST,
};
If the port only support DFP(host), I think we should never tell tcpc the data is TYPEC_DEVICE, so TYPEC_HOST.
Quoted 3 lines
Shouldn't this function actually return error if the port is DFP only, and
TYPEC_DEVICEis requested?
Current TCPM use one API to set both power and data role, doesn't consider the case of dual power role but single data role. Return error in tcpm_set_roles() may lose the setting for power role, I think the current change is use correct data role value when call to tcpm_set_roles().
For simple, I didn't change the caller places of tcpm_set_roles(), so just override the data and usb_role to be reasonable value here.
thanks
Jun
Quoted 36 lines
drivers/usb/typec/tcpm/tcpm.c static void tcpm_pd_ctrl_request(struct
Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +5
-0+ }else { +if (data ==TYPEC_DEVICE ) + usb_role =USB_ROLE_DEVICE ; + data =TYPEC_DEVICE ; + } ret =tcpm_mux_set (port,TYPEC_STATE_USB , usb_role, orientation);if (ret <0 )@@ -1817,7 +1827,7 @@ static void tcpm_pd_ctrl_request(struct
tcpm_port*port,drivers/usb/typec/tcpm/tcpm.c static int tcpm_dr_set(struct typec_port *p,
Quoted 9 lines
drivers/usb/typec/tcpm/tcpm.c +1
-1tcpm_set_state (port,SOFT_RESET ,0 );break ;case PD_CTRL_DR_SWAP : -if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->typec_caps.data !=TYPEC_PORT_DRD ) {tcpm_queue_message (port,PD_MSG_CTRL_REJECT );break ; }@@ -3969,7 +3979,7 @@ static int tcpm_dr_set(struct typec_port *p,enum
typec_data_roledata)Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +1
-2mutex_lock (&port->swap_lock);mutex_lock (&port->lock); -if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->typec_caps.data !=TYPEC_PORT_DRD ) { ret = -EINVAL ; goto port_unlock; } --2.7.4
thanks,
--
heikki
Heikki Krogerus
maintainerHi Jun,
Quoted 67 lines · Jun Li
Quoted 11 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: 2020年1月9日 19:52
To: Jun Li <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] usb: typec: tcpm: set correct data role for non-DRDHi Jun,
Where's the 1/2 of this series?
1/2 patch is for controller driver change, so not TO or CC you in mail list. Will pay attention this to avoid confuse.
Quoted 29 lines · Jun Li
drivers/usb/typec/tcpm/tcpm.c static int tcpm_set_roles(struct tcpm_port *port,
Quoted 15 lines
From: Li Jun <[email protected]>
Since the typec port data role is separated from power role, so check the port data capability when setting data role.
Signed-off-by Li Jun <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)(quoted diff) +0
-0
b/drivers/usb/typec/tcpm/tcpm.cindex 56fc356..1f0d82e 100644drivers/usb/typec/tcpm/tcpm.c +0
-0@@ -780,7 +780,7 @@ static int tcpm_set_roles(struct tcpm_port *port,bool attached,
Quoted 11 lines
drivers/usb/typec/tcpm/tcpm.c +1
-1enum typec_role role, enum typec_data_role data) {enum typec_orientation orientation; -enum usb_role usb_role; +enum usb_role usb_role =USB_ROLE_NONE ;int ret; if (port->polarity == TYPEC_POLARITY_CC1) @@ -788,10 +788,20 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached,drivers/usb/typec/tcpm/tcpm.c +0
-0else orientation =TYPEC_ORIENTATION_REVERSE ;Quoted 16 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_set_roles(struct tcpm_port *port, bool attached, · line 799
Quoted 13 lines
drivers/usb/typec/tcpm/tcpm.c +9
-4-if (data ==TYPEC_HOST ) - usb_role =USB_ROLE_HOST ; -else - usb_role =USB_ROLE_DEVICE ; +if (port->typec_caps.data ==TYPEC_PORT_DRD ) { +if (data ==TYPEC_HOST ) + usb_role =USB_ROLE_HOST ; +else + usb_role =USB_ROLE_DEVICE ; + }else if (port->typec_caps.data ==TYPEC_PORT_DFP ) { +if (data ==TYPEC_HOST ) + usb_role =USB_ROLE_HOST ; + data =TYPEC_HOST ;So if data != host, tcpc is told that data == host, but the mux is set to
USB_ROLE_NONE. So why tcpc needs to think the role is host in that case?enum
usb_role{
USB_ROLE_NONE,
USB_ROLE_HOST,
USB_ROLE_DEVICE,
};
Quoted 7 lines
enum
typec_data_role{
TYPEC_DEVICE,
TYPEC_HOST,
};If the port only support DFP(host), I think we should never tell tcpc the data is
TYPEC_DEVICE, soTYPEC_HOST.
But we should also not have to "lie" and force the role into something that works.
Quoted 9 lines
Quoted 2 lines
Shouldn't this function actually return error if the port is DFP only, and
TYPEC_DEVICEis requested?Current TCPM use one API to set both power and data role, doesn't consider the case of dual power role but single data role. Return error in
tcpm_set_roles()may lose the setting for power role, I think the current change is use correct data role value when call totcpm_set_roles().
For simple, I didn't change the caller places oftcpm_set_roles(), so just override the data andusb_roleto be reasonable value here.
I think the correct thing to do would be to fix the places where the function is called, and here return error if the unsupported role is attempted. I hate to be picky, but this looks like a workaround that may potentially hide real issues in the code.
Quoted 23 lines
Quoted 23 lines
drivers/usb/typec/tcpm/tcpm.c static void tcpm_pd_ctrl_request(struct
Quoted 9 lines
drivers/usb/typec/tcpm/tcpm.c +5
-0+ }else { +if (data ==TYPEC_DEVICE ) + usb_role =USB_ROLE_DEVICE ; + data =TYPEC_DEVICE ; + } ret =tcpm_mux_set (port,TYPEC_STATE_USB , usb_role, orientation);if (ret <0 )@@ -1817,7 +1827,7 @@ static void tcpm_pd_ctrl_request(struct
tcpm_port*port,drivers/usb/typec/tcpm/tcpm.c static int tcpm_dr_set(struct typec_port *p,
Quoted 9 lines
drivers/usb/typec/tcpm/tcpm.c +1
-1tcpm_set_state (port,SOFT_RESET ,0 );break ;case PD_CTRL_DR_SWAP : -if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->typec_caps.data !=TYPEC_PORT_DRD ) {tcpm_queue_message (port,PD_MSG_CTRL_REJECT );break ; }@@ -3969,7 +3979,7 @@ static int tcpm_dr_set(struct typec_port *p,enum
typec_data_roledata)Quoted 3 lines
drivers/usb/typec/tcpm/tcpm.c +0
-0mutex_lock (&port->swap_lock);mutex_lock (&port->lock);
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +1
-2-if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->typec_caps.data !=TYPEC_PORT_DRD ) { ret = -EINVAL ; goto port_unlock; } --2.7.4
thanks,
Signature · 1 line
heikki
Hi Heikki,
Quoted 100 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: 2020年1月20日 21:51
To: Jun Li <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] usb: typec: tcpm: set correct data role for non-DRDHi Jun,
Quoted 35 lines · Jun Li
Quoted 9 lines
-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: 2020年1月9日 19:52
To: Jun Li <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] usb: typec: tcpm: set correct data role for non-DRDQuoted 3 lines
Hi Jun,
Where's the 1/2 of this series?
1/2 patch is for controller driver change, so not TO or CC you in mail list. Will pay attention this to avoid confuse.
Quoted 19 lines · Jun Li
Quoted 15 lines
From: Li Jun <[email protected]>
Since the typec port data role is separated from power role, so check the port data capability when setting data role.
Signed-off-by Li Jun <[email protected]>--- drivers/usb/typec/tcpm/tcpm.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)(quoted diff) +0
-0
b/drivers/usb/typec/tcpm/tcpm.cindex 56fc356..1f0d82e 100644drivers/usb/typec/tcpm/tcpm.c static int tcpm_set_roles(struct tcpm_port · line 780
Quoted 1 line
drivers/usb/typec/tcpm/tcpm.c +0
-0@@ -780,7 +780,7 @@ static int tcpm_set_roles(struct tcpm_port *port,bool attached,
Quoted 7 lines
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_set_roles(struct tcpm_port *port, bool attached,
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +1
-1enum typec_role role, enum typec_data_role data) {enum typec_orientation orientation; -enum usb_role usb_role; +enum usb_role usb_role =USB_ROLE_NONE ;int ret; if (port->polarity == TYPEC_POLARITY_CC1) @@ -788,10 +788,20@@
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
static int tcpm_set_roles(struct
tcpm_port*port, bool attached,drivers/usb/typec/tcpm/tcpm.c +0
-0else orientation =TYPEC_ORIENTATION_REVERSE ;Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
drivers/usb/typec/tcpm/tcpm.c +4
-4-if (data ==TYPEC_HOST ) - usb_role =USB_ROLE_HOST ; -else - usb_role =USB_ROLE_DEVICE ; +if (port->typec_caps.data ==TYPEC_PORT_DRD ) { +if (data ==TYPEC_HOST ) + usb_role =USB_ROLE_HOST ; +else Quoted 8 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_set_roles(struct tcpm_port *port, bool attached, · line 799
Quoted 5 lines
drivers/usb/typec/tcpm/tcpm.c +5
-0+ usb_role =USB_ROLE_DEVICE ; + }else if (port->typec_caps.data ==TYPEC_PORT_DFP ) { +if (data ==TYPEC_HOST ) + usb_role =USB_ROLE_HOST ; + data =TYPEC_HOST ;So if data != host, tcpc is told that data == host, but the mux is set to
USB_ROLE_NONE. So why tcpc needs to think the role is host inthat case?
Quoted 7 lines
enum
usb_role{
USB_ROLE_NONE,
USB_ROLE_HOST,
USB_ROLE_DEVICE,
};Quoted 7 lines
enum
typec_data_role{
TYPEC_DEVICE,
TYPEC_HOST,
};If the port only support DFP(host), I think we should never tell tcpc the data is
TYPEC_DEVICE, soTYPEC_HOST.But we should also not have to "lie" and force the role into something that works.
Quoted 7 lines
Quoted 2 lines
Shouldn't this function actually return error if the port is DFP only, and
TYPEC_DEVICEis requested?Current TCPM use one API to set both power and data role, doesn't consider the case of dual power role but single data role. Return error in
tcpm_set_roles()may lose the setting for power role, I think the current change is use correct data role value when call to
Quoted 8 lines
tcpm_set_roles().Quoted 2 lines
For simple, I didn't change the caller places of
tcpm_set_roles(), so just override the data andusb_roleto be reasonable value here.I think the correct thing to do would be to fix the places where the function is called, and here return error if the unsupported role is attempted. I hate to be picky, but this looks like a workaround that may potentially hide real issues in the code.
OK, understood, I will send v2.
Thanks
Li Jun
Quoted 38 lines
Quoted 9 lines
Quoted 9 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_set_roles(struct tcpm_port *port, bool attached,
Quoted 9 lines
drivers/usb/typec/tcpm/tcpm.c +5
-0+ }else { +if (data ==TYPEC_DEVICE ) + usb_role =USB_ROLE_DEVICE ; + data =TYPEC_DEVICE ; + } ret = tcpm_mux_set(port, TYPEC_STATE_USB, usb_role,orientation);
Quoted 16 lines
Quoted 16 lines
drivers/usb/typec/tcpm/tcpm.c static void tcpm_pd_ctrl_request(struct
Quoted 2 lines
drivers/usb/typec/tcpm/tcpm.c +0
-0if (ret <0 )@@ -1817,7 +1827,7 @@ static void tcpm_pd_ctrl_request(struct
tcpm_port*port,drivers/usb/typec/tcpm/tcpm.c static int tcpm_dr_set(struct typec_port *p,
Quoted 9 lines
drivers/usb/typec/tcpm/tcpm.c +1
-1tcpm_set_state (port,SOFT_RESET ,0 );break ;case PD_CTRL_DR_SWAP : -if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->typec_caps.data !=TYPEC_PORT_DRD ) {tcpm_queue_message (port,PD_MSG_CTRL_REJECT );break ; }@@ -3969,7 +3979,7 @@ static int tcpm_dr_set(struct typec_port *p,enum
typec_data_roledata)Quoted 3 lines
drivers/usb/typec/tcpm/tcpm.c +0
-0mutex_lock (&port->swap_lock);mutex_lock (&port->lock);Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +1
-2-if (port->port_type !=TYPEC_PORT_DRP ) { +if (port->typec_caps.data !=TYPEC_PORT_DRD ) { ret = -EINVAL ; goto port_unlock; } --2.7.4
thanks,
--
heikki