Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1709236 > unrolled thread
| Started by | Guenter Roeck <linux@roeck-us.net> |
|---|---|
| First post | 2017-08-11 06:20 +0200 |
| Last post | 2017-08-11 06:20 +0200 |
| Articles | 5 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH 1/7] staging: typec: tcpm: Constify alternate modes Guenter Roeck <linux@roeck-us.net> - 2017-08-11 06:20 +0200
[PATCH 5/7] staging: typec: tcpm: Add timeout when waiting for role swap completion Guenter Roeck <linux@roeck-us.net> - 2017-08-11 06:20 +0200
[PATCH 7/7] staging: typec: tcpm: Check cc status before entering SRC_TRY_DEBOUCE Guenter Roeck <linux@roeck-us.net> - 2017-08-11 06:20 +0200
[PATCH 3/7] staging: typec: tcpm: Set default state after error recovery based on port type Guenter Roeck <linux@roeck-us.net> - 2017-08-11 06:20 +0200
[PATCH 4/7] staging: typec: tcpm: Select default state based on port type Guenter Roeck <linux@roeck-us.net> - 2017-08-11 06:20 +0200
| From | Guenter Roeck <linux@roeck-us.net> |
|---|---|
| Date | 2017-08-11 06:20 +0200 |
| Subject | [PATCH 1/7] staging: typec: tcpm: Constify alternate modes |
| Message-ID | <ud9At-782-5@gated-at.bofh.it> |
Constify alternate mode configuration data which won't be touched
by the driver.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
This series has been in my queue and kind of got lost. Sorry for the delay.
drivers/staging/typec/tcpm.c | 2 +-
drivers/staging/typec/tcpm.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index 20eb4ebcf8c3..06c49873df8e 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -3485,7 +3485,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
}
if (tcpc->config->alt_modes) {
- struct typec_altmode_desc *paltmode = tcpc->config->alt_modes;
+ const struct typec_altmode_desc *paltmode = tcpc->config->alt_modes;
i = 0;
while (paltmode->svid && i < ARRAY_SIZE(port->port_altmode)) {
diff --git a/drivers/staging/typec/tcpm.h b/drivers/staging/typec/tcpm.h
index 19c307d31a5a..4c6b38cb2c8a 100644
--- a/drivers/staging/typec/tcpm.h
+++ b/drivers/staging/typec/tcpm.h
@@ -72,7 +72,7 @@ struct tcpc_config {
enum typec_role default_role;
bool try_role_hw; /* try.{src,snk} implemented in hardware */
- struct typec_altmode_desc *alt_modes;
+ const struct typec_altmode_desc *alt_modes;
};
enum tcpc_usb_switch {
--
2.7.4
[toc] | [next] | [standalone]
| From | Guenter Roeck <linux@roeck-us.net> |
|---|---|
| Date | 2017-08-11 06:20 +0200 |
| Subject | [PATCH 5/7] staging: typec: tcpm: Add timeout when waiting for role swap completion |
| Message-ID | <ud9At-782-13@gated-at.bofh.it> |
| In reply to | #1709236 |
The Type-C protocol manager state machine could fail, which might result
in role swap requests from user space to hang forever. Add a generous
timeout when waiting for role swaps to complete to avoid this situation.
Originally-from: Badhri Jagan Sridharan <badhri@google.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/staging/typec/tcpm.c | 21 +++++++++++++++------
drivers/staging/typec/tcpm.h | 3 ++-
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index cf498c68c4af..515bec1807d7 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -3166,9 +3166,12 @@ static int tcpm_dr_set(const struct typec_capability *cap,
tcpm_set_state(port, DR_SWAP_SEND, 0);
mutex_unlock(&port->lock);
- wait_for_completion(&port->swap_complete);
+ if (!wait_for_completion_timeout(&port->swap_complete,
+ msecs_to_jiffies(PD_ROLE_SWAP_TIMEOUT)))
+ ret = -ETIMEDOUT;
+ else
+ ret = port->swap_status;
- ret = port->swap_status;
goto swap_unlock;
port_unlock:
@@ -3223,9 +3226,12 @@ static int tcpm_pr_set(const struct typec_capability *cap,
tcpm_set_state(port, PR_SWAP_SEND, 0);
mutex_unlock(&port->lock);
- wait_for_completion(&port->swap_complete);
+ if (!wait_for_completion_timeout(&port->swap_complete,
+ msecs_to_jiffies(PD_ROLE_SWAP_TIMEOUT)))
+ ret = -ETIMEDOUT;
+ else
+ ret = port->swap_status;
- ret = port->swap_status;
goto swap_unlock;
port_unlock:
@@ -3260,9 +3266,12 @@ static int tcpm_vconn_set(const struct typec_capability *cap,
tcpm_set_state(port, VCONN_SWAP_SEND, 0);
mutex_unlock(&port->lock);
- wait_for_completion(&port->swap_complete);
+ if (!wait_for_completion_timeout(&port->swap_complete,
+ msecs_to_jiffies(PD_ROLE_SWAP_TIMEOUT)))
+ ret = -ETIMEDOUT;
+ else
+ ret = port->swap_status;
- ret = port->swap_status;
goto swap_unlock;
port_unlock:
diff --git a/drivers/staging/typec/tcpm.h b/drivers/staging/typec/tcpm.h
index 4c6b38cb2c8a..374cea44a84a 100644
--- a/drivers/staging/typec/tcpm.h
+++ b/drivers/staging/typec/tcpm.h
@@ -34,7 +34,8 @@ enum typec_cc_polarity {
};
/* Time to wait for TCPC to complete transmit */
-#define PD_T_TCPC_TX_TIMEOUT 100
+#define PD_T_TCPC_TX_TIMEOUT 100 /* in ms */
+#define PD_ROLE_SWAP_TIMEOUT (MSEC_PER_SEC * 10)
enum tcpm_transmit_status {
TCPC_TX_SUCCESS = 0,
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Guenter Roeck <linux@roeck-us.net> |
|---|---|
| Date | 2017-08-11 06:20 +0200 |
| Subject | [PATCH 7/7] staging: typec: tcpm: Check cc status before entering SRC_TRY_DEBOUCE |
| Message-ID | <ud9At-782-15@gated-at.bofh.it> |
| In reply to | #1709236 |
From: Badhri Jagan Sridharan <Badhri@google.com> [ 130.893355] state change SNK_DEBOUNCED -> SRC_TRY [ 130.893363] cc:=3 [ 130.893490] pending state change SRC_TRY -> SNK_TRYWAIT @ 100 ms [ 130.895602] CC1: 3 -> 0, CC2: 0 -> 0 [state SRC_TRY, polarity 0, disconnected] [ 130.895613] state change SRC_TRY -> SRC_TRY_DEBOUNCE [ 130.895621] pending state change SRC_TRY_DEBOUNCE -> SRC_ATTACHED @ 20 ms [ 130.916843] state change SRC_TRY_DEBOUNCE -> SRC_ATTACHED [delayed 20 ms] Although the CC state was changing to TYPEC_CC_OPEN, the port entered SRC_TRY_DEBOUNCE from SRC_TRY. The port must enter SRC_TRY_DEBOUNCE only if the CC state is TYPEC_CC_RD. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> [groeck: Wording] Signed-off-by: Guenter Roeck <linux@roeck-us.net> --- drivers/staging/typec/tcpm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c index e0f71aeb4ed3..e72286464164 100644 --- a/drivers/staging/typec/tcpm.c +++ b/drivers/staging/typec/tcpm.c @@ -2898,7 +2898,8 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, break; case SRC_TRY: - tcpm_set_state(port, SRC_TRY_DEBOUNCE, 0); + if (tcpm_port_is_source(port)) + tcpm_set_state(port, SRC_TRY_DEBOUNCE, 0); break; case SRC_TRY_DEBOUNCE: tcpm_set_state(port, SRC_TRY, 0); -- 2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Guenter Roeck <linux@roeck-us.net> |
|---|---|
| Date | 2017-08-11 06:20 +0200 |
| Subject | [PATCH 3/7] staging: typec: tcpm: Set default state after error recovery based on port type |
| Message-ID | <ud9Au-782-17@gated-at.bofh.it> |
| In reply to | #1709236 |
From: Badhri Jagan Sridharan <Badhri@google.com> While exiting ERROR_RECOVERY, choose default state based on the port type instead of current power role. Quoting from specification: 4.5.2.2.2 ErrorRecovery State This state appears in Figure 4-12, Figure 4-13, Figure 4-14, Figure 4-15, Figure 4-16 and Figure 4-17. The ErrorRecovery state is where the port removes the terminations from the CC1 and CC2 pins for tErrorRecovery followed by transitioning to the appropriate Unattached.SNK or Unattached.SRC state based on port type. This is the equivalent of forcing a detach event and looking for a new attach. Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> --- drivers/staging/typec/tcpm.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c index be2a91b52d69..e7873286b5ea 100644 --- a/drivers/staging/typec/tcpm.c +++ b/drivers/staging/typec/tcpm.c @@ -3038,10 +3038,7 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port) break; case ERROR_RECOVERY_WAIT_OFF: - tcpm_set_state(port, - port->pwr_role == TYPEC_SOURCE ? - SRC_UNATTACHED : SNK_UNATTACHED, - 0); + tcpm_set_state(port, tcpm_default_state(port), 0); break; default: -- 2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Guenter Roeck <linux@roeck-us.net> |
|---|---|
| Date | 2017-08-11 06:20 +0200 |
| Subject | [PATCH 4/7] staging: typec: tcpm: Select default state based on port type |
| Message-ID | <ud9At-782-11@gated-at.bofh.it> |
| In reply to | #1709236 |
From: Badhri Jagan Sridharan <Badhri@google.com>
tcpm_default_state wasn't considering the port type when determining the
default role. This change makes tcpm_default_state to consider port type
as well.
tcpm_default_state would return the following based on the port type:
TYPEC_PORT_UFP - SNK_UNATTACHED
TYPEC_PORT_DFP - SRC_UNATTACHED
TYPEC_PORT_DRP - based on the preferred_role setting
Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
[groeck: Reworded description; minor formatting changes]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/staging/typec/tcpm.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
index e7873286b5ea..cf498c68c4af 100644
--- a/drivers/staging/typec/tcpm.c
+++ b/drivers/staging/typec/tcpm.c
@@ -332,12 +332,17 @@ struct pd_rx_event {
static enum tcpm_state tcpm_default_state(struct tcpm_port *port)
{
- if (port->try_role == TYPEC_SINK)
- return SNK_UNATTACHED;
- else if (port->try_role == TYPEC_SOURCE)
- return SRC_UNATTACHED;
- else if (port->tcpc->config->default_role == TYPEC_SINK)
+ if (port->typec_caps.type == TYPEC_PORT_DRP) {
+ if (port->try_role == TYPEC_SINK)
+ return SNK_UNATTACHED;
+ else if (port->try_role == TYPEC_SOURCE)
+ return SRC_UNATTACHED;
+ 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) {
return SNK_UNATTACHED;
+ }
return SRC_UNATTACHED;
}
--
2.7.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web