blob: b36c4522ab6ac09284f4fe6c993e91c16fdc68df [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{
Kuogee Hsiehe3b50dd2013-09-25 14:40:25 -070084 int i, off;
85 unsigned int data;
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -070086
Kuogee Hsiehe3b50dd2013-09-25 14:40:25 -070087 if (up)
88 data = 0; /* power up */
89 else
90 data = 0x7; /* power down */
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -070091
Kuogee Hsiehe3b50dd2013-09-25 14:40:25 -070092 /* 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 /* power down un used lane */
99 data = 0x7; /* power down */
100 for (i = max_lane; i < EDP_MAX_LANE; i++) {
101 off = 0x40 * i;
102 edp_write(EDP_BASE + 0x404 + off , data);
103 }
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700104}
105
Asaf Pensob8f524c2013-05-20 12:32:31 +0300106void edp_phy_sw_reset(void)
107{
108 /* phy sw reset */
109 edp_write(EDP_BASE + 0x74, 0x100); /* EDP_PHY_CTRL */
110 dmb();
111 udelay(1);
112 edp_write(EDP_BASE + 0x74, 0x000); /* EDP_PHY_CTRL */
113 dmb();
114 udelay(1);
115
116 /* phy PLL sw reset */
117 edp_write(EDP_BASE + 0x74, 0x001); /* EDP_PHY_CTRL */
118 dmb();
119 udelay(1);
120 edp_write(EDP_BASE + 0x74, 0x000); /* EDP_PHY_CTRL */
121 dmb();
122 udelay(1);
123}
124
125void edp_hw_powerup(int enable)
126{
127 int ret = 0;
128
129 if (enable) {
130 /* EDP_PHY_EDPPHY_GLB_PD_CTL */
131 edp_write(EDP_BASE + 0x52c, 0x3f);
132 /* EDP_PHY_EDPPHY_GLB_CFG */
133 edp_write(EDP_BASE + 0x528, 0x1);
134 /* EDP_PHY_PLL_UNIPHY_PLL_GLB_CFG */
135 edp_write(EDP_BASE + 0x620, 0xf);
136 /* EDP_AUX_CTRL */
137 ret = edp_read(EDP_BASE + 0x300);
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700138 ret = edp_read(EDP_BASE + 0x300);
Asaf Pensob8f524c2013-05-20 12:32:31 +0300139 edp_write(EDP_BASE + 0x300, ret | 0x1);
140 } else {
141 /* EDP_PHY_EDPPHY_GLB_PD_CTL */
142 edp_write(EDP_BASE + 0x52c, 0xc0);
143 }
144}
145
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700146void edp_pll_configure(unsigned int rate)
Asaf Pensob8f524c2013-05-20 12:32:31 +0300147{
Asaf Pensob8f524c2013-05-20 12:32:31 +0300148
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700149 if (rate == 810000000) {
150 edp_write(EDP_BASE + 0x60c, 0x18);
151 edp_write(EDP_BASE + 0x664, 0x5);
152 edp_write(EDP_BASE + 0x600, 0x0);
153 edp_write(EDP_BASE + 0x638, 0x36);
154 edp_write(EDP_BASE + 0x63c, 0x69);
155 edp_write(EDP_BASE + 0x640, 0xff);
156 edp_write(EDP_BASE + 0x644, 0x2f);
157 edp_write(EDP_BASE + 0x648, 0x0);
158 edp_write(EDP_BASE + 0x66c, 0x0a);
159 edp_write(EDP_BASE + 0x674, 0x01);
160 edp_write(EDP_BASE + 0x684, 0x5a);
161 edp_write(EDP_BASE + 0x688, 0x0);
162 edp_write(EDP_BASE + 0x68c, 0x60);
163 edp_write(EDP_BASE + 0x690, 0x0);
164 edp_write(EDP_BASE + 0x694, 0x2a);
165 edp_write(EDP_BASE + 0x698, 0x3);
166 edp_write(EDP_BASE + 0x65c, 0x10);
167 edp_write(EDP_BASE + 0x660, 0x1a);
168 edp_write(EDP_BASE + 0x604, 0x0);
169 edp_write(EDP_BASE + 0x624, 0x0);
170 edp_write(EDP_BASE + 0x628, 0x0);
171
172 edp_write(EDP_BASE + 0x620, 0x1);
173 edp_write(EDP_BASE + 0x620, 0x5);
174 edp_write(EDP_BASE + 0x620, 0x7);
175 edp_write(EDP_BASE + 0x620, 0xf);
176
177 } else if (rate == 138530000) {
178 edp_write(EDP_BASE + 0x664, 0x5); /* UNIPHY_PLL_LKDET_CFG2 */
179 edp_write(EDP_BASE + 0x600, 0x1); /* UNIPHY_PLL_REFCLK_CFG */
180 edp_write(EDP_BASE + 0x638, 0x36); /* UNIPHY_PLL_SDM_CFG0 */
181 edp_write(EDP_BASE + 0x63c, 0x62); /* UNIPHY_PLL_SDM_CFG1 */
182 edp_write(EDP_BASE + 0x640, 0x0); /* UNIPHY_PLL_SDM_CFG2 */
183 edp_write(EDP_BASE + 0x644, 0x28); /* UNIPHY_PLL_SDM_CFG3 */
184 edp_write(EDP_BASE + 0x648, 0x0); /* UNIPHY_PLL_SDM_CFG4 */
185 edp_write(EDP_BASE + 0x64c, 0x80); /* UNIPHY_PLL_SSC_CFG0 */
186 edp_write(EDP_BASE + 0x650, 0x0); /* UNIPHY_PLL_SSC_CFG1 */
187 edp_write(EDP_BASE + 0x654, 0x0); /* UNIPHY_PLL_SSC_CFG2 */
188 edp_write(EDP_BASE + 0x658, 0x0); /* UNIPHY_PLL_SSC_CFG3 */
189 edp_write(EDP_BASE + 0x66c, 0xa); /* UNIPHY_PLL_CAL_CFG0 */
190 edp_write(EDP_BASE + 0x674, 0x1); /* UNIPHY_PLL_CAL_CFG2 */
191 edp_write(EDP_BASE + 0x684, 0x5a); /* UNIPHY_PLL_CAL_CFG6 */
192 edp_write(EDP_BASE + 0x688, 0x0); /* UNIPHY_PLL_CAL_CFG7 */
193 edp_write(EDP_BASE + 0x68c, 0x60); /* UNIPHY_PLL_CAL_CFG8 */
194 edp_write(EDP_BASE + 0x690, 0x0); /* UNIPHY_PLL_CAL_CFG9 */
195 edp_write(EDP_BASE + 0x694, 0x46); /* UNIPHY_PLL_CAL_CFG10 */
196 edp_write(EDP_BASE + 0x698, 0x5); /* UNIPHY_PLL_CAL_CFG11 */
197 edp_write(EDP_BASE + 0x65c, 0x10); /* UNIPHY_PLL_LKDET_CFG0 */
198 edp_write(EDP_BASE + 0x660, 0x1a); /* UNIPHY_PLL_LKDET_CFG1 */
199 edp_write(EDP_BASE + 0x604, 0x0); /* UNIPHY_PLL_POSTDIV1_CFG */
200 edp_write(EDP_BASE + 0x624, 0x0); /* UNIPHY_PLL_POSTDIV2_CFG */
201 edp_write(EDP_BASE + 0x628, 0x0); /* UNIPHY_PLL_POSTDIV3_CFG */
202
203 edp_write(EDP_BASE + 0x620, 0x1); /* UNIPHY_PLL_GLB_CFG */
204 edp_write(EDP_BASE + 0x620, 0x5); /* UNIPHY_PLL_GLB_CFG */
205 edp_write(EDP_BASE + 0x620, 0x7); /* UNIPHY_PLL_GLB_CFG */
206 edp_write(EDP_BASE + 0x620, 0xf); /* UNIPHY_PLL_GLB_CFG */
207 } else {
208 dprintf(INFO, "%s: rate=%d is NOT supported\n", __func__, rate);
209
210 }
211}
212
213
214int mdss_edp_phy_pll_ready(void)
215{
216 int cnt;
217 int status;
218
219 cnt = 10;
220 while(cnt--) {
221 status = edp_read(EDP_BASE + 0x6c0);
222 if (status & 0x01)
223 break;
224 udelay(100);
225 }
226
227 if(cnt == 0) {
228 dprintf("%s: PLL NOT ready\n", __func__);
229 return 0;
230 }
231 else
232 return 1;
Asaf Pensob8f524c2013-05-20 12:32:31 +0300233}
234
235void edp_enable_mainlink(int enable)
236{
237 uint32_t data;
238
239 data = edp_read(EDP_BASE + 0x004);
240 data &= ~BIT(0);
241
242 if (enable) {
243 data |= 0x1;
244 edp_write(EDP_BASE + 0x004, data);
245 edp_write(EDP_BASE + 0x004, 0x1);
246 } else {
247 data |= 0x0;
248 edp_write(EDP_BASE + 0x004, data);
249 }
250}
251
252void edp_enable_lane_bist(int lane, int enable)
253{
254 unsigned char *addr_ln_bist_cfg, *addr_ln_pd_ctrl;
255
256 /* EDP_PHY_EDPPHY_LNn_PD_CTL */
257 addr_ln_pd_ctrl = (unsigned char *)(EDP_BASE + 0x404 + (0x40 * lane));
258 /* EDP_PHY_EDPPHY_LNn_BIST_CFG0 */
259 addr_ln_bist_cfg = (unsigned char *)(EDP_BASE + 0x408 + (0x40 * lane));
260
261 if (enable) {
262 edp_write(addr_ln_pd_ctrl, 0x0);
263 edp_write(addr_ln_bist_cfg, 0x10);
264
265 } else {
266 edp_write(addr_ln_pd_ctrl, 0xf);
267 edp_write(addr_ln_bist_cfg, 0x10);
268 }
269}
270
271void edp_enable_pixel_clk(int enable)
272{
273 if (!enable) {
274 edp_write(MDSS_EDPPIXEL_CBCR, 0); /* CBCR */
275 return;
276 }
277
278 edp_write(EDP_BASE + 0x624, 0x1); /* PostDiv2 */
279
280 /* Configuring MND for Pixel */
281 edp_write(EDPPIXEL_M, 0x3f); /* M value */
282 edp_write(EDPPIXEL_N, 0xb); /* N value */
283 edp_write(EDPPIXEL_D, 0x0); /* D value */
284
285 /* CFG RCGR */
286 edp_write(EDPPIXEL_CFG_RCGR, (5 << 8) | (2 << 12));
287 edp_write(EDPPIXEL_CMD_RCGR, 3); /* CMD RCGR */
288
289 edp_write(MDSS_EDPPIXEL_CBCR, 1); /* CBCR */
290}
291
292void edp_enable_link_clk(int enable)
293{
294 if (!enable) {
295 edp_write(MDSS_EDPLINK_CBCR, 0); /* CBCR */
296 return;
297 }
298
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700299 edp_write(EDPLINK_CFG_RCGR, (4 << 8) | 0x01); /* CFG RCGR */
Asaf Pensob8f524c2013-05-20 12:32:31 +0300300 edp_write(EDPLINK_CMD_RCGR, 3); /* CMD RCGR */
301
302 edp_write(MDSS_EDPLINK_CBCR, 1); /* CBCR */
303}
304
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700305void edp_enable_aux_clk(int enable)
306{
307 if (!enable) {
308 edp_write(MDSS_EDPAUX_CBCR, 0); /* CBCR */
309 return;
310 }
311
312 edp_write(EDPAUX_CFG_RCGR, 0x01); /* CFG RCGR */
313
314 edp_write(MDSS_EDPAUX_CBCR, 1); /* CBCR */
315}
316
Asaf Pensob8f524c2013-05-20 12:32:31 +0300317void edp_config_clk(void)
318{
319 edp_enable_link_clk(1);
320 edp_enable_pixel_clk(1);
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700321 edp_enable_aux_clk(1);
Asaf Pensob8f524c2013-05-20 12:32:31 +0300322}
323
324void edp_unconfig_clk(void)
325{
326 edp_enable_link_clk(0);
327 edp_enable_pixel_clk(0);
Kuogee Hsiehad69c3c2013-08-01 14:34:29 -0700328 edp_enable_aux_clk(0);
Asaf Pensob8f524c2013-05-20 12:32:31 +0300329}
330
Kuogee Hsiehe3b50dd2013-09-25 14:40:25 -0700331void edp_phy_vm_pe_init(void)
Asaf Pensob8f524c2013-05-20 12:32:31 +0300332{
333 /* EDP_PHY_EDPPHY_GLB_VM_CFG0 */
334 edp_write(EDP_BASE + 0x510, 0x3);
335 /* EDP_PHY_EDPPHY_GLB_VM_CFG1 */
336 edp_write(EDP_BASE + 0x514, 0x64);
337 /* EDP_PHY_EDPPHY_GLB_MISC9 */
338 edp_write(EDP_BASE + 0x518, 0x6c);
Asaf Pensob8f524c2013-05-20 12:32:31 +0300339}