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 |-- dsi0_phy_pll_out_byteclk
21 * +---------+ | +----------+ | +----+
23 * | | dsi0_pll_by_2_bit_clk
25 * | | +----+ | |\ dsi0_pclk_mux
26 * | |--| /2 |--o--| \ |
27 * | | +----+ | \ | +---------+
28 * | --------------| |--o--| div_7_4 |-- dsi0_phy_pll_out_dsiclk
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
42 #define VCO_REF_CLK_RATE 19200000
45 u32 pll_prop_gain_rate
;
47 u32 decimal_div_start
;
48 u32 frac_div_start_low
;
49 u32 frac_div_start_mid
;
50 u32 frac_div_start_high
;
51 u32 pll_clock_inverters
;
53 u32 ssc_stepsize_high
;
61 struct dsi_pll_config
{
66 bool disable_prescaler
;
79 struct pll_10nm_cached_state
{
80 unsigned long vco_rate
;
88 struct msm_dsi_pll base
;
91 struct platform_device
*pdev
;
93 void __iomem
*phy_cmn_mmio
;
99 /* protects REG_DSI_10nm_PHY_CMN_CLK_CFG0 register */
100 spinlock_t postdiv_lock
;
103 struct dsi_pll_config pll_configuration
;
104 struct dsi_pll_regs reg_setup
;
106 /* private clocks: */
107 struct clk_hw
*out_div_clk_hw
;
108 struct clk_hw
*bit_clk_hw
;
109 struct clk_hw
*byte_clk_hw
;
110 struct clk_hw
*by_2_bit_clk_hw
;
111 struct clk_hw
*post_out_div_clk_hw
;
112 struct clk_hw
*pclk_mux_hw
;
113 struct clk_hw
*out_dsiclk_hw
;
115 /* clock-provider: */
116 struct clk_hw_onecell_data
*hw_data
;
118 struct pll_10nm_cached_state cached_state
;
120 enum msm_dsi_phy_usecase uc
;
121 struct dsi_pll_10nm
*slave
;
124 #define to_pll_10nm(x) container_of(x, struct dsi_pll_10nm, base)
127 * Global list of private DSI PLL struct pointers. We need this for Dual DSI
128 * mode, where the master PLL's clk_ops needs access the slave's private data
130 static struct dsi_pll_10nm
*pll_10nm_list
[DSI_MAX
];
132 static void dsi_pll_setup_config(struct dsi_pll_10nm
*pll
)
134 struct dsi_pll_config
*config
= &pll
->pll_configuration
;
136 config
->ref_freq
= pll
->vco_ref_clk_rate
;
137 config
->output_div
= 1;
138 config
->dec_bits
= 8;
139 config
->frac_bits
= 18;
140 config
->lock_timer
= 64;
141 config
->ssc_freq
= 31500;
142 config
->ssc_offset
= 5000;
143 config
->ssc_adj_per
= 2;
144 config
->thresh_cycles
= 32;
145 config
->refclk_cycles
= 256;
147 config
->div_override
= false;
148 config
->ignore_frac
= false;
149 config
->disable_prescaler
= false;
151 config
->enable_ssc
= false;
152 config
->ssc_center
= 0;
155 static void dsi_pll_calc_dec_frac(struct dsi_pll_10nm
*pll
)
157 struct dsi_pll_config
*config
= &pll
->pll_configuration
;
158 struct dsi_pll_regs
*regs
= &pll
->reg_setup
;
159 u64 fref
= pll
->vco_ref_clk_rate
;
162 u64 dec
, dec_multiple
;
166 pll_freq
= pll
->vco_current_rate
;
168 if (config
->disable_prescaler
)
173 multiplier
= 1 << config
->frac_bits
;
174 dec_multiple
= div_u64(pll_freq
* multiplier
, divider
);
175 div_u64_rem(dec_multiple
, multiplier
, &frac
);
177 dec
= div_u64(dec_multiple
, multiplier
);
179 if (pll_freq
<= 1900000000UL)
180 regs
->pll_prop_gain_rate
= 8;
181 else if (pll_freq
<= 3000000000UL)
182 regs
->pll_prop_gain_rate
= 10;
184 regs
->pll_prop_gain_rate
= 12;
185 if (pll_freq
< 1100000000UL)
186 regs
->pll_clock_inverters
= 8;
188 regs
->pll_clock_inverters
= 0;
190 regs
->pll_lockdet_rate
= config
->lock_timer
;
191 regs
->decimal_div_start
= dec
;
192 regs
->frac_div_start_low
= (frac
& 0xff);
193 regs
->frac_div_start_mid
= (frac
& 0xff00) >> 8;
194 regs
->frac_div_start_high
= (frac
& 0x30000) >> 16;
197 #define SSC_CENTER BIT(0)
198 #define SSC_EN BIT(1)
200 static void dsi_pll_calc_ssc(struct dsi_pll_10nm
*pll
)
202 struct dsi_pll_config
*config
= &pll
->pll_configuration
;
203 struct dsi_pll_regs
*regs
= &pll
->reg_setup
;
209 if (!config
->enable_ssc
) {
210 DBG("SSC not enabled\n");
214 ssc_per
= DIV_ROUND_CLOSEST(config
->ref_freq
, config
->ssc_freq
) / 2 - 1;
215 ssc_mod
= (ssc_per
+ 1) % (config
->ssc_adj_per
+ 1);
218 frac
= regs
->frac_div_start_low
|
219 (regs
->frac_div_start_mid
<< 8) |
220 (regs
->frac_div_start_high
<< 16);
221 ssc_step_size
= regs
->decimal_div_start
;
222 ssc_step_size
*= (1 << config
->frac_bits
);
223 ssc_step_size
+= frac
;
224 ssc_step_size
*= config
->ssc_offset
;
225 ssc_step_size
*= (config
->ssc_adj_per
+ 1);
226 ssc_step_size
= div_u64(ssc_step_size
, (ssc_per
+ 1));
227 ssc_step_size
= DIV_ROUND_CLOSEST_ULL(ssc_step_size
, 1000000);
229 regs
->ssc_div_per_low
= ssc_per
& 0xFF;
230 regs
->ssc_div_per_high
= (ssc_per
& 0xFF00) >> 8;
231 regs
->ssc_stepsize_low
= (u32
)(ssc_step_size
& 0xFF);
232 regs
->ssc_stepsize_high
= (u32
)((ssc_step_size
& 0xFF00) >> 8);
233 regs
->ssc_adjper_low
= config
->ssc_adj_per
& 0xFF;
234 regs
->ssc_adjper_high
= (config
->ssc_adj_per
& 0xFF00) >> 8;
236 regs
->ssc_control
= config
->ssc_center
? SSC_CENTER
: 0;
238 pr_debug("SCC: Dec:%d, frac:%llu, frac_bits:%d\n",
239 regs
->decimal_div_start
, frac
, config
->frac_bits
);
240 pr_debug("SSC: div_per:0x%X, stepsize:0x%X, adjper:0x%X\n",
241 ssc_per
, (u32
)ssc_step_size
, config
->ssc_adj_per
);
244 static void dsi_pll_ssc_commit(struct dsi_pll_10nm
*pll
)
246 void __iomem
*base
= pll
->mmio
;
247 struct dsi_pll_regs
*regs
= &pll
->reg_setup
;
249 if (pll
->pll_configuration
.enable_ssc
) {
250 pr_debug("SSC is enabled\n");
252 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_STEPSIZE_LOW_1
,
253 regs
->ssc_stepsize_low
);
254 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_STEPSIZE_HIGH_1
,
255 regs
->ssc_stepsize_high
);
256 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_DIV_PER_LOW_1
,
257 regs
->ssc_div_per_low
);
258 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_DIV_PER_HIGH_1
,
259 regs
->ssc_div_per_high
);
260 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_DIV_ADJPER_LOW_1
,
261 regs
->ssc_adjper_low
);
262 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_DIV_ADJPER_HIGH_1
,
263 regs
->ssc_adjper_high
);
264 pll_write(base
+ REG_DSI_10nm_PHY_PLL_SSC_CONTROL
,
265 SSC_EN
| regs
->ssc_control
);
269 static void dsi_pll_config_hzindep_reg(struct dsi_pll_10nm
*pll
)
271 void __iomem
*base
= pll
->mmio
;
273 pll_write(base
+ REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_ONE
, 0x80);
274 pll_write(base
+ REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_TWO
, 0x03);
275 pll_write(base
+ REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_THREE
, 0x00);
276 pll_write(base
+ REG_DSI_10nm_PHY_PLL_DSM_DIVIDER
, 0x00);
277 pll_write(base
+ REG_DSI_10nm_PHY_PLL_FEEDBACK_DIVIDER
, 0x4e);
278 pll_write(base
+ REG_DSI_10nm_PHY_PLL_CALIBRATION_SETTINGS
, 0x40);
279 pll_write(base
+ REG_DSI_10nm_PHY_PLL_BAND_SEL_CAL_SETTINGS_THREE
,
281 pll_write(base
+ REG_DSI_10nm_PHY_PLL_FREQ_DETECT_SETTINGS_ONE
, 0x0c);
282 pll_write(base
+ REG_DSI_10nm_PHY_PLL_OUTDIV
, 0x00);
283 pll_write(base
+ REG_DSI_10nm_PHY_PLL_CORE_OVERRIDE
, 0x00);
284 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_DIGITAL_TIMERS_TWO
, 0x08);
285 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_PROP_GAIN_RATE_1
, 0x08);
286 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_BAND_SET_RATE_1
, 0xc0);
287 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_INT_GAIN_IFILT_BAND_1
, 0xfa);
288 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_FL_INT_GAIN_PFILT_BAND_1
,
290 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_LOCK_OVERRIDE
, 0x80);
291 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PFILT
, 0x29);
292 pll_write(base
+ REG_DSI_10nm_PHY_PLL_IFILT
, 0x3f);
295 static void dsi_pll_commit(struct dsi_pll_10nm
*pll
)
297 void __iomem
*base
= pll
->mmio
;
298 struct dsi_pll_regs
*reg
= &pll
->reg_setup
;
300 pll_write(base
+ REG_DSI_10nm_PHY_PLL_CORE_INPUT_OVERRIDE
, 0x12);
301 pll_write(base
+ REG_DSI_10nm_PHY_PLL_DECIMAL_DIV_START_1
,
302 reg
->decimal_div_start
);
303 pll_write(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_LOW_1
,
304 reg
->frac_div_start_low
);
305 pll_write(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_MID_1
,
306 reg
->frac_div_start_mid
);
307 pll_write(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_HIGH_1
,
308 reg
->frac_div_start_high
);
309 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_LOCKDET_RATE_1
, 0x40);
310 pll_write(base
+ REG_DSI_10nm_PHY_PLL_PLL_LOCK_DELAY
, 0x06);
311 pll_write(base
+ REG_DSI_10nm_PHY_PLL_CMODE
, 0x10);
312 pll_write(base
+ REG_DSI_10nm_PHY_PLL_CLOCK_INVERTERS
,
313 reg
->pll_clock_inverters
);
316 static int dsi_pll_10nm_vco_set_rate(struct clk_hw
*hw
, unsigned long rate
,
317 unsigned long parent_rate
)
319 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
320 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
322 DBG("DSI PLL%d rate=%lu, parent's=%lu", pll_10nm
->id
, rate
,
325 pll_10nm
->vco_current_rate
= rate
;
326 pll_10nm
->vco_ref_clk_rate
= VCO_REF_CLK_RATE
;
328 dsi_pll_setup_config(pll_10nm
);
330 dsi_pll_calc_dec_frac(pll_10nm
);
332 dsi_pll_calc_ssc(pll_10nm
);
334 dsi_pll_commit(pll_10nm
);
336 dsi_pll_config_hzindep_reg(pll_10nm
);
338 dsi_pll_ssc_commit(pll_10nm
);
340 /* flush, ensure all register writes are done*/
346 static int dsi_pll_10nm_lock_status(struct dsi_pll_10nm
*pll
)
350 u32
const delay_us
= 100;
351 u32
const timeout_us
= 5000;
353 rc
= readl_poll_timeout_atomic(pll
->mmio
+
354 REG_DSI_10nm_PHY_PLL_COMMON_STATUS_ONE
,
356 ((status
& BIT(0)) > 0),
360 pr_err("DSI PLL(%d) lock failed, status=0x%08x\n",
366 static void dsi_pll_disable_pll_bias(struct dsi_pll_10nm
*pll
)
368 u32 data
= pll_read(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CTRL_0
);
370 pll_write(pll
->mmio
+ REG_DSI_10nm_PHY_PLL_SYSTEM_MUXES
, 0);
371 pll_write(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CTRL_0
,
376 static void dsi_pll_enable_pll_bias(struct dsi_pll_10nm
*pll
)
378 u32 data
= pll_read(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CTRL_0
);
380 pll_write(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CTRL_0
,
382 pll_write(pll
->mmio
+ REG_DSI_10nm_PHY_PLL_SYSTEM_MUXES
, 0xc0);
386 static void dsi_pll_disable_global_clk(struct dsi_pll_10nm
*pll
)
390 data
= pll_read(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
);
391 pll_write(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
,
395 static void dsi_pll_enable_global_clk(struct dsi_pll_10nm
*pll
)
399 data
= pll_read(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
);
400 pll_write(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
,
404 static int dsi_pll_10nm_vco_prepare(struct clk_hw
*hw
)
406 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
407 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
410 dsi_pll_enable_pll_bias(pll_10nm
);
412 dsi_pll_enable_pll_bias(pll_10nm
->slave
);
414 rc
= dsi_pll_10nm_vco_set_rate(hw
,pll_10nm
->vco_current_rate
, 0);
416 pr_err("vco_set_rate failed, rc=%d\n", rc
);
421 pll_write(pll_10nm
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_PLL_CNTRL
,
425 * ensure all PLL configurations are written prior to checking
430 /* Check for PLL lock */
431 rc
= dsi_pll_10nm_lock_status(pll_10nm
);
433 pr_err("PLL(%d) lock failed\n", pll_10nm
->id
);
439 dsi_pll_enable_global_clk(pll_10nm
);
441 dsi_pll_enable_global_clk(pll_10nm
->slave
);
443 pll_write(pll_10nm
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_RBUF_CTRL
,
446 pll_write(pll_10nm
->slave
->phy_cmn_mmio
+
447 REG_DSI_10nm_PHY_CMN_RBUF_CTRL
, 0x01);
453 static void dsi_pll_disable_sub(struct dsi_pll_10nm
*pll
)
455 pll_write(pll
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_RBUF_CTRL
, 0);
456 dsi_pll_disable_pll_bias(pll
);
459 static void dsi_pll_10nm_vco_unprepare(struct clk_hw
*hw
)
461 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
462 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
465 * To avoid any stray glitches while abruptly powering down the PLL
466 * make sure to gate the clock using the clock enable bit before
467 * powering down the PLL
469 dsi_pll_disable_global_clk(pll_10nm
);
470 pll_write(pll_10nm
->phy_cmn_mmio
+ REG_DSI_10nm_PHY_CMN_PLL_CNTRL
, 0);
471 dsi_pll_disable_sub(pll_10nm
);
472 if (pll_10nm
->slave
) {
473 dsi_pll_disable_global_clk(pll_10nm
->slave
);
474 dsi_pll_disable_sub(pll_10nm
->slave
);
476 /* flush, ensure all register writes are done */
481 static unsigned long dsi_pll_10nm_vco_recalc_rate(struct clk_hw
*hw
,
482 unsigned long parent_rate
)
484 struct msm_dsi_pll
*pll
= hw_clk_to_pll(hw
);
485 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
486 void __iomem
*base
= pll_10nm
->mmio
;
487 u64 ref_clk
= pll_10nm
->vco_ref_clk_rate
;
494 dec
= pll_read(base
+ REG_DSI_10nm_PHY_PLL_DECIMAL_DIV_START_1
);
497 frac
= pll_read(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_LOW_1
);
498 frac
|= ((pll_read(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_MID_1
) &
500 frac
|= ((pll_read(base
+ REG_DSI_10nm_PHY_PLL_FRAC_DIV_START_HIGH_1
) &
505 * 1. Assumes prescaler is disabled
506 * 2. Multiplier is 2^18. it should be 2^(num_of_frac_bits)
508 multiplier
= 1 << 18;
509 pll_freq
= dec
* (ref_clk
* 2);
510 tmp64
= (ref_clk
* 2 * frac
);
511 pll_freq
+= div_u64(tmp64
, multiplier
);
515 DBG("DSI PLL%d returning vco rate = %lu, dec = %x, frac = %x",
516 pll_10nm
->id
, (unsigned long)vco_rate
, dec
, frac
);
518 return (unsigned long)vco_rate
;
521 static const struct clk_ops clk_ops_dsi_pll_10nm_vco
= {
522 .round_rate
= msm_dsi_pll_helper_clk_round_rate
,
523 .set_rate
= dsi_pll_10nm_vco_set_rate
,
524 .recalc_rate
= dsi_pll_10nm_vco_recalc_rate
,
525 .prepare
= dsi_pll_10nm_vco_prepare
,
526 .unprepare
= dsi_pll_10nm_vco_unprepare
,
533 static void dsi_pll_10nm_save_state(struct msm_dsi_pll
*pll
)
535 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
536 struct pll_10nm_cached_state
*cached
= &pll_10nm
->cached_state
;
537 void __iomem
*phy_base
= pll_10nm
->phy_cmn_mmio
;
538 u32 cmn_clk_cfg0
, cmn_clk_cfg1
;
540 cached
->pll_out_div
= pll_read(pll_10nm
->mmio
+
541 REG_DSI_10nm_PHY_PLL_PLL_OUTDIV_RATE
);
542 cached
->pll_out_div
&= 0x3;
544 cmn_clk_cfg0
= pll_read(phy_base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG0
);
545 cached
->bit_clk_div
= cmn_clk_cfg0
& 0xf;
546 cached
->pix_clk_div
= (cmn_clk_cfg0
& 0xf0) >> 4;
548 cmn_clk_cfg1
= pll_read(phy_base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
);
549 cached
->pll_mux
= cmn_clk_cfg1
& 0x3;
551 DBG("DSI PLL%d outdiv %x bit_clk_div %x pix_clk_div %x pll_mux %x",
552 pll_10nm
->id
, cached
->pll_out_div
, cached
->bit_clk_div
,
553 cached
->pix_clk_div
, cached
->pll_mux
);
556 static int dsi_pll_10nm_restore_state(struct msm_dsi_pll
*pll
)
558 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
559 struct pll_10nm_cached_state
*cached
= &pll_10nm
->cached_state
;
560 void __iomem
*phy_base
= pll_10nm
->phy_cmn_mmio
;
564 val
= pll_read(pll_10nm
->mmio
+ REG_DSI_10nm_PHY_PLL_PLL_OUTDIV_RATE
);
566 val
|= cached
->pll_out_div
;
567 pll_write(pll_10nm
->mmio
+ REG_DSI_10nm_PHY_PLL_PLL_OUTDIV_RATE
, val
);
569 pll_write(phy_base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG0
,
570 cached
->bit_clk_div
| (cached
->pix_clk_div
<< 4));
572 val
= pll_read(phy_base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
);
574 val
|= cached
->pll_mux
;
575 pll_write(phy_base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
, val
);
577 ret
= dsi_pll_10nm_vco_set_rate(&pll
->clk_hw
, pll_10nm
->vco_current_rate
, pll_10nm
->vco_ref_clk_rate
);
579 DRM_DEV_ERROR(&pll_10nm
->pdev
->dev
,
580 "restore vco rate failed. ret=%d\n", ret
);
584 DBG("DSI PLL%d", pll_10nm
->id
);
589 static int dsi_pll_10nm_set_usecase(struct msm_dsi_pll
*pll
,
590 enum msm_dsi_phy_usecase uc
)
592 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
593 void __iomem
*base
= pll_10nm
->phy_cmn_mmio
;
594 u32 data
= 0x0; /* internal PLL */
596 DBG("DSI PLL%d", pll_10nm
->id
);
599 case MSM_DSI_PHY_STANDALONE
:
601 case MSM_DSI_PHY_MASTER
:
602 pll_10nm
->slave
= pll_10nm_list
[(pll_10nm
->id
+ 1) % DSI_MAX
];
604 case MSM_DSI_PHY_SLAVE
:
605 data
= 0x1; /* external PLL */
612 pll_write(base
+ REG_DSI_10nm_PHY_CMN_CLK_CFG1
, (data
<< 2));
619 static int dsi_pll_10nm_get_provider(struct msm_dsi_pll
*pll
,
620 struct clk
**byte_clk_provider
,
621 struct clk
**pixel_clk_provider
)
623 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
624 struct clk_hw_onecell_data
*hw_data
= pll_10nm
->hw_data
;
626 DBG("DSI PLL%d", pll_10nm
->id
);
628 if (byte_clk_provider
)
629 *byte_clk_provider
= hw_data
->hws
[DSI_BYTE_PLL_CLK
]->clk
;
630 if (pixel_clk_provider
)
631 *pixel_clk_provider
= hw_data
->hws
[DSI_PIXEL_PLL_CLK
]->clk
;
636 static void dsi_pll_10nm_destroy(struct msm_dsi_pll
*pll
)
638 struct dsi_pll_10nm
*pll_10nm
= to_pll_10nm(pll
);
639 struct device
*dev
= &pll_10nm
->pdev
->dev
;
641 DBG("DSI PLL%d", pll_10nm
->id
);
642 of_clk_del_provider(dev
->of_node
);
644 clk_hw_unregister_divider(pll_10nm
->out_dsiclk_hw
);
645 clk_hw_unregister_mux(pll_10nm
->pclk_mux_hw
);
646 clk_hw_unregister_fixed_factor(pll_10nm
->post_out_div_clk_hw
);
647 clk_hw_unregister_fixed_factor(pll_10nm
->by_2_bit_clk_hw
);
648 clk_hw_unregister_fixed_factor(pll_10nm
->byte_clk_hw
);
649 clk_hw_unregister_divider(pll_10nm
->bit_clk_hw
);
650 clk_hw_unregister_divider(pll_10nm
->out_div_clk_hw
);
651 clk_hw_unregister(&pll_10nm
->base
.clk_hw
);
655 * The post dividers and mux clocks are created using the standard divider and
656 * mux API. Unlike the 14nm PHY, the slave PLL doesn't need its dividers/mux
657 * state to follow the master PLL's divider/mux state. Therefore, we don't
658 * require special clock ops that also configure the slave PLL registers
660 static int pll_10nm_register(struct dsi_pll_10nm
*pll_10nm
)
662 char clk_name
[32], parent
[32], vco_name
[32];
663 char parent2
[32], parent3
[32], parent4
[32];
664 struct clk_init_data vco_init
= {
665 .parent_names
= (const char *[]){ "xo" },
668 .flags
= CLK_IGNORE_UNUSED
,
669 .ops
= &clk_ops_dsi_pll_10nm_vco
,
671 struct device
*dev
= &pll_10nm
->pdev
->dev
;
672 struct clk_hw_onecell_data
*hw_data
;
676 DBG("DSI%d", pll_10nm
->id
);
678 hw_data
= devm_kzalloc(dev
, sizeof(*hw_data
) +
679 NUM_PROVIDED_CLKS
* sizeof(struct clk_hw
*),
684 snprintf(vco_name
, 32, "dsi%dvco_clk", pll_10nm
->id
);
685 pll_10nm
->base
.clk_hw
.init
= &vco_init
;
687 ret
= clk_hw_register(dev
, &pll_10nm
->base
.clk_hw
);
691 snprintf(clk_name
, 32, "dsi%d_pll_out_div_clk", pll_10nm
->id
);
692 snprintf(parent
, 32, "dsi%dvco_clk", pll_10nm
->id
);
694 hw
= clk_hw_register_divider(dev
, clk_name
,
695 parent
, CLK_SET_RATE_PARENT
,
697 REG_DSI_10nm_PHY_PLL_PLL_OUTDIV_RATE
,
698 0, 2, CLK_DIVIDER_POWER_OF_TWO
, NULL
);
701 goto err_base_clk_hw
;
704 pll_10nm
->out_div_clk_hw
= hw
;
706 snprintf(clk_name
, 32, "dsi%d_pll_bit_clk", pll_10nm
->id
);
707 snprintf(parent
, 32, "dsi%d_pll_out_div_clk", pll_10nm
->id
);
709 /* BIT CLK: DIV_CTRL_3_0 */
710 hw
= clk_hw_register_divider(dev
, clk_name
, parent
,
712 pll_10nm
->phy_cmn_mmio
+
713 REG_DSI_10nm_PHY_CMN_CLK_CFG0
,
714 0, 4, CLK_DIVIDER_ONE_BASED
,
715 &pll_10nm
->postdiv_lock
);
718 goto err_out_div_clk_hw
;
721 pll_10nm
->bit_clk_hw
= hw
;
723 snprintf(clk_name
, 32, "dsi%d_phy_pll_out_byteclk", pll_10nm
->id
);
724 snprintf(parent
, 32, "dsi%d_pll_bit_clk", pll_10nm
->id
);
726 /* DSI Byte clock = VCO_CLK / OUT_DIV / BIT_DIV / 8 */
727 hw
= clk_hw_register_fixed_factor(dev
, clk_name
, parent
,
728 CLK_SET_RATE_PARENT
, 1, 8);
734 pll_10nm
->byte_clk_hw
= hw
;
735 hw_data
->hws
[DSI_BYTE_PLL_CLK
] = hw
;
737 snprintf(clk_name
, 32, "dsi%d_pll_by_2_bit_clk", pll_10nm
->id
);
738 snprintf(parent
, 32, "dsi%d_pll_bit_clk", pll_10nm
->id
);
740 hw
= clk_hw_register_fixed_factor(dev
, clk_name
, parent
,
744 goto err_byte_clk_hw
;
747 pll_10nm
->by_2_bit_clk_hw
= hw
;
749 snprintf(clk_name
, 32, "dsi%d_pll_post_out_div_clk", pll_10nm
->id
);
750 snprintf(parent
, 32, "dsi%d_pll_out_div_clk", pll_10nm
->id
);
752 hw
= clk_hw_register_fixed_factor(dev
, clk_name
, parent
,
756 goto err_by_2_bit_clk_hw
;
759 pll_10nm
->post_out_div_clk_hw
= hw
;
761 snprintf(clk_name
, 32, "dsi%d_pclk_mux", pll_10nm
->id
);
762 snprintf(parent
, 32, "dsi%d_pll_bit_clk", pll_10nm
->id
);
763 snprintf(parent2
, 32, "dsi%d_pll_by_2_bit_clk", pll_10nm
->id
);
764 snprintf(parent3
, 32, "dsi%d_pll_out_div_clk", pll_10nm
->id
);
765 snprintf(parent4
, 32, "dsi%d_pll_post_out_div_clk", pll_10nm
->id
);
767 hw
= clk_hw_register_mux(dev
, clk_name
,
769 parent
, parent2
, parent3
, parent4
770 }), 4, 0, pll_10nm
->phy_cmn_mmio
+
771 REG_DSI_10nm_PHY_CMN_CLK_CFG1
,
775 goto err_post_out_div_clk_hw
;
778 pll_10nm
->pclk_mux_hw
= hw
;
780 snprintf(clk_name
, 32, "dsi%d_phy_pll_out_dsiclk", pll_10nm
->id
);
781 snprintf(parent
, 32, "dsi%d_pclk_mux", pll_10nm
->id
);
783 /* PIX CLK DIV : DIV_CTRL_7_4*/
784 hw
= clk_hw_register_divider(dev
, clk_name
, parent
,
785 0, pll_10nm
->phy_cmn_mmio
+
786 REG_DSI_10nm_PHY_CMN_CLK_CFG0
,
787 4, 4, CLK_DIVIDER_ONE_BASED
,
788 &pll_10nm
->postdiv_lock
);
791 goto err_pclk_mux_hw
;
794 pll_10nm
->out_dsiclk_hw
= hw
;
795 hw_data
->hws
[DSI_PIXEL_PLL_CLK
] = hw
;
797 hw_data
->num
= NUM_PROVIDED_CLKS
;
798 pll_10nm
->hw_data
= hw_data
;
800 ret
= of_clk_add_hw_provider(dev
->of_node
, of_clk_hw_onecell_get
,
803 DRM_DEV_ERROR(dev
, "failed to register clk provider: %d\n", ret
);
810 clk_hw_unregister_divider(pll_10nm
->out_dsiclk_hw
);
812 clk_hw_unregister_mux(pll_10nm
->pclk_mux_hw
);
813 err_post_out_div_clk_hw
:
814 clk_hw_unregister_fixed_factor(pll_10nm
->post_out_div_clk_hw
);
816 clk_hw_unregister_fixed_factor(pll_10nm
->by_2_bit_clk_hw
);
818 clk_hw_unregister_fixed_factor(pll_10nm
->byte_clk_hw
);
820 clk_hw_unregister_divider(pll_10nm
->bit_clk_hw
);
822 clk_hw_unregister_divider(pll_10nm
->out_div_clk_hw
);
824 clk_hw_unregister(&pll_10nm
->base
.clk_hw
);
829 struct msm_dsi_pll
*msm_dsi_pll_10nm_init(struct platform_device
*pdev
, int id
)
831 struct dsi_pll_10nm
*pll_10nm
;
832 struct msm_dsi_pll
*pll
;
835 pll_10nm
= devm_kzalloc(&pdev
->dev
, sizeof(*pll_10nm
), GFP_KERNEL
);
837 return ERR_PTR(-ENOMEM
);
839 DBG("DSI PLL%d", id
);
841 pll_10nm
->pdev
= pdev
;
843 pll_10nm_list
[id
] = pll_10nm
;
845 pll_10nm
->phy_cmn_mmio
= msm_ioremap(pdev
, "dsi_phy", "DSI_PHY");
846 if (IS_ERR_OR_NULL(pll_10nm
->phy_cmn_mmio
)) {
847 DRM_DEV_ERROR(&pdev
->dev
, "failed to map CMN PHY base\n");
848 return ERR_PTR(-ENOMEM
);
851 pll_10nm
->mmio
= msm_ioremap(pdev
, "dsi_pll", "DSI_PLL");
852 if (IS_ERR_OR_NULL(pll_10nm
->mmio
)) {
853 DRM_DEV_ERROR(&pdev
->dev
, "failed to map PLL base\n");
854 return ERR_PTR(-ENOMEM
);
857 spin_lock_init(&pll_10nm
->postdiv_lock
);
859 pll
= &pll_10nm
->base
;
860 pll
->min_rate
= 1000000000UL;
861 pll
->max_rate
= 3500000000UL;
862 pll
->get_provider
= dsi_pll_10nm_get_provider
;
863 pll
->destroy
= dsi_pll_10nm_destroy
;
864 pll
->save_state
= dsi_pll_10nm_save_state
;
865 pll
->restore_state
= dsi_pll_10nm_restore_state
;
866 pll
->set_usecase
= dsi_pll_10nm_set_usecase
;
868 pll_10nm
->vco_delay
= 1;
870 ret
= pll_10nm_register(pll_10nm
);
872 DRM_DEV_ERROR(&pdev
->dev
, "failed to register PLL: %d\n", ret
);
876 /* TODO: Remove this when we have proper display handover support */
877 msm_dsi_pll_save_state(pll
);