blob: b752aebe2afa911f66b9c29a20389c4b3946de45 [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>
Chandan Uddaraju09adf322012-08-16 02:55:23 -070024
Chandan Uddaraju09adf322012-08-16 02:55:23 -070025#include "clock-mdss-8974.h"
26
Abhishek Kharbandac1559842012-08-13 18:45:02 -070027#define REG_R(addr) readl_relaxed(addr)
28#define REG_W(data, addr) writel_relaxed(data, addr)
29
30#define DSI_PHY_PHYS 0xFD922800
31#define DSI_PHY_SIZE 0x00000800
32
33#define HDMI_PHY_PHYS 0xFD922500
34#define HDMI_PHY_SIZE 0x0000007C
35
36#define HDMI_PHY_PLL_PHYS 0xFD922700
37#define HDMI_PHY_PLL_SIZE 0x000000D4
38
39/* hdmi phy registers */
Ujwal Patelc8017652012-11-15 18:03:01 -080040#define HDMI_PHY_ANA_CFG0 (0x0000)
41#define HDMI_PHY_ANA_CFG1 (0x0004)
42#define HDMI_PHY_ANA_CFG2 (0x0008)
43#define HDMI_PHY_ANA_CFG3 (0x000C)
44#define HDMI_PHY_PD_CTRL0 (0x0010)
45#define HDMI_PHY_PD_CTRL1 (0x0014)
46#define HDMI_PHY_GLB_CFG (0x0018)
47#define HDMI_PHY_DCC_CFG0 (0x001C)
48#define HDMI_PHY_DCC_CFG1 (0x0020)
49#define HDMI_PHY_TXCAL_CFG0 (0x0024)
50#define HDMI_PHY_TXCAL_CFG1 (0x0028)
51#define HDMI_PHY_TXCAL_CFG2 (0x002C)
52#define HDMI_PHY_TXCAL_CFG3 (0x0030)
53#define HDMI_PHY_BIST_CFG0 (0x0034)
54#define HDMI_PHY_BIST_CFG1 (0x0038)
55#define HDMI_PHY_BIST_PATN0 (0x003C)
56#define HDMI_PHY_BIST_PATN1 (0x0040)
57#define HDMI_PHY_BIST_PATN2 (0x0044)
58#define HDMI_PHY_BIST_PATN3 (0x0048)
59#define HDMI_PHY_STATUS (0x005C)
Abhishek Kharbandac1559842012-08-13 18:45:02 -070060
61/* hdmi phy unified pll registers */
Ujwal Patelc8017652012-11-15 18:03:01 -080062#define HDMI_UNI_PLL_REFCLK_CFG (0x0000)
63#define HDMI_UNI_PLL_POSTDIV1_CFG (0x0004)
64#define HDMI_UNI_PLL_CHFPUMP_CFG (0x0008)
65#define HDMI_UNI_PLL_VCOLPF_CFG (0x000C)
66#define HDMI_UNI_PLL_VREG_CFG (0x0010)
67#define HDMI_UNI_PLL_PWRGEN_CFG (0x0014)
68#define HDMI_UNI_PLL_GLB_CFG (0x0020)
69#define HDMI_UNI_PLL_POSTDIV2_CFG (0x0024)
70#define HDMI_UNI_PLL_POSTDIV3_CFG (0x0028)
71#define HDMI_UNI_PLL_LPFR_CFG (0x002C)
72#define HDMI_UNI_PLL_LPFC1_CFG (0x0030)
73#define HDMI_UNI_PLL_LPFC2_CFG (0x0034)
74#define HDMI_UNI_PLL_SDM_CFG0 (0x0038)
75#define HDMI_UNI_PLL_SDM_CFG1 (0x003C)
76#define HDMI_UNI_PLL_SDM_CFG2 (0x0040)
77#define HDMI_UNI_PLL_SDM_CFG3 (0x0044)
78#define HDMI_UNI_PLL_SDM_CFG4 (0x0048)
79#define HDMI_UNI_PLL_SSC_CFG0 (0x004C)
80#define HDMI_UNI_PLL_SSC_CFG1 (0x0050)
81#define HDMI_UNI_PLL_SSC_CFG2 (0x0054)
82#define HDMI_UNI_PLL_SSC_CFG3 (0x0058)
83#define HDMI_UNI_PLL_LKDET_CFG0 (0x005C)
84#define HDMI_UNI_PLL_LKDET_CFG1 (0x0060)
85#define HDMI_UNI_PLL_LKDET_CFG2 (0x0064)
86#define HDMI_UNI_PLL_CAL_CFG0 (0x006C)
87#define HDMI_UNI_PLL_CAL_CFG1 (0x0070)
88#define HDMI_UNI_PLL_CAL_CFG2 (0x0074)
89#define HDMI_UNI_PLL_CAL_CFG3 (0x0078)
90#define HDMI_UNI_PLL_CAL_CFG4 (0x007C)
91#define HDMI_UNI_PLL_CAL_CFG5 (0x0080)
92#define HDMI_UNI_PLL_CAL_CFG6 (0x0084)
93#define HDMI_UNI_PLL_CAL_CFG7 (0x0088)
94#define HDMI_UNI_PLL_CAL_CFG8 (0x008C)
95#define HDMI_UNI_PLL_CAL_CFG9 (0x0090)
96#define HDMI_UNI_PLL_CAL_CFG10 (0x0094)
97#define HDMI_UNI_PLL_CAL_CFG11 (0x0098)
98#define HDMI_UNI_PLL_STATUS (0x00C0)
Chandan Uddaraju09adf322012-08-16 02:55:23 -070099
100#define VCO_CLK 424000000
101static unsigned char *mdss_dsi_base;
102static int pll_byte_clk_rate;
103static int pll_pclk_rate;
104static int pll_initialized;
105static struct clk *mdss_dsi_ahb_clk;
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700106static unsigned long dsi_pll_rate;
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700107
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700108static void __iomem *hdmi_phy_base;
109static void __iomem *hdmi_phy_pll_base;
110static unsigned hdmi_pll_on;
111
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800112void __init mdss_clk_ctrl_pre_init(struct clk *ahb_clk)
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700113{
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800114 BUG_ON(ahb_clk == NULL);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700115 mdss_dsi_base = ioremap(DSI_PHY_PHYS, DSI_PHY_SIZE);
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700116 if (!mdss_dsi_base)
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700117 pr_err("%s: unable to remap dsi base", __func__);
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700118
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800119 mdss_dsi_ahb_clk = ahb_clk;
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700120
121 hdmi_phy_base = ioremap(HDMI_PHY_PHYS, HDMI_PHY_SIZE);
122 if (!hdmi_phy_base)
123 pr_err("%s: unable to ioremap hdmi phy base", __func__);
124
125 hdmi_phy_pll_base = ioremap(HDMI_PHY_PLL_PHYS, HDMI_PHY_PLL_SIZE);
126 if (!hdmi_phy_pll_base)
127 pr_err("%s: unable to ioremap hdmi phy pll base", __func__);
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700128}
129
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800130#define PLL_POLL_MAX_READS 10
131#define PLL_POLL_TIMEOUT_US 50
132
133static int mdss_dsi_check_pll_lock(void)
134{
135 u32 status;
136
137 clk_prepare_enable(mdss_dsi_ahb_clk);
138 /* poll for PLL ready status */
139 if (readl_poll_timeout_noirq((mdss_dsi_base + 0x02c0),
140 status,
141 ((status & BIT(0)) == 1),
142 PLL_POLL_MAX_READS, PLL_POLL_TIMEOUT_US)) {
143 pr_err("%s: DSI PLL status=%x failed to Lock\n",
144 __func__, status);
145 pll_initialized = 0;
146 } else {
147 pll_initialized = 1;
148 }
149 clk_disable_unprepare(mdss_dsi_ahb_clk);
150
151 return pll_initialized;
152}
153
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700154static long mdss_dsi_pll_byte_round_rate(struct clk *c, unsigned long rate)
155{
156 if (pll_initialized)
157 return pll_byte_clk_rate;
158 else {
159 pr_err("%s: DSI PLL not configured\n",
160 __func__);
161 return -EINVAL;
162 }
163}
164
165static long mdss_dsi_pll_pixel_round_rate(struct clk *c, unsigned long rate)
166{
167 if (pll_initialized)
168 return pll_pclk_rate;
169 else {
170 pr_err("%s: Configure Byte clk first\n",
171 __func__);
172 return -EINVAL;
173 }
174}
175
176static int mdss_dsi_pll_pixel_set_rate(struct clk *c, unsigned long rate)
177{
178 if (pll_initialized)
179 return 0;
180 else {
181 pr_err("%s: Configure Byte clk first\n",
182 __func__);
183 return -EINVAL;
184 }
185}
186
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800187static int __mdss_dsi_pll_byte_set_rate(struct clk *c, unsigned long rate)
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700188{
189 int pll_divcfg1, pll_divcfg2;
190 int half_bitclk_rate;
191
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700192 pr_debug("%s:\n", __func__);
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700193 if (pll_initialized)
194 return 0;
195
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700196 half_bitclk_rate = rate * 4;
197
198 pll_divcfg1 = (VCO_CLK / half_bitclk_rate) - 2;
199
200 /* Configuring the VCO to 424 Mhz */
201 /* Configuring the half rate Bit clk to 212 Mhz */
202
203 pll_divcfg2 = 3; /* ByteClk is 1/4 the half-bitClk rate */
204
205 /* Configure the Loop filter */
206 /* Loop filter resistance value */
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700207 REG_W(0x08, mdss_dsi_base + 0x022c);
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700208 /* Loop filter capacitance values : c1 and c2 */
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700209 REG_W(0x70, mdss_dsi_base + 0x0230);
210 REG_W(0x15, mdss_dsi_base + 0x0234);
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700211
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700212 REG_W(0x02, mdss_dsi_base + 0x0208); /* ChgPump */
213 REG_W(pll_divcfg1, mdss_dsi_base + 0x0204); /* postDiv1 */
214 REG_W(pll_divcfg2, mdss_dsi_base + 0x0224); /* postDiv2 */
215 REG_W(0x03, mdss_dsi_base + 0x0228); /* postDiv3 */
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700216
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700217 REG_W(0x2b, mdss_dsi_base + 0x0278); /* Cal CFG3 */
Chandan Uddarajucee856b2013-02-15 17:27:28 -0800218 REG_W(0x66, mdss_dsi_base + 0x027c); /* Cal CFG4 */
219 REG_W(0x05, mdss_dsi_base + 0x0264); /* LKDET CFG2 */
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700220
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700221 REG_W(0x0a, mdss_dsi_base + 0x023c); /* SDM CFG1 */
222 REG_W(0xab, mdss_dsi_base + 0x0240); /* SDM CFG2 */
223 REG_W(0x0a, mdss_dsi_base + 0x0244); /* SDM CFG3 */
224 REG_W(0x00, mdss_dsi_base + 0x0248); /* SDM CFG4 */
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700225
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700226 REG_W(0x01, mdss_dsi_base + 0x0200); /* REFCLK CFG */
227 REG_W(0x00, mdss_dsi_base + 0x0214); /* PWRGEN CFG */
Chandan Uddarajucee856b2013-02-15 17:27:28 -0800228 REG_W(0x71, mdss_dsi_base + 0x020c); /* VCOLPF CFG */
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700229 REG_W(0x02, mdss_dsi_base + 0x0210); /* VREG CFG */
230 REG_W(0x00, mdss_dsi_base + 0x0238); /* SDM CFG0 */
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700231
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700232 REG_W(0x5f, mdss_dsi_base + 0x028c); /* CAL CFG8 */
233 REG_W(0xa8, mdss_dsi_base + 0x0294); /* CAL CFG10 */
234 REG_W(0x01, mdss_dsi_base + 0x0298); /* CAL CFG11 */
235 REG_W(0x0a, mdss_dsi_base + 0x026c); /* CAL CFG0 */
236 REG_W(0x30, mdss_dsi_base + 0x0284); /* CAL CFG6 */
237 REG_W(0x00, mdss_dsi_base + 0x0288); /* CAL CFG7 */
238 REG_W(0x00, mdss_dsi_base + 0x0290); /* CAL CFG9 */
239 REG_W(0x20, mdss_dsi_base + 0x029c); /* EFUSE CFG */
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700240
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700241 dsi_pll_rate = rate;
242
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700243 pll_byte_clk_rate = 53000000;
244 pll_pclk_rate = 105000000;
245
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700246 pr_debug("%s: **** PLL initialized success\n", __func__);
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700247 pll_initialized = 1;
248
249 return 0;
250}
251
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800252static int mdss_dsi_pll_byte_set_rate(struct clk *c, unsigned long rate)
253{
254 int ret;
255
256 clk_prepare_enable(mdss_dsi_ahb_clk);
257 ret = __mdss_dsi_pll_byte_set_rate(c, rate);
258 clk_disable_unprepare(mdss_dsi_ahb_clk);
259
260 return ret;
261}
262
Chandan Uddarajucee856b2013-02-15 17:27:28 -0800263static void mdss_dsi_uniphy_pll_lock_detect_setting(void)
264{
265 REG_W(0x04, mdss_dsi_base + 0x0264); /* LKDetect CFG2 */
266 udelay(100);
267 REG_W(0x05, mdss_dsi_base + 0x0264); /* LKDetect CFG2 */
268 udelay(500);
269}
270
271static void mdss_dsi_uniphy_pll_sw_reset(void)
272{
273 REG_W(0x01, mdss_dsi_base + 0x0268); /* PLL TEST CFG */
274 udelay(1);
275 REG_W(0x00, mdss_dsi_base + 0x0268); /* PLL TEST CFG */
276 udelay(1);
277}
278
Vikram Mulukutlade6fb292012-10-30 20:29:41 -0700279static int __mdss_dsi_pll_enable(struct clk *c)
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700280{
281 u32 status;
282 u32 max_reads, timeout_us;
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700283 int i;
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700284
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700285 if (!pll_initialized) {
286 if (dsi_pll_rate)
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800287 __mdss_dsi_pll_byte_set_rate(c, dsi_pll_rate);
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700288 else
289 pr_err("%s: Calling clk_en before set_rate\n",
290 __func__);
291 }
292
Chandan Uddarajucee856b2013-02-15 17:27:28 -0800293 mdss_dsi_uniphy_pll_sw_reset();
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700294 /* PLL power up */
Chandan Uddarajucee856b2013-02-15 17:27:28 -0800295 /* Add HW recommended delay between
296 register writes for the update to propagate */
297 REG_W(0x01, mdss_dsi_base + 0x0220); /* GLB CFG */
298 udelay(1000);
299 REG_W(0x05, mdss_dsi_base + 0x0220); /* GLB CFG */
300 udelay(1000);
301 REG_W(0x07, mdss_dsi_base + 0x0220); /* GLB CFG */
302 udelay(1000);
303 REG_W(0x0f, mdss_dsi_base + 0x0220); /* GLB CFG */
304 udelay(1000);
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700305
Chandan Uddarajucee856b2013-02-15 17:27:28 -0800306 for (i = 0; i < 3; i++) {
307 mdss_dsi_uniphy_pll_lock_detect_setting();
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700308 /* poll for PLL ready status */
Chandan Uddarajucee856b2013-02-15 17:27:28 -0800309 max_reads = 5;
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700310 timeout_us = 100;
311 if (readl_poll_timeout_noirq((mdss_dsi_base + 0x02c0),
312 status,
313 ((status & 0x01) == 1),
314 max_reads, timeout_us)) {
315 pr_debug("%s: DSI PLL status=%x failed to Lock\n",
316 __func__, status);
317 pr_debug("%s:Trying to power UP PLL again\n",
318 __func__);
319 } else
320 break;
Chandan Uddarajucee856b2013-02-15 17:27:28 -0800321
322 mdss_dsi_uniphy_pll_sw_reset();
323 udelay(1000);
324 /* Add HW recommended delay between
325 register writes for the update to propagate */
326 REG_W(0x01, mdss_dsi_base + 0x0220); /* GLB CFG */
327 udelay(1000);
328 REG_W(0x05, mdss_dsi_base + 0x0220); /* GLB CFG */
329 udelay(1000);
330 REG_W(0x07, mdss_dsi_base + 0x0220); /* GLB CFG */
331 udelay(1000);
332 REG_W(0x05, mdss_dsi_base + 0x0220); /* GLB CFG */
333 udelay(1000);
334 REG_W(0x07, mdss_dsi_base + 0x0220); /* GLB CFG */
335 udelay(1000);
336 REG_W(0x0f, mdss_dsi_base + 0x0220); /* GLB CFG */
337 udelay(2000);
338
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700339 }
340
341 if ((status & 0x01) != 1) {
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700342 pr_err("%s: DSI PLL status=%x failed to Lock\n",
343 __func__, status);
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700344 return -EINVAL;
345 }
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700346
347 pr_debug("%s: **** PLL Lock success\n", __func__);
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700348
349 return 0;
350}
351
Vikram Mulukutlade6fb292012-10-30 20:29:41 -0700352static void __mdss_dsi_pll_disable(void)
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700353{
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700354 writel_relaxed(0x00, mdss_dsi_base + 0x0220); /* GLB CFG */
Chandan Uddaraju62e5b922012-09-14 20:50:18 -0700355 pr_debug("%s: **** disable pll Initialize\n", __func__);
356 pll_initialized = 0;
Vikram Mulukutlade6fb292012-10-30 20:29:41 -0700357}
358
359static DEFINE_SPINLOCK(dsipll_lock);
360static int dsipll_refcount;
361
362static void mdss_dsi_pll_disable(struct clk *c)
363{
364 unsigned long flags;
365
366 spin_lock_irqsave(&dsipll_lock, flags);
367 if (WARN(dsipll_refcount == 0, "DSI PLL clock is unbalanced"))
368 goto out;
369 if (dsipll_refcount == 1)
370 __mdss_dsi_pll_disable();
371 dsipll_refcount--;
372out:
373 spin_unlock_irqrestore(&dsipll_lock, flags);
374}
375
376static int mdss_dsi_pll_enable(struct clk *c)
377{
378 unsigned long flags;
379 int ret = 0;
380
381 spin_lock_irqsave(&dsipll_lock, flags);
382 if (dsipll_refcount == 0) {
383 ret = __mdss_dsi_pll_enable(c);
384 if (ret < 0)
385 goto out;
386 }
387 dsipll_refcount++;
388out:
389 spin_unlock_irqrestore(&dsipll_lock, flags);
390 return ret;
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700391}
392
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800393static enum handoff mdss_dsi_pll_byte_handoff(struct clk *c)
Saravana Kannanc85ecf92013-01-21 17:58:35 -0800394{
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800395 if (mdss_dsi_check_pll_lock()) {
396 c->rate = 53000000;
397 dsi_pll_rate = 53000000;
398 pll_byte_clk_rate = 53000000;
399 pll_pclk_rate = 105000000;
400 dsipll_refcount++;
401 return HANDOFF_ENABLED_CLK;
402 }
403
404 return HANDOFF_DISABLED_CLK;
405}
406
407static enum handoff mdss_dsi_pll_pixel_handoff(struct clk *c)
408{
409 if (mdss_dsi_check_pll_lock()) {
410 c->rate = 105000000;
411 dsipll_refcount++;
412 return HANDOFF_ENABLED_CLK;
413 }
414
Saravana Kannanc85ecf92013-01-21 17:58:35 -0800415 return HANDOFF_DISABLED_CLK;
416}
417
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700418void hdmi_pll_disable(void)
419{
Vikram Mulukutla5d581bd2012-11-30 11:51:41 -0800420 clk_enable(mdss_dsi_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700421 REG_W(0x0, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
422 udelay(5);
423 REG_W(0x0, hdmi_phy_base + HDMI_PHY_GLB_CFG);
Vikram Mulukutla5d581bd2012-11-30 11:51:41 -0800424 clk_disable(mdss_dsi_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700425
426 hdmi_pll_on = 0;
427} /* hdmi_pll_disable */
428
429int hdmi_pll_enable(void)
430{
431 u32 status;
432 u32 max_reads, timeout_us;
433
Vikram Mulukutla5d581bd2012-11-30 11:51:41 -0800434 clk_enable(mdss_dsi_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700435 /* Global Enable */
436 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
437 /* Power up power gen */
438 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
439 udelay(350);
440
441 /* PLL Power-Up */
442 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
443 udelay(5);
444 /* Power up PLL LDO */
445 REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
446 udelay(350);
447
448 /* PLL Power-Up */
449 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
450 udelay(350);
451
452 /* poll for PLL ready status */
453 max_reads = 20;
454 timeout_us = 100;
455 if (readl_poll_timeout_noirq((hdmi_phy_pll_base + HDMI_UNI_PLL_STATUS),
456 status, ((status & BIT(0)) == 1), max_reads, timeout_us)) {
457 pr_err("%s: hdmi phy pll status=%x failed to Lock\n",
458 __func__, status);
459 hdmi_pll_disable();
Vikram Mulukutla5d581bd2012-11-30 11:51:41 -0800460 clk_disable(mdss_dsi_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700461 return -EINVAL;
462 }
463 pr_debug("%s: hdmi phy pll is locked\n", __func__);
464
465 udelay(350);
466 /* poll for PHY ready status */
467 max_reads = 20;
468 timeout_us = 100;
469 if (readl_poll_timeout_noirq((hdmi_phy_base + HDMI_PHY_STATUS),
470 status, ((status & BIT(0)) == 1), max_reads, timeout_us)) {
471 pr_err("%s: hdmi phy status=%x failed to Lock\n",
472 __func__, status);
473 hdmi_pll_disable();
Vikram Mulukutla5d581bd2012-11-30 11:51:41 -0800474 clk_disable(mdss_dsi_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700475 return -EINVAL;
476 }
477 pr_debug("%s: hdmi phy is locked\n", __func__);
Vikram Mulukutla5d581bd2012-11-30 11:51:41 -0800478 clk_disable(mdss_dsi_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700479
480 hdmi_pll_on = 1;
481
482 return 0;
483} /* hdmi_pll_enable */
484
485int hdmi_pll_set_rate(unsigned long rate)
486{
487 unsigned int set_power_dwn = 0;
488
489 if (hdmi_pll_on) {
490 hdmi_pll_disable();
491 set_power_dwn = 1;
492 }
493
Vikram Mulukutla5d581bd2012-11-30 11:51:41 -0800494 clk_enable(mdss_dsi_ahb_clk);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700495 pr_debug("%s: rate=%ld\n", __func__, rate);
496 switch (rate) {
497 case 0:
498 /* This case is needed for suspend/resume. */
499 break;
500
501 case 25200000:
502 /* 640x480p60 */
Ujwal Patelc8017652012-11-15 18:03:01 -0800503 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
504 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
505 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
506 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
507 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
508 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
509 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
510 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
511 REG_W(0x52, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700512 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
Ujwal Patelc8017652012-11-15 18:03:01 -0800513 REG_W(0xB0, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700514 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
515 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
516 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
517 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
Ujwal Patelc8017652012-11-15 18:03:01 -0800518 REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700519 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
520 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
Ujwal Patelc8017652012-11-15 18:03:01 -0800521 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700522 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
523 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
Ujwal Patelc8017652012-11-15 18:03:01 -0800524 REG_W(0xF4, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
525 REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
526 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
527 udelay(50);
528
529 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
530 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
531 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
532 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
533 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
534 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
535 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
536 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
537 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
538 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
539 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
540 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
541 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
542 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
543 udelay(200);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700544 break;
545
Ujwal Patele698fae2012-11-29 14:04:33 -0800546 case 27000000:
547 /* 576p50/576i50 case */
548 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
549 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
550 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
551 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
552 REG_W(0X0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
553 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
554 REG_W(0X0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
555 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
556 REG_W(0x54, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
557 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
558 REG_W(0x18, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
559 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
560 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
561 REG_W(0X1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
562 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
563 REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG);
564 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
565 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
566 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
567 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
568 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
569 REG_W(0x2a, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
570 REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
571 REG_W(0X1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
572 udelay(50);
573
574 REG_W(0X0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
575 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
576 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
577 REG_W(0XDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
578 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
579 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
580 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
581 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
582 REG_W(0XD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
583 REG_W(0X1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
584 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
585 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
586 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
587 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
588 udelay(200);
589 break;
590
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700591 case 27030000:
592 /* 480p60/480i60 case */
Ujwal Patelc8017652012-11-15 18:03:01 -0800593 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
594 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
595 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
596 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
597 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
598 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
599 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
600 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
601 REG_W(0x54, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
602 REG_W(0x66, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700603 REG_W(0x1D, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
604 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
605 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
606 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
607 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
608 REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG);
609 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
610 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
Ujwal Patelc8017652012-11-15 18:03:01 -0800611 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700612 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
613 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
614 REG_W(0x2A, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
615 REG_W(0x03, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
Ujwal Patelc8017652012-11-15 18:03:01 -0800616 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
617 udelay(50);
618
619 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
620 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
621 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
622 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
623 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
624 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
625 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
626 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
627 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
628 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
629 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
630 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
631 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
632 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
633 udelay(200);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700634 break;
635
636 case 74250000:
637 /*
638 * 720p60/720p50/1080i60/1080i50
639 * 1080p24/1080p30/1080p25 case
640 */
Ujwal Patelc8017652012-11-15 18:03:01 -0800641 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
642 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
643 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
644 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
645 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
646 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
647 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
648 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700649 REG_W(0x52, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
Ujwal Patelc8017652012-11-15 18:03:01 -0800650 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
651 REG_W(0x56, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700652 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
653 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
654 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
655 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
Ujwal Patelc8017652012-11-15 18:03:01 -0800656 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700657 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
658 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
Ujwal Patelc8017652012-11-15 18:03:01 -0800659 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700660 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
661 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
662 REG_W(0xE6, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
663 REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
Ujwal Patelc8017652012-11-15 18:03:01 -0800664 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
665 udelay(50);
666
667 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
668 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
669 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
670 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
671 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
672 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
673 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
674 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
675 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
676 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
677 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
678 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
679 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
680 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
681 udelay(200);
682 break;
683
684 case 148500000:
685 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
686 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
687 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
688 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
689 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
690 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
691 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
692 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
693 REG_W(0x52, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
694 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
695 REG_W(0x56, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
696 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
697 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
698 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
699 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
700 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG);
701 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
702 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
703 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
704 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
705 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
706 REG_W(0xE6, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
707 REG_W(0x02, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
708 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
709 udelay(50);
710
711 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
712 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
713 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
714 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
715 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
716 REG_W(0x02, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
717 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
718 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
719 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
720 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
721 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
722 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
723 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
724 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
725 udelay(200);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700726 break;
727
Ujwal Patele698fae2012-11-29 14:04:33 -0800728 case 268500000:
729 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
730 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
731 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
732 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
733 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
734 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
735 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
736 REG_W(0x36, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
737 REG_W(0x61, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
738 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
739 REG_W(0xF6, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
740 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
741 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
742 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
743 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
744 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG);
745 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
746 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
747 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
748 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
749 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
750 REG_W(0x3E, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
751 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
752 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
753 udelay(50);
754
755 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
756 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
757 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
758 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
759 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
760 REG_W(0x05, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
761 REG_W(0x00, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
762 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
763 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
764 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
765 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
766 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
767 REG_W(0x11, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
768 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
769 udelay(200);
770 break;
771
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700772 case 297000000:
Ujwal Patelc8017652012-11-15 18:03:01 -0800773 REG_W(0x81, hdmi_phy_base + HDMI_PHY_GLB_CFG);
774 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
775 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_REFCLK_CFG);
776 REG_W(0x19, hdmi_phy_pll_base + HDMI_UNI_PLL_VCOLPF_CFG);
777 REG_W(0x0E, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFR_CFG);
778 REG_W(0x20, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC1_CFG);
779 REG_W(0x0D, hdmi_phy_pll_base + HDMI_UNI_PLL_LPFC2_CFG);
780 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG0);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700781 REG_W(0x65, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG1);
Ujwal Patelc8017652012-11-15 18:03:01 -0800782 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700783 REG_W(0xAC, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG3);
784 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_SDM_CFG4);
785 REG_W(0x10, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG0);
786 REG_W(0x1A, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG1);
787 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_LKDET_CFG2);
788 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV1_CFG);
789 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV2_CFG);
790 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_POSTDIV3_CFG);
Ujwal Patelc8017652012-11-15 18:03:01 -0800791 REG_W(0x01, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG2);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700792 REG_W(0x60, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG8);
793 REG_W(0x00, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG9);
794 REG_W(0xCD, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG10);
795 REG_W(0x05, hdmi_phy_pll_base + HDMI_UNI_PLL_CAL_CFG11);
Ujwal Patelc8017652012-11-15 18:03:01 -0800796 REG_W(0x1F, hdmi_phy_base + HDMI_PHY_PD_CTRL0);
797 udelay(50);
798
799 REG_W(0x0F, hdmi_phy_pll_base + HDMI_UNI_PLL_GLB_CFG);
800 REG_W(0x00, hdmi_phy_base + HDMI_PHY_PD_CTRL1);
801 REG_W(0x10, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
802 REG_W(0xDB, hdmi_phy_base + HDMI_PHY_ANA_CFG0);
803 REG_W(0x43, hdmi_phy_base + HDMI_PHY_ANA_CFG1);
804 REG_W(0x06, hdmi_phy_base + HDMI_PHY_ANA_CFG2);
805 REG_W(0x03, hdmi_phy_base + HDMI_PHY_ANA_CFG3);
806 REG_W(0x04, hdmi_phy_pll_base + HDMI_UNI_PLL_VREG_CFG);
807 REG_W(0xD0, hdmi_phy_base + HDMI_PHY_DCC_CFG0);
808 REG_W(0x1A, hdmi_phy_base + HDMI_PHY_DCC_CFG1);
809 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG0);
810 REG_W(0x00, hdmi_phy_base + HDMI_PHY_TXCAL_CFG1);
811 REG_W(0x02, hdmi_phy_base + HDMI_PHY_TXCAL_CFG2);
812 REG_W(0x05, hdmi_phy_base + HDMI_PHY_TXCAL_CFG3);
813 udelay(200);
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700814 break;
815
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700816 default:
817 pr_err("%s: not supported rate=%ld\n", __func__, rate);
818 }
819
820 /* Make sure writes complete before disabling iface clock */
821 mb();
822
Vikram Mulukutla5d581bd2012-11-30 11:51:41 -0800823 clk_disable(mdss_dsi_ahb_clk);
824
Abhishek Kharbandac1559842012-08-13 18:45:02 -0700825 if (set_power_dwn)
826 hdmi_pll_enable();
827
828 return 0;
829} /* hdmi_pll_set_rate */
830
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700831struct clk_ops clk_ops_dsi_pixel_pll = {
832 .enable = mdss_dsi_pll_enable,
833 .disable = mdss_dsi_pll_disable,
834 .set_rate = mdss_dsi_pll_pixel_set_rate,
835 .round_rate = mdss_dsi_pll_pixel_round_rate,
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800836 .handoff = mdss_dsi_pll_pixel_handoff,
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700837};
838
839struct clk_ops clk_ops_dsi_byte_pll = {
840 .enable = mdss_dsi_pll_enable,
841 .disable = mdss_dsi_pll_disable,
842 .set_rate = mdss_dsi_pll_byte_set_rate,
843 .round_rate = mdss_dsi_pll_byte_round_rate,
Siddhartha Agrawal4b0d5a62013-02-25 23:23:41 -0800844 .handoff = mdss_dsi_pll_byte_handoff,
Chandan Uddaraju09adf322012-08-16 02:55:23 -0700845};