blob: decef5752ac00839597399c86d8533b149fa8f55 [file] [log] [blame]
Asaf Pensob8f524c2013-05-20 12:32:31 +03001/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions
5 * are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in
10 * the documentation and/or other materials provided with the
11 * distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29#include "edp.h"
Asaf Pensob8f524c2013-05-20 12:32:31 +030030
31/* EDP phy configuration settings */
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -070032
33void edp_phy_pll_reset(void)
34{
35 /* EDP_PHY_CTRL */
36 edp_write(EDP_BASE + 0x74, 0x005); /* bit 0, 2 */
37 dmb();
38 udelay(1);
39 edp_write(EDP_BASE + 0x74, 0x000); /* EDP_PHY_CTRL */
40}
41
42void edp_mainlink_reset(void)
43{
44 edp_write(EDP_BASE + 0x04, 0x02 ); /* EDP_MAINLINK_CTRL */
45 dmb();
46 udelay(1);
47 edp_write(EDP_BASE + 0x04, 0 ); /* EDP_MAINLINK_CTRL */
48}
49
50void edp_aux_reset(void)
51{
52 /*reset AUX */
53 edp_write(EDP_BASE + 0x300, BIT(1)); /* EDP_AUX_CTRL */
54 dmb();
55 udelay(1);
56 edp_write(EDP_BASE + 0x300, 0); /* EDP_AUX_CTRL */
57}
58
59void edp_aux_enable(void)
60{
61 edp_write(EDP_BASE + 0x300, 0x01); /* EDP_AUX_CTRL */
62 dmb();
63 udelay(1);
64}
65
66void edp_phy_powerup(int enable)
67{
68 if (enable) {
69 /* EDP_PHY_EDPPHY_GLB_PD_CTL */
70 edp_write(EDP_BASE + 0x52c, 0x3f);
71 /* EDP_PHY_EDPPHY_GLB_CFG */
72 edp_write(EDP_BASE + 0x528, 0x1);
73 /* EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG */
74 edp_write(EDP_BASE + 0x620, 0xf);
75 } else {
76 /* EDP_PHY_EDPPHY_GLB_PD_CTL */
77 edp_write(EDP_BASE + 0x52c, 0xc0);
78 edp_write(EDP_BASE + 0x620, 0x0);
79 }
80}
81
82void edp_lane_power_ctrl(int max_lane, int up)
83{
84 int i, off;
85 unsigned int data;
86
87 if (up)
88 data = 0; /* power up */
89 else
90 data = 0x7; /* power down */
91
92 /* EDP_PHY_EDPPHY_LNn_PD_CTL */
93 for (i = 0; i < max_lane; i++) {
94 off = 0x40 * i;
95 edp_write(EDP_BASE + 0x404 + off , data);
96 }
97}
98
Asaf Pensob8f524c2013-05-20 12:32:31 +030099void edp_phy_sw_reset(void)
100{
101 /* phy sw reset */
102 edp_write(EDP_BASE + 0x74, 0x100); /* EDP_PHY_CTRL */
103 dmb();
104 udelay(1);
105 edp_write(EDP_BASE + 0x74, 0x000); /* EDP_PHY_CTRL */
106 dmb();
107 udelay(1);
108
109 /* phy PLL sw reset */
110 edp_write(EDP_BASE + 0x74, 0x001); /* EDP_PHY_CTRL */
111 dmb();
112 udelay(1);
113 edp_write(EDP_BASE + 0x74, 0x000); /* EDP_PHY_CTRL */
114 dmb();
115 udelay(1);
116}
117
118void edp_hw_powerup(int enable)
119{
120 int ret = 0;
121
122 if (enable) {
123 /* EDP_PHY_EDPPHY_GLB_PD_CTL */
124 edp_write(EDP_BASE + 0x52c, 0x3f);
125 /* EDP_PHY_EDPPHY_GLB_CFG */
126 edp_write(EDP_BASE + 0x528, 0x1);
127 /* EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG */
128 edp_write(EDP_BASE + 0x620, 0xf);
129 /* EDP_AUX_CTRL */
130 ret = edp_read(EDP_BASE + 0x300);
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700131 ret = edp_read(EDP_BASE + 0x300);
Asaf Pensob8f524c2013-05-20 12:32:31 +0300132 edp_write(EDP_BASE + 0x300, ret | 0x1);
133 } else {
134 /* EDP_PHY_EDPPHY_GLB_PD_CTL */
135 edp_write(EDP_BASE + 0x52c, 0xc0);
136 }
137}
138
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700139void edp_pll_configure(unsigned int rate)
Asaf Pensob8f524c2013-05-20 12:32:31 +0300140{
Asaf Pensob8f524c2013-05-20 12:32:31 +0300141
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700142 if (rate == 810000000) {
143 edp_write(EDP_BASE + 0x60c, 0x18);
144 edp_write(EDP_BASE + 0x664, 0x5);
145 edp_write(EDP_BASE + 0x600, 0x0);
146 edp_write(EDP_BASE + 0x638, 0x36);
147 edp_write(EDP_BASE + 0x63c, 0x69);
148 edp_write(EDP_BASE + 0x640, 0xff);
149 edp_write(EDP_BASE + 0x644, 0x2f);
150 edp_write(EDP_BASE + 0x648, 0x0);
151 edp_write(EDP_BASE + 0x66c, 0x0a);
152 edp_write(EDP_BASE + 0x674, 0x01);
153 edp_write(EDP_BASE + 0x684, 0x5a);
154 edp_write(EDP_BASE + 0x688, 0x0);
155 edp_write(EDP_BASE + 0x68c, 0x60);
156 edp_write(EDP_BASE + 0x690, 0x0);
157 edp_write(EDP_BASE + 0x694, 0x2a);
158 edp_write(EDP_BASE + 0x698, 0x3);
159 edp_write(EDP_BASE + 0x65c, 0x10);
160 edp_write(EDP_BASE + 0x660, 0x1a);
161 edp_write(EDP_BASE + 0x604, 0x0);
162 edp_write(EDP_BASE + 0x624, 0x0);
163 edp_write(EDP_BASE + 0x628, 0x0);
164
165 edp_write(EDP_BASE + 0x620, 0x1);
166 edp_write(EDP_BASE + 0x620, 0x5);
167 edp_write(EDP_BASE + 0x620, 0x7);
168 edp_write(EDP_BASE + 0x620, 0xf);
169
170 } else if (rate == 138530000) {
171 edp_write(EDP_BASE + 0x664, 0x5); /* UNIPHY_PLL_LKDET_CFG2 */
172 edp_write(EDP_BASE + 0x600, 0x1); /* UNIPHY_PLL_REFCLK_CFG */
173 edp_write(EDP_BASE + 0x638, 0x36); /* UNIPHY_PLL_SDM_CFG0 */
174 edp_write(EDP_BASE + 0x63c, 0x62); /* UNIPHY_PLL_SDM_CFG1 */
175 edp_write(EDP_BASE + 0x640, 0x0); /* UNIPHY_PLL_SDM_CFG2 */
176 edp_write(EDP_BASE + 0x644, 0x28); /* UNIPHY_PLL_SDM_CFG3 */
177 edp_write(EDP_BASE + 0x648, 0x0); /* UNIPHY_PLL_SDM_CFG4 */
178 edp_write(EDP_BASE + 0x64c, 0x80); /* UNIPHY_PLL_SSC_CFG0 */
179 edp_write(EDP_BASE + 0x650, 0x0); /* UNIPHY_PLL_SSC_CFG1 */
180 edp_write(EDP_BASE + 0x654, 0x0); /* UNIPHY_PLL_SSC_CFG2 */
181 edp_write(EDP_BASE + 0x658, 0x0); /* UNIPHY_PLL_SSC_CFG3 */
182 edp_write(EDP_BASE + 0x66c, 0xa); /* UNIPHY_PLL_CAL_CFG0 */
183 edp_write(EDP_BASE + 0x674, 0x1); /* UNIPHY_PLL_CAL_CFG2 */
184 edp_write(EDP_BASE + 0x684, 0x5a); /* UNIPHY_PLL_CAL_CFG6 */
185 edp_write(EDP_BASE + 0x688, 0x0); /* UNIPHY_PLL_CAL_CFG7 */
186 edp_write(EDP_BASE + 0x68c, 0x60); /* UNIPHY_PLL_CAL_CFG8 */
187 edp_write(EDP_BASE + 0x690, 0x0); /* UNIPHY_PLL_CAL_CFG9 */
188 edp_write(EDP_BASE + 0x694, 0x46); /* UNIPHY_PLL_CAL_CFG10 */
189 edp_write(EDP_BASE + 0x698, 0x5); /* UNIPHY_PLL_CAL_CFG11 */
190 edp_write(EDP_BASE + 0x65c, 0x10); /* UNIPHY_PLL_LKDET_CFG0 */
191 edp_write(EDP_BASE + 0x660, 0x1a); /* UNIPHY_PLL_LKDET_CFG1 */
192 edp_write(EDP_BASE + 0x604, 0x0); /* UNIPHY_PLL_POSTDIV1_CFG */
193 edp_write(EDP_BASE + 0x624, 0x0); /* UNIPHY_PLL_POSTDIV2_CFG */
194 edp_write(EDP_BASE + 0x628, 0x0); /* UNIPHY_PLL_POSTDIV3_CFG */
195
196 edp_write(EDP_BASE + 0x620, 0x1); /* UNIPHY_PLL_GLB_CFG */
197 edp_write(EDP_BASE + 0x620, 0x5); /* UNIPHY_PLL_GLB_CFG */
198 edp_write(EDP_BASE + 0x620, 0x7); /* UNIPHY_PLL_GLB_CFG */
199 edp_write(EDP_BASE + 0x620, 0xf); /* UNIPHY_PLL_GLB_CFG */
200 } else {
201 dprintf(INFO, "%s: rate=%d is NOT supported\n", __func__, rate);
202
203 }
204}
205
206
207int mdss_edp_phy_pll_ready(void)
208{
209 int cnt;
210 int status;
211
212 cnt = 10;
213 while(cnt--) {
214 status = edp_read(EDP_BASE + 0x6c0);
215 if (status & 0x01)
216 break;
217 udelay(100);
218 }
219
220 if(cnt == 0) {
221 dprintf("%s: PLL NOT ready\n", __func__);
222 return 0;
223 }
224 else
225 return 1;
Asaf Pensob8f524c2013-05-20 12:32:31 +0300226}
227
228void edp_enable_mainlink(int enable)
229{
230 uint32_t data;
231
232 data = edp_read(EDP_BASE + 0x004);
233 data &= ~BIT(0);
234
235 if (enable) {
236 data |= 0x1;
237 edp_write(EDP_BASE + 0x004, data);
238 edp_write(EDP_BASE + 0x004, 0x1);
239 } else {
240 data |= 0x0;
241 edp_write(EDP_BASE + 0x004, data);
242 }
243}
244
245void edp_enable_lane_bist(int lane, int enable)
246{
247 unsigned char *addr_ln_bist_cfg, *addr_ln_pd_ctrl;
248
249 /* EDP_PHY_EDPPHY_LNn_PD_CTL */
250 addr_ln_pd_ctrl = (unsigned char *)(EDP_BASE + 0x404 + (0x40 * lane));
251 /* EDP_PHY_EDPPHY_LNn_BIST_CFG0 */
252 addr_ln_bist_cfg = (unsigned char *)(EDP_BASE + 0x408 + (0x40 * lane));
253
254 if (enable) {
255 edp_write(addr_ln_pd_ctrl, 0x0);
256 edp_write(addr_ln_bist_cfg, 0x10);
257
258 } else {
259 edp_write(addr_ln_pd_ctrl, 0xf);
260 edp_write(addr_ln_bist_cfg, 0x10);
261 }
262}
263
264void edp_enable_pixel_clk(int enable)
265{
266 if (!enable) {
267 edp_write(MDSS_EDPPIXEL_CBCR, 0); /* CBCR */
268 return;
269 }
270
271 edp_write(EDP_BASE + 0x624, 0x1); /* PostDiv2 */
272
273 /* Configuring MND for Pixel */
274 edp_write(EDPPIXEL_M, 0x3f); /* M value */
275 edp_write(EDPPIXEL_N, 0xb); /* N value */
276 edp_write(EDPPIXEL_D, 0x0); /* D value */
277
278 /* CFG RCGR */
279 edp_write(EDPPIXEL_CFG_RCGR, (5 << 8) | (2 << 12));
280 edp_write(EDPPIXEL_CMD_RCGR, 3); /* CMD RCGR */
281
282 edp_write(MDSS_EDPPIXEL_CBCR, 1); /* CBCR */
283}
284
285void edp_enable_link_clk(int enable)
286{
287 if (!enable) {
288 edp_write(MDSS_EDPLINK_CBCR, 0); /* CBCR */
289 return;
290 }
291
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700292 edp_write(EDPLINK_CFG_RCGR, (4 << 8) | 0x01); /* CFG RCGR */
Asaf Pensob8f524c2013-05-20 12:32:31 +0300293 edp_write(EDPLINK_CMD_RCGR, 3); /* CMD RCGR */
294
295 edp_write(MDSS_EDPLINK_CBCR, 1); /* CBCR */
296}
297
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700298void edp_enable_aux_clk(int enable)
299{
300 if (!enable) {
301 edp_write(MDSS_EDPAUX_CBCR, 0); /* CBCR */
302 return;
303 }
304
305 edp_write(EDPAUX_CFG_RCGR, 0x01); /* CFG RCGR */
306
307 edp_write(MDSS_EDPAUX_CBCR, 1); /* CBCR */
308}
309
Asaf Pensob8f524c2013-05-20 12:32:31 +0300310void edp_config_clk(void)
311{
312 edp_enable_link_clk(1);
313 edp_enable_pixel_clk(1);
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700314 edp_enable_aux_clk(1);
Asaf Pensob8f524c2013-05-20 12:32:31 +0300315}
316
317void edp_unconfig_clk(void)
318{
319 edp_enable_link_clk(0);
320 edp_enable_pixel_clk(0);
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700321 edp_enable_aux_clk(0);
Asaf Pensob8f524c2013-05-20 12:32:31 +0300322}
323
324void edp_phy_misc_cfg(void)
325{
326 /* EDP_PHY_EDPPHY_GLB_VM_CFG0 */
327 edp_write(EDP_BASE + 0x510, 0x3);
328 /* EDP_PHY_EDPPHY_GLB_VM_CFG1 */
329 edp_write(EDP_BASE + 0x514, 0x64);
330 /* EDP_PHY_EDPPHY_GLB_MISC9 */
331 edp_write(EDP_BASE + 0x518, 0x6c);
332 /* EDP_MISC1_MISC0 */
333 edp_write(EDP_BASE + 0x2c, 0x1);
334}