2 * SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2018, The Linux Foundation
7 #include <linux/clk-provider.h>
8 #include <linux/iopoll.h>
14 * DSI PLL 10nm - clock diagram (eg: DSI0):
16 * dsi0_pll_out_div_clk dsi0_pll_bit_clk
19 * +---------+ | +----------+ | +----+
20 * dsi0vco_clk ---| out_div |--o--| divl_3_0 |--o--| /8 |-- dsi0pllbyte
21 * +---------+ | +----------+ | +----+
23 * | | dsi0_pll_by_2_bit_clk
25 * | | +----+ | |\ dsi0_pclk_mux
26 * | |--| /2 |--o--| \ |
27 * | | +----+ | \ | +---------+
28 * | --------------| |--o--| div_7_4 |-- dsi0pll
29 * |------------------------------| / +---------+
31 * -----------| /4? |--o----------|/
35 * dsi0_pll_post_out_div_clk
38 #define DSI_BYTE_PLL_CLK 0
39 #define DSI_PIXEL_PLL_CLK 1
40 #define NUM_PROVIDED_CLKS 2
43 u32 pll_prop_gain_rate
;
45 u32 decimal_div_start
;
46 u32 frac_div_start_low
;
47 u32 frac_div_start_mid
;
48 u32 frac_div_start_high
;
49 u32 pll_clock_inverters
;
51 u32 ssc_stepsize_high
;
59 struct dsi_pll_config
{
64 bool disable_prescaler
;
77 struct pll_10nm_cached_state
{
78 unsigned long vco_rate
;
86 struct msm_dsi_pll base
;
89 struct platform_device
*pdev
;
91 void __iomem
*phy_cmn_mmio
;
97 /* protects REG_DSI_10nm_PHY_CMN_CLK_CFG0 register */
98 spinlock_t postdiv_lock
;
101 struct dsi_pll_config pll_configuration
;
102 struct dsi_pll_regs reg_setup
;
104 /* private clocks: */
105 struct clk_hw
*hws
[NUM_DSI_CLOCKS_MAX
];
108 /* clock-provider: */
109 struct clk_hw_onecell_data
*hw_data
;
111 struct pll_10nm_cached_state cached_state
;
113 enum msm_dsi_phy_usecase uc
;
114 struct dsi_pll_10nm
*slave
;
117 #define to_pll_10nm(x) container_of(x, struct dsi_pll_10nm, base)
120 * Global list of private DSI PLL struct pointers. We need this for Dual DSI
121 * mode, where the master PLL's clk_ops needs access the slave's private data
123 static struct dsi_pll_10nm
*pll_10nm_list
[DSI_MAX
];
125 static void dsi_pll_setup_config(struct dsi_pll_10nm
*pll
)
127 struct dsi_pll_config
*config
= &pll
->pll_configuration
;
129 config
->ref_freq
= pll
->vco_ref_clk_rate
;
130 config
->output_div
= 1;
131 config
->dec_bits
= 8;
132 config
->frac_bits
= 18;
133 config
->lock_timer
= 64;
134 config
->ssc_freq
= 31500;
135 config
->ssc_offset
= 5000;
136 config
->ssc_adj_per
= 2;
137 config
->thresh_cycles
= 32;
138 config
->refclk_cycles
= 256;
140 config
->div_override
= false;
141 config
->ignore_frac
= false;
142 config
->disable_prescaler
= false;
144 config
->enable_ssc
= false;
145 config
->ssc_center
= 0;
148 static void dsi_pll_calc_dec_frac(struct dsi_pll_10nm
*pll
)
150 struct dsi_pll_config
*config
= &pll
->pll_configuration
;
151 struct dsi_pll_regs
*regs
= &pll
->reg_setup
;
152 u64 fref
= pll
->vco_ref_clk_rate
;
155 u64 dec
, dec_multiple
;
159 pll_freq
= pll
->vco_current_rate
;
161 if (config
->disable_prescaler
)
166 multiplier
= 1 << config
->frac_bits
;
167 dec_multiple
= div_u64(pll_freq
* multiplier
, divider
);
168 div_u64_rem(dec_multiple
, multiplier
, &frac
);
170 dec
= div_u64(dec_multiple
, multiplier
);
172 if (pll_freq
<= 1900000000UL)
173 regs
->pll_prop_gain_rate
= 8;
174 else if (pll_freq
<= 3000000000UL)
175 regs
->pll_prop_gain_rate
= 10;
177 regs
->pll_prop_gain_rate
= 12;
178 if (pll_freq
< 1100000000UL)
179 regs
->pll_clock_inverters
= 8;
181 regs
->pll_clock_inverters
= 0;
183 regs
->pll_lockdet_rate
= config
->lock_timer
;
184 regs
->decimal_div_start
= dec
;
185 regs
->frac_div_start_low
= (frac
& 0xff);
186 regs
->frac_div_start_mid
= (frac
& 0xff00) >> 8;
187 regs
->frac_div_start_high
= (frac
& 0x30000) >> 16;
190 #define SSC_CENTER BIT(0)
191 #define SSC_EN BIT(1)
193 static void dsi_pll_calc_ssc(struct dsi_pll_10nm
*pll
)
195 struct dsi_pll_config
*config
= &pll
->pll_configuration
;
196 struct dsi_pll_regs
*regs
= &pll
->reg_setup
;
202 if (!config
->enable_ssc
) {
203 DBG("SSC not enabled\n");
207 ssc_per
= DIV_ROUND_CLOSEST(config
->ref_freq
, config
->ssc_freq
) / 2 - 1;
208 ssc_mod
= (ssc_per
+ 1) % (config
->ssc_adj_per
+ 1);
211 frac
= regs
->frac_div_start_low
|
212 (regs
->frac_div_start_mid
<< 8) |
213 (regs
->frac_div_start_high
<< 16);
214 ssc_step_size
= regs
->decimal_div_start
;
215 ssc_step_size
*= (1 << config
->frac_bits
);
216 ssc_step_size
+= frac
;
217 ssc_step_size
*= config
->ssc_offset
;
218 ssc_step_size
*= (config
->ssc_adj_per
+ 1);
219 ssc_step_size
= div_u64(ssc_step_size
, (ssc_per
+ 1));
220 ssc_step_size
= DIV_ROUND_CLOSEST_ULL(ssc_step_size
, 1000000);
222 regs
->ssc_div_per_low
= ssc_per
& 0xFF;
223 regs
->ssc_div_per_high
= (ssc_per
& 0xFF00) >> 8;
224 regs
->ssc_stepsize_low
= (u32
)(ssc_step_size
& 0xFF);
225 regs
->ssc_stepsize_high
= (u32
)((ssc_step_size
& 0xFF00) >> 8);
226 regs
->ssc_adjper_low
= config
->ssc_adj_per
& 0xFF;
227 regs
->ssc_adjper_high
= (config
->ssc_adj_per
& 0xFF00) >> 8;
229 regs
->ssc_control
= config
->ssc_center
? SSC_CENTER
: 0;
231 pr_debug("SCC: Dec:%d, frac:%llu, frac_bits:%d\n",
232 regs
->decimal_div_start
, frac
, config
->frac_bits
);
233 pr_debug("SSC: div_per:0x%X, stepsize:0x%X, adjper:0x%X\n",
234 ssc_per
, (u32
)ssc_step_size
, config
->ssc_adj_per
);
237 static void dsi_pll_ssc_commit(struct dsi_pll_10nm
*pll
)
239 void __iomem
*base
= pll
->mmio
;
240 struct dsi_pll_regs
*regs
= &pll
->reg_setup
;
242 if (pll
->pll_configuration
.enable_ssc
) {
243 pr_debug("SSC is enabled\n");
245 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_STEPSIZE_LOW_1
,
246 regs
->ssc_stepsize_low
);
247 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_STEPSIZE_HIGH_1
,
248 regs
->ssc_stepsize_high
);
249 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_DIV_PER_LOW_1
,
250 regs
->ssc_div_per_low
);
251 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_DIV_PER_HIGH_1
,
252 regs
->ssc_div_per_high
);
253 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_DIV_ADJPER_LOW_1
,
254 regs
->ssc_adjper_low
);
255 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_DIV_ADJPER_HIGH_1
,
256 regs
->ssc_adjper_high
);
257 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_CONTROL
,
258 SSC_EN
| regs
->ssc_control
);
262 static void dsi_pll_config_hzindep_reg(struct dsi_pll_10nm
*pll
)
264 void __iomem
*base
= pll
->mmio
;
266 pll_write(base
+ REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_ONE
, 0x80);
267 pll_write(base
+ REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_TWO
, 0x03);
268 pll_write(base
+ REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_THREE
, 0x00);
269 pll_write(base
+ REG_DSI_10nm_PHY_PLL_DSM_DIVIDER
, 0x00);
270 pll_write(base
+ REG_DSI_10nm_PHY_PLL_FEEDBACK_DIVIDER
, 0x4e);
271 pll_write(base
+ REG_DSI_10nm_PHY_PLL_CALIBRATION_SETTINGS
, 0x40);
272 pll_write(base
+ REG_DSI_10nm_PHY_PLL_BAND_SEL_CAL_SETTINGS_THREE
,
274 pll_write(base
+ REG_DSI_10nm_PHY_PLL_FREQ_DETECT_SETTINGS_ONE
, 0x0c);
275 pll_write(base
+ REG_DSI_10nm_PHY_PLL_OUTDIV
, 0x00);
276 pll_write(base
+ REG_DSI_10nm_PHY_PLL_CORE_OVERRIDE
, 0x00);
277 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_DIGITAL_TIMERS_TWO
, 0x08);
278 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_PROP_GAIN_RATE_1
, 0x08);
279 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_BAND_SET_RATE_1
, 0xc0);
280 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_INT_GAIN_IFILT_BAND_1
, 0xfa);
281 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_FL_INT_GAIN_PFILT_BAND_1
,
283 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_LOCK_OVERRIDE
, 0x80);
284 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PFILT
, 0x29);
285 pll_write(base
+ REG_DSI_10nm_PHY_PLL_IFILT
, 0x3f);
288 static void dsi_pll_commit(struct dsi_pll_10nm
*pll
)
290 void __iomem
*base
= pll
->mmio
;
291 struct dsi_pll_regs
*reg
= &pll
->reg_setup
;
293 pll_write(base
+ REG_DSI_10nm_PHY_PLL_CORE_INPUT_OVERRIDE
, 0x12);
294 pll_write(base
+ REG_DSI_10nm_PHY_PLL_DECIMAL_DIV_START_1
,
295 reg
->decimal_div_start
);
296 pll_write(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_LOW_1
,
297 reg
->frac_div_start_low
);
298 pll_write(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_MID_1
,
299 reg
->frac_div_start_mid
);
300 pll_write(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_HIGH_1
,
301 reg
->frac_div_start_high
);
302 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_LOCKDET_RATE_1
, 0x40);
303 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_LOCK_DELAY
, 0x06);
304 pll_write(base
+ REG_DSI_10nm_PHY_PLL_CMODE
, 0x10);
305 pll_write(base
+ REG_DSI_10nm_PHY_PLL_CLOCK_INVERTERS
,
306 reg
->pll_clock_inverters
);
309 static int dsi_pll_10nm_vco_set_rate(struct clk_hw
*hw
, unsigned long rate
,
310 unsigned long parent_rate
)
312 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
313 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
315 DBG("DSI PLL%d rate=%lu, parent's=%lu", pll_10nm
->id
, rate
,
318 pll_10nm
->vco_current_rate
= rate
;
319 pll_10nm
->vco_ref_clk_rate
= parent_rate
;
321 dsi_pll_setup_config(pll_10nm
);
323 dsi_pll_calc_dec_frac(pll_10nm
);
325 dsi_pll_calc_ssc(pll_10nm
);
327 dsi_pll_commit(pll_10nm
);
329 dsi_pll_config_hzindep_reg(pll_10nm
);
331 dsi_pll_ssc_commit(pll_10nm
);
333 /* flush, ensure all register writes are done*/
339 static int dsi_pll_10nm_lock_status(struct dsi_pll_10nm
*pll
)
343 u32
const delay_us
= 100;
344 u32
const timeout_us
= 5000;
346 rc
= readl_poll_timeout_atomic(pll
->mmio
+
347 REG_DSI_10nm_PHY_PLL_COMMON_STATUS_ONE
,
349 ((status
& BIT(0)) > 0),
353 pr_err("DSI PLL(%d) lock failed, status=0x%08x\n",
359 static void dsi_pll_disable_pll_bias(struct dsi_pll_10nm
*pll
)
361 u32 data
= pll_read(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CTRL_0
);
363 pll_write(pll
->mmio
+ REG_DSI_10nm_PHY_PLL_SYSTEM_MUXES
, 0);
364 pll_write(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CTRL_0
,
369 static void dsi_pll_enable_pll_bias(struct dsi_pll_10nm
*pll
)
371 u32 data
= pll_read(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CTRL_0
);
373 pll_write(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CTRL_0
,
375 pll_write(pll
->mmio
+ REG_DSI_10nm_PHY_PLL_SYSTEM_MUXES
, 0xc0);
379 static void dsi_pll_disable_global_clk(struct dsi_pll_10nm
*pll
)
383 data
= pll_read(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
);
384 pll_write(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
,
388 static void dsi_pll_enable_global_clk(struct dsi_pll_10nm
*pll
)
392 data
= pll_read(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
);
393 pll_write(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
,
397 static int dsi_pll_10nm_vco_prepare(struct clk_hw
*hw
)
399 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
400 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
403 dsi_pll_enable_pll_bias(pll_10nm
);
405 dsi_pll_enable_pll_bias(pll_10nm
->slave
);
408 pll_write(pll_10nm
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_PLL_CNTRL
,
412 * ensure all PLL configurations are written prior to checking
417 /* Check for PLL lock */
418 rc
= dsi_pll_10nm_lock_status(pll_10nm
);
420 pr_err("PLL(%d) lock failed\n", pll_10nm
->id
);
426 dsi_pll_enable_global_clk(pll_10nm
);
428 dsi_pll_enable_global_clk(pll_10nm
->slave
);
430 pll_write(pll_10nm
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_RBUF_CTRL
,
433 pll_write(pll_10nm
->slave
->phy_cmn_mmio
+
434 REG_DSI_10nm_PHY_CMN_RBUF_CTRL
, 0x01);
440 static void dsi_pll_disable_sub(struct dsi_pll_10nm
*pll
)
442 pll_write(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_RBUF_CTRL
, 0);
443 dsi_pll_disable_pll_bias(pll
);
446 static void dsi_pll_10nm_vco_unprepare(struct clk_hw
*hw
)
448 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
449 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
452 * To avoid any stray glitches while abruptly powering down the PLL
453 * make sure to gate the clock using the clock enable bit before
454 * powering down the PLL
456 dsi_pll_disable_global_clk(pll_10nm
);
457 pll_write(pll_10nm
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_PLL_CNTRL
, 0);
458 dsi_pll_disable_sub(pll_10nm
);
459 if (pll_10nm
->slave
) {
460 dsi_pll_disable_global_clk(pll_10nm
->slave
);
461 dsi_pll_disable_sub(pll_10nm
->slave
);
463 /* flush, ensure all register writes are done */
468 static unsigned long dsi_pll_10nm_vco_recalc_rate(struct clk_hw
*hw
,
469 unsigned long parent_rate
)
471 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
472 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
473 void __iomem
*base
= pll_10nm
->mmio
;
474 u64 ref_clk
= pll_10nm
->vco_ref_clk_rate
;
481 dec
= pll_read(base
+ REG_DSI_10nm_PHY_PLL_DECIMAL_DIV_START_1
);
484 frac
= pll_read(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_LOW_1
);
485 frac
|= ((pll_read(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_MID_1
) &
487 frac
|= ((pll_read(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_HIGH_1
) &
492 * 1. Assumes prescaler is disabled
493 * 2. Multiplier is 2^18. it should be 2^(num_of_frac_bits)
495 multiplier
= 1 << 18;
496 pll_freq
= dec
* (ref_clk
* 2);
497 tmp64
= (ref_clk
* 2 * frac
);
498 pll_freq
+= div_u64(tmp64
, multiplier
);
502 DBG("DSI PLL%d returning vco rate = %lu, dec = %x, frac = %x",
503 pll_10nm
->id
, (unsigned long)vco_rate
, dec
, frac
);
505 return (unsigned long)vco_rate
;
508 static const struct clk_ops clk_ops_dsi_pll_10nm_vco
= {
509 .round_rate
= msm_dsi_pll_helper_clk_round_rate
,
510 .set_rate
= dsi_pll_10nm_vco_set_rate
,
511 .recalc_rate
= dsi_pll_10nm_vco_recalc_rate
,
512 .prepare
= dsi_pll_10nm_vco_prepare
,
513 .unprepare
= dsi_pll_10nm_vco_unprepare
,
520 static void dsi_pll_10nm_save_state(struct msm_dsi_pll
*pll
)
522 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
523 struct pll_10nm_cached_state
*cached
= &pll_10nm
->cached_state
;
524 void __iomem
*phy_base
= pll_10nm
->phy_cmn_mmio
;
525 u32 cmn_clk_cfg0
, cmn_clk_cfg1
;
527 cached
->pll_out_div
= pll_read(pll_10nm
->mmio
+
528 REG_DSI_10nm_PHY_PLL_PLL_OUTDIV_RATE
);
529 cached
->pll_out_div
&= 0x3;
531 cmn_clk_cfg0
= pll_read(phy_base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG0
);
532 cached
->bit_clk_div
= cmn_clk_cfg0
& 0xf;
533 cached
->pix_clk_div
= (cmn_clk_cfg0
& 0xf0) >> 4;
535 cmn_clk_cfg1
= pll_read(phy_base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
);
536 cached
->pll_mux
= cmn_clk_cfg1
& 0x3;
538 DBG("DSI PLL%d outdiv %x bit_clk_div %x pix_clk_div %x pll_mux %x",
539 pll_10nm
->id
, cached
->pll_out_div
, cached
->bit_clk_div
,
540 cached
->pix_clk_div
, cached
->pll_mux
);
543 static int dsi_pll_10nm_restore_state(struct msm_dsi_pll
*pll
)
545 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
546 struct pll_10nm_cached_state
*cached
= &pll_10nm
->cached_state
;
547 void __iomem
*phy_base
= pll_10nm
->phy_cmn_mmio
;
550 val
= pll_read(pll_10nm
->mmio
+ REG_DSI_10nm_PHY_PLL_PLL_OUTDIV_RATE
);
552 val
|= cached
->pll_out_div
;
553 pll_write(pll_10nm
->mmio
+ REG_DSI_10nm_PHY_PLL_PLL_OUTDIV_RATE
, val
);
555 pll_write(phy_base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG0
,
556 cached
->bit_clk_div
| (cached
->pix_clk_div
<< 4));
558 val
= pll_read(phy_base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
);
560 val
|= cached
->pll_mux
;
561 pll_write(phy_base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
, val
);
563 DBG("DSI PLL%d", pll_10nm
->id
);
568 static int dsi_pll_10nm_set_usecase(struct msm_dsi_pll
*pll
,
569 enum msm_dsi_phy_usecase uc
)
571 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
572 void __iomem
*base
= pll_10nm
->phy_cmn_mmio
;
573 u32 data
= 0x0; /* internal PLL */
575 DBG("DSI PLL%d", pll_10nm
->id
);
578 case MSM_DSI_PHY_STANDALONE
:
580 case MSM_DSI_PHY_MASTER
:
581 pll_10nm
->slave
= pll_10nm_list
[(pll_10nm
->id
+ 1) % DSI_MAX
];
583 case MSM_DSI_PHY_SLAVE
:
584 data
= 0x1; /* external PLL */
591 pll_write(base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
, (data
<< 2));
598 static int dsi_pll_10nm_get_provider(struct msm_dsi_pll
*pll
,
599 struct clk
**byte_clk_provider
,
600 struct clk
**pixel_clk_provider
)
602 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
603 struct clk_hw_onecell_data
*hw_data
= pll_10nm
->hw_data
;
605 DBG("DSI PLL%d", pll_10nm
->id
);
607 if (byte_clk_provider
)
608 *byte_clk_provider
= hw_data
->hws
[DSI_BYTE_PLL_CLK
]->clk
;
609 if (pixel_clk_provider
)
610 *pixel_clk_provider
= hw_data
->hws
[DSI_PIXEL_PLL_CLK
]->clk
;
615 static void dsi_pll_10nm_destroy(struct msm_dsi_pll
*pll
)
617 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
619 DBG("DSI PLL%d", pll_10nm
->id
);
623 * The post dividers and mux clocks are created using the standard divider and
624 * mux API. Unlike the 14nm PHY, the slave PLL doesn't need its dividers/mux
625 * state to follow the master PLL's divider/mux state. Therefore, we don't
626 * require special clock ops that also configure the slave PLL registers
628 static int pll_10nm_register(struct dsi_pll_10nm
*pll_10nm
)
630 char clk_name
[32], parent
[32], vco_name
[32];
631 char parent2
[32], parent3
[32], parent4
[32];
632 struct clk_init_data vco_init
= {
633 .parent_names
= (const char *[]){ "xo" },
636 .flags
= CLK_IGNORE_UNUSED
,
637 .ops
= &clk_ops_dsi_pll_10nm_vco
,
639 struct device
*dev
= &pll_10nm
->pdev
->dev
;
640 struct clk_hw
**hws
= pll_10nm
->hws
;
641 struct clk_hw_onecell_data
*hw_data
;
646 DBG("DSI%d", pll_10nm
->id
);
648 hw_data
= devm_kzalloc(dev
, sizeof(*hw_data
) +
649 NUM_PROVIDED_CLKS
* sizeof(struct clk_hw
*),
654 snprintf(vco_name
, 32, "dsi%dvco_clk", pll_10nm
->id
);
655 pll_10nm
->base
.clk_hw
.init
= &vco_init
;
657 ret
= clk_hw_register(dev
, &pll_10nm
->base
.clk_hw
);
661 hws
[num
++] = &pll_10nm
->base
.clk_hw
;
663 snprintf(clk_name
, 32, "dsi%d_pll_out_div_clk", pll_10nm
->id
);
664 snprintf(parent
, 32, "dsi%dvco_clk", pll_10nm
->id
);
666 hw
= clk_hw_register_divider(dev
, clk_name
,
667 parent
, CLK_SET_RATE_PARENT
,
669 REG_DSI_10nm_PHY_PLL_PLL_OUTDIV_RATE
,
670 0, 2, CLK_DIVIDER_POWER_OF_TWO
, NULL
);
676 snprintf(clk_name
, 32, "dsi%d_pll_bit_clk", pll_10nm
->id
);
677 snprintf(parent
, 32, "dsi%d_pll_out_div_clk", pll_10nm
->id
);
679 /* BIT CLK: DIV_CTRL_3_0 */
680 hw
= clk_hw_register_divider(dev
, clk_name
, parent
,
682 pll_10nm
->phy_cmn_mmio
+
683 REG_DSI_10nm_PHY_CMN_CLK_CFG0
,
684 0, 4, CLK_DIVIDER_ONE_BASED
,
685 &pll_10nm
->postdiv_lock
);
691 snprintf(clk_name
, 32, "dsi%dpllbyte", pll_10nm
->id
);
692 snprintf(parent
, 32, "dsi%d_pll_bit_clk", pll_10nm
->id
);
694 /* DSI Byte clock = VCO_CLK / OUT_DIV / BIT_DIV / 8 */
695 hw
= clk_hw_register_fixed_factor(dev
, clk_name
, parent
,
696 CLK_SET_RATE_PARENT
, 1, 8);
701 hw_data
->hws
[DSI_BYTE_PLL_CLK
] = hw
;
703 snprintf(clk_name
, 32, "dsi%d_pll_by_2_bit_clk", pll_10nm
->id
);
704 snprintf(parent
, 32, "dsi%d_pll_bit_clk", pll_10nm
->id
);
706 hw
= clk_hw_register_fixed_factor(dev
, clk_name
, parent
,
713 snprintf(clk_name
, 32, "dsi%d_pll_post_out_div_clk", pll_10nm
->id
);
714 snprintf(parent
, 32, "dsi%d_pll_out_div_clk", pll_10nm
->id
);
716 hw
= clk_hw_register_fixed_factor(dev
, clk_name
, parent
,
723 snprintf(clk_name
, 32, "dsi%d_pclk_mux", pll_10nm
->id
);
724 snprintf(parent
, 32, "dsi%d_pll_bit_clk", pll_10nm
->id
);
725 snprintf(parent2
, 32, "dsi%d_pll_by_2_bit_clk", pll_10nm
->id
);
726 snprintf(parent3
, 32, "dsi%d_pll_out_div_clk", pll_10nm
->id
);
727 snprintf(parent4
, 32, "dsi%d_pll_post_out_div_clk", pll_10nm
->id
);
729 hw
= clk_hw_register_mux(dev
, clk_name
,
731 parent
, parent2
, parent3
, parent4
732 }, 4, 0, pll_10nm
->phy_cmn_mmio
+
733 REG_DSI_10nm_PHY_CMN_CLK_CFG1
,
740 snprintf(clk_name
, 32, "dsi%dpll", pll_10nm
->id
);
741 snprintf(parent
, 32, "dsi%d_pclk_mux", pll_10nm
->id
);
743 /* PIX CLK DIV : DIV_CTRL_7_4*/
744 hw
= clk_hw_register_divider(dev
, clk_name
, parent
,
745 0, pll_10nm
->phy_cmn_mmio
+
746 REG_DSI_10nm_PHY_CMN_CLK_CFG0
,
747 4, 4, CLK_DIVIDER_ONE_BASED
,
748 &pll_10nm
->postdiv_lock
);
753 hw_data
->hws
[DSI_PIXEL_PLL_CLK
] = hw
;
755 pll_10nm
->num_hws
= num
;
757 hw_data
->num
= NUM_PROVIDED_CLKS
;
758 pll_10nm
->hw_data
= hw_data
;
760 ret
= of_clk_add_hw_provider(dev
->of_node
, of_clk_hw_onecell_get
,
763 dev_err(dev
, "failed to register clk provider: %d\n", ret
);
770 struct msm_dsi_pll
*msm_dsi_pll_10nm_init(struct platform_device
*pdev
, int id
)
772 struct dsi_pll_10nm
*pll_10nm
;
773 struct msm_dsi_pll
*pll
;
777 return ERR_PTR(-ENODEV
);
779 pll_10nm
= devm_kzalloc(&pdev
->dev
, sizeof(*pll_10nm
), GFP_KERNEL
);
781 return ERR_PTR(-ENOMEM
);
783 DBG("DSI PLL%d", id
);
785 pll_10nm
->pdev
= pdev
;
787 pll_10nm_list
[id
] = pll_10nm
;
789 pll_10nm
->phy_cmn_mmio
= msm_ioremap(pdev
, "dsi_phy", "DSI_PHY");
790 if (IS_ERR_OR_NULL(pll_10nm
->phy_cmn_mmio
)) {
791 dev_err(&pdev
->dev
, "failed to map CMN PHY base\n");
792 return ERR_PTR(-ENOMEM
);
795 pll_10nm
->mmio
= msm_ioremap(pdev
, "dsi_pll", "DSI_PLL");
796 if (IS_ERR_OR_NULL(pll_10nm
->mmio
)) {
797 dev_err(&pdev
->dev
, "failed to map PLL base\n");
798 return ERR_PTR(-ENOMEM
);
801 spin_lock_init(&pll_10nm
->postdiv_lock
);
803 pll
= &pll_10nm
->base
;
804 pll
->min_rate
= 1000000000UL;
805 pll
->max_rate
= 3500000000UL;
806 pll
->get_provider
= dsi_pll_10nm_get_provider
;
807 pll
->destroy
= dsi_pll_10nm_destroy
;
808 pll
->save_state
= dsi_pll_10nm_save_state
;
809 pll
->restore_state
= dsi_pll_10nm_restore_state
;
810 pll
->set_usecase
= dsi_pll_10nm_set_usecase
;
812 pll_10nm
->vco_delay
= 1;
814 ret
= pll_10nm_register(pll_10nm
);
816 dev_err(&pdev
->dev
, "failed to register PLL: %d\n", ret
);
820 /* TODO: Remove this when we have proper display handover support */
821 msm_dsi_pll_save_state(pll
);