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_address.h>
16 #include <linux/phy/phy.h>
17 #include <linux/platform_device.h>
18 #include <linux/regulator/consumer.h>
19 #include <linux/reset.h>
20 #include <linux/slab.h>
22 #include <ufs/unipro.h>
23 #include "phy-qcom-qmp.h"
24 #include "phy-qcom-qmp-pcs-ufs-v2.h"
25 #include "phy-qcom-qmp-pcs-ufs-v3.h"
26 #include "phy-qcom-qmp-pcs-ufs-v4.h"
27 #include "phy-qcom-qmp-pcs-ufs-v5.h"
28 #include "phy-qcom-qmp-pcs-ufs-v6.h"
30 #include "phy-qcom-qmp-qserdes-txrx-ufs-v6.h"
32 /* QPHY_SW_RESET bit */
33 #define SW_RESET BIT(0)
34 /* QPHY_POWER_DOWN_CONTROL */
35 #define SW_PWRDN BIT(0)
36 /* QPHY_START_CONTROL bits */
37 #define SERDES_START BIT(0)
38 #define PCS_START BIT(1)
39 /* QPHY_PCS_READY_STATUS bit */
40 #define PCS_READY BIT(0)
42 #define PHY_INIT_COMPLETE_TIMEOUT 10000
44 struct qmp_phy_init_tbl {
48 * mask of lanes for which this register is written
49 * for cases when second lane needs different values
54 #define QMP_PHY_INIT_CFG(o, v) \
61 #define QMP_PHY_INIT_CFG_LANE(o, v, l) \
68 /* set of registers with offsets different per-PHY */
69 enum qphy_reg_layout {
73 QPHY_PCS_READY_STATUS,
74 QPHY_PCS_POWER_DOWN_CONTROL,
75 /* Keep last to ensure regs_layout arrays are properly initialized */
79 static const unsigned int ufsphy_v2_regs_layout[QPHY_LAYOUT_SIZE] = {
80 [QPHY_START_CTRL] = QPHY_V2_PCS_UFS_PHY_START,
81 [QPHY_PCS_READY_STATUS] = QPHY_V2_PCS_UFS_READY_STATUS,
82 [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V2_PCS_UFS_POWER_DOWN_CONTROL,
85 static const unsigned int ufsphy_v3_regs_layout[QPHY_LAYOUT_SIZE] = {
86 [QPHY_START_CTRL] = QPHY_V3_PCS_UFS_PHY_START,
87 [QPHY_PCS_READY_STATUS] = QPHY_V3_PCS_UFS_READY_STATUS,
88 [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V3_PCS_UFS_POWER_DOWN_CONTROL,
91 static const unsigned int ufsphy_v4_regs_layout[QPHY_LAYOUT_SIZE] = {
92 [QPHY_START_CTRL] = QPHY_V4_PCS_UFS_PHY_START,
93 [QPHY_PCS_READY_STATUS] = QPHY_V4_PCS_UFS_READY_STATUS,
94 [QPHY_SW_RESET] = QPHY_V4_PCS_UFS_SW_RESET,
95 [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V4_PCS_UFS_POWER_DOWN_CONTROL,
98 static const unsigned int ufsphy_v5_regs_layout[QPHY_LAYOUT_SIZE] = {
99 [QPHY_START_CTRL] = QPHY_V5_PCS_UFS_PHY_START,
100 [QPHY_PCS_READY_STATUS] = QPHY_V5_PCS_UFS_READY_STATUS,
101 [QPHY_SW_RESET] = QPHY_V5_PCS_UFS_SW_RESET,
102 [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V5_PCS_UFS_POWER_DOWN_CONTROL,
105 static const unsigned int ufsphy_v6_regs_layout[QPHY_LAYOUT_SIZE] = {
106 [QPHY_START_CTRL] = QPHY_V6_PCS_UFS_PHY_START,
107 [QPHY_PCS_READY_STATUS] = QPHY_V6_PCS_UFS_READY_STATUS,
108 [QPHY_SW_RESET] = QPHY_V6_PCS_UFS_SW_RESET,
109 [QPHY_PCS_POWER_DOWN_CONTROL] = QPHY_V6_PCS_UFS_POWER_DOWN_CONTROL,
112 static const struct qmp_phy_init_tbl msm8996_ufsphy_serdes[] = {
113 QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x0e),
114 QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0xd7),
115 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x30),
116 QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x06),
117 QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
118 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0x0a),
119 QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x05),
120 QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0x0a),
121 QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV_MODE1, 0x0a),
122 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x01),
123 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_CTRL, 0x10),
124 QMP_PHY_INIT_CFG(QSERDES_COM_RESETSM_CNTRL, 0x20),
125 QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x00),
126 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_CFG, 0x00),
127 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0xff),
128 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x3f),
129 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x54),
130 QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x05),
131 QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
132 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x00),
133 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x00),
134 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x00),
135 QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0x0b),
136 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
137 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
138 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
139 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
140 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE0, 0x28),
141 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE0, 0x02),
142 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0xff),
143 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0x0c),
144 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x00),
145 QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE1, 0x98),
146 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE1, 0x00),
147 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE1, 0x00),
148 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE1, 0x00),
149 QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE1, 0x0b),
150 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE1, 0x16),
151 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE1, 0x28),
152 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE1, 0x80),
153 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE1, 0x00),
154 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE1, 0xd6),
155 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE1, 0x00),
156 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE1, 0x32),
157 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE1, 0x0f),
158 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE1, 0x00),
161 static const struct qmp_phy_init_tbl msm8996_ufsphy_tx[] = {
162 QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
163 QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x02),
166 static const struct qmp_phy_init_tbl msm8996_ufsphy_rx[] = {
167 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_LVL, 0x24),
168 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_CNTRL, 0x02),
169 QMP_PHY_INIT_CFG(QSERDES_RX_RX_INTERFACE_MODE, 0x00),
170 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x18),
171 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_FASTLOCK_FO_GAIN, 0x0B),
172 QMP_PHY_INIT_CFG(QSERDES_RX_RX_TERM_BW, 0x5b),
173 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_LSB, 0xff),
174 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_MSB, 0x3f),
175 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_LSB, 0xff),
176 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_MSB, 0x0f),
177 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0E),
180 static const struct qmp_phy_init_tbl sc7280_ufsphy_tx[] = {
181 QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_1_DIVIDER_BAND0_1, 0x06),
182 QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_2_DIVIDER_BAND0_1, 0x03),
183 QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_3_DIVIDER_BAND0_1, 0x01),
184 QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_4_DIVIDER_BAND0_1, 0x00),
185 QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0x35),
186 QMP_PHY_INIT_CFG(QSERDES_V4_TX_TRAN_DRVR_EMP_EN, 0x0c),
189 static const struct qmp_phy_init_tbl sc7280_ufsphy_rx[] = {
190 QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_LVL, 0x24),
191 QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x0f),
192 QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
193 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_BAND, 0x18),
194 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x0a),
195 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
196 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0xf1),
197 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
198 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x80),
199 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0e),
200 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x04),
201 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x1b),
202 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
203 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
204 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1d),
205 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x00),
206 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x10),
207 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
208 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
209 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x6d),
210 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0x6d),
211 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xed),
212 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x3b),
213 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x3c),
214 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0xe0),
215 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0xc8),
216 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xc8),
217 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x3b),
218 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb1),
219 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_LOW, 0xe0),
220 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH, 0xc8),
221 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH2, 0xc8),
222 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH3, 0x3b),
223 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH4, 0xb1),
224 QMP_PHY_INIT_CFG(QSERDES_V4_RX_DCC_CTRL1, 0x0c),
227 static const struct qmp_phy_init_tbl sc7280_ufsphy_pcs[] = {
228 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
229 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
230 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
231 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
232 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_DEBUG_BUS_CLKSEL, 0x1f),
233 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
234 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
235 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_PLL_CNTL, 0x03),
236 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TIMER_20US_CORECLK_STEPS_MSB, 0x16),
237 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TIMER_20US_CORECLK_STEPS_LSB, 0xd8),
238 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_PWM_GEAR_BAND, 0xaa),
239 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_HS_GEAR_BAND, 0x06),
240 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_HSGEAR_CAPABILITY, 0x03),
241 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_HSGEAR_CAPABILITY, 0x03),
244 static const struct qmp_phy_init_tbl sc7280_ufsphy_hs_g4_rx[] = {
245 QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_LVL, 0x24),
246 QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x0f),
247 QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
248 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_BAND, 0x18),
249 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x0a),
250 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
251 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0xf1),
252 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
253 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x81),
254 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0e),
255 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x04),
256 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x6f),
257 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL1, 0x04),
258 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x00),
259 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x09),
260 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x07),
261 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x17),
262 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x00),
263 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x20),
264 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0x80),
265 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
266 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x3f),
267 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff),
268 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xff),
269 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
270 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x2c),
271 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0x6d),
272 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0x6d),
273 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xed),
274 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x3b),
275 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0x3c),
276 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_LOW, 0xe0),
277 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH, 0xc8),
278 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH2, 0xc8),
279 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH3, 0x3b),
280 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH4, 0xb1),
281 QMP_PHY_INIT_CFG(QSERDES_V4_RX_DCC_CTRL1, 0x0c),
282 QMP_PHY_INIT_CFG(QSERDES_V4_RX_GM_CAL, 0x0f),
285 static const struct qmp_phy_init_tbl sm6115_ufsphy_serdes[] = {
286 QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x0e),
287 QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0x14),
288 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x30),
289 QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x02),
290 QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x08),
291 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0x0a),
292 QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x00),
293 QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0x0a),
294 QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV_MODE1, 0x0a),
295 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x01),
296 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_CTRL, 0x00),
297 QMP_PHY_INIT_CFG(QSERDES_COM_RESETSM_CNTRL, 0x20),
298 QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x00),
299 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_CFG, 0x00),
300 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0xff),
301 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x3f),
302 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x04),
303 QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x05),
304 QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
305 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x00),
306 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x00),
307 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x00),
308 QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0x0b),
309 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
310 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
311 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
312 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
313 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE0, 0x28),
314 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE0, 0x02),
315 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0xff),
316 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0x0c),
317 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x00),
318 QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE1, 0x98),
319 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE1, 0x00),
320 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE1, 0x00),
321 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE1, 0x00),
322 QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE1, 0x0b),
323 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE1, 0x16),
324 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE1, 0x28),
325 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE1, 0x80),
326 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE1, 0x00),
327 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE1_MODE1, 0xd6),
328 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE2_MODE1, 0x00),
329 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE1, 0x32),
330 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE1, 0x0f),
331 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE1, 0x00),
332 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_IVCO, 0x0f),
333 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TRIM, 0x0f),
334 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_INITVAL1, 0xff),
335 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_INITVAL2, 0x00),
338 static const struct qmp_phy_init_tbl sm6115_ufsphy_hs_b_serdes[] = {
339 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x44),
342 static const struct qmp_phy_init_tbl sm6115_ufsphy_tx[] = {
343 QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
344 QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x06),
347 static const struct qmp_phy_init_tbl sm6115_ufsphy_rx[] = {
348 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_LVL, 0x24),
349 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_CNTRL, 0x0F),
350 QMP_PHY_INIT_CFG(QSERDES_RX_RX_INTERFACE_MODE, 0x40),
351 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x1E),
352 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_FASTLOCK_FO_GAIN, 0x0B),
353 QMP_PHY_INIT_CFG(QSERDES_RX_RX_TERM_BW, 0x5B),
354 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_LSB, 0xFF),
355 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN1_MSB, 0x3F),
356 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_LSB, 0xFF),
357 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQ_GAIN2_MSB, 0x3F),
358 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x0D),
359 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SVS_SO_GAIN_HALF, 0x04),
360 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SVS_SO_GAIN_QUARTER, 0x04),
361 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SVS_SO_GAIN, 0x04),
362 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5B),
365 static const struct qmp_phy_init_tbl sm6115_ufsphy_pcs[] = {
366 QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_PWM_GEAR_BAND, 0x15),
367 QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
368 QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0f),
369 QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
370 QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_MIN_STALL_NOCONFIG_TIME_CAP, 0x28),
371 QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_SYM_RESYNC_CTRL, 0x03),
372 QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_LARGE_AMP_POST_EMP_LVL, 0x12),
373 QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_TX_SMALL_AMP_POST_EMP_LVL, 0x0f),
374 QMP_PHY_INIT_CFG(QPHY_V2_PCS_UFS_RX_MIN_HIBERN8_TIME, 0x9a), /* 8 us */
377 static const struct qmp_phy_init_tbl sdm845_ufsphy_serdes[] = {
378 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYS_CLK_CTRL, 0x02),
379 QMP_PHY_INIT_CFG(QSERDES_V3_COM_BIAS_EN_CLKBUFLR_EN, 0x04),
380 QMP_PHY_INIT_CFG(QSERDES_V3_COM_BG_TIMER, 0x0a),
381 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_IVCO, 0x07),
382 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CMN_CONFIG, 0x06),
383 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SYSCLK_EN_SEL, 0xd5),
384 QMP_PHY_INIT_CFG(QSERDES_V3_COM_RESETSM_CNTRL, 0x20),
385 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CLK_SELECT, 0x30),
386 QMP_PHY_INIT_CFG(QSERDES_V3_COM_HSCLK_SEL, 0x00),
387 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP_EN, 0x01),
388 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_CTRL, 0x00),
389 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CORE_CLK_EN, 0x00),
390 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x04),
391 QMP_PHY_INIT_CFG(QSERDES_V3_COM_SVS_MODE_CLK_SEL, 0x05),
392 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_INITVAL1, 0xff),
393 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_INITVAL2, 0x00),
394 QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE0, 0x82),
395 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE0, 0x06),
396 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE0, 0x16),
397 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE0, 0x36),
398 QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE0, 0x3f),
399 QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE0, 0x00),
400 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE0, 0xda),
401 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE0, 0x01),
402 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE0, 0xff),
403 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE0, 0x0c),
404 QMP_PHY_INIT_CFG(QSERDES_V3_COM_DEC_START_MODE1, 0x98),
405 QMP_PHY_INIT_CFG(QSERDES_V3_COM_CP_CTRL_MODE1, 0x06),
406 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_RCTRL_MODE1, 0x16),
407 QMP_PHY_INIT_CFG(QSERDES_V3_COM_PLL_CCTRL_MODE1, 0x36),
408 QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN0_MODE1, 0x3f),
409 QMP_PHY_INIT_CFG(QSERDES_V3_COM_INTEGLOOP_GAIN1_MODE1, 0x00),
410 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE1_MODE1, 0xc1),
411 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE2_MODE1, 0x00),
412 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP1_MODE1, 0x32),
413 QMP_PHY_INIT_CFG(QSERDES_V3_COM_LOCK_CMP2_MODE1, 0x0f),
416 static const struct qmp_phy_init_tbl sdm845_ufsphy_hs_b_serdes[] = {
417 QMP_PHY_INIT_CFG(QSERDES_V3_COM_VCO_TUNE_MAP, 0x44),
420 static const struct qmp_phy_init_tbl sdm845_ufsphy_tx[] = {
421 QMP_PHY_INIT_CFG(QSERDES_V3_TX_LANE_MODE_1, 0x06),
422 QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_TX, 0x04),
423 QMP_PHY_INIT_CFG(QSERDES_V3_TX_RES_CODE_LANE_OFFSET_RX, 0x07),
426 static const struct qmp_phy_init_tbl sdm845_ufsphy_rx[] = {
427 QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_LVL, 0x24),
428 QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x0f),
429 QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
430 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_INTERFACE_MODE, 0x40),
431 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
432 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_TERM_BW, 0x5b),
433 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
434 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
435 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1b),
436 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_HALF, 0x04),
437 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_QUARTER, 0x04),
438 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN, 0x04),
439 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
440 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_PI_CONTROLS, 0x81),
441 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
442 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_MODE_00, 0x59),
445 static const struct qmp_phy_init_tbl sdm845_ufsphy_pcs[] = {
446 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL2, 0x6e),
447 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
448 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
449 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SYM_RESYNC_CTRL, 0x03),
450 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
451 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL1, 0x0f),
452 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_MIN_HIBERN8_TIME, 0x9a),
453 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
456 static const struct qmp_phy_init_tbl sm7150_ufsphy_rx[] = {
457 QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_LVL, 0x24),
458 QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_CNTRL, 0x0f),
459 QMP_PHY_INIT_CFG(QSERDES_V3_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
460 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_INTERFACE_MODE, 0x40),
461 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_FO_GAIN, 0x0b),
462 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_TERM_BW, 0x5b),
463 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
464 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
465 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1b),
466 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_HALF, 0x04),
467 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN_QUARTER, 0x04),
468 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SVS_SO_GAIN, 0x04),
469 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5b),
470 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_PI_CONTROLS, 0x81),
471 QMP_PHY_INIT_CFG(QSERDES_V3_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
472 QMP_PHY_INIT_CFG(QSERDES_V3_RX_RX_MODE_00, 0x59),
475 static const struct qmp_phy_init_tbl sm7150_ufsphy_pcs[] = {
476 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL2, 0x6f),
477 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0f),
478 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
479 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SYM_RESYNC_CTRL, 0x03),
480 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
481 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_SIGDET_CTRL1, 0x0f),
482 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
483 QMP_PHY_INIT_CFG(QPHY_V3_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
486 static const struct qmp_phy_init_tbl sm8150_ufsphy_serdes[] = {
487 QMP_PHY_INIT_CFG(QSERDES_V4_COM_SYSCLK_EN_SEL, 0xd9),
488 QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_SEL, 0x11),
489 QMP_PHY_INIT_CFG(QSERDES_V4_COM_HSCLK_HS_SWITCH_SEL, 0x00),
490 QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP_EN, 0x01),
491 QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x02),
492 QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_IVCO, 0x0f),
493 QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_INITVAL2, 0x00),
494 QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_HSCLK_SEL, 0x11),
495 QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE0, 0x82),
496 QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE0, 0x06),
497 QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE0, 0x16),
498 QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE0, 0x36),
499 QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE0, 0xff),
500 QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE0, 0x0c),
501 QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE0, 0xac),
502 QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE0, 0x1e),
503 QMP_PHY_INIT_CFG(QSERDES_V4_COM_DEC_START_MODE1, 0x98),
504 QMP_PHY_INIT_CFG(QSERDES_V4_COM_CP_CTRL_MODE1, 0x06),
505 QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_RCTRL_MODE1, 0x16),
506 QMP_PHY_INIT_CFG(QSERDES_V4_COM_PLL_CCTRL_MODE1, 0x36),
507 QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP1_MODE1, 0x32),
508 QMP_PHY_INIT_CFG(QSERDES_V4_COM_LOCK_CMP2_MODE1, 0x0f),
509 QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE1_MODE1, 0xdd),
510 QMP_PHY_INIT_CFG(QSERDES_V4_COM_BIN_VCOCAL_CMP_CODE2_MODE1, 0x23),
513 static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_b_serdes[] = {
514 QMP_PHY_INIT_CFG(QSERDES_V4_COM_VCO_TUNE_MAP, 0x06),
517 static const struct qmp_phy_init_tbl sm8150_ufsphy_tx[] = {
518 QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_1_DIVIDER_BAND0_1, 0x06),
519 QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_2_DIVIDER_BAND0_1, 0x03),
520 QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_3_DIVIDER_BAND0_1, 0x01),
521 QMP_PHY_INIT_CFG(QSERDES_V4_TX_PWM_GEAR_4_DIVIDER_BAND0_1, 0x00),
522 QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0x05),
523 QMP_PHY_INIT_CFG(QSERDES_V4_TX_TRAN_DRVR_EMP_EN, 0x0c),
526 static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_g4_tx[] = {
527 QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0x75),
530 static const struct qmp_phy_init_tbl sm8150_ufsphy_rx[] = {
531 QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_LVL, 0x24),
532 QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_CNTRL, 0x0f),
533 QMP_PHY_INIT_CFG(QSERDES_V4_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
534 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_BAND, 0x18),
535 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_FO_GAIN, 0x0a),
536 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
537 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CONTROLS, 0xf1),
538 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
539 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x80),
540 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0c),
541 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_GAIN, 0x04),
542 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x1b),
543 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
544 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
545 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1d),
546 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x00),
547 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x10),
548 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
549 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
550 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x36),
551 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0x36),
552 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xf6),
553 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x3b),
554 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x3d),
555 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0xe0),
556 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0xc8),
557 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xc8),
558 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH3, 0x3b),
559 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0xb1),
560 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_LOW, 0xe0),
561 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH, 0xc8),
562 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH2, 0xc8),
563 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH3, 0x3b),
564 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_10_HIGH4, 0xb1),
567 static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_g4_rx[] = {
568 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
569 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x81),
570 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0e),
571 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x6f),
572 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x20),
573 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0x80),
574 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
575 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x3f),
576 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff),
577 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xff),
578 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
579 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x6c),
580 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0x6d),
581 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0x6d),
582 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xed),
583 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0x3c),
586 static const struct qmp_phy_init_tbl sm8150_ufsphy_pcs[] = {
587 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
588 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
589 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
590 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
591 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_DEBUG_BUS_CLKSEL, 0x1f),
592 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
593 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
596 static const struct qmp_phy_init_tbl sm8150_ufsphy_hs_g4_pcs[] = {
597 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x10),
598 QMP_PHY_INIT_CFG(QPHY_V4_PCS_UFS_BIST_FIXED_PAT_CTRL, 0x0a),
601 static const struct qmp_phy_init_tbl sm8250_ufsphy_hs_g4_tx[] = {
602 QMP_PHY_INIT_CFG(QSERDES_V4_TX_LANE_MODE_1, 0xe5),
605 static const struct qmp_phy_init_tbl sm8250_ufsphy_hs_g4_rx[] = {
606 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
607 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_PI_CTRL2, 0x81),
608 QMP_PHY_INIT_CFG(QSERDES_V4_RX_UCDR_FO_GAIN, 0x0e),
609 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_TERM_BW, 0x6f),
610 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL1, 0x04),
611 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL2, 0x00),
612 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL3, 0x09),
613 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQU_ADAPTOR_CNTRL4, 0x07),
614 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x17),
615 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_MEASURE_TIME, 0x20),
616 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_LOW, 0x80),
617 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
618 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_LOW, 0x3f),
619 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH, 0xff),
620 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH2, 0xff),
621 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH3, 0x7f),
622 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_00_HIGH4, 0x2c),
623 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_LOW, 0x6d),
624 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH, 0x6d),
625 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH2, 0xed),
626 QMP_PHY_INIT_CFG(QSERDES_V4_RX_RX_MODE_01_HIGH4, 0x3c),
629 static const struct qmp_phy_init_tbl sm8350_ufsphy_serdes[] = {
630 QMP_PHY_INIT_CFG(QSERDES_V5_COM_SYSCLK_EN_SEL, 0xd9),
631 QMP_PHY_INIT_CFG(QSERDES_V5_COM_HSCLK_SEL, 0x11),
632 QMP_PHY_INIT_CFG(QSERDES_V5_COM_HSCLK_HS_SWITCH_SEL, 0x00),
633 QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP_EN, 0x42),
634 QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_MAP, 0x02),
635 QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_IVCO, 0x0f),
636 QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_INITVAL2, 0x00),
637 QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_HSCLK_SEL, 0x11),
638 QMP_PHY_INIT_CFG(QSERDES_V5_COM_DEC_START_MODE0, 0x82),
639 QMP_PHY_INIT_CFG(QSERDES_V5_COM_CP_CTRL_MODE0, 0x14),
640 QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_RCTRL_MODE0, 0x18),
641 QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_CCTRL_MODE0, 0x18),
642 QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP1_MODE0, 0xff),
643 QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP2_MODE0, 0x19),
644 QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE1_MODE0, 0xac),
645 QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE2_MODE0, 0x1e),
646 QMP_PHY_INIT_CFG(QSERDES_V5_COM_DEC_START_MODE1, 0x98),
647 QMP_PHY_INIT_CFG(QSERDES_V5_COM_CP_CTRL_MODE1, 0x14),
648 QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_RCTRL_MODE1, 0x18),
649 QMP_PHY_INIT_CFG(QSERDES_V5_COM_PLL_CCTRL_MODE1, 0x18),
650 QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP1_MODE1, 0x65),
651 QMP_PHY_INIT_CFG(QSERDES_V5_COM_LOCK_CMP2_MODE1, 0x1e),
652 QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE1_MODE1, 0xdd),
653 QMP_PHY_INIT_CFG(QSERDES_V5_COM_BIN_VCOCAL_CMP_CODE2_MODE1, 0x23),
656 static const struct qmp_phy_init_tbl sm8350_ufsphy_hs_b_serdes[] = {
657 QMP_PHY_INIT_CFG(QSERDES_V5_COM_VCO_TUNE_MAP, 0x06),
660 static const struct qmp_phy_init_tbl sm8350_ufsphy_tx[] = {
661 QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_1_DIVIDER_BAND0_1, 0x06),
662 QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_2_DIVIDER_BAND0_1, 0x03),
663 QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_3_DIVIDER_BAND0_1, 0x01),
664 QMP_PHY_INIT_CFG(QSERDES_V5_TX_PWM_GEAR_4_DIVIDER_BAND0_1, 0x00),
665 QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_1, 0xf5),
666 QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_3, 0x3f),
667 QMP_PHY_INIT_CFG(QSERDES_V5_TX_RES_CODE_LANE_OFFSET_TX, 0x09),
668 QMP_PHY_INIT_CFG(QSERDES_V5_TX_RES_CODE_LANE_OFFSET_RX, 0x09),
669 QMP_PHY_INIT_CFG(QSERDES_V5_TX_TRAN_DRVR_EMP_EN, 0x0c),
672 static const struct qmp_phy_init_tbl sm8350_ufsphy_rx[] = {
673 QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_LVL, 0x24),
674 QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_CNTRL, 0x0f),
675 QMP_PHY_INIT_CFG(QSERDES_V5_RX_SIGDET_DEGLITCH_CNTRL, 0x1e),
676 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_BAND, 0x18),
677 QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FASTLOCK_FO_GAIN, 0x0a),
678 QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x5a),
679 QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_PI_CONTROLS, 0xf1),
680 QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FASTLOCK_COUNT_LOW, 0x80),
681 QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_PI_CTRL2, 0x80),
682 QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_FO_GAIN, 0x0e),
683 QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_SO_GAIN, 0x04),
684 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_TERM_BW, 0x1b),
685 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL1, 0x04),
686 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL2, 0x06),
687 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL3, 0x04),
688 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL4, 0x1a),
689 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x17),
690 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_OFFSET_ADAPTOR_CNTRL2, 0x00),
691 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_MEASURE_TIME, 0x10),
692 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_LOW, 0xc0),
693 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_HIGH, 0x00),
694 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_LOW, 0x6d),
695 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH, 0x6d),
696 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH2, 0xed),
697 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH3, 0x3b),
698 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH4, 0x3c),
699 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_LOW, 0xe0),
700 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH, 0xc8),
701 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH2, 0xc8),
702 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH3, 0x3b),
703 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH4, 0xb7),
704 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_LOW, 0xe0),
705 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH, 0xc8),
706 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH2, 0xc8),
707 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH3, 0x3b),
708 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_10_HIGH4, 0xb7),
709 QMP_PHY_INIT_CFG(QSERDES_V5_RX_DCC_CTRL1, 0x0c),
712 static const struct qmp_phy_init_tbl sm8350_ufsphy_pcs[] = {
713 QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_RX_SIGDET_CTRL2, 0x6d),
714 QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0a),
715 QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_TX_SMALL_AMP_DRV_LVL, 0x02),
716 QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
717 QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_DEBUG_BUS_CLKSEL, 0x1f),
718 QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_RX_MIN_HIBERN8_TIME, 0xff),
719 QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_RX_SIGDET_CTRL1, 0x0e),
720 QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
723 static const struct qmp_phy_init_tbl sm8350_ufsphy_g4_tx[] = {
724 QMP_PHY_INIT_CFG(QSERDES_V5_TX_LANE_MODE_1, 0xe5),
727 static const struct qmp_phy_init_tbl sm8350_ufsphy_g4_rx[] = {
728 QMP_PHY_INIT_CFG(QSERDES_V5_RX_UCDR_PI_CTRL2, 0x81),
729 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_TERM_BW, 0x6f),
730 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL2, 0x00),
731 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL3, 0x4a),
732 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_EQU_ADAPTOR_CNTRL4, 0x0a),
733 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_MEASURE_TIME, 0x20),
734 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_LOW, 0x80),
735 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_IDAC_TSETTLE_HIGH, 0x01),
736 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_LOW, 0xbf),
737 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH, 0xbf),
738 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH2, 0x7f),
739 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH3, 0x7f),
740 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_00_HIGH4, 0x2d),
741 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_LOW, 0x6d),
742 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH, 0x6d),
743 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH2, 0xed),
744 QMP_PHY_INIT_CFG(QSERDES_V5_RX_RX_MODE_01_HIGH4, 0x3c),
747 static const struct qmp_phy_init_tbl sm8350_ufsphy_g4_pcs[] = {
748 QMP_PHY_INIT_CFG(QPHY_V5_PCS_UFS_BIST_FIXED_PAT_CTRL, 0x0a),
751 static const struct qmp_phy_init_tbl sm8550_ufsphy_serdes[] = {
752 QMP_PHY_INIT_CFG(QSERDES_V6_COM_SYSCLK_EN_SEL, 0xd9),
753 QMP_PHY_INIT_CFG(QSERDES_V6_COM_CMN_CONFIG_1, 0x16),
754 QMP_PHY_INIT_CFG(QSERDES_V6_COM_HSCLK_SEL_1, 0x11),
755 QMP_PHY_INIT_CFG(QSERDES_V6_COM_HSCLK_HS_SWITCH_SEL_1, 0x00),
756 QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP_EN, 0x01),
757 QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_MAP, 0x04),
758 QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_IVCO, 0x0f),
759 QMP_PHY_INIT_CFG(QSERDES_V6_COM_VCO_TUNE_INITVAL2, 0x00),
760 QMP_PHY_INIT_CFG(QSERDES_V6_COM_DEC_START_MODE0, 0x41),
761 QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE0, 0x0a),
762 QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_RCTRL_MODE0, 0x18),
763 QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_CCTRL_MODE0, 0x14),
764 QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP1_MODE0, 0x7f),
765 QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP2_MODE0, 0x06),
766 QMP_PHY_INIT_CFG(QSERDES_V6_COM_DEC_START_MODE0, 0x4c),
767 QMP_PHY_INIT_CFG(QSERDES_V6_COM_CP_CTRL_MODE0, 0x0a),
768 QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_RCTRL_MODE0, 0x18),
769 QMP_PHY_INIT_CFG(QSERDES_V6_COM_PLL_CCTRL_MODE0, 0x14),
770 QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP1_MODE0, 0x99),
771 QMP_PHY_INIT_CFG(QSERDES_V6_COM_LOCK_CMP2_MODE0, 0x07),
774 static const struct qmp_phy_init_tbl sm8550_ufsphy_tx[] = {
775 QMP_PHY_INIT_CFG(QSERDES_V6_TX_LANE_MODE_1, 0x05),
776 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_TX_RES_CODE_LANE_OFFSET_TX, 0x07),
779 static const struct qmp_phy_init_tbl sm8550_ufsphy_rx[] = {
780 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FASTLOCK_FO_GAIN_RATE2, 0x0c),
781 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_UCDR_FASTLOCK_FO_GAIN_RATE4, 0x0f),
782 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_VGA_CAL_MAN_VAL, 0x0e),
784 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B0, 0xc2),
785 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B1, 0xc2),
786 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B3, 0x1a),
787 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE_0_1_B6, 0x60),
789 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE2_B3, 0x9e),
790 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE2_B6, 0x60),
792 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B3, 0x9e),
793 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B4, 0x0e),
794 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B5, 0x36),
795 QMP_PHY_INIT_CFG(QSERDES_UFS_V6_RX_MODE_RATE3_B8, 0x02),
798 static const struct qmp_phy_init_tbl sm8550_ufsphy_pcs[] = {
799 QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_RX_SIGDET_CTRL2, 0x69),
800 QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_LARGE_AMP_DRV_LVL, 0x0f),
801 QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_TX_MID_TERM_CTRL1, 0x43),
802 QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_PLL_CNTL, 0x2b),
803 QMP_PHY_INIT_CFG(QPHY_V6_PCS_UFS_MULTI_LANE_CTRL1, 0x02),
806 struct qmp_ufs_offsets {
815 struct qmp_phy_cfg_tbls {
816 /* Init sequence for PHY blocks - serdes, tx, rx, pcs */
817 const struct qmp_phy_init_tbl *serdes;
819 const struct qmp_phy_init_tbl *tx;
821 const struct qmp_phy_init_tbl *rx;
823 const struct qmp_phy_init_tbl *pcs;
827 /* struct qmp_phy_cfg - per-PHY initialization config */
831 const struct qmp_ufs_offsets *offsets;
833 /* Main init sequence for PHY blocks - serdes, tx, rx, pcs */
834 const struct qmp_phy_cfg_tbls tbls;
835 /* Additional sequence for HS Series B */
836 const struct qmp_phy_cfg_tbls tbls_hs_b;
837 /* Additional sequence for HS G4 */
838 const struct qmp_phy_cfg_tbls tbls_hs_g4;
840 /* clock ids to be requested */
841 const char * const *clk_list;
843 /* regulators to be requested */
844 const char * const *vreg_list;
847 /* array of registers with different offsets */
848 const unsigned int *regs;
850 /* true, if PCS block has no separate SW_RESET register */
851 bool no_pcs_sw_reset;
857 const struct qmp_phy_cfg *cfg;
859 void __iomem *serdes;
861 void __iomem *pcs_misc;
867 struct clk_bulk_data *clks;
868 struct regulator_bulk_data *vregs;
869 struct reset_control *ufs_reset;
876 static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
880 reg = readl(base + offset);
882 writel(reg, base + offset);
884 /* ensure that above write is through */
885 readl(base + offset);
888 static inline void qphy_clrbits(void __iomem *base, u32 offset, u32 val)
892 reg = readl(base + offset);
894 writel(reg, base + offset);
896 /* ensure that above write is through */
897 readl(base + offset);
900 /* list of clocks required by phy */
901 static const char * const msm8996_ufs_phy_clk_l[] = {
905 /* the primary usb3 phy on sm8250 doesn't have a ref clock */
906 static const char * const sm8450_ufs_phy_clk_l[] = {
907 "qref", "ref", "ref_aux",
910 static const char * const sdm845_ufs_phy_clk_l[] = {
914 /* list of regulators */
915 static const char * const qmp_phy_vreg_l[] = {
916 "vdda-phy", "vdda-pll",
919 static const struct qmp_ufs_offsets qmp_ufs_offsets = {
928 static const struct qmp_ufs_offsets qmp_ufs_offsets_v6 = {
937 static const struct qmp_phy_cfg msm8996_ufsphy_cfg = {
940 .offsets = &qmp_ufs_offsets,
943 .serdes = msm8996_ufsphy_serdes,
944 .serdes_num = ARRAY_SIZE(msm8996_ufsphy_serdes),
945 .tx = msm8996_ufsphy_tx,
946 .tx_num = ARRAY_SIZE(msm8996_ufsphy_tx),
947 .rx = msm8996_ufsphy_rx,
948 .rx_num = ARRAY_SIZE(msm8996_ufsphy_rx),
951 .clk_list = msm8996_ufs_phy_clk_l,
952 .num_clks = ARRAY_SIZE(msm8996_ufs_phy_clk_l),
954 .vreg_list = qmp_phy_vreg_l,
955 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
957 .regs = ufsphy_v2_regs_layout,
959 .no_pcs_sw_reset = true,
962 static const struct qmp_phy_cfg sa8775p_ufsphy_cfg = {
965 .offsets = &qmp_ufs_offsets,
968 .serdes = sm8350_ufsphy_serdes,
969 .serdes_num = ARRAY_SIZE(sm8350_ufsphy_serdes),
970 .tx = sm8350_ufsphy_tx,
971 .tx_num = ARRAY_SIZE(sm8350_ufsphy_tx),
972 .rx = sm8350_ufsphy_rx,
973 .rx_num = ARRAY_SIZE(sm8350_ufsphy_rx),
974 .pcs = sm8350_ufsphy_pcs,
975 .pcs_num = ARRAY_SIZE(sm8350_ufsphy_pcs),
978 .serdes = sm8350_ufsphy_hs_b_serdes,
979 .serdes_num = ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
982 .tx = sm8350_ufsphy_g4_tx,
983 .tx_num = ARRAY_SIZE(sm8350_ufsphy_g4_tx),
984 .rx = sm8350_ufsphy_g4_rx,
985 .rx_num = ARRAY_SIZE(sm8350_ufsphy_g4_rx),
986 .pcs = sm8350_ufsphy_g4_pcs,
987 .pcs_num = ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
989 .clk_list = sm8450_ufs_phy_clk_l,
990 .num_clks = ARRAY_SIZE(sm8450_ufs_phy_clk_l),
991 .vreg_list = qmp_phy_vreg_l,
992 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
993 .regs = ufsphy_v5_regs_layout,
996 static const struct qmp_phy_cfg sc7280_ufsphy_cfg = {
999 .offsets = &qmp_ufs_offsets,
1002 .serdes = sm8150_ufsphy_serdes,
1003 .serdes_num = ARRAY_SIZE(sm8150_ufsphy_serdes),
1004 .tx = sc7280_ufsphy_tx,
1005 .tx_num = ARRAY_SIZE(sc7280_ufsphy_tx),
1006 .rx = sc7280_ufsphy_rx,
1007 .rx_num = ARRAY_SIZE(sc7280_ufsphy_rx),
1008 .pcs = sc7280_ufsphy_pcs,
1009 .pcs_num = ARRAY_SIZE(sc7280_ufsphy_pcs),
1012 .serdes = sm8150_ufsphy_hs_b_serdes,
1013 .serdes_num = ARRAY_SIZE(sm8150_ufsphy_hs_b_serdes),
1016 .tx = sm8250_ufsphy_hs_g4_tx,
1017 .tx_num = ARRAY_SIZE(sm8250_ufsphy_hs_g4_tx),
1018 .rx = sc7280_ufsphy_hs_g4_rx,
1019 .rx_num = ARRAY_SIZE(sc7280_ufsphy_hs_g4_rx),
1020 .pcs = sm8150_ufsphy_hs_g4_pcs,
1021 .pcs_num = ARRAY_SIZE(sm8150_ufsphy_hs_g4_pcs),
1023 .clk_list = sm8450_ufs_phy_clk_l,
1024 .num_clks = ARRAY_SIZE(sm8450_ufs_phy_clk_l),
1025 .vreg_list = qmp_phy_vreg_l,
1026 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
1027 .regs = ufsphy_v4_regs_layout,
1030 static const struct qmp_phy_cfg sc8280xp_ufsphy_cfg = {
1033 .offsets = &qmp_ufs_offsets,
1036 .serdes = sm8350_ufsphy_serdes,
1037 .serdes_num = ARRAY_SIZE(sm8350_ufsphy_serdes),
1038 .tx = sm8350_ufsphy_tx,
1039 .tx_num = ARRAY_SIZE(sm8350_ufsphy_tx),
1040 .rx = sm8350_ufsphy_rx,
1041 .rx_num = ARRAY_SIZE(sm8350_ufsphy_rx),
1042 .pcs = sm8350_ufsphy_pcs,
1043 .pcs_num = ARRAY_SIZE(sm8350_ufsphy_pcs),
1046 .serdes = sm8350_ufsphy_hs_b_serdes,
1047 .serdes_num = ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
1050 .tx = sm8350_ufsphy_g4_tx,
1051 .tx_num = ARRAY_SIZE(sm8350_ufsphy_g4_tx),
1052 .rx = sm8350_ufsphy_g4_rx,
1053 .rx_num = ARRAY_SIZE(sm8350_ufsphy_g4_rx),
1054 .pcs = sm8350_ufsphy_g4_pcs,
1055 .pcs_num = ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
1057 .clk_list = sdm845_ufs_phy_clk_l,
1058 .num_clks = ARRAY_SIZE(sdm845_ufs_phy_clk_l),
1059 .vreg_list = qmp_phy_vreg_l,
1060 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
1061 .regs = ufsphy_v5_regs_layout,
1064 static const struct qmp_phy_cfg sdm845_ufsphy_cfg = {
1067 .offsets = &qmp_ufs_offsets,
1070 .serdes = sdm845_ufsphy_serdes,
1071 .serdes_num = ARRAY_SIZE(sdm845_ufsphy_serdes),
1072 .tx = sdm845_ufsphy_tx,
1073 .tx_num = ARRAY_SIZE(sdm845_ufsphy_tx),
1074 .rx = sdm845_ufsphy_rx,
1075 .rx_num = ARRAY_SIZE(sdm845_ufsphy_rx),
1076 .pcs = sdm845_ufsphy_pcs,
1077 .pcs_num = ARRAY_SIZE(sdm845_ufsphy_pcs),
1080 .serdes = sdm845_ufsphy_hs_b_serdes,
1081 .serdes_num = ARRAY_SIZE(sdm845_ufsphy_hs_b_serdes),
1083 .clk_list = sdm845_ufs_phy_clk_l,
1084 .num_clks = ARRAY_SIZE(sdm845_ufs_phy_clk_l),
1085 .vreg_list = qmp_phy_vreg_l,
1086 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
1087 .regs = ufsphy_v3_regs_layout,
1089 .no_pcs_sw_reset = true,
1092 static const struct qmp_phy_cfg sm6115_ufsphy_cfg = {
1095 .offsets = &qmp_ufs_offsets,
1098 .serdes = sm6115_ufsphy_serdes,
1099 .serdes_num = ARRAY_SIZE(sm6115_ufsphy_serdes),
1100 .tx = sm6115_ufsphy_tx,
1101 .tx_num = ARRAY_SIZE(sm6115_ufsphy_tx),
1102 .rx = sm6115_ufsphy_rx,
1103 .rx_num = ARRAY_SIZE(sm6115_ufsphy_rx),
1104 .pcs = sm6115_ufsphy_pcs,
1105 .pcs_num = ARRAY_SIZE(sm6115_ufsphy_pcs),
1108 .serdes = sm6115_ufsphy_hs_b_serdes,
1109 .serdes_num = ARRAY_SIZE(sm6115_ufsphy_hs_b_serdes),
1111 .clk_list = sdm845_ufs_phy_clk_l,
1112 .num_clks = ARRAY_SIZE(sdm845_ufs_phy_clk_l),
1113 .vreg_list = qmp_phy_vreg_l,
1114 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
1115 .regs = ufsphy_v2_regs_layout,
1117 .no_pcs_sw_reset = true,
1120 static const struct qmp_phy_cfg sm7150_ufsphy_cfg = {
1123 .offsets = &qmp_ufs_offsets,
1126 .serdes = sdm845_ufsphy_serdes,
1127 .serdes_num = ARRAY_SIZE(sdm845_ufsphy_serdes),
1128 .tx = sdm845_ufsphy_tx,
1129 .tx_num = ARRAY_SIZE(sdm845_ufsphy_tx),
1130 .rx = sm7150_ufsphy_rx,
1131 .rx_num = ARRAY_SIZE(sm7150_ufsphy_rx),
1132 .pcs = sm7150_ufsphy_pcs,
1133 .pcs_num = ARRAY_SIZE(sm7150_ufsphy_pcs),
1136 .serdes = sdm845_ufsphy_hs_b_serdes,
1137 .serdes_num = ARRAY_SIZE(sdm845_ufsphy_hs_b_serdes),
1139 .clk_list = sdm845_ufs_phy_clk_l,
1140 .num_clks = ARRAY_SIZE(sdm845_ufs_phy_clk_l),
1141 .vreg_list = qmp_phy_vreg_l,
1142 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
1143 .regs = ufsphy_v3_regs_layout,
1145 .no_pcs_sw_reset = true,
1148 static const struct qmp_phy_cfg sm8150_ufsphy_cfg = {
1151 .offsets = &qmp_ufs_offsets,
1154 .serdes = sm8150_ufsphy_serdes,
1155 .serdes_num = ARRAY_SIZE(sm8150_ufsphy_serdes),
1156 .tx = sm8150_ufsphy_tx,
1157 .tx_num = ARRAY_SIZE(sm8150_ufsphy_tx),
1158 .rx = sm8150_ufsphy_rx,
1159 .rx_num = ARRAY_SIZE(sm8150_ufsphy_rx),
1160 .pcs = sm8150_ufsphy_pcs,
1161 .pcs_num = ARRAY_SIZE(sm8150_ufsphy_pcs),
1164 .serdes = sm8150_ufsphy_hs_b_serdes,
1165 .serdes_num = ARRAY_SIZE(sm8150_ufsphy_hs_b_serdes),
1168 .tx = sm8150_ufsphy_hs_g4_tx,
1169 .tx_num = ARRAY_SIZE(sm8150_ufsphy_hs_g4_tx),
1170 .rx = sm8150_ufsphy_hs_g4_rx,
1171 .rx_num = ARRAY_SIZE(sm8150_ufsphy_hs_g4_rx),
1172 .pcs = sm8150_ufsphy_hs_g4_pcs,
1173 .pcs_num = ARRAY_SIZE(sm8150_ufsphy_hs_g4_pcs),
1175 .clk_list = sdm845_ufs_phy_clk_l,
1176 .num_clks = ARRAY_SIZE(sdm845_ufs_phy_clk_l),
1177 .vreg_list = qmp_phy_vreg_l,
1178 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
1179 .regs = ufsphy_v4_regs_layout,
1182 static const struct qmp_phy_cfg sm8250_ufsphy_cfg = {
1185 .offsets = &qmp_ufs_offsets,
1188 .serdes = sm8150_ufsphy_serdes,
1189 .serdes_num = ARRAY_SIZE(sm8150_ufsphy_serdes),
1190 .tx = sm8150_ufsphy_tx,
1191 .tx_num = ARRAY_SIZE(sm8150_ufsphy_tx),
1192 .rx = sm8150_ufsphy_rx,
1193 .rx_num = ARRAY_SIZE(sm8150_ufsphy_rx),
1194 .pcs = sm8150_ufsphy_pcs,
1195 .pcs_num = ARRAY_SIZE(sm8150_ufsphy_pcs),
1198 .serdes = sm8150_ufsphy_hs_b_serdes,
1199 .serdes_num = ARRAY_SIZE(sm8150_ufsphy_hs_b_serdes),
1202 .tx = sm8250_ufsphy_hs_g4_tx,
1203 .tx_num = ARRAY_SIZE(sm8250_ufsphy_hs_g4_tx),
1204 .rx = sm8250_ufsphy_hs_g4_rx,
1205 .rx_num = ARRAY_SIZE(sm8250_ufsphy_hs_g4_rx),
1206 .pcs = sm8150_ufsphy_hs_g4_pcs,
1207 .pcs_num = ARRAY_SIZE(sm8150_ufsphy_hs_g4_pcs),
1209 .clk_list = sdm845_ufs_phy_clk_l,
1210 .num_clks = ARRAY_SIZE(sdm845_ufs_phy_clk_l),
1211 .vreg_list = qmp_phy_vreg_l,
1212 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
1213 .regs = ufsphy_v4_regs_layout,
1216 static const struct qmp_phy_cfg sm8350_ufsphy_cfg = {
1219 .offsets = &qmp_ufs_offsets,
1222 .serdes = sm8350_ufsphy_serdes,
1223 .serdes_num = ARRAY_SIZE(sm8350_ufsphy_serdes),
1224 .tx = sm8350_ufsphy_tx,
1225 .tx_num = ARRAY_SIZE(sm8350_ufsphy_tx),
1226 .rx = sm8350_ufsphy_rx,
1227 .rx_num = ARRAY_SIZE(sm8350_ufsphy_rx),
1228 .pcs = sm8350_ufsphy_pcs,
1229 .pcs_num = ARRAY_SIZE(sm8350_ufsphy_pcs),
1232 .serdes = sm8350_ufsphy_hs_b_serdes,
1233 .serdes_num = ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
1236 .tx = sm8350_ufsphy_g4_tx,
1237 .tx_num = ARRAY_SIZE(sm8350_ufsphy_g4_tx),
1238 .rx = sm8350_ufsphy_g4_rx,
1239 .rx_num = ARRAY_SIZE(sm8350_ufsphy_g4_rx),
1240 .pcs = sm8350_ufsphy_g4_pcs,
1241 .pcs_num = ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
1243 .clk_list = sdm845_ufs_phy_clk_l,
1244 .num_clks = ARRAY_SIZE(sdm845_ufs_phy_clk_l),
1245 .vreg_list = qmp_phy_vreg_l,
1246 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
1247 .regs = ufsphy_v5_regs_layout,
1250 static const struct qmp_phy_cfg sm8450_ufsphy_cfg = {
1253 .offsets = &qmp_ufs_offsets,
1256 .serdes = sm8350_ufsphy_serdes,
1257 .serdes_num = ARRAY_SIZE(sm8350_ufsphy_serdes),
1258 .tx = sm8350_ufsphy_tx,
1259 .tx_num = ARRAY_SIZE(sm8350_ufsphy_tx),
1260 .rx = sm8350_ufsphy_rx,
1261 .rx_num = ARRAY_SIZE(sm8350_ufsphy_rx),
1262 .pcs = sm8350_ufsphy_pcs,
1263 .pcs_num = ARRAY_SIZE(sm8350_ufsphy_pcs),
1266 .serdes = sm8350_ufsphy_hs_b_serdes,
1267 .serdes_num = ARRAY_SIZE(sm8350_ufsphy_hs_b_serdes),
1270 .tx = sm8350_ufsphy_g4_tx,
1271 .tx_num = ARRAY_SIZE(sm8350_ufsphy_g4_tx),
1272 .rx = sm8350_ufsphy_g4_rx,
1273 .rx_num = ARRAY_SIZE(sm8350_ufsphy_g4_rx),
1274 .pcs = sm8350_ufsphy_g4_pcs,
1275 .pcs_num = ARRAY_SIZE(sm8350_ufsphy_g4_pcs),
1277 .clk_list = sm8450_ufs_phy_clk_l,
1278 .num_clks = ARRAY_SIZE(sm8450_ufs_phy_clk_l),
1279 .vreg_list = qmp_phy_vreg_l,
1280 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
1281 .regs = ufsphy_v5_regs_layout,
1284 static const struct qmp_phy_cfg sm8550_ufsphy_cfg = {
1287 .offsets = &qmp_ufs_offsets_v6,
1290 .serdes = sm8550_ufsphy_serdes,
1291 .serdes_num = ARRAY_SIZE(sm8550_ufsphy_serdes),
1292 .tx = sm8550_ufsphy_tx,
1293 .tx_num = ARRAY_SIZE(sm8550_ufsphy_tx),
1294 .rx = sm8550_ufsphy_rx,
1295 .rx_num = ARRAY_SIZE(sm8550_ufsphy_rx),
1296 .pcs = sm8550_ufsphy_pcs,
1297 .pcs_num = ARRAY_SIZE(sm8550_ufsphy_pcs),
1299 .clk_list = sdm845_ufs_phy_clk_l,
1300 .num_clks = ARRAY_SIZE(sdm845_ufs_phy_clk_l),
1301 .vreg_list = qmp_phy_vreg_l,
1302 .num_vregs = ARRAY_SIZE(qmp_phy_vreg_l),
1303 .regs = ufsphy_v6_regs_layout,
1306 static void qmp_ufs_configure_lane(void __iomem *base,
1307 const struct qmp_phy_init_tbl tbl[],
1312 const struct qmp_phy_init_tbl *t = tbl;
1317 for (i = 0; i < num; i++, t++) {
1318 if (!(t->lane_mask & lane_mask))
1321 writel(t->val, base + t->offset);
1325 static void qmp_ufs_configure(void __iomem *base,
1326 const struct qmp_phy_init_tbl tbl[],
1329 qmp_ufs_configure_lane(base, tbl, num, 0xff);
1332 static void qmp_ufs_serdes_init(struct qmp_ufs *qmp, const struct qmp_phy_cfg_tbls *tbls)
1334 void __iomem *serdes = qmp->serdes;
1336 qmp_ufs_configure(serdes, tbls->serdes, tbls->serdes_num);
1339 static void qmp_ufs_lanes_init(struct qmp_ufs *qmp, const struct qmp_phy_cfg_tbls *tbls)
1341 const struct qmp_phy_cfg *cfg = qmp->cfg;
1342 void __iomem *tx = qmp->tx;
1343 void __iomem *rx = qmp->rx;
1345 qmp_ufs_configure_lane(tx, tbls->tx, tbls->tx_num, 1);
1346 qmp_ufs_configure_lane(rx, tbls->rx, tbls->rx_num, 1);
1348 if (cfg->lanes >= 2) {
1349 qmp_ufs_configure_lane(qmp->tx2, tbls->tx, tbls->tx_num, 2);
1350 qmp_ufs_configure_lane(qmp->rx2, tbls->rx, tbls->rx_num, 2);
1354 static void qmp_ufs_pcs_init(struct qmp_ufs *qmp, const struct qmp_phy_cfg_tbls *tbls)
1356 void __iomem *pcs = qmp->pcs;
1358 qmp_ufs_configure(pcs, tbls->pcs, tbls->pcs_num);
1361 static void qmp_ufs_init_registers(struct qmp_ufs *qmp, const struct qmp_phy_cfg *cfg)
1363 qmp_ufs_serdes_init(qmp, &cfg->tbls);
1364 if (qmp->mode == PHY_MODE_UFS_HS_B)
1365 qmp_ufs_serdes_init(qmp, &cfg->tbls_hs_b);
1366 qmp_ufs_lanes_init(qmp, &cfg->tbls);
1367 if (qmp->submode == UFS_HS_G4)
1368 qmp_ufs_lanes_init(qmp, &cfg->tbls_hs_g4);
1369 qmp_ufs_pcs_init(qmp, &cfg->tbls);
1370 if (qmp->submode == UFS_HS_G4)
1371 qmp_ufs_pcs_init(qmp, &cfg->tbls_hs_g4);
1374 static int qmp_ufs_com_init(struct qmp_ufs *qmp)
1376 const struct qmp_phy_cfg *cfg = qmp->cfg;
1377 void __iomem *pcs = qmp->pcs;
1380 ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
1382 dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret);
1386 ret = clk_bulk_prepare_enable(cfg->num_clks, qmp->clks);
1388 goto err_disable_regulators;
1390 qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
1394 err_disable_regulators:
1395 regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
1400 static int qmp_ufs_com_exit(struct qmp_ufs *qmp)
1402 const struct qmp_phy_cfg *cfg = qmp->cfg;
1404 reset_control_assert(qmp->ufs_reset);
1406 clk_bulk_disable_unprepare(cfg->num_clks, qmp->clks);
1408 regulator_bulk_disable(cfg->num_vregs, qmp->vregs);
1413 static int qmp_ufs_init(struct phy *phy)
1415 struct qmp_ufs *qmp = phy_get_drvdata(phy);
1416 const struct qmp_phy_cfg *cfg = qmp->cfg;
1418 dev_vdbg(qmp->dev, "Initializing QMP phy\n");
1420 if (cfg->no_pcs_sw_reset) {
1422 * Get UFS reset, which is delayed until now to avoid a
1423 * circular dependency where UFS needs its PHY, but the PHY
1424 * needs this UFS reset.
1426 if (!qmp->ufs_reset) {
1428 devm_reset_control_get_exclusive(qmp->dev,
1431 if (IS_ERR(qmp->ufs_reset)) {
1432 ret = PTR_ERR(qmp->ufs_reset);
1434 "failed to get UFS reset: %d\n",
1437 qmp->ufs_reset = NULL;
1442 ret = reset_control_assert(qmp->ufs_reset);
1447 ret = qmp_ufs_com_init(qmp);
1454 static int qmp_ufs_power_on(struct phy *phy)
1456 struct qmp_ufs *qmp = phy_get_drvdata(phy);
1457 const struct qmp_phy_cfg *cfg = qmp->cfg;
1458 void __iomem *pcs = qmp->pcs;
1459 void __iomem *status;
1463 qmp_ufs_init_registers(qmp, cfg);
1465 ret = reset_control_deassert(qmp->ufs_reset);
1469 /* Pull PHY out of reset state */
1470 if (!cfg->no_pcs_sw_reset)
1471 qphy_clrbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
1474 qphy_setbits(pcs, cfg->regs[QPHY_START_CTRL], SERDES_START);
1476 status = pcs + cfg->regs[QPHY_PCS_READY_STATUS];
1477 ret = readl_poll_timeout(status, val, (val & PCS_READY), 200,
1478 PHY_INIT_COMPLETE_TIMEOUT);
1480 dev_err(qmp->dev, "phy initialization timed-out\n");
1487 static int qmp_ufs_power_off(struct phy *phy)
1489 struct qmp_ufs *qmp = phy_get_drvdata(phy);
1490 const struct qmp_phy_cfg *cfg = qmp->cfg;
1493 if (!cfg->no_pcs_sw_reset)
1494 qphy_setbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
1497 qphy_clrbits(qmp->pcs, cfg->regs[QPHY_START_CTRL], SERDES_START);
1499 /* Put PHY into POWER DOWN state: active low */
1500 qphy_clrbits(qmp->pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL],
1506 static int qmp_ufs_exit(struct phy *phy)
1508 struct qmp_ufs *qmp = phy_get_drvdata(phy);
1510 qmp_ufs_com_exit(qmp);
1515 static int qmp_ufs_enable(struct phy *phy)
1519 ret = qmp_ufs_init(phy);
1523 ret = qmp_ufs_power_on(phy);
1530 static int qmp_ufs_disable(struct phy *phy)
1534 ret = qmp_ufs_power_off(phy);
1537 return qmp_ufs_exit(phy);
1540 static int qmp_ufs_set_mode(struct phy *phy, enum phy_mode mode, int submode)
1542 struct qmp_ufs *qmp = phy_get_drvdata(phy);
1545 qmp->submode = submode;
1550 static const struct phy_ops qcom_qmp_ufs_phy_ops = {
1551 .power_on = qmp_ufs_enable,
1552 .power_off = qmp_ufs_disable,
1553 .set_mode = qmp_ufs_set_mode,
1554 .owner = THIS_MODULE,
1557 static int qmp_ufs_vreg_init(struct qmp_ufs *qmp)
1559 const struct qmp_phy_cfg *cfg = qmp->cfg;
1560 struct device *dev = qmp->dev;
1561 int num = cfg->num_vregs;
1564 qmp->vregs = devm_kcalloc(dev, num, sizeof(*qmp->vregs), GFP_KERNEL);
1568 for (i = 0; i < num; i++)
1569 qmp->vregs[i].supply = cfg->vreg_list[i];
1571 return devm_regulator_bulk_get(dev, num, qmp->vregs);
1574 static int qmp_ufs_clk_init(struct qmp_ufs *qmp)
1576 const struct qmp_phy_cfg *cfg = qmp->cfg;
1577 struct device *dev = qmp->dev;
1578 int num = cfg->num_clks;
1581 qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL);
1585 for (i = 0; i < num; i++)
1586 qmp->clks[i].id = cfg->clk_list[i];
1588 return devm_clk_bulk_get(dev, num, qmp->clks);
1591 static void qmp_ufs_clk_release_provider(void *res)
1593 of_clk_del_provider(res);
1596 #define UFS_SYMBOL_CLOCKS 3
1598 static int qmp_ufs_register_clocks(struct qmp_ufs *qmp, struct device_node *np)
1600 struct clk_hw_onecell_data *clk_data;
1605 clk_data = devm_kzalloc(qmp->dev,
1606 struct_size(clk_data, hws, UFS_SYMBOL_CLOCKS),
1611 clk_data->num = UFS_SYMBOL_CLOCKS;
1613 snprintf(name, sizeof(name), "%s::rx_symbol_0", dev_name(qmp->dev));
1614 hw = devm_clk_hw_register_fixed_rate(qmp->dev, name, NULL, 0, 0);
1618 clk_data->hws[0] = hw;
1620 snprintf(name, sizeof(name), "%s::rx_symbol_1", dev_name(qmp->dev));
1621 hw = devm_clk_hw_register_fixed_rate(qmp->dev, name, NULL, 0, 0);
1625 clk_data->hws[1] = hw;
1627 snprintf(name, sizeof(name), "%s::tx_symbol_0", dev_name(qmp->dev));
1628 hw = devm_clk_hw_register_fixed_rate(qmp->dev, name, NULL, 0, 0);
1632 clk_data->hws[2] = hw;
1634 ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
1639 * Roll a devm action because the clock provider can be a child node.
1641 return devm_add_action_or_reset(qmp->dev, qmp_ufs_clk_release_provider, np);
1644 static int qmp_ufs_parse_dt_legacy(struct qmp_ufs *qmp, struct device_node *np)
1646 struct platform_device *pdev = to_platform_device(qmp->dev);
1647 const struct qmp_phy_cfg *cfg = qmp->cfg;
1648 struct device *dev = qmp->dev;
1650 qmp->serdes = devm_platform_ioremap_resource(pdev, 0);
1651 if (IS_ERR(qmp->serdes))
1652 return PTR_ERR(qmp->serdes);
1655 * Get memory resources for the PHY:
1656 * Resources are indexed as: tx -> 0; rx -> 1; pcs -> 2.
1657 * For dual lane PHYs: tx2 -> 3, rx2 -> 4, pcs_misc (optional) -> 5
1658 * For single lane PHYs: pcs_misc (optional) -> 3.
1660 qmp->tx = devm_of_iomap(dev, np, 0, NULL);
1661 if (IS_ERR(qmp->tx))
1662 return PTR_ERR(qmp->tx);
1664 qmp->rx = devm_of_iomap(dev, np, 1, NULL);
1665 if (IS_ERR(qmp->rx))
1666 return PTR_ERR(qmp->rx);
1668 qmp->pcs = devm_of_iomap(dev, np, 2, NULL);
1669 if (IS_ERR(qmp->pcs))
1670 return PTR_ERR(qmp->pcs);
1672 if (cfg->lanes >= 2) {
1673 qmp->tx2 = devm_of_iomap(dev, np, 3, NULL);
1674 if (IS_ERR(qmp->tx2))
1675 return PTR_ERR(qmp->tx2);
1677 qmp->rx2 = devm_of_iomap(dev, np, 4, NULL);
1678 if (IS_ERR(qmp->rx2))
1679 return PTR_ERR(qmp->rx2);
1681 qmp->pcs_misc = devm_of_iomap(dev, np, 5, NULL);
1683 qmp->pcs_misc = devm_of_iomap(dev, np, 3, NULL);
1686 if (IS_ERR(qmp->pcs_misc))
1687 dev_vdbg(dev, "PHY pcs_misc-reg not used\n");
1692 static int qmp_ufs_parse_dt(struct qmp_ufs *qmp)
1694 struct platform_device *pdev = to_platform_device(qmp->dev);
1695 const struct qmp_phy_cfg *cfg = qmp->cfg;
1696 const struct qmp_ufs_offsets *offs = cfg->offsets;
1702 base = devm_platform_ioremap_resource(pdev, 0);
1704 return PTR_ERR(base);
1706 qmp->serdes = base + offs->serdes;
1707 qmp->pcs = base + offs->pcs;
1708 qmp->tx = base + offs->tx;
1709 qmp->rx = base + offs->rx;
1711 if (cfg->lanes >= 2) {
1712 qmp->tx2 = base + offs->tx2;
1713 qmp->rx2 = base + offs->rx2;
1719 static int qmp_ufs_probe(struct platform_device *pdev)
1721 struct device *dev = &pdev->dev;
1722 struct phy_provider *phy_provider;
1723 struct device_node *np;
1724 struct qmp_ufs *qmp;
1727 qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL);
1733 qmp->cfg = of_device_get_match_data(dev);
1737 ret = qmp_ufs_clk_init(qmp);
1741 ret = qmp_ufs_vreg_init(qmp);
1745 /* Check for legacy binding with child node. */
1746 np = of_get_next_available_child(dev->of_node, NULL);
1748 ret = qmp_ufs_parse_dt_legacy(qmp, np);
1750 np = of_node_get(dev->of_node);
1751 ret = qmp_ufs_parse_dt(qmp);
1756 ret = qmp_ufs_register_clocks(qmp, np);
1760 qmp->phy = devm_phy_create(dev, np, &qcom_qmp_ufs_phy_ops);
1761 if (IS_ERR(qmp->phy)) {
1762 ret = PTR_ERR(qmp->phy);
1763 dev_err(dev, "failed to create PHY: %d\n", ret);
1767 phy_set_drvdata(qmp->phy, qmp);
1771 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
1773 return PTR_ERR_OR_ZERO(phy_provider);
1780 static const struct of_device_id qmp_ufs_of_match_table[] = {
1782 .compatible = "qcom,msm8996-qmp-ufs-phy",
1783 .data = &msm8996_ufsphy_cfg,
1785 .compatible = "qcom,msm8998-qmp-ufs-phy",
1786 .data = &sdm845_ufsphy_cfg,
1788 .compatible = "qcom,sa8775p-qmp-ufs-phy",
1789 .data = &sa8775p_ufsphy_cfg,
1791 .compatible = "qcom,sc7280-qmp-ufs-phy",
1792 .data = &sc7280_ufsphy_cfg,
1794 .compatible = "qcom,sc8180x-qmp-ufs-phy",
1795 .data = &sm8150_ufsphy_cfg,
1797 .compatible = "qcom,sc8280xp-qmp-ufs-phy",
1798 .data = &sc8280xp_ufsphy_cfg,
1800 .compatible = "qcom,sdm845-qmp-ufs-phy",
1801 .data = &sdm845_ufsphy_cfg,
1803 .compatible = "qcom,sm6115-qmp-ufs-phy",
1804 .data = &sm6115_ufsphy_cfg,
1806 .compatible = "qcom,sm6125-qmp-ufs-phy",
1807 .data = &sm6115_ufsphy_cfg,
1809 .compatible = "qcom,sm6350-qmp-ufs-phy",
1810 .data = &sdm845_ufsphy_cfg,
1812 .compatible = "qcom,sm7150-qmp-ufs-phy",
1813 .data = &sm7150_ufsphy_cfg,
1815 .compatible = "qcom,sm8150-qmp-ufs-phy",
1816 .data = &sm8150_ufsphy_cfg,
1818 .compatible = "qcom,sm8250-qmp-ufs-phy",
1819 .data = &sm8250_ufsphy_cfg,
1821 .compatible = "qcom,sm8350-qmp-ufs-phy",
1822 .data = &sm8350_ufsphy_cfg,
1824 .compatible = "qcom,sm8450-qmp-ufs-phy",
1825 .data = &sm8450_ufsphy_cfg,
1827 .compatible = "qcom,sm8550-qmp-ufs-phy",
1828 .data = &sm8550_ufsphy_cfg,
1832 MODULE_DEVICE_TABLE(of, qmp_ufs_of_match_table);
1834 static struct platform_driver qmp_ufs_driver = {
1835 .probe = qmp_ufs_probe,
1837 .name = "qcom-qmp-ufs-phy",
1838 .of_match_table = qmp_ufs_of_match_table,
1842 module_platform_driver(qmp_ufs_driver);
1845 MODULE_DESCRIPTION("Qualcomm QMP UFS PHY driver");
1846 MODULE_LICENSE("GPL v2");