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