diff mbox series

[RFC,2/2] ASoC: SOF: Use multi PM domains helpers

Message ID 20200302205700.29746-3-daniel.baluta@oss.nxp.com (mailing list archive)
State New, archived
Headers show
Series Introduce multi PM domains helpers | expand

Commit Message

Daniel Baluta (OSS) March 2, 2020, 8:57 p.m. UTC
From: Daniel Baluta <daniel.baluta@nxp.com>

Use dev_multi_pm_attach / dev_multi_pm_detach instead of the hardcoded
version.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
---
 sound/soc/sof/imx/imx8.c | 54 +++++-----------------------------------
 1 file changed, 6 insertions(+), 48 deletions(-)

Comments

Sridharan, Ranjani March 2, 2020, 9:26 p.m. UTC | #1
On Mon, Mar 2, 2020 at 1:00 PM Daniel Baluta <daniel.baluta@oss.nxp.com>
wrote:

> From: Daniel Baluta <daniel.baluta@nxp.com>
>
> Use dev_multi_pm_attach / dev_multi_pm_detach instead of the hardcoded
> version.
>
> Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
> ---
>  sound/soc/sof/imx/imx8.c | 54 +++++-----------------------------------
>  1 file changed, 6 insertions(+), 48 deletions(-)
>
> diff --git a/sound/soc/sof/imx/imx8.c b/sound/soc/sof/imx/imx8.c
> index b692752b2178..ca740538a2d5 100644
> --- a/sound/soc/sof/imx/imx8.c
> +++ b/sound/soc/sof/imx/imx8.c
> @@ -51,10 +51,7 @@ struct imx8_priv {
>         struct imx_sc_ipc *sc_ipc;
>
>         /* Power domain handling */
> -       int num_domains;
> -       struct device **pd_dev;
> -       struct device_link **link;
> -
> +       struct dev_multi_pm_domain_data *mpd;
>  };
>
>  static void imx8_get_reply(struct snd_sof_dev *sdev)
> @@ -207,7 +204,6 @@ static int imx8_probe(struct snd_sof_dev *sdev)
>         struct resource res;
>         u32 base, size;
>         int ret = 0;
> -       int i;
>
>         priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
>         if (!priv)
> @@ -218,39 +214,9 @@ static int imx8_probe(struct snd_sof_dev *sdev)
>         priv->sdev = sdev;
>
>         /* power up device associated power domains */
> -       priv->num_domains = of_count_phandle_with_args(np, "power-domains",
> -
> "#power-domain-cells");
> -       if (priv->num_domains < 0) {
> -               dev_err(sdev->dev, "no power-domains property in %pOF\n",
> np);
> -               return priv->num_domains;
> -       }
> -
> -       priv->pd_dev = devm_kmalloc_array(&pdev->dev, priv->num_domains,
> -                                         sizeof(*priv->pd_dev),
> GFP_KERNEL);
> -       if (!priv->pd_dev)
> -               return -ENOMEM;
> -
> -       priv->link = devm_kmalloc_array(&pdev->dev, priv->num_domains,
> -                                       sizeof(*priv->link), GFP_KERNEL);
> -       if (!priv->link)
> -               return -ENOMEM;
> -
> -       for (i = 0; i < priv->num_domains; i++) {
> -               priv->pd_dev[i] = dev_pm_domain_attach_by_id(&pdev->dev,
> i);
> -               if (IS_ERR(priv->pd_dev[i])) {
> -                       ret = PTR_ERR(priv->pd_dev[i]);
> -                       goto exit_unroll_pm;
> -               }
> -               priv->link[i] = device_link_add(&pdev->dev,
> priv->pd_dev[i],
> -                                               DL_FLAG_STATELESS |
> -                                               DL_FLAG_PM_RUNTIME |
> -                                               DL_FLAG_RPM_ACTIVE);
> -               if (!priv->link[i]) {
> -                       ret = -ENOMEM;
> -                       dev_pm_domain_detach(priv->pd_dev[i], false);
> -                       goto exit_unroll_pm;
> -               }
> -       }
> +       priv->mpd = dev_multi_pm_attach(&pdev->dev);
> +       if (IS_ERR(priv->mpd))
> +               return PTR_ERR(priv->mpd);
>
>         ret = imx_scu_get_handle(&priv->sc_ipc);
>         if (ret) {
> @@ -329,25 +295,17 @@ static int imx8_probe(struct snd_sof_dev *sdev)
>  exit_pdev_unregister:
>         platform_device_unregister(priv->ipc_dev);
>  exit_unroll_pm:
>
Can we also rename the label to exit_pm_detach maybe? It is no longer an
unroll anymore right?

Thanks,
Ranjani
Daniel Baluta March 3, 2020, 1:17 p.m. UTC | #2
On Mon, Mar 2, 2020 at 11:26 PM Sridharan, Ranjani
<ranjani.sridharan@intel.com> wrote:
>
>
>
> On Mon, Mar 2, 2020 at 1:00 PM Daniel Baluta <daniel.baluta@oss.nxp.com> wrote:
>>
>> From: Daniel Baluta <daniel.baluta@nxp.com>
>>
>> Use dev_multi_pm_attach / dev_multi_pm_detach instead of the hardcoded
>> version.
>>
>> Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
>> ---
>>  sound/soc/sof/imx/imx8.c | 54 +++++-----------------------------------
>>  1 file changed, 6 insertions(+), 48 deletions(-)
>>
>> diff --git a/sound/soc/sof/imx/imx8.c b/sound/soc/sof/imx/imx8.c
>> index b692752b2178..ca740538a2d5 100644
>> --- a/sound/soc/sof/imx/imx8.c
>> +++ b/sound/soc/sof/imx/imx8.c
>> @@ -51,10 +51,7 @@ struct imx8_priv {
>>         struct imx_sc_ipc *sc_ipc;
>>
>>         /* Power domain handling */
>> -       int num_domains;
>> -       struct device **pd_dev;
>> -       struct device_link **link;
>> -
>> +       struct dev_multi_pm_domain_data *mpd;
>>  };
>>
>>  static void imx8_get_reply(struct snd_sof_dev *sdev)
>> @@ -207,7 +204,6 @@ static int imx8_probe(struct snd_sof_dev *sdev)
>>         struct resource res;
>>         u32 base, size;
>>         int ret = 0;
>> -       int i;
>>
>>         priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
>>         if (!priv)
>> @@ -218,39 +214,9 @@ static int imx8_probe(struct snd_sof_dev *sdev)
>>         priv->sdev = sdev;
>>
>>         /* power up device associated power domains */
>> -       priv->num_domains = of_count_phandle_with_args(np, "power-domains",
>> -                                                      "#power-domain-cells");
>> -       if (priv->num_domains < 0) {
>> -               dev_err(sdev->dev, "no power-domains property in %pOF\n", np);
>> -               return priv->num_domains;
>> -       }
>> -
>> -       priv->pd_dev = devm_kmalloc_array(&pdev->dev, priv->num_domains,
>> -                                         sizeof(*priv->pd_dev), GFP_KERNEL);
>> -       if (!priv->pd_dev)
>> -               return -ENOMEM;
>> -
>> -       priv->link = devm_kmalloc_array(&pdev->dev, priv->num_domains,
>> -                                       sizeof(*priv->link), GFP_KERNEL);
>> -       if (!priv->link)
>> -               return -ENOMEM;
>> -
>> -       for (i = 0; i < priv->num_domains; i++) {
>> -               priv->pd_dev[i] = dev_pm_domain_attach_by_id(&pdev->dev, i);
>> -               if (IS_ERR(priv->pd_dev[i])) {
>> -                       ret = PTR_ERR(priv->pd_dev[i]);
>> -                       goto exit_unroll_pm;
>> -               }
>> -               priv->link[i] = device_link_add(&pdev->dev, priv->pd_dev[i],
>> -                                               DL_FLAG_STATELESS |
>> -                                               DL_FLAG_PM_RUNTIME |
>> -                                               DL_FLAG_RPM_ACTIVE);
>> -               if (!priv->link[i]) {
>> -                       ret = -ENOMEM;
>> -                       dev_pm_domain_detach(priv->pd_dev[i], false);
>> -                       goto exit_unroll_pm;
>> -               }
>> -       }
>> +       priv->mpd = dev_multi_pm_attach(&pdev->dev);
>> +       if (IS_ERR(priv->mpd))
>> +               return PTR_ERR(priv->mpd);
>>
>>         ret = imx_scu_get_handle(&priv->sc_ipc);
>>         if (ret) {
>> @@ -329,25 +295,17 @@ static int imx8_probe(struct snd_sof_dev *sdev)
>>  exit_pdev_unregister:
>>         platform_device_unregister(priv->ipc_dev);
>>  exit_unroll_pm:
>
> Can we also rename the label to exit_pm_detach maybe? It is no longer an unroll anymore right?

Sure, will do in v2.
diff mbox series

Patch

diff --git a/sound/soc/sof/imx/imx8.c b/sound/soc/sof/imx/imx8.c
index b692752b2178..ca740538a2d5 100644
--- a/sound/soc/sof/imx/imx8.c
+++ b/sound/soc/sof/imx/imx8.c
@@ -51,10 +51,7 @@  struct imx8_priv {
 	struct imx_sc_ipc *sc_ipc;
 
 	/* Power domain handling */
-	int num_domains;
-	struct device **pd_dev;
-	struct device_link **link;
-
+	struct dev_multi_pm_domain_data *mpd;
 };
 
 static void imx8_get_reply(struct snd_sof_dev *sdev)
@@ -207,7 +204,6 @@  static int imx8_probe(struct snd_sof_dev *sdev)
 	struct resource res;
 	u32 base, size;
 	int ret = 0;
-	int i;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -218,39 +214,9 @@  static int imx8_probe(struct snd_sof_dev *sdev)
 	priv->sdev = sdev;
 
 	/* power up device associated power domains */
-	priv->num_domains = of_count_phandle_with_args(np, "power-domains",
-						       "#power-domain-cells");
-	if (priv->num_domains < 0) {
-		dev_err(sdev->dev, "no power-domains property in %pOF\n", np);
-		return priv->num_domains;
-	}
-
-	priv->pd_dev = devm_kmalloc_array(&pdev->dev, priv->num_domains,
-					  sizeof(*priv->pd_dev), GFP_KERNEL);
-	if (!priv->pd_dev)
-		return -ENOMEM;
-
-	priv->link = devm_kmalloc_array(&pdev->dev, priv->num_domains,
-					sizeof(*priv->link), GFP_KERNEL);
-	if (!priv->link)
-		return -ENOMEM;
-
-	for (i = 0; i < priv->num_domains; i++) {
-		priv->pd_dev[i] = dev_pm_domain_attach_by_id(&pdev->dev, i);
-		if (IS_ERR(priv->pd_dev[i])) {
-			ret = PTR_ERR(priv->pd_dev[i]);
-			goto exit_unroll_pm;
-		}
-		priv->link[i] = device_link_add(&pdev->dev, priv->pd_dev[i],
-						DL_FLAG_STATELESS |
-						DL_FLAG_PM_RUNTIME |
-						DL_FLAG_RPM_ACTIVE);
-		if (!priv->link[i]) {
-			ret = -ENOMEM;
-			dev_pm_domain_detach(priv->pd_dev[i], false);
-			goto exit_unroll_pm;
-		}
-	}
+	priv->mpd = dev_multi_pm_attach(&pdev->dev);
+	if (IS_ERR(priv->mpd))
+		return PTR_ERR(priv->mpd);
 
 	ret = imx_scu_get_handle(&priv->sc_ipc);
 	if (ret) {
@@ -329,25 +295,17 @@  static int imx8_probe(struct snd_sof_dev *sdev)
 exit_pdev_unregister:
 	platform_device_unregister(priv->ipc_dev);
 exit_unroll_pm:
-	while (--i >= 0) {
-		device_link_del(priv->link[i]);
-		dev_pm_domain_detach(priv->pd_dev[i], false);
-	}
-
+	dev_multi_pm_detach(priv->mpd);
 	return ret;
 }
 
 static int imx8_remove(struct snd_sof_dev *sdev)
 {
 	struct imx8_priv *priv = (struct imx8_priv *)sdev->private;
-	int i;
 
 	platform_device_unregister(priv->ipc_dev);
 
-	for (i = 0; i < priv->num_domains; i++) {
-		device_link_del(priv->link[i]);
-		dev_pm_domain_detach(priv->pd_dev[i], false);
-	}
+	dev_multi_pm_detach(priv->mpd);
 
 	return 0;
 }