blob: 66f95c6751fa6f64a65a3f8443036dc33da137e2 [file] [log] [blame]
Jeevan Shriram01379322015-01-07 17:41:26 -08001/* 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>
Matthew Qin81933ce2015-02-03 17:58:52 +080044#include <arch/ops.h>
Kinson Chikfe931032011-07-21 10:01:34 -070045
46extern void mdp_disable(void);
Ajay Dudanib01e5062011-12-03 23:23:42 -080047extern int mipi_dsi_cmd_config(struct fbcon_config mipi_fb_cfg,
48 unsigned short num_of_lanes);
Kinson Chikfe931032011-07-21 10:01:34 -070049extern void mdp_shutdown(void);
50extern void mdp_start_dma(void);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070051
Siddhartha Agrawal1b2ed842013-05-29 18:02:28 -070052#if (DISPLAY_TYPE_MDSS == 0)
53#define MIPI_DSI0_BASE MIPI_DSI_BASE
54#define MIPI_DSI1_BASE MIPI_DSI_BASE
55#endif
56
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -080057struct fbcon_config mipi_fb_cfg = {
Ajay Dudanib01e5062011-12-03 23:23:42 -080058 .height = 0,
59 .width = 0,
60 .stride = 0,
61 .format = 0,
62 .bpp = 0,
63 .update_start = NULL,
64 .update_done = NULL,
Chandan Uddarajufe93e822010-11-21 20:44:47 -080065};
Chandan Uddarajufe93e822010-11-21 20:44:47 -080066
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -080067static char read_id_a1h_cmd[4] = { 0xA1, 0x00, 0x06, 0xA0 }; /* DTYPE_DCS_READ */
68static struct mipi_dsi_cmd read_ddb_start_cmd =
69 {sizeof(read_id_a1h_cmd), read_id_a1h_cmd, 0x00};
70
Greg Griscod6250552011-06-29 14:40:23 -070071void secure_writel(uint32_t, uint32_t);
72uint32_t secure_readl(uint32_t);
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070073
Shivaraj Shetty64604032013-11-14 16:44:10 +053074static uint32_t response_value = 0;
75
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080076static uint32_t mdss_dsi_read_panel_signature(struct mipi_panel_info *mipi)
Shivaraj Shetty64604032013-11-14 16:44:10 +053077{
78 uint32_t rec_buf[1];
79 uint32_t *lp = rec_buf, data;
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -080080 uint32_t ret = response_value;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080081 uint32_t panel_signature = mipi->signature;
Shivaraj Shetty64604032013-11-14 16:44:10 +053082
83#if (DISPLAY_TYPE_MDSS == 1)
84 if (ret && ret != panel_signature)
85 goto exit_read_signature;
86
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080087 ret = mdss_dsi_cmds_tx(mipi, &read_ddb_start_cmd, 1, 0);
Shivaraj Shetty64604032013-11-14 16:44:10 +053088 if (ret)
89 goto exit_read_signature;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -080090 if (!mdss_dsi_cmds_rx(mipi, &lp, 1, 1))
Shivaraj Shetty64604032013-11-14 16:44:10 +053091 goto exit_read_signature;
92
93 data = ntohl(*lp);
94 data = data >> 8;
95 response_value = data;
96 if (response_value != panel_signature)
97 ret = response_value;
98
99exit_read_signature:
100 /* Keep the non detectable panel at the end and set panel signature 0xFFFF */
Vineet Bajajc0d150d2014-11-07 17:04:44 +0530101 if ((panel_signature == 0) || (panel_signature == 0xFFFF))
Shivaraj Shetty64604032013-11-14 16:44:10 +0530102 ret = 0;
103#endif
104 return ret;
105}
106
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800107static int mdss_dsi_cmd_dma_trigger_for_panel(char dual_dsi,
108 uint32_t ctl_base, uint32_t sctl_base)
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700109{
110 uint32_t ReadValue;
111 uint32_t count = 0;
112 int status = 0;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800113 uint32_t base = dual_dsi ? sctl_base : ctl_base;
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700114
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400115#if (DISPLAY_TYPE_MDSS == 1)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800116 writel(0x03030303, ctl_base + INT_CTRL);
117 writel(0x1, ctl_base + CMD_MODE_DMA_SW_TRIGGER);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700118 dsb();
119
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800120 if (dual_dsi) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800121 writel(0x03030303, sctl_base + INT_CTRL);
122 writel(0x1, sctl_base + CMD_MODE_DMA_SW_TRIGGER);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800123 dsb();
124 }
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700125
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800126 ReadValue = readl(base + INT_CTRL) & 0x00000001;
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700127 while (ReadValue != 0x00000001) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800128 ReadValue = readl(base + INT_CTRL) & 0x00000001;
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700129 count++;
130 if (count > 0xffff) {
131 status = FAIL;
132 dprintf(CRITICAL,
133 "Panel CMD: command mode dma test failed\n");
134 return status;
135 }
136 }
137
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800138 writel((readl(base + INT_CTRL) | 0x01000001), base + INT_CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700139 dprintf(SPEW, "Panel CMD: command mode dma tested successfully\n");
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400140#endif
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700141 return status;
142}
143
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800144static int mdss_dsi_wait4_video_done(uint32_t ctl_base)
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700145{
146 unsigned long read;
147 unsigned long count = 0;
148 int status = 0;
149
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530150 /* If video mode is not enabled, return here */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800151 if ((readl(ctl_base + CTRL) & BIT(1)) == 0)
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530152 return 0;
153
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800154 read = readl(ctl_base + INT_CTRL);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700155 /* Enable VIDEO MODE DONE MASK and clear the interrupt */
156 read = read | DSI_VIDEO_MODE_DONE_MASK | DSI_VIDEO_MODE_DONE_AK;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800157 writel(read, ctl_base + INT_CTRL);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700158 dsb();
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800159 do {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800160 read = readl(ctl_base + INT_CTRL) &
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800161 DSI_VIDEO_MODE_DONE_STAT;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700162 count++;
163 if (count > 0xffff) {
164 status = FAIL;
165 dprintf(CRITICAL,
166 "Panel CMD: Did not recieve video mode done interrupt\n");
167 return status;
168 }
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800169 } while (!read);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700170
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800171 writel((readl(ctl_base + INT_CTRL) | 0x01000001), ctl_base + INT_CTRL);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700172 dprintf(SPEW, "Panel wait_4_video_done: Recieved video mode done ack\n");
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530173
174 /* Skip BLLP 4ms */
175 mdelay(4);
176
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700177 return status;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700178}
179
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800180int mdss_dsi_cmds_tx(struct mipi_panel_info *mipi,
181 struct mipi_dsi_cmd *cmds, int count, char dual_dsi)
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700182{
183 int ret = 0;
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800184#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700185 struct mipi_dsi_cmd *cm;
186 int i = 0;
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800187 uint8_t pload[256];
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700188 uint32_t off;
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800189 uint32_t size;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800190 uint32_t ctl_base, sctl_base;
191
192 /* if dest controller is not specified, default to DSI0 */
193 if (!mipi) {
194 ctl_base = MIPI_DSI0_BASE;
195 sctl_base = MIPI_DSI1_BASE;
196 } else {
197 ctl_base = mipi->ctl_base;
198 sctl_base = mipi->sctl_base;
199 }
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700200
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800201 /* Align pload at 8 byte boundary */
202 off = (uint32_t) pload;
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700203 off &= 0x07;
204 if (off)
205 off = 8 - off;
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800206 off += (uint32_t) pload;
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700207
208 cm = cmds;
209 for (i = 0; i < count; i++) {
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530210 /* Wait for VIDEO_MODE_DONE */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800211 ret = mdss_dsi_wait4_video_done(ctl_base);
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530212 if (ret)
213 goto wait4video_error;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700214
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800215 /* The payload size has to be a multiple of 4 */
216 size = cm->size;
217 size &= 0x03;
218 if (size)
219 size = 4 - size;
220 size += cm->size;
221 memcpy((uint8_t *)off, (cm->payload), size);
Matthew Qin81933ce2015-02-03 17:58:52 +0800222 arch_clean_invalidate_cache_range((addr_t)(off), size);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800223 writel(off, ctl_base + DMA_CMD_OFFSET);
224 writel(size, ctl_base + DMA_CMD_LENGTH);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800225 if (dual_dsi) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800226 writel(off, sctl_base + DMA_CMD_OFFSET);
227 writel(size, sctl_base + DMA_CMD_LENGTH);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800228 }
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700229 dsb();
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800230 ret += mdss_dsi_cmd_dma_trigger_for_panel(dual_dsi, ctl_base,
231 sctl_base);
Dhaval Patel607a6242013-10-29 12:37:24 -0700232 if (cm->wait)
233 mdelay(cm->wait);
234 else
235 udelay(80);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700236 cm++;
237 }
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700238wait4video_error:
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530239#endif
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700240 return ret;
241}
242
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800243int mdss_dsi_cmds_rx(struct mipi_panel_info *mipi, uint32_t **rp, int rp_len,
244 int rdbk_len)
Casey Piper84036752013-09-05 14:56:37 -0700245{
246 uint32_t *lp, data;
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -0800247 uint32_t *dp;
Casey Piper84036752013-09-05 14:56:37 -0700248 int i, off;
249 int rlen, res;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800250 uint32_t ctl_base;
251
252 /* if dest controller is not specified, default to DSI0 */
253 if (!mipi)
254 ctl_base = MIPI_DSI0_BASE;
255 else
256 ctl_base = mipi->ctl_base;
Casey Piper84036752013-09-05 14:56:37 -0700257
258 if (rdbk_len > rp_len) {
259 return 0;
260 }
261
262 if (rdbk_len <= 2)
263 rlen = 4; /* short read */
264 else
265 rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */
266
267 if (rlen > MIPI_DSI_REG_LEN) {
268 return 0;
269 }
270
271 res = rlen & 0x03;
272
273 rlen += res; /* 4 byte align */
274 lp = *rp;
275
276 rlen += 3;
277 rlen >>= 2;
278
279 if (rlen > 4)
280 rlen = 4; /* 4 x 32 bits registers only */
281
Shivaraj Shetty3c77da62013-12-09 15:58:16 +0530282 off = RDBK_DATA0;
Casey Piper84036752013-09-05 14:56:37 -0700283 off += ((rlen - 1) * 4);
284
285 for (i = 0; i < rlen; i++) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800286 data = readl(ctl_base + off);
Casey Piper84036752013-09-05 14:56:37 -0700287 *lp = ntohl(data); /* to network byte order */
288 lp++;
289
290 off -= 4;
291 }
292
293 if (rdbk_len > 2) {
294 /*First 4 bytes + paded bytes will be header next len bytes would be payload */
295 for (i = 0; i < rdbk_len; i++) {
296 dp = *rp;
297 dp[i] = dp[(res + i) >> 2];
298 }
299 }
300 return rdbk_len;
301}
302
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800303static int mdss_dsi_cmd_bta_sw_trigger(uint32_t ctl_base)
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800304{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800305 uint32_t data;
306 int cnt = 0;
307 int err = 0;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800308
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800309 writel(0x01, ctl_base + 0x094); /* trigger */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800310 while (cnt < 10000) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800311 data = readl(ctl_base + 0x0004); /*DSI_STATUS */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800312 if ((data & 0x0010) == 0)
313 break;
314 cnt++;
315 }
316 if (cnt == 10000)
317 err = 1;
318 return err;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800319}
320
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800321int mdss_dsi_host_init(struct mipi_panel_info *mipi, uint32_t
Dhaval Patel9207dec2014-04-16 10:45:32 -0700322 dual_dsi, uint32_t broadcast)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700323{
324 uint8_t DMA_STREAM1 = 0; // for mdp display processor path
325 uint8_t EMBED_MODE1 = 1; // from frame buffer
326 uint8_t POWER_MODE2 = 1; // from frame buffer
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800327 uint8_t PACK_TYPE1 = 0; // long packet
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700328 uint8_t VC1 = 0;
329 uint8_t DT1 = 0; // non embedded mode
330 uint8_t WC1 = 0; // for non embedded mode only
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700331 uint8_t DLNx_EN;
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700332 uint8_t lane_swap = 0;
Siddhartha Agrawalb6c861f2013-05-31 19:36:44 -0700333 uint32_t timing_ctl = 0;
Vineet Bajaj2f08a362014-07-24 20:50:42 +0530334 uint32_t lane_swap_dsi1 = 0;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700335 uint32_t ctrl_mode = 0x105; //Default is command mode to send cmds.
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700336
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400337#if (DISPLAY_TYPE_MDSS == 1)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800338 switch (mipi->num_of_lanes) {
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700339 default:
340 case 1:
341 DLNx_EN = 1; // 1 lane
342 break;
343 case 2:
344 DLNx_EN = 3; // 2 lane
345 break;
346 case 3:
347 DLNx_EN = 7; // 3 lane
348 break;
349 case 4:
350 DLNx_EN = 0x0F; /* 4 lanes */
351 break;
352 }
353
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800354 lane_swap = mipi->lane_swap;
355 timing_ctl = ((mipi->t_clk_post << 8) | mipi->t_clk_pre);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700356
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800357 if (mipi->cmds_post_tg) {
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700358 /*
359 * Need to send pixel data before sending the ON commands
360 * so need to configure controller to VIDEO MODE.
361 */
362 ctrl_mode = 0x103;
363 }
364
Dhaval Patel9207dec2014-04-16 10:45:32 -0700365 if (dual_dsi) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800366 writel(0x0001, mipi->sctl_base + SOFT_RESET);
367 writel(0x0000, mipi->sctl_base + SOFT_RESET);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700368
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800369 /* Turn on all DSI Clks */
370 writel((0 << 16) | 0x3f, mipi->sctl_base + CLK_CTRL);
371 writel(DMA_STREAM1 << 8 | 0x04, mipi->sctl_base + TRIG_CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700372
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800373 writel(0 << 30 | DLNx_EN << 4 | ctrl_mode, mipi->sctl_base + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700374 writel(broadcast << 31 | EMBED_MODE1 << 28 | POWER_MODE2 << 26
375 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800376 mipi->sctl_base + COMMAND_MODE_DMA_CTRL);
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700377
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800378 /* for 8939 hw dsi1 has Lane_map as 3210 */
Jeevan Shriram01379322015-01-07 17:41:26 -0800379 if (readl(mipi->ctl_base) == DSI_HW_REV_103_1)
Vineet Bajaj2f08a362014-07-24 20:50:42 +0530380 lane_swap_dsi1 = 0x7;
381 else
382 lane_swap_dsi1 = lane_swap;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800383 writel(lane_swap_dsi1, mipi->sctl_base + LANE_SWAP_CTL);
384 writel(timing_ctl, mipi->sctl_base + TIMING_CTL);
Ray Zhang8da5e5d2015-01-21 10:14:09 +0800385
386 if (mipi->force_clk_lane_hs) {
387 uint32_t tmp;
388
389 tmp = readl(mipi->sctl_base + LANE_CTL);
390 tmp |= BIT(28);
391 writel(tmp, mipi->sctl_base + LANE_CTL);
392 }
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700393 }
394
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800395 writel(0x0001, mipi->ctl_base + SOFT_RESET);
396 writel(0x0000, mipi->ctl_base + SOFT_RESET);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700397
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800398 /* Turn on all DSI Clks */
399 writel((0 << 16) | 0x3f, mipi->ctl_base + CLK_CTRL);
400 writel(DMA_STREAM1 << 8 | 0x04, mipi->ctl_base + TRIG_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700401
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800402 writel(0 << 30 | DLNx_EN << 4 | ctrl_mode, mipi->ctl_base + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700403 writel(broadcast << 31 | EMBED_MODE1 << 28 | POWER_MODE2 << 26
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700404 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800405 mipi->ctl_base + COMMAND_MODE_DMA_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700406
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800407 writel(lane_swap, mipi->ctl_base + LANE_SWAP_CTL);
408 writel(timing_ctl, mipi->ctl_base + TIMING_CTL);
Ray Zhang8da5e5d2015-01-21 10:14:09 +0800409
410 if (mipi->force_clk_lane_hs) {
411 uint32_t tmp;
412
413 tmp = readl(mipi->ctl_base + LANE_CTL);
414 tmp |= BIT(28);
415 writel(tmp, mipi->ctl_base + LANE_CTL);
416 }
Huaibin Yang952dce32015-02-19 18:01:27 -0800417
418 if ((mipi->mode == DSI_VIDEO_MODE) && mipi->tx_eot_append)
419 writel(0x1, mipi->ctl_base + EOT_PACKET_CTRL);
420
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800421#endif
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700422
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800423 return 0;
424}
425
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530426void mdss_dsi_panel_shutdown(struct msm_panel_info *pinfo)
427{
428#if (DISPLAY_TYPE_MDSS == 1)
429 unsigned long read_val = 0;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800430 uint32_t ctl_base = pinfo->mipi.ctl_base;
431 uint32_t sctl_base = pinfo->mipi.sctl_base;
432
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530433 if (pinfo->mipi.panel_off_cmds) {
434 /*
435 * Once MDP TG is disabled, reset of DSI controller is
436 * needed before we send panel OFF commands.
437 */
438 if (pinfo->type == MIPI_VIDEO_PANEL) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800439 read_val = readl(ctl_base + CTRL);
440 writel((read_val & ~BIT(0)), ctl_base + CTRL);
441 writel(0x0001, ctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530442 dsb();
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800443 writel(0x0000, ctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530444 dsb();
445 /* Enable cmd mode only */
446 writel(((read_val & ~BIT(1)) | BIT(2)),
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800447 ctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530448 }
449
450 if (pinfo->mipi.broadcast) {
451 if (pinfo->type == MIPI_VIDEO_PANEL) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800452 read_val = readl(sctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530453 writel((read_val & ~BIT(0)),
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800454 sctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530455
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800456 writel(0x0001, sctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530457 dsb();
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800458 writel(0x0000, sctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530459 dsb();
460
461 writel(((read_val & ~BIT(1)) | BIT(2)),
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800462 sctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530463 }
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530464 }
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800465 mdss_dsi_cmds_tx(&pinfo->mipi, pinfo->mipi.panel_off_cmds,
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800466 pinfo->mipi.num_of_panel_off_cmds,
467 pinfo->mipi.broadcast);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530468 }
469#endif
470}
471
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800472int mdss_dsi_panel_initialize(struct mipi_panel_info *mipi, uint32_t
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800473 broadcast)
474{
475 int status = 0;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700476 uint32_t ctrl_mode = 0;
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800477
478#if (DISPLAY_TYPE_MDSS == 1)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800479 if (!mipi->panel_on_cmds)
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800480 goto end;
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700481
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800482 ctrl_mode = readl(mipi->ctl_base + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700483
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800484 /* Enable command mode before sending the commands. */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800485 writel(ctrl_mode | 0x04, mipi->ctl_base + CTRL);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800486 if (broadcast)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800487 writel(ctrl_mode | 0x04, mipi->sctl_base + CTRL);
488 status = mdss_dsi_cmds_tx(mipi, mipi->panel_on_cmds,
489 mipi->num_of_panel_on_cmds, broadcast);
490 writel(ctrl_mode, mipi->ctl_base + CTRL);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800491 if (broadcast)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800492 writel(ctrl_mode, mipi->sctl_base + CTRL);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800493
494 if (!broadcast && !status && target_panel_auto_detect_enabled())
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800495 status = mdss_dsi_read_panel_signature(mipi);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800496
497end:
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400498#endif
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700499 return status;
500}
501
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700502int mdss_dsi_video_mode_config(uint16_t disp_width,
503 uint16_t disp_height,
504 uint16_t img_width,
505 uint16_t img_height,
506 uint16_t hsync_porch0_fp,
507 uint16_t hsync_porch0_bp,
508 uint16_t vsync_porch0_fp,
509 uint16_t vsync_porch0_bp,
510 uint16_t hsync_width,
511 uint16_t vsync_width,
512 uint16_t dst_format,
513 uint16_t traffic_mode,
514 uint8_t lane_en,
Padmanabhan Komandurue3209872015-01-12 16:33:16 +0530515 uint8_t pulse_mode_hsa_he,
516 uint32_t low_pwr_stop_mode,
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700517 uint8_t eof_bllp_pwr,
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700518 uint8_t interleav,
519 uint32_t ctl_base)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700520{
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700521 int status = 0;
522
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400523#if (DISPLAY_TYPE_MDSS == 1)
Padmanabhan Komanduru684b58f2015-02-11 16:22:51 +0530524 int last_line_interleave_en = 0;
525
526 /*Check if EOF_BLLP_PWR_MODE bit is set*/
527 if(eof_bllp_pwr & 0x8)
528 last_line_interleave_en = 1;
529
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700530 /* disable mdp first */
531 mdp_disable();
532
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700533 writel(0x00000000, ctl_base + CLK_CTRL);
534 writel(0x00000002, ctl_base + CLK_CTRL);
535 writel(0x00000006, ctl_base + CLK_CTRL);
536 writel(0x0000000e, ctl_base + CLK_CTRL);
537 writel(0x0000001e, ctl_base + CLK_CTRL);
538 writel(0x0000023f, ctl_base + CLK_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700539
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700540 writel(0, ctl_base + CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700541
Padmanabhan Komanduru2f8e0bc2014-11-27 18:25:36 +0530542 writel(0x03f03fe0, ctl_base + ERR_INT_MASK0);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700543
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700544 writel(0x02020202, ctl_base + INT_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700545
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530546 /* For 8916/8939, enable DSI timing double buffering */
Kuogee Hsieh861e25d2014-10-29 16:50:15 -0700547 if (readl(ctl_base) >= DSI_HW_REV_103 &&
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530548 mdp_get_revision() != MDP_REV_305)
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530549 writel(0x1, ctl_base + TIMING_DB_MODE);
550
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700551 writel(((disp_width + hsync_porch0_bp) << 16) | hsync_porch0_bp,
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700552 ctl_base + VIDEO_MODE_ACTIVE_H);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700553
554 writel(((disp_height + vsync_porch0_bp) << 16) | (vsync_porch0_bp),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700555 ctl_base + VIDEO_MODE_ACTIVE_V);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700556
Terence Hampson7385f6a2013-08-16 15:31:25 -0400557 if (mdp_get_revision() >= MDP_REV_41 ||
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530558 mdp_get_revision() == MDP_REV_304 ||
559 mdp_get_revision() == MDP_REV_305) {
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700560 writel(((disp_height + vsync_porch0_fp
561 + vsync_porch0_bp - 1) << 16)
562 | (disp_width + hsync_porch0_fp
563 + hsync_porch0_bp - 1),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700564 ctl_base + VIDEO_MODE_TOTAL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700565 } else {
566 writel(((disp_height + vsync_porch0_fp
567 + vsync_porch0_bp) << 16)
568 | (disp_width + hsync_porch0_fp
569 + hsync_porch0_bp),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700570 ctl_base + VIDEO_MODE_TOTAL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700571 }
572
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700573 writel((hsync_width << 16) | 0, ctl_base + VIDEO_MODE_HSYNC);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700574
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700575 writel(0 << 16 | 0, ctl_base + VIDEO_MODE_VSYNC);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700576
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700577 writel(vsync_width << 16 | 0, ctl_base + VIDEO_MODE_VSYNC_VPOS);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700578
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530579 /* For 8916/8939, flush the DSI timing registers */
Kuogee Hsieh861e25d2014-10-29 16:50:15 -0700580 if (readl(ctl_base) >= DSI_HW_REV_103 &&
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530581 mdp_get_revision() != MDP_REV_305)
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530582 writel(0x1, ctl_base + TIMING_FLUSH);
583
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700584 writel(0x0, ctl_base + EOT_PACKET_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700585
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700586 writel(0x00000100, ctl_base + MISR_VIDEO_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700587
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530588 if (mdp_get_revision() >= MDP_REV_41 || mdp_get_revision() == MDP_REV_305) {
Padmanabhan Komanduru684b58f2015-02-11 16:22:51 +0530589 writel(last_line_interleave_en << 31 | pulse_mode_hsa_he << 28 |
590 low_pwr_stop_mode << 16 | eof_bllp_pwr << 12 |
591 traffic_mode << 8 | dst_format << 4 | 0x0,
592 ctl_base + VIDEO_MODE_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700593 } else {
594 writel(1 << 28 | 1 << 24 | 1 << 20 | low_pwr_stop_mode << 16 |
595 eof_bllp_pwr << 12 | traffic_mode << 8
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700596 | dst_format << 4 | 0x0, ctl_base + VIDEO_MODE_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700597 }
598
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700599 writel(0x3fd08, ctl_base + HS_TIMER_CTRL);
600 writel(0x00010100, ctl_base + MISR_VIDEO_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700601
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700602 writel(0x00010100, ctl_base + INT_CTRL);
603 writel(0x02010202, ctl_base + INT_CTRL);
604 writel(0x02030303, ctl_base + INT_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700605
606 writel(interleav << 30 | 0 << 24 | 0 << 20 | lane_en << 4
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700607 | 0x103, ctl_base + CTRL);
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400608#endif
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700609
610 return status;
611}
612
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800613int mdss_dsi_config(struct msm_fb_panel_data *panel)
614{
615 int ret = NO_ERROR;
616 struct msm_panel_info *pinfo;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800617 struct mipi_panel_info *mipi;
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800618
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400619#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800620 if (!panel)
621 return ERR_INVALID_ARGS;
622
623 pinfo = &(panel->panel_info);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800624 mipi = &(pinfo->mipi);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800625
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800626 dprintf(SPEW, "ctl_base=0x%08x, phy_base=0x%08x\n", mipi->ctl_base,
627 mipi->phy_base);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800628
Jeevan Shriram01379322015-01-07 17:41:26 -0800629 mdss_dsi_phy_init(mipi);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800630
631 ret = mdss_dsi_host_init(mipi, mipi->dual_dsi,
632 mipi->broadcast);
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800633 if (ret) {
634 dprintf(CRITICAL, "dsi host init error\n");
635 goto error;
636 }
637
Aravind Venkateswaran51e57552014-12-09 13:23:19 -0800638 mdss_dsi_phy_contention_detection(mipi, mipi->phy_base);
639 if (mipi->dual_dsi)
640 mdss_dsi_phy_contention_detection(mipi, mipi->sphy_base);
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400641
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800642 if (panel->pre_init_func) {
643 ret = panel->pre_init_func();
644 if (ret) {
645 dprintf(CRITICAL, "pre_init_func error\n");
646 goto error;
647 }
648 }
649
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800650 if (!mipi->cmds_post_tg) {
651 ret = mdss_dsi_panel_initialize(mipi, mipi->broadcast);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700652 if (ret) {
653 dprintf(CRITICAL, "dsi panel init error\n");
654 goto error;
655 }
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800656 }
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800657
658 if (pinfo->rotate && panel->rotate)
659 pinfo->rotate();
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400660#endif
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800661
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800662error:
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800663 return ret;
664}
665
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700666int mdss_dsi_post_on(struct msm_fb_panel_data *panel)
667{
668 int ret = 0;
669 struct msm_panel_info *pinfo = &(panel->panel_info);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700670
671 if (pinfo->mipi.cmds_post_tg) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800672 ret = mdss_dsi_panel_initialize(&pinfo->mipi, pinfo->mipi.broadcast);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700673 if (ret) {
674 dprintf(CRITICAL, "dsi panel init error\n");
675 }
676 }
677 return ret;
678}
679
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700680int mdss_dsi_cmd_mode_config(uint16_t disp_width,
681 uint16_t disp_height,
682 uint16_t img_width,
683 uint16_t img_height,
684 uint16_t dst_format,
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400685 uint8_t ystride,
686 uint8_t lane_en,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800687 uint8_t interleav,
688 uint32_t ctl_base)
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700689{
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400690 uint16_t dst_fmt = 0;
691
692 switch (dst_format) {
693 case DSI_VIDEO_DST_FORMAT_RGB565:
694 dst_fmt = DSI_CMD_DST_FORMAT_RGB565;
695 break;
696 case DSI_VIDEO_DST_FORMAT_RGB666:
697 case DSI_VIDEO_DST_FORMAT_RGB666_LOOSE:
698 dst_fmt = DSI_CMD_DST_FORMAT_RGB666;
699 break;
700 case DSI_VIDEO_DST_FORMAT_RGB888:
701 dst_fmt = DSI_CMD_DST_FORMAT_RGB888;
702 break;
703 default:
704 dprintf(CRITICAL, "unsupported dst format\n");
705 return ERROR;
706 }
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700707
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400708#if (DISPLAY_TYPE_MDSS == 1)
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800709 writel(0x00000000, ctl_base + CLK_CTRL);
710 writel(0x00000000, ctl_base + CLK_CTRL);
711 writel(0x00000000, ctl_base + CLK_CTRL);
712 writel(0x00000000, ctl_base + CLK_CTRL);
713 writel(0x00000002, ctl_base + CLK_CTRL);
714 writel(0x00000006, ctl_base + CLK_CTRL);
715 writel(0x0000000e, ctl_base + CLK_CTRL);
716 writel(0x0000001e, ctl_base + CLK_CTRL);
717 writel(0x0000023f, ctl_base + CLK_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700718
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800719 writel(0, ctl_base + CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700720
Padmanabhan Komanduru2f8e0bc2014-11-27 18:25:36 +0530721 writel(0x03f03fe0, ctl_base + ERR_INT_MASK0);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700722
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800723 writel(0x02020202, ctl_base + INT_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700724
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800725 writel(dst_fmt, ctl_base + COMMAND_MODE_MDP_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700726 writel((img_width * ystride + 1) << 16 | 0x0039,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800727 ctl_base + COMMAND_MODE_MDP_STREAM0_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700728 writel((img_width * ystride + 1) << 16 | 0x0039,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800729 ctl_base + COMMAND_MODE_MDP_STREAM1_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700730 writel(img_height << 16 | img_width,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800731 ctl_base + COMMAND_MODE_MDP_STREAM0_TOTAL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700732 writel(img_height << 16 | img_width,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800733 ctl_base + COMMAND_MODE_MDP_STREAM1_TOTAL);
734 writel(0x13c2c, ctl_base + COMMAND_MODE_MDP_DCS_CMD_CTRL);
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400735 writel(interleav << 30 | 0 << 24 | 0 << 20 | lane_en << 4 | 0x105,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800736 ctl_base + CTRL);
Padmanabhan Komanduru7860be52014-03-18 19:07:36 +0530737 writel(0x14000000, ctl_base + COMMAND_MODE_DMA_CTRL);
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800738 writel(0x10000000, ctl_base + MISR_CMD_CTRL);
Xiaoming Zhoua0469332014-03-04 18:34:24 -0500739 writel(0x1, ctl_base + EOT_PACKET_CTRL);
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400740#endif
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400741 return 0;
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700742}
743
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800744int mipi_dsi_on(struct msm_panel_info *pinfo)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700745{
746 int ret = NO_ERROR;
747 unsigned long ReadValue;
748 unsigned long count = 0;
749
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800750 ReadValue = readl(pinfo->mipi.ctl_base + INT_CTRL) & 0x00010000;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700751
752 mdelay(10);
753
754 while (ReadValue != 0x00010000) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800755 ReadValue = readl(pinfo->mipi.ctl_base + INT_CTRL) & 0x00010000;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700756 count++;
757 if (count > 0xffff) {
758 dprintf(CRITICAL, "Video lane test failed\n");
759 return ERROR;
760 }
761 }
762
Amir Samuelov2d4ba162012-07-22 11:53:14 +0300763 dprintf(INFO, "Video lane tested successfully\n");
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700764 return ret;
765}
766
Siddhartha Agrawal24d81b52013-07-01 11:13:32 -0700767int mipi_dsi_off(struct msm_panel_info *pinfo)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700768{
Amol Jadi6834f1a2012-06-29 14:42:59 -0700769 if(!target_cont_splash_screen())
770 {
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530771 mdss_dsi_panel_shutdown(pinfo);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800772 writel(0, pinfo->mipi.ctl_base + CLK_CTRL);
773 writel(0x1F1, pinfo->mipi.ctl_base + CTRL);
Siddhartha Agrawale0033a12013-02-23 15:37:42 -0800774 }
775
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800776 writel(0x1115501, pinfo->mipi.ctl_base + INT_CTRL);
Siddhartha Agrawal24d81b52013-07-01 11:13:32 -0700777 if (pinfo->mipi.broadcast)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800778 writel(0x1115501, pinfo->mipi.sctl_base + INT_CTRL);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700779
780 return NO_ERROR;
781}
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530782
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800783#if (DISPLAY_TYPE_MDSS == 0)
784static int dsi_cmd_dma_trigger_for_panel()
785{
786 unsigned long ReadValue;
787 unsigned long count = 0;
788 int status = 0;
789
790 writel(0x03030303, DSI_INT_CTRL);
791 writel(0x1, DSI_CMD_MODE_DMA_SW_TRIGGER);
792 dsb();
793 ReadValue = readl(DSI_INT_CTRL) & 0x00000001;
794 while (ReadValue != 0x00000001) {
795 ReadValue = readl(DSI_INT_CTRL) & 0x00000001;
796 count++;
797 if (count > 0xffff) {
798 status = FAIL;
799 dprintf(CRITICAL,
800 "Panel CMD: command mode dma test failed\n");
801 return status;
802 }
803 }
804
805 writel((readl(DSI_INT_CTRL) | 0x01000001), DSI_INT_CTRL);
806 dprintf(SPEW, "Panel CMD: command mode dma tested successfully\n");
807 return status;
808}
809
810int mipi_dsi_cmds_tx(struct mipi_dsi_cmd *cmds, int count)
811{
812 int ret = 0;
813 struct mipi_dsi_cmd *cm;
814 int i = 0;
815 char pload[256];
816 uint32_t off;
817
818 /* Align pload at 8 byte boundry */
819 off = pload;
820 off &= 0x07;
821 if (off)
822 off = 8 - off;
823 off += pload;
824
825 cm = cmds;
826 for (i = 0; i < count; i++) {
827 /* Wait for VIDEO_MODE_DONE */
828 ret = mdss_dsi_wait4_video_done();
829 if (ret)
830 goto mipi_cmds_error;
831
832 memcpy((void *)off, (cm->payload), cm->size);
Matthew Qin81933ce2015-02-03 17:58:52 +0800833 arch_clean_invalidate_cache_range((addr_t)(off), size);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800834 writel(off, DSI_DMA_CMD_OFFSET);
835 writel(cm->size, DSI_DMA_CMD_LENGTH); // reg 0x48 for this build
836 dsb();
837 ret += dsi_cmd_dma_trigger_for_panel();
838 dsb();
839 if (cm->wait)
840 mdelay(cm->wait);
841 else
842 udelay(80);
843 cm++;
844 }
845mipi_cmds_error:
846 return ret;
847}
848
849/*
850 * mipi_dsi_cmd_rx: can receive at most 16 bytes
851 * per transaction since it only have 4 32bits reigsters
852 * to hold data.
853 * therefore Maximum Return Packet Size need to be set to 16.
854 * any return data more than MRPS need to be break down
855 * to multiple transactions.
856 */
857int mipi_dsi_cmds_rx(char **rp, int len)
858{
859 uint32_t *lp, data;
860 char *dp;
861 int i, off, cnt;
862 int rlen, res;
863
864 if (len <= 2)
865 rlen = 4; /* short read */
866 else
867 rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */
868
869 if (rlen > MIPI_DSI_REG_LEN) {
870 return 0;
871 }
872
873 res = rlen & 0x03;
874
875 rlen += res; /* 4 byte align */
876 lp = (uint32_t *) (*rp);
877
878 cnt = rlen;
879 cnt += 3;
880 cnt >>= 2;
881
882 if (cnt > 4)
883 cnt = 4; /* 4 x 32 bits registers only */
884
885 off = 0x068; /* DSI_RDBK_DATA0 */
886 off += ((cnt - 1) * 4);
887
888 for (i = 0; i < cnt; i++) {
889 data = (uint32_t) readl(MIPI_DSI_BASE + off);
890 *lp++ = ntohl(data); /* to network byte order */
891 off -= 4;
892 }
893
894 if (len > 2) {
895 /*First 4 bytes + paded bytes will be header next len bytes would be payload */
896 for (i = 0; i < len; i++) {
897 dp = *rp;
898 dp[i] = dp[4 + res + i];
899 }
900 }
901
902 return len;
903}
904
905static int mipi_dsi_panel_initialize(struct mipi_dsi_panel_config *pinfo)
906{
907 uint8_t DMA_STREAM1 = 0; // for mdp display processor path
908 uint8_t EMBED_MODE1 = 1; // from frame buffer
909 uint8_t POWER_MODE2 = 1; // from frame buffer
910 uint8_t PACK_TYPE1; // long packet
911 uint8_t VC1 = 0;
912 uint8_t DT1 = 0; // non embedded mode
913 uint8_t WC1 = 0; // for non embedded mode only
914 int status = 0;
915 uint8_t DLNx_EN;
916
917 switch (pinfo->num_of_lanes) {
918 default:
919 case 1:
920 DLNx_EN = 1; // 1 lane
921 break;
922 case 2:
923 DLNx_EN = 3; // 2 lane
924 break;
925 case 3:
926 DLNx_EN = 7; // 3 lane
927 break;
928 case 4:
929 DLNx_EN = 0x0F; /* 4 lanes */
930 break;
931 }
932
933 PACK_TYPE1 = pinfo->pack;
934
935 writel(0x0001, DSI_SOFT_RESET);
936 writel(0x0000, DSI_SOFT_RESET);
937
938 writel((0 << 16) | 0x3f, DSI_CLK_CTRL); /* Turn on all DSI Clks */
939 writel(DMA_STREAM1 << 8 | 0x04, DSI_TRIG_CTRL); // reg 0x80 dma trigger: sw
940 // trigger 0x4; dma stream1
941
942 writel(0 << 30 | DLNx_EN << 4 | 0x105, DSI_CTRL); // reg 0x00 for this
943 // build
944 writel(EMBED_MODE1 << 28 | POWER_MODE2 << 26
945 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
946 DSI_COMMAND_MODE_DMA_CTRL);
947
948 if (pinfo->panel_on_cmds)
949 status = mipi_dsi_cmds_tx(pinfo->panel_on_cmds,
950 pinfo->num_of_panel_on_cmds);
951
952 return status;
953}
954#endif
955
956void mipi_dsi_shutdown(void)
957{
958#if (DISPLAY_TYPE_MDSS == 0)
959 if(!target_cont_splash_screen())
960 {
961 mdp_shutdown();
962 writel(0x01010101, DSI_INT_CTRL);
963 writel(0x13FF3BFF, DSI_ERR_INT_MASK0);
964
965 writel(0, DSI_CLK_CTRL);
966 writel(0, DSI_CTRL);
967 writel(0, DSIPHY_PLL_CTRL(0));
968 }
969 else
970 {
971 /* To keep the splash screen displayed till kernel driver takes
972 control, do not turn off the video mode engine and clocks.
973 Only disabling the MIPI DSI IRQs */
974 writel(0x01010101, DSI_INT_CTRL);
975 writel(0x13FF3BFF, DSI_ERR_INT_MASK0);
976 }
977#endif
978}
979
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530980int mipi_cmd_trigger()
981{
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800982#if (DISPLAY_TYPE_MDSS == 0)
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530983 writel(0x1, DSI_CMD_MODE_MDP_SW_TRIGGER);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800984#endif
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530985 return NO_ERROR;
986}
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800987
988int mipi_config(struct msm_fb_panel_data *panel)
989{
990 int ret = NO_ERROR;
991#if (DISPLAY_TYPE_MDSS == 0)
992 struct msm_panel_info *pinfo;
993 struct mipi_dsi_panel_config mipi_pinfo;
994
995 if (!panel)
996 return ERR_INVALID_ARGS;
997
998 pinfo = &(panel->panel_info);
999 mipi_pinfo.mode = pinfo->mipi.mode;
1000 mipi_pinfo.num_of_lanes = pinfo->mipi.num_of_lanes;
1001 mipi_pinfo.dsi_phy_config = pinfo->mipi.dsi_phy_db;
1002 mipi_pinfo.panel_on_cmds = pinfo->mipi.panel_on_cmds;
1003 mipi_pinfo.num_of_panel_on_cmds = pinfo->mipi.num_of_panel_on_cmds;
1004 mipi_pinfo.lane_swap = pinfo->mipi.lane_swap;
1005 mipi_pinfo.pack = 1;
1006
1007 /* Enable MMSS_AHB_ARB_MATER_PORT_E for
1008 arbiter master0 and master 1 request */
1009#if (!DISPLAY_MIPI_PANEL_RENESAS && !DISPLAY_TYPE_DSI6G && !DISPLAY_TYPE_8610)
1010 writel(0x00001800, MMSS_SFPB_GPREG);
1011#endif
1012
1013 mipi_dsi_phy_init(&mipi_pinfo);
1014
1015 ret += mipi_dsi_panel_initialize(&mipi_pinfo);
1016
1017 if (pinfo->rotate && panel->rotate)
1018 pinfo->rotate();
1019#endif
1020 return ret;
1021}