Skip to content

Commit baf94e6

Browse files
YongWu-HFwilldeacon
authored andcommitted
iommu/mediatek: Add device link for smi-common and m4u
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 last smi-larb device, then add the device_link. Signed-off-by: Yong Wu <[email protected]> Reviewed-by: Tomasz Figa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 986d9ec commit baf94e6

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/of_irq.h>
2121
#include <linux/of_platform.h>
2222
#include <linux/platform_device.h>
23+
#include <linux/pm_runtime.h>
2324
#include <linux/regmap.h>
2425
#include <linux/slab.h>
2526
#include <linux/spinlock.h>
@@ -633,6 +634,9 @@ static int mtk_iommu_probe(struct platform_device *pdev)
633634
{
634635
struct mtk_iommu_data *data;
635636
struct device *dev = &pdev->dev;
637+
struct device_node *larbnode, *smicomm_node;
638+
struct platform_device *plarbdev;
639+
struct device_link *link;
636640
struct resource *res;
637641
resource_size_t ioaddr;
638642
struct component_match *match = NULL;
@@ -699,8 +703,6 @@ static int mtk_iommu_probe(struct platform_device *pdev)
699703
return larb_nr;
700704

701705
for (i = 0; i < larb_nr; i++) {
702-
struct device_node *larbnode;
703-
struct platform_device *plarbdev;
704706
u32 id;
705707

706708
larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i);
@@ -727,12 +729,28 @@ static int mtk_iommu_probe(struct platform_device *pdev)
727729
compare_of, larbnode);
728730
}
729731

732+
/* Get smi-common dev from the last larb. */
733+
smicomm_node = of_parse_phandle(larbnode, "mediatek,smi", 0);
734+
if (!smicomm_node)
735+
return -EINVAL;
736+
737+
plarbdev = of_find_device_by_node(smicomm_node);
738+
of_node_put(smicomm_node);
739+
data->smicomm_dev = &plarbdev->dev;
740+
741+
link = device_link_add(data->smicomm_dev, dev,
742+
DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);
743+
if (!link) {
744+
dev_err(dev, "Unable link %s.\n", dev_name(data->smicomm_dev));
745+
return -EINVAL;
746+
}
747+
730748
platform_set_drvdata(pdev, data);
731749

732750
ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,
733751
"mtk-iommu.%pa", &ioaddr);
734752
if (ret)
735-
return ret;
753+
goto out_link_remove;
736754

737755
iommu_device_set_ops(&data->iommu, &mtk_iommu_ops);
738756
iommu_device_set_fwnode(&data->iommu, &pdev->dev.of_node->fwnode);
@@ -762,6 +780,8 @@ static int mtk_iommu_probe(struct platform_device *pdev)
762780
iommu_device_unregister(&data->iommu);
763781
out_sysfs_remove:
764782
iommu_device_sysfs_remove(&data->iommu);
783+
out_link_remove:
784+
device_link_remove(data->smicomm_dev, dev);
765785
return ret;
766786
}
767787

@@ -776,6 +796,7 @@ static int mtk_iommu_remove(struct platform_device *pdev)
776796
bus_set_iommu(&platform_bus_type, NULL);
777797

778798
clk_disable_unprepare(data->bclk);
799+
device_link_remove(data->smicomm_dev, &pdev->dev);
779800
devm_free_irq(&pdev->dev, data->irq, data);
780801
component_master_del(&pdev->dev, &mtk_iommu_com_ops);
781802
return 0;

drivers/iommu/mtk_iommu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct mtk_iommu_data {
6868

6969
struct iommu_device iommu;
7070
const struct mtk_iommu_plat_data *plat_data;
71+
struct device *smicomm_dev;
7172

7273
struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */
7374

0 commit comments

Comments
 (0)