Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2188385pxb; Mon, 11 Jan 2021 03:25:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvlGVeLGGz3n3/rQIopdE5HU2AxUZKx2YFOjSIlFD9lZixCPTmqQPA8AlUHMdkeVtIAOcW X-Received: by 2002:a17:906:4c4c:: with SMTP id d12mr10550474ejw.307.1610364309788; Mon, 11 Jan 2021 03:25:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610364309; cv=none; d=google.com; s=arc-20160816; b=L3ogYrJgLb3ZSwSbFvga+YCbW5q+ia90jTinuhTJnkYX5tTRk1D+QnzYoT9/p0h6xP RdfaDhv1HLZWTG60FUxUAfu90mkRYMQdRDIZpT/BwT93S5AftZ7VctGgxaM8DK35U4iN EOjjXM93iVnocm8/99WrO+o5HOOZbXndCGDAWAWDfyFGtWHVQ7gSIDASBf6IzMTj6y77 IiQBQL4zsWEuhX8JZquoHMCSVLLy83IKS6d10tpapEycl9h/8KTEzfmUuTfBSJSgK/8I +Y5WvTbHBzB4Mw174vmfbrplM2+kGOTOogx49oVp1IW8XJjRI/RdBEoBmTLFMHZ+jYCL Xk1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=7AdIYCJup8BxG3as2qKi6GprVY7X+Rwp0xvnJ73EIBE=; b=DgLnd6rgnU5AasLfkRhEs54rF/U+1dUc4Lxa/hwe4Cn101FOcflwQp/6bfmp2AKinS myraUb0rrbLhTzsWnwfN26q6UhAFFf0oWi4znH8ySW/lLSVFY09NS3+OckPv9Pc5rxI9 mydVLYgKO+WQooIoPiU32lAfw1R2MEvkRy5xd8C3C9VatpAqJILk0BOFHTE2rOcd6Mu5 fkJZ+vqbG6pY6stY6ZgMQVxr0O8NjsInKj/mbeFfTbwJgBSqc/QAM1uzu1Is9KM4XHme b73tDmXCwkpYaldjbUgCB66XGhm0mzonMt6yvH0peD+pyoFWNlC/5bmzOJdNvmDPfOqA 8+SA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o7si2560072eja.635.2021.01.11.03.24.45; Mon, 11 Jan 2021 03:25:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729880AbhAKLWx (ORCPT + 99 others); Mon, 11 Jan 2021 06:22:53 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:60030 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729877AbhAKLWw (ORCPT ); Mon, 11 Jan 2021 06:22:52 -0500 X-UUID: aa53b37d93f74f7fa8d200ae0b5abe1c-20210111 X-UUID: aa53b37d93f74f7fa8d200ae0b5abe1c-20210111 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1926634196; Mon, 11 Jan 2021 19:22:19 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 11 Jan 2021 19:22:17 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 11 Jan 2021 19:22:17 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , Matthias Brugger , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Evan Green , Tomasz Figa , , , , , , , , , Nicolas Boichat , , Subject: [PATCH v6 18/33] iommu/mediatek: Add device link for smi-common and m4u Date: Mon, 11 Jan 2021 19:18:59 +0800 Message-ID: <20210111111914.22211-19-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210111111914.22211-1-yong.wu@mediatek.com> References: <20210111111914.22211-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/iommu/mtk_iommu.c | 27 ++++++++++++++++++++++++--- drivers/iommu/mtk_iommu.h | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 189165e7a2ab..0fe7c1617dc3 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -633,6 +634,9 @@ static int mtk_iommu_probe(struct platform_device *pdev) { struct mtk_iommu_data *data; struct device *dev = &pdev->dev; + struct device_node *larbnode, *smicomm_node; + struct platform_device *plarbdev; + struct device_link *link; struct resource *res; resource_size_t ioaddr; struct component_match *match = NULL; @@ -699,8 +703,6 @@ static int mtk_iommu_probe(struct platform_device *pdev) return larb_nr; for (i = 0; i < larb_nr; i++) { - struct device_node *larbnode; - struct platform_device *plarbdev; u32 id; larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i); @@ -727,12 +729,28 @@ static int mtk_iommu_probe(struct platform_device *pdev) compare_of, larbnode); } + /* Get smi-common dev from the last larb. */ + 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; + + 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); 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); @@ -762,6 +780,8 @@ 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: + device_link_remove(data->smicomm_dev, dev); return ret; } @@ -776,6 +796,7 @@ static int mtk_iommu_remove(struct platform_device *pdev) bus_set_iommu(&platform_bus_type, NULL); clk_disable_unprepare(data->bclk); + 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 c1584dea66cb..a9b79e118f02 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