Shashank Mittal | 3026290 | 2012-02-21 15:37:24 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, Code Aurora Forum. 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. |
| 12 | * * Neither the name of Code Aurora Forum, Inc. nor the names of its |
| 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> |
| 38 | #include <platform/iomap.h> |
| 39 | #include <platform/clock.h> |
Greg Grisco | 1073a5e | 2011-07-28 18:59:18 -0700 | [diff] [blame] | 40 | #include <platform/timer.h> |
Kinson Chik | fe93103 | 2011-07-21 10:01:34 -0700 | [diff] [blame] | 41 | |
| 42 | extern void mdp_disable(void); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 43 | extern int mipi_dsi_cmd_config(struct fbcon_config mipi_fb_cfg, |
| 44 | unsigned short num_of_lanes); |
Kinson Chik | fe93103 | 2011-07-21 10:01:34 -0700 | [diff] [blame] | 45 | extern void mdp_shutdown(void); |
| 46 | extern void mdp_start_dma(void); |
Deepa Dinamani | a080a40 | 2011-11-05 18:59:26 -0700 | [diff] [blame] | 47 | extern void dsb(void); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 48 | |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 49 | #if DISPLAY_MIPI_PANEL_TOSHIBA |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 50 | static struct fbcon_config mipi_fb_cfg = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 51 | .height = TSH_MIPI_FB_HEIGHT, |
| 52 | .width = TSH_MIPI_FB_WIDTH, |
| 53 | .stride = TSH_MIPI_FB_WIDTH, |
| 54 | .format = FB_FORMAT_RGB888, |
| 55 | .bpp = 24, |
| 56 | .update_start = NULL, |
| 57 | .update_done = NULL, |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 58 | }; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 59 | |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 60 | struct mipi_dsi_panel_config toshiba_panel_info = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 61 | .mode = MIPI_VIDEO_MODE, |
| 62 | .num_of_lanes = 1, |
| 63 | .dsi_phy_config = &mipi_dsi_toshiba_panel_phy_ctrl, |
| 64 | .panel_cmds = toshiba_panel_video_mode_cmds, |
| 65 | .num_of_panel_cmds = ARRAY_SIZE(toshiba_panel_video_mode_cmds), |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 66 | }; |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 67 | #elif DISPLAY_MIPI_PANEL_NOVATEK_BLUE |
| 68 | static struct fbcon_config mipi_fb_cfg = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 69 | .height = NOV_MIPI_FB_HEIGHT, |
| 70 | .width = NOV_MIPI_FB_WIDTH, |
| 71 | .stride = NOV_MIPI_FB_WIDTH, |
| 72 | .format = FB_FORMAT_RGB888, |
| 73 | .bpp = 24, |
| 74 | .update_start = NULL, |
| 75 | .update_done = NULL, |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 76 | }; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 77 | |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 78 | struct mipi_dsi_panel_config novatek_panel_info = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 79 | .mode = MIPI_CMD_MODE, |
| 80 | .num_of_lanes = 2, |
| 81 | .dsi_phy_config = &mipi_dsi_novatek_panel_phy_ctrl, |
| 82 | .panel_cmds = novatek_panel_cmd_mode_cmds, |
| 83 | .num_of_panel_cmds = ARRAY_SIZE(novatek_panel_cmd_mode_cmds), |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 84 | }; |
| 85 | #elif DISPLAY_MIPI_PANEL_TOSHIBA_MDT61 |
| 86 | static struct fbcon_config mipi_fb_cfg = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 87 | .height = TSH_MDT61_MIPI_FB_HEIGHT, |
| 88 | .width = TSH_MDT61_MIPI_FB_WIDTH, |
| 89 | .stride = TSH_MDT61_MIPI_FB_WIDTH, |
| 90 | .format = FB_FORMAT_RGB888, |
| 91 | .bpp = 24, |
| 92 | .update_start = NULL, |
| 93 | .update_done = NULL, |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 94 | }; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 95 | |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 96 | struct mipi_dsi_panel_config toshiba_mdt61_panel_info = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 97 | .mode = MIPI_VIDEO_MODE, |
| 98 | .num_of_lanes = 3, |
| 99 | .dsi_phy_config = &mipi_dsi_toshiba_mdt61_panel_phy_ctrl, |
| 100 | .panel_cmds = toshiba_mdt61_video_mode_cmds, |
| 101 | .num_of_panel_cmds = ARRAY_SIZE(toshiba_mdt61_video_mode_cmds), |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 102 | }; |
Aparna Mallavarapu | f712f5e | 2011-08-04 21:11:00 +0530 | [diff] [blame] | 103 | #elif DISPLAY_MIPI_PANEL_RENESAS |
| 104 | static struct fbcon_config mipi_fb_cfg = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 105 | .height = REN_MIPI_FB_HEIGHT, |
| 106 | .width = REN_MIPI_FB_WIDTH, |
| 107 | .stride = REN_MIPI_FB_WIDTH, |
| 108 | .format = FB_FORMAT_RGB888, |
| 109 | .bpp = 24, |
| 110 | .update_start = NULL, |
| 111 | .update_done = NULL, |
Aparna Mallavarapu | f712f5e | 2011-08-04 21:11:00 +0530 | [diff] [blame] | 112 | }; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 113 | |
Aparna Mallavarapu | f712f5e | 2011-08-04 21:11:00 +0530 | [diff] [blame] | 114 | struct mipi_dsi_panel_config renesas_panel_info = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 115 | .mode = MIPI_VIDEO_MODE, |
| 116 | .num_of_lanes = 2, |
| 117 | .dsi_phy_config = &mipi_dsi_renesas_panel_phy_ctrl, |
| 118 | .panel_cmds = renesas_panel_video_mode_cmds, |
| 119 | .num_of_panel_cmds = ARRAY_SIZE(renesas_panel_video_mode_cmds), |
| 120 | .lane_swap = 1, |
Aparna Mallavarapu | f712f5e | 2011-08-04 21:11:00 +0530 | [diff] [blame] | 121 | }; |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 122 | #else |
| 123 | static struct fbcon_config mipi_fb_cfg = { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 124 | .height = 0, |
| 125 | .width = 0, |
| 126 | .stride = 0, |
| 127 | .format = 0, |
| 128 | .bpp = 0, |
| 129 | .update_start = NULL, |
| 130 | .update_done = NULL, |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 131 | }; |
| 132 | #endif |
| 133 | |
| 134 | static int cmd_mode_status = 0; |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 135 | void secure_writel(uint32_t, uint32_t); |
| 136 | uint32_t secure_readl(uint32_t); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 137 | |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 138 | int mipi_dsi_phy_ctrl_config(struct mipi_dsi_panel_config *pinfo) |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 139 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 140 | unsigned i; |
| 141 | unsigned off = 0; |
| 142 | struct mipi_dsi_phy_ctrl *pd; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 143 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 144 | writel(0x00000001, DSIPHY_SW_RESET); |
| 145 | writel(0x00000000, DSIPHY_SW_RESET); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 146 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 147 | pd = (pinfo->dsi_phy_config); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 148 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 149 | off = 0x02cc; /* regulator ctrl 0 */ |
| 150 | for (i = 0; i < 4; i++) { |
| 151 | writel(pd->regulator[i], MIPI_DSI_BASE + off); |
| 152 | off += 4; |
| 153 | } |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 154 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 155 | off = 0x0260; /* phy timig ctrl 0 */ |
| 156 | for (i = 0; i < 11; i++) { |
| 157 | writel(pd->timing[i], MIPI_DSI_BASE + off); |
| 158 | off += 4; |
| 159 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 160 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 161 | // T_CLK_POST, T_CLK_PRE for CLK lane P/N HS 200 mV timing length should > |
| 162 | // data lane HS timing length |
| 163 | writel(0xa1e, DSI_CLKOUT_TIMING_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 164 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 165 | off = 0x0290; /* ctrl 0 */ |
| 166 | for (i = 0; i < 4; i++) { |
| 167 | writel(pd->ctrl[i], MIPI_DSI_BASE + off); |
| 168 | off += 4; |
| 169 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 170 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 171 | off = 0x02a0; /* strength 0 */ |
| 172 | for (i = 0; i < 4; i++) { |
| 173 | writel(pd->strength[i], MIPI_DSI_BASE + off); |
| 174 | off += 4; |
| 175 | } |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 176 | |
Kinson Chik | 1eaeab5 | 2011-10-05 16:32:02 -0700 | [diff] [blame] | 177 | #if DISPLAY_MIPI_PANEL_RENESAS |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 178 | if (machine_is_7x25a()) { |
| 179 | pd->pll[10] |= 0x8; |
| 180 | } |
Kinson Chik | 1eaeab5 | 2011-10-05 16:32:02 -0700 | [diff] [blame] | 181 | #endif |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 182 | off = 0x0204; /* pll ctrl 1, skip 0 */ |
| 183 | for (i = 1; i < 21; i++) { |
| 184 | writel(pd->pll[i], MIPI_DSI_BASE + off); |
| 185 | off += 4; |
| 186 | } |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 187 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 188 | /* pll ctrl 0 */ |
| 189 | writel(pd->pll[0], MIPI_DSI_BASE + 0x200); |
| 190 | writel((pd->pll[0] | 0x01), MIPI_DSI_BASE + 0x200); |
| 191 | /* lane swp ctrol */ |
| 192 | if (pinfo->lane_swap) |
| 193 | writel(pinfo->lane_swap, MIPI_DSI_BASE + 0xac); |
| 194 | return (0); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 197 | struct mipi_dsi_panel_config *get_panel_info(void) |
| 198 | { |
| 199 | #if DISPLAY_MIPI_PANEL_TOSHIBA |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 200 | return &toshiba_panel_info; |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 201 | #elif DISPLAY_MIPI_PANEL_NOVATEK_BLUE |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 202 | return &novatek_panel_info; |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 203 | #elif DISPLAY_MIPI_PANEL_TOSHIBA_MDT61 |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 204 | return &toshiba_mdt61_panel_info; |
Aparna Mallavarapu | f712f5e | 2011-08-04 21:11:00 +0530 | [diff] [blame] | 205 | #elif DISPLAY_MIPI_PANEL_RENESAS |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 206 | if (machine_is_7x25a()) { |
| 207 | renesas_panel_info.num_of_lanes = 1; |
| 208 | mipi_fb_cfg.height = REN_MIPI_FB_HEIGHT_HVGA; |
| 209 | } |
| 210 | return &renesas_panel_info; |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 211 | #endif |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 212 | return NULL; |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 215 | int dsi_cmd_dma_trigger_for_panel() |
| 216 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 217 | unsigned long ReadValue; |
| 218 | unsigned long count = 0; |
| 219 | int status = 0; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 220 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 221 | writel(0x03030303, DSI_INT_CTRL); |
| 222 | writel(0x1, DSI_CMD_MODE_DMA_SW_TRIGGER); |
| 223 | dsb(); |
| 224 | ReadValue = readl(DSI_INT_CTRL) & 0x00000001; |
| 225 | while (ReadValue != 0x00000001) { |
| 226 | ReadValue = readl(DSI_INT_CTRL) & 0x00000001; |
| 227 | count++; |
| 228 | if (count > 0xffff) { |
| 229 | status = FAIL; |
| 230 | dprintf(CRITICAL, |
| 231 | "Panel CMD: command mode dma test failed\n"); |
| 232 | return status; |
| 233 | } |
| 234 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 235 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 236 | writel((readl(DSI_INT_CTRL) | 0x01000001), DSI_INT_CTRL); |
| 237 | dprintf(SPEW, "Panel CMD: command mode dma tested successfully\n"); |
| 238 | return status; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 241 | int mipi_dsi_cmds_tx(struct mipi_dsi_cmd *cmds, int count) |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 242 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 243 | int ret = 0; |
| 244 | struct mipi_dsi_cmd *cm; |
| 245 | int i = 0; |
| 246 | char pload[256]; |
| 247 | uint32_t off; |
Deepa Dinamani | a080a40 | 2011-11-05 18:59:26 -0700 | [diff] [blame] | 248 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 249 | /* Align pload at 8 byte boundry */ |
| 250 | off = pload; |
| 251 | off &= 0x07; |
| 252 | if (off) |
| 253 | off = 8 - off; |
| 254 | off += pload; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 255 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 256 | cm = cmds; |
| 257 | for (i = 0; i < count; i++) { |
| 258 | memcpy((void *)off, (cm->payload), cm->size); |
| 259 | writel(off, DSI_DMA_CMD_OFFSET); |
| 260 | writel(cm->size, DSI_DMA_CMD_LENGTH); // reg 0x48 for this build |
| 261 | dsb(); |
| 262 | ret += dsi_cmd_dma_trigger_for_panel(); |
| 263 | udelay(80); |
| 264 | cm++; |
| 265 | } |
| 266 | return ret; |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 269 | /* |
| 270 | * mipi_dsi_cmd_rx: can receive at most 16 bytes |
| 271 | * per transaction since it only have 4 32bits reigsters |
| 272 | * to hold data. |
| 273 | * therefore Maximum Return Packet Size need to be set to 16. |
| 274 | * any return data more than MRPS need to be break down |
| 275 | * to multiple transactions. |
| 276 | */ |
| 277 | int mipi_dsi_cmds_rx(char **rp, int len) |
| 278 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 279 | uint32_t *lp, data; |
| 280 | char *dp; |
| 281 | int i, off, cnt; |
| 282 | int rlen, res; |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 283 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 284 | if (len <= 2) |
| 285 | rlen = 4; /* short read */ |
| 286 | else |
| 287 | rlen = MIPI_DSI_MRPS + 6; /* 4 bytes header + 2 bytes crc */ |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 288 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 289 | if (rlen > MIPI_DSI_REG_LEN) { |
| 290 | return 0; |
| 291 | } |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 292 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 293 | res = rlen & 0x03; |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 294 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 295 | rlen += res; /* 4 byte align */ |
| 296 | lp = (uint32_t *) (*rp); |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 297 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 298 | cnt = rlen; |
| 299 | cnt += 3; |
| 300 | cnt >>= 2; |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 301 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 302 | if (cnt > 4) |
| 303 | cnt = 4; /* 4 x 32 bits registers only */ |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 304 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 305 | off = 0x068; /* DSI_RDBK_DATA0 */ |
| 306 | off += ((cnt - 1) * 4); |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 307 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 308 | for (i = 0; i < cnt; i++) { |
| 309 | data = (uint32_t) readl(MIPI_DSI_BASE + off); |
| 310 | *lp++ = ntohl(data); /* to network byte order */ |
| 311 | off -= 4; |
| 312 | } |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 313 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 314 | if (len > 2) { |
| 315 | /*First 4 bytes + paded bytes will be header next len bytes would be payload */ |
| 316 | for (i = 0; i < len; i++) { |
| 317 | dp = *rp; |
| 318 | dp[i] = dp[4 + res + i]; |
| 319 | } |
| 320 | } |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 321 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 322 | return len; |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | static int mipi_dsi_cmd_bta_sw_trigger(void) |
| 326 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 327 | uint32_t data; |
| 328 | int cnt = 0; |
| 329 | int err = 0; |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 330 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 331 | writel(0x01, MIPI_DSI_BASE + 0x094); /* trigger */ |
| 332 | while (cnt < 10000) { |
| 333 | data = readl(MIPI_DSI_BASE + 0x0004); /*DSI_STATUS */ |
| 334 | if ((data & 0x0010) == 0) |
| 335 | break; |
| 336 | cnt++; |
| 337 | } |
| 338 | if (cnt == 10000) |
| 339 | err = 1; |
| 340 | return err; |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static uint32_t mipi_novatek_manufacture_id(void) |
| 344 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 345 | char rec_buf[24]; |
| 346 | char *rp = rec_buf; |
| 347 | uint32_t *lp, data; |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 348 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 349 | mipi_dsi_cmds_tx(&novatek_panel_manufacture_id_cmd, 1); |
| 350 | mipi_dsi_cmds_rx(&rp, 3); |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 351 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 352 | lp = (uint32_t *) rp; |
| 353 | data = (uint32_t) * lp; |
| 354 | data = ntohl(data); |
| 355 | data = data >> 8; |
| 356 | return data; |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 359 | int mipi_dsi_panel_initialize(struct mipi_dsi_panel_config *pinfo) |
| 360 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 361 | unsigned char DMA_STREAM1 = 0; // for mdp display processor path |
| 362 | unsigned char EMBED_MODE1 = 1; // from frame buffer |
| 363 | unsigned char POWER_MODE2 = 1; // from frame buffer |
| 364 | unsigned char PACK_TYPE1 = 1; // long packet |
| 365 | unsigned char VC1 = 0; |
| 366 | unsigned char DT1 = 0; // non embedded mode |
| 367 | unsigned short WC1 = 0; // for non embedded mode only |
| 368 | int status = 0; |
| 369 | unsigned char DLNx_EN; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 370 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 371 | switch (pinfo->num_of_lanes) { |
| 372 | default: |
| 373 | case 1: |
| 374 | DLNx_EN = 1; // 1 lane |
| 375 | break; |
| 376 | case 2: |
| 377 | DLNx_EN = 3; // 2 lane |
| 378 | break; |
| 379 | case 3: |
| 380 | DLNx_EN = 7; // 3 lane |
| 381 | break; |
| 382 | } |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 383 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 384 | writel(0x0001, DSI_SOFT_RESET); |
| 385 | writel(0x0000, DSI_SOFT_RESET); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 386 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 387 | writel((0 << 16) | 0x3f, DSI_CLK_CTRL); /* Turn on all DSI Clks */ |
| 388 | writel(DMA_STREAM1 << 8 | 0x04, DSI_TRIG_CTRL); // reg 0x80 dma trigger: sw |
| 389 | // trigger 0x4; dma stream1 |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 390 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 391 | writel(0 << 30 | DLNx_EN << 4 | 0x105, DSI_CTRL); // reg 0x00 for this |
| 392 | // build |
| 393 | writel(EMBED_MODE1 << 28 | POWER_MODE2 << 26 |
| 394 | | PACK_TYPE1 << 24 | VC1 << 22 | DT1 << 16 | WC1, |
| 395 | DSI_COMMAND_MODE_DMA_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 396 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 397 | status = mipi_dsi_cmds_tx(pinfo->panel_cmds, pinfo->num_of_panel_cmds); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 398 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 399 | return status; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 402 | //TODO: Clean up arguments being passed in not being used |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 403 | int |
| 404 | config_dsi_video_mode(unsigned short disp_width, unsigned short disp_height, |
| 405 | unsigned short img_width, unsigned short img_height, |
| 406 | unsigned short hsync_porch0_fp, |
| 407 | unsigned short hsync_porch0_bp, |
| 408 | unsigned short vsync_porch0_fp, |
| 409 | unsigned short vsync_porch0_bp, |
| 410 | unsigned short hsync_width, |
| 411 | unsigned short vsync_width, unsigned short dst_format, |
| 412 | unsigned short traffic_mode, unsigned short datalane_num) |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 413 | { |
| 414 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 415 | unsigned char DST_FORMAT; |
| 416 | unsigned char TRAFIC_MODE; |
| 417 | unsigned char DLNx_EN; |
| 418 | // video mode data ctrl |
| 419 | int status = 0; |
| 420 | unsigned long low_pwr_stop_mode = 0; |
| 421 | unsigned char eof_bllp_pwr = 0x9; |
| 422 | unsigned char interleav = 0; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 423 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 424 | // disable mdp first |
| 425 | mdp_disable(); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 426 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 427 | writel(0x00000000, DSI_CLK_CTRL); |
| 428 | writel(0x00000000, DSI_CLK_CTRL); |
| 429 | writel(0x00000000, DSI_CLK_CTRL); |
| 430 | writel(0x00000000, DSI_CLK_CTRL); |
| 431 | writel(0x00000002, DSI_CLK_CTRL); |
| 432 | writel(0x00000006, DSI_CLK_CTRL); |
| 433 | writel(0x0000000e, DSI_CLK_CTRL); |
| 434 | writel(0x0000001e, DSI_CLK_CTRL); |
| 435 | writel(0x0000003e, DSI_CLK_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 436 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 437 | writel(0, DSI_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 438 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 439 | writel(0, DSI_ERR_INT_MASK0); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 440 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 441 | DST_FORMAT = 0; // RGB565 |
| 442 | dprintf(SPEW, "DSI_Video_Mode - Dst Format: RGB565\n"); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 443 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 444 | DLNx_EN = 1; // 1 lane with clk programming |
| 445 | dprintf(SPEW, "Data Lane: 1 lane\n"); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 446 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 447 | TRAFIC_MODE = 0; // non burst mode with sync pulses |
| 448 | dprintf(SPEW, "Traffic mode: non burst mode with sync pulses\n"); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 449 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 450 | writel(0x02020202, DSI_INT_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 451 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 452 | writel(((img_width + hsync_porch0_bp) << 16) | hsync_porch0_bp, |
| 453 | DSI_VIDEO_MODE_ACTIVE_H); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 454 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 455 | writel(((img_height + vsync_porch0_bp) << 16) | (vsync_porch0_bp), |
| 456 | DSI_VIDEO_MODE_ACTIVE_V); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 457 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 458 | writel(((img_height + vsync_porch0_fp + vsync_porch0_bp) << 16) |
| 459 | | img_width + hsync_porch0_fp + hsync_porch0_bp, |
| 460 | DSI_VIDEO_MODE_TOTAL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 461 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 462 | writel((hsync_width << 16) | 0, DSI_VIDEO_MODE_HSYNC); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 463 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 464 | writel(0 << 16 | 0, DSI_VIDEO_MODE_VSYNC); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 465 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 466 | writel(vsync_width << 16 | 0, DSI_VIDEO_MODE_VSYNC_VPOS); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 467 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 468 | writel(1, DSI_EOT_PACKET_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 469 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 470 | writel(0x00000100, DSI_MISR_VIDEO_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 471 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 472 | writel(low_pwr_stop_mode << 16 | eof_bllp_pwr << 12 | TRAFIC_MODE << 8 |
| 473 | | DST_FORMAT << 4 | 0x0, DSI_VIDEO_MODE_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 474 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 475 | writel(0x67, DSI_CAL_STRENGTH_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 476 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 477 | writel(0x80006711, DSI_CAL_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 478 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 479 | writel(0x00010100, DSI_MISR_VIDEO_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 480 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 481 | writel(0x00010100, DSI_INT_CTRL); |
| 482 | writel(0x02010202, DSI_INT_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 483 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 484 | writel(0x02030303, DSI_INT_CTRL); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 485 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 486 | writel(interleav << 30 | 0 << 24 | 0 << 20 | DLNx_EN << 4 |
| 487 | | 0x103, DSI_CTRL); |
| 488 | mdelay(10); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 489 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 490 | return status; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 493 | int |
| 494 | config_dsi_cmd_mode(unsigned short disp_width, unsigned short disp_height, |
| 495 | unsigned short img_width, unsigned short img_height, |
| 496 | unsigned short dst_format, |
| 497 | unsigned short traffic_mode, unsigned short datalane_num) |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 498 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 499 | unsigned char DST_FORMAT; |
| 500 | unsigned char TRAFIC_MODE; |
| 501 | unsigned char DLNx_EN; |
| 502 | // video mode data ctrl |
| 503 | int status = 0; |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 504 | unsigned char interleav = 0; |
| 505 | unsigned char ystride = 0x03; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 506 | // disable mdp first |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 507 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 508 | writel(0x00000000, DSI_CLK_CTRL); |
| 509 | writel(0x00000000, DSI_CLK_CTRL); |
| 510 | writel(0x00000000, DSI_CLK_CTRL); |
| 511 | writel(0x00000000, DSI_CLK_CTRL); |
| 512 | writel(0x00000002, DSI_CLK_CTRL); |
| 513 | writel(0x00000006, DSI_CLK_CTRL); |
| 514 | writel(0x0000000e, DSI_CLK_CTRL); |
| 515 | writel(0x0000001e, DSI_CLK_CTRL); |
| 516 | writel(0x0000003e, DSI_CLK_CTRL); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 517 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 518 | writel(0x10000000, DSI_ERR_INT_MASK0); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 519 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 520 | // writel(0, DSI_CTRL); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 521 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 522 | // writel(0, DSI_ERR_INT_MASK0); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 523 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 524 | DST_FORMAT = 8; // RGB888 |
| 525 | dprintf(SPEW, "DSI_Cmd_Mode - Dst Format: RGB888\n"); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 526 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 527 | DLNx_EN = 3; // 2 lane with clk programming |
| 528 | dprintf(SPEW, "Data Lane: 2 lane\n"); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 529 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 530 | TRAFIC_MODE = 0; // non burst mode with sync pulses |
| 531 | dprintf(SPEW, "Traffic mode: non burst mode with sync pulses\n"); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 532 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 533 | writel(0x02020202, DSI_INT_CTRL); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 534 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 535 | writel(0x00100000 | DST_FORMAT, DSI_COMMAND_MODE_MDP_CTRL); |
| 536 | writel((img_width * ystride + 1) << 16 | 0x0039, |
| 537 | DSI_COMMAND_MODE_MDP_STREAM0_CTRL); |
| 538 | writel((img_width * ystride + 1) << 16 | 0x0039, |
| 539 | DSI_COMMAND_MODE_MDP_STREAM1_CTRL); |
| 540 | writel(img_height << 16 | img_width, |
| 541 | DSI_COMMAND_MODE_MDP_STREAM0_TOTAL); |
| 542 | writel(img_height << 16 | img_width, |
| 543 | DSI_COMMAND_MODE_MDP_STREAM1_TOTAL); |
| 544 | writel(0xEE, DSI_CAL_STRENGTH_CTRL); |
| 545 | writel(0x80000000, DSI_CAL_CTRL); |
| 546 | writel(0x40, DSI_TRIG_CTRL); |
| 547 | writel(0x13c2c, DSI_COMMAND_MODE_MDP_DCS_CMD_CTRL); |
| 548 | writel(interleav << 30 | 0 << 24 | 0 << 20 | DLNx_EN << 4 | 0x105, |
| 549 | DSI_CTRL); |
| 550 | mdelay(10); |
| 551 | writel(0x10000000, DSI_COMMAND_MODE_DMA_CTRL); |
| 552 | writel(0x10000000, DSI_MISR_CMD_CTRL); |
| 553 | writel(0x00000040, DSI_ERR_INT_MASK0); |
| 554 | writel(0x1, DSI_EOT_PACKET_CTRL); |
| 555 | // writel(0x0, MDP_OVERLAYPROC0_START); |
| 556 | mdp_start_dma(); |
| 557 | mdelay(10); |
| 558 | writel(0x1, DSI_CMD_MODE_MDP_SW_TRIGGER); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 559 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 560 | status = 1; |
| 561 | return status; |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 564 | int mipi_dsi_video_config(unsigned short num_of_lanes) |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 565 | { |
| 566 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 567 | int status = 0; |
| 568 | unsigned long ReadValue; |
| 569 | unsigned long count = 0; |
| 570 | unsigned long low_pwr_stop_mode = 0; // low power mode 0x1111 start from |
| 571 | // bit16, high spd mode 0x0 |
| 572 | unsigned char eof_bllp_pwr = 0x9; // bit 12, 15, 1:low power stop mode or |
| 573 | // let cmd mode eng send packets in hs |
| 574 | // or lp mode |
| 575 | unsigned short image_wd = mipi_fb_cfg.width; |
| 576 | unsigned short image_ht = mipi_fb_cfg.height; |
Greg Grisco | 1073a5e | 2011-07-28 18:59:18 -0700 | [diff] [blame] | 577 | #if !DISPLAY_MIPI_PANEL_TOSHIBA_MDT61 |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 578 | unsigned short display_wd = mipi_fb_cfg.width; |
| 579 | unsigned short display_ht = mipi_fb_cfg.height; |
| 580 | unsigned short hsync_porch_fp = MIPI_HSYNC_FRONT_PORCH_DCLK; |
| 581 | unsigned short hsync_porch_bp = MIPI_HSYNC_BACK_PORCH_DCLK; |
| 582 | unsigned short vsync_porch_fp = MIPI_VSYNC_FRONT_PORCH_LINES; |
| 583 | unsigned short vsync_porch_bp = MIPI_VSYNC_BACK_PORCH_LINES; |
| 584 | unsigned short hsync_width = MIPI_HSYNC_PULSE_WIDTH; |
| 585 | unsigned short vsync_width = MIPI_VSYNC_PULSE_WIDTH; |
| 586 | unsigned short dst_format = 0; |
| 587 | unsigned short traffic_mode = 0; |
Greg Grisco | 1073a5e | 2011-07-28 18:59:18 -0700 | [diff] [blame] | 588 | #endif |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 589 | unsigned short pack_pattern = 0x12; //BGR |
| 590 | unsigned char ystride = 3; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 591 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 592 | low_pwr_stop_mode = 0x1111; // low pwr mode bit16:HSA, bit20:HBA, |
| 593 | // bit24:HFP, bit28:PULSE MODE, need enough |
| 594 | // time for swithc from LP to HS |
| 595 | eof_bllp_pwr = 0x9; // low power stop mode or let cmd mode eng send |
| 596 | // packets in hs or lp mode |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 597 | |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 598 | #if DISPLAY_MIPI_PANEL_TOSHIBA_MDT61 |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 599 | pack_pattern = 0x21; //RGB |
| 600 | config_mdt61_dsi_video_mode(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 601 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 602 | /* Two functions make up mdp_setup_dma_p_video_mode with mdt61 panel functions */ |
| 603 | mdp_setup_dma_p_video_config(pack_pattern, image_wd, image_ht, |
| 604 | MIPI_FB_ADDR, image_wd, ystride); |
| 605 | mdp_setup_mdt61_video_dsi_config(); |
Aparna Mallavarapu | f712f5e | 2011-08-04 21:11:00 +0530 | [diff] [blame] | 606 | #elif DISPLAY_MIPI_PANEL_RENESAS |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 607 | if (machine_is_7x25a()) { |
| 608 | display_wd = REN_MIPI_FB_WIDTH_HVGA; |
| 609 | display_ht = REN_MIPI_FB_HEIGHT_HVGA; |
| 610 | image_wd = REN_MIPI_FB_WIDTH_HVGA; |
| 611 | image_ht = REN_MIPI_FB_HEIGHT_HVGA; |
| 612 | hsync_porch_fp = MIPI_HSYNC_FRONT_PORCH_DCLK_HVGA; |
| 613 | hsync_porch_bp = MIPI_HSYNC_BACK_PORCH_DCLK_HVGA; |
| 614 | vsync_porch_fp = MIPI_VSYNC_FRONT_PORCH_LINES_HVGA; |
| 615 | vsync_porch_bp = MIPI_VSYNC_BACK_PORCH_LINES_HVGA; |
| 616 | hsync_width = MIPI_HSYNC_PULSE_WIDTH_HVGA; |
| 617 | vsync_width = MIPI_VSYNC_PULSE_WIDTH_HVGA; |
| 618 | } |
Aparna Mallavarapu | 45869c3 | 2011-08-05 13:22:35 +0530 | [diff] [blame] | 619 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 620 | pack_pattern = 0x21; //RGB |
| 621 | config_renesas_dsi_video_mode(); |
Aparna Mallavarapu | f712f5e | 2011-08-04 21:11:00 +0530 | [diff] [blame] | 622 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 623 | status += |
| 624 | mdp_setup_dma_p_video_mode(display_wd, display_ht, image_wd, |
| 625 | image_ht, hsync_porch_fp, hsync_porch_bp, |
| 626 | vsync_porch_fp, vsync_porch_bp, |
| 627 | hsync_width, vsync_width, MIPI_FB_ADDR, |
| 628 | image_wd, pack_pattern, ystride); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 629 | #else |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 630 | status += |
| 631 | config_dsi_video_mode(display_wd, display_ht, image_wd, image_ht, |
| 632 | hsync_porch_fp, hsync_porch_bp, |
| 633 | vsync_porch_fp, vsync_porch_bp, hsync_width, |
| 634 | vsync_width, dst_format, traffic_mode, |
| 635 | num_of_lanes); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 636 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 637 | status += |
| 638 | mdp_setup_dma_p_video_mode(display_wd, display_ht, image_wd, |
| 639 | image_ht, hsync_porch_fp, hsync_porch_bp, |
| 640 | vsync_porch_fp, vsync_porch_bp, |
| 641 | hsync_width, vsync_width, MIPI_FB_ADDR, |
| 642 | image_wd, pack_pattern, ystride); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 643 | #endif |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 644 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 645 | ReadValue = readl(DSI_INT_CTRL) & 0x00010000; |
| 646 | while (ReadValue != 0x00010000) { |
| 647 | ReadValue = readl(DSI_INT_CTRL) & 0x00010000; |
| 648 | count++; |
| 649 | if (count > 0xffff) { |
| 650 | status = FAIL; |
| 651 | dprintf(CRITICAL, "Video lane test failed\n"); |
| 652 | return status; |
| 653 | } |
| 654 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 655 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 656 | dprintf(SPEW, "Video lane tested successfully\n"); |
| 657 | return status; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 660 | int is_cmd_mode_enabled(void) |
| 661 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 662 | return cmd_mode_status; |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 665 | #if DISPLAY_MIPI_PANEL_NOVATEK_BLUE |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 666 | void mipi_dsi_cmd_mode_trigger(void) |
| 667 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 668 | int status = 0; |
| 669 | unsigned short display_wd = mipi_fb_cfg.width; |
| 670 | unsigned short display_ht = mipi_fb_cfg.height; |
| 671 | unsigned short image_wd = mipi_fb_cfg.width; |
| 672 | unsigned short image_ht = mipi_fb_cfg.height; |
| 673 | unsigned short dst_format = 0; |
| 674 | unsigned short traffic_mode = 0; |
| 675 | struct mipi_dsi_panel_config *panel_info = &novatek_panel_info; |
| 676 | status += mipi_dsi_cmd_config(mipi_fb_cfg, panel_info->num_of_lanes); |
| 677 | mdelay(50); |
| 678 | config_dsi_cmd_mode(display_wd, display_ht, image_wd, image_ht, |
| 679 | dst_format, traffic_mode, |
| 680 | panel_info->num_of_lanes /* num_of_lanes */ ); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 681 | } |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 682 | #endif |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 683 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 684 | void mipi_dsi_shutdown(void) |
| 685 | { |
Chandan Uddaraju | 4877d37 | 2011-07-21 12:51:51 -0700 | [diff] [blame^] | 686 | #if (!CONT_SPLASH_SCREEN) |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 687 | mdp_shutdown(); |
| 688 | writel(0x01010101, DSI_INT_CTRL); |
| 689 | writel(0x13FF3BFF, DSI_ERR_INT_MASK0); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 690 | #if DISPLAY_MIPI_PANEL_TOSHIBA_MDT61 |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 691 | /* Disable branch clocks */ |
Shashank Mittal | 3026290 | 2012-02-21 15:37:24 -0800 | [diff] [blame] | 692 | writel(0x0, DSI1_BYTE_CC_REG); |
| 693 | writel(0x0, DSI_PIXEL_CC_REG); |
| 694 | writel(0x0, DSI1_ESC_CC_REG); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 695 | /* Disable root clock */ |
| 696 | writel(0x0, DSI_CC_REG); |
Aparna Mallavarapu | f712f5e | 2011-08-04 21:11:00 +0530 | [diff] [blame] | 697 | #elif (!DISPLAY_MIPI_PANEL_RENESAS) |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 698 | secure_writel(0x0, DSI_CC_REG); |
Shashank Mittal | 3026290 | 2012-02-21 15:37:24 -0800 | [diff] [blame] | 699 | secure_writel(0x0, DSI_PIXEL_CC_REG); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 700 | #endif |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 701 | writel(0, DSI_CLK_CTRL); |
| 702 | writel(0, DSI_CTRL); |
| 703 | writel(0, DSIPHY_PLL_CTRL(0)); |
Chandan Uddaraju | 4877d37 | 2011-07-21 12:51:51 -0700 | [diff] [blame^] | 704 | #else |
| 705 | /* To keep the splash screen displayed till kernel driver takes |
| 706 | control, do not turn off the video mode engine and clocks. |
| 707 | Only disabling the MIPI DSI IRQs */ |
| 708 | writel(0x01010101, DSI_INT_CTRL); |
| 709 | writel(0x13FF3BFF, DSI_ERR_INT_MASK0); |
| 710 | #endif |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | struct fbcon_config *mipi_init(void) |
| 714 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 715 | int status = 0; |
| 716 | struct mipi_dsi_panel_config *panel_info = get_panel_info(); |
| 717 | /* Enable MMSS_AHB_ARB_MATER_PORT_E for arbiter master0 and master 1 request */ |
Aparna Mallavarapu | f712f5e | 2011-08-04 21:11:00 +0530 | [diff] [blame] | 718 | #if (!DISPLAY_MIPI_PANEL_RENESAS) |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 719 | writel(0x00001800, MMSS_SFPB_GPREG); |
Aparna Mallavarapu | f712f5e | 2011-08-04 21:11:00 +0530 | [diff] [blame] | 720 | #endif |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 721 | |
| 722 | #if DISPLAY_MIPI_PANEL_TOSHIBA_MDT61 |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 723 | mipi_dsi_phy_init(panel_info); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 724 | #else |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 725 | mipi_dsi_phy_ctrl_config(panel_info); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 726 | #endif |
| 727 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 728 | status += mipi_dsi_panel_initialize(panel_info); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 729 | |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 730 | #if DISPLAY_MIPI_PANEL_NOVATEK_BLUE |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 731 | mipi_dsi_cmd_bta_sw_trigger(); |
| 732 | mipi_novatek_manufacture_id(); |
Shashank Mittal | cbd271d | 2011-01-14 15:18:33 -0800 | [diff] [blame] | 733 | #endif |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 734 | mipi_fb_cfg.base = MIPI_FB_ADDR; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 735 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 736 | if (panel_info->mode == MIPI_VIDEO_MODE) |
| 737 | status += mipi_dsi_video_config(panel_info->num_of_lanes); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 738 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 739 | if (panel_info->mode == MIPI_CMD_MODE) |
| 740 | cmd_mode_status = 1; |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 741 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 742 | return &mipi_fb_cfg; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 743 | } |