blob: e1cadf39d37fc60e112761de0aacb558db6ca85b [file] [log] [blame]
Dhaval Patelea19a1e2014-01-02 16:17:26 -08001/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Arpita Banerjee841fa062013-05-24 14:59:51 -07002 *
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 Patel551f7f62014-02-18 17:13:00 -080041#include <string.h>
Arpita Banerjee841fa062013-05-24 14:59:51 -070042
43
44/*---------------------------------------------------------------------------*/
45/* Panel Header */
46/*---------------------------------------------------------------------------*/
47#include "panel_display.h"
48#include "include/panel.h"
49
50/*---------------------------------------------------------------------------*/
51/* Panel Init */
52/*---------------------------------------------------------------------------*/
53int 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;
Kuogee Hsieh31b4ff92014-10-22 14:55:42 -070066
67 pinfo->border_top = pstruct->panelres->vtop_border;
68 pinfo->border_bottom = pstruct->panelres->vbottom_border;
69 pinfo->border_left = pstruct->panelres->hleft_border;
70 pinfo->border_right = pstruct->panelres->hright_border;
71
72 dprintf(SPEW, "%s: left=%d right=%d top=%d bottom=%d\n", __func__,
73 pinfo->border_left, pinfo->border_right,
74 pinfo->border_top, pinfo->border_bottom);
75
76 pinfo->xres += (pinfo->border_left + pinfo->border_right);
77 pinfo->yres += (pinfo->border_top + pinfo->border_bottom);
Arpita Banerjee841fa062013-05-24 14:59:51 -070078
Dhaval Patelee8675a2013-10-25 10:07:57 -070079 if (pstruct->paneldata->panel_operating_mode & DUAL_PIPE_FLAG)
80 pinfo->lcdc.dual_pipe = 1;
81 if (pstruct->paneldata->panel_operating_mode & PIPE_SWAP_FLAG)
82 pinfo->lcdc.pipe_swap = 1;
83 if (pstruct->paneldata->panel_operating_mode & SPLIT_DISPLAY_FLAG)
84 pinfo->lcdc.split_display = 1;
Vineet Bajaj4effb132014-07-24 16:55:41 +053085 if (pstruct->paneldata->panel_operating_mode & DST_SPLIT_FLAG)
86 pinfo->lcdc.dst_split = 1;
Arpita Banerjee841fa062013-05-24 14:59:51 -070087
88 /* Color setting*/
89 pinfo->lcdc.border_clr = pstruct->color->border_color;
90 pinfo->lcdc.underflow_clr = pstruct->color->underflow_color;
91 pinfo->mipi.rgb_swap = pstruct->color->color_order;
92 switch (pinfo->bpp) {
93 case BPP_16:
94 pinfo->mipi.dst_format = DSI_VIDEO_DST_FORMAT_RGB565;
95 break;
96 case BPP_18:
97 if (pstruct->color->pixel_packing)
98 pinfo->mipi.dst_format
99 = DSI_VIDEO_DST_FORMAT_RGB666_LOOSE;
100 else
101 pinfo->mipi.dst_format
102 = DSI_VIDEO_DST_FORMAT_RGB666;
103 break;
104 case BPP_24:
105 default:
106 pinfo->mipi.dst_format = DSI_VIDEO_DST_FORMAT_RGB888;
107 break;
108 }
109
110 /* Panel generic info */
111 pinfo->mipi.mode = pstruct->paneldata->panel_type;
112 if (pinfo->mipi.mode) {
113 pinfo->type = MIPI_CMD_PANEL;
114 } else {
115 pinfo->type = MIPI_VIDEO_PANEL;
116 }
117 pinfo->bpp = pstruct->color->color_format;
118 pinfo->clk_rate = pstruct->paneldata->panel_clockrate;
Prashant Nukala64eeff92014-07-11 07:35:34 +0530119 pinfo->orientation = pstruct->paneldata->panel_orientation;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700120 pinfo->mipi.interleave_mode = pstruct->paneldata->interleave_mode;
Dhaval Patelee8675a2013-10-25 10:07:57 -0700121 pinfo->mipi.broadcast = pstruct->paneldata->panel_broadcast_mode;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700122 pinfo->mipi.vc = pstruct->paneldata->dsi_virtualchannel_id;
123 pinfo->mipi.frame_rate = pstruct->paneldata->panel_framerate;
124 pinfo->mipi.stream = pstruct->paneldata->dsi_stream;
Dhaval Patelee8675a2013-10-25 10:07:57 -0700125 if (pstruct->paneldata->panel_operating_mode & DUAL_DSI_FLAG)
126 pinfo->mipi.dual_dsi = 1;
Dhaval Patel29f24492013-08-08 20:45:42 -0700127 pinfo->mipi.mode_gpio_state = pstruct->paneldata->mode_gpio_state;
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -0700128 pinfo->mipi.bitclock = pstruct->paneldata->panel_bitclock_freq;
Aravind Venkateswaran1e31c782013-11-04 17:32:14 -0800129 pinfo->mipi.use_enable_gpio =
130 pstruct->paneldata->panel_with_enable_gpio;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700131
132 /* Video Panel configuration */
133 pinfo->mipi.pulse_mode_hsa_he = pstruct->videopanel->hsync_pulse;
134 pinfo->mipi.hfp_power_stop = pstruct->videopanel->hfp_power_mode;
135 pinfo->mipi.hbp_power_stop = pstruct->videopanel->hbp_power_mode;
136 pinfo->mipi.hsa_power_stop = pstruct->videopanel->hsa_power_mode;
137 pinfo->mipi.eof_bllp_power_stop
138 = pstruct->videopanel->bllp_eof_power_mode;
139 pinfo->mipi.bllp_power_stop = pstruct->videopanel->bllp_power_mode;
140 pinfo->mipi.traffic_mode = pstruct->videopanel->traffic_mode;
141 pinfo->mipi.eof_bllp_power = pstruct->videopanel->bllp_eof_power;
142
143 /* Command Panel configuratoin */
144 pinfo->mipi.insert_dcs_cmd = pstruct->commandpanel->tedcs_command;
145 pinfo->mipi.wr_mem_continue
146 = pstruct->commandpanel->tevsync_continue_lines;
147 pinfo->mipi.wr_mem_start
148 = pstruct->commandpanel->tevsync_rdptr_irqline;
149 pinfo->mipi.te_sel = pstruct->commandpanel->tepin_select;
150
151 /* Data lane configuraiton */
152 pinfo->mipi.num_of_lanes = pstruct->laneconfig->dsi_lanes;
153 pinfo->mipi.data_lane0 = pstruct->laneconfig->lane0_state;
154 pinfo->mipi.data_lane1 = pstruct->laneconfig->lane1_state;
155 pinfo->mipi.data_lane2 = pstruct->laneconfig->lane2_state;
156 pinfo->mipi.data_lane3 = pstruct->laneconfig->lane3_state;
157 pinfo->mipi.lane_swap = pstruct->laneconfig->dsi_lanemap;
158
159 pinfo->mipi.t_clk_post = pstruct->paneltiminginfo->tclk_post;
160 pinfo->mipi.t_clk_pre = pstruct->paneltiminginfo->tclk_pre;
161 pinfo->mipi.mdp_trigger = pstruct->paneltiminginfo->dsi_mdp_trigger;
162 pinfo->mipi.dma_trigger = pstruct->paneltiminginfo->dsi_dma_trigger;
163
Siddhartha Agrawalfe64dcb2014-10-07 12:41:01 -0700164 pinfo->fbc.enabled = pstruct->fbcinfo.enabled;
165 if (pinfo->fbc.enabled) {
166 pinfo->fbc.enabled = pstruct->fbcinfo.enabled;
167 pinfo->fbc.comp_ratio= pstruct->fbcinfo.comp_ratio;
168 pinfo->fbc.comp_mode = pstruct->fbcinfo.comp_mode;
169 pinfo->fbc.qerr_enable = pstruct->fbcinfo.qerr_enable;
170 pinfo->fbc.cd_bias = pstruct->fbcinfo.cd_bias;
171 pinfo->fbc.pat_enable = pstruct->fbcinfo.pat_enable;
172 pinfo->fbc.vlc_enable = pstruct->fbcinfo.vlc_enable;
173 pinfo->fbc.bflc_enable = pstruct->fbcinfo.bflc_enable;
174 pinfo->fbc.line_x_budget = pstruct->fbcinfo.line_x_budget;
175 pinfo->fbc.block_x_budget = pstruct->fbcinfo.block_x_budget;
176 pinfo->fbc.block_budget = pstruct->fbcinfo.block_budget;
177 pinfo->fbc.lossless_mode_thd = pstruct->fbcinfo.lossless_mode_thd;
178 pinfo->fbc.lossy_mode_thd = pstruct->fbcinfo.lossy_mode_thd;
179 pinfo->fbc.lossy_rgb_thd = pstruct->fbcinfo.lossy_rgb_thd;
180 pinfo->fbc.lossy_mode_idx = pstruct->fbcinfo.lossy_mode_idx;
Jeevan Shriram1b07e372014-11-30 22:03:50 -0800181 pinfo->fbc.slice_height = pstruct->fbcinfo.slice_height;
182 pinfo->fbc.pred_mode = pstruct->fbcinfo.pred_mode;
183 pinfo->fbc.max_pred_err = pstruct->fbcinfo.max_pred_err;
184
Siddhartha Agrawalfe64dcb2014-10-07 12:41:01 -0700185 } else {
186 pinfo->fbc.comp_ratio = 1;
187 }
188
Dhaval Patelb22f1bc2013-10-25 13:56:26 -0700189 pinfo->pre_on = dsi_panel_pre_on;
190 pinfo->pre_off = dsi_panel_pre_off;
191 pinfo->on = dsi_panel_post_on;
192 pinfo->off = dsi_panel_post_off;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700193 pinfo->rotate = dsi_panel_rotation;
194 pinfo->config = dsi_panel_config;
195
196 return NO_ERROR;
197}
198
199/*---------------------------------------------------------------------------*/
200/* Panel Callbacks */
201/*---------------------------------------------------------------------------*/
202
Dhaval Patelb22f1bc2013-10-25 13:56:26 -0700203int dsi_panel_pre_on()
Arpita Banerjee841fa062013-05-24 14:59:51 -0700204{
Dhaval Patelb22f1bc2013-10-25 13:56:26 -0700205 return target_display_pre_on();
206}
207
208int dsi_panel_pre_off()
209{
210 return target_display_pre_off();
211}
212
213int dsi_panel_post_on()
214{
215 int ret = NO_ERROR;
216
217 ret = target_display_post_on();
218 if (ret)
219 return ret;
220
Arpita Banerjee841fa062013-05-24 14:59:51 -0700221 return oem_panel_on();
222}
223
Dhaval Patelb22f1bc2013-10-25 13:56:26 -0700224int dsi_panel_post_off()
Arpita Banerjee841fa062013-05-24 14:59:51 -0700225{
Dhaval Patelb22f1bc2013-10-25 13:56:26 -0700226 int ret = NO_ERROR;
227
228 ret = target_display_post_off();
229 if (ret)
230 return ret;
231
Arpita Banerjee841fa062013-05-24 14:59:51 -0700232 return oem_panel_off();
233}
234
235int dsi_panel_rotation()
236{
237 return oem_panel_rotation();
238}
239
240int dsi_video_panel_config(struct msm_panel_info *pinfo,
241 struct lcdc_panel_info *plcdc
242 )
243{
244 int ret = NO_ERROR;
245 uint8_t lane_enable = 0;
246 uint32_t panel_width = pinfo->xres;
Siddhartha Agrawalfe64dcb2014-10-07 12:41:01 -0700247 uint32_t final_xres, final_yres, final_width;
248 uint32_t final_height, final_hbp, final_hfp,final_vbp;
249 uint32_t final_vfp, final_hpw, final_vpw;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700250
251 if (pinfo->mipi.dual_dsi)
252 panel_width = panel_width / 2;
253
Xiaoming Zhou7e0b1e62013-07-29 15:49:39 -0400254 if (pinfo->mipi.data_lane0)
255 lane_enable |= (1 << 0);
256 if (pinfo->mipi.data_lane1)
257 lane_enable |= (1 << 1);
258 if (pinfo->mipi.data_lane2)
259 lane_enable |= (1 << 2);
260 if (pinfo->mipi.data_lane3)
261 lane_enable |= (1 << 3);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700262
Siddhartha Agrawalfe64dcb2014-10-07 12:41:01 -0700263 final_xres = panel_width;
264 final_width = panel_width + pinfo->lcdc.xres_pad;
265
266 if (pinfo->fbc.enabled && pinfo->fbc.comp_ratio) {
267 final_xres /= pinfo->fbc.comp_ratio;
268 final_width /= pinfo->fbc.comp_ratio;
269 dprintf(SPEW, "DSI xres =%d final_width=%d\n", final_xres,
270 final_width);
271 }
272 final_yres = pinfo->yres;
273 final_height = pinfo->yres + pinfo->lcdc.yres_pad;
274 final_hbp = pinfo->lcdc.h_back_porch;
275 final_hfp = pinfo->lcdc.h_front_porch;
276 final_vbp = pinfo->lcdc.v_back_porch;
277 final_vfp = pinfo->lcdc.v_front_porch;
278 final_hpw = pinfo->lcdc.h_pulse_width;
279 final_vpw = pinfo->lcdc.v_pulse_width;
280
281 ret = mdss_dsi_video_mode_config(final_width, final_height,
282 final_xres, final_yres,
283 final_hfp, final_hbp + final_hpw,
284 final_vfp, final_vbp + final_vpw,
285 final_hpw, final_vpw,
Arpita Banerjee841fa062013-05-24 14:59:51 -0700286 pinfo->mipi.dst_format,
287 pinfo->mipi.traffic_mode,
288 lane_enable,
Dhaval Patel729aa972014-01-06 15:20:01 -0800289 pinfo->mipi.hsa_power_stop,
Arpita Banerjee841fa062013-05-24 14:59:51 -0700290 pinfo->mipi.eof_bllp_power,
291 pinfo->mipi.interleave_mode,
292 MIPI_DSI0_BASE);
293
294 if (pinfo->mipi.dual_dsi)
Siddhartha Agrawalfe64dcb2014-10-07 12:41:01 -0700295 ret = mdss_dsi_video_mode_config(final_width, final_height,
296 final_xres, final_yres,
297 final_hfp, final_hbp + final_hpw,
298 final_vfp, final_vbp + final_vpw,
299 final_hpw, final_vpw,
300 pinfo->mipi.dst_format,
301 pinfo->mipi.traffic_mode,
302 lane_enable,
303 pinfo->mipi.hsa_power_stop,
304 pinfo->mipi.eof_bllp_power,
305 pinfo->mipi.interleave_mode,
306 MIPI_DSI1_BASE);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700307
308 return ret;
309}
310
311int dsi_cmd_panel_config (struct msm_panel_info *pinfo,
312 struct lcdc_panel_info *plcdc)
313{
314 int ret = NO_ERROR;
Xiaoming Zhou7e0b1e62013-07-29 15:49:39 -0400315 uint8_t lane_en = 0;
316 uint8_t ystride = pinfo->bpp / 8;
Dhaval Patelea19a1e2014-01-02 16:17:26 -0800317 uint32_t panel_width = pinfo->xres;
318
319 if (pinfo->mipi.dual_dsi)
320 panel_width = panel_width / 2;
Xiaoming Zhou7e0b1e62013-07-29 15:49:39 -0400321
322 if (pinfo->mipi.data_lane0)
323 lane_en |= (1 << 0);
324 if (pinfo->mipi.data_lane1)
325 lane_en |= (1 << 1);
326 if (pinfo->mipi.data_lane2)
327 lane_en |= (1 << 2);
328 if (pinfo->mipi.data_lane3)
329 lane_en |= (1 << 3);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700330
Dhaval Patelea19a1e2014-01-02 16:17:26 -0800331 ret = mdss_dsi_cmd_mode_config((panel_width + plcdc->xres_pad),
Arpita Banerjee841fa062013-05-24 14:59:51 -0700332 (pinfo->yres + plcdc->yres_pad),
Dhaval Patelea19a1e2014-01-02 16:17:26 -0800333 panel_width, (pinfo->yres),
Xiaoming Zhou7e0b1e62013-07-29 15:49:39 -0400334 pinfo->mipi.dst_format,
335 ystride, lane_en,
Dhaval Patelea19a1e2014-01-02 16:17:26 -0800336 pinfo->mipi.interleave_mode,
337 MIPI_DSI0_BASE);
338
339 if (pinfo->mipi.dual_dsi)
340 ret = mdss_dsi_cmd_mode_config((panel_width + plcdc->xres_pad),
341 (pinfo->yres + plcdc->yres_pad),
342 panel_width, (pinfo->yres),
343 pinfo->mipi.dst_format,
344 ystride, lane_en,
345 pinfo->mipi.interleave_mode,
346 MIPI_DSI1_BASE);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700347
348 return ret;
349}
350
351
352int dsi_panel_config(void *pdata)
353{
354 int ret = NO_ERROR;
355 struct msm_panel_info *pinfo = (struct msm_panel_info *)pdata;
356 struct lcdc_panel_info *plcdc = NULL;
357
358 if (pinfo == NULL)
359 return ERR_INVALID_ARGS;
360
361 plcdc = &(pinfo->lcdc);
362 if (plcdc == NULL)
363 return ERR_INVALID_ARGS;
364
365
366 if (pinfo->mipi.mode == DSI_VIDEO_MODE) {
367 ret = dsi_video_panel_config(pinfo, plcdc);
368 } else {
369 ret = dsi_cmd_panel_config(pinfo, plcdc);
370 }
371
372 return ret;
373}
Dhaval Patel551f7f62014-02-18 17:13:00 -0800374
375int32_t panel_name_to_id(struct panel_list supp_panels[],
376 uint32_t supp_panels_size,
377 const char *panel_name)
378{
379 uint32_t i;
380 int32_t panel_id = ERR_NOT_FOUND;
381
382 if (!panel_name) {
383 dprintf(CRITICAL, "Invalid panel name\n");
384 return panel_id;
385 }
386
387 /* Remove any leading whitespaces */
388 panel_name += strspn(panel_name, " ");
389 for (i = 0; i < supp_panels_size; i++) {
390 if (!strncmp(panel_name, supp_panels[i].name,
391 MAX_PANEL_ID_LEN)) {
392 panel_id = supp_panels[i].id;
393 break;
394 }
395 }
396
397 return panel_id;
398}