blob: 9dd4a49e2512bc78e829c959289f2574a3a72f8e [file] [log] [blame]
Greg Griscod6250552011-06-29 14:40:23 -07001/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
Chandan Uddaraju78ae6752010-10-19 12:57:10 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * 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
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of Code Aurora Forum, Inc. 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 "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#include <reg.h>
Shashank Mittalcbd271d2011-01-14 15:18:33 -080031#include <endian.h>
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070032#include <mipi_dsi.h>
33#include <dev/fbcon.h>
Greg Griscod6250552011-06-29 14:40:23 -070034#include <stdlib.h>
Kinson Chike5c93432011-06-17 09:10:29 -070035#include <debug.h>
Kinson Chikfe931032011-07-21 10:01:34 -070036#include <target/display.h>
37#include <platform/iomap.h>
38#include <platform/clock.h>
39
40extern void mdp_disable(void);
41extern int mipi_dsi_cmd_config(struct fbcon_config mipi_fb_cfg, unsigned short num_of_lanes);
42extern void mdp_shutdown(void);
43extern void mdp_start_dma(void);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070044
Chandan Uddarajufe93e822010-11-21 20:44:47 -080045#if DISPLAY_MIPI_PANEL_TOSHIBA
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070046static struct fbcon_config mipi_fb_cfg = {
47 .height = TSH_MIPI_FB_HEIGHT,
48 .width = TSH_MIPI_FB_WIDTH,
49 .stride = TSH_MIPI_FB_WIDTH,
50 .format = FB_FORMAT_RGB888,
51 .bpp = 24,
52 .update_start = NULL,
53 .update_done = NULL,
54};
Kinson Chike5c93432011-06-17 09:10:29 -070055struct mipi_dsi_panel_config toshiba_panel_info = {
56 .mode = MIPI_VIDEO_MODE,
57 .num_of_lanes = 1,
58 .dsi_phy_config = &mipi_dsi_toshiba_panel_phy_ctrl,
59 .panel_cmds = toshiba_panel_video_mode_cmds,
60 .num_of_panel_cmds = ARRAY_SIZE(toshiba_panel_video_mode_cmds),
61};
Chandan Uddarajufe93e822010-11-21 20:44:47 -080062#elif DISPLAY_MIPI_PANEL_NOVATEK_BLUE
63static struct fbcon_config mipi_fb_cfg = {
64 .height = NOV_MIPI_FB_HEIGHT,
65 .width = NOV_MIPI_FB_WIDTH,
66 .stride = NOV_MIPI_FB_WIDTH,
67 .format = FB_FORMAT_RGB888,
68 .bpp = 24,
69 .update_start = NULL,
70 .update_done = NULL,
71};
Kinson Chike5c93432011-06-17 09:10:29 -070072struct mipi_dsi_panel_config novatek_panel_info = {
73 .mode = MIPI_CMD_MODE,
74 .num_of_lanes = 2,
75 .dsi_phy_config = &mipi_dsi_novatek_panel_phy_ctrl,
76 .panel_cmds = novatek_panel_cmd_mode_cmds,
77 .num_of_panel_cmds = ARRAY_SIZE(novatek_panel_cmd_mode_cmds),
78};
79#elif DISPLAY_MIPI_PANEL_TOSHIBA_MDT61
80static struct fbcon_config mipi_fb_cfg = {
81 .height = TSH_MDT61_MIPI_FB_HEIGHT,
82 .width = TSH_MDT61_MIPI_FB_WIDTH,
83 .stride = TSH_MDT61_MIPI_FB_WIDTH,
84 .format = FB_FORMAT_RGB888,
85 .bpp = 24,
86 .update_start = NULL,
87 .update_done = NULL,
88};
89struct mipi_dsi_panel_config toshiba_mdt61_panel_info = {
90 .mode = MIPI_VIDEO_MODE,
91 .num_of_lanes = 3,
92 .dsi_phy_config = &mipi_dsi_toshiba_mdt61_panel_phy_ctrl,
93 .panel_cmds = toshiba_mdt61_video_mode_cmds,
94 .num_of_panel_cmds = ARRAY_SIZE(toshiba_mdt61_video_mode_cmds),
95};
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +053096#elif DISPLAY_MIPI_PANEL_RENESAS
97static struct fbcon_config mipi_fb_cfg = {
98 .height = REN_MIPI_FB_HEIGHT,
99 .width = REN_MIPI_FB_WIDTH,
100 .stride = REN_MIPI_FB_WIDTH,
101 .format = FB_FORMAT_RGB888,
102 .bpp = 24,
103 .update_start = NULL,
104 .update_done = NULL,
105};
106struct mipi_dsi_panel_config renesas_panel_info = {
107 .mode = MIPI_VIDEO_MODE,
108 .num_of_lanes = 2,
109 .dsi_phy_config = &mipi_dsi_renesas_panel_phy_ctrl,
110 .panel_cmds = renesas_panel_video_mode_cmds,
111 .num_of_panel_cmds = ARRAY_SIZE(renesas_panel_video_mode_cmds),
112 .lane_swap = 1,
113};
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800114#else
115static struct fbcon_config mipi_fb_cfg = {
116 .height = 0,
117 .width = 0,
118 .stride = 0,
119 .format = 0,
120 .bpp = 0,
121 .update_start = NULL,
122 .update_done = NULL,
123};
124#endif
125
126static int cmd_mode_status = 0;
Greg Griscod6250552011-06-29 14:40:23 -0700127void secure_writel(uint32_t, uint32_t);
128uint32_t secure_readl(uint32_t);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700129
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800130int mipi_dsi_phy_ctrl_config(struct mipi_dsi_panel_config *pinfo)
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700131{
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800132 unsigned i;
133 unsigned off = 0;
134 struct mipi_dsi_phy_ctrl *pd;
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700135
Kinson Chikfe931032011-07-21 10:01:34 -0700136 writel(0x00000001, DSIPHY_SW_RESET);
137 writel(0x00000000, DSIPHY_SW_RESET);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700138
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800139 pd = (pinfo->dsi_phy_config);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700140
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800141 off = 0x02cc; /* regulator ctrl 0 */
142 for (i = 0; i < 4; i++) {
143 writel(pd->regulator[i], MIPI_DSI_BASE + off);
144 off += 4;
145 }
146
147 off = 0x0260; /* phy timig ctrl 0 */
148 for (i = 0; i < 11; i++) {
149 writel(pd->timing[i], MIPI_DSI_BASE + off);
150 off += 4;
151 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700152
153 // T_CLK_POST, T_CLK_PRE for CLK lane P/N HS 200 mV timing length should >
154 // data lane HS timing length
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800155 writel(0xa1e, DSI_CLKOUT_TIMING_CTRL);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700156
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800157 off = 0x0290; /* ctrl 0 */
158 for (i = 0; i < 4; i++) {
159 writel(pd->ctrl[i], MIPI_DSI_BASE + off);
160 off += 4;
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700161 }
162
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800163 off = 0x02a0; /* strength 0 */
164 for (i = 0; i < 4; i++) {
165 writel(pd->strength[i], MIPI_DSI_BASE + off);
166 off += 4;
167 }
168
169 off = 0x0204; /* pll ctrl 1, skip 0 */
170 for (i = 1; i < 21; i++) {
171 writel(pd->pll[i], MIPI_DSI_BASE + off);
172 off += 4;
173 }
174
175 /* pll ctrl 0 */
176 writel(pd->pll[0], MIPI_DSI_BASE + 0x200);
177 writel((pd->pll[0] | 0x01), MIPI_DSI_BASE + 0x200);
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530178 /* lane swp ctrol */
179 if (pinfo->lane_swap)
180 writel(pinfo->lane_swap, MIPI_DSI_BASE + 0xac);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700181 return (0);
182}
183
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800184struct mipi_dsi_panel_config *get_panel_info(void)
185{
186#if DISPLAY_MIPI_PANEL_TOSHIBA
187 return &toshiba_panel_info;
188#elif DISPLAY_MIPI_PANEL_NOVATEK_BLUE
189 return &novatek_panel_info;
Kinson Chike5c93432011-06-17 09:10:29 -0700190#elif DISPLAY_MIPI_PANEL_TOSHIBA_MDT61
191 return &toshiba_mdt61_panel_info;
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530192#elif DISPLAY_MIPI_PANEL_RENESAS
193 return &renesas_panel_info;
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800194#endif
195 return NULL;
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800196}
197
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700198int dsi_cmd_dma_trigger_for_panel()
199{
200 unsigned long ReadValue;
201 unsigned long count = 0;
202 int status = 0;
203
204 writel(0x03030303, DSI_INT_CTRL);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700205 writel(0x1, DSI_CMD_MODE_DMA_SW_TRIGGER);
206 ReadValue = readl(DSI_INT_CTRL) & 0x00000001;
207 while (ReadValue != 0x00000001) {
208 ReadValue = readl(DSI_INT_CTRL) & 0x00000001;
209 count++;
210 if (count > 0xffff) {
211 status = FAIL;
Kinson Chike5c93432011-06-17 09:10:29 -0700212 dprintf(CRITICAL, "Panel CMD: command mode dma test failed\n");
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700213 return status;
214 }
215 }
216
217 writel((readl(DSI_INT_CTRL) | 0x01000001), DSI_INT_CTRL);
Kinson Chike5c93432011-06-17 09:10:29 -0700218 dprintf
219 (SPEW, "Panel CMD: command mode dma tested successfully\n");
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700220 return status;
221}
222
Chandan Uddarajuc1df5652011-03-03 21:15:51 -0800223
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800224int mipi_dsi_cmds_tx(struct mipi_dsi_cmd *cmds, int count)
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700225{
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800226 int ret = 0;
227 struct mipi_dsi_cmd *cm;
228 int i = 0;
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700229
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800230 cm = cmds;
231 for (i = 0; i < count; i++) {
232 memcpy(DSI_CMD_DMA_MEM_START_ADDR_PANEL, (cm->payload), cm->size);
233 writel(DSI_CMD_DMA_MEM_START_ADDR_PANEL, DSI_DMA_CMD_OFFSET);
234 writel(cm->size, DSI_DMA_CMD_LENGTH); // reg 0x48 for this build
235 ret += dsi_cmd_dma_trigger_for_panel();
Kinson Chikf91907f2011-07-15 10:06:48 -0700236 udelay(80);
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800237 cm++;
238 }
239 return ret;
240}
241
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800242/*
243 * mipi_dsi_cmd_rx: can receive at most 16 bytes
244 * per transaction since it only have 4 32bits reigsters
245 * to hold data.
246 * therefore Maximum Return Packet Size need to be set to 16.
247 * any return data more than MRPS need to be break down
248 * to multiple transactions.
249 */
250int mipi_dsi_cmds_rx(char **rp, int len)
251{
252 uint32_t *lp, data;
253 char * dp;
254 int i, off, cnt;
255 int rlen, res;
256
257 if(len <= 2)
258 rlen = 4; /* short read */
259 else
260 rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */
261
262 if (rlen > MIPI_DSI_REG_LEN) {
263 return 0;
264 }
265
266 res = rlen & 0x03;
267
268 rlen += res; /* 4 byte align */
269 lp = (uint32_t *)(*rp);
270
271 cnt = rlen;
272 cnt += 3;
273 cnt >>=2;
274
275 if (cnt > 4)
276 cnt = 4; /* 4 x 32 bits registers only */
277
278 off = 0x068; /* DSI_RDBK_DATA0 */
279 off += ((cnt - 1) * 4);
280
281 for (i = 0; i < cnt; i++) {
282 data = (uint32_t)readl(MIPI_DSI_BASE + off);
283 *lp++ = ntohl(data); /* to network byte order */
284 off -= 4;
285 }
286
287 if(len > 2)
288 {
289 /*First 4 bytes + paded bytes will be header next len bytes would be payload*/
290 for(i = 0; i < len; i++)
291 {
292 dp = *rp;
293 dp[i] = dp[4 + res + i];
294 }
295 }
296
297 return len;
298}
299
300static int mipi_dsi_cmd_bta_sw_trigger(void)
301{
302 uint32_t data;
303 int cnt = 0;
304 int err = 0;
305
306 writel(0x01, MIPI_DSI_BASE + 0x094); /* trigger */
307 while (cnt < 10000) {
308 data = readl(MIPI_DSI_BASE + 0x0004); /*DSI_STATUS*/
309 if ((data & 0x0010) == 0)
310 break;
311 cnt++;
312 }
313 if(cnt == 10000)
314 err = 1;
315 return err;
316}
317
318static uint32_t mipi_novatek_manufacture_id(void)
319{
320 char rec_buf[24];
321 char *rp = rec_buf;
322 uint32_t *lp, data;
323
324 mipi_dsi_cmds_tx(&novatek_panel_manufacture_id_cmd, 1);
325 mipi_dsi_cmds_rx(&rp, 3);
326
327 lp = (uint32_t *)rp;
328 data = (uint32_t)*lp;
329 data = ntohl(data);
330 data = data >> 8;
331 return data;
332}
333
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800334int mipi_dsi_panel_initialize(struct mipi_dsi_panel_config *pinfo)
335{
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700336 unsigned char DMA_STREAM1 = 0; // for mdp display processor path
337 unsigned char EMBED_MODE1 = 1; // from frame buffer
338 unsigned char POWER_MODE2 = 1; // from frame buffer
339 unsigned char PACK_TYPE1 = 1; // long packet
340 unsigned char VC1 = 0;
341 unsigned char DT1 = 0; // non embedded mode
342 unsigned short WC1 = 0; // for non embedded mode only
343 int status = 0;
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800344 unsigned char DLNx_EN;
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700345
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800346 switch (pinfo->num_of_lanes) {
347 default:
348 case 1:
349 DLNx_EN = 1; // 1 lane
350 break;
351 case 2:
352 DLNx_EN = 3; // 2 lane
353 break;
354 case 3:
355 DLNx_EN = 7; // 3 lane
356 break;
357 }
358
359 writel(0x0001, DSI_SOFT_RESET);
360 writel(0x0000, DSI_SOFT_RESET);
361
Kinson Chike5c93432011-06-17 09:10:29 -0700362 writel((0 << 16) | 0x3f, DSI_CLK_CTRL); /* Turn on all DSI Clks */
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700363 writel(DMA_STREAM1 << 8 | 0x04, DSI_TRIG_CTRL); // reg 0x80 dma trigger: sw
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800364 // trigger 0x4; dma stream1
Kinson Chike5c93432011-06-17 09:10:29 -0700365
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700366 writel(0 << 30 | DLNx_EN << 4 | 0x105, DSI_CTRL); // reg 0x00 for this
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800367 // build
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700368 writel(EMBED_MODE1 << 28 | POWER_MODE2 << 26
369 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
370 DSI_COMMAND_MODE_DMA_CTRL);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700371
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800372 status = mipi_dsi_cmds_tx(pinfo->panel_cmds, pinfo->num_of_panel_cmds);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700373
374 return status;
375}
376
Kinson Chike5c93432011-06-17 09:10:29 -0700377//TODO: Clean up arguments being passed in not being used
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700378int config_dsi_video_mode(unsigned short disp_width, unsigned short disp_height,
379 unsigned short img_width, unsigned short img_height,
380 unsigned short hsync_porch0_fp,
381 unsigned short hsync_porch0_bp,
382 unsigned short vsync_porch0_fp,
383 unsigned short vsync_porch0_bp,
384 unsigned short hsync_width,
385 unsigned short vsync_width, unsigned short dst_format,
386 unsigned short traffic_mode,
387 unsigned short datalane_num)
388{
389
390 unsigned char DST_FORMAT;
391 unsigned char TRAFIC_MODE;
392 unsigned char DLNx_EN;
393 // video mode data ctrl
394 int status = 0;
395 unsigned long low_pwr_stop_mode = 0;
396 unsigned char eof_bllp_pwr = 0x9;
397 unsigned char interleav = 0;
398
399 // disable mdp first
Kinson Chikfe931032011-07-21 10:01:34 -0700400 mdp_disable();
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700401
402 writel(0x00000000, DSI_CLK_CTRL);
403 writel(0x00000000, DSI_CLK_CTRL);
404 writel(0x00000000, DSI_CLK_CTRL);
405 writel(0x00000000, DSI_CLK_CTRL);
406 writel(0x00000002, DSI_CLK_CTRL);
407 writel(0x00000006, DSI_CLK_CTRL);
408 writel(0x0000000e, DSI_CLK_CTRL);
409 writel(0x0000001e, DSI_CLK_CTRL);
410 writel(0x0000003e, DSI_CLK_CTRL);
411
412 writel(0, DSI_CTRL);
413
414 writel(0, DSI_ERR_INT_MASK0);
415
416 DST_FORMAT = 0; // RGB565
Kinson Chike5c93432011-06-17 09:10:29 -0700417 dprintf(SPEW, "DSI_Video_Mode - Dst Format: RGB565\n");
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700418
419 DLNx_EN = 1; // 1 lane with clk programming
Kinson Chike5c93432011-06-17 09:10:29 -0700420 dprintf(SPEW, "Data Lane: 1 lane\n");
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700421
422 TRAFIC_MODE = 0; // non burst mode with sync pulses
Kinson Chike5c93432011-06-17 09:10:29 -0700423 dprintf(SPEW, "Traffic mode: non burst mode with sync pulses\n");
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700424
425 writel(0x02020202, DSI_INT_CTRL);
426
427 writel(((img_width + hsync_porch0_bp) << 16) | hsync_porch0_bp,
428 DSI_VIDEO_MODE_ACTIVE_H);
429
430 writel(((img_height + vsync_porch0_bp) << 16) | (vsync_porch0_bp),
431 DSI_VIDEO_MODE_ACTIVE_V);
432
433 writel(((img_height + vsync_porch0_fp + vsync_porch0_bp) << 16)
434 | img_width + hsync_porch0_fp + hsync_porch0_bp,
435 DSI_VIDEO_MODE_TOTAL);
436
437 writel((hsync_width << 16) | 0, DSI_VIDEO_MODE_HSYNC);
438
439 writel(0 << 16 | 0, DSI_VIDEO_MODE_VSYNC);
440
441 writel(vsync_width << 16 | 0, DSI_VIDEO_MODE_VSYNC_VPOS);
442
443 writel(1, DSI_EOT_PACKET_CTRL);
444
445 writel(0x00000100, DSI_MISR_VIDEO_CTRL);
446
447 writel(low_pwr_stop_mode << 16 | eof_bllp_pwr << 12 | TRAFIC_MODE << 8
448 | DST_FORMAT << 4 | 0x0, DSI_VIDEO_MODE_CTRL);
449
450 writel(0x67, DSI_CAL_STRENGTH_CTRL);
451
452 writel(0x80006711, DSI_CAL_CTRL);
453
454 writel(0x00010100, DSI_MISR_VIDEO_CTRL);
455
456 writel(0x00010100, DSI_INT_CTRL);
457 writel(0x02010202, DSI_INT_CTRL);
458
459 writel(0x02030303, DSI_INT_CTRL);
460
461 writel(interleav << 30 | 0 << 24 | 0 << 20 | DLNx_EN << 4
462 | 0x103, DSI_CTRL);
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800463 mdelay(10);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700464
465 return status;
466}
467
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800468int config_dsi_cmd_mode(unsigned short disp_width, unsigned short disp_height,
469 unsigned short img_width, unsigned short img_height,
470 unsigned short dst_format,
471 unsigned short traffic_mode,
472 unsigned short datalane_num)
473{
474 unsigned char DST_FORMAT;
475 unsigned char TRAFIC_MODE;
476 unsigned char DLNx_EN;
477 // video mode data ctrl
478 int status = 0;
Greg Griscod6250552011-06-29 14:40:23 -0700479 unsigned char interleav = 0;
480 unsigned char ystride = 0x03;
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800481 // disable mdp first
482
483 writel(0x00000000, DSI_CLK_CTRL);
484 writel(0x00000000, DSI_CLK_CTRL);
485 writel(0x00000000, DSI_CLK_CTRL);
486 writel(0x00000000, DSI_CLK_CTRL);
487 writel(0x00000002, DSI_CLK_CTRL);
488 writel(0x00000006, DSI_CLK_CTRL);
489 writel(0x0000000e, DSI_CLK_CTRL);
490 writel(0x0000001e, DSI_CLK_CTRL);
491 writel(0x0000003e, DSI_CLK_CTRL);
492
493 writel(0x10000000, DSI_ERR_INT_MASK0);
494
495 // writel(0, DSI_CTRL);
496
497 // writel(0, DSI_ERR_INT_MASK0);
498
499 DST_FORMAT = 8; // RGB888
Kinson Chike5c93432011-06-17 09:10:29 -0700500 dprintf(SPEW, "DSI_Cmd_Mode - Dst Format: RGB888\n");
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800501
502 DLNx_EN = 3; // 2 lane with clk programming
Kinson Chike5c93432011-06-17 09:10:29 -0700503 dprintf(SPEW, "Data Lane: 2 lane\n");
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800504
505 TRAFIC_MODE = 0; // non burst mode with sync pulses
Kinson Chike5c93432011-06-17 09:10:29 -0700506 dprintf(SPEW, "Traffic mode: non burst mode with sync pulses\n");
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800507
508 writel(0x02020202, DSI_INT_CTRL);
509
510 writel(0x00100000 | DST_FORMAT, DSI_COMMAND_MODE_MDP_CTRL);
511 writel((img_width * ystride + 1) << 16 | 0x0039,
512 DSI_COMMAND_MODE_MDP_STREAM0_CTRL);
513 writel((img_width * ystride + 1) << 16 | 0x0039,
514 DSI_COMMAND_MODE_MDP_STREAM1_CTRL);
515 writel(img_height << 16 | img_width, DSI_COMMAND_MODE_MDP_STREAM0_TOTAL);
516 writel(img_height << 16 | img_width, DSI_COMMAND_MODE_MDP_STREAM1_TOTAL);
517 writel(0xEE, DSI_CAL_STRENGTH_CTRL);
518 writel(0x80000000, DSI_CAL_CTRL);
519 writel(0x40, DSI_TRIG_CTRL);
520 writel(0x13c2c, DSI_COMMAND_MODE_MDP_DCS_CMD_CTRL);
521 writel(interleav << 30 | 0 << 24 | 0 << 20 | DLNx_EN << 4 | 0x105,
522 DSI_CTRL);
523 mdelay(10);
524 writel(0x10000000, DSI_COMMAND_MODE_DMA_CTRL);
525 writel(0x10000000, DSI_MISR_CMD_CTRL);
526 writel(0x00000040, DSI_ERR_INT_MASK0);
527 writel(0x1, DSI_EOT_PACKET_CTRL);
528 // writel(0x0, MDP_OVERLAYPROC0_START);
Kinson Chikfe931032011-07-21 10:01:34 -0700529 mdp_start_dma();
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800530 mdelay(10);
531 writel(0x1, DSI_CMD_MODE_MDP_SW_TRIGGER);
532
533 status = 1;
534 return status;
535}
536
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800537int mipi_dsi_video_config(unsigned short num_of_lanes)
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700538{
539
540 int status = 0;
541 unsigned long ReadValue;
542 unsigned long count = 0;
543 unsigned long low_pwr_stop_mode = 0; // low power mode 0x1111 start from
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800544 // bit16, high spd mode 0x0
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700545 unsigned char eof_bllp_pwr = 0x9; // bit 12, 15, 1:low power stop mode or
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800546 // let cmd mode eng send packets in hs
547 // or lp mode
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700548 unsigned short display_wd = mipi_fb_cfg.width;
549 unsigned short display_ht = mipi_fb_cfg.height;
550 unsigned short image_wd = mipi_fb_cfg.width;
551 unsigned short image_ht = mipi_fb_cfg.height;
552 unsigned short hsync_porch_fp = MIPI_HSYNC_FRONT_PORCH_DCLK;
553 unsigned short hsync_porch_bp = MIPI_HSYNC_BACK_PORCH_DCLK;
554 unsigned short vsync_porch_fp = MIPI_VSYNC_FRONT_PORCH_LINES;
555 unsigned short vsync_porch_bp = MIPI_VSYNC_BACK_PORCH_LINES;
556 unsigned short hsync_width = MIPI_HSYNC_PULSE_WIDTH;
557 unsigned short vsync_width = MIPI_VSYNC_PULSE_WIDTH;
558 unsigned short dst_format = 0;
559 unsigned short traffic_mode = 0;
Kinson Chike5c93432011-06-17 09:10:29 -0700560 unsigned short pack_pattern = 0x12; //BGR
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700561 unsigned char ystride = 3;
562
563 low_pwr_stop_mode = 0x1111; // low pwr mode bit16:HSA, bit20:HBA,
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800564 // bit24:HFP, bit28:PULSE MODE, need enough
565 // time for swithc from LP to HS
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700566 eof_bllp_pwr = 0x9; // low power stop mode or let cmd mode eng send
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800567 // packets in hs or lp mode
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700568
Kinson Chike5c93432011-06-17 09:10:29 -0700569#if DISPLAY_MIPI_PANEL_TOSHIBA_MDT61
570 pack_pattern = 0x21; //RGB
571 config_mdt61_dsi_video_mode();
572
573 /* Two functions make up mdp_setup_dma_p_video_mode with mdt61 panel functions*/
574 mdp_setup_dma_p_video_config(pack_pattern, image_wd, image_ht, MIPI_FB_ADDR, image_wd, ystride);
575 mdp_setup_mdt61_video_dsi_config();
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530576#elif DISPLAY_MIPI_PANEL_RENESAS
577 pack_pattern = 0x21; //RGB
578 config_renesas_dsi_video_mode();
579
580 status +=
581 mdp_setup_dma_p_video_mode(display_wd, display_ht, image_wd, image_ht,
582 hsync_porch_fp, hsync_porch_bp,
583 vsync_porch_fp, vsync_porch_bp, hsync_width,
584 vsync_width, MIPI_FB_ADDR, image_wd,
585 pack_pattern, ystride);
Kinson Chike5c93432011-06-17 09:10:29 -0700586#else
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700587 status += config_dsi_video_mode(display_wd, display_ht, image_wd, image_ht,
588 hsync_porch_fp, hsync_porch_bp,
589 vsync_porch_fp, vsync_porch_bp, hsync_width,
590 vsync_width, dst_format, traffic_mode,
591 num_of_lanes);
592
593 status +=
594 mdp_setup_dma_p_video_mode(display_wd, display_ht, image_wd, image_ht,
595 hsync_porch_fp, hsync_porch_bp,
596 vsync_porch_fp, vsync_porch_bp, hsync_width,
597 vsync_width, MIPI_FB_ADDR, image_wd,
598 pack_pattern, ystride);
Kinson Chike5c93432011-06-17 09:10:29 -0700599#endif
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700600
601 ReadValue = readl(DSI_INT_CTRL) & 0x00010000;
602 while (ReadValue != 0x00010000) {
603 ReadValue = readl(DSI_INT_CTRL) & 0x00010000;
604 count++;
605 if (count > 0xffff) {
606 status = FAIL;
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530607 dprintf(CRITICAL, "Video lane test failed\n");
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700608 return status;
609 }
610 }
611
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530612 dprintf(SPEW, "Video lane tested successfully\n");
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700613 return status;
614}
615
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800616int is_cmd_mode_enabled(void)
617{
618 return cmd_mode_status;
619}
620
Kinson Chike5c93432011-06-17 09:10:29 -0700621#if DISPLAY_MIPI_PANEL_NOVATEK_BLUE
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800622void mipi_dsi_cmd_mode_trigger(void)
623{
624 int status = 0;
625 unsigned short display_wd = mipi_fb_cfg.width;
626 unsigned short display_ht = mipi_fb_cfg.height;
627 unsigned short image_wd = mipi_fb_cfg.width;
628 unsigned short image_ht = mipi_fb_cfg.height;
629 unsigned short dst_format = 0;
630 unsigned short traffic_mode = 0;
631 struct mipi_dsi_panel_config *panel_info = &novatek_panel_info;
Kinson Chikfe931032011-07-21 10:01:34 -0700632 status += mipi_dsi_cmd_config(mipi_fb_cfg, panel_info->num_of_lanes);
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800633 mdelay(50);
634 config_dsi_cmd_mode(display_wd, display_ht, image_wd, image_ht,
635 dst_format, traffic_mode,
636 panel_info->num_of_lanes /* num_of_lanes */ );
637}
Kinson Chike5c93432011-06-17 09:10:29 -0700638#endif
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800639
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700640void mipi_dsi_shutdown(void)
641{
Kinson Chikfe931032011-07-21 10:01:34 -0700642 mdp_shutdown();
Ajay Dudani8fb36092011-01-27 18:09:50 -0800643 writel(0x01010101, DSI_INT_CTRL);
Chandan Uddarajuc1df5652011-03-03 21:15:51 -0800644 writel(0x13FF3BFF, DSI_ERR_INT_MASK0);
Kinson Chikfe931032011-07-21 10:01:34 -0700645 writel(0, DSIPHY_PLL_CTRL(0));
Ajay Dudani8fb36092011-01-27 18:09:50 -0800646 writel(0, DSI_CLK_CTRL);
647 writel(0, DSI_CTRL);
Kinson Chike5c93432011-06-17 09:10:29 -0700648#if DISPLAY_MIPI_PANEL_TOSHIBA_MDT61
Kinson Chikfe931032011-07-21 10:01:34 -0700649 writel(0x0, DSI_CC_REG);
650 writel(0x0, PIXEL_CC_REG);
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530651#elif (!DISPLAY_MIPI_PANEL_RENESAS)
Kinson Chikfe931032011-07-21 10:01:34 -0700652 secure_writel(0x0, DSI_CC_REG);
653 secure_writel(0x0, PIXEL_CC_REG);
Kinson Chike5c93432011-06-17 09:10:29 -0700654#endif
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700655}
656
657struct fbcon_config *mipi_init(void)
658{
659 int status = 0;
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800660 struct mipi_dsi_panel_config *panel_info = get_panel_info();
Kinson Chike5c93432011-06-17 09:10:29 -0700661 /* Enable MMSS_AHB_ARB_MATER_PORT_E for arbiter master0 and master 1 request */
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530662#if (!DISPLAY_MIPI_PANEL_RENESAS)
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700663 writel(0x00001800, MMSS_SFPB_GPREG);
Aparna Mallavarapuf712f5e2011-08-04 21:11:00 +0530664#endif
Kinson Chike5c93432011-06-17 09:10:29 -0700665
666#if DISPLAY_MIPI_PANEL_TOSHIBA_MDT61
667 mipi_dsi_phy_init(panel_info);
668#else
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800669 mipi_dsi_phy_ctrl_config(panel_info);
Kinson Chike5c93432011-06-17 09:10:29 -0700670#endif
671
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800672 status += mipi_dsi_panel_initialize(panel_info);
Kinson Chike5c93432011-06-17 09:10:29 -0700673
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800674#if DISPLAY_MIPI_PANEL_NOVATEK_BLUE
675 mipi_dsi_cmd_bta_sw_trigger();
676 mipi_novatek_manufacture_id();
677#endif
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700678 mipi_fb_cfg.base = MIPI_FB_ADDR;
679
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800680 if (panel_info->mode == MIPI_VIDEO_MODE)
681 status += mipi_dsi_video_config(panel_info->num_of_lanes);
682
683 if (panel_info->mode == MIPI_CMD_MODE)
684 cmd_mode_status = 1;
685
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700686 return &mipi_fb_cfg;
687}