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

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

The rproc_release() implementations in TI K3 DSP and M4 remoteproc
drivers deassert reset in the same way. Refactor the above function into
the ti_k3_common.c driver as k3_rproc_release() and use it throughout
DSP and M4 drivers for releasing the reset from the remote processor.

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

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

v10: Changelog:
1. Split [v9 13/26] into [v10 16/33] and [v10 17/33] patches.

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

drivers/remoteproc/ti_k3_common.c | 25 ++++++++++++++++++++++
drivers/remoteproc/ti_k3_common.h | 1 +
drivers/remoteproc/ti_k3_dsp_remoteproc.c | 26 +----------------------
drivers/remoteproc/ti_k3_m4_remoteproc.c | 26 +----------------------
4 files changed, 28 insertions(+), 50 deletions(-)

diff --git a/drivers/remoteproc/ti_k3_common.c b/drivers/remoteproc/ti_k3_common.c
index 894b4c9168f59..e4a924cb1798e 100644
--- a/drivers/remoteproc/ti_k3_common.c
+++ b/drivers/remoteproc/ti_k3_common.c
@@ -126,5 +126,30 @@ int k3_rproc_reset(struct k3_rproc *kproc)
}
EXPORT_SYMBOL_GPL(k3_rproc_reset);

+/* Release the remote processor from reset */
+int k3_rproc_release(struct k3_rproc *kproc)
+{
+ struct device *dev = kproc->dev;
+ int ret;
+
+ if (kproc->data->uses_lreset) {
+ ret = reset_control_deassert(kproc->reset);
+ if (ret) {
+ dev_err(dev, "local-reset deassert failed, (%pe)\n", ERR_PTR(ret));
+ if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
+ kproc->ti_sci_id))
+ dev_warn(dev, "module-reset assert back failed\n");
+ }
+ } else {
+ ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
+ kproc->ti_sci_id);
+ if (ret)
+ dev_err(dev, "module-reset deassert failed (%pe)\n", ERR_PTR(ret));
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(k3_rproc_release);
+
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 f3400fc774766..c1af39cd288c1 100644
--- a/drivers/remoteproc/ti_k3_common.h
+++ b/drivers/remoteproc/ti_k3_common.h
@@ -91,4 +91,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);
+int k3_rproc_release(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 08e6dde3ea267..577dcd65093a9 100644
--- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c
@@ -24,30 +24,6 @@

#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)

-/* Release the DSP processor from reset */
-static int k3_dsp_rproc_release(struct k3_rproc *kproc)
-{
- struct device *dev = kproc->dev;
- int ret;
-
- if (kproc->data->uses_lreset) {
- ret = reset_control_deassert(kproc->reset);
- if (ret) {
- dev_err(dev, "local-reset deassert failed, (%pe)\n", ERR_PTR(ret));
- if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
- kproc->ti_sci_id))
- dev_warn(dev, "module-reset assert back failed\n");
- }
- } else {
- ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
- kproc->ti_sci_id);
- if (ret)
- dev_err(dev, "module-reset deassert failed (%pe)\n", ERR_PTR(ret));
- }
-
- return ret;
-}
-
static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;
@@ -156,7 +132,7 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
if (ret)
return ret;

- ret = k3_dsp_rproc_release(kproc);
+ ret = k3_rproc_release(kproc);
if (ret)
return ret;

diff --git a/drivers/remoteproc/ti_k3_m4_remoteproc.c b/drivers/remoteproc/ti_k3_m4_remoteproc.c
index 74f1b6c0a9562..aba3672facce0 100644
--- a/drivers/remoteproc/ti_k3_m4_remoteproc.c
+++ b/drivers/remoteproc/ti_k3_m4_remoteproc.c
@@ -21,30 +21,6 @@
#include "ti_sci_proc.h"
#include "ti_k3_common.h"

-/* Release the M4 remote processor from reset */
-static int k3_m4_rproc_release(struct k3_rproc *kproc)
-{
- struct device *dev = kproc->dev;
- int ret;
-
- if (kproc->data->uses_lreset) {
- ret = reset_control_deassert(kproc->reset);
- if (ret) {
- dev_err(dev, "local-reset deassert failed, ret = %d\n", ret);
- if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
- kproc->ti_sci_id))
- dev_warn(dev, "module-reset assert back failed\n");
- }
- } else {
- ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
- kproc->ti_sci_id);
- if (ret)
- dev_err(dev, "module-reset deassert failed, ret = %d\n", ret);
- }
-
- return ret;
-}
-
static int k3_m4_rproc_ping_mbox(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
@@ -377,7 +353,7 @@ static int k3_m4_rproc_start(struct rproc *rproc)
if (ret)
return ret;

- ret = k3_m4_rproc_release(kproc);
+ ret = k3_rproc_release(kproc);

return ret;
}
--
2.34.1