static enum handoff hdmi_20nm_vco_handoff(struct clk *c) { enum handoff ret = HANDOFF_DISABLED_CLK; struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c); struct mdss_pll_resources *io = vco->priv; if (mdss_pll_resource_enable(io, true)) { pr_err("pll resource can't be enabled\n"); return ret; } io->handoff_resources = true; if (hdmi_20nm_pll_lock_status(io)) { io->pll_on = true; c->rate = hdmi_20nm_vco_get_rate(c); ret = HANDOFF_ENABLED_CLK; } else { io->handoff_resources = false; mdss_pll_resource_enable(io, false); } pr_debug("done, ret=%d\n", ret); return ret; }
int dsi_pll_mux_prepare(struct clk *c) { struct mux_clk *mux = to_mux_clk(c); int i, rc, sel = 0; struct mdss_pll_resources *dsi_pll_res = mux->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } for (i = 0; i < mux->num_parents; i++) if (mux->parents[i].src == c->parent) { sel = mux->parents[i].sel; break; } if (i == mux->num_parents) { pr_err("Failed to select the parent clock\n"); rc = -EINVAL; goto error; } /* Restore the mux source select value */ rc = mux->ops->set_mux_sel(mux, sel); error: mdss_pll_resource_enable(dsi_pll_res, false); return rc; }
static int dsi_pll_enable(struct clk *c) { int i, rc; struct dsi_pll_vco_clk *vco = to_vco_clk(c); struct mdss_pll_resources *dsi_pll_res = vco->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } /* Try all enable sequences until one succeeds */ for (i = 0; i < vco->pll_en_seq_cnt; i++) { rc = vco->pll_enable_seqs[i](dsi_pll_res); pr_debug("DSI PLL %s after sequence #%d\n", rc ? "unlocked" : "locked", i + 1); if (!rc) break; } if (rc) { mdss_pll_resource_enable(dsi_pll_res, false); pr_err("DSI PLL failed to lock\n"); } dsi_pll_res->pll_on = true; return rc; }
static int hdmi_20nm_vco_set_rate(struct clk *c, unsigned long rate) { struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c); struct mdss_pll_resources *io = vco->priv; void __iomem *pll_base; void __iomem *phy_base; unsigned int set_power_dwn = 0; int rc; rc = mdss_pll_resource_enable(io, true); if (rc) { pr_err("pll resource can't be enabled\n"); return rc; } if (io->pll_on) set_power_dwn = 1; pll_base = io->pll_base; phy_base = io->phy_base; pr_debug("rate=%ld\n", rate); hdmi_20nm_phy_pll_set_clk_rate(c, rate); mdss_pll_resource_enable(io, false); if (set_power_dwn) hdmi_20nm_vco_enable(c); vco->rate = rate; vco->rate_set = true; return 0; }
static int vco_set_rate_lpm(struct clk *c, unsigned long rate) { int rc; struct dsi_pll_vco_clk *vco = to_vco_clk(c); struct mdss_pll_resources *dsi_pll_res = vco->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } /* * DSI PLL software reset. Add HW recommended delays after toggling * the software reset bit off and back on. */ MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_TEST_CFG, 0x01); udelay(1000); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_TEST_CFG, 0x00); udelay(1000); rc = vco_set_rate(vco, rate); mdss_pll_resource_enable(dsi_pll_res, false); return rc; }
static unsigned long vco_get_rate(struct clk *c) { u32 sdm0, doubler, sdm_byp_div; u64 vco_rate; u32 sdm_dc_off, sdm_freq_seed, sdm2, sdm3; struct dsi_pll_vco_clk *vco = to_vco_clk(c); u64 ref_clk = vco->ref_clk_rate; int rc; struct mdss_pll_resources *dsi_pll_res = vco->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } /* Check to see if the ref clk doubler is enabled */ doubler = MDSS_PLL_REG_R(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_REFCLK_CFG) & BIT(0); ref_clk += (doubler * vco->ref_clk_rate); /* see if it is integer mode or sdm mode */ sdm0 = MDSS_PLL_REG_R(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_SDM_CFG0); if (sdm0 & BIT(6)) { /* integer mode */ sdm_byp_div = (MDSS_PLL_REG_R(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_SDM_CFG0) & 0x3f) + 1; vco_rate = ref_clk * sdm_byp_div; } else { /* sdm mode */ sdm_dc_off = MDSS_PLL_REG_R(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_SDM_CFG1) & 0xFF; pr_debug("sdm_dc_off = %d\n", sdm_dc_off); sdm2 = MDSS_PLL_REG_R(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_SDM_CFG2) & 0xFF; sdm3 = MDSS_PLL_REG_R(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_SDM_CFG3) & 0xFF; sdm_freq_seed = (sdm3 << 8) | sdm2; pr_debug("sdm_freq_seed = %d\n", sdm_freq_seed); vco_rate = (ref_clk * (sdm_dc_off + 1)) + mult_frac(ref_clk, sdm_freq_seed, BIT(16)); pr_debug("vco rate = %lld", vco_rate); } pr_debug("returning vco rate = %lu\n", (unsigned long)vco_rate); mdss_pll_resource_enable(dsi_pll_res, false); return (unsigned long)vco_rate; }
static int vco_set_rate_dummy(struct clk *c, unsigned long rate) { struct dsi_pll_vco_clk *vco = to_vco_clk(c); struct mdss_pll_resources *pll_res = vco->priv; mdss_pll_resource_enable(pll_res, true); pll_20nm_config_powerdown(pll_res->pll_base); mdss_pll_resource_enable(pll_res, false); pr_debug("Configuring PLL1 registers.\n"); return 0; }
static unsigned long hdmi_20nm_vco_get_rate(struct clk *c) { unsigned long freq = 0; int rc; struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c); struct mdss_pll_resources *io = vco->priv; rc = mdss_pll_resource_enable(io, true); if (rc) { pr_err("pll resource can't be enabled\n"); return rc; } mdss_pll_resource_enable(io, false); return freq; }
static int analog_set_div(struct div_clk *clk, int div) { int rc; struct mdss_pll_resources *dsi_pll_res = clk->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_POSTDIV1_CFG, div - 1); mdss_pll_resource_enable(dsi_pll_res, false); return rc; }
static int digital_get_div(struct div_clk *clk) { int div = 0, rc; struct mdss_pll_resources *dsi_pll_res = clk->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } div = MDSS_PLL_REG_R(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_POSTDIV3_CFG); mdss_pll_resource_enable(dsi_pll_res, false); return div + 1; }
static int hdmi_20nm_pll_lock_status(struct mdss_pll_resources *io) { u32 status; int pll_locked = 0; int phy_ready = 0; int rc; rc = mdss_pll_resource_enable(io, true); if (rc) { pr_err("pll resource can't be enabled\n"); return rc; } /* Poll for C_READY and PHY READY */ pr_debug("%s: Waiting for PHY Ready\n", __func__); /* poll for PLL ready status */ if (!readl_poll_timeout_noirq( (io->pll_base + QSERDES_COM_RESET_SM), status, ((status & BIT(6)) == 1), HDMI_PLL_POLL_MAX_READS, HDMI_PLL_POLL_TIMEOUT_US)) { pr_debug("%s: C READY\n", __func__); pll_locked = 1; } else { pr_debug("%s: C READY TIMEOUT\n", __func__); pll_locked = 0; } /* poll for PHY ready status */ if (pll_locked && !readl_poll_timeout_noirq( (io->phy_base + HDMI_PHY_STATUS), status, ((status & BIT(0)) == 1), HDMI_PLL_POLL_MAX_READS, HDMI_PLL_POLL_TIMEOUT_US)) { pr_debug("%s: PHY READY\n", __func__); phy_ready = 1; } else { pr_debug("%s: PHY READY TIMEOUT\n", __func__); phy_ready = 0; } mdss_pll_resource_enable(io, false); return phy_ready; }
int set_byte_mux_sel(struct mux_clk *clk, int sel) { int rc; struct mdss_pll_resources *dsi_pll_res = clk->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } pr_debug("byte mux set to %s mode\n", sel ? "indirect" : "direct"); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_VREG_CFG, (sel << 1)); mdss_pll_resource_enable(dsi_pll_res, false); return 0; }
static void dsi_pll_off_work(struct work_struct *work) { struct mdss_pll_resources *pll_res; if (!work) { pr_err("pll_resource is invalid\n"); return; } pr_debug("Starting PLL off Worker%s\n", __func__); pll_res = container_of(work, struct mdss_pll_resources, pll_off); mdss_pll_resource_enable(pll_res, true); pll_20nm_config_powerdown(pll_res->pll_base); mdss_pll_resource_enable(pll_res, false); }
int get_byte_mux_sel(struct mux_clk *clk) { int mux_mode, rc; struct mdss_pll_resources *dsi_pll_res = clk->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } mux_mode = MDSS_PLL_REG_R(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_VREG_CFG) & BIT(1); pr_debug("byte mux mode = %s", mux_mode ? "indirect" : "direct"); mdss_pll_resource_enable(dsi_pll_res, false); return !!mux_mode; }
static int vco_set_rate_20nm(struct clk *c, unsigned long rate) { int rc; struct dsi_pll_vco_clk *vco = to_vco_clk(c); struct mdss_pll_resources *dsi_pll_res = vco->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } pr_debug("Cancel pending pll off work\n"); cancel_work_sync(&dsi_pll_res->pll_off); rc = pll_20nm_vco_set_rate(vco, rate); mdss_pll_resource_enable(dsi_pll_res, false); return rc; }
static int vco_set_rate_hpm(struct clk *c, unsigned long rate) { int rc; struct dsi_pll_vco_clk *vco = to_vco_clk(c); struct mdss_pll_resources *dsi_pll_res = vco->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } dsi_pll_software_reset(dsi_pll_res); rc = vco_set_rate(vco, rate); mdss_pll_resource_enable(dsi_pll_res, false); return rc; }
static void dsi_pll_disable(struct clk *c) { struct dsi_pll_vco_clk *vco = to_vco_clk(c); struct mdss_pll_resources *dsi_pll_res = vco->priv; if (!dsi_pll_res->pll_on && mdss_pll_resource_enable(dsi_pll_res, true)) { pr_err("Failed to enable mdss dsi pll resources\n"); return; } dsi_pll_res->handoff_resources = false; MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x00); mdss_pll_resource_enable(dsi_pll_res, false); dsi_pll_res->pll_on = false; pr_debug("DSI PLL Disabled\n"); return; }
static void hdmi_20nm_vco_unprepare(struct clk *c) { struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c); struct mdss_pll_resources *io = vco->priv; vco->rate_set = false; if (!io) { pr_err("Invalid input parameter\n"); return; } if (!io->pll_on && mdss_pll_resource_enable(io, true)) { pr_err("pll resource can't be enabled\n"); return; } io->handoff_resources = false; mdss_pll_resource_enable(io, false); io->pll_on = false; }
static enum handoff vco_handoff(struct clk *c) { int rc; enum handoff ret = HANDOFF_DISABLED_CLK; struct dsi_pll_vco_clk *vco = to_vco_clk(c); struct mdss_pll_resources *dsi_pll_res = vco->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return ret; } if (dsi_pll_lock_status(dsi_pll_res)) { dsi_pll_res->handoff_resources = true; dsi_pll_res->pll_on = true; c->rate = vco_get_rate(c); ret = HANDOFF_ENABLED_CLK; } else { mdss_pll_resource_enable(dsi_pll_res, false); } return ret; }
static int hdmi_20nm_vco_prepare(struct clk *c) { struct hdmi_pll_vco_clk *vco = to_hdmi_20nm_vco_clk(c); struct mdss_pll_resources *io = vco->priv; int ret = 0; pr_debug("rate=%ld\n", vco->rate); if (!vco->rate_set && vco->rate) ret = hdmi_20nm_vco_set_rate(c, vco->rate); if (!ret) { ret = mdss_pll_resource_enable(io, true); if (ret) pr_err("pll resource can't be enabled\n"); } return ret; }
static int vco_set_rate(struct clk *c, unsigned long rate) { s64 vco_clk_rate = rate; s32 rem; s64 refclk_cfg, frac_n_mode, ref_doubler_en_b; s64 ref_clk_to_pll, div_fbx1000, frac_n_value; s64 sdm_cfg0, sdm_cfg1, sdm_cfg2, sdm_cfg3; s64 gen_vco_clk, cal_cfg10, cal_cfg11; u32 res; int i, rc; struct dsi_pll_vco_clk *vco = to_vco_clk(c); struct mdss_pll_resources *dsi_pll_res = vco->priv; rc = mdss_pll_resource_enable(dsi_pll_res, true); if (rc) { pr_err("Failed to enable mdss dsi pll resources\n"); return rc; } /* Configure the Loop filter resistance */ for (i = 0; i < vco->lpfr_lut_size; i++) if (vco_clk_rate <= vco->lpfr_lut[i].vco_rate) break; if (i == vco->lpfr_lut_size) { pr_err("unable to get loop filter resistance. vco=%ld\n", rate); rc = -EINVAL; goto error; } res = vco->lpfr_lut[i].r; MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_LPFR_CFG, res); /* Loop filter capacitance values : c1 and c2 */ MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_LPFC1_CFG, 0x70); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_LPFC2_CFG, 0x15); div_s64_rem(vco_clk_rate, vco->ref_clk_rate, &rem); if (rem) { refclk_cfg = 0x1; frac_n_mode = 1; ref_doubler_en_b = 0; } else { refclk_cfg = 0x0; frac_n_mode = 0; ref_doubler_en_b = 1; } pr_debug("refclk_cfg = %lld\n", refclk_cfg); ref_clk_to_pll = ((vco->ref_clk_rate * 2 * (refclk_cfg)) + (ref_doubler_en_b * vco->ref_clk_rate)); div_fbx1000 = div_s64((vco_clk_rate * 1000), ref_clk_to_pll); div_s64_rem(div_fbx1000, 1000, &rem); frac_n_value = div_s64((rem * (1 << 16)), 1000); gen_vco_clk = div_s64(div_fbx1000 * ref_clk_to_pll, 1000); pr_debug("ref_clk_to_pll = %lld\n", ref_clk_to_pll); pr_debug("div_fb = %lld\n", div_fbx1000); pr_debug("frac_n_value = %lld\n", frac_n_value); pr_debug("Generated VCO Clock: %lld\n", gen_vco_clk); rem = 0; if (frac_n_mode) { sdm_cfg0 = (0x0 << 5); sdm_cfg0 |= (0x0 & 0x3f); sdm_cfg1 = (div_s64(div_fbx1000, 1000) & 0x3f) - 1; sdm_cfg3 = div_s64_rem(frac_n_value, 256, &rem); sdm_cfg2 = rem; } else { sdm_cfg0 = (0x1 << 5); sdm_cfg0 |= (div_s64(div_fbx1000, 1000) & 0x3f) - 1; sdm_cfg1 = (0x0 & 0x3f); sdm_cfg2 = 0; sdm_cfg3 = 0; } pr_debug("sdm_cfg0=%lld\n", sdm_cfg0); pr_debug("sdm_cfg1=%lld\n", sdm_cfg1); pr_debug("sdm_cfg2=%lld\n", sdm_cfg2); pr_debug("sdm_cfg3=%lld\n", sdm_cfg3); cal_cfg11 = div_s64_rem(gen_vco_clk, 256 * 1000000, &rem); cal_cfg10 = rem / 1000000; pr_debug("cal_cfg10=%lld, cal_cfg11=%lld\n", cal_cfg10, cal_cfg11); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_CHGPUMP_CFG, 0x02); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_CAL_CFG3, 0x2b); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_CAL_CFG4, 0x66); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_LKDET_CFG2, 0x0d); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_SDM_CFG1, (u32)(sdm_cfg1 & 0xff)); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_SDM_CFG2, (u32)(sdm_cfg2 & 0xff)); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_SDM_CFG3, (u32)(sdm_cfg3 & 0xff)); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_SDM_CFG4, 0x00); /* Add hardware recommended delay for correct PLL configuration */ udelay(1); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_REFCLK_CFG, (u32)refclk_cfg); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_PWRGEN_CFG, 0x00); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_VCOLPF_CFG, 0x71); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_SDM_CFG0, (u32)sdm_cfg0); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_CAL_CFG0, 0x12); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_CAL_CFG6, 0x30); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_CAL_CFG7, 0x00); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_CAL_CFG8, 0x60); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_CAL_CFG9, 0x00); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_CAL_CFG10, (u32)(cal_cfg10 & 0xff)); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_CAL_CFG11, (u32)(cal_cfg11 & 0xff)); MDSS_PLL_REG_W(dsi_pll_res->pll_base, DSI_PHY_PLL_UNIPHY_PLL_EFUSE_CFG, 0x20); error: mdss_pll_resource_enable(dsi_pll_res, false); return rc; }