1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
4 * Copyright (C) 2011 Google, Inc.
7 * Jay Cheng <jacheng@nvidia.com>
8 * James Wylder <james.wylder@motorola.com>
9 * Benoit Goby <benoit@android.com>
10 * Colin Cross <ccross@android.com>
11 * Hiroshi DOYU <hdoyu@nvidia.com>
14 #include <linux/err.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
21 #include <soc/tegra/ahb.h>
23 #define DRV_NAME "tegra-ahb"
25 #define AHB_ARBITRATION_DISABLE 0x04
26 #define AHB_ARBITRATION_PRIORITY_CTRL 0x08
27 #define AHB_PRIORITY_WEIGHT(x) (((x) & 0x7) << 29)
28 #define PRIORITY_SELECT_USB BIT(6)
29 #define PRIORITY_SELECT_USB2 BIT(18)
30 #define PRIORITY_SELECT_USB3 BIT(17)
32 #define AHB_GIZMO_AHB_MEM 0x10
33 #define ENB_FAST_REARBITRATE BIT(2)
34 #define DONT_SPLIT_AHB_WR BIT(7)
36 #define AHB_GIZMO_APB_DMA 0x14
37 #define AHB_GIZMO_IDE 0x1c
38 #define AHB_GIZMO_USB 0x20
39 #define AHB_GIZMO_AHB_XBAR_BRIDGE 0x24
40 #define AHB_GIZMO_CPU_AHB_BRIDGE 0x28
41 #define AHB_GIZMO_COP_AHB_BRIDGE 0x2c
42 #define AHB_GIZMO_XBAR_APB_CTLR 0x30
43 #define AHB_GIZMO_VCP_AHB_BRIDGE 0x34
44 #define AHB_GIZMO_NAND 0x40
45 #define AHB_GIZMO_SDMMC4 0x48
46 #define AHB_GIZMO_XIO 0x4c
47 #define AHB_GIZMO_BSEV 0x64
48 #define AHB_GIZMO_BSEA 0x74
49 #define AHB_GIZMO_NOR 0x78
50 #define AHB_GIZMO_USB2 0x7c
51 #define AHB_GIZMO_USB3 0x80
52 #define IMMEDIATE BIT(18)
54 #define AHB_GIZMO_SDMMC1 0x84
55 #define AHB_GIZMO_SDMMC2 0x88
56 #define AHB_GIZMO_SDMMC3 0x8c
57 #define AHB_MEM_PREFETCH_CFG_X 0xdc
58 #define AHB_ARBITRATION_XBAR_CTRL 0xe0
59 #define AHB_MEM_PREFETCH_CFG3 0xe4
60 #define AHB_MEM_PREFETCH_CFG4 0xe8
61 #define AHB_MEM_PREFETCH_CFG1 0xf0
62 #define AHB_MEM_PREFETCH_CFG2 0xf4
63 #define PREFETCH_ENB BIT(31)
64 #define MST_ID(x) (((x) & 0x1f) << 26)
65 #define AHBDMA_MST_ID MST_ID(5)
66 #define USB_MST_ID MST_ID(6)
67 #define USB2_MST_ID MST_ID(18)
68 #define USB3_MST_ID MST_ID(17)
69 #define ADDR_BNDRY(x) (((x) & 0xf) << 21)
70 #define INACTIVITY_TIMEOUT(x) (((x) & 0xffff) << 0)
72 #define AHB_ARBITRATION_AHB_MEM_WRQUE_MST_ID 0xfc
74 #define AHB_ARBITRATION_XBAR_CTRL_SMMU_INIT_DONE BIT(17)
77 * INCORRECT_BASE_ADDR_LOW_BYTE: Legacy kernel DT files for Tegra SoCs
78 * prior to Tegra124 generally use a physical base address ending in
79 * 0x4 for the AHB IP block. According to the TRM, the low byte
80 * should be 0x0. During device probing, this macro is used to detect
81 * whether the passed-in physical address is incorrect, and if so, to
84 #define INCORRECT_BASE_ADDR_LOW_BYTE 0x4
86 static struct platform_driver tegra_ahb_driver;
88 static const u32 tegra_ahb_gizmo[] = {
89 AHB_ARBITRATION_DISABLE,
90 AHB_ARBITRATION_PRIORITY_CTRL,
95 AHB_GIZMO_AHB_XBAR_BRIDGE,
96 AHB_GIZMO_CPU_AHB_BRIDGE,
97 AHB_GIZMO_COP_AHB_BRIDGE,
98 AHB_GIZMO_XBAR_APB_CTLR,
99 AHB_GIZMO_VCP_AHB_BRIDGE,
111 AHB_MEM_PREFETCH_CFG_X,
112 AHB_ARBITRATION_XBAR_CTRL,
113 AHB_MEM_PREFETCH_CFG3,
114 AHB_MEM_PREFETCH_CFG4,
115 AHB_MEM_PREFETCH_CFG1,
116 AHB_MEM_PREFETCH_CFG2,
117 AHB_ARBITRATION_AHB_MEM_WRQUE_MST_ID,
126 static inline u32 gizmo_readl(struct tegra_ahb *ahb, u32 offset)
128 return readl(ahb->regs + offset);
131 static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
133 writel(value, ahb->regs + offset);
136 #ifdef CONFIG_TEGRA_IOMMU_SMMU
137 int tegra_ahb_enable_smmu(struct device_node *dn)
141 struct tegra_ahb *ahb;
143 dev = driver_find_device_by_of_node(&tegra_ahb_driver.driver, dn);
145 return -EPROBE_DEFER;
146 ahb = dev_get_drvdata(dev);
147 val = gizmo_readl(ahb, AHB_ARBITRATION_XBAR_CTRL);
148 val |= AHB_ARBITRATION_XBAR_CTRL_SMMU_INIT_DONE;
149 gizmo_writel(ahb, val, AHB_ARBITRATION_XBAR_CTRL);
152 EXPORT_SYMBOL(tegra_ahb_enable_smmu);
155 static int __maybe_unused tegra_ahb_suspend(struct device *dev)
158 struct tegra_ahb *ahb = dev_get_drvdata(dev);
160 for (i = 0; i < ARRAY_SIZE(tegra_ahb_gizmo); i++)
161 ahb->ctx[i] = gizmo_readl(ahb, tegra_ahb_gizmo[i]);
165 static int __maybe_unused tegra_ahb_resume(struct device *dev)
168 struct tegra_ahb *ahb = dev_get_drvdata(dev);
170 for (i = 0; i < ARRAY_SIZE(tegra_ahb_gizmo); i++)
171 gizmo_writel(ahb, ahb->ctx[i], tegra_ahb_gizmo[i]);
175 static UNIVERSAL_DEV_PM_OPS(tegra_ahb_pm,
177 tegra_ahb_resume, NULL);
179 static void tegra_ahb_gizmo_init(struct tegra_ahb *ahb)
183 val = gizmo_readl(ahb, AHB_GIZMO_AHB_MEM);
184 val |= ENB_FAST_REARBITRATE | IMMEDIATE | DONT_SPLIT_AHB_WR;
185 gizmo_writel(ahb, val, AHB_GIZMO_AHB_MEM);
187 val = gizmo_readl(ahb, AHB_GIZMO_USB);
189 gizmo_writel(ahb, val, AHB_GIZMO_USB);
191 val = gizmo_readl(ahb, AHB_GIZMO_USB2);
193 gizmo_writel(ahb, val, AHB_GIZMO_USB2);
195 val = gizmo_readl(ahb, AHB_GIZMO_USB3);
197 gizmo_writel(ahb, val, AHB_GIZMO_USB3);
199 val = gizmo_readl(ahb, AHB_ARBITRATION_PRIORITY_CTRL);
200 val |= PRIORITY_SELECT_USB |
201 PRIORITY_SELECT_USB2 |
202 PRIORITY_SELECT_USB3 |
203 AHB_PRIORITY_WEIGHT(7);
204 gizmo_writel(ahb, val, AHB_ARBITRATION_PRIORITY_CTRL);
206 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG1);
208 val |= PREFETCH_ENB |
211 INACTIVITY_TIMEOUT(0x1000);
212 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG1);
214 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG2);
216 val |= PREFETCH_ENB |
219 INACTIVITY_TIMEOUT(0x1000);
220 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG2);
222 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG3);
224 val |= PREFETCH_ENB |
227 INACTIVITY_TIMEOUT(0x1000);
228 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG3);
230 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG4);
232 val |= PREFETCH_ENB |
235 INACTIVITY_TIMEOUT(0x1000);
236 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG4);
239 static int tegra_ahb_probe(struct platform_device *pdev)
241 struct resource *res;
242 struct tegra_ahb *ahb;
245 bytes = sizeof(*ahb) + sizeof(u32) * ARRAY_SIZE(tegra_ahb_gizmo);
246 ahb = devm_kzalloc(&pdev->dev, bytes, GFP_KERNEL);
250 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
252 /* Correct the IP block base address if necessary */
254 (res->start & INCORRECT_BASE_ADDR_LOW_BYTE) ==
255 INCORRECT_BASE_ADDR_LOW_BYTE) {
256 dev_warn(&pdev->dev, "incorrect AHB base address in DT data - enabling workaround\n");
257 res->start -= INCORRECT_BASE_ADDR_LOW_BYTE;
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);