Skip to content

Commit 3f6905f

Browse files
committed
remoteproc: imx_rproc: Convert to dev_pm_domain_attach|detach_list()
Let's avoid the boilerplate code to manage the multiple PM domain case, by converting into using dev_pm_domain_attach|detach_list(). Cc: Bjorn Andersson <andersson@kernel.org> Cc: Shawn Guo <shawnguo@kernel.org> Cc: Sascha Hauer <s.hauer@pengutronix.de> Cc: Daniel Baluta <daniel.baluta@nxp.com> Cc: <linux-remoteproc@vger.kernel.org> Tested-by: Iuliana Prodan <iuliana.prodan@nxp.com> Reviewed-by: Iuliana Prodan <iuliana.prodan@nxp.com> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://lore.kernel.org/r/20240130123951.236243-4-ulf.hansson@linaro.org
1 parent ccd9468 commit 3f6905f

File tree

1 file changed

+9
-64
lines changed

1 file changed

+9
-64
lines changed

drivers/remoteproc/imx_rproc.c

Lines changed: 9 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ struct imx_rproc_mem {
9292

9393
static int imx_rproc_xtr_mbox_init(struct rproc *rproc);
9494
static void imx_rproc_free_mbox(struct rproc *rproc);
95-
static int imx_rproc_detach_pd(struct rproc *rproc);
9695

9796
struct imx_rproc {
9897
struct device *dev;
@@ -113,10 +112,8 @@ struct imx_rproc {
113112
u32 rproc_pt; /* partition id */
114113
u32 rsrc_id; /* resource id */
115114
u32 entry; /* cpu start address */
116-
int num_pd;
117115
u32 core_index;
118-
struct device **pd_dev;
119-
struct device_link **pd_dev_link;
116+
struct dev_pm_domain_list *pd_list;
120117
};
121118

122119
static const struct imx_rproc_att imx_rproc_att_imx93[] = {
@@ -853,7 +850,7 @@ static void imx_rproc_put_scu(struct rproc *rproc)
853850
return;
854851

855852
if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id)) {
856-
imx_rproc_detach_pd(rproc);
853+
dev_pm_domain_detach_list(priv->pd_list);
857854
return;
858855
}
859856

@@ -880,72 +877,20 @@ static int imx_rproc_partition_notify(struct notifier_block *nb,
880877
static int imx_rproc_attach_pd(struct imx_rproc *priv)
881878
{
882879
struct device *dev = priv->dev;
883-
int ret, i;
884-
885-
/*
886-
* If there is only one power-domain entry, the platform driver framework
887-
* will handle it, no need handle it in this driver.
888-
*/
889-
priv->num_pd = of_count_phandle_with_args(dev->of_node, "power-domains",
890-
"#power-domain-cells");
891-
if (priv->num_pd <= 1)
892-
return 0;
893-
894-
priv->pd_dev = devm_kmalloc_array(dev, priv->num_pd, sizeof(*priv->pd_dev), GFP_KERNEL);
895-
if (!priv->pd_dev)
896-
return -ENOMEM;
897-
898-
priv->pd_dev_link = devm_kmalloc_array(dev, priv->num_pd, sizeof(*priv->pd_dev_link),
899-
GFP_KERNEL);
900-
901-
if (!priv->pd_dev_link)
902-
return -ENOMEM;
903-
904-
for (i = 0; i < priv->num_pd; i++) {
905-
priv->pd_dev[i] = dev_pm_domain_attach_by_id(dev, i);
906-
if (IS_ERR(priv->pd_dev[i])) {
907-
ret = PTR_ERR(priv->pd_dev[i]);
908-
goto detach_pd;
909-
}
910-
911-
priv->pd_dev_link[i] = device_link_add(dev, priv->pd_dev[i], DL_FLAG_STATELESS |
912-
DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE);
913-
if (!priv->pd_dev_link[i]) {
914-
dev_pm_domain_detach(priv->pd_dev[i], false);
915-
ret = -EINVAL;
916-
goto detach_pd;
917-
}
918-
}
919-
920-
return 0;
921-
922-
detach_pd:
923-
while (--i >= 0) {
924-
device_link_del(priv->pd_dev_link[i]);
925-
dev_pm_domain_detach(priv->pd_dev[i], false);
926-
}
927-
928-
return ret;
929-
}
930-
931-
static int imx_rproc_detach_pd(struct rproc *rproc)
932-
{
933-
struct imx_rproc *priv = rproc->priv;
934-
int i;
880+
int ret;
881+
struct dev_pm_domain_attach_data pd_data = {
882+
.pd_flags = PD_FLAG_DEV_LINK_ON,
883+
};
935884

936885
/*
937886
* If there is only one power-domain entry, the platform driver framework
938887
* will handle it, no need handle it in this driver.
939888
*/
940-
if (priv->num_pd <= 1)
889+
if (dev->pm_domain)
941890
return 0;
942891

943-
for (i = 0; i < priv->num_pd; i++) {
944-
device_link_del(priv->pd_dev_link[i]);
945-
dev_pm_domain_detach(priv->pd_dev[i], false);
946-
}
947-
948-
return 0;
892+
ret = dev_pm_domain_attach_list(dev, &pd_data, &priv->pd_list);
893+
return ret < 0 ? ret : 0;
949894
}
950895

951896
static int imx_rproc_detect_mode(struct imx_rproc *priv)

0 commit comments

Comments
 (0)