blob: be86d77d4b7d3641c9c689eebc97fc9be41753fd [file] [log] [blame]
Dhaval Patel5b22fe72014-01-02 16:28:38 -08001/* Copyright (c) 2010-2014, The Linux Foundation. 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.
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -080012 * * Neither the name of The Linux Foundation nor the names of its
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070013 * 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>
Greg Grisco1073a5e2011-07-28 18:59:18 -070035#include <string.h>
Kinson Chike5c93432011-06-17 09:10:29 -070036#include <debug.h>
Kinson Chikfe931032011-07-21 10:01:34 -070037#include <target/display.h>
38#include <platform/iomap.h>
39#include <platform/clock.h>
Greg Grisco1073a5e2011-07-28 18:59:18 -070040#include <platform/timer.h>
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070041#include <err.h>
42#include <msm_panel.h>
Kinson Chikfe931032011-07-21 10:01:34 -070043
44extern void mdp_disable(void);
Ajay Dudanib01e5062011-12-03 23:23:42 -080045extern int mipi_dsi_cmd_config(struct fbcon_config mipi_fb_cfg,
46 unsigned short num_of_lanes);
Kinson Chikfe931032011-07-21 10:01:34 -070047extern void mdp_shutdown(void);
48extern void mdp_start_dma(void);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070049
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -070050#if (DISPLAY_TYPE_MDSS == 0)
51#define MIPI_DSI0_BASE MIPI_DSI_BASE
52#define MIPI_DSI1_BASE MIPI_DSI_BASE
53#endif
54
Chandan Uddarajufe93e822010-11-21 20:44:47 -080055static struct fbcon_config mipi_fb_cfg = {
Ajay Dudanib01e5062011-12-03 23:23:42 -080056 .height = 0,
57 .width = 0,
58 .stride = 0,
59 .format = 0,
60 .bpp = 0,
61 .update_start = NULL,
62 .update_done = NULL,
Chandan Uddarajufe93e822010-11-21 20:44:47 -080063};
Chandan Uddarajufe93e822010-11-21 20:44:47 -080064
65static int cmd_mode_status = 0;
Greg Griscod6250552011-06-29 14:40:23 -070066void secure_writel(uint32_t, uint32_t);
67uint32_t secure_readl(uint32_t);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070068
Shivaraj Shetty64604032013-11-14 16:44:10 +053069static uint32_t response_value = 0;
70
71uint32_t mdss_dsi_read_panel_signature(uint32_t panel_signature)
72{
73 uint32_t rec_buf[1];
74 uint32_t *lp = rec_buf, data;
75 int ret = response_value;
76
77#if (DISPLAY_TYPE_MDSS == 1)
78 if (ret && ret != panel_signature)
79 goto exit_read_signature;
80
81 ret = mipi_dsi_cmds_tx(&read_ddb_start_cmd, 1);
82 if (ret)
83 goto exit_read_signature;
84 if (!mdss_dsi_cmds_rx(&lp, 1, 1))
85 goto exit_read_signature;
86
87 data = ntohl(*lp);
88 data = data >> 8;
89 response_value = data;
90 if (response_value != panel_signature)
91 ret = response_value;
92
93exit_read_signature:
94 /* Keep the non detectable panel at the end and set panel signature 0xFFFF */
95 if (panel_signature == 0xFFFF)
96 ret = 0;
97#endif
98 return ret;
99}
100
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700101int mdss_dual_dsi_cmd_dma_trigger_for_panel()
102{
103 uint32_t ReadValue;
104 uint32_t count = 0;
105 int status = 0;
106
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400107#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700108 writel(0x03030303, MIPI_DSI0_BASE + INT_CTRL);
109 writel(0x1, MIPI_DSI0_BASE + CMD_MODE_DMA_SW_TRIGGER);
110 dsb();
111
112 writel(0x03030303, MIPI_DSI1_BASE + INT_CTRL);
113 writel(0x1, MIPI_DSI1_BASE + CMD_MODE_DMA_SW_TRIGGER);
114 dsb();
115
116 ReadValue = readl(MIPI_DSI1_BASE + INT_CTRL) & 0x00000001;
117 while (ReadValue != 0x00000001) {
118 ReadValue = readl(MIPI_DSI1_BASE + INT_CTRL) & 0x00000001;
119 count++;
120 if (count > 0xffff) {
121 status = FAIL;
122 dprintf(CRITICAL,
123 "Panel CMD: command mode dma test failed\n");
124 return status;
125 }
126 }
127
128 writel((readl(MIPI_DSI1_BASE + INT_CTRL) | 0x01000001),
129 MIPI_DSI1_BASE + INT_CTRL);
130 dprintf(SPEW, "Panel CMD: command mode dma tested successfully\n");
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400131#endif
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700132 return status;
133}
134
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700135int dsi_cmd_dma_trigger_for_panel()
136{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800137 unsigned long ReadValue;
138 unsigned long count = 0;
139 int status = 0;
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700140
Ajay Dudanib01e5062011-12-03 23:23:42 -0800141 writel(0x03030303, DSI_INT_CTRL);
142 writel(0x1, DSI_CMD_MODE_DMA_SW_TRIGGER);
143 dsb();
144 ReadValue = readl(DSI_INT_CTRL) & 0x00000001;
145 while (ReadValue != 0x00000001) {
146 ReadValue = readl(DSI_INT_CTRL) & 0x00000001;
147 count++;
148 if (count > 0xffff) {
149 status = FAIL;
150 dprintf(CRITICAL,
151 "Panel CMD: command mode dma test failed\n");
152 return status;
153 }
154 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700155
Ajay Dudanib01e5062011-12-03 23:23:42 -0800156 writel((readl(DSI_INT_CTRL) | 0x01000001), DSI_INT_CTRL);
157 dprintf(SPEW, "Panel CMD: command mode dma tested successfully\n");
158 return status;
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700159}
160
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700161int mdss_dsi_wait4_video_done()
162{
163 unsigned long read;
164 unsigned long count = 0;
165 int status = 0;
166
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530167 /* If video mode is not enabled, return here */
168 if ((readl(DSI_CTRL) & BIT(1)) == 0)
169 return 0;
170
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700171 read = readl(DSI_INT_CTRL);
172 /* Enable VIDEO MODE DONE MASK and clear the interrupt */
173 read = read | DSI_VIDEO_MODE_DONE_MASK | DSI_VIDEO_MODE_DONE_AK;
174 writel(read, DSI_INT_CTRL);
175 dsb();
176 read = readl(DSI_INT_CTRL) & DSI_VIDEO_MODE_DONE_STAT;
177 while (!read) {
178 read = readl(DSI_INT_CTRL) & DSI_VIDEO_MODE_DONE_STAT;
179 count++;
180 if (count > 0xffff) {
181 status = FAIL;
182 dprintf(CRITICAL,
183 "Panel CMD: Did not recieve video mode done interrupt\n");
184 return status;
185 }
186 }
187
188 writel((readl(DSI_INT_CTRL) | 0x01000001), DSI_INT_CTRL);
189 dprintf(SPEW, "Panel wait_4_video_done: Recieved video mode done ack\n");
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530190
191 /* Skip BLLP 4ms */
192 mdelay(4);
193
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700194 return status;
195
196}
197
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700198int mdss_dual_dsi_cmds_tx(struct mipi_dsi_cmd *cmds, int count)
199{
200 int ret = 0;
201 struct mipi_dsi_cmd *cm;
202 int i = 0;
203 char pload[256];
204 uint32_t off;
205
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400206#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700207 /* Align pload at 8 byte boundry */
208 off = pload;
209 off &= 0x07;
210 if (off)
211 off = 8 - off;
212 off += pload;
213
214 cm = cmds;
215 for (i = 0; i < count; i++) {
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530216 /* Wait for VIDEO_MODE_DONE */
217 ret = mdss_dsi_wait4_video_done();
218 if (ret)
219 goto wait4video_error;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700220
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700221 memcpy((void *)off, (cm->payload), cm->size);
222 writel(off, MIPI_DSI0_BASE + DMA_CMD_OFFSET);
223 writel(cm->size, MIPI_DSI0_BASE + DMA_CMD_LENGTH); // reg 0x48 for this build
224 writel(off, MIPI_DSI1_BASE + DMA_CMD_OFFSET);
225 writel(cm->size, MIPI_DSI1_BASE + DMA_CMD_LENGTH); // reg 0x48 for this build
226 dsb();
227 ret += mdss_dual_dsi_cmd_dma_trigger_for_panel();
Dhaval Patel607a6242013-10-29 12:37:24 -0700228 if (cm->wait)
229 mdelay(cm->wait);
230 else
231 udelay(80);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700232 cm++;
233 }
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700234wait4video_error:
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530235#endif
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700236 return ret;
237}
238
Casey Piper84036752013-09-05 14:56:37 -0700239int mdss_dsi_cmds_rx(uint32_t **rp, int rp_len, int rdbk_len)
240{
241 uint32_t *lp, data;
242 char *dp;
243 int i, off;
244 int rlen, res;
245
246 if (rdbk_len > rp_len) {
247 return 0;
248 }
249
250 if (rdbk_len <= 2)
251 rlen = 4; /* short read */
252 else
253 rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */
254
255 if (rlen > MIPI_DSI_REG_LEN) {
256 return 0;
257 }
258
259 res = rlen & 0x03;
260
261 rlen += res; /* 4 byte align */
262 lp = *rp;
263
264 rlen += 3;
265 rlen >>= 2;
266
267 if (rlen > 4)
268 rlen = 4; /* 4 x 32 bits registers only */
269
Shivaraj Shetty3c77da62013-12-09 15:58:16 +0530270 off = RDBK_DATA0;
Casey Piper84036752013-09-05 14:56:37 -0700271 off += ((rlen - 1) * 4);
272
273 for (i = 0; i < rlen; i++) {
274 data = readl(MIPI_DSI_BASE + off);
275 *lp = ntohl(data); /* to network byte order */
276 lp++;
277
278 off -= 4;
279 }
280
281 if (rdbk_len > 2) {
282 /*First 4 bytes + paded bytes will be header next len bytes would be payload */
283 for (i = 0; i < rdbk_len; i++) {
284 dp = *rp;
285 dp[i] = dp[(res + i) >> 2];
286 }
287 }
288 return rdbk_len;
289}
290
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800291int mipi_dsi_cmds_tx(struct mipi_dsi_cmd *cmds, int count)
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700292{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800293 int ret = 0;
294 struct mipi_dsi_cmd *cm;
295 int i = 0;
296 char pload[256];
297 uint32_t off;
Deepa Dinamania080a402011-11-05 18:59:26 -0700298
Ajay Dudanib01e5062011-12-03 23:23:42 -0800299 /* Align pload at 8 byte boundry */
300 off = pload;
301 off &= 0x07;
302 if (off)
303 off = 8 - off;
304 off += pload;
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700305
Ajay Dudanib01e5062011-12-03 23:23:42 -0800306 cm = cmds;
307 for (i = 0; i < count; i++) {
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530308 /* Wait for VIDEO_MODE_DONE */
309 ret = mdss_dsi_wait4_video_done();
310 if (ret)
311 goto mipi_cmds_error;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700312
Ajay Dudanib01e5062011-12-03 23:23:42 -0800313 memcpy((void *)off, (cm->payload), cm->size);
314 writel(off, DSI_DMA_CMD_OFFSET);
315 writel(cm->size, DSI_DMA_CMD_LENGTH); // reg 0x48 for this build
316 dsb();
317 ret += dsi_cmd_dma_trigger_for_panel();
Sangani Suryanarayana Raju769f9ac2013-04-30 19:05:06 +0530318 dsb();
319 if (cm->wait)
320 mdelay(cm->wait);
321 else
322 udelay(80);
Ajay Dudanib01e5062011-12-03 23:23:42 -0800323 cm++;
324 }
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700325mipi_cmds_error:
Ajay Dudanib01e5062011-12-03 23:23:42 -0800326 return ret;
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800327}
328
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800329/*
330 * mipi_dsi_cmd_rx: can receive at most 16 bytes
331 * per transaction since it only have 4 32bits reigsters
332 * to hold data.
333 * therefore Maximum Return Packet Size need to be set to 16.
334 * any return data more than MRPS need to be break down
335 * to multiple transactions.
336 */
337int mipi_dsi_cmds_rx(char **rp, int len)
338{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800339 uint32_t *lp, data;
340 char *dp;
341 int i, off, cnt;
342 int rlen, res;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800343
Ajay Dudanib01e5062011-12-03 23:23:42 -0800344 if (len <= 2)
345 rlen = 4; /* short read */
346 else
347 rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800348
Ajay Dudanib01e5062011-12-03 23:23:42 -0800349 if (rlen > MIPI_DSI_REG_LEN) {
350 return 0;
351 }
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800352
Ajay Dudanib01e5062011-12-03 23:23:42 -0800353 res = rlen & 0x03;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800354
Ajay Dudanib01e5062011-12-03 23:23:42 -0800355 rlen += res; /* 4 byte align */
356 lp = (uint32_t *) (*rp);
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800357
Ajay Dudanib01e5062011-12-03 23:23:42 -0800358 cnt = rlen;
359 cnt += 3;
360 cnt >>= 2;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800361
Ajay Dudanib01e5062011-12-03 23:23:42 -0800362 if (cnt > 4)
363 cnt = 4; /* 4 x 32 bits registers only */
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800364
Ajay Dudanib01e5062011-12-03 23:23:42 -0800365 off = 0x068; /* DSI_RDBK_DATA0 */
366 off += ((cnt - 1) * 4);
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800367
Ajay Dudanib01e5062011-12-03 23:23:42 -0800368 for (i = 0; i < cnt; i++) {
369 data = (uint32_t) readl(MIPI_DSI_BASE + off);
370 *lp++ = ntohl(data); /* to network byte order */
371 off -= 4;
372 }
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800373
Ajay Dudanib01e5062011-12-03 23:23:42 -0800374 if (len > 2) {
375 /*First 4 bytes + paded bytes will be header next len bytes would be payload */
376 for (i = 0; i < len; i++) {
377 dp = *rp;
378 dp[i] = dp[4 + res + i];
379 }
380 }
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800381
Ajay Dudanib01e5062011-12-03 23:23:42 -0800382 return len;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800383}
384
385static int mipi_dsi_cmd_bta_sw_trigger(void)
386{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800387 uint32_t data;
388 int cnt = 0;
389 int err = 0;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800390
Ajay Dudanib01e5062011-12-03 23:23:42 -0800391 writel(0x01, MIPI_DSI_BASE + 0x094); /* trigger */
392 while (cnt < 10000) {
393 data = readl(MIPI_DSI_BASE + 0x0004); /*DSI_STATUS */
394 if ((data & 0x0010) == 0)
395 break;
396 cnt++;
397 }
398 if (cnt == 10000)
399 err = 1;
400 return err;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800401}
402
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800403int mdss_dsi_host_init(struct mipi_dsi_panel_config *pinfo, uint32_t
Dhaval Patel9207dec2014-04-16 10:45:32 -0700404 dual_dsi, uint32_t broadcast)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700405{
406 uint8_t DMA_STREAM1 = 0; // for mdp display processor path
407 uint8_t EMBED_MODE1 = 1; // from frame buffer
408 uint8_t POWER_MODE2 = 1; // from frame buffer
409 uint8_t PACK_TYPE1; // long packet
410 uint8_t VC1 = 0;
411 uint8_t DT1 = 0; // non embedded mode
412 uint8_t WC1 = 0; // for non embedded mode only
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700413 uint8_t DLNx_EN;
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700414 uint8_t lane_swap = 0;
Siddhartha Agrawalb6c861f2013-05-31 19:36:44 -0700415 uint32_t timing_ctl = 0;
Vineet Bajaj2f08a362014-07-24 20:50:42 +0530416 uint32_t lane_swap_dsi1 = 0;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700417 uint32_t ctrl_mode = 0x105; //Default is command mode to send cmds.
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700418
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400419#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700420 switch (pinfo->num_of_lanes) {
421 default:
422 case 1:
423 DLNx_EN = 1; // 1 lane
424 break;
425 case 2:
426 DLNx_EN = 3; // 2 lane
427 break;
428 case 3:
429 DLNx_EN = 7; // 3 lane
430 break;
431 case 4:
432 DLNx_EN = 0x0F; /* 4 lanes */
433 break;
434 }
435
436 PACK_TYPE1 = pinfo->pack;
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700437 lane_swap = pinfo->lane_swap;
Siddhartha Agrawalb6c861f2013-05-31 19:36:44 -0700438 timing_ctl = ((pinfo->t_clk_post << 8) | pinfo->t_clk_pre);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700439
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700440 if (pinfo->cmds_post_tg) {
441 /*
442 * Need to send pixel data before sending the ON commands
443 * so need to configure controller to VIDEO MODE.
444 */
445 ctrl_mode = 0x103;
446 }
447
Dhaval Patel9207dec2014-04-16 10:45:32 -0700448 if (dual_dsi) {
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700449 writel(0x0001, MIPI_DSI1_BASE + SOFT_RESET);
450 writel(0x0000, MIPI_DSI1_BASE + SOFT_RESET);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700451
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700452 writel((0 << 16) | 0x3f, MIPI_DSI1_BASE + CLK_CTRL); /* Turn on all DSI Clks */
453 writel(DMA_STREAM1 << 8 | 0x04, MIPI_DSI1_BASE + TRIG_CTRL); // reg 0x80 dma trigger: sw
454 // trigger 0x4; dma stream1
455
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700456 writel(0 << 30 | DLNx_EN << 4 | ctrl_mode, MIPI_DSI1_BASE + CTRL); // reg 0x00 for this
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700457 // build
458 writel(broadcast << 31 | EMBED_MODE1 << 28 | POWER_MODE2 << 26
459 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
460 MIPI_DSI1_BASE + COMMAND_MODE_DMA_CTRL);
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700461
Vineet Bajaj2f08a362014-07-24 20:50:42 +0530462 if (readl(MIPI_DSI_BASE) == DSI_HW_REV_103_1) /*for 8939 hw dsi1 has Lane_map as 3210*/
463 lane_swap_dsi1 = 0x7;
464 else
465 lane_swap_dsi1 = lane_swap;
466 writel(lane_swap_dsi1, MIPI_DSI1_BASE + LANE_SWAP_CTL);
Siddhartha Agrawalb6c861f2013-05-31 19:36:44 -0700467 writel(timing_ctl, MIPI_DSI1_BASE + TIMING_CTL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700468 }
469
470 writel(0x0001, MIPI_DSI0_BASE + SOFT_RESET);
471 writel(0x0000, MIPI_DSI0_BASE + SOFT_RESET);
472
473 writel((0 << 16) | 0x3f, MIPI_DSI0_BASE + CLK_CTRL); /* Turn on all DSI Clks */
474 writel(DMA_STREAM1 << 8 | 0x04, MIPI_DSI0_BASE + TRIG_CTRL); // reg 0x80 dma trigger: sw
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700475 // trigger 0x4; dma stream1
476
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700477 writel(0 << 30 | DLNx_EN << 4 | ctrl_mode, MIPI_DSI0_BASE + CTRL); // reg 0x00 for this
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700478 // build
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700479 writel(broadcast << 31 | EMBED_MODE1 << 28 | POWER_MODE2 << 26
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700480 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700481 MIPI_DSI0_BASE + COMMAND_MODE_DMA_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700482
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700483 writel(lane_swap, MIPI_DSI0_BASE + LANE_SWAP_CTL);
Siddhartha Agrawalb6c861f2013-05-31 19:36:44 -0700484 writel(timing_ctl, MIPI_DSI0_BASE + TIMING_CTL);
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800485#endif
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700486
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800487 return 0;
488}
489
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530490void mdss_dsi_panel_shutdown(struct msm_panel_info *pinfo)
491{
492#if (DISPLAY_TYPE_MDSS == 1)
493 unsigned long read_val = 0;
494 if (pinfo->mipi.panel_off_cmds) {
495 /*
496 * Once MDP TG is disabled, reset of DSI controller is
497 * needed before we send panel OFF commands.
498 */
499 if (pinfo->type == MIPI_VIDEO_PANEL) {
500 read_val = readl(MIPI_DSI0_BASE + CTRL);
501 writel((read_val & ~BIT(0)), MIPI_DSI0_BASE + CTRL);
502 writel(0x0001, MIPI_DSI0_BASE + SOFT_RESET);
503 dsb();
504 writel(0x0000, MIPI_DSI0_BASE + SOFT_RESET);
505 dsb();
506 /* Enable cmd mode only */
507 writel(((read_val & ~BIT(1)) | BIT(2)),
508 MIPI_DSI0_BASE + CTRL);
509 }
510
511 if (pinfo->mipi.broadcast) {
512 if (pinfo->type == MIPI_VIDEO_PANEL) {
513 read_val = readl(MIPI_DSI1_BASE + CTRL);
514 writel((read_val & ~BIT(0)),
515 MIPI_DSI1_BASE + CTRL);
516
517 writel(0x0001, MIPI_DSI1_BASE + SOFT_RESET);
518 dsb();
519 writel(0x0000, MIPI_DSI1_BASE + SOFT_RESET);
520 dsb();
521
522 writel(((read_val & ~BIT(1)) | BIT(2)),
523 MIPI_DSI1_BASE + CTRL);
524 }
525 mdss_dual_dsi_cmds_tx(pinfo->mipi.panel_off_cmds,
526 pinfo->mipi.num_of_panel_off_cmds);
527 } else {
528 mipi_dsi_cmds_tx(pinfo->mipi.panel_off_cmds,
529 pinfo->mipi.num_of_panel_off_cmds);
530 }
531 }
532#endif
533}
534
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800535int mdss_dsi_panel_initialize(struct mipi_dsi_panel_config *pinfo, uint32_t
536 broadcast)
537{
538 int status = 0;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700539 uint32_t ctrl_mode = 0;
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800540
541#if (DISPLAY_TYPE_MDSS == 1)
Padmanabhan Komandurub3d31842014-11-04 15:47:53 +0530542 if (pinfo->panel_on_cmds) {
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700543
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700544 ctrl_mode = readl(MIPI_DSI0_BASE + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700545 if (broadcast) {
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700546 /* Enable command mode before sending the commands. */
547 writel(ctrl_mode | 0x04, MIPI_DSI0_BASE + CTRL);
548 writel(ctrl_mode | 0x04, MIPI_DSI1_BASE + CTRL);
Padmanabhan Komandurub3d31842014-11-04 15:47:53 +0530549 status = mdss_dual_dsi_cmds_tx(pinfo->panel_on_cmds,
550 pinfo->num_of_panel_on_cmds);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700551 writel(ctrl_mode, MIPI_DSI0_BASE + CTRL);
552 writel(ctrl_mode, MIPI_DSI1_BASE + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700553
554 } else {
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700555 /* Enable command mode before sending the commands. */
556 writel(ctrl_mode | 0x04, MIPI_DSI0_BASE + CTRL);
Padmanabhan Komandurub3d31842014-11-04 15:47:53 +0530557 status = mipi_dsi_cmds_tx(pinfo->panel_on_cmds,
558 pinfo->num_of_panel_on_cmds);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700559 writel(ctrl_mode, MIPI_DSI0_BASE + CTRL);
Casey Piper84036752013-09-05 14:56:37 -0700560 if (!status && target_panel_auto_detect_enabled())
561 status =
Shivaraj Shetty64604032013-11-14 16:44:10 +0530562 mdss_dsi_read_panel_signature(pinfo->signature);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700563 }
564 }
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400565#endif
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700566 return status;
567}
568
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800569int mipi_dsi_panel_initialize(struct mipi_dsi_panel_config *pinfo)
570{
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800571 uint8_t DMA_STREAM1 = 0; // for mdp display processor path
572 uint8_t EMBED_MODE1 = 1; // from frame buffer
573 uint8_t POWER_MODE2 = 1; // from frame buffer
574 uint8_t PACK_TYPE1; // long packet
575 uint8_t VC1 = 0;
576 uint8_t DT1 = 0; // non embedded mode
577 uint8_t WC1 = 0; // for non embedded mode only
Ajay Dudanib01e5062011-12-03 23:23:42 -0800578 int status = 0;
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800579 uint8_t DLNx_EN;
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700580
Ajay Dudanib01e5062011-12-03 23:23:42 -0800581 switch (pinfo->num_of_lanes) {
582 default:
583 case 1:
584 DLNx_EN = 1; // 1 lane
585 break;
586 case 2:
587 DLNx_EN = 3; // 2 lane
588 break;
589 case 3:
590 DLNx_EN = 7; // 3 lane
591 break;
Amir Samuelov2d4ba162012-07-22 11:53:14 +0300592 case 4:
593 DLNx_EN = 0x0F; /* 4 lanes */
594 break;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800595 }
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800596
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800597 PACK_TYPE1 = pinfo->pack;
598
Ajay Dudanib01e5062011-12-03 23:23:42 -0800599 writel(0x0001, DSI_SOFT_RESET);
600 writel(0x0000, DSI_SOFT_RESET);
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800601
Ajay Dudanib01e5062011-12-03 23:23:42 -0800602 writel((0 << 16) | 0x3f, DSI_CLK_CTRL); /* Turn on all DSI Clks */
603 writel(DMA_STREAM1 << 8 | 0x04, DSI_TRIG_CTRL); // reg 0x80 dma trigger: sw
604 // trigger 0x4; dma stream1
Kinson Chike5c93432011-06-17 09:10:29 -0700605
Ajay Dudanib01e5062011-12-03 23:23:42 -0800606 writel(0 << 30 | DLNx_EN << 4 | 0x105, DSI_CTRL); // reg 0x00 for this
607 // build
608 writel(EMBED_MODE1 << 28 | POWER_MODE2 << 26
609 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
610 DSI_COMMAND_MODE_DMA_CTRL);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700611
Padmanabhan Komandurub3d31842014-11-04 15:47:53 +0530612 if (pinfo->panel_on_cmds)
613 status = mipi_dsi_cmds_tx(pinfo->panel_on_cmds,
614 pinfo->num_of_panel_on_cmds);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700615
Ajay Dudanib01e5062011-12-03 23:23:42 -0800616 return status;
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700617}
618
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700619void mipi_dsi_shutdown(void)
620{
Amol Jadi6834f1a2012-06-29 14:42:59 -0700621 if(!target_cont_splash_screen())
622 {
623 mdp_shutdown();
624 writel(0x01010101, DSI_INT_CTRL);
625 writel(0x13FF3BFF, DSI_ERR_INT_MASK0);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700626
Amol Jadi6834f1a2012-06-29 14:42:59 -0700627 writel(0, DSI_CLK_CTRL);
628 writel(0, DSI_CTRL);
629 writel(0, DSIPHY_PLL_CTRL(0));
630 }
631 else
632 {
Chandan Uddaraju4877d372011-07-21 12:51:51 -0700633 /* To keep the splash screen displayed till kernel driver takes
634 control, do not turn off the video mode engine and clocks.
635 Only disabling the MIPI DSI IRQs */
636 writel(0x01010101, DSI_INT_CTRL);
637 writel(0x13FF3BFF, DSI_ERR_INT_MASK0);
Amol Jadi6834f1a2012-06-29 14:42:59 -0700638 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700639}
640
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700641int mipi_config(struct msm_fb_panel_data *panel)
642{
643 int ret = NO_ERROR;
644 struct msm_panel_info *pinfo;
645 struct mipi_dsi_panel_config mipi_pinfo;
646
647 if (!panel)
648 return ERR_INVALID_ARGS;
649
650 pinfo = &(panel->panel_info);
651 mipi_pinfo.mode = pinfo->mipi.mode;
652 mipi_pinfo.num_of_lanes = pinfo->mipi.num_of_lanes;
653 mipi_pinfo.dsi_phy_config = pinfo->mipi.dsi_phy_db;
Padmanabhan Komandurub3d31842014-11-04 15:47:53 +0530654 mipi_pinfo.panel_on_cmds = pinfo->mipi.panel_on_cmds;
655 mipi_pinfo.num_of_panel_on_cmds = pinfo->mipi.num_of_panel_on_cmds;
Channagoud Kadabi539ef722012-03-29 16:02:50 +0530656 mipi_pinfo.lane_swap = pinfo->mipi.lane_swap;
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800657 mipi_pinfo.pack = 1;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700658
659 /* Enable MMSS_AHB_ARB_MATER_PORT_E for
660 arbiter master0 and master 1 request */
Terence Hampsonf49ff4e2013-06-18 15:11:31 -0400661#if (!DISPLAY_MIPI_PANEL_RENESAS && !DISPLAY_TYPE_DSI6G && !DISPLAY_TYPE_8610)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700662 writel(0x00001800, MMSS_SFPB_GPREG);
663#endif
664
665 mipi_dsi_phy_init(&mipi_pinfo);
666
667 ret += mipi_dsi_panel_initialize(&mipi_pinfo);
668
Channagoud Kadabi01c91822012-06-06 15:53:30 +0530669 if (pinfo->rotate && panel->rotate)
670 pinfo->rotate();
671
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700672 return ret;
673}
674
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700675int mdss_dsi_video_mode_config(uint16_t disp_width,
676 uint16_t disp_height,
677 uint16_t img_width,
678 uint16_t img_height,
679 uint16_t hsync_porch0_fp,
680 uint16_t hsync_porch0_bp,
681 uint16_t vsync_porch0_fp,
682 uint16_t vsync_porch0_bp,
683 uint16_t hsync_width,
684 uint16_t vsync_width,
685 uint16_t dst_format,
686 uint16_t traffic_mode,
687 uint8_t lane_en,
688 uint16_t low_pwr_stop_mode,
689 uint8_t eof_bllp_pwr,
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700690 uint8_t interleav,
691 uint32_t ctl_base)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700692{
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700693 int status = 0;
694
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400695#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700696 /* disable mdp first */
697 mdp_disable();
698
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700699 writel(0x00000000, ctl_base + CLK_CTRL);
700 writel(0x00000002, ctl_base + CLK_CTRL);
701 writel(0x00000006, ctl_base + CLK_CTRL);
702 writel(0x0000000e, ctl_base + CLK_CTRL);
703 writel(0x0000001e, ctl_base + CLK_CTRL);
704 writel(0x0000023f, ctl_base + CLK_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700705
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700706 writel(0, ctl_base + CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700707
Padmanabhan Komanduru7860be52014-03-18 19:07:36 +0530708 writel(0x13ff3fe0, ctl_base + ERR_INT_MASK0);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700709
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700710 writel(0x02020202, ctl_base + INT_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700711
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530712 /* For 8916/8939, enable DSI timing double buffering */
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530713 if (readl(ctl_base) == DSI_HW_REV_103_1 &&
714 mdp_get_revision() != MDP_REV_305)
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530715 writel(0x1, ctl_base + TIMING_DB_MODE);
716
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700717 writel(((disp_width + hsync_porch0_bp) << 16) | hsync_porch0_bp,
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700718 ctl_base + VIDEO_MODE_ACTIVE_H);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700719
720 writel(((disp_height + vsync_porch0_bp) << 16) | (vsync_porch0_bp),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700721 ctl_base + VIDEO_MODE_ACTIVE_V);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700722
Terence Hampson7385f6a2013-08-16 15:31:25 -0400723 if (mdp_get_revision() >= MDP_REV_41 ||
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530724 mdp_get_revision() == MDP_REV_304 ||
725 mdp_get_revision() == MDP_REV_305) {
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700726 writel(((disp_height + vsync_porch0_fp
727 + vsync_porch0_bp - 1) << 16)
728 | (disp_width + hsync_porch0_fp
729 + hsync_porch0_bp - 1),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700730 ctl_base + VIDEO_MODE_TOTAL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700731 } else {
732 writel(((disp_height + vsync_porch0_fp
733 + vsync_porch0_bp) << 16)
734 | (disp_width + hsync_porch0_fp
735 + hsync_porch0_bp),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700736 ctl_base + VIDEO_MODE_TOTAL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700737 }
738
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700739 writel((hsync_width << 16) | 0, ctl_base + VIDEO_MODE_HSYNC);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700740
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700741 writel(0 << 16 | 0, ctl_base + VIDEO_MODE_VSYNC);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700742
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700743 writel(vsync_width << 16 | 0, ctl_base + VIDEO_MODE_VSYNC_VPOS);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700744
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530745 /* For 8916/8939, flush the DSI timing registers */
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530746 if (readl(ctl_base) == DSI_HW_REV_103_1 &&
747 mdp_get_revision() != MDP_REV_305)
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530748 writel(0x1, ctl_base + TIMING_FLUSH);
749
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700750 writel(0x0, ctl_base + EOT_PACKET_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700751
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700752 writel(0x00000100, ctl_base + MISR_VIDEO_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700753
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530754 if (mdp_get_revision() >= MDP_REV_41 || mdp_get_revision() == MDP_REV_305) {
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700755 writel(low_pwr_stop_mode << 16 |
756 eof_bllp_pwr << 12 | traffic_mode << 8
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700757 | dst_format << 4 | 0x0, ctl_base + VIDEO_MODE_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700758 } else {
759 writel(1 << 28 | 1 << 24 | 1 << 20 | low_pwr_stop_mode << 16 |
760 eof_bllp_pwr << 12 | traffic_mode << 8
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700761 | dst_format << 4 | 0x0, ctl_base + VIDEO_MODE_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700762 }
763
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700764 writel(0x3fd08, ctl_base + HS_TIMER_CTRL);
765 writel(0x00010100, ctl_base + MISR_VIDEO_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700766
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700767 writel(0x00010100, ctl_base + INT_CTRL);
768 writel(0x02010202, ctl_base + INT_CTRL);
769 writel(0x02030303, ctl_base + INT_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700770
771 writel(interleav << 30 | 0 << 24 | 0 << 20 | lane_en << 4
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700772 | 0x103, ctl_base + CTRL);
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400773#endif
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700774
775 return status;
776}
777
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800778int mdss_dsi_config(struct msm_fb_panel_data *panel)
779{
780 int ret = NO_ERROR;
781 struct msm_panel_info *pinfo;
782 struct mipi_dsi_panel_config mipi_pinfo;
783
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400784#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800785 if (!panel)
786 return ERR_INVALID_ARGS;
787
788 pinfo = &(panel->panel_info);
789 mipi_pinfo.mode = pinfo->mipi.mode;
790 mipi_pinfo.num_of_lanes = pinfo->mipi.num_of_lanes;
791 mipi_pinfo.mdss_dsi_phy_config = pinfo->mipi.mdss_dsi_phy_db;
Padmanabhan Komandurub3d31842014-11-04 15:47:53 +0530792 mipi_pinfo.panel_on_cmds = pinfo->mipi.panel_on_cmds;
793 mipi_pinfo.num_of_panel_on_cmds = pinfo->mipi.num_of_panel_on_cmds;
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800794 mipi_pinfo.lane_swap = pinfo->mipi.lane_swap;
795 mipi_pinfo.pack = 0;
Siddhartha Agrawalb6c861f2013-05-31 19:36:44 -0700796 mipi_pinfo.t_clk_pre = pinfo->mipi.t_clk_pre;
797 mipi_pinfo.t_clk_post = pinfo->mipi.t_clk_post;
Casey Piper84036752013-09-05 14:56:37 -0700798 mipi_pinfo.signature = pinfo->mipi.signature;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700799 mipi_pinfo.cmds_post_tg = pinfo->mipi.cmds_post_tg;
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800800
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530801 mdss_dsi_phy_init(&mipi_pinfo, MIPI_DSI0_BASE, DSI0_PHY_BASE);
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -0700802 if (pinfo->mipi.dual_dsi)
Padmanabhan Komandurucdc651e2014-03-25 20:25:55 +0530803 mdss_dsi_phy_init(&mipi_pinfo, MIPI_DSI1_BASE, DSI1_PHY_BASE);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800804
Dhaval Patel9207dec2014-04-16 10:45:32 -0700805 ret = mdss_dsi_host_init(&mipi_pinfo, pinfo->mipi.dual_dsi,
806 pinfo->mipi.broadcast);
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800807 if (ret) {
808 dprintf(CRITICAL, "dsi host init error\n");
809 goto error;
810 }
811
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400812 mdss_dsi_phy_contention_detection(&mipi_pinfo, DSI0_PHY_BASE);
813
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800814 if (panel->pre_init_func) {
815 ret = panel->pre_init_func();
816 if (ret) {
817 dprintf(CRITICAL, "pre_init_func error\n");
818 goto error;
819 }
820 }
821
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700822 if (!mipi_pinfo.cmds_post_tg) {
823 ret = mdss_dsi_panel_initialize(&mipi_pinfo, pinfo->mipi.broadcast);
824 if (ret) {
825 dprintf(CRITICAL, "dsi panel init error\n");
826 goto error;
827 }
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800828 }
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800829
830 if (pinfo->rotate && panel->rotate)
831 pinfo->rotate();
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400832#endif
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800833
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800834error:
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800835 return ret;
836}
837
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700838int mdss_dsi_post_on(struct msm_fb_panel_data *panel)
839{
840 int ret = 0;
841 struct msm_panel_info *pinfo = &(panel->panel_info);
842 struct mipi_dsi_panel_config mipi_pinfo;
843
844 if (pinfo->mipi.cmds_post_tg) {
Padmanabhan Komandurub3d31842014-11-04 15:47:53 +0530845 mipi_pinfo.panel_on_cmds = pinfo->mipi.panel_on_cmds;
846 mipi_pinfo.num_of_panel_on_cmds =
847 pinfo->mipi.num_of_panel_on_cmds;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700848 mipi_pinfo.signature = pinfo->mipi.signature;
849
850 ret = mdss_dsi_panel_initialize(&mipi_pinfo, pinfo->mipi.broadcast);
851 if (ret) {
852 dprintf(CRITICAL, "dsi panel init error\n");
853 }
854 }
855 return ret;
856}
857
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700858int mdss_dsi_cmd_mode_config(uint16_t disp_width,
859 uint16_t disp_height,
860 uint16_t img_width,
861 uint16_t img_height,
862 uint16_t dst_format,
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400863 uint8_t ystride,
864 uint8_t lane_en,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800865 uint8_t interleav,
866 uint32_t ctl_base)
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700867{
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400868 uint16_t dst_fmt = 0;
869
870 switch (dst_format) {
871 case DSI_VIDEO_DST_FORMAT_RGB565:
872 dst_fmt = DSI_CMD_DST_FORMAT_RGB565;
873 break;
874 case DSI_VIDEO_DST_FORMAT_RGB666:
875 case DSI_VIDEO_DST_FORMAT_RGB666_LOOSE:
876 dst_fmt = DSI_CMD_DST_FORMAT_RGB666;
877 break;
878 case DSI_VIDEO_DST_FORMAT_RGB888:
879 dst_fmt = DSI_CMD_DST_FORMAT_RGB888;
880 break;
881 default:
882 dprintf(CRITICAL, "unsupported dst format\n");
883 return ERROR;
884 }
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700885
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400886#if (DISPLAY_TYPE_MDSS == 1)
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800887 writel(0x00000000, ctl_base + CLK_CTRL);
888 writel(0x00000000, ctl_base + CLK_CTRL);
889 writel(0x00000000, ctl_base + CLK_CTRL);
890 writel(0x00000000, ctl_base + CLK_CTRL);
891 writel(0x00000002, ctl_base + CLK_CTRL);
892 writel(0x00000006, ctl_base + CLK_CTRL);
893 writel(0x0000000e, ctl_base + CLK_CTRL);
894 writel(0x0000001e, ctl_base + CLK_CTRL);
895 writel(0x0000023f, ctl_base + CLK_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700896
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800897 writel(0, ctl_base + CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700898
Padmanabhan Komanduru7860be52014-03-18 19:07:36 +0530899 writel(0x13ff3fe0, ctl_base + ERR_INT_MASK0);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700900
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800901 writel(0x02020202, ctl_base + INT_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700902
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800903 writel(dst_fmt, ctl_base + COMMAND_MODE_MDP_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700904 writel((img_width * ystride + 1) << 16 | 0x0039,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800905 ctl_base + COMMAND_MODE_MDP_STREAM0_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700906 writel((img_width * ystride + 1) << 16 | 0x0039,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800907 ctl_base + COMMAND_MODE_MDP_STREAM1_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700908 writel(img_height << 16 | img_width,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800909 ctl_base + COMMAND_MODE_MDP_STREAM0_TOTAL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700910 writel(img_height << 16 | img_width,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800911 ctl_base + COMMAND_MODE_MDP_STREAM1_TOTAL);
912 writel(0x13c2c, ctl_base + COMMAND_MODE_MDP_DCS_CMD_CTRL);
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400913 writel(interleav << 30 | 0 << 24 | 0 << 20 | lane_en << 4 | 0x105,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800914 ctl_base + CTRL);
Padmanabhan Komanduru7860be52014-03-18 19:07:36 +0530915 writel(0x14000000, ctl_base + COMMAND_MODE_DMA_CTRL);
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800916 writel(0x10000000, ctl_base + MISR_CMD_CTRL);
Xiaoming Zhoua0469332014-03-04 18:34:24 -0500917 writel(0x1, ctl_base + EOT_PACKET_CTRL);
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400918#endif
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400919 return 0;
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700920}
921
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700922int mipi_dsi_on()
923{
924 int ret = NO_ERROR;
925 unsigned long ReadValue;
926 unsigned long count = 0;
927
928 ReadValue = readl(DSI_INT_CTRL) & 0x00010000;
929
930 mdelay(10);
931
932 while (ReadValue != 0x00010000) {
933 ReadValue = readl(DSI_INT_CTRL) & 0x00010000;
934 count++;
935 if (count > 0xffff) {
936 dprintf(CRITICAL, "Video lane test failed\n");
937 return ERROR;
938 }
939 }
940
Amir Samuelov2d4ba162012-07-22 11:53:14 +0300941 dprintf(INFO, "Video lane tested successfully\n");
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700942 return ret;
943}
944
Siddhartha Agrawal24d81b52013-07-01 11:13:32 -0700945int mipi_dsi_off(struct msm_panel_info *pinfo)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700946{
Amol Jadi6834f1a2012-06-29 14:42:59 -0700947 if(!target_cont_splash_screen())
948 {
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530949 mdss_dsi_panel_shutdown(pinfo);
Amol Jadi6834f1a2012-06-29 14:42:59 -0700950 writel(0, DSI_CLK_CTRL);
951 writel(0, DSI_CTRL);
Siddhartha Agrawale0033a12013-02-23 15:37:42 -0800952 }
953
Dhaval Patelddde45a2014-08-13 19:07:59 -0700954 writel(0x1115501, MIPI_DSI0_BASE + INT_CTRL);
Siddhartha Agrawal24d81b52013-07-01 11:13:32 -0700955 if (pinfo->mipi.broadcast)
Dhaval Patelddde45a2014-08-13 19:07:59 -0700956 writel(0x1115501, MIPI_DSI1_BASE + INT_CTRL);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700957
958 return NO_ERROR;
959}
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530960
961int mipi_cmd_trigger()
962{
963 writel(0x1, DSI_CMD_MODE_MDP_SW_TRIGGER);
964
965 return NO_ERROR;
966}