blob: 64dc297ae27b31dbb75fe7c943a7b6dd1e0e0dd2 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Tom Warrenf80dd822015-02-02 13:22:29 -07002/*
3 * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
Tom Warrenf80dd822015-02-02 13:22:29 -07004 */
5
6#define pr_fmt(fmt) "tegra-xusb-padctl: " fmt
7
8#include <common.h>
9#include <errno.h>
Simon Glasscf0c6e22017-07-25 08:29:59 -060010#include <dm/of_access.h>
11#include <dm/ofnode.h>
Tom Warrenf80dd822015-02-02 13:22:29 -070012
Stephen Warren7de245d2015-10-23 10:50:51 -060013#include "../xusb-padctl-common.h"
Tom Warrenf80dd822015-02-02 13:22:29 -070014
15#include <asm/arch/clock.h>
Tom Warrenf80dd822015-02-02 13:22:29 -070016
17#include <dt-bindings/pinctrl/pinctrl-tegra-xusb.h>
18
Simon Glasscf0c6e22017-07-25 08:29:59 -060019DECLARE_GLOBAL_DATA_PTR;
20
Stephen Warrene3ba5692015-10-23 10:50:52 -060021enum tegra210_function {
22 TEGRA210_FUNC_SNPS,
23 TEGRA210_FUNC_XUSB,
24 TEGRA210_FUNC_UART,
25 TEGRA210_FUNC_PCIE_X1,
26 TEGRA210_FUNC_PCIE_X4,
27 TEGRA210_FUNC_USB3,
28 TEGRA210_FUNC_SATA,
29 TEGRA210_FUNC_RSVD,
30};
31
32static const char *const tegra210_functions[] = {
33 "snps",
34 "xusb",
35 "uart",
36 "pcie-x1",
37 "pcie-x4",
38 "usb3",
39 "sata",
40 "rsvd",
41};
42
43static const unsigned int tegra210_otg_functions[] = {
44 TEGRA210_FUNC_SNPS,
45 TEGRA210_FUNC_XUSB,
46 TEGRA210_FUNC_UART,
47 TEGRA210_FUNC_RSVD,
48};
49
50static const unsigned int tegra210_usb_functions[] = {
51 TEGRA210_FUNC_SNPS,
52 TEGRA210_FUNC_XUSB,
53};
54
55static const unsigned int tegra210_pci_functions[] = {
56 TEGRA210_FUNC_PCIE_X1,
57 TEGRA210_FUNC_USB3,
58 TEGRA210_FUNC_SATA,
59 TEGRA210_FUNC_PCIE_X4,
60};
61
62#define TEGRA210_LANE(_name, _offset, _shift, _mask, _iddq, _funcs) \
63 { \
64 .name = _name, \
65 .offset = _offset, \
66 .shift = _shift, \
67 .mask = _mask, \
68 .iddq = _iddq, \
69 .num_funcs = ARRAY_SIZE(tegra210_##_funcs##_functions), \
70 .funcs = tegra210_##_funcs##_functions, \
71 }
72
73static const struct tegra_xusb_padctl_lane tegra210_lanes[] = {
74 TEGRA210_LANE("otg-0", 0x004, 0, 0x3, 0, otg),
75 TEGRA210_LANE("otg-1", 0x004, 2, 0x3, 0, otg),
76 TEGRA210_LANE("otg-2", 0x004, 4, 0x3, 0, otg),
77 TEGRA210_LANE("otg-3", 0x004, 6, 0x3, 0, otg),
78 TEGRA210_LANE("usb2-bias", 0x004, 18, 0x3, 0, otg),
79 TEGRA210_LANE("hsic-0", 0x004, 14, 0x1, 0, usb),
80 TEGRA210_LANE("hsic-1", 0x004, 15, 0x1, 0, usb),
81 TEGRA210_LANE("pcie-0", 0x028, 12, 0x3, 1, pci),
82 TEGRA210_LANE("pcie-1", 0x028, 14, 0x3, 2, pci),
83 TEGRA210_LANE("pcie-2", 0x028, 16, 0x3, 3, pci),
84 TEGRA210_LANE("pcie-3", 0x028, 18, 0x3, 4, pci),
85 TEGRA210_LANE("pcie-4", 0x028, 20, 0x3, 5, pci),
86 TEGRA210_LANE("pcie-5", 0x028, 22, 0x3, 6, pci),
87 TEGRA210_LANE("pcie-6", 0x028, 24, 0x3, 7, pci),
88 TEGRA210_LANE("sata-0", 0x028, 30, 0x3, 8, pci),
89};
90
Tom Warrenf80dd822015-02-02 13:22:29 -070091#define XUSB_PADCTL_ELPG_PROGRAM 0x024
92#define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN (1 << 31)
93#define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY (1 << 30)
94#define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN (1 << 29)
95
96static int tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
97{
98 u32 value;
99
100 if (padctl->enable++ > 0)
101 return 0;
102
103 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
104 value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN;
105 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
106
107 udelay(100);
108
109 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
110 value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY;
111 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
112
113 udelay(100);
114
115 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
116 value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN;
117 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
118
119 return 0;
120}
121
122static int tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
123{
124 u32 value;
125
126 if (padctl->enable == 0) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900127 pr_err("unbalanced enable/disable");
Tom Warrenf80dd822015-02-02 13:22:29 -0700128 return 0;
129 }
130
131 if (--padctl->enable > 0)
132 return 0;
133
134 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
135 value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN;
136 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
137
138 udelay(100);
139
140 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
141 value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY;
142 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
143
144 udelay(100);
145
146 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
147 value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN;
148 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
149
150 return 0;
151}
152
153static int phy_prepare(struct tegra_xusb_phy *phy)
154{
155 int err;
156
157 err = tegra_xusb_padctl_enable(phy->padctl);
158 if (err < 0)
159 return err;
160
161 reset_set_enable(PERIPH_ID_PEX_USB_UPHY, 0);
162
163 return 0;
164}
165
166static int phy_unprepare(struct tegra_xusb_phy *phy)
167{
168 reset_set_enable(PERIPH_ID_PEX_USB_UPHY, 1);
169
170 return tegra_xusb_padctl_disable(phy->padctl);
171}
172
JC Kuof479aca2020-03-26 16:10:09 -0700173#define XUSB_PADCTL_USB3_PAD_MUX 0x28
174#define XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE (1 << 0)
175#define XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK0 (1 << 1)
176#define XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK1 (1 << 2)
177#define XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK2 (1 << 3)
178#define XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK3 (1 << 4)
179#define XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK4 (1 << 5)
180#define XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK5 (1 << 6)
181#define XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK6 (1 << 7)
182#define XUSB_PADCTL_USB3_PAD_MUX_FORCE_SATA_PAD_IDDQ_DISABLE_MASK0 (1 << 8)
183
Tom Warrenf80dd822015-02-02 13:22:29 -0700184#define XUSB_PADCTL_UPHY_PLL_P0_CTL1 0x360
185#define XUSB_PADCTL_UPHY_PLL_P0_CTL1_FREQ_NDIV_MASK (0xff << 20)
186#define XUSB_PADCTL_UPHY_PLL_P0_CTL1_FREQ_NDIV(x) (((x) & 0xff) << 20)
187#define XUSB_PADCTL_UPHY_PLL_P0_CTL1_FREQ_MDIV_MASK (0x3 << 16)
188#define XUSB_PADCTL_UPHY_PLL_P0_CTL1_LOCKDET_STATUS (1 << 15)
189#define XUSB_PADCTL_UPHY_PLL_P0_CTL1_PWR_OVRD (1 << 4)
190#define XUSB_PADCTL_UPHY_PLL_P0_CTL1_ENABLE (1 << 3)
191#define XUSB_PADCTL_UPHY_PLL_P0_CTL1_SLEEP_MASK (0x3 << 1)
192#define XUSB_PADCTL_UPHY_PLL_P0_CTL1_SLEEP(x) (((x) & 0x3) << 1)
193#define XUSB_PADCTL_UPHY_PLL_P0_CTL1_IDDQ (1 << 0)
194
195#define XUSB_PADCTL_UPHY_PLL_P0_CTL2 0x364
196#define XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_CTRL_MASK (0xffffff << 4)
197#define XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_CTRL(x) (((x) & 0xffffff) << 4)
198#define XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_OVRD (1 << 2)
199#define XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_DONE (1 << 1)
200#define XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_EN (1 << 0)
201
202#define XUSB_PADCTL_UPHY_PLL_P0_CTL4 0x36c
203#define XUSB_PADCTL_UPHY_PLL_P0_CTL4_TXCLKREF_EN (1 << 15)
204#define XUSB_PADCTL_UPHY_PLL_P0_CTL4_TXCLKREF_SEL_MASK (0x3 << 12)
205#define XUSB_PADCTL_UPHY_PLL_P0_CTL4_TXCLKREF_SEL(x) (((x) & 0x3) << 12)
206#define XUSB_PADCTL_UPHY_PLL_P0_CTL4_REFCLKBUF_EN (1 << 8)
207#define XUSB_PADCTL_UPHY_PLL_P0_CTL4_REFCLK_SEL_MASK (0xf << 4)
208
209#define XUSB_PADCTL_UPHY_PLL_P0_CTL5 0x370
210#define XUSB_PADCTL_UPHY_PLL_P0_CTL5_DCO_CTRL_MASK (0xff << 16)
211#define XUSB_PADCTL_UPHY_PLL_P0_CTL5_DCO_CTRL(x) (((x) & 0xff) << 16)
212
213#define XUSB_PADCTL_UPHY_PLL_P0_CTL8 0x37c
214#define XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_DONE (1 << 31)
215#define XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_OVRD (1 << 15)
216#define XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_CLK_EN (1 << 13)
217#define XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_EN (1 << 12)
218
219#define CLK_RST_XUSBIO_PLL_CFG0 0x51c
220#define CLK_RST_XUSBIO_PLL_CFG0_SEQ_ENABLE (1 << 24)
221#define CLK_RST_XUSBIO_PLL_CFG0_PADPLL_SLEEP_IDDQ (1 << 13)
222#define CLK_RST_XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET (1 << 6)
223#define CLK_RST_XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL (1 << 2)
224#define CLK_RST_XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL (1 << 0)
225
226static int pcie_phy_enable(struct tegra_xusb_phy *phy)
227{
228 struct tegra_xusb_padctl *padctl = phy->padctl;
229 unsigned long start;
230 u32 value;
231
232 debug("> %s(phy=%p)\n", __func__, phy);
233
234 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
235 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_CTRL_MASK;
236 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_CTRL(0x136);
237 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
238
239 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL5);
240 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL5_DCO_CTRL_MASK;
241 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL5_DCO_CTRL(0x2a);
242 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL5);
243
244 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
245 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL1_PWR_OVRD;
246 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
247
248 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
249 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_OVRD;
250 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
251
252 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
253 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_OVRD;
254 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
255
256 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL4);
257 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL4_TXCLKREF_SEL_MASK;
258 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL4_REFCLK_SEL_MASK;
259 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL4_TXCLKREF_SEL(2);
260 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL4_TXCLKREF_EN;
261 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL4);
262
263 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
264 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL1_FREQ_MDIV_MASK;
265 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL1_FREQ_NDIV_MASK;
266 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL1_FREQ_NDIV(25);
267 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
268
269 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
270 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL1_IDDQ;
271 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
272
273 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
274 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL1_SLEEP_MASK;
275 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
276
277 udelay(1);
278
279 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL4);
280 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL4_REFCLKBUF_EN;
281 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL4);
282
283 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
284 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_EN;
285 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
286
287 debug(" waiting for calibration\n");
288
289 start = get_timer(0);
290
291 while (get_timer(start) < 250) {
292 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
293 if (value & XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_DONE)
294 break;
295 }
Stephen Warren6f6ed1b2015-10-23 10:50:53 -0600296 if (!(value & XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_DONE)) {
297 debug(" timeout\n");
298 return -ETIMEDOUT;
299 }
Tom Warrenf80dd822015-02-02 13:22:29 -0700300 debug(" done\n");
301
302 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
303 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_EN;
304 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
305
306 debug(" waiting for calibration to stop\n");
307
308 start = get_timer(0);
309
310 while (get_timer(start) < 250) {
311 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL2);
312 if ((value & XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_DONE) == 0)
313 break;
314 }
Stephen Warren6f6ed1b2015-10-23 10:50:53 -0600315 if (value & XUSB_PADCTL_UPHY_PLL_P0_CTL2_CAL_DONE) {
316 debug(" timeout\n");
317 return -ETIMEDOUT;
318 }
Tom Warrenf80dd822015-02-02 13:22:29 -0700319 debug(" done\n");
320
321 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
322 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL1_ENABLE;
323 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
324
325 debug(" waiting for PLL to lock...\n");
326 start = get_timer(0);
327
328 while (get_timer(start) < 250) {
329 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
330 if (value & XUSB_PADCTL_UPHY_PLL_P0_CTL1_LOCKDET_STATUS)
331 break;
332 }
Stephen Warren6f6ed1b2015-10-23 10:50:53 -0600333 if (!(value & XUSB_PADCTL_UPHY_PLL_P0_CTL1_LOCKDET_STATUS)) {
334 debug(" timeout\n");
335 return -ETIMEDOUT;
336 }
Tom Warrenf80dd822015-02-02 13:22:29 -0700337 debug(" done\n");
338
339 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
340 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_CLK_EN;
341 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_EN;
342 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
343
344 debug(" waiting for register calibration...\n");
345 start = get_timer(0);
346
347 while (get_timer(start) < 250) {
348 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
349 if (value & XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_DONE)
350 break;
351 }
Stephen Warren6f6ed1b2015-10-23 10:50:53 -0600352 if (!(value & XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_DONE)) {
353 debug(" timeout\n");
354 return -ETIMEDOUT;
355 }
Tom Warrenf80dd822015-02-02 13:22:29 -0700356 debug(" done\n");
357
358 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
359 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_EN;
360 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
361
362 debug(" waiting for register calibration to stop...\n");
363 start = get_timer(0);
364
365 while (get_timer(start) < 250) {
366 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
367 if ((value & XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_DONE) == 0)
368 break;
369 }
Stephen Warren6f6ed1b2015-10-23 10:50:53 -0600370 if (value & XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_DONE) {
371 debug(" timeout\n");
372 return -ETIMEDOUT;
373 }
Tom Warrenf80dd822015-02-02 13:22:29 -0700374 debug(" done\n");
375
376 value = padctl_readl(padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
377 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL8_RCAL_CLK_EN;
378 padctl_writel(padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL8);
379
Tom Warrenf80dd822015-02-02 13:22:29 -0700380 debug("< %s()\n", __func__);
381 return 0;
382}
383
384static int pcie_phy_disable(struct tegra_xusb_phy *phy)
385{
386 return 0;
387}
388
389static const struct tegra_xusb_phy_ops pcie_phy_ops = {
390 .prepare = phy_prepare,
391 .enable = pcie_phy_enable,
392 .disable = pcie_phy_disable,
393 .unprepare = phy_unprepare,
394};
395
Stephen Warren7de245d2015-10-23 10:50:51 -0600396static struct tegra_xusb_phy tegra210_phys[] = {
397 {
398 .type = TEGRA_XUSB_PADCTL_PCIE,
399 .ops = &pcie_phy_ops,
400 .padctl = &padctl,
Tom Warrenf80dd822015-02-02 13:22:29 -0700401 },
402};
403
Stephen Warren7de245d2015-10-23 10:50:51 -0600404static const struct tegra_xusb_padctl_soc tegra210_socdata = {
Stephen Warrene3ba5692015-10-23 10:50:52 -0600405 .lanes = tegra210_lanes,
406 .num_lanes = ARRAY_SIZE(tegra210_lanes),
407 .functions = tegra210_functions,
408 .num_functions = ARRAY_SIZE(tegra210_functions),
Stephen Warren7de245d2015-10-23 10:50:51 -0600409 .phys = tegra210_phys,
410 .num_phys = ARRAY_SIZE(tegra210_phys),
411};
Tom Warrenf80dd822015-02-02 13:22:29 -0700412
Simon Glasscf0c6e22017-07-25 08:29:59 -0600413void tegra_xusb_padctl_init(void)
Tom Warrenf80dd822015-02-02 13:22:29 -0700414{
Simon Glasscf0c6e22017-07-25 08:29:59 -0600415 ofnode nodes[1];
416 int count = 0;
417 int ret;
Tom Warrenf80dd822015-02-02 13:22:29 -0700418
Simon Glasscf0c6e22017-07-25 08:29:59 -0600419 debug("%s: start\n", __func__);
420 if (of_live_active()) {
421 struct device_node *np = of_find_compatible_node(NULL, NULL,
422 "nvidia,tegra210-xusb-padctl");
Tom Warrenf80dd822015-02-02 13:22:29 -0700423
Simon Glasscf0c6e22017-07-25 08:29:59 -0600424 debug("np=%p\n", np);
425 if (np) {
426 nodes[0] = np_to_ofnode(np);
427 count = 1;
428 }
429 } else {
430 int node_offsets[1];
431 int i;
Tom Warrenf80dd822015-02-02 13:22:29 -0700432
Simon Glasscf0c6e22017-07-25 08:29:59 -0600433 count = fdtdec_find_aliases_for_id(gd->fdt_blob, "padctl",
434 COMPAT_NVIDIA_TEGRA210_XUSB_PADCTL,
435 node_offsets, ARRAY_SIZE(node_offsets));
436 for (i = 0; i < count; i++)
437 nodes[i] = offset_to_ofnode(node_offsets[i]);
438 }
439
440 ret = tegra_xusb_process_nodes(nodes, count, &tegra210_socdata);
441 debug("%s: done, ret=%d\n", __func__, ret);
Tom Warrenf80dd822015-02-02 13:22:29 -0700442}
JC Kuof479aca2020-03-26 16:10:09 -0700443
444void tegra_xusb_padctl_exit(void)
445{
446 u32 value;
447
448 debug("> %s\n", __func__);
449
450 value = padctl_readl(&padctl, XUSB_PADCTL_USB3_PAD_MUX);
451 value &= ~XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE;
452 value &= ~XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK0;
453 value &= ~XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK1;
454 value &= ~XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK2;
455 value &= ~XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK3;
456 value &= ~XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK4;
457 value &= ~XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK5;
458 value &= ~XUSB_PADCTL_USB3_PAD_MUX_FORCE_PCIE_PAD_IDDQ_DISABLE_MASK6;
459 value &= ~XUSB_PADCTL_USB3_PAD_MUX_FORCE_SATA_PAD_IDDQ_DISABLE_MASK0;
460 padctl_writel(&padctl, value, XUSB_PADCTL_USB3_PAD_MUX);
461
462 value = padctl_readl(&padctl, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
463 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL1_IDDQ;
464 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL1_SLEEP_MASK;
465 value |= XUSB_PADCTL_UPHY_PLL_P0_CTL1_SLEEP(3);
466 value &= ~XUSB_PADCTL_UPHY_PLL_P0_CTL1_ENABLE;
467 padctl_writel(&padctl, value, XUSB_PADCTL_UPHY_PLL_P0_CTL1);
468
469 reset_set_enable(PERIPH_ID_PEX_USB_UPHY, 1);
470 while (padctl.enable)
471 tegra_xusb_padctl_disable(&padctl);
472
473 debug("< %s()\n", __func__);
474}