Lines Matching +full:pll +full:-
1 // SPDX-License-Identifier: GPL-2.0-only
6 #include <linux/clk-provider.h>
33 /* pll mmio base */
81 static inline struct hdmi_phy *pll_get_phy(struct hdmi_pll_8996 *pll) in pll_get_phy() argument
83 return platform_get_drvdata(pll->pdev); in pll_get_phy()
86 static inline void hdmi_pll_write(struct hdmi_pll_8996 *pll, int offset, in hdmi_pll_write() argument
89 writel(data, pll->mmio_qserdes_com + offset); in hdmi_pll_write()
92 static inline u32 hdmi_pll_read(struct hdmi_pll_8996 *pll, int offset) in hdmi_pll_read() argument
94 return readl(pll->mmio_qserdes_com + offset); in hdmi_pll_read()
97 static inline void hdmi_tx_chan_write(struct hdmi_pll_8996 *pll, int channel, in hdmi_tx_chan_write() argument
100 writel(data, pll->mmio_qserdes_tx[channel] + offset); in hdmi_tx_chan_write()
154 return dividend - 1; in pll_get_pll_cmp()
179 vco_optimal_index = -1; in pll_get_post_div()
201 if (vco_optimal_index == -1) { in pll_get_post_div()
207 pd->vco_freq = vco_optimal; in pll_get_post_div()
208 pd->tx_band_sel = tx_band_sel[vco_optimal_index % 4]; in pll_get_post_div()
209 pd->vco_ratio = ratio[vco_optimal_index / 4]; in pll_get_post_div()
210 pd->hsclk_divsel = hs_divsel[vco_optimal_index / 4]; in pll_get_post_div()
215 return -EINVAL; in pll_get_post_div()
255 frac_start -= dec_start * (1 << 20); in pll_calculate()
286 cfg->com_svs_mode_clk_sel = 1; in pll_calculate()
288 cfg->com_svs_mode_clk_sel = 2; in pll_calculate()
290 cfg->com_hsclk_sel = (0x20 | pd.hsclk_divsel); in pll_calculate()
291 cfg->com_pll_cctrl_mode0 = cctrl; in pll_calculate()
292 cfg->com_pll_rctrl_mode0 = rctrl; in pll_calculate()
293 cfg->com_cp_ctrl_mode0 = cpctrl; in pll_calculate()
294 cfg->com_dec_start_mode0 = dec_start; in pll_calculate()
295 cfg->com_div_frac_start1_mode0 = (frac_start & 0xff); in pll_calculate()
296 cfg->com_div_frac_start2_mode0 = ((frac_start & 0xff00) >> 8); in pll_calculate()
297 cfg->com_div_frac_start3_mode0 = ((frac_start & 0xf0000) >> 16); in pll_calculate()
298 cfg->com_integloop_gain0_mode0 = (integloop_gain & 0xff); in pll_calculate()
299 cfg->com_integloop_gain1_mode0 = ((integloop_gain & 0xf00) >> 8); in pll_calculate()
300 cfg->com_lock_cmp1_mode0 = (pll_cmp & 0xff); in pll_calculate()
301 cfg->com_lock_cmp2_mode0 = ((pll_cmp & 0xff00) >> 8); in pll_calculate()
302 cfg->com_lock_cmp3_mode0 = ((pll_cmp & 0x30000) >> 16); in pll_calculate()
303 cfg->com_lock_cmp_en = 0x0; in pll_calculate()
304 cfg->com_core_clk_en = 0x2c; in pll_calculate()
305 cfg->com_coreclk_div = HDMI_CORECLK_DIV; in pll_calculate()
306 cfg->phy_mode = (bclk > HDMI_HIGH_FREQ_BIT_CLK_THRESHOLD) ? 0x10 : 0x0; in pll_calculate()
307 cfg->com_vco_tune_ctrl = 0x0; in pll_calculate()
309 cfg->tx_lx_lane_mode[0] = in pll_calculate()
310 cfg->tx_lx_lane_mode[2] = 0x43; in pll_calculate()
312 cfg->tx_lx_hp_pd_enables[0] = in pll_calculate()
313 cfg->tx_lx_hp_pd_enables[1] = in pll_calculate()
314 cfg->tx_lx_hp_pd_enables[2] = 0x0c; in pll_calculate()
315 cfg->tx_lx_hp_pd_enables[3] = 0x3; in pll_calculate()
318 cfg->tx_lx_tx_band[i] = pd.tx_band_sel + 4; in pll_calculate()
321 cfg->tx_lx_tx_drv_lvl[0] = in pll_calculate()
322 cfg->tx_lx_tx_drv_lvl[1] = in pll_calculate()
323 cfg->tx_lx_tx_drv_lvl[2] = 0x25; in pll_calculate()
324 cfg->tx_lx_tx_drv_lvl[3] = 0x22; in pll_calculate()
326 cfg->tx_lx_tx_emp_post1_lvl[0] = in pll_calculate()
327 cfg->tx_lx_tx_emp_post1_lvl[1] = in pll_calculate()
328 cfg->tx_lx_tx_emp_post1_lvl[2] = 0x23; in pll_calculate()
329 cfg->tx_lx_tx_emp_post1_lvl[3] = 0x27; in pll_calculate()
331 cfg->tx_lx_vmode_ctrl1[0] = in pll_calculate()
332 cfg->tx_lx_vmode_ctrl1[1] = in pll_calculate()
333 cfg->tx_lx_vmode_ctrl1[2] = in pll_calculate()
334 cfg->tx_lx_vmode_ctrl1[3] = 0x00; in pll_calculate()
336 cfg->tx_lx_vmode_ctrl2[0] = in pll_calculate()
337 cfg->tx_lx_vmode_ctrl2[1] = in pll_calculate()
338 cfg->tx_lx_vmode_ctrl2[2] = 0x0D; in pll_calculate()
340 cfg->tx_lx_vmode_ctrl2[3] = 0x00; in pll_calculate()
343 cfg->tx_lx_tx_drv_lvl[i] = 0x25; in pll_calculate()
344 cfg->tx_lx_tx_emp_post1_lvl[i] = 0x23; in pll_calculate()
345 cfg->tx_lx_vmode_ctrl1[i] = 0x00; in pll_calculate()
348 cfg->tx_lx_vmode_ctrl2[0] = in pll_calculate()
349 cfg->tx_lx_vmode_ctrl2[1] = in pll_calculate()
350 cfg->tx_lx_vmode_ctrl2[2] = 0x0D; in pll_calculate()
351 cfg->tx_lx_vmode_ctrl2[3] = 0x00; in pll_calculate()
354 cfg->tx_lx_tx_drv_lvl[i] = 0x20; in pll_calculate()
355 cfg->tx_lx_tx_emp_post1_lvl[i] = 0x20; in pll_calculate()
356 cfg->tx_lx_vmode_ctrl1[i] = 0x00; in pll_calculate()
357 cfg->tx_lx_vmode_ctrl2[i] = 0x0E; in pll_calculate()
361 DBG("com_svs_mode_clk_sel = 0x%x", cfg->com_svs_mode_clk_sel); in pll_calculate()
362 DBG("com_hsclk_sel = 0x%x", cfg->com_hsclk_sel); in pll_calculate()
363 DBG("com_lock_cmp_en = 0x%x", cfg->com_lock_cmp_en); in pll_calculate()
364 DBG("com_pll_cctrl_mode0 = 0x%x", cfg->com_pll_cctrl_mode0); in pll_calculate()
365 DBG("com_pll_rctrl_mode0 = 0x%x", cfg->com_pll_rctrl_mode0); in pll_calculate()
366 DBG("com_cp_ctrl_mode0 = 0x%x", cfg->com_cp_ctrl_mode0); in pll_calculate()
367 DBG("com_dec_start_mode0 = 0x%x", cfg->com_dec_start_mode0); in pll_calculate()
368 DBG("com_div_frac_start1_mode0 = 0x%x", cfg->com_div_frac_start1_mode0); in pll_calculate()
369 DBG("com_div_frac_start2_mode0 = 0x%x", cfg->com_div_frac_start2_mode0); in pll_calculate()
370 DBG("com_div_frac_start3_mode0 = 0x%x", cfg->com_div_frac_start3_mode0); in pll_calculate()
371 DBG("com_integloop_gain0_mode0 = 0x%x", cfg->com_integloop_gain0_mode0); in pll_calculate()
372 DBG("com_integloop_gain1_mode0 = 0x%x", cfg->com_integloop_gain1_mode0); in pll_calculate()
373 DBG("com_lock_cmp1_mode0 = 0x%x", cfg->com_lock_cmp1_mode0); in pll_calculate()
374 DBG("com_lock_cmp2_mode0 = 0x%x", cfg->com_lock_cmp2_mode0); in pll_calculate()
375 DBG("com_lock_cmp3_mode0 = 0x%x", cfg->com_lock_cmp3_mode0); in pll_calculate()
376 DBG("com_core_clk_en = 0x%x", cfg->com_core_clk_en); in pll_calculate()
377 DBG("com_coreclk_div = 0x%x", cfg->com_coreclk_div); in pll_calculate()
378 DBG("phy_mode = 0x%x", cfg->phy_mode); in pll_calculate()
380 DBG("tx_l0_lane_mode = 0x%x", cfg->tx_lx_lane_mode[0]); in pll_calculate()
381 DBG("tx_l2_lane_mode = 0x%x", cfg->tx_lx_lane_mode[2]); in pll_calculate()
384 DBG("tx_l%d_tx_band = 0x%x", i, cfg->tx_lx_tx_band[i]); in pll_calculate()
385 DBG("tx_l%d_tx_drv_lvl = 0x%x", i, cfg->tx_lx_tx_drv_lvl[i]); in pll_calculate()
387 cfg->tx_lx_tx_emp_post1_lvl[i]); in pll_calculate()
388 DBG("tx_l%d_vmode_ctrl1 = 0x%x", i, cfg->tx_lx_vmode_ctrl1[i]); in pll_calculate()
389 DBG("tx_l%d_vmode_ctrl2 = 0x%x", i, cfg->tx_lx_vmode_ctrl2[i]); in pll_calculate()
398 struct hdmi_pll_8996 *pll = hw_clk_to_pll(hw); in hdmi_8996_pll_set_clk_rate() local
399 struct hdmi_phy *phy = pll_get_phy(pll); in hdmi_8996_pll_set_clk_rate()
407 DRM_ERROR("PLL calculation failed\n"); in hdmi_8996_pll_set_clk_rate()
417 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_BG_CTRL, 0x04); in hdmi_8996_pll_set_clk_rate()
420 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_RESETSM_CNTRL, 0x20); in hdmi_8996_pll_set_clk_rate()
425 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
428 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
431 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
436 hdmi_tx_chan_write(pll, 0, REG_HDMI_PHY_QSERDES_TX_LX_LANE_MODE, in hdmi_8996_pll_set_clk_rate()
438 hdmi_tx_chan_write(pll, 2, REG_HDMI_PHY_QSERDES_TX_LX_LANE_MODE, in hdmi_8996_pll_set_clk_rate()
441 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_SYSCLK_BUF_ENABLE, 0x1E); in hdmi_8996_pll_set_clk_rate()
442 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x07); in hdmi_8996_pll_set_clk_rate()
443 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_SYSCLK_EN_SEL, 0x37); in hdmi_8996_pll_set_clk_rate()
444 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_SYS_CLK_CTRL, 0x02); in hdmi_8996_pll_set_clk_rate()
445 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_CLK_ENABLE1, 0x0E); in hdmi_8996_pll_set_clk_rate()
448 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_SVS_MODE_CLK_SEL, in hdmi_8996_pll_set_clk_rate()
451 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_BG_TRIM, 0x0F); in hdmi_8996_pll_set_clk_rate()
452 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_PLL_IVCO, 0x0F); in hdmi_8996_pll_set_clk_rate()
453 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_VCO_TUNE_CTRL, in hdmi_8996_pll_set_clk_rate()
456 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_BG_CTRL, 0x06); in hdmi_8996_pll_set_clk_rate()
458 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_CLK_SELECT, 0x30); in hdmi_8996_pll_set_clk_rate()
459 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_HSCLK_SEL, in hdmi_8996_pll_set_clk_rate()
461 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_LOCK_CMP_EN, in hdmi_8996_pll_set_clk_rate()
464 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_PLL_CCTRL_MODE0, in hdmi_8996_pll_set_clk_rate()
466 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_PLL_RCTRL_MODE0, in hdmi_8996_pll_set_clk_rate()
468 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_CP_CTRL_MODE0, in hdmi_8996_pll_set_clk_rate()
470 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_DEC_START_MODE0, in hdmi_8996_pll_set_clk_rate()
472 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_DIV_FRAC_START1_MODE0, in hdmi_8996_pll_set_clk_rate()
474 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_DIV_FRAC_START2_MODE0, in hdmi_8996_pll_set_clk_rate()
476 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_DIV_FRAC_START3_MODE0, in hdmi_8996_pll_set_clk_rate()
479 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_INTEGLOOP_GAIN0_MODE0, in hdmi_8996_pll_set_clk_rate()
481 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_INTEGLOOP_GAIN1_MODE0, in hdmi_8996_pll_set_clk_rate()
484 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_LOCK_CMP1_MODE0, in hdmi_8996_pll_set_clk_rate()
486 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_LOCK_CMP2_MODE0, in hdmi_8996_pll_set_clk_rate()
488 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_LOCK_CMP3_MODE0, in hdmi_8996_pll_set_clk_rate()
491 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_VCO_TUNE_MAP, 0x00); in hdmi_8996_pll_set_clk_rate()
492 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_CORE_CLK_EN, in hdmi_8996_pll_set_clk_rate()
494 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_CORECLK_DIV, in hdmi_8996_pll_set_clk_rate()
496 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_CMN_CONFIG, 0x02); in hdmi_8996_pll_set_clk_rate()
498 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_RESCODE_DIV_NUM, 0x15); in hdmi_8996_pll_set_clk_rate()
502 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
505 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
508 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
511 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
514 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
517 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
520 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
523 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
526 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_set_clk_rate()
536 * enabling the PLL in hdmi_8996_pll_set_clk_rate()
552 while (nb_tries--) { in hdmi_8996_phy_ready_status()
567 static int hdmi_8996_pll_lock_status(struct hdmi_pll_8996 *pll) in hdmi_8996_pll_lock_status() argument
574 DBG("Waiting for PLL lock"); in hdmi_8996_pll_lock_status()
576 while (nb_tries--) { in hdmi_8996_pll_lock_status()
577 status = hdmi_pll_read(pll, in hdmi_8996_pll_lock_status()
587 DBG("HDMI PLL is %slocked", pll_locked ? "" : "*not* "); in hdmi_8996_pll_lock_status()
594 struct hdmi_pll_8996 *pll = hw_clk_to_pll(hw); in hdmi_8996_pll_prepare() local
595 struct hdmi_phy *phy = pll_get_phy(pll); in hdmi_8996_pll_prepare()
604 ret = hdmi_8996_pll_lock_status(pll); in hdmi_8996_pll_prepare()
609 hdmi_tx_chan_write(pll, i, in hdmi_8996_pll_prepare()
614 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_SSC_PER1, 0x0); in hdmi_8996_pll_prepare()
615 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_SSC_PER2, 0x0); in hdmi_8996_pll_prepare()
616 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_SSC_STEP_SIZE1, 0x0); in hdmi_8996_pll_prepare()
617 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_SSC_STEP_SIZE2, 0x0); in hdmi_8996_pll_prepare()
618 hdmi_pll_write(pll, REG_HDMI_PHY_QSERDES_COM_SSC_EN_CENTER, 0x2); in hdmi_8996_pll_prepare()
647 struct hdmi_pll_8996 *pll = hw_clk_to_pll(hw); in hdmi_8996_pll_recalc_rate() local
651 cmp1 = hdmi_pll_read(pll, REG_HDMI_PHY_QSERDES_COM_LOCK_CMP1_MODE0); in hdmi_8996_pll_recalc_rate()
652 cmp2 = hdmi_pll_read(pll, REG_HDMI_PHY_QSERDES_COM_LOCK_CMP2_MODE0); in hdmi_8996_pll_recalc_rate()
653 cmp3 = hdmi_pll_read(pll, REG_HDMI_PHY_QSERDES_COM_LOCK_CMP3_MODE0); in hdmi_8996_pll_recalc_rate()
666 struct hdmi_pll_8996 *pll = hw_clk_to_pll(hw); in hdmi_8996_pll_unprepare() local
667 struct hdmi_phy *phy = pll_get_phy(pll); in hdmi_8996_pll_unprepare()
675 struct hdmi_pll_8996 *pll = hw_clk_to_pll(hw); in hdmi_8996_pll_is_enabled() local
679 status = hdmi_pll_read(pll, REG_HDMI_PHY_QSERDES_COM_C_READY_STATUS); in hdmi_8996_pll_is_enabled()
706 struct device *dev = &pdev->dev; in msm_hdmi_pll_8996_init()
707 struct hdmi_pll_8996 *pll; in msm_hdmi_pll_8996_init() local
710 pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); in msm_hdmi_pll_8996_init()
711 if (!pll) in msm_hdmi_pll_8996_init()
712 return -ENOMEM; in msm_hdmi_pll_8996_init()
714 pll->pdev = pdev; in msm_hdmi_pll_8996_init()
716 pll->mmio_qserdes_com = msm_ioremap(pdev, "hdmi_pll"); in msm_hdmi_pll_8996_init()
717 if (IS_ERR(pll->mmio_qserdes_com)) { in msm_hdmi_pll_8996_init()
718 DRM_DEV_ERROR(dev, "failed to map pll base\n"); in msm_hdmi_pll_8996_init()
719 return -ENOMEM; in msm_hdmi_pll_8996_init()
727 pll->mmio_qserdes_tx[i] = msm_ioremap(pdev, name); in msm_hdmi_pll_8996_init()
728 if (IS_ERR(pll->mmio_qserdes_tx[i])) { in msm_hdmi_pll_8996_init()
729 DRM_DEV_ERROR(dev, "failed to map pll base\n"); in msm_hdmi_pll_8996_init()
730 return -ENOMEM; in msm_hdmi_pll_8996_init()
733 pll->clk_hw.init = &pll_init; in msm_hdmi_pll_8996_init()
735 ret = devm_clk_hw_register(dev, &pll->clk_hw); in msm_hdmi_pll_8996_init()
737 DRM_DEV_ERROR(dev, "failed to register pll clock\n"); in msm_hdmi_pll_8996_init()
741 ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, &pll->clk_hw); in msm_hdmi_pll_8996_init()