2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
3 * Copyright (C) 2011 Google, Inc.
6 * Jay Cheng <jacheng@nvidia.com>
7 * James Wylder <james.wylder@motorola.com>
8 * Benoit Goby <benoit@android.com>
9 * Colin Cross <ccross@android.com>
10 * Hiroshi DOYU <hdoyu@nvidia.com>
12 * This software is licensed under the terms of the GNU General Public
13 * License version 2, as published by the Free Software Foundation, and
14 * may be copied, distributed, and modified under those terms.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
23 #include <linux/err.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/platform_device.h>
29 #include <soc/tegra/ahb.h>
31 #define DRV_NAME "tegra-ahb"
33 #define AHB_ARBITRATION_DISABLE 0x00
34 #define AHB_ARBITRATION_PRIORITY_CTRL 0x04
35 #define AHB_PRIORITY_WEIGHT(x) (((x) & 0x7) << 29)
36 #define PRIORITY_SELECT_USB BIT(6)
37 #define PRIORITY_SELECT_USB2 BIT(18)
38 #define PRIORITY_SELECT_USB3 BIT(17)
40 #define AHB_GIZMO_AHB_MEM 0x0c
41 #define ENB_FAST_REARBITRATE BIT(2)
42 #define DONT_SPLIT_AHB_WR BIT(7)
44 #define AHB_GIZMO_APB_DMA 0x10
45 #define AHB_GIZMO_IDE 0x18
46 #define AHB_GIZMO_USB 0x1c
47 #define AHB_GIZMO_AHB_XBAR_BRIDGE 0x20
48 #define AHB_GIZMO_CPU_AHB_BRIDGE 0x24
49 #define AHB_GIZMO_COP_AHB_BRIDGE 0x28
50 #define AHB_GIZMO_XBAR_APB_CTLR 0x2c
51 #define AHB_GIZMO_VCP_AHB_BRIDGE 0x30
52 #define AHB_GIZMO_NAND 0x3c
53 #define AHB_GIZMO_SDMMC4 0x44
54 #define AHB_GIZMO_XIO 0x48
55 #define AHB_GIZMO_BSEV 0x60
56 #define AHB_GIZMO_BSEA 0x70
57 #define AHB_GIZMO_NOR 0x74
58 #define AHB_GIZMO_USB2 0x78
59 #define AHB_GIZMO_USB3 0x7c
60 #define IMMEDIATE BIT(18)
62 #define AHB_GIZMO_SDMMC1 0x80
63 #define AHB_GIZMO_SDMMC2 0x84
64 #define AHB_GIZMO_SDMMC3 0x88
65 #define AHB_MEM_PREFETCH_CFG_X 0xd8
66 #define AHB_ARBITRATION_XBAR_CTRL 0xdc
67 #define AHB_MEM_PREFETCH_CFG3 0xe0
68 #define AHB_MEM_PREFETCH_CFG4 0xe4
69 #define AHB_MEM_PREFETCH_CFG1 0xec
70 #define AHB_MEM_PREFETCH_CFG2 0xf0
71 #define PREFETCH_ENB BIT(31)
72 #define MST_ID(x) (((x) & 0x1f) << 26)
73 #define AHBDMA_MST_ID MST_ID(5)
74 #define USB_MST_ID MST_ID(6)
75 #define USB2_MST_ID MST_ID(18)
76 #define USB3_MST_ID MST_ID(17)
77 #define ADDR_BNDRY(x) (((x) & 0xf) << 21)
78 #define INACTIVITY_TIMEOUT(x) (((x) & 0xffff) << 0)
80 #define AHB_ARBITRATION_AHB_MEM_WRQUE_MST_ID 0xf8
82 #define AHB_ARBITRATION_XBAR_CTRL_SMMU_INIT_DONE BIT(17)
84 static struct platform_driver tegra_ahb_driver;
86 static const u32 tegra_ahb_gizmo[] = {
87 AHB_ARBITRATION_DISABLE,
88 AHB_ARBITRATION_PRIORITY_CTRL,
93 AHB_GIZMO_AHB_XBAR_BRIDGE,
94 AHB_GIZMO_CPU_AHB_BRIDGE,
95 AHB_GIZMO_COP_AHB_BRIDGE,
96 AHB_GIZMO_XBAR_APB_CTLR,
97 AHB_GIZMO_VCP_AHB_BRIDGE,
109 AHB_MEM_PREFETCH_CFG_X,
110 AHB_ARBITRATION_XBAR_CTRL,
111 AHB_MEM_PREFETCH_CFG3,
112 AHB_MEM_PREFETCH_CFG4,
113 AHB_MEM_PREFETCH_CFG1,
114 AHB_MEM_PREFETCH_CFG2,
115 AHB_ARBITRATION_AHB_MEM_WRQUE_MST_ID,
124 static inline u32 gizmo_readl(struct tegra_ahb *ahb, u32 offset)
126 return readl(ahb->regs + offset);
129 static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
131 writel(value, ahb->regs + offset);
134 #ifdef CONFIG_TEGRA_IOMMU_SMMU
135 static int tegra_ahb_match_by_smmu(struct device *dev, void *data)
137 struct tegra_ahb *ahb = dev_get_drvdata(dev);
138 struct device_node *dn = data;
140 return (ahb->dev->of_node == dn) ? 1 : 0;
143 int tegra_ahb_enable_smmu(struct device_node *dn)
147 struct tegra_ahb *ahb;
149 dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
150 tegra_ahb_match_by_smmu);
152 return -EPROBE_DEFER;
153 ahb = dev_get_drvdata(dev);
154 val = gizmo_readl(ahb, AHB_ARBITRATION_XBAR_CTRL);
155 val |= AHB_ARBITRATION_XBAR_CTRL_SMMU_INIT_DONE;
156 gizmo_writel(ahb, val, AHB_ARBITRATION_XBAR_CTRL);
159 EXPORT_SYMBOL(tegra_ahb_enable_smmu);
163 static int tegra_ahb_suspend(struct device *dev)
166 struct tegra_ahb *ahb = dev_get_drvdata(dev);
168 for (i = 0; i < ARRAY_SIZE(tegra_ahb_gizmo); i++)
169 ahb->ctx[i] = gizmo_readl(ahb, tegra_ahb_gizmo[i]);
173 static int tegra_ahb_resume(struct device *dev)
176 struct tegra_ahb *ahb = dev_get_drvdata(dev);
178 for (i = 0; i < ARRAY_SIZE(tegra_ahb_gizmo); i++)
179 gizmo_writel(ahb, ahb->ctx[i], tegra_ahb_gizmo[i]);
184 static UNIVERSAL_DEV_PM_OPS(tegra_ahb_pm,
186 tegra_ahb_resume, NULL);
188 static void tegra_ahb_gizmo_init(struct tegra_ahb *ahb)
192 val = gizmo_readl(ahb, AHB_GIZMO_AHB_MEM);
193 val |= ENB_FAST_REARBITRATE | IMMEDIATE | DONT_SPLIT_AHB_WR;
194 gizmo_writel(ahb, val, AHB_GIZMO_AHB_MEM);
196 val = gizmo_readl(ahb, AHB_GIZMO_USB);
198 gizmo_writel(ahb, val, AHB_GIZMO_USB);
200 val = gizmo_readl(ahb, AHB_GIZMO_USB2);
202 gizmo_writel(ahb, val, AHB_GIZMO_USB2);
204 val = gizmo_readl(ahb, AHB_GIZMO_USB3);
206 gizmo_writel(ahb, val, AHB_GIZMO_USB3);
208 val = gizmo_readl(ahb, AHB_ARBITRATION_PRIORITY_CTRL);
209 val |= PRIORITY_SELECT_USB |
210 PRIORITY_SELECT_USB2 |
211 PRIORITY_SELECT_USB3 |
212 AHB_PRIORITY_WEIGHT(7);
213 gizmo_writel(ahb, val, AHB_ARBITRATION_PRIORITY_CTRL);
215 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG1);
217 val |= PREFETCH_ENB |
220 INACTIVITY_TIMEOUT(0x1000);
221 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG1);
223 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG2);
225 val |= PREFETCH_ENB |
228 INACTIVITY_TIMEOUT(0x1000);
229 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG2);
231 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG3);
233 val |= PREFETCH_ENB |
236 INACTIVITY_TIMEOUT(0x1000);
237 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG3);
239 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG4);
241 val |= PREFETCH_ENB |
244 INACTIVITY_TIMEOUT(0x1000);
245 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG4);
248 static int tegra_ahb_probe(struct platform_device *pdev)
250 struct resource *res;
251 struct tegra_ahb *ahb;
254 bytes = sizeof(*ahb) + sizeof(u32) * ARRAY_SIZE(tegra_ahb_gizmo);
255 ahb = devm_kzalloc(&pdev->dev, bytes, GFP_KERNEL);
259 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
260 ahb->regs = devm_ioremap_resource(&pdev->dev, res);
261 if (IS_ERR(ahb->regs))
262 return PTR_ERR(ahb->regs);
264 ahb->dev = &pdev->dev;
265 platform_set_drvdata(pdev, ahb);
266 tegra_ahb_gizmo_init(ahb);
270 static const struct of_device_id tegra_ahb_of_match[] = {
271 { .compatible = "nvidia,tegra30-ahb", },
272 { .compatible = "nvidia,tegra20-ahb", },
276 static struct platform_driver tegra_ahb_driver = {
277 .probe = tegra_ahb_probe,
280 .of_match_table = tegra_ahb_of_match,
284 module_platform_driver(tegra_ahb_driver);
286 MODULE_AUTHOR("Hiroshi DOYU <hdoyu@nvidia.com>");
287 MODULE_DESCRIPTION("Tegra AHB driver");
288 MODULE_LICENSE("GPL v2");
289 MODULE_ALIAS("platform:" DRV_NAME);