diff mbox series

[v5,02/15] USB: typec: Add cmd timeout and response delay

Message ID 20230917152639.21443-3-alkuor@gmail.com (mailing list archive)
State Superseded
Headers show
Series Add TPS25750 USB type-C PD controller support | expand

Commit Message

Abdel Alkuor Sept. 17, 2023, 3:26 p.m. UTC
Some commands in tps25750 take longer than 1 second
to complete, and some responses need some delay before
the result becomes available.

Signed-off-by: Abdel Alkuor <alkuor@gmail.com>
---
 drivers/usb/typec/tipd/core.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

Heikki Krogerus Sept. 18, 2023, 10:44 a.m. UTC | #1
On Sun, Sep 17, 2023 at 11:26:26AM -0400, Abdel Alkuor wrote:
> Some commands in tps25750 take longer than 1 second
> to complete, and some responses need some delay before
> the result becomes available.
> 
> Signed-off-by: Abdel Alkuor <alkuor@gmail.com>
> ---
>  drivers/usb/typec/tipd/core.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 37b56ce75f39..a8aee4e1aeba 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -284,7 +284,8 @@ static void tps6598x_disconnect(struct tps6598x *tps, u32 status)
>  
>  static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd,
>  			     size_t in_len, u8 *in_data,
> -			     size_t out_len, u8 *out_data)
> +			     size_t out_len, u8 *out_data,
> +			     u32 cmd_timeout_ms, u32 res_delay_ms)

It looks like 1s/0s is still the "default", so you could have just
made this old function a wrapper:

static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd,
			     size_t in_len, u8 *in_data,
			     size_t out_len, u8 *out_data)
{
        return tps6598x_exec_cmd_tmo(tps, cmd, in_len, in_data, out_len, out_data, 1000, 0);
}

thanks,
Abdel Alkuor Sept. 20, 2023, 2:29 p.m. UTC | #2
On Mon, Sep 18, 2023 at 01:44:48PM +0300, Heikki Krogerus wrote:
> On Sun, Sep 17, 2023 at 11:26:26AM -0400, Abdel Alkuor wrote:
> > Some commands in tps25750 take longer than 1 second
> > to complete, and some responses need some delay before
> > the result becomes available.
> > 
> > Signed-off-by: Abdel Alkuor <alkuor@gmail.com>
> > ---
> >  drivers/usb/typec/tipd/core.c | 18 ++++++++++++------
> >  1 file changed, 12 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> > index 37b56ce75f39..a8aee4e1aeba 100644
> > --- a/drivers/usb/typec/tipd/core.c
> > +++ b/drivers/usb/typec/tipd/core.c
> > @@ -284,7 +284,8 @@ static void tps6598x_disconnect(struct tps6598x *tps, u32 status)
> >  
> >  static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd,
> >  			     size_t in_len, u8 *in_data,
> > -			     size_t out_len, u8 *out_data)
> > +			     size_t out_len, u8 *out_data,
> > +			     u32 cmd_timeout_ms, u32 res_delay_ms)
> 
> It looks like 1s/0s is still the "default", so you could have just
> made this old function a wrapper:
> 
> static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd,
> 			     size_t in_len, u8 *in_data,
> 			     size_t out_len, u8 *out_data)
> {
>         return tps6598x_exec_cmd_tmo(tps, cmd, in_len, in_data, out_len, out_data, 1000, 0);
> }
Sounds good. I will change it in v6.
> 
> thanks,
> 
> -- 
> heikki

Thanks,
Abdel
diff mbox series

Patch

diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index 37b56ce75f39..a8aee4e1aeba 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -284,7 +284,8 @@  static void tps6598x_disconnect(struct tps6598x *tps, u32 status)
 
 static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd,
 			     size_t in_len, u8 *in_data,
-			     size_t out_len, u8 *out_data)
+			     size_t out_len, u8 *out_data,
+			     u32 cmd_timeout_ms, u32 res_delay_ms)
 {
 	unsigned long timeout;
 	u32 val;
@@ -307,8 +308,7 @@  static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd,
 	if (ret < 0)
 		return ret;
 
-	/* XXX: Using 1s for now, but it may not be enough for every command. */
-	timeout = jiffies + msecs_to_jiffies(1000);
+	timeout = jiffies + msecs_to_jiffies(cmd_timeout_ms);
 
 	do {
 		ret = tps6598x_read32(tps, TPS_REG_CMD1, &val);
@@ -321,6 +321,9 @@  static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd,
 			return -ETIMEDOUT;
 	} while (val);
 
+	/* some commands require delay for the result to be available */
+	mdelay(res_delay_ms);
+
 	if (out_len) {
 		ret = tps6598x_block_read(tps, TPS_REG_DATA1,
 					  out_data, out_len);
@@ -354,7 +357,7 @@  static int tps6598x_dr_set(struct typec_port *port, enum typec_data_role role)
 
 	mutex_lock(&tps->lock);
 
-	ret = tps6598x_exec_cmd(tps, cmd, 0, NULL, 0, NULL);
+	ret = tps6598x_exec_cmd(tps, cmd, 0, NULL, 0, NULL, 1000, 0);
 	if (ret)
 		goto out_unlock;
 
@@ -384,7 +387,7 @@  static int tps6598x_pr_set(struct typec_port *port, enum typec_role role)
 
 	mutex_lock(&tps->lock);
 
-	ret = tps6598x_exec_cmd(tps, cmd, 0, NULL, 0, NULL);
+	ret = tps6598x_exec_cmd(tps, cmd, 0, NULL, 0, NULL, 1000, 0);
 	if (ret)
 		goto out_unlock;
 
@@ -654,7 +657,10 @@  static int cd321x_switch_power_state(struct tps6598x *tps, u8 target_state)
 	if (state == target_state)
 		return 0;
 
-	ret = tps6598x_exec_cmd(tps, "SSPS", sizeof(u8), &target_state, 0, NULL);
+	ret = tps6598x_exec_cmd(tps, "SSPS",
+				sizeof(u8), &target_state,
+				0, NULL,
+				1000, 0);
 	if (ret)
 		return ret;