blob: 3eaa459ae0579d0c839399874491cbd0d0723464 [file] [log] [blame]
Thomas Gleixner9c92ab62019-05-29 07:17:56 -07001// SPDX-License-Identifier: GPL-2.0-only
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +02002/*
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
4 * Copyright (C) 2011 Google, Inc.
5 *
6 * Author:
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>
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +020012 */
13
Thierry Reding903b33e2013-01-21 11:08:57 +010014#include <linux/err.h>
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +020015#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/io.h>
Paul Walmsley049e4b32015-03-26 08:53:57 +010019#include <linux/of.h>
Thierry Reding306a7f92014-07-17 13:17:24 +020020
21#include <soc/tegra/ahb.h>
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +020022
23#define DRV_NAME "tegra-ahb"
24
Paul Walmsley049e4b32015-03-26 08:53:57 +010025#define AHB_ARBITRATION_DISABLE 0x04
26#define AHB_ARBITRATION_PRIORITY_CTRL 0x08
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +020027#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)
31
Paul Walmsley049e4b32015-03-26 08:53:57 +010032#define AHB_GIZMO_AHB_MEM 0x10
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +020033#define ENB_FAST_REARBITRATE BIT(2)
34#define DONT_SPLIT_AHB_WR BIT(7)
35
Paul Walmsley049e4b32015-03-26 08:53:57 +010036#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
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +020052#define IMMEDIATE BIT(18)
53
Paul Walmsley049e4b32015-03-26 08:53:57 +010054#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
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +020063#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)
71
Paul Walmsley049e4b32015-03-26 08:53:57 +010072#define AHB_ARBITRATION_AHB_MEM_WRQUE_MST_ID 0xfc
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +020073
Hiroshi DOYU89c788b2012-05-07 09:43:46 +030074#define AHB_ARBITRATION_XBAR_CTRL_SMMU_INIT_DONE BIT(17)
75
Paul Walmsleyce7a10b2015-03-26 08:56:35 +010076/*
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
82 * correct it.
83 */
84#define INCORRECT_BASE_ADDR_LOW_BYTE 0x4
85
Hiroshi DOYU89c788b2012-05-07 09:43:46 +030086static struct platform_driver tegra_ahb_driver;
87
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +020088static const u32 tegra_ahb_gizmo[] = {
89 AHB_ARBITRATION_DISABLE,
90 AHB_ARBITRATION_PRIORITY_CTRL,
91 AHB_GIZMO_AHB_MEM,
92 AHB_GIZMO_APB_DMA,
93 AHB_GIZMO_IDE,
94 AHB_GIZMO_USB,
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,
100 AHB_GIZMO_NAND,
101 AHB_GIZMO_SDMMC4,
102 AHB_GIZMO_XIO,
103 AHB_GIZMO_BSEV,
104 AHB_GIZMO_BSEA,
105 AHB_GIZMO_NOR,
106 AHB_GIZMO_USB2,
107 AHB_GIZMO_USB3,
108 AHB_GIZMO_SDMMC1,
109 AHB_GIZMO_SDMMC2,
110 AHB_GIZMO_SDMMC3,
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,
118};
119
120struct tegra_ahb {
121 void __iomem *regs;
122 struct device *dev;
123 u32 ctx[0];
124};
125
126static inline u32 gizmo_readl(struct tegra_ahb *ahb, u32 offset)
127{
Paul Walmsleyce7a10b2015-03-26 08:56:35 +0100128 return readl(ahb->regs + offset);
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +0200129}
130
131static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset)
132{
Paul Walmsleyce7a10b2015-03-26 08:56:35 +0100133 writel(value, ahb->regs + offset);
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +0200134}
135
Hiroshi Doyub44bf432013-02-06 20:12:35 +0100136#ifdef CONFIG_TEGRA_IOMMU_SMMU
Hiroshi DOYU89c788b2012-05-07 09:43:46 +0300137static int tegra_ahb_match_by_smmu(struct device *dev, void *data)
138{
139 struct tegra_ahb *ahb = dev_get_drvdata(dev);
140 struct device_node *dn = data;
141
142 return (ahb->dev->of_node == dn) ? 1 : 0;
143}
144
145int tegra_ahb_enable_smmu(struct device_node *dn)
146{
147 struct device *dev;
148 u32 val;
149 struct tegra_ahb *ahb;
150
151 dev = driver_find_device(&tegra_ahb_driver.driver, NULL, dn,
152 tegra_ahb_match_by_smmu);
153 if (!dev)
154 return -EPROBE_DEFER;
155 ahb = dev_get_drvdata(dev);
156 val = gizmo_readl(ahb, AHB_ARBITRATION_XBAR_CTRL);
157 val |= AHB_ARBITRATION_XBAR_CTRL_SMMU_INIT_DONE;
158 gizmo_writel(ahb, val, AHB_ARBITRATION_XBAR_CTRL);
159 return 0;
160}
161EXPORT_SYMBOL(tegra_ahb_enable_smmu);
162#endif
163
Arnd Bergmann6d616562019-04-26 16:56:03 +0200164static int __maybe_unused tegra_ahb_suspend(struct device *dev)
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +0200165{
166 int i;
167 struct tegra_ahb *ahb = dev_get_drvdata(dev);
168
169 for (i = 0; i < ARRAY_SIZE(tegra_ahb_gizmo); i++)
170 ahb->ctx[i] = gizmo_readl(ahb, tegra_ahb_gizmo[i]);
171 return 0;
172}
173
Arnd Bergmann6d616562019-04-26 16:56:03 +0200174static int __maybe_unused tegra_ahb_resume(struct device *dev)
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +0200175{
176 int i;
177 struct tegra_ahb *ahb = dev_get_drvdata(dev);
178
179 for (i = 0; i < ARRAY_SIZE(tegra_ahb_gizmo); i++)
180 gizmo_writel(ahb, ahb->ctx[i], tegra_ahb_gizmo[i]);
181 return 0;
182}
183
184static UNIVERSAL_DEV_PM_OPS(tegra_ahb_pm,
185 tegra_ahb_suspend,
186 tegra_ahb_resume, NULL);
187
188static void tegra_ahb_gizmo_init(struct tegra_ahb *ahb)
189{
190 u32 val;
191
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);
195
196 val = gizmo_readl(ahb, AHB_GIZMO_USB);
197 val |= IMMEDIATE;
198 gizmo_writel(ahb, val, AHB_GIZMO_USB);
199
200 val = gizmo_readl(ahb, AHB_GIZMO_USB2);
201 val |= IMMEDIATE;
202 gizmo_writel(ahb, val, AHB_GIZMO_USB2);
203
204 val = gizmo_readl(ahb, AHB_GIZMO_USB3);
205 val |= IMMEDIATE;
206 gizmo_writel(ahb, val, AHB_GIZMO_USB3);
207
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);
214
215 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG1);
216 val &= ~MST_ID(~0);
217 val |= PREFETCH_ENB |
218 AHBDMA_MST_ID |
219 ADDR_BNDRY(0xc) |
220 INACTIVITY_TIMEOUT(0x1000);
221 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG1);
222
223 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG2);
224 val &= ~MST_ID(~0);
225 val |= PREFETCH_ENB |
226 USB_MST_ID |
227 ADDR_BNDRY(0xc) |
228 INACTIVITY_TIMEOUT(0x1000);
229 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG2);
230
231 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG3);
232 val &= ~MST_ID(~0);
233 val |= PREFETCH_ENB |
234 USB3_MST_ID |
235 ADDR_BNDRY(0xc) |
236 INACTIVITY_TIMEOUT(0x1000);
237 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG3);
238
239 val = gizmo_readl(ahb, AHB_MEM_PREFETCH_CFG4);
240 val &= ~MST_ID(~0);
241 val |= PREFETCH_ENB |
242 USB2_MST_ID |
243 ADDR_BNDRY(0xc) |
244 INACTIVITY_TIMEOUT(0x1000);
245 gizmo_writel(ahb, val, AHB_MEM_PREFETCH_CFG4);
246}
247
Greg Kroah-Hartmanc571b212012-12-21 13:16:42 -0800248static int tegra_ahb_probe(struct platform_device *pdev)
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +0200249{
250 struct resource *res;
251 struct tegra_ahb *ahb;
252 size_t bytes;
253
254 bytes = sizeof(*ahb) + sizeof(u32) * ARRAY_SIZE(tegra_ahb_gizmo);
255 ahb = devm_kzalloc(&pdev->dev, bytes, GFP_KERNEL);
256 if (!ahb)
257 return -ENOMEM;
258
259 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Paul Walmsleyce7a10b2015-03-26 08:56:35 +0100260
261 /* Correct the IP block base address if necessary */
262 if (res &&
263 (res->start & INCORRECT_BASE_ADDR_LOW_BYTE) ==
264 INCORRECT_BASE_ADDR_LOW_BYTE) {
265 dev_warn(&pdev->dev, "incorrect AHB base address in DT data - enabling workaround\n");
266 res->start -= INCORRECT_BASE_ADDR_LOW_BYTE;
267 }
268
Thierry Reding903b33e2013-01-21 11:08:57 +0100269 ahb->regs = devm_ioremap_resource(&pdev->dev, res);
270 if (IS_ERR(ahb->regs))
271 return PTR_ERR(ahb->regs);
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +0200272
273 ahb->dev = &pdev->dev;
274 platform_set_drvdata(pdev, ahb);
275 tegra_ahb_gizmo_init(ahb);
276 return 0;
277}
278
Greg Kroah-Hartmanc571b212012-12-21 13:16:42 -0800279static const struct of_device_id tegra_ahb_of_match[] = {
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +0200280 { .compatible = "nvidia,tegra30-ahb", },
281 { .compatible = "nvidia,tegra20-ahb", },
282 {},
283};
284
285static struct platform_driver tegra_ahb_driver = {
286 .probe = tegra_ahb_probe,
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +0200287 .driver = {
288 .name = DRV_NAME,
Hiroshi DOYU87d0bab22012-05-07 12:24:48 +0200289 .of_match_table = tegra_ahb_of_match,
290 .pm = &tegra_ahb_pm,
291 },
292};
293module_platform_driver(tegra_ahb_driver);
294
295MODULE_AUTHOR("Hiroshi DOYU <hdoyu@nvidia.com>");
296MODULE_DESCRIPTION("Tegra AHB driver");
297MODULE_LICENSE("GPL v2");
298MODULE_ALIAS("platform:" DRV_NAME);