drm/rockchip: Don't change hdmi reference clock rate
[drm/drm-misc.git] / drivers / video / fbdev / omap2 / omapfb / dss / video-pll.c
blobca430ca69ba3e0d0535ee125587ed70b6b1df3a8
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2014 Texas Instruments Ltd
4 */
6 #include <linux/clk.h>
7 #include <linux/delay.h>
8 #include <linux/err.h>
9 #include <linux/io.h>
10 #include <linux/kernel.h>
11 #include <linux/platform_device.h>
12 #include <linux/sched.h>
14 #include <video/omapfb_dss.h>
16 #include "dss.h"
17 #include "dss_features.h"
19 struct dss_video_pll {
20 struct dss_pll pll;
22 struct device *dev;
24 void __iomem *clkctrl_base;
27 #define REG_MOD(reg, val, start, end) \
28 writel_relaxed(FLD_MOD(readl_relaxed(reg), val, start, end), reg)
30 static void dss_dpll_enable_scp_clk(struct dss_video_pll *vpll)
32 REG_MOD(vpll->clkctrl_base, 1, 14, 14); /* CIO_CLK_ICG */
35 static void dss_dpll_disable_scp_clk(struct dss_video_pll *vpll)
37 REG_MOD(vpll->clkctrl_base, 0, 14, 14); /* CIO_CLK_ICG */
40 static void dss_dpll_power_enable(struct dss_video_pll *vpll)
42 REG_MOD(vpll->clkctrl_base, 2, 31, 30); /* PLL_POWER_ON_ALL */
45 * DRA7x PLL CTRL's PLL_PWR_STATUS seems to always return 0,
46 * so we have to use fixed delay here.
48 msleep(1);
51 static void dss_dpll_power_disable(struct dss_video_pll *vpll)
53 REG_MOD(vpll->clkctrl_base, 0, 31, 30); /* PLL_POWER_OFF */
56 static int dss_video_pll_enable(struct dss_pll *pll)
58 struct dss_video_pll *vpll = container_of(pll, struct dss_video_pll, pll);
59 int r;
61 r = dss_runtime_get();
62 if (r)
63 return r;
65 dss_ctrl_pll_enable(pll->id, true);
67 dss_dpll_enable_scp_clk(vpll);
69 r = dss_pll_wait_reset_done(pll);
70 if (r)
71 goto err_reset;
73 dss_dpll_power_enable(vpll);
75 return 0;
77 err_reset:
78 dss_dpll_disable_scp_clk(vpll);
79 dss_ctrl_pll_enable(pll->id, false);
80 dss_runtime_put();
82 return r;
85 static void dss_video_pll_disable(struct dss_pll *pll)
87 struct dss_video_pll *vpll = container_of(pll, struct dss_video_pll, pll);
89 dss_dpll_power_disable(vpll);
91 dss_dpll_disable_scp_clk(vpll);
93 dss_ctrl_pll_enable(pll->id, false);
95 dss_runtime_put();
98 static const struct dss_pll_ops dss_pll_ops = {
99 .enable = dss_video_pll_enable,
100 .disable = dss_video_pll_disable,
101 .set_config = dss_pll_write_config_type_a,
104 static const struct dss_pll_hw dss_dra7_video_pll_hw = {
105 .n_max = (1 << 8) - 1,
106 .m_max = (1 << 12) - 1,
107 .mX_max = (1 << 5) - 1,
108 .fint_min = 500000,
109 .fint_max = 2500000,
110 .clkdco_max = 1800000000,
112 .n_msb = 8,
113 .n_lsb = 1,
114 .m_msb = 20,
115 .m_lsb = 9,
117 .mX_msb[0] = 25,
118 .mX_lsb[0] = 21,
119 .mX_msb[1] = 30,
120 .mX_lsb[1] = 26,
122 .has_refsel = true,
125 struct dss_pll *dss_video_pll_init(struct platform_device *pdev, int id,
126 struct regulator *regulator)
128 const char * const reg_name[] = { "pll1", "pll2" };
129 const char * const clkctrl_name[] = { "pll1_clkctrl", "pll2_clkctrl" };
130 const char * const clkin_name[] = { "video1_clk", "video2_clk" };
132 struct dss_video_pll *vpll;
133 void __iomem *pll_base, *clkctrl_base;
134 struct clk *clk;
135 struct dss_pll *pll;
136 int r;
138 /* PLL CONTROL */
140 pll_base = devm_platform_ioremap_resource_byname(pdev, reg_name[id]);
141 if (IS_ERR(pll_base)) {
142 dev_err(&pdev->dev, "failed to ioremap pll%d reg_name\n", id);
143 return ERR_CAST(pll_base);
146 /* CLOCK CONTROL */
148 clkctrl_base = devm_platform_ioremap_resource_byname(pdev, clkctrl_name[id]);
149 if (IS_ERR(clkctrl_base)) {
150 dev_err(&pdev->dev, "failed to ioremap pll%d clkctrl\n", id);
151 return ERR_CAST(clkctrl_base);
154 /* CLKIN */
156 clk = devm_clk_get(&pdev->dev, clkin_name[id]);
157 if (IS_ERR(clk)) {
158 DSSERR("can't get video pll clkin\n");
159 return ERR_CAST(clk);
162 vpll = devm_kzalloc(&pdev->dev, sizeof(*vpll), GFP_KERNEL);
163 if (!vpll)
164 return ERR_PTR(-ENOMEM);
166 vpll->dev = &pdev->dev;
167 vpll->clkctrl_base = clkctrl_base;
169 pll = &vpll->pll;
171 pll->name = id == 0 ? "video0" : "video1";
172 pll->id = id == 0 ? DSS_PLL_VIDEO1 : DSS_PLL_VIDEO2;
173 pll->clkin = clk;
174 pll->regulator = regulator;
175 pll->base = pll_base;
176 pll->hw = &dss_dra7_video_pll_hw;
177 pll->ops = &dss_pll_ops;
179 r = dss_pll_register(pll);
180 if (r)
181 return ERR_PTR(r);
183 return pll;
186 void dss_video_pll_uninit(struct dss_pll *pll)
188 dss_pll_unregister(pll);