1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Rockchip HDMI/DP Combo PHY with Samsung IP block
4 *
5 * Copyright (c) 2021 Rockchip Electronics Co. Ltd.
6 */
7
8 #include <common.h>
9 #include <clk-uclass.h>
10 #include <dm.h>
11 #include <reset.h>
12 #include <regmap.h>
13 #include <syscon.h>
14 #include <asm/io.h>
15 #include <linux/bitfield.h>
16 #include <linux/rational.h>
17 #include <linux/iopoll.h>
18 #include <asm/arch/clock.h>
19 #include <dm/lists.h>
20 #include <dm/of_access.h>
21
22 #include "rockchip_display.h"
23 #include "rockchip_crtc.h"
24 #include "rockchip_phy.h"
25
26 #define UPDATE(x, h, l) (((x) << (l)) & GENMASK((h), (l)))
27
28 #define GRF_HDPTX_CON0 0x00
29 #define LC_REF_CLK_SEL BIT(11)
30 #define HDPTX_I_PLL_EN BIT(7)
31 #define HDPTX_I_BIAS_EN BIT(6)
32 #define HDPTX_I_BGR_EN BIT(5)
33 #define GRF_HDPTX_STATUS 0x80
34 #define HDPTX_O_PLL_LOCK_DONE BIT(3)
35 #define HDPTX_O_PHY_CLK_RDY BIT(2)
36 #define HDPTX_O_PHY_RDY BIT(1)
37 #define HDPTX_O_SB_RDY BIT(0)
38
39 #define CMN_REG0000 0x0000
40 #define CMN_REG0001 0x0004
41 #define CMN_REG0002 0x0008
42 #define CMN_REG0003 0x000C
43 #define CMN_REG0004 0x0010
44 #define CMN_REG0005 0x0014
45 #define CMN_REG0006 0x0018
46 #define CMN_REG0007 0x001C
47 #define CMN_REG0008 0x0020
48 #define LCPLL_EN_MASK BIT(6)
49 #define LCPLL_EN(x) UPDATE(x, 4, 4)
50 #define LCPLL_LCVCO_MODE_EN_MASK BIT(4)
51 #define LCPLL_LCVCO_MODE_EN(x) UPDATE(x, 4, 4)
52 #define CMN_REG0009 0x0024
53 #define CMN_REG000A 0x0028
54 #define CMN_REG000B 0x002C
55 #define CMN_REG000C 0x0030
56 #define CMN_REG000D 0x0034
57 #define CMN_REG000E 0x0038
58 #define CMN_REG000F 0x003C
59 #define CMN_REG0010 0x0040
60 #define CMN_REG0011 0x0044
61 #define CMN_REG0012 0x0048
62 #define CMN_REG0013 0x004C
63 #define CMN_REG0014 0x0050
64 #define CMN_REG0015 0x0054
65 #define CMN_REG0016 0x0058
66 #define CMN_REG0017 0x005C
67 #define CMN_REG0018 0x0060
68 #define CMN_REG0019 0x0064
69 #define CMN_REG001A 0x0068
70 #define CMN_REG001B 0x006C
71 #define CMN_REG001C 0x0070
72 #define CMN_REG001D 0x0074
73 #define CMN_REG001E 0x0078
74 #define LCPLL_PI_EN_MASK BIT(5)
75 #define LCPLL_PI_EN(x) UPDATE(x, 5, 5)
76 #define LCPLL_100M_CLK_EN_MASK BIT(0)
77 #define LCPLL_100M_CLK_EN(x) UPDATE(x, 0, 0)
78 #define CMN_REG001F 0x007C
79 #define CMN_REG0020 0x0080
80 #define CMN_REG0021 0x0084
81 #define CMN_REG0022 0x0088
82 #define CMN_REG0023 0x008C
83 #define CMN_REG0024 0x0090
84 #define CMN_REG0025 0x0094
85 #define LCPLL_PMS_IQDIV_RSTN BIT(4)
86 #define CMN_REG0026 0x0098
87 #define CMN_REG0027 0x009C
88 #define CMN_REG0028 0x00A0
89 #define LCPLL_SDC_FRAC_EN BIT(2)
90 #define LCPLL_SDC_FRAC_RSTN BIT(0)
91 #define CMN_REG0029 0x00A4
92 #define CMN_REG002A 0x00A8
93 #define CMN_REG002B 0x00AC
94 #define CMN_REG002C 0x00B0
95 #define CMN_REG002D 0x00B4
96 #define LCPLL_SDC_N_MASK GENMASK(3, 1)
97 #define LCPLL_SDC_N(x) UPDATE(x, 3, 1)
98 #define CMN_REG002E 0x00B8
99 #define LCPLL_SDC_NUMBERATOR_MASK GENMASK(5, 0)
100 #define LCPLL_SDC_NUMBERATOR(x) UPDATE(x, 5, 0)
101 #define CMN_REG002F 0x00BC
102 #define LCPLL_SDC_DENOMINATOR_MASK GENMASK(7, 2)
103 #define LCPLL_SDC_DENOMINATOR(x) UPDATE(x, 7, 2)
104 #define LCPLL_SDC_NDIV_RSTN BIT(0)
105 #define CMN_REG0030 0x00C0
106 #define CMN_REG0031 0x00C4
107 #define CMN_REG0032 0x00C8
108 #define CMN_REG0033 0x00CC
109 #define CMN_REG0034 0x00D0
110 #define CMN_REG0035 0x00D4
111 #define CMN_REG0036 0x00D8
112 #define CMN_REG0037 0x00DC
113 #define CMN_REG0038 0x00E0
114 #define CMN_REG0039 0x00E4
115 #define CMN_REG003A 0x00E8
116 #define CMN_REG003B 0x00EC
117 #define CMN_REG003C 0x00F0
118 #define CMN_REG003D 0x00F4
119 #define ROPLL_LCVCO_EN BIT(4)
120 #define CMN_REG003E 0x00F8
121 #define CMN_REG003F 0x00FC
122 #define CMN_REG0040 0x0100
123 #define CMN_REG0041 0x0104
124 #define CMN_REG0042 0x0108
125 #define CMN_REG0043 0x010C
126 #define CMN_REG0044 0x0110
127 #define CMN_REG0045 0x0114
128 #define CMN_REG0046 0x0118
129 #define CMN_REG0047 0x011C
130 #define CMN_REG0048 0x0120
131 #define CMN_REG0049 0x0124
132 #define CMN_REG004A 0x0128
133 #define CMN_REG004B 0x012C
134 #define CMN_REG004C 0x0130
135 #define CMN_REG004D 0x0134
136 #define CMN_REG004E 0x0138
137 #define ROPLL_PI_EN BIT(5)
138 #define CMN_REG004F 0x013C
139 #define CMN_REG0050 0x0140
140 #define CMN_REG0051 0x0144
141 #define CMN_REG0052 0x0148
142 #define CMN_REG0053 0x014C
143 #define CMN_REG0054 0x0150
144 #define CMN_REG0055 0x0154
145 #define CMN_REG0056 0x0158
146 #define CMN_REG0057 0x015C
147 #define CMN_REG0058 0x0160
148 #define CMN_REG0059 0x0164
149 #define CMN_REG005A 0x0168
150 #define CMN_REG005B 0x016C
151 #define CMN_REG005C 0x0170
152 #define ROPLL_PMS_IQDIV_RSTN BIT(5)
153 #define CMN_REG005D 0x0174
154 #define CMN_REG005E 0x0178
155 #define ROPLL_SDM_EN_MASK BIT(6)
156 #define ROPLL_SDM_EN(x) UPDATE(x, 6, 6)
157 #define ROPLL_SDM_FRAC_EN_RBR BIT(3)
158 #define ROPLL_SDM_FRAC_EN_HBR BIT(2)
159 #define ROPLL_SDM_FRAC_EN_HBR2 BIT(1)
160 #define ROPLL_SDM_FRAC_EN_HBR3 BIT(0)
161 #define CMN_REG005F 0x017C
162 #define CMN_REG0060 0x0180
163 #define CMN_REG0061 0x0184
164 #define CMN_REG0062 0x0188
165 #define CMN_REG0063 0x018C
166 #define CMN_REG0064 0x0190
167 #define ROPLL_SDM_NUM_SIGN_RBR_MASK BIT(3)
168 #define ROPLL_SDM_NUM_SIGN_RBR(x) UPDATE(x, 3, 3)
169 #define CMN_REG0065 0x0194
170 #define CMN_REG0066 0x0198
171 #define CMN_REG0067 0x019C
172 #define CMN_REG0068 0x01A0
173 #define CMN_REG0069 0x01A4
174 #define ROPLL_SDC_N_RBR_MASK GENMASK(2, 0)
175 #define ROPLL_SDC_N_RBR(x) UPDATE(x, 2, 0)
176 #define CMN_REG006A 0x01A8
177 #define CMN_REG006B 0x01AC
178 #define CMN_REG006C 0x01B0
179 #define CMN_REG006D 0x01B4
180 #define CMN_REG006E 0x01B8
181 #define CMN_REG006F 0x01BC
182 #define CMN_REG0070 0x01C0
183 #define CMN_REG0071 0x01C4
184 #define CMN_REG0072 0x01C8
185 #define CMN_REG0073 0x01CC
186 #define CMN_REG0074 0x01D0
187 #define ROPLL_SDC_NDIV_RSTN BIT(2)
188 #define ROPLL_SSC_EN BIT(0)
189 #define CMN_REG0075 0x01D4
190 #define CMN_REG0076 0x01D8
191 #define CMN_REG0077 0x01DC
192 #define CMN_REG0078 0x01E0
193 #define CMN_REG0079 0x01E4
194 #define CMN_REG007A 0x01E8
195 #define CMN_REG007B 0x01EC
196 #define CMN_REG007C 0x01F0
197 #define CMN_REG007D 0x01F4
198 #define CMN_REG007E 0x01F8
199 #define CMN_REG007F 0x01FC
200 #define CMN_REG0080 0x0200
201 #define CMN_REG0081 0x0204
202 #define OVRD_PLL_CD_CLK_EN BIT(8)
203 #define PLL_CD_HSCLK_EAST_EN BIT(0)
204 #define CMN_REG0082 0x0208
205 #define CMN_REG0083 0x020C
206 #define CMN_REG0084 0x0210
207 #define CMN_REG0085 0x0214
208 #define CMN_REG0086 0x0218
209 #define PLL_PCG_POSTDIV_SEL_MASK GENMASK(7, 4)
210 #define PLL_PCG_POSTDIV_SEL(x) UPDATE(x, 7, 4)
211 #define PLL_PCG_CLK_SEL_MASK GENMASK(3, 1)
212 #define PLL_PCG_CLK_SEL(x) UPDATE(x, 3, 1)
213 #define PLL_PCG_CLK_EN BIT(0)
214 #define CMN_REG0087 0x021C
215 #define PLL_FRL_MODE_EN BIT(3)
216 #define PLL_TX_HS_CLK_EN BIT(2)
217 #define CMN_REG0088 0x0220
218 #define CMN_REG0089 0x0224
219 #define LCPLL_ALONE_MODE BIT(1)
220 #define CMN_REG008A 0x0228
221 #define CMN_REG008B 0x022C
222 #define CMN_REG008C 0x0230
223 #define CMN_REG008D 0x0234
224 #define CMN_REG008E 0x0238
225 #define CMN_REG008F 0x023C
226 #define CMN_REG0090 0x0240
227 #define CMN_REG0091 0x0244
228 #define CMN_REG0092 0x0248
229 #define CMN_REG0093 0x024C
230 #define CMN_REG0094 0x0250
231 #define CMN_REG0095 0x0254
232 #define CMN_REG0096 0x0258
233 #define CMN_REG0097 0x025C
234 #define DIG_CLK_SEL BIT(1)
235 #define ROPLL_REF BIT(1)
236 #define LCPLL_REF 0
237 #define CMN_REG0098 0x0260
238 #define CMN_REG0099 0x0264
239 #define CMN_ROPLL_ALONE_MODE BIT(2)
240 #define ROPLL_ALONE_MODE BIT(2)
241 #define CMN_REG009A 0x0268
242 #define HS_SPEED_SEL BIT(0)
243 #define DIV_10_CLOCK BIT(0)
244 #define CMN_REG009B 0x026C
245 #define IS_SPEED_SEL BIT(4)
246 #define LINK_SYMBOL_CLOCK BIT(4)
247 #define LINK_SYMBOL_CLOCK1_2 0
248 #define CMN_REG009C 0x0270
249 #define CMN_REG009D 0x0274
250 #define CMN_REG009E 0x0278
251 #define CMN_REG009F 0x027C
252 #define CMN_REG00A0 0x0280
253 #define CMN_REG00A1 0x0284
254 #define CMN_REG00A2 0x0288
255 #define CMN_REG00A3 0x028C
256 #define CMN_REG00AD 0x0290
257 #define CMN_REG00A5 0x0294
258 #define CMN_REG00A6 0x0298
259 #define CMN_REG00A7 0x029C
260 #define SB_REG0100 0x0400
261 #define SB_REG0101 0x0404
262 #define SB_REG0102 0x0408
263 #define OVRD_SB_RXTERM_EN_MASK BIT(5)
264 #define OVRD_SB_RXTERM_EN(x) UPDATE(x, 5, 5)
265 #define SB_RXTERM_EN_MASK BIT(4)
266 #define SB_RXTERM_EN(x) UPDATE(x, 4, 4)
267 #define ANA_SB_RXTERM_OFFSP_MASK GENMASK(3, 0)
268 #define ANA_SB_RXTERM_OFFSP(x) UPDATE(x, 3, 0)
269 #define SB_REG0103 0x040C
270 #define ANA_SB_RXTERM_OFFSN_MASK GENMASK(6, 3)
271 #define ANA_SB_RXTERM_OFFSN(x) UPDATE(x, 6, 3)
272 #define OVRD_SB_RX_RESCAL_DONE_MASK BIT(1)
273 #define OVRD_SB_RX_RESCAL_DONE(x) UPDATE(x, 1, 1)
274 #define SB_RX_RESCAL_DONE_MASK BIT(0)
275 #define SB_RX_RESCAL_DONE(x) UPDATE(x, 0, 0)
276 #define SB_REG0104 0x0410
277 #define OVRD_SB_EN_MASK BIT(5)
278 #define OVRD_SB_EN(x) UPDATE(x, 5, 5)
279 #define SB_EN_MASK BIT(4)
280 #define SB_EN(x) UPDATE(x, 4, 4)
281 #define SB_REG0105 0x0414
282 #define OVRD_SB_EARC_CMDC_EN_MASK BIT(6)
283 #define OVRD_SB_EARC_CMDC_EN(x) UPDATE(x, 6, 6)
284 #define SB_EARC_CMDC_EN_MASK BIT(5)
285 #define SB_EARC_CMDC_EN(x) UPDATE(x, 5, 5)
286 #define ANA_SB_TX_HLVL_PROG_MASK GENMASK(2, 0)
287 #define ANA_SB_TX_HLVL_PROG(x) UPDATE(x, 2, 0)
288 #define SB_REG0106 0x0418
289 #define ANA_SB_TX_LLVL_PROG_MASK GENMASK(6, 4)
290 #define ANA_SB_TX_LLVL_PROG(x) UPDATE(x, 6, 4)
291 #define SB_REG0107 0x041C
292 #define SB_REG0108 0x0420
293 #define SB_REG0109 0x0424
294 #define ANA_SB_DMRX_AFC_DIV_RATIO_MASK GENMASK(2, 0)
295 #define ANA_SB_DMRX_AFC_DIV_RATIO(x) UPDATE(x, 2, 0)
296 #define SB_REG010A 0x0428
297 #define SB_REG010B 0x042C
298 #define SB_REG010C 0x0430
299 #define SB_REG010D 0x0434
300 #define SB_REG010E 0x0438
301 #define SB_REG010F 0x043C
302 #define OVRD_SB_VREG_EN_MASK BIT(7)
303 #define OVRD_SB_VREG_EN(x) UPDATE(x, 7, 7)
304 #define SB_VREG_EN_MASK BIT(6)
305 #define SB_VREG_EN(x) UPDATE(x, 6, 6)
306 #define OVRD_SB_VREG_LPF_BYPASS_MASK BIT(5)
307 #define OVRD_SB_VREG_LPF_BYPASS(x) UPDATE(x, 5, 5)
308 #define SB_VREG_LPF_BYPASS_MASK BIT(4)
309 #define SB_VREG_LPF_BYPASS(x) UPDATE(x, 4, 4)
310 #define ANA_SB_VREG_GAIN_CTRL_MASK GENMASK(3, 0)
311 #define ANA_SB_VREG_GAIN_CTRL(x) UPDATE(x, 3, 0)
312 #define SB_REG0110 0x0440
313 #define ANA_SB_VREG_REF_SEL_MASK BIT(0)
314 #define ANA_SB_VREG_REF_SEL(x) UPDATE(x, 0, 0)
315 #define SB_REG0111 0x0444
316 #define SB_REG0112 0x0448
317 #define SB_REG0113 0x044C
318 #define SB_RX_RCAL_OPT_CODE_MASK GENMASK(5, 4)
319 #define SB_RX_RCAL_OPT_CODE(x) UPDATE(x, 5, 4)
320 #define SB_RX_RTERM_CTRL_MASK GENMASK(3, 0)
321 #define SB_RX_RTERM_CTRL(x) UPDATE(x, 3, 0)
322 #define SB_REG0114 0x0450
323 #define SB_TG_SB_EN_DELAY_TIME_MASK GENMASK(5, 3)
324 #define SB_TG_SB_EN_DELAY_TIME(x) UPDATE(x, 5, 3)
325 #define SB_TG_RXTERM_EN_DELAY_TIME_MASK GENMASK(2, 0)
326 #define SB_TG_RXTERM_EN_DELAY_TIME(x) UPDATE(x, 2, 0)
327 #define SB_REG0115 0x0454
328 #define SB_READY_DELAY_TIME_MASK GENMASK(5, 3)
329 #define SB_READY_DELAY_TIME(x) UPDATE(x, 5, 3)
330 #define SB_TG_OSC_EN_DELAY_TIME_MASK GENMASK(2, 0)
331 #define SB_TG_OSC_EN_DELAY_TIME(x) UPDATE(x, 2, 0)
332 #define SB_REG0116 0x0458
333 #define AFC_RSTN_DELAY_TIME_MASK GENMASK(6, 4)
334 #define AFC_RSTN_DELAY_TIME(x) UPDATE(x, 6, 4)
335 #define SB_REG0117 0x045C
336 #define FAST_PULSE_TIME_MASK GENMASK(3, 0)
337 #define FAST_PULSE_TIME(x) UPDATE(x, 3, 0)
338 #define SB_REG0118 0x0460
339 #define SB_REG0119 0x0464
340 #define SB_REG011A 0x0468
341 #define SB_REG011B 0x046C
342 #define SB_EARC_SIG_DET_BYPASS_MASK BIT(4)
343 #define SB_EARC_SIG_DET_BYPASS(x) UPDATE(x, 4, 4)
344 #define SB_AFC_TOL_MASK GENMASK(3, 0)
345 #define SB_AFC_TOL(x) UPDATE(x, 3, 0)
346 #define SB_REG011C 0x0470
347 #define SB_REG011D 0x0474
348 #define SB_REG011E 0x0478
349 #define SB_REG011F 0x047C
350 #define SB_PWM_AFC_CTRL_MASK GENMASK(7, 2)
351 #define SB_PWM_AFC_CTRL(x) UPDATE(x, 7, 2)
352 #define SB_RCAL_RSTN_MASK BIT(1)
353 #define SB_RCAL_RSTN(x) UPDATE(x, 1, 1)
354 #define SB_REG0120 0x0480
355 #define SB_EARC_EN_MASK BIT(1)
356 #define SB_EARC_EN(x) UPDATE(x, 1, 1)
357 #define SB_EARC_AFC_EN_MASK BIT(2)
358 #define SB_EARC_AFC_EN(x) UPDATE(x, 2, 2)
359 #define SB_REG0121 0x0484
360 #define SB_REG0122 0x0488
361 #define SB_REG0123 0x048C
362 #define OVRD_SB_READY_MASK BIT(5)
363 #define OVRD_SB_READY(x) UPDATE(x, 5, 5)
364 #define SB_READY_MASK BIT(4)
365 #define SB_READY(x) UPDATE(x, 4, 4)
366 #define SB_REG0124 0x0490
367 #define SB_REG0125 0x0494
368 #define SB_REG0126 0x0498
369 #define SB_REG0127 0x049C
370 #define SB_REG0128 0x04A0
371 #define SB_REG0129 0x04AD
372 #define LNTOP_REG0200 0x0800
373 #define PROTOCOL_SEL BIT(2)
374 #define HDMI_MODE BIT(2)
375 #define HDMI_TMDS_FRL_SEL BIT(1)
376 #define LNTOP_REG0201 0x0804
377 #define LNTOP_REG0202 0x0808
378 #define LNTOP_REG0203 0x080C
379 #define LNTOP_REG0204 0x0810
380 #define LNTOP_REG0205 0x0814
381 #define LNTOP_REG0206 0x0818
382 #define DATA_BUS_WIDTH (0x3 << 1)
383 #define WIDTH_40BIT (0x3 << 1)
384 #define WIDTH_36BIT (0x2 << 1)
385 #define DATA_BUS_SEL BIT(0)
386 #define DATA_BUS_36_40 BIT(0)
387 #define LNTOP_REG0207 0x081C
388 #define LANE_EN 0xf
389 #define ALL_LANE_EN 0xf
390 #define LNTOP_REG0208 0x0820
391 #define LNTOP_REG0209 0x0824
392 #define LNTOP_REG020A 0x0828
393 #define LNTOP_REG020B 0x082C
394 #define LNTOP_REG020C 0x0830
395 #define LNTOP_REG020D 0x0834
396 #define LNTOP_REG020E 0x0838
397 #define LNTOP_REG020F 0x083C
398 #define LNTOP_REG0210 0x0840
399 #define LNTOP_REG0211 0x0844
400 #define LNTOP_REG0212 0x0848
401 #define LNTOP_REG0213 0x084C
402 #define LNTOP_REG0214 0x0850
403 #define LNTOP_REG0215 0x0854
404 #define LNTOP_REG0216 0x0858
405 #define LNTOP_REG0217 0x085C
406 #define LNTOP_REG0218 0x0860
407 #define LNTOP_REG0219 0x0864
408 #define LNTOP_REG021A 0x0868
409 #define LNTOP_REG021B 0x086C
410 #define LNTOP_REG021C 0x0870
411 #define LNTOP_REG021D 0x0874
412 #define LNTOP_REG021E 0x0878
413 #define LNTOP_REG021F 0x087C
414 #define LNTOP_REG0220 0x0880
415 #define LNTOP_REG0221 0x0884
416 #define LNTOP_REG0222 0x0888
417 #define LNTOP_REG0223 0x088C
418 #define LNTOP_REG0224 0x0890
419 #define LNTOP_REG0225 0x0894
420 #define LNTOP_REG0226 0x0898
421 #define LNTOP_REG0227 0x089C
422 #define LNTOP_REG0228 0x08A0
423 #define LNTOP_REG0229 0x08A4
424 #define LANE_REG0300 0x0C00
425 #define LANE_REG0301 0x0C04
426 #define LANE_REG0302 0x0C08
427 #define LANE_REG0303 0x0C0C
428 #define LANE_REG0304 0x0C10
429 #define LANE_REG0305 0x0C14
430 #define LANE_REG0306 0x0C18
431 #define LANE_REG0307 0x0C1C
432 #define LANE_REG0308 0x0C20
433 #define LANE_REG0309 0x0C24
434 #define LANE_REG030A 0x0C28
435 #define LANE_REG030B 0x0C2C
436 #define LANE_REG030C 0x0C30
437 #define LANE_REG030D 0x0C34
438 #define LANE_REG030E 0x0C38
439 #define LANE_REG030F 0x0C3C
440 #define LANE_REG0310 0x0C40
441 #define LANE_REG0311 0x0C44
442 #define LANE_REG0312 0x0C48
443 #define LN0_TX_SER_RATE_SEL_RBR BIT(5)
444 #define LN0_TX_SER_RATE_SEL_HBR BIT(4)
445 #define LN0_TX_SER_RATE_SEL_HBR2 BIT(3)
446 #define LN0_TX_SER_RATE_SEL_HBR3 BIT(2)
447 #define LANE_REG0313 0x0C4C
448 #define LANE_REG0314 0x0C50
449 #define LANE_REG0315 0x0C54
450 #define LANE_REG0316 0x0C58
451 #define LANE_REG0317 0x0C5C
452 #define LANE_REG0318 0x0C60
453 #define LANE_REG0319 0x0C64
454 #define LANE_REG031A 0x0C68
455 #define LANE_REG031B 0x0C6C
456 #define LANE_REG031C 0x0C70
457 #define LANE_REG031D 0x0C74
458 #define LANE_REG031E 0x0C78
459 #define LANE_REG031F 0x0C7C
460 #define LANE_REG0320 0x0C80
461 #define LANE_REG0321 0x0C84
462 #define LANE_REG0322 0x0C88
463 #define LANE_REG0323 0x0C8C
464 #define LANE_REG0324 0x0C90
465 #define LANE_REG0325 0x0C94
466 #define LANE_REG0326 0x0C98
467 #define LANE_REG0327 0x0C9C
468 #define LANE_REG0328 0x0CA0
469 #define LANE_REG0329 0x0CA4
470 #define LANE_REG032A 0x0CA8
471 #define LANE_REG032B 0x0CAC
472 #define LANE_REG032C 0x0CB0
473 #define LANE_REG032D 0x0CB4
474 #define LANE_REG0400 0x1000
475 #define LANE_REG0401 0x1004
476 #define LANE_REG0402 0x1008
477 #define LANE_REG0403 0x100C
478 #define LANE_REG0404 0x1010
479 #define LANE_REG0405 0x1014
480 #define LANE_REG0406 0x1018
481 #define LANE_REG0407 0x101C
482 #define LANE_REG0408 0x1020
483 #define LANE_REG0409 0x1024
484 #define LANE_REG040A 0x1028
485 #define LANE_REG040B 0x102C
486 #define LANE_REG040C 0x1030
487 #define LANE_REG040D 0x1034
488 #define LANE_REG040E 0x1038
489 #define LANE_REG040F 0x103C
490 #define LANE_REG0410 0x1040
491 #define LANE_REG0411 0x1044
492 #define LANE_REG0412 0x1048
493 #define LN1_TX_SER_RATE_SEL_RBR BIT(5)
494 #define LN1_TX_SER_RATE_SEL_HBR BIT(4)
495 #define LN1_TX_SER_RATE_SEL_HBR2 BIT(3)
496 #define LN1_TX_SER_RATE_SEL_HBR3 BIT(2)
497 #define LANE_REG0413 0x104C
498 #define LANE_REG0414 0x1050
499 #define LANE_REG0415 0x1054
500 #define LANE_REG0416 0x1058
501 #define LANE_REG0417 0x105C
502 #define LANE_REG0418 0x1060
503 #define LANE_REG0419 0x1064
504 #define LANE_REG041A 0x1068
505 #define LANE_REG041B 0x106C
506 #define LANE_REG041C 0x1070
507 #define LANE_REG041D 0x1074
508 #define LANE_REG041E 0x1078
509 #define LANE_REG041F 0x107C
510 #define LANE_REG0420 0x1080
511 #define LANE_REG0421 0x1084
512 #define LANE_REG0422 0x1088
513 #define LANE_REG0423 0x108C
514 #define LANE_REG0424 0x1090
515 #define LANE_REG0425 0x1094
516 #define LANE_REG0426 0x1098
517 #define LANE_REG0427 0x109C
518 #define LANE_REG0428 0x10A0
519 #define LANE_REG0429 0x10A4
520 #define LANE_REG042A 0x10A8
521 #define LANE_REG042B 0x10AC
522 #define LANE_REG042C 0x10B0
523 #define LANE_REG042D 0x10B4
524 #define LANE_REG0500 0x1400
525 #define LANE_REG0501 0x1404
526 #define LANE_REG0502 0x1408
527 #define LANE_REG0503 0x140C
528 #define LANE_REG0504 0x1410
529 #define LANE_REG0505 0x1414
530 #define LANE_REG0506 0x1418
531 #define LANE_REG0507 0x141C
532 #define LANE_REG0508 0x1420
533 #define LANE_REG0509 0x1424
534 #define LANE_REG050A 0x1428
535 #define LANE_REG050B 0x142C
536 #define LANE_REG050C 0x1430
537 #define LANE_REG050D 0x1434
538 #define LANE_REG050E 0x1438
539 #define LANE_REG050F 0x143C
540 #define LANE_REG0510 0x1440
541 #define LANE_REG0511 0x1444
542 #define LANE_REG0512 0x1448
543 #define LN2_TX_SER_RATE_SEL_RBR BIT(5)
544 #define LN2_TX_SER_RATE_SEL_HBR BIT(4)
545 #define LN2_TX_SER_RATE_SEL_HBR2 BIT(3)
546 #define LN2_TX_SER_RATE_SEL_HBR3 BIT(2)
547 #define LANE_REG0513 0x144C
548 #define LANE_REG0514 0x1450
549 #define LANE_REG0515 0x1454
550 #define LANE_REG0516 0x1458
551 #define LANE_REG0517 0x145C
552 #define LANE_REG0518 0x1460
553 #define LANE_REG0519 0x1464
554 #define LANE_REG051A 0x1468
555 #define LANE_REG051B 0x146C
556 #define LANE_REG051C 0x1470
557 #define LANE_REG051D 0x1474
558 #define LANE_REG051E 0x1478
559 #define LANE_REG051F 0x147C
560 #define LANE_REG0520 0x1480
561 #define LANE_REG0521 0x1484
562 #define LANE_REG0522 0x1488
563 #define LANE_REG0523 0x148C
564 #define LANE_REG0524 0x1490
565 #define LANE_REG0525 0x1494
566 #define LANE_REG0526 0x1498
567 #define LANE_REG0527 0x149C
568 #define LANE_REG0528 0x14A0
569 #define LANE_REG0529 0x14AD
570 #define LANE_REG052A 0x14A8
571 #define LANE_REG052B 0x14AC
572 #define LANE_REG052C 0x14B0
573 #define LANE_REG052D 0x14B4
574 #define LANE_REG0600 0x1800
575 #define LANE_REG0601 0x1804
576 #define LANE_REG0602 0x1808
577 #define LANE_REG0603 0x180C
578 #define LANE_REG0604 0x1810
579 #define LANE_REG0605 0x1814
580 #define LANE_REG0606 0x1818
581 #define LANE_REG0607 0x181C
582 #define LANE_REG0608 0x1820
583 #define LANE_REG0609 0x1824
584 #define LANE_REG060A 0x1828
585 #define LANE_REG060B 0x182C
586 #define LANE_REG060C 0x1830
587 #define LANE_REG060D 0x1834
588 #define LANE_REG060E 0x1838
589 #define LANE_REG060F 0x183C
590 #define LANE_REG0610 0x1840
591 #define LANE_REG0611 0x1844
592 #define LANE_REG0612 0x1848
593 #define LN3_TX_SER_RATE_SEL_RBR BIT(5)
594 #define LN3_TX_SER_RATE_SEL_HBR BIT(4)
595 #define LN3_TX_SER_RATE_SEL_HBR2 BIT(3)
596 #define LN3_TX_SER_RATE_SEL_HBR3 BIT(2)
597 #define LANE_REG0613 0x184C
598 #define LANE_REG0614 0x1850
599 #define LANE_REG0615 0x1854
600 #define LANE_REG0616 0x1858
601 #define LANE_REG0617 0x185C
602 #define LANE_REG0618 0x1860
603 #define LANE_REG0619 0x1864
604 #define LANE_REG061A 0x1868
605 #define LANE_REG061B 0x186C
606 #define LANE_REG061C 0x1870
607 #define LANE_REG061D 0x1874
608 #define LANE_REG061E 0x1878
609 #define LANE_REG061F 0x187C
610 #define LANE_REG0620 0x1880
611 #define LANE_REG0621 0x1884
612 #define LANE_REG0622 0x1888
613 #define LANE_REG0623 0x188C
614 #define LANE_REG0624 0x1890
615 #define LANE_REG0625 0x1894
616 #define LANE_REG0626 0x1898
617 #define LANE_REG0627 0x189C
618 #define LANE_REG0628 0x18A0
619 #define LANE_REG0629 0x18A4
620 #define LANE_REG062A 0x18A8
621 #define LANE_REG062B 0x18AC
622 #define LANE_REG062C 0x18B0
623 #define LANE_REG062D 0x18B4
624
625 #define HDMI20_MAX_RATE 600000000
626 #define DATA_RATE_MASK 0xFFFFFFF
627 #define COLOR_DEPTH_MASK BIT(31)
628 #define HDMI_MODE_MASK BIT(30)
629 #define HDMI_EARC_MASK BIT(29)
630
631 #define FRL_8G_4LANES 3200000000ULL
632 #define FRL_6G_3LANES 1800000000
633 #define FRL_3G_3LANES 900000000
634
635 struct lcpll_config {
636 u32 bit_rate;
637 u8 lcvco_mode_en;
638 u8 pi_en;
639 u8 clk_en_100m;
640 u8 pms_mdiv;
641 u8 pms_mdiv_afc;
642 u8 pms_pdiv;
643 u8 pms_refdiv;
644 u8 pms_sdiv;
645 u8 pi_cdiv_rstn;
646 u8 pi_cdiv_sel;
647 u8 sdm_en;
648 u8 sdm_rstn;
649 u8 sdc_frac_en;
650 u8 sdc_rstn;
651 u8 sdm_deno;
652 u8 sdm_num_sign;
653 u8 sdm_num;
654 u8 sdc_n;
655 u8 sdc_n2;
656 u8 sdc_num;
657 u8 sdc_deno;
658 u8 sdc_ndiv_rstn;
659 u8 ssc_en;
660 u8 ssc_fm_dev;
661 u8 ssc_fm_freq;
662 u8 ssc_clk_div_sel;
663 u8 cd_tx_ser_rate_sel;
664 };
665
666 struct ropll_config {
667 u32 bit_rate;
668 u8 pms_mdiv;
669 u8 pms_mdiv_afc;
670 u8 pms_pdiv;
671 u8 pms_refdiv;
672 u8 pms_sdiv;
673 u8 pms_iqdiv_rstn;
674 u8 ref_clk_sel;
675 u8 sdm_en;
676 u8 sdm_rstn;
677 u8 sdc_frac_en;
678 u8 sdc_rstn;
679 u8 sdm_clk_div;
680 u8 sdm_deno;
681 u8 sdm_num_sign;
682 u8 sdm_num;
683 u8 sdc_n;
684 u8 sdc_num;
685 u8 sdc_deno;
686 u8 sdc_ndiv_rstn;
687 u8 ssc_en;
688 u8 ssc_fm_dev;
689 u8 ssc_fm_freq;
690 u8 ssc_clk_div_sel;
691 u8 ana_cpp_ctrl;
692 u8 ana_lpf_c_sel;
693 u8 cd_tx_ser_rate_sel;
694 };
695
696 struct rockchip_hdptx_phy {
697 struct udevice *dev;
698 void __iomem *base;
699 struct regmap *grf;
700
701 int id;
702 bool dclk_en;
703 bool pll_locked;
704
705 unsigned long rate;
706 u32 bus_width;
707
708 struct reset_ctl apb_reset;
709 struct reset_ctl cmn_reset;
710 struct reset_ctl init_reset;
711 struct reset_ctl lane_reset;
712 struct reset_ctl phy_reset;
713 struct reset_ctl ropll_reset;
714 struct reset_ctl lcpll_reset;
715 };
716
717 struct clk_hdptx {
718 struct udevice *dev;
719 ulong rate;
720 };
721
722 /* global variables are used to pass reource from phy drivers to clk driver */
723 static struct rockchip_hdptx_phy *g_hdptx0;
724 static struct rockchip_hdptx_phy *g_hdptx1;
725
726 struct lcpll_config lcpll_cfg[] = {
727 { 48000000, 1, 0, 0, 0x7d, 0x7d, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 2,
728 0, 0x13, 0x18, 1, 0, 0x20, 0x0c, 1, 0,
729 },
730 { 40000000, 1, 1, 0, 0x68, 0x68, 1, 1, 0, 0, 0, 1, 1, 1, 1, 9, 0, 1, 1,
731 0, 2, 3, 1, 0, 0x20, 0x0c, 1, 0,
732 },
733 { 24000000, 1, 0, 0, 0x7d, 0x7d, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 2,
734 0, 0x13, 0x18, 1, 0, 0x20, 0x0c, 1, 0,
735 },
736 { 18000000, 1, 0, 0, 0x7d, 0x7d, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 2,
737 0, 0x13, 0x18, 1, 0, 0x20, 0x0c, 1, 0,
738 },
739 { 9000000, 1, 0, 0, 0x7d, 0x7d, 1, 1, 3, 0, 0, 0, 0, 1, 1, 1, 0, 0, 2,
740 0, 0x13, 0x18, 1, 0, 0x20, 0x0c, 1, 0,
741 },
742 { ~0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
743 0, 0, 0, 0, 0, 0,
744 },
745 };
746
747 struct ropll_config ropll_frl_cfg[] = {
748 { 24000000, 0x19, 0x19, 1, 1, 0, 1, 2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0,
749 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
750 },
751 { 18000000, 0x7d, 0x7d, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0,
752 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
753 },
754 { 9000000, 0x7d, 0x7d, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0,
755 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
756 },
757 { ~0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
758 0, 0, 0, 0,
759 },
760 };
761
762 struct ropll_config ropll_tmds_cfg[] = {
763 { 5940000, 124, 124, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
764 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
765 },
766 { 3712500, 155, 155, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
767 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
768 },
769 { 2970000, 124, 124, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
770 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
771 },
772 { 1620000, 135, 135, 1, 1, 3, 1, 1, 0, 1, 1, 1, 1, 4, 0, 3, 5, 5, 0x10,
773 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
774 },
775 { 1856250, 155, 155, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
776 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
777 },
778 { 1485000, 0x7b, 0x7b, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 4, 0, 3, 5, 5, 0x10,
779 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
780 },
781 { 1462500, 122, 122, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 244, 1, 16, 1, 0, 1,
782 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
783 },
784 { 1065000, 89, 89, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 89, 1, 16, 1, 0, 1,
785 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
786 },
787 { 1080000, 135, 135, 1, 1, 5, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0, 0x14,
788 0x18, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
789 },
790 { 855000, 125, 125, 1, 1, 6, 1, 1, 1, 1, 1, 1, 1, 80, 1, 16, 2, 0,
791 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
792 },
793 { 835000, 105, 105, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 42, 1, 16, 1, 0,
794 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
795 },
796 { 928125, 155, 155, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
797 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
798 },
799 { 742500, 124, 124, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0,
800 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
801 },
802 { 650000, 162, 162, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 54, 0, 16, 4, 1,
803 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
804 },
805 { 337500, 0x70, 0x70, 1, 1, 0xf, 1, 1, 1, 1, 1, 1, 1, 0x2, 0, 0x01, 5, 1,
806 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
807 },
808 { 400000, 100, 100, 1, 1, 11, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0, 0x14,
809 0x18, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
810 },
811 { 270000, 0x5a, 0x5a, 1, 1, 0xf, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0, 0x14,
812 0x18, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
813 },
814 { 251750, 84, 84, 1, 1, 0xf, 1, 1, 1, 1, 1, 1, 1, 168, 1, 16, 4, 1,
815 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0,
816 },
817 { ~0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
818 0, 0, 0, 0,
819 },
820 };
821
hdptx_write(struct rockchip_hdptx_phy * hdptx,uint reg,uint val)822 static inline void hdptx_write(struct rockchip_hdptx_phy *hdptx, uint reg,
823 uint val)
824 {
825 writel(val, hdptx->base + reg);
826 }
827
hdptx_read(struct rockchip_hdptx_phy * hdptx,uint reg)828 static inline uint hdptx_read(struct rockchip_hdptx_phy *hdptx, uint reg)
829 {
830 return readl(hdptx->base + reg);
831 }
832
hdptx_update_bits(struct rockchip_hdptx_phy * hdptx,uint reg,uint mask,uint val)833 static void hdptx_update_bits(struct rockchip_hdptx_phy *hdptx, uint reg,
834 uint mask, uint val)
835 {
836 uint orig, tmp;
837
838 orig = hdptx_read(hdptx, reg);
839 tmp = orig & ~mask;
840 tmp |= val & mask;
841 hdptx_write(hdptx, reg, tmp);
842 }
843
hdptx_grf_write(struct rockchip_hdptx_phy * hdptx,uint reg,uint val)844 static void hdptx_grf_write(struct rockchip_hdptx_phy *hdptx, uint reg,
845 uint val)
846 {
847 regmap_write(hdptx->grf, reg, val);
848 }
849
hdptx_grf_read(struct rockchip_hdptx_phy * hdptx,uint reg)850 static uint hdptx_grf_read(struct rockchip_hdptx_phy *hdptx, uint reg)
851 {
852 uint val;
853 int ret;
854
855 ret = regmap_read(hdptx->grf, reg, &val);
856 if (ret)
857 dev_err(hdptx->dev, "regmap_read err:%d", ret);
858
859 return val;
860 }
861
hdptx_pre_power_up(struct rockchip_hdptx_phy * hdptx)862 static void hdptx_pre_power_up(struct rockchip_hdptx_phy *hdptx)
863 {
864 u32 val = 0;
865
866 reset_assert(&hdptx->apb_reset);
867 udelay(20);
868 reset_deassert(&hdptx->apb_reset);
869
870 reset_assert(&hdptx->lane_reset);
871 reset_assert(&hdptx->cmn_reset);
872 reset_assert(&hdptx->init_reset);
873
874 val = (HDPTX_I_PLL_EN | HDPTX_I_BIAS_EN | HDPTX_I_BGR_EN) << 16;
875 hdptx_grf_write(hdptx, GRF_HDPTX_CON0, val);
876 }
877
hdptx_post_enable_lane(struct rockchip_hdptx_phy * hdptx)878 static int hdptx_post_enable_lane(struct rockchip_hdptx_phy *hdptx)
879 {
880 u32 val = 0;
881 int i;
882
883 reset_deassert(&hdptx->lane_reset);
884
885 val = (HDPTX_I_BIAS_EN | HDPTX_I_BGR_EN) << 16 | HDPTX_I_BIAS_EN |
886 HDPTX_I_BGR_EN;
887 hdptx_grf_write(hdptx, GRF_HDPTX_CON0, val);
888
889 /* 3 lanes frl mode */
890 if (hdptx->rate == FRL_6G_3LANES || hdptx->rate == FRL_3G_3LANES)
891 hdptx_write(hdptx, LNTOP_REG0207, 0x07);
892 else
893 hdptx_write(hdptx, LNTOP_REG0207, 0x0f);
894
895 val = 0;
896 for (i = 0; i < 50; i++) {
897 val = hdptx_grf_read(hdptx, GRF_HDPTX_STATUS);
898
899 if (val & HDPTX_O_PHY_RDY && val & HDPTX_O_PLL_LOCK_DONE)
900 break;
901 udelay(100);
902 }
903
904 if (i == 50) {
905 dev_err(hdptx->dev, "hdptx phy lane can't ready!\n");
906 return -EINVAL;
907 }
908
909 dev_err(hdptx->dev, "hdptx phy lane locked!\n");
910
911 return 0;
912 }
913
hdptx_post_enable_pll(struct rockchip_hdptx_phy * hdptx)914 static int hdptx_post_enable_pll(struct rockchip_hdptx_phy *hdptx)
915 {
916 u32 val = 0;
917 int i;
918
919 val = (HDPTX_I_BIAS_EN | HDPTX_I_BGR_EN) << 16 | HDPTX_I_BIAS_EN |
920 HDPTX_I_BGR_EN;
921 hdptx_grf_write(hdptx, GRF_HDPTX_CON0, val);
922 udelay(10);
923 reset_deassert(&hdptx->init_reset);
924 udelay(10);
925 val = HDPTX_I_PLL_EN << 16 | HDPTX_I_PLL_EN;
926 hdptx_grf_write(hdptx, GRF_HDPTX_CON0, val);
927 udelay(10);
928 reset_deassert(&hdptx->cmn_reset);
929
930 val = 0;
931 for (i = 0; i < 50; i++) {
932 val = hdptx_grf_read(hdptx, GRF_HDPTX_STATUS);
933
934 if (val & HDPTX_O_PHY_CLK_RDY)
935 break;
936 udelay(20);
937 }
938
939 if (i == 50) {
940 dev_err(hdptx->dev, "hdptx phy pll can't lock!\n");
941 return -EINVAL;
942 }
943
944 hdptx->pll_locked = true;
945 dev_err(hdptx->dev, "hdptx phy pll locked!\n");
946
947 return 0;
948 }
949
hdptx_phy_clk_pll_calc(unsigned int data_rate,struct ropll_config * cfg)950 static bool hdptx_phy_clk_pll_calc(unsigned int data_rate,
951 struct ropll_config *cfg)
952 {
953 unsigned int fref = 24000;
954 unsigned int sdc;
955 unsigned int fout = data_rate / 2;
956 unsigned int fvco;
957 u32 mdiv, sdiv, n = 8;
958 unsigned long k = 0, lc, k_sub, lc_sub;
959
960 for (sdiv = 1; sdiv <= 16; sdiv++) {
961 if (sdiv % 2 && sdiv != 1)
962 continue;
963
964 fvco = fout * sdiv;
965
966 if (fvco < 2000000 || fvco > 4000000)
967 continue;
968
969 mdiv = DIV_ROUND_UP(fvco, fref);
970 if (mdiv < 20 || mdiv > 255)
971 continue;
972
973 if (fref * mdiv - fvco) {
974 for (sdc = 264000; sdc <= 750000; sdc += fref)
975 if (sdc * n > fref * mdiv)
976 break;
977
978 if (sdc > 750000)
979 continue;
980
981 rational_best_approximation(fref * mdiv - fvco,
982 sdc / 16,
983 GENMASK(6, 0),
984 GENMASK(7, 0),
985 &k, &lc);
986
987 rational_best_approximation(sdc * n - fref * mdiv,
988 sdc,
989 GENMASK(6, 0),
990 GENMASK(7, 0),
991 &k_sub, &lc_sub);
992 }
993
994 break;
995 }
996
997 if (sdiv > 16)
998 return false;
999
1000 if (cfg) {
1001 cfg->pms_mdiv = mdiv;
1002 cfg->pms_mdiv_afc = mdiv;
1003 cfg->pms_pdiv = 1;
1004 cfg->pms_refdiv = 1;
1005 cfg->pms_sdiv = sdiv - 1;
1006
1007 cfg->sdm_en = k > 0 ? 1 : 0;
1008 if (cfg->sdm_en) {
1009 cfg->sdm_deno = lc;
1010 cfg->sdm_num_sign = 1;
1011 cfg->sdm_num = k;
1012 cfg->sdc_n = n - 3;
1013 cfg->sdc_num = k_sub;
1014 cfg->sdc_deno = lc_sub;
1015 }
1016 }
1017
1018 return true;
1019 }
1020
hdptx_lcpll_cmn_config(struct rockchip_hdptx_phy * hdptx,unsigned long bit_rate)1021 static int hdptx_lcpll_cmn_config(struct rockchip_hdptx_phy *hdptx, unsigned long bit_rate)
1022 {
1023 u8 color_depth = (bit_rate & COLOR_DEPTH_MASK) ? 1 : 0;
1024 struct lcpll_config *cfg = lcpll_cfg;
1025
1026 printf("%s rate:%lu\n", __func__, bit_rate);
1027 hdptx->rate = bit_rate * 100;
1028
1029 for (; cfg->bit_rate != ~0; cfg++)
1030 if (bit_rate == cfg->bit_rate)
1031 break;
1032
1033 if (cfg->bit_rate == ~0)
1034 return -EINVAL;
1035
1036 hdptx_pre_power_up(hdptx);
1037
1038 reset_assert(&hdptx->lcpll_reset);
1039 udelay(20);
1040 reset_deassert(&hdptx->lcpll_reset);
1041
1042 hdptx_grf_write(hdptx, GRF_HDPTX_CON0, LC_REF_CLK_SEL << 16);
1043
1044 hdptx_update_bits(hdptx, CMN_REG0008, LCPLL_EN_MASK |
1045 LCPLL_LCVCO_MODE_EN_MASK, LCPLL_EN(1) |
1046 LCPLL_LCVCO_MODE_EN(cfg->lcvco_mode_en));
1047 hdptx_write(hdptx, CMN_REG0009, 0x0c);
1048 hdptx_write(hdptx, CMN_REG000A, 0x83);
1049 hdptx_write(hdptx, CMN_REG000B, 0x06);
1050 hdptx_write(hdptx, CMN_REG000C, 0x20);
1051 hdptx_write(hdptx, CMN_REG000D, 0xb8);
1052 hdptx_write(hdptx, CMN_REG000E, 0x0f);
1053 hdptx_write(hdptx, CMN_REG000F, 0x0f);
1054 hdptx_write(hdptx, CMN_REG0010, 0x04);
1055 hdptx_write(hdptx, CMN_REG0011, 0x00);
1056 hdptx_write(hdptx, CMN_REG0012, 0x26);
1057 hdptx_write(hdptx, CMN_REG0013, 0x22);
1058 hdptx_write(hdptx, CMN_REG0014, 0x24);
1059 hdptx_write(hdptx, CMN_REG0015, 0x77);
1060 hdptx_write(hdptx, CMN_REG0016, 0x08);
1061 hdptx_write(hdptx, CMN_REG0017, 0x00);
1062 hdptx_write(hdptx, CMN_REG0018, 0x04);
1063 hdptx_write(hdptx, CMN_REG0019, 0x48);
1064 hdptx_write(hdptx, CMN_REG001A, 0x01);
1065 hdptx_write(hdptx, CMN_REG001B, 0x00);
1066 hdptx_write(hdptx, CMN_REG001C, 0x01);
1067 hdptx_write(hdptx, CMN_REG001D, 0x64);
1068 hdptx_update_bits(hdptx, CMN_REG001E, LCPLL_PI_EN_MASK |
1069 LCPLL_100M_CLK_EN_MASK,
1070 LCPLL_PI_EN(cfg->pi_en) |
1071 LCPLL_100M_CLK_EN(cfg->clk_en_100m));
1072 hdptx_write(hdptx, CMN_REG001F, 0x00);
1073 hdptx_write(hdptx, CMN_REG0020, cfg->pms_mdiv);
1074 hdptx_write(hdptx, CMN_REG0021, cfg->pms_mdiv_afc);
1075 hdptx_write(hdptx, CMN_REG0022, (cfg->pms_pdiv << 4) | cfg->pms_refdiv);
1076 hdptx_write(hdptx, CMN_REG0023, (cfg->pms_sdiv << 4) | cfg->pms_sdiv);
1077 hdptx_write(hdptx, CMN_REG0025, 0x10);
1078 hdptx_write(hdptx, CMN_REG0026, 0x53);
1079 hdptx_write(hdptx, CMN_REG0027, 0x01);
1080 hdptx_write(hdptx, CMN_REG0028, 0x0d);
1081 hdptx_write(hdptx, CMN_REG0029, 0x01);
1082 hdptx_write(hdptx, CMN_REG002A, cfg->sdm_deno);
1083 hdptx_write(hdptx, CMN_REG002B, cfg->sdm_num_sign);
1084 hdptx_write(hdptx, CMN_REG002C, cfg->sdm_num);
1085 hdptx_update_bits(hdptx, CMN_REG002D, LCPLL_SDC_N_MASK,
1086 LCPLL_SDC_N(cfg->sdc_n));
1087 hdptx_write(hdptx, CMN_REG002E, 0x02);
1088 hdptx_write(hdptx, CMN_REG002F, 0x0d);
1089 hdptx_write(hdptx, CMN_REG0030, 0x00);
1090 hdptx_write(hdptx, CMN_REG0031, 0x20);
1091 hdptx_write(hdptx, CMN_REG0032, 0x30);
1092 hdptx_write(hdptx, CMN_REG0033, 0x0b);
1093 hdptx_write(hdptx, CMN_REG0034, 0x23);
1094 hdptx_write(hdptx, CMN_REG0035, 0x00);
1095 hdptx_write(hdptx, CMN_REG0038, 0x00);
1096 hdptx_write(hdptx, CMN_REG0039, 0x00);
1097 hdptx_write(hdptx, CMN_REG003A, 0x00);
1098 hdptx_write(hdptx, CMN_REG003B, 0x00);
1099 hdptx_write(hdptx, CMN_REG003C, 0x80);
1100 hdptx_write(hdptx, CMN_REG003D, 0x00);
1101 hdptx_write(hdptx, CMN_REG003E, 0x0c);
1102 hdptx_write(hdptx, CMN_REG003F, 0x83);
1103 hdptx_write(hdptx, CMN_REG0040, 0x06);
1104 hdptx_write(hdptx, CMN_REG0041, 0x20);
1105 hdptx_write(hdptx, CMN_REG0042, 0xb8);
1106 hdptx_write(hdptx, CMN_REG0043, 0x00);
1107 hdptx_write(hdptx, CMN_REG0044, 0x46);
1108 hdptx_write(hdptx, CMN_REG0045, 0x24);
1109 hdptx_write(hdptx, CMN_REG0046, 0xff);
1110 hdptx_write(hdptx, CMN_REG0047, 0x00);
1111 hdptx_write(hdptx, CMN_REG0048, 0x44);
1112 hdptx_write(hdptx, CMN_REG0049, 0xfa);
1113 hdptx_write(hdptx, CMN_REG004A, 0x08);
1114 hdptx_write(hdptx, CMN_REG004B, 0x00);
1115 hdptx_write(hdptx, CMN_REG004C, 0x01);
1116 hdptx_write(hdptx, CMN_REG004D, 0x64);
1117 hdptx_write(hdptx, CMN_REG004E, 0x14);
1118 hdptx_write(hdptx, CMN_REG004F, 0x00);
1119 hdptx_write(hdptx, CMN_REG0050, 0x00);
1120 hdptx_write(hdptx, CMN_REG0051, 0x00);
1121 hdptx_write(hdptx, CMN_REG0055, 0x00);
1122 hdptx_write(hdptx, CMN_REG0059, 0x11);
1123 hdptx_write(hdptx, CMN_REG005A, 0x03);
1124 hdptx_write(hdptx, CMN_REG005C, 0x05);
1125 hdptx_write(hdptx, CMN_REG005D, 0x0c);
1126 hdptx_write(hdptx, CMN_REG005E, 0x07);
1127 hdptx_write(hdptx, CMN_REG005F, 0x01);
1128 hdptx_write(hdptx, CMN_REG0060, 0x01);
1129 hdptx_write(hdptx, CMN_REG0064, 0x07);
1130 hdptx_write(hdptx, CMN_REG0065, 0x00);
1131 hdptx_write(hdptx, CMN_REG0069, 0x00);
1132 hdptx_write(hdptx, CMN_REG006B, 0x04);
1133 hdptx_write(hdptx, CMN_REG006C, 0x00);
1134 hdptx_write(hdptx, CMN_REG0070, 0x01);
1135 hdptx_write(hdptx, CMN_REG0073, 0x30);
1136 hdptx_write(hdptx, CMN_REG0074, 0x00);
1137 hdptx_write(hdptx, CMN_REG0075, 0x20);
1138 hdptx_write(hdptx, CMN_REG0076, 0x30);
1139 hdptx_write(hdptx, CMN_REG0077, 0x08);
1140 hdptx_write(hdptx, CMN_REG0078, 0x0c);
1141 hdptx_write(hdptx, CMN_REG0079, 0x00);
1142 hdptx_write(hdptx, CMN_REG007B, 0x00);
1143 hdptx_write(hdptx, CMN_REG007C, 0x00);
1144 hdptx_write(hdptx, CMN_REG007D, 0x00);
1145 hdptx_write(hdptx, CMN_REG007E, 0x00);
1146 hdptx_write(hdptx, CMN_REG007F, 0x00);
1147 hdptx_write(hdptx, CMN_REG0080, 0x00);
1148 hdptx_write(hdptx, CMN_REG0081, 0x09);
1149 hdptx_write(hdptx, CMN_REG0082, 0x04);
1150 hdptx_write(hdptx, CMN_REG0083, 0x24);
1151 hdptx_write(hdptx, CMN_REG0084, 0x20);
1152 hdptx_write(hdptx, CMN_REG0085, 0x03);
1153 hdptx_write(hdptx, CMN_REG0086, 0x01);
1154 hdptx_update_bits(hdptx, CMN_REG0086, PLL_PCG_POSTDIV_SEL_MASK,
1155 PLL_PCG_POSTDIV_SEL(cfg->pms_sdiv));
1156 hdptx_update_bits(hdptx, CMN_REG0086, PLL_PCG_CLK_SEL_MASK,
1157 PLL_PCG_CLK_SEL(color_depth));
1158 hdptx_write(hdptx, CMN_REG0087, 0x0c);
1159 hdptx_write(hdptx, CMN_REG0089, 0x02);
1160 hdptx_write(hdptx, CMN_REG008A, 0x55);
1161 hdptx_write(hdptx, CMN_REG008B, 0x25);
1162 hdptx_write(hdptx, CMN_REG008C, 0x2c);
1163 hdptx_write(hdptx, CMN_REG008D, 0x22);
1164 hdptx_write(hdptx, CMN_REG008E, 0x14);
1165 hdptx_write(hdptx, CMN_REG008F, 0x20);
1166 hdptx_write(hdptx, CMN_REG0090, 0x00);
1167 hdptx_write(hdptx, CMN_REG0091, 0x00);
1168 hdptx_write(hdptx, CMN_REG0092, 0x00);
1169 hdptx_write(hdptx, CMN_REG0093, 0x00);
1170 hdptx_write(hdptx, CMN_REG0095, 0x00);
1171 hdptx_write(hdptx, CMN_REG0097, 0x00);
1172 hdptx_write(hdptx, CMN_REG0099, 0x00);
1173 hdptx_write(hdptx, CMN_REG009A, 0x11);
1174 hdptx_write(hdptx, CMN_REG009B, 0x10);
1175 hdptx_write(hdptx, SB_REG0114, 0x00);
1176 hdptx_write(hdptx, SB_REG0115, 0x00);
1177 hdptx_write(hdptx, SB_REG0116, 0x00);
1178 hdptx_write(hdptx, SB_REG0117, 0x00);
1179
1180 return hdptx_post_enable_pll(hdptx);
1181 }
1182
hdptx_ropll_cmn_config(struct rockchip_hdptx_phy * hdptx,unsigned long bit_rate)1183 static int hdptx_ropll_cmn_config(struct rockchip_hdptx_phy *hdptx, unsigned long bit_rate)
1184 {
1185 int bus_width = hdptx->bus_width;
1186 u8 color_depth = (bus_width & COLOR_DEPTH_MASK) ? 1 : 0;
1187 struct ropll_config *cfg = ropll_tmds_cfg;
1188 struct ropll_config rc = {0};
1189
1190 printf("%s bus_width:%x rate:%lu\n", __func__, bus_width, bit_rate);
1191 hdptx->rate = bit_rate * 100;
1192
1193 for (; cfg->bit_rate != ~0; cfg++)
1194 if (bit_rate == cfg->bit_rate)
1195 break;
1196
1197 if (cfg->bit_rate == ~0) {
1198 if (hdptx_phy_clk_pll_calc(bit_rate, &rc)) {
1199 cfg = &rc;
1200 } else {
1201 dev_err(hdptx->dev, "%s can't find pll cfg\n", __func__);
1202 return -EINVAL;
1203 }
1204 }
1205
1206 dev_dbg(hdptx->dev, "mdiv=%u, sdiv=%u\n",
1207 cfg->pms_mdiv, cfg->pms_sdiv + 1);
1208 dev_dbg(hdptx->dev, "sdm_en=%u, k_sign=%u, k=%u, lc=%u",
1209 cfg->sdm_en, cfg->sdm_num_sign, cfg->sdm_num, cfg->sdm_deno);
1210 dev_dbg(hdptx->dev, "n=%u, k_sub=%u, lc_sub=%u\n",
1211 cfg->sdc_n + 3, cfg->sdc_num, cfg->sdc_deno);
1212
1213 hdptx_pre_power_up(hdptx);
1214
1215 reset_assert(&hdptx->ropll_reset);
1216 udelay(20);
1217 reset_deassert(&hdptx->ropll_reset);
1218
1219 hdptx_grf_write(hdptx, GRF_HDPTX_CON0, LC_REF_CLK_SEL << 16);
1220
1221 hdptx_write(hdptx, CMN_REG0008, 0x00);
1222 hdptx_write(hdptx, CMN_REG0009, 0x0c);
1223 hdptx_write(hdptx, CMN_REG000A, 0x83);
1224 hdptx_write(hdptx, CMN_REG000B, 0x06);
1225 hdptx_write(hdptx, CMN_REG000C, 0x20);
1226 hdptx_write(hdptx, CMN_REG000D, 0xb8);
1227 hdptx_write(hdptx, CMN_REG000E, 0x0f);
1228 hdptx_write(hdptx, CMN_REG000F, 0x0f);
1229 hdptx_write(hdptx, CMN_REG0010, 0x04);
1230 hdptx_write(hdptx, CMN_REG0011, 0x01);
1231 hdptx_write(hdptx, CMN_REG0012, 0x26);
1232 hdptx_write(hdptx, CMN_REG0013, 0x22);
1233 hdptx_write(hdptx, CMN_REG0014, 0x24);
1234 hdptx_write(hdptx, CMN_REG0015, 0x77);
1235 hdptx_write(hdptx, CMN_REG0016, 0x08);
1236 hdptx_write(hdptx, CMN_REG0017, 0x20);
1237 hdptx_write(hdptx, CMN_REG0018, 0x04);
1238 hdptx_write(hdptx, CMN_REG0019, 0x48);
1239 hdptx_write(hdptx, CMN_REG001A, 0x01);
1240 hdptx_write(hdptx, CMN_REG001B, 0x00);
1241 hdptx_write(hdptx, CMN_REG001C, 0x01);
1242 hdptx_write(hdptx, CMN_REG001D, 0x64);
1243 hdptx_write(hdptx, CMN_REG001E, 0x14);
1244 hdptx_write(hdptx, CMN_REG001F, 0x00);
1245 hdptx_write(hdptx, CMN_REG0020, 0x00);
1246 hdptx_write(hdptx, CMN_REG0021, 0x00);
1247 hdptx_write(hdptx, CMN_REG0022, 0x11);
1248 hdptx_write(hdptx, CMN_REG0023, 0x00);
1249 hdptx_write(hdptx, CMN_REG0024, 0x00);
1250 hdptx_write(hdptx, CMN_REG0025, 0x53);
1251 hdptx_write(hdptx, CMN_REG0026, 0x00);
1252 hdptx_write(hdptx, CMN_REG0027, 0x00);
1253 hdptx_write(hdptx, CMN_REG0028, 0x01);
1254 hdptx_write(hdptx, CMN_REG0029, 0x01);
1255 hdptx_write(hdptx, CMN_REG002A, 0x00);
1256 hdptx_write(hdptx, CMN_REG002B, 0x00);
1257 hdptx_write(hdptx, CMN_REG002C, 0x00);
1258 hdptx_write(hdptx, CMN_REG002D, 0x00);
1259 hdptx_write(hdptx, CMN_REG002E, 0x04);
1260 hdptx_write(hdptx, CMN_REG002F, 0x00);
1261 hdptx_write(hdptx, CMN_REG0030, 0x20);
1262 hdptx_write(hdptx, CMN_REG0031, 0x30);
1263 hdptx_write(hdptx, CMN_REG0032, 0x0b);
1264 hdptx_write(hdptx, CMN_REG0033, 0x23);
1265 hdptx_write(hdptx, CMN_REG0034, 0x00);
1266 hdptx_write(hdptx, CMN_REG0035, 0x00);
1267 hdptx_write(hdptx, CMN_REG0038, 0x00);
1268 hdptx_write(hdptx, CMN_REG0039, 0x00);
1269 hdptx_write(hdptx, CMN_REG003A, 0x00);
1270 hdptx_write(hdptx, CMN_REG003B, 0x00);
1271 hdptx_write(hdptx, CMN_REG003C, 0x80);
1272 hdptx_write(hdptx, CMN_REG003D, 0x40);
1273 hdptx_write(hdptx, CMN_REG003E, 0x0c);
1274 hdptx_write(hdptx, CMN_REG003F, 0x83);
1275 hdptx_write(hdptx, CMN_REG0040, 0x06);
1276 hdptx_write(hdptx, CMN_REG0041, 0x20);
1277 hdptx_write(hdptx, CMN_REG0042, 0x78);
1278 hdptx_write(hdptx, CMN_REG0043, 0x00);
1279 hdptx_write(hdptx, CMN_REG0044, 0x46);
1280 hdptx_write(hdptx, CMN_REG0045, 0x24);
1281 hdptx_write(hdptx, CMN_REG0046, 0xdd);
1282 hdptx_write(hdptx, CMN_REG0047, 0x00);
1283 hdptx_write(hdptx, CMN_REG0048, 0x11);
1284 hdptx_write(hdptx, CMN_REG0049, 0xfa);
1285 hdptx_write(hdptx, CMN_REG004A, 0x08);
1286 hdptx_write(hdptx, CMN_REG004B, 0x00);
1287 hdptx_write(hdptx, CMN_REG004C, 0x01);
1288 hdptx_write(hdptx, CMN_REG004D, 0x64);
1289 hdptx_write(hdptx, CMN_REG004E, 0x34);
1290 hdptx_write(hdptx, CMN_REG004F, 0x00);
1291 hdptx_write(hdptx, CMN_REG0050, 0x00);
1292
1293 hdptx_write(hdptx, CMN_REG0051, cfg->pms_mdiv);
1294 hdptx_write(hdptx, CMN_REG0055, cfg->pms_mdiv_afc);
1295
1296 hdptx_write(hdptx, CMN_REG0059, (cfg->pms_pdiv << 4) | cfg->pms_refdiv);
1297
1298 hdptx_write(hdptx, CMN_REG005A, (cfg->pms_sdiv << 4));
1299
1300 hdptx_write(hdptx, CMN_REG005C, 0x25);
1301 hdptx_write(hdptx, CMN_REG005D, 0x0c);
1302 hdptx_write(hdptx, CMN_REG005E, 0x4f);
1303 hdptx_update_bits(hdptx, CMN_REG005E, ROPLL_SDM_EN_MASK,
1304 ROPLL_SDM_EN(cfg->sdm_en));
1305 if (!cfg->sdm_en)
1306 hdptx_update_bits(hdptx, CMN_REG005E, 0xf, 0);
1307
1308 hdptx_write(hdptx, CMN_REG005F, 0x01);
1309
1310 hdptx_update_bits(hdptx, CMN_REG0064, ROPLL_SDM_NUM_SIGN_RBR_MASK,
1311 ROPLL_SDM_NUM_SIGN_RBR(cfg->sdm_num_sign));
1312 hdptx_write(hdptx, CMN_REG0065, cfg->sdm_num);
1313 hdptx_write(hdptx, CMN_REG0060, cfg->sdm_deno);
1314
1315 hdptx_update_bits(hdptx, CMN_REG0069, ROPLL_SDC_N_RBR_MASK,
1316 ROPLL_SDC_N_RBR(cfg->sdc_n));
1317
1318 hdptx_write(hdptx, CMN_REG006C, cfg->sdc_num);
1319 hdptx_write(hdptx, CMN_REG0070, cfg->sdc_deno);
1320
1321 hdptx_write(hdptx, CMN_REG006B, 0x04);
1322
1323 hdptx_write(hdptx, CMN_REG0073, 0x30);
1324 hdptx_write(hdptx, CMN_REG0074, 0x04);
1325 hdptx_write(hdptx, CMN_REG0075, 0x20);
1326 hdptx_write(hdptx, CMN_REG0076, 0x30);
1327 hdptx_write(hdptx, CMN_REG0077, 0x08);
1328 hdptx_write(hdptx, CMN_REG0078, 0x0c);
1329 hdptx_write(hdptx, CMN_REG0079, 0x00);
1330 hdptx_write(hdptx, CMN_REG007B, 0x00);
1331 hdptx_write(hdptx, CMN_REG007C, 0x00);
1332 hdptx_write(hdptx, CMN_REG007D, 0x00);
1333 hdptx_write(hdptx, CMN_REG007E, 0x00);
1334 hdptx_write(hdptx, CMN_REG007F, 0x00);
1335 hdptx_write(hdptx, CMN_REG0080, 0x00);
1336 hdptx_write(hdptx, CMN_REG0081, 0x01);
1337 hdptx_write(hdptx, CMN_REG0082, 0x04);
1338 hdptx_write(hdptx, CMN_REG0083, 0x24);
1339 hdptx_write(hdptx, CMN_REG0084, 0x20);
1340 hdptx_write(hdptx, CMN_REG0085, 0x03);
1341
1342 hdptx_update_bits(hdptx, CMN_REG0086, PLL_PCG_POSTDIV_SEL_MASK,
1343 PLL_PCG_POSTDIV_SEL(cfg->pms_sdiv));
1344
1345 hdptx_update_bits(hdptx, CMN_REG0086, PLL_PCG_CLK_SEL_MASK,
1346 PLL_PCG_CLK_SEL(color_depth));
1347
1348 hdptx_update_bits(hdptx, CMN_REG0086, PLL_PCG_CLK_EN, PLL_PCG_CLK_EN);
1349
1350 hdptx_write(hdptx, CMN_REG0087, 0x04);
1351 hdptx_write(hdptx, CMN_REG0089, 0x00);
1352 hdptx_write(hdptx, CMN_REG008A, 0x55);
1353 hdptx_write(hdptx, CMN_REG008B, 0x25);
1354 hdptx_write(hdptx, CMN_REG008C, 0x2c);
1355 hdptx_write(hdptx, CMN_REG008D, 0x22);
1356 hdptx_write(hdptx, CMN_REG008E, 0x14);
1357 hdptx_write(hdptx, CMN_REG008F, 0x20);
1358 hdptx_write(hdptx, CMN_REG0090, 0x00);
1359 hdptx_write(hdptx, CMN_REG0091, 0x00);
1360 hdptx_write(hdptx, CMN_REG0092, 0x00);
1361 hdptx_write(hdptx, CMN_REG0093, 0x00);
1362 hdptx_write(hdptx, CMN_REG0095, 0x00);
1363 hdptx_write(hdptx, CMN_REG0097, 0x02);
1364 hdptx_write(hdptx, CMN_REG0099, 0x04);
1365 hdptx_write(hdptx, CMN_REG009A, 0x11);
1366 hdptx_write(hdptx, CMN_REG009B, 0x00);
1367
1368 return hdptx_post_enable_pll(hdptx);
1369 }
1370
hdptx_ropll_tmds_mode_config(struct rockchip_hdptx_phy * hdptx,u32 rate)1371 static int hdptx_ropll_tmds_mode_config(struct rockchip_hdptx_phy *hdptx, u32 rate)
1372 {
1373 u32 bit_rate = rate & DATA_RATE_MASK;
1374 u8 color_depth = (rate & COLOR_DEPTH_MASK) ? 1 : 0;
1375
1376 if (color_depth)
1377 bit_rate = bit_rate * 5 / 4;
1378
1379 hdptx_write(hdptx, SB_REG0114, 0x00);
1380 hdptx_write(hdptx, SB_REG0115, 0x00);
1381 hdptx_write(hdptx, SB_REG0116, 0x00);
1382 hdptx_write(hdptx, SB_REG0117, 0x00);
1383 hdptx_write(hdptx, LNTOP_REG0200, 0x06);
1384
1385 if (bit_rate >= 3400000) {
1386 /* For 1/40 bitrate clk */
1387 hdptx_write(hdptx, LNTOP_REG0201, 0x00);
1388 hdptx_write(hdptx, LNTOP_REG0202, 0x00);
1389 hdptx_write(hdptx, LNTOP_REG0203, 0x0f);
1390 hdptx_write(hdptx, LNTOP_REG0204, 0xff);
1391 hdptx_write(hdptx, LNTOP_REG0205, 0xff);
1392 } else {
1393 /* For 1/10 bitrate clk */
1394 hdptx_write(hdptx, LNTOP_REG0201, 0x07);
1395 hdptx_write(hdptx, LNTOP_REG0202, 0xc1);
1396 hdptx_write(hdptx, LNTOP_REG0203, 0xf0);
1397 hdptx_write(hdptx, LNTOP_REG0204, 0x7c);
1398 hdptx_write(hdptx, LNTOP_REG0205, 0x1f);
1399 }
1400
1401 hdptx_write(hdptx, LNTOP_REG0206, 0x07);
1402 hdptx_write(hdptx, LANE_REG0303, 0x0c);
1403 hdptx_write(hdptx, LANE_REG0307, 0x20);
1404 hdptx_write(hdptx, LANE_REG030A, 0x17);
1405 hdptx_write(hdptx, LANE_REG030B, 0x77);
1406 hdptx_write(hdptx, LANE_REG030C, 0x77);
1407 hdptx_write(hdptx, LANE_REG030D, 0x77);
1408 hdptx_write(hdptx, LANE_REG030E, 0x38);
1409 hdptx_write(hdptx, LANE_REG0310, 0x03);
1410 hdptx_write(hdptx, LANE_REG0311, 0x0f);
1411 hdptx_write(hdptx, LANE_REG0312, 0x00);
1412 hdptx_write(hdptx, LANE_REG0316, 0x02);
1413 hdptx_write(hdptx, LANE_REG031B, 0x01);
1414 hdptx_write(hdptx, LANE_REG031E, 0x00);
1415 hdptx_write(hdptx, LANE_REG031F, 0x15);
1416 hdptx_write(hdptx, LANE_REG0320, 0xa0);
1417 hdptx_write(hdptx, LANE_REG0403, 0x0c);
1418 hdptx_write(hdptx, LANE_REG0407, 0x20);
1419 hdptx_write(hdptx, LANE_REG040A, 0x17);
1420 hdptx_write(hdptx, LANE_REG040B, 0x77);
1421 hdptx_write(hdptx, LANE_REG040C, 0x77);
1422 hdptx_write(hdptx, LANE_REG040D, 0x77);
1423 hdptx_write(hdptx, LANE_REG040E, 0x38);
1424 hdptx_write(hdptx, LANE_REG0410, 0x03);
1425 hdptx_write(hdptx, LANE_REG0411, 0x0f);
1426 hdptx_write(hdptx, LANE_REG0412, 0x00);
1427 hdptx_write(hdptx, LANE_REG0416, 0x02);
1428 hdptx_write(hdptx, LANE_REG041B, 0x01);
1429 hdptx_write(hdptx, LANE_REG041E, 0x00);
1430 hdptx_write(hdptx, LANE_REG041F, 0x15);
1431 hdptx_write(hdptx, LANE_REG0420, 0xa0);
1432 hdptx_write(hdptx, LANE_REG0503, 0x0c);
1433 hdptx_write(hdptx, LANE_REG0507, 0x20);
1434 hdptx_write(hdptx, LANE_REG050A, 0x17);
1435 hdptx_write(hdptx, LANE_REG050B, 0x77);
1436 hdptx_write(hdptx, LANE_REG050C, 0x77);
1437 hdptx_write(hdptx, LANE_REG050D, 0x77);
1438 hdptx_write(hdptx, LANE_REG050E, 0x38);
1439 hdptx_write(hdptx, LANE_REG0510, 0x03);
1440 hdptx_write(hdptx, LANE_REG0511, 0x0f);
1441 hdptx_write(hdptx, LANE_REG0512, 0x00);
1442 hdptx_write(hdptx, LANE_REG0516, 0x02);
1443 hdptx_write(hdptx, LANE_REG051B, 0x01);
1444 hdptx_write(hdptx, LANE_REG051E, 0x00);
1445 hdptx_write(hdptx, LANE_REG051F, 0x15);
1446 hdptx_write(hdptx, LANE_REG0520, 0xa0);
1447 hdptx_write(hdptx, LANE_REG0603, 0x0c);
1448 hdptx_write(hdptx, LANE_REG0607, 0x20);
1449 hdptx_write(hdptx, LANE_REG060A, 0x17);
1450 hdptx_write(hdptx, LANE_REG060B, 0x77);
1451 hdptx_write(hdptx, LANE_REG060C, 0x77);
1452 hdptx_write(hdptx, LANE_REG060D, 0x77);
1453 hdptx_write(hdptx, LANE_REG060E, 0x38);
1454 hdptx_write(hdptx, LANE_REG0610, 0x03);
1455 hdptx_write(hdptx, LANE_REG0611, 0x0f);
1456 hdptx_write(hdptx, LANE_REG0612, 0x00);
1457 hdptx_write(hdptx, LANE_REG0616, 0x02);
1458 hdptx_write(hdptx, LANE_REG061B, 0x01);
1459 hdptx_write(hdptx, LANE_REG061E, 0x08);
1460
1461 /* fix Inter-Pair Skew exceed the limits */
1462 hdptx_write(hdptx, LANE_REG031E, 0x02);
1463 hdptx_write(hdptx, LANE_REG041E, 0x02);
1464 hdptx_write(hdptx, LANE_REG051E, 0x02);
1465 hdptx_write(hdptx, LANE_REG061E, 0x0a);
1466
1467 hdptx_write(hdptx, LANE_REG061F, 0x15);
1468 hdptx_write(hdptx, LANE_REG0620, 0xa0);
1469
1470 hdptx_write(hdptx, LANE_REG0303, 0x2f);
1471 hdptx_write(hdptx, LANE_REG0403, 0x2f);
1472 hdptx_write(hdptx, LANE_REG0503, 0x2f);
1473 hdptx_write(hdptx, LANE_REG0603, 0x2f);
1474 hdptx_write(hdptx, LANE_REG0305, 0x03);
1475 hdptx_write(hdptx, LANE_REG0405, 0x03);
1476 hdptx_write(hdptx, LANE_REG0505, 0x03);
1477 hdptx_write(hdptx, LANE_REG0605, 0x03);
1478 hdptx_write(hdptx, LANE_REG0306, 0x1c);
1479 hdptx_write(hdptx, LANE_REG0406, 0x1c);
1480 hdptx_write(hdptx, LANE_REG0506, 0x1c);
1481 hdptx_write(hdptx, LANE_REG0606, 0x1c);
1482
1483 return hdptx_post_enable_lane(hdptx);
1484 }
1485
1486 static int
hdptx_lcpll_ropll_cmn_config(struct rockchip_hdptx_phy * hdptx,unsigned long rate)1487 hdptx_lcpll_ropll_cmn_config(struct rockchip_hdptx_phy *hdptx,
1488 unsigned long rate)
1489 {
1490 u32 val;
1491
1492 printf("%s rate:%lu\n", __func__, rate);
1493
1494 hdptx->rate = rate * 100;
1495
1496 hdptx_pre_power_up(hdptx);
1497
1498 reset_assert(&hdptx->ropll_reset);
1499 udelay(20);
1500 reset_deassert(&hdptx->ropll_reset);
1501
1502 reset_assert(&hdptx->lcpll_reset);
1503 udelay(20);
1504 reset_deassert(&hdptx->lcpll_reset);
1505
1506 /* ROPLL input reference clock from LCPLL (cascade mode) */
1507 val = (LC_REF_CLK_SEL << 16) | LC_REF_CLK_SEL;
1508 hdptx_grf_write(hdptx, GRF_HDPTX_CON0, val);
1509
1510 hdptx_write(hdptx, CMN_REG0008, 0xd0);
1511 hdptx_write(hdptx, CMN_REG0009, 0x0c);
1512 hdptx_write(hdptx, CMN_REG000A, 0x83);
1513 hdptx_write(hdptx, CMN_REG000B, 0x06);
1514 hdptx_write(hdptx, CMN_REG000C, 0x20);
1515 hdptx_write(hdptx, CMN_REG000D, 0xb8);
1516 hdptx_write(hdptx, CMN_REG000E, 0x0f);
1517 hdptx_write(hdptx, CMN_REG000F, 0x0f);
1518 hdptx_write(hdptx, CMN_REG0010, 0x04);
1519 hdptx_write(hdptx, CMN_REG0011, 0x00);
1520 hdptx_write(hdptx, CMN_REG0012, 0x26);
1521 hdptx_write(hdptx, CMN_REG0013, 0x22);
1522 hdptx_write(hdptx, CMN_REG0014, 0x24);
1523 hdptx_write(hdptx, CMN_REG0015, 0x77);
1524 hdptx_write(hdptx, CMN_REG0016, 0x08);
1525 hdptx_write(hdptx, CMN_REG0017, 0x00);
1526 hdptx_write(hdptx, CMN_REG0018, 0x04);
1527 hdptx_write(hdptx, CMN_REG0019, 0x48);
1528 hdptx_write(hdptx, CMN_REG001A, 0x01);
1529 hdptx_write(hdptx, CMN_REG001B, 0x00);
1530 hdptx_write(hdptx, CMN_REG001C, 0x01);
1531 hdptx_write(hdptx, CMN_REG001D, 0x64);
1532 hdptx_write(hdptx, CMN_REG001E, 0x35);
1533 hdptx_write(hdptx, CMN_REG001F, 0x00);
1534 hdptx_write(hdptx, CMN_REG0020, 0x6b);
1535 hdptx_write(hdptx, CMN_REG0021, 0x6b);
1536 hdptx_write(hdptx, CMN_REG0022, 0x11);
1537 hdptx_write(hdptx, CMN_REG0024, 0x00);
1538 hdptx_write(hdptx, CMN_REG0025, 0x10);
1539 hdptx_write(hdptx, CMN_REG0026, 0x53);
1540 hdptx_write(hdptx, CMN_REG0027, 0x15);
1541 hdptx_write(hdptx, CMN_REG0028, 0x0d);
1542 hdptx_write(hdptx, CMN_REG0029, 0x01);
1543 hdptx_write(hdptx, CMN_REG002A, 0x09);
1544 hdptx_write(hdptx, CMN_REG002B, 0x01);
1545 hdptx_write(hdptx, CMN_REG002C, 0x02);
1546 hdptx_write(hdptx, CMN_REG002D, 0x02);
1547 hdptx_write(hdptx, CMN_REG002E, 0x0d);
1548 hdptx_write(hdptx, CMN_REG002F, 0x61);
1549 hdptx_write(hdptx, CMN_REG0030, 0x00);
1550 hdptx_write(hdptx, CMN_REG0031, 0x20);
1551 hdptx_write(hdptx, CMN_REG0032, 0x30);
1552 hdptx_write(hdptx, CMN_REG0033, 0x0b);
1553 hdptx_write(hdptx, CMN_REG0034, 0x23);
1554 hdptx_write(hdptx, CMN_REG0035, 0x00);
1555 hdptx_write(hdptx, CMN_REG0037, 0x00);
1556 hdptx_write(hdptx, CMN_REG0038, 0x00);
1557 hdptx_write(hdptx, CMN_REG0039, 0x00);
1558 hdptx_write(hdptx, CMN_REG003A, 0x00);
1559 hdptx_write(hdptx, CMN_REG003B, 0x00);
1560 hdptx_write(hdptx, CMN_REG003C, 0x80);
1561 hdptx_write(hdptx, CMN_REG003D, 0xc0);
1562 hdptx_write(hdptx, CMN_REG003E, 0x0c);
1563 hdptx_write(hdptx, CMN_REG003F, 0x83);
1564 hdptx_write(hdptx, CMN_REG0040, 0x06);
1565 hdptx_write(hdptx, CMN_REG0041, 0x20);
1566 hdptx_write(hdptx, CMN_REG0042, 0xb8);
1567 hdptx_write(hdptx, CMN_REG0043, 0x00);
1568 hdptx_write(hdptx, CMN_REG0044, 0x46);
1569 hdptx_write(hdptx, CMN_REG0045, 0x24);
1570 hdptx_write(hdptx, CMN_REG0046, 0xff);
1571 hdptx_write(hdptx, CMN_REG0047, 0x00);
1572 hdptx_write(hdptx, CMN_REG0048, 0x44);
1573 hdptx_write(hdptx, CMN_REG0049, 0xfa);
1574 hdptx_write(hdptx, CMN_REG004A, 0x08);
1575 hdptx_write(hdptx, CMN_REG004B, 0x00);
1576 hdptx_write(hdptx, CMN_REG004C, 0x01);
1577 hdptx_write(hdptx, CMN_REG004D, 0x64);
1578 hdptx_write(hdptx, CMN_REG004E, 0x14);
1579 hdptx_write(hdptx, CMN_REG004F, 0x00);
1580 hdptx_write(hdptx, CMN_REG0050, 0x00);
1581 hdptx_write(hdptx, CMN_REG0054, 0x19);
1582 hdptx_write(hdptx, CMN_REG0058, 0x19);
1583 hdptx_write(hdptx, CMN_REG0059, 0x11);
1584 hdptx_write(hdptx, CMN_REG005B, 0x30);
1585 hdptx_write(hdptx, CMN_REG005C, 0x25);
1586 hdptx_write(hdptx, CMN_REG005D, 0x14);
1587 hdptx_write(hdptx, CMN_REG005E, 0x0e);
1588 hdptx_write(hdptx, CMN_REG005F, 0x01);
1589 hdptx_write(hdptx, CMN_REG0063, 0x01);
1590 hdptx_write(hdptx, CMN_REG0064, 0x0e);
1591 hdptx_write(hdptx, CMN_REG0068, 0x00);
1592 hdptx_write(hdptx, CMN_REG0069, 0x02);
1593 hdptx_write(hdptx, CMN_REG006B, 0x00);
1594 hdptx_write(hdptx, CMN_REG006F, 0x00);
1595 hdptx_write(hdptx, CMN_REG0073, 0x02);
1596 hdptx_write(hdptx, CMN_REG0074, 0x00);
1597 hdptx_write(hdptx, CMN_REG0075, 0x20);
1598 hdptx_write(hdptx, CMN_REG0076, 0x30);
1599 hdptx_write(hdptx, CMN_REG0077, 0x08);
1600 hdptx_write(hdptx, CMN_REG0078, 0x0c);
1601 hdptx_write(hdptx, CMN_REG007A, 0x00);
1602 hdptx_write(hdptx, CMN_REG007B, 0x00);
1603 hdptx_write(hdptx, CMN_REG007C, 0x00);
1604 hdptx_write(hdptx, CMN_REG007D, 0x00);
1605 hdptx_write(hdptx, CMN_REG007E, 0x00);
1606 hdptx_write(hdptx, CMN_REG007F, 0x00);
1607 hdptx_write(hdptx, CMN_REG0080, 0x00);
1608 hdptx_write(hdptx, CMN_REG0081, 0x09);
1609 hdptx_write(hdptx, CMN_REG0082, 0x04);
1610 hdptx_write(hdptx, CMN_REG0083, 0x24);
1611 hdptx_write(hdptx, CMN_REG0084, 0x20);
1612 hdptx_write(hdptx, CMN_REG0085, 0x03);
1613 hdptx_write(hdptx, CMN_REG0086, 0x11);
1614 hdptx_write(hdptx, CMN_REG0087, 0x0c);
1615 hdptx_write(hdptx, CMN_REG0089, 0x00);
1616 hdptx_write(hdptx, CMN_REG008A, 0x55);
1617 hdptx_write(hdptx, CMN_REG008B, 0x25);
1618 hdptx_write(hdptx, CMN_REG008C, 0x2c);
1619 hdptx_write(hdptx, CMN_REG008D, 0x22);
1620 hdptx_write(hdptx, CMN_REG008E, 0x14);
1621 hdptx_write(hdptx, CMN_REG008F, 0x20);
1622 hdptx_write(hdptx, CMN_REG0090, 0x00);
1623 hdptx_write(hdptx, CMN_REG0091, 0x00);
1624 hdptx_write(hdptx, CMN_REG0092, 0x00);
1625 hdptx_write(hdptx, CMN_REG0093, 0x00);
1626 hdptx_write(hdptx, CMN_REG0095, 0x03);
1627 hdptx_write(hdptx, CMN_REG0097, 0x00);
1628 hdptx_write(hdptx, CMN_REG0099, 0x00);
1629 hdptx_write(hdptx, CMN_REG009A, 0x11);
1630 hdptx_write(hdptx, CMN_REG009B, 0x10);
1631
1632 hdptx_write(hdptx, CMN_REG009E, 0x03);
1633 hdptx_write(hdptx, CMN_REG00A0, 0x60);
1634 hdptx_write(hdptx, CMN_REG009F, 0xff);
1635
1636 return hdptx_post_enable_pll(hdptx);
1637 }
1638
1639
hdptx_lcpll_ropll_frl_mode_config(struct rockchip_hdptx_phy * hdptx)1640 static int hdptx_lcpll_ropll_frl_mode_config(struct rockchip_hdptx_phy *hdptx)
1641 {
1642 hdptx_write(hdptx, SB_REG0114, 0x00);
1643 hdptx_write(hdptx, SB_REG0115, 0x00);
1644 hdptx_write(hdptx, SB_REG0116, 0x00);
1645 hdptx_write(hdptx, SB_REG0117, 0x00);
1646 hdptx_write(hdptx, LNTOP_REG0200, 0x04);
1647 hdptx_write(hdptx, LNTOP_REG0201, 0x00);
1648 hdptx_write(hdptx, LNTOP_REG0202, 0x00);
1649 hdptx_write(hdptx, LNTOP_REG0203, 0xf0);
1650 hdptx_write(hdptx, LNTOP_REG0204, 0xff);
1651 hdptx_write(hdptx, LNTOP_REG0205, 0xff);
1652 hdptx_write(hdptx, LNTOP_REG0206, 0x05);
1653 hdptx_write(hdptx, LANE_REG0303, 0x0c);
1654 hdptx_write(hdptx, LANE_REG0307, 0x20);
1655 hdptx_write(hdptx, LANE_REG030A, 0x17);
1656 hdptx_write(hdptx, LANE_REG030B, 0x77);
1657 hdptx_write(hdptx, LANE_REG030C, 0x77);
1658 hdptx_write(hdptx, LANE_REG030D, 0x77);
1659 hdptx_write(hdptx, LANE_REG030E, 0x38);
1660 hdptx_write(hdptx, LANE_REG0310, 0x03);
1661 hdptx_write(hdptx, LANE_REG0311, 0x0f);
1662 hdptx_write(hdptx, LANE_REG0312, 0x3c);
1663 hdptx_write(hdptx, LANE_REG0316, 0x02);
1664 hdptx_write(hdptx, LANE_REG031B, 0x01);
1665 hdptx_write(hdptx, LANE_REG031F, 0x15);
1666 hdptx_write(hdptx, LANE_REG0320, 0xa0);
1667 hdptx_write(hdptx, LANE_REG0403, 0x0c);
1668 hdptx_write(hdptx, LANE_REG0407, 0x20);
1669 hdptx_write(hdptx, LANE_REG040A, 0x17);
1670 hdptx_write(hdptx, LANE_REG040B, 0x77);
1671 hdptx_write(hdptx, LANE_REG040C, 0x77);
1672 hdptx_write(hdptx, LANE_REG040D, 0x77);
1673 hdptx_write(hdptx, LANE_REG040E, 0x38);
1674 hdptx_write(hdptx, LANE_REG0410, 0x03);
1675 hdptx_write(hdptx, LANE_REG0411, 0x0f);
1676 hdptx_write(hdptx, LANE_REG0412, 0x3c);
1677 hdptx_write(hdptx, LANE_REG0416, 0x02);
1678 hdptx_write(hdptx, LANE_REG041B, 0x01);
1679 hdptx_write(hdptx, LANE_REG041F, 0x15);
1680 hdptx_write(hdptx, LANE_REG0420, 0xa0);
1681 hdptx_write(hdptx, LANE_REG0503, 0x0c);
1682 hdptx_write(hdptx, LANE_REG0507, 0x20);
1683 hdptx_write(hdptx, LANE_REG050A, 0x17);
1684 hdptx_write(hdptx, LANE_REG050B, 0x77);
1685 hdptx_write(hdptx, LANE_REG050C, 0x77);
1686 hdptx_write(hdptx, LANE_REG050D, 0x77);
1687 hdptx_write(hdptx, LANE_REG0507, 0x20);
1688 hdptx_write(hdptx, LANE_REG050A, 0x17);
1689 hdptx_write(hdptx, LANE_REG050B, 0x77);
1690 hdptx_write(hdptx, LANE_REG050C, 0x77);
1691 hdptx_write(hdptx, LANE_REG050D, 0x77);
1692 hdptx_write(hdptx, LANE_REG050E, 0x38);
1693 hdptx_write(hdptx, LANE_REG0510, 0x03);
1694 hdptx_write(hdptx, LANE_REG0511, 0x0f);
1695 hdptx_write(hdptx, LANE_REG0512, 0x3c);
1696 hdptx_write(hdptx, LANE_REG0516, 0x02);
1697 hdptx_write(hdptx, LANE_REG051B, 0x01);
1698 hdptx_write(hdptx, LANE_REG051F, 0x15);
1699 hdptx_write(hdptx, LANE_REG0520, 0xa0);
1700 hdptx_write(hdptx, LANE_REG0603, 0x0c);
1701 hdptx_write(hdptx, LANE_REG0607, 0x20);
1702 hdptx_write(hdptx, LANE_REG060A, 0x17);
1703 hdptx_write(hdptx, LANE_REG060B, 0x77);
1704 hdptx_write(hdptx, LANE_REG060C, 0x77);
1705 hdptx_write(hdptx, LANE_REG060D, 0x77);
1706 hdptx_write(hdptx, LANE_REG060E, 0x38);
1707 hdptx_write(hdptx, LANE_REG0610, 0x03);
1708 hdptx_write(hdptx, LANE_REG0611, 0x0f);
1709 hdptx_write(hdptx, LANE_REG0612, 0x3c);
1710 hdptx_write(hdptx, LANE_REG0616, 0x02);
1711 hdptx_write(hdptx, LANE_REG061B, 0x01);
1712 hdptx_write(hdptx, LANE_REG061F, 0x15);
1713 hdptx_write(hdptx, LANE_REG0620, 0xa0);
1714
1715 hdptx_write(hdptx, LANE_REG031E, 0x02);
1716 hdptx_write(hdptx, LANE_REG041E, 0x02);
1717 hdptx_write(hdptx, LANE_REG051E, 0x02);
1718 hdptx_write(hdptx, LANE_REG061E, 0x02);
1719
1720 hdptx_write(hdptx, LANE_REG0303, 0x2f);
1721 hdptx_write(hdptx, LANE_REG0403, 0x2f);
1722 hdptx_write(hdptx, LANE_REG0503, 0x2f);
1723 hdptx_write(hdptx, LANE_REG0603, 0x2f);
1724 hdptx_write(hdptx, LANE_REG0305, 0x03);
1725 hdptx_write(hdptx, LANE_REG0405, 0x03);
1726 hdptx_write(hdptx, LANE_REG0505, 0x03);
1727 hdptx_write(hdptx, LANE_REG0605, 0x03);
1728 hdptx_write(hdptx, LANE_REG0306, 0xfc);
1729 hdptx_write(hdptx, LANE_REG0406, 0xfc);
1730 hdptx_write(hdptx, LANE_REG0506, 0xfc);
1731 hdptx_write(hdptx, LANE_REG0606, 0xfc);
1732
1733 hdptx_write(hdptx, LANE_REG0305, 0x4f);
1734 hdptx_write(hdptx, LANE_REG0405, 0x4f);
1735 hdptx_write(hdptx, LANE_REG0505, 0x4f);
1736 hdptx_write(hdptx, LANE_REG0605, 0x4f);
1737 hdptx_write(hdptx, LANE_REG0304, 0x14);
1738 hdptx_write(hdptx, LANE_REG0404, 0x14);
1739 hdptx_write(hdptx, LANE_REG0504, 0x14);
1740 hdptx_write(hdptx, LANE_REG0604, 0x14);
1741
1742 return hdptx_post_enable_lane(hdptx);
1743 }
1744
1745
hdptx_lcpll_frl_mode_config(struct rockchip_hdptx_phy * hdptx,u32 rate)1746 static int hdptx_lcpll_frl_mode_config(struct rockchip_hdptx_phy *hdptx, u32 rate)
1747 {
1748 hdptx_write(hdptx, LNTOP_REG0200, 0x04);
1749 hdptx_write(hdptx, LNTOP_REG0201, 0x00);
1750 hdptx_write(hdptx, LNTOP_REG0202, 0x00);
1751 hdptx_write(hdptx, LNTOP_REG0203, 0xf0);
1752 hdptx_write(hdptx, LNTOP_REG0204, 0xff);
1753 hdptx_write(hdptx, LNTOP_REG0205, 0xff);
1754 hdptx_write(hdptx, LNTOP_REG0206, 0x05);
1755 hdptx_write(hdptx, LANE_REG0303, 0x0c);
1756 hdptx_write(hdptx, LANE_REG0307, 0x20);
1757 hdptx_write(hdptx, LANE_REG030A, 0x17);
1758 hdptx_write(hdptx, LANE_REG030B, 0x77);
1759 hdptx_write(hdptx, LANE_REG030C, 0x77);
1760 hdptx_write(hdptx, LANE_REG030D, 0x77);
1761 hdptx_write(hdptx, LANE_REG030E, 0x38);
1762 hdptx_write(hdptx, LANE_REG0310, 0x03);
1763 hdptx_write(hdptx, LANE_REG0311, 0x0f);
1764 hdptx_write(hdptx, LANE_REG0312, 0x3c);
1765 hdptx_write(hdptx, LANE_REG0316, 0x02);
1766 hdptx_write(hdptx, LANE_REG031B, 0x01);
1767 hdptx_write(hdptx, LANE_REG031F, 0x15);
1768 hdptx_write(hdptx, LANE_REG0320, 0xa0);
1769 hdptx_write(hdptx, LANE_REG0403, 0x0c);
1770 hdptx_write(hdptx, LANE_REG0407, 0x20);
1771 hdptx_write(hdptx, LANE_REG040A, 0x17);
1772 hdptx_write(hdptx, LANE_REG040B, 0x77);
1773 hdptx_write(hdptx, LANE_REG040C, 0x77);
1774 hdptx_write(hdptx, LANE_REG040D, 0x77);
1775 hdptx_write(hdptx, LANE_REG040E, 0x38);
1776 hdptx_write(hdptx, LANE_REG0410, 0x03);
1777 hdptx_write(hdptx, LANE_REG0411, 0x0f);
1778 hdptx_write(hdptx, LANE_REG0412, 0x3c);
1779 hdptx_write(hdptx, LANE_REG0416, 0x02);
1780 hdptx_write(hdptx, LANE_REG041B, 0x01);
1781 hdptx_write(hdptx, LANE_REG041F, 0x15);
1782 hdptx_write(hdptx, LANE_REG0420, 0xa0);
1783 hdptx_write(hdptx, LANE_REG0503, 0x0c);
1784 hdptx_write(hdptx, LANE_REG0507, 0x20);
1785 hdptx_write(hdptx, LANE_REG050A, 0x17);
1786 hdptx_write(hdptx, LANE_REG050B, 0x77);
1787 hdptx_write(hdptx, LANE_REG050C, 0x77);
1788 hdptx_write(hdptx, LANE_REG050D, 0x77);
1789 hdptx_write(hdptx, LANE_REG050E, 0x38);
1790 hdptx_write(hdptx, LANE_REG0510, 0x03);
1791 hdptx_write(hdptx, LANE_REG0511, 0x0f);
1792 hdptx_write(hdptx, LANE_REG0512, 0x3c);
1793 hdptx_write(hdptx, LANE_REG0516, 0x02);
1794 hdptx_write(hdptx, LANE_REG051B, 0x01);
1795 hdptx_write(hdptx, LANE_REG051F, 0x15);
1796 hdptx_write(hdptx, LANE_REG0520, 0xa0);
1797 hdptx_write(hdptx, LANE_REG0603, 0x0c);
1798 hdptx_write(hdptx, LANE_REG0607, 0x20);
1799 hdptx_write(hdptx, LANE_REG060A, 0x17);
1800 hdptx_write(hdptx, LANE_REG060B, 0x77);
1801 hdptx_write(hdptx, LANE_REG060C, 0x77);
1802 hdptx_write(hdptx, LANE_REG060D, 0x77);
1803 hdptx_write(hdptx, LANE_REG060E, 0x38);
1804 hdptx_write(hdptx, LANE_REG0610, 0x03);
1805 hdptx_write(hdptx, LANE_REG0611, 0x0f);
1806 hdptx_write(hdptx, LANE_REG0612, 0x3c);
1807 hdptx_write(hdptx, LANE_REG0616, 0x02);
1808 hdptx_write(hdptx, LANE_REG061B, 0x01);
1809 hdptx_write(hdptx, LANE_REG061F, 0x15);
1810 hdptx_write(hdptx, LANE_REG0620, 0xa0);
1811
1812 hdptx_write(hdptx, LANE_REG031E, 0x02);
1813 hdptx_write(hdptx, LANE_REG041E, 0x02);
1814 hdptx_write(hdptx, LANE_REG051E, 0x02);
1815 hdptx_write(hdptx, LANE_REG061E, 0x02);
1816
1817 hdptx_write(hdptx, LANE_REG0303, 0x2f);
1818 hdptx_write(hdptx, LANE_REG0403, 0x2f);
1819 hdptx_write(hdptx, LANE_REG0503, 0x2f);
1820 hdptx_write(hdptx, LANE_REG0603, 0x2f);
1821 hdptx_write(hdptx, LANE_REG0305, 0x03);
1822 hdptx_write(hdptx, LANE_REG0405, 0x03);
1823 hdptx_write(hdptx, LANE_REG0505, 0x03);
1824 hdptx_write(hdptx, LANE_REG0605, 0x03);
1825 hdptx_write(hdptx, LANE_REG0306, 0xfc);
1826 hdptx_write(hdptx, LANE_REG0406, 0xfc);
1827 hdptx_write(hdptx, LANE_REG0506, 0xfc);
1828 hdptx_write(hdptx, LANE_REG0606, 0xfc);
1829
1830 hdptx_write(hdptx, LANE_REG0305, 0x4f);
1831 hdptx_write(hdptx, LANE_REG0405, 0x4f);
1832 hdptx_write(hdptx, LANE_REG0505, 0x4f);
1833 hdptx_write(hdptx, LANE_REG0605, 0x4f);
1834 hdptx_write(hdptx, LANE_REG0304, 0x14);
1835 hdptx_write(hdptx, LANE_REG0404, 0x14);
1836 hdptx_write(hdptx, LANE_REG0504, 0x14);
1837 hdptx_write(hdptx, LANE_REG0604, 0x14);
1838
1839 return hdptx_post_enable_lane(hdptx);
1840 }
1841
rockchip_hdptx_phy_power_on(struct rockchip_phy * phy)1842 static int rockchip_hdptx_phy_power_on(struct rockchip_phy *phy)
1843 {
1844 struct rockchip_hdptx_phy *hdptx = dev_get_priv(phy->dev);
1845 int bus_width = hdptx->bus_width;
1846 int bit_rate = bus_width & DATA_RATE_MASK;
1847
1848 printf("bus_width:0x%x,bit_rate:%d\n", bus_width, bit_rate);
1849
1850 if (bus_width & HDMI_MODE_MASK)
1851 if (bit_rate != (FRL_8G_4LANES / 100))
1852 return hdptx_lcpll_frl_mode_config(hdptx, bus_width);
1853 else
1854 return hdptx_lcpll_ropll_frl_mode_config(hdptx);
1855 else
1856 return hdptx_ropll_tmds_mode_config(hdptx, bus_width);
1857 }
1858
rockchip_hdptx_phy_power_off(struct rockchip_phy * phy)1859 static int rockchip_hdptx_phy_power_off(struct rockchip_phy *phy)
1860 {
1861 return 0;
1862 }
1863
rockchip_hdptx_phy_clk_round_rate(struct rockchip_phy * phy,unsigned long rate)1864 static long rockchip_hdptx_phy_clk_round_rate(struct rockchip_phy *phy,
1865 unsigned long rate)
1866 {
1867 struct ropll_config *cfg = ropll_tmds_cfg;
1868 u32 bit_rate = rate / 100;
1869
1870 for (; cfg->bit_rate != ~0; cfg++)
1871 if (bit_rate == cfg->bit_rate)
1872 break;
1873
1874 if (cfg->bit_rate == ~0 && !hdptx_phy_clk_pll_calc(bit_rate, NULL))
1875 return -EINVAL;
1876
1877 return rate;
1878 }
1879
rockchip_hdptx_phy_clk_set_rate(struct rockchip_phy * phy,unsigned long rate)1880 static unsigned long rockchip_hdptx_phy_clk_set_rate(struct rockchip_phy *phy,
1881 unsigned long rate)
1882 {
1883 struct rockchip_hdptx_phy *hdptx = dev_get_priv(phy->dev);
1884 int bus_width = hdptx->bus_width;
1885 u8 color_depth = (bus_width & COLOR_DEPTH_MASK) ? 1 : 0;
1886
1887 if (color_depth)
1888 rate = (rate / 100) * 5 / 4;
1889 else
1890 rate = rate / 100;
1891 return hdptx_ropll_cmn_config(hdptx, rate);
1892 }
1893
1894 static int
rockchip_hdptx_phy_set_bus_width(struct rockchip_phy * phy,u32 bus_width)1895 rockchip_hdptx_phy_set_bus_width(struct rockchip_phy *phy, u32 bus_width)
1896 {
1897 struct rockchip_hdptx_phy *hdptx = dev_get_priv(phy->dev);
1898
1899 hdptx->bus_width = bus_width;
1900
1901 return 0;
1902 }
1903
1904 const struct rockchip_phy_funcs hdptx_hdmi_phy_funcs = {
1905 .power_on = rockchip_hdptx_phy_power_on,
1906 .power_off = rockchip_hdptx_phy_power_off,
1907 .set_pll = rockchip_hdptx_phy_clk_set_rate,
1908 .set_bus_width = rockchip_hdptx_phy_set_bus_width,
1909 .round_rate = rockchip_hdptx_phy_clk_round_rate,
1910 };
1911
1912 static struct rockchip_phy hdptx_hdmi_phy_driver_data0 = {
1913 .funcs = &hdptx_hdmi_phy_funcs,
1914 };
1915
1916 static struct rockchip_phy hdptx_hdmi_phy_driver_data1 = {
1917 .funcs = &hdptx_hdmi_phy_funcs,
1918 };
1919
rockchip_hdptx_phy_hdmi_probe(struct udevice * dev)1920 static int rockchip_hdptx_phy_hdmi_probe(struct udevice *dev)
1921 {
1922 struct rockchip_hdptx_phy *hdptx = dev_get_priv(dev);
1923 struct rockchip_phy *phy;
1924 struct udevice *syscon;
1925 int ret;
1926
1927 hdptx->id = of_alias_get_id(ofnode_to_np(dev->node), "hdptxhdmi");
1928 if (hdptx->id < 0)
1929 hdptx->id = 0;
1930
1931 if (!hdptx->id) {
1932 g_hdptx0 = hdptx;
1933 dev->driver_data = (ulong)&hdptx_hdmi_phy_driver_data0;
1934 phy = &hdptx_hdmi_phy_driver_data0;
1935 } else {
1936 g_hdptx1 = hdptx;
1937 dev->driver_data = (ulong)&hdptx_hdmi_phy_driver_data1;
1938 phy = &hdptx_hdmi_phy_driver_data1;
1939 }
1940
1941 hdptx->base = dev_read_addr_ptr(dev);
1942 if (!hdptx->base)
1943 return -ENOENT;
1944
1945 ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "rockchip,grf",
1946 &syscon);
1947 if (ret)
1948 return ret;
1949
1950 hdptx->grf = syscon_get_regmap(syscon);
1951 if (IS_ERR(hdptx->grf)) {
1952 ret = PTR_ERR(hdptx->grf);
1953 dev_err(dev, "unable to find regmap: %d\n", ret);
1954 return ret;
1955 }
1956
1957 hdptx->dev = dev;
1958 phy->dev = dev;
1959
1960 ret = reset_get_by_name(dev, "apb", &hdptx->apb_reset);
1961 if (ret < 0) {
1962 dev_err(dev, "failed to get apb reset: %d\n", ret);
1963 return ret;
1964 }
1965
1966 ret = reset_get_by_name(dev, "init", &hdptx->init_reset);
1967 if (ret < 0) {
1968 dev_err(dev, "failed to get init reset: %d\n", ret);
1969 return ret;
1970 }
1971
1972 ret = reset_get_by_name(dev, "cmn", &hdptx->cmn_reset);
1973 if (ret < 0) {
1974 dev_err(dev, "failed to get cmn reset: %d\n", ret);
1975 return ret;
1976 }
1977
1978 ret = reset_get_by_name(dev, "lane", &hdptx->lane_reset);
1979 if (ret < 0) {
1980 dev_err(dev, "failed to get lane reset: %d\n", ret);
1981 return ret;
1982 }
1983
1984 ret = reset_get_by_name(dev, "ropll", &hdptx->ropll_reset);
1985 if (ret < 0) {
1986 dev_err(dev, "failed to get ropll reset: %d\n", ret);
1987 return ret;
1988 }
1989
1990 ret = reset_get_by_name(dev, "lcpll", &hdptx->lcpll_reset);
1991 if (ret < 0) {
1992 dev_err(dev, "failed to get lane reset: %d\n", ret);
1993 return ret;
1994 }
1995
1996 return 0;
1997 }
1998
rockchip_hdptx_phy_hdmi_bind(struct udevice * parent)1999 static int rockchip_hdptx_phy_hdmi_bind(struct udevice *parent)
2000 {
2001 struct udevice *child;
2002 ofnode subnode;
2003 char name[30], *str;
2004 int id, ret;
2005
2006 id = of_alias_get_id(ofnode_to_np(parent->node), "hdptxhdmi");
2007 if (id < 0)
2008 id = 0;
2009
2010 sprintf(name, "hdmiphypll_clk%d", id);
2011 str = strdup(name);
2012
2013 subnode = ofnode_find_subnode(parent->node, "clk-port");
2014 if (!ofnode_valid(subnode)) {
2015 free(str);
2016 printf("%s: no subnode for %s\n", __func__, parent->name);
2017 return -ENXIO;
2018 }
2019
2020 ret = device_bind_driver_to_node(parent, "clk_hdptx", str, subnode, &child);
2021 if (ret) {
2022 free(str);
2023 printf("%s: clk-port cannot bind its driver\n", __func__);
2024 return ret;
2025 }
2026
2027 return 0;
2028 }
2029
2030 static const struct udevice_id rockchip_hdptx_phy_hdmi_ids[] = {
2031 { .compatible = "rockchip,rk3588-hdptx-phy-hdmi",
2032 .data = (ulong)&hdptx_hdmi_phy_driver_data0,
2033 },
2034 {}
2035 };
2036
2037 U_BOOT_DRIVER(rockchip_hdptx_phy_hdmi) = {
2038 .name = "rockchip_hdptx_phy_hdmi",
2039 .id = UCLASS_PHY,
2040 .of_match = rockchip_hdptx_phy_hdmi_ids,
2041 .probe = rockchip_hdptx_phy_hdmi_probe,
2042 .bind = rockchip_hdptx_phy_hdmi_bind,
2043 .priv_auto_alloc_size = sizeof(struct rockchip_hdptx_phy),
2044 };
2045
get_hdptx(struct udevice * dev)2046 static struct rockchip_hdptx_phy *get_hdptx(struct udevice *dev)
2047 {
2048 if (!strcmp(dev->name, "hdmiphypll_clk0"))
2049 return g_hdptx0;
2050
2051 return g_hdptx1;
2052 }
2053
hdptx_clk_get_rate(struct clk * clk)2054 static ulong hdptx_clk_get_rate(struct clk *clk)
2055 {
2056 struct clk_hdptx *priv = dev_get_priv(clk->dev);
2057
2058 return priv->rate;
2059 }
2060
hdptx_clk_set_rate(struct clk * clk,ulong rate)2061 static ulong hdptx_clk_set_rate(struct clk *clk, ulong rate)
2062 {
2063 struct clk_hdptx *priv = dev_get_priv(clk->dev);
2064 struct rockchip_hdptx_phy *hdptx = get_hdptx(clk->dev);
2065 int bus_width = hdptx->bus_width;
2066 u8 color_depth = (bus_width & COLOR_DEPTH_MASK) ? 1 : 0;
2067 ulong new_rate = -ENOENT;
2068
2069 if (color_depth && rate <= HDMI20_MAX_RATE)
2070 rate = (rate / 100) * 5 / 4;
2071 else
2072 rate = rate / 100;
2073
2074 if (rate > (HDMI20_MAX_RATE / 100)) {
2075 if (rate == FRL_8G_4LANES / 100) {
2076 if (!hdptx_lcpll_ropll_cmn_config(hdptx, rate)) {
2077 new_rate = rate;
2078 priv->rate = rate;
2079 }
2080 } else {
2081 if (!hdptx_lcpll_cmn_config(hdptx, rate)) {
2082 new_rate = rate;
2083 priv->rate = rate;
2084 }
2085 }
2086 } else {
2087 if (!hdptx_ropll_cmn_config(hdptx, rate)) {
2088 new_rate = rate;
2089 priv->rate = rate;
2090 }
2091 }
2092
2093 return new_rate;
2094 }
2095
2096 static const struct clk_ops hdptx_clk_ops = {
2097 .get_rate = hdptx_clk_get_rate,
2098 .set_rate = hdptx_clk_set_rate,
2099 };
2100
hdptx_clk_probe(struct udevice * dev)2101 static int hdptx_clk_probe(struct udevice *dev)
2102 {
2103 return 0;
2104 }
2105
2106 /*
2107 * In order for other display interfaces to use hdmiphy as source
2108 * for dclk, hdmiphy must register a virtual clock driver
2109 */
2110 U_BOOT_DRIVER(clk_hdptx) = {
2111 .name = "clk_hdptx",
2112 .id = UCLASS_CLK,
2113 .priv_auto_alloc_size = sizeof(struct clk_hdptx),
2114 .ops = &hdptx_clk_ops,
2115 .probe = hdptx_clk_probe,
2116 };
2117