[PATCH v11 16/35] remoteproc: k3: Refactor rproc_reset() implementation into common driver

Beleswar Padhi
2025-04-25T10:42:48Z

The rproc_reset() implementations in TI K3 DSP and M4 remoteproc drivers
assert reset in the same way. Refactor the above function into the
ti_k3_common.c driver as k3_rproc_reset() and use it throughout DSP and
M4 drivers for resetting the remote processor.

Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
Tested-by: Judith Mendez <jm@ti.com>
---
v11: Changelog:
1. Split [v10 15/33] into [v11 15/35] and [v11 16/35].
2. Carried T/B tag.

Link to v10:
https://lore.kernel.org/all/20250417182001.3903905-16-b-padhi@ti.com/

v10: Changelog:
1. Split [v9 12/26] into [v10 14/33] and [v10 15/33] patches.

Link to v9:
https://lore.kernel.org/all/20250317120622.1746415-13-b-padhi@ti.com/

drivers/remoteproc/ti_k3_common.c | 21 ++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 24 ++---------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 24 ++---------------------
4 files changed, 26 insertions(+), 44 deletions(-)

diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index aace308b49b0e..894b4c9168f59 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -105,5 +105,26 @@ void k3_rproc_kick(struct rproc *rproc, int vqid)
}
EXPORT_SYMBOL_GPL(k3_rproc_kick);

+/* Put the remote processor into reset */
+int k3_rproc_reset(struct k3_rproc *kproc)
+{
+ struct device *dev = kproc->dev;
+ int ret;
+
+ if (kproc->data->uses_lreset) {
+ ret = reset_control_assert(kproc->reset);
+ if (ret)
+ dev_err(dev, "local-reset assert failed (%pe)\n", ERR_PTR(ret));
+ } else {
+ ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
+ kproc->ti_sci_id);
+ if (ret)
+ dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret));
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_reset);
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("TI K3 common Remoteproc code");
diff --git a/drivers/remoteproc/ti_k3_common.h b/drivers/remoteproc/ti_k3_common.h
index 6ae7ac4ec5696..f3400fc774766 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -90,4 +90,5 @@ struct k3_rproc {

void k3_rproc_mbox_callback(struct mbox_client *client, void *data);
void k3_rproc_kick(struct rproc *rproc, int vqid);
+int k3_rproc_reset(struct k3_rproc *kproc);
#endif /* REMOTEPROC_TI_K3_COMMON_H */
diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
index 2ffcdba1c7754..f8a5282df5b71 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -24,26 +24,6 @@

#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)

-/* Put the DSP processor into reset */
-static int k3_dsp_rproc_reset(struct k3_rproc *kproc)
-{
- struct device *dev = kproc->dev;
- int ret;
-
- if (kproc->data->uses_lreset) {
- ret = reset_control_assert(kproc->reset);
- if (ret)
- dev_err(dev, "local-reset assert failed (%pe)\n", ERR_PTR(ret));
- } else {
- ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
- kproc->ti_sci_id);
- if (ret)
- dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret));
- }
-
- return ret;
-}
-
/* Release the DSP processor from reset */
static int k3_dsp_rproc_release(struct k3_rproc *kproc)
{
@@ -197,7 +177,7 @@ static int k3_dsp_rproc_stop(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;

- k3_dsp_rproc_reset(kproc);
+ k3_rproc_reset(kproc);

return 0;
}
@@ -561,7 +541,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
return dev_err_probe(dev, ret, "failed to get reset status\n");
} else if (ret == 0) {
dev_warn(dev, "local reset is deasserted for device\n");
- k3_dsp_rproc_reset(kproc);
+ k3_rproc_reset(kproc);
}
}
}
diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 2abf22f45bea3..7d5b75be2e4f8 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,26 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"

-/* Put the M4 remote processor into reset */
-static int k3_m4_rproc_reset(struct k3_rproc *kproc)
-{
- struct device *dev = kproc->dev;
- int ret;
-
- if (kproc->data->uses_lreset) {
- ret = reset_control_assert(kproc->reset);
- if (ret)
- dev_err(dev, "local-reset assert failed, ret = %d\n", ret);
- } else {
- ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
- kproc->ti_sci_id);
- if (ret)
- dev_err(dev, "module-reset assert failed, ret = %d\n", ret);
- }
-
- return ret;
-}
-
static int k3_m4_rproc_ping_mbox(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
@@ -85,7 +65,7 @@ static int k3_m4_rproc_prepare(struct rproc *rproc)
* Ensure the local reset is asserted so the core doesn't
* execute bogus code when the module reset is released.
*/
- ret = k3_m4_rproc_reset(kproc);
+ ret = k3_rproc_reset(kproc);
if (ret)
return ret;

@@ -393,7 +373,7 @@ static int k3_m4_rproc_stop(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;

- return k3_m4_rproc_reset(kproc);
+ return k3_rproc_reset(kproc);
}

/*
--
2.34.1