blob: c09da682449a344938358a73332863e58e70988a [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;
181 } else {
182 pinfo->fbc.comp_ratio = 1;
183 }
184
Dhaval Patelb22f1bc2013-10-25 13:56:26 -0700185 pinfo->pre_on = dsi_panel_pre_on;
186 pinfo->pre_off = dsi_panel_pre_off;
187 pinfo->on = dsi_panel_post_on;
188 pinfo->off = dsi_panel_post_off;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700189 pinfo->rotate = dsi_panel_rotation;
190 pinfo->config = dsi_panel_config;
191
192 return NO_ERROR;
193}
194
195/*---------------------------------------------------------------------------*/
196/* Panel Callbacks */
197/*---------------------------------------------------------------------------*/
198
Dhaval Patelb22f1bc2013-10-25 13:56:26 -0700199int dsi_panel_pre_on()
Arpita Banerjee841fa062013-05-24 14:59:51 -0700200{
Dhaval Patelb22f1bc2013-10-25 13:56:26 -0700201 return target_display_pre_on();
202}
203
204int dsi_panel_pre_off()
205{
206 return target_display_pre_off();
207}
208
209int dsi_panel_post_on()
210{
211 int ret = NO_ERROR;
212
213 ret = target_display_post_on();
214 if (ret)
215 return ret;
216
Arpita Banerjee841fa062013-05-24 14:59:51 -0700217 return oem_panel_on();
218}
219
Dhaval Patelb22f1bc2013-10-25 13:56:26 -0700220int dsi_panel_post_off()
Arpita Banerjee841fa062013-05-24 14:59:51 -0700221{
Dhaval Patelb22f1bc2013-10-25 13:56:26 -0700222 int ret = NO_ERROR;
223
224 ret = target_display_post_off();
225 if (ret)
226 return ret;
227
Arpita Banerjee841fa062013-05-24 14:59:51 -0700228 return oem_panel_off();
229}
230
231int dsi_panel_rotation()
232{
233 return oem_panel_rotation();
234}
235
236int dsi_video_panel_config(struct msm_panel_info *pinfo,
237 struct lcdc_panel_info *plcdc
238 )
239{
240 int ret = NO_ERROR;
241 uint8_t lane_enable = 0;
242 uint32_t panel_width = pinfo->xres;
Siddhartha Agrawalfe64dcb2014-10-07 12:41:01 -0700243 uint32_t final_xres, final_yres, final_width;
244 uint32_t final_height, final_hbp, final_hfp,final_vbp;
245 uint32_t final_vfp, final_hpw, final_vpw;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700246
247 if (pinfo->mipi.dual_dsi)
248 panel_width = panel_width / 2;
249
Xiaoming Zhou7e0b1e62013-07-29 15:49:39 -0400250 if (pinfo->mipi.data_lane0)
251 lane_enable |= (1 << 0);
252 if (pinfo->mipi.data_lane1)
253 lane_enable |= (1 << 1);
254 if (pinfo->mipi.data_lane2)
255 lane_enable |= (1 << 2);
256 if (pinfo->mipi.data_lane3)
257 lane_enable |= (1 << 3);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700258
Siddhartha Agrawalfe64dcb2014-10-07 12:41:01 -0700259 final_xres = panel_width;
260 final_width = panel_width + pinfo->lcdc.xres_pad;
261
262 if (pinfo->fbc.enabled && pinfo->fbc.comp_ratio) {
263 final_xres /= pinfo->fbc.comp_ratio;
264 final_width /= pinfo->fbc.comp_ratio;
265 dprintf(SPEW, "DSI xres =%d final_width=%d\n", final_xres,
266 final_width);
267 }
268 final_yres = pinfo->yres;
269 final_height = pinfo->yres + pinfo->lcdc.yres_pad;
270 final_hbp = pinfo->lcdc.h_back_porch;
271 final_hfp = pinfo->lcdc.h_front_porch;
272 final_vbp = pinfo->lcdc.v_back_porch;
273 final_vfp = pinfo->lcdc.v_front_porch;
274 final_hpw = pinfo->lcdc.h_pulse_width;
275 final_vpw = pinfo->lcdc.v_pulse_width;
276
277 ret = mdss_dsi_video_mode_config(final_width, final_height,
278 final_xres, final_yres,
279 final_hfp, final_hbp + final_hpw,
280 final_vfp, final_vbp + final_vpw,
281 final_hpw, final_vpw,
Arpita Banerjee841fa062013-05-24 14:59:51 -0700282 pinfo->mipi.dst_format,
283 pinfo->mipi.traffic_mode,
284 lane_enable,
Dhaval Patel729aa972014-01-06 15:20:01 -0800285 pinfo->mipi.hsa_power_stop,
Arpita Banerjee841fa062013-05-24 14:59:51 -0700286 pinfo->mipi.eof_bllp_power,
287 pinfo->mipi.interleave_mode,
288 MIPI_DSI0_BASE);
289
290 if (pinfo->mipi.dual_dsi)
Siddhartha Agrawalfe64dcb2014-10-07 12:41:01 -0700291 ret = mdss_dsi_video_mode_config(final_width, final_height,
292 final_xres, final_yres,
293 final_hfp, final_hbp + final_hpw,
294 final_vfp, final_vbp + final_vpw,
295 final_hpw, final_vpw,
296 pinfo->mipi.dst_format,
297 pinfo->mipi.traffic_mode,
298 lane_enable,
299 pinfo->mipi.hsa_power_stop,
300 pinfo->mipi.eof_bllp_power,
301 pinfo->mipi.interleave_mode,
302 MIPI_DSI1_BASE);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700303
304 return ret;
305}
306
307int dsi_cmd_panel_config (struct msm_panel_info *pinfo,
308 struct lcdc_panel_info *plcdc)
309{
310 int ret = NO_ERROR;
Xiaoming Zhou7e0b1e62013-07-29 15:49:39 -0400311 uint8_t lane_en = 0;
312 uint8_t ystride = pinfo->bpp / 8;
Dhaval Patelea19a1e2014-01-02 16:17:26 -0800313 uint32_t panel_width = pinfo->xres;
314
315 if (pinfo->mipi.dual_dsi)
316 panel_width = panel_width / 2;
Xiaoming Zhou7e0b1e62013-07-29 15:49:39 -0400317
318 if (pinfo->mipi.data_lane0)
319 lane_en |= (1 << 0);
320 if (pinfo->mipi.data_lane1)
321 lane_en |= (1 << 1);
322 if (pinfo->mipi.data_lane2)
323 lane_en |= (1 << 2);
324 if (pinfo->mipi.data_lane3)
325 lane_en |= (1 << 3);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700326
Dhaval Patelea19a1e2014-01-02 16:17:26 -0800327 ret = mdss_dsi_cmd_mode_config((panel_width + plcdc->xres_pad),
Arpita Banerjee841fa062013-05-24 14:59:51 -0700328 (pinfo->yres + plcdc->yres_pad),
Dhaval Patelea19a1e2014-01-02 16:17:26 -0800329 panel_width, (pinfo->yres),
Xiaoming Zhou7e0b1e62013-07-29 15:49:39 -0400330 pinfo->mipi.dst_format,
331 ystride, lane_en,
Dhaval Patelea19a1e2014-01-02 16:17:26 -0800332 pinfo->mipi.interleave_mode,
333 MIPI_DSI0_BASE);
334
335 if (pinfo->mipi.dual_dsi)
336 ret = mdss_dsi_cmd_mode_config((panel_width + plcdc->xres_pad),
337 (pinfo->yres + plcdc->yres_pad),
338 panel_width, (pinfo->yres),
339 pinfo->mipi.dst_format,
340 ystride, lane_en,
341 pinfo->mipi.interleave_mode,
342 MIPI_DSI1_BASE);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700343
344 return ret;
345}
346
347
348int dsi_panel_config(void *pdata)
349{
350 int ret = NO_ERROR;
351 struct msm_panel_info *pinfo = (struct msm_panel_info *)pdata;
352 struct lcdc_panel_info *plcdc = NULL;
353
354 if (pinfo == NULL)
355 return ERR_INVALID_ARGS;
356
357 plcdc = &(pinfo->lcdc);
358 if (plcdc == NULL)
359 return ERR_INVALID_ARGS;
360
361
362 if (pinfo->mipi.mode == DSI_VIDEO_MODE) {
363 ret = dsi_video_panel_config(pinfo, plcdc);
364 } else {
365 ret = dsi_cmd_panel_config(pinfo, plcdc);
366 }
367
368 return ret;
369}
Dhaval Patel551f7f62014-02-18 17:13:00 -0800370
371int32_t panel_name_to_id(struct panel_list supp_panels[],
372 uint32_t supp_panels_size,
373 const char *panel_name)
374{
375 uint32_t i;
376 int32_t panel_id = ERR_NOT_FOUND;
377
378 if (!panel_name) {
379 dprintf(CRITICAL, "Invalid panel name\n");
380 return panel_id;
381 }
382
383 /* Remove any leading whitespaces */
384 panel_name += strspn(panel_name, " ");
385 for (i = 0; i < supp_panels_size; i++) {
386 if (!strncmp(panel_name, supp_panels[i].name,
387 MAX_PANEL_ID_LEN)) {
388 panel_id = supp_panels[i].id;
389 break;
390 }
391 }
392
393 return panel_id;
394}