blob: 69736aa392553194b3a6b71d9fb341442e6a373c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Thierry Reding79c7a902014-12-09 22:25:09 -07002/*
Stephen Warren1680d7b2015-10-23 10:50:49 -06003 * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
Thierry Reding79c7a902014-12-09 22:25:09 -07004 */
5
6#define pr_fmt(fmt) "tegra-xusb-padctl: " fmt
7
8#include <common.h>
9#include <errno.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Simon Glassbe789092017-07-25 08:29:59 -060011#include <dm/of_access.h>
12#include <dm/ofnode.h>
Simon Glassc05ed002020-05-10 11:40:11 -060013#include <linux/delay.h>
Simon Glass1e94b462023-09-14 18:21:46 -060014#include <linux/printk.h>
Simon Glass401d1c42020-10-30 21:38:53 -060015#include <asm/global_data.h>
Thierry Reding79c7a902014-12-09 22:25:09 -070016
Stephen Warren1680d7b2015-10-23 10:50:49 -060017#include "../xusb-padctl-common.h"
18
Thierry Reding79c7a902014-12-09 22:25:09 -070019#include <dt-bindings/pinctrl/pinctrl-tegra-xusb.h>
20
21#define XUSB_PADCTL_ELPG_PROGRAM 0x01c
22#define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN (1 << 26)
23#define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY (1 << 25)
24#define XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN (1 << 24)
25
26#define XUSB_PADCTL_IOPHY_PLL_P0_CTL1 0x040
27#define XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL0_LOCKDET (1 << 19)
28#define XUSB_PADCTL_IOPHY_PLL_P0_CTL1_REFCLK_SEL_MASK (0xf << 12)
29#define XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST (1 << 1)
30
31#define XUSB_PADCTL_IOPHY_PLL_P0_CTL2 0x044
32#define XUSB_PADCTL_IOPHY_PLL_P0_CTL2_REFCLKBUF_EN (1 << 6)
33#define XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_EN (1 << 5)
34#define XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_SEL (1 << 4)
35
36#define XUSB_PADCTL_IOPHY_PLL_S0_CTL1 0x138
37#define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_LOCKDET (1 << 27)
38#define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE (1 << 24)
39#define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD (1 << 3)
40#define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST (1 << 1)
41#define XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ (1 << 0)
42
43#define XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1 0x148
44#define XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD (1 << 1)
45#define XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ (1 << 0)
46
47enum tegra124_function {
48 TEGRA124_FUNC_SNPS,
49 TEGRA124_FUNC_XUSB,
50 TEGRA124_FUNC_UART,
51 TEGRA124_FUNC_PCIE,
52 TEGRA124_FUNC_USB3,
53 TEGRA124_FUNC_SATA,
54 TEGRA124_FUNC_RSVD,
55};
56
57static const char *const tegra124_functions[] = {
58 "snps",
59 "xusb",
60 "uart",
61 "pcie",
62 "usb3",
63 "sata",
64 "rsvd",
65};
66
67static const unsigned int tegra124_otg_functions[] = {
68 TEGRA124_FUNC_SNPS,
69 TEGRA124_FUNC_XUSB,
70 TEGRA124_FUNC_UART,
71 TEGRA124_FUNC_RSVD,
72};
73
74static const unsigned int tegra124_usb_functions[] = {
75 TEGRA124_FUNC_SNPS,
76 TEGRA124_FUNC_XUSB,
77};
78
79static const unsigned int tegra124_pci_functions[] = {
80 TEGRA124_FUNC_PCIE,
81 TEGRA124_FUNC_USB3,
82 TEGRA124_FUNC_SATA,
83 TEGRA124_FUNC_RSVD,
84};
85
Thierry Reding79c7a902014-12-09 22:25:09 -070086#define TEGRA124_LANE(_name, _offset, _shift, _mask, _iddq, _funcs) \
87 { \
88 .name = _name, \
89 .offset = _offset, \
90 .shift = _shift, \
91 .mask = _mask, \
92 .iddq = _iddq, \
93 .num_funcs = ARRAY_SIZE(tegra124_##_funcs##_functions), \
94 .funcs = tegra124_##_funcs##_functions, \
95 }
96
97static const struct tegra_xusb_padctl_lane tegra124_lanes[] = {
98 TEGRA124_LANE("otg-0", 0x004, 0, 0x3, 0, otg),
99 TEGRA124_LANE("otg-1", 0x004, 2, 0x3, 0, otg),
100 TEGRA124_LANE("otg-2", 0x004, 4, 0x3, 0, otg),
101 TEGRA124_LANE("ulpi-0", 0x004, 12, 0x1, 0, usb),
102 TEGRA124_LANE("hsic-0", 0x004, 14, 0x1, 0, usb),
103 TEGRA124_LANE("hsic-1", 0x004, 15, 0x1, 0, usb),
104 TEGRA124_LANE("pcie-0", 0x134, 16, 0x3, 1, pci),
105 TEGRA124_LANE("pcie-1", 0x134, 18, 0x3, 2, pci),
106 TEGRA124_LANE("pcie-2", 0x134, 20, 0x3, 3, pci),
107 TEGRA124_LANE("pcie-3", 0x134, 22, 0x3, 4, pci),
108 TEGRA124_LANE("pcie-4", 0x134, 24, 0x3, 5, pci),
109 TEGRA124_LANE("sata-0", 0x134, 26, 0x3, 6, pci),
110};
111
Thierry Reding79c7a902014-12-09 22:25:09 -0700112static int tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
113{
114 u32 value;
115
116 if (padctl->enable++ > 0)
117 return 0;
118
119 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
120 value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN;
121 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
122
123 udelay(100);
124
125 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
126 value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY;
127 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
128
129 udelay(100);
130
131 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
132 value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN;
133 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
134
135 return 0;
136}
137
138static int tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
139{
140 u32 value;
141
142 if (padctl->enable == 0) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900143 pr_err("unbalanced enable/disable");
Thierry Reding79c7a902014-12-09 22:25:09 -0700144 return 0;
145 }
146
147 if (--padctl->enable > 0)
148 return 0;
149
150 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
151 value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN;
152 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
153
154 udelay(100);
155
156 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
157 value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN_EARLY;
158 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
159
160 udelay(100);
161
162 value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
163 value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN;
164 padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
165
166 return 0;
167}
168
169static int phy_prepare(struct tegra_xusb_phy *phy)
170{
171 return tegra_xusb_padctl_enable(phy->padctl);
172}
173
174static int phy_unprepare(struct tegra_xusb_phy *phy)
175{
176 return tegra_xusb_padctl_disable(phy->padctl);
177}
178
179static int pcie_phy_enable(struct tegra_xusb_phy *phy)
180{
181 struct tegra_xusb_padctl *padctl = phy->padctl;
182 int err = -ETIMEDOUT;
183 unsigned long start;
184 u32 value;
185
186 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
187 value &= ~XUSB_PADCTL_IOPHY_PLL_P0_CTL1_REFCLK_SEL_MASK;
188 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
189
190 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_P0_CTL2);
191 value |= XUSB_PADCTL_IOPHY_PLL_P0_CTL2_REFCLKBUF_EN |
192 XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_EN |
193 XUSB_PADCTL_IOPHY_PLL_P0_CTL2_TXCLKREF_SEL;
194 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_P0_CTL2);
195
196 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
197 value |= XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST;
198 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
199
200 start = get_timer(0);
201
202 while (get_timer(start) < 50) {
203 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
204 if (value & XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL0_LOCKDET) {
205 err = 0;
206 break;
207 }
208 }
209
210 return err;
211}
212
213static int pcie_phy_disable(struct tegra_xusb_phy *phy)
214{
215 struct tegra_xusb_padctl *padctl = phy->padctl;
216 u32 value;
217
218 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
219 value &= ~XUSB_PADCTL_IOPHY_PLL_P0_CTL1_PLL_RST;
220 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_P0_CTL1);
221
222 return 0;
223}
224
225static int sata_phy_enable(struct tegra_xusb_phy *phy)
226{
227 struct tegra_xusb_padctl *padctl = phy->padctl;
228 int err = -ETIMEDOUT;
229 unsigned long start;
230 u32 value;
231
232 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1);
233 value &= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD;
234 value &= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ;
235 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1);
236
237 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
238 value &= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD;
239 value &= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ;
240 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
241
242 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
243 value |= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE;
244 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
245
246 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
247 value |= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST;
248 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
249
250 start = get_timer(0);
251
252 while (get_timer(start) < 50) {
253 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
254 if (value & XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_LOCKDET) {
255 err = 0;
256 break;
257 }
258 }
259
260 return err;
261}
262
263static int sata_phy_disable(struct tegra_xusb_phy *phy)
264{
265 struct tegra_xusb_padctl *padctl = phy->padctl;
266 u32 value;
267
268 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
269 value &= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_RST;
270 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
271
272 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
273 value &= ~XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL1_MODE;
274 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
275
276 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
277 value |= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_PWR_OVRD;
278 value |= XUSB_PADCTL_IOPHY_PLL_S0_CTL1_PLL_IDDQ;
279 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_PLL_S0_CTL1);
280
281 value = padctl_readl(padctl, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1);
282 value |= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ_OVRD;
283 value |= ~XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1_IDDQ;
284 padctl_writel(padctl, value, XUSB_PADCTL_IOPHY_MISC_PAD_S0_CTL1);
285
286 return 0;
287}
288
289static const struct tegra_xusb_phy_ops pcie_phy_ops = {
290 .prepare = phy_prepare,
291 .enable = pcie_phy_enable,
292 .disable = pcie_phy_disable,
293 .unprepare = phy_unprepare,
294};
295
296static const struct tegra_xusb_phy_ops sata_phy_ops = {
297 .prepare = phy_prepare,
298 .enable = sata_phy_enable,
299 .disable = sata_phy_disable,
300 .unprepare = phy_unprepare,
301};
302
Stephen Warren095e6582015-10-23 10:50:50 -0600303static struct tegra_xusb_phy tegra124_phys[] = {
304 {
305 .type = TEGRA_XUSB_PADCTL_PCIE,
306 .ops = &pcie_phy_ops,
307 .padctl = &padctl,
308 },
309 {
310 .type = TEGRA_XUSB_PADCTL_SATA,
311 .ops = &sata_phy_ops,
312 .padctl = &padctl,
Thierry Reding79c7a902014-12-09 22:25:09 -0700313 },
314};
315
Stephen Warren095e6582015-10-23 10:50:50 -0600316static const struct tegra_xusb_padctl_soc tegra124_socdata = {
317 .lanes = tegra124_lanes,
318 .num_lanes = ARRAY_SIZE(tegra124_lanes),
319 .functions = tegra124_functions,
320 .num_functions = ARRAY_SIZE(tegra124_functions),
321 .phys = tegra124_phys,
322 .num_phys = ARRAY_SIZE(tegra124_phys),
323};
Thierry Reding79c7a902014-12-09 22:25:09 -0700324
Simon Glassbe789092017-07-25 08:29:59 -0600325void tegra_xusb_padctl_init(void)
Thierry Reding79c7a902014-12-09 22:25:09 -0700326{
Simon Glassbe789092017-07-25 08:29:59 -0600327 ofnode nodes[1];
328 int count = 0;
329 int ret;
Thierry Reding79c7a902014-12-09 22:25:09 -0700330
Simon Glassbe789092017-07-25 08:29:59 -0600331 debug("%s: start\n", __func__);
332 if (of_live_active()) {
333 struct device_node *np = of_find_compatible_node(NULL, NULL,
334 "nvidia,tegra124-xusb-padctl");
335
336 debug("np=%p\n", np);
337 if (np) {
338 nodes[0] = np_to_ofnode(np);
339 count = 1;
340 }
341 } else {
342 int node_offsets[1];
343 int i;
344
345 count = fdtdec_find_aliases_for_id(gd->fdt_blob, "padctl",
346 COMPAT_NVIDIA_TEGRA124_XUSB_PADCTL,
347 node_offsets, ARRAY_SIZE(node_offsets));
348 for (i = 0; i < count; i++)
349 nodes[i] = offset_to_ofnode(node_offsets[i]);
350 }
351
352 ret = tegra_xusb_process_nodes(nodes, count, &tegra124_socdata);
353 debug("%s: done, ret=%d\n", __func__, ret);
Thierry Reding79c7a902014-12-09 22:25:09 -0700354}