From: Jiawen Liu <liu1298662399@gmail.com>
To: Sebastian Reichel <sre@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] HSI: omap_ssi_port: Guard TX wake writes with runtime PM
Date: Sun, 29 Nov 2026 19:25:33 +0000 [thread overview]
Message-ID: <179598033707.2.16928400219194317754.pattern-ext-074.8@gmail.com> (raw)
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
reply other threads:[~2026-11-29 19:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179598033707.2.16928400219194317754.pattern-ext-074.8@gmail.com \
--to=liu1298662399@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sre@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®