Veera Sundaram Sankaran | 9439eb1 | 2016-06-13 13:53:56 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010-2016, The Linux Foundation. All rights reserved. |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 2 | * |
| 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 Agrawal | 3e694ea | 2013-01-23 17:01:31 -0800 | [diff] [blame] | 12 | * * Neither the name of The Linux Foundation nor the names of its |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include <reg.h> |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 31 | #include <endian.h> |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 32 | #include <mipi_dsi.h> |
| 33 | #include <dev/fbcon.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 34 | #include <stdlib.h> |
Greg Grisco | 1073a5e | 2011-07-28 18:59:18 -0700 | [diff] [blame] | 35 | #include <string.h> |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 36 | #include <debug.h> |
Kinson Chik | fe93103 | 2011-07-21 10:01:34 -0700 | [diff] [blame] | 37 | #include <target/display.h> |
Veera Sundaram Sankaran | 602d95a | 2014-12-09 17:55:04 -0800 | [diff] [blame] | 38 | #include <mdp5.h> |
Kinson Chik | fe93103 | 2011-07-21 10:01:34 -0700 | [diff] [blame] | 39 | #include <platform/iomap.h> |
| 40 | #include <platform/clock.h> |
Greg Grisco | 1073a5e | 2011-07-28 18:59:18 -0700 | [diff] [blame] | 41 | #include <platform/timer.h> |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 42 | #include <err.h> |
| 43 | #include <msm_panel.h> |
Matthew Qin | 81933ce | 2015-02-03 17:58:52 +0800 | [diff] [blame] | 44 | #include <arch/ops.h> |
Kinson Chik | fe93103 | 2011-07-21 10:01:34 -0700 | [diff] [blame] | 45 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 46 | extern int mipi_dsi_cmd_config(struct fbcon_config mipi_fb_cfg, |
| 47 | unsigned short num_of_lanes); |
Kinson Chik | fe93103 | 2011-07-21 10:01:34 -0700 | [diff] [blame] | 48 | extern void mdp_shutdown(void); |
| 49 | extern void mdp_start_dma(void); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 50 | |
Siddhartha Agrawal | 1b2ed84 | 2013-05-29 18:02:28 -0700 | [diff] [blame] | 51 | #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 Sankaran | db0b2bf | 2014-12-16 18:09:27 -0800 | [diff] [blame] | 56 | struct fbcon_config mipi_fb_cfg = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 57 | .height = 0, |
| 58 | .width = 0, |
| 59 | .stride = 0, |
| 60 | .format = 0, |
| 61 | .bpp = 0, |
| 62 | .update_start = NULL, |
| 63 | .update_done = NULL, |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 64 | }; |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 65 | |
Veera Sundaram Sankaran | db0b2bf | 2014-12-16 18:09:27 -0800 | [diff] [blame] | 66 | static char read_id_a1h_cmd[4] = { 0xA1, 0x00, 0x06, 0xA0 }; /* DTYPE_DCS_READ */ |
| 67 | static struct mipi_dsi_cmd read_ddb_start_cmd = |
| 68 | {sizeof(read_id_a1h_cmd), read_id_a1h_cmd, 0x00}; |
| 69 | |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 70 | void secure_writel(uint32_t, uint32_t); |
| 71 | uint32_t secure_readl(uint32_t); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 72 | |
Shivaraj Shetty | 6460403 | 2013-11-14 16:44:10 +0530 | [diff] [blame] | 73 | static uint32_t response_value = 0; |
| 74 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 75 | static uint32_t mdss_dsi_read_panel_signature(struct mipi_panel_info *mipi) |
Shivaraj Shetty | 6460403 | 2013-11-14 16:44:10 +0530 | [diff] [blame] | 76 | { |
| 77 | uint32_t rec_buf[1]; |
| 78 | uint32_t *lp = rec_buf, data; |
Veera Sundaram Sankaran | db0b2bf | 2014-12-16 18:09:27 -0800 | [diff] [blame] | 79 | uint32_t ret = response_value; |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 80 | uint32_t panel_signature = mipi->signature; |
Shivaraj Shetty | 6460403 | 2013-11-14 16:44:10 +0530 | [diff] [blame] | 81 | |
| 82 | #if (DISPLAY_TYPE_MDSS == 1) |
| 83 | if (ret && ret != panel_signature) |
| 84 | goto exit_read_signature; |
| 85 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 86 | ret = mdss_dsi_cmds_tx(mipi, &read_ddb_start_cmd, 1, 0); |
Shivaraj Shetty | 6460403 | 2013-11-14 16:44:10 +0530 | [diff] [blame] | 87 | if (ret) |
| 88 | goto exit_read_signature; |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 89 | if (!mdss_dsi_cmds_rx(mipi, &lp, 1, 1)) |
Shivaraj Shetty | 6460403 | 2013-11-14 16:44:10 +0530 | [diff] [blame] | 90 | 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 | |
| 98 | exit_read_signature: |
| 99 | /* Keep the non detectable panel at the end and set panel signature 0xFFFF */ |
Vineet Bajaj | c0d150d | 2014-11-07 17:04:44 +0530 | [diff] [blame] | 100 | if ((panel_signature == 0) || (panel_signature == 0xFFFF)) |
Shivaraj Shetty | 6460403 | 2013-11-14 16:44:10 +0530 | [diff] [blame] | 101 | ret = 0; |
| 102 | #endif |
| 103 | return ret; |
| 104 | } |
| 105 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 106 | static int mdss_dsi_cmd_dma_trigger_for_panel(char dual_dsi, |
| 107 | uint32_t ctl_base, uint32_t sctl_base) |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 108 | { |
| 109 | uint32_t ReadValue; |
| 110 | uint32_t count = 0; |
| 111 | int status = 0; |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 112 | uint32_t base = dual_dsi ? sctl_base : ctl_base; |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 113 | |
Terence Hampson | cc3345c | 2013-06-27 15:30:10 -0400 | [diff] [blame] | 114 | #if (DISPLAY_TYPE_MDSS == 1) |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 115 | writel(0x03030303, ctl_base + INT_CTRL); |
| 116 | writel(0x1, ctl_base + CMD_MODE_DMA_SW_TRIGGER); |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 117 | dsb(); |
| 118 | |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 119 | if (dual_dsi) { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 120 | writel(0x03030303, sctl_base + INT_CTRL); |
| 121 | writel(0x1, sctl_base + CMD_MODE_DMA_SW_TRIGGER); |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 122 | dsb(); |
| 123 | } |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 124 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 125 | ReadValue = readl(base + INT_CTRL) & 0x00000001; |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 126 | while (ReadValue != 0x00000001) { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 127 | ReadValue = readl(base + INT_CTRL) & 0x00000001; |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 128 | 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 Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 137 | writel((readl(base + INT_CTRL) | 0x01000001), base + INT_CTRL); |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 138 | dprintf(SPEW, "Panel CMD: command mode dma tested successfully\n"); |
Terence Hampson | cc3345c | 2013-06-27 15:30:10 -0400 | [diff] [blame] | 139 | #endif |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 140 | return status; |
| 141 | } |
| 142 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 143 | static int mdss_dsi_wait4_video_done(uint32_t ctl_base) |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 144 | { |
| 145 | unsigned long read; |
| 146 | unsigned long count = 0; |
| 147 | int status = 0; |
| 148 | |
Padmanabhan Komanduru | 66459a9 | 2014-11-04 00:05:08 +0530 | [diff] [blame] | 149 | /* If video mode is not enabled, return here */ |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 150 | if ((readl(ctl_base + CTRL) & BIT(1)) == 0) |
Padmanabhan Komanduru | 66459a9 | 2014-11-04 00:05:08 +0530 | [diff] [blame] | 151 | return 0; |
| 152 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 153 | read = readl(ctl_base + INT_CTRL); |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 154 | /* Enable VIDEO MODE DONE MASK and clear the interrupt */ |
| 155 | read = read | DSI_VIDEO_MODE_DONE_MASK | DSI_VIDEO_MODE_DONE_AK; |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 156 | writel(read, ctl_base + INT_CTRL); |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 157 | dsb(); |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 158 | do { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 159 | read = readl(ctl_base + INT_CTRL) & |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 160 | DSI_VIDEO_MODE_DONE_STAT; |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 161 | 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 Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 168 | } while (!read); |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 169 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 170 | writel((readl(ctl_base + INT_CTRL) | 0x01000001), ctl_base + INT_CTRL); |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 171 | dprintf(SPEW, "Panel wait_4_video_done: Recieved video mode done ack\n"); |
Padmanabhan Komanduru | 66459a9 | 2014-11-04 00:05:08 +0530 | [diff] [blame] | 172 | |
| 173 | /* Skip BLLP 4ms */ |
| 174 | mdelay(4); |
| 175 | |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 176 | return status; |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 179 | int mdss_dsi_cmds_tx(struct mipi_panel_info *mipi, |
| 180 | struct mipi_dsi_cmd *cmds, int count, char dual_dsi) |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 181 | { |
| 182 | int ret = 0; |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 183 | #if (DISPLAY_TYPE_MDSS == 1) |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 184 | struct mipi_dsi_cmd *cm; |
| 185 | int i = 0; |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 186 | uint8_t pload[256]; |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 187 | uint32_t off; |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 188 | uint32_t size; |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 189 | 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 Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 199 | |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 200 | /* Align pload at 8 byte boundary */ |
| 201 | off = (uint32_t) pload; |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 202 | off &= 0x07; |
| 203 | if (off) |
| 204 | off = 8 - off; |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 205 | off += (uint32_t) pload; |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 206 | |
| 207 | cm = cmds; |
| 208 | for (i = 0; i < count; i++) { |
Padmanabhan Komanduru | 66459a9 | 2014-11-04 00:05:08 +0530 | [diff] [blame] | 209 | /* Wait for VIDEO_MODE_DONE */ |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 210 | ret = mdss_dsi_wait4_video_done(ctl_base); |
Padmanabhan Komanduru | 66459a9 | 2014-11-04 00:05:08 +0530 | [diff] [blame] | 211 | if (ret) |
| 212 | goto wait4video_error; |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 213 | |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 214 | /* 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 Qin | 81933ce | 2015-02-03 17:58:52 +0800 | [diff] [blame] | 221 | arch_clean_invalidate_cache_range((addr_t)(off), size); |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 222 | writel(off, ctl_base + DMA_CMD_OFFSET); |
| 223 | writel(size, ctl_base + DMA_CMD_LENGTH); |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 224 | if (dual_dsi) { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 225 | writel(off, sctl_base + DMA_CMD_OFFSET); |
| 226 | writel(size, sctl_base + DMA_CMD_LENGTH); |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 227 | } |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 228 | dsb(); |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 229 | ret += mdss_dsi_cmd_dma_trigger_for_panel(dual_dsi, ctl_base, |
| 230 | sctl_base); |
Dhaval Patel | 607a624 | 2013-10-29 12:37:24 -0700 | [diff] [blame] | 231 | if (cm->wait) |
| 232 | mdelay(cm->wait); |
| 233 | else |
| 234 | udelay(80); |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 235 | cm++; |
| 236 | } |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 237 | wait4video_error: |
Padmanabhan Komanduru | 66459a9 | 2014-11-04 00:05:08 +0530 | [diff] [blame] | 238 | #endif |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 239 | return ret; |
| 240 | } |
| 241 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 242 | int mdss_dsi_cmds_rx(struct mipi_panel_info *mipi, uint32_t **rp, int rp_len, |
| 243 | int rdbk_len) |
Casey Piper | 8403675 | 2013-09-05 14:56:37 -0700 | [diff] [blame] | 244 | { |
| 245 | uint32_t *lp, data; |
Veera Sundaram Sankaran | db0b2bf | 2014-12-16 18:09:27 -0800 | [diff] [blame] | 246 | uint32_t *dp; |
Casey Piper | 8403675 | 2013-09-05 14:56:37 -0700 | [diff] [blame] | 247 | int i, off; |
| 248 | int rlen, res; |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 249 | 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 Piper | 8403675 | 2013-09-05 14:56:37 -0700 | [diff] [blame] | 256 | |
| 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 Shetty | 3c77da6 | 2013-12-09 15:58:16 +0530 | [diff] [blame] | 281 | off = RDBK_DATA0; |
Casey Piper | 8403675 | 2013-09-05 14:56:37 -0700 | [diff] [blame] | 282 | off += ((rlen - 1) * 4); |
| 283 | |
| 284 | for (i = 0; i < rlen; i++) { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 285 | data = readl(ctl_base + off); |
Casey Piper | 8403675 | 2013-09-05 14:56:37 -0700 | [diff] [blame] | 286 | *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 Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 302 | static int mdss_dsi_cmd_bta_sw_trigger(uint32_t ctl_base) |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 303 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 304 | uint32_t data; |
| 305 | int cnt = 0; |
| 306 | int err = 0; |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 307 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 308 | writel(0x01, ctl_base + 0x094); /* trigger */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 309 | while (cnt < 10000) { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 310 | data = readl(ctl_base + 0x0004); /*DSI_STATUS */ |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 311 | if ((data & 0x0010) == 0) |
| 312 | break; |
| 313 | cnt++; |
| 314 | } |
| 315 | if (cnt == 10000) |
| 316 | err = 1; |
| 317 | return err; |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Veera Sundaram Sankaran | 9439eb1 | 2016-06-13 13:53:56 -0700 | [diff] [blame] | 320 | static 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 Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 336 | int mdss_dsi_host_init(struct mipi_panel_info *mipi, uint32_t |
Dhaval Patel | 9207dec | 2014-04-16 10:45:32 -0700 | [diff] [blame] | 337 | dual_dsi, uint32_t broadcast) |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 338 | { |
| 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 Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 342 | uint8_t PACK_TYPE1 = 0; // long packet |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 343 | uint8_t VC1 = 0; |
| 344 | uint8_t DT1 = 0; // non embedded mode |
| 345 | uint8_t WC1 = 0; // for non embedded mode only |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 346 | uint8_t DLNx_EN; |
Siddhartha Agrawal | 2679a82 | 2013-05-31 19:15:12 -0700 | [diff] [blame] | 347 | uint8_t lane_swap = 0; |
Siddhartha Agrawal | b6c861f | 2013-05-31 19:36:44 -0700 | [diff] [blame] | 348 | uint32_t timing_ctl = 0; |
Vineet Bajaj | 2f08a36 | 2014-07-24 20:50:42 +0530 | [diff] [blame] | 349 | uint32_t lane_swap_dsi1 = 0; |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 350 | uint32_t ctrl_mode = 0x105; //Default is command mode to send cmds. |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 351 | |
Terence Hampson | cc3345c | 2013-06-27 15:30:10 -0400 | [diff] [blame] | 352 | #if (DISPLAY_TYPE_MDSS == 1) |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 353 | switch (mipi->num_of_lanes) { |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 354 | 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 Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 369 | lane_swap = mipi->lane_swap; |
| 370 | timing_ctl = ((mipi->t_clk_post << 8) | mipi->t_clk_pre); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 371 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 372 | if (mipi->cmds_post_tg) { |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 373 | /* |
| 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 Patel | 9207dec | 2014-04-16 10:45:32 -0700 | [diff] [blame] | 380 | if (dual_dsi) { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 381 | writel(0x0001, mipi->sctl_base + SOFT_RESET); |
| 382 | writel(0x0000, mipi->sctl_base + SOFT_RESET); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 383 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 384 | /* 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 Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 387 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 388 | writel(0 << 30 | DLNx_EN << 4 | ctrl_mode, mipi->sctl_base + CTRL); |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 389 | writel(broadcast << 31 | EMBED_MODE1 << 28 | POWER_MODE2 << 26 |
| 390 | | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1, |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 391 | mipi->sctl_base + COMMAND_MODE_DMA_CTRL); |
Siddhartha Agrawal | 2679a82 | 2013-05-31 19:15:12 -0700 | [diff] [blame] | 392 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 393 | /* for 8939 hw dsi1 has Lane_map as 3210 */ |
Jeevan Shriram | 0137932 | 2015-01-07 17:41:26 -0800 | [diff] [blame] | 394 | if (readl(mipi->ctl_base) == DSI_HW_REV_103_1) |
Vineet Bajaj | 2f08a36 | 2014-07-24 20:50:42 +0530 | [diff] [blame] | 395 | lane_swap_dsi1 = 0x7; |
| 396 | else |
| 397 | lane_swap_dsi1 = lane_swap; |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 398 | writel(lane_swap_dsi1, mipi->sctl_base + LANE_SWAP_CTL); |
| 399 | writel(timing_ctl, mipi->sctl_base + TIMING_CTL); |
Ray Zhang | 8da5e5d | 2015-01-21 10:14:09 +0800 | [diff] [blame] | 400 | |
Sandeep Panda | d9cc3a9 | 2015-05-25 15:19:38 +0530 | [diff] [blame] | 401 | if ((mipi->mode == DSI_CMD_MODE) && |
| 402 | (readl(mipi->sctl_base) >= DSI_HW_REV_103)) { |
| 403 | uint32_t tmp; |
| 404 | tmp = readl(mipi->sctl_base + 0x01b8); |
| 405 | tmp |= BIT(16); /* enable burst mode */ |
| 406 | writel(tmp, mipi->sctl_base + 0x01b8); |
| 407 | } |
Padmanabhan Komanduru | cea9676 | 2016-03-30 14:49:01 +0530 | [diff] [blame] | 408 | |
| 409 | writel(((mipi->rx_eot_ignore & 0x1) << 4) | |
| 410 | (mipi->tx_eot_append & 0x1), |
| 411 | mipi->sctl_base + EOT_PACKET_CTRL); |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 414 | writel(0x0001, mipi->ctl_base + SOFT_RESET); |
| 415 | writel(0x0000, mipi->ctl_base + SOFT_RESET); |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 416 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 417 | /* Turn on all DSI Clks */ |
| 418 | writel((0 << 16) | 0x3f, mipi->ctl_base + CLK_CTRL); |
| 419 | writel(DMA_STREAM1 << 8 | 0x04, mipi->ctl_base + TRIG_CTRL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 420 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 421 | writel(0 << 30 | DLNx_EN << 4 | ctrl_mode, mipi->ctl_base + CTRL); |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 422 | writel(broadcast << 31 | EMBED_MODE1 << 28 | POWER_MODE2 << 26 |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 423 | | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1, |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 424 | mipi->ctl_base + COMMAND_MODE_DMA_CTRL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 425 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 426 | writel(lane_swap, mipi->ctl_base + LANE_SWAP_CTL); |
| 427 | writel(timing_ctl, mipi->ctl_base + TIMING_CTL); |
Ray Zhang | 8da5e5d | 2015-01-21 10:14:09 +0800 | [diff] [blame] | 428 | |
Sandeep Panda | d9cc3a9 | 2015-05-25 15:19:38 +0530 | [diff] [blame] | 429 | if ((mipi->mode == DSI_CMD_MODE) && |
| 430 | (readl(mipi->ctl_base) >= DSI_HW_REV_103)) { |
| 431 | uint32_t tmp; |
| 432 | tmp = readl(mipi->ctl_base + 0x01b8); |
| 433 | tmp |= BIT(16); /* enable burst mode */ |
| 434 | writel(tmp, mipi->ctl_base + 0x01b8); |
| 435 | } |
| 436 | |
Padmanabhan Komanduru | cea9676 | 2016-03-30 14:49:01 +0530 | [diff] [blame] | 437 | writel(((mipi->rx_eot_ignore & 0x1) << 4) | (mipi->tx_eot_append & 0x1), |
| 438 | mipi->ctl_base + EOT_PACKET_CTRL); |
Huaibin Yang | 952dce3 | 2015-02-19 18:01:27 -0800 | [diff] [blame] | 439 | |
Ray Zhang | 4c7e37f | 2013-12-03 17:04:55 +0800 | [diff] [blame] | 440 | #endif |
Siddhartha Agrawal | 2679a82 | 2013-05-31 19:15:12 -0700 | [diff] [blame] | 441 | |
Ray Zhang | 4c7e37f | 2013-12-03 17:04:55 +0800 | [diff] [blame] | 442 | return 0; |
| 443 | } |
| 444 | |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 445 | void mdss_dsi_panel_shutdown(struct msm_panel_info *pinfo) |
| 446 | { |
| 447 | #if (DISPLAY_TYPE_MDSS == 1) |
| 448 | unsigned long read_val = 0; |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 449 | uint32_t ctl_base = pinfo->mipi.ctl_base; |
| 450 | uint32_t sctl_base = pinfo->mipi.sctl_base; |
| 451 | |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 452 | if (pinfo->mipi.panel_off_cmds) { |
| 453 | /* |
| 454 | * Once MDP TG is disabled, reset of DSI controller is |
| 455 | * needed before we send panel OFF commands. |
| 456 | */ |
| 457 | if (pinfo->type == MIPI_VIDEO_PANEL) { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 458 | read_val = readl(ctl_base + CTRL); |
| 459 | writel((read_val & ~BIT(0)), ctl_base + CTRL); |
| 460 | writel(0x0001, ctl_base + SOFT_RESET); |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 461 | dsb(); |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 462 | writel(0x0000, ctl_base + SOFT_RESET); |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 463 | dsb(); |
| 464 | /* Enable cmd mode only */ |
| 465 | writel(((read_val & ~BIT(1)) | BIT(2)), |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 466 | ctl_base + CTRL); |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | if (pinfo->mipi.broadcast) { |
| 470 | if (pinfo->type == MIPI_VIDEO_PANEL) { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 471 | read_val = readl(sctl_base + CTRL); |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 472 | writel((read_val & ~BIT(0)), |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 473 | sctl_base + CTRL); |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 474 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 475 | writel(0x0001, sctl_base + SOFT_RESET); |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 476 | dsb(); |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 477 | writel(0x0000, sctl_base + SOFT_RESET); |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 478 | dsb(); |
| 479 | |
| 480 | writel(((read_val & ~BIT(1)) | BIT(2)), |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 481 | sctl_base + CTRL); |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 482 | } |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 483 | } |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 484 | mdss_dsi_cmds_tx(&pinfo->mipi, pinfo->mipi.panel_off_cmds, |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 485 | pinfo->mipi.num_of_panel_off_cmds, |
| 486 | pinfo->mipi.broadcast); |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 487 | } |
| 488 | #endif |
| 489 | } |
| 490 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 491 | int mdss_dsi_panel_initialize(struct mipi_panel_info *mipi, uint32_t |
Ray Zhang | 4c7e37f | 2013-12-03 17:04:55 +0800 | [diff] [blame] | 492 | broadcast) |
| 493 | { |
| 494 | int status = 0; |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 495 | uint32_t ctrl_mode = 0; |
Ray Zhang | 4c7e37f | 2013-12-03 17:04:55 +0800 | [diff] [blame] | 496 | |
| 497 | #if (DISPLAY_TYPE_MDSS == 1) |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 498 | if (!mipi->panel_on_cmds) |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 499 | goto end; |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 500 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 501 | ctrl_mode = readl(mipi->ctl_base + CTRL); |
Siddhartha Agrawal | 980b5ee | 2013-05-30 12:17:50 -0700 | [diff] [blame] | 502 | |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 503 | /* Enable command mode before sending the commands. */ |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 504 | writel(ctrl_mode | 0x04, mipi->ctl_base + CTRL); |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 505 | if (broadcast) |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 506 | writel(ctrl_mode | 0x04, mipi->sctl_base + CTRL); |
| 507 | status = mdss_dsi_cmds_tx(mipi, mipi->panel_on_cmds, |
| 508 | mipi->num_of_panel_on_cmds, broadcast); |
| 509 | writel(ctrl_mode, mipi->ctl_base + CTRL); |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 510 | if (broadcast) |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 511 | writel(ctrl_mode, mipi->sctl_base + CTRL); |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 512 | |
| 513 | if (!broadcast && !status && target_panel_auto_detect_enabled()) |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 514 | status = mdss_dsi_read_panel_signature(mipi); |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 515 | |
| 516 | end: |
Terence Hampson | cc3345c | 2013-06-27 15:30:10 -0400 | [diff] [blame] | 517 | #endif |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 518 | return status; |
| 519 | } |
| 520 | |
Kuogee Hsieh | d58c809 | 2015-07-07 10:31:34 -0700 | [diff] [blame] | 521 | int mdss_dsi_video_mode_config(struct msm_panel_info *pinfo, |
| 522 | uint16_t disp_width, |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 523 | uint16_t disp_height, |
| 524 | uint16_t img_width, |
| 525 | uint16_t img_height, |
| 526 | uint16_t hsync_porch0_fp, |
| 527 | uint16_t hsync_porch0_bp, |
| 528 | uint16_t vsync_porch0_fp, |
| 529 | uint16_t vsync_porch0_bp, |
| 530 | uint16_t hsync_width, |
| 531 | uint16_t vsync_width, |
| 532 | uint16_t dst_format, |
| 533 | uint16_t traffic_mode, |
| 534 | uint8_t lane_en, |
Padmanabhan Komanduru | e320987 | 2015-01-12 16:33:16 +0530 | [diff] [blame] | 535 | uint8_t pulse_mode_hsa_he, |
| 536 | uint32_t low_pwr_stop_mode, |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 537 | uint8_t eof_bllp_pwr, |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 538 | uint8_t interleav, |
| 539 | uint32_t ctl_base) |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 540 | { |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 541 | int status = 0; |
| 542 | |
Terence Hampson | cc3345c | 2013-06-27 15:30:10 -0400 | [diff] [blame] | 543 | #if (DISPLAY_TYPE_MDSS == 1) |
Padmanabhan Komanduru | 684b58f | 2015-02-11 16:22:51 +0530 | [diff] [blame] | 544 | int last_line_interleave_en = 0; |
Kuogee Hsieh | d58c809 | 2015-07-07 10:31:34 -0700 | [diff] [blame] | 545 | struct dsc_desc *dsc = NULL; |
| 546 | |
| 547 | if (pinfo->compression_mode == COMPRESSION_DSC) |
| 548 | dsc = &pinfo->dsc; |
Padmanabhan Komanduru | 684b58f | 2015-02-11 16:22:51 +0530 | [diff] [blame] | 549 | |
| 550 | /*Check if EOF_BLLP_PWR_MODE bit is set*/ |
| 551 | if(eof_bllp_pwr & 0x8) |
| 552 | last_line_interleave_en = 1; |
| 553 | |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 554 | writel(0x00000000, ctl_base + CLK_CTRL); |
| 555 | writel(0x00000002, ctl_base + CLK_CTRL); |
| 556 | writel(0x00000006, ctl_base + CLK_CTRL); |
| 557 | writel(0x0000000e, ctl_base + CLK_CTRL); |
| 558 | writel(0x0000001e, ctl_base + CLK_CTRL); |
| 559 | writel(0x0000023f, ctl_base + CLK_CTRL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 560 | |
Padmanabhan Komanduru | 2f8e0bc | 2014-11-27 18:25:36 +0530 | [diff] [blame] | 561 | writel(0x03f03fe0, ctl_base + ERR_INT_MASK0); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 562 | |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 563 | writel(0x02020202, ctl_base + INT_CTRL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 564 | |
Padmanabhan Komanduru | daebf6b | 2014-08-20 20:39:40 +0530 | [diff] [blame] | 565 | /* For 8916/8939, enable DSI timing double buffering */ |
Kuogee Hsieh | 861e25d | 2014-10-29 16:50:15 -0700 | [diff] [blame] | 566 | if (readl(ctl_base) >= DSI_HW_REV_103 && |
Shivaraj Shetty | 41d2d48 | 2014-11-04 16:07:32 +0530 | [diff] [blame] | 567 | mdp_get_revision() != MDP_REV_305) |
Padmanabhan Komanduru | daebf6b | 2014-08-20 20:39:40 +0530 | [diff] [blame] | 568 | writel(0x1, ctl_base + TIMING_DB_MODE); |
| 569 | |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 570 | writel(((disp_width + hsync_porch0_bp) << 16) | hsync_porch0_bp, |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 571 | ctl_base + VIDEO_MODE_ACTIVE_H); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 572 | |
| 573 | writel(((disp_height + vsync_porch0_bp) << 16) | (vsync_porch0_bp), |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 574 | ctl_base + VIDEO_MODE_ACTIVE_V); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 575 | |
Terence Hampson | 7385f6a | 2013-08-16 15:31:25 -0400 | [diff] [blame] | 576 | if (mdp_get_revision() >= MDP_REV_41 || |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 577 | mdp_get_revision() == MDP_REV_304 || |
| 578 | mdp_get_revision() == MDP_REV_305) { |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 579 | writel(((disp_height + vsync_porch0_fp |
| 580 | + vsync_porch0_bp - 1) << 16) |
| 581 | | (disp_width + hsync_porch0_fp |
| 582 | + hsync_porch0_bp - 1), |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 583 | ctl_base + VIDEO_MODE_TOTAL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 584 | } else { |
| 585 | writel(((disp_height + vsync_porch0_fp |
| 586 | + vsync_porch0_bp) << 16) |
| 587 | | (disp_width + hsync_porch0_fp |
| 588 | + hsync_porch0_bp), |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 589 | ctl_base + VIDEO_MODE_TOTAL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 592 | writel((hsync_width << 16) | 0, ctl_base + VIDEO_MODE_HSYNC); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 593 | |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 594 | writel(0 << 16 | 0, ctl_base + VIDEO_MODE_VSYNC); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 595 | |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 596 | writel(vsync_width << 16 | 0, ctl_base + VIDEO_MODE_VSYNC_VPOS); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 597 | |
Padmanabhan Komanduru | daebf6b | 2014-08-20 20:39:40 +0530 | [diff] [blame] | 598 | /* For 8916/8939, flush the DSI timing registers */ |
Kuogee Hsieh | 861e25d | 2014-10-29 16:50:15 -0700 | [diff] [blame] | 599 | if (readl(ctl_base) >= DSI_HW_REV_103 && |
Shivaraj Shetty | 41d2d48 | 2014-11-04 16:07:32 +0530 | [diff] [blame] | 600 | mdp_get_revision() != MDP_REV_305) |
Padmanabhan Komanduru | daebf6b | 2014-08-20 20:39:40 +0530 | [diff] [blame] | 601 | writel(0x1, ctl_base + TIMING_FLUSH); |
| 602 | |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 603 | writel(0x00000100, ctl_base + MISR_VIDEO_CTRL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 604 | |
Shivaraj Shetty | 41d2d48 | 2014-11-04 16:07:32 +0530 | [diff] [blame] | 605 | if (mdp_get_revision() >= MDP_REV_41 || mdp_get_revision() == MDP_REV_305) { |
Padmanabhan Komanduru | 684b58f | 2015-02-11 16:22:51 +0530 | [diff] [blame] | 606 | writel(last_line_interleave_en << 31 | pulse_mode_hsa_he << 28 | |
| 607 | low_pwr_stop_mode << 16 | eof_bllp_pwr << 12 | |
| 608 | traffic_mode << 8 | dst_format << 4 | 0x0, |
| 609 | ctl_base + VIDEO_MODE_CTRL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 610 | } else { |
| 611 | writel(1 << 28 | 1 << 24 | 1 << 20 | low_pwr_stop_mode << 16 | |
| 612 | eof_bllp_pwr << 12 | traffic_mode << 8 |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 613 | | dst_format << 4 | 0x0, ctl_base + VIDEO_MODE_CTRL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 616 | writel(0x3fd08, ctl_base + HS_TIMER_CTRL); |
| 617 | writel(0x00010100, ctl_base + MISR_VIDEO_CTRL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 618 | |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 619 | writel(0x00010100, ctl_base + INT_CTRL); |
| 620 | writel(0x02010202, ctl_base + INT_CTRL); |
| 621 | writel(0x02030303, ctl_base + INT_CTRL); |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 622 | |
| 623 | writel(interleav << 30 | 0 << 24 | 0 << 20 | lane_en << 4 |
Siddhartha Agrawal | 6e76004 | 2013-05-30 21:10:18 -0700 | [diff] [blame] | 624 | | 0x103, ctl_base + CTRL); |
Kuogee Hsieh | d58c809 | 2015-07-07 10:31:34 -0700 | [diff] [blame] | 625 | if (dsc) { |
| 626 | if (dsc->dsi_dsc_config) |
| 627 | dsc->dsi_dsc_config(pinfo->mipi.ctl_base, DSI_VIDEO_MODE, dsc); |
| 628 | } |
Terence Hampson | cc3345c | 2013-06-27 15:30:10 -0400 | [diff] [blame] | 629 | #endif |
Siddhartha Agrawal | 06bb82f | 2013-05-24 12:32:33 -0700 | [diff] [blame] | 630 | |
| 631 | return status; |
| 632 | } |
| 633 | |
Siddhartha Agrawal | 3e694ea | 2013-01-23 17:01:31 -0800 | [diff] [blame] | 634 | int mdss_dsi_config(struct msm_fb_panel_data *panel) |
| 635 | { |
| 636 | int ret = NO_ERROR; |
| 637 | struct msm_panel_info *pinfo; |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 638 | struct mipi_panel_info *mipi; |
Kuogee Hsieh | d58c809 | 2015-07-07 10:31:34 -0700 | [diff] [blame] | 639 | struct dsc_desc *dsc = NULL; |
| 640 | struct mipi_dsi_cmd cmd; |
Siddhartha Agrawal | 3e694ea | 2013-01-23 17:01:31 -0800 | [diff] [blame] | 641 | |
Terence Hampson | cc3345c | 2013-06-27 15:30:10 -0400 | [diff] [blame] | 642 | #if (DISPLAY_TYPE_MDSS == 1) |
Siddhartha Agrawal | 3e694ea | 2013-01-23 17:01:31 -0800 | [diff] [blame] | 643 | if (!panel) |
| 644 | return ERR_INVALID_ARGS; |
| 645 | |
| 646 | pinfo = &(panel->panel_info); |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 647 | mipi = &(pinfo->mipi); |
Siddhartha Agrawal | 3e694ea | 2013-01-23 17:01:31 -0800 | [diff] [blame] | 648 | |
Kuogee Hsieh | d58c809 | 2015-07-07 10:31:34 -0700 | [diff] [blame] | 649 | |
| 650 | if (pinfo->compression_mode == COMPRESSION_DSC) { |
| 651 | dsc = &pinfo->dsc; |
| 652 | if (dsc) { |
| 653 | if (dsc->dsc2buf) |
| 654 | dsc->dsc2buf(pinfo); |
| 655 | } |
| 656 | } |
| 657 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 658 | dprintf(SPEW, "ctl_base=0x%08x, phy_base=0x%08x\n", mipi->ctl_base, |
| 659 | mipi->phy_base); |
Siddhartha Agrawal | 3e694ea | 2013-01-23 17:01:31 -0800 | [diff] [blame] | 660 | |
Jeevan Shriram | 0137932 | 2015-01-07 17:41:26 -0800 | [diff] [blame] | 661 | mdss_dsi_phy_init(mipi); |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 662 | |
| 663 | ret = mdss_dsi_host_init(mipi, mipi->dual_dsi, |
| 664 | mipi->broadcast); |
Ray Zhang | 4c7e37f | 2013-12-03 17:04:55 +0800 | [diff] [blame] | 665 | if (ret) { |
| 666 | dprintf(CRITICAL, "dsi host init error\n"); |
| 667 | goto error; |
| 668 | } |
| 669 | |
Aravind Venkateswaran | 51e5755 | 2014-12-09 13:23:19 -0800 | [diff] [blame] | 670 | mdss_dsi_phy_contention_detection(mipi, mipi->phy_base); |
| 671 | if (mipi->dual_dsi) |
| 672 | mdss_dsi_phy_contention_detection(mipi, mipi->sphy_base); |
Xiaoming Zhou | 03fd48b | 2014-07-31 15:24:41 -0400 | [diff] [blame] | 673 | |
Ray Zhang | 4c7e37f | 2013-12-03 17:04:55 +0800 | [diff] [blame] | 674 | if (panel->pre_init_func) { |
| 675 | ret = panel->pre_init_func(); |
| 676 | if (ret) { |
| 677 | dprintf(CRITICAL, "pre_init_func error\n"); |
| 678 | goto error; |
| 679 | } |
| 680 | } |
| 681 | |
Veera Sundaram Sankaran | 9439eb1 | 2016-06-13 13:53:56 -0700 | [diff] [blame] | 682 | if (mipi->force_clk_lane_hs) |
| 683 | mdss_dsi_force_clk_lane_hs(mipi, mipi->dual_dsi); |
| 684 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 685 | if (!mipi->cmds_post_tg) { |
| 686 | ret = mdss_dsi_panel_initialize(mipi, mipi->broadcast); |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 687 | if (ret) { |
| 688 | dprintf(CRITICAL, "dsi panel init error\n"); |
| 689 | goto error; |
| 690 | } |
Ray Zhang | 4c7e37f | 2013-12-03 17:04:55 +0800 | [diff] [blame] | 691 | } |
Siddhartha Agrawal | 3e694ea | 2013-01-23 17:01:31 -0800 | [diff] [blame] | 692 | |
Kuogee Hsieh | d58c809 | 2015-07-07 10:31:34 -0700 | [diff] [blame] | 693 | if (dsc) { |
| 694 | cmd.size = DCS_HDR_LEN + DSC_PPS_LEN; |
| 695 | cmd.payload = dsc->pps_buf; |
| 696 | cmd.wait = 0x10; |
| 697 | mdss_dsi_cmds_tx(mipi, &cmd, 1, mipi->broadcast); |
| 698 | } |
| 699 | |
Siddhartha Agrawal | 3e694ea | 2013-01-23 17:01:31 -0800 | [diff] [blame] | 700 | if (pinfo->rotate && panel->rotate) |
| 701 | pinfo->rotate(); |
Terence Hampson | cc3345c | 2013-06-27 15:30:10 -0400 | [diff] [blame] | 702 | #endif |
Siddhartha Agrawal | 3e694ea | 2013-01-23 17:01:31 -0800 | [diff] [blame] | 703 | |
Ray Zhang | 4c7e37f | 2013-12-03 17:04:55 +0800 | [diff] [blame] | 704 | error: |
Siddhartha Agrawal | 3e694ea | 2013-01-23 17:01:31 -0800 | [diff] [blame] | 705 | return ret; |
| 706 | } |
| 707 | |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 708 | int mdss_dsi_post_on(struct msm_fb_panel_data *panel) |
| 709 | { |
| 710 | int ret = 0; |
| 711 | struct msm_panel_info *pinfo = &(panel->panel_info); |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 712 | |
| 713 | if (pinfo->mipi.cmds_post_tg) { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 714 | ret = mdss_dsi_panel_initialize(&pinfo->mipi, pinfo->mipi.broadcast); |
Siddhartha Agrawal | 007ea9e | 2014-10-14 15:02:48 -0700 | [diff] [blame] | 715 | if (ret) { |
| 716 | dprintf(CRITICAL, "dsi panel init error\n"); |
| 717 | } |
| 718 | } |
| 719 | return ret; |
| 720 | } |
| 721 | |
Kuogee Hsieh | d58c809 | 2015-07-07 10:31:34 -0700 | [diff] [blame] | 722 | int mdss_dsi_cmd_mode_config(struct msm_panel_info *pinfo, |
| 723 | uint16_t disp_width, |
Siddhartha Agrawal | 7317e48 | 2013-04-21 16:16:57 -0700 | [diff] [blame] | 724 | uint16_t disp_height, |
| 725 | uint16_t img_width, |
| 726 | uint16_t img_height, |
| 727 | uint16_t dst_format, |
Xiaoming Zhou | 8d534dd | 2013-07-29 15:49:19 -0400 | [diff] [blame] | 728 | uint8_t ystride, |
| 729 | uint8_t lane_en, |
Dhaval Patel | 5b22fe7 | 2014-01-02 16:28:38 -0800 | [diff] [blame] | 730 | uint8_t interleav, |
| 731 | uint32_t ctl_base) |
Siddhartha Agrawal | 7317e48 | 2013-04-21 16:16:57 -0700 | [diff] [blame] | 732 | { |
Xiaoming Zhou | 8d534dd | 2013-07-29 15:49:19 -0400 | [diff] [blame] | 733 | uint16_t dst_fmt = 0; |
Kuogee Hsieh | d58c809 | 2015-07-07 10:31:34 -0700 | [diff] [blame] | 734 | struct dsc_desc *dsc = NULL; |
| 735 | unsigned int data; |
Xiaoming Zhou | 8d534dd | 2013-07-29 15:49:19 -0400 | [diff] [blame] | 736 | |
| 737 | switch (dst_format) { |
| 738 | case DSI_VIDEO_DST_FORMAT_RGB565: |
| 739 | dst_fmt = DSI_CMD_DST_FORMAT_RGB565; |
| 740 | break; |
| 741 | case DSI_VIDEO_DST_FORMAT_RGB666: |
| 742 | case DSI_VIDEO_DST_FORMAT_RGB666_LOOSE: |
| 743 | dst_fmt = DSI_CMD_DST_FORMAT_RGB666; |
| 744 | break; |
| 745 | case DSI_VIDEO_DST_FORMAT_RGB888: |
| 746 | dst_fmt = DSI_CMD_DST_FORMAT_RGB888; |
| 747 | break; |
| 748 | default: |
| 749 | dprintf(CRITICAL, "unsupported dst format\n"); |
| 750 | return ERROR; |
| 751 | } |
Siddhartha Agrawal | 7317e48 | 2013-04-21 16:16:57 -0700 | [diff] [blame] | 752 | |
Terence Hampson | cc3345c | 2013-06-27 15:30:10 -0400 | [diff] [blame] | 753 | #if (DISPLAY_TYPE_MDSS == 1) |
Dhaval Patel | 5b22fe7 | 2014-01-02 16:28:38 -0800 | [diff] [blame] | 754 | writel(0x00000000, ctl_base + CLK_CTRL); |
| 755 | writel(0x00000000, ctl_base + CLK_CTRL); |
| 756 | writel(0x00000000, ctl_base + CLK_CTRL); |
| 757 | writel(0x00000000, ctl_base + CLK_CTRL); |
| 758 | writel(0x00000002, ctl_base + CLK_CTRL); |
| 759 | writel(0x00000006, ctl_base + CLK_CTRL); |
| 760 | writel(0x0000000e, ctl_base + CLK_CTRL); |
| 761 | writel(0x0000001e, ctl_base + CLK_CTRL); |
| 762 | writel(0x0000023f, ctl_base + CLK_CTRL); |
Siddhartha Agrawal | 7317e48 | 2013-04-21 16:16:57 -0700 | [diff] [blame] | 763 | |
Dhaval Patel | 5b22fe7 | 2014-01-02 16:28:38 -0800 | [diff] [blame] | 764 | writel(0, ctl_base + CTRL); |
Siddhartha Agrawal | 7317e48 | 2013-04-21 16:16:57 -0700 | [diff] [blame] | 765 | |
Padmanabhan Komanduru | 2f8e0bc | 2014-11-27 18:25:36 +0530 | [diff] [blame] | 766 | writel(0x03f03fe0, ctl_base + ERR_INT_MASK0); |
Siddhartha Agrawal | 7317e48 | 2013-04-21 16:16:57 -0700 | [diff] [blame] | 767 | |
Dhaval Patel | 5b22fe7 | 2014-01-02 16:28:38 -0800 | [diff] [blame] | 768 | writel(0x02020202, ctl_base + INT_CTRL); |
Siddhartha Agrawal | 7317e48 | 2013-04-21 16:16:57 -0700 | [diff] [blame] | 769 | |
Dhaval Patel | 5b22fe7 | 2014-01-02 16:28:38 -0800 | [diff] [blame] | 770 | writel(dst_fmt, ctl_base + COMMAND_MODE_MDP_CTRL); |
Kuogee Hsieh | d58c809 | 2015-07-07 10:31:34 -0700 | [diff] [blame] | 771 | |
| 772 | if (pinfo->compression_mode == COMPRESSION_DSC) |
| 773 | dsc = &pinfo->dsc; |
| 774 | |
| 775 | if (dsc) { |
| 776 | data = dsc->bytes_per_pkt; |
| 777 | if (pinfo->mipi.insert_dcs_cmd) |
| 778 | data++; |
| 779 | data <<= 16; |
| 780 | data |= 0x039; |
| 781 | writel(data, ctl_base + COMMAND_MODE_MDP_STREAM0_CTRL); |
| 782 | writel(data, ctl_base + COMMAND_MODE_MDP_STREAM1_CTRL); |
| 783 | data = dsc->pic_height << 16; |
| 784 | data |= dsc->pclk_per_line; |
| 785 | writel(data, ctl_base + COMMAND_MODE_MDP_STREAM0_TOTAL); |
| 786 | writel(data, ctl_base + COMMAND_MODE_MDP_STREAM1_TOTAL); |
| 787 | |
| 788 | if (dsc->dsi_dsc_config) |
Kuogee Hsieh | 6a8802f | 2015-09-01 09:11:40 -0700 | [diff] [blame] | 789 | dsc->dsi_dsc_config(pinfo->mipi.ctl_base, DSI_CMD_MODE, dsc); |
Kuogee Hsieh | d58c809 | 2015-07-07 10:31:34 -0700 | [diff] [blame] | 790 | } else { |
| 791 | |
| 792 | writel((img_width * ystride + 1) << 16 | 0x0039, |
| 793 | ctl_base + COMMAND_MODE_MDP_STREAM0_CTRL); |
| 794 | writel((img_width * ystride + 1) << 16 | 0x0039, |
| 795 | ctl_base + COMMAND_MODE_MDP_STREAM1_CTRL); |
| 796 | writel(img_height << 16 | img_width, |
| 797 | ctl_base + COMMAND_MODE_MDP_STREAM0_TOTAL); |
| 798 | writel(img_height << 16 | img_width, |
| 799 | ctl_base + COMMAND_MODE_MDP_STREAM1_TOTAL); |
| 800 | } |
| 801 | |
Dhaval Patel | 5b22fe7 | 2014-01-02 16:28:38 -0800 | [diff] [blame] | 802 | writel(0x13c2c, ctl_base + COMMAND_MODE_MDP_DCS_CMD_CTRL); |
Xiaoming Zhou | 8d534dd | 2013-07-29 15:49:19 -0400 | [diff] [blame] | 803 | writel(interleav << 30 | 0 << 24 | 0 << 20 | lane_en << 4 | 0x105, |
Dhaval Patel | 5b22fe7 | 2014-01-02 16:28:38 -0800 | [diff] [blame] | 804 | ctl_base + CTRL); |
Padmanabhan Komanduru | 7860be5 | 2014-03-18 19:07:36 +0530 | [diff] [blame] | 805 | writel(0x14000000, ctl_base + COMMAND_MODE_DMA_CTRL); |
Dhaval Patel | 5b22fe7 | 2014-01-02 16:28:38 -0800 | [diff] [blame] | 806 | writel(0x10000000, ctl_base + MISR_CMD_CTRL); |
Terence Hampson | cc3345c | 2013-06-27 15:30:10 -0400 | [diff] [blame] | 807 | #endif |
Xiaoming Zhou | 8d534dd | 2013-07-29 15:49:19 -0400 | [diff] [blame] | 808 | return 0; |
Siddhartha Agrawal | 7317e48 | 2013-04-21 16:16:57 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 811 | int mipi_dsi_on(struct msm_panel_info *pinfo) |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 812 | { |
| 813 | int ret = NO_ERROR; |
| 814 | unsigned long ReadValue; |
| 815 | unsigned long count = 0; |
| 816 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 817 | ReadValue = readl(pinfo->mipi.ctl_base + INT_CTRL) & 0x00010000; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 818 | |
| 819 | mdelay(10); |
| 820 | |
| 821 | while (ReadValue != 0x00010000) { |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 822 | ReadValue = readl(pinfo->mipi.ctl_base + INT_CTRL) & 0x00010000; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 823 | count++; |
| 824 | if (count > 0xffff) { |
| 825 | dprintf(CRITICAL, "Video lane test failed\n"); |
| 826 | return ERROR; |
| 827 | } |
| 828 | } |
| 829 | |
Amir Samuelov | 2d4ba16 | 2012-07-22 11:53:14 +0300 | [diff] [blame] | 830 | dprintf(INFO, "Video lane tested successfully\n"); |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 831 | return ret; |
| 832 | } |
| 833 | |
Siddhartha Agrawal | 24d81b5 | 2013-07-01 11:13:32 -0700 | [diff] [blame] | 834 | int mipi_dsi_off(struct msm_panel_info *pinfo) |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 835 | { |
Amol Jadi | 6834f1a | 2012-06-29 14:42:59 -0700 | [diff] [blame] | 836 | if(!target_cont_splash_screen()) |
| 837 | { |
Padmanabhan Komanduru | f8986be | 2014-11-04 15:57:19 +0530 | [diff] [blame] | 838 | mdss_dsi_panel_shutdown(pinfo); |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 839 | writel(0, pinfo->mipi.ctl_base + CLK_CTRL); |
Naseer Ahmed | d2f6de3 | 2015-11-27 11:13:09 -0500 | [diff] [blame] | 840 | writel(0, pinfo->mipi.ctl_base + CTRL); |
Siddhartha Agrawal | e0033a1 | 2013-02-23 15:37:42 -0800 | [diff] [blame] | 841 | } |
| 842 | |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 843 | writel(0x1115501, pinfo->mipi.ctl_base + INT_CTRL); |
feifanz | 87f1985 | 2015-09-25 11:54:26 +0800 | [diff] [blame] | 844 | if (pinfo->mipi.dual_dsi) |
Aravind Venkateswaran | fec354c | 2014-12-04 18:10:14 -0800 | [diff] [blame] | 845 | writel(0x1115501, pinfo->mipi.sctl_base + INT_CTRL); |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 846 | |
| 847 | return NO_ERROR; |
| 848 | } |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 849 | |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 850 | #if (DISPLAY_TYPE_MDSS == 0) |
| 851 | static int dsi_cmd_dma_trigger_for_panel() |
| 852 | { |
| 853 | unsigned long ReadValue; |
| 854 | unsigned long count = 0; |
| 855 | int status = 0; |
| 856 | |
| 857 | writel(0x03030303, DSI_INT_CTRL); |
| 858 | writel(0x1, DSI_CMD_MODE_DMA_SW_TRIGGER); |
| 859 | dsb(); |
| 860 | ReadValue = readl(DSI_INT_CTRL) & 0x00000001; |
| 861 | while (ReadValue != 0x00000001) { |
| 862 | ReadValue = readl(DSI_INT_CTRL) & 0x00000001; |
| 863 | count++; |
| 864 | if (count > 0xffff) { |
| 865 | status = FAIL; |
| 866 | dprintf(CRITICAL, |
| 867 | "Panel CMD: command mode dma test failed\n"); |
| 868 | return status; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | writel((readl(DSI_INT_CTRL) | 0x01000001), DSI_INT_CTRL); |
| 873 | dprintf(SPEW, "Panel CMD: command mode dma tested successfully\n"); |
| 874 | return status; |
| 875 | } |
| 876 | |
| 877 | int mipi_dsi_cmds_tx(struct mipi_dsi_cmd *cmds, int count) |
| 878 | { |
| 879 | int ret = 0; |
| 880 | struct mipi_dsi_cmd *cm; |
| 881 | int i = 0; |
| 882 | char pload[256]; |
| 883 | uint32_t off; |
| 884 | |
| 885 | /* Align pload at 8 byte boundry */ |
| 886 | off = pload; |
| 887 | off &= 0x07; |
| 888 | if (off) |
| 889 | off = 8 - off; |
| 890 | off += pload; |
| 891 | |
| 892 | cm = cmds; |
| 893 | for (i = 0; i < count; i++) { |
| 894 | /* Wait for VIDEO_MODE_DONE */ |
| 895 | ret = mdss_dsi_wait4_video_done(); |
| 896 | if (ret) |
| 897 | goto mipi_cmds_error; |
| 898 | |
| 899 | memcpy((void *)off, (cm->payload), cm->size); |
Matthew Qin | 81933ce | 2015-02-03 17:58:52 +0800 | [diff] [blame] | 900 | arch_clean_invalidate_cache_range((addr_t)(off), size); |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 901 | writel(off, DSI_DMA_CMD_OFFSET); |
| 902 | writel(cm->size, DSI_DMA_CMD_LENGTH); // reg 0x48 for this build |
| 903 | dsb(); |
| 904 | ret += dsi_cmd_dma_trigger_for_panel(); |
| 905 | dsb(); |
| 906 | if (cm->wait) |
| 907 | mdelay(cm->wait); |
| 908 | else |
| 909 | udelay(80); |
| 910 | cm++; |
| 911 | } |
| 912 | mipi_cmds_error: |
| 913 | return ret; |
| 914 | } |
| 915 | |
| 916 | /* |
| 917 | * mipi_dsi_cmd_rx: can receive at most 16 bytes |
| 918 | * per transaction since it only have 4 32bits reigsters |
| 919 | * to hold data. |
| 920 | * therefore Maximum Return Packet Size need to be set to 16. |
| 921 | * any return data more than MRPS need to be break down |
| 922 | * to multiple transactions. |
| 923 | */ |
| 924 | int mipi_dsi_cmds_rx(char **rp, int len) |
| 925 | { |
| 926 | uint32_t *lp, data; |
| 927 | char *dp; |
| 928 | int i, off, cnt; |
| 929 | int rlen, res; |
| 930 | |
| 931 | if (len <= 2) |
| 932 | rlen = 4; /* short read */ |
| 933 | else |
| 934 | rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */ |
| 935 | |
| 936 | if (rlen > MIPI_DSI_REG_LEN) { |
| 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | res = rlen & 0x03; |
| 941 | |
| 942 | rlen += res; /* 4 byte align */ |
| 943 | lp = (uint32_t *) (*rp); |
| 944 | |
| 945 | cnt = rlen; |
| 946 | cnt += 3; |
| 947 | cnt >>= 2; |
| 948 | |
| 949 | if (cnt > 4) |
| 950 | cnt = 4; /* 4 x 32 bits registers only */ |
| 951 | |
| 952 | off = 0x068; /* DSI_RDBK_DATA0 */ |
| 953 | off += ((cnt - 1) * 4); |
| 954 | |
| 955 | for (i = 0; i < cnt; i++) { |
| 956 | data = (uint32_t) readl(MIPI_DSI_BASE + off); |
| 957 | *lp++ = ntohl(data); /* to network byte order */ |
| 958 | off -= 4; |
| 959 | } |
| 960 | |
| 961 | if (len > 2) { |
| 962 | /*First 4 bytes + paded bytes will be header next len bytes would be payload */ |
| 963 | for (i = 0; i < len; i++) { |
| 964 | dp = *rp; |
| 965 | dp[i] = dp[4 + res + i]; |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | return len; |
| 970 | } |
| 971 | |
| 972 | static int mipi_dsi_panel_initialize(struct mipi_dsi_panel_config *pinfo) |
| 973 | { |
| 974 | uint8_t DMA_STREAM1 = 0; // for mdp display processor path |
| 975 | uint8_t EMBED_MODE1 = 1; // from frame buffer |
| 976 | uint8_t POWER_MODE2 = 1; // from frame buffer |
| 977 | uint8_t PACK_TYPE1; // long packet |
| 978 | uint8_t VC1 = 0; |
| 979 | uint8_t DT1 = 0; // non embedded mode |
| 980 | uint8_t WC1 = 0; // for non embedded mode only |
| 981 | int status = 0; |
| 982 | uint8_t DLNx_EN; |
| 983 | |
| 984 | switch (pinfo->num_of_lanes) { |
| 985 | default: |
| 986 | case 1: |
| 987 | DLNx_EN = 1; // 1 lane |
| 988 | break; |
| 989 | case 2: |
| 990 | DLNx_EN = 3; // 2 lane |
| 991 | break; |
| 992 | case 3: |
| 993 | DLNx_EN = 7; // 3 lane |
| 994 | break; |
| 995 | case 4: |
| 996 | DLNx_EN = 0x0F; /* 4 lanes */ |
| 997 | break; |
| 998 | } |
| 999 | |
| 1000 | PACK_TYPE1 = pinfo->pack; |
| 1001 | |
| 1002 | writel(0x0001, DSI_SOFT_RESET); |
| 1003 | writel(0x0000, DSI_SOFT_RESET); |
| 1004 | |
| 1005 | writel((0 << 16) | 0x3f, DSI_CLK_CTRL); /* Turn on all DSI Clks */ |
| 1006 | writel(DMA_STREAM1 << 8 | 0x04, DSI_TRIG_CTRL); // reg 0x80 dma trigger: sw |
| 1007 | // trigger 0x4; dma stream1 |
| 1008 | |
| 1009 | writel(0 << 30 | DLNx_EN << 4 | 0x105, DSI_CTRL); // reg 0x00 for this |
| 1010 | // build |
| 1011 | writel(EMBED_MODE1 << 28 | POWER_MODE2 << 26 |
| 1012 | | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1, |
| 1013 | DSI_COMMAND_MODE_DMA_CTRL); |
| 1014 | |
| 1015 | if (pinfo->panel_on_cmds) |
| 1016 | status = mipi_dsi_cmds_tx(pinfo->panel_on_cmds, |
| 1017 | pinfo->num_of_panel_on_cmds); |
| 1018 | |
| 1019 | return status; |
| 1020 | } |
| 1021 | #endif |
| 1022 | |
| 1023 | void mipi_dsi_shutdown(void) |
| 1024 | { |
| 1025 | #if (DISPLAY_TYPE_MDSS == 0) |
| 1026 | if(!target_cont_splash_screen()) |
| 1027 | { |
| 1028 | mdp_shutdown(); |
| 1029 | writel(0x01010101, DSI_INT_CTRL); |
| 1030 | writel(0x13FF3BFF, DSI_ERR_INT_MASK0); |
| 1031 | |
| 1032 | writel(0, DSI_CLK_CTRL); |
| 1033 | writel(0, DSI_CTRL); |
| 1034 | writel(0, DSIPHY_PLL_CTRL(0)); |
| 1035 | } |
| 1036 | else |
| 1037 | { |
| 1038 | /* To keep the splash screen displayed till kernel driver takes |
| 1039 | control, do not turn off the video mode engine and clocks. |
| 1040 | Only disabling the MIPI DSI IRQs */ |
| 1041 | writel(0x01010101, DSI_INT_CTRL); |
| 1042 | writel(0x13FF3BFF, DSI_ERR_INT_MASK0); |
| 1043 | } |
| 1044 | #endif |
| 1045 | } |
| 1046 | |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 1047 | int mipi_cmd_trigger() |
| 1048 | { |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 1049 | #if (DISPLAY_TYPE_MDSS == 0) |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 1050 | writel(0x1, DSI_CMD_MODE_MDP_SW_TRIGGER); |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 1051 | #endif |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 1052 | return NO_ERROR; |
| 1053 | } |
Aravind Venkateswaran | ce4dd7f | 2014-12-04 16:54:26 -0800 | [diff] [blame] | 1054 | |
| 1055 | int mipi_config(struct msm_fb_panel_data *panel) |
| 1056 | { |
| 1057 | int ret = NO_ERROR; |
| 1058 | #if (DISPLAY_TYPE_MDSS == 0) |
| 1059 | struct msm_panel_info *pinfo; |
| 1060 | struct mipi_dsi_panel_config mipi_pinfo; |
| 1061 | |
| 1062 | if (!panel) |
| 1063 | return ERR_INVALID_ARGS; |
| 1064 | |
| 1065 | pinfo = &(panel->panel_info); |
| 1066 | mipi_pinfo.mode = pinfo->mipi.mode; |
| 1067 | mipi_pinfo.num_of_lanes = pinfo->mipi.num_of_lanes; |
| 1068 | mipi_pinfo.dsi_phy_config = pinfo->mipi.dsi_phy_db; |
| 1069 | mipi_pinfo.panel_on_cmds = pinfo->mipi.panel_on_cmds; |
| 1070 | mipi_pinfo.num_of_panel_on_cmds = pinfo->mipi.num_of_panel_on_cmds; |
| 1071 | mipi_pinfo.lane_swap = pinfo->mipi.lane_swap; |
| 1072 | mipi_pinfo.pack = 1; |
| 1073 | |
| 1074 | /* Enable MMSS_AHB_ARB_MATER_PORT_E for |
| 1075 | arbiter master0 and master 1 request */ |
| 1076 | #if (!DISPLAY_MIPI_PANEL_RENESAS && !DISPLAY_TYPE_DSI6G && !DISPLAY_TYPE_8610) |
| 1077 | writel(0x00001800, MMSS_SFPB_GPREG); |
| 1078 | #endif |
| 1079 | |
| 1080 | mipi_dsi_phy_init(&mipi_pinfo); |
| 1081 | |
| 1082 | ret += mipi_dsi_panel_initialize(&mipi_pinfo); |
| 1083 | |
| 1084 | if (pinfo->rotate && panel->rotate) |
| 1085 | pinfo->rotate(); |
| 1086 | #endif |
| 1087 | return ret; |
| 1088 | } |