Skip to content

Commit b7ea858

Browse files
MrVanmathieupoirier
authored andcommitted
remoteproc: imx_rproc: Simplify IMX_RPROC_SCU_API switch case
Introduce imx_rproc_scu_api_{start, stop, detect_mode}() helper functions for all i.MX variants using IMX_RPROC_SCU_API to manage remote processors. This allows the removal of the IMX_RPROC_SCU_API switch-case blocks from imx_rproc_start(), imx_rproc_stop(), and imx_rproc_detect_mode(), resulting in cleaner and more maintainable code. No functional changes. Reviewed-by: Frank Li <Frank.Li@nxp.com> Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com> Signed-off-by: Peng Fan <peng.fan@nxp.com> Link: https://lore.kernel.org/r/20250910-imx-rproc-cleanup-v2-4-10386685b8a9@nxp.com Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
1 parent e14168b commit b7ea858

1 file changed

Lines changed: 85 additions & 64 deletions

File tree

drivers/remoteproc/imx_rproc.c

Lines changed: 85 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ static int imx_rproc_mmio_start(struct rproc *rproc)
296296
return regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, dcfg->src_start);
297297
}
298298

299+
static int imx_rproc_scu_api_start(struct rproc *rproc)
300+
{
301+
struct imx_rproc *priv = rproc->priv;
302+
303+
return imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, true, priv->entry);
304+
}
305+
299306
static int imx_rproc_start(struct rproc *rproc)
300307
{
301308
struct imx_rproc *priv = rproc->priv;
@@ -318,9 +325,6 @@ static int imx_rproc_start(struct rproc *rproc)
318325
arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_START, 0, 0, 0, 0, 0, 0, &res);
319326
ret = res.a0;
320327
break;
321-
case IMX_RPROC_SCU_API:
322-
ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, true, priv->entry);
323-
break;
324328
default:
325329
return -EOPNOTSUPP;
326330
}
@@ -349,6 +353,13 @@ static int imx_rproc_mmio_stop(struct rproc *rproc)
349353
return regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, dcfg->src_stop);
350354
}
351355

356+
static int imx_rproc_scu_api_stop(struct rproc *rproc)
357+
{
358+
struct imx_rproc *priv = rproc->priv;
359+
360+
return imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, false, priv->entry);
361+
}
362+
352363
static int imx_rproc_stop(struct rproc *rproc)
353364
{
354365
struct imx_rproc *priv = rproc->priv;
@@ -369,9 +380,6 @@ static int imx_rproc_stop(struct rproc *rproc)
369380
if (res.a1)
370381
dev_info(dev, "Not in wfi, force stopped\n");
371382
break;
372-
case IMX_RPROC_SCU_API:
373-
ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, false, priv->entry);
374-
break;
375383
default:
376384
return -EOPNOTSUPP;
377385
}
@@ -907,14 +915,74 @@ static int imx_rproc_mmio_detect_mode(struct rproc *rproc)
907915
return 0;
908916
}
909917

910-
static int imx_rproc_detect_mode(struct imx_rproc *priv)
918+
static int imx_rproc_scu_api_detect_mode(struct rproc *rproc)
911919
{
912-
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
920+
struct imx_rproc *priv = rproc->priv;
913921
struct device *dev = priv->dev;
914-
struct arm_smccc_res res;
915922
int ret;
916923
u8 pt;
917924

925+
ret = imx_scu_get_handle(&priv->ipc_handle);
926+
if (ret)
927+
return ret;
928+
ret = of_property_read_u32(dev->of_node, "fsl,resource-id", &priv->rsrc_id);
929+
if (ret) {
930+
dev_err(dev, "No fsl,resource-id property\n");
931+
return ret;
932+
}
933+
934+
if (priv->rsrc_id == IMX_SC_R_M4_1_PID0)
935+
priv->core_index = 1;
936+
else
937+
priv->core_index = 0;
938+
939+
/*
940+
* If Mcore resource is not owned by Acore partition, It is kicked by ROM,
941+
* and Linux could only do IPC with Mcore and nothing else.
942+
*/
943+
if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id)) {
944+
if (of_property_read_u32(dev->of_node, "fsl,entry-address", &priv->entry))
945+
return -EINVAL;
946+
947+
return imx_rproc_attach_pd(priv);
948+
}
949+
950+
priv->rproc->state = RPROC_DETACHED;
951+
priv->rproc->recovery_disabled = false;
952+
rproc_set_feature(priv->rproc, RPROC_FEAT_ATTACH_ON_RECOVERY);
953+
954+
/* Get partition id and enable irq in SCFW */
955+
ret = imx_sc_rm_get_resource_owner(priv->ipc_handle, priv->rsrc_id, &pt);
956+
if (ret) {
957+
dev_err(dev, "not able to get resource owner\n");
958+
return ret;
959+
}
960+
961+
priv->rproc_pt = pt;
962+
priv->rproc_nb.notifier_call = imx_rproc_partition_notify;
963+
964+
ret = imx_scu_irq_register_notifier(&priv->rproc_nb);
965+
if (ret) {
966+
dev_err(dev, "register scu notifier failed, %d\n", ret);
967+
return ret;
968+
}
969+
970+
ret = imx_scu_irq_group_enable(IMX_SC_IRQ_GROUP_REBOOTED, BIT(priv->rproc_pt),
971+
true);
972+
if (ret) {
973+
imx_scu_irq_unregister_notifier(&priv->rproc_nb);
974+
dev_err(dev, "Enable irq failed, %d\n", ret);
975+
return ret;
976+
}
977+
978+
return 0;
979+
}
980+
981+
static int imx_rproc_detect_mode(struct imx_rproc *priv)
982+
{
983+
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
984+
struct arm_smccc_res res;
985+
918986
if (dcfg->ops && dcfg->ops->detect_mode)
919987
return dcfg->ops->detect_mode(priv->rproc);
920988

@@ -927,61 +995,6 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
927995
if (res.a0)
928996
priv->rproc->state = RPROC_DETACHED;
929997
return 0;
930-
case IMX_RPROC_SCU_API:
931-
ret = imx_scu_get_handle(&priv->ipc_handle);
932-
if (ret)
933-
return ret;
934-
ret = of_property_read_u32(dev->of_node, "fsl,resource-id", &priv->rsrc_id);
935-
if (ret) {
936-
dev_err(dev, "No fsl,resource-id property\n");
937-
return ret;
938-
}
939-
940-
if (priv->rsrc_id == IMX_SC_R_M4_1_PID0)
941-
priv->core_index = 1;
942-
else
943-
priv->core_index = 0;
944-
945-
/*
946-
* If Mcore resource is not owned by Acore partition, It is kicked by ROM,
947-
* and Linux could only do IPC with Mcore and nothing else.
948-
*/
949-
if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id)) {
950-
if (of_property_read_u32(dev->of_node, "fsl,entry-address", &priv->entry))
951-
return -EINVAL;
952-
953-
return imx_rproc_attach_pd(priv);
954-
}
955-
956-
priv->rproc->state = RPROC_DETACHED;
957-
priv->rproc->recovery_disabled = false;
958-
rproc_set_feature(priv->rproc, RPROC_FEAT_ATTACH_ON_RECOVERY);
959-
960-
/* Get partition id and enable irq in SCFW */
961-
ret = imx_sc_rm_get_resource_owner(priv->ipc_handle, priv->rsrc_id, &pt);
962-
if (ret) {
963-
dev_err(dev, "not able to get resource owner\n");
964-
return ret;
965-
}
966-
967-
priv->rproc_pt = pt;
968-
priv->rproc_nb.notifier_call = imx_rproc_partition_notify;
969-
970-
ret = imx_scu_irq_register_notifier(&priv->rproc_nb);
971-
if (ret) {
972-
dev_err(dev, "register scu notifier failed, %d\n", ret);
973-
return ret;
974-
}
975-
976-
ret = imx_scu_irq_group_enable(IMX_SC_IRQ_GROUP_REBOOTED, BIT(priv->rproc_pt),
977-
true);
978-
if (ret) {
979-
imx_scu_irq_unregister_notifier(&priv->rproc_nb);
980-
dev_err(dev, "Enable irq failed, %d\n", ret);
981-
return ret;
982-
}
983-
984-
return 0;
985998
default:
986999
break;
9871000
}
@@ -1163,6 +1176,12 @@ static const struct imx_rproc_plat_ops imx_rproc_ops_mmio = {
11631176
.detect_mode = imx_rproc_mmio_detect_mode,
11641177
};
11651178

1179+
static const struct imx_rproc_plat_ops imx_rproc_ops_scu_api = {
1180+
.start = imx_rproc_scu_api_start,
1181+
.stop = imx_rproc_scu_api_stop,
1182+
.detect_mode = imx_rproc_scu_api_detect_mode,
1183+
};
1184+
11661185
static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mn_mmio = {
11671186
.src_reg = IMX7D_SRC_SCR,
11681187
.src_mask = IMX7D_M4_RST_MASK,
@@ -1197,12 +1216,14 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx8qm = {
11971216
.att = imx_rproc_att_imx8qm,
11981217
.att_size = ARRAY_SIZE(imx_rproc_att_imx8qm),
11991218
.method = IMX_RPROC_SCU_API,
1219+
.ops = &imx_rproc_ops_scu_api,
12001220
};
12011221

12021222
static const struct imx_rproc_dcfg imx_rproc_cfg_imx8qxp = {
12031223
.att = imx_rproc_att_imx8qxp,
12041224
.att_size = ARRAY_SIZE(imx_rproc_att_imx8qxp),
12051225
.method = IMX_RPROC_SCU_API,
1226+
.ops = &imx_rproc_ops_scu_api,
12061227
};
12071228

12081229
static const struct imx_rproc_dcfg imx_rproc_cfg_imx8ulp = {

0 commit comments

Comments
 (0)