1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
7 #include <linux/clk-provider.h>
8 #include <linux/delay.h>
11 #include <linux/iopoll.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
15 #include <linux/of_device.h>
16 #include <linux/of_address.h>
17 #include <linux/phy/phy.h>
18 #include <linux/platform_device.h>
19 #include <linux/regulator/consumer.h>
20 #include <linux/reset.h>
21 #include <linux/slab.h>
23 #include <dt-bindings/phy/phy.h>
25 #include "phy-qcom-qmp.h"
27 /* QPHY_SW_RESET bit */
28 #define SW_RESET BIT(0)
29 /* QPHY_POWER_DOWN_CONTROL */
30 #define SW_PWRDN BIT(0)
31 #define REFCLK_DRV_DSBL BIT(1)
32 /* QPHY_START_CONTROL bits */
33 #define SERDES_START BIT(0)
34 #define PCS_START BIT(1)
35 #define PLL_READY_GATE_EN BIT(3)
36 /* QPHY_PCS_STATUS bit */
37 #define PHYSTATUS BIT(6)
38 /* QPHY_COM_PCS_READY_STATUS bit */
39 #define PCS_READY BIT(0)
41 /* QPHY_V3_DP_COM_RESET_OVRD_CTRL register bits */
42 /* DP PHY soft reset */
43 #define SW_DPPHY_RESET BIT(0)
44 /* mux to select DP PHY reset control, 0:HW control, 1: software reset */
45 #define SW_DPPHY_RESET_MUX BIT(1)
46 /* USB3 PHY soft reset */
47 #define SW_USB3PHY_RESET BIT(2)
48 /* mux to select USB3 PHY reset control, 0:HW control, 1: software reset */
49 #define SW_USB3PHY_RESET_MUX BIT(3)
51 /* QPHY_V3_DP_COM_PHY_MODE_CTRL register bits */
52 #define USB3_MODE BIT(0) /* enables USB3 mode */
53 #define DP_MODE BIT(1) /* enables DP mode */
55 /* QPHY_PCS_AUTONOMOUS_MODE_CTRL register bits */
56 #define ARCVR_DTCT_EN BIT(0)
57 #define ALFPS_DTCT_EN BIT(1)
58 #define ARCVR_DTCT_EVENT_SEL BIT(4)
60 /* QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR register bits */
61 #define IRQ_CLEAR BIT(0)
63 /* QPHY_PCS_LFPS_RXTERM_IRQ_STATUS register bits */
64 #define RCVR_DETECT BIT(0)
66 /* QPHY_V3_PCS_MISC_CLAMP_ENABLE register bits */
67 #define CLAMP_EN BIT(0) /* enables i/o clamp_n */
69 #define PHY_INIT_COMPLETE_TIMEOUT 10000
70 #define POWER_DOWN_DELAY_US_MIN 10
71 #define POWER_DOWN_DELAY_US_MAX 11
73 #define MAX_PROP_NAME 32
75 struct qmp_phy_init_tbl {
79 * register part of layout ?
80 * if yes, then offset gives index in the reg-layout
85 #define QMP_PHY_INIT_CFG(o, v) \
91 #define QMP_PHY_INIT_CFG_L(o, v) \
98 /* set of registers with offsets different per-PHY */
99 enum qphy_reg_layout {
100 /* Common block control registers */
102 QPHY_COM_POWER_DOWN_CONTROL,
103 QPHY_COM_START_CONTROL,
104 QPHY_COM_PCS_READY_STATUS,
106 QPHY_PLL_LOCK_CHK_DLY_TIME,
110 QPHY_FLL_CNT_VAL_H_TOL,
114 QPHY_PCS_READY_STATUS,
115 QPHY_PCS_AUTONOMOUS_MODE_CTRL,
116 QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR,
117 QPHY_PCS_LFPS_RXTERM_IRQ_STATUS,
120 static const unsigned int pciephy_regs_layout[] = {
121 [QPHY_COM_SW_RESET] = 0x400,
122 [QPHY_COM_POWER_DOWN_CONTROL] = 0x404,
123 [QPHY_COM_START_CONTROL] = 0x408,
124 [QPHY_COM_PCS_READY_STATUS] = 0x448,
125 [QPHY_PLL_LOCK_CHK_DLY_TIME] = 0xa8,
126 [QPHY_FLL_CNTRL1] = 0xc4,
127 [QPHY_FLL_CNTRL2] = 0xc8,
128 [QPHY_FLL_CNT_VAL_L] = 0xcc,
129 [QPHY_FLL_CNT_VAL_H_TOL] = 0xd0,
130 [QPHY_FLL_MAN_CODE] = 0xd4,
131 [QPHY_SW_RESET] = 0x00,
132 [QPHY_START_CTRL] = 0x08,
133 [QPHY_PCS_READY_STATUS] = 0x174,
136 static const unsigned int usb3phy_regs_layout[] = {
137 [QPHY_FLL_CNTRL1] = 0xc0,
138 [QPHY_FLL_CNTRL2] = 0xc4,
139 [QPHY_FLL_CNT_VAL_L] = 0xc8,
140 [QPHY_FLL_CNT_VAL_H_TOL] = 0xcc,
141 [QPHY_FLL_MAN_CODE] = 0xd0,
142 [QPHY_SW_RESET] = 0x00,
143 [QPHY_START_CTRL] = 0x08,
144 [QPHY_PCS_READY_STATUS] = 0x17c,
145 [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = 0x0d4,
146 [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = 0x0d8,
147 [QPHY_PCS_LFPS_RXTERM_IRQ_STATUS] = 0x178,
150 static const unsigned int qmp_v3_usb3phy_regs_layout[] = {
151 [QPHY_SW_RESET] = 0x00,
152 [QPHY_START_CTRL] = 0x08,
153 [QPHY_PCS_READY_STATUS] = 0x174,
154 [QPHY_PCS_AUTONOMOUS_MODE_CTRL] = 0x0d8,
155 [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = 0x0dc,
156 [QPHY_PCS_LFPS_RXTERM_IRQ_STATUS] = 0x170,
159 static const struct qmp_phy_init_tbl msm8996_pcie_serdes_tbl[] = {
160 QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x1c),
161 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_ENABLE1, 0x10),
162 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x33),
163 QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x06),
164 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x42),
165 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x00),
166 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0xff),
167 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x1f),
168 QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x01),
169 QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x01),
170 QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x00),
171 QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0x0a),
172 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0x09),
173 QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
174 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x03),
175 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x55),
176 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x55),
177 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x00),
178 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0x1a),
179 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0x0a),
180 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x33),
181 QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x02),
182 QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_BUF_ENABLE, 0x1f),
183 QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0x04),
184 QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0x0b),
185 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
186 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
187 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
188 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
189 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_EN_CENTER, 0x01),
190 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER1, 0x31),
191 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER2, 0x01),
192 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER1, 0x02),
193 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER2, 0x00),
194 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE1, 0x2f),
195 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE2, 0x19),
196 QMP_PHY_INIT_CFG(QSERDES_COM_RESCODE_DIV_NUM, 0x15),
197 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TRIM, 0x0f),
198 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_IVCO, 0x0f),
199 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_EP_DIV, 0x19),
200 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_ENABLE1, 0x10),
201 QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x00),
202 QMP_PHY_INIT_CFG(QSERDES_COM_RESCODE_DIV_NUM, 0x40),
205 static const struct qmp_phy_init_tbl msm8996_pcie_tx_tbl[] = {
206 QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
207 QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x06),
210 static const struct qmp_phy_init_tbl msm8996_pcie_rx_tbl[] = {
211 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_ENABLES, 0x1c),
212 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x01),
213 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3, 0x00),
214 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4, 0xdb),
215 QMP_PHY_INIT_CFG(QSERDES_RX_RX_BAND, 0x18),
216 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_GAIN, 0x04),
217 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_GAIN_HALF, 0x04),
218 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
219 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x14),
220 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_LVL, 0x19),
223 static const struct qmp_phy_init_tbl msm8996_pcie_pcs_tbl[] = {
224 QMP_PHY_INIT_CFG(QPHY_RX_IDLE_DTCT_CNTRL, 0x4c),
225 QMP_PHY_INIT_CFG(QPHY_PWRUP_RESET_DLY_TIME_AUXCLK, 0x00),
226 QMP_PHY_INIT_CFG(QPHY_LP_WAKEUP_DLY_TIME_AUXCLK, 0x01),
228 QMP_PHY_INIT_CFG_L(QPHY_PLL_LOCK_CHK_DLY_TIME, 0x05),
230 QMP_PHY_INIT_CFG(QPHY_ENDPOINT_REFCLK_DRIVE, 0x05),
231 QMP_PHY_INIT_CFG(QPHY_POWER_DOWN_CONTROL, 0x02),
232 QMP_PHY_INIT_CFG(QPHY_POWER_STATE_CONFIG4, 0x00),
233 QMP_PHY_INIT_CFG(QPHY_POWER_STATE_CONFIG1, 0xa3),
234 QMP_PHY_INIT_CFG(QPHY_TXDEEMPH_M3P5DB_V0, 0x0e),
237 static const struct qmp_phy_init_tbl msm8996_usb3_serdes_tbl[] = {
238 QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0x14),
239 QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
240 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x30),
241 QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x06),
242 QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x01),
243 QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x00),
244 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TRIM, 0x0f),
245 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_IVCO, 0x0f),
246 QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x04),
247 /* PLL and Loop filter settings */
248 QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
249 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x55),
250 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x55),
251 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x03),
252 QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0x0b),
253 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
254 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
255 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
256 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_CTRL, 0x00),
257 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0x15),
258 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0x34),
259 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x00),
260 QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x00),
261 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_CFG, 0x00),
262 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x00),
263 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0x0a),
265 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_EN_CENTER, 0x01),
266 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER1, 0x31),
267 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER2, 0x01),
268 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER1, 0x00),
269 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER2, 0x00),
270 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE1, 0xde),
271 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE2, 0x07),
274 static const struct qmp_phy_init_tbl msm8996_usb3_tx_tbl[] = {
275 QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
276 QMP_PHY_INIT_CFG(QSERDES_TX_RCV_DETECT_LVL_2, 0x12),
277 QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x06),
280 static const struct qmp_phy_init_tbl msm8996_usb3_rx_tbl[] = {
281 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
282 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_GAIN, 0x04),
283 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x02),
284 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4c),
285 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4, 0xbb),
286 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
287 QMP_PHY_INIT_CFG(QSERDES_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x80),
288 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_CNTRL, 0x03),
289 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_LVL, 0x18),
290 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x16),
293 static const struct qmp_phy_init_tbl msm8996_usb3_pcs_tbl[] = {
295 QMP_PHY_INIT_CFG_L(QPHY_FLL_CNTRL2, 0x03),
296 QMP_PHY_INIT_CFG_L(QPHY_FLL_CNTRL1, 0x02),
297 QMP_PHY_INIT_CFG_L(QPHY_FLL_CNT_VAL_L, 0x09),
298 QMP_PHY_INIT_CFG_L(QPHY_FLL_CNT_VAL_H_TOL, 0x42),
299 QMP_PHY_INIT_CFG_L(QPHY_FLL_MAN_CODE, 0x85),
301 /* Lock Det settings */
302 QMP_PHY_INIT_CFG(QPHY_LOCK_DETECT_CONFIG1, 0xd1),
303 QMP_PHY_INIT_CFG(QPHY_LOCK_DETECT_CONFIG2, 0x1f),
304 QMP_PHY_INIT_CFG(QPHY_LOCK_DETECT_CONFIG3, 0x47),
305 QMP_PHY_INIT_CFG(QPHY_POWER_STATE_CONFIG2, 0x08),
308 static const struct qmp_phy_init_tbl ipq8074_pcie_serdes_tbl[] = {
309 QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x18),
310 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_ENABLE1, 0x10),
311 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TRIM, 0xf),
312 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x1),
313 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x0),
314 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0xff),
315 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x1f),
316 QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x6),
317 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_IVCO, 0xf),
318 QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x0),
319 QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x1),
320 QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x20),
321 QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0xa),
322 QMP_PHY_INIT_CFG(QSERDES_COM_RESETSM_CNTRL, 0x20),
323 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0xa),
324 QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0xa),
325 QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
326 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x3),
327 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x55),
328 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x55),
329 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x0),
330 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0xD),
331 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0xD04),
332 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x33),
333 QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x2),
334 QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_BUF_ENABLE, 0x1f),
335 QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0xb),
336 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
337 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
338 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x0),
339 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
340 QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CTRL_BY_PSM, 0x1),
341 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_EN_CENTER, 0x1),
342 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER1, 0x31),
343 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER2, 0x1),
344 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER1, 0x2),
345 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER2, 0x0),
346 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE1, 0x2f),
347 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE2, 0x19),
348 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_EP_DIV, 0x19),
351 static const struct qmp_phy_init_tbl ipq8074_pcie_tx_tbl[] = {
352 QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
353 QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x6),
354 QMP_PHY_INIT_CFG(QSERDES_TX_RES_CODE_LANE_OFFSET, 0x2),
355 QMP_PHY_INIT_CFG(QSERDES_TX_RCV_DETECT_LVL_2, 0x12),
356 QMP_PHY_INIT_CFG(QSERDES_TX_EMP_POST1_LVL, 0x36),
357 QMP_PHY_INIT_CFG(QSERDES_TX_SLEW_CNTL, 0x0a),
360 static const struct qmp_phy_init_tbl ipq8074_pcie_rx_tbl[] = {
361 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_ENABLES, 0x1c),
362 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x14),
363 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x1),
364 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3, 0x0),
365 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4, 0xdb),
366 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
367 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_GAIN, 0x4),
370 static const struct qmp_phy_init_tbl ipq8074_pcie_pcs_tbl[] = {
371 QMP_PHY_INIT_CFG(QPHY_ENDPOINT_REFCLK_DRIVE, 0x4),
372 QMP_PHY_INIT_CFG(QPHY_OSC_DTCT_ACTIONS, 0x0),
373 QMP_PHY_INIT_CFG(QPHY_PWRUP_RESET_DLY_TIME_AUXCLK, 0x40),
374 QMP_PHY_INIT_CFG(QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_MSB, 0x0),
375 QMP_PHY_INIT_CFG(QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_LSB, 0x40),
376 QMP_PHY_INIT_CFG(QPHY_PLL_LOCK_CHK_DLY_TIME_AUXCLK_LSB, 0x0),
377 QMP_PHY_INIT_CFG(QPHY_LP_WAKEUP_DLY_TIME_AUXCLK, 0x40),
378 QMP_PHY_INIT_CFG_L(QPHY_PLL_LOCK_CHK_DLY_TIME, 0x73),
379 QMP_PHY_INIT_CFG(QPHY_RX_SIGDET_LVL, 0x99),
380 QMP_PHY_INIT_CFG(QPHY_TXDEEMPH_M6DB_V0, 0x15),
381 QMP_PHY_INIT_CFG(QPHY_TXDEEMPH_M3P5DB_V0, 0xe),
382 QMP_PHY_INIT_CFG_L(QPHY_SW_RESET, 0x0),
383 QMP_PHY_INIT_CFG_L(QPHY_START_CTRL, 0x3),
386 static const struct qmp_phy_init_tbl qmp_v3_usb3_serdes_tbl[] = {
387 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
388 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0x14),
389 QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
390 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
391 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
392 QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL2, 0x08),
393 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x16),
394 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x01),
395 QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x80),
396 QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82),
397 QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START1_MODE0, 0xab),
398 QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0xea),
399 QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x02),
400 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
401 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
402 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
403 QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
404 QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
405 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01),
406 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xc9),
407 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORECLK_DIV_MODE0, 0x0a),
408 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP3_MODE0, 0x00),
409 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x34),
410 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x15),
411 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x04),
412 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00),
413 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_CFG, 0x00),
414 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x00),
415 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_BUF_ENABLE, 0x0a),
416 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_EN_CENTER, 0x01),
417 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER1, 0x31),
418 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER2, 0x01),
419 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER1, 0x00),
420 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER2, 0x00),
421 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE1, 0x85),
422 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE2, 0x07),
425 static const struct qmp_phy_init_tbl qmp_v3_usb3_tx_tbl[] = {
426 QMP_PHY_INIT_CFG(QSERDES_V3_TX_HIGHZ_DRVR_EN, 0x10),
427 QMP_PHY_INIT_CFG(QSERDES_V3_TX_RCV_DETECT_LVL_2, 0x12),
428 QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0x16),
429 QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x09),
430 QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x06),
433 static const struct qmp_phy_init_tbl qmp_v3_usb3_rx_tbl[] = {
434 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
435 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0f),
436 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4e),
437 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x18),
438 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
439 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x80),
440 QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x03),
441 QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x16),
442 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x75),
445 static const struct qmp_phy_init_tbl qmp_v3_usb3_pcs_tbl[] = {
447 QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL2, 0x83),
448 QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_L, 0x09),
449 QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_H_TOL, 0xa2),
450 QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_MAN_CODE, 0x40),
451 QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL1, 0x02),
453 /* Lock Det settings */
454 QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG1, 0xd1),
455 QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG2, 0x1f),
456 QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG3, 0x47),
457 QMP_PHY_INIT_CFG(QPHY_V3_PCS_POWER_STATE_CONFIG2, 0x1b),
459 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RX_SIGDET_LVL, 0xba),
460 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V0, 0x9f),
461 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V1, 0x9f),
462 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V2, 0xb7),
463 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V3, 0x4e),
464 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V4, 0x65),
465 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_LS, 0x6b),
466 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V0, 0x15),
467 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V0, 0x0d),
468 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V1, 0x15),
469 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V1, 0x0d),
470 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V2, 0x15),
471 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V2, 0x0d),
472 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V3, 0x15),
473 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V3, 0x1d),
474 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V4, 0x15),
475 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V4, 0x0d),
476 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_LS, 0x15),
477 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_LS, 0x0d),
479 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RATE_SLEW_CNTRL, 0x02),
480 QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
481 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TSYNC_RSYNC_TIME, 0x44),
482 QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
483 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_L, 0xe7),
484 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_H, 0x03),
485 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_L, 0x40),
486 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_H, 0x00),
487 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_WAIT_TIME, 0x75),
488 QMP_PHY_INIT_CFG(QPHY_V3_PCS_LFPS_TX_ECSTART_EQTLOCK, 0x86),
489 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_RUN_TIME, 0x13),
492 static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_serdes_tbl[] = {
493 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
494 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0x14),
495 QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x04),
496 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
497 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
498 QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL2, 0x08),
499 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x06),
500 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x01),
501 QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x80),
502 QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82),
503 QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START1_MODE0, 0xab),
504 QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START2_MODE0, 0xea),
505 QMP_PHY_INIT_CFG(QSERDES_V3_COM_DIV_FRAC_START3_MODE0, 0x02),
506 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
507 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
508 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
509 QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
510 QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
511 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01),
512 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xc9),
513 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORECLK_DIV_MODE0, 0x0a),
514 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP3_MODE0, 0x00),
515 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x34),
516 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0x15),
517 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x04),
518 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00),
519 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_CFG, 0x00),
520 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x00),
521 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_BUF_ENABLE, 0x0a),
522 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_EN_CENTER, 0x01),
523 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER1, 0x31),
524 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_PER2, 0x01),
525 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER1, 0x00),
526 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_ADJ_PER2, 0x00),
527 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE1, 0x85),
528 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SSC_STEP_SIZE2, 0x07),
531 static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_tx_tbl[] = {
532 QMP_PHY_INIT_CFG(QSERDES_V3_TX_HIGHZ_DRVR_EN, 0x10),
533 QMP_PHY_INIT_CFG(QSERDES_V3_TX_RCV_DETECT_LVL_2, 0x12),
534 QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0xc6),
535 QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x06),
536 QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x06),
539 static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_rx_tbl[] = {
540 QMP_PHY_INIT_CFG(QSERDES_V3_RX_VGA_CAL_CNTRL2, 0x0c),
541 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_MODE_00, 0x50),
542 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
543 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0e),
544 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4e),
545 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x18),
546 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x77),
547 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x80),
548 QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x03),
549 QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x1c),
550 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x75),
553 static const struct qmp_phy_init_tbl qmp_v3_usb3_uniphy_pcs_tbl[] = {
555 QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL2, 0x83),
556 QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_L, 0x09),
557 QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNT_VAL_H_TOL, 0xa2),
558 QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_MAN_CODE, 0x40),
559 QMP_PHY_INIT_CFG(QPHY_V3_PCS_FLL_CNTRL1, 0x02),
561 /* Lock Det settings */
562 QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG1, 0xd1),
563 QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG2, 0x1f),
564 QMP_PHY_INIT_CFG(QPHY_V3_PCS_LOCK_DETECT_CONFIG3, 0x47),
565 QMP_PHY_INIT_CFG(QPHY_V3_PCS_POWER_STATE_CONFIG2, 0x1b),
567 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RX_SIGDET_LVL, 0xba),
568 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V0, 0x9f),
569 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V1, 0x9f),
570 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V2, 0xb5),
571 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V3, 0x4c),
572 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_V4, 0x64),
573 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXMGN_LS, 0x6a),
574 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V0, 0x15),
575 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V0, 0x0d),
576 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V1, 0x15),
577 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V1, 0x0d),
578 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V2, 0x15),
579 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V2, 0x0d),
580 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V3, 0x15),
581 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V3, 0x1d),
582 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_V4, 0x15),
583 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_V4, 0x0d),
584 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M6DB_LS, 0x15),
585 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TXDEEMPH_M3P5DB_LS, 0x0d),
587 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RATE_SLEW_CNTRL, 0x02),
588 QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
589 QMP_PHY_INIT_CFG(QPHY_V3_PCS_TSYNC_RSYNC_TIME, 0x44),
590 QMP_PHY_INIT_CFG(QPHY_V3_PCS_PWRUP_RESET_DLY_TIME_AUXCLK, 0x04),
591 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_L, 0xe7),
592 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_P1U2_H, 0x03),
593 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_L, 0x40),
594 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RCVR_DTCT_DLY_U3_H, 0x00),
595 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_WAIT_TIME, 0x75),
596 QMP_PHY_INIT_CFG(QPHY_V3_PCS_LFPS_TX_ECSTART_EQTLOCK, 0x86),
597 QMP_PHY_INIT_CFG(QPHY_V3_PCS_RXEQTRAINING_RUN_TIME, 0x13),
599 QMP_PHY_INIT_CFG(QPHY_V3_PCS_REFGEN_REQ_CONFIG1, 0x21),
600 QMP_PHY_INIT_CFG(QPHY_V3_PCS_REFGEN_REQ_CONFIG2, 0x60),
604 /* struct qmp_phy_cfg - per-PHY initialization config */
606 /* phy-type - PCIE/UFS/USB */
608 /* number of lanes provided by phy */
611 /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
612 const struct qmp_phy_init_tbl *serdes_tbl;
614 const struct qmp_phy_init_tbl *tx_tbl;
616 const struct qmp_phy_init_tbl *rx_tbl;
618 const struct qmp_phy_init_tbl *pcs_tbl;
621 /* clock ids to be requested */
622 const char * const *clk_list;
624 /* resets to be requested */
625 const char * const *reset_list;
627 /* regulators to be requested */
628 const char * const *vreg_list;
631 /* array of registers with different offsets */
632 const unsigned int *regs;
634 unsigned int start_ctrl;
635 unsigned int pwrdn_ctrl;
636 unsigned int mask_pcs_ready;
637 unsigned int mask_com_pcs_ready;
639 /* true, if PHY has a separate PHY_COM control block */
640 bool has_phy_com_ctrl;
641 /* true, if PHY has a reset for individual lanes */
643 /* true, if PHY needs delay after POWER_DOWN */
644 bool has_pwrdn_delay;
645 /* power_down delay in usec */
649 /* true, if PHY has a separate DP_COM control block */
650 bool has_phy_dp_com_ctrl;
651 /* Register offset of secondary tx/rx lanes for USB DP combo PHY */
652 unsigned int tx_b_lane_offset;
653 unsigned int rx_b_lane_offset;
657 * struct qmp_phy - per-lane phy descriptor
660 * @tx: iomapped memory space for lane's tx
661 * @rx: iomapped memory space for lane's rx
662 * @pcs: iomapped memory space for lane's pcs
663 * @pcs_misc: iomapped memory space for lane's pcs_misc
664 * @pipe_clk: pipe lock
666 * @qmp: QMP phy to which this lane belongs
667 * @lane_rst: lane's reset controller
674 void __iomem *pcs_misc;
675 struct clk *pipe_clk;
677 struct qcom_qmp *qmp;
678 struct reset_control *lane_rst;
682 * struct qcom_qmp - structure holding QMP phy block attributes
685 * @serdes: iomapped memory space for phy's serdes
686 * @dp_com: iomapped memory space for phy's dp_com control block
688 * @clks: array of clocks required by phy
689 * @resets: array of resets required by phy
690 * @vregs: regulator supplies bulk data
692 * @cfg: phy specific configuration
693 * @phys: array of per-lane phy descriptors
694 * @phy_mutex: mutex lock for PHY common block initialization
695 * @init_count: phy common block initialization count
696 * @phy_initialized: indicate if PHY has been initialized
697 * @mode: current PHY mode
701 void __iomem *serdes;
702 void __iomem *dp_com;
704 struct clk_bulk_data *clks;
705 struct reset_control **resets;
706 struct regulator_bulk_data *vregs;
708 const struct qmp_phy_cfg *cfg;
709 struct qmp_phy **phys;
711 struct mutex phy_mutex;
713 bool phy_initialized;
717 static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
721 reg = readl(base + offset);
723 writel(reg, base + offset);
725 /* ensure that above write is through */
726 readl(base + offset);
729 static inline void qphy_clrbits(void __iomem *base, u32 offset, u32 val)
733 reg = readl(base + offset);
735 writel(reg, base + offset);
737 /* ensure that above write is through */
738 readl(base + offset);
741 /* list of clocks required by phy */
742 static const char * const msm8996_phy_clk_l[] = {
743 "aux", "cfg_ahb", "ref",
746 static const char * const qmp_v3_phy_clk_l[] = {
747 "aux", "cfg_ahb", "ref", "com_aux",
751 static const char * const msm8996_pciephy_reset_l[] = {
752 "phy", "common", "cfg",
755 static const char * const msm8996_usb3phy_reset_l[] = {
759 /* list of regulators */
760 static const char * const msm8996_phy_vreg_l[] = {
761 "vdda-phy", "vdda-pll",
764 static const struct qmp_phy_cfg msm8996_pciephy_cfg = {
765 .type = PHY_TYPE_PCIE,
768 .serdes_tbl = msm8996_pcie_serdes_tbl,
769 .serdes_tbl_num = ARRAY_SIZE(msm8996_pcie_serdes_tbl),
770 .tx_tbl = msm8996_pcie_tx_tbl,
771 .tx_tbl_num = ARRAY_SIZE(msm8996_pcie_tx_tbl),
772 .rx_tbl = msm8996_pcie_rx_tbl,
773 .rx_tbl_num = ARRAY_SIZE(msm8996_pcie_rx_tbl),
774 .pcs_tbl = msm8996_pcie_pcs_tbl,
775 .pcs_tbl_num = ARRAY_SIZE(msm8996_pcie_pcs_tbl),
776 .clk_list = msm8996_phy_clk_l,
777 .num_clks = ARRAY_SIZE(msm8996_phy_clk_l),
778 .reset_list = msm8996_pciephy_reset_l,
779 .num_resets = ARRAY_SIZE(msm8996_pciephy_reset_l),
780 .vreg_list = msm8996_phy_vreg_l,
781 .num_vregs = ARRAY_SIZE(msm8996_phy_vreg_l),
782 .regs = pciephy_regs_layout,
784 .start_ctrl = PCS_START | PLL_READY_GATE_EN,
785 .pwrdn_ctrl = SW_PWRDN | REFCLK_DRV_DSBL,
786 .mask_com_pcs_ready = PCS_READY,
788 .has_phy_com_ctrl = true,
789 .has_lane_rst = true,
790 .has_pwrdn_delay = true,
791 .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
792 .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
795 static const struct qmp_phy_cfg msm8996_usb3phy_cfg = {
796 .type = PHY_TYPE_USB3,
799 .serdes_tbl = msm8996_usb3_serdes_tbl,
800 .serdes_tbl_num = ARRAY_SIZE(msm8996_usb3_serdes_tbl),
801 .tx_tbl = msm8996_usb3_tx_tbl,
802 .tx_tbl_num = ARRAY_SIZE(msm8996_usb3_tx_tbl),
803 .rx_tbl = msm8996_usb3_rx_tbl,
804 .rx_tbl_num = ARRAY_SIZE(msm8996_usb3_rx_tbl),
805 .pcs_tbl = msm8996_usb3_pcs_tbl,
806 .pcs_tbl_num = ARRAY_SIZE(msm8996_usb3_pcs_tbl),
807 .clk_list = msm8996_phy_clk_l,
808 .num_clks = ARRAY_SIZE(msm8996_phy_clk_l),
809 .reset_list = msm8996_usb3phy_reset_l,
810 .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
811 .vreg_list = msm8996_phy_vreg_l,
812 .num_vregs = ARRAY_SIZE(msm8996_phy_vreg_l),
813 .regs = usb3phy_regs_layout,
815 .start_ctrl = SERDES_START | PCS_START,
816 .pwrdn_ctrl = SW_PWRDN,
817 .mask_pcs_ready = PHYSTATUS,
820 static const char * const ipq8074_pciephy_clk_l[] = {
824 static const char * const ipq8074_pciephy_reset_l[] = {
828 static const struct qmp_phy_cfg ipq8074_pciephy_cfg = {
829 .type = PHY_TYPE_PCIE,
832 .serdes_tbl = ipq8074_pcie_serdes_tbl,
833 .serdes_tbl_num = ARRAY_SIZE(ipq8074_pcie_serdes_tbl),
834 .tx_tbl = ipq8074_pcie_tx_tbl,
835 .tx_tbl_num = ARRAY_SIZE(ipq8074_pcie_tx_tbl),
836 .rx_tbl = ipq8074_pcie_rx_tbl,
837 .rx_tbl_num = ARRAY_SIZE(ipq8074_pcie_rx_tbl),
838 .pcs_tbl = ipq8074_pcie_pcs_tbl,
839 .pcs_tbl_num = ARRAY_SIZE(ipq8074_pcie_pcs_tbl),
840 .clk_list = ipq8074_pciephy_clk_l,
841 .num_clks = ARRAY_SIZE(ipq8074_pciephy_clk_l),
842 .reset_list = ipq8074_pciephy_reset_l,
843 .num_resets = ARRAY_SIZE(ipq8074_pciephy_reset_l),
846 .regs = pciephy_regs_layout,
848 .start_ctrl = SERDES_START | PCS_START,
849 .pwrdn_ctrl = SW_PWRDN | REFCLK_DRV_DSBL,
850 .mask_pcs_ready = PHYSTATUS,
852 .has_phy_com_ctrl = false,
853 .has_lane_rst = false,
854 .has_pwrdn_delay = true,
855 .pwrdn_delay_min = 995, /* us */
856 .pwrdn_delay_max = 1005, /* us */
859 static const struct qmp_phy_cfg qmp_v3_usb3phy_cfg = {
860 .type = PHY_TYPE_USB3,
863 .serdes_tbl = qmp_v3_usb3_serdes_tbl,
864 .serdes_tbl_num = ARRAY_SIZE(qmp_v3_usb3_serdes_tbl),
865 .tx_tbl = qmp_v3_usb3_tx_tbl,
866 .tx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_tx_tbl),
867 .rx_tbl = qmp_v3_usb3_rx_tbl,
868 .rx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_rx_tbl),
869 .pcs_tbl = qmp_v3_usb3_pcs_tbl,
870 .pcs_tbl_num = ARRAY_SIZE(qmp_v3_usb3_pcs_tbl),
871 .clk_list = qmp_v3_phy_clk_l,
872 .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
873 .reset_list = msm8996_usb3phy_reset_l,
874 .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
875 .vreg_list = msm8996_phy_vreg_l,
876 .num_vregs = ARRAY_SIZE(msm8996_phy_vreg_l),
877 .regs = qmp_v3_usb3phy_regs_layout,
879 .start_ctrl = SERDES_START | PCS_START,
880 .pwrdn_ctrl = SW_PWRDN,
881 .mask_pcs_ready = PHYSTATUS,
883 .has_pwrdn_delay = true,
884 .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
885 .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
887 .has_phy_dp_com_ctrl = true,
888 .tx_b_lane_offset = 0x400,
889 .rx_b_lane_offset = 0x400,
892 static const struct qmp_phy_cfg qmp_v3_usb3_uniphy_cfg = {
893 .type = PHY_TYPE_USB3,
896 .serdes_tbl = qmp_v3_usb3_uniphy_serdes_tbl,
897 .serdes_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_serdes_tbl),
898 .tx_tbl = qmp_v3_usb3_uniphy_tx_tbl,
899 .tx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_tx_tbl),
900 .rx_tbl = qmp_v3_usb3_uniphy_rx_tbl,
901 .rx_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_rx_tbl),
902 .pcs_tbl = qmp_v3_usb3_uniphy_pcs_tbl,
903 .pcs_tbl_num = ARRAY_SIZE(qmp_v3_usb3_uniphy_pcs_tbl),
904 .clk_list = qmp_v3_phy_clk_l,
905 .num_clks = ARRAY_SIZE(qmp_v3_phy_clk_l),
906 .reset_list = msm8996_usb3phy_reset_l,
907 .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l),
908 .vreg_list = msm8996_phy_vreg_l,
909 .num_vregs = ARRAY_SIZE(msm8996_phy_vreg_l),
910 .regs = qmp_v3_usb3phy_regs_layout,
912 .start_ctrl = SERDES_START | PCS_START,
913 .pwrdn_ctrl = SW_PWRDN,
914 .mask_pcs_ready = PHYSTATUS,
916 .has_pwrdn_delay = true,
917 .pwrdn_delay_min = POWER_DOWN_DELAY_US_MIN,
918 .pwrdn_delay_max = POWER_DOWN_DELAY_US_MAX,
921 static void qcom_qmp_phy_configure(void __iomem *base,
922 const unsigned int *regs,
923 const struct qmp_phy_init_tbl tbl[],
927 const struct qmp_phy_init_tbl *t = tbl;
932 for (i = 0; i < num; i++, t++) {
934 writel(t->val, base + regs[t->offset]);
936 writel(t->val, base + t->offset);
940 static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
942 const struct qmp_phy_cfg *cfg = qmp->cfg;
943 void __iomem *serdes = qmp->serdes;
944 void __iomem *dp_com = qmp->dp_com;
947 mutex_lock(&qmp->phy_mutex);
948 if (qmp->init_count++) {
949 mutex_unlock(&qmp->phy_mutex);
953 /* turn on regulator supplies */
954 ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
956 dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret);
960 for (i = 0; i < cfg->num_resets; i++) {
961 ret = reset_control_assert(qmp->resets[i]);
963 dev_err(qmp->dev, "%s reset assert failed\n",
969 for (i = cfg->num_resets - 1; i >= 0; i--) {
970 ret = reset_control_deassert(qmp->resets[i]);
972 dev_err(qmp->dev, "%s reset deassert failed\n",
973 qmp->cfg->reset_list[i]);
978 ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
980 dev_err(qmp->dev, "failed to enable clks, err=%d\n", ret);
984 if (cfg->has_phy_com_ctrl)
985 qphy_setbits(serdes, cfg->regs[QPHY_COM_POWER_DOWN_CONTROL],
988 if (cfg->has_phy_dp_com_ctrl) {
989 qphy_setbits(dp_com, QPHY_V3_DP_COM_POWER_DOWN_CTRL,
991 /* override hardware control for reset of qmp phy */
992 qphy_setbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
993 SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
994 SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
996 qphy_setbits(dp_com, QPHY_V3_DP_COM_PHY_MODE_CTRL,
997 USB3_MODE | DP_MODE);
999 /* bring both QMP USB and QMP DP PHYs PCS block out of reset */
1000 qphy_clrbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
1001 SW_DPPHY_RESET_MUX | SW_DPPHY_RESET |
1002 SW_USB3PHY_RESET_MUX | SW_USB3PHY_RESET);
1005 /* Serdes configuration */
1006 qcom_qmp_phy_configure(serdes, cfg->regs, cfg->serdes_tbl,
1007 cfg->serdes_tbl_num);
1009 if (cfg->has_phy_com_ctrl) {
1010 void __iomem *status;
1011 unsigned int mask, val;
1013 qphy_clrbits(serdes, cfg->regs[QPHY_COM_SW_RESET], SW_RESET);
1014 qphy_setbits(serdes, cfg->regs[QPHY_COM_START_CONTROL],
1015 SERDES_START | PCS_START);
1017 status = serdes + cfg->regs[QPHY_COM_PCS_READY_STATUS];
1018 mask = cfg->mask_com_pcs_ready;
1020 ret = readl_poll_timeout(status, val, (val & mask), 10,
1021 PHY_INIT_COMPLETE_TIMEOUT);
1024 "phy common block init timed-out\n");
1029 mutex_unlock(&qmp->phy_mutex);
1034 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
1036 while (++i < cfg->num_resets)
1037 reset_control_assert(qmp->resets[i]);
1039 regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
1041 mutex_unlock(&qmp->phy_mutex);
1046 static int qcom_qmp_phy_com_exit(struct qcom_qmp *qmp)
1048 const struct qmp_phy_cfg *cfg = qmp->cfg;
1049 void __iomem *serdes = qmp->serdes;
1050 int i = cfg->num_resets;
1052 mutex_lock(&qmp->phy_mutex);
1053 if (--qmp->init_count) {
1054 mutex_unlock(&qmp->phy_mutex);
1058 if (cfg->has_phy_com_ctrl) {
1059 qphy_setbits(serdes, cfg->regs[QPHY_COM_START_CONTROL],
1060 SERDES_START | PCS_START);
1061 qphy_clrbits(serdes, cfg->regs[QPHY_COM_SW_RESET],
1063 qphy_setbits(serdes, cfg->regs[QPHY_COM_POWER_DOWN_CONTROL],
1068 reset_control_assert(qmp->resets[i]);
1070 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
1072 regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
1074 mutex_unlock(&qmp->phy_mutex);
1079 /* PHY Initialization */
1080 static int qcom_qmp_phy_init(struct phy *phy)
1082 struct qmp_phy *qphy = phy_get_drvdata(phy);
1083 struct qcom_qmp *qmp = qphy->qmp;
1084 const struct qmp_phy_cfg *cfg = qmp->cfg;
1085 void __iomem *tx = qphy->tx;
1086 void __iomem *rx = qphy->rx;
1087 void __iomem *pcs = qphy->pcs;
1088 void __iomem *dp_com = qmp->dp_com;
1089 void __iomem *status;
1090 unsigned int mask, val;
1093 dev_vdbg(qmp->dev, "Initializing QMP phy\n");
1095 ret = qcom_qmp_phy_com_init(qmp);
1099 if (cfg->has_lane_rst) {
1100 ret = reset_control_deassert(qphy->lane_rst);
1102 dev_err(qmp->dev, "lane%d reset deassert failed\n",
1108 ret = clk_prepare_enable(qphy->pipe_clk);
1110 dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
1111 goto err_clk_enable;
1114 /* Tx, Rx, and PCS configurations */
1115 qcom_qmp_phy_configure(tx, cfg->regs, cfg->tx_tbl, cfg->tx_tbl_num);
1116 /* Configuration for other LANE for USB-DP combo PHY */
1117 if (cfg->has_phy_dp_com_ctrl)
1118 qcom_qmp_phy_configure(tx + cfg->tx_b_lane_offset, cfg->regs,
1119 cfg->tx_tbl, cfg->tx_tbl_num);
1121 qcom_qmp_phy_configure(rx, cfg->regs, cfg->rx_tbl, cfg->rx_tbl_num);
1122 if (cfg->has_phy_dp_com_ctrl)
1123 qcom_qmp_phy_configure(rx + cfg->rx_b_lane_offset, cfg->regs,
1124 cfg->rx_tbl, cfg->rx_tbl_num);
1126 qcom_qmp_phy_configure(pcs, cfg->regs, cfg->pcs_tbl, cfg->pcs_tbl_num);
1129 * Pull out PHY from POWER DOWN state.
1130 * This is active low enable signal to power-down PHY.
1132 qphy_setbits(pcs, QPHY_POWER_DOWN_CONTROL, cfg->pwrdn_ctrl);
1134 if (cfg->has_pwrdn_delay)
1135 usleep_range(cfg->pwrdn_delay_min, cfg->pwrdn_delay_max);
1137 /* Pull PHY out of reset state */
1138 qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
1139 if (cfg->has_phy_dp_com_ctrl)
1140 qphy_clrbits(dp_com, QPHY_V3_DP_COM_SW_RESET, SW_RESET);
1142 /* start SerDes and Phy-Coding-Sublayer */
1143 qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], cfg->start_ctrl);
1145 status = pcs + cfg->regs[QPHY_PCS_READY_STATUS];
1146 mask = cfg->mask_pcs_ready;
1148 ret = readl_poll_timeout(status, val, !(val & mask), 1,
1149 PHY_INIT_COMPLETE_TIMEOUT);
1151 dev_err(qmp->dev, "phy initialization timed-out\n");
1154 qmp->phy_initialized = true;
1159 clk_disable_unprepare(qphy->pipe_clk);
1161 if (cfg->has_lane_rst)
1162 reset_control_assert(qphy->lane_rst);
1164 qcom_qmp_phy_com_exit(qmp);
1169 static int qcom_qmp_phy_exit(struct phy *phy)
1171 struct qmp_phy *qphy = phy_get_drvdata(phy);
1172 struct qcom_qmp *qmp = qphy->qmp;
1173 const struct qmp_phy_cfg *cfg = qmp->cfg;
1175 clk_disable_unprepare(qphy->pipe_clk);
1178 qphy_setbits(qphy->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
1180 /* stop SerDes and Phy-Coding-Sublayer */
1181 qphy_clrbits(qphy->pcs, cfg->regs[QPHY_START_CTRL], cfg->start_ctrl);
1183 /* Put PHY into POWER DOWN state: active low */
1184 qphy_clrbits(qphy->pcs, QPHY_POWER_DOWN_CONTROL, cfg->pwrdn_ctrl);
1186 if (cfg->has_lane_rst)
1187 reset_control_assert(qphy->lane_rst);
1189 qcom_qmp_phy_com_exit(qmp);
1191 qmp->phy_initialized = false;
1196 static int qcom_qmp_phy_set_mode(struct phy *phy, enum phy_mode mode)
1198 struct qmp_phy *qphy = phy_get_drvdata(phy);
1199 struct qcom_qmp *qmp = qphy->qmp;
1206 static void qcom_qmp_phy_enable_autonomous_mode(struct qmp_phy *qphy)
1208 struct qcom_qmp *qmp = qphy->qmp;
1209 const struct qmp_phy_cfg *cfg = qmp->cfg;
1210 void __iomem *pcs = qphy->pcs;
1211 void __iomem *pcs_misc = qphy->pcs_misc;
1214 if (qmp->mode == PHY_MODE_USB_HOST_SS ||
1215 qmp->mode == PHY_MODE_USB_DEVICE_SS)
1216 intr_mask = ARCVR_DTCT_EN | ALFPS_DTCT_EN;
1218 intr_mask = ARCVR_DTCT_EN | ARCVR_DTCT_EVENT_SEL;
1220 /* Clear any pending interrupts status */
1221 qphy_setbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
1222 /* Writing 1 followed by 0 clears the interrupt */
1223 qphy_clrbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
1225 qphy_clrbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
1226 ARCVR_DTCT_EN | ALFPS_DTCT_EN | ARCVR_DTCT_EVENT_SEL);
1228 /* Enable required PHY autonomous mode interrupts */
1229 qphy_setbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL], intr_mask);
1231 /* Enable i/o clamp_n for autonomous mode */
1233 qphy_clrbits(pcs_misc, QPHY_V3_PCS_MISC_CLAMP_ENABLE, CLAMP_EN);
1236 static void qcom_qmp_phy_disable_autonomous_mode(struct qmp_phy *qphy)
1238 struct qcom_qmp *qmp = qphy->qmp;
1239 const struct qmp_phy_cfg *cfg = qmp->cfg;
1240 void __iomem *pcs = qphy->pcs;
1241 void __iomem *pcs_misc = qphy->pcs_misc;
1243 /* Disable i/o clamp_n on resume for normal mode */
1245 qphy_setbits(pcs_misc, QPHY_V3_PCS_MISC_CLAMP_ENABLE, CLAMP_EN);
1247 qphy_clrbits(pcs, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
1248 ARCVR_DTCT_EN | ARCVR_DTCT_EVENT_SEL | ALFPS_DTCT_EN);
1250 qphy_setbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
1251 /* Writing 1 followed by 0 clears the interrupt */
1252 qphy_clrbits(pcs, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
1255 static int __maybe_unused qcom_qmp_phy_runtime_suspend(struct device *dev)
1257 struct qcom_qmp *qmp = dev_get_drvdata(dev);
1258 struct qmp_phy *qphy = qmp->phys[0];
1259 const struct qmp_phy_cfg *cfg = qmp->cfg;
1261 dev_vdbg(dev, "Suspending QMP phy, mode:%d\n", qmp->mode);
1263 /* Supported only for USB3 PHY */
1264 if (cfg->type != PHY_TYPE_USB3)
1267 if (!qmp->phy_initialized) {
1268 dev_vdbg(dev, "PHY not initialized, bailing out\n");
1272 qcom_qmp_phy_enable_autonomous_mode(qphy);
1274 clk_disable_unprepare(qphy->pipe_clk);
1275 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
1280 static int __maybe_unused qcom_qmp_phy_runtime_resume(struct device *dev)
1282 struct qcom_qmp *qmp = dev_get_drvdata(dev);
1283 struct qmp_phy *qphy = qmp->phys[0];
1284 const struct qmp_phy_cfg *cfg = qmp->cfg;
1287 dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->mode);
1289 /* Supported only for USB3 PHY */
1290 if (cfg->type != PHY_TYPE_USB3)
1293 if (!qmp->phy_initialized) {
1294 dev_vdbg(dev, "PHY not initialized, bailing out\n");
1298 ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
1300 dev_err(qmp->dev, "failed to enable clks, err=%d\n", ret);
1304 ret = clk_prepare_enable(qphy->pipe_clk);
1306 dev_err(dev, "pipe_clk enable failed, err=%d\n", ret);
1307 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
1311 qcom_qmp_phy_disable_autonomous_mode(qphy);
1316 static int qcom_qmp_phy_vreg_init(struct device *dev)
1318 struct qcom_qmp *qmp = dev_get_drvdata(dev);
1319 int num = qmp->cfg->num_vregs;
1322 qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL);
1326 for (i = 0; i < num; i++)
1327 qmp->vregs[i].supply = qmp->cfg->vreg_list[i];
1329 return devm_regulator_bulk_get(dev, num, qmp->vregs);
1332 static int qcom_qmp_phy_reset_init(struct device *dev)
1334 struct qcom_qmp *qmp = dev_get_drvdata(dev);
1337 qmp->resets = devm_kcalloc(dev, qmp->cfg->num_resets,
1338 sizeof(*qmp->resets), GFP_KERNEL);
1342 for (i = 0; i < qmp->cfg->num_resets; i++) {
1343 struct reset_control *rst;
1344 const char *name = qmp->cfg->reset_list[i];
1346 rst = devm_reset_control_get(dev, name);
1348 dev_err(dev, "failed to get %s reset\n", name);
1349 return PTR_ERR(rst);
1351 qmp->resets[i] = rst;
1357 static int qcom_qmp_phy_clk_init(struct device *dev)
1359 struct qcom_qmp *qmp = dev_get_drvdata(dev);
1360 int num = qmp->cfg->num_clks;
1363 qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL);
1367 for (i = 0; i < num; i++)
1368 qmp->clks[i].id = qmp->cfg->clk_list[i];
1370 return devm_clk_bulk_get(dev, num, qmp->clks);
1374 * Register a fixed rate pipe clock.
1376 * The <s>_pipe_clksrc generated by PHY goes to the GCC that gate
1377 * controls it. The <s>_pipe_clk coming out of the GCC is requested
1378 * by the PHY driver for its operations.
1379 * We register the <s>_pipe_clksrc here. The gcc driver takes care
1380 * of assigning this <s>_pipe_clksrc as parent to <s>_pipe_clk.
1381 * Below picture shows this relationship.
1384 * | PHY block |<<---------------------------------------+
1386 * | +-------+ | +-----+ |
1387 * I/P---^-->| PLL |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
1388 * clk | +-------+ | +-----+
1391 static int phy_pipe_clk_register(struct qcom_qmp *qmp, struct device_node *np)
1393 struct clk_fixed_rate *fixed;
1394 struct clk_init_data init = { };
1397 if ((qmp->cfg->type != PHY_TYPE_USB3) &&
1398 (qmp->cfg->type != PHY_TYPE_PCIE)) {
1399 /* not all phys register pipe clocks, so return success */
1403 ret = of_property_read_string(np, "clock-output-names", &init.name);
1405 dev_err(qmp->dev, "%s: No clock-output-names\n", np->name);
1409 fixed = devm_kzalloc(qmp->dev, sizeof(*fixed), GFP_KERNEL);
1413 init.ops = &clk_fixed_rate_ops;
1415 /* controllers using QMP phys use 125MHz pipe clock interface */
1416 fixed->fixed_rate = 125000000;
1417 fixed->hw.init = &init;
1419 return devm_clk_hw_register(qmp->dev, &fixed->hw);
1422 static const struct phy_ops qcom_qmp_phy_gen_ops = {
1423 .init = qcom_qmp_phy_init,
1424 .exit = qcom_qmp_phy_exit,
1425 .set_mode = qcom_qmp_phy_set_mode,
1426 .owner = THIS_MODULE,
1429 static void qcom_qmp_reset_control_put(void *data)
1431 reset_control_put(data);
1435 int qcom_qmp_phy_create(struct device *dev, struct device_node *np, int id)
1437 struct qcom_qmp *qmp = dev_get_drvdata(dev);
1438 struct phy *generic_phy;
1439 struct qmp_phy *qphy;
1440 char prop_name[MAX_PROP_NAME];
1443 qphy = devm_kzalloc(dev, sizeof(*qphy), GFP_KERNEL);
1448 * Get memory resources for each phy lane:
1449 * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2; and
1450 * pcs_misc (optional) -> 3.
1452 qphy->tx = of_iomap(np, 0);
1456 qphy->rx = of_iomap(np, 1);
1460 qphy->pcs = of_iomap(np, 2);
1464 qphy->pcs_misc = of_iomap(np, 3);
1465 if (!qphy->pcs_misc)
1466 dev_vdbg(dev, "PHY pcs_misc-reg not used\n");
1469 * Get PHY's Pipe clock, if any. USB3 and PCIe are PIPE3
1470 * based phys, so they essentially have pipe clock. So,
1471 * we return error in case phy is USB3 or PIPE type.
1472 * Otherwise, we initialize pipe clock to NULL for
1473 * all phys that don't need this.
1475 snprintf(prop_name, sizeof(prop_name), "pipe%d", id);
1476 qphy->pipe_clk = devm_get_clk_from_child(dev, np, prop_name);
1477 if (IS_ERR(qphy->pipe_clk)) {
1478 if (qmp->cfg->type == PHY_TYPE_PCIE ||
1479 qmp->cfg->type == PHY_TYPE_USB3) {
1480 ret = PTR_ERR(qphy->pipe_clk);
1481 if (ret != -EPROBE_DEFER)
1483 "failed to get lane%d pipe_clk, %d\n",
1487 qphy->pipe_clk = NULL;
1490 /* Get lane reset, if any */
1491 if (qmp->cfg->has_lane_rst) {
1492 snprintf(prop_name, sizeof(prop_name), "lane%d", id);
1493 qphy->lane_rst = of_reset_control_get(np, prop_name);
1494 if (IS_ERR(qphy->lane_rst)) {
1495 dev_err(dev, "failed to get lane%d reset\n", id);
1496 return PTR_ERR(qphy->lane_rst);
1498 ret = devm_add_action_or_reset(dev, qcom_qmp_reset_control_put,
1504 generic_phy = devm_phy_create(dev, np, &qcom_qmp_phy_gen_ops);
1505 if (IS_ERR(generic_phy)) {
1506 ret = PTR_ERR(generic_phy);
1507 dev_err(dev, "failed to create qphy %d\n", ret);
1511 qphy->phy = generic_phy;
1514 qmp->phys[id] = qphy;
1515 phy_set_drvdata(generic_phy, qphy);
1520 static const struct of_device_id qcom_qmp_phy_of_match_table[] = {
1522 .compatible = "qcom,msm8996-qmp-pcie-phy",
1523 .data = &msm8996_pciephy_cfg,
1525 .compatible = "qcom,msm8996-qmp-usb3-phy",
1526 .data = &msm8996_usb3phy_cfg,
1528 .compatible = "qcom,ipq8074-qmp-pcie-phy",
1529 .data = &ipq8074_pciephy_cfg,
1531 .compatible = "qcom,sdm845-qmp-usb3-phy",
1532 .data = &qmp_v3_usb3phy_cfg,
1534 .compatible = "qcom,sdm845-qmp-usb3-uni-phy",
1535 .data = &qmp_v3_usb3_uniphy_cfg,
1539 MODULE_DEVICE_TABLE(of, qcom_qmp_phy_of_match_table);
1541 static const struct dev_pm_ops qcom_qmp_phy_pm_ops = {
1542 SET_RUNTIME_PM_OPS(qcom_qmp_phy_runtime_suspend,
1543 qcom_qmp_phy_runtime_resume, NULL)
1546 static int qcom_qmp_phy_probe(struct platform_device *pdev)
1548 struct qcom_qmp *qmp;
1549 struct device *dev = &pdev->dev;
1550 struct resource *res;
1551 struct device_node *child;
1552 struct phy_provider *phy_provider;
1557 qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL);
1562 dev_set_drvdata(dev, qmp);
1564 /* Get the specific init parameters of QMP phy */
1565 qmp->cfg = of_device_get_match_data(dev);
1569 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1570 base = devm_ioremap_resource(dev, res);
1572 return PTR_ERR(base);
1574 /* per PHY serdes; usually located at base address */
1577 /* per PHY dp_com; if PHY has dp_com control block */
1578 if (qmp->cfg->has_phy_dp_com_ctrl) {
1579 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1581 base = devm_ioremap_resource(dev, res);
1583 return PTR_ERR(base);
1588 mutex_init(&qmp->phy_mutex);
1590 ret = qcom_qmp_phy_clk_init(dev);
1594 ret = qcom_qmp_phy_reset_init(dev);
1598 ret = qcom_qmp_phy_vreg_init(dev);
1600 dev_err(dev, "failed to get regulator supplies\n");
1604 num = of_get_available_child_count(dev->of_node);
1605 /* do we have a rogue child node ? */
1606 if (num > qmp->cfg->nlanes)
1609 qmp->phys = devm_kcalloc(dev, num, sizeof(*qmp->phys), GFP_KERNEL);
1614 pm_runtime_set_active(dev);
1615 pm_runtime_enable(dev);
1617 * Prevent runtime pm from being ON by default. Users can enable
1618 * it using power/control in sysfs.
1620 pm_runtime_forbid(dev);
1622 for_each_available_child_of_node(dev->of_node, child) {
1623 /* Create per-lane phy */
1624 ret = qcom_qmp_phy_create(dev, child, id);
1626 dev_err(dev, "failed to create lane%d phy, %d\n",
1628 pm_runtime_disable(dev);
1633 * Register the pipe clock provided by phy.
1634 * See function description to see details of this pipe clock.
1636 ret = phy_pipe_clk_register(qmp, child);
1639 "failed to register pipe clock source\n");
1640 pm_runtime_disable(dev);
1646 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
1647 if (!IS_ERR(phy_provider))
1648 dev_info(dev, "Registered Qcom-QMP phy\n");
1650 pm_runtime_disable(dev);
1652 return PTR_ERR_OR_ZERO(phy_provider);
1655 static struct platform_driver qcom_qmp_phy_driver = {
1656 .probe = qcom_qmp_phy_probe,
1658 .name = "qcom-qmp-phy",
1659 .pm = &qcom_qmp_phy_pm_ops,
1660 .of_match_table = qcom_qmp_phy_of_match_table,
1664 module_platform_driver(qcom_qmp_phy_driver);
1666 MODULE_AUTHOR("Vivek Gautam <vivek.gautam@codeaurora.org>");
1667 MODULE_DESCRIPTION("Qualcomm QMP PHY driver");
1668 MODULE_LICENSE("GPL v2");