Skip to content

Commit ecadd76

Browse files
MrVanmathieupoirier
authored andcommitted
remoteproc: imx_rproc: Simplify IMX_RPROC_SMC switch case
Introduce imx_rproc_arm_smc_{start, stop, detect_mode}() helper functions for all i.MX variants using IMX_RPROC_SMC to manage remote processors. This allows the removal of the IMX_RPROC_SMC switch-case blocks from imx_rproc_start(), imx_rproc_stop(), and imx_rproc_detect_mode(), resulting in cleaner and more maintainable code. Since this is the last switch in imx_rproc_{start,stop}{}, remove the switch-case. 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-5-10386685b8a9@nxp.com Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
1 parent b7ea858 commit ecadd76

1 file changed

Lines changed: 43 additions & 26 deletions

File tree

drivers/remoteproc/imx_rproc.c

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ static const struct imx_rproc_att imx_rproc_att_imx6sx[] = {
285285
{ 0x80000000, 0x80000000, 0x60000000, 0 },
286286
};
287287

288+
static int imx_rproc_arm_smc_start(struct rproc *rproc)
289+
{
290+
struct arm_smccc_res res;
291+
292+
arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_START, 0, 0, 0, 0, 0, 0, &res);
293+
294+
return res.a0;
295+
}
296+
288297
static int imx_rproc_mmio_start(struct rproc *rproc)
289298
{
290299
struct imx_rproc *priv = rproc->priv;
@@ -308,7 +317,6 @@ static int imx_rproc_start(struct rproc *rproc)
308317
struct imx_rproc *priv = rproc->priv;
309318
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
310319
struct device *dev = priv->dev;
311-
struct arm_smccc_res res;
312320
int ret;
313321

314322
ret = imx_rproc_xtr_mbox_init(rproc, true);
@@ -320,14 +328,7 @@ static int imx_rproc_start(struct rproc *rproc)
320328
goto start_ret;
321329
}
322330

323-
switch (dcfg->method) {
324-
case IMX_RPROC_SMC:
325-
arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_START, 0, 0, 0, 0, 0, 0, &res);
326-
ret = res.a0;
327-
break;
328-
default:
329-
return -EOPNOTSUPP;
330-
}
331+
return -EOPNOTSUPP;
331332

332333
start_ret:
333334
if (ret)
@@ -336,6 +337,18 @@ static int imx_rproc_start(struct rproc *rproc)
336337
return ret;
337338
}
338339

340+
static int imx_rproc_arm_smc_stop(struct rproc *rproc)
341+
{
342+
struct imx_rproc *priv = rproc->priv;
343+
struct arm_smccc_res res;
344+
345+
arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STOP, 0, 0, 0, 0, 0, 0, &res);
346+
if (res.a1)
347+
dev_info(priv->dev, "Not in wfi, force stopped\n");
348+
349+
return res.a0;
350+
}
351+
339352
static int imx_rproc_mmio_stop(struct rproc *rproc)
340353
{
341354
struct imx_rproc *priv = rproc->priv;
@@ -365,24 +378,14 @@ static int imx_rproc_stop(struct rproc *rproc)
365378
struct imx_rproc *priv = rproc->priv;
366379
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
367380
struct device *dev = priv->dev;
368-
struct arm_smccc_res res;
369381
int ret;
370382

371383
if (dcfg->ops && dcfg->ops->stop) {
372384
ret = dcfg->ops->stop(rproc);
373385
goto stop_ret;
374386
}
375387

376-
switch (dcfg->method) {
377-
case IMX_RPROC_SMC:
378-
arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STOP, 0, 0, 0, 0, 0, 0, &res);
379-
ret = res.a0;
380-
if (res.a1)
381-
dev_info(dev, "Not in wfi, force stopped\n");
382-
break;
383-
default:
384-
return -EOPNOTSUPP;
385-
}
388+
return -EOPNOTSUPP;
386389

387390
stop_ret:
388391
if (ret)
@@ -867,6 +870,18 @@ static int imx_rproc_attach_pd(struct imx_rproc *priv)
867870
return 0;
868871
}
869872

873+
static int imx_rproc_arm_smc_detect_mode(struct rproc *rproc)
874+
{
875+
struct imx_rproc *priv = rproc->priv;
876+
struct arm_smccc_res res;
877+
878+
arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STARTED, 0, 0, 0, 0, 0, 0, &res);
879+
if (res.a0)
880+
priv->rproc->state = RPROC_DETACHED;
881+
882+
return 0;
883+
}
884+
870885
static int imx_rproc_mmio_detect_mode(struct rproc *rproc)
871886
{
872887
const struct regmap_config config = { .name = "imx-rproc" };
@@ -981,7 +996,6 @@ static int imx_rproc_scu_api_detect_mode(struct rproc *rproc)
981996
static int imx_rproc_detect_mode(struct imx_rproc *priv)
982997
{
983998
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
984-
struct arm_smccc_res res;
985999

9861000
if (dcfg->ops && dcfg->ops->detect_mode)
9871001
return dcfg->ops->detect_mode(priv->rproc);
@@ -990,11 +1004,6 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
9901004
case IMX_RPROC_NONE:
9911005
priv->rproc->state = RPROC_DETACHED;
9921006
return 0;
993-
case IMX_RPROC_SMC:
994-
arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STARTED, 0, 0, 0, 0, 0, 0, &res);
995-
if (res.a0)
996-
priv->rproc->state = RPROC_DETACHED;
997-
return 0;
9981007
default:
9991008
break;
10001009
}
@@ -1170,6 +1179,12 @@ static void imx_rproc_remove(struct platform_device *pdev)
11701179
destroy_workqueue(priv->workqueue);
11711180
}
11721181

1182+
static const struct imx_rproc_plat_ops imx_rproc_ops_arm_smc = {
1183+
.start = imx_rproc_arm_smc_start,
1184+
.stop = imx_rproc_arm_smc_stop,
1185+
.detect_mode = imx_rproc_arm_smc_detect_mode,
1186+
};
1187+
11731188
static const struct imx_rproc_plat_ops imx_rproc_ops_mmio = {
11741189
.start = imx_rproc_mmio_start,
11751190
.stop = imx_rproc_mmio_stop,
@@ -1199,6 +1214,7 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mn = {
11991214
.att = imx_rproc_att_imx8mn,
12001215
.att_size = ARRAY_SIZE(imx_rproc_att_imx8mn),
12011216
.method = IMX_RPROC_SMC,
1217+
.ops = &imx_rproc_ops_arm_smc,
12021218
};
12031219

12041220
static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
@@ -1265,6 +1281,7 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx93 = {
12651281
.att = imx_rproc_att_imx93,
12661282
.att_size = ARRAY_SIZE(imx_rproc_att_imx93),
12671283
.method = IMX_RPROC_SMC,
1284+
.ops = &imx_rproc_ops_arm_smc,
12681285
};
12691286

12701287
static const struct of_device_id imx_rproc_of_match[] = {

0 commit comments

Comments
 (0)