Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Peng Fan and committed by
Mathieu Poirier
b7ea858a e14168bf

+85 -64
+85 -64
drivers/remoteproc/imx_rproc.c
··· 296 296 return regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, dcfg->src_start); 297 297 } 298 298 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 + 299 306 static int imx_rproc_start(struct rproc *rproc) 300 307 { 301 308 struct imx_rproc *priv = rproc->priv; ··· 324 317 case IMX_RPROC_SMC: 325 318 arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_START, 0, 0, 0, 0, 0, 0, &res); 326 319 ret = res.a0; 327 - break; 328 - case IMX_RPROC_SCU_API: 329 - ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, true, priv->entry); 330 320 break; 331 321 default: 332 322 return -EOPNOTSUPP; ··· 353 349 return regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, dcfg->src_stop); 354 350 } 355 351 352 + static int imx_rproc_scu_api_stop(struct rproc *rproc) 353 + { 354 + struct imx_rproc *priv = rproc->priv; 355 + 356 + return imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, false, priv->entry); 357 + } 358 + 356 359 static int imx_rproc_stop(struct rproc *rproc) 357 360 { 358 361 struct imx_rproc *priv = rproc->priv; ··· 379 368 ret = res.a0; 380 369 if (res.a1) 381 370 dev_info(dev, "Not in wfi, force stopped\n"); 382 - break; 383 - case IMX_RPROC_SCU_API: 384 - ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, false, priv->entry); 385 371 break; 386 372 default: 387 373 return -EOPNOTSUPP; ··· 915 907 return 0; 916 908 } 917 909 910 + static int imx_rproc_scu_api_detect_mode(struct rproc *rproc) 911 + { 912 + struct imx_rproc *priv = rproc->priv; 913 + struct device *dev = priv->dev; 914 + int ret; 915 + u8 pt; 916 + 917 + ret = imx_scu_get_handle(&priv->ipc_handle); 918 + if (ret) 919 + return ret; 920 + ret = of_property_read_u32(dev->of_node, "fsl,resource-id", &priv->rsrc_id); 921 + if (ret) { 922 + dev_err(dev, "No fsl,resource-id property\n"); 923 + return ret; 924 + } 925 + 926 + if (priv->rsrc_id == IMX_SC_R_M4_1_PID0) 927 + priv->core_index = 1; 928 + else 929 + priv->core_index = 0; 930 + 931 + /* 932 + * If Mcore resource is not owned by Acore partition, It is kicked by ROM, 933 + * and Linux could only do IPC with Mcore and nothing else. 934 + */ 935 + if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id)) { 936 + if (of_property_read_u32(dev->of_node, "fsl,entry-address", &priv->entry)) 937 + return -EINVAL; 938 + 939 + return imx_rproc_attach_pd(priv); 940 + } 941 + 942 + priv->rproc->state = RPROC_DETACHED; 943 + priv->rproc->recovery_disabled = false; 944 + rproc_set_feature(priv->rproc, RPROC_FEAT_ATTACH_ON_RECOVERY); 945 + 946 + /* Get partition id and enable irq in SCFW */ 947 + ret = imx_sc_rm_get_resource_owner(priv->ipc_handle, priv->rsrc_id, &pt); 948 + if (ret) { 949 + dev_err(dev, "not able to get resource owner\n"); 950 + return ret; 951 + } 952 + 953 + priv->rproc_pt = pt; 954 + priv->rproc_nb.notifier_call = imx_rproc_partition_notify; 955 + 956 + ret = imx_scu_irq_register_notifier(&priv->rproc_nb); 957 + if (ret) { 958 + dev_err(dev, "register scu notifier failed, %d\n", ret); 959 + return ret; 960 + } 961 + 962 + ret = imx_scu_irq_group_enable(IMX_SC_IRQ_GROUP_REBOOTED, BIT(priv->rproc_pt), 963 + true); 964 + if (ret) { 965 + imx_scu_irq_unregister_notifier(&priv->rproc_nb); 966 + dev_err(dev, "Enable irq failed, %d\n", ret); 967 + return ret; 968 + } 969 + 970 + return 0; 971 + } 972 + 918 973 static int imx_rproc_detect_mode(struct imx_rproc *priv) 919 974 { 920 975 const struct imx_rproc_dcfg *dcfg = priv->dcfg; 921 - struct device *dev = priv->dev; 922 976 struct arm_smccc_res res; 923 - int ret; 924 - u8 pt; 925 977 926 978 if (dcfg->ops && dcfg->ops->detect_mode) 927 979 return dcfg->ops->detect_mode(priv->rproc); ··· 994 926 arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_STARTED, 0, 0, 0, 0, 0, 0, &res); 995 927 if (res.a0) 996 928 priv->rproc->state = RPROC_DETACHED; 997 - return 0; 998 - case IMX_RPROC_SCU_API: 999 - ret = imx_scu_get_handle(&priv->ipc_handle); 1000 - if (ret) 1001 - return ret; 1002 - ret = of_property_read_u32(dev->of_node, "fsl,resource-id", &priv->rsrc_id); 1003 - if (ret) { 1004 - dev_err(dev, "No fsl,resource-id property\n"); 1005 - return ret; 1006 - } 1007 - 1008 - if (priv->rsrc_id == IMX_SC_R_M4_1_PID0) 1009 - priv->core_index = 1; 1010 - else 1011 - priv->core_index = 0; 1012 - 1013 - /* 1014 - * If Mcore resource is not owned by Acore partition, It is kicked by ROM, 1015 - * and Linux could only do IPC with Mcore and nothing else. 1016 - */ 1017 - if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id)) { 1018 - if (of_property_read_u32(dev->of_node, "fsl,entry-address", &priv->entry)) 1019 - return -EINVAL; 1020 - 1021 - return imx_rproc_attach_pd(priv); 1022 - } 1023 - 1024 - priv->rproc->state = RPROC_DETACHED; 1025 - priv->rproc->recovery_disabled = false; 1026 - rproc_set_feature(priv->rproc, RPROC_FEAT_ATTACH_ON_RECOVERY); 1027 - 1028 - /* Get partition id and enable irq in SCFW */ 1029 - ret = imx_sc_rm_get_resource_owner(priv->ipc_handle, priv->rsrc_id, &pt); 1030 - if (ret) { 1031 - dev_err(dev, "not able to get resource owner\n"); 1032 - return ret; 1033 - } 1034 - 1035 - priv->rproc_pt = pt; 1036 - priv->rproc_nb.notifier_call = imx_rproc_partition_notify; 1037 - 1038 - ret = imx_scu_irq_register_notifier(&priv->rproc_nb); 1039 - if (ret) { 1040 - dev_err(dev, "register scu notifier failed, %d\n", ret); 1041 - return ret; 1042 - } 1043 - 1044 - ret = imx_scu_irq_group_enable(IMX_SC_IRQ_GROUP_REBOOTED, BIT(priv->rproc_pt), 1045 - true); 1046 - if (ret) { 1047 - imx_scu_irq_unregister_notifier(&priv->rproc_nb); 1048 - dev_err(dev, "Enable irq failed, %d\n", ret); 1049 - return ret; 1050 - } 1051 - 1052 929 return 0; 1053 930 default: 1054 931 break; ··· 1176 1163 .detect_mode = imx_rproc_mmio_detect_mode, 1177 1164 }; 1178 1165 1166 + static const struct imx_rproc_plat_ops imx_rproc_ops_scu_api = { 1167 + .start = imx_rproc_scu_api_start, 1168 + .stop = imx_rproc_scu_api_stop, 1169 + .detect_mode = imx_rproc_scu_api_detect_mode, 1170 + }; 1171 + 1179 1172 static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mn_mmio = { 1180 1173 .src_reg = IMX7D_SRC_SCR, 1181 1174 .src_mask = IMX7D_M4_RST_MASK, ··· 1216 1197 .att = imx_rproc_att_imx8qm, 1217 1198 .att_size = ARRAY_SIZE(imx_rproc_att_imx8qm), 1218 1199 .method = IMX_RPROC_SCU_API, 1200 + .ops = &imx_rproc_ops_scu_api, 1219 1201 }; 1220 1202 1221 1203 static const struct imx_rproc_dcfg imx_rproc_cfg_imx8qxp = { 1222 1204 .att = imx_rproc_att_imx8qxp, 1223 1205 .att_size = ARRAY_SIZE(imx_rproc_att_imx8qxp), 1224 1206 .method = IMX_RPROC_SCU_API, 1207 + .ops = &imx_rproc_ops_scu_api, 1225 1208 }; 1226 1209 1227 1210 static const struct imx_rproc_dcfg imx_rproc_cfg_imx8ulp = {