Linux USB
 help / color / mirror / Atom feed
* [PATCH v3 0/3] usb: typec: qcom-pmic-typec: properly tear down port on remove and shutdown
@ 2026-12-01  8:50 Neil Armstrong
  2026-12-01  8:50 ` [PATCH v3 1/3] usb: typec: qcom-pmic-typec: pdphy: disable the PD PHY on stop Neil Armstrong
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Neil Armstrong @ 2026-12-01  8:50 UTC (permalink / raw)
  To: Bryan O'Donoghue, Heikki Krogerus, Greg Kroah-Hartman,
	Guenter Roeck, Casey Connolly, Dmitry Baryshkov
  Cc: linux-arm-msm, linux-usb, Neil Armstrong

The current driver doesn't leave the port in the same
state as found when probing, and leaves the port enabled
on system shutdown.

Loosely depends on [1].

[1] https://lore.kernel.org/all/20261125-topic-tcpm-core-fixes-v2-0-aede2a3471f4@linaro.org/

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
Changes in v3:
- Squash patch 3 in patch 2
- Move patch 4 as patch 2 and move patch 2 as last patch
- Call qcom_pmic_typec_port_disable() from qcom_pmic_typec_port_probe() with the proper teardown sequencer
- Link to v2: https://patch.msgid.link/20261125-topic-tcpm-qcom-fixes-v2-0-6fede9a69f6f@linaro.org

Changes in v2:
- Add Fixes and review tags
- Also disable on remove
- New patch: switch to SNK_ONLY before DISABLE when disabling port
- New patch: detach the port on probe
- Link to v1: https://patch.msgid.link/20261120-topic-tcpm-qcom-fixes-v1-0-9a152f906fba@linaro.org

To: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Guenter Roeck <linux@roeck-us.net>
To: Casey Connolly <casey.connolly@linaro.org>
To: Dmitry Baryshkov <lumag@kernel.org>
Cc: linux-arm-msm@vger.kernel.org
Cc: linux-usb@vger.kernel.org

---
Neil Armstrong (3):
      usb: typec: qcom-pmic-typec: pdphy: disable the PD PHY on stop
      usb: typec: qcom-pmic-typec: detach the port on probe
      usb: typec: qcom-pmic-typec: detach the port on shutdown

 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c      | 12 +++++++++
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.h      |  1 +
 .../usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c    |  2 +-
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 30 ++++++++++++++++++++++
 4 files changed, 44 insertions(+), 1 deletion(-)
---
base-commit: 3dd8c790a7b7027abdd568e36db5e82ffaea7c77
change-id: 20261120-topic-tcpm-qcom-fixes-c9ce1e65c570

Best regards,
--  
Neil Armstrong <neil.armstrong@linaro.org>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/3] usb: typec: qcom-pmic-typec: pdphy: disable the PD PHY on stop
  2026-12-01  8:50 [PATCH v3 0/3] usb: typec: qcom-pmic-typec: properly tear down port on remove and shutdown Neil Armstrong
@ 2026-12-01  8:50 ` Neil Armstrong
  2026-12-01  8:50 ` [PATCH v3 2/3] usb: typec: qcom-pmic-typec: detach the port on probe Neil Armstrong
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Neil Armstrong @ 2026-12-01  8:50 UTC (permalink / raw)
  To: Bryan O'Donoghue, Heikki Krogerus, Greg Kroah-Hartman,
	Guenter Roeck, Casey Connolly, Dmitry Baryshkov
  Cc: linux-arm-msm, linux-usb, Neil Armstrong

qcom_pmic_typec_pdphy_stop() only terminates the ongoing transmission and
clears the RX frame filter, the PD PHY itself stays enabled.

Use qcom_pmic_typec_pdphy_disable() so the PD PHY is also turned off
before its supply is released, leaving it in the same state as before
qcom_pmic_typec_pdphy_start().

Assisted-by: LLM
Fixes: a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
index 435e07659d65..08cf65951796 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
@@ -545,7 +545,7 @@ static void qcom_pmic_typec_pdphy_stop(struct pmic_typec *tcpm)
 
 	cancel_work_sync(&pmic_typec_pdphy->reset_work);
 
-	qcom_pmic_typec_pdphy_reset_on(pmic_typec_pdphy);
+	qcom_pmic_typec_pdphy_disable(pmic_typec_pdphy);
 
 	regulator_disable(pmic_typec_pdphy->vdd_pdphy);
 }

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/3] usb: typec: qcom-pmic-typec: detach the port on probe
  2026-12-01  8:50 [PATCH v3 0/3] usb: typec: qcom-pmic-typec: properly tear down port on remove and shutdown Neil Armstrong
  2026-12-01  8:50 ` [PATCH v3 1/3] usb: typec: qcom-pmic-typec: pdphy: disable the PD PHY on stop Neil Armstrong
@ 2026-12-01  8:50 ` Neil Armstrong
  2026-12-01  8:50 ` [PATCH v3 3/3] usb: typec: qcom-pmic-typec: detach the port on shutdown Neil Armstrong
  2026-12-01  9:05 ` [PATCH v3 0/3] usb: typec: qcom-pmic-typec: properly tear down port on remove and shutdown sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: Neil Armstrong @ 2026-12-01  8:50 UTC (permalink / raw)
  To: Bryan O'Donoghue, Heikki Krogerus, Greg Kroah-Hartman,
	Guenter Roeck, Casey Connolly, Dmitry Baryshkov
  Cc: linux-arm-msm, linux-usb, Neil Armstrong

The Type-C block may have been left attached by the bootloader, force a
detach longer than tPDDebounce so the partner and TCPM start from a known
state.

Fixes: a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
index d433fc3e7e56..948a15b65c01 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
@@ -782,6 +782,17 @@ int qcom_pmic_typec_port_probe(struct platform_device *pdev,
 	tcpm->port_start = qcom_pmic_typec_port_start;
 	tcpm->port_stop = qcom_pmic_typec_port_stop;
 
+	/*
+	 * The Type-C block may have been left attached by the bootloader,
+	 * force a detach longer than tPDDebounce so the partner and TCPM
+	 * start from a known state.
+	 */
+	regmap_write(pmic_typec_port->regmap,
+		     pmic_typec_port->base + TYPEC_MODE_CFG_REG,
+		     TYPEC_DISABLE_CMD);
+
+	msleep(200);
+
 	return 0;
 }
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 3/3] usb: typec: qcom-pmic-typec: detach the port on shutdown
  2026-12-01  8:50 [PATCH v3 0/3] usb: typec: qcom-pmic-typec: properly tear down port on remove and shutdown Neil Armstrong
  2026-12-01  8:50 ` [PATCH v3 1/3] usb: typec: qcom-pmic-typec: pdphy: disable the PD PHY on stop Neil Armstrong
  2026-12-01  8:50 ` [PATCH v3 2/3] usb: typec: qcom-pmic-typec: detach the port on probe Neil Armstrong
@ 2026-12-01  8:50 ` Neil Armstrong
  2026-12-01  9:05   ` sashiko-bot
  2026-12-01  9:05 ` [PATCH v3 0/3] usb: typec: qcom-pmic-typec: properly tear down port on remove and shutdown sashiko-bot
  3 siblings, 1 reply; 6+ messages in thread
From: Neil Armstrong @ 2026-12-01  8:50 UTC (permalink / raw)
  To: Bryan O'Donoghue, Heikki Krogerus, Greg Kroah-Hartman,
	Guenter Roeck, Casey Connolly, Dmitry Baryshkov
  Cc: linux-arm-msm, linux-usb, Neil Armstrong

On reboot or power off the port is left as is: a source partner keeps
the negotiated contract, possibly above 5V, and a sink partner stays
powered by the OTG boost while nothing services the port anymore.

Add a shutdown callback stopping the port and the PD PHY, unregistering
the TCPM port, which turns VBUS and VCONN off, and finally disabling the
Type-C block so the partner sees a detach. Also disable on remove.

Disabling it straight from DRP mode can trigger an over-voltage fault on
the VBUS boost, so switch it first to sink only mode for 2ms, then present
neither Rp nor Rd, so a connected partner detects a detach in a safe way.

Assisted-by: LLM
Fixes: a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Fixes: f1a27f081c1f ("usb: typec: qcom-pmic-typec: allow different implementations for the port backend")
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c      | 12 +++++++++++
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.h      |  1 +
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 25 +++++++++++++++++++---
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
index 58d1e6aae637..be7508936796 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
@@ -132,6 +132,17 @@ static void qcom_pmic_typec_remove(struct platform_device *pdev)
 	tcpm->port_stop(tcpm);
 	tcpm_unregister_port(tcpm->tcpm_port);
 	fwnode_handle_put(tcpm->tcpc.fwnode);
+	tcpm->port_disable(tcpm);
+}
+
+static void qcom_pmic_typec_shutdown(struct platform_device *pdev)
+{
+	struct pmic_typec *tcpm = platform_get_drvdata(pdev);
+
+	tcpm->pdphy_stop(tcpm);
+	tcpm->port_stop(tcpm);
+	tcpm_unregister_port(tcpm->tcpm_port);
+	tcpm->port_disable(tcpm);
 }
 
 static const struct pmic_typec_resources pm8150b_typec_res = {
@@ -158,6 +169,7 @@ static struct platform_driver qcom_pmic_typec_driver = {
 	},
 	.probe = qcom_pmic_typec_probe,
 	.remove = qcom_pmic_typec_remove,
+	.shutdown = qcom_pmic_typec_shutdown,
 };
 
 module_platform_driver(qcom_pmic_typec_driver);
diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.h b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.h
index 3c75820c9187..0818582fe850 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.h
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.h
@@ -20,6 +20,7 @@ struct pmic_typec {
 	int (*port_start)(struct pmic_typec *tcpm,
 			  struct tcpm_port *tcpm_port);
 	void (*port_stop)(struct pmic_typec *tcpm);
+	void (*port_disable)(struct pmic_typec *tcpm);
 };
 
 #define tcpc_to_tcpm(_tcpc_) container_of(_tcpc_, struct pmic_typec, tcpc)
diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
index 948a15b65c01..c68492d41453 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
@@ -701,6 +701,26 @@ static void qcom_pmic_typec_port_stop(struct pmic_typec *tcpm)
 	disable_delayed_work_sync(&pmic_typec_port->cc_debounce_dwork);
 }
 
+static void qcom_pmic_typec_port_disable(struct pmic_typec *tcpm)
+{
+	struct pmic_typec_port *pmic_typec_port = tcpm->pmic_typec_port;
+
+	/*
+	 * Disabling the Type-C block straight from DRP mode can trigger
+	 * a VBUS boost over-voltage fault, so go through sink only mode first.
+	 */
+	regmap_write(pmic_typec_port->regmap,
+		     pmic_typec_port->base + TYPEC_MODE_CFG_REG,
+		     EN_SNK_ONLY);
+
+	usleep_range(2000, 3000);
+
+	/* Present neither Rp nor Rd, so a connected partner detects a detach */
+	regmap_write(pmic_typec_port->regmap,
+		     pmic_typec_port->base + TYPEC_MODE_CFG_REG,
+		     TYPEC_DISABLE_CMD);
+}
+
 int qcom_pmic_typec_port_probe(struct platform_device *pdev,
 			       struct pmic_typec *tcpm,
 			       const struct pmic_typec_port_resources *res,
@@ -781,15 +801,14 @@ int qcom_pmic_typec_port_probe(struct platform_device *pdev,
 
 	tcpm->port_start = qcom_pmic_typec_port_start;
 	tcpm->port_stop = qcom_pmic_typec_port_stop;
+	tcpm->port_disable = qcom_pmic_typec_port_disable;
 
 	/*
 	 * The Type-C block may have been left attached by the bootloader,
 	 * force a detach longer than tPDDebounce so the partner and TCPM
 	 * start from a known state.
 	 */
-	regmap_write(pmic_typec_port->regmap,
-		     pmic_typec_port->base + TYPEC_MODE_CFG_REG,
-		     TYPEC_DISABLE_CMD);
+	qcom_pmic_typec_port_disable(tcpm);
 
 	msleep(200);
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 3/3] usb: typec: qcom-pmic-typec: detach the port on shutdown
  2026-12-01  8:50 ` [PATCH v3 3/3] usb: typec: qcom-pmic-typec: detach the port on shutdown Neil Armstrong
@ 2026-12-01  9:05   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-01  9:05 UTC (permalink / raw)
  To: Neil Armstrong; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usb: typec: qcom: NULL deref in tcpm_vbus_change() on shutdown
  with VBUS on
- [Medium] usb: typec: qcom: missing port_disable() on
  qcom_pmic_typec_probe() error path
--

commit 4cd6e3b2d4452793cc04ed00c87bc010696a9646
Author: Neil Armstrong <neil.armstrong@linaro.org>

usb: typec: qcom-pmic-typec: detach the port on shutdown

This commit adds a port_disable callback to switch the Type-C block through
sink-only mode to disabled, and invokes it on probe, remove, and a new
shutdown callback.

> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> index 58d1e6aae637d..be7508936796e 100644
> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> @@ -132,6 +132,17 @@ static void qcom_pmic_typec_remove(struct platform_device *pdev)
>  	tcpm->port_stop(tcpm);
>  	tcpm_unregister_port(tcpm->tcpm_port);
>  	fwnode_handle_put(tcpm->tcpc.fwnode);
> +	tcpm->port_disable(tcpm);
> +}

[Severity: Medium]
Should the error unwind path in qcom_pmic_typec_probe() also call
tcpm->port_disable(tcpm)?

tcpm_register_port() and qcom_pmic_typec_port_start() re-enable
TYPEC_MODE_CFG_REG after qcom_pmic_typec_port_probe() disables it, so a later
failure in probe leaves the Type-C block active presenting Rp or Rd with no
driver bound.

> +
> +static void qcom_pmic_typec_shutdown(struct platform_device *pdev)
> +{
> +	struct pmic_typec *tcpm = platform_get_drvdata(pdev);
> +
> +	tcpm->pdphy_stop(tcpm);
> +	tcpm->port_stop(tcpm);
> +	tcpm_unregister_port(tcpm->tcpm_port);
> +	tcpm->port_disable(tcpm);
> +}

[Severity: High]
Can calling tcpm_unregister_port() on shutdown while sourcing VBUS to a sink
partner trigger a NULL pointer dereference in tcpm_vbus_change()?

tcpm_unregister_port() destroys port->wq and sets it to NULL before calling
tcpm_reset_port():

drivers/usb/typec/tcpm/tcpm.c:tcpm_unregister_port() {
	port->registered = false;
	kthread_destroy_worker(port->wq);
	port->wq = NULL;
	...
	tcpm_reset_port(port);
}

When VBUS is enabled, tcpm_reset_port() -> tcpm_init_vbus() calls
qcom_pmic_typec_port_set_vbus(tcpc, false, false), which calls
tcpm_vbus_change(tcpm->tcpm_port) and passes the NULL port->wq to
kthread_queue_work(), crashing before tcpm->port_disable(tcpm) is reached.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-topic-tcpm-qcom-fixes-v3-0-8dca0188915e@linaro.org?part=3

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/3] usb: typec: qcom-pmic-typec: properly tear down port on remove and shutdown
  2026-12-01  8:50 [PATCH v3 0/3] usb: typec: qcom-pmic-typec: properly tear down port on remove and shutdown Neil Armstrong
                   ` (2 preceding siblings ...)
  2026-12-01  8:50 ` [PATCH v3 3/3] usb: typec: qcom-pmic-typec: detach the port on shutdown Neil Armstrong
@ 2026-12-01  9:05 ` sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-01  9:05 UTC (permalink / raw)
  To: Neil Armstrong; +Cc: linux-usb

Sashiko has finished reviewing this 3-patch series:

- Patches 1 and 2: no issues found.
- Patch 3 ("usb: typec: qcom-pmic-typec: detach the port on shut..."): 2
  potential issues (1 High, 1 Medium)

A detailed review has been sent as a separate reply to patch 3.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-topic-tcpm-qcom-fixes-v3-0-8dca0188915e@linaro.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-01  9:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  8:50 [PATCH v3 0/3] usb: typec: qcom-pmic-typec: properly tear down port on remove and shutdown Neil Armstrong
2026-12-01  8:50 ` [PATCH v3 1/3] usb: typec: qcom-pmic-typec: pdphy: disable the PD PHY on stop Neil Armstrong
2026-12-01  8:50 ` [PATCH v3 2/3] usb: typec: qcom-pmic-typec: detach the port on probe Neil Armstrong
2026-12-01  8:50 ` [PATCH v3 3/3] usb: typec: qcom-pmic-typec: detach the port on shutdown Neil Armstrong
2026-12-01  9:05   ` sashiko-bot
2026-12-01  9:05 ` [PATCH v3 0/3] usb: typec: qcom-pmic-typec: properly tear down port on remove and shutdown sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox