diff mbox series

[v9,06/14] USB: typec: tps6598x: Clear dead battery flag

Message ID 20231001081134.37101-7-alkuor@gmail.com (mailing list archive)
State New, archived
Headers show
Series Add TPS25750 USB type-C PD controller support | expand

Commit Message

Abdel Alkuor Oct. 1, 2023, 8:11 a.m. UTC
From: Abdel Alkuor <abdelalkuor@geotab.com>

Dead battery flag must be cleared after switching tps25750 to APP mode
so the PD controller becomes fully functional.

Signed-off-by: Abdel Alkuor <abdelalkuor@geotab.com>
---
Changes in v9:
  - No changes
Changes in v8:
  - No changes
Changes in v7:
  - Add driver name to commit subject
Changes in v6:
  - No changes
Changes in v5:
  - Incorporating tps25750 into tps6598x driver

 drivers/usb/typec/tipd/core.c     | 16 ++++++++++++++++
 drivers/usb/typec/tipd/tps6598x.h |  1 +
 2 files changed, 17 insertions(+)

Comments

Heikki Krogerus Oct. 3, 2023, 6:03 a.m. UTC | #1
On Sun, Oct 01, 2023 at 04:11:26AM -0400, Abdel Alkuor wrote:
> From: Abdel Alkuor <abdelalkuor@geotab.com>
> 
> Dead battery flag must be cleared after switching tps25750 to APP mode
> so the PD controller becomes fully functional.
> 
> Signed-off-by: Abdel Alkuor <abdelalkuor@geotab.com>

I'm sorry I noticed these so late, but this one really feels like it
should be part of the patch 4/14. Is there some reason why you do this
separately?

> ---
> Changes in v9:
>   - No changes
> Changes in v8:
>   - No changes
> Changes in v7:
>   - Add driver name to commit subject
> Changes in v6:
>   - No changes
> Changes in v5:
>   - Incorporating tps25750 into tps6598x driver
> 
>  drivers/usb/typec/tipd/core.c     | 16 ++++++++++++++++
>  drivers/usb/typec/tipd/tps6598x.h |  1 +
>  2 files changed, 17 insertions(+)
> 
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 21b0ea2c9627..2598433a69cf 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -946,6 +946,22 @@ static int tps25750_apply_patch(struct tps6598x *tps)
>  
>  	} while (ret != TPS_MODE_APP);
>  
> +	/*
> +	 * The dead battery flag may be triggered when the controller
> +	 * port is connected to a device that can source power and
> +	 * attempts to power up both the controller and the board it is on.
> +	 * To restore controller functionality, it is necessary to clear
> +	 * this flag
> +	 */
> +	if (status & TPS_BOOT_STATUS_DEAD_BATTERY_FLAG) {
> +		ret = tps6598x_exec_cmd(tps, "DBfg", 0, NULL, 0, NULL);
> +		if (ret) {
> +			dev_err(tps->dev,
> +				"failed to clear dead battery %d\n", ret);

One line is enough.

> +			return ret;
> +		}
> +	}
> +
>  	dev_info(tps->dev, "controller switched to \"APP\" mode\n");
>  
>  	return 0;
> diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h
> index a80d0929f3ee..c000170f4547 100644
> --- a/drivers/usb/typec/tipd/tps6598x.h
> +++ b/drivers/usb/typec/tipd/tps6598x.h
> @@ -200,6 +200,7 @@
>  #define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B    (BIT(2) | BIT(1))
>  
>  /* BOOT STATUS REG*/
> +#define TPS_BOOT_STATUS_DEAD_BATTERY_FLAG	BIT(2)
>  #define TPS_BOOT_STATUS_I2C_EEPROM_PRESENT	BIT(3)
>  
>  #endif /* __TPS6598X_H__ */
> -- 
> 2.34.1

Br,
Abdel Alkuor Oct. 3, 2023, 11:13 a.m. UTC | #2
On Tue, Oct 03, 2023 at 09:03:42AM +0300, Heikki Krogerus wrote:
> On Sun, Oct 01, 2023 at 04:11:26AM -0400, Abdel Alkuor wrote:
> > From: Abdel Alkuor <abdelalkuor@geotab.com>
> > 
> > Dead battery flag must be cleared after switching tps25750 to APP mode
> > so the PD controller becomes fully functional.
> > 
> > Signed-off-by: Abdel Alkuor <abdelalkuor@geotab.com>
> 
> I'm sorry I noticed these so late, but this one really feels like it
> should be part of the patch 4/14. Is there some reason why you do this
> separately?
>
That's a good. There is no actual reason, it was just simply part of the
implementation flow. I will move it to be part the patch that supports
tps25750 implementation

Thanks,
Abdel
> Br,
> 
> -- 
> heikki
diff mbox series

Patch

diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index 21b0ea2c9627..2598433a69cf 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -946,6 +946,22 @@  static int tps25750_apply_patch(struct tps6598x *tps)
 
 	} while (ret != TPS_MODE_APP);
 
+	/*
+	 * The dead battery flag may be triggered when the controller
+	 * port is connected to a device that can source power and
+	 * attempts to power up both the controller and the board it is on.
+	 * To restore controller functionality, it is necessary to clear
+	 * this flag
+	 */
+	if (status & TPS_BOOT_STATUS_DEAD_BATTERY_FLAG) {
+		ret = tps6598x_exec_cmd(tps, "DBfg", 0, NULL, 0, NULL);
+		if (ret) {
+			dev_err(tps->dev,
+				"failed to clear dead battery %d\n", ret);
+			return ret;
+		}
+	}
+
 	dev_info(tps->dev, "controller switched to \"APP\" mode\n");
 
 	return 0;
diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h
index a80d0929f3ee..c000170f4547 100644
--- a/drivers/usb/typec/tipd/tps6598x.h
+++ b/drivers/usb/typec/tipd/tps6598x.h
@@ -200,6 +200,7 @@ 
 #define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B    (BIT(2) | BIT(1))
 
 /* BOOT STATUS REG*/
+#define TPS_BOOT_STATUS_DEAD_BATTERY_FLAG	BIT(2)
 #define TPS_BOOT_STATUS_I2C_EEPROM_PRESENT	BIT(3)
 
 #endif /* __TPS6598X_H__ */