From patchwork Fri Mar 6 10:48:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WW9uZyBXdSAo5ZC05YuHKQ==?= X-Patchwork-Id: 5953401 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D9D2DBF440 for ; Fri, 6 Mar 2015 10:52:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C264820304 for ; Fri, 6 Mar 2015 10:52:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BDFB8203EC for ; Fri, 6 Mar 2015 10:52:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YTppn-0007KE-Iw; Fri, 06 Mar 2015 10:50:23 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YTpoc-0004xA-K5; Fri, 06 Mar 2015 10:49:12 +0000 X-Listener-Flag: 11101 Received: from mtkhts07.mediatek.inc [(172.21.101.69)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1455431666; Fri, 06 Mar 2015 18:48:47 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkhts07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 14.3.181.6; Fri, 6 Mar 2015 18:48:45 +0800 From: To: Rob Herring , Joerg Roedel , Matthias Brugger Subject: [PATCH 1/5] soc: mediatek: Add SMI driver Date: Fri, 6 Mar 2015 18:48:16 +0800 Message-ID: <1425638900-24989-2-git-send-email-yong.wu@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1425638900-24989-1-git-send-email-yong.wu@mediatek.com> References: <1425638900-24989-1-git-send-email-yong.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150306_024911_130381_E3D45691 X-CRM114-Status: GOOD ( 19.10 ) X-Spam-Score: 1.3 (+) Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, Tomasz Figa , iommu@lists.linux-foundation.org, Daniel Kurtz , Yong Wu , Sasha Hauer , linux-mediatek@lists.infradead.org, Robin Murphy , linux-arm-kernel@lists.infradead.org, Lucas Stach X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yong Wu This patch add SMI(Smart Multimedia Interface) driver. This driver is responsible to enable/disable iommu and control the clocks of each local arbiter. Signed-off-by: Yong Wu --- drivers/soc/mediatek/Kconfig | 7 ++ drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mt8173-smi.c | 143 ++++++++++++++++++++++++++++++++++++++ include/linux/mtk-smi.h | 40 +++++++++++ 4 files changed, 191 insertions(+) create mode 100644 drivers/soc/mediatek/mt8173-smi.c create mode 100644 include/linux/mtk-smi.h diff --git a/drivers/soc/mediatek/Kconfig b/drivers/soc/mediatek/Kconfig index 729f93e..27fb26c 100644 --- a/drivers/soc/mediatek/Kconfig +++ b/drivers/soc/mediatek/Kconfig @@ -20,3 +20,10 @@ config MT8173_PMIC_WRAP PMIC wrapper is a proprietary hardware in MT8173 to make communication protocols to access PMIC device. This driver implement access protocols for MT8173. + +config MTK_SMI + bool + help + Smi help enable/disable iommu in mt8173 and control the + clock of each local arbiter. + It should be true while MTK_IOMMU enable. diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile index 9b5709b..cdfe95c 100644 --- a/drivers/soc/mediatek/Makefile +++ b/drivers/soc/mediatek/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_MT8135_PMIC_WRAP) += mt8135-pmic-wrap.o obj-$(CONFIG_MT8173_PMIC_WRAP) += mt8173-pmic-wrap.o +obj-$(CONFIG_MTK_SMI) += mt8173-smi.o diff --git a/drivers/soc/mediatek/mt8173-smi.c b/drivers/soc/mediatek/mt8173-smi.c new file mode 100644 index 0000000..4e3fab9 --- /dev/null +++ b/drivers/soc/mediatek/mt8173-smi.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2014-2015 MediaTek Inc. + * Author: Yong Wu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include +#include +#include +#include +#include +#include + +#define SMI_LARB_MMU_EN (0xf00) +#define F_SMI_MMU_EN(port) (1 << (port)) + +struct mtk_smi_larb { + void __iomem *larb_base; + struct clk *larb_clk[3];/* each larb has 3 clk at most */ +}; + +static const char * const mtk_smi_clk_name[] = { + "larb_sub0", "larb_sub1", "larb_sub2" +}; + +static const struct of_device_id mtk_smi_of_ids[] = { + { .compatible = "mediatek,mt8173-smi-larb", + }, + {} +}; + +int mtk_smi_larb_get(struct platform_device *plarbdev) +{ + struct mtk_smi_larb *larbpriv = dev_get_drvdata(&plarbdev->dev); + int i, ret = 0; + + for (i = 0; i < 3; i++) + if (larbpriv->larb_clk[i]) { + ret = clk_prepare_enable(larbpriv->larb_clk[i]); + if (ret) { + dev_err(&plarbdev->dev, + "failed to enable larbclk%d:%d\n", + i, ret); + break; + } + } + return ret; +} + +void mtk_smi_larb_put(struct platform_device *plarbdev) +{ + struct mtk_smi_larb *larbpriv = dev_get_drvdata(&plarbdev->dev); + int i; + + for (i = 2; i >= 0; i--) + if (larbpriv->larb_clk[i]) + clk_disable_unprepare(larbpriv->larb_clk[i]); +} + +int mtk_smi_config_port(struct platform_device *plarbdev, + unsigned int larbportid) +{ + struct mtk_smi_larb *larbpriv = dev_get_drvdata(&plarbdev->dev); + int ret; + u32 reg; + + ret = mtk_smi_larb_get(plarbdev); + if (ret) + return ret; + + reg = readl(larbpriv->larb_base + SMI_LARB_MMU_EN); + reg &= ~F_SMI_MMU_EN(larbportid); + reg |= F_SMI_MMU_EN(larbportid); + writel(reg, larbpriv->larb_base + SMI_LARB_MMU_EN); + + mtk_smi_larb_put(plarbdev); + + return 0; +} + +static int mtk_smi_probe(struct platform_device *pdev) +{ + struct mtk_smi_larb *larbpriv; + struct resource *res; + struct device *dev = &pdev->dev; + unsigned int i; + + larbpriv = devm_kzalloc(dev, sizeof(struct mtk_smi_larb), GFP_KERNEL); + if (!larbpriv) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + larbpriv->larb_base = devm_ioremap_resource(dev, res); + if (IS_ERR(larbpriv->larb_base)) { + dev_err(dev, "larbbase %p err\n", larbpriv->larb_base); + return PTR_ERR(larbpriv->larb_base); + } + + for (i = 0; i < 3; i++) { + larbpriv->larb_clk[i] = devm_clk_get(dev, mtk_smi_clk_name[i]); + + if (IS_ERR(larbpriv->larb_clk[i])) { + if (i == 2) {/* some larb may have only 2 clock */ + larbpriv->larb_clk[i] = NULL; + } else { + dev_err(dev, "clock-%d err: %p\n", i, + larbpriv->larb_clk[i]); + return PTR_ERR(larbpriv->larb_clk[i]); + } + } + } + dev_set_drvdata(dev, larbpriv); + return 0; +} + +static int mtk_smi_remove(struct platform_device *pdev) +{ + return 0; +} + +static struct platform_driver mtk_smi_driver = { + .probe = mtk_smi_probe, + .remove = mtk_smi_remove, + .driver = { + .name = "mtksmi", + .of_match_table = mtk_smi_of_ids, + } +}; + +static int __init mtk_smi_init(void) +{ + return platform_driver_register(&mtk_smi_driver); +} + +subsys_initcall(mtk_smi_init); + diff --git a/include/linux/mtk-smi.h b/include/linux/mtk-smi.h new file mode 100644 index 0000000..1411f7b --- /dev/null +++ b/include/linux/mtk-smi.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014-2015 MediaTek Inc. + * Author: Yong Wu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#ifndef MTK_IOMMU_SMI_H +#define MTK_IOMMU_SMI_H +#include + +/* + * Enable iommu for each port, it is only for iommu. + * + * Returns 0 if successfully, others if failed. + */ +int mtk_smi_config_port(struct platform_device *pdev, + unsigned int larbportid); + +/* + * The multimedia module should call the two function below + * which help open/close the clock of the larb. + * so the client dtsi should add the larb like "larb = <&larb0>" + * to get platform_device. + * + * mtk_smi_larb_get should be called before the multimedia h/w work. + * mtk_smi_larb_put should be called after h/w done. + * + * Returns 0 if successfully, others if failed. + */ +int mtk_smi_larb_get(struct platform_device *plarbdev); +void mtk_smi_larb_put(struct platform_device *plarbdev); + +#endif