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 | |
| 70 | pinfo->lcdc.dual_pipe = (pstruct->paneldata->panel_operating_mode |
| 71 | & 0x2); |
| 72 | pinfo->lcdc.pipe_swap = (pstruct->paneldata->panel_operating_mode |
| 73 | & 0x4); |
| 74 | |
| 75 | /* Color setting*/ |
| 76 | pinfo->lcdc.border_clr = pstruct->color->border_color; |
| 77 | pinfo->lcdc.underflow_clr = pstruct->color->underflow_color; |
| 78 | pinfo->mipi.rgb_swap = pstruct->color->color_order; |
| 79 | switch (pinfo->bpp) { |
| 80 | case BPP_16: |
| 81 | pinfo->mipi.dst_format = DSI_VIDEO_DST_FORMAT_RGB565; |
| 82 | break; |
| 83 | case BPP_18: |
| 84 | if (pstruct->color->pixel_packing) |
| 85 | pinfo->mipi.dst_format |
| 86 | = DSI_VIDEO_DST_FORMAT_RGB666_LOOSE; |
| 87 | else |
| 88 | pinfo->mipi.dst_format |
| 89 | = DSI_VIDEO_DST_FORMAT_RGB666; |
| 90 | break; |
| 91 | case BPP_24: |
| 92 | default: |
| 93 | pinfo->mipi.dst_format = DSI_VIDEO_DST_FORMAT_RGB888; |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | /* Panel generic info */ |
| 98 | pinfo->mipi.mode = pstruct->paneldata->panel_type; |
| 99 | if (pinfo->mipi.mode) { |
| 100 | pinfo->type = MIPI_CMD_PANEL; |
| 101 | } else { |
| 102 | pinfo->type = MIPI_VIDEO_PANEL; |
| 103 | } |
| 104 | pinfo->bpp = pstruct->color->color_format; |
| 105 | pinfo->clk_rate = pstruct->paneldata->panel_clockrate; |
| 106 | pinfo->rotation = pstruct->paneldata->panel_orientation; |
| 107 | pinfo->mipi.interleave_mode = pstruct->paneldata->interleave_mode; |
| 108 | pinfo->broadcastmode = pstruct->paneldata->panel_broadcast_mode; |
| 109 | pinfo->lowpowerstop = pstruct->paneldata->dsi_lp11_atinit; |
| 110 | pinfo->mipi.vc = pstruct->paneldata->dsi_virtualchannel_id; |
| 111 | pinfo->mipi.frame_rate = pstruct->paneldata->panel_framerate; |
| 112 | pinfo->mipi.stream = pstruct->paneldata->dsi_stream; |
| 113 | pinfo->mipi.dual_dsi = (pstruct->paneldata->panel_operating_mode |
| 114 | & 0x1); |
Dhaval Patel | 29f2449 | 2013-08-08 20:45:42 -0700 | [diff] [blame] | 115 | pinfo->mipi.mode_gpio_state = pstruct->paneldata->mode_gpio_state; |
Arpita Banerjee | da0c39a | 2013-05-24 16:12:45 -0700 | [diff] [blame] | 116 | pinfo->mipi.bitclock = pstruct->paneldata->panel_bitclock_freq; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 117 | |
| 118 | /* Video Panel configuration */ |
| 119 | pinfo->mipi.pulse_mode_hsa_he = pstruct->videopanel->hsync_pulse; |
| 120 | pinfo->mipi.hfp_power_stop = pstruct->videopanel->hfp_power_mode; |
| 121 | pinfo->mipi.hbp_power_stop = pstruct->videopanel->hbp_power_mode; |
| 122 | pinfo->mipi.hsa_power_stop = pstruct->videopanel->hsa_power_mode; |
| 123 | pinfo->mipi.eof_bllp_power_stop |
| 124 | = pstruct->videopanel->bllp_eof_power_mode; |
| 125 | pinfo->mipi.bllp_power_stop = pstruct->videopanel->bllp_power_mode; |
| 126 | pinfo->mipi.traffic_mode = pstruct->videopanel->traffic_mode; |
| 127 | pinfo->mipi.eof_bllp_power = pstruct->videopanel->bllp_eof_power; |
| 128 | |
| 129 | /* Command Panel configuratoin */ |
| 130 | pinfo->mipi.insert_dcs_cmd = pstruct->commandpanel->tedcs_command; |
| 131 | pinfo->mipi.wr_mem_continue |
| 132 | = pstruct->commandpanel->tevsync_continue_lines; |
| 133 | pinfo->mipi.wr_mem_start |
| 134 | = pstruct->commandpanel->tevsync_rdptr_irqline; |
| 135 | pinfo->mipi.te_sel = pstruct->commandpanel->tepin_select; |
| 136 | |
| 137 | /* Data lane configuraiton */ |
| 138 | pinfo->mipi.num_of_lanes = pstruct->laneconfig->dsi_lanes; |
| 139 | pinfo->mipi.data_lane0 = pstruct->laneconfig->lane0_state; |
| 140 | pinfo->mipi.data_lane1 = pstruct->laneconfig->lane1_state; |
| 141 | pinfo->mipi.data_lane2 = pstruct->laneconfig->lane2_state; |
| 142 | pinfo->mipi.data_lane3 = pstruct->laneconfig->lane3_state; |
| 143 | pinfo->mipi.lane_swap = pstruct->laneconfig->dsi_lanemap; |
| 144 | |
| 145 | pinfo->mipi.t_clk_post = pstruct->paneltiminginfo->tclk_post; |
| 146 | pinfo->mipi.t_clk_pre = pstruct->paneltiminginfo->tclk_pre; |
| 147 | pinfo->mipi.mdp_trigger = pstruct->paneltiminginfo->dsi_mdp_trigger; |
| 148 | pinfo->mipi.dma_trigger = pstruct->paneltiminginfo->dsi_dma_trigger; |
| 149 | |
| 150 | pinfo->on = dsi_panel_on; |
| 151 | pinfo->off = dsi_panel_off; |
| 152 | pinfo->rotate = dsi_panel_rotation; |
| 153 | pinfo->config = dsi_panel_config; |
| 154 | |
| 155 | return NO_ERROR; |
| 156 | } |
| 157 | |
| 158 | /*---------------------------------------------------------------------------*/ |
| 159 | /* Panel Callbacks */ |
| 160 | /*---------------------------------------------------------------------------*/ |
| 161 | |
| 162 | int dsi_panel_on() |
| 163 | { |
| 164 | return oem_panel_on(); |
| 165 | } |
| 166 | |
| 167 | int dsi_panel_off() |
| 168 | { |
| 169 | return oem_panel_off(); |
| 170 | } |
| 171 | |
| 172 | int dsi_panel_rotation() |
| 173 | { |
| 174 | return oem_panel_rotation(); |
| 175 | } |
| 176 | |
| 177 | int dsi_video_panel_config(struct msm_panel_info *pinfo, |
| 178 | struct lcdc_panel_info *plcdc |
| 179 | ) |
| 180 | { |
| 181 | int ret = NO_ERROR; |
| 182 | uint8_t lane_enable = 0; |
| 183 | uint32_t panel_width = pinfo->xres; |
| 184 | |
| 185 | if (pinfo->mipi.dual_dsi) |
| 186 | panel_width = panel_width / 2; |
| 187 | |
Xiaoming Zhou | 7e0b1e6 | 2013-07-29 15:49:39 -0400 | [diff] [blame] | 188 | if (pinfo->mipi.data_lane0) |
| 189 | lane_enable |= (1 << 0); |
| 190 | if (pinfo->mipi.data_lane1) |
| 191 | lane_enable |= (1 << 1); |
| 192 | if (pinfo->mipi.data_lane2) |
| 193 | lane_enable |= (1 << 2); |
| 194 | if (pinfo->mipi.data_lane3) |
| 195 | lane_enable |= (1 << 3); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 196 | |
| 197 | ret = mdss_dsi_video_mode_config((panel_width + plcdc->xres_pad), |
| 198 | (pinfo->yres + plcdc->yres_pad), |
| 199 | (panel_width), |
| 200 | (pinfo->yres), |
| 201 | (plcdc->h_front_porch), |
| 202 | (plcdc->h_back_porch + plcdc->h_pulse_width), |
| 203 | (plcdc->v_front_porch), |
| 204 | (plcdc->v_back_porch + plcdc->v_pulse_width), |
| 205 | (plcdc->h_pulse_width), |
| 206 | (plcdc->v_pulse_width), |
| 207 | pinfo->mipi.dst_format, |
| 208 | pinfo->mipi.traffic_mode, |
| 209 | lane_enable, |
| 210 | pinfo->lowpowerstop, |
| 211 | pinfo->mipi.eof_bllp_power, |
| 212 | pinfo->mipi.interleave_mode, |
| 213 | MIPI_DSI0_BASE); |
| 214 | |
| 215 | if (pinfo->mipi.dual_dsi) |
| 216 | ret = mdss_dsi_video_mode_config( |
| 217 | (panel_width + plcdc->xres_pad), |
| 218 | (pinfo->yres + plcdc->yres_pad), |
| 219 | (panel_width), |
| 220 | (pinfo->yres), |
| 221 | (plcdc->h_front_porch), |
| 222 | (plcdc->h_back_porch + plcdc->h_pulse_width), |
| 223 | (plcdc->v_front_porch), |
| 224 | (plcdc->v_back_porch + plcdc->v_pulse_width), |
| 225 | (plcdc->h_pulse_width), |
| 226 | (plcdc->v_pulse_width), |
| 227 | pinfo->mipi.dst_format, |
| 228 | pinfo->mipi.traffic_mode, |
| 229 | lane_enable, |
| 230 | pinfo->lowpowerstop, |
| 231 | pinfo->mipi.eof_bllp_power, |
| 232 | pinfo->mipi.interleave_mode, |
| 233 | MIPI_DSI1_BASE); |
| 234 | |
| 235 | return ret; |
| 236 | } |
| 237 | |
| 238 | int dsi_cmd_panel_config (struct msm_panel_info *pinfo, |
| 239 | struct lcdc_panel_info *plcdc) |
| 240 | { |
| 241 | int ret = NO_ERROR; |
Xiaoming Zhou | 7e0b1e6 | 2013-07-29 15:49:39 -0400 | [diff] [blame] | 242 | uint8_t lane_en = 0; |
| 243 | uint8_t ystride = pinfo->bpp / 8; |
| 244 | |
| 245 | if (pinfo->mipi.data_lane0) |
| 246 | lane_en |= (1 << 0); |
| 247 | if (pinfo->mipi.data_lane1) |
| 248 | lane_en |= (1 << 1); |
| 249 | if (pinfo->mipi.data_lane2) |
| 250 | lane_en |= (1 << 2); |
| 251 | if (pinfo->mipi.data_lane3) |
| 252 | lane_en |= (1 << 3); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 253 | |
| 254 | ret = mdss_dsi_cmd_mode_config((pinfo->xres + plcdc->xres_pad), |
| 255 | (pinfo->yres + plcdc->yres_pad), |
| 256 | (pinfo->xres), (pinfo->yres), |
Xiaoming Zhou | 7e0b1e6 | 2013-07-29 15:49:39 -0400 | [diff] [blame] | 257 | pinfo->mipi.dst_format, |
| 258 | ystride, lane_en, |
| 259 | pinfo->mipi.interleave_mode); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 260 | |
| 261 | return ret; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | int dsi_panel_config(void *pdata) |
| 266 | { |
| 267 | int ret = NO_ERROR; |
| 268 | struct msm_panel_info *pinfo = (struct msm_panel_info *)pdata; |
| 269 | struct lcdc_panel_info *plcdc = NULL; |
| 270 | |
| 271 | if (pinfo == NULL) |
| 272 | return ERR_INVALID_ARGS; |
| 273 | |
| 274 | plcdc = &(pinfo->lcdc); |
| 275 | if (plcdc == NULL) |
| 276 | return ERR_INVALID_ARGS; |
| 277 | |
| 278 | |
| 279 | if (pinfo->mipi.mode == DSI_VIDEO_MODE) { |
| 280 | ret = dsi_video_panel_config(pinfo, plcdc); |
| 281 | } else { |
| 282 | ret = dsi_cmd_panel_config(pinfo, plcdc); |
| 283 | } |
| 284 | |
| 285 | return ret; |
| 286 | } |