Dhaval Patel | 1f95251 | 2014-01-02 16:17:26 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -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 The Linux Foundation 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 | /*---------------------------------------------------------------------------*/ |
| 31 | /* HEADER files */ |
| 32 | /*---------------------------------------------------------------------------*/ |
| 33 | #include <stdint.h> |
| 34 | #include <msm_panel.h> |
| 35 | #include <mipi_dsi.h> |
| 36 | #include <sys/types.h> |
| 37 | #include <platform/iomap.h> |
| 38 | #include <err.h> |
| 39 | #include <reg.h> |
| 40 | #include <mdp5.h> |
Dhaval Patel | 920d918 | 2014-02-18 17:13:00 -0800 | [diff] [blame] | 41 | #include <string.h> |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 42 | |
| 43 | |
| 44 | /*---------------------------------------------------------------------------*/ |
| 45 | /* Panel Header */ |
| 46 | /*---------------------------------------------------------------------------*/ |
| 47 | #include "panel_display.h" |
| 48 | #include "include/panel.h" |
| 49 | |
| 50 | /*---------------------------------------------------------------------------*/ |
| 51 | /* Panel Init */ |
| 52 | /*---------------------------------------------------------------------------*/ |
| 53 | int dsi_panel_init(struct msm_panel_info *pinfo, |
| 54 | struct panel_struct *pstruct) |
| 55 | { |
| 56 | /* Resolution setting*/ |
| 57 | pinfo->xres = pstruct->panelres->panel_width; |
| 58 | pinfo->yres = pstruct->panelres->panel_height; |
| 59 | pinfo->lcdc.h_back_porch = pstruct->panelres->hback_porch; |
| 60 | pinfo->lcdc.h_front_porch = pstruct->panelres->hfront_porch; |
| 61 | pinfo->lcdc.h_pulse_width = pstruct->panelres->hpulse_width; |
| 62 | pinfo->lcdc.v_back_porch = pstruct->panelres->vback_porch; |
| 63 | pinfo->lcdc.v_front_porch = pstruct->panelres->vfront_porch; |
| 64 | pinfo->lcdc.v_pulse_width = pstruct->panelres->vpulse_width; |
| 65 | pinfo->lcdc.hsync_skew = pstruct->panelres->hsync_skew; |
| 66 | pinfo->lcdc.xres_pad = pstruct->panelres->hleft_border + |
| 67 | pstruct->panelres->hright_border; |
| 68 | pinfo->lcdc.yres_pad = pstruct->panelres->vtop_border + |
| 69 | pstruct->panelres->vbottom_border; |
| 70 | |
Dhaval Patel | ad15209 | 2013-10-25 10:07:57 -0700 | [diff] [blame] | 71 | if (pstruct->paneldata->panel_operating_mode & DUAL_PIPE_FLAG) |
| 72 | pinfo->lcdc.dual_pipe = 1; |
| 73 | if (pstruct->paneldata->panel_operating_mode & PIPE_SWAP_FLAG) |
| 74 | pinfo->lcdc.pipe_swap = 1; |
| 75 | if (pstruct->paneldata->panel_operating_mode & SPLIT_DISPLAY_FLAG) |
| 76 | pinfo->lcdc.split_display = 1; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 77 | |
| 78 | /* Color setting*/ |
| 79 | pinfo->lcdc.border_clr = pstruct->color->border_color; |
| 80 | pinfo->lcdc.underflow_clr = pstruct->color->underflow_color; |
| 81 | pinfo->mipi.rgb_swap = pstruct->color->color_order; |
| 82 | switch (pinfo->bpp) { |
| 83 | case BPP_16: |
| 84 | pinfo->mipi.dst_format = DSI_VIDEO_DST_FORMAT_RGB565; |
| 85 | break; |
| 86 | case BPP_18: |
| 87 | if (pstruct->color->pixel_packing) |
| 88 | pinfo->mipi.dst_format |
| 89 | = DSI_VIDEO_DST_FORMAT_RGB666_LOOSE; |
| 90 | else |
| 91 | pinfo->mipi.dst_format |
| 92 | = DSI_VIDEO_DST_FORMAT_RGB666; |
| 93 | break; |
| 94 | case BPP_24: |
| 95 | default: |
| 96 | pinfo->mipi.dst_format = DSI_VIDEO_DST_FORMAT_RGB888; |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | /* Panel generic info */ |
| 101 | pinfo->mipi.mode = pstruct->paneldata->panel_type; |
| 102 | if (pinfo->mipi.mode) { |
| 103 | pinfo->type = MIPI_CMD_PANEL; |
| 104 | } else { |
| 105 | pinfo->type = MIPI_VIDEO_PANEL; |
| 106 | } |
| 107 | pinfo->bpp = pstruct->color->color_format; |
| 108 | pinfo->clk_rate = pstruct->paneldata->panel_clockrate; |
| 109 | pinfo->rotation = pstruct->paneldata->panel_orientation; |
| 110 | pinfo->mipi.interleave_mode = pstruct->paneldata->interleave_mode; |
Dhaval Patel | ad15209 | 2013-10-25 10:07:57 -0700 | [diff] [blame] | 111 | pinfo->mipi.broadcast = pstruct->paneldata->panel_broadcast_mode; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 112 | pinfo->mipi.vc = pstruct->paneldata->dsi_virtualchannel_id; |
| 113 | pinfo->mipi.frame_rate = pstruct->paneldata->panel_framerate; |
| 114 | pinfo->mipi.stream = pstruct->paneldata->dsi_stream; |
Dhaval Patel | ad15209 | 2013-10-25 10:07:57 -0700 | [diff] [blame] | 115 | if (pstruct->paneldata->panel_operating_mode & DUAL_DSI_FLAG) |
| 116 | pinfo->mipi.dual_dsi = 1; |
Dhaval Patel | 29f2449 | 2013-08-08 20:45:42 -0700 | [diff] [blame] | 117 | pinfo->mipi.mode_gpio_state = pstruct->paneldata->mode_gpio_state; |
Arpita Banerjee | da0c39a | 2013-05-24 16:12:45 -0700 | [diff] [blame] | 118 | pinfo->mipi.bitclock = pstruct->paneldata->panel_bitclock_freq; |
Aravind Venkateswaran | 1f3ad73 | 2013-11-04 17:32:14 -0800 | [diff] [blame] | 119 | pinfo->mipi.use_enable_gpio = |
| 120 | pstruct->paneldata->panel_with_enable_gpio; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 121 | |
| 122 | /* Video Panel configuration */ |
| 123 | pinfo->mipi.pulse_mode_hsa_he = pstruct->videopanel->hsync_pulse; |
| 124 | pinfo->mipi.hfp_power_stop = pstruct->videopanel->hfp_power_mode; |
| 125 | pinfo->mipi.hbp_power_stop = pstruct->videopanel->hbp_power_mode; |
| 126 | pinfo->mipi.hsa_power_stop = pstruct->videopanel->hsa_power_mode; |
| 127 | pinfo->mipi.eof_bllp_power_stop |
| 128 | = pstruct->videopanel->bllp_eof_power_mode; |
| 129 | pinfo->mipi.bllp_power_stop = pstruct->videopanel->bllp_power_mode; |
| 130 | pinfo->mipi.traffic_mode = pstruct->videopanel->traffic_mode; |
| 131 | pinfo->mipi.eof_bllp_power = pstruct->videopanel->bllp_eof_power; |
| 132 | |
| 133 | /* Command Panel configuratoin */ |
| 134 | pinfo->mipi.insert_dcs_cmd = pstruct->commandpanel->tedcs_command; |
| 135 | pinfo->mipi.wr_mem_continue |
| 136 | = pstruct->commandpanel->tevsync_continue_lines; |
| 137 | pinfo->mipi.wr_mem_start |
| 138 | = pstruct->commandpanel->tevsync_rdptr_irqline; |
| 139 | pinfo->mipi.te_sel = pstruct->commandpanel->tepin_select; |
| 140 | |
| 141 | /* Data lane configuraiton */ |
| 142 | pinfo->mipi.num_of_lanes = pstruct->laneconfig->dsi_lanes; |
| 143 | pinfo->mipi.data_lane0 = pstruct->laneconfig->lane0_state; |
| 144 | pinfo->mipi.data_lane1 = pstruct->laneconfig->lane1_state; |
| 145 | pinfo->mipi.data_lane2 = pstruct->laneconfig->lane2_state; |
| 146 | pinfo->mipi.data_lane3 = pstruct->laneconfig->lane3_state; |
| 147 | pinfo->mipi.lane_swap = pstruct->laneconfig->dsi_lanemap; |
| 148 | |
| 149 | pinfo->mipi.t_clk_post = pstruct->paneltiminginfo->tclk_post; |
| 150 | pinfo->mipi.t_clk_pre = pstruct->paneltiminginfo->tclk_pre; |
| 151 | pinfo->mipi.mdp_trigger = pstruct->paneltiminginfo->dsi_mdp_trigger; |
| 152 | pinfo->mipi.dma_trigger = pstruct->paneltiminginfo->dsi_dma_trigger; |
| 153 | |
Dhaval Patel | 430f8ec | 2013-10-25 13:56:26 -0700 | [diff] [blame] | 154 | pinfo->pre_on = dsi_panel_pre_on; |
| 155 | pinfo->pre_off = dsi_panel_pre_off; |
| 156 | pinfo->on = dsi_panel_post_on; |
| 157 | pinfo->off = dsi_panel_post_off; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 158 | pinfo->rotate = dsi_panel_rotation; |
| 159 | pinfo->config = dsi_panel_config; |
| 160 | |
| 161 | return NO_ERROR; |
| 162 | } |
| 163 | |
| 164 | /*---------------------------------------------------------------------------*/ |
| 165 | /* Panel Callbacks */ |
| 166 | /*---------------------------------------------------------------------------*/ |
| 167 | |
Dhaval Patel | 430f8ec | 2013-10-25 13:56:26 -0700 | [diff] [blame] | 168 | int dsi_panel_pre_on() |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 169 | { |
Dhaval Patel | 430f8ec | 2013-10-25 13:56:26 -0700 | [diff] [blame] | 170 | return target_display_pre_on(); |
| 171 | } |
| 172 | |
| 173 | int dsi_panel_pre_off() |
| 174 | { |
| 175 | return target_display_pre_off(); |
| 176 | } |
| 177 | |
| 178 | int dsi_panel_post_on() |
| 179 | { |
| 180 | int ret = NO_ERROR; |
| 181 | |
| 182 | ret = target_display_post_on(); |
| 183 | if (ret) |
| 184 | return ret; |
| 185 | |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 186 | return oem_panel_on(); |
| 187 | } |
| 188 | |
Dhaval Patel | 430f8ec | 2013-10-25 13:56:26 -0700 | [diff] [blame] | 189 | int dsi_panel_post_off() |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 190 | { |
Dhaval Patel | 430f8ec | 2013-10-25 13:56:26 -0700 | [diff] [blame] | 191 | int ret = NO_ERROR; |
| 192 | |
| 193 | ret = target_display_post_off(); |
| 194 | if (ret) |
| 195 | return ret; |
| 196 | |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 197 | return oem_panel_off(); |
| 198 | } |
| 199 | |
| 200 | int dsi_panel_rotation() |
| 201 | { |
| 202 | return oem_panel_rotation(); |
| 203 | } |
| 204 | |
| 205 | int dsi_video_panel_config(struct msm_panel_info *pinfo, |
| 206 | struct lcdc_panel_info *plcdc |
| 207 | ) |
| 208 | { |
| 209 | int ret = NO_ERROR; |
| 210 | uint8_t lane_enable = 0; |
| 211 | uint32_t panel_width = pinfo->xres; |
| 212 | |
| 213 | if (pinfo->mipi.dual_dsi) |
| 214 | panel_width = panel_width / 2; |
| 215 | |
Xiaoming Zhou | 7e0b1e6 | 2013-07-29 15:49:39 -0400 | [diff] [blame] | 216 | if (pinfo->mipi.data_lane0) |
| 217 | lane_enable |= (1 << 0); |
| 218 | if (pinfo->mipi.data_lane1) |
| 219 | lane_enable |= (1 << 1); |
| 220 | if (pinfo->mipi.data_lane2) |
| 221 | lane_enable |= (1 << 2); |
| 222 | if (pinfo->mipi.data_lane3) |
| 223 | lane_enable |= (1 << 3); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 224 | |
| 225 | ret = mdss_dsi_video_mode_config((panel_width + plcdc->xres_pad), |
| 226 | (pinfo->yres + plcdc->yres_pad), |
| 227 | (panel_width), |
| 228 | (pinfo->yres), |
| 229 | (plcdc->h_front_porch), |
| 230 | (plcdc->h_back_porch + plcdc->h_pulse_width), |
| 231 | (plcdc->v_front_porch), |
| 232 | (plcdc->v_back_porch + plcdc->v_pulse_width), |
| 233 | (plcdc->h_pulse_width), |
| 234 | (plcdc->v_pulse_width), |
| 235 | pinfo->mipi.dst_format, |
| 236 | pinfo->mipi.traffic_mode, |
| 237 | lane_enable, |
Dhaval Patel | 72cc193 | 2014-01-06 15:20:01 -0800 | [diff] [blame] | 238 | pinfo->mipi.hsa_power_stop, |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 239 | pinfo->mipi.eof_bllp_power, |
| 240 | pinfo->mipi.interleave_mode, |
| 241 | MIPI_DSI0_BASE); |
| 242 | |
| 243 | if (pinfo->mipi.dual_dsi) |
| 244 | ret = mdss_dsi_video_mode_config( |
| 245 | (panel_width + plcdc->xres_pad), |
| 246 | (pinfo->yres + plcdc->yres_pad), |
| 247 | (panel_width), |
| 248 | (pinfo->yres), |
| 249 | (plcdc->h_front_porch), |
| 250 | (plcdc->h_back_porch + plcdc->h_pulse_width), |
| 251 | (plcdc->v_front_porch), |
| 252 | (plcdc->v_back_porch + plcdc->v_pulse_width), |
| 253 | (plcdc->h_pulse_width), |
| 254 | (plcdc->v_pulse_width), |
| 255 | pinfo->mipi.dst_format, |
| 256 | pinfo->mipi.traffic_mode, |
| 257 | lane_enable, |
Dhaval Patel | 72cc193 | 2014-01-06 15:20:01 -0800 | [diff] [blame] | 258 | pinfo->mipi.hsa_power_stop, |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 259 | pinfo->mipi.eof_bllp_power, |
| 260 | pinfo->mipi.interleave_mode, |
| 261 | MIPI_DSI1_BASE); |
| 262 | |
| 263 | return ret; |
| 264 | } |
| 265 | |
| 266 | int dsi_cmd_panel_config (struct msm_panel_info *pinfo, |
| 267 | struct lcdc_panel_info *plcdc) |
| 268 | { |
| 269 | int ret = NO_ERROR; |
Xiaoming Zhou | 7e0b1e6 | 2013-07-29 15:49:39 -0400 | [diff] [blame] | 270 | uint8_t lane_en = 0; |
| 271 | uint8_t ystride = pinfo->bpp / 8; |
Dhaval Patel | 1f95251 | 2014-01-02 16:17:26 -0800 | [diff] [blame] | 272 | uint32_t panel_width = pinfo->xres; |
| 273 | |
| 274 | if (pinfo->mipi.dual_dsi) |
| 275 | panel_width = panel_width / 2; |
Xiaoming Zhou | 7e0b1e6 | 2013-07-29 15:49:39 -0400 | [diff] [blame] | 276 | |
| 277 | if (pinfo->mipi.data_lane0) |
| 278 | lane_en |= (1 << 0); |
| 279 | if (pinfo->mipi.data_lane1) |
| 280 | lane_en |= (1 << 1); |
| 281 | if (pinfo->mipi.data_lane2) |
| 282 | lane_en |= (1 << 2); |
| 283 | if (pinfo->mipi.data_lane3) |
| 284 | lane_en |= (1 << 3); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 285 | |
Dhaval Patel | 1f95251 | 2014-01-02 16:17:26 -0800 | [diff] [blame] | 286 | ret = mdss_dsi_cmd_mode_config((panel_width + plcdc->xres_pad), |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 287 | (pinfo->yres + plcdc->yres_pad), |
Dhaval Patel | 1f95251 | 2014-01-02 16:17:26 -0800 | [diff] [blame] | 288 | panel_width, (pinfo->yres), |
Xiaoming Zhou | 7e0b1e6 | 2013-07-29 15:49:39 -0400 | [diff] [blame] | 289 | pinfo->mipi.dst_format, |
| 290 | ystride, lane_en, |
Dhaval Patel | 1f95251 | 2014-01-02 16:17:26 -0800 | [diff] [blame] | 291 | pinfo->mipi.interleave_mode, |
| 292 | MIPI_DSI0_BASE); |
| 293 | |
| 294 | if (pinfo->mipi.dual_dsi) |
| 295 | ret = mdss_dsi_cmd_mode_config((panel_width + plcdc->xres_pad), |
| 296 | (pinfo->yres + plcdc->yres_pad), |
| 297 | panel_width, (pinfo->yres), |
| 298 | pinfo->mipi.dst_format, |
| 299 | ystride, lane_en, |
| 300 | pinfo->mipi.interleave_mode, |
| 301 | MIPI_DSI1_BASE); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 302 | |
| 303 | return ret; |
| 304 | } |
| 305 | |
| 306 | |
| 307 | int dsi_panel_config(void *pdata) |
| 308 | { |
| 309 | int ret = NO_ERROR; |
| 310 | struct msm_panel_info *pinfo = (struct msm_panel_info *)pdata; |
| 311 | struct lcdc_panel_info *plcdc = NULL; |
| 312 | |
| 313 | if (pinfo == NULL) |
| 314 | return ERR_INVALID_ARGS; |
| 315 | |
| 316 | plcdc = &(pinfo->lcdc); |
| 317 | if (plcdc == NULL) |
| 318 | return ERR_INVALID_ARGS; |
| 319 | |
| 320 | |
| 321 | if (pinfo->mipi.mode == DSI_VIDEO_MODE) { |
| 322 | ret = dsi_video_panel_config(pinfo, plcdc); |
| 323 | } else { |
| 324 | ret = dsi_cmd_panel_config(pinfo, plcdc); |
| 325 | } |
| 326 | |
| 327 | return ret; |
| 328 | } |
Dhaval Patel | 920d918 | 2014-02-18 17:13:00 -0800 | [diff] [blame] | 329 | |
| 330 | int32_t panel_name_to_id(struct panel_list supp_panels[], |
| 331 | uint32_t supp_panels_size, |
| 332 | const char *panel_name) |
| 333 | { |
| 334 | uint32_t i; |
| 335 | int32_t panel_id = ERR_NOT_FOUND; |
| 336 | |
| 337 | if (!panel_name) { |
| 338 | dprintf(CRITICAL, "Invalid panel name\n"); |
| 339 | return panel_id; |
| 340 | } |
| 341 | |
| 342 | /* Remove any leading whitespaces */ |
| 343 | panel_name += strspn(panel_name, " "); |
| 344 | for (i = 0; i < supp_panels_size; i++) { |
| 345 | if (!strncmp(panel_name, supp_panels[i].name, |
| 346 | MAX_PANEL_ID_LEN)) { |
| 347 | panel_id = supp_panels[i].id; |
| 348 | break; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | return panel_id; |
| 353 | } |