diff mbox series

[v5,03/15] USB: typec: Add patch mode to tps6598x

Message ID 20230917152639.21443-4-alkuor@gmail.com
State New
Headers show
Series Add TPS25750 USB type-C PD controller support | expand

Commit Message

Abdel Alkuor Sept. 17, 2023, 3:26 p.m. UTC
TPS25750 has a patch mode indicating the device requires
a configuration to get the device into operational mode

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

Comments

Heikki Krogerus Sept. 18, 2023, 11:07 a.m. UTC | #1
On Sun, Sep 17, 2023 at 11:26:27AM -0400, Abdel Alkuor wrote:
> TPS25750 has a patch mode indicating the device requires
> a configuration to get the device into operational mode
> 
> Signed-off-by: Abdel Alkuor <alkuor@gmail.com>
> ---
>  drivers/usb/typec/tipd/core.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index a8aee4e1aeba..6d2151325fbb 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -68,6 +68,7 @@ enum {
>  	TPS_MODE_BOOT,
>  	TPS_MODE_BIST,
>  	TPS_MODE_DISC,
> +	TPS_MODE_PTCH,
>  };
>  
>  static const char *const modes[] = {
> @@ -75,6 +76,7 @@ static const char *const modes[] = {
>  	[TPS_MODE_BOOT]	= "BOOT",
>  	[TPS_MODE_BIST]	= "BIST",
>  	[TPS_MODE_DISC]	= "DISC",
> +	[TPS_MODE_PTCH] = "PTCH",
>  };
>  
>  /* Unrecognized commands will be replaced with "!CMD" */
> @@ -576,7 +578,7 @@ static void tps6598x_poll_work(struct work_struct *work)
>  			   &tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL));
>  }
>  
> -static int tps6598x_check_mode(struct tps6598x *tps)
> +static int tps6598x_check_mode(struct tps6598x *tps, u8 *curr_mode)
>  {
>  	char mode[5] = { };
>  	int ret;
> @@ -585,8 +587,11 @@ static int tps6598x_check_mode(struct tps6598x *tps)
>  	if (ret)
>  		return ret;
>  
> -	switch (match_string(modes, ARRAY_SIZE(modes), mode)) {
> +	*curr_mode = match_string(modes, ARRAY_SIZE(modes), mode);
> +
> +	switch (*curr_mode) {
>  	case TPS_MODE_APP:
> +	case TPS_MODE_PTCH:

This check is OK, but it seems that you are not using that curr_mode
for anything yet, so don't change the paramaters of this function in
this patch.

I would also just return the mode. Then this function would be used
like this:

        ret = tps6598x_check_mode(...)
        if (ret < 0)
                return ret;

Now mode = ret.

>  		return 0;
>  	case TPS_MODE_BOOT:
>  		dev_warn(tps->dev, "dead-battery condition\n");
> @@ -715,6 +720,7 @@ static int tps6598x_probe(struct i2c_client *client)
>  	u32 vid;
>  	int ret;
>  	u64 mask1;
> +	u8 mode;
>  
>  	tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
>  	if (!tps)
> @@ -759,7 +765,7 @@ static int tps6598x_probe(struct i2c_client *client)
>  
>  	tps->irq_handler = irq_handler;
>  	/* Make sure the controller has application firmware running */
> -	ret = tps6598x_check_mode(tps);
> +	ret = tps6598x_check_mode(tps, &mode);

Actually, if you need to know the mode in here later, then I'm not
sure tps6592x_check_mode() is useful after that. This is the only
place it's called. Just read and check the mode in here directly at
that point.

thanks,
Abdel Alkuor Sept. 20, 2023, 2:42 p.m. UTC | #2
On Mon, Sep 18, 2023 at 02:07:44PM +0300, Heikki Krogerus wrote:
> On Sun, Sep 17, 2023 at 11:26:27AM -0400, Abdel Alkuor wrote:
> > TPS25750 has a patch mode indicating the device requires
> > a configuration to get the device into operational mode
> > 
> > Signed-off-by: Abdel Alkuor <alkuor@gmail.com>
> > ---
> >  drivers/usb/typec/tipd/core.c | 12 +++++++++---
> >  1 file changed, 9 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> > index a8aee4e1aeba..6d2151325fbb 100644
> > --- a/drivers/usb/typec/tipd/core.c
> > +++ b/drivers/usb/typec/tipd/core.c
> > @@ -68,6 +68,7 @@ enum {
> >  	TPS_MODE_BOOT,
> >  	TPS_MODE_BIST,
> >  	TPS_MODE_DISC,
> > +	TPS_MODE_PTCH,
> >  };
> >  
> >  static const char *const modes[] = {
> > @@ -75,6 +76,7 @@ static const char *const modes[] = {
> >  	[TPS_MODE_BOOT]	= "BOOT",
> >  	[TPS_MODE_BIST]	= "BIST",
> >  	[TPS_MODE_DISC]	= "DISC",
> > +	[TPS_MODE_PTCH] = "PTCH",
> >  };
> >  
> >  /* Unrecognized commands will be replaced with "!CMD" */
> > @@ -576,7 +578,7 @@ static void tps6598x_poll_work(struct work_struct *work)
> >  			   &tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL));
> >  }
> >  
> > -static int tps6598x_check_mode(struct tps6598x *tps)
> > +static int tps6598x_check_mode(struct tps6598x *tps, u8 *curr_mode)
> >  {
> >  	char mode[5] = { };
> >  	int ret;
> > @@ -585,8 +587,11 @@ static int tps6598x_check_mode(struct tps6598x *tps)
> >  	if (ret)
> >  		return ret;
> >  
> > -	switch (match_string(modes, ARRAY_SIZE(modes), mode)) {
> > +	*curr_mode = match_string(modes, ARRAY_SIZE(modes), mode);
> > +
> > +	switch (*curr_mode) {
> >  	case TPS_MODE_APP:
> > +	case TPS_MODE_PTCH:
> 
> This check is OK, but it seems that you are not using that curr_mode
> for anything yet, so don't change the paramaters of this function in
> this patch.
> 
> I would also just return the mode. Then this function would be used
> like this:
> 
>         ret = tps6598x_check_mode(...)
>         if (ret < 0)
>                 return ret;
> 
> Now mode = ret.
> 
> >  		return 0;
> >  	case TPS_MODE_BOOT:
> >  		dev_warn(tps->dev, "dead-battery condition\n");
> > @@ -715,6 +720,7 @@ static int tps6598x_probe(struct i2c_client *client)
> >  	u32 vid;
> >  	int ret;
> >  	u64 mask1;
> > +	u8 mode;
> >  
> >  	tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
> >  	if (!tps)
> > @@ -759,7 +765,7 @@ static int tps6598x_probe(struct i2c_client *client)
> >  
> >  	tps->irq_handler = irq_handler;
> >  	/* Make sure the controller has application firmware running */
> > -	ret = tps6598x_check_mode(tps);
> > +	ret = tps6598x_check_mode(tps, &mode);
> 
> Actually, if you need to know the mode in here later, then I'm not
> sure tps6592x_check_mode() is useful after that. This is the only
> place it's called. Just read and check the mode in here directly at
> that point.

I will return the mode and check ret directly.
> 
> 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 a8aee4e1aeba..6d2151325fbb 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -68,6 +68,7 @@  enum {
 	TPS_MODE_BOOT,
 	TPS_MODE_BIST,
 	TPS_MODE_DISC,
+	TPS_MODE_PTCH,
 };
 
 static const char *const modes[] = {
@@ -75,6 +76,7 @@  static const char *const modes[] = {
 	[TPS_MODE_BOOT]	= "BOOT",
 	[TPS_MODE_BIST]	= "BIST",
 	[TPS_MODE_DISC]	= "DISC",
+	[TPS_MODE_PTCH] = "PTCH",
 };
 
 /* Unrecognized commands will be replaced with "!CMD" */
@@ -576,7 +578,7 @@  static void tps6598x_poll_work(struct work_struct *work)
 			   &tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL));
 }
 
-static int tps6598x_check_mode(struct tps6598x *tps)
+static int tps6598x_check_mode(struct tps6598x *tps, u8 *curr_mode)
 {
 	char mode[5] = { };
 	int ret;
@@ -585,8 +587,11 @@  static int tps6598x_check_mode(struct tps6598x *tps)
 	if (ret)
 		return ret;
 
-	switch (match_string(modes, ARRAY_SIZE(modes), mode)) {
+	*curr_mode = match_string(modes, ARRAY_SIZE(modes), mode);
+
+	switch (*curr_mode) {
 	case TPS_MODE_APP:
+	case TPS_MODE_PTCH:
 		return 0;
 	case TPS_MODE_BOOT:
 		dev_warn(tps->dev, "dead-battery condition\n");
@@ -715,6 +720,7 @@  static int tps6598x_probe(struct i2c_client *client)
 	u32 vid;
 	int ret;
 	u64 mask1;
+	u8 mode;
 
 	tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
 	if (!tps)
@@ -759,7 +765,7 @@  static int tps6598x_probe(struct i2c_client *client)
 
 	tps->irq_handler = irq_handler;
 	/* Make sure the controller has application firmware running */
-	ret = tps6598x_check_mode(tps);
+	ret = tps6598x_check_mode(tps, &mode);
 	if (ret)
 		return ret;