diff mbox series

[v5,16/27] iommu/mediatek: Add device link for smi-common and m4u

Message ID 20201209080102.26626-17-yong.wu@mediatek.com
State New
Headers show
Series MT8192 IOMMU support | expand

Commit Message

Yong Wu Dec. 9, 2020, 8 a.m. UTC
In the lastest SoC, M4U has its special power domain. thus, If the engine
begin to work, it should help enable the power for M4U firstly.
Currently if the engine work, it always enable the power/clocks for
smi-larbs/smi-common. This patch adds device_link for smi-common and M4U.
then, if smi-common power is enabled, the M4U power also is powered on
automatically.

Normally M4U connect with several smi-larbs and their smi-common always
are the same, In this patch it get smi-common dev from the first smi-larb
device(i==0), then add the device_link only while m4u has power-domain.

Signed-off-by: Yong Wu <yong.wu@mediatek.com>
---
 drivers/iommu/mtk_iommu.c | 30 ++++++++++++++++++++++++++++--
 drivers/iommu/mtk_iommu.h |  1 +
 2 files changed, 29 insertions(+), 2 deletions(-)

Comments

Tomasz Figa Dec. 23, 2020, 8:29 a.m. UTC | #1
On Wed, Dec 09, 2020 at 04:00:51PM +0800, Yong Wu wrote:
> In the lastest SoC, M4U has its special power domain. thus, If the engine

> begin to work, it should help enable the power for M4U firstly.

> Currently if the engine work, it always enable the power/clocks for

> smi-larbs/smi-common. This patch adds device_link for smi-common and M4U.

> then, if smi-common power is enabled, the M4U power also is powered on

> automatically.

> 

> Normally M4U connect with several smi-larbs and their smi-common always

> are the same, In this patch it get smi-common dev from the first smi-larb

> device(i==0), then add the device_link only while m4u has power-domain.

> 

> Signed-off-by: Yong Wu <yong.wu@mediatek.com>

> ---

>  drivers/iommu/mtk_iommu.c | 30 ++++++++++++++++++++++++++++--

>  drivers/iommu/mtk_iommu.h |  1 +

>  2 files changed, 29 insertions(+), 2 deletions(-)

> 

> diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c

> index 09c8c58feb78..5614015e5b96 100644

> --- a/drivers/iommu/mtk_iommu.c

> +++ b/drivers/iommu/mtk_iommu.c

> @@ -20,6 +20,7 @@

>  #include <linux/of_irq.h>

>  #include <linux/of_platform.h>

>  #include <linux/platform_device.h>

> +#include <linux/pm_runtime.h>

>  #include <linux/regmap.h>

>  #include <linux/slab.h>

>  #include <linux/spinlock.h>

> @@ -706,7 +707,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)

>  		return larb_nr;

>  

>  	for (i = 0; i < larb_nr; i++) {

> -		struct device_node *larbnode;

> +		struct device_node *larbnode, *smicomm_node;

>  		struct platform_device *plarbdev;

>  		u32 id;

>  

> @@ -732,6 +733,26 @@ static int mtk_iommu_probe(struct platform_device *pdev)

>  

>  		component_match_add_release(dev, &match, release_of,

>  					    compare_of, larbnode);

> +		if (i != 0)

> +			continue;


How about using the last larb instead and moving the code below outside
of the loop?

> +		smicomm_node = of_parse_phandle(larbnode, "mediatek,smi", 0);

> +		if (!smicomm_node)

> +			return -EINVAL;

> +

> +		plarbdev = of_find_device_by_node(smicomm_node);

> +		of_node_put(smicomm_node);

> +		data->smicomm_dev = &plarbdev->dev;

> +	}

> +

> +	if (dev->pm_domain) {

> +		struct device_link *link;

> +

> +		link = device_link_add(data->smicomm_dev, dev,

> +				       DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);

> +		if (!link) {

> +			dev_err(dev, "Unable link %s.\n", dev_name(data->smicomm_dev));

> +			return -EINVAL;

> +		}

>  	}

>  

>  	platform_set_drvdata(pdev, data);

> @@ -739,7 +760,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)

>  	ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,

>  				     "mtk-iommu.%pa", &ioaddr);

>  	if (ret)

> -		return ret;

> +		goto out_link_remove;

>  

>  	iommu_device_set_ops(&data->iommu, &mtk_iommu_ops);

>  	iommu_device_set_fwnode(&data->iommu, &pdev->dev.of_node->fwnode);

> @@ -763,6 +784,9 @@ static int mtk_iommu_probe(struct platform_device *pdev)

>  	iommu_device_unregister(&data->iommu);

>  out_sysfs_remove:

>  	iommu_device_sysfs_remove(&data->iommu);

> +out_link_remove:

> +	if (dev->pm_domain)

> +		device_link_remove(data->smicomm_dev, dev);

>  	return ret;

>  }

>  

> @@ -777,6 +801,8 @@ static int mtk_iommu_remove(struct platform_device *pdev)

>  		bus_set_iommu(&platform_bus_type, NULL);

>  

>  	clk_disable_unprepare(data->bclk);

> +	if (pdev->dev.pm_domain)

> +		device_link_remove(data->smicomm_dev, &pdev->dev);

>  	devm_free_irq(&pdev->dev, data->irq, data);

>  	component_master_del(&pdev->dev, &mtk_iommu_com_ops);

>  	return 0;

> diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h

> index d0c93652bdbe..5e03a029c4dc 100644

> --- a/drivers/iommu/mtk_iommu.h

> +++ b/drivers/iommu/mtk_iommu.h

> @@ -68,6 +68,7 @@ struct mtk_iommu_data {

>  

>  	struct iommu_device		iommu;

>  	const struct mtk_iommu_plat_data *plat_data;

> +	struct device			*smicomm_dev;

>  

>  	struct dma_iommu_mapping	*mapping; /* For mtk_iommu_v1.c */

>  

> -- 

> 2.18.0

> 

> _______________________________________________

> iommu mailing list

> iommu@lists.linux-foundation.org

> https://lists.linuxfoundation.org/mailman/listinfo/iommu
Yong Wu Dec. 29, 2020, 11:25 a.m. UTC | #2
On Wed, 2020-12-23 at 17:29 +0900, Tomasz Figa wrote:
> On Wed, Dec 09, 2020 at 04:00:51PM +0800, Yong Wu wrote:

> > In the lastest SoC, M4U has its special power domain. thus, If the engine

> > begin to work, it should help enable the power for M4U firstly.

> > Currently if the engine work, it always enable the power/clocks for

> > smi-larbs/smi-common. This patch adds device_link for smi-common and M4U.

> > then, if smi-common power is enabled, the M4U power also is powered on

> > automatically.

> > 

> > Normally M4U connect with several smi-larbs and their smi-common always

> > are the same, In this patch it get smi-common dev from the first smi-larb

> > device(i==0), then add the device_link only while m4u has power-domain.

> > 

> > Signed-off-by: Yong Wu <yong.wu@mediatek.com>

> > ---

> >  drivers/iommu/mtk_iommu.c | 30 ++++++++++++++++++++++++++++--

> >  drivers/iommu/mtk_iommu.h |  1 +

> >  2 files changed, 29 insertions(+), 2 deletions(-)

> > 

> > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c

> > index 09c8c58feb78..5614015e5b96 100644

> > --- a/drivers/iommu/mtk_iommu.c

> > +++ b/drivers/iommu/mtk_iommu.c

> > @@ -20,6 +20,7 @@

> >  #include <linux/of_irq.h>

> >  #include <linux/of_platform.h>

> >  #include <linux/platform_device.h>

> > +#include <linux/pm_runtime.h>

> >  #include <linux/regmap.h>

> >  #include <linux/slab.h>

> >  #include <linux/spinlock.h>

> > @@ -706,7 +707,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)

> >  		return larb_nr;

> >  

> >  	for (i = 0; i < larb_nr; i++) {

> > -		struct device_node *larbnode;

> > +		struct device_node *larbnode, *smicomm_node;

> >  		struct platform_device *plarbdev;

> >  		u32 id;

> >  

> > @@ -732,6 +733,26 @@ static int mtk_iommu_probe(struct platform_device *pdev)

> >  

> >  		component_match_add_release(dev, &match, release_of,

> >  					    compare_of, larbnode);

> > +		if (i != 0)

> > +			continue;

> 

> How about using the last larb instead and moving the code below outside

> of the loop?


Of course OK. Thanks.
diff mbox series

Patch

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 09c8c58feb78..5614015e5b96 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -20,6 +20,7 @@ 
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
@@ -706,7 +707,7 @@  static int mtk_iommu_probe(struct platform_device *pdev)
 		return larb_nr;
 
 	for (i = 0; i < larb_nr; i++) {
-		struct device_node *larbnode;
+		struct device_node *larbnode, *smicomm_node;
 		struct platform_device *plarbdev;
 		u32 id;
 
@@ -732,6 +733,26 @@  static int mtk_iommu_probe(struct platform_device *pdev)
 
 		component_match_add_release(dev, &match, release_of,
 					    compare_of, larbnode);
+		if (i != 0)
+			continue;
+		smicomm_node = of_parse_phandle(larbnode, "mediatek,smi", 0);
+		if (!smicomm_node)
+			return -EINVAL;
+
+		plarbdev = of_find_device_by_node(smicomm_node);
+		of_node_put(smicomm_node);
+		data->smicomm_dev = &plarbdev->dev;
+	}
+
+	if (dev->pm_domain) {
+		struct device_link *link;
+
+		link = device_link_add(data->smicomm_dev, dev,
+				       DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);
+		if (!link) {
+			dev_err(dev, "Unable link %s.\n", dev_name(data->smicomm_dev));
+			return -EINVAL;
+		}
 	}
 
 	platform_set_drvdata(pdev, data);
@@ -739,7 +760,7 @@  static int mtk_iommu_probe(struct platform_device *pdev)
 	ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,
 				     "mtk-iommu.%pa", &ioaddr);
 	if (ret)
-		return ret;
+		goto out_link_remove;
 
 	iommu_device_set_ops(&data->iommu, &mtk_iommu_ops);
 	iommu_device_set_fwnode(&data->iommu, &pdev->dev.of_node->fwnode);
@@ -763,6 +784,9 @@  static int mtk_iommu_probe(struct platform_device *pdev)
 	iommu_device_unregister(&data->iommu);
 out_sysfs_remove:
 	iommu_device_sysfs_remove(&data->iommu);
+out_link_remove:
+	if (dev->pm_domain)
+		device_link_remove(data->smicomm_dev, dev);
 	return ret;
 }
 
@@ -777,6 +801,8 @@  static int mtk_iommu_remove(struct platform_device *pdev)
 		bus_set_iommu(&platform_bus_type, NULL);
 
 	clk_disable_unprepare(data->bclk);
+	if (pdev->dev.pm_domain)
+		device_link_remove(data->smicomm_dev, &pdev->dev);
 	devm_free_irq(&pdev->dev, data->irq, data);
 	component_master_del(&pdev->dev, &mtk_iommu_com_ops);
 	return 0;
diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h
index d0c93652bdbe..5e03a029c4dc 100644
--- a/drivers/iommu/mtk_iommu.h
+++ b/drivers/iommu/mtk_iommu.h
@@ -68,6 +68,7 @@  struct mtk_iommu_data {
 
 	struct iommu_device		iommu;
 	const struct mtk_iommu_plat_data *plat_data;
+	struct device			*smicomm_dev;
 
 	struct dma_iommu_mapping	*mapping; /* For mtk_iommu_v1.c */