1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2008-2018 Fuzhou Rockchip Electronics Co., Ltd
4 *
5 * Author: Guochun Huang <hero.huang@rock-chips.com>
6 */
7
8 #include <config.h>
9 #include <common.h>
10 #include <errno.h>
11 #include <dm.h>
12 #include <div64.h>
13 #include <asm/io.h>
14 #include <asm/arch-rockchip/clock.h>
15 #include <linux/ioport.h>
16 #include <linux/iopoll.h>
17 #include <linux/math64.h>
18 #include <reset.h>
19 #include <regmap.h>
20 #include <syscon.h>
21
22 #include "rockchip_phy.h"
23
24 #define MAX_DPHY_BW 4500000L
25 #define MAX_CPHY_BW 2000000L
26
27 #define MSEC_PER_SEC 1000L
28 #define USEC_PER_SEC 1000000LL
29 #define PSEC_PER_SEC 1000000000000LL
30
31 #define UPDATE(x, h, l) (((x) << (l)) & GENMASK((h), (l)))
32 #define HIWORD_UPDATE(v, h, l) (((v) << (l)) | (GENMASK((h), (l)) << 16))
33
34 #define BIAS_CON0 0x0000
35 #define BIAS_CON1 0x0004
36 #define BIAS_CON2 0x0008
37 #define BIAS_CON4 0x0010
38 #define I_MUX_SEL_MASK GENMASK(6, 5)
39 #define I_MUX_SEL(x) UPDATE(x, 6, 5)
40
41 #define PLL_CON0 0x0100
42 #define PLL_EN BIT(12)
43 #define S_MASK GENMASK(10, 8)
44 #define S(x) UPDATE(x, 10, 8)
45 #define P_MASK GENMASK(5, 0)
46 #define P(x) UPDATE(x, 5, 0)
47 #define PLL_CON1 0x0104
48 #define PLL_CON2 0x0108
49 #define M_MASK GENMASK(9, 0)
50 #define M(x) UPDATE(x, 9, 0)
51 #define PLL_CON3 0x010c
52 #define MRR_MASK GENMASK(13, 8)
53 #define MRR(x) UPDATE(x, 13, 8)
54 #define MFR_MASK GENMASK(7, 0)
55 #define MFR(x) UPDATE(x, 7, 0)
56 #define PLL_CON4 0x0110
57 #define SSCG_EN BIT(11)
58 #define PLL_CON5 0x0114
59 #define RESET_N_SEL BIT(10)
60 #define PLL_ENABLE_SEL BIT(8)
61 #define PLL_CON6 0x0118
62 #define PLL_CON7 0x011c
63 #define PLL_LOCK_CNT(x) UPDATE(x, 15, 0)
64 #define PLL_CON8 0x0120
65 #define PLL_STB_CNT(x) UPDATE(x, 15, 0)
66 #define PLL_STAT0 0x0140
67 #define PLL_LOCK BIT(0)
68
69 #define DPHY_MC_GNR_CON0 0x0300
70 #define PHY_READY BIT(1)
71 #define PHY_ENABLE BIT(0)
72 #define DPHY_MC_GNR_CON1 0x0304
73 #define T_PHY_READY(x) UPDATE(x, 15, 0)
74 #define DPHY_MC_ANA_CON0 0x0308
75 #define DPHY_MC_ANA_CON1 0x030c
76 #define DPHY_MC_ANA_CON2 0x0310
77 #define HS_VREG_AMP_ICON(x) UPDATE(x, 1, 0)
78 #define DPHY_MC_TIME_CON0 0x0330
79 #define HSTX_CLK_SEL BIT(12)
80 #define T_LPX(x) UPDATE(x, 11, 4)
81 #define DPHY_MC_TIME_CON1 0x0334
82 #define T_CLK_ZERO(x) UPDATE(x, 15, 8)
83 #define T_CLK_PREPARE(x) UPDATE(x, 7, 0)
84 #define DPHY_MC_TIME_CON2 0x0338
85 #define T_HS_EXIT(x) UPDATE(x, 15, 8)
86 #define T_CLK_TRAIL(x) UPDATE(x, 7, 0)
87 #define DPHY_MC_TIME_CON3 0x033c
88 #define T_CLK_POST(x) UPDATE(x, 7, 0)
89 #define DPHY_MC_TIME_CON4 0x0340
90 #define T_ULPS_EXIT(x) UPDATE(x, 9, 0)
91 #define DPHY_MC_DESKEW_CON0 0x0350
92 #define SKEW_CAL_RUN_TIME(x) UPDATE(x, 15, 12)
93
94 #define SKEW_CAL_INIT_RUN_TIME(x) UPDATE(x, 11, 8)
95 #define SKEW_CAL_INIT_WAIT_TIME(x) UPDATE(x, 7, 4)
96 #define SKEW_CAL_EN BIT(0)
97
98 #define COMBO_MD0_GNR_CON0 0x0400
99 #define COMBO_MD0_GNR_CON1 0x0404
100 #define COMBO_MD0_ANA_CON0 0x0408
101 #define COMBO_MD0_ANA_CON1 0x040C
102 #define COMBO_MD0_ANA_CON2 0x0410
103
104 #define COMBO_MD0_TIME_CON0 0x0430
105 #define COMBO_MD0_TIME_CON1 0x0434
106 #define COMBO_MD0_TIME_CON2 0x0438
107 #define COMBO_MD0_TIME_CON3 0x043C
108 #define COMBO_MD0_TIME_CON4 0x0440
109 #define COMBO_MD0_DATA_CON0 0x0444
110
111 #define COMBO_MD1_GNR_CON0 0x0500
112 #define COMBO_MD1_GNR_CON1 0x0504
113 #define COMBO_MD1_ANA_CON0 0x0508
114 #define COMBO_MD1_ANA_CON1 0x050c
115 #define COMBO_MD1_ANA_CON2 0x0510
116 #define COMBO_MD1_TIME_CON0 0x0530
117 #define COMBO_MD1_TIME_CON1 0x0534
118 #define COMBO_MD1_TIME_CON2 0x0538
119 #define COMBO_MD1_TIME_CON3 0x053C
120 #define COMBO_MD1_TIME_CON4 0x0540
121 #define COMBO_MD1_DATA_CON0 0x0544
122
123 #define COMBO_MD2_GNR_CON0 0x0600
124 #define COMBO_MD2_GNR_CON1 0x0604
125 #define COMBO_MD2_ANA_CON0 0X0608
126 #define COMBO_MD2_ANA_CON1 0X060C
127 #define COMBO_MD2_ANA_CON2 0X0610
128 #define COMBO_MD2_TIME_CON0 0x0630
129 #define COMBO_MD2_TIME_CON1 0x0634
130 #define COMBO_MD2_TIME_CON2 0x0638
131 #define COMBO_MD2_TIME_CON3 0x063C
132 #define COMBO_MD2_TIME_CON4 0x0640
133 #define COMBO_MD2_DATA_CON0 0x0644
134
135 #define DPHY_MD3_GNR_CON0 0x0700
136 #define DPHY_MD3_GNR_CON1 0x0704
137 #define DPHY_MD3_ANA_CON0 0X0708
138 #define DPHY_MD3_ANA_CON1 0X070C
139 #define DPHY_MD3_ANA_CON2 0X0710
140 #define DPHY_MD3_TIME_CON0 0x0730
141 #define DPHY_MD3_TIME_CON1 0x0734
142 #define DPHY_MD3_TIME_CON2 0x0738
143 #define DPHY_MD3_TIME_CON3 0x073C
144 #define DPHY_MD3_TIME_CON4 0x0740
145 #define DPHY_MD3_DATA_CON0 0x0744
146
147 #define T_LP_EXIT_SKEW(x) UPDATE(x, 3, 2)
148 #define T_LP_ENTRY_SKEW(x) UPDATE(x, 1, 0)
149 #define T_HS_ZERO(x) UPDATE(x, 15, 8)
150 #define T_HS_PREPARE(x) UPDATE(x, 7, 0)
151 #define T_HS_EXIT(x) UPDATE(x, 15, 8)
152 #define T_HS_TRAIL(x) UPDATE(x, 7, 0)
153 #define T_TA_GET(x) UPDATE(x, 7, 4)
154 #define T_TA_GO(x) UPDATE(x, 3, 0)
155
156 /* MIPI_CDPHY_GRF registers */
157 #define MIPI_DCPHY_GRF_CON0 0x0000
158 #define S_CPHY_MODE HIWORD_UPDATE(1, 3, 3)
159 #define M_CPHY_MODE HIWORD_UPDATE(1, 0, 0)
160
161 struct samsung_mipi_dphy_timing {
162 unsigned int max_lane_mbps;
163 u8 clk_prepare;
164 u8 clk_zero;
165 u8 clk_post;
166 u8 clk_trail_eot;
167 u8 hs_prepare;
168 u8 hs_zero;
169 u8 hs_trail_eot;
170 u8 lpx;
171 u8 hs_exit;
172 u8 hs_settle;
173 };
174
175 struct samsung_mipi_cphy_timing {
176 unsigned int max_lane_msps;
177 u8 prepare_3;
178 u8 prebegin_3;
179 u8 post_3;
180 u8 lpx;
181 u8 hs_exit;
182 u8 settle_3;
183 };
184
185 struct samsung_mipi_dcphy {
186 enum phy_mode mode;
187 void *base;
188 void *grf;
189 int lanes;
190 bool c_option;
191 struct reset_ctl m_phy_rst;
192
193 struct {
194 unsigned long long rate;
195 u8 prediv;
196 u16 fbdiv;
197 long dsm;
198 u8 scaler;
199
200 bool ssc_en;
201 u8 mfr;
202 u8 mrr;
203 } pll;
204 };
205
206 static const
207 struct samsung_mipi_dphy_timing samsung_mipi_dphy_timing_table[] = {
208 {6500, 32, 117, 31, 28, 30, 56, 27, 24, 44, 37},
209 {6490, 32, 116, 31, 28, 30, 56, 27, 24, 44, 37},
210 {6480, 32, 116, 31, 28, 30, 56, 27, 24, 44, 37},
211 {6470, 32, 116, 31, 28, 30, 56, 27, 24, 44, 37},
212 {6460, 32, 116, 31, 28, 30, 56, 27, 24, 44, 37},
213 {6450, 32, 115, 31, 28, 30, 56, 27, 24, 44, 37},
214 {6440, 32, 115, 31, 28, 30, 56, 27, 24, 44, 37},
215 {6430, 31, 116, 31, 28, 30, 55, 27, 24, 44, 37},
216 {6420, 31, 116, 31, 28, 30, 55, 27, 24, 44, 37},
217 {6410, 31, 116, 31, 27, 30, 55, 27, 24, 44, 37},
218 {6400, 31, 115, 30, 27, 30, 55, 27, 23, 43, 36},
219 {6390, 31, 115, 30, 27, 30, 55, 27, 23, 43, 36},
220 {6380, 31, 115, 30, 27, 30, 55, 27, 23, 43, 36},
221 {6370, 31, 115, 30, 27, 30, 55, 26, 23, 43, 36},
222 {6360, 31, 114, 30, 27, 30, 54, 26, 23, 43, 36},
223 {6350, 31, 114, 30, 27, 30, 54, 26, 23, 43, 36},
224 {6340, 31, 114, 30, 27, 30, 54, 26, 23, 43, 36},
225 {6330, 31, 114, 30, 27, 30, 54, 26, 23, 43, 36},
226 {6320, 31, 113, 30, 27, 30, 54, 26, 23, 43, 36},
227 {6310, 31, 113, 30, 27, 30, 54, 26, 23, 43, 36},
228 {6300, 31, 113, 30, 27, 30, 54, 26, 23, 43, 36},
229 {6290, 31, 113, 30, 27, 29, 54, 26, 23, 43, 36},
230 {6280, 31, 112, 30, 27, 29, 54, 26, 23, 43, 36},
231 {6270, 31, 112, 30, 27, 29, 54, 26, 23, 43, 36},
232 {6260, 31, 112, 30, 27, 29, 54, 26, 23, 43, 36},
233 {6250, 31, 112, 30, 27, 29, 54, 26, 23, 42, 36},
234 {6240, 30, 113, 30, 27, 29, 54, 26, 23, 42, 36},
235 {6230, 30, 112, 30, 27, 29, 54, 26, 23, 42, 35},
236 {6220, 30, 112, 30, 27, 29, 53, 26, 23, 42, 35},
237 {6210, 30, 112, 30, 27, 29, 53, 26, 23, 42, 35},
238 {6200, 30, 112, 29, 27, 29, 53, 26, 23, 42, 35},
239 {6190, 30, 111, 29, 27, 29, 53, 26, 23, 42, 35},
240 {6180, 30, 111, 29, 27, 29, 53, 26, 23, 42, 35},
241 {6170, 30, 111, 29, 26, 29, 53, 26, 23, 42, 35},
242 {6160, 30, 111, 29, 26, 29, 53, 26, 23, 42, 35},
243 {6150, 30, 110, 29, 26, 29, 53, 26, 23, 42, 35},
244 {6140, 30, 110, 29, 26, 29, 52, 26, 23, 42, 35},
245 {6130, 30, 110, 29, 26, 29, 52, 25, 22, 42, 35},
246 {6120, 30, 110, 29, 26, 29, 52, 25, 22, 42, 35},
247 {6110, 30, 110, 29, 26, 29, 52, 25, 22, 42, 35},
248 {6100, 30, 109, 29, 26, 29, 52, 25, 22, 41, 35},
249 {6090, 30, 109, 29, 26, 29, 52, 25, 22, 41, 35},
250 {6080, 30, 109, 29, 26, 28, 53, 25, 22, 41, 35},
251 {6070, 30, 109, 29, 26, 28, 52, 25, 22, 41, 34},
252 {6060, 30, 108, 29, 26, 28, 52, 25, 22, 41, 34},
253 {6050, 30, 108, 29, 26, 28, 52, 25, 22, 41, 34},
254 {6040, 29, 109, 29, 26, 28, 52, 25, 22, 41, 34},
255 {6030, 29, 109, 29, 26, 28, 52, 25, 22, 41, 34},
256 {6020, 29, 108, 29, 26, 28, 52, 25, 22, 41, 34},
257 {6010, 29, 108, 29, 26, 28, 52, 25, 22, 41, 34},
258 {6000, 29, 108, 28, 26, 28, 51, 25, 22, 41, 34},
259 {5990, 29, 108, 28, 26, 28, 51, 25, 22, 41, 34},
260 {5980, 29, 107, 28, 26, 28, 51, 25, 22, 41, 34},
261 {5970, 29, 107, 28, 26, 28, 51, 25, 22, 41, 34},
262 {5960, 29, 107, 28, 26, 28, 51, 25, 22, 40, 34},
263 {5950, 29, 107, 28, 26, 28, 51, 25, 22, 40, 34},
264 {5940, 29, 107, 28, 25, 28, 51, 25, 22, 40, 34},
265 {5930, 29, 106, 28, 25, 28, 50, 25, 22, 40, 34},
266 {5920, 29, 106, 28, 25, 28, 50, 25, 22, 40, 34},
267 {5910, 29, 106, 28, 25, 28, 50, 25, 22, 40, 34},
268 {5900, 29, 106, 28, 25, 28, 50, 24, 22, 40, 33},
269 {5890, 29, 105, 28, 25, 28, 50, 24, 22, 40, 33},
270 {5880, 29, 105, 28, 25, 28, 50, 24, 22, 40, 33},
271 {5870, 29, 105, 28, 25, 27, 51, 24, 22, 40, 33},
272 {5860, 29, 105, 28, 25, 27, 51, 24, 21, 40, 33},
273 {5850, 29, 104, 28, 25, 27, 50, 24, 21, 40, 33},
274 {5840, 28, 105, 28, 25, 27, 50, 24, 21, 40, 33},
275 {5830, 28, 105, 28, 25, 27, 50, 24, 21, 40, 33},
276 {5820, 28, 105, 28, 25, 27, 50, 24, 21, 40, 33},
277 {5810, 28, 104, 28, 25, 27, 50, 24, 21, 39, 33},
278 {5800, 28, 104, 27, 25, 27, 50, 24, 21, 39, 33},
279 {5790, 28, 104, 27, 25, 27, 50, 24, 21, 39, 33},
280 {5780, 28, 104, 27, 25, 27, 49, 24, 21, 39, 33},
281 {5770, 28, 104, 27, 25, 27, 49, 24, 21, 39, 33},
282 {5760, 28, 103, 27, 25, 27, 49, 24, 21, 39, 33},
283 {5750, 28, 103, 27, 25, 27, 49, 24, 21, 39, 33},
284 {5740, 28, 103, 27, 25, 27, 49, 24, 21, 39, 33},
285 {5730, 28, 103, 27, 25, 27, 49, 24, 21, 39, 32},
286 {5720, 28, 102, 27, 25, 27, 49, 24, 21, 39, 32},
287 {5710, 28, 102, 27, 25, 27, 48, 24, 21, 39, 32},
288 {5700, 28, 102, 27, 24, 27, 48, 24, 21, 39, 32},
289 {5690, 28, 102, 27, 24, 27, 48, 24, 21, 39, 32},
290 {5680, 28, 101, 27, 24, 27, 48, 24, 21, 39, 32},
291 {5670, 28, 101, 27, 24, 27, 48, 23, 21, 38, 32},
292 {5660, 28, 101, 27, 24, 26, 49, 23, 21, 38, 32},
293 {5650, 28, 101, 27, 24, 26, 49, 23, 21, 38, 32},
294 {5640, 27, 101, 27, 24, 26, 48, 23, 21, 38, 32},
295 {5630, 27, 101, 27, 24, 26, 48, 23, 21, 38, 32},
296 {5620, 27, 101, 27, 24, 26, 48, 23, 21, 38, 32},
297 {5610, 27, 101, 27, 24, 26, 48, 23, 21, 38, 32},
298 {5600, 27, 101, 26, 24, 26, 48, 23, 20, 38, 32},
299 {5590, 27, 100, 26, 24, 26, 48, 23, 20, 38, 32},
300 {5580, 27, 100, 26, 24, 26, 48, 23, 20, 38, 32},
301 {5570, 27, 100, 26, 24, 26, 48, 23, 20, 38, 31},
302 {5560, 27, 100, 26, 24, 26, 47, 23, 20, 38, 31},
303 {5550, 27, 99, 26, 24, 26, 47, 23, 20, 38, 31},
304 {5540, 27, 99, 26, 24, 26, 47, 23, 20, 38, 31},
305 {5530, 27, 99, 26, 24, 26, 47, 23, 20, 38, 31},
306 {5520, 27, 99, 26, 24, 26, 47, 23, 20, 37, 31},
307 {5510, 27, 98, 26, 24, 26, 47, 23, 20, 37, 31},
308 {5500, 27, 98, 26, 24, 26, 47, 23, 20, 37, 31},
309 {5490, 27, 98, 26, 24, 26, 46, 23, 20, 37, 31},
310 {5480, 27, 98, 26, 24, 26, 46, 23, 20, 37, 31},
311 {5470, 27, 97, 26, 23, 26, 46, 23, 20, 37, 31},
312 {5460, 27, 97, 26, 23, 26, 46, 23, 20, 37, 31},
313 {5450, 27, 97, 26, 23, 25, 47, 23, 20, 37, 31},
314 {5440, 26, 98, 26, 23, 25, 47, 23, 20, 37, 31},
315 {5430, 26, 98, 26, 23, 25, 47, 22, 20, 37, 31},
316 {5420, 26, 97, 26, 23, 25, 46, 22, 20, 37, 31},
317 {5410, 26, 97, 26, 23, 25, 46, 22, 20, 37, 31},
318 {5400, 26, 97, 25, 23, 25, 46, 22, 20, 37, 30},
319 {5390, 26, 97, 25, 23, 25, 46, 22, 20, 37, 30},
320 {5380, 26, 96, 25, 23, 25, 46, 22, 20, 36, 30},
321 {5370, 26, 96, 25, 23, 25, 46, 22, 20, 36, 30},
322 {5360, 26, 96, 25, 23, 25, 46, 22, 20, 36, 30},
323 {5350, 26, 96, 25, 23, 25, 46, 22, 20, 36, 30},
324 {5340, 26, 95, 25, 23, 25, 45, 22, 20, 36, 30},
325 {5330, 26, 95, 25, 23, 25, 45, 22, 19, 36, 30},
326 {5320, 26, 95, 25, 23, 25, 45, 22, 19, 36, 30},
327 {5310, 26, 95, 25, 23, 25, 45, 22, 19, 36, 30},
328 {5300, 26, 95, 25, 23, 25, 45, 22, 19, 36, 30},
329 {5290, 26, 94, 25, 23, 25, 45, 22, 19, 36, 30},
330 {5280, 26, 94, 25, 23, 25, 45, 22, 19, 36, 30},
331 {5270, 26, 94, 25, 23, 25, 44, 22, 19, 36, 30},
332 {5260, 26, 94, 25, 23, 25, 44, 22, 19, 36, 30},
333 {5250, 25, 94, 25, 23, 24, 45, 22, 19, 36, 30},
334 {5240, 25, 94, 25, 23, 24, 45, 22, 19, 36, 29},
335 {5230, 25, 94, 25, 22, 24, 45, 22, 19, 35, 29},
336 {5220, 25, 94, 25, 22, 24, 45, 22, 19, 35, 29},
337 {5210, 25, 93, 25, 22, 24, 45, 22, 19, 35, 29},
338 {5200, 25, 93, 24, 22, 24, 44, 21, 19, 35, 29},
339 {5190, 25, 93, 24, 22, 24, 44, 21, 19, 35, 29},
340 {5180, 25, 93, 24, 22, 24, 44, 21, 19, 35, 29},
341 {5170, 25, 92, 24, 22, 24, 44, 21, 19, 35, 29},
342 {5160, 25, 92, 24, 22, 24, 44, 21, 19, 35, 29},
343 {5150, 25, 92, 24, 22, 24, 44, 21, 19, 35, 29},
344 {5140, 25, 92, 24, 22, 24, 44, 21, 19, 35, 29},
345 {5130, 25, 92, 24, 22, 24, 43, 21, 19, 35, 29},
346 {5120, 25, 91, 24, 22, 24, 43, 21, 19, 35, 29},
347 {5110, 25, 91, 24, 22, 24, 43, 21, 19, 35, 29},
348 {5100, 25, 91, 24, 22, 24, 43, 21, 19, 35, 29},
349 {5090, 25, 91, 24, 22, 24, 43, 21, 19, 34, 29},
350 {5080, 25, 90, 24, 22, 24, 43, 21, 19, 34, 29},
351 {5070, 25, 90, 24, 22, 24, 43, 21, 19, 34, 28},
352 {5060, 25, 90, 24, 22, 24, 43, 21, 18, 34, 28},
353 {5050, 24, 91, 24, 22, 24, 42, 21, 18, 34, 28},
354 {5040, 24, 90, 24, 22, 23, 43, 21, 18, 34, 28},
355 {5030, 24, 90, 24, 22, 23, 43, 21, 18, 34, 28},
356 {5020, 24, 90, 24, 22, 23, 43, 21, 18, 34, 28},
357 {5010, 24, 90, 24, 22, 23, 43, 21, 18, 34, 28},
358 {5000, 24, 89, 23, 21, 23, 43, 21, 18, 34, 28},
359 {4990, 24, 89, 23, 21, 23, 43, 21, 18, 34, 28},
360 {4980, 24, 89, 23, 21, 23, 42, 21, 18, 34, 28},
361 {4970, 24, 89, 23, 21, 23, 42, 21, 18, 34, 28},
362 {4960, 24, 89, 23, 21, 23, 42, 20, 18, 34, 28},
363 {4950, 24, 88, 23, 21, 23, 42, 20, 18, 34, 28},
364 {4940, 24, 88, 23, 21, 23, 42, 20, 18, 33, 28},
365 {4930, 24, 88, 23, 21, 23, 42, 20, 18, 33, 28},
366 {4920, 24, 88, 23, 21, 23, 42, 20, 18, 33, 28},
367 {4910, 24, 87, 23, 21, 23, 41, 20, 18, 33, 28},
368 {4900, 24, 87, 23, 21, 23, 41, 20, 18, 33, 27},
369 {4890, 24, 87, 23, 21, 23, 41, 20, 18, 33, 27},
370 {4880, 24, 87, 23, 21, 23, 41, 20, 18, 33, 27},
371 {4870, 24, 86, 23, 21, 23, 41, 20, 18, 33, 27},
372 {4860, 24, 86, 23, 21, 23, 41, 20, 18, 33, 27},
373 {4850, 23, 87, 23, 21, 23, 41, 20, 18, 33, 27},
374 {4840, 23, 87, 23, 21, 23, 40, 20, 18, 33, 27},
375 {4830, 23, 86, 23, 21, 22, 41, 20, 18, 33, 27},
376 {4820, 23, 86, 23, 21, 22, 41, 20, 18, 33, 27},
377 {4810, 23, 86, 23, 21, 22, 41, 20, 18, 33, 27},
378 {4800, 23, 86, 22, 21, 22, 41, 20, 17, 32, 27},
379 {4790, 23, 86, 22, 21, 22, 41, 20, 17, 32, 27},
380 {4780, 23, 85, 22, 21, 22, 41, 20, 17, 32, 27},
381 {4770, 23, 85, 22, 21, 22, 41, 20, 17, 32, 27},
382 {4760, 23, 85, 22, 20, 22, 40, 20, 17, 32, 27},
383 {4750, 23, 85, 22, 20, 22, 40, 20, 17, 32, 27},
384 {4740, 23, 84, 22, 20, 22, 40, 20, 17, 32, 26},
385 {4730, 23, 84, 22, 20, 22, 40, 19, 17, 32, 26},
386 {4720, 23, 84, 22, 20, 22, 40, 19, 17, 32, 26},
387 {4710, 23, 84, 22, 20, 22, 40, 19, 17, 32, 26},
388 {4700, 23, 83, 22, 20, 22, 40, 19, 17, 32, 26},
389 {4690, 23, 83, 22, 20, 22, 39, 19, 17, 32, 26},
390 {4680, 23, 83, 22, 20, 22, 39, 19, 17, 32, 26},
391 {4670, 23, 83, 22, 20, 22, 39, 19, 17, 32, 26},
392 {4660, 23, 82, 22, 20, 22, 39, 19, 17, 32, 26},
393 {4650, 22, 83, 22, 20, 22, 39, 19, 17, 31, 26},
394 {4640, 22, 83, 22, 20, 22, 39, 19, 17, 31, 26},
395 {4630, 22, 83, 22, 20, 22, 39, 19, 17, 31, 26},
396 {4620, 22, 83, 22, 20, 21, 39, 19, 17, 31, 26},
397 {4610, 22, 82, 22, 20, 21, 39, 19, 17, 31, 26},
398 {4600, 22, 82, 21, 20, 21, 39, 19, 17, 31, 26},
399 {4590, 22, 82, 21, 20, 21, 39, 19, 17, 31, 26},
400 {4580, 22, 82, 21, 20, 21, 39, 19, 17, 31, 26},
401 {4570, 22, 81, 21, 20, 21, 39, 19, 17, 31, 25},
402 {4560, 22, 81, 21, 20, 21, 39, 19, 17, 31, 25},
403 {4550, 22, 81, 21, 20, 21, 38, 19, 17, 31, 25},
404 {4540, 22, 81, 21, 20, 21, 38, 19, 17, 31, 25},
405 {4530, 22, 80, 21, 19, 21, 38, 19, 16, 31, 25},
406 {4520, 22, 80, 21, 19, 21, 38, 19, 16, 31, 25},
407 {4510, 22, 80, 21, 19, 21, 38, 19, 16, 31, 25},
408 {4500, 22, 80, 21, 19, 21, 38, 19, 16, 30, 25},
409 {4490, 22, 80, 21, 19, 21, 38, 18, 16, 30, 25},
410 {4480, 22, 79, 21, 19, 21, 38, 18, 16, 30, 25},
411 {4470, 22, 79, 21, 19, 21, 37, 18, 16, 30, 25},
412 {4460, 22, 79, 21, 19, 21, 37, 18, 16, 30, 25},
413 {4450, 21, 80, 21, 19, 21, 37, 18, 16, 30, 25},
414 {4440, 21, 79, 21, 19, 21, 37, 18, 16, 30, 25},
415 {4430, 21, 79, 21, 19, 21, 37, 18, 16, 30, 25},
416 {4420, 21, 79, 21, 19, 21, 37, 18, 16, 30, 25},
417 {4410, 21, 79, 21, 19, 20, 38, 18, 16, 30, 25},
418 {4400, 21, 78, 20, 19, 20, 37, 18, 16, 30, 24},
419 {4390, 21, 78, 20, 19, 20, 37, 18, 16, 30, 24},
420 {4380, 21, 78, 20, 19, 20, 37, 18, 16, 30, 24},
421 {4370, 21, 78, 20, 19, 20, 37, 18, 16, 30, 24},
422 {4360, 21, 77, 20, 19, 20, 37, 18, 16, 29, 24},
423 {4350, 21, 77, 20, 19, 20, 37, 18, 16, 29, 24},
424 {4340, 21, 77, 20, 19, 20, 37, 18, 16, 29, 24},
425 {4330, 21, 77, 20, 19, 20, 36, 18, 16, 29, 24},
426 {4320, 21, 77, 20, 19, 20, 36, 18, 16, 29, 24},
427 {4310, 21, 76, 20, 19, 20, 36, 18, 16, 29, 24},
428 {4300, 21, 76, 20, 18, 20, 36, 18, 16, 29, 24},
429 {4290, 21, 76, 20, 18, 20, 36, 18, 16, 29, 24},
430 {4280, 21, 76, 20, 18, 20, 36, 18, 16, 29, 24},
431 {4270, 21, 75, 20, 18, 20, 36, 18, 16, 29, 24},
432 {4260, 21, 75, 20, 18, 20, 35, 17, 15, 29, 24},
433 {4250, 20, 76, 20, 18, 20, 35, 17, 15, 29, 24},
434 {4240, 20, 76, 20, 18, 20, 35, 17, 15, 29, 23},
435 {4230, 20, 75, 20, 18, 20, 35, 17, 15, 29, 23},
436 {4220, 20, 75, 20, 18, 20, 35, 17, 15, 29, 23},
437 {4210, 20, 75, 20, 18, 20, 35, 17, 15, 28, 23},
438 {4200, 20, 75, 19, 18, 19, 36, 17, 15, 28, 23},
439 {4190, 20, 74, 19, 18, 19, 36, 17, 15, 28, 23},
440 {4180, 20, 74, 19, 18, 19, 35, 17, 15, 28, 23},
441 {4170, 20, 74, 19, 18, 19, 35, 17, 15, 28, 23},
442 {4160, 20, 74, 19, 18, 19, 35, 17, 15, 28, 23},
443 {4150, 20, 74, 19, 18, 19, 35, 17, 15, 28, 23},
444 {4140, 20, 73, 19, 18, 19, 35, 17, 15, 28, 23},
445 {4130, 20, 73, 19, 18, 19, 35, 17, 15, 28, 23},
446 {4120, 20, 73, 19, 18, 19, 35, 17, 15, 28, 23},
447 {4110, 20, 73, 19, 18, 19, 34, 17, 15, 28, 23},
448 {4100, 20, 72, 19, 18, 19, 34, 17, 15, 28, 23},
449 {4090, 20, 72, 19, 18, 19, 34, 17, 15, 28, 23},
450 {4080, 20, 72, 19, 18, 19, 34, 17, 15, 28, 23},
451 {4070, 20, 72, 19, 18, 19, 34, 17, 15, 27, 22},
452 {4060, 19, 72, 19, 17, 19, 34, 17, 15, 27, 22},
453 {4050, 19, 72, 19, 17, 19, 34, 17, 15, 27, 22},
454 {4040, 19, 72, 19, 17, 19, 33, 17, 15, 27, 22},
455 {4030, 19, 72, 19, 17, 19, 33, 17, 15, 27, 22},
456 {4020, 19, 71, 19, 17, 19, 33, 16, 15, 27, 22},
457 {4010, 19, 71, 19, 17, 19, 33, 16, 15, 27, 22},
458 {4000, 19, 71, 18, 17, 19, 33, 16, 14, 27, 22},
459 {3990, 19, 71, 18, 17, 18, 34, 16, 14, 27, 22},
460 {3980, 19, 71, 18, 17, 18, 34, 16, 14, 27, 22},
461 {3970, 19, 70, 18, 17, 18, 33, 16, 14, 27, 22},
462 {3960, 19, 70, 18, 17, 18, 33, 16, 14, 27, 22},
463 {3950, 19, 70, 18, 17, 18, 33, 16, 14, 27, 22},
464 {3940, 19, 70, 18, 17, 18, 33, 16, 14, 27, 22},
465 {3930, 19, 69, 18, 17, 18, 33, 16, 14, 27, 22},
466 {3920, 19, 69, 18, 17, 18, 33, 16, 14, 26, 22},
467 {3910, 19, 69, 18, 17, 18, 33, 16, 14, 26, 22},
468 {3900, 19, 69, 18, 17, 18, 33, 16, 14, 26, 21},
469 {3890, 19, 68, 18, 17, 18, 32, 16, 14, 26, 21},
470 {3880, 19, 68, 18, 17, 18, 32, 16, 14, 26, 21},
471 {3870, 19, 68, 18, 17, 18, 32, 16, 14, 26, 21},
472 {3860, 18, 69, 18, 17, 18, 32, 16, 14, 26, 21},
473 {3850, 18, 68, 18, 17, 18, 32, 16, 14, 26, 21},
474 {3840, 18, 68, 18, 17, 18, 32, 16, 14, 26, 21},
475 {3830, 18, 68, 18, 16, 18, 32, 16, 14, 26, 21},
476 {3820, 18, 68, 18, 16, 18, 31, 16, 14, 26, 21},
477 {3810, 18, 68, 18, 16, 18, 31, 16, 14, 26, 21},
478 {3800, 18, 67, 17, 16, 18, 31, 16, 14, 26, 21},
479 {3790, 18, 67, 17, 16, 17, 32, 15, 14, 26, 21},
480 {3780, 18, 67, 17, 16, 17, 32, 15, 14, 25, 21},
481 {3770, 18, 67, 17, 16, 17, 32, 15, 14, 25, 21},
482 {3760, 18, 66, 17, 16, 17, 32, 15, 14, 25, 21},
483 {3750, 18, 66, 17, 16, 17, 31, 15, 14, 25, 21},
484 {3740, 18, 66, 17, 16, 17, 31, 15, 14, 25, 20},
485 {3730, 18, 66, 17, 16, 17, 31, 15, 13, 25, 20},
486 {3720, 18, 65, 17, 16, 17, 31, 15, 13, 25, 20},
487 {3710, 18, 65, 17, 16, 17, 31, 15, 13, 25, 20},
488 {3700, 18, 65, 17, 16, 17, 31, 15, 13, 25, 20},
489 {3690, 18, 65, 17, 16, 17, 31, 15, 13, 25, 20},
490 {3680, 18, 64, 17, 16, 17, 31, 15, 13, 25, 20},
491 {3670, 18, 64, 17, 16, 17, 30, 15, 13, 25, 20},
492 {3660, 17, 65, 17, 16, 17, 30, 15, 13, 25, 20},
493 {3650, 17, 65, 17, 16, 17, 30, 15, 13, 25, 20},
494 {3640, 17, 65, 17, 16, 17, 30, 15, 13, 25, 20},
495 {3630, 17, 64, 17, 16, 17, 30, 15, 13, 24, 20},
496 {3620, 17, 64, 17, 16, 17, 30, 15, 13, 24, 20},
497 {3610, 17, 64, 17, 16, 17, 30, 15, 13, 24, 20},
498 {3600, 17, 64, 16, 16, 17, 29, 15, 13, 24, 20},
499 {3590, 17, 63, 16, 15, 17, 29, 15, 13, 24, 20},
500 {3580, 17, 63, 16, 15, 16, 30, 15, 13, 24, 20},
501 {3570, 17, 63, 16, 15, 16, 30, 15, 13, 24, 19},
502 {3560, 17, 63, 16, 15, 16, 30, 14, 13, 24, 19},
503 {3550, 17, 62, 16, 15, 16, 30, 14, 13, 24, 19},
504 {3540, 17, 62, 16, 15, 16, 30, 14, 13, 24, 19},
505 {3530, 17, 62, 16, 15, 16, 29, 14, 13, 24, 19},
506 {3520, 17, 62, 16, 15, 16, 29, 14, 13, 24, 19},
507 {3510, 17, 62, 16, 15, 16, 29, 14, 13, 24, 19},
508 {3500, 17, 61, 16, 15, 16, 29, 14, 13, 24, 19},
509 {3490, 17, 61, 16, 15, 16, 29, 14, 13, 23, 19},
510 {3480, 17, 61, 16, 15, 16, 29, 14, 13, 23, 19},
511 {3470, 17, 61, 16, 15, 16, 29, 14, 13, 23, 19},
512 {3460, 16, 61, 16, 15, 16, 28, 14, 12, 23, 19},
513 {3450, 16, 61, 16, 15, 16, 28, 14, 12, 23, 19},
514 {3440, 16, 61, 16, 15, 16, 28, 14, 12, 23, 19},
515 {3430, 16, 61, 16, 15, 16, 28, 14, 12, 23, 19},
516 {3420, 16, 60, 16, 15, 16, 28, 14, 12, 23, 19},
517 {3410, 16, 60, 16, 15, 16, 28, 14, 12, 23, 18},
518 {3400, 16, 60, 15, 15, 16, 28, 14, 12, 23, 18},
519 {3390, 16, 60, 15, 15, 16, 28, 14, 12, 23, 18},
520 {3380, 16, 59, 15, 15, 16, 27, 14, 12, 23, 18},
521 {3370, 16, 59, 15, 15, 15, 28, 14, 12, 23, 18},
522 {3360, 16, 59, 15, 14, 15, 28, 14, 12, 23, 18},
523 {3350, 16, 59, 15, 14, 15, 28, 14, 12, 23, 18},
524 {3340, 16, 59, 15, 14, 15, 28, 14, 12, 22, 18},
525 {3330, 16, 58, 15, 14, 15, 28, 14, 12, 22, 18},
526 {3320, 16, 58, 15, 14, 15, 28, 13, 12, 22, 18},
527 {3310, 16, 58, 15, 14, 15, 27, 13, 12, 22, 18},
528 {3300, 16, 58, 15, 14, 15, 27, 13, 12, 22, 18},
529 {3290, 16, 57, 15, 14, 15, 27, 13, 12, 22, 18},
530 {3280, 16, 57, 15, 14, 15, 27, 13, 12, 22, 18},
531 {3270, 16, 57, 15, 14, 15, 27, 13, 12, 22, 18},
532 {3260, 15, 58, 15, 14, 15, 27, 13, 12, 22, 18},
533 {3250, 15, 57, 15, 14, 15, 27, 13, 12, 22, 18},
534 {3240, 15, 57, 15, 14, 15, 26, 13, 12, 22, 17},
535 {3230, 15, 57, 15, 14, 15, 26, 13, 12, 22, 17},
536 {3220, 15, 57, 15, 14, 15, 26, 13, 12, 22, 17},
537 {3210, 15, 56, 15, 14, 15, 26, 13, 12, 22, 17},
538 {3200, 15, 56, 14, 14, 15, 26, 13, 11, 21, 17},
539 {3190, 15, 56, 14, 14, 15, 26, 13, 11, 21, 17},
540 {3180, 15, 56, 14, 14, 15, 26, 13, 11, 21, 17},
541 {3170, 15, 56, 14, 14, 15, 25, 13, 11, 21, 17},
542 {3160, 15, 55, 14, 14, 14, 26, 13, 11, 21, 17},
543 {3150, 15, 55, 14, 14, 14, 26, 13, 11, 21, 17},
544 {3140, 15, 55, 14, 14, 14, 26, 13, 11, 21, 17},
545 {3130, 15, 55, 14, 14, 14, 26, 13, 11, 21, 17},
546 {3120, 15, 54, 14, 13, 14, 26, 13, 11, 21, 17},
547 {3110, 15, 54, 14, 13, 14, 26, 13, 11, 21, 17},
548 {3100, 15, 54, 14, 13, 14, 26, 13, 11, 21, 17},
549 {3090, 15, 54, 14, 13, 14, 25, 12, 11, 21, 17},
550 {3080, 15, 53, 14, 13, 14, 25, 12, 11, 21, 17},
551 {3070, 14, 54, 14, 13, 14, 25, 12, 11, 21, 16},
552 {3060, 14, 54, 14, 13, 14, 25, 12, 11, 21, 16},
553 {3050, 14, 54, 14, 13, 14, 25, 12, 11, 20, 16},
554 {3040, 14, 53, 14, 13, 14, 25, 12, 11, 20, 16},
555 {3030, 14, 53, 14, 13, 14, 25, 12, 11, 20, 16},
556 {3020, 14, 53, 14, 13, 14, 24, 12, 11, 20, 16},
557 {3010, 14, 53, 14, 13, 14, 24, 12, 11, 20, 16},
558 {3000, 14, 53, 13, 13, 14, 24, 12, 11, 20, 16},
559 {2990, 14, 52, 13, 13, 14, 24, 12, 11, 20, 16},
560 {2980, 14, 52, 13, 13, 14, 24, 12, 11, 20, 16},
561 {2970, 14, 52, 13, 13, 14, 24, 12, 11, 20, 16},
562 {2960, 14, 52, 13, 13, 14, 24, 12, 11, 20, 16},
563 {2950, 14, 51, 13, 13, 13, 24, 12, 11, 20, 16},
564 {2940, 14, 51, 13, 13, 13, 24, 12, 11, 20, 16},
565 {2930, 14, 51, 13, 13, 13, 24, 12, 10, 20, 16},
566 {2920, 14, 51, 13, 13, 13, 24, 12, 10, 20, 16},
567 {2910, 14, 50, 13, 13, 13, 24, 12, 10, 20, 15},
568 {2900, 14, 50, 13, 13, 13, 24, 12, 10, 19, 15},
569 {2890, 14, 50, 13, 12, 13, 24, 12, 10, 19, 15},
570 {2880, 14, 50, 13, 12, 13, 23, 12, 10, 19, 15},
571 {2870, 13, 50, 13, 12, 13, 23, 12, 10, 19, 15},
572 {2860, 13, 50, 13, 12, 13, 23, 12, 10, 19, 15},
573 {2850, 13, 50, 13, 12, 13, 23, 11, 10, 19, 15},
574 {2840, 13, 50, 13, 12, 13, 23, 11, 10, 19, 15},
575 {2830, 13, 50, 13, 12, 13, 23, 11, 10, 19, 15},
576 {2820, 13, 49, 13, 12, 13, 23, 11, 10, 19, 15},
577 {2810, 13, 49, 13, 12, 13, 23, 11, 10, 19, 15},
578 {2800, 13, 49, 12, 12, 13, 22, 11, 10, 19, 15},
579 {2790, 13, 49, 12, 12, 13, 22, 11, 10, 19, 15},
580 {2780, 13, 48, 12, 12, 13, 22, 11, 10, 19, 15},
581 {2770, 13, 48, 12, 12, 13, 22, 11, 10, 19, 15},
582 {2760, 13, 48, 12, 12, 13, 22, 11, 10, 18, 15},
583 {2750, 13, 48, 12, 12, 13, 22, 11, 10, 18, 15},
584 {2740, 13, 47, 12, 12, 12, 23, 11, 10, 18, 14},
585 {2730, 13, 47, 12, 12, 12, 22, 11, 10, 18, 14},
586 {2720, 13, 47, 12, 12, 12, 22, 11, 10, 18, 14},
587 {2710, 13, 47, 12, 12, 12, 22, 11, 10, 18, 14},
588 {2700, 13, 47, 12, 12, 12, 22, 11, 10, 18, 14},
589 {2690, 13, 46, 12, 12, 12, 22, 11, 10, 18, 14},
590 {2680, 13, 46, 12, 12, 12, 22, 11, 10, 18, 14},
591 {2670, 12, 47, 12, 12, 12, 22, 11, 10, 18, 14},
592 {2660, 12, 47, 12, 12, 12, 21, 11, 9, 18, 14},
593 {2650, 12, 46, 12, 11, 12, 21, 11, 9, 18, 14},
594 {2640, 12, 46, 12, 11, 12, 21, 11, 9, 18, 14},
595 {2630, 12, 46, 12, 11, 12, 21, 11, 9, 18, 14},
596 {2620, 12, 46, 12, 11, 12, 21, 10, 9, 18, 14},
597 {2610, 12, 45, 12, 11, 12, 21, 10, 9, 17, 14},
598 {2600, 12, 45, 11, 11, 12, 21, 10, 9, 17, 14},
599 {2590, 12, 45, 11, 11, 12, 20, 10, 9, 17, 14},
600 {2580, 12, 45, 11, 11, 12, 20, 10, 9, 17, 14},
601 {2570, 12, 44, 11, 11, 12, 20, 10, 9, 17, 13},
602 {2560, 12, 44, 11, 11, 12, 20, 10, 9, 17, 13},
603 {2550, 12, 44, 11, 11, 12, 20, 10, 9, 17, 13},
604 {2540, 12, 44, 11, 11, 11, 21, 10, 9, 17, 13},
605 {2530, 12, 44, 11, 11, 11, 21, 10, 9, 17, 13},
606 {2520, 12, 43, 11, 11, 11, 21, 10, 9, 17, 13},
607 {2510, 12, 43, 11, 11, 11, 20, 10, 9, 17, 13},
608 {2500, 12, 43, 11, 11, 11, 20, 10, 9, 17, 13},
609 {2490, 12, 43, 11, 11, 11, 20, 10, 9, 17, 13},
610 {2480, 12, 42, 11, 11, 11, 20, 10, 9, 17, 13},
611 {2470, 11, 43, 11, 11, 11, 20, 10, 9, 16, 13},
612 {2460, 11, 43, 11, 11, 11, 20, 10, 9, 16, 13},
613 {2450, 11, 43, 11, 11, 11, 20, 10, 9, 16, 13},
614 {2440, 11, 42, 11, 11, 11, 19, 10, 9, 16, 13},
615 {2430, 11, 42, 11, 11, 11, 19, 10, 9, 16, 13},
616 {2420, 11, 42, 11, 10, 11, 19, 10, 9, 16, 13},
617 {2410, 11, 42, 11, 10, 11, 19, 10, 9, 16, 12},
618 {2400, 11, 41, 10, 10, 11, 19, 10, 8, 16, 12},
619 {2390, 11, 41, 10, 10, 11, 19, 10, 8, 16, 12},
620 {2380, 11, 41, 10, 10, 11, 19, 9, 8, 16, 12},
621 {2370, 11, 41, 10, 10, 11, 18, 9, 8, 16, 12},
622 {2360, 11, 41, 10, 10, 11, 18, 9, 8, 16, 12},
623 {2350, 11, 40, 10, 10, 11, 18, 9, 8, 16, 12},
624 {2340, 11, 40, 10, 10, 11, 18, 9, 8, 16, 12},
625 {2330, 11, 40, 10, 10, 10, 19, 9, 8, 16, 12},
626 {2320, 11, 40, 10, 10, 10, 19, 9, 8, 15, 12},
627 {2310, 11, 39, 10, 10, 10, 19, 9, 8, 15, 12},
628 {2300, 11, 39, 10, 10, 10, 18, 9, 8, 15, 12},
629 {2290, 11, 39, 10, 10, 10, 18, 9, 8, 15, 12},
630 {2280, 11, 39, 10, 10, 10, 18, 9, 8, 15, 12},
631 {2270, 10, 39, 10, 10, 10, 18, 9, 8, 15, 12},
632 {2260, 10, 39, 10, 10, 10, 18, 9, 8, 15, 12},
633 {2250, 10, 39, 10, 10, 10, 18, 9, 8, 15, 12},
634 {2240, 10, 39, 10, 10, 10, 18, 9, 8, 15, 11},
635 {2230, 10, 38, 10, 10, 10, 18, 9, 8, 15, 11},
636 {2220, 10, 38, 10, 10, 10, 17, 9, 8, 15, 11},
637 {2210, 10, 38, 10, 10, 10, 17, 9, 8, 15, 11},
638 {2200, 10, 38, 9, 10, 10, 17, 9, 8, 15, 11},
639 {2190, 10, 38, 9, 9, 10, 17, 9, 8, 15, 11},
640 {2180, 10, 37, 9, 9, 10, 17, 9, 8, 14, 11},
641 {2170, 10, 37, 9, 9, 10, 17, 9, 8, 14, 11},
642 {2160, 10, 37, 9, 9, 10, 17, 9, 8, 14, 11},
643 {2150, 10, 37, 9, 9, 10, 16, 8, 8, 14, 11},
644 {2140, 10, 36, 9, 9, 10, 16, 8, 8, 14, 11},
645 {2130, 10, 36, 9, 9, 10, 16, 8, 7, 14, 11},
646 {2120, 10, 36, 9, 9, 9, 17, 8, 7, 14, 11},
647 {2110, 10, 36, 9, 9, 9, 17, 8, 7, 14, 11},
648 {2100, 10, 35, 9, 9, 9, 17, 8, 7, 14, 11},
649 {2090, 10, 35, 9, 9, 9, 17, 8, 7, 14, 11},
650 {2080, 9, 36, 9, 9, 9, 16, 8, 7, 14, 11},
651 {2070, 9, 36, 9, 9, 9, 16, 8, 7, 14, 10},
652 {2060, 9, 35, 9, 9, 9, 16, 8, 7, 14, 10},
653 {2050, 9, 35, 9, 9, 9, 16, 8, 7, 14, 10},
654 {2040, 9, 35, 9, 9, 9, 16, 8, 7, 14, 10},
655 {2030, 9, 35, 9, 9, 9, 16, 8, 7, 13, 10},
656 {2020, 9, 35, 9, 9, 9, 16, 8, 7, 13, 10},
657 {2010, 9, 34, 9, 9, 9, 15, 8, 7, 13, 10},
658 {2000, 9, 34, 8, 9, 9, 15, 8, 7, 13, 10},
659 {1990, 9, 34, 8, 9, 9, 15, 8, 7, 13, 10},
660 {1980, 9, 34, 8, 9, 9, 15, 8, 7, 13, 10},
661 {1970, 9, 33, 8, 9, 9, 15, 8, 7, 13, 10},
662 {1960, 9, 33, 8, 9, 9, 15, 8, 7, 13, 10},
663 {1950, 9, 33, 8, 8, 9, 15, 8, 7, 13, 10},
664 {1940, 9, 33, 8, 8, 9, 15, 8, 7, 13, 10},
665 {1930, 9, 32, 8, 8, 9, 14, 8, 7, 13, 10},
666 {1920, 9, 32, 8, 8, 9, 14, 8, 7, 13, 10},
667 {1910, 9, 32, 8, 8, 8, 15, 7, 7, 13, 9},
668 {1900, 9, 32, 8, 8, 8, 15, 7, 7, 13, 9},
669 {1890, 9, 31, 8, 8, 8, 15, 7, 7, 12, 9},
670 {1880, 8, 32, 8, 8, 8, 15, 7, 7, 12, 9},
671 {1870, 8, 32, 8, 8, 8, 15, 7, 7, 12, 9},
672 {1860, 8, 32, 8, 8, 8, 14, 7, 6, 12, 9},
673 {1850, 8, 32, 8, 8, 8, 14, 7, 6, 12, 9},
674 {1840, 8, 31, 8, 8, 8, 14, 7, 6, 12, 9},
675 {1830, 8, 31, 8, 8, 8, 14, 7, 6, 12, 9},
676 {1820, 8, 31, 8, 8, 8, 14, 7, 6, 12, 9},
677 {1810, 8, 31, 8, 8, 8, 14, 7, 6, 12, 9},
678 {1800, 8, 30, 7, 8, 8, 14, 7, 6, 12, 9},
679 {1790, 8, 30, 7, 8, 8, 13, 7, 6, 12, 9},
680 {1780, 8, 30, 7, 8, 8, 13, 7, 6, 12, 9},
681 {1770, 8, 30, 7, 8, 8, 13, 7, 6, 12, 9},
682 {1760, 8, 29, 7, 8, 8, 13, 7, 6, 12, 9},
683 {1750, 8, 29, 7, 8, 8, 13, 7, 6, 12, 9},
684 {1740, 8, 29, 7, 8, 8, 13, 7, 6, 11, 8},
685 {1730, 8, 29, 7, 8, 8, 13, 7, 6, 11, 8},
686 {1720, 8, 29, 7, 7, 8, 13, 7, 6, 11, 8},
687 {1710, 8, 28, 7, 7, 8, 12, 7, 6, 11, 8},
688 {1700, 8, 28, 7, 7, 7, 13, 7, 6, 11, 8},
689 {1690, 8, 28, 7, 7, 7, 13, 7, 6, 11, 8},
690 {1680, 7, 29, 7, 7, 7, 13, 6, 6, 11, 8},
691 {1670, 7, 28, 7, 7, 7, 13, 6, 6, 11, 8},
692 {1660, 7, 28, 7, 7, 7, 13, 6, 6, 11, 8},
693 {1650, 7, 28, 7, 7, 7, 13, 6, 6, 11, 8},
694 {1640, 7, 28, 7, 7, 7, 12, 6, 6, 11, 8},
695 {1630, 7, 27, 7, 7, 7, 12, 6, 6, 11, 8},
696 {1620, 7, 27, 7, 7, 7, 12, 6, 6, 11, 8},
697 {1610, 7, 27, 7, 7, 7, 12, 6, 6, 11, 8},
698 {1600, 7, 27, 6, 7, 7, 12, 6, 5, 10, 8},
699 {1590, 7, 26, 6, 7, 7, 12, 6, 5, 10, 8},
700 {1580, 7, 26, 6, 7, 7, 12, 6, 5, 10, 7},
701 {1570, 7, 26, 6, 7, 7, 11, 6, 5, 10, 7},
702 {1560, 7, 26, 6, 7, 7, 11, 6, 5, 10, 7},
703 {1550, 7, 26, 6, 7, 7, 11, 6, 5, 10, 7},
704 {1540, 7, 25, 6, 7, 7, 11, 6, 5, 10, 7},
705 {1530, 7, 25, 6, 7, 7, 11, 6, 5, 10, 7},
706 {1520, 7, 25, 6, 7, 7, 11, 6, 5, 10, 7},
707 {1510, 7, 25, 6, 7, 7, 11, 6, 5, 10, 7},
708 {1500, 7, 24, 6, 7, 7, 10, 6, 5, 10, 7},
709 {1490, 59, 25, 6, 77, 59, 10, 70, 44, 9, 73},
710 {1480, 59, 24, 6, 76, 58, 10, 70, 44, 9, 73},
711 {1470, 58, 24, 6, 76, 58, 10, 69, 44, 9, 72},
712 {1460, 58, 24, 6, 76, 58, 10, 69, 43, 9, 72},
713 {1450, 58, 24, 6, 75, 57, 10, 68, 43, 9, 71},
714 {1440, 57, 24, 6, 75, 57, 10, 68, 43, 9, 71},
715 {1430, 57, 23, 6, 75, 57, 10, 68, 43, 8, 70},
716 {1420, 56, 23, 6, 74, 57, 9, 67, 43, 8, 70},
717 {1410, 56, 23, 6, 74, 57, 9, 67, 43, 8, 69},
718 {1400, 56, 23, 5, 74, 55, 9, 67, 41, 8, 69},
719 {1390, 55, 23, 5, 73, 55, 9, 66, 41, 8, 68},
720 {1380, 55, 23, 5, 73, 54, 9, 66, 41, 8, 68},
721 {1370, 54, 22, 5, 72, 54, 9, 66, 41, 8, 67},
722 {1360, 54, 22, 5, 72, 54, 9, 65, 40, 8, 67},
723 {1350, 54, 22, 5, 72, 53, 9, 65, 40, 8, 66},
724 {1340, 53, 22, 5, 71, 53, 9, 65, 40, 8, 66},
725 {1330, 53, 22, 5, 71, 53, 9, 64, 39, 8, 65},
726 {1320, 52, 22, 5, 71, 53, 8, 64, 40, 8, 65},
727 {1310, 52, 21, 5, 70, 53, 8, 64, 40, 8, 64},
728 {1300, 51, 21, 5, 70, 51, 8, 63, 38, 8, 64},
729 {1290, 51, 21, 5, 70, 51, 8, 63, 38, 7, 64},
730 {1280, 51, 21, 5, 69, 51, 8, 63, 38, 7, 63},
731 {1270, 50, 21, 5, 69, 50, 8, 62, 38, 7, 63},
732 {1260, 50, 20, 5, 69, 50, 8, 62, 37, 7, 62},
733 {1250, 49, 20, 5, 68, 49, 8, 62, 37, 7, 62},
734 {1240, 49, 20, 5, 68, 49, 8, 61, 37, 7, 61},
735 {1230, 49, 20, 5, 68, 49, 8, 61, 36, 7, 61},
736 {1220, 48, 20, 5, 67, 48, 8, 61, 36, 7, 60},
737 {1210, 48, 19, 5, 67, 48, 7, 60, 36, 7, 60},
738 {1200, 49, 19, 4, 67, 49, 7, 60, 36, 7, 59},
739 {1190, 48, 19, 4, 66, 48, 7, 60, 36, 7, 59},
740 {1180, 48, 19, 4, 66, 48, 7, 59, 36, 7, 58},
741 {1170, 46, 19, 4, 66, 46, 7, 59, 35, 7, 58},
742 {1160, 46, 18, 4, 65, 46, 7, 59, 34, 7, 57},
743 {1150, 45, 18, 4, 65, 46, 7, 58, 34, 7, 57},
744 {1140, 45, 18, 4, 65, 45, 7, 58, 34, 6, 56},
745 {1130, 45, 18, 4, 64, 45, 7, 58, 33, 6, 56},
746 {1120, 44, 18, 4, 64, 44, 7, 57, 33, 6, 55},
747 {1110, 44, 18, 4, 64, 44, 7, 57, 33, 6, 55},
748 {1100, 43, 17, 4, 63, 44, 6, 57, 32, 6, 54},
749 {1090, 43, 17, 4, 63, 44, 6, 56, 33, 6, 54},
750 {1080, 43, 17, 4, 63, 44, 6, 56, 33, 6, 53},
751 {1070, 42, 17, 4, 62, 44, 6, 56, 33, 6, 53},
752 {1060, 42, 17, 4, 62, 42, 6, 55, 31, 6, 52},
753 {1050, 41, 17, 4, 62, 42, 6, 55, 31, 6, 52},
754 {1040, 41, 16, 4, 61, 41, 6, 54, 31, 6, 52},
755 {1030, 41, 16, 4, 61, 41, 6, 54, 30, 6, 51},
756 {1020, 40, 16, 4, 61, 41, 6, 54, 30, 6, 51},
757 {1010, 40, 16, 4, 60, 40, 6, 53, 30, 6, 50},
758 {1000, 39, 16, 3, 60, 40, 6, 53, 29, 5, 50},
759 { 990, 39, 15, 3, 60, 39, 6, 53, 29, 5, 49},
760 { 980, 39, 15, 3, 59, 39, 5, 52, 29, 5, 49},
761 { 970, 38, 15, 3, 59, 39, 5, 52, 29, 5, 48},
762 { 960, 38, 15, 3, 59, 39, 5, 52, 29, 5, 48},
763 { 950, 37, 15, 3, 58, 39, 5, 51, 29, 5, 47},
764 { 940, 37, 14, 3, 58, 39, 5, 51, 29, 5, 47},
765 { 930, 37, 14, 3, 57, 37, 5, 51, 27, 5, 46},
766 { 920, 36, 14, 3, 57, 37, 5, 50, 27, 5, 46},
767 { 910, 36, 14, 3, 57, 36, 5, 50, 27, 5, 45},
768 { 900, 35, 14, 3, 56, 36, 5, 50, 26, 5, 45},
769 { 890, 35, 14, 3, 56, 36, 5, 49, 26, 5, 44},
770 { 880, 35, 13, 3, 56, 35, 5, 49, 26, 5, 44},
771 { 870, 34, 13, 3, 55, 35, 4, 49, 26, 5, 43},
772 { 860, 34, 13, 3, 55, 35, 4, 48, 25, 5, 43},
773 { 850, 33, 13, 3, 55, 35, 4, 48, 26, 4, 42},
774 { 840, 33, 13, 3, 54, 35, 4, 48, 26, 4, 42},
775 { 830, 33, 12, 3, 54, 33, 4, 47, 24, 4, 41},
776 { 820, 32, 12, 3, 54, 33, 4, 47, 24, 4, 41},
777 { 810, 32, 12, 3, 53, 33, 4, 47, 24, 4, 40},
778 { 800, 31, 12, 2, 53, 32, 4, 46, 23, 4, 40},
779 { 790, 31, 12, 2, 53, 32, 4, 46, 23, 4, 39},
780 { 780, 30, 12, 2, 52, 31, 4, 46, 23, 4, 39},
781 { 770, 30, 11, 2, 52, 31, 4, 45, 23, 4, 39},
782 { 760, 30, 11, 2, 52, 31, 3, 45, 22, 4, 38},
783 { 750, 29, 11, 2, 51, 30, 3, 45, 22, 4, 38},
784 { 740, 29, 11, 2, 51, 30, 3, 44, 22, 4, 37},
785 { 730, 28, 11, 2, 51, 31, 3, 44, 22, 4, 37},
786 { 720, 28, 10, 2, 50, 30, 3, 44, 22, 4, 36},
787 { 710, 28, 10, 2, 50, 30, 3, 43, 22, 4, 36},
788 { 700, 27, 10, 2, 50, 28, 3, 43, 20, 3, 35},
789 { 690, 27, 10, 2, 49, 28, 3, 43, 20, 3, 35},
790 { 680, 26, 10, 2, 49, 28, 3, 42, 20, 3, 34},
791 { 670, 26, 10, 2, 49, 27, 3, 42, 20, 3, 34},
792 { 660, 26, 9, 2, 48, 27, 3, 42, 19, 3, 33},
793 { 650, 25, 9, 2, 48, 26, 3, 41, 19, 3, 33},
794 { 640, 25, 9, 2, 48, 26, 2, 41, 19, 3, 32},
795 { 630, 24, 9, 2, 47, 26, 2, 40, 18, 3, 32},
796 { 620, 24, 9, 2, 47, 26, 2, 40, 19, 3, 31},
797 { 610, 24, 8, 2, 47, 26, 2, 40, 19, 3, 31},
798 { 600, 23, 8, 1, 46, 26, 2, 39, 18, 3, 30},
799 { 590, 23, 8, 1, 46, 24, 2, 39, 17, 3, 30},
800 { 580, 22, 8, 1, 46, 24, 2, 39, 17, 3, 29},
801 { 570, 22, 8, 1, 45, 23, 2, 38, 17, 3, 29},
802 { 560, 22, 7, 1, 45, 23, 2, 38, 16, 2, 28},
803 { 550, 21, 7, 1, 45, 23, 2, 38, 16, 2, 28},
804 { 540, 21, 7, 1, 44, 22, 2, 37, 16, 2, 27},
805 { 530, 20, 7, 1, 44, 22, 1, 37, 15, 2, 27},
806 { 520, 20, 7, 1, 43, 21, 1, 37, 15, 2, 27},
807 { 510, 20, 6, 1, 43, 21, 1, 36, 15, 2, 26},
808 { 500, 19, 6, 1, 43, 22, 1, 36, 15, 2, 26},
809 { 490, 19, 6, 1, 42, 21, 1, 36, 15, 2, 25},
810 { 480, 18, 6, 1, 42, 21, 1, 35, 15, 2, 25},
811 { 470, 18, 6, 1, 42, 21, 1, 35, 15, 2, 24},
812 { 460, 18, 6, 1, 41, 19, 1, 35, 13, 2, 24},
813 { 450, 17, 5, 1, 41, 19, 1, 34, 13, 2, 23},
814 { 440, 17, 5, 1, 41, 18, 1, 34, 13, 2, 23},
815 { 430, 16, 5, 1, 40, 18, 0, 34, 12, 2, 22},
816 { 420, 16, 5, 1, 40, 18, 0, 33, 12, 2, 22},
817 { 410, 16, 5, 1, 40, 17, 0, 33, 12, 1, 21},
818 { 400, 15, 5, 0, 39, 17, 0, 33, 11, 1, 21},
819 { 390, 15, 4, 0, 39, 17, 0, 32, 12, 1, 20},
820 { 380, 14, 4, 0, 39, 17, 0, 32, 12, 1, 20},
821 { 370, 14, 4, 0, 38, 17, 0, 32, 12, 1, 19},
822 { 360, 14, 4, 0, 38, 15, 0, 31, 10, 1, 19},
823 { 350, 13, 4, 0, 38, 15, 0, 31, 10, 1, 18},
824 { 340, 13, 3, 0, 37, 15, 0, 31, 10, 1, 18},
825 { 330, 12, 3, 0, 37, 14, 0, 30, 9, 1, 17},
826 { 320, 12, 3, 0, 37, 14, 0, 30, 9, 1, 17},
827 { 310, 12, 3, 0, 36, 13, 0, 30, 9, 1, 16},
828 { 300, 11, 3, 0, 36, 13, 0, 29, 8, 1, 16},
829 { 290, 11, 2, 0, 36, 13, 0, 29, 8, 1, 15},
830 { 280, 10, 2, 0, 35, 12, 0, 29, 8, 1, 15},
831 { 270, 10, 2, 0, 35, 12, 0, 28, 8, 0, 14},
832 { 260, 9, 2, 0, 35, 12, 0, 28, 8, 0, 14},
833 { 250, 9, 2, 0, 34, 12, 0, 28, 8, 0, 14},
834 { 240, 9, 2, 0, 34, 12, 0, 27, 8, 0, 13},
835 { 230, 8, 1, 0, 34, 10, 0, 27, 6, 0, 13},
836 { 220, 8, 1, 0, 33, 10, 0, 27, 6, 0, 12},
837 { 210, 7, 1, 0, 33, 10, 0, 26, 6, 0, 12},
838 { 200, 7, 1, 0, 33, 9, 0, 26, 5, 0, 11},
839 { 190, 7, 1, 0, 32, 9, 0, 25, 5, 0, 11},
840 { 180, 6, 1, 0, 32, 8, 0, 25, 5, 0, 10},
841 { 170, 6, 0, 0, 32, 8, 0, 25, 5, 0, 10},
842 { 160, 5, 0, 0, 31, 8, 0, 24, 4, 0, 9},
843 { 150, 5, 0, 0, 31, 8, 0, 24, 5, 0, 9},
844 { 140, 5, 0, 0, 31, 8, 0, 24, 5, 0, 8},
845 { 130, 4, 0, 0, 30, 6, 0, 23, 3, 0, 8},
846 { 120, 4, 0, 0, 30, 6, 0, 23, 3, 0, 7},
847 { 110, 3, 0, 0, 30, 6, 0, 23, 3, 0, 7},
848 { 100, 3, 0, 0, 29, 5, 0, 22, 2, 0, 6},
849 { 90, 3, 0, 0, 29, 5, 0, 22, 2, 0, 6},
850 { 80, 2, 0, 0, 28, 5, 0, 22, 2, 0, 5},
851 };
852
853 static const
854 struct samsung_mipi_cphy_timing samsung_mipi_cphy_timing_table[] = {
855 { 3500, 39, 50, 25, 29, 54, 1 },
856 { 3490, 39, 50, 25, 29, 54, 1 },
857 { 3480, 39, 50, 25, 29, 54, 1 },
858 { 3470, 39, 50, 25, 29, 54, 1 },
859 { 3460, 39, 50, 25, 29, 54, 1 },
860 { 3450, 39, 50, 25, 29, 54, 1 },
861 { 3440, 38, 50, 25, 29, 54, 1 },
862 { 3430, 38, 50, 25, 29, 53, 1 },
863 { 3420, 38, 50, 25, 29, 53, 1 },
864 { 3410, 38, 50, 25, 29, 53, 1 },
865 { 3400, 38, 50, 25, 29, 53, 1 },
866 { 3390, 38, 50, 25, 29, 53, 1 },
867 { 3380, 38, 50, 25, 28, 53, 1 },
868 { 3370, 38, 50, 25, 28, 52, 1 },
869 { 3360, 37, 50, 25, 28, 52, 1 },
870 { 3350, 37, 50, 25, 28, 52, 1 },
871 { 3340, 37, 50, 25, 28, 52, 1 },
872 { 3330, 37, 50, 25, 28, 52, 1 },
873 { 3320, 37, 50, 25, 28, 52, 1 },
874 { 3310, 37, 50, 25, 28, 52, 1 },
875 { 3300, 37, 50, 25, 28, 51, 1 },
876 { 3290, 37, 50, 25, 28, 51, 1 },
877 { 3280, 37, 50, 25, 28, 51, 1 },
878 { 3270, 36, 50, 25, 28, 51, 1 },
879 { 3260, 36, 50, 25, 27, 51, 1 },
880 { 3250, 36, 50, 25, 27, 51, 1 },
881 { 3240, 36, 50, 25, 27, 50, 1 },
882 { 3230, 36, 50, 25, 27, 50, 1 },
883 { 3220, 36, 50, 25, 27, 50, 1 },
884 { 3210, 36, 50, 25, 27, 50, 1 },
885 { 3200, 36, 50, 25, 27, 50, 1 },
886 { 3190, 36, 50, 25, 27, 50, 1 },
887 { 3180, 35, 50, 25, 27, 49, 1 },
888 { 3170, 35, 50, 25, 27, 49, 1 },
889 { 3160, 35, 50, 25, 27, 49, 1 },
890 { 3150, 35, 50, 25, 26, 49, 1 },
891 { 3140, 35, 50, 25, 26, 49, 1 },
892 { 3130, 35, 50, 25, 26, 49, 1 },
893 { 3120, 35, 50, 25, 26, 49, 1 },
894 { 3110, 35, 50, 25, 26, 48, 1 },
895 { 3100, 34, 50, 25, 26, 48, 1 },
896 { 3090, 34, 50, 25, 26, 48, 1 },
897 { 3080, 34, 50, 25, 26, 48, 1 },
898 { 3070, 34, 50, 25, 26, 48, 1 },
899 { 3060, 34, 50, 25, 26, 48, 1 },
900 { 3050, 34, 50, 25, 26, 47, 1 },
901 { 3040, 34, 50, 25, 26, 47, 1 },
902 { 3030, 34, 50, 25, 25, 47, 1 },
903 { 3020, 34, 50, 25, 25, 47, 1 },
904 { 3010, 33, 50, 25, 25, 47, 1 },
905 { 3000, 33, 50, 25, 25, 47, 1 },
906 { 2990, 33, 50, 25, 25, 46, 1 },
907 { 2980, 33, 50, 25, 25, 46, 1 },
908 { 2970, 33, 50, 25, 25, 46, 1 },
909 { 2960, 33, 50, 25, 25, 46, 1 },
910 { 2950, 33, 50, 25, 25, 46, 1 },
911 { 2940, 33, 50, 25, 25, 46, 1 },
912 { 2930, 33, 50, 25, 25, 46, 1 },
913 { 2920, 32, 50, 25, 25, 45, 1 },
914 { 2910, 32, 50, 25, 24, 45, 1 },
915 { 2900, 32, 50, 25, 24, 45, 1 },
916 { 2890, 32, 50, 25, 24, 45, 1 },
917 { 2880, 32, 50, 25, 24, 45, 1 },
918 { 2870, 32, 50, 25, 24, 45, 1 },
919 { 2860, 32, 50, 25, 24, 44, 1 },
920 { 2850, 32, 50, 25, 24, 44, 1 },
921 { 2840, 31, 50, 25, 24, 44, 1 },
922 { 2830, 31, 50, 25, 24, 44, 1 },
923 { 2820, 31, 50, 25, 24, 44, 1 },
924 { 2810, 31, 50, 25, 24, 44, 1 },
925 { 2800, 31, 50, 25, 23, 43, 1 },
926 { 2790, 31, 50, 25, 23, 43, 1 },
927 { 2780, 31, 50, 25, 23, 43, 1 },
928 { 2770, 31, 50, 25, 23, 43, 1 },
929 { 2760, 31, 50, 25, 23, 43, 1 },
930 { 2750, 30, 50, 25, 23, 43, 1 },
931 { 2740, 30, 50, 25, 23, 43, 1 },
932 { 2730, 30, 50, 25, 23, 42, 1 },
933 { 2720, 30, 50, 25, 23, 42, 1 },
934 { 2710, 30, 50, 25, 23, 42, 1 },
935 { 2700, 30, 50, 25, 23, 42, 1 },
936 { 2690, 30, 50, 25, 23, 42, 1 },
937 { 2680, 30, 50, 25, 22, 42, 1 },
938 { 2670, 30, 50, 25, 22, 41, 1 },
939 { 2660, 29, 50, 25, 22, 41, 1 },
940 { 2650, 29, 50, 25, 22, 41, 1 },
941 { 2640, 29, 50, 25, 22, 41, 1 },
942 { 2630, 29, 50, 25, 22, 41, 1 },
943 { 2620, 29, 50, 25, 22, 41, 1 },
944 { 2610, 29, 50, 25, 22, 41, 1 },
945 { 2600, 29, 50, 25, 22, 40, 1 },
946 { 2590, 29, 50, 25, 22, 40, 1 },
947 { 2580, 28, 50, 25, 22, 40, 1 },
948 { 2570, 28, 50, 25, 22, 40, 1 },
949 { 2560, 28, 50, 25, 21, 40, 1 },
950 { 2550, 28, 50, 25, 21, 40, 1 },
951 { 2540, 28, 50, 25, 21, 39, 1 },
952 { 2530, 28, 50, 25, 21, 39, 1 },
953 { 2520, 28, 50, 25, 21, 39, 1 },
954 { 2510, 28, 50, 25, 21, 39, 1 },
955 { 2500, 28, 50, 25, 21, 39, 1 },
956 { 2490, 27, 50, 25, 21, 39, 1 },
957 { 2480, 27, 50, 25, 21, 38, 1 },
958 { 2470, 27, 50, 25, 21, 38, 1 },
959 { 2460, 27, 50, 25, 21, 38, 1 },
960 { 2450, 27, 50, 25, 20, 38, 1 },
961 { 2440, 27, 50, 25, 20, 38, 1 },
962 { 2430, 27, 50, 25, 20, 38, 1 },
963 { 2420, 27, 50, 25, 20, 38, 1 },
964 { 2410, 27, 50, 25, 20, 37, 1 },
965 { 2400, 26, 50, 25, 20, 37, 1 },
966 { 2390, 26, 50, 25, 20, 37, 1 },
967 { 2380, 26, 50, 25, 20, 37, 1 },
968 { 2370, 26, 50, 25, 20, 37, 1 },
969 { 2360, 26, 50, 25, 20, 37, 1 },
970 { 2350, 26, 50, 25, 20, 36, 1 },
971 { 2340, 26, 50, 25, 20, 36, 1 },
972 { 2330, 26, 50, 25, 19, 36, 1 },
973 { 2320, 25, 50, 25, 19, 36, 1 },
974 { 2310, 25, 50, 25, 19, 36, 1 },
975 { 2300, 25, 50, 25, 19, 36, 1 },
976 { 2290, 25, 50, 25, 19, 35, 1 },
977 { 2280, 25, 50, 25, 19, 35, 1 },
978 { 2270, 25, 50, 25, 19, 35, 1 },
979 { 2260, 25, 50, 25, 19, 35, 1 },
980 { 2250, 25, 50, 25, 19, 35, 1 },
981 { 2240, 25, 50, 25, 19, 35, 1 },
982 { 2230, 24, 50, 25, 19, 35, 1 },
983 { 2220, 24, 50, 25, 19, 34, 1 },
984 { 2210, 24, 50, 25, 18, 34, 1 },
985 { 2200, 24, 50, 25, 18, 34, 1 },
986 { 2190, 24, 50, 25, 18, 34, 1 },
987 { 2180, 24, 50, 25, 18, 34, 1 },
988 { 2170, 24, 50, 25, 18, 34, 1 },
989 { 2160, 24, 50, 25, 18, 33, 1 },
990 { 2150, 24, 50, 25, 18, 33, 1 },
991 { 2140, 23, 50, 25, 18, 33, 1 },
992 { 2130, 23, 50, 25, 18, 33, 1 },
993 { 2120, 23, 50, 25, 18, 33, 1 },
994 { 2110, 23, 50, 25, 18, 33, 1 },
995 { 2100, 23, 50, 25, 17, 32, 1 },
996 { 2090, 23, 50, 25, 17, 32, 1 },
997 { 2080, 23, 50, 25, 17, 32, 1 },
998 { 2070, 23, 50, 25, 17, 32, 1 },
999 { 2060, 22, 50, 25, 17, 32, 1 },
1000 { 2050, 22, 50, 25, 17, 32, 1 },
1001 { 2040, 22, 50, 25, 17, 32, 1 },
1002 { 2030, 22, 50, 25, 17, 31, 1 },
1003 { 2020, 22, 50, 25, 17, 31, 1 },
1004 { 2010, 22, 50, 25, 17, 31, 1 },
1005 { 2000, 22, 50, 25, 17, 31, 1 },
1006 { 1990, 22, 50, 25, 17, 31, 1 },
1007 { 1980, 22, 50, 25, 16, 31, 1 },
1008 { 1970, 21, 50, 25, 16, 30, 1 },
1009 { 1960, 21, 50, 25, 16, 30, 1 },
1010 { 1950, 21, 50, 25, 16, 30, 1 },
1011 { 1940, 21, 50, 25, 16, 30, 1 },
1012 { 1930, 21, 50, 25, 16, 30, 1 },
1013 { 1920, 21, 50, 25, 16, 30, 1 },
1014 { 1910, 21, 50, 25, 16, 30, 1 },
1015 { 1900, 21, 50, 25, 16, 29, 1 },
1016 { 1890, 21, 50, 25, 16, 29, 1 },
1017 { 1880, 20, 50, 25, 16, 29, 1 },
1018 { 1870, 20, 50, 25, 16, 29, 1 },
1019 { 1860, 20, 50, 25, 15, 29, 1 },
1020 { 1850, 20, 50, 25, 15, 29, 1 },
1021 { 1840, 20, 50, 25, 15, 28, 1 },
1022 { 1830, 20, 50, 25, 15, 28, 1 },
1023 { 1820, 20, 50, 25, 15, 28, 1 },
1024 { 1810, 20, 50, 25, 15, 28, 1 },
1025 { 1800, 19, 50, 25, 15, 28, 1 },
1026 { 1790, 19, 50, 25, 15, 28, 1 },
1027 { 1780, 19, 50, 25, 15, 27, 1 },
1028 { 1770, 19, 50, 25, 15, 27, 1 },
1029 { 1760, 19, 50, 25, 15, 27, 1 },
1030 { 1750, 19, 50, 25, 14, 27, 1 },
1031 { 1740, 19, 50, 25, 14, 27, 1 },
1032 { 1730, 19, 50, 25, 14, 27, 1 },
1033 { 1720, 19, 50, 25, 14, 27, 1 },
1034 { 1710, 18, 50, 25, 14, 26, 1 },
1035 { 1700, 18, 50, 25, 14, 26, 1 },
1036 { 1690, 18, 50, 25, 14, 26, 1 },
1037 { 1680, 18, 50, 25, 14, 26, 1 },
1038 { 1670, 18, 50, 25, 14, 26, 1 },
1039 { 1660, 18, 50, 25, 14, 26, 1 },
1040 { 1650, 18, 50, 25, 14, 25, 1 },
1041 { 1640, 18, 50, 25, 14, 25, 1 },
1042 { 1630, 18, 50, 25, 13, 25, 1 },
1043 { 1620, 17, 50, 25, 13, 25, 1 },
1044 { 1610, 17, 50, 25, 13, 25, 1 },
1045 { 1600, 17, 50, 25, 13, 25, 1 },
1046 { 1590, 17, 50, 25, 13, 24, 1 },
1047 { 1580, 17, 50, 25, 13, 24, 1 },
1048 { 1570, 17, 50, 25, 13, 24, 1 },
1049 { 1560, 17, 50, 25, 13, 24, 1 },
1050 { 1550, 17, 50, 25, 13, 24, 1 },
1051 { 1540, 16, 50, 25, 13, 24, 1 },
1052 { 1530, 16, 50, 25, 13, 24, 1 },
1053 { 1520, 16, 50, 25, 13, 23, 1 },
1054 { 1510, 16, 50, 25, 12, 23, 1 },
1055 { 1500, 16, 50, 25, 12, 23, 1 },
1056 { 1490, 16, 50, 25, 12, 23, 1 },
1057 { 1480, 16, 50, 25, 12, 23, 1 },
1058 { 1470, 16, 50, 25, 12, 23, 1 },
1059 { 1460, 16, 50, 25, 12, 22, 1 },
1060 { 1450, 15, 50, 25, 12, 22, 1 },
1061 { 1440, 15, 50, 25, 12, 22, 1 },
1062 { 1430, 15, 50, 25, 12, 22, 1 },
1063 { 1420, 15, 50, 25, 12, 22, 1 },
1064 { 1410, 15, 50, 25, 12, 22, 1 },
1065 { 1400, 15, 50, 25, 11, 21, 1 },
1066 { 1390, 15, 50, 25, 11, 21, 1 },
1067 { 1380, 15, 50, 25, 11, 21, 1 },
1068 { 1370, 15, 50, 25, 11, 21, 1 },
1069 { 1360, 14, 50, 25, 11, 21, 1 },
1070 { 1350, 14, 50, 25, 11, 21, 1 },
1071 { 1340, 14, 50, 25, 11, 21, 1 },
1072 { 1330, 14, 50, 25, 11, 20, 1 },
1073 { 1320, 14, 50, 25, 11, 20, 1 },
1074 { 1310, 14, 50, 25, 11, 20, 1 },
1075 { 1300, 14, 50, 25, 11, 20, 1 },
1076 { 1290, 14, 50, 25, 11, 20, 1 },
1077 { 1280, 13, 50, 25, 10, 20, 1 },
1078 { 1270, 13, 50, 25, 10, 19, 1 },
1079 { 1260, 13, 50, 25, 10, 19, 1 },
1080 { 1250, 13, 50, 25, 10, 19, 1 },
1081 { 1240, 13, 50, 25, 10, 19, 1 },
1082 { 1230, 13, 50, 25, 10, 19, 1 },
1083 { 1220, 13, 50, 25, 10, 19, 1 },
1084 { 1210, 13, 50, 25, 10, 19, 1 },
1085 { 1200, 13, 50, 25, 10, 18, 1 },
1086 { 1190, 12, 50, 25, 10, 18, 1 },
1087 { 1180, 12, 50, 25, 10, 18, 1 },
1088 { 1170, 12, 50, 25, 10, 18, 1 },
1089 { 1160, 12, 50, 25, 9, 18, 1 },
1090 { 1150, 12, 50, 25, 9, 18, 1 },
1091 { 1140, 12, 50, 25, 9, 17, 1 },
1092 { 1130, 12, 50, 25, 9, 17, 1 },
1093 { 1120, 12, 50, 25, 9, 17, 1 },
1094 { 1110, 12, 50, 25, 9, 17, 1 },
1095 { 1100, 11, 50, 25, 9, 17, 1 },
1096 { 1090, 11, 50, 25, 9, 17, 1 },
1097 { 1080, 11, 50, 25, 9, 16, 1 },
1098 { 1070, 11, 50, 25, 9, 16, 1 },
1099 { 1060, 11, 50, 25, 9, 16, 1 },
1100 { 1050, 11, 50, 25, 8, 16, 1 },
1101 { 1040, 11, 50, 25, 8, 16, 1 },
1102 { 1030, 11, 50, 25, 8, 16, 1 },
1103 { 1020, 10, 50, 25, 8, 16, 1 },
1104 { 1010, 10, 50, 25, 8, 15, 1 },
1105 { 1000, 10, 50, 25, 8, 15, 1 },
1106 { 990, 10, 50, 25, 8, 15, 2 },
1107 { 980, 10, 50, 25, 8, 15, 2 },
1108 { 970, 10, 50, 25, 8, 15, 2 },
1109 { 960, 10, 50, 25, 8, 15, 2 },
1110 { 950, 10, 50, 25, 8, 14, 2 },
1111 { 940, 10, 50, 25, 8, 14, 2 },
1112 { 930, 9, 50, 25, 7, 14, 2 },
1113 { 920, 9, 50, 25, 7, 14, 2 },
1114 { 910, 9, 50, 25, 7, 14, 2 },
1115 { 900, 9, 50, 25, 7, 14, 2 },
1116 { 890, 9, 50, 25, 7, 13, 2 },
1117 { 880, 9, 50, 25, 7, 13, 2 },
1118 { 870, 9, 50, 25, 7, 13, 2 },
1119 { 860, 9, 50, 25, 7, 13, 2 },
1120 { 850, 9, 50, 25, 7, 13, 2 },
1121 { 840, 8, 50, 25, 7, 13, 2 },
1122 { 830, 8, 50, 25, 7, 13, 2 },
1123 { 820, 8, 50, 25, 7, 12, 2 },
1124 { 810, 8, 50, 25, 6, 12, 2 },
1125 { 800, 8, 50, 25, 6, 12, 2 },
1126 { 790, 8, 50, 25, 6, 12, 2 },
1127 { 780, 8, 50, 25, 6, 12, 2 },
1128 { 770, 8, 50, 25, 6, 12, 2 },
1129 { 760, 7, 50, 25, 6, 11, 2 },
1130 { 750, 7, 50, 25, 6, 11, 2 },
1131 { 740, 7, 50, 25, 6, 11, 2 },
1132 { 730, 7, 50, 25, 6, 11, 2 },
1133 { 720, 7, 50, 25, 6, 11, 2 },
1134 { 710, 7, 50, 25, 6, 11, 2 },
1135 { 700, 7, 50, 25, 5, 10, 2 },
1136 { 690, 7, 50, 25, 5, 10, 2 },
1137 { 680, 7, 50, 25, 5, 10, 2 },
1138 { 670, 6, 50, 25, 5, 10, 2 },
1139 { 660, 6, 50, 25, 5, 10, 2 },
1140 { 650, 6, 50, 25, 5, 10, 2 },
1141 { 640, 6, 50, 25, 5, 10, 2 },
1142 { 630, 6, 50, 25, 5, 9, 2 },
1143 { 620, 6, 50, 25, 5, 9, 2 },
1144 { 610, 6, 50, 25, 5, 9, 2 },
1145 { 600, 6, 50, 25, 5, 9, 2 },
1146 { 590, 6, 50, 25, 5, 9, 2 },
1147 { 580, 5, 50, 25, 4, 9, 2 },
1148 { 570, 5, 50, 25, 4, 8, 2 },
1149 { 560, 5, 50, 25, 4, 8, 2 },
1150 { 550, 5, 50, 25, 4, 8, 2 },
1151 { 540, 5, 50, 25, 4, 8, 2 },
1152 { 530, 5, 50, 25, 4, 8, 2 },
1153 { 520, 5, 50, 25, 4, 8, 2 },
1154 { 510, 5, 50, 25, 4, 8, 2 },
1155 { 500, 4, 50, 25, 4, 7, 2 },
1156 { 490, 18, 50, 25, 14, 6, 2 },
1157 { 480, 17, 50, 25, 14, 6, 2 },
1158 { 470, 17, 50, 25, 14, 6, 2 },
1159 { 460, 17, 50, 25, 13, 6, 2 },
1160 { 450, 16, 50, 25, 13, 6, 2 },
1161 { 440, 16, 50, 25, 13, 6, 2 },
1162 { 430, 15, 50, 25, 12, 6, 2 },
1163 { 420, 15, 50, 25, 12, 5, 2 },
1164 { 410, 15, 50, 25, 12, 5, 2 },
1165 { 400, 14, 50, 25, 11, 5, 2 },
1166 { 390, 14, 50, 25, 11, 5, 2 },
1167 { 380, 13, 50, 25, 11, 5, 2 },
1168 { 370, 13, 50, 25, 11, 5, 2 },
1169 { 360, 13, 50, 25, 10, 4, 2 },
1170 { 350, 12, 50, 25, 10, 4, 2 },
1171 { 340, 12, 50, 25, 10, 4, 2 },
1172 { 330, 11, 50, 25, 9, 4, 2 },
1173 { 320, 11, 50, 25, 9, 4, 2 },
1174 { 310, 11, 50, 25, 9, 4, 2 },
1175 { 300, 10, 50, 25, 8, 3, 2 },
1176 { 290, 10, 50, 25, 8, 3, 2 },
1177 { 280, 9, 50, 25, 8, 3, 2 },
1178 { 270, 9, 50, 25, 8, 3, 2 },
1179 { 260, 8, 50, 25, 7, 3, 2 },
1180 { 250, 8, 50, 25, 7, 3, 2 },
1181 { 240, 8, 50, 25, 7, 3, 2 },
1182 { 230, 7, 50, 25, 6, 2, 2 },
1183 { 220, 7, 50, 25, 6, 2, 2 },
1184 { 210, 6, 50, 25, 6, 2, 2 },
1185 { 200, 6, 50, 25, 5, 2, 2 },
1186 { 190, 6, 50, 25, 5, 2, 2 },
1187 { 180, 5, 50, 25, 5, 2, 2 },
1188 { 170, 5, 50, 25, 5, 1, 2 },
1189 { 160, 4, 50, 25, 4, 1, 2 },
1190 { 150, 4, 50, 25, 4, 1, 2 },
1191 { 140, 4, 50, 25, 4, 1, 2 },
1192 { 130, 3, 50, 25, 3, 1, 2 },
1193 { 120, 3, 50, 25, 3, 1, 2 },
1194 { 110, 2, 50, 25, 3, 1, 2 },
1195 { 100, 2, 50, 25, 2, 0, 2 },
1196 { 90, 2, 50, 25, 2, 0, 2 },
1197 { 80, 1, 50, 25, 2, 0, 2 },
1198 };
1199
1200 static inline void
phy_write(struct samsung_mipi_dcphy * samsung,u32 reg,u32 val)1201 phy_write(struct samsung_mipi_dcphy *samsung, u32 reg, u32 val)
1202 {
1203 writel(val, samsung->base + reg);
1204 }
1205
phy_read(struct samsung_mipi_dcphy * samsung,u32 reg)1206 static inline u32 phy_read(struct samsung_mipi_dcphy *samsung, u32 reg)
1207 {
1208 return readl(samsung->base + reg);
1209 }
1210
phy_update_bits(struct samsung_mipi_dcphy * samsung,u32 reg,u32 mask,u32 val)1211 static inline void phy_update_bits(struct samsung_mipi_dcphy *samsung,
1212 u32 reg, u32 mask, u32 val)
1213 {
1214 u32 orig, tmp;
1215
1216 orig = phy_read(samsung, reg);
1217 tmp = orig & ~mask;
1218 tmp |= val & mask;
1219 phy_write(samsung, reg, tmp);
1220 }
1221
grf_write(struct samsung_mipi_dcphy * samsung,u32 reg,u32 val)1222 static inline void grf_write(struct samsung_mipi_dcphy *samsung,
1223 u32 reg, u32 val)
1224 {
1225 regmap_write(samsung->grf, reg, val);
1226 }
1227
1228 static const struct samsung_mipi_dphy_timing *
samsung_mipi_dphy_get_timing(struct samsung_mipi_dcphy * samsung)1229 samsung_mipi_dphy_get_timing(struct samsung_mipi_dcphy *samsung)
1230 {
1231 const struct samsung_mipi_dphy_timing *timings;
1232 unsigned int num_timings;
1233 unsigned int lane_mbps = samsung->pll.rate / USEC_PER_SEC;
1234 unsigned int i;
1235
1236 timings = samsung_mipi_dphy_timing_table;
1237 num_timings = ARRAY_SIZE(samsung_mipi_dphy_timing_table);
1238
1239 for (i = num_timings; i > 0; i--)
1240 if (lane_mbps <= timings[i - 1].max_lane_mbps)
1241 break;
1242
1243 if (i == 0)
1244 ++i;
1245
1246 return &timings[i - 1];
1247 }
1248
1249 static const struct samsung_mipi_cphy_timing *
samsung_mipi_cphy_get_timing(struct samsung_mipi_dcphy * samsung)1250 samsung_mipi_cphy_get_timing(struct samsung_mipi_dcphy *samsung)
1251 {
1252 const struct samsung_mipi_cphy_timing *timings;
1253 unsigned int num_timings;
1254 unsigned int lane_msps = div64_ul(samsung->pll.rate, USEC_PER_SEC);
1255 unsigned int i;
1256
1257 timings = samsung_mipi_cphy_timing_table;
1258 num_timings = ARRAY_SIZE(samsung_mipi_cphy_timing_table);
1259
1260 for (i = num_timings; i > 0; i--)
1261 if (lane_msps <= timings[i - 1].max_lane_msps)
1262 break;
1263
1264 if (i == 0)
1265 ++i;
1266
1267 return &timings[i - 1];
1268 }
1269
samsung_mipi_dcphy_bias_block_enable(struct samsung_mipi_dcphy * samsung)1270 static void samsung_mipi_dcphy_bias_block_enable(struct samsung_mipi_dcphy *samsung)
1271 {
1272 phy_write(samsung, BIAS_CON0, 0x0010);
1273 phy_write(samsung, BIAS_CON1, 0x0110);
1274 phy_write(samsung, BIAS_CON2, 0x3223);
1275
1276 if (samsung->c_option)
1277 phy_update_bits(samsung, BIAS_CON4, I_MUX_SEL_MASK, I_MUX_SEL(2));
1278 }
1279
samsung_mipi_dcphy_bias_block_disable(struct samsung_mipi_dcphy * samsung)1280 static void samsung_mipi_dcphy_bias_block_disable(struct samsung_mipi_dcphy *samsung)
1281 {
1282 }
1283
samsung_mipi_dcphy_pll_configure(struct samsung_mipi_dcphy * samsung)1284 static void samsung_mipi_dcphy_pll_configure(struct samsung_mipi_dcphy *samsung)
1285 {
1286 phy_update_bits(samsung, PLL_CON0, S_MASK | P_MASK,
1287 S(samsung->pll.scaler) | P(samsung->pll.prediv));
1288
1289 if (samsung->pll.dsm < 0) {
1290 u16 dsm_tmp;
1291
1292 /* Using opposite number subtraction to find complement */
1293 dsm_tmp = abs(samsung->pll.dsm);
1294 dsm_tmp = dsm_tmp - 1;
1295 dsm_tmp ^= 0xffff;
1296 phy_write(samsung, PLL_CON1, dsm_tmp);
1297 } else {
1298 phy_write(samsung, PLL_CON1, samsung->pll.dsm);
1299 }
1300
1301 phy_update_bits(samsung, PLL_CON2, M_MASK, M(samsung->pll.fbdiv));
1302
1303 if (samsung->pll.ssc_en) {
1304 phy_write(samsung, PLL_CON3,
1305 MRR(samsung->pll.mrr) | MFR(samsung->pll.mfr));
1306 phy_update_bits(samsung, PLL_CON4, SSCG_EN, SSCG_EN);
1307 }
1308
1309 phy_write(samsung, PLL_CON5, RESET_N_SEL | PLL_ENABLE_SEL);
1310 phy_write(samsung, PLL_CON7, PLL_LOCK_CNT(0xf000));
1311 phy_write(samsung, PLL_CON8, PLL_STB_CNT(0xf000));
1312 }
1313
1314 static void
samsung_mipi_dphy_clk_lane_timing_init(struct samsung_mipi_dcphy * samsung)1315 samsung_mipi_dphy_clk_lane_timing_init(struct samsung_mipi_dcphy *samsung)
1316 {
1317 const struct samsung_mipi_dphy_timing *timing;
1318 unsigned int lane_hs_rate = div64_ul(samsung->pll.rate, USEC_PER_SEC);
1319 u32 val = 0;
1320
1321 timing = samsung_mipi_dphy_get_timing(samsung);
1322 phy_write(samsung, DPHY_MC_GNR_CON0, 0xf000);
1323 phy_write(samsung, DPHY_MC_ANA_CON0, 0x7133);
1324
1325 if (lane_hs_rate >= 4500)
1326 phy_write(samsung, DPHY_MC_ANA_CON1, 0x0001);
1327
1328 /*
1329 * Divide-by-2 Clock from Serial Clock. Use this when data rate is under
1330 * 1500Mbps, otherwise divide-by-16 Clock from Serial Clock
1331 */
1332 if (lane_hs_rate < 1500)
1333 val = HSTX_CLK_SEL;
1334
1335 val |= T_LPX(timing->lpx);
1336 /* T_LP_EXIT_SKEW/T_LP_ENTRY_SKEW unconfig */
1337 phy_write(samsung, DPHY_MC_TIME_CON0, val);
1338
1339 val = T_CLK_ZERO(timing->clk_zero) | T_CLK_PREPARE(timing->clk_prepare);
1340 phy_write(samsung, DPHY_MC_TIME_CON1, val);
1341
1342 val = T_HS_EXIT(timing->hs_exit) | T_CLK_TRAIL(timing->clk_trail_eot);
1343 phy_write(samsung, DPHY_MC_TIME_CON2, val);
1344
1345 val = T_CLK_POST(timing->clk_post);
1346 phy_write(samsung, DPHY_MC_TIME_CON3, val);
1347
1348 /* Escape Clock is 20.00MHz */
1349 phy_write(samsung, DPHY_MC_TIME_CON4, 0x1f4);
1350
1351 /*
1352 * skew calibration should be off, if the operation data rate is
1353 * under 1.5Gbps or equal to 1.5Gbps.
1354 */
1355 if (lane_hs_rate > 1500)
1356 phy_write(samsung, DPHY_MC_DESKEW_CON0, 0x9cb1);
1357 }
1358
1359 static void
samsung_mipi_dphy_data_lane_timing_init(struct samsung_mipi_dcphy * samsung)1360 samsung_mipi_dphy_data_lane_timing_init(struct samsung_mipi_dcphy *samsung)
1361 {
1362 const struct samsung_mipi_dphy_timing *timing;
1363 unsigned int lane_hs_rate = div64_ul(samsung->pll.rate, USEC_PER_SEC);
1364 u32 val = 0;
1365
1366 timing = samsung_mipi_dphy_get_timing(samsung);
1367
1368 phy_write(samsung, COMBO_MD0_ANA_CON0, 0x7133);
1369 phy_write(samsung, COMBO_MD1_ANA_CON0, 0x7133);
1370 phy_write(samsung, COMBO_MD2_ANA_CON0, 0x7133);
1371 phy_write(samsung, DPHY_MD3_ANA_CON0, 0x7133);
1372
1373 if (lane_hs_rate >= 1500) {
1374 phy_write(samsung, COMBO_MD0_ANA_CON1, 0x0001);
1375 phy_write(samsung, COMBO_MD1_ANA_CON1, 0x0001);
1376 phy_write(samsung, COMBO_MD2_ANA_CON1, 0x0001);
1377 phy_write(samsung, DPHY_MD3_ANA_CON1, 0x0001);
1378 }
1379
1380 /*
1381 * Divide-by-2 Clock from Serial Clock. Use this when data rate is under
1382 * 1500Mbps, otherwise divide-by-16 Clock from Serial Clock
1383 */
1384 if (lane_hs_rate < 1500)
1385 val = HSTX_CLK_SEL;
1386
1387 val |= T_LPX(timing->lpx);
1388 /* T_LP_EXIT_SKEW/T_LP_ENTRY_SKEW unconfig */
1389 phy_write(samsung, COMBO_MD0_TIME_CON0, val);
1390 phy_write(samsung, COMBO_MD1_TIME_CON0, val);
1391 phy_write(samsung, COMBO_MD2_TIME_CON0, val);
1392 phy_write(samsung, DPHY_MD3_TIME_CON0, val);
1393
1394 val = T_HS_ZERO(timing->hs_zero) | T_HS_PREPARE(timing->hs_prepare);
1395 phy_write(samsung, COMBO_MD0_TIME_CON1, val);
1396 phy_write(samsung, COMBO_MD1_TIME_CON1, val);
1397 phy_write(samsung, COMBO_MD2_TIME_CON1, val);
1398 phy_write(samsung, DPHY_MD3_TIME_CON1, val);
1399
1400 val = T_HS_EXIT(timing->hs_exit) | T_HS_TRAIL(timing->hs_trail_eot);
1401 phy_write(samsung, COMBO_MD0_TIME_CON2, val);
1402 phy_write(samsung, COMBO_MD1_TIME_CON2, val);
1403 phy_write(samsung, COMBO_MD2_TIME_CON2, val);
1404 phy_write(samsung, DPHY_MD3_TIME_CON2, val);
1405
1406 /* TTA-GET/TTA-GO Timing Counter register use default value */
1407 val = T_TA_GET(0x3) | T_TA_GO(0x0);
1408 phy_write(samsung, COMBO_MD0_TIME_CON3, val);
1409 phy_write(samsung, COMBO_MD1_TIME_CON3, val);
1410 phy_write(samsung, COMBO_MD2_TIME_CON3, val);
1411 phy_write(samsung, DPHY_MD3_TIME_CON3, val);
1412
1413 /* Escape Clock is 20.00MHz */
1414 phy_write(samsung, COMBO_MD0_TIME_CON4, 0x1f4);
1415 phy_write(samsung, COMBO_MD1_TIME_CON4, 0x1f4);
1416 phy_write(samsung, COMBO_MD2_TIME_CON4, 0x1f4);
1417 phy_write(samsung, DPHY_MD3_TIME_CON4, 0x1f4);
1418 }
1419
samsung_mipi_dcphy_pll_enable(struct samsung_mipi_dcphy * samsung)1420 static void samsung_mipi_dcphy_pll_enable(struct samsung_mipi_dcphy *samsung)
1421 {
1422 u32 sts;
1423 int ret;
1424
1425 phy_update_bits(samsung, PLL_CON0, PLL_EN, PLL_EN);
1426
1427 ret = readl_poll_timeout(samsung->base + PLL_STAT0,
1428 sts, (sts & PLL_LOCK), 20000);
1429 if (ret < 0)
1430 dev_err(samsung->dev, "DC-PHY pll is not locked\n");
1431 }
1432
samsung_mipi_dcphy_pll_disable(struct samsung_mipi_dcphy * samsung)1433 static void samsung_mipi_dcphy_pll_disable(struct samsung_mipi_dcphy *samsung)
1434 {
1435 phy_update_bits(samsung, PLL_CON0, PLL_EN, 0);
1436 }
1437
samsung_mipi_dphy_lane_enable(struct samsung_mipi_dcphy * samsung)1438 static void samsung_mipi_dphy_lane_enable(struct samsung_mipi_dcphy *samsung)
1439 {
1440 phy_write(samsung, DPHY_MC_GNR_CON1, T_PHY_READY(0x2000));
1441 phy_update_bits(samsung, DPHY_MC_GNR_CON0, PHY_ENABLE, PHY_ENABLE);
1442
1443 switch (samsung->lanes) {
1444 case 4:
1445 phy_write(samsung, DPHY_MD3_GNR_CON1, T_PHY_READY(0x2000));
1446 phy_update_bits(samsung, DPHY_MD3_GNR_CON0,
1447 PHY_ENABLE, PHY_ENABLE);
1448 //fallthrough;
1449 case 3:
1450 phy_write(samsung, COMBO_MD2_GNR_CON1, T_PHY_READY(0x2000));
1451 phy_update_bits(samsung, COMBO_MD2_GNR_CON0,
1452 PHY_ENABLE, PHY_ENABLE);
1453 //fallthrough;
1454 case 2:
1455 phy_write(samsung, COMBO_MD1_GNR_CON1, T_PHY_READY(0x2000));
1456 phy_update_bits(samsung, COMBO_MD1_GNR_CON0,
1457 PHY_ENABLE, PHY_ENABLE);
1458 //fallthrough;
1459 case 1:
1460 default:
1461 phy_write(samsung, COMBO_MD0_GNR_CON1, T_PHY_READY(0x2000));
1462 phy_update_bits(samsung, COMBO_MD0_GNR_CON0,
1463 PHY_ENABLE, PHY_ENABLE);
1464 break;
1465 }
1466 }
1467
samsung_mipi_cphy_timing_init(struct samsung_mipi_dcphy * samsung)1468 static void samsung_mipi_cphy_timing_init(struct samsung_mipi_dcphy *samsung)
1469 {
1470 const struct samsung_mipi_cphy_timing *timing;
1471 unsigned int lane_hs_rate = div64_ul(samsung->pll.rate, USEC_PER_SEC);
1472 u32 val = 0;
1473
1474 timing = samsung_mipi_cphy_get_timing(samsung);
1475
1476 /*
1477 * Divide-by-2 Clock from Serial Clock. Use this when data rate is under
1478 * 1500Mbps, otherwise divide-by-16 Clock from Serial Clock
1479 */
1480 if (lane_hs_rate < 1500)
1481 val = HSTX_CLK_SEL;
1482
1483 val |= T_LPX(timing->lpx);
1484 /* T_LP_EXIT_SKEW/T_LP_ENTRY_SKEW unconfig */
1485 phy_write(samsung, COMBO_MD0_TIME_CON0, val);
1486 phy_write(samsung, COMBO_MD1_TIME_CON0, val);
1487 phy_write(samsung, COMBO_MD2_TIME_CON0, val);
1488
1489 val = T_HS_ZERO(timing->prebegin_3) | T_HS_PREPARE(timing->prepare_3);
1490 phy_write(samsung, COMBO_MD0_TIME_CON1, val);
1491 phy_write(samsung, COMBO_MD1_TIME_CON1, val);
1492 phy_write(samsung, COMBO_MD2_TIME_CON1, val);
1493
1494 val = T_HS_EXIT(timing->hs_exit) | T_HS_TRAIL(timing->post_3);
1495 phy_write(samsung, DPHY_MD3_TIME_CON2, val);
1496 phy_write(samsung, COMBO_MD0_TIME_CON2, val);
1497 phy_write(samsung, COMBO_MD1_TIME_CON2, val);
1498 phy_write(samsung, COMBO_MD2_TIME_CON2, val);
1499
1500 /* TTA-GET/TTA-GO Timing Counter register use default value */
1501 val = T_TA_GET(0x3) | T_TA_GO(0x0);
1502 phy_write(samsung, COMBO_MD0_TIME_CON3, val);
1503 phy_write(samsung, COMBO_MD1_TIME_CON3, val);
1504 phy_write(samsung, COMBO_MD2_TIME_CON3, val);
1505
1506 /* Escape Clock is 20.00MHz */
1507 phy_write(samsung, COMBO_MD0_TIME_CON4, 0x1f4);
1508 phy_write(samsung, COMBO_MD1_TIME_CON4, 0x1f4);
1509 phy_write(samsung, COMBO_MD2_TIME_CON4, 0x1f4);
1510
1511 /* set T_ERR_SOT_SYNC default value */
1512 }
1513
samsung_mipi_cphy_lane_enable(struct samsung_mipi_dcphy * samsung)1514 static void samsung_mipi_cphy_lane_enable(struct samsung_mipi_dcphy *samsung)
1515 {
1516 phy_write(samsung, COMBO_MD0_GNR_CON1, T_PHY_READY(0x2000));
1517 phy_write(samsung, COMBO_MD1_GNR_CON1, T_PHY_READY(0x2000));
1518 phy_write(samsung, COMBO_MD2_GNR_CON1, T_PHY_READY(0x2000));
1519
1520 phy_update_bits(samsung, COMBO_MD0_GNR_CON0, PHY_ENABLE, PHY_ENABLE);
1521 phy_update_bits(samsung, COMBO_MD1_GNR_CON0, PHY_ENABLE, PHY_ENABLE);
1522 phy_update_bits(samsung, COMBO_MD2_GNR_CON0, PHY_ENABLE, PHY_ENABLE);
1523 }
1524
1525 static void
samsung_mipi_dcphy_hs_vreg_amp_config(struct samsung_mipi_dcphy * samsung)1526 samsung_mipi_dcphy_hs_vreg_amp_config(struct samsung_mipi_dcphy *samsung)
1527 {
1528 phy_write(samsung, DPHY_MC_ANA_CON2, HS_VREG_AMP_ICON(2));
1529 }
1530
samsung_mipi_dphy_power_on(struct samsung_mipi_dcphy * samsung)1531 static void samsung_mipi_dphy_power_on(struct samsung_mipi_dcphy *samsung)
1532 {
1533 reset_assert(&samsung->m_phy_rst);
1534
1535 samsung_mipi_dcphy_bias_block_enable(samsung);
1536 samsung_mipi_dcphy_pll_configure(samsung);
1537 samsung_mipi_dphy_clk_lane_timing_init(samsung);
1538 samsung_mipi_dphy_data_lane_timing_init(samsung);
1539 samsung_mipi_dcphy_pll_enable(samsung);
1540 samsung_mipi_dphy_lane_enable(samsung);
1541
1542 reset_deassert(&samsung->m_phy_rst);
1543 }
1544
samsung_mipi_cphy_power_on(struct samsung_mipi_dcphy * samsung)1545 static void samsung_mipi_cphy_power_on(struct samsung_mipi_dcphy *samsung)
1546 {
1547 grf_write(samsung, MIPI_DCPHY_GRF_CON0, M_CPHY_MODE);
1548 reset_assert(&samsung->m_phy_rst);
1549
1550 samsung_mipi_dcphy_bias_block_enable(samsung);
1551 samsung_mipi_dcphy_hs_vreg_amp_config(samsung);
1552 samsung_mipi_dcphy_pll_configure(samsung);
1553 samsung_mipi_cphy_timing_init(samsung);
1554 samsung_mipi_dcphy_pll_enable(samsung);
1555 samsung_mipi_cphy_lane_enable(samsung);
1556
1557 reset_deassert(&samsung->m_phy_rst);
1558 }
1559
samsung_mipi_dphy_lane_disable(struct samsung_mipi_dcphy * samsung)1560 static void samsung_mipi_dphy_lane_disable(struct samsung_mipi_dcphy *samsung)
1561 {
1562 phy_update_bits(samsung, DPHY_MC_GNR_CON0, PHY_ENABLE, 0);
1563 phy_update_bits(samsung, COMBO_MD0_GNR_CON0, PHY_ENABLE, 0);
1564 phy_update_bits(samsung, COMBO_MD1_GNR_CON0, PHY_ENABLE, 0);
1565 phy_update_bits(samsung, COMBO_MD2_GNR_CON0, PHY_ENABLE, 0);
1566 phy_update_bits(samsung, DPHY_MD3_GNR_CON0, PHY_ENABLE, 0);
1567 }
1568
samsung_mipi_cphy_lane_disable(struct samsung_mipi_dcphy * samsung)1569 static void samsung_mipi_cphy_lane_disable(struct samsung_mipi_dcphy *samsung)
1570 {
1571 phy_update_bits(samsung, COMBO_MD0_GNR_CON0, PHY_ENABLE, 0);
1572 phy_update_bits(samsung, COMBO_MD1_GNR_CON0, PHY_ENABLE, 0);
1573 phy_update_bits(samsung, COMBO_MD2_GNR_CON0, PHY_ENABLE, 0);
1574 }
1575
samsung_mipi_dcphy_power_on(struct rockchip_phy * phy)1576 static int samsung_mipi_dcphy_power_on(struct rockchip_phy *phy)
1577 {
1578 struct samsung_mipi_dcphy *samsung = dev_get_priv(phy->dev);
1579
1580 if (samsung->mode == PHY_MODE_MIPI_DPHY)
1581 samsung_mipi_dphy_power_on(samsung);
1582 else
1583 samsung_mipi_cphy_power_on(samsung);
1584
1585 return 0;
1586 }
1587
samsung_mipi_dcphy_power_off(struct rockchip_phy * phy)1588 static int samsung_mipi_dcphy_power_off(struct rockchip_phy *phy)
1589 {
1590 struct samsung_mipi_dcphy *samsung = dev_get_priv(phy->dev);
1591
1592 if (samsung->mode == PHY_MODE_MIPI_DPHY)
1593 samsung_mipi_dphy_lane_disable(samsung);
1594 else
1595 samsung_mipi_cphy_lane_disable(samsung);
1596
1597 samsung_mipi_dcphy_pll_disable(samsung);
1598 samsung_mipi_dcphy_bias_block_disable(samsung);
1599
1600 return 0;
1601 }
1602
1603 static int
samsung_mipi_dcphy_pll_ssc_modulation_calc(struct samsung_mipi_dcphy * samsung,u8 * mfr,u8 * mrr)1604 samsung_mipi_dcphy_pll_ssc_modulation_calc(struct samsung_mipi_dcphy *samsung,
1605 u8 *mfr, u8 *mrr)
1606 {
1607 unsigned long fin = 24000;
1608 u16 prediv = samsung->pll.prediv;
1609 u16 fbdiv = samsung->pll.fbdiv;
1610 u16 min_mfr, max_mfr;
1611 u16 _mfr, best_mfr = 0;
1612 u16 mr, _mrr, best_mrr = 0;
1613
1614 /* 20KHz ≤ MF ≤ 150KHz */
1615 max_mfr = DIV_ROUND_UP(fin, (20 * prediv) << 5);
1616 min_mfr = div64_ul(fin, ((150 * prediv) << 5));
1617 /*0 ≤ mfr ≤ 255 */
1618 if (max_mfr > 256)
1619 max_mfr = 256;
1620
1621 for (_mfr = min_mfr; _mfr < max_mfr; _mfr++) {
1622 /* 1 ≤ mrr ≤ 31 */
1623 for (_mrr = 1; _mrr < 32; _mrr++) {
1624 mr = DIV_ROUND_UP(_mfr * _mrr * 100, fbdiv << 6);
1625 /* 0 ≤ MR ≤ 5% */
1626 if (mr > 5)
1627 continue;
1628
1629 if (_mfr * _mrr < 513) {
1630 best_mfr = _mfr;
1631 best_mrr = _mrr;
1632 break;
1633 }
1634 }
1635 }
1636
1637 if (best_mrr) {
1638 *mfr = best_mfr & 0xff;
1639 *mrr = best_mrr & 0x3f;
1640 } else {
1641 dev_err(samsung->dev, "failed to calc ssc parameter mfr and mrr\n");
1642 return -EINVAL;
1643 }
1644
1645 return 0;
1646 }
1647
1648 static unsigned long
samsung_mipi_dcphy_pll_round_rate(struct samsung_mipi_dcphy * samsung,unsigned long prate,unsigned long rate,u8 * prediv,u16 * fbdiv,int * dsm,u8 * scaler)1649 samsung_mipi_dcphy_pll_round_rate(struct samsung_mipi_dcphy *samsung,
1650 unsigned long prate, unsigned long rate,
1651 u8 *prediv, u16 *fbdiv, int *dsm, u8 *scaler)
1652 {
1653 u64 max_fout = samsung->c_option ? MAX_CPHY_BW : MAX_DPHY_BW;
1654 u64 best_freq = 0;
1655 u64 fin, fvco, fout;
1656 u8 min_prediv, max_prediv;
1657 u8 _prediv, best_prediv = 1;
1658 u16 _fbdiv, best_fbdiv = 1;
1659 u8 _scaler, best_scaler = 0;
1660 long _dsm, best_dsm = 0;
1661 u32 min_delta = 0xffffffff;
1662
1663 /*
1664 * The PLL output frequency can be calculated using a simple formula:
1665 * Fvco = ((m+k/65536) x 2 x Fin) / p
1666 * Fout = ((m+k/65536) x 2 x Fin) / (p x 2^s)
1667 */
1668 fin = div64_ul(prate, MSEC_PER_SEC);
1669
1670 while (!best_freq) {
1671 fout = div64_ul(rate, MSEC_PER_SEC);
1672 if (fout > max_fout)
1673 fout = max_fout;
1674
1675 /* 0 ≤ S[2:0] ≤ 6 */
1676 for (_scaler = 0; _scaler < 7; _scaler++) {
1677 fvco = fout << _scaler;
1678
1679 /*
1680 * 2600MHz ≤ FVCO ≤ 6600MHz
1681 */
1682 if (fvco < 2600 * MSEC_PER_SEC || fvco > 6600 * MSEC_PER_SEC)
1683 continue;
1684
1685 /* 6MHz ≤ Fref(Fin / p) ≤ 30MHz */
1686 min_prediv = DIV_ROUND_UP(fin, 30 * MSEC_PER_SEC);
1687 max_prediv = DIV_ROUND_CLOSEST(fin, 6 * MSEC_PER_SEC);
1688
1689 for (_prediv = min_prediv; _prediv <= max_prediv; _prediv++) {
1690 u64 delta, tmp;
1691
1692 _fbdiv = DIV_ROUND_CLOSEST(fvco * _prediv, 2 * fin);
1693
1694 /* 64 ≤ M[9:0] ≤ 1023 */
1695 if ((_fbdiv < 64) || (_fbdiv > 1023))
1696 continue;
1697
1698 /* -32767 ≤ K[15:0] ≤ 32767 */
1699 _dsm = ((_prediv * fvco) - (2 * _fbdiv * fin));
1700 _dsm = DIV_ROUND_UP(_dsm << 15, fin);
1701 if (abs(_dsm) > 32767)
1702 continue;
1703
1704 tmp = DIV_ROUND_CLOSEST((_fbdiv * fin * 2 * 1000), _prediv);
1705 tmp += DIV_ROUND_CLOSEST((_dsm * fin * 1000), _prediv << 15);
1706
1707 delta = abs(fvco * MSEC_PER_SEC - tmp);
1708 if (delta < min_delta) {
1709 best_prediv = _prediv;
1710 best_fbdiv = _fbdiv;
1711 best_dsm = _dsm;
1712 best_scaler = _scaler;
1713 min_delta = delta;
1714 best_freq = DIV_ROUND_CLOSEST(tmp, 1000) * MSEC_PER_SEC;
1715 }
1716 }
1717 }
1718
1719 rate += 100 * MSEC_PER_SEC;
1720 }
1721
1722 *prediv = best_prediv;
1723 *fbdiv = best_fbdiv;
1724 *dsm = (int)best_dsm & 0xffff;
1725 *scaler = best_scaler;
1726 dev_info(samsung->dev, "p: %d, m: %d, dsm:%ld, scaler: %d\n",
1727 best_prediv, best_fbdiv, best_dsm, best_scaler);
1728
1729 return best_freq >> best_scaler;
1730 }
1731
samsung_mipi_dcphy_set_pll(struct rockchip_phy * phy,unsigned long rate)1732 static unsigned long samsung_mipi_dcphy_set_pll(struct rockchip_phy *phy,
1733 unsigned long rate)
1734 {
1735 struct samsung_mipi_dcphy *samsung = dev_get_priv(phy->dev);
1736 unsigned long fin = 24000000, fout;
1737 u8 scaler = 0, mfr = 0, mrr = 0;
1738 u16 fbdiv = 1;
1739 u8 prediv = 1;
1740 int dsm = 0;
1741 int ret;
1742
1743 samsung->c_option = (samsung->mode == PHY_MODE_MIPI_DPHY) ? false : true;
1744 fout = samsung_mipi_dcphy_pll_round_rate(samsung, fin, rate, &prediv,
1745 &fbdiv, &dsm, &scaler);
1746
1747 dev_info(samsung->dev, "fin=%lu, req_rate=%lu\n", fin, rate);
1748 dev_info(samsung->dev, "fout=%lu, prediv=%u, fbdiv=%u\n", fout, prediv, fbdiv);
1749
1750 samsung->pll.prediv = prediv;
1751 samsung->pll.fbdiv = fbdiv;
1752 samsung->pll.dsm = dsm;
1753 samsung->pll.scaler = scaler;
1754 samsung->pll.rate = fout;
1755
1756 /*
1757 * All DPHY 2.0 compliant Transmitters shall support SSC operating above
1758 * 2.5 Gbps
1759 */
1760 if (fout > 2500000000LL) {
1761 ret = samsung_mipi_dcphy_pll_ssc_modulation_calc(samsung,
1762 &mfr, &mrr);
1763 if (!ret) {
1764 samsung->pll.ssc_en = true;
1765 samsung->pll.mfr = mfr;
1766 samsung->pll.mrr = mrr;
1767 }
1768 }
1769
1770 return fout;
1771 }
1772
samsung_mipi_dcphy_set_mode(struct rockchip_phy * phy,enum phy_mode mode)1773 static int samsung_mipi_dcphy_set_mode(struct rockchip_phy *phy,
1774 enum phy_mode mode)
1775 {
1776 struct samsung_mipi_dcphy *samsung = dev_get_priv(phy->dev);
1777
1778 samsung->mode = mode;
1779
1780 return 0;
1781 }
1782
samsung_mipi_dcphy_probe(struct udevice * dev)1783 static int samsung_mipi_dcphy_probe(struct udevice *dev)
1784 {
1785 struct samsung_mipi_dcphy *samsung = dev_get_priv(dev);
1786 struct rockchip_phy *tmp_phy;
1787 struct rockchip_phy *phy;
1788 struct udevice *syscon;
1789 int ret;
1790
1791 phy = calloc(1, sizeof(*phy));
1792 if (!phy)
1793 return -ENOMEM;
1794
1795 tmp_phy = (struct rockchip_phy *)dev_get_driver_data(dev);
1796 dev->driver_data = (ulong)phy;
1797 memcpy(phy, tmp_phy, sizeof(*phy));
1798
1799 samsung->lanes = ofnode_read_u32_default(dev->node, "samsung,lanes", 4);
1800
1801 samsung->base = dev_read_addr_ptr(dev);
1802 if (IS_ERR(samsung->base)) {
1803 dev_err(dev, "resource \"phy\" not found\n");
1804 return PTR_ERR(samsung->base);
1805 }
1806
1807 ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "rockchip,grf",
1808 &syscon);
1809 if (!ret) {
1810 samsung->grf = syscon_get_regmap(syscon);
1811 if (!samsung->grf)
1812 return -ENODEV;
1813 }
1814
1815 ret = reset_get_by_name(dev, "m_phy", &samsung->m_phy_rst);
1816 if (ret) {
1817 ret = reset_get_by_name(dev, "phy", &samsung->m_phy_rst);
1818 if (ret) {
1819 pr_err("reset_get_by_name(phy) failed: %d\n", ret);
1820 return ret;
1821 }
1822 }
1823
1824 phy->dev = dev;
1825
1826 return 0;
1827 }
1828
1829 static const struct rockchip_phy_funcs samsung_mipi_dcphy_funcs = {
1830 .power_on = samsung_mipi_dcphy_power_on,
1831 .power_off = samsung_mipi_dcphy_power_off,
1832 .set_pll = samsung_mipi_dcphy_set_pll,
1833 .set_mode = samsung_mipi_dcphy_set_mode,
1834 };
1835
1836 static struct rockchip_phy rk3588_samsung_mipi_dcphy_driver_data = {
1837 .funcs = &samsung_mipi_dcphy_funcs,
1838 };
1839
1840 static const struct udevice_id samsung_mipi_dcphy_ids[] = {
1841 {
1842 .compatible = "rockchip,rk3588-mipi-dcphy",
1843 .data = (ulong)&rk3588_samsung_mipi_dcphy_driver_data,
1844 },
1845 {}
1846 };
1847
1848 U_BOOT_DRIVER(samsung_mipi_dcphy) = {
1849 .name = "samsung-mipi-dcphy",
1850 .id = UCLASS_PHY,
1851 .of_match = samsung_mipi_dcphy_ids,
1852 .probe = samsung_mipi_dcphy_probe,
1853 .priv_auto_alloc_size = sizeof(struct samsung_mipi_dcphy),
1854 };
1855