Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 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> |
| 41 | |
| 42 | |
| 43 | /*---------------------------------------------------------------------------*/ |
| 44 | /* Panel Header */ |
| 45 | /*---------------------------------------------------------------------------*/ |
| 46 | #include "panel_display.h" |
| 47 | #include "include/panel.h" |
| 48 | |
| 49 | /*---------------------------------------------------------------------------*/ |
| 50 | /* Panel Init */ |
| 51 | /*---------------------------------------------------------------------------*/ |
| 52 | int dsi_panel_init(struct msm_panel_info *pinfo, |
| 53 | struct panel_struct *pstruct) |
| 54 | { |
| 55 | /* Resolution setting*/ |
| 56 | pinfo->xres = pstruct->panelres->panel_width; |
| 57 | pinfo->yres = pstruct->panelres->panel_height; |
| 58 | pinfo->lcdc.h_back_porch = pstruct->panelres->hback_porch; |
| 59 | pinfo->lcdc.h_front_porch = pstruct->panelres->hfront_porch; |
| 60 | pinfo->lcdc.h_pulse_width = pstruct->panelres->hpulse_width; |
| 61 | pinfo->lcdc.v_back_porch = pstruct->panelres->vback_porch; |
| 62 | pinfo->lcdc.v_front_porch = pstruct->panelres->vfront_porch; |
| 63 | pinfo->lcdc.v_pulse_width = pstruct->panelres->vpulse_width; |
| 64 | pinfo->lcdc.hsync_skew = pstruct->panelres->hsync_skew; |
| 65 | pinfo->lcdc.xres_pad = pstruct->panelres->hleft_border + |
| 66 | pstruct->panelres->hright_border; |
| 67 | pinfo->lcdc.yres_pad = pstruct->panelres->vtop_border + |
| 68 | pstruct->panelres->vbottom_border; |
| 69 | |
Dhaval Patel | ee8675a | 2013-10-25 10:07:57 -0700 | [diff] [blame] | 70 | if (pstruct->paneldata->panel_operating_mode & DUAL_PIPE_FLAG) |
| 71 | pinfo->lcdc.dual_pipe = 1; |
| 72 | if (pstruct->paneldata->panel_operating_mode & PIPE_SWAP_FLAG) |
| 73 | pinfo->lcdc.pipe_swap = 1; |
| 74 | if (pstruct->paneldata->panel_operating_mode & SPLIT_DISPLAY_FLAG) |
| 75 | pinfo->lcdc.split_display = 1; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 76 | |
| 77 | /* Color setting*/ |
| 78 | pinfo->lcdc.border_clr = pstruct->color->border_color; |
| 79 | pinfo->lcdc.underflow_clr = pstruct->color->underflow_color; |
| 80 | pinfo->mipi.rgb_swap = pstruct->color->color_order; |
| 81 | switch (pinfo->bpp) { |
| 82 | case BPP_16: |
| 83 | pinfo->mipi.dst_format = DSI_VIDEO_DST_FORMAT_RGB565; |
| 84 | break; |
| 85 | case BPP_18: |
| 86 | if (pstruct->color->pixel_packing) |
| 87 | pinfo->mipi.dst_format |
| 88 | = DSI_VIDEO_DST_FORMAT_RGB666_LOOSE; |
| 89 | else |
| 90 | pinfo->mipi.dst_format |
| 91 | = DSI_VIDEO_DST_FORMAT_RGB666; |
| 92 | break; |
| 93 | case BPP_24: |
| 94 | default: |
| 95 | pinfo->mipi.dst_format = DSI_VIDEO_DST_FORMAT_RGB888; |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | /* Panel generic info */ |
| 100 | pinfo->mipi.mode = pstruct->paneldata->panel_type; |
| 101 | if (pinfo->mipi.mode) { |
| 102 | pinfo->type = MIPI_CMD_PANEL; |
| 103 | } else { |
| 104 | pinfo->type = MIPI_VIDEO_PANEL; |
| 105 | } |
| 106 | pinfo->bpp = pstruct->color->color_format; |
| 107 | pinfo->clk_rate = pstruct->paneldata->panel_clockrate; |
| 108 | pinfo->rotation = pstruct->paneldata->panel_orientation; |
| 109 | pinfo->mipi.interleave_mode = pstruct->paneldata->interleave_mode; |
Dhaval Patel | ee8675a | 2013-10-25 10:07:57 -0700 | [diff] [blame] | 110 | pinfo->mipi.broadcast = pstruct->paneldata->panel_broadcast_mode; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 111 | pinfo->lowpowerstop = pstruct->paneldata->dsi_lp11_atinit; |
| 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 | ee8675a | 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; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 119 | |
| 120 | /* Video Panel configuration */ |
| 121 | pinfo->mipi.pulse_mode_hsa_he = pstruct->videopanel->hsync_pulse; |
| 122 | pinfo->mipi.hfp_power_stop = pstruct->videopanel->hfp_power_mode; |
| 123 | pinfo->mipi.hbp_power_stop = pstruct->videopanel->hbp_power_mode; |
| 124 | pinfo->mipi.hsa_power_stop = pstruct->videopanel->hsa_power_mode; |
| 125 | pinfo->mipi.eof_bllp_power_stop |
| 126 | = pstruct->videopanel->bllp_eof_power_mode; |
| 127 | pinfo->mipi.bllp_power_stop = pstruct->videopanel->bllp_power_mode; |
| 128 | pinfo->mipi.traffic_mode = pstruct->videopanel->traffic_mode; |
| 129 | pinfo->mipi.eof_bllp_power = pstruct->videopanel->bllp_eof_power; |
| 130 | |
| 131 | /* Command Panel configuratoin */ |
| 132 | pinfo->mipi.insert_dcs_cmd = pstruct->commandpanel->tedcs_command; |
| 133 | pinfo->mipi.wr_mem_continue |
| 134 | = pstruct->commandpanel->tevsync_continue_lines; |
| 135 | pinfo->mipi.wr_mem_start |
| 136 | = pstruct->commandpanel->tevsync_rdptr_irqline; |
| 137 | pinfo->mipi.te_sel = pstruct->commandpanel->tepin_select; |
| 138 | |
| 139 | /* Data lane configuraiton */ |
| 140 | pinfo->mipi.num_of_lanes = pstruct->laneconfig->dsi_lanes; |
| 141 | pinfo->mipi.data_lane0 = pstruct->laneconfig->lane0_state; |
| 142 | pinfo->mipi.data_lane1 = pstruct->laneconfig->lane1_state; |
| 143 | pinfo->mipi.data_lane2 = pstruct->laneconfig->lane2_state; |
| 144 | pinfo->mipi.data_lane3 = pstruct->laneconfig->lane3_state; |
| 145 | pinfo->mipi.lane_swap = pstruct->laneconfig->dsi_lanemap; |
| 146 | |
| 147 | pinfo->mipi.t_clk_post = pstruct->paneltiminginfo->tclk_post; |
| 148 | pinfo->mipi.t_clk_pre = pstruct->paneltiminginfo->tclk_pre; |
| 149 | pinfo->mipi.mdp_trigger = pstruct->paneltiminginfo->dsi_mdp_trigger; |
| 150 | pinfo->mipi.dma_trigger = pstruct->paneltiminginfo->dsi_dma_trigger; |
| 151 | |
Dhaval Patel | b22f1bc | 2013-10-25 13:56:26 -0700 | [diff] [blame^] | 152 | pinfo->pre_on = dsi_panel_pre_on; |
| 153 | pinfo->pre_off = dsi_panel_pre_off; |
| 154 | pinfo->on = dsi_panel_post_on; |
| 155 | pinfo->off = dsi_panel_post_off; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 156 | pinfo->rotate = dsi_panel_rotation; |
| 157 | pinfo->config = dsi_panel_config; |
| 158 | |
| 159 | return NO_ERROR; |
| 160 | } |
| 161 | |
| 162 | /*---------------------------------------------------------------------------*/ |
| 163 | /* Panel Callbacks */ |
| 164 | /*---------------------------------------------------------------------------*/ |
| 165 | |
Dhaval Patel | b22f1bc | 2013-10-25 13:56:26 -0700 | [diff] [blame^] | 166 | int dsi_panel_pre_on() |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 167 | { |
Dhaval Patel | b22f1bc | 2013-10-25 13:56:26 -0700 | [diff] [blame^] | 168 | return target_display_pre_on(); |
| 169 | } |
| 170 | |
| 171 | int dsi_panel_pre_off() |
| 172 | { |
| 173 | return target_display_pre_off(); |
| 174 | } |
| 175 | |
| 176 | int dsi_panel_post_on() |
| 177 | { |
| 178 | int ret = NO_ERROR; |
| 179 | |
| 180 | ret = target_display_post_on(); |
| 181 | if (ret) |
| 182 | return ret; |
| 183 | |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 184 | return oem_panel_on(); |
| 185 | } |
| 186 | |
Dhaval Patel | b22f1bc | 2013-10-25 13:56:26 -0700 | [diff] [blame^] | 187 | int dsi_panel_post_off() |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 188 | { |
Dhaval Patel | b22f1bc | 2013-10-25 13:56:26 -0700 | [diff] [blame^] | 189 | int ret = NO_ERROR; |
| 190 | |
| 191 | ret = target_display_post_off(); |
| 192 | if (ret) |
| 193 | return ret; |
| 194 | |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 195 | return oem_panel_off(); |
| 196 | } |
| 197 | |
| 198 | int dsi_panel_rotation() |
| 199 | { |
| 200 | return oem_panel_rotation(); |
| 201 | } |
| 202 | |
| 203 | int dsi_video_panel_config(struct msm_panel_info *pinfo, |
| 204 | struct lcdc_panel_info *plcdc |
| 205 | ) |
| 206 | { |
| 207 | int ret = NO_ERROR; |
| 208 | uint8_t lane_enable = 0; |
| 209 | uint32_t panel_width = pinfo->xres; |
| 210 | |
| 211 | if (pinfo->mipi.dual_dsi) |
| 212 | panel_width = panel_width / 2; |
| 213 | |
Xiaoming Zhou | 7e0b1e6 | 2013-07-29 15:49:39 -0400 | [diff] [blame] | 214 | if (pinfo->mipi.data_lane0) |
| 215 | lane_enable |= (1 << 0); |
| 216 | if (pinfo->mipi.data_lane1) |
| 217 | lane_enable |= (1 << 1); |
| 218 | if (pinfo->mipi.data_lane2) |
| 219 | lane_enable |= (1 << 2); |
| 220 | if (pinfo->mipi.data_lane3) |
| 221 | lane_enable |= (1 << 3); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 222 | |
| 223 | ret = mdss_dsi_video_mode_config((panel_width + plcdc->xres_pad), |
| 224 | (pinfo->yres + plcdc->yres_pad), |
| 225 | (panel_width), |
| 226 | (pinfo->yres), |
| 227 | (plcdc->h_front_porch), |
| 228 | (plcdc->h_back_porch + plcdc->h_pulse_width), |
| 229 | (plcdc->v_front_porch), |
| 230 | (plcdc->v_back_porch + plcdc->v_pulse_width), |
| 231 | (plcdc->h_pulse_width), |
| 232 | (plcdc->v_pulse_width), |
| 233 | pinfo->mipi.dst_format, |
| 234 | pinfo->mipi.traffic_mode, |
| 235 | lane_enable, |
| 236 | pinfo->lowpowerstop, |
| 237 | pinfo->mipi.eof_bllp_power, |
| 238 | pinfo->mipi.interleave_mode, |
| 239 | MIPI_DSI0_BASE); |
| 240 | |
| 241 | if (pinfo->mipi.dual_dsi) |
| 242 | ret = mdss_dsi_video_mode_config( |
| 243 | (panel_width + plcdc->xres_pad), |
| 244 | (pinfo->yres + plcdc->yres_pad), |
| 245 | (panel_width), |
| 246 | (pinfo->yres), |
| 247 | (plcdc->h_front_porch), |
| 248 | (plcdc->h_back_porch + plcdc->h_pulse_width), |
| 249 | (plcdc->v_front_porch), |
| 250 | (plcdc->v_back_porch + plcdc->v_pulse_width), |
| 251 | (plcdc->h_pulse_width), |
| 252 | (plcdc->v_pulse_width), |
| 253 | pinfo->mipi.dst_format, |
| 254 | pinfo->mipi.traffic_mode, |
| 255 | lane_enable, |
| 256 | pinfo->lowpowerstop, |
| 257 | pinfo->mipi.eof_bllp_power, |
| 258 | pinfo->mipi.interleave_mode, |
| 259 | MIPI_DSI1_BASE); |
| 260 | |
| 261 | return ret; |
| 262 | } |
| 263 | |
| 264 | int dsi_cmd_panel_config (struct msm_panel_info *pinfo, |
| 265 | struct lcdc_panel_info *plcdc) |
| 266 | { |
| 267 | int ret = NO_ERROR; |
Xiaoming Zhou | 7e0b1e6 | 2013-07-29 15:49:39 -0400 | [diff] [blame] | 268 | uint8_t lane_en = 0; |
| 269 | uint8_t ystride = pinfo->bpp / 8; |
| 270 | |
| 271 | if (pinfo->mipi.data_lane0) |
| 272 | lane_en |= (1 << 0); |
| 273 | if (pinfo->mipi.data_lane1) |
| 274 | lane_en |= (1 << 1); |
| 275 | if (pinfo->mipi.data_lane2) |
| 276 | lane_en |= (1 << 2); |
| 277 | if (pinfo->mipi.data_lane3) |
| 278 | lane_en |= (1 << 3); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 279 | |
| 280 | ret = mdss_dsi_cmd_mode_config((pinfo->xres + plcdc->xres_pad), |
| 281 | (pinfo->yres + plcdc->yres_pad), |
| 282 | (pinfo->xres), (pinfo->yres), |
Xiaoming Zhou | 7e0b1e6 | 2013-07-29 15:49:39 -0400 | [diff] [blame] | 283 | pinfo->mipi.dst_format, |
| 284 | ystride, lane_en, |
| 285 | pinfo->mipi.interleave_mode); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 286 | |
| 287 | return ret; |
| 288 | } |
| 289 | |
| 290 | |
| 291 | int dsi_panel_config(void *pdata) |
| 292 | { |
| 293 | int ret = NO_ERROR; |
| 294 | struct msm_panel_info *pinfo = (struct msm_panel_info *)pdata; |
| 295 | struct lcdc_panel_info *plcdc = NULL; |
| 296 | |
| 297 | if (pinfo == NULL) |
| 298 | return ERR_INVALID_ARGS; |
| 299 | |
| 300 | plcdc = &(pinfo->lcdc); |
| 301 | if (plcdc == NULL) |
| 302 | return ERR_INVALID_ARGS; |
| 303 | |
| 304 | |
| 305 | if (pinfo->mipi.mode == DSI_VIDEO_MODE) { |
| 306 | ret = dsi_video_panel_config(pinfo, plcdc); |
| 307 | } else { |
| 308 | ret = dsi_cmd_panel_config(pinfo, plcdc); |
| 309 | } |
| 310 | |
| 311 | return ret; |
| 312 | } |