Skip to content

Commit de27700

Browse files
3V3RYONEmathieupoirier
authored andcommitted
remoteproc: k3: Refactor .prepare rproc ops into common driver
The .prepare rproc ops implementations in TI K3 DSP and M4 remoteproc drivers deasserts the local and module reset of the processor to allow firmware loading into internal memory. Refactor the implementations into the ti_k3_common.c driver as k3_rproc_prepare() and register this common function as .prepare ops in the DSP and M4 drivers. Signed-off-by: Beleswar Padhi <[email protected]> Tested-by: Judith Mendez <[email protected]> Reviewed-by: Andrew Davis <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent b80151c commit de27700

File tree

4 files changed

+49
-90
lines changed

4 files changed

+49
-90
lines changed

drivers/remoteproc/ti_k3_common.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,51 @@ int k3_rproc_request_mbox(struct rproc *rproc)
191191
}
192192
EXPORT_SYMBOL_GPL(k3_rproc_request_mbox);
193193

194+
/*
195+
* The K3 DSP and M4 cores have a local reset that affects only the CPU, and a
196+
* generic module reset that powers on the device and allows the internal
197+
* memories to be accessed while the local reset is asserted. This function is
198+
* used to release the global reset on remote cores to allow loading into the
199+
* internal RAMs. The .prepare() ops is invoked by remoteproc core before any
200+
* firmware loading, and is followed by the .start() ops after loading to
201+
* actually let the remote cores to run.
202+
*/
203+
int k3_rproc_prepare(struct rproc *rproc)
204+
{
205+
struct k3_rproc *kproc = rproc->priv;
206+
struct device *dev = kproc->dev;
207+
int ret;
208+
209+
/* If the core is running already no need to deassert the module reset */
210+
if (rproc->state == RPROC_DETACHED)
211+
return 0;
212+
213+
/*
214+
* Ensure the local reset is asserted so the core doesn't
215+
* execute bogus code when the module reset is released.
216+
*/
217+
if (kproc->data->uses_lreset) {
218+
ret = k3_rproc_reset(kproc);
219+
if (ret)
220+
return ret;
221+
222+
ret = reset_control_status(kproc->reset);
223+
if (ret <= 0) {
224+
dev_err(dev, "local reset still not asserted\n");
225+
return ret;
226+
}
227+
}
228+
229+
ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
230+
kproc->ti_sci_id);
231+
if (ret) {
232+
dev_err(dev, "could not deassert module-reset for internal RAM loading\n");
233+
return ret;
234+
}
235+
236+
return 0;
237+
}
238+
EXPORT_SYMBOL_GPL(k3_rproc_prepare);
239+
194240
MODULE_LICENSE("GPL");
195241
MODULE_DESCRIPTION("TI K3 common Remoteproc code");

drivers/remoteproc/ti_k3_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,5 @@ void k3_rproc_kick(struct rproc *rproc, int vqid);
9898
int k3_rproc_reset(struct k3_rproc *kproc);
9999
int k3_rproc_release(struct k3_rproc *kproc);
100100
int k3_rproc_request_mbox(struct rproc *rproc);
101+
int k3_rproc_prepare(struct rproc *rproc);
101102
#endif /* REMOTEPROC_TI_K3_COMMON_H */

drivers/remoteproc/ti_k3_dsp_remoteproc.c

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,6 @@
2424

2525
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
2626

27-
/*
28-
* The C66x DSP cores have a local reset that affects only the CPU, and a
29-
* generic module reset that powers on the device and allows the DSP internal
30-
* memories to be accessed while the local reset is asserted. This function is
31-
* used to release the global reset on C66x DSPs to allow loading into the DSP
32-
* internal RAMs. The .prepare() ops is invoked by remoteproc core before any
33-
* firmware loading, and is followed by the .start() ops after loading to
34-
* actually let the C66x DSP cores run. This callback is invoked only in
35-
* remoteproc mode.
36-
*/
37-
static int k3_dsp_rproc_prepare(struct rproc *rproc)
38-
{
39-
struct k3_rproc *kproc = rproc->priv;
40-
struct device *dev = kproc->dev;
41-
int ret;
42-
43-
/* If the core is running already no need to deassert the module reset */
44-
if (rproc->state == RPROC_DETACHED)
45-
return 0;
46-
47-
/*
48-
* Ensure the local reset is asserted so the core doesn't
49-
* execute bogus code when the module reset is released.
50-
*/
51-
if (kproc->data->uses_lreset) {
52-
ret = k3_rproc_reset(kproc);
53-
if (ret)
54-
return ret;
55-
56-
ret = reset_control_status(kproc->reset);
57-
if (ret <= 0) {
58-
dev_err(dev, "local reset still not asserted\n");
59-
return ret;
60-
}
61-
}
62-
63-
ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
64-
kproc->ti_sci_id);
65-
if (ret)
66-
dev_err(dev, "module-reset deassert failed, cannot enable internal RAM loading (%pe)\n",
67-
ERR_PTR(ret));
68-
69-
return ret;
70-
}
71-
7227
/*
7328
* This function implements the .unprepare() ops and performs the complimentary
7429
* operations to that of the .prepare() ops. The function is used to assert the
@@ -428,7 +383,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
428383
rproc->has_iommu = false;
429384
rproc->recovery_disabled = true;
430385
if (data->uses_lreset) {
431-
rproc->ops->prepare = k3_dsp_rproc_prepare;
386+
rproc->ops->prepare = k3_rproc_prepare;
432387
rproc->ops->unprepare = k3_dsp_rproc_unprepare;
433388
}
434389
kproc = rproc->priv;

drivers/remoteproc/ti_k3_m4_remoteproc.c

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,6 @@
2121
#include "ti_sci_proc.h"
2222
#include "ti_k3_common.h"
2323

24-
/*
25-
* The M4 cores have a local reset that affects only the CPU, and a
26-
* generic module reset that powers on the device and allows the internal
27-
* memories to be accessed while the local reset is asserted. This function is
28-
* used to release the global reset on remote cores to allow loading into the
29-
* internal RAMs. The .prepare() ops is invoked by remoteproc core before any
30-
* firmware loading, and is followed by the .start() ops after loading to
31-
* actually let the remote cores to run.
32-
*/
33-
static int k3_m4_rproc_prepare(struct rproc *rproc)
34-
{
35-
struct k3_rproc *kproc = rproc->priv;
36-
struct device *dev = kproc->dev;
37-
int ret;
38-
39-
/* If the core is running already no need to deassert the module reset */
40-
if (rproc->state == RPROC_DETACHED)
41-
return 0;
42-
43-
/*
44-
* Ensure the local reset is asserted so the core doesn't
45-
* execute bogus code when the module reset is released.
46-
*/
47-
ret = k3_rproc_reset(kproc);
48-
if (ret)
49-
return ret;
50-
51-
ret = reset_control_status(kproc->reset);
52-
if (ret <= 0) {
53-
dev_err(dev, "local reset still not asserted\n");
54-
return ret;
55-
}
56-
57-
ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
58-
kproc->ti_sci_id);
59-
if (ret) {
60-
dev_err(dev, "could not deassert module-reset for internal RAM loading\n");
61-
return ret;
62-
}
63-
64-
return 0;
65-
}
66-
6724
/*
6825
* This function implements the .unprepare() ops and performs the complimentary
6926
* operations to that of the .prepare() ops. The function is used to assert the
@@ -368,7 +325,7 @@ static int k3_m4_rproc_detach(struct rproc *rproc)
368325
}
369326

370327
static const struct rproc_ops k3_m4_rproc_ops = {
371-
.prepare = k3_m4_rproc_prepare,
328+
.prepare = k3_rproc_prepare,
372329
.unprepare = k3_m4_rproc_unprepare,
373330
.start = k3_m4_rproc_start,
374331
.stop = k3_m4_rproc_stop,

0 commit comments

Comments
 (0)