mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] HSI: omap_ssi_port: Guard TX wake writes with runtime PM
@ 2026-11-29 19:25 Jiawen Liu
  0 siblings, 0 replies; only message in thread
From: Jiawen Liu @ 2026-11-29 19:25 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-kernel

The first TX wake request after autosuspend queues start_tx_work(). On
OMAP3, a timeout waiting for the parent SSI module to become ready rolls
back its clock enables and causes the port's runtime resume to fail.
The worker still writes the set-wake register, and the last stop still
writes the clear-wake register. The peer may never see wake asserted,
leaving the SSI protocol client waiting for READY until it times out.

Use pm_runtime_resume_and_get() and check that a wake request is still
outstanding before asserting wake. Track the asserted wake and its PM
reference under wk_lock so the last stop or removal clears wake and drops
the reference exactly once. Disable and drain the TX wake work during
removal and keep driver data available until runtime PM is disabled.

Verification included source review,
ARM object builds with and without CONFIG_PM, git diff --check, and
checkpatch. No runtime or hardware reproduction was performed.

Fixes: 7c5d81620ecd ("HSI: omap_ssi_port: prepare start_tx/stop_tx for blocking pm_runtime calls")
Signed-off-by: Jiawen Liu <liu1298662399@gmail.com>
---
 drivers/hsi/controllers/omap_ssi.h      |  4 +-
 drivers/hsi/controllers/omap_ssi_port.c | 60 +++++++++++++++++--------
 2 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/drivers/hsi/controllers/omap_ssi.h b/drivers/hsi/controllers/omap_ssi.h
index c72f74b5bb42a..f4fdc553b98fb 100644
--- a/drivers/hsi/controllers/omap_ssi.h
+++ b/drivers/hsi/controllers/omap_ssi.h
@@ -66,7 +66,8 @@ struct omap_ssm_ctx {
  * @wake_irq: IRQ number for incoming wake line (-1 if none)
  * @wake_gpio: GPIO number for incoming wake line (-1 if none)
  * @flags: flags to keep track of states
- * @wk_refcount: Reference count for output wake line
+ * @wk_refcount: Number of outstanding TX wake requests
+ * @tx_wake: TX wake asserted with a runtime PM reference held
  * @work: worker for starting TX
  * @sys_mpu_enable: Context for the interrupt enable register for irq 0
  * @sst: Context for the synchronous serial transmitter
@@ -93,6 +94,7 @@ struct omap_ssi_port {
 	bool			wktest:1; /* FIXME: HACK to be removed */
 	unsigned long		flags;
 	unsigned int		wk_refcount;
+	bool			tx_wake;
 	struct work_struct	work;
 	/* OMAP SSI port context */
 	u32			sys_mpu_enable; /* We use only one irq */
diff --git a/drivers/hsi/controllers/omap_ssi_port.c b/drivers/hsi/controllers/omap_ssi_port.c
index a6d654be8c4a5..65c78d036caf8 100644
--- a/drivers/hsi/controllers/omap_ssi_port.c
+++ b/drivers/hsi/controllers/omap_ssi_port.c
@@ -577,9 +577,23 @@ static void start_tx_work(struct work_struct *work)
 	struct hsi_port *port = to_hsi_port(omap_port->dev);
 	struct hsi_controller *ssi = to_hsi_controller(port->device.parent);
 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
+	int err;
+
+	err = pm_runtime_resume_and_get(omap_port->pdev);
+	if (err < 0) {
+		dev_err(omap_port->pdev, "Failed to resume for TX wake: %d\n", err);
+		return;
+	}
 
-	pm_runtime_get_sync(omap_port->pdev); /* Grab clocks */
+	spin_lock_bh(&omap_port->wk_lock);
+	if (!omap_port->wk_refcount || omap_port->tx_wake) {
+		spin_unlock_bh(&omap_port->wk_lock);
+		pm_runtime_put_autosuspend(omap_port->pdev);
+		return;
+	}
 	writel(SSI_WAKE(0), omap_ssi->sys + SSI_SET_WAKE_REG(port->num));
+	omap_port->tx_wake = true;
+	spin_unlock_bh(&omap_port->wk_lock);
 }
 
 static int ssi_start_tx(struct hsi_client *cl)
@@ -590,38 +604,41 @@ static int ssi_start_tx(struct hsi_client *cl)
 	dev_dbg(&port->device, "Wake out high %d\n", omap_port->wk_refcount);
 
 	spin_lock_bh(&omap_port->wk_lock);
-	if (omap_port->wk_refcount++) {
-		spin_unlock_bh(&omap_port->wk_lock);
-		return 0;
-	}
+	if (!omap_port->wk_refcount++)
+		schedule_work(&omap_port->work);
 	spin_unlock_bh(&omap_port->wk_lock);
 
-	schedule_work(&omap_port->work);
-
 	return 0;
 }
 
-static int ssi_stop_tx(struct hsi_client *cl)
+/* Called with wk_lock held. */
+static void ssi_clear_tx_wake(struct hsi_port *port)
 {
-	struct hsi_port *port = hsi_get_port(cl);
 	struct omap_ssi_port *omap_port = hsi_port_drvdata(port);
 	struct hsi_controller *ssi = to_hsi_controller(port->device.parent);
 	struct omap_ssi_controller *omap_ssi = hsi_controller_drvdata(ssi);
 
+	if (!omap_port->tx_wake)
+		return;
+
+	writel(SSI_WAKE(0), omap_ssi->sys + SSI_CLEAR_WAKE_REG(port->num));
+	omap_port->tx_wake = false;
+	pm_runtime_put_autosuspend(omap_port->pdev);
+}
+
+static int ssi_stop_tx(struct hsi_client *cl)
+{
+	struct hsi_port *port = hsi_get_port(cl);
+	struct omap_ssi_port *omap_port = hsi_port_drvdata(port);
+
 	dev_dbg(&port->device, "Wake out low %d\n", omap_port->wk_refcount);
 
 	spin_lock_bh(&omap_port->wk_lock);
 	BUG_ON(!omap_port->wk_refcount);
-	if (--omap_port->wk_refcount) {
-		spin_unlock_bh(&omap_port->wk_lock);
-		return 0;
-	}
-	writel(SSI_WAKE(0), omap_ssi->sys + SSI_CLEAR_WAKE_REG(port->num));
+	if (!--omap_port->wk_refcount)
+		ssi_clear_tx_wake(port);
 	spin_unlock_bh(&omap_port->wk_lock);
 
-	pm_runtime_put_autosuspend(omap_port->pdev); /* Release clocks */
-
-
 	return 0;
 }
 
@@ -1217,6 +1234,7 @@ static void ssi_port_remove(struct platform_device *pd)
 #endif
 
 	cancel_delayed_work_sync(&omap_port->errqueue_work);
+	disable_work_sync(&omap_port->work);
 
 	hsi_port_unregister_clients(port);
 
@@ -1227,11 +1245,15 @@ static void ssi_port_remove(struct platform_device *pd)
 	port->stop_tx	= hsi_dummy_cl;
 	port->release	= hsi_dummy_cl;
 
-	omap_ssi->port[omap_port->port_id] = NULL;
-	platform_set_drvdata(pd, NULL);
+	spin_lock_bh(&omap_port->wk_lock);
+	ssi_clear_tx_wake(port);
+	spin_unlock_bh(&omap_port->wk_lock);
 
 	pm_runtime_dont_use_autosuspend(&pd->dev);
 	pm_runtime_disable(&pd->dev);
+
+	omap_ssi->port[omap_port->port_id] = NULL;
+	platform_set_drvdata(pd, NULL);
 }
 
 static int ssi_restore_divisor(struct omap_ssi_port *omap_port)
-- 
2.34.1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-29 19:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 19:25 [PATCH] HSI: omap_ssi_port: Guard TX wake writes with runtime PM Jiawen Liu

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

all inboxes | Powered by JetHome®