blob: 818155fdf438c0dd31f5a2456c7cd87554e0dc4f [file] [log] [blame]
Padmanabhan Komandurubd8268a2018-04-30 17:05:56 +05301/* Copyright (c) 2010-2016, 2018, 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
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);
Matthew Qin81933ce2015-02-03 17:58:52 +0800221 arch_clean_invalidate_cache_range((addr_t)(off), size);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800222 writel(off, ctl_base + DMA_CMD_OFFSET);
223 writel(size, ctl_base + DMA_CMD_LENGTH);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800224 if (dual_dsi) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800225 writel(off, sctl_base + DMA_CMD_OFFSET);
226 writel(size, sctl_base + DMA_CMD_LENGTH);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800227 }
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700228 dsb();
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800229 ret += mdss_dsi_cmd_dma_trigger_for_panel(dual_dsi, ctl_base,
230 sctl_base);
Dhaval Patel607a6242013-10-29 12:37:24 -0700231 if (cm->wait)
232 mdelay(cm->wait);
233 else
234 udelay(80);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700235 cm++;
236 }
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700237wait4video_error:
Padmanabhan Komanduru66459a92014-11-04 00:05:08 +0530238#endif
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700239 return ret;
240}
241
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800242int mdss_dsi_cmds_rx(struct mipi_panel_info *mipi, uint32_t **rp, int rp_len,
243 int rdbk_len)
Casey Piper84036752013-09-05 14:56:37 -0700244{
245 uint32_t *lp, data;
Veera Sundaram Sankarandb0b2bf2014-12-16 18:09:27 -0800246 uint32_t *dp;
Casey Piper84036752013-09-05 14:56:37 -0700247 int i, off;
248 int rlen, res;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800249 uint32_t ctl_base;
250
251 /* if dest controller is not specified, default to DSI0 */
252 if (!mipi)
253 ctl_base = MIPI_DSI0_BASE;
254 else
255 ctl_base = mipi->ctl_base;
Casey Piper84036752013-09-05 14:56:37 -0700256
257 if (rdbk_len > rp_len) {
258 return 0;
259 }
260
261 if (rdbk_len <= 2)
262 rlen = 4; /* short read */
263 else
264 rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */
265
266 if (rlen > MIPI_DSI_REG_LEN) {
267 return 0;
268 }
269
270 res = rlen & 0x03;
271
272 rlen += res; /* 4 byte align */
273 lp = *rp;
274
275 rlen += 3;
276 rlen >>= 2;
277
278 if (rlen > 4)
279 rlen = 4; /* 4 x 32 bits registers only */
280
Shivaraj Shetty3c77da62013-12-09 15:58:16 +0530281 off = RDBK_DATA0;
Casey Piper84036752013-09-05 14:56:37 -0700282 off += ((rlen - 1) * 4);
283
284 for (i = 0; i < rlen; i++) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800285 data = readl(ctl_base + off);
Casey Piper84036752013-09-05 14:56:37 -0700286 *lp = ntohl(data); /* to network byte order */
287 lp++;
288
289 off -= 4;
290 }
291
292 if (rdbk_len > 2) {
293 /*First 4 bytes + paded bytes will be header next len bytes would be payload */
294 for (i = 0; i < rdbk_len; i++) {
295 dp = *rp;
296 dp[i] = dp[(res + i) >> 2];
297 }
298 }
299 return rdbk_len;
300}
301
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800302static int mdss_dsi_cmd_bta_sw_trigger(uint32_t ctl_base)
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800303{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800304 uint32_t data;
305 int cnt = 0;
306 int err = 0;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800307
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800308 writel(0x01, ctl_base + 0x094); /* trigger */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800309 while (cnt < 10000) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800310 data = readl(ctl_base + 0x0004); /*DSI_STATUS */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800311 if ((data & 0x0010) == 0)
312 break;
313 cnt++;
314 }
315 if (cnt == 10000)
316 err = 1;
317 return err;
Shashank Mittalcbd271d2011-01-14 15:18:33 -0800318}
319
Veera Sundaram Sankaran9439eb12016-06-13 13:53:56 -0700320static void mdss_dsi_force_clk_lane_hs(struct mipi_panel_info *mipi,
321 uint32_t dual_dsi)
322{
323 uint32_t tmp;
324
325 if (dual_dsi) {
326 tmp = readl(mipi->sctl_base + LANE_CTL);
327 tmp |= BIT(28);
328 writel(tmp, mipi->sctl_base + LANE_CTL);
329 }
330
331 tmp = readl(mipi->ctl_base + LANE_CTL);
332 tmp |= BIT(28);
333 writel(tmp, mipi->ctl_base + LANE_CTL);
334}
335
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800336int mdss_dsi_host_init(struct mipi_panel_info *mipi, uint32_t
Dhaval Patel9207dec2014-04-16 10:45:32 -0700337 dual_dsi, uint32_t broadcast)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700338{
339 uint8_t DMA_STREAM1 = 0; // for mdp display processor path
340 uint8_t EMBED_MODE1 = 1; // from frame buffer
341 uint8_t POWER_MODE2 = 1; // from frame buffer
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800342 uint8_t PACK_TYPE1 = 0; // long packet
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700343 uint8_t VC1 = 0;
344 uint8_t DT1 = 0; // non embedded mode
345 uint8_t WC1 = 0; // for non embedded mode only
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700346 uint8_t DLNx_EN;
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700347 uint8_t lane_swap = 0;
Siddhartha Agrawalb6c861f2013-05-31 19:36:44 -0700348 uint32_t timing_ctl = 0;
Vineet Bajaj2f08a362014-07-24 20:50:42 +0530349 uint32_t lane_swap_dsi1 = 0;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700350 uint32_t ctrl_mode = 0x105; //Default is command mode to send cmds.
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700351
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400352#if (DISPLAY_TYPE_MDSS == 1)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800353 switch (mipi->num_of_lanes) {
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700354 default:
355 case 1:
356 DLNx_EN = 1; // 1 lane
357 break;
358 case 2:
359 DLNx_EN = 3; // 2 lane
360 break;
361 case 3:
362 DLNx_EN = 7; // 3 lane
363 break;
364 case 4:
365 DLNx_EN = 0x0F; /* 4 lanes */
366 break;
367 }
368
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800369 lane_swap = mipi->lane_swap;
370 timing_ctl = ((mipi->t_clk_post << 8) | mipi->t_clk_pre);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700371
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800372 if (mipi->cmds_post_tg) {
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700373 /*
374 * Need to send pixel data before sending the ON commands
375 * so need to configure controller to VIDEO MODE.
376 */
377 ctrl_mode = 0x103;
378 }
379
Dhaval Patel9207dec2014-04-16 10:45:32 -0700380 if (dual_dsi) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800381 writel(0x0001, mipi->sctl_base + SOFT_RESET);
382 writel(0x0000, mipi->sctl_base + SOFT_RESET);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700383
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800384 /* Turn on all DSI Clks */
385 writel((0 << 16) | 0x3f, mipi->sctl_base + CLK_CTRL);
386 writel(DMA_STREAM1 << 8 | 0x04, mipi->sctl_base + TRIG_CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700387
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800388 writel(0 << 30 | DLNx_EN << 4 | ctrl_mode, mipi->sctl_base + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700389 writel(broadcast << 31 | EMBED_MODE1 << 28 | POWER_MODE2 << 26
390 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800391 mipi->sctl_base + COMMAND_MODE_DMA_CTRL);
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700392
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800393 /* for 8939 hw dsi1 has Lane_map as 3210 */
Jeevan Shriram01379322015-01-07 17:41:26 -0800394 if (readl(mipi->ctl_base) == DSI_HW_REV_103_1)
Vineet Bajaj2f08a362014-07-24 20:50:42 +0530395 lane_swap_dsi1 = 0x7;
396 else
397 lane_swap_dsi1 = lane_swap;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800398 writel(lane_swap_dsi1, mipi->sctl_base + LANE_SWAP_CTL);
Padmanabhan Komandurubd8268a2018-04-30 17:05:56 +0530399 if (mipi->mdss_dsi_phy_db->pll_type != DSI_PLL_TYPE_12NM)
400 writel_relaxed(timing_ctl,
401 mipi->sctl_base + TIMING_CTL);
Ray Zhang8da5e5d2015-01-21 10:14:09 +0800402
Sandeep Pandad9cc3a92015-05-25 15:19:38 +0530403 if ((mipi->mode == DSI_CMD_MODE) &&
404 (readl(mipi->sctl_base) >= DSI_HW_REV_103)) {
405 uint32_t tmp;
406 tmp = readl(mipi->sctl_base + 0x01b8);
407 tmp |= BIT(16); /* enable burst mode */
408 writel(tmp, mipi->sctl_base + 0x01b8);
409 }
Padmanabhan Komandurucea96762016-03-30 14:49:01 +0530410
411 writel(((mipi->rx_eot_ignore & 0x1) << 4) |
412 (mipi->tx_eot_append & 0x1),
413 mipi->sctl_base + EOT_PACKET_CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700414 }
415
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800416 writel(0x0001, mipi->ctl_base + SOFT_RESET);
417 writel(0x0000, mipi->ctl_base + SOFT_RESET);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700418
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800419 /* Turn on all DSI Clks */
420 writel((0 << 16) | 0x3f, mipi->ctl_base + CLK_CTRL);
421 writel(DMA_STREAM1 << 8 | 0x04, mipi->ctl_base + TRIG_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700422
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800423 writel(0 << 30 | DLNx_EN << 4 | ctrl_mode, mipi->ctl_base + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700424 writel(broadcast << 31 | EMBED_MODE1 << 28 | POWER_MODE2 << 26
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700425 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800426 mipi->ctl_base + COMMAND_MODE_DMA_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700427
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800428 writel(lane_swap, mipi->ctl_base + LANE_SWAP_CTL);
Padmanabhan Komandurubd8268a2018-04-30 17:05:56 +0530429 if (mipi->mdss_dsi_phy_db->pll_type != DSI_PLL_TYPE_12NM)
430 writel_relaxed(timing_ctl, mipi->ctl_base + TIMING_CTL);
Ray Zhang8da5e5d2015-01-21 10:14:09 +0800431
Sandeep Pandad9cc3a92015-05-25 15:19:38 +0530432 if ((mipi->mode == DSI_CMD_MODE) &&
433 (readl(mipi->ctl_base) >= DSI_HW_REV_103)) {
434 uint32_t tmp;
435 tmp = readl(mipi->ctl_base + 0x01b8);
436 tmp |= BIT(16); /* enable burst mode */
437 writel(tmp, mipi->ctl_base + 0x01b8);
438 }
439
Padmanabhan Komandurucea96762016-03-30 14:49:01 +0530440 writel(((mipi->rx_eot_ignore & 0x1) << 4) | (mipi->tx_eot_append & 0x1),
441 mipi->ctl_base + EOT_PACKET_CTRL);
Huaibin Yang952dce32015-02-19 18:01:27 -0800442
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800443#endif
Siddhartha Agrawal2679a822013-05-31 19:15:12 -0700444
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800445 return 0;
446}
447
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530448void mdss_dsi_panel_shutdown(struct msm_panel_info *pinfo)
449{
450#if (DISPLAY_TYPE_MDSS == 1)
451 unsigned long read_val = 0;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800452 uint32_t ctl_base = pinfo->mipi.ctl_base;
453 uint32_t sctl_base = pinfo->mipi.sctl_base;
454
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530455 if (pinfo->mipi.panel_off_cmds) {
456 /*
457 * Once MDP TG is disabled, reset of DSI controller is
458 * needed before we send panel OFF commands.
459 */
460 if (pinfo->type == MIPI_VIDEO_PANEL) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800461 read_val = readl(ctl_base + CTRL);
462 writel((read_val & ~BIT(0)), ctl_base + CTRL);
463 writel(0x0001, ctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530464 dsb();
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800465 writel(0x0000, ctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530466 dsb();
467 /* Enable cmd mode only */
468 writel(((read_val & ~BIT(1)) | BIT(2)),
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800469 ctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530470 }
471
472 if (pinfo->mipi.broadcast) {
473 if (pinfo->type == MIPI_VIDEO_PANEL) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800474 read_val = readl(sctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530475 writel((read_val & ~BIT(0)),
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800476 sctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530477
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800478 writel(0x0001, sctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530479 dsb();
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800480 writel(0x0000, sctl_base + SOFT_RESET);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530481 dsb();
482
483 writel(((read_val & ~BIT(1)) | BIT(2)),
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800484 sctl_base + CTRL);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530485 }
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530486 }
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800487 mdss_dsi_cmds_tx(&pinfo->mipi, pinfo->mipi.panel_off_cmds,
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800488 pinfo->mipi.num_of_panel_off_cmds,
489 pinfo->mipi.broadcast);
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530490 }
491#endif
492}
493
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800494int mdss_dsi_panel_initialize(struct mipi_panel_info *mipi, uint32_t
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800495 broadcast)
496{
497 int status = 0;
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700498 uint32_t ctrl_mode = 0;
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800499
500#if (DISPLAY_TYPE_MDSS == 1)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800501 if (!mipi->panel_on_cmds)
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800502 goto end;
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700503
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800504 ctrl_mode = readl(mipi->ctl_base + CTRL);
Siddhartha Agrawal980b5ee2013-05-30 12:17:50 -0700505
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800506 /* Enable command mode before sending the commands. */
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800507 writel(ctrl_mode | 0x04, mipi->ctl_base + CTRL);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800508 if (broadcast)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800509 writel(ctrl_mode | 0x04, mipi->sctl_base + CTRL);
510 status = mdss_dsi_cmds_tx(mipi, mipi->panel_on_cmds,
511 mipi->num_of_panel_on_cmds, broadcast);
512 writel(ctrl_mode, mipi->ctl_base + CTRL);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800513 if (broadcast)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800514 writel(ctrl_mode, mipi->sctl_base + CTRL);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800515
516 if (!broadcast && !status && target_panel_auto_detect_enabled())
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800517 status = mdss_dsi_read_panel_signature(mipi);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800518
519end:
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400520#endif
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700521 return status;
522}
523
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700524int mdss_dsi_video_mode_config(struct msm_panel_info *pinfo,
525 uint16_t disp_width,
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700526 uint16_t disp_height,
527 uint16_t img_width,
528 uint16_t img_height,
529 uint16_t hsync_porch0_fp,
530 uint16_t hsync_porch0_bp,
531 uint16_t vsync_porch0_fp,
532 uint16_t vsync_porch0_bp,
533 uint16_t hsync_width,
534 uint16_t vsync_width,
535 uint16_t dst_format,
536 uint16_t traffic_mode,
537 uint8_t lane_en,
Padmanabhan Komandurue3209872015-01-12 16:33:16 +0530538 uint8_t pulse_mode_hsa_he,
539 uint32_t low_pwr_stop_mode,
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700540 uint8_t eof_bllp_pwr,
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700541 uint8_t interleav,
542 uint32_t ctl_base)
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700543{
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700544 int status = 0;
545
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400546#if (DISPLAY_TYPE_MDSS == 1)
Padmanabhan Komanduru684b58f2015-02-11 16:22:51 +0530547 int last_line_interleave_en = 0;
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700548 struct dsc_desc *dsc = NULL;
549
550 if (pinfo->compression_mode == COMPRESSION_DSC)
551 dsc = &pinfo->dsc;
Padmanabhan Komanduru684b58f2015-02-11 16:22:51 +0530552
553 /*Check if EOF_BLLP_PWR_MODE bit is set*/
554 if(eof_bllp_pwr & 0x8)
555 last_line_interleave_en = 1;
556
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700557 writel(0x00000000, ctl_base + CLK_CTRL);
558 writel(0x00000002, ctl_base + CLK_CTRL);
559 writel(0x00000006, ctl_base + CLK_CTRL);
560 writel(0x0000000e, ctl_base + CLK_CTRL);
561 writel(0x0000001e, ctl_base + CLK_CTRL);
562 writel(0x0000023f, ctl_base + CLK_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700563
Padmanabhan Komanduru2f8e0bc2014-11-27 18:25:36 +0530564 writel(0x03f03fe0, ctl_base + ERR_INT_MASK0);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700565
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700566 writel(0x02020202, ctl_base + INT_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700567
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530568 /* For 8916/8939, enable DSI timing double buffering */
Kuogee Hsieh861e25d2014-10-29 16:50:15 -0700569 if (readl(ctl_base) >= DSI_HW_REV_103 &&
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530570 mdp_get_revision() != MDP_REV_305)
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530571 writel(0x1, ctl_base + TIMING_DB_MODE);
572
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700573 writel(((disp_width + hsync_porch0_bp) << 16) | hsync_porch0_bp,
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700574 ctl_base + VIDEO_MODE_ACTIVE_H);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700575
576 writel(((disp_height + vsync_porch0_bp) << 16) | (vsync_porch0_bp),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700577 ctl_base + VIDEO_MODE_ACTIVE_V);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700578
Terence Hampson7385f6a2013-08-16 15:31:25 -0400579 if (mdp_get_revision() >= MDP_REV_41 ||
Shivaraj Shettyf9e10c42014-09-17 04:21:15 +0530580 mdp_get_revision() == MDP_REV_304 ||
581 mdp_get_revision() == MDP_REV_305) {
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700582 writel(((disp_height + vsync_porch0_fp
583 + vsync_porch0_bp - 1) << 16)
584 | (disp_width + hsync_porch0_fp
585 + hsync_porch0_bp - 1),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700586 ctl_base + VIDEO_MODE_TOTAL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700587 } else {
588 writel(((disp_height + vsync_porch0_fp
589 + vsync_porch0_bp) << 16)
590 | (disp_width + hsync_porch0_fp
591 + hsync_porch0_bp),
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700592 ctl_base + VIDEO_MODE_TOTAL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700593 }
594
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700595 writel((hsync_width << 16) | 0, ctl_base + VIDEO_MODE_HSYNC);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700596
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700597 writel(0 << 16 | 0, ctl_base + VIDEO_MODE_VSYNC);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700598
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700599 writel(vsync_width << 16 | 0, ctl_base + VIDEO_MODE_VSYNC_VPOS);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700600
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530601 /* For 8916/8939, flush the DSI timing registers */
Kuogee Hsieh861e25d2014-10-29 16:50:15 -0700602 if (readl(ctl_base) >= DSI_HW_REV_103 &&
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530603 mdp_get_revision() != MDP_REV_305)
Padmanabhan Komandurudaebf6b2014-08-20 20:39:40 +0530604 writel(0x1, ctl_base + TIMING_FLUSH);
605
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700606 writel(0x00000100, ctl_base + MISR_VIDEO_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700607
Shivaraj Shetty41d2d482014-11-04 16:07:32 +0530608 if (mdp_get_revision() >= MDP_REV_41 || mdp_get_revision() == MDP_REV_305) {
Padmanabhan Komanduru684b58f2015-02-11 16:22:51 +0530609 writel(last_line_interleave_en << 31 | pulse_mode_hsa_he << 28 |
610 low_pwr_stop_mode << 16 | eof_bllp_pwr << 12 |
611 traffic_mode << 8 | dst_format << 4 | 0x0,
612 ctl_base + VIDEO_MODE_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700613 } else {
614 writel(1 << 28 | 1 << 24 | 1 << 20 | low_pwr_stop_mode << 16 |
615 eof_bllp_pwr << 12 | traffic_mode << 8
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700616 | dst_format << 4 | 0x0, ctl_base + VIDEO_MODE_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700617 }
618
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700619 writel(0x3fd08, ctl_base + HS_TIMER_CTRL);
620 writel(0x00010100, ctl_base + MISR_VIDEO_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700621
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700622 writel(0x00010100, ctl_base + INT_CTRL);
623 writel(0x02010202, ctl_base + INT_CTRL);
624 writel(0x02030303, ctl_base + INT_CTRL);
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700625
626 writel(interleav << 30 | 0 << 24 | 0 << 20 | lane_en << 4
Siddhartha Agrawal6e760042013-05-30 21:10:18 -0700627 | 0x103, ctl_base + CTRL);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700628 if (dsc) {
629 if (dsc->dsi_dsc_config)
630 dsc->dsi_dsc_config(pinfo->mipi.ctl_base, DSI_VIDEO_MODE, dsc);
631 }
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400632#endif
Siddhartha Agrawal06bb82f2013-05-24 12:32:33 -0700633
634 return status;
635}
636
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800637int mdss_dsi_config(struct msm_fb_panel_data *panel)
638{
639 int ret = NO_ERROR;
640 struct msm_panel_info *pinfo;
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800641 struct mipi_panel_info *mipi;
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700642 struct dsc_desc *dsc = NULL;
643 struct mipi_dsi_cmd cmd;
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800644
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400645#if (DISPLAY_TYPE_MDSS == 1)
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800646 if (!panel)
647 return ERR_INVALID_ARGS;
648
649 pinfo = &(panel->panel_info);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800650 mipi = &(pinfo->mipi);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800651
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700652
653 if (pinfo->compression_mode == COMPRESSION_DSC) {
654 dsc = &pinfo->dsc;
655 if (dsc) {
656 if (dsc->dsc2buf)
657 dsc->dsc2buf(pinfo);
658 }
659 }
660
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800661 dprintf(SPEW, "ctl_base=0x%08x, phy_base=0x%08x\n", mipi->ctl_base,
662 mipi->phy_base);
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800663
Jeevan Shriram01379322015-01-07 17:41:26 -0800664 mdss_dsi_phy_init(mipi);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800665
666 ret = mdss_dsi_host_init(mipi, mipi->dual_dsi,
667 mipi->broadcast);
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800668 if (ret) {
669 dprintf(CRITICAL, "dsi host init error\n");
670 goto error;
671 }
672
Aravind Venkateswaran51e57552014-12-09 13:23:19 -0800673 mdss_dsi_phy_contention_detection(mipi, mipi->phy_base);
674 if (mipi->dual_dsi)
675 mdss_dsi_phy_contention_detection(mipi, mipi->sphy_base);
Xiaoming Zhou03fd48b2014-07-31 15:24:41 -0400676
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800677 if (panel->pre_init_func) {
678 ret = panel->pre_init_func();
679 if (ret) {
680 dprintf(CRITICAL, "pre_init_func error\n");
681 goto error;
682 }
683 }
684
Veera Sundaram Sankaran9439eb12016-06-13 13:53:56 -0700685 if (mipi->force_clk_lane_hs)
686 mdss_dsi_force_clk_lane_hs(mipi, mipi->dual_dsi);
687
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800688 if (!mipi->cmds_post_tg) {
689 ret = mdss_dsi_panel_initialize(mipi, mipi->broadcast);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700690 if (ret) {
691 dprintf(CRITICAL, "dsi panel init error\n");
692 goto error;
693 }
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800694 }
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800695
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700696 if (dsc) {
697 cmd.size = DCS_HDR_LEN + DSC_PPS_LEN;
698 cmd.payload = dsc->pps_buf;
699 cmd.wait = 0x10;
700 mdss_dsi_cmds_tx(mipi, &cmd, 1, mipi->broadcast);
701 }
702
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800703 if (pinfo->rotate && panel->rotate)
704 pinfo->rotate();
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400705#endif
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800706
Ray Zhang4c7e37f2013-12-03 17:04:55 +0800707error:
Siddhartha Agrawal3e694ea2013-01-23 17:01:31 -0800708 return ret;
709}
710
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700711int mdss_dsi_post_on(struct msm_fb_panel_data *panel)
712{
713 int ret = 0;
714 struct msm_panel_info *pinfo = &(panel->panel_info);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700715
716 if (pinfo->mipi.cmds_post_tg) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800717 ret = mdss_dsi_panel_initialize(&pinfo->mipi, pinfo->mipi.broadcast);
Siddhartha Agrawal007ea9e2014-10-14 15:02:48 -0700718 if (ret) {
719 dprintf(CRITICAL, "dsi panel init error\n");
720 }
721 }
722 return ret;
723}
724
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700725int mdss_dsi_cmd_mode_config(struct msm_panel_info *pinfo,
726 uint16_t disp_width,
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700727 uint16_t disp_height,
728 uint16_t img_width,
729 uint16_t img_height,
730 uint16_t dst_format,
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400731 uint8_t ystride,
732 uint8_t lane_en,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800733 uint8_t interleav,
734 uint32_t ctl_base)
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700735{
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400736 uint16_t dst_fmt = 0;
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700737 struct dsc_desc *dsc = NULL;
738 unsigned int data;
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400739
740 switch (dst_format) {
741 case DSI_VIDEO_DST_FORMAT_RGB565:
742 dst_fmt = DSI_CMD_DST_FORMAT_RGB565;
743 break;
744 case DSI_VIDEO_DST_FORMAT_RGB666:
745 case DSI_VIDEO_DST_FORMAT_RGB666_LOOSE:
746 dst_fmt = DSI_CMD_DST_FORMAT_RGB666;
747 break;
748 case DSI_VIDEO_DST_FORMAT_RGB888:
749 dst_fmt = DSI_CMD_DST_FORMAT_RGB888;
750 break;
751 default:
752 dprintf(CRITICAL, "unsupported dst format\n");
753 return ERROR;
754 }
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700755
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400756#if (DISPLAY_TYPE_MDSS == 1)
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800757 writel(0x00000000, ctl_base + CLK_CTRL);
758 writel(0x00000000, ctl_base + CLK_CTRL);
759 writel(0x00000000, ctl_base + CLK_CTRL);
760 writel(0x00000000, ctl_base + CLK_CTRL);
761 writel(0x00000002, ctl_base + CLK_CTRL);
762 writel(0x00000006, ctl_base + CLK_CTRL);
763 writel(0x0000000e, ctl_base + CLK_CTRL);
764 writel(0x0000001e, ctl_base + CLK_CTRL);
765 writel(0x0000023f, ctl_base + CLK_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700766
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800767 writel(0, ctl_base + CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700768
Padmanabhan Komanduru2f8e0bc2014-11-27 18:25:36 +0530769 writel(0x03f03fe0, ctl_base + ERR_INT_MASK0);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700770
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800771 writel(0x02020202, ctl_base + INT_CTRL);
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700772
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800773 writel(dst_fmt, ctl_base + COMMAND_MODE_MDP_CTRL);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700774
775 if (pinfo->compression_mode == COMPRESSION_DSC)
776 dsc = &pinfo->dsc;
777
778 if (dsc) {
779 data = dsc->bytes_per_pkt;
780 if (pinfo->mipi.insert_dcs_cmd)
781 data++;
782 data <<= 16;
783 data |= 0x039;
784 writel(data, ctl_base + COMMAND_MODE_MDP_STREAM0_CTRL);
785 writel(data, ctl_base + COMMAND_MODE_MDP_STREAM1_CTRL);
786 data = dsc->pic_height << 16;
787 data |= dsc->pclk_per_line;
788 writel(data, ctl_base + COMMAND_MODE_MDP_STREAM0_TOTAL);
789 writel(data, ctl_base + COMMAND_MODE_MDP_STREAM1_TOTAL);
790
791 if (dsc->dsi_dsc_config)
Kuogee Hsieh6a8802f2015-09-01 09:11:40 -0700792 dsc->dsi_dsc_config(pinfo->mipi.ctl_base, DSI_CMD_MODE, dsc);
Kuogee Hsiehd58c8092015-07-07 10:31:34 -0700793 } else {
794
795 writel((img_width * ystride + 1) << 16 | 0x0039,
796 ctl_base + COMMAND_MODE_MDP_STREAM0_CTRL);
797 writel((img_width * ystride + 1) << 16 | 0x0039,
798 ctl_base + COMMAND_MODE_MDP_STREAM1_CTRL);
799 writel(img_height << 16 | img_width,
800 ctl_base + COMMAND_MODE_MDP_STREAM0_TOTAL);
801 writel(img_height << 16 | img_width,
802 ctl_base + COMMAND_MODE_MDP_STREAM1_TOTAL);
803 }
804
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800805 writel(0x13c2c, ctl_base + COMMAND_MODE_MDP_DCS_CMD_CTRL);
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400806 writel(interleav << 30 | 0 << 24 | 0 << 20 | lane_en << 4 | 0x105,
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800807 ctl_base + CTRL);
Padmanabhan Komanduru7860be52014-03-18 19:07:36 +0530808 writel(0x14000000, ctl_base + COMMAND_MODE_DMA_CTRL);
Dhaval Patel5b22fe72014-01-02 16:28:38 -0800809 writel(0x10000000, ctl_base + MISR_CMD_CTRL);
Terence Hampsoncc3345c2013-06-27 15:30:10 -0400810#endif
Xiaoming Zhou8d534dd2013-07-29 15:49:19 -0400811 return 0;
Siddhartha Agrawal7317e482013-04-21 16:16:57 -0700812}
813
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800814int mipi_dsi_on(struct msm_panel_info *pinfo)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700815{
816 int ret = NO_ERROR;
817 unsigned long ReadValue;
818 unsigned long count = 0;
819
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800820 ReadValue = readl(pinfo->mipi.ctl_base + INT_CTRL) & 0x00010000;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700821
822 mdelay(10);
823
824 while (ReadValue != 0x00010000) {
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800825 ReadValue = readl(pinfo->mipi.ctl_base + INT_CTRL) & 0x00010000;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700826 count++;
827 if (count > 0xffff) {
828 dprintf(CRITICAL, "Video lane test failed\n");
829 return ERROR;
830 }
831 }
832
Amir Samuelov2d4ba162012-07-22 11:53:14 +0300833 dprintf(INFO, "Video lane tested successfully\n");
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700834 return ret;
835}
836
Siddhartha Agrawal24d81b52013-07-01 11:13:32 -0700837int mipi_dsi_off(struct msm_panel_info *pinfo)
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700838{
Amol Jadi6834f1a2012-06-29 14:42:59 -0700839 if(!target_cont_splash_screen())
840 {
Padmanabhan Komanduruf8986be2014-11-04 15:57:19 +0530841 mdss_dsi_panel_shutdown(pinfo);
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800842 writel(0, pinfo->mipi.ctl_base + CLK_CTRL);
Naseer Ahmedd2f6de32015-11-27 11:13:09 -0500843 writel(0, pinfo->mipi.ctl_base + CTRL);
Siddhartha Agrawale0033a12013-02-23 15:37:42 -0800844 }
845
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800846 writel(0x1115501, pinfo->mipi.ctl_base + INT_CTRL);
feifanz87f19852015-09-25 11:54:26 +0800847 if (pinfo->mipi.dual_dsi)
Aravind Venkateswaranfec354c2014-12-04 18:10:14 -0800848 writel(0x1115501, pinfo->mipi.sctl_base + INT_CTRL);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700849
850 return NO_ERROR;
851}
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530852
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800853#if (DISPLAY_TYPE_MDSS == 0)
854static int dsi_cmd_dma_trigger_for_panel()
855{
856 unsigned long ReadValue;
857 unsigned long count = 0;
858 int status = 0;
859
860 writel(0x03030303, DSI_INT_CTRL);
861 writel(0x1, DSI_CMD_MODE_DMA_SW_TRIGGER);
862 dsb();
863 ReadValue = readl(DSI_INT_CTRL) & 0x00000001;
864 while (ReadValue != 0x00000001) {
865 ReadValue = readl(DSI_INT_CTRL) & 0x00000001;
866 count++;
867 if (count > 0xffff) {
868 status = FAIL;
869 dprintf(CRITICAL,
870 "Panel CMD: command mode dma test failed\n");
871 return status;
872 }
873 }
874
875 writel((readl(DSI_INT_CTRL) | 0x01000001), DSI_INT_CTRL);
876 dprintf(SPEW, "Panel CMD: command mode dma tested successfully\n");
877 return status;
878}
879
880int mipi_dsi_cmds_tx(struct mipi_dsi_cmd *cmds, int count)
881{
882 int ret = 0;
883 struct mipi_dsi_cmd *cm;
884 int i = 0;
885 char pload[256];
886 uint32_t off;
887
888 /* Align pload at 8 byte boundry */
889 off = pload;
890 off &= 0x07;
891 if (off)
892 off = 8 - off;
893 off += pload;
894
895 cm = cmds;
896 for (i = 0; i < count; i++) {
897 /* Wait for VIDEO_MODE_DONE */
898 ret = mdss_dsi_wait4_video_done();
899 if (ret)
900 goto mipi_cmds_error;
901
902 memcpy((void *)off, (cm->payload), cm->size);
Matthew Qin81933ce2015-02-03 17:58:52 +0800903 arch_clean_invalidate_cache_range((addr_t)(off), size);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -0800904 writel(off, DSI_DMA_CMD_OFFSET);
905 writel(cm->size, DSI_DMA_CMD_LENGTH); // reg 0x48 for this build
906 dsb();
907 ret += dsi_cmd_dma_trigger_for_panel();
908 dsb();
909 if (cm->wait)
910 mdelay(cm->wait);
911 else
912 udelay(80);
913 cm++;
914 }
915mipi_cmds_error:
916 return ret;
917}
918
919/*
920 * mipi_dsi_cmd_rx: can receive at most 16 bytes
921 * per transaction since it only have 4 32bits reigsters
922 * to hold data.
923 * therefore Maximum Return Packet Size need to be set to 16.
924 * any return data more than MRPS need to be break down
925 * to multiple transactions.
926 */
927int mipi_dsi_cmds_rx(char **rp, int len)
928{
929 uint32_t *lp, data;
930 char *dp;
931 int i, off, cnt;
932 int rlen, res;
933
934 if (len <= 2)
935 rlen = 4; /* short read */
936 else
937 rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */
938
939 if (rlen > MIPI_DSI_REG_LEN) {
940 return 0;
941 }
942
943 res = rlen & 0x03;
944
945 rlen += res; /* 4 byte align */
946 lp = (uint32_t *) (*rp);
947
948 cnt = rlen;
949 cnt += 3;
950 cnt >>= 2;
951
952 if (cnt > 4)
953 cnt = 4; /* 4 x 32 bits registers only */
954
955 off = 0x068; /* DSI_RDBK_DATA0 */
956 off += ((cnt - 1) * 4);
957
958 for (i = 0; i < cnt; i++) {
959 data = (uint32_t) readl(MIPI_DSI_BASE + off);
960 *lp++ = ntohl(data); /* to network byte order */
961 off -= 4;
962 }
963
964 if (len > 2) {
965 /*First 4 bytes + paded bytes will be header next len bytes would be payload */
966 for (i = 0; i < len; i++) {
967 dp = *rp;
968 dp[i] = dp[4 + res + i];
969 }
970 }
971
972 return len;
973}
974
975static int mipi_dsi_panel_initialize(struct mipi_dsi_panel_config *pinfo)
976{
977 uint8_t DMA_STREAM1 = 0; // for mdp display processor path
978 uint8_t EMBED_MODE1 = 1; // from frame buffer
979 uint8_t POWER_MODE2 = 1; // from frame buffer
980 uint8_t PACK_TYPE1; // long packet
981 uint8_t VC1 = 0;
982 uint8_t DT1 = 0; // non embedded mode
983 uint8_t WC1 = 0; // for non embedded mode only
984 int status = 0;
985 uint8_t DLNx_EN;
986
987 switch (pinfo->num_of_lanes) {
988 default:
989 case 1:
990 DLNx_EN = 1; // 1 lane
991 break;
992 case 2:
993 DLNx_EN = 3; // 2 lane
994 break;
995 case 3:
996 DLNx_EN = 7; // 3 lane
997 break;
998 case 4:
999 DLNx_EN = 0x0F; /* 4 lanes */
1000 break;
1001 }
1002
1003 PACK_TYPE1 = pinfo->pack;
1004
1005 writel(0x0001, DSI_SOFT_RESET);
1006 writel(0x0000, DSI_SOFT_RESET);
1007
1008 writel((0 << 16) | 0x3f, DSI_CLK_CTRL); /* Turn on all DSI Clks */
1009 writel(DMA_STREAM1 << 8 | 0x04, DSI_TRIG_CTRL); // reg 0x80 dma trigger: sw
1010 // trigger 0x4; dma stream1
1011
1012 writel(0 << 30 | DLNx_EN << 4 | 0x105, DSI_CTRL); // reg 0x00 for this
1013 // build
1014 writel(EMBED_MODE1 << 28 | POWER_MODE2 << 26
1015 | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1,
1016 DSI_COMMAND_MODE_DMA_CTRL);
1017
1018 if (pinfo->panel_on_cmds)
1019 status = mipi_dsi_cmds_tx(pinfo->panel_on_cmds,
1020 pinfo->num_of_panel_on_cmds);
1021
1022 return status;
1023}
1024#endif
1025
1026void mipi_dsi_shutdown(void)
1027{
1028#if (DISPLAY_TYPE_MDSS == 0)
1029 if(!target_cont_splash_screen())
1030 {
1031 mdp_shutdown();
1032 writel(0x01010101, DSI_INT_CTRL);
1033 writel(0x13FF3BFF, DSI_ERR_INT_MASK0);
1034
1035 writel(0, DSI_CLK_CTRL);
1036 writel(0, DSI_CTRL);
1037 writel(0, DSIPHY_PLL_CTRL(0));
1038 }
1039 else
1040 {
1041 /* To keep the splash screen displayed till kernel driver takes
1042 control, do not turn off the video mode engine and clocks.
1043 Only disabling the MIPI DSI IRQs */
1044 writel(0x01010101, DSI_INT_CTRL);
1045 writel(0x13FF3BFF, DSI_ERR_INT_MASK0);
1046 }
1047#endif
1048}
1049
Channagoud Kadabi10189fd2012-05-25 13:33:39 +05301050int mipi_cmd_trigger()
1051{
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -08001052#if (DISPLAY_TYPE_MDSS == 0)
Channagoud Kadabi10189fd2012-05-25 13:33:39 +05301053 writel(0x1, DSI_CMD_MODE_MDP_SW_TRIGGER);
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -08001054#endif
Channagoud Kadabi10189fd2012-05-25 13:33:39 +05301055 return NO_ERROR;
1056}
Aravind Venkateswarance4dd7f2014-12-04 16:54:26 -08001057
1058int mipi_config(struct msm_fb_panel_data *panel)
1059{
1060 int ret = NO_ERROR;
1061#if (DISPLAY_TYPE_MDSS == 0)
1062 struct msm_panel_info *pinfo;
1063 struct mipi_dsi_panel_config mipi_pinfo;
1064
1065 if (!panel)
1066 return ERR_INVALID_ARGS;
1067
1068 pinfo = &(panel->panel_info);
1069 mipi_pinfo.mode = pinfo->mipi.mode;
1070 mipi_pinfo.num_of_lanes = pinfo->mipi.num_of_lanes;
1071 mipi_pinfo.dsi_phy_config = pinfo->mipi.dsi_phy_db;
1072 mipi_pinfo.panel_on_cmds = pinfo->mipi.panel_on_cmds;
1073 mipi_pinfo.num_of_panel_on_cmds = pinfo->mipi.num_of_panel_on_cmds;
1074 mipi_pinfo.lane_swap = pinfo->mipi.lane_swap;
1075 mipi_pinfo.pack = 1;
1076
1077 /* Enable MMSS_AHB_ARB_MATER_PORT_E for
1078 arbiter master0 and master 1 request */
1079#if (!DISPLAY_MIPI_PANEL_RENESAS && !DISPLAY_TYPE_DSI6G && !DISPLAY_TYPE_8610)
1080 writel(0x00001800, MMSS_SFPB_GPREG);
1081#endif
1082
1083 mipi_dsi_phy_init(&mipi_pinfo);
1084
1085 ret += mipi_dsi_panel_initialize(&mipi_pinfo);
1086
1087 if (pinfo->rotate && panel->rotate)
1088 pinfo->rotate();
1089#endif
1090 return ret;
1091}
Padmanabhan Komandurubd8268a2018-04-30 17:05:56 +05301092
1093void mdss_dsi_lane_config(struct msm_panel_info *pinfo)
1094{
1095 uint8_t lane_enable = 0;
1096
1097 if (pinfo->mipi.data_lane0)
1098 lane_enable |= (1 << 0);
1099 if (pinfo->mipi.data_lane1)
1100 lane_enable |= (1 << 1);
1101 if (pinfo->mipi.data_lane2)
1102 lane_enable |= (1 << 2);
1103 if (pinfo->mipi.data_lane3)
1104 lane_enable |= (1 << 3);
1105
1106 writel_relaxed((0 << 30 | 0 << 24 | 0 << 20 |
1107 lane_enable << 4 | 0x105), pinfo->mipi.ctl_base + CTRL);
1108 if (pinfo->mipi.dual_dsi)
1109 writel_relaxed((0 << 30 | 0 << 24 | 0 << 20 | lane_enable << 4 |
1110 0x105), pinfo->mipi.sctl_base + CTRL);
1111}