blob: d1b1885cb90a76d9a1180d01b64493499b0f54ce [file] [log] [blame]
Saravana Kannanc85ecf92013-01-21 17:58:35 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Chandan Uddaraju09adf322012-08-16 02:55:23 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/kernel.h>
14#include <linux/io.h>
15#include <linux/err.h>
16#include <linux/delay.h>
17#include <linux/string.h>
18#include <linux/iopoll.h>
19#include <linux/clk.h>
20
21#include <asm/processor.h>
22#include <mach/msm_iomap.h>
Matt Wagantall33d01f52012-02-23 23:27:44 -080023#include <mach/clk-provider.h>
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -070024#include <mach/clk.h>
25#include <mach/clock-generic.h>
Chandan Uddaraju09adf322012-08-16 02:55:23 -070026
Chandan Uddaraju09adf322012-08-16 02:55:23 -070027#include "clock-mdss-8974.h"
28
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -070029#define REG_R(addr) readl_relaxed(addr)
30#define REG_W(data, addr) writel_relaxed(data, addr)
31#define DSS_REG_W(base, offset, data) REG_W((data), (base) + (offset))
32#define DSS_REG_R(base, offset) REG_R((base) + (offset))
Abhishek Kharbandac1559842012-08-13 18:45:02 -070033
Huaibin Yang3931cb72013-07-12 10:48:59 -070034#define GDSC_PHYS 0xFD8C2300
35#define GDSC_SIZE 0x8
Matt Wagantall7cf535b2013-02-28 16:16:51 -080036
Vikram Mulukutla81e17e52013-05-02 20:31:51 -070037#define DSI_PHY_PHYS 0xFD922A00
38#define DSI_PHY_SIZE 0x000000D4
Abhishek Kharbandac1559842012-08-13 18:45:02 -070039
Kuogee Hsieha20087c2013-08-05 17:53:12 -070040#define EDP_PHY_PHYS 0xFD923A00
41#define EDP_PHY_SIZE 0x000000D4
42
Abhishek Kharbandac1559842012-08-13 18:45:02 -070043#define HDMI_PHY_PHYS 0xFD922500
44#define HDMI_PHY_SIZE 0x0000007C
45
46#define HDMI_PHY_PLL_PHYS 0xFD922700
47#define HDMI_PHY_PLL_SIZE 0x000000D4
48
49/* hdmi phy registers */
Ujwal Patelc8017652012-11-15 18:03:01 -080050#define HDMI_PHY_ANA_CFG0 (0x0000)
51#define HDMI_PHY_ANA_CFG1 (0x0004)
52#define HDMI_PHY_ANA_CFG2 (0x0008)
53#define HDMI_PHY_ANA_CFG3 (0x000C)
54#define HDMI_PHY_PD_CTRL0 (0x0010)
55#define HDMI_PHY_PD_CTRL1 (0x0014)
56#define HDMI_PHY_GLB_CFG (0x0018)
57#define HDMI_PHY_DCC_CFG0 (0x001C)
58#define HDMI_PHY_DCC_CFG1 (0x0020)
59#define HDMI_PHY_TXCAL_CFG0 (0x0024)
60#define HDMI_PHY_TXCAL_CFG1 (0x0028)
61#define HDMI_PHY_TXCAL_CFG2 (0x002C)
62#define HDMI_PHY_TXCAL_CFG3 (0x0030)
63#define HDMI_PHY_BIST_CFG0 (0x0034)
64#define HDMI_PHY_BIST_CFG1 (0x0038)
65#define HDMI_PHY_BIST_PATN0 (0x003C)
66#define HDMI_PHY_BIST_PATN1 (0x0040)
67#define HDMI_PHY_BIST_PATN2 (0x0044)
68#define HDMI_PHY_BIST_PATN3 (0x0048)
69#define HDMI_PHY_STATUS (0x005C)
Abhishek Kharbandac1559842012-08-13 18:45:02 -070070
71/* hdmi phy unified pll registers */
Ujwal Patelc8017652012-11-15 18:03:01 -080072#define HDMI_UNI_PLL_REFCLK_CFG (0x0000)
73#define HDMI_UNI_PLL_POSTDIV1_CFG (0x0004)
74#define HDMI_UNI_PLL_CHFPUMP_CFG (0x0008)
75#define HDMI_UNI_PLL_VCOLPF_CFG (0x000C)
76#define HDMI_UNI_PLL_VREG_CFG (0x0010)
77#define HDMI_UNI_PLL_PWRGEN_CFG (0x0014)
78#define HDMI_UNI_PLL_GLB_CFG (0x0020)
79#define HDMI_UNI_PLL_POSTDIV2_CFG (0x0024)
80#define HDMI_UNI_PLL_POSTDIV3_CFG (0x0028)
81#define HDMI_UNI_PLL_LPFR_CFG (0x002C)
82#define HDMI_UNI_PLL_LPFC1_CFG (0x0030)
83#define HDMI_UNI_PLL_LPFC2_CFG (0x0034)
84#define HDMI_UNI_PLL_SDM_CFG0 (0x0038)
85#define HDMI_UNI_PLL_SDM_CFG1 (0x003C)
86#define HDMI_UNI_PLL_SDM_CFG2 (0x0040)
87#define HDMI_UNI_PLL_SDM_CFG3 (0x0044)
88#define HDMI_UNI_PLL_SDM_CFG4 (0x0048)
89#define HDMI_UNI_PLL_SSC_CFG0 (0x004C)
90#define HDMI_UNI_PLL_SSC_CFG1 (0x0050)
91#define HDMI_UNI_PLL_SSC_CFG2 (0x0054)
92#define HDMI_UNI_PLL_SSC_CFG3 (0x0058)
93#define HDMI_UNI_PLL_LKDET_CFG0 (0x005C)
94#define HDMI_UNI_PLL_LKDET_CFG1 (0x0060)
95#define HDMI_UNI_PLL_LKDET_CFG2 (0x0064)
96#define HDMI_UNI_PLL_CAL_CFG0 (0x006C)
97#define HDMI_UNI_PLL_CAL_CFG1 (0x0070)
98#define HDMI_UNI_PLL_CAL_CFG2 (0x0074)
99#define HDMI_UNI_PLL_CAL_CFG3 (0x0078)
100#define HDMI_UNI_PLL_CAL_CFG4 (0x007C)
101#define HDMI_UNI_PLL_CAL_CFG5 (0x0080)
102#define HDMI_UNI_PLL_CAL_CFG6 (0x0084)
103#define HDMI_UNI_PLL_CAL_CFG7 (0x0088)
104#define HDMI_UNI_PLL_CAL_CFG8 (0x008C)
105#define HDMI_UNI_PLL_CAL_CFG9 (0x0090)
106#define HDMI_UNI_PLL_CAL_CFG10 (0x0094)
107#define HDMI_UNI_PLL_CAL_CFG11 (0x0098)
108#define HDMI_UNI_PLL_STATUS (0x00C0)
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700109
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -0700110#define DSI_0_PHY_PLL_UNIPHY_PLL_REFCLK_CFG (0x00000000)
111#define DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV1_CFG (0x00000004)
112#define DSI_0_PHY_PLL_UNIPHY_PLL_CHGPUMP_CFG (0x00000008)
113#define DSI_0_PHY_PLL_UNIPHY_PLL_VCOLPF_CFG (0x0000000C)
114#define DSI_0_PHY_PLL_UNIPHY_PLL_VREG_CFG (0x00000010)
115#define DSI_0_PHY_PLL_UNIPHY_PLL_PWRGEN_CFG (0x00000014)
116#define DSI_0_PHY_PLL_UNIPHY_PLL_DMUX_CFG (0x00000018)
117#define DSI_0_PHY_PLL_UNIPHY_PLL_AMUX_CFG (0x0000001C)
118#define DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG (0x00000020)
119#define DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV2_CFG (0x00000024)
120#define DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV3_CFG (0x00000028)
121#define DSI_0_PHY_PLL_UNIPHY_PLL_LPFR_CFG (0x0000002C)
122#define DSI_0_PHY_PLL_UNIPHY_PLL_LPFC1_CFG (0x00000030)
123#define DSI_0_PHY_PLL_UNIPHY_PLL_LPFC2_CFG (0x00000034)
124#define DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG0 (0x00000038)
125#define DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG1 (0x0000003C)
126#define DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG2 (0x00000040)
127#define DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG3 (0x00000044)
128#define DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG4 (0x00000048)
129#define DSI_0_PHY_PLL_UNIPHY_PLL_SSC_CFG0 (0x0000004C)
130#define DSI_0_PHY_PLL_UNIPHY_PLL_SSC_CFG1 (0x00000050)
131#define DSI_0_PHY_PLL_UNIPHY_PLL_SSC_CFG2 (0x00000054)
132#define DSI_0_PHY_PLL_UNIPHY_PLL_SSC_CFG3 (0x00000058)
133#define DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG0 (0x0000005C)
134#define DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG1 (0x00000060)
135#define DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2 (0x00000064)
136#define DSI_0_PHY_PLL_UNIPHY_PLL_TEST_CFG (0x00000068)
137#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG0 (0x0000006C)
138#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG1 (0x00000070)
139#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG2 (0x00000074)
140#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG3 (0x00000078)
141#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG4 (0x0000007C)
142#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG5 (0x00000080)
143#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG6 (0x00000084)
144#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG7 (0x00000088)
145#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG8 (0x0000008C)
146#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG9 (0x00000090)
147#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG10 (0x00000094)
148#define DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG11 (0x00000098)
149#define DSI_0_PHY_PLL_UNIPHY_PLL_EFUSE_CFG (0x0000009C)
150#define DSI_0_PHY_PLL_UNIPHY_PLL_STATUS (0x000000C0)
151
152#define PLL_POLL_MAX_READS 10
153#define PLL_POLL_TIMEOUT_US 50
154
155static long vco_cached_rate;
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700156static unsigned char *mdss_dsi_base;
Matt Wagantall7cf535b2013-02-28 16:16:51 -0800157static unsigned char *gdsc_base;
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -0700158static struct clk *mdss_ahb_clk;
Kuogee Hsieha20087c2013-08-05 17:53:12 -0700159static unsigned char *mdss_edp_base;
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700160
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700161static void __iomem *hdmi_phy_base;
162static void __iomem *hdmi_phy_pll_base;
163static unsigned hdmi_pll_on;
164
Matt Wagantall7cf535b2013-02-28 16:16:51 -0800165static int mdss_gdsc_enabled(void)
166{
167 if (!gdsc_base)
168 return 0;
169
Huaibin Yang3931cb72013-07-12 10:48:59 -0700170 return (readl_relaxed(gdsc_base + 0x4) & BIT(31)) &&
171 (!(readl_relaxed(gdsc_base) & BIT(0)));
Matt Wagantall7cf535b2013-02-28 16:16:51 -0800172}
173
Ajay Singh Parmar6e090282013-09-30 21:43:57 -0700174/* Auto PLL calibaration */
175static int mdss_ahb_clk_enable(int enable)
176{
177 int rc = 0;
178
179 /* todo: Ideally, we should enable/disable GDSC whenever we are
180 * attempting to enable/disable MDSS AHB clock.
181 * For now, just return error if GDSC is not enabled.
182 */
183 if (!mdss_gdsc_enabled()) {
184 pr_err("%s: mdss GDSC is not enabled\n", __func__);
185 return -EPERM;
186 }
187
188 if (enable)
189 rc = clk_prepare_enable(mdss_ahb_clk);
190 else
191 clk_disable_unprepare(mdss_ahb_clk);
192
193 return rc;
194}
195
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700196static void hdmi_vco_disable(struct clk *c)
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700197{
Ajay Singh Parmar6e090282013-09-30 21:43:57 -0700198 u32 rc;
199
200 if (!mdss_gdsc_enabled()) {
201 pr_err("%s: mdss GDSC is not enabled\n", __func__);
202 return;
203 }
204
205 rc = clk_enable(mdss_ahb_clk);
206 if (rc) {
207 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
208 __func__, rc);
209 return;
210 }
211
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700212 REG_W(0x0, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
213 udelay(5);
214 REG_W(0x0, hdmi_phy_base + HDMI_PHY_GLB_CFG);
Ajay Singh Parmar6e090282013-09-30 21:43:57 -0700215
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -0700216 clk_disable(mdss_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700217
218 hdmi_pll_on = 0;
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700219} /* hdmi_vco_disable */
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700220
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700221static int hdmi_vco_enable(struct clk *c)
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700222{
223 u32 status;
Ajay Singh Parmar6e090282013-09-30 21:43:57 -0700224 u32 rc;
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700225 u32 max_reads, timeout_us;
226
Ajay Singh Parmar6e090282013-09-30 21:43:57 -0700227 if (!mdss_gdsc_enabled()) {
228 pr_err("%s: mdss GDSC is not enabled\n", __func__);
229 return -EPERM;
230 }
231
232 rc = clk_enable(mdss_ahb_clk);
233 if (rc) {
234 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
235 __func__, rc);
236 return rc;
237 }
238
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700239 /* Global Enable */
240 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
241 /* Power up power gen */
242 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
243 udelay(350);
244
245 /* PLL Power-Up */
246 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
247 udelay(5);
248 /* Power up PLL LDO */
249 REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
250 udelay(350);
251
252 /* PLL Power-Up */
253 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
254 udelay(350);
255
256 /* poll for PLL ready status */
257 max_reads = 20;
258 timeout_us = 100;
259 if (readl_poll_timeout_noirq((hdmi_phy_pll_base + HDMI_UNI_PLL_STATUS),
260 status, ((status & BIT(0)) == 1), max_reads, timeout_us)) {
261 pr_err("%s: hdmi phy pll status=%x failed to Lock\n",
262 __func__, status);
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700263 hdmi_vco_disable(c);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -0700264 clk_disable(mdss_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700265 return -EINVAL;
266 }
267 pr_debug("%s: hdmi phy pll is locked\n", __func__);
268
269 udelay(350);
270 /* poll for PHY ready status */
271 max_reads = 20;
272 timeout_us = 100;
273 if (readl_poll_timeout_noirq((hdmi_phy_base + HDMI_PHY_STATUS),
274 status, ((status & BIT(0)) == 1), max_reads, timeout_us)) {
275 pr_err("%s: hdmi phy status=%x failed to Lock\n",
276 __func__, status);
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700277 hdmi_vco_disable(c);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -0700278 clk_disable(mdss_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700279 return -EINVAL;
280 }
281 pr_debug("%s: hdmi phy is locked\n", __func__);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -0700282 clk_disable(mdss_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700283
284 hdmi_pll_on = 1;
285
286 return 0;
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700287} /* hdmi_vco_enable */
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700288
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700289static inline struct hdmi_pll_vco_clk *to_hdmi_vco_clk(struct clk *clk)
290{
291 return container_of(clk, struct hdmi_pll_vco_clk, c);
292}
293
Ajay Singh Parmarc4d53dc2013-09-03 17:19:16 -0700294static void hdmi_phy_pll_calculator(u32 vco_freq)
295{
296 u32 ref_clk = 19200000;
297 u32 sdm_mode = 1;
298 u32 ref_clk_multiplier = sdm_mode == 1 ? 2 : 1;
299 u32 int_ref_clk_freq = ref_clk * ref_clk_multiplier;
300 u32 fbclk_pre_div = 1;
301 u32 ssc_mode = 0;
302 u32 kvco = 270;
303 u32 vdd = 95;
304 u32 ten_power_six = 1000000;
305 u32 ssc_ds_ppm = ssc_mode ? 5000 : 0;
306 u32 sdm_res = 16;
307 u32 ssc_tri_step = 32;
308 u32 ssc_freq = 2;
309 u64 ssc_ds = vco_freq * ssc_ds_ppm;
310 u32 div_in_freq = vco_freq / fbclk_pre_div;
311 u64 dc_offset = (div_in_freq / int_ref_clk_freq - 1) *
312 ten_power_six * 10;
313 u32 ssc_kdiv = (int_ref_clk_freq / ssc_freq) -
314 ten_power_six;
315 u64 sdm_freq_seed;
316 u32 ssc_tri_inc;
317 u64 fb_div_n;
318
319 u32 val;
320
321 pr_debug("%s: vco_freq = %u\n", __func__, vco_freq);
322
323 do_div(ssc_ds, (u64)ten_power_six);
324
325 fb_div_n = (u64)div_in_freq * (u64)ten_power_six * 10;
326 do_div(fb_div_n, int_ref_clk_freq);
327
328 sdm_freq_seed = ((fb_div_n - dc_offset - ten_power_six * 10) *
329 (1 << sdm_res) * 10) + 5;
330 do_div(sdm_freq_seed, ((u64)ten_power_six * 100));
331
332 ssc_tri_inc = (u32)ssc_ds;
333 ssc_tri_inc = (ssc_tri_inc / int_ref_clk_freq) * (1 << 16) /
334 ssc_tri_step;
335
336 val = (ref_clk_multiplier == 2 ? 1 : 0) +
337 ((fbclk_pre_div == 2 ? 1 : 0) * 16);
338 pr_debug("%s: HDMI_UNI_PLL_REFCLK_CFG = 0x%x\n", __func__, val);
339 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
340
341 REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CHFPUMP_CFG);
342 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
343 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
344 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_PWRGEN_CFG);
345 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
346 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
347 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
348 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
349 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
350
351 do_div(dc_offset, (u64)ten_power_six * 10);
352 val = sdm_mode == 0 ? 64 + dc_offset : 0;
353 pr_debug("%s: HDMI_UNI_PLL_SDM_CFG0 = 0x%x\n", __func__, val);
354 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
355
356 val = 64 + dc_offset;
357 pr_debug("%s: HDMI_UNI_PLL_SDM_CFG1 = 0x%x\n", __func__, val);
358 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
359
360 val = sdm_freq_seed & 0xFF;
361 pr_debug("%s: HDMI_UNI_PLL_SDM_CFG2 = 0x%x\n", __func__, val);
362 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
363
364 val = (sdm_freq_seed >> 8) & 0xFF;
365 pr_debug("%s: HDMI_UNI_PLL_SDM_CFG3 = 0x%x\n", __func__, val);
366 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
367
368 val = (sdm_freq_seed >> 16) & 0xFF;
369 pr_debug("%s: HDMI_UNI_PLL_SDM_CFG4 = 0x%x\n", __func__, val);
370 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
371
372 val = (ssc_mode == 0 ? 128 : 0) + (ssc_kdiv / ten_power_six);
373 pr_debug("%s: HDMI_UNI_PLL_SSC_CFG0 = 0x%x\n", __func__, val);
374 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_SSC_CFG0);
375
376 val = ssc_tri_inc & 0xFF;
377 pr_debug("%s: HDMI_UNI_PLL_SSC_CFG1 = 0x%x\n", __func__, val);
378 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_SSC_CFG1);
379
380 val = (ssc_tri_inc >> 8) & 0xFF;
381 pr_debug("%s: HDMI_UNI_PLL_SSC_CFG2 = 0x%x\n", __func__, val);
382 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_SSC_CFG2);
383
384 pr_debug("%s: HDMI_UNI_PLL_SSC_CFG3 = 0x%x\n", __func__, ssc_tri_step);
385 REG_W(ssc_tri_step, hdmi_phy_pll_base + HDMI_UNI_PLL_SSC_CFG3);
386
387 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
388 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
389 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
390 REG_W(0x0A, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG0);
391 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG1);
392 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
393 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG3);
394 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG4);
395 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG5);
396
397 val = (kvco * vdd * 10000) / 6;
398 val += 500000;
399 val /= ten_power_six;
400 pr_debug("%s: HDMI_UNI_PLL_CAL_CFG6 = 0x%x\n", __func__, val);
401 REG_W(val & 0xFF, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG6);
402
403 val = (kvco * vdd * 10000) / 6;
404 val -= ten_power_six;
405 val /= ten_power_six;
406 val = (val >> 8) & 0xFF;
407 pr_debug("%s: HDMI_UNI_PLL_CAL_CFG7 = 0x%x\n", __func__, val);
408 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG7);
409
410 val = (ref_clk * 5) / ten_power_six;
411 pr_debug("%s: HDMI_UNI_PLL_CAL_CFG8 = 0x%x\n", __func__, val);
412 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
413
414 val = ((ref_clk * 5) / ten_power_six) >> 8;
415 pr_debug("%s: HDMI_UNI_PLL_CAL_CFG9 = 0x%x\n", __func__, val);
416 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
417
418 vco_freq /= ten_power_six;
419 val = vco_freq & 0xFF;
420 pr_debug("%s: HDMI_UNI_PLL_CAL_CFG10 = 0x%x\n", __func__, val);
421 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
422
423 val = vco_freq >> 8;
424 pr_debug("%s: HDMI_UNI_PLL_CAL_CFG11 = 0x%x\n", __func__, val);
425 REG_W(val, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
426} /* hdmi_phy_pll_calculator */
427
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700428static int hdmi_vco_set_rate(struct clk *c, unsigned long rate)
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700429{
430 unsigned int set_power_dwn = 0;
Ajay Singh Parmar6e090282013-09-30 21:43:57 -0700431 int rc = 0;
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700432
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700433 struct hdmi_pll_vco_clk *vco = to_hdmi_vco_clk(c);
434
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700435 if (hdmi_pll_on) {
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700436 hdmi_vco_disable(c);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700437 set_power_dwn = 1;
438 }
439
Ajay Singh Parmar6e090282013-09-30 21:43:57 -0700440 rc = mdss_ahb_clk_enable(1);
441 if (rc) {
442 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
443 __func__, rc);
444 return rc;
445 }
446
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700447 pr_debug("%s: rate=%ld\n", __func__, rate);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700448
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700449 switch (rate) {
Ajay Singh Parmarc4d53dc2013-09-03 17:19:16 -0700450 case 0:
451 break;
452
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700453 case 756000000:
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700454 /* 640x480p60 */
Ujwal Patelc8017652012-11-15 18:03:01 -0800455 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
456 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
457 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
458 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
459 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
460 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
461 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
462 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
463 REG_W(0x52, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700464 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
Ujwal Patelc8017652012-11-15 18:03:01 -0800465 REG_W(0xB0, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700466 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
467 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
468 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
469 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700470 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
471 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
Ujwal Patelc8017652012-11-15 18:03:01 -0800472 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700473 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
474 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
Ujwal Patelc8017652012-11-15 18:03:01 -0800475 REG_W(0xF4, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
476 REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
477 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
478 udelay(50);
479
480 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
481 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
482 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
483 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
484 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
485 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
486 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
487 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
488 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
489 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
490 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
491 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
492 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
493 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
494 udelay(200);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700495 break;
496
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700497 case 810000000:
Ujwal Patele698fae2012-11-29 14:04:33 -0800498 /* 576p50/576i50 case */
499 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
500 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
501 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
502 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
503 REG_W(0X0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
504 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
505 REG_W(0X0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
506 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
507 REG_W(0x54, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
508 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
509 REG_W(0x18, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
510 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
511 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
512 REG_W(0X1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
513 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
Ujwal Patele698fae2012-11-29 14:04:33 -0800514 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
515 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
516 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
517 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
518 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
519 REG_W(0x2a, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
520 REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
521 REG_W(0X1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
522 udelay(50);
523
524 REG_W(0X0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
525 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
526 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
527 REG_W(0XDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
528 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
529 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
530 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
531 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
532 REG_W(0XD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
533 REG_W(0X1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
534 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
535 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
536 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
537 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
538 udelay(200);
539 break;
540
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700541 case 810900000:
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700542 /* 480p60/480i60 case */
Ujwal Patelc8017652012-11-15 18:03:01 -0800543 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
544 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
545 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
546 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
547 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
548 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
549 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
550 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
551 REG_W(0x54, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
552 REG_W(0x66, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700553 REG_W(0x1D, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
554 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
555 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
556 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
557 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700558 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
559 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
Ujwal Patelc8017652012-11-15 18:03:01 -0800560 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700561 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
562 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
563 REG_W(0x2A, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
564 REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
Ujwal Patelc8017652012-11-15 18:03:01 -0800565 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
566 udelay(50);
567
568 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
569 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
570 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
571 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
572 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
573 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
574 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
575 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
576 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
577 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
578 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
579 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
580 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
581 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
582 udelay(200);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700583 break;
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700584 case 650000000:
Manoj Rao6c1d2792013-05-08 11:59:38 -0700585 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
586 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
587 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
588 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
589 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
590 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
591 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
592 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
593 REG_W(0x4F, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
594 REG_W(0x55, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
595 REG_W(0xED, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
596 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
597 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
598 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
599 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
Manoj Rao6c1d2792013-05-08 11:59:38 -0700600 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
601 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
602 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
603 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
604 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
605 REG_W(0x8A, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
606 REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
607 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
608 udelay(50);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700609
Manoj Rao6c1d2792013-05-08 11:59:38 -0700610 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
611 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
612 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
613 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
614 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
615 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
616 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
617 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
618 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
619 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
620 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
621 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
622 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
623 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
624 udelay(200);
625 break;
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700626 case 742500000:
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700627 /*
628 * 720p60/720p50/1080i60/1080i50
629 * 1080p24/1080p30/1080p25 case
630 */
Ujwal Patelc8017652012-11-15 18:03:01 -0800631 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
632 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
633 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
634 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
635 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
636 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
637 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
638 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700639 REG_W(0x52, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
Ujwal Patelc8017652012-11-15 18:03:01 -0800640 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
641 REG_W(0x56, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700642 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
643 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
644 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
645 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700646 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
647 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
Ujwal Patelc8017652012-11-15 18:03:01 -0800648 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700649 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
650 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
651 REG_W(0xE6, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
652 REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
Ujwal Patelc8017652012-11-15 18:03:01 -0800653 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
654 udelay(50);
655
656 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
657 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
658 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
659 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
660 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
661 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
662 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
663 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
664 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
665 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
666 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
667 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
668 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
669 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
670 udelay(200);
671 break;
672
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700673 case 1080000000:
Manoj Rao6c1d2792013-05-08 11:59:38 -0700674 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
675 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
676 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
677 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
678 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
679 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
680 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
681 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
682 REG_W(0x5B, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
683 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
684 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
685 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
686 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
687 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
688 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
Manoj Rao6c1d2792013-05-08 11:59:38 -0700689 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
690 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
691 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
692 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
693 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
694 REG_W(0x38, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
695 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
696 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
697 udelay(50);
698
699 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
700 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
701 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
702 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
703 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
704 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
705 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
706 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
707 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
708 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
709 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
710 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
711 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
712 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
713 udelay(200);
714 break;
715
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700716 case 1342500000:
Ujwal Patele698fae2012-11-29 14:04:33 -0800717 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
718 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
719 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
720 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
721 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
722 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
723 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
724 REG_W(0x36, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
725 REG_W(0x61, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
726 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
727 REG_W(0xF6, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
728 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
729 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
730 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
731 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
Ujwal Patele698fae2012-11-29 14:04:33 -0800732 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
733 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
734 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
735 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
736 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
737 REG_W(0x3E, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
738 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
739 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
740 udelay(50);
741
742 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
743 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
744 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
745 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
746 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
747 REG_W(0x05, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
748 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
749 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
750 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
751 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
752 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
753 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
754 REG_W(0x11, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
755 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
756 udelay(200);
757 break;
758
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700759 case 1485000000:
Ujwal Patelc8017652012-11-15 18:03:01 -0800760 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
761 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
762 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
763 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
764 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
765 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
766 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
767 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700768 REG_W(0x65, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
Ujwal Patelc8017652012-11-15 18:03:01 -0800769 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700770 REG_W(0xAC, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
771 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
772 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
773 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
774 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700775 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
776 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
Ujwal Patelc8017652012-11-15 18:03:01 -0800777 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700778 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
779 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
780 REG_W(0xCD, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
781 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
Ujwal Patelc8017652012-11-15 18:03:01 -0800782 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
783 udelay(50);
784
785 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
786 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
787 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
788 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
789 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
790 REG_W(0x06, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
791 REG_W(0x03, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
792 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
793 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
794 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
795 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
796 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
797 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
798 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
799 udelay(200);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700800 break;
801
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700802 default:
Ajay Singh Parmarc4d53dc2013-09-03 17:19:16 -0700803 pr_debug("%s: Use pll settings calculator for rate=%ld\n",
804 __func__, rate);
805
806 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
807 hdmi_phy_pll_calculator(rate);
808 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
809 udelay(50);
810
811 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
812 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
813 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
814 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
815 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
816
817 if (rate < 825000000) {
818 REG_W(0x01, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
819 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
820 } else if (rate >= 825000000 && rate < 1342500000) {
821 REG_W(0x05, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
822 REG_W(0x03, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
823 } else {
824 REG_W(0x06, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
825 REG_W(0x03, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
826 }
827
828 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
829 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
830 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
831 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
832 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
833
834 if (rate < 825000000)
835 REG_W(0x01, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
836 else
837 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
838
839 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
840 REG_W(0x62, hdmi_phy_base + HDMI_PHY_BIST_PATN0);
841 REG_W(0x03, hdmi_phy_base + HDMI_PHY_BIST_PATN1);
842 REG_W(0x69, hdmi_phy_base + HDMI_PHY_BIST_PATN2);
843 REG_W(0x02, hdmi_phy_base + HDMI_PHY_BIST_PATN3);
844
845 udelay(200);
846
847 REG_W(0x00, hdmi_phy_base + HDMI_PHY_BIST_CFG1);
848 REG_W(0x00, hdmi_phy_base + HDMI_PHY_BIST_CFG0);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700849 }
850
851 /* Make sure writes complete before disabling iface clock */
852 mb();
853
Ajay Singh Parmar6e090282013-09-30 21:43:57 -0700854 mdss_ahb_clk_enable(0);
Vikram Mulukutla5d581bd2012-11-30 11:51:41 -0800855
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700856 if (set_power_dwn)
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -0700857 hdmi_vco_enable(c);
858
859 vco->rate = rate;
860 vco->rate_set = true;
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700861
862 return 0;
863} /* hdmi_pll_set_rate */
864
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -0700865int set_byte_mux_sel(struct mux_clk *clk, int sel)
866{
867 pr_debug("%s: byte mux set to %s mode\n", __func__,
868 sel ? "indirect" : "direct");
869 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_VREG_CFG,
870 (sel << 1));
871 return 0;
872}
873
874int get_byte_mux_sel(struct mux_clk *clk)
875{
876 int mux_mode;
877
878 if (mdss_ahb_clk_enable(1)) {
879 pr_debug("%s: Failed to enable mdss ahb clock\n", __func__);
880 return 0;
881 }
882
883 mux_mode = DSS_REG_R(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_VREG_CFG)
884 & BIT(1);
885 pr_debug("%s: byte mux mode = %s", __func__,
886 mux_mode ? "indirect" : "direct");
887
888 mdss_ahb_clk_enable(0);
889 return !!mux_mode;
890}
891
892static inline struct dsi_pll_vco_clk *to_vco_clk(struct clk *clk)
893{
894 return container_of(clk, struct dsi_pll_vco_clk, c);
895}
896
897/*
898 * When the display is turned off, the display registers are wiped out.
899 * Temporarily use the prepare ops to restore the register values.
900 *
901*/
902int div_prepare(struct clk *c)
903{
904 struct div_clk *div = to_div_clk(c);
905 /* Restore the divider's value */
Patrick Daly86abe9b2013-09-03 18:55:37 -0700906 return div->ops->set_div(div, div->data.div);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -0700907}
908
909int mux_prepare(struct clk *c)
910{
911 struct mux_clk *mux = to_mux_clk(c);
912 int i, rc, sel = 0;
913
914 rc = mdss_ahb_clk_enable(1);
915 if (rc) {
916 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
917 __func__, rc);
918 return rc;
919 }
920
921 for (i = 0; i < mux->num_parents; i++)
922 if (mux->parents[i].src == c->parent) {
923 sel = mux->parents[i].sel;
924 break;
925 }
926
927 if (i == mux->num_parents) {
928 rc = -EINVAL;
929 goto error;
930 }
931
932 /* Restore the mux source select value */
933 rc = mux->ops->set_mux_sel(mux, sel);
934
935error:
936 mdss_ahb_clk_enable(0);
937 return rc;
938}
939
940static int fixed_4div_set_div(struct div_clk *clk, int div)
941{
942 int rc = 0;
943
944 rc = mdss_ahb_clk_enable(1);
945 if (rc) {
946 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
947 __func__, rc);
948 return rc;
949 }
950
951 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV2_CFG,
952 (div - 1));
953
954 mdss_ahb_clk_enable(0);
955 return 0;
956}
957
958static int fixed_4div_get_div(struct div_clk *clk)
959{
960 int div = 0;
961
962 if (mdss_ahb_clk_enable(1)) {
963 pr_debug("%s: Failed to enable mdss ahb clock\n", __func__);
964 return 1;
965 }
966 div = DSS_REG_R(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV2_CFG);
967 mdss_ahb_clk_enable(0);
968 return div + 1;
969}
970
971static int digital_set_div(struct div_clk *clk, int div)
972{
973 int rc = 0;
974
975 rc = mdss_ahb_clk_enable(1);
976 if (rc) {
977 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
978 __func__, rc);
979 return rc;
980 }
981
982 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV3_CFG,
983 (div - 1));
984
985 mdss_ahb_clk_enable(0);
986 return 0;
987}
988
989static int digital_get_div(struct div_clk *clk)
990{
991 int div = 0;
992
993 if (mdss_ahb_clk_enable(1)) {
994 pr_debug("%s: Failed to enable mdss ahb clock\n", __func__);
995 return 1;
996 }
997 div = DSS_REG_R(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV3_CFG);
998 mdss_ahb_clk_enable(0);
999 return div + 1;
1000}
1001
1002static int analog_set_div(struct div_clk *clk, int div)
1003{
1004 int rc = 0;
1005
1006 rc = mdss_ahb_clk_enable(1);
1007 if (rc) {
1008 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
1009 __func__, rc);
1010 return rc;
1011 }
1012
1013 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV1_CFG,
1014 div - 1);
1015
1016 mdss_ahb_clk_enable(0);
1017 return 0;
1018}
1019
1020static int analog_get_div(struct div_clk *clk)
1021{
1022 int div = 0;
1023
1024 if (mdss_ahb_clk_enable(1)) {
1025 pr_debug("%s: Failed to enable mdss ahb clock\n", __func__);
1026 return 1;
1027 }
1028 div = DSS_REG_R(mdss_dsi_base,
1029 DSI_0_PHY_PLL_UNIPHY_PLL_POSTDIV1_CFG) + 1;
1030 mdss_ahb_clk_enable(0);
1031 return div;
1032}
1033
Aravind Venkateswaranb38f8302013-06-27 16:49:44 -07001034static void dsi_pll_toggle_lock_detect(void)
1035{
1036 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2,
1037 0x05);
1038 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2,
1039 0x04);
1040 udelay(1);
1041 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2,
1042 0x05);
1043}
1044
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001045static int dsi_pll_lock_status(void)
1046{
1047 u32 status;
1048 int pll_locked = 0;
1049
1050 /* poll for PLL ready status */
1051 if (readl_poll_timeout_noirq((mdss_dsi_base +
1052 DSI_0_PHY_PLL_UNIPHY_PLL_STATUS),
1053 status,
1054 ((status & BIT(0)) == 1),
1055 PLL_POLL_MAX_READS, PLL_POLL_TIMEOUT_US)) {
1056 pr_debug("%s: DSI PLL status=%x failed to Lock\n",
1057 __func__, status);
1058 pll_locked = 0;
1059 } else {
1060 pll_locked = 1;
1061 }
1062
1063 return pll_locked;
1064}
1065
Aravind Venkateswaranfe2fa6e2013-07-06 22:42:58 -07001066static inline int dsi_pll_toggle_lock_detect_and_check_status(void)
1067{
1068 dsi_pll_toggle_lock_detect();
1069 return dsi_pll_lock_status();
1070}
1071
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001072static void dsi_pll_software_reset(void)
1073{
1074 /*
1075 * Add HW recommended delays after toggling the software
1076 * reset bit off and back on.
1077 */
1078 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_TEST_CFG, 0x01);
1079 udelay(1000);
1080 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_TEST_CFG, 0x00);
1081 udelay(1000);
1082}
1083
1084static int dsi_pll_enable_seq_m(void)
1085{
1086 int i = 0;
1087 int pll_locked = 0;
1088
1089 dsi_pll_software_reset();
1090
1091 /*
1092 * Add hardware recommended delays between register writes for
1093 * the updates to take effect. These delays are necessary for the
1094 * PLL to successfully lock
1095 */
1096 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01);
1097 udelay(200);
1098 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05);
1099 udelay(200);
1100 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f);
1101 udelay(1000);
1102
Aravind Venkateswaranfe2fa6e2013-07-06 22:42:58 -07001103 pll_locked = dsi_pll_toggle_lock_detect_and_check_status();
Aravind Venkateswarand3f41e52013-06-18 12:07:14 -07001104 for (i = 0; (i < 4) && !pll_locked; i++) {
1105 DSS_REG_W(mdss_dsi_base,
1106 DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x07);
1107 if (i != 0)
1108 DSS_REG_W(mdss_dsi_base,
1109 DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG1, 0x34);
1110 udelay(1);
1111 DSS_REG_W(mdss_dsi_base,
1112 DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f);
1113 udelay(1000);
Aravind Venkateswaranfe2fa6e2013-07-06 22:42:58 -07001114 pll_locked = dsi_pll_toggle_lock_detect_and_check_status();
Aravind Venkateswarand3f41e52013-06-18 12:07:14 -07001115 }
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001116
1117 if (pll_locked)
1118 pr_debug("%s: PLL Locked at attempt #%d\n", __func__, i);
1119 else
1120 pr_debug("%s: PLL failed to lock after %d attempt(s)\n",
1121 __func__, i);
1122
1123 return pll_locked ? 0 : -EINVAL;
1124}
1125
1126static int dsi_pll_enable_seq_d(void)
1127{
1128 int pll_locked = 0;
1129
1130 dsi_pll_software_reset();
1131
1132 /*
1133 * Add hardware recommended delays between register writes for
1134 * the updates to take effect. These delays are necessary for the
1135 * PLL to successfully lock
1136 */
1137 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01);
Aravind Venkateswarand3f41e52013-06-18 12:07:14 -07001138 udelay(200);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001139 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05);
Aravind Venkateswarand3f41e52013-06-18 12:07:14 -07001140 udelay(200);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001141 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x07);
Aravind Venkateswarand3f41e52013-06-18 12:07:14 -07001142 udelay(200);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001143 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05);
Aravind Venkateswarand3f41e52013-06-18 12:07:14 -07001144 udelay(200);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001145 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x07);
Aravind Venkateswarand3f41e52013-06-18 12:07:14 -07001146 udelay(200);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001147 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f);
Aravind Venkateswarand3f41e52013-06-18 12:07:14 -07001148 udelay(1000);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001149
Aravind Venkateswaranfe2fa6e2013-07-06 22:42:58 -07001150 pll_locked = dsi_pll_toggle_lock_detect_and_check_status();
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001151 pr_debug("%s: PLL status = %s\n", __func__,
1152 pll_locked ? "Locked" : "Unlocked");
1153
1154 return pll_locked ? 0 : -EINVAL;
1155}
1156
1157static int dsi_pll_enable_seq_f1(void)
1158{
1159 int pll_locked = 0;
1160
1161 dsi_pll_software_reset();
1162
1163 /*
1164 * Add hardware recommended delays between register writes for
1165 * the updates to take effect. These delays are necessary for the
1166 * PLL to successfully lock
1167 */
1168 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01);
1169 udelay(200);
1170 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05);
1171 udelay(200);
1172 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f);
1173 udelay(200);
1174 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0d);
1175 udelay(200);
1176 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f);
1177 udelay(1000);
1178
Aravind Venkateswaranfe2fa6e2013-07-06 22:42:58 -07001179 pll_locked = dsi_pll_toggle_lock_detect_and_check_status();
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001180 pr_debug("%s: PLL status = %s\n", __func__,
1181 pll_locked ? "Locked" : "Unlocked");
1182
1183 return pll_locked ? 0 : -EINVAL;
1184}
1185
1186static int dsi_pll_enable_seq_c(void)
1187{
1188 int pll_locked = 0;
1189
1190 dsi_pll_software_reset();
1191
1192 /*
1193 * Add hardware recommended delays between register writes for
1194 * the updates to take effect. These delays are necessary for the
1195 * PLL to successfully lock
1196 */
1197 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01);
1198 udelay(200);
1199 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05);
1200 udelay(200);
1201 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f);
1202 udelay(1000);
1203
Aravind Venkateswaranfe2fa6e2013-07-06 22:42:58 -07001204 pll_locked = dsi_pll_toggle_lock_detect_and_check_status();
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001205 pr_debug("%s: PLL status = %s\n", __func__,
1206 pll_locked ? "Locked" : "Unlocked");
1207
1208 return pll_locked ? 0 : -EINVAL;
1209}
1210
1211static int dsi_pll_enable_seq_e(void)
1212{
1213 int pll_locked = 0;
1214
1215 dsi_pll_software_reset();
1216
1217 /*
1218 * Add hardware recommended delays between register writes for
1219 * the updates to take effect. These delays are necessary for the
1220 * PLL to successfully lock
1221 */
1222 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01);
1223 udelay(200);
1224 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05);
1225 udelay(200);
1226 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0d);
Aravind Venkateswarand3f41e52013-06-18 12:07:14 -07001227 udelay(1);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001228 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f);
1229 udelay(1000);
1230
Aravind Venkateswaranfe2fa6e2013-07-06 22:42:58 -07001231 pll_locked = dsi_pll_toggle_lock_detect_and_check_status();
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001232 pr_debug("%s: PLL status = %s\n", __func__,
1233 pll_locked ? "Locked" : "Unlocked");
1234
1235 return pll_locked ? 0 : -EINVAL;
1236}
1237
1238static int dsi_pll_enable_seq_8974(void)
1239{
1240 int i, rc = 0;
1241 u32 status, max_reads, timeout_us;
1242
1243 dsi_pll_software_reset();
1244
1245 /*
1246 * PLL power up sequence.
1247 * Add necessary delays recommeded by hardware.
1248 */
1249 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x01);
1250 udelay(1000);
1251 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x05);
1252 udelay(1000);
1253 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x07);
1254 udelay(1000);
1255 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x0f);
1256 udelay(1000);
1257
1258 for (i = 0; i < 3; i++) {
1259 /* DSI Uniphy lock detect setting */
1260 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2,
1261 0x04);
1262 udelay(100);
1263 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2,
1264 0x05);
1265 udelay(500);
1266 /* poll for PLL ready status */
1267 max_reads = 5;
1268 timeout_us = 100;
1269 if (readl_poll_timeout_noirq((mdss_dsi_base +
1270 DSI_0_PHY_PLL_UNIPHY_PLL_STATUS),
1271 status,
1272 ((status & 0x01) == 1),
1273 max_reads, timeout_us)) {
1274 pr_debug("%s: DSI PLL status=%x failed to Lock\n",
1275 __func__, status);
1276 pr_debug("%s:Trying to power UP PLL again\n",
1277 __func__);
1278 } else {
1279 break;
1280 }
1281
1282 dsi_pll_software_reset();
1283 /*
1284 * PLL power up sequence.
1285 * Add necessary delays recommeded by hardware.
1286 */
1287 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x1);
1288 udelay(1000);
1289 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x5);
1290 udelay(1000);
1291 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x7);
1292 udelay(1000);
1293 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x5);
1294 udelay(1000);
1295 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x7);
1296 udelay(1000);
1297 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0xf);
1298 udelay(2000);
1299
1300 }
1301
1302 if ((status & 0x01) != 1) {
1303 pr_debug("%s: DSI PLL status=%x failed to Lock\n",
1304 __func__, status);
1305 rc = -EINVAL;
1306 goto error;
1307 }
1308
1309 pr_debug("%s: DSI PLL Lock success\n", __func__);
1310
1311error:
1312 return rc;
1313}
1314
Aravind Venkateswaranae7c52f2013-07-13 14:47:14 -07001315static int dsi_pll_enable(struct clk *c)
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001316{
1317 int i, rc = 0;
1318 struct dsi_pll_vco_clk *vco = to_vco_clk(c);
1319
Huaibin Yang3931cb72013-07-12 10:48:59 -07001320 if (!mdss_gdsc_enabled()) {
1321 pr_err("%s: mdss GDSC is not enabled\n", __func__);
1322 return -EPERM;
1323 }
1324
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001325 rc = clk_enable(mdss_ahb_clk);
1326 if (rc) {
1327 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
1328 __func__, rc);
1329 return rc;
1330 }
1331
1332 /* Try all enable sequences until one succeeds */
1333 for (i = 0; i < vco->pll_en_seq_cnt; i++) {
1334 rc = vco->pll_enable_seqs[i]();
1335 pr_debug("%s: DSI PLL %s after sequence #%d\n", __func__,
1336 rc ? "unlocked" : "locked", i + 1);
1337 if (!rc)
1338 break;
1339 }
1340 clk_disable(mdss_ahb_clk);
1341
1342 if (rc)
1343 pr_err("%s: DSI PLL failed to lock\n", __func__);
1344
1345 return rc;
1346}
1347
Aravind Venkateswaranae7c52f2013-07-13 14:47:14 -07001348static void dsi_pll_disable(struct clk *c)
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001349{
1350 int rc = 0;
1351
Huaibin Yang3931cb72013-07-12 10:48:59 -07001352 if (!mdss_gdsc_enabled()) {
1353 pr_warn("%s: mdss GDSC disabled before disabling DSI PLL\n",
1354 __func__);
1355 return;
1356 }
1357
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001358 rc = clk_enable(mdss_ahb_clk);
1359 if (rc) {
1360 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
1361 __func__, rc);
1362 return;
1363 }
1364
1365 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_GLB_CFG, 0x00);
1366
1367 clk_disable(mdss_ahb_clk);
1368 pr_debug("%s: DSI PLL Disabled\n", __func__);
1369 return;
1370}
1371
1372static int vco_set_rate(struct clk *c, unsigned long rate)
1373{
1374 s64 vco_clk_rate = rate;
1375 s32 rem;
1376 s64 refclk_cfg, frac_n_mode, ref_doubler_en_b;
1377 s64 ref_clk_to_pll, div_fbx1000, frac_n_value;
1378 s64 sdm_cfg0, sdm_cfg1, sdm_cfg2, sdm_cfg3;
1379 s64 gen_vco_clk, cal_cfg10, cal_cfg11;
1380 u32 res;
1381 int i, rc = 0;
1382 struct dsi_pll_vco_clk *vco = to_vco_clk(c);
1383
1384 rc = mdss_ahb_clk_enable(1);
1385 if (rc) {
1386 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
1387 __func__, rc);
1388 return rc;
1389 }
1390
1391 /* Configure the Loop filter resistance */
1392 for (i = 0; i < vco->lpfr_lut_size; i++)
1393 if (vco_clk_rate <= vco->lpfr_lut[i].vco_rate)
1394 break;
1395 if (i == vco->lpfr_lut_size) {
1396 pr_err("%s: unable to get loop filter resistance. vco=%ld\n",
1397 __func__, rate);
1398 rc = -EINVAL;
1399 goto error;
1400 }
1401 res = vco->lpfr_lut[i].r;
1402 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LPFR_CFG, res);
1403
1404 /* Loop filter capacitance values : c1 and c2 */
1405 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LPFC1_CFG, 0x70);
1406 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LPFC2_CFG, 0x15);
1407
1408 div_s64_rem(vco_clk_rate, vco->ref_clk_rate, &rem);
1409 if (rem) {
1410 refclk_cfg = 0x1;
1411 frac_n_mode = 1;
1412 ref_doubler_en_b = 0;
1413 } else {
1414 refclk_cfg = 0x0;
1415 frac_n_mode = 0;
1416 ref_doubler_en_b = 1;
1417 }
1418
1419 pr_debug("%s:refclk_cfg = %lld\n", __func__, refclk_cfg);
1420
1421 ref_clk_to_pll = ((vco->ref_clk_rate * 2 * (refclk_cfg))
1422 + (ref_doubler_en_b * vco->ref_clk_rate));
1423 div_fbx1000 = div_s64((vco_clk_rate * 1000), ref_clk_to_pll);
1424
1425 div_s64_rem(div_fbx1000, 1000, &rem);
1426 frac_n_value = div_s64((rem * (1 << 16)), 1000);
1427 gen_vco_clk = div_s64(div_fbx1000 * ref_clk_to_pll, 1000);
1428
1429 pr_debug("%s:ref_clk_to_pll = %lld\n", __func__, ref_clk_to_pll);
1430 pr_debug("%s:div_fb = %lld\n", __func__, div_fbx1000);
1431 pr_debug("%s:frac_n_value = %lld\n", __func__, frac_n_value);
1432
1433 pr_debug("%s:Generated VCO Clock: %lld\n", __func__, gen_vco_clk);
1434 rem = 0;
1435 if (frac_n_mode) {
1436 sdm_cfg0 = (0x0 << 5);
1437 sdm_cfg0 |= (0x0 & 0x3f);
1438 sdm_cfg1 = (div_s64(div_fbx1000, 1000) & 0x3f) - 1;
1439 sdm_cfg3 = div_s64_rem(frac_n_value, 256, &rem);
1440 sdm_cfg2 = rem;
1441 } else {
1442 sdm_cfg0 = (0x1 << 5);
1443 sdm_cfg0 |= (div_s64(div_fbx1000, 1000) & 0x3f) - 1;
1444 sdm_cfg1 = (0x0 & 0x3f);
1445 sdm_cfg2 = 0;
1446 sdm_cfg3 = 0;
1447 }
1448
1449 pr_debug("%s: sdm_cfg0=%lld\n", __func__, sdm_cfg0);
1450 pr_debug("%s: sdm_cfg1=%lld\n", __func__, sdm_cfg1);
1451 pr_debug("%s: sdm_cfg2=%lld\n", __func__, sdm_cfg2);
1452 pr_debug("%s: sdm_cfg3=%lld\n", __func__, sdm_cfg3);
1453
1454 cal_cfg11 = div_s64_rem(gen_vco_clk, 256 * 1000000, &rem);
1455 cal_cfg10 = rem / 1000000;
1456 pr_debug("%s: cal_cfg10=%lld, cal_cfg11=%lld\n", __func__,
1457 cal_cfg10, cal_cfg11);
1458
1459 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CHGPUMP_CFG, 0x02);
1460 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG3, 0x2b);
1461 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG4, 0x66);
1462 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_LKDET_CFG2, 0x05);
1463
1464 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG1,
1465 (u32)(sdm_cfg1 & 0xff));
1466 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG2,
1467 (u32)(sdm_cfg2 & 0xff));
1468 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG3,
1469 (u32)(sdm_cfg3 & 0xff));
1470 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG4, 0x00);
1471
1472 /* Add hardware recommended delay for correct PLL configuration */
1473 udelay(1000);
1474
1475 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_REFCLK_CFG,
1476 (u32)refclk_cfg);
1477 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_PWRGEN_CFG, 0x00);
1478 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_VCOLPF_CFG, 0x71);
1479 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG0,
1480 (u32)sdm_cfg0);
1481 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG0, 0x0a);
1482 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG6, 0x30);
1483 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG7, 0x00);
1484 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG8, 0x60);
1485 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG9, 0x00);
1486 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG10,
1487 (u32)(cal_cfg10 & 0xff));
1488 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_CAL_CFG11,
1489 (u32)(cal_cfg11 & 0xff));
1490 DSS_REG_W(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_EFUSE_CFG, 0x20);
1491
1492error:
1493 mdss_ahb_clk_enable(0);
1494 return rc;
1495}
1496
1497/* rate is the bit clk rate */
1498static long vco_round_rate(struct clk *c, unsigned long rate)
1499{
1500 unsigned long rrate = rate;
1501 struct dsi_pll_vco_clk *vco = to_vco_clk(c);
1502
1503 if (rate < vco->min_rate)
1504 rrate = vco->min_rate;
1505 if (rate > vco->max_rate)
1506 rrate = vco->max_rate;
1507
1508 return rrate;
1509}
1510
1511static unsigned long vco_get_rate(struct clk *c)
1512{
1513 u32 sdm0, doubler, sdm_byp_div;
1514 u64 vco_rate;
1515 u32 sdm_dc_off, sdm_freq_seed, sdm2, sdm3;
1516 struct dsi_pll_vco_clk *vco = to_vco_clk(c);
1517 u64 ref_clk = vco->ref_clk_rate;
1518
1519 /* Check to see if the ref clk doubler is enabled */
1520 doubler = DSS_REG_R(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_REFCLK_CFG)
1521 & BIT(0);
1522 ref_clk += (doubler * vco->ref_clk_rate);
1523
1524 /* see if it is integer mode or sdm mode */
1525 sdm0 = DSS_REG_R(mdss_dsi_base, DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG0);
1526 if (sdm0 & BIT(6)) {
1527 /* integer mode */
1528 sdm_byp_div = (DSS_REG_R(mdss_dsi_base,
1529 DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG0) & 0x3f) + 1;
1530 vco_rate = ref_clk * sdm_byp_div;
1531 } else {
1532 /* sdm mode */
1533 sdm_dc_off = DSS_REG_R(mdss_dsi_base,
1534 DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG1) & 0xFF;
1535 pr_debug("%s: sdm_dc_off = %d\n", __func__, sdm_dc_off);
1536 sdm2 = DSS_REG_R(mdss_dsi_base,
1537 DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG2) & 0xFF;
1538 sdm3 = DSS_REG_R(mdss_dsi_base,
1539 DSI_0_PHY_PLL_UNIPHY_PLL_SDM_CFG3) & 0xFF;
1540 sdm_freq_seed = (sdm3 << 8) | sdm2;
1541 pr_debug("%s: sdm_freq_seed = %d\n", __func__, sdm_freq_seed);
1542
1543 vco_rate = (ref_clk * (sdm_dc_off + 1)) +
1544 mult_frac(ref_clk, sdm_freq_seed, BIT(16));
1545 pr_debug("%s: vco rate = %lld", __func__, vco_rate);
1546 }
1547
1548 pr_debug("%s: returning vco rate = %lu\n", __func__,
1549 (unsigned long)vco_rate);
1550 return (unsigned long)vco_rate;
1551}
1552
1553static enum handoff vco_handoff(struct clk *c)
1554{
1555 int rc = 0;
1556 enum handoff ret = HANDOFF_DISABLED_CLK;
1557
1558 rc = mdss_ahb_clk_enable(1);
1559 if (rc) {
1560 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
1561 __func__, rc);
1562 return ret;
1563 }
1564 if (dsi_pll_lock_status()) {
1565 c->rate = vco_get_rate(c);
1566 ret = HANDOFF_ENABLED_CLK;
1567 }
1568
1569 mdss_ahb_clk_enable(0);
1570 return ret;
1571}
1572
1573static int vco_prepare(struct clk *c)
1574{
Aravind Venkateswaranae7c52f2013-07-13 14:47:14 -07001575 int rc = 0;
1576
Chandan Uddaraju834d4832013-08-27 13:18:08 -07001577 if ((vco_cached_rate != 0)
1578 && (vco_cached_rate == c->rate)) {
Aravind Venkateswaranae7c52f2013-07-13 14:47:14 -07001579 rc = vco_set_rate(c, vco_cached_rate);
1580 if (rc) {
1581 pr_err("%s: vco_set_rate failed. rc=%d\n",
1582 __func__, rc);
1583 goto error;
1584 }
1585 }
1586
1587 rc = dsi_pll_enable(c);
1588
1589error:
1590 return rc;
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001591}
1592
1593static void vco_unprepare(struct clk *c)
1594{
1595 vco_cached_rate = c->rate;
Aravind Venkateswaranae7c52f2013-07-13 14:47:14 -07001596 dsi_pll_disable(c);
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001597}
1598
1599/* Op structures */
1600
1601static struct clk_ops clk_ops_dsi_vco = {
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001602 .set_rate = vco_set_rate,
1603 .round_rate = vco_round_rate,
1604 .handoff = vco_handoff,
1605 .prepare = vco_prepare,
1606 .unprepare = vco_unprepare,
1607};
1608
1609static struct clk_div_ops fixed_2div_ops;
1610
1611static struct clk_div_ops fixed_4div_ops = {
1612 .set_div = fixed_4div_set_div,
1613 .get_div = fixed_4div_get_div,
1614};
1615
1616static struct clk_div_ops analog_postdiv_ops = {
1617 .set_div = analog_set_div,
1618 .get_div = analog_get_div,
1619};
1620
1621static struct clk_div_ops digital_postdiv_ops = {
1622 .set_div = digital_set_div,
1623 .get_div = digital_get_div,
1624};
1625
1626struct clk_mux_ops byte_mux_ops = {
1627 .set_mux_sel = set_byte_mux_sel,
1628 .get_mux_sel = get_byte_mux_sel,
1629};
1630
1631struct clk_ops byte_mux_clk_ops;
1632
1633static struct clk_ops pixel_clk_src_ops;
1634static struct clk_ops byte_clk_src_ops;
1635static struct clk_ops analog_potsdiv_clk_ops;
1636
1637/* Display clocks */
1638
1639struct dsi_pll_vco_clk dsi_vco_clk_8226 = {
1640 .ref_clk_rate = 19200000,
1641 .min_rate = 350000000,
1642 .max_rate = 750000000,
1643 .pll_en_seq_cnt = 6,
1644 .pll_enable_seqs[0] = dsi_pll_enable_seq_m,
1645 .pll_enable_seqs[1] = dsi_pll_enable_seq_d,
1646 .pll_enable_seqs[2] = dsi_pll_enable_seq_d,
1647 .pll_enable_seqs[3] = dsi_pll_enable_seq_f1,
1648 .pll_enable_seqs[4] = dsi_pll_enable_seq_c,
1649 .pll_enable_seqs[5] = dsi_pll_enable_seq_e,
1650 .lpfr_lut_size = 10,
1651 .lpfr_lut = (struct lpfr_cfg[]){
1652 {479500000, 8},
1653 {480000000, 11},
1654 {575500000, 8},
1655 {576000000, 12},
1656 {610500000, 8},
1657 {659500000, 9},
1658 {671500000, 10},
1659 {672000000, 14},
1660 {708500000, 10},
1661 {750000000, 11},
1662 },
1663 .c = {
1664 .dbg_name = "dsi_vco_clk",
1665 .ops = &clk_ops_dsi_vco,
1666 CLK_INIT(dsi_vco_clk_8226.c),
1667 },
1668};
1669
1670struct div_clk analog_postdiv_clk_8226 = {
Patrick Daly86abe9b2013-09-03 18:55:37 -07001671 .data = {
1672 .max_div = 255,
1673 .min_div = 1,
1674 },
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001675 .ops = &analog_postdiv_ops,
1676 .c = {
1677 .parent = &dsi_vco_clk_8226.c,
1678 .dbg_name = "analog_postdiv_clk",
1679 .ops = &analog_potsdiv_clk_ops,
1680 .flags = CLKFLAG_NO_RATE_CACHE,
1681 CLK_INIT(analog_postdiv_clk_8226.c),
1682 },
1683};
1684
1685struct div_clk indirect_path_div2_clk_8226 = {
1686 .ops = &fixed_2div_ops,
Patrick Daly86abe9b2013-09-03 18:55:37 -07001687 .data = {
1688 .div = 2,
Junjie Wu4d3917d2013-10-01 21:11:45 -07001689 .min_div = 2,
1690 .max_div = 2,
Patrick Daly86abe9b2013-09-03 18:55:37 -07001691 },
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001692 .c = {
1693 .parent = &analog_postdiv_clk_8226.c,
1694 .dbg_name = "indirect_path_div2_clk",
1695 .ops = &clk_ops_div,
1696 .flags = CLKFLAG_NO_RATE_CACHE,
1697 CLK_INIT(indirect_path_div2_clk_8226.c),
1698 },
1699};
1700
1701struct div_clk pixel_clk_src_8226 = {
Patrick Daly86abe9b2013-09-03 18:55:37 -07001702 .data = {
1703 .max_div = 255,
1704 .min_div = 1,
1705 },
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001706 .ops = &digital_postdiv_ops,
1707 .c = {
1708 .parent = &dsi_vco_clk_8226.c,
1709 .dbg_name = "pixel_clk_src",
1710 .ops = &pixel_clk_src_ops,
1711 .flags = CLKFLAG_NO_RATE_CACHE,
1712 CLK_INIT(pixel_clk_src_8226.c),
1713 },
1714};
1715
1716struct mux_clk byte_mux_8226 = {
1717 .num_parents = 2,
1718 .parents = (struct clk_src[]){
1719 {&dsi_vco_clk_8226.c, 0},
1720 {&indirect_path_div2_clk_8226.c, 1},
1721 },
1722 .ops = &byte_mux_ops,
1723 .c = {
1724 .parent = &dsi_vco_clk_8226.c,
1725 .dbg_name = "byte_mux",
1726 .ops = &byte_mux_clk_ops,
1727 CLK_INIT(byte_mux_8226.c),
1728 },
1729};
1730
1731struct div_clk byte_clk_src_8226 = {
1732 .ops = &fixed_4div_ops,
Patrick Daly86abe9b2013-09-03 18:55:37 -07001733 .data = {
1734 .min_div = 4,
1735 .max_div = 4,
1736 },
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001737 .c = {
1738 .parent = &byte_mux_8226.c,
1739 .dbg_name = "byte_clk_src",
1740 .ops = &byte_clk_src_ops,
1741 CLK_INIT(byte_clk_src_8226.c),
1742 },
1743};
1744
1745struct dsi_pll_vco_clk dsi_vco_clk_8974 = {
1746 .ref_clk_rate = 19200000,
1747 .min_rate = 350000000,
1748 .max_rate = 750000000,
1749 .pll_en_seq_cnt = 3,
1750 .pll_enable_seqs[0] = dsi_pll_enable_seq_8974,
1751 .pll_enable_seqs[1] = dsi_pll_enable_seq_8974,
1752 .pll_enable_seqs[2] = dsi_pll_enable_seq_8974,
1753 .lpfr_lut_size = 10,
1754 .lpfr_lut = (struct lpfr_cfg[]){
1755 {479500000, 8},
1756 {480000000, 11},
1757 {575500000, 8},
1758 {576000000, 12},
1759 {610500000, 8},
1760 {659500000, 9},
1761 {671500000, 10},
1762 {672000000, 14},
1763 {708500000, 10},
1764 {750000000, 11},
1765 },
1766 .c = {
1767 .dbg_name = "dsi_vco_clk",
1768 .ops = &clk_ops_dsi_vco,
1769 CLK_INIT(dsi_vco_clk_8974.c),
1770 },
1771};
1772
1773struct div_clk analog_postdiv_clk_8974 = {
Patrick Daly86abe9b2013-09-03 18:55:37 -07001774 .data = {
1775 .max_div = 255,
1776 .min_div = 1,
1777 },
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001778 .ops = &analog_postdiv_ops,
1779 .c = {
1780 .parent = &dsi_vco_clk_8974.c,
1781 .dbg_name = "analog_postdiv_clk",
1782 .ops = &analog_potsdiv_clk_ops,
1783 .flags = CLKFLAG_NO_RATE_CACHE,
1784 CLK_INIT(analog_postdiv_clk_8974.c),
1785 },
1786};
1787
1788struct div_clk indirect_path_div2_clk_8974 = {
1789 .ops = &fixed_2div_ops,
Patrick Daly86abe9b2013-09-03 18:55:37 -07001790 .data = {
1791 .div = 2,
Junjie Wu4d3917d2013-10-01 21:11:45 -07001792 .min_div = 2,
1793 .max_div = 2,
Patrick Daly86abe9b2013-09-03 18:55:37 -07001794 },
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001795 .c = {
1796 .parent = &analog_postdiv_clk_8974.c,
1797 .dbg_name = "indirect_path_div2_clk",
1798 .ops = &clk_ops_div,
1799 .flags = CLKFLAG_NO_RATE_CACHE,
1800 CLK_INIT(indirect_path_div2_clk_8974.c),
1801 },
1802};
1803
1804struct div_clk pixel_clk_src_8974 = {
Patrick Daly86abe9b2013-09-03 18:55:37 -07001805 .data = {
1806 .max_div = 255,
1807 .min_div = 1,
1808 },
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001809 .ops = &digital_postdiv_ops,
1810 .c = {
1811 .parent = &dsi_vco_clk_8974.c,
1812 .dbg_name = "pixel_clk_src",
1813 .ops = &pixel_clk_src_ops,
1814 .flags = CLKFLAG_NO_RATE_CACHE,
1815 CLK_INIT(pixel_clk_src_8974.c),
1816 },
1817};
1818
1819struct mux_clk byte_mux_8974 = {
1820 .num_parents = 2,
1821 .parents = (struct clk_src[]){
1822 {&dsi_vco_clk_8974.c, 0},
1823 {&indirect_path_div2_clk_8974.c, 1},
1824 },
1825 .ops = &byte_mux_ops,
1826 .c = {
1827 .parent = &dsi_vco_clk_8974.c,
1828 .dbg_name = "byte_mux",
1829 .ops = &byte_mux_clk_ops,
1830 CLK_INIT(byte_mux_8974.c),
1831 },
1832};
1833
1834struct div_clk byte_clk_src_8974 = {
1835 .ops = &fixed_4div_ops,
Patrick Daly86abe9b2013-09-03 18:55:37 -07001836 .data = {
1837 .min_div = 4,
1838 .max_div = 4,
1839 },
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07001840 .c = {
1841 .parent = &byte_mux_8974.c,
1842 .dbg_name = "byte_clk_src",
1843 .ops = &byte_clk_src_ops,
1844 CLK_INIT(byte_clk_src_8974.c),
1845 },
1846};
1847
Kuogee Hsieha20087c2013-08-05 17:53:12 -07001848static inline struct edp_pll_vco_clk *to_edp_vco_clk(struct clk *clk)
1849{
1850 return container_of(clk, struct edp_pll_vco_clk, c);
1851}
1852
1853static int edp_vco_set_rate(struct clk *c, unsigned long vco_rate)
1854{
1855 struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
1856 int rc = 0;
1857
1858 pr_debug("%s: vco_rate=%d\n", __func__, (int)vco_rate);
1859
1860 rc = mdss_ahb_clk_enable(1);
1861 if (rc) {
1862 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
1863 __func__, rc);
1864 rc = -EINVAL;
1865 }
1866 if (vco_rate == 810000000) {
1867 DSS_REG_W(mdss_edp_base, 0x0c, 0x18);
1868 /* UNIPHY_PLL_LKDET_CFG2 */
1869 DSS_REG_W(mdss_edp_base, 0x64, 0x05);
1870 /* UNIPHY_PLL_REFCLK_CFG */
1871 DSS_REG_W(mdss_edp_base, 0x00, 0x00);
1872 /* UNIPHY_PLL_SDM_CFG0 */
1873 DSS_REG_W(mdss_edp_base, 0x38, 0x36);
1874 /* UNIPHY_PLL_SDM_CFG1 */
1875 DSS_REG_W(mdss_edp_base, 0x3c, 0x69);
1876 /* UNIPHY_PLL_SDM_CFG2 */
1877 DSS_REG_W(mdss_edp_base, 0x40, 0xff);
1878 /* UNIPHY_PLL_SDM_CFG3 */
1879 DSS_REG_W(mdss_edp_base, 0x44, 0x2f);
1880 /* UNIPHY_PLL_SDM_CFG4 */
1881 DSS_REG_W(mdss_edp_base, 0x48, 0x00);
1882 /* UNIPHY_PLL_SSC_CFG0 */
1883 DSS_REG_W(mdss_edp_base, 0x4c, 0x80);
1884 /* UNIPHY_PLL_SSC_CFG1 */
1885 DSS_REG_W(mdss_edp_base, 0x50, 0x00);
1886 /* UNIPHY_PLL_SSC_CFG2 */
1887 DSS_REG_W(mdss_edp_base, 0x54, 0x00);
1888 /* UNIPHY_PLL_SSC_CFG3 */
1889 DSS_REG_W(mdss_edp_base, 0x58, 0x00);
1890 /* UNIPHY_PLL_CAL_CFG0 */
1891 DSS_REG_W(mdss_edp_base, 0x6c, 0x0a);
1892 /* UNIPHY_PLL_CAL_CFG2 */
1893 DSS_REG_W(mdss_edp_base, 0x74, 0x01);
1894 /* UNIPHY_PLL_CAL_CFG6 */
1895 DSS_REG_W(mdss_edp_base, 0x84, 0x5a);
1896 /* UNIPHY_PLL_CAL_CFG7 */
1897 DSS_REG_W(mdss_edp_base, 0x88, 0x0);
1898 /* UNIPHY_PLL_CAL_CFG8 */
1899 DSS_REG_W(mdss_edp_base, 0x8c, 0x60);
1900 /* UNIPHY_PLL_CAL_CFG9 */
1901 DSS_REG_W(mdss_edp_base, 0x90, 0x0);
1902 /* UNIPHY_PLL_CAL_CFG10 */
1903 DSS_REG_W(mdss_edp_base, 0x94, 0x2a);
1904 /* UNIPHY_PLL_CAL_CFG11 */
1905 DSS_REG_W(mdss_edp_base, 0x98, 0x3);
1906 /* UNIPHY_PLL_LKDET_CFG0 */
1907 DSS_REG_W(mdss_edp_base, 0x5c, 0x10);
1908 /* UNIPHY_PLL_LKDET_CFG1 */
1909 DSS_REG_W(mdss_edp_base, 0x60, 0x1a);
1910 /* UNIPHY_PLL_POSTDIV1_CFG */
1911 DSS_REG_W(mdss_edp_base, 0x04, 0x00);
1912 /* UNIPHY_PLL_POSTDIV3_CFG */
1913 DSS_REG_W(mdss_edp_base, 0x28, 0x00);
1914 } else if (vco_rate == 1350000000) {
1915 /* UNIPHY_PLL_LKDET_CFG2 */
1916 DSS_REG_W(mdss_edp_base, 0x64, 0x05);
1917 /* UNIPHY_PLL_REFCLK_CFG */
1918 DSS_REG_W(mdss_edp_base, 0x00, 0x01);
1919 /* UNIPHY_PLL_SDM_CFG0 */
1920 DSS_REG_W(mdss_edp_base, 0x38, 0x36);
1921 /* UNIPHY_PLL_SDM_CFG1 */
1922 DSS_REG_W(mdss_edp_base, 0x3c, 0x62);
1923 /* UNIPHY_PLL_SDM_CFG2 */
1924 DSS_REG_W(mdss_edp_base, 0x40, 0x00);
1925 /* UNIPHY_PLL_SDM_CFG3 */
1926 DSS_REG_W(mdss_edp_base, 0x44, 0x28);
1927 /* UNIPHY_PLL_SDM_CFG4 */
1928 DSS_REG_W(mdss_edp_base, 0x48, 0x00);
1929 /* UNIPHY_PLL_SSC_CFG0 */
1930 DSS_REG_W(mdss_edp_base, 0x4c, 0x80);
1931 /* UNIPHY_PLL_SSC_CFG1 */
1932 DSS_REG_W(mdss_edp_base, 0x50, 0x00);
1933 /* UNIPHY_PLL_SSC_CFG2 */
1934 DSS_REG_W(mdss_edp_base, 0x54, 0x00);
1935 /* UNIPHY_PLL_SSC_CFG3 */
1936 DSS_REG_W(mdss_edp_base, 0x58, 0x00);
1937 /* UNIPHY_PLL_CAL_CFG0 */
1938 DSS_REG_W(mdss_edp_base, 0x6c, 0x0a);
1939 /* UNIPHY_PLL_CAL_CFG2 */
1940 DSS_REG_W(mdss_edp_base, 0x74, 0x01);
1941 /* UNIPHY_PLL_CAL_CFG6 */
1942 DSS_REG_W(mdss_edp_base, 0x84, 0x5a);
1943 /* UNIPHY_PLL_CAL_CFG7 */
1944 DSS_REG_W(mdss_edp_base, 0x88, 0x0);
1945 /* UNIPHY_PLL_CAL_CFG8 */
1946 DSS_REG_W(mdss_edp_base, 0x8c, 0x60);
1947 /* UNIPHY_PLL_CAL_CFG9 */
1948 DSS_REG_W(mdss_edp_base, 0x90, 0x0);
1949 /* UNIPHY_PLL_CAL_CFG10 */
1950 DSS_REG_W(mdss_edp_base, 0x94, 0x46);
1951 /* UNIPHY_PLL_CAL_CFG11 */
1952 DSS_REG_W(mdss_edp_base, 0x98, 0x5);
1953 /* UNIPHY_PLL_LKDET_CFG0 */
1954 DSS_REG_W(mdss_edp_base, 0x5c, 0x10);
1955 /* UNIPHY_PLL_LKDET_CFG1 */
1956 DSS_REG_W(mdss_edp_base, 0x60, 0x1a);
1957 /* UNIPHY_PLL_POSTDIV1_CFG */
1958 DSS_REG_W(mdss_edp_base, 0x04, 0x00);
1959 /* UNIPHY_PLL_POSTDIV3_CFG */
1960 DSS_REG_W(mdss_edp_base, 0x28, 0x00);
1961 } else {
1962 pr_err("%s: rate=%d is NOT supported\n", __func__,
1963 (int)vco_rate);
1964 vco_rate = 0;
1965 rc = -EINVAL;
1966 }
1967
1968 DSS_REG_W(mdss_edp_base, 0x20, 0x01); /* UNIPHY_PLL_GLB_CFG */
1969 udelay(100);
1970 DSS_REG_W(mdss_edp_base, 0x20, 0x05); /* UNIPHY_PLL_GLB_CFG */
1971 udelay(100);
1972 DSS_REG_W(mdss_edp_base, 0x20, 0x07); /* UNIPHY_PLL_GLB_CFG */
1973 udelay(100);
1974 DSS_REG_W(mdss_edp_base, 0x20, 0x0f); /* UNIPHY_PLL_GLB_CFG */
1975 udelay(100);
1976 mdss_ahb_clk_enable(0);
1977
1978 vco->rate = vco_rate;
1979
1980 return rc;
1981}
1982
1983static int edp_pll_ready_poll(void)
1984{
1985 int cnt;
1986 u32 status;
1987
1988 /* ahb clock should be enabled by caller */
1989 cnt = 100;
1990 while (cnt--) {
1991 udelay(100);
1992 status = DSS_REG_R(mdss_edp_base, 0xc0);
1993 status &= 0x01;
1994 if (status)
1995 break;
1996 }
1997 pr_debug("%s: cnt=%d status=%d\n", __func__, cnt, (int)status);
1998
1999 if (status)
2000 return 1;
2001
2002 pr_err("%s: PLL NOT ready\n", __func__);
2003 return 0;
2004}
2005
2006static int edp_vco_enable(struct clk *c)
2007{
2008 int i, ready;
2009 int rc = 0;
2010
2011 if (!mdss_gdsc_enabled()) {
2012 pr_err("%s: mdss GDSC is not enabled\n", __func__);
2013 return -EPERM;
2014 }
2015
2016 /* called from enable, irq disable. can not call clk_prepare */
2017 rc = clk_enable(mdss_ahb_clk);
2018 if (rc) {
2019 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
2020 __func__, rc);
2021 return rc;
2022 }
2023
2024 for (i = 0; i < 3; i++) {
2025 ready = edp_pll_ready_poll();
2026 if (ready)
2027 break;
2028 DSS_REG_W(mdss_edp_base, 0x20, 0x01); /* UNIPHY_PLL_GLB_CFG */
2029 udelay(100);
2030 DSS_REG_W(mdss_edp_base, 0x20, 0x05); /* UNIPHY_PLL_GLB_CFG */
2031 udelay(100);
2032 DSS_REG_W(mdss_edp_base, 0x20, 0x07); /* UNIPHY_PLL_GLB_CFG */
2033 udelay(100);
2034 DSS_REG_W(mdss_edp_base, 0x20, 0x0f); /* UNIPHY_PLL_GLB_CFG */
2035 udelay(100);
2036 }
2037 clk_disable(mdss_ahb_clk);
2038
2039 if (ready) {
2040 pr_debug("%s: EDP PLL locked\n", __func__);
2041 return 0;
2042 }
2043
2044 pr_err("%s: EDP PLL failed to lock\n", __func__);
2045 return -EINVAL;
2046}
2047
2048static void edp_vco_disable(struct clk *c)
2049{
2050 int rc = 0;
2051
2052 if (!mdss_gdsc_enabled()) {
2053 pr_err("%s: mdss GDSC is not enabled\n", __func__);
2054 return;
2055 }
2056
2057 /* called from unprepare which is not atomic */
2058 rc = mdss_ahb_clk_enable(1);
2059 if (rc) {
2060 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
2061 __func__, rc);
2062 return;
2063 }
2064
2065 DSS_REG_W(mdss_edp_base, 0x20, 0x00);
2066
2067 mdss_ahb_clk_enable(0);
2068
2069 pr_debug("%s: EDP PLL Disabled\n", __func__);
2070 return;
2071}
2072
2073static unsigned long edp_vco_get_rate(struct clk *c)
2074{
2075 struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
2076 u32 pll_status, div2;
2077 int rc;
2078
2079 rc = mdss_ahb_clk_enable(1);
2080 if (rc) {
2081 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
2082 __func__, rc);
2083 return rc;
2084 }
2085 if (vco->rate == 0) {
2086 pll_status = DSS_REG_R(mdss_edp_base, 0xc0);
2087 if (pll_status & 0x01) {
2088 div2 = DSS_REG_R(mdss_edp_base, 0x24);
2089 if (div2 & 0x01)
2090 vco->rate = 1350000000;
2091 else
2092 vco->rate = 810000000;
2093 }
2094 }
2095 mdss_ahb_clk_enable(0);
2096
2097 pr_debug("%s: rate=%d\n", __func__, (int)vco->rate);
2098
2099 return vco->rate;
2100}
2101
2102static long edp_vco_round_rate(struct clk *c, unsigned long rate)
2103{
2104 struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
2105 unsigned long rrate = -ENOENT;
2106 unsigned long *lp;
2107
2108 lp = vco->rate_list;
2109 while (*lp) {
2110 rrate = *lp;
2111 if (rate <= rrate)
2112 break;
2113 lp++;
2114 }
2115
2116 pr_debug("%s: rrate=%d\n", __func__, (int)rrate);
2117
2118 return rrate;
2119}
2120
2121static int edp_vco_prepare(struct clk *c)
2122{
2123 struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
2124
2125 pr_debug("%s: rate=%d\n", __func__, (int)vco->rate);
2126
2127 return edp_vco_set_rate(c, vco->rate);
2128}
2129
2130static void edp_vco_unprepare(struct clk *c)
2131{
2132 struct edp_pll_vco_clk *vco = to_edp_vco_clk(c);
2133
2134 pr_debug("%s: rate=%d\n", __func__, (int)vco->rate);
2135
2136 edp_vco_disable(c);
2137}
2138
2139static int edp_pll_lock_status(void)
2140{
2141 u32 status;
2142 int pll_locked = 0;
2143 int rc;
2144
2145 rc = mdss_ahb_clk_enable(1);
2146 if (rc) {
2147 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
2148 __func__, rc);
2149 return rc;
2150 }
2151 /* poll for PLL ready status */
2152 if (readl_poll_timeout_noirq((mdss_edp_base + 0xc0),
2153 status, ((status & BIT(0)) == 1),
2154 PLL_POLL_MAX_READS, PLL_POLL_TIMEOUT_US)) {
2155 pr_debug("%s: EDP PLL status=%x failed to Lock\n",
2156 __func__, status);
2157 pll_locked = 0;
2158 } else {
2159 pll_locked = 1;
2160 }
2161 mdss_ahb_clk_enable(0);
2162
2163 return pll_locked;
2164}
2165
2166static enum handoff edp_vco_handoff(struct clk *c)
2167{
2168 enum handoff ret = HANDOFF_DISABLED_CLK;
2169
2170 if (edp_pll_lock_status()) {
2171 c->rate = edp_vco_get_rate(c);
2172 ret = HANDOFF_ENABLED_CLK;
2173 }
2174
2175 pr_debug("%s: done, ret=%d\n", __func__, ret);
2176 return ret;
2177}
2178
2179/* edp vco rate */
2180static unsigned long edp_vco_rate_list[] = {
2181 810000000, 1350000000, 0};
2182
2183struct clk_ops edp_vco_clk_ops = {
2184 .enable = edp_vco_enable,
2185 .set_rate = edp_vco_set_rate,
2186 .get_rate = edp_vco_get_rate,
2187 .round_rate = edp_vco_round_rate,
2188 .prepare = edp_vco_prepare,
2189 .unprepare = edp_vco_unprepare,
2190 .handoff = edp_vco_handoff,
2191};
2192
2193struct edp_pll_vco_clk edp_vco_clk = {
2194 .ref_clk_rate = 19200000,
2195 .rate = 0,
2196 .rate_list = edp_vco_rate_list,
2197 .c = {
2198 .dbg_name = "edp_vco_clk",
2199 .ops = &edp_vco_clk_ops,
2200 CLK_INIT(edp_vco_clk.c),
2201 },
2202};
2203
2204static unsigned long edp_mainlink_get_rate(struct clk *c)
2205{
2206 struct div_clk *mclk = to_div_clk(c);
2207 struct clk *pclk;
2208 unsigned long rate = 0;
2209
2210 pclk = clk_get_parent(c);
2211
2212 if (pclk->ops->get_rate) {
2213 rate = pclk->ops->get_rate(pclk);
2214 rate /= mclk->data.div;
2215 }
2216
2217 pr_debug("%s: rate=%d div=%d\n", __func__, (int)rate, mclk->data.div);
2218
2219 return rate;
2220}
2221
2222static struct clk_ops edp_mainlink_clk_src_ops;
2223static struct clk_div_ops fixed_5div_ops; /* null ops */
2224
2225struct div_clk edp_mainlink_clk_src = {
2226 .ops = &fixed_5div_ops,
2227 .data = {
2228 .div = 5,
2229 },
2230 .c = {
2231 .parent = &edp_vco_clk.c,
2232 .dbg_name = "edp_mainlink_clk_src",
2233 .ops = &edp_mainlink_clk_src_ops,
2234 .flags = CLKFLAG_NO_RATE_CACHE,
2235 CLK_INIT(edp_mainlink_clk_src.c),
2236 }
2237};
2238
2239
2240static struct clk_ops edp_pixel_clk_ops;
2241
2242/*
2243 * this rate is from pll to clock controller
2244 * output from pll to CC has two possibilities
2245 * 1: if mainlink rate is 270M, then 675M
2246 * 2: if mainlink rate is 162M, then 810M
2247 */
2248static int edp_pixel_set_div(struct div_clk *clk, int div)
2249{
2250 int rc = 0;
2251
2252 rc = mdss_ahb_clk_enable(1);
2253 if (rc) {
2254 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
2255 __func__, rc);
2256 return rc;
2257 }
2258
2259 pr_debug("%s: div=%d\n", __func__, div);
2260 DSS_REG_W(mdss_edp_base, 0x24, (div - 1)); /* UNIPHY_PLL_POSTDIV2_CFG */
2261
2262 mdss_ahb_clk_enable(0);
2263 return 0;
2264}
2265
2266static int edp_pixel_get_div(struct div_clk *clk)
2267{
2268 int div = 0;
2269
2270 if (mdss_ahb_clk_enable(1)) {
2271 pr_debug("%s: Failed to enable mdss ahb clock\n", __func__);
2272 return 1;
2273 }
2274 div = DSS_REG_R(mdss_edp_base, 0x24); /* UNIPHY_PLL_POSTDIV2_CFG */
2275 div &= 0x01;
2276 pr_debug("%s: div=%d\n", __func__, div);
2277 mdss_ahb_clk_enable(0);
2278 return div + 1;
2279}
2280
2281static struct clk_div_ops edp_pixel_ops = {
2282 .set_div = edp_pixel_set_div,
2283 .get_div = edp_pixel_get_div,
2284};
2285
2286struct div_clk edp_pixel_clk_src = {
2287 .data = {
2288 .max_div = 2,
2289 .min_div = 1,
2290 },
2291 .ops = &edp_pixel_ops,
2292 .c = {
2293 .parent = &edp_vco_clk.c,
2294 .dbg_name = "edp_pixel_clk_src",
2295 .ops = &edp_pixel_clk_ops,
2296 .flags = CLKFLAG_NO_RATE_CACHE,
2297 CLK_INIT(edp_pixel_clk_src.c),
2298 },
2299};
2300
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -07002301/* HDMI PLL DIV CLK */
2302
2303static unsigned long hdmi_vco_get_rate(struct clk *c)
2304{
2305 unsigned long freq = 0;
2306
2307 if (mdss_ahb_clk_enable(1)) {
2308 pr_err("%s: Failed to enable mdss ahb clock\n", __func__);
2309 return freq;
2310 }
2311
2312 freq = DSS_REG_R(hdmi_phy_pll_base, HDMI_UNI_PLL_CAL_CFG11) << 8 |
2313 DSS_REG_R(hdmi_phy_pll_base, HDMI_UNI_PLL_CAL_CFG10);
2314
2315 switch (freq) {
2316 case 742:
2317 freq = 742500000;
2318 break;
2319 case 810:
2320 if (DSS_REG_R(hdmi_phy_pll_base, HDMI_UNI_PLL_SDM_CFG3) == 0x18)
2321 freq = 810000000;
2322 else
2323 freq = 810900000;
2324 break;
2325 case 1342:
2326 freq = 1342500000;
2327 break;
2328 default:
2329 freq *= 1000000;
2330 }
2331
2332 mdss_ahb_clk_enable(0);
2333
2334 return freq;
2335}
2336
2337static long hdmi_vco_round_rate(struct clk *c, unsigned long rate)
2338{
Ajay Singh Parmarc4d53dc2013-09-03 17:19:16 -07002339 unsigned long rrate = rate;
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -07002340 struct hdmi_pll_vco_clk *vco = to_hdmi_vco_clk(c);
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -07002341
Ajay Singh Parmarc4d53dc2013-09-03 17:19:16 -07002342 if (rate < vco->min_rate)
2343 rrate = vco->min_rate;
2344 if (rate > vco->max_rate)
2345 rrate = vco->max_rate;
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -07002346
2347 pr_debug("%s: rrate=%ld\n", __func__, rrate);
2348
2349 return rrate;
2350}
2351
2352static int hdmi_vco_prepare(struct clk *c)
2353{
2354 struct hdmi_pll_vco_clk *vco = to_hdmi_vco_clk(c);
2355 int ret = 0;
2356
2357 pr_debug("%s: rate=%ld\n", __func__, vco->rate);
2358
Ajay Singh Parmardb66a452013-11-04 18:31:37 -08002359 if (!vco->rate_set && vco->rate)
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -07002360 ret = hdmi_vco_set_rate(c, vco->rate);
2361
2362 if (!ret)
2363 ret = clk_prepare(mdss_ahb_clk);
2364
2365 return ret;
2366}
2367
2368static void hdmi_vco_unprepare(struct clk *c)
2369{
Ajay Singh Parmardb66a452013-11-04 18:31:37 -08002370 struct hdmi_pll_vco_clk *vco = to_hdmi_vco_clk(c);
2371
2372 vco->rate_set = false;
2373
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -07002374 clk_unprepare(mdss_ahb_clk);
2375}
2376
2377static int hdmi_pll_lock_status(void)
2378{
2379 u32 status;
2380 int pll_locked = 0;
2381 int rc;
2382
2383 rc = mdss_ahb_clk_enable(1);
2384 if (rc) {
2385 pr_err("%s: failed to enable mdss ahb clock. rc=%d\n",
2386 __func__, rc);
2387 return 0;
2388 }
2389 /* poll for PLL ready status */
2390 if (readl_poll_timeout_noirq((hdmi_phy_base + HDMI_PHY_STATUS),
2391 status, ((status & BIT(0)) == 1),
2392 PLL_POLL_MAX_READS, PLL_POLL_TIMEOUT_US)) {
2393 pr_debug("%s: HDMI PLL status=%x failed to Lock\n",
2394 __func__, status);
2395 pll_locked = 0;
2396 } else {
2397 pll_locked = 1;
2398 }
2399 mdss_ahb_clk_enable(0);
2400
2401 return pll_locked;
2402}
2403
2404static enum handoff hdmi_vco_handoff(struct clk *c)
2405{
2406 enum handoff ret = HANDOFF_DISABLED_CLK;
2407
2408 if (hdmi_pll_lock_status()) {
2409 c->rate = hdmi_vco_get_rate(c);
2410 ret = HANDOFF_ENABLED_CLK;
2411 }
2412
2413 pr_debug("%s: done, ret=%d\n", __func__, ret);
2414 return ret;
2415}
2416
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -07002417static struct clk_ops hdmi_vco_clk_ops = {
2418 .enable = hdmi_vco_enable,
2419 .set_rate = hdmi_vco_set_rate,
2420 .get_rate = hdmi_vco_get_rate,
2421 .round_rate = hdmi_vco_round_rate,
2422 .prepare = hdmi_vco_prepare,
2423 .unprepare = hdmi_vco_unprepare,
2424 .disable = hdmi_vco_disable,
2425 .handoff = hdmi_vco_handoff,
2426};
2427
2428static struct hdmi_pll_vco_clk hdmi_vco_clk = {
Ajay Singh Parmarc4d53dc2013-09-03 17:19:16 -07002429 .min_rate = 600000000,
2430 .max_rate = 1800000000,
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -07002431 .c = {
2432 .dbg_name = "hdmi_vco_clk",
2433 .ops = &hdmi_vco_clk_ops,
2434 CLK_INIT(hdmi_vco_clk.c),
2435 },
2436};
2437
2438struct div_clk hdmipll_div1_clk = {
2439 .data = {
2440 .div = 1,
2441 .min_div = 1,
2442 .max_div = 1,
2443 },
2444 .c = {
2445 .parent = &hdmi_vco_clk.c,
2446 .dbg_name = "hdmipll_div1_clk",
2447 .ops = &clk_ops_div,
2448 .flags = CLKFLAG_NO_RATE_CACHE,
2449 CLK_INIT(hdmipll_div1_clk.c),
2450 },
2451};
2452
2453struct div_clk hdmipll_div2_clk = {
2454 .data = {
2455 .div = 2,
2456 .min_div = 2,
2457 .max_div = 2,
2458 },
2459 .c = {
2460 .parent = &hdmi_vco_clk.c,
2461 .dbg_name = "hdmipll_div2_clk",
2462 .ops = &clk_ops_div,
2463 .flags = CLKFLAG_NO_RATE_CACHE,
2464 CLK_INIT(hdmipll_div2_clk.c),
2465 },
2466};
2467
2468struct div_clk hdmipll_div4_clk = {
2469 .data = {
2470 .div = 4,
2471 .min_div = 4,
2472 .max_div = 4,
2473 },
2474 .c = {
2475 .parent = &hdmi_vco_clk.c,
2476 .dbg_name = "hdmipll_div4_clk",
2477 .ops = &clk_ops_div,
2478 .flags = CLKFLAG_NO_RATE_CACHE,
2479 CLK_INIT(hdmipll_div4_clk.c),
2480 },
2481};
2482
2483struct div_clk hdmipll_div6_clk = {
2484 .data = {
2485 .div = 6,
2486 .min_div = 6,
2487 .max_div = 6,
2488 },
2489 .c = {
2490 .parent = &hdmi_vco_clk.c,
2491 .dbg_name = "hdmipll_div6_clk",
2492 .ops = &clk_ops_div,
2493 .flags = CLKFLAG_NO_RATE_CACHE,
2494 CLK_INIT(hdmipll_div6_clk.c),
2495 },
2496};
2497
2498static int hdmipll_set_mux_sel(struct mux_clk *clk, int mux_sel)
2499{
2500 int rc;
2501
2502 if (!mdss_gdsc_enabled()) {
2503 pr_err("%s: mdss GDSC is not enabled\n", __func__);
2504 return -EPERM;
2505 }
2506
2507 rc = clk_enable(mdss_ahb_clk);
2508 if (rc) {
2509 pr_err("%s: Failed to enable mdss ahb clock\n", __func__);
2510 return rc;
2511 }
2512
2513 pr_debug("%s: mux_sel=%d\n", __func__, mux_sel);
2514 DSS_REG_W(hdmi_phy_pll_base, HDMI_UNI_PLL_POSTDIV1_CFG, mux_sel);
2515
2516 clk_disable(mdss_ahb_clk);
2517
2518 return 0;
2519}
2520
2521static int hdmipll_get_mux_sel(struct mux_clk *clk)
2522{
2523 int mux_sel = 0;
2524
2525 if (mdss_ahb_clk_enable(1)) {
2526 pr_err("%s: Failed to enable mdss ahb clock\n", __func__);
2527 return mux_sel;
2528 }
2529
2530 mux_sel = DSS_REG_R(hdmi_phy_pll_base, HDMI_UNI_PLL_POSTDIV1_CFG);
2531 mux_sel &= 0x03;
2532 pr_debug("%s: mux_sel=%d\n", __func__, mux_sel);
Ajay Singh Parmar6e090282013-09-30 21:43:57 -07002533
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -07002534 mdss_ahb_clk_enable(0);
2535
2536 return mux_sel;
2537}
2538
2539static struct clk_mux_ops hdmipll_mux_ops = {
2540 .set_mux_sel = hdmipll_set_mux_sel,
2541 .get_mux_sel = hdmipll_get_mux_sel,
2542};
2543
2544static struct clk_ops hdmi_mux_ops;
2545
2546static int hdmi_mux_prepare(struct clk *c)
2547{
2548 int ret = 0;
2549
2550 if (c && c->ops && c->ops->set_rate)
2551 ret = c->ops->set_rate(c, c->rate);
2552
2553 return ret;
2554}
2555
2556static struct mux_clk hdmipll_mux_clk = {
2557 MUX_SRC_LIST(
2558 { &hdmipll_div1_clk.c, 0 },
2559 { &hdmipll_div2_clk.c, 1 },
2560 { &hdmipll_div4_clk.c, 2 },
2561 { &hdmipll_div6_clk.c, 3 },
2562 ),
2563 .ops = &hdmipll_mux_ops,
2564 .c = {
2565 .parent = &hdmipll_div1_clk.c,
2566 .dbg_name = "hdmipll_mux_clk",
2567 .ops = &hdmi_mux_ops,
2568 CLK_INIT(hdmipll_mux_clk.c),
2569 },
2570};
2571
2572struct div_clk hdmipll_clk_src = {
2573 .data = {
2574 .div = 5,
2575 .min_div = 5,
2576 .max_div = 5,
2577 },
2578 .c = {
2579 .parent = &hdmipll_mux_clk.c,
2580 .dbg_name = "hdmipll_clk_src",
2581 .ops = &clk_ops_div,
2582 CLK_INIT(hdmipll_clk_src.c),
2583 },
2584};
2585
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07002586void __init mdss_clk_ctrl_pre_init(struct clk *ahb_clk)
2587{
2588 BUG_ON(ahb_clk == NULL);
2589
2590 gdsc_base = ioremap(GDSC_PHYS, GDSC_SIZE);
2591 if (!gdsc_base)
2592 pr_err("%s: unable to remap gdsc base", __func__);
2593
2594 mdss_dsi_base = ioremap(DSI_PHY_PHYS, DSI_PHY_SIZE);
2595 if (!mdss_dsi_base)
2596 pr_err("%s: unable to remap dsi base", __func__);
2597
2598 mdss_ahb_clk = ahb_clk;
2599
2600 hdmi_phy_base = ioremap(HDMI_PHY_PHYS, HDMI_PHY_SIZE);
2601 if (!hdmi_phy_base)
2602 pr_err("%s: unable to ioremap hdmi phy base", __func__);
2603
2604 hdmi_phy_pll_base = ioremap(HDMI_PHY_PLL_PHYS, HDMI_PHY_PLL_SIZE);
2605 if (!hdmi_phy_pll_base)
2606 pr_err("%s: unable to ioremap hdmi phy pll base", __func__);
2607
Kuogee Hsieha20087c2013-08-05 17:53:12 -07002608 mdss_edp_base = ioremap(EDP_PHY_PHYS, EDP_PHY_SIZE);
2609 if (!mdss_edp_base)
2610 pr_err("%s: unable to remap edp base", __func__);
2611
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07002612 pixel_clk_src_ops = clk_ops_slave_div;
2613 pixel_clk_src_ops.prepare = div_prepare;
2614
2615 byte_clk_src_ops = clk_ops_div;
2616 byte_clk_src_ops.prepare = div_prepare;
2617
2618 analog_potsdiv_clk_ops = clk_ops_div;
2619 analog_potsdiv_clk_ops.prepare = div_prepare;
2620
2621 byte_mux_clk_ops = clk_ops_gen_mux;
2622 byte_mux_clk_ops.prepare = mux_prepare;
Vikram Mulukutla853e2fa2013-05-02 20:02:13 -07002623
Kuogee Hsieha20087c2013-08-05 17:53:12 -07002624 edp_mainlink_clk_src_ops = clk_ops_div;
2625 edp_mainlink_clk_src_ops.get_parent = clk_get_parent;
2626 edp_mainlink_clk_src_ops.get_rate = edp_mainlink_get_rate;
2627
2628 edp_pixel_clk_ops = clk_ops_slave_div;
2629 edp_pixel_clk_ops.prepare = div_prepare;
Ajay Singh Parmar44ae83f2013-08-23 00:54:12 -07002630
2631 hdmi_mux_ops = clk_ops_gen_mux;
2632 hdmi_mux_ops.prepare = hdmi_mux_prepare;
Kuogee Hsieha20087c2013-08-05 17:53:12 -07002633}