• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2016, The Linux Foundation. All rights reserved.
4  */
5 
6 #include <linux/clk.h>
7 #include <linux/clk-provider.h>
8 #include <linux/delay.h>
9 
10 #include "dsi_phy.h"
11 #include "dsi.xml.h"
12 #include "dsi_phy_14nm.xml.h"
13 
14 #define PHY_14NM_CKLN_IDX	4
15 
16 /*
17  * DSI PLL 14nm - clock diagram (eg: DSI0):
18  *
19  *         dsi0n1_postdiv_clk
20  *                         |
21  *                         |
22  *                 +----+  |  +----+
23  *  dsi0vco_clk ---| n1 |--o--| /8 |-- dsi0pllbyte
24  *                 +----+  |  +----+
25  *                         |           dsi0n1_postdivby2_clk
26  *                         |   +----+  |
27  *                         o---| /2 |--o--|\
28  *                         |   +----+     | \   +----+
29  *                         |              |  |--| n2 |-- dsi0pll
30  *                         o--------------| /   +----+
31  *                                        |/
32  */
33 
34 #define POLL_MAX_READS			15
35 #define POLL_TIMEOUT_US			1000
36 
37 #define VCO_REF_CLK_RATE		19200000
38 #define VCO_MIN_RATE			1300000000UL
39 #define VCO_MAX_RATE			2600000000UL
40 
41 struct dsi_pll_config {
42 	u64 vco_current_rate;
43 
44 	u32 ssc_en;	/* SSC enable/disable */
45 
46 	/* fixed params */
47 	u32 plllock_cnt;
48 	u32 ssc_center;
49 	u32 ssc_adj_period;
50 	u32 ssc_spread;
51 	u32 ssc_freq;
52 
53 	/* calculated */
54 	u32 dec_start;
55 	u32 div_frac_start;
56 	u32 ssc_period;
57 	u32 ssc_step_size;
58 	u32 plllock_cmp;
59 	u32 pll_vco_div_ref;
60 	u32 pll_vco_count;
61 	u32 pll_kvco_div_ref;
62 	u32 pll_kvco_count;
63 };
64 
65 struct pll_14nm_cached_state {
66 	unsigned long vco_rate;
67 	u8 n2postdiv;
68 	u8 n1postdiv;
69 };
70 
71 struct dsi_pll_14nm {
72 	struct clk_hw clk_hw;
73 
74 	struct msm_dsi_phy *phy;
75 
76 	/* protects REG_DSI_14nm_PHY_CMN_CLK_CFG0 register */
77 	spinlock_t postdiv_lock;
78 
79 	struct pll_14nm_cached_state cached_state;
80 
81 	struct dsi_pll_14nm *slave;
82 };
83 
84 #define to_pll_14nm(x)	container_of(x, struct dsi_pll_14nm, clk_hw)
85 
86 /*
87  * Private struct for N1/N2 post-divider clocks. These clocks are similar to
88  * the generic clk_divider class of clocks. The only difference is that it
89  * also sets the slave DSI PLL's post-dividers if in bonded DSI mode
90  */
91 struct dsi_pll_14nm_postdiv {
92 	struct clk_hw hw;
93 
94 	/* divider params */
95 	u8 shift;
96 	u8 width;
97 	u8 flags; /* same flags as used by clk_divider struct */
98 
99 	struct dsi_pll_14nm *pll;
100 };
101 
102 #define to_pll_14nm_postdiv(_hw) container_of(_hw, struct dsi_pll_14nm_postdiv, hw)
103 
104 /*
105  * Global list of private DSI PLL struct pointers. We need this for bonded DSI
106  * mode, where the master PLL's clk_ops needs access the slave's private data
107  */
108 static struct dsi_pll_14nm *pll_14nm_list[DSI_MAX];
109 
pll_14nm_poll_for_ready(struct dsi_pll_14nm * pll_14nm,u32 nb_tries,u32 timeout_us)110 static bool pll_14nm_poll_for_ready(struct dsi_pll_14nm *pll_14nm,
111 				    u32 nb_tries, u32 timeout_us)
112 {
113 	bool pll_locked = false, pll_ready = false;
114 	void __iomem *base = pll_14nm->phy->pll_base;
115 	u32 tries, val;
116 
117 	tries = nb_tries;
118 	while (tries--) {
119 		val = dsi_phy_read(base + REG_DSI_14nm_PHY_PLL_RESET_SM_READY_STATUS);
120 		pll_locked = !!(val & BIT(5));
121 
122 		if (pll_locked)
123 			break;
124 
125 		udelay(timeout_us);
126 	}
127 
128 	if (!pll_locked)
129 		goto out;
130 
131 	tries = nb_tries;
132 	while (tries--) {
133 		val = dsi_phy_read(base + REG_DSI_14nm_PHY_PLL_RESET_SM_READY_STATUS);
134 		pll_ready = !!(val & BIT(0));
135 
136 		if (pll_ready)
137 			break;
138 
139 		udelay(timeout_us);
140 	}
141 
142 out:
143 	DBG("DSI PLL is %slocked, %sready", pll_locked ? "" : "*not* ", pll_ready ? "" : "*not* ");
144 
145 	return pll_locked && pll_ready;
146 }
147 
dsi_pll_14nm_config_init(struct dsi_pll_config * pconf)148 static void dsi_pll_14nm_config_init(struct dsi_pll_config *pconf)
149 {
150 	/* fixed input */
151 	pconf->plllock_cnt = 1;
152 
153 	/*
154 	 * SSC is enabled by default. We might need DT props for configuring
155 	 * some SSC params like PPM and center/down spread etc.
156 	 */
157 	pconf->ssc_en = 1;
158 	pconf->ssc_center = 0;		/* down spread by default */
159 	pconf->ssc_spread = 5;		/* PPM / 1000 */
160 	pconf->ssc_freq = 31500;	/* default recommended */
161 	pconf->ssc_adj_period = 37;
162 }
163 
164 #define CEIL(x, y)		(((x) + ((y) - 1)) / (y))
165 
pll_14nm_ssc_calc(struct dsi_pll_14nm * pll,struct dsi_pll_config * pconf)166 static void pll_14nm_ssc_calc(struct dsi_pll_14nm *pll, struct dsi_pll_config *pconf)
167 {
168 	u32 period, ssc_period;
169 	u32 ref, rem;
170 	u64 step_size;
171 
172 	DBG("vco=%lld ref=%d", pconf->vco_current_rate, VCO_REF_CLK_RATE);
173 
174 	ssc_period = pconf->ssc_freq / 500;
175 	period = (u32)VCO_REF_CLK_RATE / 1000;
176 	ssc_period  = CEIL(period, ssc_period);
177 	ssc_period -= 1;
178 	pconf->ssc_period = ssc_period;
179 
180 	DBG("ssc freq=%d spread=%d period=%d", pconf->ssc_freq,
181 	    pconf->ssc_spread, pconf->ssc_period);
182 
183 	step_size = (u32)pconf->vco_current_rate;
184 	ref = VCO_REF_CLK_RATE;
185 	ref /= 1000;
186 	step_size = div_u64(step_size, ref);
187 	step_size <<= 20;
188 	step_size = div_u64(step_size, 1000);
189 	step_size *= pconf->ssc_spread;
190 	step_size = div_u64(step_size, 1000);
191 	step_size *= (pconf->ssc_adj_period + 1);
192 
193 	rem = 0;
194 	step_size = div_u64_rem(step_size, ssc_period + 1, &rem);
195 	if (rem)
196 		step_size++;
197 
198 	DBG("step_size=%lld", step_size);
199 
200 	step_size &= 0x0ffff;	/* take lower 16 bits */
201 
202 	pconf->ssc_step_size = step_size;
203 }
204 
pll_14nm_dec_frac_calc(struct dsi_pll_14nm * pll,struct dsi_pll_config * pconf)205 static void pll_14nm_dec_frac_calc(struct dsi_pll_14nm *pll, struct dsi_pll_config *pconf)
206 {
207 	u64 multiplier = BIT(20);
208 	u64 dec_start_multiple, dec_start, pll_comp_val;
209 	u32 duration, div_frac_start;
210 	u64 vco_clk_rate = pconf->vco_current_rate;
211 	u64 fref = VCO_REF_CLK_RATE;
212 
213 	DBG("vco_clk_rate=%lld ref_clk_rate=%lld", vco_clk_rate, fref);
214 
215 	dec_start_multiple = div_u64(vco_clk_rate * multiplier, fref);
216 	div_u64_rem(dec_start_multiple, multiplier, &div_frac_start);
217 
218 	dec_start = div_u64(dec_start_multiple, multiplier);
219 
220 	pconf->dec_start = (u32)dec_start;
221 	pconf->div_frac_start = div_frac_start;
222 
223 	if (pconf->plllock_cnt == 0)
224 		duration = 1024;
225 	else if (pconf->plllock_cnt == 1)
226 		duration = 256;
227 	else if (pconf->plllock_cnt == 2)
228 		duration = 128;
229 	else
230 		duration = 32;
231 
232 	pll_comp_val = duration * dec_start_multiple;
233 	pll_comp_val = div_u64(pll_comp_val, multiplier);
234 	do_div(pll_comp_val, 10);
235 
236 	pconf->plllock_cmp = (u32)pll_comp_val;
237 }
238 
pll_14nm_kvco_slop(u32 vrate)239 static u32 pll_14nm_kvco_slop(u32 vrate)
240 {
241 	u32 slop = 0;
242 
243 	if (vrate > VCO_MIN_RATE && vrate <= 1800000000UL)
244 		slop =  600;
245 	else if (vrate > 1800000000UL && vrate < 2300000000UL)
246 		slop = 400;
247 	else if (vrate > 2300000000UL && vrate < VCO_MAX_RATE)
248 		slop = 280;
249 
250 	return slop;
251 }
252 
pll_14nm_calc_vco_count(struct dsi_pll_14nm * pll,struct dsi_pll_config * pconf)253 static void pll_14nm_calc_vco_count(struct dsi_pll_14nm *pll, struct dsi_pll_config *pconf)
254 {
255 	u64 vco_clk_rate = pconf->vco_current_rate;
256 	u64 fref = VCO_REF_CLK_RATE;
257 	u32 vco_measure_time = 5;
258 	u32 kvco_measure_time = 5;
259 	u64 data;
260 	u32 cnt;
261 
262 	data = fref * vco_measure_time;
263 	do_div(data, 1000000);
264 	data &= 0x03ff;	/* 10 bits */
265 	data -= 2;
266 	pconf->pll_vco_div_ref = data;
267 
268 	data = div_u64(vco_clk_rate, 1000000);	/* unit is Mhz */
269 	data *= vco_measure_time;
270 	do_div(data, 10);
271 	pconf->pll_vco_count = data;
272 
273 	data = fref * kvco_measure_time;
274 	do_div(data, 1000000);
275 	data &= 0x03ff;	/* 10 bits */
276 	data -= 1;
277 	pconf->pll_kvco_div_ref = data;
278 
279 	cnt = pll_14nm_kvco_slop(vco_clk_rate);
280 	cnt *= 2;
281 	cnt /= 100;
282 	cnt *= kvco_measure_time;
283 	pconf->pll_kvco_count = cnt;
284 }
285 
pll_db_commit_ssc(struct dsi_pll_14nm * pll,struct dsi_pll_config * pconf)286 static void pll_db_commit_ssc(struct dsi_pll_14nm *pll, struct dsi_pll_config *pconf)
287 {
288 	void __iomem *base = pll->phy->pll_base;
289 	u8 data;
290 
291 	data = pconf->ssc_adj_period;
292 	data &= 0x0ff;
293 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_SSC_ADJ_PER1, data);
294 	data = (pconf->ssc_adj_period >> 8);
295 	data &= 0x03;
296 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_SSC_ADJ_PER2, data);
297 
298 	data = pconf->ssc_period;
299 	data &= 0x0ff;
300 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_SSC_PER1, data);
301 	data = (pconf->ssc_period >> 8);
302 	data &= 0x0ff;
303 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_SSC_PER2, data);
304 
305 	data = pconf->ssc_step_size;
306 	data &= 0x0ff;
307 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_SSC_STEP_SIZE1, data);
308 	data = (pconf->ssc_step_size >> 8);
309 	data &= 0x0ff;
310 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_SSC_STEP_SIZE2, data);
311 
312 	data = (pconf->ssc_center & 0x01);
313 	data <<= 1;
314 	data |= 0x01; /* enable */
315 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_SSC_EN_CENTER, data);
316 
317 	wmb();	/* make sure register committed */
318 }
319 
pll_db_commit_common(struct dsi_pll_14nm * pll,struct dsi_pll_config * pconf)320 static void pll_db_commit_common(struct dsi_pll_14nm *pll,
321 				 struct dsi_pll_config *pconf)
322 {
323 	void __iomem *base = pll->phy->pll_base;
324 	u8 data;
325 
326 	/* confgiure the non frequency dependent pll registers */
327 	data = 0;
328 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_SYSCLK_EN_RESET, data);
329 
330 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_TXCLK_EN, 1);
331 
332 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_RESETSM_CNTRL, 48);
333 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_RESETSM_CNTRL2, 4 << 3); /* bandgap_timer */
334 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_RESETSM_CNTRL5, 5); /* pll_wakeup_timer */
335 
336 	data = pconf->pll_vco_div_ref & 0xff;
337 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_VCO_DIV_REF1, data);
338 	data = (pconf->pll_vco_div_ref >> 8) & 0x3;
339 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_VCO_DIV_REF2, data);
340 
341 	data = pconf->pll_kvco_div_ref & 0xff;
342 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_KVCO_DIV_REF1, data);
343 	data = (pconf->pll_kvco_div_ref >> 8) & 0x3;
344 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_KVCO_DIV_REF2, data);
345 
346 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLL_MISC1, 16);
347 
348 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_IE_TRIM, 4);
349 
350 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_IP_TRIM, 4);
351 
352 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_CP_SET_CUR, 1 << 3 | 1);
353 
354 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLL_ICPCSET, 0 << 3 | 0);
355 
356 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLL_ICPMSET, 0 << 3 | 0);
357 
358 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLL_ICP_SET, 4 << 3 | 4);
359 
360 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLL_LPF1, 1 << 4 | 11);
361 
362 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_IPTAT_TRIM, 7);
363 
364 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLL_CRCTRL, 1 << 4 | 2);
365 }
366 
pll_14nm_software_reset(struct dsi_pll_14nm * pll_14nm)367 static void pll_14nm_software_reset(struct dsi_pll_14nm *pll_14nm)
368 {
369 	void __iomem *cmn_base = pll_14nm->phy->base;
370 
371 	/* de assert pll start and apply pll sw reset */
372 
373 	/* stop pll */
374 	dsi_phy_write(cmn_base + REG_DSI_14nm_PHY_CMN_PLL_CNTRL, 0);
375 
376 	/* pll sw reset */
377 	dsi_phy_write_udelay(cmn_base + REG_DSI_14nm_PHY_CMN_CTRL_1, 0x20, 10);
378 	wmb();	/* make sure register committed */
379 
380 	dsi_phy_write(cmn_base + REG_DSI_14nm_PHY_CMN_CTRL_1, 0);
381 	wmb();	/* make sure register committed */
382 }
383 
pll_db_commit_14nm(struct dsi_pll_14nm * pll,struct dsi_pll_config * pconf)384 static void pll_db_commit_14nm(struct dsi_pll_14nm *pll,
385 			       struct dsi_pll_config *pconf)
386 {
387 	void __iomem *base = pll->phy->pll_base;
388 	void __iomem *cmn_base = pll->phy->base;
389 	u8 data;
390 
391 	DBG("DSI%d PLL", pll->phy->id);
392 
393 	dsi_phy_write(cmn_base + REG_DSI_14nm_PHY_CMN_LDO_CNTRL, 0x3c);
394 
395 	pll_db_commit_common(pll, pconf);
396 
397 	pll_14nm_software_reset(pll);
398 
399 	/* Use the /2 path in Mux */
400 	dsi_phy_write(cmn_base + REG_DSI_14nm_PHY_CMN_CLK_CFG1, 1);
401 
402 	data = 0xff; /* data, clk, pll normal operation */
403 	dsi_phy_write(cmn_base + REG_DSI_14nm_PHY_CMN_CTRL_0, data);
404 
405 	/* configure the frequency dependent pll registers */
406 	data = pconf->dec_start;
407 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_DEC_START, data);
408 
409 	data = pconf->div_frac_start & 0xff;
410 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_DIV_FRAC_START1, data);
411 	data = (pconf->div_frac_start >> 8) & 0xff;
412 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_DIV_FRAC_START2, data);
413 	data = (pconf->div_frac_start >> 16) & 0xf;
414 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_DIV_FRAC_START3, data);
415 
416 	data = pconf->plllock_cmp & 0xff;
417 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLLLOCK_CMP1, data);
418 
419 	data = (pconf->plllock_cmp >> 8) & 0xff;
420 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLLLOCK_CMP2, data);
421 
422 	data = (pconf->plllock_cmp >> 16) & 0x3;
423 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLLLOCK_CMP3, data);
424 
425 	data = pconf->plllock_cnt << 1 | 0 << 3; /* plllock_rng */
426 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLLLOCK_CMP_EN, data);
427 
428 	data = pconf->pll_vco_count & 0xff;
429 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_VCO_COUNT1, data);
430 	data = (pconf->pll_vco_count >> 8) & 0xff;
431 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_VCO_COUNT2, data);
432 
433 	data = pconf->pll_kvco_count & 0xff;
434 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_KVCO_COUNT1, data);
435 	data = (pconf->pll_kvco_count >> 8) & 0x3;
436 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_KVCO_COUNT2, data);
437 
438 	/*
439 	 * High nibble configures the post divider internal to the VCO. It's
440 	 * fixed to divide by 1 for now.
441 	 *
442 	 * 0: divided by 1
443 	 * 1: divided by 2
444 	 * 2: divided by 4
445 	 * 3: divided by 8
446 	 */
447 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLL_LPF2_POSTDIV, 0 << 4 | 3);
448 
449 	if (pconf->ssc_en)
450 		pll_db_commit_ssc(pll, pconf);
451 
452 	wmb();	/* make sure register committed */
453 }
454 
455 /*
456  * VCO clock Callbacks
457  */
dsi_pll_14nm_vco_set_rate(struct clk_hw * hw,unsigned long rate,unsigned long parent_rate)458 static int dsi_pll_14nm_vco_set_rate(struct clk_hw *hw, unsigned long rate,
459 				     unsigned long parent_rate)
460 {
461 	struct dsi_pll_14nm *pll_14nm = to_pll_14nm(hw);
462 	struct dsi_pll_config conf;
463 
464 	DBG("DSI PLL%d rate=%lu, parent's=%lu", pll_14nm->phy->id, rate,
465 	    parent_rate);
466 
467 	dsi_pll_14nm_config_init(&conf);
468 	conf.vco_current_rate = rate;
469 
470 	pll_14nm_dec_frac_calc(pll_14nm, &conf);
471 
472 	if (conf.ssc_en)
473 		pll_14nm_ssc_calc(pll_14nm, &conf);
474 
475 	pll_14nm_calc_vco_count(pll_14nm, &conf);
476 
477 	/* commit the slave DSI PLL registers if we're master. Note that we
478 	 * don't lock the slave PLL. We just ensure that the PLL/PHY registers
479 	 * of the master and slave are identical
480 	 */
481 	if (pll_14nm->phy->usecase == MSM_DSI_PHY_MASTER) {
482 		struct dsi_pll_14nm *pll_14nm_slave = pll_14nm->slave;
483 
484 		pll_db_commit_14nm(pll_14nm_slave, &conf);
485 	}
486 
487 	pll_db_commit_14nm(pll_14nm, &conf);
488 
489 	return 0;
490 }
491 
dsi_pll_14nm_vco_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)492 static unsigned long dsi_pll_14nm_vco_recalc_rate(struct clk_hw *hw,
493 						  unsigned long parent_rate)
494 {
495 	struct dsi_pll_14nm *pll_14nm = to_pll_14nm(hw);
496 	void __iomem *base = pll_14nm->phy->pll_base;
497 	u64 vco_rate, multiplier = BIT(20);
498 	u32 div_frac_start;
499 	u32 dec_start;
500 	u64 ref_clk = parent_rate;
501 
502 	dec_start = dsi_phy_read(base + REG_DSI_14nm_PHY_PLL_DEC_START);
503 	dec_start &= 0x0ff;
504 
505 	DBG("dec_start = %x", dec_start);
506 
507 	div_frac_start = (dsi_phy_read(base + REG_DSI_14nm_PHY_PLL_DIV_FRAC_START3)
508 				& 0xf) << 16;
509 	div_frac_start |= (dsi_phy_read(base + REG_DSI_14nm_PHY_PLL_DIV_FRAC_START2)
510 				& 0xff) << 8;
511 	div_frac_start |= dsi_phy_read(base + REG_DSI_14nm_PHY_PLL_DIV_FRAC_START1)
512 				& 0xff;
513 
514 	DBG("div_frac_start = %x", div_frac_start);
515 
516 	vco_rate = ref_clk * dec_start;
517 
518 	vco_rate += ((ref_clk * div_frac_start) / multiplier);
519 
520 	/*
521 	 * Recalculating the rate from dec_start and frac_start doesn't end up
522 	 * the rate we originally set. Convert the freq to KHz, round it up and
523 	 * convert it back to MHz.
524 	 */
525 	vco_rate = DIV_ROUND_UP_ULL(vco_rate, 1000) * 1000;
526 
527 	DBG("returning vco rate = %lu", (unsigned long)vco_rate);
528 
529 	return (unsigned long)vco_rate;
530 }
531 
dsi_pll_14nm_vco_prepare(struct clk_hw * hw)532 static int dsi_pll_14nm_vco_prepare(struct clk_hw *hw)
533 {
534 	struct dsi_pll_14nm *pll_14nm = to_pll_14nm(hw);
535 	void __iomem *base = pll_14nm->phy->pll_base;
536 	void __iomem *cmn_base = pll_14nm->phy->base;
537 	bool locked;
538 
539 	DBG("");
540 
541 	if (unlikely(pll_14nm->phy->pll_on))
542 		return 0;
543 
544 	if (dsi_pll_14nm_vco_recalc_rate(hw, VCO_REF_CLK_RATE) == 0)
545 		dsi_pll_14nm_vco_set_rate(hw, pll_14nm->phy->cfg->min_pll_rate, VCO_REF_CLK_RATE);
546 
547 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_VREF_CFG1, 0x10);
548 	dsi_phy_write(cmn_base + REG_DSI_14nm_PHY_CMN_PLL_CNTRL, 1);
549 
550 	locked = pll_14nm_poll_for_ready(pll_14nm, POLL_MAX_READS,
551 					 POLL_TIMEOUT_US);
552 
553 	if (unlikely(!locked)) {
554 		DRM_DEV_ERROR(&pll_14nm->phy->pdev->dev, "DSI PLL lock failed\n");
555 		return -EINVAL;
556 	}
557 
558 	DBG("DSI PLL lock success");
559 	pll_14nm->phy->pll_on = true;
560 
561 	return 0;
562 }
563 
dsi_pll_14nm_vco_unprepare(struct clk_hw * hw)564 static void dsi_pll_14nm_vco_unprepare(struct clk_hw *hw)
565 {
566 	struct dsi_pll_14nm *pll_14nm = to_pll_14nm(hw);
567 	void __iomem *cmn_base = pll_14nm->phy->base;
568 
569 	DBG("");
570 
571 	if (unlikely(!pll_14nm->phy->pll_on))
572 		return;
573 
574 	dsi_phy_write(cmn_base + REG_DSI_14nm_PHY_CMN_PLL_CNTRL, 0);
575 
576 	pll_14nm->phy->pll_on = false;
577 }
578 
dsi_pll_14nm_clk_round_rate(struct clk_hw * hw,unsigned long rate,unsigned long * parent_rate)579 static long dsi_pll_14nm_clk_round_rate(struct clk_hw *hw,
580 		unsigned long rate, unsigned long *parent_rate)
581 {
582 	struct dsi_pll_14nm *pll_14nm = to_pll_14nm(hw);
583 
584 	if      (rate < pll_14nm->phy->cfg->min_pll_rate)
585 		return  pll_14nm->phy->cfg->min_pll_rate;
586 	else if (rate > pll_14nm->phy->cfg->max_pll_rate)
587 		return  pll_14nm->phy->cfg->max_pll_rate;
588 	else
589 		return rate;
590 }
591 
592 static const struct clk_ops clk_ops_dsi_pll_14nm_vco = {
593 	.round_rate = dsi_pll_14nm_clk_round_rate,
594 	.set_rate = dsi_pll_14nm_vco_set_rate,
595 	.recalc_rate = dsi_pll_14nm_vco_recalc_rate,
596 	.prepare = dsi_pll_14nm_vco_prepare,
597 	.unprepare = dsi_pll_14nm_vco_unprepare,
598 };
599 
600 /*
601  * N1 and N2 post-divider clock callbacks
602  */
603 #define div_mask(width)	((1 << (width)) - 1)
dsi_pll_14nm_postdiv_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)604 static unsigned long dsi_pll_14nm_postdiv_recalc_rate(struct clk_hw *hw,
605 						      unsigned long parent_rate)
606 {
607 	struct dsi_pll_14nm_postdiv *postdiv = to_pll_14nm_postdiv(hw);
608 	struct dsi_pll_14nm *pll_14nm = postdiv->pll;
609 	void __iomem *base = pll_14nm->phy->base;
610 	u8 shift = postdiv->shift;
611 	u8 width = postdiv->width;
612 	u32 val;
613 
614 	DBG("DSI%d PLL parent rate=%lu", pll_14nm->phy->id, parent_rate);
615 
616 	val = dsi_phy_read(base + REG_DSI_14nm_PHY_CMN_CLK_CFG0) >> shift;
617 	val &= div_mask(width);
618 
619 	return divider_recalc_rate(hw, parent_rate, val, NULL,
620 				   postdiv->flags, width);
621 }
622 
dsi_pll_14nm_postdiv_round_rate(struct clk_hw * hw,unsigned long rate,unsigned long * prate)623 static long dsi_pll_14nm_postdiv_round_rate(struct clk_hw *hw,
624 					    unsigned long rate,
625 					    unsigned long *prate)
626 {
627 	struct dsi_pll_14nm_postdiv *postdiv = to_pll_14nm_postdiv(hw);
628 	struct dsi_pll_14nm *pll_14nm = postdiv->pll;
629 
630 	DBG("DSI%d PLL parent rate=%lu", pll_14nm->phy->id, rate);
631 
632 	return divider_round_rate(hw, rate, prate, NULL,
633 				  postdiv->width,
634 				  postdiv->flags);
635 }
636 
dsi_pll_14nm_postdiv_set_rate(struct clk_hw * hw,unsigned long rate,unsigned long parent_rate)637 static int dsi_pll_14nm_postdiv_set_rate(struct clk_hw *hw, unsigned long rate,
638 					 unsigned long parent_rate)
639 {
640 	struct dsi_pll_14nm_postdiv *postdiv = to_pll_14nm_postdiv(hw);
641 	struct dsi_pll_14nm *pll_14nm = postdiv->pll;
642 	void __iomem *base = pll_14nm->phy->base;
643 	spinlock_t *lock = &pll_14nm->postdiv_lock;
644 	u8 shift = postdiv->shift;
645 	u8 width = postdiv->width;
646 	unsigned int value;
647 	unsigned long flags = 0;
648 	u32 val;
649 
650 	DBG("DSI%d PLL parent rate=%lu parent rate %lu", pll_14nm->phy->id, rate,
651 	    parent_rate);
652 
653 	value = divider_get_val(rate, parent_rate, NULL, postdiv->width,
654 				postdiv->flags);
655 
656 	spin_lock_irqsave(lock, flags);
657 
658 	val = dsi_phy_read(base + REG_DSI_14nm_PHY_CMN_CLK_CFG0);
659 	val &= ~(div_mask(width) << shift);
660 
661 	val |= value << shift;
662 	dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_CLK_CFG0, val);
663 
664 	/* If we're master in bonded DSI mode, then the slave PLL's post-dividers
665 	 * follow the master's post dividers
666 	 */
667 	if (pll_14nm->phy->usecase == MSM_DSI_PHY_MASTER) {
668 		struct dsi_pll_14nm *pll_14nm_slave = pll_14nm->slave;
669 		void __iomem *slave_base = pll_14nm_slave->phy->base;
670 
671 		dsi_phy_write(slave_base + REG_DSI_14nm_PHY_CMN_CLK_CFG0, val);
672 	}
673 
674 	spin_unlock_irqrestore(lock, flags);
675 
676 	return 0;
677 }
678 
679 static const struct clk_ops clk_ops_dsi_pll_14nm_postdiv = {
680 	.recalc_rate = dsi_pll_14nm_postdiv_recalc_rate,
681 	.round_rate = dsi_pll_14nm_postdiv_round_rate,
682 	.set_rate = dsi_pll_14nm_postdiv_set_rate,
683 };
684 
685 /*
686  * PLL Callbacks
687  */
688 
dsi_14nm_pll_save_state(struct msm_dsi_phy * phy)689 static void dsi_14nm_pll_save_state(struct msm_dsi_phy *phy)
690 {
691 	struct dsi_pll_14nm *pll_14nm = to_pll_14nm(phy->vco_hw);
692 	struct pll_14nm_cached_state *cached_state = &pll_14nm->cached_state;
693 	void __iomem *cmn_base = pll_14nm->phy->base;
694 	u32 data;
695 
696 	data = dsi_phy_read(cmn_base + REG_DSI_14nm_PHY_CMN_CLK_CFG0);
697 
698 	cached_state->n1postdiv = data & 0xf;
699 	cached_state->n2postdiv = (data >> 4) & 0xf;
700 
701 	DBG("DSI%d PLL save state %x %x", pll_14nm->phy->id,
702 	    cached_state->n1postdiv, cached_state->n2postdiv);
703 
704 	cached_state->vco_rate = clk_hw_get_rate(phy->vco_hw);
705 }
706 
dsi_14nm_pll_restore_state(struct msm_dsi_phy * phy)707 static int dsi_14nm_pll_restore_state(struct msm_dsi_phy *phy)
708 {
709 	struct dsi_pll_14nm *pll_14nm = to_pll_14nm(phy->vco_hw);
710 	struct pll_14nm_cached_state *cached_state = &pll_14nm->cached_state;
711 	void __iomem *cmn_base = pll_14nm->phy->base;
712 	u32 data;
713 	int ret;
714 
715 	ret = dsi_pll_14nm_vco_set_rate(phy->vco_hw,
716 					cached_state->vco_rate, 0);
717 	if (ret) {
718 		DRM_DEV_ERROR(&pll_14nm->phy->pdev->dev,
719 			"restore vco rate failed. ret=%d\n", ret);
720 		return ret;
721 	}
722 
723 	data = cached_state->n1postdiv | (cached_state->n2postdiv << 4);
724 
725 	DBG("DSI%d PLL restore state %x %x", pll_14nm->phy->id,
726 	    cached_state->n1postdiv, cached_state->n2postdiv);
727 
728 	dsi_phy_write(cmn_base + REG_DSI_14nm_PHY_CMN_CLK_CFG0, data);
729 
730 	/* also restore post-dividers for slave DSI PLL */
731 	if (phy->usecase == MSM_DSI_PHY_MASTER) {
732 		struct dsi_pll_14nm *pll_14nm_slave = pll_14nm->slave;
733 		void __iomem *slave_base = pll_14nm_slave->phy->base;
734 
735 		dsi_phy_write(slave_base + REG_DSI_14nm_PHY_CMN_CLK_CFG0, data);
736 	}
737 
738 	return 0;
739 }
740 
dsi_14nm_set_usecase(struct msm_dsi_phy * phy)741 static int dsi_14nm_set_usecase(struct msm_dsi_phy *phy)
742 {
743 	struct dsi_pll_14nm *pll_14nm = to_pll_14nm(phy->vco_hw);
744 	void __iomem *base = phy->pll_base;
745 	u32 clkbuflr_en, bandgap = 0;
746 
747 	switch (phy->usecase) {
748 	case MSM_DSI_PHY_STANDALONE:
749 		clkbuflr_en = 0x1;
750 		break;
751 	case MSM_DSI_PHY_MASTER:
752 		clkbuflr_en = 0x3;
753 		pll_14nm->slave = pll_14nm_list[(pll_14nm->phy->id + 1) % DSI_MAX];
754 		break;
755 	case MSM_DSI_PHY_SLAVE:
756 		clkbuflr_en = 0x0;
757 		bandgap = 0x3;
758 		break;
759 	default:
760 		return -EINVAL;
761 	}
762 
763 	dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_CLKBUFLR_EN, clkbuflr_en);
764 	if (bandgap)
765 		dsi_phy_write(base + REG_DSI_14nm_PHY_PLL_PLL_BANDGAP, bandgap);
766 
767 	return 0;
768 }
769 
pll_14nm_postdiv_register(struct dsi_pll_14nm * pll_14nm,const char * name,const char * parent_name,unsigned long flags,u8 shift)770 static struct clk_hw *pll_14nm_postdiv_register(struct dsi_pll_14nm *pll_14nm,
771 						const char *name,
772 						const char *parent_name,
773 						unsigned long flags,
774 						u8 shift)
775 {
776 	struct dsi_pll_14nm_postdiv *pll_postdiv;
777 	struct device *dev = &pll_14nm->phy->pdev->dev;
778 	struct clk_init_data postdiv_init = {
779 		.parent_names = (const char *[]) { parent_name },
780 		.num_parents = 1,
781 		.name = name,
782 		.flags = flags,
783 		.ops = &clk_ops_dsi_pll_14nm_postdiv,
784 	};
785 	int ret;
786 
787 	pll_postdiv = devm_kzalloc(dev, sizeof(*pll_postdiv), GFP_KERNEL);
788 	if (!pll_postdiv)
789 		return ERR_PTR(-ENOMEM);
790 
791 	pll_postdiv->pll = pll_14nm;
792 	pll_postdiv->shift = shift;
793 	/* both N1 and N2 postdividers are 4 bits wide */
794 	pll_postdiv->width = 4;
795 	/* range of each divider is from 1 to 15 */
796 	pll_postdiv->flags = CLK_DIVIDER_ONE_BASED;
797 	pll_postdiv->hw.init = &postdiv_init;
798 
799 	ret = devm_clk_hw_register(dev, &pll_postdiv->hw);
800 	if (ret)
801 		return ERR_PTR(ret);
802 
803 	return &pll_postdiv->hw;
804 }
805 
pll_14nm_register(struct dsi_pll_14nm * pll_14nm,struct clk_hw ** provided_clocks)806 static int pll_14nm_register(struct dsi_pll_14nm *pll_14nm, struct clk_hw **provided_clocks)
807 {
808 	char clk_name[32], parent[32], vco_name[32];
809 	struct clk_init_data vco_init = {
810 		.parent_data = &(const struct clk_parent_data) {
811 			.fw_name = "ref",
812 		},
813 		.num_parents = 1,
814 		.name = vco_name,
815 		.flags = CLK_IGNORE_UNUSED,
816 		.ops = &clk_ops_dsi_pll_14nm_vco,
817 	};
818 	struct device *dev = &pll_14nm->phy->pdev->dev;
819 	struct clk_hw *hw;
820 	int ret;
821 
822 	DBG("DSI%d", pll_14nm->phy->id);
823 
824 	snprintf(vco_name, 32, "dsi%dvco_clk", pll_14nm->phy->id);
825 	pll_14nm->clk_hw.init = &vco_init;
826 
827 	ret = devm_clk_hw_register(dev, &pll_14nm->clk_hw);
828 	if (ret)
829 		return ret;
830 
831 	snprintf(clk_name, 32, "dsi%dn1_postdiv_clk", pll_14nm->phy->id);
832 	snprintf(parent, 32, "dsi%dvco_clk", pll_14nm->phy->id);
833 
834 	/* N1 postdiv, bits 0-3 in REG_DSI_14nm_PHY_CMN_CLK_CFG0 */
835 	hw = pll_14nm_postdiv_register(pll_14nm, clk_name, parent,
836 				       CLK_SET_RATE_PARENT, 0);
837 	if (IS_ERR(hw))
838 		return PTR_ERR(hw);
839 
840 	snprintf(clk_name, 32, "dsi%dpllbyte", pll_14nm->phy->id);
841 	snprintf(parent, 32, "dsi%dn1_postdiv_clk", pll_14nm->phy->id);
842 
843 	/* DSI Byte clock = VCO_CLK / N1 / 8 */
844 	hw = devm_clk_hw_register_fixed_factor(dev, clk_name, parent,
845 					  CLK_SET_RATE_PARENT, 1, 8);
846 	if (IS_ERR(hw))
847 		return PTR_ERR(hw);
848 
849 	provided_clocks[DSI_BYTE_PLL_CLK] = hw;
850 
851 	snprintf(clk_name, 32, "dsi%dn1_postdivby2_clk", pll_14nm->phy->id);
852 	snprintf(parent, 32, "dsi%dn1_postdiv_clk", pll_14nm->phy->id);
853 
854 	/*
855 	 * Skip the mux for now, force DSICLK_SEL to 1, Add a /2 divider
856 	 * on the way. Don't let it set parent.
857 	 */
858 	hw = devm_clk_hw_register_fixed_factor(dev, clk_name, parent, 0, 1, 2);
859 	if (IS_ERR(hw))
860 		return PTR_ERR(hw);
861 
862 	snprintf(clk_name, 32, "dsi%dpll", pll_14nm->phy->id);
863 	snprintf(parent, 32, "dsi%dn1_postdivby2_clk", pll_14nm->phy->id);
864 
865 	/* DSI pixel clock = VCO_CLK / N1 / 2 / N2
866 	 * This is the output of N2 post-divider, bits 4-7 in
867 	 * REG_DSI_14nm_PHY_CMN_CLK_CFG0. Don't let it set parent.
868 	 */
869 	hw = pll_14nm_postdiv_register(pll_14nm, clk_name, parent, 0, 4);
870 	if (IS_ERR(hw))
871 		return PTR_ERR(hw);
872 
873 	provided_clocks[DSI_PIXEL_PLL_CLK]	= hw;
874 
875 	return 0;
876 }
877 
dsi_pll_14nm_init(struct msm_dsi_phy * phy)878 static int dsi_pll_14nm_init(struct msm_dsi_phy *phy)
879 {
880 	struct platform_device *pdev = phy->pdev;
881 	struct dsi_pll_14nm *pll_14nm;
882 	int ret;
883 
884 	if (!pdev)
885 		return -ENODEV;
886 
887 	pll_14nm = devm_kzalloc(&pdev->dev, sizeof(*pll_14nm), GFP_KERNEL);
888 	if (!pll_14nm)
889 		return -ENOMEM;
890 
891 	DBG("PLL%d", phy->id);
892 
893 	pll_14nm_list[phy->id] = pll_14nm;
894 
895 	spin_lock_init(&pll_14nm->postdiv_lock);
896 
897 	pll_14nm->phy = phy;
898 
899 	ret = pll_14nm_register(pll_14nm, phy->provided_clocks->hws);
900 	if (ret) {
901 		DRM_DEV_ERROR(&pdev->dev, "failed to register PLL: %d\n", ret);
902 		return ret;
903 	}
904 
905 	phy->vco_hw = &pll_14nm->clk_hw;
906 
907 	return 0;
908 }
909 
dsi_14nm_dphy_set_timing(struct msm_dsi_phy * phy,struct msm_dsi_dphy_timing * timing,int lane_idx)910 static void dsi_14nm_dphy_set_timing(struct msm_dsi_phy *phy,
911 				     struct msm_dsi_dphy_timing *timing,
912 				     int lane_idx)
913 {
914 	void __iomem *base = phy->lane_base;
915 	bool clk_ln = (lane_idx == PHY_14NM_CKLN_IDX);
916 	u32 zero = clk_ln ? timing->clk_zero : timing->hs_zero;
917 	u32 prepare = clk_ln ? timing->clk_prepare : timing->hs_prepare;
918 	u32 trail = clk_ln ? timing->clk_trail : timing->hs_trail;
919 	u32 rqst = clk_ln ? timing->hs_rqst_ckln : timing->hs_rqst;
920 	u32 prep_dly = clk_ln ? timing->hs_prep_dly_ckln : timing->hs_prep_dly;
921 	u32 halfbyte_en = clk_ln ? timing->hs_halfbyte_en_ckln :
922 				   timing->hs_halfbyte_en;
923 
924 	dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_4(lane_idx),
925 		      DSI_14nm_PHY_LN_TIMING_CTRL_4_HS_EXIT(timing->hs_exit));
926 	dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_5(lane_idx),
927 		      DSI_14nm_PHY_LN_TIMING_CTRL_5_HS_ZERO(zero));
928 	dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_6(lane_idx),
929 		      DSI_14nm_PHY_LN_TIMING_CTRL_6_HS_PREPARE(prepare));
930 	dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_7(lane_idx),
931 		      DSI_14nm_PHY_LN_TIMING_CTRL_7_HS_TRAIL(trail));
932 	dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_8(lane_idx),
933 		      DSI_14nm_PHY_LN_TIMING_CTRL_8_HS_RQST(rqst));
934 	dsi_phy_write(base + REG_DSI_14nm_PHY_LN_CFG0(lane_idx),
935 		      DSI_14nm_PHY_LN_CFG0_PREPARE_DLY(prep_dly));
936 	dsi_phy_write(base + REG_DSI_14nm_PHY_LN_CFG1(lane_idx),
937 		      halfbyte_en ? DSI_14nm_PHY_LN_CFG1_HALFBYTECLK_EN : 0);
938 	dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_9(lane_idx),
939 		      DSI_14nm_PHY_LN_TIMING_CTRL_9_TA_GO(timing->ta_go) |
940 		      DSI_14nm_PHY_LN_TIMING_CTRL_9_TA_SURE(timing->ta_sure));
941 	dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_10(lane_idx),
942 		      DSI_14nm_PHY_LN_TIMING_CTRL_10_TA_GET(timing->ta_get));
943 	dsi_phy_write(base + REG_DSI_14nm_PHY_LN_TIMING_CTRL_11(lane_idx),
944 		      DSI_14nm_PHY_LN_TIMING_CTRL_11_TRIG3_CMD(0xa0));
945 }
946 
dsi_14nm_phy_enable(struct msm_dsi_phy * phy,struct msm_dsi_phy_clk_request * clk_req)947 static int dsi_14nm_phy_enable(struct msm_dsi_phy *phy,
948 			       struct msm_dsi_phy_clk_request *clk_req)
949 {
950 	struct msm_dsi_dphy_timing *timing = &phy->timing;
951 	u32 data;
952 	int i;
953 	int ret;
954 	void __iomem *base = phy->base;
955 	void __iomem *lane_base = phy->lane_base;
956 	u32 glbl_test_ctrl;
957 
958 	if (msm_dsi_dphy_timing_calc_v2(timing, clk_req)) {
959 		DRM_DEV_ERROR(&phy->pdev->dev,
960 			"%s: D-PHY timing calculation failed\n", __func__);
961 		return -EINVAL;
962 	}
963 
964 	data = 0x1c;
965 	if (phy->usecase != MSM_DSI_PHY_STANDALONE)
966 		data |= DSI_14nm_PHY_CMN_LDO_CNTRL_VREG_CTRL(32);
967 	dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_LDO_CNTRL, data);
968 
969 	dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL, 0x1);
970 
971 	/* 4 data lanes + 1 clk lane configuration */
972 	for (i = 0; i < 5; i++) {
973 		dsi_phy_write(lane_base + REG_DSI_14nm_PHY_LN_VREG_CNTRL(i),
974 			      0x1d);
975 
976 		dsi_phy_write(lane_base +
977 			      REG_DSI_14nm_PHY_LN_STRENGTH_CTRL_0(i), 0xff);
978 		dsi_phy_write(lane_base +
979 			      REG_DSI_14nm_PHY_LN_STRENGTH_CTRL_1(i),
980 			      (i == PHY_14NM_CKLN_IDX) ? 0x00 : 0x06);
981 
982 		dsi_phy_write(lane_base + REG_DSI_14nm_PHY_LN_CFG3(i),
983 			      (i == PHY_14NM_CKLN_IDX) ? 0x8f : 0x0f);
984 		dsi_phy_write(lane_base + REG_DSI_14nm_PHY_LN_CFG2(i), 0x10);
985 		dsi_phy_write(lane_base + REG_DSI_14nm_PHY_LN_TEST_DATAPATH(i),
986 			      0);
987 		dsi_phy_write(lane_base + REG_DSI_14nm_PHY_LN_TEST_STR(i),
988 			      0x88);
989 
990 		dsi_14nm_dphy_set_timing(phy, timing, i);
991 	}
992 
993 	/* Make sure PLL is not start */
994 	dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_PLL_CNTRL, 0x00);
995 
996 	wmb(); /* make sure everything is written before reset and enable */
997 
998 	/* reset digital block */
999 	dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_CTRL_1, 0x80);
1000 	wmb(); /* ensure reset is asserted */
1001 	udelay(100);
1002 	dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_CTRL_1, 0x00);
1003 
1004 	glbl_test_ctrl = dsi_phy_read(base + REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL);
1005 	if (phy->id == DSI_1 && phy->usecase == MSM_DSI_PHY_SLAVE)
1006 		glbl_test_ctrl |= DSI_14nm_PHY_CMN_GLBL_TEST_CTRL_BITCLK_HS_SEL;
1007 	else
1008 		glbl_test_ctrl &= ~DSI_14nm_PHY_CMN_GLBL_TEST_CTRL_BITCLK_HS_SEL;
1009 	dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL, glbl_test_ctrl);
1010 	ret = dsi_14nm_set_usecase(phy);
1011 	if (ret) {
1012 		DRM_DEV_ERROR(&phy->pdev->dev, "%s: set pll usecase failed, %d\n",
1013 			__func__, ret);
1014 		return ret;
1015 	}
1016 
1017 	/* Remove power down from PLL and all lanes */
1018 	dsi_phy_write(base + REG_DSI_14nm_PHY_CMN_CTRL_0, 0xff);
1019 
1020 	return 0;
1021 }
1022 
dsi_14nm_phy_disable(struct msm_dsi_phy * phy)1023 static void dsi_14nm_phy_disable(struct msm_dsi_phy *phy)
1024 {
1025 	dsi_phy_write(phy->base + REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL, 0);
1026 	dsi_phy_write(phy->base + REG_DSI_14nm_PHY_CMN_CTRL_0, 0);
1027 
1028 	/* ensure that the phy is completely disabled */
1029 	wmb();
1030 }
1031 
1032 const struct msm_dsi_phy_cfg dsi_phy_14nm_cfgs = {
1033 	.has_phy_lane = true,
1034 	.reg_cfg = {
1035 		.num = 1,
1036 		.regs = {
1037 			{"vcca", 17000, 32},
1038 		},
1039 	},
1040 	.ops = {
1041 		.enable = dsi_14nm_phy_enable,
1042 		.disable = dsi_14nm_phy_disable,
1043 		.pll_init = dsi_pll_14nm_init,
1044 		.save_pll_state = dsi_14nm_pll_save_state,
1045 		.restore_pll_state = dsi_14nm_pll_restore_state,
1046 	},
1047 	.min_pll_rate = VCO_MIN_RATE,
1048 	.max_pll_rate = VCO_MAX_RATE,
1049 	.io_start = { 0x994400, 0x996400 },
1050 	.num_dsi_phy = 2,
1051 };
1052 
1053 const struct msm_dsi_phy_cfg dsi_phy_14nm_660_cfgs = {
1054 	.has_phy_lane = true,
1055 	.reg_cfg = {
1056 		.num = 1,
1057 		.regs = {
1058 			{"vcca", 73400, 32},
1059 		},
1060 	},
1061 	.ops = {
1062 		.enable = dsi_14nm_phy_enable,
1063 		.disable = dsi_14nm_phy_disable,
1064 		.pll_init = dsi_pll_14nm_init,
1065 		.save_pll_state = dsi_14nm_pll_save_state,
1066 		.restore_pll_state = dsi_14nm_pll_restore_state,
1067 	},
1068 	.min_pll_rate = VCO_MIN_RATE,
1069 	.max_pll_rate = VCO_MAX_RATE,
1070 	.io_start = { 0xc994400, 0xc996400 },
1071 	.num_dsi_phy = 2,
1072 };
1073