public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] staging: usb: typec: tcpm set port type callback
@ 2017-08-27  5:23 Badhri Jagan Sridharan
  2017-08-27 17:20 ` Guenter Roeck
  2017-08-27 18:01 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 5+ messages in thread
From: Badhri Jagan Sridharan @ 2017-08-27  5:23 UTC (permalink / raw)
  To: Guenter Roeck, Greg Kroah-Hartman
  Cc: devel, linux-kernel, Badhri Jagan Sridharan

The port type callback call enquires the tcpc_dev if
the requested port type is supported. If supported, then
performs a tcpm reset if required after setting the tcpm
internal port_type variable.

Check against the tcpm port_type instead of checking
against caps.type as port_type reflects the current
configuration.

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
---
 drivers/staging/typec/tcpm.c | 52 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index a911cad41a59..6c045ac9c42a 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -197,6 +197,7 @@ struct tcpm_port {
 
 	bool attached;
 	bool connected;
+	enum typec_port_type port_type;
 	bool vbus_present;
 	bool vbus_never_low;
 	bool vbus_source;
@@ -334,7 +335,7 @@ struct pd_rx_event {
 
 static enum tcpm_state tcpm_default_state(struct tcpm_port *port)
 {
-	if (port->typec_caps.type == TYPEC_PORT_DRP) {
+	if (port->port_type == TYPEC_PORT_DRP) {
 		if (port->try_role == TYPEC_SINK)
 			return SNK_UNATTACHED;
 		else if (port->try_role == TYPEC_SOURCE)
@@ -342,7 +343,7 @@ static enum tcpm_state tcpm_default_state(struct tcpm_port *port)
 		else if (port->tcpc->config->default_role == TYPEC_SINK)
 			return SNK_UNATTACHED;
 		/* Fall through to return SRC_UNATTACHED */
-	} else if (port->typec_caps.type == TYPEC_PORT_UFP) {
+	} else if (port->port_type == TYPEC_PORT_UFP) {
 		return SNK_UNATTACHED;
 	}
 	return SRC_UNATTACHED;
@@ -1458,7 +1459,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->typec_caps.type != TYPEC_PORT_DRP) {
+		if (port->port_type != TYPEC_PORT_DRP) {
 			tcpm_queue_message(port, PD_MSG_CTRL_REJECT);
 			break;
 		}
@@ -1478,7 +1479,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
 		}
 		break;
 	case PD_CTRL_PR_SWAP:
-		if (port->typec_caps.type != TYPEC_PORT_DRP) {
+		if (port->port_type != TYPEC_PORT_DRP) {
 			tcpm_queue_message(port, PD_MSG_CTRL_REJECT);
 			break;
 		}
@@ -1853,7 +1854,7 @@ static bool tcpm_start_drp_toggling(struct tcpm_port *port)
 	int ret;
 
 	if (port->tcpc->start_drp_toggling &&
-	    port->typec_caps.type == TYPEC_PORT_DRP) {
+	    port->port_type == TYPEC_PORT_DRP) {
 		tcpm_log_force(port, "Start DRP toggling");
 		ret = port->tcpc->start_drp_toggling(port->tcpc,
 						     tcpm_rp_cc(port));
@@ -2163,7 +2164,7 @@ static void run_state_machine(struct tcpm_port *port)
 			break;
 		}
 		tcpm_set_cc(port, tcpm_rp_cc(port));
-		if (port->typec_caps.type == TYPEC_PORT_DRP)
+		if (port->port_type == TYPEC_PORT_DRP)
 			tcpm_set_state(port, SNK_UNATTACHED, PD_T_DRP_SNK);
 		break;
 	case SRC_ATTACH_WAIT:
@@ -2320,7 +2321,7 @@ static void run_state_machine(struct tcpm_port *port)
 			break;
 		}
 		tcpm_set_cc(port, TYPEC_CC_RD);
-		if (port->typec_caps.type == TYPEC_PORT_DRP)
+		if (port->port_type == TYPEC_PORT_DRP)
 			tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC);
 		break;
 	case SNK_ATTACH_WAIT:
@@ -2411,7 +2412,7 @@ static void run_state_machine(struct tcpm_port *port)
 		 * see USB power delivery specification, section 8.3.3.6.1.5.1).
 		 */
 		tcpm_set_state(port, hard_reset_state(port),
-			       port->typec_caps.type == TYPEC_PORT_DRP ?
+			       port->port_type == TYPEC_PORT_DRP ?
 					PD_T_DB_DETECT : PD_T_NO_RESPONSE);
 		break;
 	case SNK_DISCOVERY_DEBOUNCE:
@@ -3167,7 +3168,7 @@ static int tcpm_dr_set(const struct typec_capability *cap,
 	mutex_lock(&port->swap_lock);
 	mutex_lock(&port->lock);
 
-	if (port->typec_caps.type != TYPEC_PORT_DRP) {
+	if (port->port_type != TYPEC_PORT_DRP) {
 		ret = -EINVAL;
 		goto port_unlock;
 	}
@@ -3235,7 +3236,7 @@ static int tcpm_pr_set(const struct typec_capability *cap,
 	mutex_lock(&port->swap_lock);
 	mutex_lock(&port->lock);
 
-	if (port->typec_caps.type != TYPEC_PORT_DRP) {
+	if (port->port_type != TYPEC_PORT_DRP) {
 		ret = -EINVAL;
 		goto port_unlock;
 	}
@@ -3357,6 +3358,34 @@ static void tcpm_init(struct tcpm_port *port)
 	tcpm_set_state(port, PORT_RESET, 0);
 }
 
+static int tcpm_port_type_set(const struct typec_capability *cap,
+			      enum typec_port_type type)
+{
+	struct tcpm_port *port = typec_cap_to_tcpm(cap);
+
+	mutex_lock(&port->lock);
+	if (type == port->port_type)
+		goto port_unlock;
+
+	port->port_type = type;
+
+	if (!port->connected) {
+		tcpm_set_state(port, PORT_RESET, 0);
+	} else if (type == TYPEC_PORT_UFP) {
+		if (!(port->pwr_role == TYPEC_SINK &&
+		      port->data_role == TYPEC_DEVICE))
+			tcpm_set_state(port, PORT_RESET, 0);
+	} else if (type == TYPEC_PORT_DFP) {
+		if (!(port->pwr_role == TYPEC_SOURCE &&
+		      port->data_role == TYPEC_HOST))
+			tcpm_set_state(port, PORT_RESET, 0);
+	}
+
+port_unlock:
+	mutex_unlock(&port->lock);
+	return 0;
+}
+
 void tcpm_tcpc_reset(struct tcpm_port *port)
 {
 	mutex_lock(&port->lock);
@@ -3504,9 +3533,10 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
 	port->typec_caps.pr_set = tcpm_pr_set;
 	port->typec_caps.vconn_set = tcpm_vconn_set;
 	port->typec_caps.try_role = tcpm_try_role;
+	port->typec_caps.port_type_set = tcpm_port_type_set;
 
 	port->partner_desc.identity = &port->partner_ident;
-
+	port->port_type = tcpc->config->type;
 	/*
 	 * TODO:
 	 *  - alt_modes, set_alt_mode
-- 
2.14.1.342.g6490525c54-goog

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

* Re: [PATCH 1/6] staging: usb: typec: tcpm set port type callback
  2017-08-27  5:23 [PATCH 1/6] staging: usb: typec: tcpm set port type callback Badhri Jagan Sridharan
@ 2017-08-27 17:20 ` Guenter Roeck
  2017-08-27 18:01 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2017-08-27 17:20 UTC (permalink / raw)
  To: Badhri Jagan Sridharan; +Cc: Greg Kroah-Hartman, devel, linux-kernel

On Sat, Aug 26, 2017 at 10:23:24PM -0700, Badhri Jagan Sridharan wrote:
> The port type callback call enquires the tcpc_dev if
> the requested port type is supported. If supported, then
> performs a tcpm reset if required after setting the tcpm
> internal port_type variable.
> 
> Check against the tcpm port_type instead of checking
> against caps.type as port_type reflects the current
> configuration.
> 
> Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>

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

> ---
>  drivers/staging/typec/tcpm.c | 52 ++++++++++++++++++++++++++++++++++----------
>  1 file changed, 41 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
> index a911cad41a59..6c045ac9c42a 100644
> --- a/drivers/staging/typec/tcpm.c
> +++ b/drivers/staging/typec/tcpm.c
> @@ -197,6 +197,7 @@ struct tcpm_port {
>  
>  	bool attached;
>  	bool connected;
> +	enum typec_port_type port_type;
>  	bool vbus_present;
>  	bool vbus_never_low;
>  	bool vbus_source;
> @@ -334,7 +335,7 @@ struct pd_rx_event {
>  
>  static enum tcpm_state tcpm_default_state(struct tcpm_port *port)
>  {
> -	if (port->typec_caps.type == TYPEC_PORT_DRP) {
> +	if (port->port_type == TYPEC_PORT_DRP) {
>  		if (port->try_role == TYPEC_SINK)
>  			return SNK_UNATTACHED;
>  		else if (port->try_role == TYPEC_SOURCE)
> @@ -342,7 +343,7 @@ static enum tcpm_state tcpm_default_state(struct tcpm_port *port)
>  		else if (port->tcpc->config->default_role == TYPEC_SINK)
>  			return SNK_UNATTACHED;
>  		/* Fall through to return SRC_UNATTACHED */
> -	} else if (port->typec_caps.type == TYPEC_PORT_UFP) {
> +	} else if (port->port_type == TYPEC_PORT_UFP) {
>  		return SNK_UNATTACHED;
>  	}
>  	return SRC_UNATTACHED;
> @@ -1458,7 +1459,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->typec_caps.type != TYPEC_PORT_DRP) {
> +		if (port->port_type != TYPEC_PORT_DRP) {
>  			tcpm_queue_message(port, PD_MSG_CTRL_REJECT);
>  			break;
>  		}
> @@ -1478,7 +1479,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,
>  		}
>  		break;
>  	case PD_CTRL_PR_SWAP:
> -		if (port->typec_caps.type != TYPEC_PORT_DRP) {
> +		if (port->port_type != TYPEC_PORT_DRP) {
>  			tcpm_queue_message(port, PD_MSG_CTRL_REJECT);
>  			break;
>  		}
> @@ -1853,7 +1854,7 @@ static bool tcpm_start_drp_toggling(struct tcpm_port *port)
>  	int ret;
>  
>  	if (port->tcpc->start_drp_toggling &&
> -	    port->typec_caps.type == TYPEC_PORT_DRP) {
> +	    port->port_type == TYPEC_PORT_DRP) {
>  		tcpm_log_force(port, "Start DRP toggling");
>  		ret = port->tcpc->start_drp_toggling(port->tcpc,
>  						     tcpm_rp_cc(port));
> @@ -2163,7 +2164,7 @@ static void run_state_machine(struct tcpm_port *port)
>  			break;
>  		}
>  		tcpm_set_cc(port, tcpm_rp_cc(port));
> -		if (port->typec_caps.type == TYPEC_PORT_DRP)
> +		if (port->port_type == TYPEC_PORT_DRP)
>  			tcpm_set_state(port, SNK_UNATTACHED, PD_T_DRP_SNK);
>  		break;
>  	case SRC_ATTACH_WAIT:
> @@ -2320,7 +2321,7 @@ static void run_state_machine(struct tcpm_port *port)
>  			break;
>  		}
>  		tcpm_set_cc(port, TYPEC_CC_RD);
> -		if (port->typec_caps.type == TYPEC_PORT_DRP)
> +		if (port->port_type == TYPEC_PORT_DRP)
>  			tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC);
>  		break;
>  	case SNK_ATTACH_WAIT:
> @@ -2411,7 +2412,7 @@ static void run_state_machine(struct tcpm_port *port)
>  		 * see USB power delivery specification, section 8.3.3.6.1.5.1).
>  		 */
>  		tcpm_set_state(port, hard_reset_state(port),
> -			       port->typec_caps.type == TYPEC_PORT_DRP ?
> +			       port->port_type == TYPEC_PORT_DRP ?
>  					PD_T_DB_DETECT : PD_T_NO_RESPONSE);
>  		break;
>  	case SNK_DISCOVERY_DEBOUNCE:
> @@ -3167,7 +3168,7 @@ static int tcpm_dr_set(const struct typec_capability *cap,
>  	mutex_lock(&port->swap_lock);
>  	mutex_lock(&port->lock);
>  
> -	if (port->typec_caps.type != TYPEC_PORT_DRP) {
> +	if (port->port_type != TYPEC_PORT_DRP) {
>  		ret = -EINVAL;
>  		goto port_unlock;
>  	}
> @@ -3235,7 +3236,7 @@ static int tcpm_pr_set(const struct typec_capability *cap,
>  	mutex_lock(&port->swap_lock);
>  	mutex_lock(&port->lock);
>  
> -	if (port->typec_caps.type != TYPEC_PORT_DRP) {
> +	if (port->port_type != TYPEC_PORT_DRP) {
>  		ret = -EINVAL;
>  		goto port_unlock;
>  	}
> @@ -3357,6 +3358,34 @@ static void tcpm_init(struct tcpm_port *port)
>  	tcpm_set_state(port, PORT_RESET, 0);
>  }
>  
> +static int tcpm_port_type_set(const struct typec_capability *cap,
> +			      enum typec_port_type type)
> +{
> +	struct tcpm_port *port = typec_cap_to_tcpm(cap);
> +
> +	mutex_lock(&port->lock);
> +	if (type == port->port_type)
> +		goto port_unlock;
> +
> +	port->port_type = type;
> +
> +	if (!port->connected) {
> +		tcpm_set_state(port, PORT_RESET, 0);
> +	} else if (type == TYPEC_PORT_UFP) {
> +		if (!(port->pwr_role == TYPEC_SINK &&
> +		      port->data_role == TYPEC_DEVICE))
> +			tcpm_set_state(port, PORT_RESET, 0);
> +	} else if (type == TYPEC_PORT_DFP) {
> +		if (!(port->pwr_role == TYPEC_SOURCE &&
> +		      port->data_role == TYPEC_HOST))
> +			tcpm_set_state(port, PORT_RESET, 0);
> +	}
> +
> +port_unlock:
> +	mutex_unlock(&port->lock);
> +	return 0;
> +}
> +
>  void tcpm_tcpc_reset(struct tcpm_port *port)
>  {
>  	mutex_lock(&port->lock);
> @@ -3504,9 +3533,10 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
>  	port->typec_caps.pr_set = tcpm_pr_set;
>  	port->typec_caps.vconn_set = tcpm_vconn_set;
>  	port->typec_caps.try_role = tcpm_try_role;
> +	port->typec_caps.port_type_set = tcpm_port_type_set;
>  
>  	port->partner_desc.identity = &port->partner_ident;
> -
> +	port->port_type = tcpc->config->type;
>  	/*
>  	 * TODO:
>  	 *  - alt_modes, set_alt_mode
> -- 
> 2.14.1.342.g6490525c54-goog
> 

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

* Re: [PATCH 1/6] staging: usb: typec: tcpm set port type callback
  2017-08-27  5:23 [PATCH 1/6] staging: usb: typec: tcpm set port type callback Badhri Jagan Sridharan
  2017-08-27 17:20 ` Guenter Roeck
@ 2017-08-27 18:01 ` Greg Kroah-Hartman
  2017-08-27 18:16   ` Guenter Roeck
  1 sibling, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-27 18:01 UTC (permalink / raw)
  To: Badhri Jagan Sridharan; +Cc: Guenter Roeck, devel, linux-kernel

On Sat, Aug 26, 2017 at 10:23:24PM -0700, Badhri Jagan Sridharan wrote:
> The port type callback call enquires the tcpc_dev if
> the requested port type is supported. If supported, then
> performs a tcpm reset if required after setting the tcpm
> internal port_type variable.
> 
> Check against the tcpm port_type instead of checking
> against caps.type as port_type reflects the current
> configuration.
> 
> Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/staging/typec/tcpm.c | 52 ++++++++++++++++++++++++++++++++++----------
>  1 file changed, 41 insertions(+), 11 deletions(-)

This series is really messed up.  I see patches out of 6 and out of 11,
and none of it "threaded" so I don't know what is what to apply :(

Please resend the whole series, correctly, with Guenter's reviewed-by,
so I know what to apply and in what order.

thanks,

greg k-h

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

* Re: [PATCH 1/6] staging: usb: typec: tcpm set port type callback
  2017-08-27 18:01 ` Greg Kroah-Hartman
@ 2017-08-27 18:16   ` Guenter Roeck
  2017-08-28 16:55     ` Badhri Jagan Sridharan
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2017-08-27 18:16 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Badhri Jagan Sridharan; +Cc: devel, linux-kernel

On 08/27/2017 11:01 AM, Greg Kroah-Hartman wrote:
> On Sat, Aug 26, 2017 at 10:23:24PM -0700, Badhri Jagan Sridharan wrote:
>> The port type callback call enquires the tcpc_dev if
>> the requested port type is supported. If supported, then
>> performs a tcpm reset if required after setting the tcpm
>> internal port_type variable.
>>
>> Check against the tcpm port_type instead of checking
>> against caps.type as port_type reflects the current
>> configuration.
>>
>> Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
>> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>>   drivers/staging/typec/tcpm.c | 52 ++++++++++++++++++++++++++++++++++----------
>>   1 file changed, 41 insertions(+), 11 deletions(-)
> 
> This series is really messed up.  I see patches out of 6 and out of 11,
> and none of it "threaded" so I don't know what is what to apply :(
> 
> Please resend the whole series, correctly, with Guenter's reviewed-by,
> so I know what to apply and in what order.
> 

Agreed, I got confused a bit as well. I think Badhri resent patches 1..6
as part of the 1..11 series and marked those as v2, but he did not mark
patches 7..11 as v2.

Badhri, please mark all patches as v3 and indicate the reason in the
changelog (the reason being to add my Reviewed-by: tag and to fix patch
sequence/version numbers). In general, if you add a patch to a series,
please mark the entire series with the same version and provide a changelog
entry indicating that the patch was added in this version.

Thanks,
Guenter

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

* Re: [PATCH 1/6] staging: usb: typec: tcpm set port type callback
  2017-08-27 18:16   ` Guenter Roeck
@ 2017-08-28 16:55     ` Badhri Jagan Sridharan
  0 siblings, 0 replies; 5+ messages in thread
From: Badhri Jagan Sridharan @ 2017-08-28 16:55 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Greg Kroah-Hartman, devel, LKML

On Sun, Aug 27, 2017 at 11:16 AM, Guenter Roeck <linux@roeck-us.net> wrote:
>
> On 08/27/2017 11:01 AM, Greg Kroah-Hartman wrote:
>>
>> On Sat, Aug 26, 2017 at 10:23:24PM -0700, Badhri Jagan Sridharan wrote:
>>>
>>> The port type callback call enquires the tcpc_dev if
>>> the requested port type is supported. If supported, then
>>> performs a tcpm reset if required after setting the tcpm
>>> internal port_type variable.
>>>
>>> Check against the tcpm port_type instead of checking
>>> against caps.type as port_type reflects the current
>>> configuration.
>>>
>>> Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
>>> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
>>> ---
>>>   drivers/staging/typec/tcpm.c | 52 ++++++++++++++++++++++++++++++++++----------
>>>   1 file changed, 41 insertions(+), 11 deletions(-)
>>
>>
>> This series is really messed up.  I see patches out of 6 and out of 11,
>> and none of it "threaded" so I don't know what is what to apply :(
>>
>> Please resend the whole series, correctly, with Guenter's reviewed-by,
>> so I know what to apply and in what order.
>>
>
> Agreed, I got confused a bit as well. I think Badhri resent patches 1..6
> as part of the 1..11 series and marked those as v2, but he did not mark
> patches 7..11 as v2.
>
> Badhri, please mark all patches as v3 and indicate the reason in the
> changelog (the reason being to add my Reviewed-by: tag and to fix patch
> sequence/version numbers). In general, if you add a patch to a series,
> please mark the entire series with the same version and provide a changelog
> entry indicating that the patch was added in this version.


Apologies for sending a confusing patch stack.
I wasnt aware of the procedure to add new patches to an already sent patchlist.
Thanks for advising on this. Resending the patch series with
Reviewed-by: Guenter Roeck <linux@roeck-us.net>, will change the version
number to v3  and the sequence number as well.
Now that I am aware of this, will follow this in the future as well.

>
>
> Thanks,
> Guenter

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

end of thread, other threads:[~2017-08-28 16:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-27  5:23 [PATCH 1/6] staging: usb: typec: tcpm set port type callback Badhri Jagan Sridharan
2017-08-27 17:20 ` Guenter Roeck
2017-08-27 18:01 ` Greg Kroah-Hartman
2017-08-27 18:16   ` Guenter Roeck
2017-08-28 16:55     ` Badhri Jagan Sridharan

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