blob: 27391f207645739a372c393309e3e02f3ec94060 [file] [log] [blame]
Padmanabhan Komandurue3209872015-01-12 16:33:16 +05301/* Copyright (c) 2010-2015, 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>
Veera Sundaram Sankaran602d95a2014-12-09 17:55:04 -080038#include <mdp5.h>
Kinson Chikfe931032011-07-21 10:01:34 -070039#include <platform/iomap.h>
40#include <platform/clock.h>
Greg Grisco1073a5e2011-07-28 18:59:18 -070041#include <platform/timer.h>
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070042#include <err.h>
43#include <msm_panel.h>
Kinson Chikfe931032011-07-21 10:01:34 -070044
45extern void mdp_disable(void);
Ajay Dudanib01e5062011-12-03 23:23:42 -080046extern int mipi_dsi_cmd_config(struct fbcon_config mipi_fb_cfg,
47 unsigned short num_of_lanes);
Kinson Chikfe931032011-07-21 10:01:34 -070048extern void mdp_shutdown(void);
49extern void mdp_start_dma(void);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070050
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -070051#if (DISPLAY_TYPE_MDSS == 0)
52#define MIPI_DSI0_BASE MIPI_DSI_BASE
53#define MIPI_DSI1_BASE MIPI_DSI_BASE
54#endif
55
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -080056struct fbcon_config mipi_fb_cfg = {
Ajay Dudanib01e5062011-12-03 23:23:42 -080057 .height = 0,
58 .width = 0,
59 .stride = 0,
60 .format = 0,
61 .bpp = 0,
62 .update_start = NULL,
63 .update_done = NULL,
Chandan Uddarajufe93e822010-11-21 20:44:47 -080064};
Chandan Uddarajufe93e822010-11-21 20:44:47 -080065
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -080066static char read_id_a1h_cmd[4] = { 0xA1, 0x00, 0x06, 0xA0 }; /* DTYPE_DCS_READ */
67static struct mipi_dsi_cmd read_ddb_start_cmd =
68 {sizeof(read_id_a1h_cmd), read_id_a1h_cmd, 0x00};
69
Greg Griscod6250552011-06-29 14:40:23 -070070void secure_writel(uint32_t, uint32_t);
71uint32_t secure_readl(uint32_t);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070072
Shivaraj Shetty64604032013-11-14 16:44:10 +053073static uint32_t response_value = 0;
74
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080075static uint32_t mdss_dsi_read_panel_signature(struct mipi_panel_info *mipi)
Shivaraj Shetty64604032013-11-14 16:44:10 +053076{
77 uint32_t rec_buf[1];
78 uint32_t *lp = rec_buf, data;
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -080079 uint32_t ret = response_value;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080080 uint32_t panel_signature = mipi->signature;
Shivaraj Shetty64604032013-11-14 16:44:10 +053081
82#if (DISPLAY_TYPE_MDSS == 1)
83 if (ret && ret != panel_signature)
84 goto exit_read_signature;
85
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080086 ret = mdss_dsi_cmds_tx(mipi, &read_ddb_start_cmd, 1, 0);
Shivaraj Shetty64604032013-11-14 16:44:10 +053087 if (ret)
88 goto exit_read_signature;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080089 if (!mdss_dsi_cmds_rx(mipi, &lp, 1, 1))
Shivaraj Shetty64604032013-11-14 16:44:10 +053090 goto exit_read_signature;
91
92 data = ntohl(*lp);
93 data = data >> 8;
94 response_value = data;
95 if (response_value != panel_signature)
96 ret = response_value;
97
98exit_read_signature:
99 /* Keep the non detectable panel at the end and set panel signature 0xFFFF */
Vineet Bajajc0d150d2014-11-07 17:04:44 +0530100 if ((panel_signature == 0) || (panel_signature == 0xFFFF))
Shivaraj Shetty64604032013-11-14 16:44:10 +0530101 ret = 0;
102#endif
103 return ret;
104}
105
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800106static int mdss_dsi_cmd_dma_trigger_for_panel(char dual_dsi,
107 uint32_t ctl_base, uint32_t sctl_base)
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700108{
109 uint32_t ReadValue;
110 uint32_t count = 0;
111 int status = 0;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800112 uint32_t base = dual_dsi ? sctl_base : ctl_base;
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700113
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400114#if (DISPLAY_TYPE_MDSS == 1)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800115 writel(0x03030303, ctl_base + INT_CTRL);
116 writel(0x1, ctl_base + CMD_MODE_DMA_SW_TRIGGER);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700117 dsb();
118
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800119 if (dual_dsi) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800120 writel(0x03030303, sctl_base + INT_CTRL);
121 writel(0x1, sctl_base + CMD_MODE_DMA_SW_TRIGGER);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800122 dsb();
123 }
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700124
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800125 ReadValue = readl(base + INT_CTRL) & 0x00000001;
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700126 while (ReadValue != 0x00000001) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800127 ReadValue = readl(base + INT_CTRL) & 0x00000001;
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700128 count++;
129 if (count > 0xffff) {
130 status = FAIL;
131 dprintf(CRITICAL,
132 "Panel CMD: command mode dma test failed\n");
133 return status;
134 }
135 }
136
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800137 writel((readl(base + INT_CTRL) | 0x01000001), base + INT_CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700138 dprintf(SPEW, "Panel CMD: command mode dma tested successfully\n");
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400139#endif
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700140 return status;
141}
142
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800143static int mdss_dsi_wait4_video_done(uint32_t ctl_base)
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700144{
145 unsigned long read;
146 unsigned long count = 0;
147 int status = 0;
148
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530149 /* If video mode is not enabled, return here */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800150 if ((readl(ctl_base + CTRL) & BIT(1)) == 0)
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530151 return 0;
152
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800153 read = readl(ctl_base + INT_CTRL);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700154 /* Enable VIDEO MODE DONE MASK and clear the interrupt */
155 read = read | DSI_VIDEO_MODE_DONE_MASK | DSI_VIDEO_MODE_DONE_AK;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800156 writel(read, ctl_base + INT_CTRL);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700157 dsb();
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800158 do {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800159 read = readl(ctl_base + INT_CTRL) &
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800160 DSI_VIDEO_MODE_DONE_STAT;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700161 count++;
162 if (count > 0xffff) {
163 status = FAIL;
164 dprintf(CRITICAL,
165 "Panel CMD: Did not recieve video mode done interrupt\n");
166 return status;
167 }
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800168 } while (!read);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700169
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800170 writel((readl(ctl_base + INT_CTRL) | 0x01000001), ctl_base + INT_CTRL);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700171 dprintf(SPEW, "Panel wait_4_video_done: Recieved video mode done ack\n");
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530172
173 /* Skip BLLP 4ms */
174 mdelay(4);
175
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700176 return status;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700177}
178
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800179int mdss_dsi_cmds_tx(struct mipi_panel_info *mipi,
180 struct mipi_dsi_cmd *cmds, int count, char dual_dsi)
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700181{
182 int ret = 0;
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800183#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700184 struct mipi_dsi_cmd *cm;
185 int i = 0;
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800186 uint8_t pload[256];
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700187 uint32_t off;
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800188 uint32_t size;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800189 uint32_t ctl_base, sctl_base;
190
191 /* if dest controller is not specified, default to DSI0 */
192 if (!mipi) {
193 ctl_base = MIPI_DSI0_BASE;
194 sctl_base = MIPI_DSI1_BASE;
195 } else {
196 ctl_base = mipi->ctl_base;
197 sctl_base = mipi->sctl_base;
198 }
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700199
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800200 /* Align pload at 8 byte boundary */
201 off = (uint32_t) pload;
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700202 off &= 0x07;
203 if (off)
204 off = 8 - off;
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800205 off += (uint32_t) pload;
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700206
207 cm = cmds;
208 for (i = 0; i < count; i++) {
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530209 /* Wait for VIDEO_MODE_DONE */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800210 ret = mdss_dsi_wait4_video_done(ctl_base);
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530211 if (ret)
212 goto wait4video_error;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700213
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800214 /* The payload size has to be a multiple of 4 */
215 size = cm->size;
216 size &= 0x03;
217 if (size)
218 size = 4 - size;
219 size += cm->size;
220 memcpy((uint8_t *)off, (cm->payload), size);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800221 writel(off, ctl_base + DMA_CMD_OFFSET);
222 writel(size, ctl_base + DMA_CMD_LENGTH);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800223 if (dual_dsi) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800224 writel(off, sctl_base + DMA_CMD_OFFSET);
225 writel(size, sctl_base + DMA_CMD_LENGTH);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800226 }
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700227 dsb();
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800228 ret += mdss_dsi_cmd_dma_trigger_for_panel(dual_dsi, ctl_base,
229 sctl_base);
Dhaval Patel607a6242013-10-29 12:37:24 -0700230 if (cm->wait)
231 mdelay(cm->wait);
232 else
233 udelay(80);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700234 cm++;
235 }
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700236wait4video_error:
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530237#endif
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700238 return ret;
239}
240
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800241int mdss_dsi_cmds_rx(struct mipi_panel_info *mipi, uint32_t **rp, int rp_len,
242 int rdbk_len)
Casey Piper84036752013-09-05 14:56:37 -0700243{
244 uint32_t *lp, data;
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -0800245 uint32_t *dp;
Casey Piper84036752013-09-05 14:56:37 -0700246 int i, off;
247 int rlen, res;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800248 uint32_t ctl_base;
249
250 /* if dest controller is not specified, default to DSI0 */
251 if (!mipi)
252 ctl_base = MIPI_DSI0_BASE;
253 else
254 ctl_base = mipi->ctl_base;
Casey Piper84036752013-09-05 14:56:37 -0700255
256 if (rdbk_len > rp_len) {
257 return 0;
258 }
259
260 if (rdbk_len <= 2)
261 rlen = 4; /* short read */
262 else
263 rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */
264
265 if (rlen > MIPI_DSI_REG_LEN) {
266 return 0;
267 }
268
269 res = rlen & 0x03;
270
271 rlen += res; /* 4 byte align */
272 lp = *rp;
273
274 rlen += 3;
275 rlen >>= 2;
276
277 if (rlen > 4)
278 rlen = 4; /* 4 x 32 bits registers only */
279
Shivaraj Shetty3c77da62013-12-09 15:58:16 +0530280 off = RDBK_DATA0;
Casey Piper84036752013-09-05 14:56:37 -0700281 off += ((rlen - 1) * 4);
282
283 for (i = 0; i < rlen; i++) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800284 data = readl(ctl_base + off);
Casey Piper84036752013-09-05 14:56:37 -0700285 *lp = ntohl(data); /* to network byte order */
286 lp++;
287
288 off -= 4;
289 }
290
291 if (rdbk_len > 2) {
292 /*First 4 bytes + paded bytes will be header next len bytes would be payload */
293 for (i = 0; i < rdbk_len; i++) {
294 dp = *rp;
295 dp[i] = dp[(res + i) >> 2];
296 }
297 }
298 return rdbk_len;
299}
300
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800301static int mdss_dsi_cmd_bta_sw_trigger(uint32_t ctl_base)
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800302{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800303 uint32_t data;
304 int cnt = 0;
305 int err = 0;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800306
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800307 writel(0x01, ctl_base + 0x094); /* trigger */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800308 while (cnt < 10000) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800309 data = readl(ctl_base + 0x0004); /*DSI_STATUS */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800310 if ((data & 0x0010) == 0)
311 break;
312 cnt++;
313 }
314 if (cnt == 10000)
315 err = 1;
316 return err;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800317}
318
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800319int mdss_dsi_host_init(struct mipi_panel_info *mipi, uint32_t
Dhaval Patel9207dec2014-04-16 10:45:32 -0700320 dual_dsi, uint32_t broadcast)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700321{
322 uint8_t DMA_STREAM1 = 0; // for mdp display processor path
323 uint8_t EMBED_MODE1 = 1; // from frame buffer
324 uint8_t POWER_MODE2 = 1; // from frame buffer
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800325 uint8_t PACK_TYPE1 = 0; // long packet
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700326 uint8_t VC1 = 0;
327 uint8_t DT1 = 0; // non embedded mode
328 uint8_t WC1 = 0; // for non embedded mode only
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700329 uint8_t DLNx_EN;
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700330 uint8_t lane_swap = 0;
Siddhartha Agrawalb6c861f2013-05-31 19:36:44 -0700331 uint32_t timing_ctl = 0;
Vineet Bajaj2f08a362014-07-24 20:50:42 +0530332 uint32_t lane_swap_dsi1 = 0;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700333 uint32_t ctrl_mode = 0x105; //Default is command mode to send cmds.
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700334
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400335#if (DISPLAY_TYPE_MDSS == 1)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800336 switch (mipi->num_of_lanes) {
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700337 default:
338 case 1:
339 DLNx_EN = 1; // 1 lane
340 break;
341 case 2:
342 DLNx_EN = 3; // 2 lane
343 break;
344 case 3:
345 DLNx_EN = 7; // 3 lane
346 break;
347 case 4:
348 DLNx_EN = 0x0F; /* 4 lanes */
349 break;
350 }
351
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800352 lane_swap = mipi->lane_swap;
353 timing_ctl = ((mipi->t_clk_post << 8) | mipi->t_clk_pre);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700354
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800355 if (mipi->cmds_post_tg) {
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700356 /*
357 * Need to send pixel data before sending the ON commands
358 * so need to configure controller to VIDEO MODE.
359 */
360 ctrl_mode = 0x103;
361 }
362
Dhaval Patel9207dec2014-04-16 10:45:32 -0700363 if (dual_dsi) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800364 writel(0x0001, mipi->sctl_base + SOFT_RESET);
365 writel(0x0000, mipi->sctl_base + SOFT_RESET);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700366
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800367 /* Turn on all DSI Clks */
368 writel((0 << 16) | 0x3f, mipi->sctl_base + CLK_CTRL);
369 writel(DMA_STREAM1 << 8 | 0x04, mipi->sctl_base + TRIG_CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700370
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800371 writel(0 << 30 | DLNx_EN << 4 | ctrl_mode, mipi->sctl_base + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700372 writel(broadcast << 31 | EMBED_MODE1 << 28 | POWER_MODE2 << 26
373 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800374 mipi->sctl_base + COMMAND_MODE_DMA_CTRL);
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700375
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800376 /* for 8939 hw dsi1 has Lane_map as 3210 */
377 if (readl(MIPI_DSI_BASE) == DSI_HW_REV_103_1)
Vineet Bajaj2f08a362014-07-24 20:50:42 +0530378 lane_swap_dsi1 = 0x7;
379 else
380 lane_swap_dsi1 = lane_swap;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800381 writel(lane_swap_dsi1, mipi->sctl_base + LANE_SWAP_CTL);
382 writel(timing_ctl, mipi->sctl_base + TIMING_CTL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700383 }
384
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800385 writel(0x0001, mipi->ctl_base + SOFT_RESET);
386 writel(0x0000, mipi->ctl_base + SOFT_RESET);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700387
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800388 /* Turn on all DSI Clks */
389 writel((0 << 16) | 0x3f, mipi->ctl_base + CLK_CTRL);
390 writel(DMA_STREAM1 << 8 | 0x04, mipi->ctl_base + TRIG_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700391
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800392 writel(0 << 30 | DLNx_EN << 4 | ctrl_mode, mipi->ctl_base + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700393 writel(broadcast << 31 | EMBED_MODE1 << 28 | POWER_MODE2 << 26
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700394 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800395 mipi->ctl_base + COMMAND_MODE_DMA_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700396
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800397 writel(lane_swap, mipi->ctl_base + LANE_SWAP_CTL);
398 writel(timing_ctl, mipi->ctl_base + TIMING_CTL);
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800399#endif
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700400
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800401 return 0;
402}
403
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530404void mdss_dsi_panel_shutdown(struct msm_panel_info *pinfo)
405{
406#if (DISPLAY_TYPE_MDSS == 1)
407 unsigned long read_val = 0;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800408 uint32_t ctl_base = pinfo->mipi.ctl_base;
409 uint32_t sctl_base = pinfo->mipi.sctl_base;
410
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530411 if (pinfo->mipi.panel_off_cmds) {
412 /*
413 * Once MDP TG is disabled, reset of DSI controller is
414 * needed before we send panel OFF commands.
415 */
416 if (pinfo->type == MIPI_VIDEO_PANEL) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800417 read_val = readl(ctl_base + CTRL);
418 writel((read_val & ~BIT(0)), ctl_base + CTRL);
419 writel(0x0001, ctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530420 dsb();
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800421 writel(0x0000, ctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530422 dsb();
423 /* Enable cmd mode only */
424 writel(((read_val & ~BIT(1)) | BIT(2)),
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800425 ctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530426 }
427
428 if (pinfo->mipi.broadcast) {
429 if (pinfo->type == MIPI_VIDEO_PANEL) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800430 read_val = readl(sctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530431 writel((read_val & ~BIT(0)),
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800432 sctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530433
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800434 writel(0x0001, sctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530435 dsb();
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800436 writel(0x0000, sctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530437 dsb();
438
439 writel(((read_val & ~BIT(1)) | BIT(2)),
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800440 sctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530441 }
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530442 }
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800443 mdss_dsi_cmds_tx(&pinfo->mipi, pinfo->mipi.panel_off_cmds,
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800444 pinfo->mipi.num_of_panel_off_cmds,
445 pinfo->mipi.broadcast);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530446 }
447#endif
448}
449
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800450int mdss_dsi_panel_initialize(struct mipi_panel_info *mipi, uint32_t
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800451 broadcast)
452{
453 int status = 0;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700454 uint32_t ctrl_mode = 0;
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800455
456#if (DISPLAY_TYPE_MDSS == 1)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800457 if (!mipi->panel_on_cmds)
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800458 goto end;
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700459
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800460 ctrl_mode = readl(mipi->ctl_base + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700461
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800462 /* Enable command mode before sending the commands. */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800463 writel(ctrl_mode | 0x04, mipi->ctl_base + CTRL);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800464 if (broadcast)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800465 writel(ctrl_mode | 0x04, mipi->sctl_base + CTRL);
466 status = mdss_dsi_cmds_tx(mipi, mipi->panel_on_cmds,
467 mipi->num_of_panel_on_cmds, broadcast);
468 writel(ctrl_mode, mipi->ctl_base + CTRL);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800469 if (broadcast)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800470 writel(ctrl_mode, mipi->sctl_base + CTRL);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800471
472 if (!broadcast && !status && target_panel_auto_detect_enabled())
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800473 status = mdss_dsi_read_panel_signature(mipi);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800474
475end:
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400476#endif
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700477 return status;
478}
479
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700480int mdss_dsi_video_mode_config(uint16_t disp_width,
481 uint16_t disp_height,
482 uint16_t img_width,
483 uint16_t img_height,
484 uint16_t hsync_porch0_fp,
485 uint16_t hsync_porch0_bp,
486 uint16_t vsync_porch0_fp,
487 uint16_t vsync_porch0_bp,
488 uint16_t hsync_width,
489 uint16_t vsync_width,
490 uint16_t dst_format,
491 uint16_t traffic_mode,
492 uint8_t lane_en,
Padmanabhan Komandurue3209872015-01-12 16:33:16 +0530493 uint8_t pulse_mode_hsa_he,
494 uint32_t low_pwr_stop_mode,
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700495 uint8_t eof_bllp_pwr,
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700496 uint8_t interleav,
497 uint32_t ctl_base)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700498{
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700499 int status = 0;
500
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400501#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700502 /* disable mdp first */
503 mdp_disable();
504
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700505 writel(0x00000000, ctl_base + CLK_CTRL);
506 writel(0x00000002, ctl_base + CLK_CTRL);
507 writel(0x00000006, ctl_base + CLK_CTRL);
508 writel(0x0000000e, ctl_base + CLK_CTRL);
509 writel(0x0000001e, ctl_base + CLK_CTRL);
510 writel(0x0000023f, ctl_base + CLK_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700511
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700512 writel(0, ctl_base + CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700513
Padmanabhan Komanduru2f8e0bc2014-11-27 18:25:36 +0530514 writel(0x03f03fe0, ctl_base + ERR_INT_MASK0);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700515
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700516 writel(0x02020202, ctl_base + INT_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700517
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530518 /* For 8916/8939, enable DSI timing double buffering */
Kuogee Hsieh861e25d2014-10-29 16:50:15 -0700519 if (readl(ctl_base) >= DSI_HW_REV_103 &&
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530520 mdp_get_revision() != MDP_REV_305)
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530521 writel(0x1, ctl_base + TIMING_DB_MODE);
522
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700523 writel(((disp_width + hsync_porch0_bp) << 16) | hsync_porch0_bp,
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700524 ctl_base + VIDEO_MODE_ACTIVE_H);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700525
526 writel(((disp_height + vsync_porch0_bp) << 16) | (vsync_porch0_bp),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700527 ctl_base + VIDEO_MODE_ACTIVE_V);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700528
Terence Hampson7385f6a2013-08-16 15:31:25 -0400529 if (mdp_get_revision() >= MDP_REV_41 ||
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530530 mdp_get_revision() == MDP_REV_304 ||
531 mdp_get_revision() == MDP_REV_305) {
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700532 writel(((disp_height + vsync_porch0_fp
533 + vsync_porch0_bp - 1) << 16)
534 | (disp_width + hsync_porch0_fp
535 + hsync_porch0_bp - 1),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700536 ctl_base + VIDEO_MODE_TOTAL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700537 } else {
538 writel(((disp_height + vsync_porch0_fp
539 + vsync_porch0_bp) << 16)
540 | (disp_width + hsync_porch0_fp
541 + hsync_porch0_bp),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700542 ctl_base + VIDEO_MODE_TOTAL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700543 }
544
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700545 writel((hsync_width << 16) | 0, ctl_base + VIDEO_MODE_HSYNC);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700546
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700547 writel(0 << 16 | 0, ctl_base + VIDEO_MODE_VSYNC);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700548
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700549 writel(vsync_width << 16 | 0, ctl_base + VIDEO_MODE_VSYNC_VPOS);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700550
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530551 /* For 8916/8939, flush the DSI timing registers */
Kuogee Hsieh861e25d2014-10-29 16:50:15 -0700552 if (readl(ctl_base) >= DSI_HW_REV_103 &&
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530553 mdp_get_revision() != MDP_REV_305)
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530554 writel(0x1, ctl_base + TIMING_FLUSH);
555
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700556 writel(0x0, ctl_base + EOT_PACKET_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700557
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700558 writel(0x00000100, ctl_base + MISR_VIDEO_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700559
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530560 if (mdp_get_revision() >= MDP_REV_41 || mdp_get_revision() == MDP_REV_305) {
Padmanabhan Komandurue3209872015-01-12 16:33:16 +0530561 writel(pulse_mode_hsa_he << 28 | low_pwr_stop_mode << 16 |
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700562 eof_bllp_pwr << 12 | traffic_mode << 8
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700563 | dst_format << 4 | 0x0, ctl_base + VIDEO_MODE_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700564 } else {
565 writel(1 << 28 | 1 << 24 | 1 << 20 | low_pwr_stop_mode << 16 |
566 eof_bllp_pwr << 12 | traffic_mode << 8
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700567 | dst_format << 4 | 0x0, ctl_base + VIDEO_MODE_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700568 }
569
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700570 writel(0x3fd08, ctl_base + HS_TIMER_CTRL);
571 writel(0x00010100, ctl_base + MISR_VIDEO_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700572
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700573 writel(0x00010100, ctl_base + INT_CTRL);
574 writel(0x02010202, ctl_base + INT_CTRL);
575 writel(0x02030303, ctl_base + INT_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700576
577 writel(interleav << 30 | 0 << 24 | 0 << 20 | lane_en << 4
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700578 | 0x103, ctl_base + CTRL);
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400579#endif
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700580
581 return status;
582}
583
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800584int mdss_dsi_config(struct msm_fb_panel_data *panel)
585{
586 int ret = NO_ERROR;
587 struct msm_panel_info *pinfo;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800588 struct mipi_panel_info *mipi;
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800589
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400590#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800591 if (!panel)
592 return ERR_INVALID_ARGS;
593
594 pinfo = &(panel->panel_info);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800595 mipi = &(pinfo->mipi);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800596
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800597 dprintf(SPEW, "ctl_base=0x%08x, phy_base=0x%08x\n", mipi->ctl_base,
598 mipi->phy_base);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800599
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800600 mdss_dsi_phy_init(mipi, mipi->ctl_base, mipi->phy_base);
601 if (mipi->dual_dsi)
602 mdss_dsi_phy_init(mipi, mipi->sctl_base, mipi->sphy_base);
603
604 ret = mdss_dsi_host_init(mipi, mipi->dual_dsi,
605 mipi->broadcast);
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800606 if (ret) {
607 dprintf(CRITICAL, "dsi host init error\n");
608 goto error;
609 }
610
Aravind Venkateswaran51e57552014-12-09 13:23:19 -0800611 mdss_dsi_phy_contention_detection(mipi, mipi->phy_base);
612 if (mipi->dual_dsi)
613 mdss_dsi_phy_contention_detection(mipi, mipi->sphy_base);
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400614
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800615 if (panel->pre_init_func) {
616 ret = panel->pre_init_func();
617 if (ret) {
618 dprintf(CRITICAL, "pre_init_func error\n");
619 goto error;
620 }
621 }
622
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800623 if (!mipi->cmds_post_tg) {
624 ret = mdss_dsi_panel_initialize(mipi, mipi->broadcast);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700625 if (ret) {
626 dprintf(CRITICAL, "dsi panel init error\n");
627 goto error;
628 }
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800629 }
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800630
631 if (pinfo->rotate && panel->rotate)
632 pinfo->rotate();
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400633#endif
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800634
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800635error:
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800636 return ret;
637}
638
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700639int mdss_dsi_post_on(struct msm_fb_panel_data *panel)
640{
641 int ret = 0;
642 struct msm_panel_info *pinfo = &(panel->panel_info);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700643
644 if (pinfo->mipi.cmds_post_tg) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800645 ret = mdss_dsi_panel_initialize(&pinfo->mipi, pinfo->mipi.broadcast);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700646 if (ret) {
647 dprintf(CRITICAL, "dsi panel init error\n");
648 }
649 }
650 return ret;
651}
652
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700653int mdss_dsi_cmd_mode_config(uint16_t disp_width,
654 uint16_t disp_height,
655 uint16_t img_width,
656 uint16_t img_height,
657 uint16_t dst_format,
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400658 uint8_t ystride,
659 uint8_t lane_en,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800660 uint8_t interleav,
661 uint32_t ctl_base)
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700662{
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400663 uint16_t dst_fmt = 0;
664
665 switch (dst_format) {
666 case DSI_VIDEO_DST_FORMAT_RGB565:
667 dst_fmt = DSI_CMD_DST_FORMAT_RGB565;
668 break;
669 case DSI_VIDEO_DST_FORMAT_RGB666:
670 case DSI_VIDEO_DST_FORMAT_RGB666_LOOSE:
671 dst_fmt = DSI_CMD_DST_FORMAT_RGB666;
672 break;
673 case DSI_VIDEO_DST_FORMAT_RGB888:
674 dst_fmt = DSI_CMD_DST_FORMAT_RGB888;
675 break;
676 default:
677 dprintf(CRITICAL, "unsupported dst format\n");
678 return ERROR;
679 }
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700680
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400681#if (DISPLAY_TYPE_MDSS == 1)
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800682 writel(0x00000000, ctl_base + CLK_CTRL);
683 writel(0x00000000, ctl_base + CLK_CTRL);
684 writel(0x00000000, ctl_base + CLK_CTRL);
685 writel(0x00000000, ctl_base + CLK_CTRL);
686 writel(0x00000002, ctl_base + CLK_CTRL);
687 writel(0x00000006, ctl_base + CLK_CTRL);
688 writel(0x0000000e, ctl_base + CLK_CTRL);
689 writel(0x0000001e, ctl_base + CLK_CTRL);
690 writel(0x0000023f, ctl_base + CLK_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700691
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800692 writel(0, ctl_base + CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700693
Padmanabhan Komanduru2f8e0bc2014-11-27 18:25:36 +0530694 writel(0x03f03fe0, ctl_base + ERR_INT_MASK0);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700695
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800696 writel(0x02020202, ctl_base + INT_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700697
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800698 writel(dst_fmt, ctl_base + COMMAND_MODE_MDP_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700699 writel((img_width * ystride + 1) << 16 | 0x0039,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800700 ctl_base + COMMAND_MODE_MDP_STREAM0_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700701 writel((img_width * ystride + 1) << 16 | 0x0039,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800702 ctl_base + COMMAND_MODE_MDP_STREAM1_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700703 writel(img_height << 16 | img_width,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800704 ctl_base + COMMAND_MODE_MDP_STREAM0_TOTAL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700705 writel(img_height << 16 | img_width,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800706 ctl_base + COMMAND_MODE_MDP_STREAM1_TOTAL);
707 writel(0x13c2c, ctl_base + COMMAND_MODE_MDP_DCS_CMD_CTRL);
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400708 writel(interleav << 30 | 0 << 24 | 0 << 20 | lane_en << 4 | 0x105,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800709 ctl_base + CTRL);
Padmanabhan Komanduru7860be52014-03-18 19:07:36 +0530710 writel(0x14000000, ctl_base + COMMAND_MODE_DMA_CTRL);
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800711 writel(0x10000000, ctl_base + MISR_CMD_CTRL);
Xiaoming Zhoua0469332014-03-04 18:34:24 -0500712 writel(0x1, ctl_base + EOT_PACKET_CTRL);
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400713#endif
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400714 return 0;
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700715}
716
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800717int mipi_dsi_on(struct msm_panel_info *pinfo)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700718{
719 int ret = NO_ERROR;
720 unsigned long ReadValue;
721 unsigned long count = 0;
722
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800723 ReadValue = readl(pinfo->mipi.ctl_base + INT_CTRL) & 0x00010000;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700724
725 mdelay(10);
726
727 while (ReadValue != 0x00010000) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800728 ReadValue = readl(pinfo->mipi.ctl_base + INT_CTRL) & 0x00010000;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700729 count++;
730 if (count > 0xffff) {
731 dprintf(CRITICAL, "Video lane test failed\n");
732 return ERROR;
733 }
734 }
735
Amir Samuelov2d4ba162012-07-22 11:53:14 +0300736 dprintf(INFO, "Video lane tested successfully\n");
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700737 return ret;
738}
739
Siddhartha Agrawal24d81b52013-07-01 11:13:32 -0700740int mipi_dsi_off(struct msm_panel_info *pinfo)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700741{
Amol Jadi6834f1a2012-06-29 14:42:59 -0700742 if(!target_cont_splash_screen())
743 {
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530744 mdss_dsi_panel_shutdown(pinfo);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800745 writel(0, pinfo->mipi.ctl_base + CLK_CTRL);
746 writel(0x1F1, pinfo->mipi.ctl_base + CTRL);
Siddhartha Agrawale0033a12013-02-23 15:37:42 -0800747 }
748
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800749 writel(0x1115501, pinfo->mipi.ctl_base + INT_CTRL);
Siddhartha Agrawal24d81b52013-07-01 11:13:32 -0700750 if (pinfo->mipi.broadcast)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800751 writel(0x1115501, pinfo->mipi.sctl_base + INT_CTRL);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700752
753 return NO_ERROR;
754}
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530755
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800756#if (DISPLAY_TYPE_MDSS == 0)
757static int dsi_cmd_dma_trigger_for_panel()
758{
759 unsigned long ReadValue;
760 unsigned long count = 0;
761 int status = 0;
762
763 writel(0x03030303, DSI_INT_CTRL);
764 writel(0x1, DSI_CMD_MODE_DMA_SW_TRIGGER);
765 dsb();
766 ReadValue = readl(DSI_INT_CTRL) & 0x00000001;
767 while (ReadValue != 0x00000001) {
768 ReadValue = readl(DSI_INT_CTRL) & 0x00000001;
769 count++;
770 if (count > 0xffff) {
771 status = FAIL;
772 dprintf(CRITICAL,
773 "Panel CMD: command mode dma test failed\n");
774 return status;
775 }
776 }
777
778 writel((readl(DSI_INT_CTRL) | 0x01000001), DSI_INT_CTRL);
779 dprintf(SPEW, "Panel CMD: command mode dma tested successfully\n");
780 return status;
781}
782
783int mipi_dsi_cmds_tx(struct mipi_dsi_cmd *cmds, int count)
784{
785 int ret = 0;
786 struct mipi_dsi_cmd *cm;
787 int i = 0;
788 char pload[256];
789 uint32_t off;
790
791 /* Align pload at 8 byte boundry */
792 off = pload;
793 off &= 0x07;
794 if (off)
795 off = 8 - off;
796 off += pload;
797
798 cm = cmds;
799 for (i = 0; i < count; i++) {
800 /* Wait for VIDEO_MODE_DONE */
801 ret = mdss_dsi_wait4_video_done();
802 if (ret)
803 goto mipi_cmds_error;
804
805 memcpy((void *)off, (cm->payload), cm->size);
806 writel(off, DSI_DMA_CMD_OFFSET);
807 writel(cm->size, DSI_DMA_CMD_LENGTH); // reg 0x48 for this build
808 dsb();
809 ret += dsi_cmd_dma_trigger_for_panel();
810 dsb();
811 if (cm->wait)
812 mdelay(cm->wait);
813 else
814 udelay(80);
815 cm++;
816 }
817mipi_cmds_error:
818 return ret;
819}
820
821/*
822 * mipi_dsi_cmd_rx: can receive at most 16 bytes
823 * per transaction since it only have 4 32bits reigsters
824 * to hold data.
825 * therefore Maximum Return Packet Size need to be set to 16.
826 * any return data more than MRPS need to be break down
827 * to multiple transactions.
828 */
829int mipi_dsi_cmds_rx(char **rp, int len)
830{
831 uint32_t *lp, data;
832 char *dp;
833 int i, off, cnt;
834 int rlen, res;
835
836 if (len <= 2)
837 rlen = 4; /* short read */
838 else
839 rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */
840
841 if (rlen > MIPI_DSI_REG_LEN) {
842 return 0;
843 }
844
845 res = rlen & 0x03;
846
847 rlen += res; /* 4 byte align */
848 lp = (uint32_t *) (*rp);
849
850 cnt = rlen;
851 cnt += 3;
852 cnt >>= 2;
853
854 if (cnt > 4)
855 cnt = 4; /* 4 x 32 bits registers only */
856
857 off = 0x068; /* DSI_RDBK_DATA0 */
858 off += ((cnt - 1) * 4);
859
860 for (i = 0; i < cnt; i++) {
861 data = (uint32_t) readl(MIPI_DSI_BASE + off);
862 *lp++ = ntohl(data); /* to network byte order */
863 off -= 4;
864 }
865
866 if (len > 2) {
867 /*First 4 bytes + paded bytes will be header next len bytes would be payload */
868 for (i = 0; i < len; i++) {
869 dp = *rp;
870 dp[i] = dp[4 + res + i];
871 }
872 }
873
874 return len;
875}
876
877static int mipi_dsi_panel_initialize(struct mipi_dsi_panel_config *pinfo)
878{
879 uint8_t DMA_STREAM1 = 0; // for mdp display processor path
880 uint8_t EMBED_MODE1 = 1; // from frame buffer
881 uint8_t POWER_MODE2 = 1; // from frame buffer
882 uint8_t PACK_TYPE1; // long packet
883 uint8_t VC1 = 0;
884 uint8_t DT1 = 0; // non embedded mode
885 uint8_t WC1 = 0; // for non embedded mode only
886 int status = 0;
887 uint8_t DLNx_EN;
888
889 switch (pinfo->num_of_lanes) {
890 default:
891 case 1:
892 DLNx_EN = 1; // 1 lane
893 break;
894 case 2:
895 DLNx_EN = 3; // 2 lane
896 break;
897 case 3:
898 DLNx_EN = 7; // 3 lane
899 break;
900 case 4:
901 DLNx_EN = 0x0F; /* 4 lanes */
902 break;
903 }
904
905 PACK_TYPE1 = pinfo->pack;
906
907 writel(0x0001, DSI_SOFT_RESET);
908 writel(0x0000, DSI_SOFT_RESET);
909
910 writel((0 << 16) | 0x3f, DSI_CLK_CTRL); /* Turn on all DSI Clks */
911 writel(DMA_STREAM1 << 8 | 0x04, DSI_TRIG_CTRL); // reg 0x80 dma trigger: sw
912 // trigger 0x4; dma stream1
913
914 writel(0 << 30 | DLNx_EN << 4 | 0x105, DSI_CTRL); // reg 0x00 for this
915 // build
916 writel(EMBED_MODE1 << 28 | POWER_MODE2 << 26
917 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
918 DSI_COMMAND_MODE_DMA_CTRL);
919
920 if (pinfo->panel_on_cmds)
921 status = mipi_dsi_cmds_tx(pinfo->panel_on_cmds,
922 pinfo->num_of_panel_on_cmds);
923
924 return status;
925}
926#endif
927
928void mipi_dsi_shutdown(void)
929{
930#if (DISPLAY_TYPE_MDSS == 0)
931 if(!target_cont_splash_screen())
932 {
933 mdp_shutdown();
934 writel(0x01010101, DSI_INT_CTRL);
935 writel(0x13FF3BFF, DSI_ERR_INT_MASK0);
936
937 writel(0, DSI_CLK_CTRL);
938 writel(0, DSI_CTRL);
939 writel(0, DSIPHY_PLL_CTRL(0));
940 }
941 else
942 {
943 /* To keep the splash screen displayed till kernel driver takes
944 control, do not turn off the video mode engine and clocks.
945 Only disabling the MIPI DSI IRQs */
946 writel(0x01010101, DSI_INT_CTRL);
947 writel(0x13FF3BFF, DSI_ERR_INT_MASK0);
948 }
949#endif
950}
951
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530952int mipi_cmd_trigger()
953{
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800954#if (DISPLAY_TYPE_MDSS == 0)
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530955 writel(0x1, DSI_CMD_MODE_MDP_SW_TRIGGER);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800956#endif
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530957 return NO_ERROR;
958}
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800959
960int mipi_config(struct msm_fb_panel_data *panel)
961{
962 int ret = NO_ERROR;
963#if (DISPLAY_TYPE_MDSS == 0)
964 struct msm_panel_info *pinfo;
965 struct mipi_dsi_panel_config mipi_pinfo;
966
967 if (!panel)
968 return ERR_INVALID_ARGS;
969
970 pinfo = &(panel->panel_info);
971 mipi_pinfo.mode = pinfo->mipi.mode;
972 mipi_pinfo.num_of_lanes = pinfo->mipi.num_of_lanes;
973 mipi_pinfo.dsi_phy_config = pinfo->mipi.dsi_phy_db;
974 mipi_pinfo.panel_on_cmds = pinfo->mipi.panel_on_cmds;
975 mipi_pinfo.num_of_panel_on_cmds = pinfo->mipi.num_of_panel_on_cmds;
976 mipi_pinfo.lane_swap = pinfo->mipi.lane_swap;
977 mipi_pinfo.pack = 1;
978
979 /* Enable MMSS_AHB_ARB_MATER_PORT_E for
980 arbiter master0 and master 1 request */
981#if (!DISPLAY_MIPI_PANEL_RENESAS && !DISPLAY_TYPE_DSI6G && !DISPLAY_TYPE_8610)
982 writel(0x00001800, MMSS_SFPB_GPREG);
983#endif
984
985 mipi_dsi_phy_init(&mipi_pinfo);
986
987 ret += mipi_dsi_panel_initialize(&mipi_pinfo);
988
989 if (pinfo->rotate && panel->rotate)
990 pinfo->rotate();
991#endif
992 return ret;
993}