diff mbox series

[v3] usb: typec: ucsi: Wait 20ms before reading CCI after a reset

Message ID 20240409-ucsi-reset-delay-v3-1-8440710b012b@chromium.org (mailing list archive)
State Accepted
Commit c4ede56172dc5a9b60d7b7f11a5cf2073b14c14e
Headers show
Series [v3] usb: typec: ucsi: Wait 20ms before reading CCI after a reset | expand

Commit Message

Pavan Holla April 9, 2024, 1:58 a.m. UTC
The PPM might take time to process a reset. Allow 20ms for the reset to
be processed before reading the CCI.

This should not slow down existing implementations because they would
not set any bits in the CCI after a reset, and would take a 20ms delay
to read the CCI anyway. This change makes the delay explicit, and
reduces a CCI read. Based on the spec, the PPM has 10ms to set busy, so,
20ms seems like a reasonable delay before we read the CCI.

Signed-off-by: Pavan Holla <pholla@chromium.org>
Reviewed-by: Prashant Malani <pmalani@chromium.org>
---
The PPM might take time to process a reset and set the CCI. Give the PPM
20ms to update it's CCI.

Commit message now summarizes discussion in v1.
---
Changes in v3:
- Commit message updated.
- Link to v2: https://lore.kernel.org/r/20240403-ucsi-reset-delay-v2-1-244c175825a4@chromium.org

Changes in v2:
- Commit message updated.
- Link to v1: https://lore.kernel.org/r/20240325-ucsi-reset-delay-v1-1-d9e183e0f1e6@chromium.org
---
 drivers/usb/typec/ucsi/ucsi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


---
base-commit: 4cece764965020c22cff7665b18a012006359095
change-id: 20240325-ucsi-reset-delay-bdf6712455fd

Best regards,

Comments

Heikki Krogerus April 9, 2024, 8:11 a.m. UTC | #1
On Tue, Apr 09, 2024 at 01:58:57AM +0000, Pavan Holla wrote:
> The PPM might take time to process a reset. Allow 20ms for the reset to
> be processed before reading the CCI.
> 
> This should not slow down existing implementations because they would
> not set any bits in the CCI after a reset, and would take a 20ms delay
> to read the CCI anyway. This change makes the delay explicit, and
> reduces a CCI read. Based on the spec, the PPM has 10ms to set busy, so,
> 20ms seems like a reasonable delay before we read the CCI.
> 
> Signed-off-by: Pavan Holla <pholla@chromium.org>
> Reviewed-by: Prashant Malani <pmalani@chromium.org>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> The PPM might take time to process a reset and set the CCI. Give the PPM
> 20ms to update it's CCI.
> 
> Commit message now summarizes discussion in v1.
> ---
> Changes in v3:
> - Commit message updated.
> - Link to v2: https://lore.kernel.org/r/20240403-ucsi-reset-delay-v2-1-244c175825a4@chromium.org
> 
> Changes in v2:
> - Commit message updated.
> - Link to v1: https://lore.kernel.org/r/20240325-ucsi-reset-delay-v1-1-d9e183e0f1e6@chromium.org
> ---
>  drivers/usb/typec/ucsi/ucsi.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index cf52cb34d285..c0706c40fa64 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1280,6 +1280,9 @@ static int ucsi_reset_ppm(struct ucsi *ucsi)
>  			goto out;
>  		}
>  
> +		/* Give the PPM time to process a reset before reading CCI */
> +		msleep(20);
> +
>  		ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
>  		if (ret)
>  			goto out;
> @@ -1293,7 +1296,6 @@ static int ucsi_reset_ppm(struct ucsi *ucsi)
>  				goto out;
>  		}
>  
> -		msleep(20);
>  	} while (!(cci & UCSI_CCI_RESET_COMPLETE));
>  
>  out:
> 
> ---
> base-commit: 4cece764965020c22cff7665b18a012006359095
> change-id: 20240325-ucsi-reset-delay-bdf6712455fd
> 
> Best regards,
> -- 
> Pavan Holla <pholla@chromium.org>
diff mbox series

Patch

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index cf52cb34d285..c0706c40fa64 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1280,6 +1280,9 @@  static int ucsi_reset_ppm(struct ucsi *ucsi)
 			goto out;
 		}
 
+		/* Give the PPM time to process a reset before reading CCI */
+		msleep(20);
+
 		ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
 		if (ret)
 			goto out;
@@ -1293,7 +1296,6 @@  static int ucsi_reset_ppm(struct ucsi *ucsi)
 				goto out;
 		}
 
-		msleep(20);
 	} while (!(cci & UCSI_CCI_RESET_COMPLETE));
 
 out: