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