2 * Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 #include <linux/delay.h>
16 #include <linux/module.h>
18 #include <linux/phy/phy.h>
19 #include <linux/pinctrl/pinctrl.h>
20 #include <linux/pinctrl/pinmux.h>
21 #include <linux/platform_device.h>
22 #include <linux/regulator/consumer.h>
23 #include <linux/workqueue.h>
24 #include <linux/tegra-fuse.h>
25 #include <linux/tegra-soc.h>
26 #include <linux/clk/tegra.h>
27 #include <linux/tegra_prod.h>
29 #define TEGRA_XUSB_PCIE_PHYS 1
30 #define TEGRA_XUSB_SATA_PHYS 1
31 #define TEGRA_XUSB_UFS_PHYS 1
32 #define TEGRA_XUSB_USB3_PHYS 3
33 #define TEGRA_XUSB_UTMI_PHYS 3
34 #define TEGRA_XUSB_HSIC_PHYS 1
35 #define TEGRA_XUSB_NUM_USB_PHYS (TEGRA_XUSB_USB3_PHYS + TEGRA_XUSB_UTMI_PHYS + \
37 #define TEGRA_XUSB_NUM_PHYS (TEGRA_XUSB_NUM_USB_PHYS + TEGRA_XUSB_PCIE_PHYS + \
38 TEGRA_XUSB_SATA_PHYS + TEGRA_XUSB_UFS_PHYS)
40 #include <dt-bindings/pinctrl/pinctrl-tegra-xusb.h>
41 #include "../../../arch/arm/mach-tegra/iomap.h" /* FIXME */
46 #define TRACE(fmt, args...) pr_info("%s %d " fmt "\n", __func__, __LINE__, ## args)
51 #define TRACE_DEV(dev, fmt, args...) dev_info(dev, "%s %d " fmt "\n", __func__, __LINE__, ## args)
54 #include "pinctrl-utils.h"
56 #define T186_UPHY_LANES (6)
58 /* UPHY PLL registers */
59 #define UPHY_PLL_CTL_1 (0x0)
60 #define PLL_IDDQ (1 << 0)
61 #define PLL_SLEEP(x) (((x) & 0x3) << 1)
62 #define PLL_ENABLE (1 << 3)
63 #define PWR_OVRD (1 << 4)
64 #define RATE_ID(x) (((x) & 0x3) << 8)
65 #define RATE_ID_OVRD (1 << 11)
66 #define LOCKDET_STATUS (1 << 15)
68 #define UPHY_PLL_CTL_2 (0x4)
69 #define CAL_EN (1 << 0)
70 #define CAL_DONE (1 << 1)
71 #define CAL_OVRD (1 << 2)
72 #define CAL_RESET (1 << 3)
73 #define RCAL_EN (1 << 12)
74 #define RCAL_CLK_EN (1 << 13)
75 #define RCAL_OVRD (1 << 15)
76 #define RCAL_DONE (1 << 31)
78 #define UPHY_PLL_CTL_4 (0xc)
80 /* UPHY Lane registers */
81 #define UPHY_LANE_AUX_CTL_1 (0x0)
82 #define AUX_RX_IDLE_TH(x) (((x) & 0x3) << 24)
84 #define UPHY_LANE_DIRECT_CTL_1 (0x10)
85 #define MISC_CTRL(x) (((x) & 0xff) << 0)
86 #define MISC_OUT(x) (((x) & 0xff) << 16)
88 #define UPHY_LANE_DIRECT_CTL_2 (0x14)
89 #define CFG_WDATA(x) (((x) & 0xffff) << 0)
90 #define CFG_ADDR(x) (((x) & 0xff) << 16)
91 #define CFG_WDS(x) (((x) & 0x1) << 24)
92 #define CFG_RDS(x) (((x) & 0x1) << 25)
93 #define CFG_RESET(x) (((x) & 0x1) << 27)
95 #define UPHY_LANE_MUX (0x284)
96 #define SEL(x) (((x) & 0x7) << 0)
97 #define SEL_XUSB SEL(0)
98 #define SEL_PCIE SEL(1)
99 #define SEL_SATA SEL(2)
100 #define SEL_MPHY SEL(3)
101 #define CLAMP_EN_EARLY (1 << 8)
102 #define FORCE_IDDQ_DISABLE (1 << 9)
104 /* UPHY APB Dynamic DYN_CTL registers */
105 #define UPHY_LANE_DYN_CTL_1 (0x80)
106 #define TX_DRV_AMP_SEL0(x) (((x) & 0x3f) << 0)
107 #define TX_DRV_AMP_SEL1(x) (((x) & 0x3f) << 8)
108 #define TX_DRV_AMP_SEL2(x) (((x) & 0x3f) << 16)
109 #define TX_DRV_AMP_SEL3(x) (((x) & 0x3f) << 24)
111 #define UPHY_LANE_DYN_CTL_2 (0x84)
112 #define TX_DRV_AMP_SEL4(x) (((x) & 0x3f) << 0)
113 #define TX_DRV_AMP_SEL5(x) (((x) & 0x3f) << 8)
114 #define TX_DRV_AMP_SEL6(x) (((x) & 0x3f) << 16)
115 #define TX_DRV_AMP_SEL7(x) (((x) & 0x3f) << 24)
117 #define UPHY_LANE_DYN_CTL_3 (0x88)
118 #define TX_DRV_AMP_SEL8(x) (((x) & 0x3f) << 0)
119 #define TX_DRV_AMP_SEL9(x) (((x) & 0x3f) << 8)
121 #define UPHY_LANE_DYN_CTL_4 (0x8c)
122 #define TX_DRV_POST_SEL0(x) (((x) & 0x3f) << 0)
123 #define TX_DRV_PRE_SEL0(x) (((x) & 0x3f) << 8)
124 #define TX_DRV_POST_SEL1(x) (((x) & 0x3f) << 16)
125 #define TX_DRV_PRE_SEL1(x) (((x) & 0x3f) << 24)
127 #define UPHY_LANE_DYN_CTL_5 (0x90)
128 #define TX_DRV_POST_SEL2(x) (((x) & 0x3f) << 0)
129 #define TX_DRV_PRE_SEL2(x) (((x) & 0x3f) << 8)
130 #define TX_DRV_POST_SEL3(x) (((x) & 0x3f) << 16)
131 #define TX_DRV_PRE_SEL3(x) (((x) & 0x3f) << 24)
133 /* FUSE USB_CALIB registers */ /* TODO: check spec */
134 #define USB_CALIB_HS_CURR_LEVEL_PADX_SHIFT(x) ((x) ? (11 + (x - 1) * 6) : 0)
135 #define USB_CALIB_HS_CURR_LEVEL_PAD_MASK (0x3f)
136 #define USB_CALIB_HS_TERM_RANGE_ADJ_SHIFT (7)
137 #define USB_CALIB_HS_TERM_RANGE_ADJ_MASK (0xf)
139 #define USB_CALIB_EXT_RPD_CTRL_SHIFT (7)
140 #define USB_CALIB_EXT_RPD_CTRL_MASK (0xf)
142 /* FUSE SATA MPHY registers */
143 #define FUSE_SATA_MPHY_ODM_CALIB_0 (0x224)
144 #define SATA_MPHY_ODM_CALIB_0_1(x) (((x) & 0x3) << 0)
146 #define FUSE_SATA_NV_CALIB_0 (0x49c)
147 #define SATA_NV_CALIB_0_1(x) (((x) & (0x3 << 0)) >> 0)
148 #define SATA_NV_CALIB_2_3(x) (((x) & (0x3 << 2)) >> 2)
150 #define FUSE_MPHY_NV_CALIB_0 (0x4a0)
151 #define MPHY_NV_CALIB_0_1(x) (((x) & (0x3 << 0)) >> 0)
152 #define MPHY_NV_CALIB_2_3(x) (((x) & (0x3 << 2)) >> 2)
153 #define MPHY_NV_CALIB_4_5(x) (((x) & (0x3 << 4)) >> 4)
155 /* XUSB PADCTL registers */
156 #define XUSB_PADCTL_USB2_PAD_MUX (0x4)
158 #define XUSB_PADCTL_USB2_PORT_CAP (0x8)
159 #define XUSB_PADCTL_SS_PORT_CAP (0xc)
160 #define PORTX_CAP_SHIFT(x) ((x) * 4)
161 #define PORT_CAP_MASK (0x3)
162 #define PORT_CAP_DISABLED (0x0)
163 #define PORT_CAP_HOST (0x1)
164 #define PORT_CAP_DEVICE (0x2)
165 #define PORT_CAP_OTG (0x3)
167 #define XUSB_PADCTL_ELPG_PROGRAM (0x20)
169 #define XUSB_PADCTL_ELPG_PROGRAM_1 (0x24)
170 #define SSPX_ELPG_CLAMP_EN(x) (1 << (0 + (x) * 3))
171 #define SSPX_ELPG_CLAMP_EN_EARLY(x) (1 << (1 + (x) * 3))
172 #define SSPX_ELPG_VCORE_DOWN(x) (1 << (2 + (x) * 3))
174 #define USB2_BATTERY_CHRG_OTGPADX_CTL1(x) (0x84 + (x) * 0x40)
175 #define VREG_LEV(x) (((x) & 0x3) << 7)
176 #define VREG_FIX18 (1 << 6)
178 #define XUSB_PADCTL_USB2_OTG_PADX_CTL0(x) (0x88 + (x) * 0x40)
179 #define HS_CURR_LEVEL(x) ((x) & 0x3f)
180 #define USB2_OTG_PD (1 << 26)
181 #define USB2_OTG_PD2 (1 << 27)
182 #define USB2_OTG_PD_ZI (1 << 29)
184 #define XUSB_PADCTL_USB2_OTG_PADX_CTL1(x) (0x8c + (x) * 0x40)
185 #define USB2_OTG_PD_DR (1 << 2)
186 #define TERM_RANGE_ADJ(x) (((x) & 0xf) << 3)
187 #define RPD_CTRL(x) (((x) & 0x1f) << 26)
189 #define XUSB_PADCTL_USB2_BIAS_PAD_CTL0 (0x284)
190 #define BIAS_PAD_PD (1 << 11)
192 #define USB2_VBUS_ID (0x360)
193 #define VBUS_OVERRIDE (1 << 14)
195 /* XUSB AO registers */
196 #define XUSB_AO_UTMIP_TRIGGERS(x) (0x40 + (x) * 4)
197 #define CLR_WALK_PTR (1 << 0)
198 #define CAP_CFG (1 << 1)
199 #define CLR_WAKE_ALARM (1 << 3)
201 #define XUSB_AO_UTMIP_SLEEPWALK_CFG(x) (0xd0 + (x) * 4)
202 #define XUSB_AO_UHSIC_SLEEPWALK_CFG(x) (0xf0 + (x) * 4)
203 #define MASTER_ENABLE (1 << 15)
204 #define MASTER_CFG_SEL (1 << 22)
206 #define XUSB_AO_UTMIP_SLEEPWALK(x) (0x120 + (x) * 4)
207 #if 0 /* TODO: implement */
208 #define padctl_ao_readl padctl_readl /* FIXME */
209 #define padctl_ao_writel padctl_writel /* FIXME */
210 static int utmip_setup_sleepwalk(struct tegra_padctl_uphy *ctx, int pad)
214 /* ensure sleepwalk logic is disabled */
215 reg = padctl_ao_readl(ctx, XUSB_AO_UTMIP_SLEEPWALK_CFG(pad));
216 reg &= ~MASTER_ENABLE;
217 padctl_ao_writel(ctx, reg, XUSB_AO_UTMIP_SLEEPWALK_CFG(pad));
223 /* UPHY PLL config space registers */
224 #define MGMT_FREQ_CTRL_ID0 (0)
225 #define MGMT_FREQ_CTRL_ID1 (1)
226 #define CFG_FREQ_NDIV(x) (((x) & 0xff) << 0)
227 #define CFG_FREQ_MDIV(x) (((x) & 0x3) << 8)
228 #define CFG_FREQ_PSDIV(x) (((x) & 0x3) << 10)
229 #define CFG_MODE(x) (((x) & 0x3) << 12)
231 #define MGMT_REFCLK_CTRL (2)
233 #define MGMT_CORECLK_CTRL_ID0 (3)
234 #define MGMT_CORECLK_CTRL_ID1 (4)
235 #define CFG_TXCLKREF_EN(x) (((x) & 0x1) << 0)
236 #define CFG_TXCLKREF_SEL(x) (((x) & 0x3) << 4)
237 #define DIVIDE_TX_BY_10 (0)
238 #define DIVIDE_TX_BY_8 (1)
239 #define DIVIDE_TX_BY_5 (2)
240 #define DIVIDE_TX_BY_4 (3)
241 #define CFG_XDIGCLK_EN(x) (((x) & 0x1) << 8)
242 #define CFG_XDIGCLK_SEL(x) (((x) & 0x3) << 12)
244 #define PLLC_CRSWRD_OVRD_ID0 (5)
246 #define PLLC_CRSWRD_OVRD_ID1 (6)
248 #define MGMT_CYA_CTRL (29)
249 #define CFG_MGMT_CLK_SEL(x) (((x) & 0x1) << 4)
251 /* UPHY Lane config space registers */
252 #define MGMT_TX_RATE_CTRL_ID0 (0)
253 #define MGMT_TX_RATE_CTRL_ID1 (1)
254 #define MGMT_TX_RATE_CTRL_ID2 (2)
255 #define MGMT_TX_RATE_CTRL_ID3 (3)
256 #define TX_RATE_SDIV(x) (((x) & 0x3) << 0)
262 #define MGMT_RX_RATE_CTRL_ID0 (4)
263 #define MGMT_RX_RATE_CTRL_ID1 (5)
264 #define MGMT_RX_RATE_CTRL_ID2 (6)
265 #define MGMT_RX_RATE_CTRL_ID3 (7)
266 #define RX_RATE_SDIV(x) (((x) & 0x3) << 0)
267 #define RX_RATE_CDIV(x) (((x) & 0x3) << 4)
273 #define MGMT_TX_CTRL (8)
274 #define TX_TERM_MODE(x) (((x) & 0x1) << 0)
275 #define SYNC_DLY(x) (((x) & 0xf) << 4)
277 #define AE_CTLE_CTRL_ID0 (10)
278 #define AE_CTLE_CTRL_ID1 (11)
279 #define AE_CTLE_CTRL_ID2 (12)
280 #define AE_CTLE_CTRL_ID3 (13)
281 #define LF_UGRAY(x) (((x) & 0xf) << 0)
282 #define HF_UBIN(x) (((x) & 0xf) << 4)
284 #define AE_DFE0_CTRL_ID0 (14)
285 #define AE_DFE0_CTRL_ID1 (15)
286 #define AE_DFE0_CTRL_ID2 (16)
287 #define AE_DFE1_CTRL_ID2 (20)
288 #define H1_SBIN(x) (((x) & 0x1f) << 0)
289 #define H2_SBIN(x) (((x) & 0xf) << 8)
290 #define H3_SBIN(x) (((x) & 0x7) << 12)
292 #define AE_DFE1_CTRL_ID0 (18)
293 #define H4_SBIN(x) (((x) & 0x7) << 0)
294 #define H0_SBIN(x) (((x) & 0x3f) << 8)
296 #define AE_CDR_CTRL_ID0 (22)
297 #define AE_CDR_CTRL_ID1 (23)
298 #define AE_CDR_CTRL_ID2 (24)
299 #define AE_CDR_CTRL_ID3 (25)
300 #define PHGAIN(x) (((x) & 0xf) << 0)
301 #define FRGAIN(x) (((x) & 0xf) << 4)
302 #define FRLOOP_EN(x) (((x) & 0x1) << 8)
304 #define AE_EQ0_CTRL_ID0 (26)
305 #define AE_EQ0_CTRL_ID1 (27)
306 #define AE_EQ0_CTRL_ID2 (28)
307 #define EQ0_SEQ_MODE(x) (((x) & 0x3) << 0)
308 #define SEQ_MODE_HF_Z_H0_HN_Z (0)
309 #define SEQ_MODE_H0_HN_Z_HF_Z (1)
310 #define SEQ_MODE_HF_H0_HN_Z (2)
311 #define SEQ_MODE_HF_H0_HN_Z_HF (3)
312 #define H0INIT_ITERS(x) (((x) & 0xf) << 4)
313 #define H4_GRAD_INV(x) (((x) & 0x1) << 8)
314 #define H3_GRAD_INV(x) (((x) & 0x1) << 9)
315 #define H2_GRAD_INV(x) (((x) & 0x1) << 10)
316 #define H1_GRAD_INV(x) (((x) & 0x1) << 11)
317 #define H0_GRAD_INV(x) (((x) & 0x1) << 12)
318 #define CTLE_HF_GRAD_INV(x) (((x) & 0x1) << 13)
319 #define SAMP_VOS_GRAD_INV(x) (((x) & 0x1) << 14)
320 #define CTLE_VOS_GRAD_INV(x) (((x) & 0x1) << 15)
322 #define AE_EQ1_CTRL_ID0 (30)
323 #define AE_EQ1_CTRL_ID1 (31)
324 #define AE_EQ1_CTRL_ID2 (32)
325 #define AE_EQ1_CTRL_ID3 (33)
326 #define CTLE_HF_MODE(x) (((x) & 0x3) << 0)
327 #define VAR_MODE_AUTO (0)
328 #define VAR_MODE_OFF (1)
329 #define VAR_MODE_HOLD (2)
330 #define VAR_MODE_LOAD (3)
331 #define CTLE_HF_GRAD(x) (((x) & 0x3) << 2)
332 #define CTLE_HF_GRAD_1P5 (0)
333 #define CTLE_HF_GRAD_2P5 (1)
334 #define CTLE_HF_GRAD_3P5 (2)
335 #define CTLE_HF_GRAD_1TP (3)
336 #define H1_MODE(x) (((x) & 0x3) << 8)
337 #define H2_MODE(x) (((x) & 0x3) << 10)
338 #define H3_MODE(x) (((x) & 0x3) << 12)
339 #define H4_MODE(x) (((x) & 0x3) << 14)
341 #define AE_EQ2_CTRL_ID0 (34)
342 #define AE_EQ2_CTRL_ID1 (35)
343 #define AE_EQ2_CTRL_ID2 (36)
344 #define AE_EQ2_CTRL_ID3 (37)
345 #define H0_MODE(x) (((x) & 0x3) << 0)
346 #define H0_DAC_TIME(x) (((x) & 0x3) << 2)
347 #define H0_TIME(x) (((x) & 0xf) << 4)
348 #define H0_ITERS(x) (((x) & 0xf) << 8)
349 #define HN_ITERS(x) (((x) & 0xf) << 12)
351 #define AE_EQ3_CTRL_ID0 (38)
352 #define AE_EQ3_CTRL_ID2 (40)
353 #define H0_GAIN(x) (((x) & 0xf) << 0)
354 #define HN_GAIN(x) (((x) & 0xf) << 4)
355 #define CTLE_HF_TIME(x) (((x) & 0xf) << 8)
356 #define CTLE_HF_GAIN(x) (((x) & 0xf) << 12)
358 #define MGMT_RX_PI_CTRL_ID2 (48)
359 #define TX_SLEW(x) (((x) & 0x3) << 0)
360 #define RX_SLEW(x) (((x) & 0x3) << 2)
362 #define CLK_RST_CONTROLLER_RST_DEV_UPHY_0 (0x4000c)
363 #define SWR_UPHY_RST (1 << 0)
365 #define CLK_RST_CONTROLLER_RST_DEV_PEX_USB_UPHY_0 (0x40000)
366 #define SWR_PEX_USB_UPHY_RST (1 << 0)
367 #define SWR_PEX_USB_UPHY_PLL0_RST (1 << 7)
368 #define SWR_PEX_USB_UPHY_PLL1_RST (1 << 15)
369 #define SWR_PEX_USB_UPHY_LANE_RST(lane) (1 << (16+lane))
371 enum tegra186_function {
373 TEGRA186_FUNC_HSIC_PLUS,
380 TEGRA186_FUNC_RSVD_0,
381 TEGRA186_FUNC_RSVD_3,
384 struct tegra_padctl_uphy_function {
386 const char * const *groups;
387 unsigned int num_groups;
390 struct tegra_padctl_uphy_group {
391 const unsigned int *funcs;
392 unsigned int num_funcs;
395 struct tegra_padctl_uphy_soc {
396 const struct pinctrl_pin_desc *pins;
397 unsigned int num_pins;
399 const struct tegra_padctl_uphy_function *functions;
400 unsigned int num_functions;
402 const struct tegra_padctl_uphy_lane *lanes;
403 unsigned int num_lanes;
405 unsigned int hsic_port_offset;
408 struct tegra_padctl_uphy_lane {
416 const unsigned int *funcs;
417 unsigned int num_funcs;
420 struct tegra_xusb_fuse_calibration {
421 u32 hs_curr_level[TEGRA_XUSB_UTMI_PHYS];
422 u32 hs_term_range_adj;
426 struct tegra_fuse_calibration {
432 struct tegra_xusb_usb3_port {
436 struct tegra_padctl_uphy {
438 void __iomem *padctl_regs;
439 void __iomem *uphy_regs;
440 void __iomem *uphy_pll_regs[2];
441 void __iomem *uphy_lane_regs[6];
443 struct clk *clk; /* uphy pad macro clock */
447 const struct tegra_padctl_uphy_soc *soc;
448 struct tegra_xusb_fuse_calibration calib;
449 struct tegra_fuse_calibration fuse_calib;
450 struct tegra_prod_list *prod_list;
451 struct pinctrl_dev *pinctrl;
452 struct pinctrl_desc desc;
454 struct phy_provider *provider;
455 // struct phy *phys[TEGRA_XUSB_NUM_PHYS];
456 struct phy *usb3_phys[TEGRA_XUSB_USB3_PHYS];
457 struct phy *utmi_phys[TEGRA_XUSB_UTMI_PHYS];
458 struct phy *hsic_phys[TEGRA_XUSB_HSIC_PHYS];
459 struct phy *pcie_phys[TEGRA_XUSB_PCIE_PHYS];
460 struct phy *sata_phys[TEGRA_XUSB_SATA_PHYS];
461 struct phy *ufs_phys[TEGRA_XUSB_UFS_PHYS];
462 unsigned long usb3_lanes;
463 unsigned long pcie_lanes;
464 unsigned long sata_lanes;
465 unsigned long ufs_lanes;
467 unsigned int padctl_clients;
468 bool sata_bypass_fuse;
470 struct tegra_xusb_usb3_port usb3_ports[TEGRA_XUSB_USB3_PHYS];
471 unsigned int utmi_enable;
472 unsigned int hs_curr_level_offset[TEGRA_XUSB_UTMI_PHYS];
473 struct regulator *vbus[TEGRA_XUSB_UTMI_PHYS];
474 struct regulator *vddio_hsic;
476 int uphy_pll_clients[2];
477 struct clk *uphy_pll_clk[2];
478 struct clk *uphy_lane_clk[6];
484 #define writel(v,c) {*(u32 *)(c) = v;}
486 #define readl(c) ({ *(u32 *)(c);})
490 static inline void padctl_writel(struct tegra_padctl_uphy *padctl, u32 value,
491 unsigned long offset)
493 writel(value, padctl->padctl_regs + offset);
496 static inline u32 padctl_readl(struct tegra_padctl_uphy *padctl,
497 unsigned long offset)
499 return readl(padctl->padctl_regs + offset);
502 #define padctl_writel(_padctl, _value, _offset) \
504 unsigned long v = _value, o = _offset; \
505 pr_info("%s padctl_write %s(@0x%lx) with 0x%lx\n", __func__, \
507 writel(v, _padctl->padctl_regs + o); \
510 #define padctl_readl(_padctl, _offset) \
512 unsigned long v, o = _offset; \
513 v = readl(_padctl->padctl_regs + o); \
514 pr_info("%s padctl_read %s(@0x%lx) = 0x%lx\n", __func__, \
521 static inline void uphy_pll_writel(struct tegra_padctl_uphy *ctx, int pll,
522 u32 value, unsigned long offset)
524 writel(value, ctx->uphy_pll_regs[pll] + offset);
527 static inline u32 uphy_pll_readl(struct tegra_padctl_uphy *ctx, int pll,
528 unsigned long offset)
530 return readl(ctx->uphy_pll_regs[pll] + offset);
533 #define uphy_pll_writel(_ctx, _pll, _value, _offset) \
535 unsigned long v = _value, o = _offset; \
536 pr_info("%s uphy_pll_writel pll %d %s(@0x%lx) with 0x%lx\n", __func__, \
537 _pll, #_offset, o, v); \
538 writel(v, _ctx->uphy_pll_regs[_pll] + o); \
541 #define uphy_pll_readl(_ctx, _pll, _offset) \
543 unsigned long v, o = _offset; \
544 v = readl(_ctx->uphy_pll_regs[_pll] + o); \
545 pr_info("%s uphy_pll_readl pll %d %s(@0x%lx) = 0x%lx\n", __func__, \
546 _pll, #_offset, o, v); \
552 static inline void uphy_lane_writel(struct tegra_padctl_uphy *ctx, int lane,
553 u32 value, unsigned long offset)
555 writel(value, ctx->uphy_lane_regs[lane] + offset);
558 static inline u32 uphy_pll_readl(struct tegra_padctl_uphy *ctx, int lane,
559 unsigned long offset)
561 return readl(ctx->uphy_lane_regs[lane] + offset);
564 #define uphy_lane_writel(_ctx, _lane, _value, _offset) \
566 unsigned long v = _value, o = _offset; \
567 pr_info("%s uphy_lane_writel lane %d %s(@0x%lx) with 0x%lx\n", __func__, \
568 _lane, #_offset, o, v); \
569 writel(v, _ctx->uphy_lane_regs[_lane] + o); \
572 #define uphy_lane_readl(_ctx, _lane, _offset) \
574 unsigned long v, o = _offset; \
575 v = readl(_ctx->uphy_lane_regs[_lane] + o); \
576 pr_info("%s uphy_lane_readl lane %d %s(@0x%lx) = 0x%lx\n", __func__, \
577 _lane, #_offset, o, v); \
582 struct tegra_mphy_sata_calib {
603 static struct tegra_mphy_sata_calib mphy_data[] = {
605 .aux_rx_idle_th = 0x0,
606 .tx_drv_amp_sel0 = 0x8,
607 .tx_drv_amp_sel1 = 0x11,
608 .tx_drv_amp_sel2 = 0x8,
609 .tx_drv_amp_sel3 = 0x11,
610 .tx_drv_amp_sel4 = 0x8,
611 .tx_drv_amp_sel5 = 0x11,
612 .tx_drv_amp_sel6 = 0x8,
613 .tx_drv_amp_sel7 = 0x11,
614 .tx_drv_amp_sel8 = 0x8,
615 .tx_drv_amp_sel9 = 0x11,
616 .tx_drv_post_sel0 = 0x0,
617 .tx_drv_post_sel1 = 0xa,
618 .tx_drv_post_sel2 = 0xf,
619 .tx_drv_post_sel3 = 0x8,
620 .tx_drv_pre_sel3 = 0x8,
623 .aux_rx_idle_th = 0x1,
624 .tx_drv_amp_sel0 = 0x8,
625 .tx_drv_amp_sel1 = 0x11,
626 .tx_drv_amp_sel2 = 0x8,
627 .tx_drv_amp_sel3 = 0x11,
628 .tx_drv_amp_sel4 = 0x8,
629 .tx_drv_amp_sel5 = 0x11,
630 .tx_drv_amp_sel6 = 0x8,
631 .tx_drv_amp_sel7 = 0x11,
632 .tx_drv_amp_sel8 = 0x8,
633 .tx_drv_amp_sel9 = 0x11,
634 .tx_drv_post_sel0 = 0x0,
635 .tx_drv_post_sel1 = 0xa,
636 .tx_drv_post_sel2 = 0xf,
637 .tx_drv_post_sel3 = 0x8,
638 .tx_drv_pre_sel3 = 0x8,
641 .aux_rx_idle_th = 0x2,
642 .tx_drv_amp_sel0 = 0x8,
643 .tx_drv_amp_sel1 = 0x11,
644 .tx_drv_amp_sel2 = 0x8,
645 .tx_drv_amp_sel3 = 0x11,
646 .tx_drv_amp_sel4 = 0x8,
647 .tx_drv_amp_sel5 = 0x11,
648 .tx_drv_amp_sel6 = 0x8,
649 .tx_drv_amp_sel7 = 0x11,
650 .tx_drv_amp_sel8 = 0x8,
651 .tx_drv_amp_sel9 = 0x11,
652 .tx_drv_post_sel0 = 0x0,
653 .tx_drv_post_sel1 = 0xa,
654 .tx_drv_post_sel2 = 0xf,
655 .tx_drv_post_sel3 = 0x8,
656 .tx_drv_pre_sel3 = 0x8,
659 .aux_rx_idle_th = 0x3,
660 .tx_drv_amp_sel0 = 0x8,
661 .tx_drv_amp_sel1 = 0x11,
662 .tx_drv_amp_sel2 = 0x8,
663 .tx_drv_amp_sel3 = 0x11,
664 .tx_drv_amp_sel4 = 0x8,
665 .tx_drv_amp_sel5 = 0x11,
666 .tx_drv_amp_sel6 = 0x8,
667 .tx_drv_amp_sel7 = 0x11,
668 .tx_drv_amp_sel8 = 0x8,
669 .tx_drv_amp_sel9 = 0x11,
670 .tx_drv_post_sel0 = 0x0,
671 .tx_drv_post_sel1 = 0xa,
672 .tx_drv_post_sel2 = 0xf,
673 .tx_drv_post_sel3 = 0x8,
674 .tx_drv_pre_sel3 = 0x8,
678 static struct tegra_mphy_sata_calib sata_data[] = {
680 .aux_rx_idle_th = 0x0,
681 .tx_drv_amp_sel0 = 0x1b,
682 .tx_drv_amp_sel1 = 0x1f,
683 .tx_drv_post_sel0 = 0x7,
684 .tx_drv_post_sel1 = 0xa,
685 .ae_ctle_ctrl_id0 = 0xf,
686 .ae_ctle_ctrl_id1 = 0x8f,
689 .aux_rx_idle_th = 0x1,
690 .tx_drv_amp_sel0 = 0x17,
691 .tx_drv_amp_sel1 = 0x1b,
692 .tx_drv_post_sel0 = 0x5,
693 .tx_drv_post_sel1 = 0xa,
694 .ae_ctle_ctrl_id0 = 0xf,
695 .ae_ctle_ctrl_id1 = 0x4f,
698 .aux_rx_idle_th = 0x2,
699 .tx_drv_amp_sel0 = 0x13,
700 .tx_drv_amp_sel1 = 0x17,
701 .tx_drv_post_sel0 = 0x4,
702 .tx_drv_post_sel1 = 0xa,
703 .ae_ctle_ctrl_id0 = 0xf,
704 .ae_ctle_ctrl_id1 = 0xf,
707 .aux_rx_idle_th = 0x3,
708 .tx_drv_amp_sel0 = 0x1f,
709 .tx_drv_amp_sel1 = 0x23,
710 .tx_drv_post_sel0 = 0xa,
711 .tx_drv_post_sel1 = 0xe,
712 .ae_ctle_ctrl_id0 = 0xf,
713 .ae_ctle_ctrl_id1 = 0xcd,
725 static struct init_data usb3_pll_g1_init_data[] = {
727 .cfg_addr = MGMT_CORECLK_CTRL_ID0,
728 .cfg_wdata = CFG_TXCLKREF_EN(1) |
729 CFG_TXCLKREF_SEL(DIVIDE_TX_BY_5),
733 static void pcie_usb3_pll_defaults(struct tegra_padctl_uphy *ctx)
738 for (i = 0; i < ARRAY_SIZE(usb3_pll_g1_init_data); i++) {
739 reg = CFG_ADDR(usb3_pll_g1_init_data[i].cfg_addr);
740 reg |= CFG_WDATA(usb3_pll_g1_init_data[i].cfg_wdata);
741 uphy_pll_writel(ctx, 0, reg, UPHY_PLL_CTL_4);
745 #define pcie_pll_init pcie_usb3_pll_defaults
747 static struct init_data sata_pll_g1_g2_g3_init_data[] = {
749 .cfg_addr = MGMT_FREQ_CTRL_ID0,
750 .cfg_wdata = CFG_FREQ_NDIV(30),
753 .cfg_addr = MGMT_CORECLK_CTRL_ID0,
754 .cfg_wdata = CFG_TXCLKREF_EN(1) |
755 CFG_TXCLKREF_SEL(DIVIDE_TX_BY_10),
759 static void sata_pll_init(struct tegra_padctl_uphy *ctx)
764 for (i = 0; i < ARRAY_SIZE(sata_pll_g1_g2_g3_init_data); i++) {
765 reg = CFG_ADDR(sata_pll_g1_g2_g3_init_data[i].cfg_addr);
766 reg |= CFG_WDATA(sata_pll_g1_g2_g3_init_data[i].cfg_wdata);
767 uphy_pll_writel(ctx, 1, reg, UPHY_PLL_CTL_4);
771 static struct init_data ufs_pll_g1_g2_g3_A_B_init_data[] = {
773 .cfg_addr = MGMT_FREQ_CTRL_ID0,
774 .cfg_wdata = CFG_FREQ_NDIV(24) | CFG_FREQ_MDIV(1),
777 .cfg_addr = MGMT_FREQ_CTRL_ID1,
778 .cfg_wdata = CFG_FREQ_NDIV(28) | CFG_FREQ_MDIV(1),
781 .cfg_addr = MGMT_CORECLK_CTRL_ID0,
782 .cfg_wdata = CFG_TXCLKREF_EN(1) |
783 CFG_TXCLKREF_SEL(DIVIDE_TX_BY_10),
786 .cfg_addr = MGMT_CORECLK_CTRL_ID1,
787 .cfg_wdata = CFG_TXCLKREF_EN(1) |
788 CFG_TXCLKREF_SEL(DIVIDE_TX_BY_10),
791 .cfg_addr = PLLC_CRSWRD_OVRD_ID1,
795 .cfg_addr = MGMT_CYA_CTRL,
796 .cfg_wdata = CFG_MGMT_CLK_SEL(1),
799 static void ufs_pll_init(struct tegra_padctl_uphy *ctx)
804 for (i = 0; i < ARRAY_SIZE(ufs_pll_g1_g2_g3_A_B_init_data); i++) {
805 reg = CFG_ADDR(ufs_pll_g1_g2_g3_A_B_init_data[i].cfg_addr);
806 reg |= CFG_WDATA(ufs_pll_g1_g2_g3_A_B_init_data[i].cfg_wdata);
807 uphy_pll_writel(ctx, 1, reg, UPHY_PLL_CTL_4);
811 static struct init_data ufs_pll_rateid_init_data[] = {
813 .cfg_addr = MGMT_FREQ_CTRL_ID0,
814 .cfg_wdata = CFG_FREQ_NDIV(0x18) | CFG_FREQ_MDIV(0x1),
819 .cfg_addr = MGMT_FREQ_CTRL_ID1,
820 .cfg_wdata = CFG_FREQ_NDIV(0x1c) | CFG_FREQ_MDIV(0x1),
825 .cfg_addr = MGMT_REFCLK_CTRL,
831 .cfg_addr = MGMT_CORECLK_CTRL_ID0,
832 .cfg_wdata = CFG_XDIGCLK_SEL(0x7) | CFG_XDIGCLK_EN(0x1)
833 | CFG_TXCLKREF_SEL(0x2) | CFG_TXCLKREF_EN(1),
838 .cfg_addr = MGMT_TX_RATE_CTRL_ID1,
839 .cfg_wdata = CFG_XDIGCLK_SEL(0x7) | CFG_XDIGCLK_EN(0x1)
840 | CFG_TXCLKREF_SEL(0x2) | CFG_TXCLKREF_EN(1),
845 .cfg_addr = PLLC_CRSWRD_OVRD_ID0,
852 static void ufs_pll_rateid_init(struct tegra_padctl_uphy *ctx)
857 for (i = 0; i < ARRAY_SIZE(ufs_pll_rateid_init_data); i++) {
858 reg = CFG_ADDR(ufs_pll_rateid_init_data[i].cfg_addr);
859 reg |= CFG_WDATA(ufs_pll_rateid_init_data[i].cfg_wdata);
860 reg |= CFG_WDS(ufs_pll_rateid_init_data[i].cfg_wds);
861 reg |= CFG_RDS(ufs_pll_rateid_init_data[i].cfg_rds);
862 reg |= CFG_RESET(ufs_pll_rateid_init_data[i].cfg_rst);
863 uphy_pll_writel(ctx, 1, reg, UPHY_PLL_CTL_4);
867 static struct init_data ufs_lane_rateid_init_data[] = {
869 .cfg_addr = MGMT_TX_RATE_CTRL_ID0,
870 .cfg_wdata = TX_RATE_SDIV(SDIV4),
875 .cfg_addr = MGMT_TX_RATE_CTRL_ID1,
876 .cfg_wdata = TX_RATE_SDIV(SDIV2),
881 .cfg_addr = MGMT_TX_RATE_CTRL_ID2,
882 .cfg_wdata = TX_RATE_SDIV(SDIV1),
887 .cfg_addr = MGMT_TX_RATE_CTRL_ID3,
888 .cfg_wdata = TX_RATE_SDIV(SDIV1),
893 .cfg_addr = MGMT_RX_RATE_CTRL_ID0,
894 .cfg_wdata = RX_RATE_SDIV(CDIV1),
899 .cfg_addr = MGMT_RX_RATE_CTRL_ID1,
900 .cfg_wdata = RX_RATE_SDIV(CDIV2),
905 .cfg_addr = MGMT_RX_RATE_CTRL_ID2,
906 .cfg_wdata = RX_RATE_SDIV(CDIV4),
911 .cfg_addr = MGMT_RX_RATE_CTRL_ID0,
912 .cfg_wdata = RX_RATE_SDIV(CDIV4),
917 .cfg_addr = MGMT_TX_CTRL,
918 .cfg_wdata = TX_TERM_MODE(0x1),
923 .cfg_addr = AE_CDR_CTRL_ID0,
924 .cfg_wdata = FRLOOP_EN(0x1) | FRGAIN(0x3) | PHGAIN(0x7),
929 .cfg_addr = AE_CDR_CTRL_ID1,
930 .cfg_wdata = FRLOOP_EN(0x1) | FRGAIN(0x6) | PHGAIN(0x7),
935 .cfg_addr = AE_CDR_CTRL_ID2,
936 .cfg_wdata = FRLOOP_EN(0x1) | FRGAIN(0xc) | PHGAIN(0x7),
941 .cfg_addr = AE_CDR_CTRL_ID3,
942 .cfg_wdata = FRLOOP_EN(0x1) | FRGAIN(0xc) | PHGAIN(0x7),
947 .cfg_addr = AE_CTLE_CTRL_ID0,
948 .cfg_wdata = HF_UBIN(0x0) | LF_UGRAY(0xf),
953 .cfg_addr = AE_CTLE_CTRL_ID1,
954 .cfg_wdata = HF_UBIN(0x0) | LF_UGRAY(0xf),
959 .cfg_addr = AE_CTLE_CTRL_ID2,
960 .cfg_wdata = HF_UBIN(0x8) | LF_UGRAY(0xf),
965 .cfg_addr = AE_CTLE_CTRL_ID3,
966 .cfg_wdata = HF_UBIN(0xf) | LF_UGRAY(0xd),
971 .cfg_addr = AE_EQ1_CTRL_ID0,
972 .cfg_wdata = CTLE_HF_MODE(0x1),
977 .cfg_addr = AE_EQ1_CTRL_ID1,
978 .cfg_wdata = CTLE_HF_MODE(0x1),
983 .cfg_addr = AE_EQ1_CTRL_ID2,
984 .cfg_wdata = CTLE_HF_MODE(0x1),
989 .cfg_addr = AE_EQ1_CTRL_ID3,
990 .cfg_wdata = CTLE_HF_MODE(0x0),
995 .cfg_addr = AE_EQ2_CTRL_ID0,
996 .cfg_wdata = H0_MODE(0x1),
1001 .cfg_addr = AE_EQ2_CTRL_ID0,
1002 .cfg_wdata = H0_MODE(0x1),
1007 .cfg_addr = AE_EQ2_CTRL_ID0,
1008 .cfg_wdata = H0_MODE(0x1),
1013 .cfg_addr = AE_EQ2_CTRL_ID0,
1014 .cfg_wdata = H0_MODE(0x0),
1020 static void ufs_lane_rateid_init(struct tegra_padctl_uphy *ctx, int lane)
1025 for (i = 0; i < ARRAY_SIZE(ufs_lane_rateid_init_data); i++) {
1026 reg = CFG_ADDR(ufs_lane_rateid_init_data[i].cfg_addr);
1027 reg |= CFG_WDATA(ufs_lane_rateid_init_data[i].cfg_wdata);
1028 reg |= CFG_WDS(ufs_lane_rateid_init_data[i].cfg_wds);
1029 reg |= CFG_RDS(ufs_lane_rateid_init_data[i].cfg_rds);
1030 reg |= CFG_RESET(ufs_lane_rateid_init_data[i].cfg_rst);
1031 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DIRECT_CTL_2);
1036 static struct init_data pcie_lane_g1_g2_init_data[] = {
1039 static void pcie_lane_defaults(struct tegra_padctl_uphy *ctx, int lane)
1044 for (i = 0; i < ARRAY_SIZE(pcie_lane_g1_g2_init_data); i++) {
1045 reg = CFG_ADDR(pcie_lane_g1_g2_init_data[i].cfg_addr);
1046 reg |= CFG_WDATA(pcie_lane_g1_g2_init_data[i].cfg_wdata);
1047 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DIRECT_CTL_2);
1051 static struct init_data usb3_lane_g1_init_data[] = {
1053 .cfg_addr = MGMT_TX_RATE_CTRL_ID0,
1054 .cfg_wdata = TX_RATE_SDIV(SDIV1),
1057 .cfg_addr = MGMT_RX_RATE_CTRL_ID0,
1058 .cfg_wdata = RX_RATE_SDIV(SDIV1) | RX_RATE_CDIV(CDIV4),
1061 .cfg_addr = MGMT_TX_CTRL,
1062 .cfg_wdata = TX_TERM_MODE(0),
1065 .cfg_addr = AE_CTLE_CTRL_ID0,
1066 .cfg_wdata = LF_UGRAY(0xd) | HF_UBIN(0xf),
1069 .cfg_addr = AE_DFE0_CTRL_ID0,
1070 .cfg_wdata = LF_UGRAY(0xd) | HF_UBIN(0xf),
1073 .cfg_addr = AE_DFE1_CTRL_ID0,
1074 .cfg_wdata = H0_SBIN(48) | H4_SBIN(-1),
1077 .cfg_addr = AE_CDR_CTRL_ID0,
1078 .cfg_wdata = PHGAIN(0x7) | FRGAIN(0xc) | FRLOOP_EN(1),
1081 .cfg_addr = AE_EQ0_CTRL_ID0,
1082 .cfg_wdata = EQ0_SEQ_MODE(SEQ_MODE_HF_Z_H0_HN_Z) |
1086 .cfg_addr = AE_EQ1_CTRL_ID0,
1087 .cfg_wdata = CTLE_HF_MODE(VAR_MODE_AUTO) |
1088 CTLE_HF_GRAD(CTLE_HF_GRAD_1P5) |
1089 H1_MODE(VAR_MODE_AUTO) |
1090 H2_MODE(VAR_MODE_AUTO) |
1091 H3_MODE(VAR_MODE_AUTO) |
1092 H4_MODE(VAR_MODE_AUTO),
1095 .cfg_addr = AE_EQ2_CTRL_ID0,
1096 .cfg_wdata = H1_MODE(VAR_MODE_AUTO) | H0_DAC_TIME(0x2) |
1097 H0_TIME(0x6) | H0_ITERS(0x3) | HN_ITERS(0x1),
1100 .cfg_addr = AE_EQ3_CTRL_ID0,
1101 .cfg_wdata = HN_GAIN(0Xf) | CTLE_HF_TIME(0xc) |
1106 static void usb3_lane_defaults(struct tegra_padctl_uphy *ctx, int lane)
1111 for (i = 0; i < ARRAY_SIZE(usb3_lane_g1_init_data); i++) {
1112 reg = CFG_ADDR(usb3_lane_g1_init_data[i].cfg_addr);
1113 reg |= CFG_WDATA(usb3_lane_g1_init_data[i].cfg_wdata);
1114 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DIRECT_CTL_2);
1119 static struct init_data sata_lane_g1_g2_init_data[] = {
1121 .cfg_addr = MGMT_TX_RATE_CTRL_ID0,
1122 .cfg_wdata = TX_RATE_SDIV(SDIV4),
1125 .cfg_addr = MGMT_TX_RATE_CTRL_ID1,
1126 .cfg_wdata = TX_RATE_SDIV(SDIV2),
1129 .cfg_addr = MGMT_RX_RATE_CTRL_ID0,
1130 .cfg_wdata = RX_RATE_SDIV(SDIV4) | RX_RATE_CDIV(CDIV1),
1133 .cfg_addr = MGMT_RX_RATE_CTRL_ID1,
1134 .cfg_wdata = RX_RATE_SDIV(SDIV2) | RX_RATE_CDIV(CDIV2),
1137 .cfg_addr = MGMT_TX_CTRL,
1138 .cfg_wdata = TX_TERM_MODE(0),
1141 .cfg_addr = AE_CTLE_CTRL_ID0,
1142 .cfg_wdata = LF_UGRAY(0x8),
1145 .cfg_addr = AE_CDR_CTRL_ID0,
1146 .cfg_wdata = PHGAIN(0x7) | FRGAIN(0x3) | FRLOOP_EN(1),
1149 .cfg_addr = AE_CDR_CTRL_ID1,
1150 .cfg_wdata = PHGAIN(0x7) | FRGAIN(0x6) | FRLOOP_EN(1),
1154 static void sata_lane_init(struct tegra_padctl_uphy *ctx, int lane)
1159 for (i = 0; i < ARRAY_SIZE(sata_lane_g1_g2_init_data); i++) {
1160 reg = CFG_ADDR(sata_lane_g1_g2_init_data[i].cfg_addr);
1161 reg |= CFG_WDATA(sata_lane_g1_g2_init_data[i].cfg_wdata);
1162 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DIRECT_CTL_2);
1167 static struct init_data ufs_lane_g1_g2_g3_init_data[] = {
1169 .cfg_addr = MGMT_TX_RATE_CTRL_ID0,
1170 .cfg_wdata = TX_RATE_SDIV(SDIV4),
1173 .cfg_addr = MGMT_TX_RATE_CTRL_ID1,
1174 .cfg_wdata = TX_RATE_SDIV(SDIV2),
1177 .cfg_addr = MGMT_RX_RATE_CTRL_ID0,
1178 .cfg_wdata = RX_RATE_SDIV(SDIV4) | RX_RATE_CDIV(CDIV1),
1181 .cfg_addr = MGMT_RX_RATE_CTRL_ID1,
1182 .cfg_wdata = RX_RATE_SDIV(SDIV2) | RX_RATE_CDIV(CDIV2),
1185 .cfg_addr = MGMT_TX_CTRL,
1186 .cfg_wdata = TX_TERM_MODE(1),
1189 .cfg_addr = AE_CTLE_CTRL_ID0,
1190 .cfg_wdata = LF_UGRAY(0xf),
1193 .cfg_addr = AE_CTLE_CTRL_ID1,
1194 .cfg_wdata = LF_UGRAY(0xf),
1197 .cfg_addr = AE_CTLE_CTRL_ID2,
1198 .cfg_wdata = LF_UGRAY(0xf) | HF_UBIN(8),
1202 .cfg_addr = AE_DFE0_CTRL_ID2,
1206 .cfg_addr = AE_DFE1_CTRL_ID2,
1210 .cfg_addr = AE_CDR_CTRL_ID0,
1211 .cfg_wdata = PHGAIN(0x7) | FRGAIN(0x3) | FRLOOP_EN(1),
1214 .cfg_addr = AE_CDR_CTRL_ID1,
1215 .cfg_wdata = PHGAIN(0x7) | FRGAIN(0x6) | FRLOOP_EN(1),
1218 .cfg_addr = AE_CDR_CTRL_ID2,
1219 .cfg_wdata = PHGAIN(0x7) | FRGAIN(0xc) | FRLOOP_EN(1),
1222 .cfg_addr = AE_EQ0_CTRL_ID2,
1223 .cfg_wdata = EQ0_SEQ_MODE(SEQ_MODE_HF_Z_H0_HN_Z),
1226 .cfg_addr = AE_EQ1_CTRL_ID2,
1227 .cfg_wdata = CTLE_HF_MODE(VAR_MODE_OFF) |
1228 CTLE_HF_GRAD(CTLE_HF_GRAD_1P5) |
1229 H1_MODE(VAR_MODE_OFF) |
1230 H2_MODE(VAR_MODE_OFF) |
1231 H3_MODE(VAR_MODE_OFF) |
1232 H4_MODE(VAR_MODE_OFF),
1235 .cfg_addr = AE_EQ2_CTRL_ID2,
1236 .cfg_wdata = H1_MODE(VAR_MODE_OFF),
1239 .cfg_addr = AE_EQ3_CTRL_ID2,
1243 .cfg_addr = MGMT_RX_PI_CTRL_ID2,
1248 static void ufs_lane_init(struct tegra_padctl_uphy *ctx, int lane)
1253 for (i = 0; i < ARRAY_SIZE(ufs_lane_g1_g2_g3_init_data); i++) {
1254 reg = CFG_ADDR(ufs_lane_g1_g2_g3_init_data[i].cfg_addr);
1255 reg |= CFG_WDATA(ufs_lane_g1_g2_g3_init_data[i].cfg_wdata);
1256 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DIRECT_CTL_2);
1261 static int __uphy_pll_init(struct tegra_padctl_uphy *ctx, int pll)
1263 struct device *dev = ctx->dev;
1267 /* FIXME: Need to see needed ??? */
1268 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_1);
1270 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_1);
1272 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1273 reg |= (CAL_OVRD | RCAL_OVRD | CAL_RESET);
1274 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_2);
1277 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_1);
1279 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_1);
1281 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_1);
1282 reg &= ~PLL_SLEEP(~0);
1283 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_1);
1287 /* perform PLL calibration */
1288 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1290 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_2);
1291 for (i = 0; i < 20; i++) {
1292 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1295 usleep_range(10, 15);
1297 if (!(reg & CAL_DONE)) {
1298 dev_err(dev, "start PLL %d calibration timeout\n", pll);
1302 /* stop PLL calibration */
1303 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1305 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_2);
1306 for (i = 0; i < 20; i++) {
1307 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1308 if (!(reg & CAL_DONE))
1310 usleep_range(10, 15);
1312 if (reg & CAL_DONE) {
1313 dev_err(dev, "stop PLL %d calibration timeout\n", pll);
1318 /* perform PLL rate change for UPHY_PLL_1, used by UFS */
1319 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_1);
1320 reg &= ~RATE_ID(~0);
1321 reg |= (RATE_ID(1) | RATE_ID_OVRD);
1322 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_1);
1326 /* perform PLL calibration for rate B */
1327 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1329 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_2);
1330 for (i = 0; i < 20; i++) {
1331 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1334 usleep_range(10, 15);
1336 if (!(reg & CAL_DONE)) {
1337 dev_err(dev, "start PLL %d calibration timeout\n", pll);
1341 /* stop PLL calibration */
1342 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1344 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_2);
1345 for (i = 0; i < 20; i++) {
1346 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1347 if (!(reg & CAL_DONE))
1349 usleep_range(10, 15);
1351 if (reg & CAL_DONE) {
1352 dev_err(dev, "stop PLL %d calibration timeout\n", pll);
1356 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_1);
1357 reg &= ~RATE_ID(~0);
1358 reg |= RATE_ID_OVRD;
1359 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_1);
1363 /* enable PLL and wait for lock */
1364 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_1);
1366 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_1);
1367 usleep_range(20, 25);
1368 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_1);
1369 if (!(reg & LOCKDET_STATUS)) {
1370 dev_err(dev, "enable PLL %d timeout\n", pll);
1374 /* perform resistor calibration */
1375 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1377 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_2);
1378 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1380 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_2);
1381 usleep_range(5, 10);
1382 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1383 if (!(reg & RCAL_DONE)) {
1384 dev_err(dev, "start resistor %d calibration timeout\n", pll);
1388 /* stop resistor calibration */
1389 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1391 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_2);
1392 usleep_range(5, 10);
1393 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1394 if (reg & RCAL_DONE) {
1395 dev_err(dev, "stop resistor %d calibration timeout\n", pll);
1398 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1399 reg &= ~RCAL_CLK_EN;
1400 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_2);
1402 /* remove SW overrides to allow HW sequencer to run */
1403 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_1);
1406 reg &= ~RATE_ID_OVRD;
1407 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_1);
1408 reg = uphy_pll_readl(ctx, pll, UPHY_PLL_CTL_2);
1409 reg &= ~(CAL_OVRD | RCAL_OVRD);
1410 uphy_pll_writel(ctx, pll, reg, UPHY_PLL_CTL_2);
1415 static int uphy_pll_init(struct tegra_padctl_uphy *ctx, int pll)
1417 struct device *dev = ctx->dev;
1418 char clk_name[] = "uphy_pllX";
1421 if (pll < 0 || pll > 1)
1424 if (!ctx->uphy_pll_clk[pll]) {
1425 snprintf(clk_name, sizeof(clk_name), "uphy_pll%d", pll);
1426 ctx->uphy_pll_clk[pll] = clk_get_sys(NULL, clk_name);
1428 if (IS_ERR(ctx->uphy_pll_clk[pll])) {
1429 rc = PTR_ERR(ctx->uphy_pll_clk[pll]);
1430 dev_err(dev, "fail get uphy_pll%d clk %d\n", pll, rc);
1431 ctx->uphy_pll_clk[pll] = NULL;
1437 TRACE_DEV(dev, "clients %d", ctx->uphy_pll_clients[pll]);
1438 if (ctx->uphy_pll_clients[pll]++ > 0)
1441 tegra_periph_reset_deassert(ctx->uphy_pll_clk[pll]);
1442 rc = __uphy_pll_init(ctx, pll);
1448 static int uphy_pll_deinit(struct tegra_padctl_uphy *ctx, int pll)
1450 struct device *dev = ctx->dev;
1452 TRACE_DEV(dev, "clients %d", ctx->uphy_pll_clients[pll]);
1453 ctx->uphy_pll_clients[pll]--;
1455 TRACE("FIXME: implement!\n"); /* TODO */
1459 static int uphy_lane_init(struct tegra_padctl_uphy *ctx, int lane)
1461 struct device *dev = ctx->dev;
1462 char clk_name[] = "uphy_laneX";
1465 if (lane < 0 || lane > 5)
1468 if (!ctx->uphy_lane_clk[lane]) {
1469 snprintf(clk_name, sizeof(clk_name), "uphy_lane%d", lane);
1470 ctx->uphy_lane_clk[lane] = clk_get_sys(NULL, clk_name);
1472 if (IS_ERR(ctx->uphy_lane_clk[lane])) {
1473 rc = PTR_ERR(ctx->uphy_lane_clk[lane]);
1474 dev_err(dev, "fail get uphy_lane%d clk %d\n", lane, rc);
1475 ctx->uphy_lane_clk[lane] = NULL;
1480 tegra_periph_reset_deassert(ctx->uphy_lane_clk[lane]);
1485 static int uphy_lane_deinit(struct tegra_padctl_uphy *ctx, int lane)
1487 if (lane < 0 || lane > 5)
1490 if (ctx->uphy_lane_clk[lane])
1491 tegra_periph_reset_assert(ctx->uphy_lane_clk[lane]);
1501 #define PIN_HSIC_0 4
1502 #define PIN_HSIC_1 5
1503 #define PIN_UPHY_0 6
1504 #define PIN_UPHY_1 7
1505 #define PIN_UPHY_2 8
1506 #define PIN_UPHY_3 9
1507 #define PIN_UPHY_4 10
1508 #define PIN_UPHY_5 11
1509 #define PIN_UPHY_6 12
1510 #define PIN_SATA_0 13
1512 static inline bool lane_is_otg(unsigned int lane)
1514 return lane >= PIN_OTG_0 && lane <= PIN_OTG_3;
1517 static inline bool lane_is_hsic(unsigned int lane)
1519 return lane >= PIN_HSIC_0 && lane <= PIN_HSIC_1;
1522 static inline bool lane_is_uphy(unsigned int lane)
1524 return lane >= PIN_UPHY_0 && lane <= PIN_UPHY_6;
1527 static inline bool lane_is_pcie_or_sata(unsigned int lane)
1529 return lane >= PIN_UPHY_0 && lane <= PIN_SATA_0;
1532 static int lane_to_usb3_port(struct tegra_padctl_uphy *padctl,
1537 for (i = 0; i < TEGRA_XUSB_USB3_PHYS; i++) {
1538 if (padctl->usb3_ports[i].lane == lane)
1545 static int tegra_xusb_padctl_get_groups_count(struct pinctrl_dev *pinctrl)
1547 struct tegra_padctl_uphy *padctl = pinctrl_dev_get_drvdata(pinctrl);
1549 TRACE("num_pins %u", padctl->soc->num_pins);
1550 return padctl->soc->num_pins;
1553 static const char *tegra_xusb_padctl_get_group_name(struct pinctrl_dev *pinctrl,
1556 struct tegra_padctl_uphy *padctl = pinctrl_dev_get_drvdata(pinctrl);
1558 TRACE("group %u name %s", group, padctl->soc->pins[group].name);
1559 return padctl->soc->pins[group].name;
1562 static int tegra_xusb_padctl_get_group_pins(struct pinctrl_dev *pinctrl,
1564 const unsigned **pins,
1567 struct tegra_padctl_uphy *padctl = pinctrl_dev_get_drvdata(pinctrl);
1569 *pins = &padctl->soc->pins[group].number;
1570 *num_pins = 1; /* one pin per group */
1572 TRACE("group %u num_pins %u pins[0] %u", group, *num_pins, *pins[0]);
1577 enum tegra_xusb_padctl_param {
1578 TEGRA_XUSB_PADCTL_USB3_PORT,
1579 TEGRA_XUSB_PADCTL_USB2_PORT,
1582 static const struct tegra_xusb_padctl_property {
1584 enum tegra_xusb_padctl_param param;
1586 {"nvidia,usb3-port", TEGRA_XUSB_PADCTL_USB3_PORT},
1587 {"nvidia,usb2-port", TEGRA_XUSB_PADCTL_USB2_PORT},
1590 #define TEGRA_XUSB_PADCTL_PACK(param, value) ((param) << 16 | (value))
1591 #define TEGRA_XUSB_PADCTL_UNPACK_PARAM(config) ((config) >> 16)
1592 #define TEGRA_XUSB_PADCTL_UNPACK_VALUE(config) ((config) & 0xffff)
1594 static int tegra186_padctl_uphy_parse_subnode(struct tegra_padctl_uphy *padctl,
1595 struct device_node *np,
1596 struct pinctrl_map **maps,
1597 unsigned int *reserved_maps,
1598 unsigned int *num_maps)
1600 unsigned int i, reserve = 0, num_configs = 0;
1601 unsigned long config, *configs = NULL;
1602 const char *function, *group;
1603 struct property *prop;
1608 err = of_property_read_string(np, "nvidia,function", &function);
1609 TRACE("err %d function %s", err, function ? function : "(null)");
1617 for (i = 0; i < ARRAY_SIZE(properties); i++) {
1618 err = of_property_read_u32(np, properties[i].name, &value);
1619 TRACE("err %d property %s (%d) value %d",
1620 err, properties[i].name, i, value);
1628 config = TEGRA_XUSB_PADCTL_PACK(properties[i].param, value);
1630 err = pinctrl_utils_add_config(padctl->pinctrl, &configs,
1631 &num_configs, config);
1632 TRACE("err %d num_configs %d", err, num_configs);
1643 err = of_property_count_strings(np, "nvidia,lanes");
1644 TRACE("of_property_count_strings(\"nvidia,lanes\") %d", err);
1650 err = pinctrl_utils_reserve_map(padctl->pinctrl, maps, reserved_maps,
1652 TRACE("pinctrl_utils_reserve_map reserve %d num_maps %d err %d",
1653 reserve, *num_maps, err);
1657 of_property_for_each_string(np, "nvidia,lanes", prop, group) {
1659 err = pinctrl_utils_add_map_mux(padctl->pinctrl, maps,
1660 reserved_maps, num_maps, group,
1662 TRACE("pinctrl_utils_add_map_mux() err %d num_maps %u group %s function %s",
1663 err, *num_maps, group, function);
1669 err = pinctrl_utils_add_map_configs(padctl->pinctrl,
1670 maps, reserved_maps, num_maps, group,
1671 configs, num_configs,
1672 PIN_MAP_TYPE_CONFIGS_GROUP);
1673 TRACE("pinctrl_utils_add_map_configs() err %d", err);
1682 static int tegra_xusb_padctl_dt_node_to_map(struct pinctrl_dev *pinctrl,
1683 struct device_node *parent,
1684 struct pinctrl_map **maps,
1685 unsigned int *num_maps)
1687 struct tegra_padctl_uphy *padctl = pinctrl_dev_get_drvdata(pinctrl);
1688 unsigned int reserved_maps = 0;
1689 struct device_node *np;
1695 pr_info("%s %d\n", __func__, __LINE__);
1696 for_each_child_of_node(parent, np) {
1697 err = tegra186_padctl_uphy_parse_subnode(padctl, np, maps,
1701 pr_info("%s %d err %d\n", __func__, __LINE__, err);
1709 static const struct pinctrl_ops tegra_xusb_padctl_pinctrl_ops = {
1710 .get_groups_count = tegra_xusb_padctl_get_groups_count,
1711 .get_group_name = tegra_xusb_padctl_get_group_name,
1712 .get_group_pins = tegra_xusb_padctl_get_group_pins,
1713 .dt_node_to_map = tegra_xusb_padctl_dt_node_to_map,
1714 .dt_free_map = pinctrl_utils_dt_free_map,
1717 static int tegra186_padctl_uphy_get_functions_count(struct pinctrl_dev *pinctrl)
1719 struct tegra_padctl_uphy *padctl = pinctrl_dev_get_drvdata(pinctrl);
1721 TRACE("num_functions %u", padctl->soc->num_functions);
1722 return padctl->soc->num_functions;
1726 tegra186_padctl_uphy_get_function_name(struct pinctrl_dev *pinctrl,
1727 unsigned int function)
1729 struct tegra_padctl_uphy *padctl = pinctrl_dev_get_drvdata(pinctrl);
1731 TRACE("function %u name %s", function, padctl->soc->functions[function].name);
1732 return padctl->soc->functions[function].name;
1735 static int tegra186_padctl_uphy_get_function_groups(struct pinctrl_dev *pinctrl,
1736 unsigned int function,
1737 const char * const **groups,
1738 unsigned * const num_groups)
1740 struct tegra_padctl_uphy *padctl = pinctrl_dev_get_drvdata(pinctrl);
1742 *num_groups = padctl->soc->functions[function].num_groups;
1743 *groups = padctl->soc->functions[function].groups;
1745 TRACE("function %u *num_groups %u groups %s",
1746 function, *num_groups, *groups[0]);
1750 static int tegra186_padctl_uphy_pinmux_enable(struct pinctrl_dev *pinctrl,
1751 unsigned int function,
1754 struct tegra_padctl_uphy *ctx = pinctrl_dev_get_drvdata(pinctrl);
1755 const struct tegra_padctl_uphy_lane *lane;
1759 lane = &ctx->soc->lanes[group];
1761 TRACE_DEV(pinctrl->dev, "group %u (%s) function %u num_funcs %d",
1762 group, lane->name, function, lane->num_funcs);
1764 for (i = 0; i < lane->num_funcs; i++) {
1765 TRACE_DEV(pinctrl->dev, "funcs[%d] %d", i, lane->funcs[i]);
1766 if (lane->funcs[i] == function)
1770 if (i >= lane->num_funcs)
1773 TRACE_DEV(pinctrl->dev, "group %s set to function %d", lane->name, i);
1775 if (lane_is_otg(group) || lane_is_hsic(group)) {
1776 value = padctl_readl(ctx, lane->offset);
1777 value &= ~(lane->mask << lane->shift);
1778 value |= i << lane->shift;
1779 padctl_writel(ctx, value, lane->offset);
1780 } else if (lane_is_uphy(group)) {
1781 int uphy_lane = group - PIN_UPHY_0;
1782 if (function == TEGRA186_FUNC_USB3)
1783 set_bit(uphy_lane, &ctx->usb3_lanes);
1784 else if (function == TEGRA186_FUNC_PCIE)
1785 set_bit(uphy_lane, &ctx->pcie_lanes);
1786 else if (function == TEGRA186_FUNC_SATA)
1787 set_bit(uphy_lane, &ctx->sata_lanes);
1788 else if (function == TEGRA186_FUNC_MPHY)
1789 set_bit(uphy_lane, &ctx->ufs_lanes);
1791 value = uphy_lane_readl(ctx, uphy_lane, lane->offset);
1792 value &= ~(lane->mask << lane->shift);
1793 value |= i << lane->shift;
1794 uphy_lane_writel(ctx, uphy_lane, value, lane->offset);
1802 static const struct pinmux_ops tegra186_padctl_uphy_pinmux_ops = {
1803 .get_functions_count = tegra186_padctl_uphy_get_functions_count,
1804 .get_function_name = tegra186_padctl_uphy_get_function_name,
1805 .get_function_groups = tegra186_padctl_uphy_get_function_groups,
1806 .enable = tegra186_padctl_uphy_pinmux_enable,
1809 static int tegra_xusb_padctl_pinconf_group_get(struct pinctrl_dev *pinctrl,
1811 unsigned long *config)
1813 struct tegra_padctl_uphy *padctl = pinctrl_dev_get_drvdata(pinctrl);
1814 const struct tegra_padctl_uphy_lane *lane;
1815 enum tegra_xusb_padctl_param param;
1819 param = TEGRA_XUSB_PADCTL_UNPACK_PARAM(*config);
1820 lane = &padctl->soc->lanes[group];
1822 TRACE("group %u param 0x%x\n", group, param);
1825 case TEGRA_XUSB_PADCTL_USB3_PORT:
1826 value = lane_to_usb3_port(padctl, group);
1828 dev_err(padctl->dev,
1829 "Pin %d not mapped to USB3 port\n", group);
1834 case TEGRA_XUSB_PADCTL_USB2_PORT:
1835 port = lane_to_usb3_port(padctl, group);
1837 dev_err(padctl->dev,
1838 "Pin %d not mapped to USB3 port\n", group);
1845 dev_err(padctl->dev, "invalid configuration parameter: %04x\n",
1850 *config = TEGRA_XUSB_PADCTL_PACK(param, value);
1855 static int tegra_xusb_padctl_pinconf_group_set(struct pinctrl_dev *pinctrl,
1857 unsigned long *configs,
1858 unsigned int num_configs)
1860 struct tegra_padctl_uphy *padctl = pinctrl_dev_get_drvdata(pinctrl);
1861 const struct tegra_padctl_uphy_lane *lane;
1862 enum tegra_xusb_padctl_param param;
1863 unsigned long value;
1867 lane = &padctl->soc->lanes[group];
1869 for (i = 0; i < num_configs; i++) {
1870 param = TEGRA_XUSB_PADCTL_UNPACK_PARAM(configs[i]);
1871 value = TEGRA_XUSB_PADCTL_UNPACK_VALUE(configs[i]);
1873 TRACE("group %u config %d param 0x%x value 0x%lx",
1874 group, i, param, value);
1877 case TEGRA_XUSB_PADCTL_USB3_PORT:
1878 if (value >= TEGRA_XUSB_USB3_PHYS) {
1879 dev_err(padctl->dev, "Invalid USB3 port: %lu\n",
1883 if (!lane_is_uphy(group)) {
1884 dev_err(padctl->dev,
1885 "USB3 port not applicable for pin %d\n",
1890 padctl->usb3_ports[value].lane = group;
1893 case TEGRA_XUSB_PADCTL_USB2_PORT:
1894 if (value >= TEGRA_XUSB_UTMI_PHYS) {
1895 dev_err(padctl->dev, "Invalid USB2 port: %lu\n",
1899 if (!lane_is_pcie_or_sata(group)) {
1900 dev_err(padctl->dev,
1901 "USB2 port not applicable for pin %d\n",
1905 port = lane_to_usb3_port(padctl, group);
1907 dev_err(padctl->dev,
1908 "Pin %d not mapped to USB3 port\n",
1916 dev_err(padctl->dev,
1917 "invalid configuration parameter: %04x\n",
1926 static int tegra_xusb_padctl_pinconf_group_set(struct pinctrl_dev *pinctrl,
1928 unsigned long config)
1930 struct tegra_padctl_uphy *padctl = pinctrl_dev_get_drvdata(pinctrl);
1931 const struct tegra_padctl_uphy_lane *lane;
1932 enum tegra_xusb_padctl_param param;
1933 unsigned long value;
1936 lane = &padctl->soc->lanes[group];
1938 param = TEGRA_XUSB_PADCTL_UNPACK_PARAM(config);
1939 value = TEGRA_XUSB_PADCTL_UNPACK_VALUE(config);
1941 TRACE("group %u config 0x%lx param 0x%x value 0x%lx",
1942 group, config, param, value);
1945 case TEGRA_XUSB_PADCTL_USB3_PORT:
1946 if (value >= TEGRA_XUSB_USB3_PHYS) {
1947 dev_err(padctl->dev, "Invalid USB3 port: %lu\n",
1951 if (!lane_is_uphy(group)) {
1952 dev_err(padctl->dev,
1953 "USB3 port not applicable for pin %d\n",
1958 padctl->usb3_ports[value].lane = group;
1961 case TEGRA_XUSB_PADCTL_USB2_PORT:
1962 if (value >= TEGRA_XUSB_UTMI_PHYS) {
1963 dev_err(padctl->dev, "Invalid USB2 port: %lu\n",
1967 if (!lane_is_pcie_or_sata(group)) {
1968 dev_err(padctl->dev,
1969 "USB2 port not applicable for pin %d\n",
1973 port = lane_to_usb3_port(padctl, group);
1975 dev_err(padctl->dev,
1976 "Pin %d not mapped to USB3 port\n",
1984 dev_err(padctl->dev,
1985 "invalid configuration parameter: %04x\n",
1994 #ifdef CONFIG_DEBUG_FS
1995 static const char *strip_prefix(const char *s)
1997 const char *comma = strchr(s, ',');
2005 tegra_xusb_padctl_pinconf_group_dbg_show(struct pinctrl_dev *pinctrl,
2011 for (i = 0; i < ARRAY_SIZE(properties); i++) {
2012 unsigned long config, value;
2015 config = TEGRA_XUSB_PADCTL_PACK(properties[i].param, 0);
2017 err = tegra_xusb_padctl_pinconf_group_get(pinctrl, group,
2022 value = TEGRA_XUSB_PADCTL_UNPACK_VALUE(config);
2024 seq_printf(s, "\n\t%s=%lu\n", strip_prefix(properties[i].name),
2030 tegra_xusb_padctl_pinconf_config_dbg_show(struct pinctrl_dev *pinctrl,
2032 unsigned long config)
2034 enum tegra_xusb_padctl_param param;
2035 const char *name = "unknown";
2036 unsigned long value;
2039 param = TEGRA_XUSB_PADCTL_UNPACK_PARAM(config);
2040 value = TEGRA_XUSB_PADCTL_UNPACK_VALUE(config);
2042 for (i = 0; i < ARRAY_SIZE(properties); i++) {
2043 if (properties[i].param == param) {
2044 name = properties[i].name;
2049 seq_printf(s, "%s=%lu", strip_prefix(name), value);
2053 static const struct pinconf_ops tegra_xusb_padctl_pinconf_ops = {
2054 .pin_config_group_get = tegra_xusb_padctl_pinconf_group_get,
2055 .pin_config_group_set = tegra_xusb_padctl_pinconf_group_set,
2056 #ifdef CONFIG_DEBUG_FS
2057 .pin_config_group_dbg_show = tegra_xusb_padctl_pinconf_group_dbg_show,
2058 .pin_config_config_dbg_show = tegra_xusb_padctl_pinconf_config_dbg_show,
2062 static int tegra_xusb_padctl_enable(struct tegra_padctl_uphy *ctx)
2065 mutex_lock(&ctx->lock);
2066 TRACE_DEV(ctx->dev, "padctl_clients %d", ctx->padctl_clients);
2068 if (ctx->padctl_clients++ > 0)
2072 mutex_unlock(&ctx->lock);
2076 static int tegra_xusb_padctl_disable(struct tegra_padctl_uphy *ctx)
2079 mutex_lock(&ctx->lock);
2081 TRACE_DEV(ctx->dev, "padctl_clients %d", ctx->padctl_clients);
2083 if (WARN_ON(ctx->padctl_clients == 0))
2086 if (--ctx->padctl_clients > 0)
2090 mutex_unlock(&ctx->lock);
2094 static int tegra_xusb_phy_init(struct phy *phy)
2096 struct tegra_padctl_uphy *padctl = phy_get_drvdata(phy);
2098 return tegra_xusb_padctl_enable(padctl);
2101 static int tegra_xusb_phy_exit(struct phy *phy)
2103 struct tegra_padctl_uphy *padctl = phy_get_drvdata(phy);
2105 return tegra_xusb_padctl_disable(padctl);
2108 static int tegra186_pcie_phy_power_on(struct phy *phy)
2110 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2111 unsigned int uphy_lane;
2114 for_each_set_bit(uphy_lane, &ctx->pcie_lanes, T186_UPHY_LANES) {
2115 TRACE_DEV(&phy->dev, "lane %d", uphy_lane);
2117 reg = uphy_lane_readl(ctx, uphy_lane, UPHY_LANE_MUX);
2120 reg |= FORCE_IDDQ_DISABLE;
2121 reg &= ~CLAMP_EN_EARLY;
2122 uphy_lane_writel(ctx, uphy_lane, reg, UPHY_LANE_MUX);
2125 TRACE_DEV(&phy->dev, "FIXME: implement!"); /* TODO: more? */
2129 static int tegra186_pcie_phy_power_off(struct phy *phy)
2131 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2132 unsigned int uphy_lane;
2135 for_each_set_bit(uphy_lane, &ctx->pcie_lanes, T186_UPHY_LANES) {
2136 TRACE_DEV(&phy->dev, "lane %d", uphy_lane);
2138 reg = uphy_lane_readl(ctx, uphy_lane, UPHY_LANE_MUX);
2139 reg &= ~FORCE_IDDQ_DISABLE;
2140 reg |= CLAMP_EN_EARLY;
2141 uphy_lane_writel(ctx, uphy_lane, reg, UPHY_LANE_MUX);
2144 TRACE_DEV(&phy->dev, "FIXME: implement!"); /* TODO */
2148 static int tegra186_pcie_phy_init(struct phy *phy)
2150 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2153 for_each_set_bit(uphy_lane, &ctx->pcie_lanes, T186_UPHY_LANES) {
2154 TRACE_DEV(&phy->dev, "lane %d", uphy_lane);
2156 uphy_pll_init(ctx, 0);
2157 uphy_lane_init(ctx, uphy_lane);
2158 pcie_lane_defaults(ctx, uphy_lane);
2159 pcie_usb3_pll_defaults(ctx);
2162 return tegra_xusb_phy_init(phy);
2165 static int tegra186_pcie_phy_exit(struct phy *phy)
2167 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2170 for_each_set_bit(uphy_lane, &ctx->pcie_lanes, T186_UPHY_LANES) {
2171 TRACE_DEV(&phy->dev, "lane %d", uphy_lane);
2173 uphy_lane_deinit(ctx, uphy_lane);
2174 uphy_pll_deinit(ctx, 0);
2177 return tegra_xusb_phy_exit(phy);
2180 static const struct phy_ops pcie_phy_ops = {
2181 .init = tegra186_pcie_phy_init,
2182 .exit = tegra186_pcie_phy_exit,
2183 .power_on = tegra186_pcie_phy_power_on,
2184 .power_off = tegra186_pcie_phy_power_off,
2185 .owner = THIS_MODULE,
2188 static int tegra186_sata_phy_power_on(struct phy *phy)
2190 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2191 unsigned int uphy_lane;
2194 for_each_set_bit(uphy_lane, &ctx->sata_lanes, T186_UPHY_LANES) {
2195 TRACE_DEV(&phy->dev, "lane %d", uphy_lane);
2197 reg = uphy_lane_readl(ctx, uphy_lane, UPHY_LANE_MUX);
2200 reg |= FORCE_IDDQ_DISABLE;
2201 reg &= ~CLAMP_EN_EARLY;
2202 uphy_lane_writel(ctx, uphy_lane, reg, UPHY_LANE_MUX);
2205 TRACE_DEV(&phy->dev, "FIXME: implement!"); /* TODO: more? */
2209 static int tegra186_sata_phy_power_off(struct phy *phy)
2211 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2212 unsigned int uphy_lane;
2215 for_each_set_bit(uphy_lane, &ctx->sata_lanes, T186_UPHY_LANES) {
2216 TRACE_DEV(&phy->dev, "lane %d", uphy_lane);
2218 reg = uphy_lane_readl(ctx, uphy_lane, UPHY_LANE_MUX);
2219 reg &= ~FORCE_IDDQ_DISABLE;
2220 reg |= CLAMP_EN_EARLY;
2221 uphy_lane_writel(ctx, uphy_lane, reg, UPHY_LANE_MUX);
2224 TRACE_DEV(&phy->dev, "FIXME: implement!"); /* TODO */
2228 static int tegra186_sata_fuse_calibration(struct tegra_padctl_uphy *ctx,
2235 if (ctx->sata_bypass_fuse && ctx->prod_list) {
2236 base = ctx->uphy_lane_regs[lane];
2237 err = tegra_prod_set_by_name(&base,
2238 "prod_c_sata", ctx->prod_list);
2242 /* In case of err update setting based on fuse */
2244 "Failed to set sata prod settings, err %d", err);
2247 /* Update based on fuse_sata_nv_calib[1:0] value */
2248 idx = SATA_NV_CALIB_0_1(ctx->fuse_calib.sata_nv);
2250 reg = uphy_lane_readl(ctx, lane, UPHY_LANE_AUX_CTL_1);
2251 reg |= AUX_RX_IDLE_TH(sata_data[idx].aux_rx_idle_th);
2252 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_AUX_CTL_1);
2254 /* Update based on fuse_sata_nv_calib[3:2] value TBD */
2255 idx = SATA_NV_CALIB_2_3(ctx->fuse_calib.sata_nv);
2257 /* Update based on fuse_sata_mphy_odm_calib[1:0] value */
2258 idx = SATA_MPHY_ODM_CALIB_0_1(ctx->fuse_calib.sata_mphy_odm);
2260 reg = uphy_lane_readl(ctx, lane, UPHY_LANE_DYN_CTL_1);
2261 reg |= TX_DRV_AMP_SEL0(sata_data[idx].tx_drv_amp_sel0);
2262 reg |= TX_DRV_AMP_SEL1(sata_data[idx].tx_drv_amp_sel1);
2263 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DYN_CTL_1);
2265 reg = uphy_lane_readl(ctx, lane, UPHY_LANE_DYN_CTL_4);
2266 reg |= TX_DRV_POST_SEL0(sata_data[idx].tx_drv_post_sel0);
2267 reg |= TX_DRV_POST_SEL1(sata_data[idx].tx_drv_post_sel1);
2268 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DYN_CTL_4);
2270 reg = CFG_ADDR(AE_CTLE_CTRL_ID0);
2271 reg |= CFG_WDATA(sata_data[idx].ae_ctle_ctrl_id0);
2272 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DIRECT_CTL_2);
2274 reg = CFG_ADDR(AE_CTLE_CTRL_ID1);
2275 reg |= CFG_WDATA(sata_data[idx].ae_ctle_ctrl_id1);
2276 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DIRECT_CTL_2);
2281 static int tegra186_sata_phy_init(struct phy *phy)
2283 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2288 for_each_set_bit(uphy_lane, &ctx->sata_lanes, T186_UPHY_LANES) {
2289 TRACE_DEV(&phy->dev, "uphy_lane %u\n", uphy_lane);
2290 sata_lane_init(ctx, uphy_lane);
2293 tegra186_sata_fuse_calibration(ctx, ctx->sata_lanes);
2295 return tegra_xusb_phy_init(phy);
2298 static int tegra186_sata_phy_exit(struct phy *phy)
2300 TRACE_DEV(&phy->dev, "");
2301 return tegra_xusb_phy_exit(phy);
2304 static const struct phy_ops sata_phy_ops = {
2305 .init = tegra186_sata_phy_init,
2306 .exit = tegra186_sata_phy_exit,
2307 .power_on = tegra186_sata_phy_power_on,
2308 .power_off = tegra186_sata_phy_power_off,
2309 .owner = THIS_MODULE,
2313 static int tegra186_ufs_phy_power_on(struct phy *phy)
2319 static int tegra186_ufs_phy_power_off(struct phy *phy)
2321 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2322 unsigned int uphy_lane;
2326 for_each_set_bit(uphy_lane, &ctx->ufs_lanes, T186_UPHY_LANES) {
2327 TRACE_DEV(&phy->dev, "lane %d", uphy_lane);
2328 reg = uphy_lane_readl(ctx, uphy_lane, UPHY_LANE_MUX);
2329 reg &= ~FORCE_IDDQ_DISABLE;
2330 reg |= CLAMP_EN_EARLY;
2331 uphy_lane_writel(ctx, uphy_lane, reg, UPHY_LANE_MUX);
2337 static void tegra186_uphy_lane_pad_macro(bool on)
2339 void __iomem *car_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
2342 reg = ioread32(car_base + CLK_RST_CONTROLLER_RST_DEV_UPHY_0);
2344 reg |= SWR_UPHY_RST;
2346 reg &= ~SWR_UPHY_RST;
2347 iowrite32(reg, car_base + CLK_RST_CONTROLLER_RST_DEV_UPHY_0);
2350 static void tegra186_uphy_lane_and_pll_reset(int function, unsigned long lanes)
2352 void __iomem *car_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
2356 reg = ioread32(car_base + CLK_RST_CONTROLLER_RST_DEV_PEX_USB_UPHY_0);
2358 /* De-assert global reset */
2359 reg |= SWR_PEX_USB_UPHY_RST;
2361 /* De-assert corresponding pll reset */
2362 if (function == TEGRA186_FUNC_MPHY)
2363 reg &= ~SWR_PEX_USB_UPHY_PLL1_RST;
2365 reg &= ~SWR_PEX_USB_UPHY_PLL0_RST;
2367 /* De-assert corresponding lane reset */
2368 for_each_set_bit(uphy_lane, &lanes, T186_UPHY_LANES) {
2369 reg &= ~SWR_PEX_USB_UPHY_LANE_RST(uphy_lane);
2372 iowrite32(reg, car_base + CLK_RST_CONTROLLER_RST_DEV_PEX_USB_UPHY_0);
2375 static int tegra186_ufs_fuse_calibration(struct tegra_padctl_uphy *ctx,
2381 /* Update based on fuse_mphy_nv_calib[1:0] value */
2382 idx = MPHY_NV_CALIB_0_1(ctx->fuse_calib.mphy_nv);
2384 reg = uphy_lane_readl(ctx, lane, UPHY_LANE_AUX_CTL_1);
2385 reg |= AUX_RX_IDLE_TH(mphy_data[idx].aux_rx_idle_th);
2386 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_AUX_CTL_1);
2388 /* Update based on fuse_mphy_nv_calib[3:2] value TBD */
2389 idx = MPHY_NV_CALIB_2_3(ctx->fuse_calib.mphy_nv);
2392 /* Update based on fuse_mphy_nv_calib[5:4] value TBD */
2393 idx = MPHY_NV_CALIB_4_5(ctx->fuse_calib.mphy_nv);
2396 /* Update based on fuse_sata_mphy_odm_calib[1:0] value */
2397 idx = SATA_MPHY_ODM_CALIB_0_1(ctx->fuse_calib.sata_mphy_odm);
2399 reg = uphy_lane_readl(ctx, lane, UPHY_LANE_DYN_CTL_1);
2400 reg |= TX_DRV_AMP_SEL0(mphy_data[idx].tx_drv_amp_sel0);
2401 reg |= TX_DRV_AMP_SEL1(mphy_data[idx].tx_drv_amp_sel1);
2402 reg |= TX_DRV_AMP_SEL2(mphy_data[idx].tx_drv_amp_sel2);
2403 reg |= TX_DRV_AMP_SEL3(mphy_data[idx].tx_drv_amp_sel3);
2404 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DYN_CTL_1);
2406 reg = uphy_lane_readl(ctx, lane, UPHY_LANE_DYN_CTL_2);
2407 reg |= TX_DRV_AMP_SEL4(mphy_data[idx].tx_drv_amp_sel4);
2408 reg |= TX_DRV_AMP_SEL5(mphy_data[idx].tx_drv_amp_sel5);
2409 reg |= TX_DRV_AMP_SEL6(mphy_data[idx].tx_drv_amp_sel6);
2410 reg |= TX_DRV_AMP_SEL7(mphy_data[idx].tx_drv_amp_sel7);
2411 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DYN_CTL_2);
2413 reg = uphy_lane_readl(ctx, lane, UPHY_LANE_DYN_CTL_3);
2414 reg |= TX_DRV_AMP_SEL8(mphy_data[idx].tx_drv_amp_sel8);
2415 reg |= TX_DRV_AMP_SEL9(mphy_data[idx].tx_drv_amp_sel9);
2416 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DYN_CTL_3);
2418 reg = uphy_lane_readl(ctx, lane, UPHY_LANE_DYN_CTL_4);
2419 reg |= TX_DRV_POST_SEL0(mphy_data[idx].tx_drv_post_sel0);
2420 reg |= TX_DRV_POST_SEL1(mphy_data[idx].tx_drv_post_sel1);
2421 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DYN_CTL_4);
2423 reg = uphy_lane_readl(ctx, lane, UPHY_LANE_DYN_CTL_5);
2424 reg |= TX_DRV_POST_SEL2(mphy_data[idx].tx_drv_post_sel2);
2425 reg |= TX_DRV_POST_SEL3(mphy_data[idx].tx_drv_post_sel3);
2426 reg |= TX_DRV_PRE_SEL3(mphy_data[idx].tx_drv_pre_sel3);
2427 uphy_lane_writel(ctx, lane, reg, UPHY_LANE_DYN_CTL_5);
2432 static int tegra186_ufs_phy_init(struct phy *phy)
2434 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2439 /* FIXME: step 1: Enable refplle to 208M and pllp 102M */
2441 /* step 2: De-assert UPHY LANE PAD Macro */
2442 /* FIXME: Should be part of probe ? */
2443 tegra186_uphy_lane_pad_macro(false);
2445 /* Bring the lanes out of IDDQ, remove clamps, select MPHY for mux */
2446 for_each_set_bit(uphy_lane, &ctx->ufs_lanes, T186_UPHY_LANES) {
2447 reg = uphy_lane_readl(ctx, uphy_lane, UPHY_LANE_MUX);
2450 reg |= FORCE_IDDQ_DISABLE;
2451 reg &= ~CLAMP_EN_EARLY;
2452 uphy_lane_writel(ctx, uphy_lane, reg, UPHY_LANE_MUX);
2455 /* FIXME: bring refPLLE to under HW control. Needed ? */
2458 /* step 3: Enable PLL1 and lane by releasing resets */
2459 tegra186_uphy_lane_and_pll_reset(TEGRA186_FUNC_MPHY, ctx->ufs_lanes);
2461 /* pll parameters init */
2464 /* lane parameters init */
2465 for_each_set_bit(uphy_lane, &ctx->ufs_lanes, T186_UPHY_LANES) {
2466 TRACE_DEV(&phy->dev, "uphy_lane %u\n", uphy_lane);
2467 ufs_lane_init(ctx, uphy_lane);
2470 /* step 4: electrical parameters programming based on fuses */
2471 for_each_set_bit(uphy_lane, &ctx->ufs_lanes, T186_UPHY_LANES)
2472 tegra186_ufs_fuse_calibration(ctx, uphy_lane);
2474 /* step 5: rate id programming */
2475 ufs_pll_rateid_init(ctx);
2476 ufs_lane_rateid_init(ctx, ctx->ufs_lanes);
2478 /* step 6: uphy pll1 calibration */
2479 uphy_pll_init(ctx, 0);
2481 /* FIXME: Need to add MPHY programming in above step ? */
2483 return tegra_xusb_phy_init(phy);
2486 static int tegra186_ufs_phy_exit(struct phy *phy)
2488 TRACE_DEV(&phy->dev, "");
2489 return tegra_xusb_phy_exit(phy);
2492 static const struct phy_ops ufs_phy_ops = {
2493 .init = tegra186_ufs_phy_init,
2494 .exit = tegra186_ufs_phy_exit,
2495 .power_on = tegra186_ufs_phy_power_on,
2496 .power_off = tegra186_ufs_phy_power_off,
2497 .owner = THIS_MODULE,
2500 static int usb3_phy_to_port(struct phy *phy)
2502 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2505 for (i = 0; i < TEGRA_XUSB_USB3_PHYS; i++) {
2506 if (phy == ctx->usb3_phys[i])
2514 static int tegra186_usb3_phy_power_on(struct phy *phy)
2516 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2517 int port = usb3_phy_to_port(phy);
2518 unsigned int uphy_lane;
2522 TRACE_DEV(&phy->dev, "port %d", port);
2526 lane = ctx->usb3_ports[port].lane;
2527 if (!lane_is_uphy(lane)) {
2528 dev_err(ctx->dev, "USB3 PHY %d mapped to invalid lane: %d\n",
2533 reg = padctl_readl(ctx, XUSB_PADCTL_SS_PORT_CAP);
2534 reg &= ~(PORT_CAP_MASK << PORTX_CAP_SHIFT(port));
2535 reg |= (PORT_CAP_HOST << PORTX_CAP_SHIFT(port));
2536 padctl_writel(ctx, reg, XUSB_PADCTL_SS_PORT_CAP);
2538 uphy_lane = lane - PIN_UPHY_0;
2539 reg = uphy_lane_readl(ctx, uphy_lane, UPHY_LANE_MUX);
2542 reg |= FORCE_IDDQ_DISABLE;
2543 reg &= ~CLAMP_EN_EARLY;
2544 uphy_lane_writel(ctx, uphy_lane, reg, UPHY_LANE_MUX);
2546 reg = padctl_readl(ctx, XUSB_PADCTL_ELPG_PROGRAM_1);
2547 reg &= ~SSPX_ELPG_CLAMP_EN_EARLY(port);
2548 padctl_writel(ctx, reg, XUSB_PADCTL_ELPG_PROGRAM_1);
2550 usleep_range(100, 200);
2552 reg = padctl_readl(ctx, XUSB_PADCTL_ELPG_PROGRAM_1);
2553 reg &= ~SSPX_ELPG_CLAMP_EN_EARLY(port);
2554 padctl_writel(ctx, reg, XUSB_PADCTL_ELPG_PROGRAM_1);
2556 reg = padctl_readl(ctx, XUSB_PADCTL_ELPG_PROGRAM_1);
2557 reg &= ~SSPX_ELPG_VCORE_DOWN(port);
2558 padctl_writel(ctx, reg, XUSB_PADCTL_ELPG_PROGRAM_1);
2563 static int tegra186_usb3_phy_power_off(struct phy *phy)
2565 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2566 int port = usb3_phy_to_port(phy);
2567 unsigned int uphy_lane;
2571 TRACE_DEV(&phy->dev, "port %d", port);
2575 lane = ctx->usb3_ports[port].lane;
2576 if (!lane_is_uphy(lane)) {
2577 dev_err(ctx->dev, "USB3 PHY %d mapped to invalid lane: %d\n",
2582 uphy_lane = lane - PIN_UPHY_0;
2583 reg = uphy_lane_readl(ctx, uphy_lane, UPHY_LANE_MUX);
2584 reg &= ~FORCE_IDDQ_DISABLE;
2585 reg |= CLAMP_EN_EARLY;
2586 uphy_lane_writel(ctx, uphy_lane, reg, UPHY_LANE_MUX);
2588 reg = padctl_readl(ctx, XUSB_PADCTL_ELPG_PROGRAM_1);
2589 reg |= SSPX_ELPG_CLAMP_EN_EARLY(port);
2590 padctl_writel(ctx, reg, XUSB_PADCTL_ELPG_PROGRAM_1);
2592 usleep_range(100, 200);
2594 reg = padctl_readl(ctx, XUSB_PADCTL_ELPG_PROGRAM_1);
2595 reg |= SSPX_ELPG_CLAMP_EN_EARLY(port);
2596 padctl_writel(ctx, reg, XUSB_PADCTL_ELPG_PROGRAM_1);
2598 usleep_range(250, 350);
2600 reg = padctl_readl(ctx, XUSB_PADCTL_ELPG_PROGRAM_1);
2601 reg |= SSPX_ELPG_VCORE_DOWN(port);
2602 padctl_writel(ctx, reg, XUSB_PADCTL_ELPG_PROGRAM_1);
2607 static int tegra186_usb3_phy_init(struct phy *phy)
2609 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2610 int port = usb3_phy_to_port(phy);
2614 TRACE_DEV(&phy->dev, "port %d", port);
2618 lane = ctx->usb3_ports[port].lane;
2619 if (!lane_is_uphy(lane)) {
2620 dev_err(ctx->dev, "USB3 PHY %d mapped to invalid lane: %d\n",
2625 uphy_pll_init(ctx, 0);
2627 uphy_lane = lane - PIN_UPHY_0;
2628 uphy_lane_init(ctx, uphy_lane);
2629 usb3_lane_defaults(ctx, uphy_lane);
2630 pcie_usb3_pll_defaults(ctx);
2632 return tegra_xusb_phy_init(phy);
2635 static int tegra186_usb3_phy_exit(struct phy *phy)
2637 struct tegra_padctl_uphy *ctx = phy_get_drvdata(phy);
2638 int port = usb3_phy_to_port(phy);
2642 TRACE_DEV(&phy->dev, "port %d", port);
2646 lane = ctx->usb3_ports[port].lane;
2647 if (!lane_is_uphy(lane)) {
2648 dev_err(ctx->dev, "USB3 PHY %d mapped to invalid lane: %d\n",
2653 uphy_lane = lane - PIN_UPHY_0;
2654 uphy_lane_deinit(ctx, lane);
2655 uphy_pll_deinit(ctx, 0);
2657 return tegra_xusb_phy_exit(phy);
2660 static const struct phy_ops usb3_phy_ops = {
2661 .init = tegra186_usb3_phy_init,
2662 .exit = tegra186_usb3_phy_exit,
2663 .power_on = tegra186_usb3_phy_power_on,
2664 .power_off = tegra186_usb3_phy_power_off,
2665 .owner = THIS_MODULE,
2668 static int utmi_phy_to_port(struct phy *phy)
2670 struct tegra_padctl_uphy *padctl = phy_get_drvdata(phy);
2673 for (i = 0; i < TEGRA_XUSB_UTMI_PHYS; i++) {
2674 if (phy == padctl->utmi_phys[i])
2682 static int tegra186_utmi_phy_power_on(struct phy *phy)
2684 struct tegra_padctl_uphy *padctl = phy_get_drvdata(phy);
2685 int port = utmi_phy_to_port(phy);
2689 TRACE_DEV(&phy->dev, "port %d", port);
2694 value = padctl_readl(padctl, XUSB_PADCTL_USB2_PORT_CAP);
2695 value &= ~(PORT_CAP_MASK << PORTX_CAP_SHIFT(port));
2697 if (port == 0) /* TODO: support OTG */
2698 value |= (PORT_CAP_DEVICE << PORTX_CAP_SHIFT(port));
2701 value |= (PORT_CAP_HOST << PORTX_CAP_SHIFT(port));
2702 padctl_writel(padctl, value, XUSB_PADCTL_USB2_PORT_CAP);
2705 value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(port));
2706 value &= ~(USB2_OTG_PD | USB2_OTG_PD2 | USB2_OTG_PD_ZI);
2707 value &= ~HS_CURR_LEVEL(~0);
2708 value |= HS_CURR_LEVEL(padctl->calib.hs_curr_level[port]);
2709 padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(port));
2711 value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(port));
2712 value &= ~USB2_OTG_PD_DR;
2713 value &= ~TERM_RANGE_ADJ(~0);
2714 value |= TERM_RANGE_ADJ(padctl->calib.hs_term_range_adj);
2715 padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(port));
2717 err = regulator_enable(padctl->vbus[port]);
2721 mutex_lock(&padctl->lock);
2723 if (padctl->utmi_enable++ > 0)
2726 value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
2727 value &= ~BIAS_PAD_PD;
2728 padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
2731 mutex_unlock(&padctl->lock);
2735 static int tegra186_utmi_phy_power_off(struct phy *phy)
2737 struct tegra_padctl_uphy *padctl = phy_get_drvdata(phy);
2738 int port = utmi_phy_to_port(phy);
2741 TRACE_DEV(&phy->dev, "port %d", port);
2745 regulator_disable(padctl->vbus[port]);
2747 mutex_lock(&padctl->lock);
2749 if (WARN_ON(padctl->utmi_enable == 0))
2752 if (--padctl->utmi_enable > 0)
2755 value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
2756 value |= BIAS_PAD_PD;
2757 padctl_writel(padctl, value, XUSB_PADCTL_USB2_BIAS_PAD_CTL0);
2760 mutex_unlock(&padctl->lock);
2764 static int tegra186_utmi_phy_init(struct phy *phy)
2766 TRACE_DEV(&phy->dev, "");
2767 return tegra_xusb_phy_init(phy);
2770 static int tegra186_utmi_phy_exit(struct phy *phy)
2772 TRACE_DEV(&phy->dev, "");
2773 return tegra_xusb_phy_exit(phy);
2776 static const struct phy_ops utmi_phy_ops = {
2777 .init = tegra186_utmi_phy_init,
2778 .exit = tegra186_utmi_phy_exit,
2779 .power_on = tegra186_utmi_phy_power_on,
2780 .power_off = tegra186_utmi_phy_power_off,
2781 .owner = THIS_MODULE,
2785 static int utmi_phy_set_role(struct phy *phy, bool host)
2787 struct tegra_padctl_uphy *padctl = phy_get_drvdata(phy);
2788 int pad = utmi_phy_to_port(phy);
2791 dev_info(&phy->dev, "%s %d port %d\n", __func__, __LINE__, pad);
2795 reg = padctl_readl(padctl, USB2_BATTERY_CHRG_OTGPADX_CTL1(pad));
2796 reg &= ~(VREG_FIX18 | VREG_LEV(~0));
2801 padctl_writel(padctl, reg, USB2_BATTERY_CHRG_OTGPADX_CTL1(pad));
2803 reg = padctl_readl(padctl, USB2_VBUS_ID);
2805 reg &= ~VBUS_OVERRIDE;
2807 reg |= VBUS_OVERRIDE;
2808 padctl_writel(padctl, reg, USB2_VBUS_ID);
2813 static int tegra_phy_otg_set_host(struct phy *phy)
2815 return utmi_phy_set_role(phy, true);
2818 static int tegra_phy_otg_set_device(struct phy *phy)
2820 return utmi_phy_set_role(phy, false);
2823 static int hsic_phy_to_port(struct phy *phy)
2825 struct tegra_padctl_uphy *padctl = phy_get_drvdata(phy);
2828 for (i = 0; i < TEGRA_XUSB_HSIC_PHYS; i++) {
2829 if (phy == padctl->hsic_phys[i])
2837 static int tegra186_hsic_phy_power_on(struct phy *phy)
2839 struct tegra_padctl_uphy *padctl = phy_get_drvdata(phy);
2840 int port = hsic_phy_to_port(phy);
2844 TRACE_DEV(&phy->dev, "port %d", port);
2848 err = regulator_enable(padctl->vddio_hsic);
2852 value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL1(port));
2853 value &= ~(XUSB_PADCTL_HSIC_PAD_CTL1_RPD_STROBE |
2854 XUSB_PADCTL_HSIC_PAD_CTL1_RPU_DATA |
2855 XUSB_PADCTL_HSIC_PAD_CTL1_PD_RX |
2856 XUSB_PADCTL_HSIC_PAD_CTL1_PD_ZI |
2857 XUSB_PADCTL_HSIC_PAD_CTL1_PD_TRX |
2858 XUSB_PADCTL_HSIC_PAD_CTL1_PD_TX);
2859 value |= XUSB_PADCTL_HSIC_PAD_CTL1_RPD_DATA |
2860 XUSB_PADCTL_HSIC_PAD_CTL1_RPU_STROBE;
2861 padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL1(port));
2864 TRACE_DEV(&phy->dev, "FIXME: implement!"); /* TODO */
2869 static int tegra186_hsic_phy_power_off(struct phy *phy)
2871 struct tegra_padctl_uphy *padctl = phy_get_drvdata(phy);
2872 int port = hsic_phy_to_port(phy);
2875 TRACE_DEV(&phy->dev, "port %d\n", port);
2879 value = padctl_readl(padctl, XUSB_PADCTL_HSIC_PADX_CTL1(port));
2880 value |= XUSB_PADCTL_HSIC_PAD_CTL1_PD_RX |
2881 XUSB_PADCTL_HSIC_PAD_CTL1_PD_ZI |
2882 XUSB_PADCTL_HSIC_PAD_CTL1_PD_TRX |
2883 XUSB_PADCTL_HSIC_PAD_CTL1_PD_TX;
2884 padctl_writel(padctl, value, XUSB_PADCTL_HSIC_PADX_CTL1(port));
2887 TRACE_DEV(&phy->dev, "FIXME: implement!"); /* TODO */
2889 regulator_disable(padctl->vddio_hsic);
2894 static int tegra186_hsic_phy_init(struct phy *phy)
2896 TRACE_DEV(&phy->dev, "");
2897 return tegra_xusb_phy_init(phy);
2900 static int tegra186_hsic_phy_exit(struct phy *phy)
2902 TRACE_DEV(&phy->dev, "");
2903 return tegra_xusb_phy_exit(phy);
2906 static const struct phy_ops hsic_phy_ops = {
2907 .init = tegra186_hsic_phy_init,
2908 .exit = tegra186_hsic_phy_exit,
2909 .power_on = tegra186_hsic_phy_power_on,
2910 .power_off = tegra186_hsic_phy_power_off,
2911 .owner = THIS_MODULE,
2914 static struct phy *tegra186_padctl_uphy_xlate(struct device *dev,
2915 struct of_phandle_args *args)
2917 struct tegra_padctl_uphy *padctl = dev_get_drvdata(dev);
2918 unsigned int index = args->args[0];
2919 unsigned int phy_index;
2920 struct phy *phy = NULL;
2922 if (args->args_count <= 0)
2923 return ERR_PTR(-EINVAL);
2925 TRACE_DEV(dev, "index %d", index);
2927 if ((index >= TEGRA_USB3_PADCTL_USB3_BASE) &&
2928 (index < TEGRA_USB3_PADCTL_USB3_BASE + 16)) {
2930 phy_index = index - TEGRA_USB3_PADCTL_USB3_BASE;
2931 if (phy_index < TEGRA_XUSB_USB3_PHYS)
2932 phy = padctl->usb3_phys[phy_index];
2934 } else if ((index >= TEGRA_USB3_PADCTL_UTMI_BASE) &&
2935 (index < TEGRA_USB3_PADCTL_UTMI_BASE + 16)) {
2937 phy_index = index - TEGRA_USB3_PADCTL_UTMI_BASE;
2938 if (phy_index < TEGRA_XUSB_UTMI_PHYS)
2939 phy = padctl->utmi_phys[phy_index];
2941 } else if ((index >= TEGRA_USB3_PADCTL_HSIC_BASE) &&
2942 (index < TEGRA_USB3_PADCTL_HSIC_BASE + 16)) {
2944 phy_index = index - TEGRA_USB3_PADCTL_HSIC_BASE;
2945 if (phy_index < TEGRA_XUSB_HSIC_PHYS)
2946 phy = padctl->hsic_phys[phy_index];
2948 } else if ((index >= TEGRA_USB3_PADCTL_PCIE_BASE) &&
2949 (index < TEGRA_USB3_PADCTL_PCIE_BASE + 16)) {
2951 phy_index = index - TEGRA_USB3_PADCTL_PCIE_BASE;
2952 if (phy_index < TEGRA_XUSB_PCIE_PHYS)
2953 phy = padctl->pcie_phys[phy_index];
2955 } else if ((index >= TEGRA_USB3_PADCTL_SATA_BASE) &&
2956 (index < TEGRA_USB3_PADCTL_SATA_BASE + 16)) {
2958 phy_index = index - TEGRA_USB3_PADCTL_SATA_BASE;
2959 if (phy_index < TEGRA_XUSB_SATA_PHYS)
2960 phy = padctl->sata_phys[phy_index];
2962 } else if ((index >= TEGRA_USB3_PADCTL_UFS_BASE) &&
2963 (index < TEGRA_USB3_PADCTL_UFS_BASE + 16)) {
2965 phy_index = index - TEGRA_USB3_PADCTL_UFS_BASE;
2966 if (phy_index < TEGRA_XUSB_UFS_PHYS)
2967 phy = padctl->ufs_phys[phy_index];
2971 return (phy) ? phy : ERR_PTR(-EINVAL);
2974 static const struct pinctrl_pin_desc tegra186_pins[] = {
2975 PINCTRL_PIN(PIN_OTG_0, "otg-0"),
2976 PINCTRL_PIN(PIN_OTG_1, "otg-1"),
2977 PINCTRL_PIN(PIN_OTG_2, "otg-2"),
2978 PINCTRL_PIN(PIN_OTG_3, "otg-3"),
2979 PINCTRL_PIN(PIN_HSIC_0, "hsic-0"),
2980 PINCTRL_PIN(PIN_HSIC_1, "hsic-1"),
2981 PINCTRL_PIN(PIN_UPHY_0, "uphy-lane-0"),
2982 PINCTRL_PIN(PIN_UPHY_1, "uphy-lane-1"),
2983 PINCTRL_PIN(PIN_UPHY_2, "uphy-lane-2"),
2984 PINCTRL_PIN(PIN_UPHY_3, "uphy-lane-3"),
2985 PINCTRL_PIN(PIN_UPHY_4, "uphy-lane-4"),
2986 PINCTRL_PIN(PIN_UPHY_5, "uphy-lane-5"),
2990 static const char * const tegra186_hsic_groups[] = {
2995 static const char * const tegra186_hsic_plus_groups[] = {
3000 static const char * const tegra186_xusb_groups[] = {
3007 static const char * const tegra186_uart_groups[] = {
3014 static const char * const tegra186_pcie_groups[] = {
3023 static const char * const tegra186_usb3_groups[] = {
3032 static const char * const tegra186_sata_groups[] = {
3041 static const char * const tegra186_mphy_groups[] = {
3050 #define TEGRA186_FUNCTION(_name) \
3053 .num_groups = ARRAY_SIZE(tegra186_##_name##_groups), \
3054 .groups = tegra186_##_name##_groups, \
3057 static struct tegra_padctl_uphy_function tegra186_functions[] = {
3058 TEGRA186_FUNCTION(hsic),
3059 TEGRA186_FUNCTION(hsic_plus),
3060 TEGRA186_FUNCTION(xusb),
3061 TEGRA186_FUNCTION(uart),
3062 TEGRA186_FUNCTION(pcie),
3063 TEGRA186_FUNCTION(usb3),
3064 TEGRA186_FUNCTION(sata),
3065 TEGRA186_FUNCTION(mphy),
3068 static const unsigned int tegra186_otg_functions[] = {
3069 TEGRA186_FUNC_RSVD_0,
3072 TEGRA186_FUNC_RSVD_3
3075 static const unsigned int tegra186_hsic_functions[] = {
3077 TEGRA186_FUNC_HSIC_PLUS,
3080 static const unsigned int tegra186_uphy_functions[] = {
3087 #define TEGRA186_LANE(_name, _offset, _shift, _mask, _iddq, _funcs) \
3090 .offset = _offset, \
3094 .num_funcs = ARRAY_SIZE(tegra186_##_funcs##_functions), \
3095 .funcs = tegra186_##_funcs##_functions, \
3098 static const struct tegra_padctl_uphy_lane tegra186_lanes[] = {
3099 TEGRA186_LANE("otg-0", 0x004, 0, 0x3, 0, otg),
3100 TEGRA186_LANE("otg-1", 0x004, 2, 0x3, 0, otg),
3101 TEGRA186_LANE("otg-2", 0x004, 4, 0x3, 0, otg),
3102 TEGRA186_LANE("otg-3", 0x004, 6, 0x3, 0, otg),
3103 TEGRA186_LANE("hsic-0", 0x004, 20, 0x1, 0, hsic),
3104 TEGRA186_LANE("hsic-1", 0x004, 21, 0x1, 0, hsic),
3105 TEGRA186_LANE("uphy-lane-0", 0x284, 0, 0x3, 9, uphy),
3106 TEGRA186_LANE("uphy-lane-1", 0x284, 0, 0x3, 9, uphy),
3107 TEGRA186_LANE("uphy-lane-2", 0x284, 0, 0x3, 9, uphy),
3108 TEGRA186_LANE("uphy-lane-3", 0x284, 0, 0x3, 9, uphy),
3109 TEGRA186_LANE("uphy-lane-4", 0x284, 0, 0x3, 9, uphy),
3110 TEGRA186_LANE("uphy-lane-5", 0x284, 0, 0x3, 9, uphy),
3113 static const struct tegra_padctl_uphy_soc tegra186_soc = {
3114 .num_pins = ARRAY_SIZE(tegra186_pins),
3115 .pins = tegra186_pins,
3116 .num_functions = ARRAY_SIZE(tegra186_functions),
3117 .functions = tegra186_functions,
3118 .num_lanes = ARRAY_SIZE(tegra186_lanes),
3119 .lanes = tegra186_lanes,
3120 .hsic_port_offset = 6,
3123 static const struct of_device_id tegra_padctl_uphy_of_match[] = {
3124 { .compatible = "nvidia,tegra186-padctl-uphy", .data = &tegra186_soc },
3127 MODULE_DEVICE_TABLE(of, tegra_padctl_uphy_of_match);
3129 static int tegra_xusb_read_fuse_calibration(struct tegra_padctl_uphy *padctl)
3134 value = tegra_fuse_readl(FUSE_SKU_USB_CALIB_0);
3135 dev_info(padctl->dev, "FUSE_SKU_USB_CALIB_0 0x%x\n", value);
3136 for (i = 0; i < TEGRA_XUSB_UTMI_PHYS; i++) {
3137 padctl->calib.hs_curr_level[i] =
3138 (value >> USB_CALIB_HS_CURR_LEVEL_PADX_SHIFT(i)) &
3139 USB_CALIB_HS_CURR_LEVEL_PAD_MASK;
3141 padctl->calib.hs_term_range_adj =
3142 (value >> USB_CALIB_HS_TERM_RANGE_ADJ_SHIFT) &
3143 USB_CALIB_HS_TERM_RANGE_ADJ_MASK;
3145 value = tegra_fuse_readl(FUSE_USB_CALIB_EXT_0);
3146 dev_info(padctl->dev, "FUSE_USB_CALIB_EXT_0 0x%x\n", value);
3147 padctl->calib.rpd_ctrl =
3148 (value >> USB_CALIB_EXT_RPD_CTRL_SHIFT) &
3149 USB_CALIB_EXT_RPD_CTRL_MASK;
3154 static int tegra_mphy_stata_fuse_calibration(struct tegra_padctl_uphy *padctl)
3158 value = tegra_fuse_readl(FUSE_SATA_MPHY_ODM_CALIB_0);
3159 padctl->fuse_calib.sata_mphy_odm = value;
3161 value = tegra_fuse_readl(FUSE_SATA_NV_CALIB_0);
3162 padctl->fuse_calib.sata_nv = value;
3164 value = tegra_fuse_readl(FUSE_MPHY_NV_CALIB_0);
3165 padctl->fuse_calib.mphy_nv = value;
3170 static int tegra_xusb_setup_usb(struct tegra_padctl_uphy *ctx)
3175 for (i = 0; i < TEGRA_XUSB_USB3_PHYS; i++) {
3176 phy = devm_phy_create(ctx->dev, &usb3_phy_ops, NULL);
3177 TRACE("SS P%d phy %p\n", i, phy);
3179 return PTR_ERR(phy);
3181 ctx->usb3_phys[i] = phy;
3182 phy_set_drvdata(phy, ctx);
3185 for (i = 0; i < TEGRA_XUSB_UTMI_PHYS; i++) {
3186 char reg_name[sizeof("vbus-N")];
3188 sprintf(reg_name, "vbus-%d", i);
3189 ctx->vbus[i] = devm_regulator_get(ctx->dev, reg_name);
3190 TRACE("UTMI P%d vbus %p IS_ERR %ld PTR_ERR %ld\n", i, ctx->vbus[i], IS_ERR(ctx->vbus[i]), PTR_ERR(ctx->vbus[i]));
3191 if (IS_ERR(ctx->vbus[i]))
3192 return PTR_ERR(ctx->vbus[i]);
3194 phy = devm_phy_create(ctx->dev, &utmi_phy_ops, NULL);
3195 TRACE("UTMI P%d phy %p IS_ERR %ld PTR_ERR %ld\n", i, phy, IS_ERR(phy), PTR_ERR(phy));
3197 return PTR_ERR(phy);
3199 ctx->utmi_phys[i] = phy;
3200 phy_set_drvdata(phy, ctx);
3203 ctx->vddio_hsic = devm_regulator_get(ctx->dev, "vddio_hsic");
3204 if (IS_ERR(ctx->vddio_hsic))
3205 return PTR_ERR(ctx->vddio_hsic);
3207 for (i = 0; i < TEGRA_XUSB_HSIC_PHYS; i++) {
3208 phy = devm_phy_create(ctx->dev, &hsic_phy_ops, NULL);
3209 TRACE("HSIC P%d phy %p\n", i, phy);
3211 return PTR_ERR(phy);
3213 ctx->hsic_phys[i] = phy;
3214 phy_set_drvdata(phy, ctx);
3222 #define reg_dump(_dev, _base, _reg) \
3223 dev_info(_dev, "%s @%x = 0x%x\n", #_reg, _reg, ioread32(_base + _reg));
3225 #define reg_dump(_dev, _base, _reg) do {} while (0)
3228 static void __iomem *car_base;
3229 static void tegra186_fpga_hacks_init(struct platform_device *pdev)
3231 #if defined(CONFIG_ARCH_TEGRA_18x_SOC)
3232 car_base = devm_ioremap(&pdev->dev, 0x05000000, 0x1000000);
3235 dev_err(&pdev->dev, "failed to map CAR mmio\n");
3239 void tegra186_fpga_hacks_uphy_reset(struct platform_device *pdev, bool on)
3243 dev_err(&pdev->dev, "CAR mmio is not mapped\n");
3247 reg_dump(&pdev->dev, car_base, CLK_RST_CONTROLLER_RST_DEV_UPHY_0);
3248 reg = ioread32(car_base + CLK_RST_CONTROLLER_RST_DEV_UPHY_0);
3250 reg |= SWR_UPHY_RST;
3252 reg &= ~SWR_UPHY_RST;
3253 iowrite32(reg, car_base + CLK_RST_CONTROLLER_RST_DEV_UPHY_0);
3254 reg_dump(&pdev->dev, car_base, CLK_RST_CONTROLLER_RST_DEV_UPHY_0);
3257 static int tegra186_padctl_uphy_probe(struct platform_device *pdev)
3259 struct tegra_padctl_uphy *ctx;
3260 const struct of_device_id *match;
3261 struct device_node *np = pdev->dev.of_node;
3262 struct resource *res;
3267 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
3272 platform_set_drvdata(pdev, ctx);
3273 mutex_init(&ctx->lock);
3274 ctx->dev = &pdev->dev;
3277 match = of_match_node(tegra_padctl_uphy_of_match, pdev->dev.of_node);
3278 ctx->soc = match->data;
3283 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3284 ctx->padctl_regs = devm_ioremap_resource(&pdev->dev, res);
3285 TRACE_DEV(&pdev->dev, "padctl mmio start %pa end %pa\n", &res->start, &res->end);
3286 if (IS_ERR(ctx->padctl_regs))
3287 return PTR_ERR(ctx->padctl_regs);
3289 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
3290 ctx->uphy_regs = devm_ioremap_resource(&pdev->dev, res);
3291 TRACE_DEV(&pdev->dev, "uphy mmio start %pa end %pa\n", &res->start, &res->end);
3292 if (IS_ERR(ctx->uphy_regs))
3293 return PTR_ERR(ctx->uphy_regs);
3295 ctx->uphy_pll_regs[0] = ctx->uphy_regs;
3296 ctx->uphy_lane_regs[0] = ctx->uphy_regs + 0x20000;
3297 ctx->uphy_lane_regs[1] = ctx->uphy_regs + 0x30000;
3298 ctx->uphy_lane_regs[2] = ctx->uphy_regs + 0x40000;
3299 ctx->uphy_lane_regs[3] = ctx->uphy_regs + 0x50000;
3300 ctx->uphy_lane_regs[4] = ctx->uphy_regs + 0x60000;
3301 ctx->uphy_lane_regs[5] = ctx->uphy_regs + 0x70000;
3302 ctx->uphy_pll_regs[1] = ctx->uphy_regs + 0x80000;
3305 if (tegra_platform_is_silicon()) {
3306 err = tegra_xusb_read_fuse_calibration(ctx);
3310 err = tegra_mphy_stata_fuse_calibration(ctx);
3316 if (tegra_platform_is_silicon()) {
3317 /* TODO: check clock framework */
3318 ctx->clk = devm_clk_get(ctx->dev, "uphy");
3319 if (IS_ERR(ctx->clk)) {
3320 dev_err(ctx->dev, "failed to get uphy pad clock\n");
3321 return PTR_ERR(ctx->clk);
3323 tegra_periph_reset_deassert(ctx->clk);
3326 if (tegra_platform_is_fpga()) {
3327 tegra186_fpga_hacks_init(pdev);
3328 tegra186_fpga_hacks_uphy_reset(pdev, false);
3332 memset(&ctx->desc, 0, sizeof(ctx->desc));
3333 ctx->desc.name = dev_name(ctx->dev);
3334 ctx->desc.pins = ctx->soc->pins;
3335 ctx->desc.npins = ctx->soc->num_pins;
3336 ctx->desc.pctlops = &tegra_xusb_padctl_pinctrl_ops;
3337 ctx->desc.pmxops = &tegra186_padctl_uphy_pinmux_ops;
3338 ctx->desc.confops = &tegra_xusb_padctl_pinconf_ops;
3339 ctx->desc.owner = THIS_MODULE;
3341 ctx->pinctrl = pinctrl_register(&ctx->desc, &pdev->dev, ctx);
3342 if (!ctx->pinctrl) {
3343 dev_err(&pdev->dev, "failed to register pincontrol\n");
3345 goto assert_clk_reset;
3349 phy = devm_phy_create(&pdev->dev, &pcie_phy_ops, NULL);
3355 ctx->pcie_phys[0] = phy;
3356 phy_set_drvdata(phy, ctx);
3359 phy = devm_phy_create(&pdev->dev, &sata_phy_ops, NULL);
3365 ctx->sata_phys[0] = phy;
3366 phy_set_drvdata(phy, ctx);
3369 phy = devm_phy_create(&pdev->dev, &ufs_phy_ops, NULL);
3375 ctx->ufs_phys[0] = phy;
3376 phy_set_drvdata(phy, ctx);
3379 err = tegra_xusb_setup_usb(ctx);
3380 TRACE("err %d\n", err);
3385 ctx->provider = devm_of_phy_provider_register(&pdev->dev,
3386 tegra186_padctl_uphy_xlate);
3387 if (IS_ERR(ctx->provider)) {
3388 dev_err(&pdev->dev, "failed to register PHYs: %d\n", err);
3394 ctx->prod_list = tegra_prod_get(&pdev->dev, NULL);
3395 if (IS_ERR_OR_NULL(ctx->prod_list)) {
3396 dev_warn(&pdev->dev, "uphy: prod list not found %ld\n",
3397 PTR_ERR(ctx->prod_list));
3398 ctx->prod_list = NULL;
3401 ctx->sata_bypass_fuse =
3402 of_property_read_bool(np, "nvidia,sata-use-prods");
3408 pinctrl_unregister(ctx->pinctrl);
3410 if (tegra_platform_is_silicon())
3411 tegra_periph_reset_assert(ctx->clk);
3415 static int tegra186_padctl_uphy_remove(struct platform_device *pdev)
3417 struct tegra_padctl_uphy *ctx = platform_get_drvdata(pdev);
3419 tegra_prod_release(&ctx->prod_list);
3421 pinctrl_unregister(ctx->pinctrl);
3422 tegra_periph_reset_assert(ctx->clk);
3426 static struct platform_driver tegra186_padctl_uphy_driver = {
3428 .name = "tegra186-padctl-uphy",
3429 .of_match_table = tegra_padctl_uphy_of_match,
3431 .probe = tegra186_padctl_uphy_probe,
3432 .remove = tegra186_padctl_uphy_remove,
3434 module_platform_driver(tegra186_padctl_uphy_driver);
3436 MODULE_AUTHOR("JC Kuo <jckuo@nvidia.com>");
3437 MODULE_DESCRIPTION("Tegra 186 XUSB Pad Control and UPHY driver");
3438 MODULE_LICENSE("GPL v2");