blob: 244ba829da25964edb892af57093a07ced01bdbb [file] [log] [blame]
Wenjun Zhang4e63ce42017-11-28 05:11:34 -05001/* Copyright (c) 2013-2018 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
5 * are 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 copyright
9 * notice, this list of conditions and the following disclaimer in
10 * the documentation and/or other materials provided with the
11 * 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <debug.h>
31#include <err.h>
32#include <smem.h>
Veera Sundaram Sankaran824e6fa2014-12-09 11:32:58 -080033#include <clock.h>
Arpita Banerjee841fa062013-05-24 14:59:51 -070034#include <msm_panel.h>
Dhaval Patel9f61f132013-07-18 14:45:11 -070035#include <string.h>
36#include <stdlib.h>
Arpita Banerjee841fa062013-05-24 14:59:51 -070037#include <board.h>
38#include <mdp5.h>
Veera Sundaram Sankaran824e6fa2014-12-09 11:32:58 -080039#include <qtimer.h>
Arpita Banerjee841fa062013-05-24 14:59:51 -070040#include <platform/gpio.h>
41#include <mipi_dsi.h>
Huaibin Yangb6fa92b2015-01-28 16:21:37 -080042#include <partition_parser.h>
Arpita Banerjee841fa062013-05-24 14:59:51 -070043
44#include "include/display_resource.h"
45#include "include/panel.h"
46#include "panel_display.h"
47#include "gcdb_display.h"
48#include "target/display.h"
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070049#include "gcdb_autopll.h"
Arpita Banerjee841fa062013-05-24 14:59:51 -070050
51/*---------------------------------------------------------------------------*/
52/* static */
53/*---------------------------------------------------------------------------*/
54static struct msm_fb_panel_data panel;
55struct panel_struct panelstruct;
56static uint8_t display_enable;
57static struct mdss_dsi_phy_ctrl dsi_video_mode_phy_db;
58
Arpita Banerjee841fa062013-05-24 14:59:51 -070059/*---------------------------------------------------------------------------*/
60/* Extern */
61/*---------------------------------------------------------------------------*/
62extern int msm_display_init(struct msm_fb_panel_data *pdata);
63extern int msm_display_off();
64
65static uint32_t panel_backlight_ctrl(uint8_t enable)
66{
Vineet Bajaj22442342015-04-29 16:55:18 +053067 uint32_t ret = NO_ERROR;
68 if (panelstruct.backlightinfo)
69 ret = target_backlight_ctrl(panelstruct.backlightinfo, enable);
70 return ret;
Arpita Banerjee841fa062013-05-24 14:59:51 -070071}
72
73static uint32_t mdss_dsi_panel_reset(uint8_t enable)
74{
75 uint32_t ret = NO_ERROR;
Vineet Bajaj22442342015-04-29 16:55:18 +053076 if (panelstruct.panelresetseq)
77 ret = target_panel_reset(enable, panelstruct.panelresetseq,
78 &panel.panel_info);
Arpita Banerjee841fa062013-05-24 14:59:51 -070079 return ret;
80}
81
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070082static uint32_t mdss_dsi_panel_clock(uint8_t enable,
83 struct msm_panel_info *pinfo)
Arpita Banerjee841fa062013-05-24 14:59:51 -070084{
85 uint32_t ret = NO_ERROR;
86
Arpita Banerjeeda0c39a2013-05-24 16:12:45 -070087 ret = calculate_clock_config(pinfo);
Huaibin Yangcbec39b2014-11-07 13:54:38 -080088 if (ret)
89 dprintf(CRITICAL, "Clock calculation failed\n");
90 else
91 ret = target_panel_clock(enable, pinfo);
Arpita Banerjee841fa062013-05-24 14:59:51 -070092
93 return ret;
94}
95
Kuogee Hsieh93bcff62014-08-22 14:02:08 -070096static int mdss_dsi_panel_power(uint8_t enable,
97 struct msm_panel_info *pinfo)
Arpita Banerjee841fa062013-05-24 14:59:51 -070098{
99 int ret = NO_ERROR;
100
101 if (enable) {
Kuogee Hsieh93bcff62014-08-22 14:02:08 -0700102 ret = target_ldo_ctrl(enable, pinfo);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700103 if (ret) {
Jayant Shekharc9611a92013-11-20 16:59:27 +0530104 dprintf(CRITICAL, "LDO control enable failed\n");
Arpita Banerjee841fa062013-05-24 14:59:51 -0700105 return ret;
106 }
107
108 /* Panel Reset */
Jayant Shekharc9611a92013-11-20 16:59:27 +0530109 if (!panelstruct.paneldata->panel_lp11_init) {
110 ret = mdss_dsi_panel_reset(enable);
111 if (ret) {
112 dprintf(CRITICAL, "panel reset failed\n");
113 return ret;
114 }
Arpita Banerjee841fa062013-05-24 14:59:51 -0700115 }
116 dprintf(SPEW, "Panel power on done\n");
117 } else {
Casey Piper1bbd1572013-09-11 16:23:18 -0700118 /* Disable panel and ldo */
Arpita Banerjee841fa062013-05-24 14:59:51 -0700119 ret = mdss_dsi_panel_reset(enable);
120 if (ret) {
Jayant Shekharc9611a92013-11-20 16:59:27 +0530121 dprintf(CRITICAL, "panel reset disable failed\n");
Arpita Banerjee841fa062013-05-24 14:59:51 -0700122 return ret;
123 }
124
Kuogee Hsieh93bcff62014-08-22 14:02:08 -0700125 ret = target_ldo_ctrl(enable, pinfo);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700126 if (ret) {
Jayant Shekharc9611a92013-11-20 16:59:27 +0530127 dprintf(CRITICAL, "ldo control disable failed\n");
Arpita Banerjee841fa062013-05-24 14:59:51 -0700128 return ret;
129 }
130 dprintf(SPEW, "Panel power off done\n");
131 }
132
133 return ret;
134}
135
Ray Zhangeb462f62013-12-03 17:16:08 +0800136static int mdss_dsi_panel_pre_init(void)
Jayant Shekharc9611a92013-11-20 16:59:27 +0530137{
138 int ret = NO_ERROR;
139
Ray Zhangeb462f62013-12-03 17:16:08 +0800140 if (panelstruct.paneldata->panel_lp11_init) {
141 ret = mdss_dsi_panel_reset(1);
142 if (ret) {
143 dprintf(CRITICAL, "panel reset failed\n");
144 return ret;
Jayant Shekharc9611a92013-11-20 16:59:27 +0530145 }
Jayant Shekharc9611a92013-11-20 16:59:27 +0530146 }
147
Ray Zhangeb462f62013-12-03 17:16:08 +0800148 if(panelstruct.paneldata->panel_init_delay)
149 udelay(panelstruct.paneldata->panel_init_delay);
150
151 dprintf(SPEW, "Panel pre init done\n");
Jayant Shekharc9611a92013-11-20 16:59:27 +0530152 return ret;
153}
154
Huaibin Yangb6fa92b2015-01-28 16:21:37 -0800155static int mdss_dsi_dfps_get_pll_codes_cal(struct msm_panel_info *pinfo)
Huaibin Yangcbec39b2014-11-07 13:54:38 -0800156{
157 int ret = NO_ERROR;
158 uint32_t fps_bak;
159 uint32_t i;
160
161 fps_bak = pinfo->mipi.frame_rate;
162
163 for (i = 0; i < pinfo->dfps.panel_dfps.frame_rate_cnt; i++) {
164 int err;
165 pinfo->mipi.frame_rate = pinfo->dfps.panel_dfps.frame_rate[i];
166
167 err = mdss_dsi_panel_clock(1, pinfo);
168 if (!err) {
Jeevan Shrirame2014662015-08-03 15:11:27 -0700169 dprintf(SPEW, "frame_rate=%d, vcorate=%d success!\n",
170 pinfo->mipi.frame_rate,
171 pinfo->mipi.dsi_pll_config->vco_clock);
Huaibin Yangcbec39b2014-11-07 13:54:38 -0800172 pinfo->dfps.codes_dfps[i].is_valid = 1;
173 pinfo->dfps.codes_dfps[i].frame_rate =
174 pinfo->mipi.frame_rate;
Huaibin Yangcbec39b2014-11-07 13:54:38 -0800175 pinfo->dfps.codes_dfps[i].clk_rate =
176 pinfo->mipi.dsi_pll_config->vco_clock;
177 pinfo->dfps.codes_dfps[i].pll_codes =
178 pinfo->mipi.pll_codes;
179
180 mdss_dsi_panel_clock(0, pinfo);
181 } else {
182 ret = err;
183 pinfo->dfps.codes_dfps[i].is_valid = 0;
184 dprintf(CRITICAL, "frame_rate=%d failed!\n",
185 pinfo->mipi.frame_rate);
186 }
187 }
188
189 pinfo->mipi.frame_rate = fps_bak;
190
191 return ret;
192}
193
Huaibin Yangb6fa92b2015-01-28 16:21:37 -0800194static int mdss_dsi_dfps_get_stored_pll_codes(struct msm_panel_info *pinfo)
195{
196 int ret = NO_ERROR;
197 int index;
198 unsigned long long ptn;
199 uint32_t blocksize;
200 struct dfps_info *dfps;
201
202 index = partition_get_index("splash");
Casey Piper69f95682015-03-30 16:19:45 -0700203 if (index == INVALID_PTN) {
204 dprintf(INFO, "%s: splash partition table not found\n", __func__);
Jeevan Shrirame2014662015-08-03 15:11:27 -0700205 ret = ERROR;
Huaibin Yangb6fa92b2015-01-28 16:21:37 -0800206 goto splash_err;
207 }
208
209 ptn = partition_get_offset(index);
210 if (ptn == 0) {
211 dprintf(CRITICAL, "ERROR: splash Partition invalid offset\n");
212 ret = ERROR;
213 goto splash_err;
214 }
215
Channagoud Kadabi7f666372015-02-24 14:37:32 -0800216 mmc_set_lun(partition_get_lun(index));
217
Huaibin Yangb6fa92b2015-01-28 16:21:37 -0800218 blocksize = mmc_get_device_blocksize();
219 if (blocksize == 0) {
220 dprintf(CRITICAL, "ERROR:splash Partition invalid blocksize\n");
221 ret = ERROR;
222 goto splash_err;
223 }
224
225 dfps = (struct dfps_info *)memalign(CACHE_LINE, ROUNDUP(PAGE_SIZE,
226 CACHE_LINE));
227 if (!dfps) {
228 dprintf(CRITICAL, "ERROR:splash Partition invalid memory\n");
229 ret = ERROR;
230 goto splash_err;
231 }
232
233 if (mmc_read(ptn, (uint32_t *) dfps, blocksize)) {
234 dprintf(CRITICAL, "mmc read splash failure%d\n", PAGE_SIZE);
235 ret = ERROR;
236 free(dfps);
237 goto splash_err;
238 }
239
240 dprintf(SPEW, "enable=%d cnt=%d\n", dfps->panel_dfps.enabled,
241 dfps->panel_dfps.frame_rate_cnt);
242
Ashish Garg342420a2017-04-24 18:00:12 +0530243 dprintf(CRITICAL, "chip serial splash =%d\n", dfps->chip_serial);
244 dprintf(CRITICAL, "chip serial pinfo =%d\n", pinfo->dfps.chip_serial);
245
246 if (!dfps->panel_dfps.enabled ||
247 (dfps->panel_dfps.frame_rate_cnt > DFPS_MAX_FRAME_RATE) ||
248 (dfps->dfps_fb_base != pinfo->dfps.dfps_fb_base) ||
249 (pinfo->dfps.chip_serial != dfps->chip_serial)) {
Huaibin Yangb6fa92b2015-01-28 16:21:37 -0800250 ret = ERROR;
251 free(dfps);
252 goto splash_err;
253 }
254
255 pinfo->dfps = *dfps;
256 free(dfps);
257
258splash_err:
259 return ret;
260}
261
262static int mdss_dsi_dfps_store_pll_codes(struct msm_panel_info *pinfo)
263{
264 int ret = NO_ERROR;
265 int index;
266 unsigned long long ptn;
267
268 index = partition_get_index("splash");
Casey Piper69f95682015-03-30 16:19:45 -0700269 if (index == INVALID_PTN) {
270 dprintf(INFO, "%s: splash partition table not found\n", __func__);
Jeevan Shrirame2014662015-08-03 15:11:27 -0700271 ret = ERROR;
Huaibin Yangb6fa92b2015-01-28 16:21:37 -0800272 goto store_err;
273 }
274
275 ptn = partition_get_offset(index);
276 if (ptn == 0) {
277 dprintf(CRITICAL, "ERROR: splash Partition invalid offset\n");
278 ret = ERROR;
279 goto store_err;
280 }
281
Channagoud Kadabi7f666372015-02-24 14:37:32 -0800282 mmc_set_lun(partition_get_lun(index));
283
Huaibin Yangb6fa92b2015-01-28 16:21:37 -0800284 ret = mmc_write(ptn, sizeof(uint32_t), &pinfo->dfps);
285 if (ret)
286 dprintf(CRITICAL, "mmc write failed!\n");
287
288store_err:
289 return ret;
290}
291
Huaibin Yangcbec39b2014-11-07 13:54:38 -0800292static int mdss_dsi_mipi_dfps_config(struct msm_panel_info *pinfo)
293{
294 int ret = NO_ERROR;
295
296 if (!pinfo)
297 return ERROR;
298
299 if (!pinfo->dfps.panel_dfps.enabled)
300 goto dfps_done;
301
Ashish Garg342420a2017-04-24 18:00:12 +0530302 pinfo->dfps.chip_serial = board_chip_serial();
303
Huaibin Yangb6fa92b2015-01-28 16:21:37 -0800304 if (!mdss_dsi_dfps_get_stored_pll_codes(pinfo)) {
Ashish Garg342420a2017-04-24 18:00:12 +0530305 dprintf(CRITICAL, "Found stored PLL codes!\n");
Huaibin Yangb6fa92b2015-01-28 16:21:37 -0800306 goto dfps_cal_done;
307 }
Huaibin Yangcbec39b2014-11-07 13:54:38 -0800308
Ashish Garg342420a2017-04-24 18:00:12 +0530309 dprintf(CRITICAL, "Calculate PLL codes!\n");
Huaibin Yangb6fa92b2015-01-28 16:21:37 -0800310 ret = mdss_dsi_dfps_get_pll_codes_cal(pinfo);
311 if (ret) {
312 dprintf(CRITICAL, "Cannot cal pll codes!\n");
313 goto dfps_done;
314 } else {
315 dprintf(SPEW, "Calibrate all pll codes!\n");
316 }
317
318 ret = mdss_dsi_dfps_store_pll_codes(pinfo);
319 if (ret)
320 dprintf(CRITICAL, "Cannot store pll codes!\n");
321
322dfps_cal_done:
Huaibin Yangb9f15e52015-01-22 10:34:47 -0800323 if (pinfo->dfps.dfps_fb_base)
324 memcpy(pinfo->dfps.dfps_fb_base, &pinfo->dfps,
325 sizeof(struct dfps_info));
Huaibin Yangcbec39b2014-11-07 13:54:38 -0800326dfps_done:
327 return ret;
328}
329
Casey Piper1bbd1572013-09-11 16:23:18 -0700330static int mdss_dsi_bl_enable(uint8_t enable)
331{
332 int ret = NO_ERROR;
333
334 ret = panel_backlight_ctrl(enable);
335 if (ret)
336 dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" :
337 "disable");
338 return ret;
339}
340
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700341static void mdss_edp_panel_init(struct msm_panel_info *pinfo)
342{
343 return target_edp_panel_init(pinfo);
344}
345
346static uint32_t mdss_edp_panel_clock(uint8_t enable,
347 struct msm_panel_info *pinfo)
348{
349 return target_edp_panel_clock(enable, pinfo);
350}
351
352static uint32_t mdss_edp_panel_enable(void)
353{
354 return target_edp_panel_enable();
355}
356
357static uint32_t mdss_edp_panel_disable(void)
358{
359 return target_edp_panel_disable();
360}
361
Kuogee Hsieh93bcff62014-08-22 14:02:08 -0700362static int mdss_edp_panel_power(uint8_t enable,
363 struct msm_panel_info *pinfo)
Arpita Banerjee841fa062013-05-24 14:59:51 -0700364{
Casey Piperc574e082013-09-05 14:54:42 -0700365 int ret = NO_ERROR;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700366
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700367 if (enable) {
Kuogee Hsieh93bcff62014-08-22 14:02:08 -0700368 ret = target_ldo_ctrl(enable, pinfo);
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700369 if (ret) {
370 dprintf(CRITICAL, "LDO control enable failed\n");
371 return ret;
372 }
373
374 ret = mdss_edp_panel_enable();
375 if (ret) {
376 dprintf(CRITICAL, "%s: panel enable failed\n", __func__);
377 return ret;
378 }
379 dprintf(SPEW, "EDP Panel power on done\n");
380 } else {
381 /* Disable panel and ldo */
382 ret = mdss_edp_panel_disable();
383 if (ret) {
384 dprintf(CRITICAL, "%s: panel disable failed\n", __func__);
385 return ret;
386 }
387
Kuogee Hsieh93bcff62014-08-22 14:02:08 -0700388 ret = target_ldo_ctrl(enable, pinfo);
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700389 if (ret) {
390 dprintf(CRITICAL, "%s: ldo control disable failed\n", __func__);
391 return ret;
392 }
393 dprintf(SPEW, "EDP Panel power off done\n");
394 }
395
396 return ret;
397}
398
399static int mdss_edp_bl_enable(uint8_t enable)
400{
401 int ret = NO_ERROR;
402
403 ret = target_edp_bl_ctrl(enable);
404 if (ret)
405 dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" :
406 "disable");
407 return ret;
408}
409
Vineet Bajajc2272462015-05-07 17:35:03 +0530410static int mdss_dsi2HDMI_config (struct msm_panel_info *pinfo)
411{
412 return target_display_dsi2hdmi_config(pinfo);
413}
414
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530415struct panel_struct mdss_dsi_get_panel_data(void)
416{
417 return panelstruct;
418}
419
Padmanabhan Komandurudc0eaca2015-08-28 16:29:59 +0530420static void mdss_dsi_check_swap_status(void)
421{
422 char *panel_dest, *dsi_controller;
423 struct oem_panel_data *oem_data = mdss_dsi_get_oem_data_ptr();
424
425 if (!oem_data->swap_dsi_ctrl)
426 return;
427
428 if (panelstruct.paneldata->panel_operating_mode &
429 (SPLIT_DISPLAY_FLAG | DUAL_DSI_FLAG)) {
430 dprintf(CRITICAL, "DSI swap invalid for split DSI panel!\n");
431 return;
432 }
433
434 /* Swap the panel destination and use appropriate PLL */
435 if (!strcmp(panelstruct.paneldata->panel_destination, "DISPLAY_1")) {
436 panel_dest = "DISPLAY_2";
437 dsi_controller = "dsi:1:";
438 panelstruct.paneldata->panel_operating_mode |= USE_DSI1_PLL_FLAG;
439 } else {
440 panel_dest = "DISPLAY_1";
441 dsi_controller = "dsi:0:";
442 panelstruct.paneldata->panel_operating_mode &= ~USE_DSI1_PLL_FLAG;
443 }
444 panelstruct.paneldata->panel_destination = panel_dest;
445 panelstruct.paneldata->panel_controller = dsi_controller;
446}
447
Padmanabhan Komanduru75f5b3b2015-07-06 18:28:51 +0530448static void mdss_dsi_set_pll_src(void)
449{
450 struct oem_panel_data *oem_data = mdss_dsi_get_oem_data_ptr();
451
Padmanabhan Komanduruaa1e6832015-08-28 14:55:24 +0530452 /* Set PLL_SRC to PLL1 for non dual-DSI cases only */
453 if (!is_dsi_config_dual() &&
454 (panelstruct.paneldata->panel_operating_mode &
455 USE_DSI1_PLL_FLAG))
Padmanabhan Komanduru75f5b3b2015-07-06 18:28:51 +0530456 oem_data->dsi_pll_src = DSI_PLL1;
457
Padmanabhan Komanduruaa1e6832015-08-28 14:55:24 +0530458 if (is_dsi_config_dual()) {
Padmanabhan Komanduru75f5b3b2015-07-06 18:28:51 +0530459 if (oem_data->dsi_pll_src != DSI_PLL_DEFAULT) {
460 dprintf(CRITICAL, "Dual DSI config detected!"
461 "Use default PLL\n");
462 oem_data->dsi_pll_src = DSI_PLL_DEFAULT;
463 }
Padmanabhan Komanduruaa1e6832015-08-28 14:55:24 +0530464 } else if (is_dsi_config_split()) {
Padmanabhan Komanduru75f5b3b2015-07-06 18:28:51 +0530465 if((dsi_video_mode_phy_db.pll_type != DSI_PLL_TYPE_THULIUM)
466 && (oem_data->dsi_pll_src == DSI_PLL1)) {
467 dprintf(CRITICAL, "Split DSI on 28nm/20nm!"
468 "Use DSI PLL0\n");
469 oem_data->dsi_pll_src = DSI_PLL0;
470 }
471 } else {
472 if ((dsi_video_mode_phy_db.pll_type != DSI_PLL_TYPE_THULIUM)
473 && !strcmp(panelstruct.paneldata->panel_destination,
474 "DISPLAY_1") && (oem_data->dsi_pll_src == DSI_PLL1)) {
475 dprintf(CRITICAL, "Single DSI with DSI-0 on 28nm/20nm!"
476 "Use DSI PLL0\n");
477 oem_data->dsi_pll_src = DSI_PLL0;
478 }
479 }
480
481 if (oem_data->dsi_pll_src == DSI_PLL1)
482 panelstruct.paneldata->panel_operating_mode |=
483 USE_DSI1_PLL_FLAG;
Padmanabhan Komanduruaa1e6832015-08-28 14:55:24 +0530484 else if (oem_data->dsi_pll_src == DSI_PLL0)
Padmanabhan Komanduru75f5b3b2015-07-06 18:28:51 +0530485 panelstruct.paneldata->panel_operating_mode &=
486 ~USE_DSI1_PLL_FLAG;
Padmanabhan Komanduru75f5b3b2015-07-06 18:28:51 +0530487}
488
Wenjun Zhang4e63ce42017-11-28 05:11:34 -0500489static int mdss_spi_bl_enable(uint8_t enable)
490{
491 int ret = NO_ERROR;
492
493 ret = panel_backlight_ctrl(enable);
494 if (ret)
495 dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" : "disable");
496 return ret;
497}
498
499static int mdss_spi_panel_power(uint8_t enable, struct msm_panel_info *pinfo)
500{
501 int ret = NO_ERROR;
502
503 if (enable) {
504 ret = target_ldo_ctrl(enable, pinfo);
505 if (ret) {
506 dprintf(CRITICAL, "LDO control enable failed\n");
507 return ret;
508 }
509
510 /*Panel Reset*/
511 ret = target_panel_reset(enable,panelstruct.panelresetseq, &panel.panel_info);
512 if (ret) {
513 dprintf(CRITICAL, "panel reset failed\n");
514 return ret;
515 }
516 dprintf(INFO, "Panel power on done\n");
517 } else {
518 /*Disable panel and ldo*/
519 ret = target_panel_reset(enable, panelstruct.panelresetseq, &panel.panel_info);
520 if (ret) {
521 dprintf(CRITICAL, "panel reset disable failed \n");
522 return ret;
523 }
524
525 ret = target_ldo_ctrl(enable, pinfo);
526 if (ret) {
527 dprintf(CRITICAL, "panel reset disable failed \n");
528 return ret;
529 }
530 dprintf(INFO, "Panel power off done\n");
531 }
532
533 return ret;
534}
535
Dhaval Pateld96d0922015-10-20 16:06:21 -0700536static int update_dsi_display_config()
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700537{
538 int ret = NO_ERROR;
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700539
Ujwal Patel41a665a2015-07-17 13:51:30 -0700540 if ((panel.panel_info.lm_split[0] > 0) &&
541 (panel.panel_info.lm_split[1] > 0))
542 panelstruct.paneldata->panel_operating_mode |= DUAL_PIPE_FLAG;
543
544 if (panelstruct.paneldata->panel_operating_mode & DUAL_PIPE_FLAG) {
545 if ((panel.panel_info.lm_split[0] <= 0) ||
546 (panel.panel_info.lm_split[1] <= 0)) {
547 panel.panel_info.lm_split[0] =
548 panelstruct.panelres->panel_width / 2;
549 panel.panel_info.lm_split[1] =
550 panel.panel_info.lm_split[0];
551 }
552 }
553
Ujwal Patel5c3227b2015-08-12 14:48:02 -0700554 if (panelstruct.config && panelstruct.config->use_pingpong_split)
555 panelstruct.paneldata->panel_operating_mode |= DST_SPLIT_FLAG;
556
557 if ((panelstruct.paneldata->panel_operating_mode & DUAL_PIPE_FLAG) &&
558 (panelstruct.paneldata->panel_operating_mode & DST_SPLIT_FLAG)) {
559 dprintf(CRITICAL, "DUAL_PIPE_FLAG and DST_SPLIT_FLAG cannot be selected togather\n");
560 ret = ERROR;
Ujwal Patel5c3227b2015-08-12 14:48:02 -0700561 }
562
Dhaval Pateld96d0922015-10-20 16:06:21 -0700563 return ret;
564}
565
566int gcdb_display_init(const char *panel_name, uint32_t rev, void *base)
567{
568 int ret = NO_ERROR;
569 int pan_type;
570
571 dsi_video_mode_phy_db.pll_type = DSI_PLL_TYPE_28NM;
Frank Yi2b7e2b92018-04-25 16:24:45 +0800572 panel.panel_info.disable_wled_labibb = false;
Dhaval Pateld96d0922015-10-20 16:06:21 -0700573 pan_type = oem_panel_select(panel_name, &panelstruct, &(panel.panel_info),
574 &dsi_video_mode_phy_db);
575
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700576 if (pan_type == PANEL_TYPE_DSI) {
Dhaval Pateld96d0922015-10-20 16:06:21 -0700577 if (update_dsi_display_config())
578 goto error_gcdb_display_init;
Dhaval Patel7709c412015-05-12 10:09:41 -0700579 target_dsi_phy_config(&dsi_video_mode_phy_db);
Padmanabhan Komandurudc0eaca2015-08-28 16:29:59 +0530580 mdss_dsi_check_swap_status();
Padmanabhan Komanduru75f5b3b2015-07-06 18:28:51 +0530581 mdss_dsi_set_pll_src();
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700582 if (dsi_panel_init(&(panel.panel_info), &panelstruct)) {
583 dprintf(CRITICAL, "DSI panel init failed!\n");
584 ret = ERROR;
585 goto error_gcdb_display_init;
586 }
587
588 panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db;
589 panel.pll_clk_func = mdss_dsi_panel_clock;
Huaibin Yangcbec39b2014-11-07 13:54:38 -0800590 panel.dfps_func = mdss_dsi_mipi_dfps_config;
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700591 panel.power_func = mdss_dsi_panel_power;
592 panel.pre_init_func = mdss_dsi_panel_pre_init;
593 panel.bl_func = mdss_dsi_bl_enable;
Vineet Bajajc2272462015-05-07 17:35:03 +0530594 panel.dsi2HDMI_config = mdss_dsi2HDMI_config;
Huaibin Yangb9f15e52015-01-22 10:34:47 -0800595 /*
Padmanabhan Komanduru53c2e972016-02-18 19:00:34 +0530596 * Reserve fb memory to store pll codes and pass
597 * pll codes values to kernel.
Huaibin Yangb9f15e52015-01-22 10:34:47 -0800598 */
Padmanabhan Komanduru53c2e972016-02-18 19:00:34 +0530599 panel.panel_info.dfps.dfps_fb_base = base;
600 base += DFPS_PLL_CODES_SIZE;
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700601 panel.fb.base = base;
Padmanabhan Komanduru53c2e972016-02-18 19:00:34 +0530602 dprintf(SPEW, "dfps base=0x%p,d, fb_base=0x%p!\n",
603 panel.panel_info.dfps.dfps_fb_base, base);
604
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700605 panel.fb.width = panel.panel_info.xres;
606 panel.fb.height = panel.panel_info.yres;
607 panel.fb.stride = panel.panel_info.xres;
608 panel.fb.bpp = panel.panel_info.bpp;
609 panel.fb.format = panel.panel_info.mipi.dst_format;
610 } else if (pan_type == PANEL_TYPE_EDP) {
611 mdss_edp_panel_init(&(panel.panel_info));
612 /* prepare func is set up at edp_panel_init */
613 panel.clk_func = mdss_edp_panel_clock;
614 panel.power_func = mdss_edp_panel_power;
615 panel.bl_func = mdss_edp_bl_enable;
616 panel.fb.format = FB_FORMAT_RGB888;
Wenjun Zhang4e63ce42017-11-28 05:11:34 -0500617 } else if (pan_type == PANEL_TYPE_SPI) {
618 panel.panel_info.xres = panelstruct.panelres->panel_width;
619 panel.panel_info.yres = panelstruct.panelres->panel_height;
620 panel.panel_info.bpp = panelstruct.color->color_format;
621 panel.power_func = mdss_spi_panel_power;
622 panel.bl_func = mdss_spi_bl_enable;
623 panel.fb.base = base;
624 panel.fb.width = panel.panel_info.xres;
625 panel.fb.height = panel.panel_info.yres;
626 panel.fb.bpp = panel.panel_info.bpp;
627 panel.fb.format = FB_FORMAT_RGB565;
628 panel.panel_info.type = SPI_PANEL;
Kuogee Hsieh80b8a6c2014-06-09 17:25:38 -0700629 } else {
Arpita Banerjee841fa062013-05-24 14:59:51 -0700630 dprintf(CRITICAL, "Target panel init not found!\n");
Casey Piperc574e082013-09-05 14:54:42 -0700631 ret = ERR_NOT_SUPPORTED;
632 goto error_gcdb_display_init;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700633 }
634
Arpita Banerjee841fa062013-05-24 14:59:51 -0700635 panel.fb.base = base;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700636 panel.mdp_rev = rev;
637
Casey Piperc574e082013-09-05 14:54:42 -0700638 ret = msm_display_init(&panel);
Arpita Banerjee841fa062013-05-24 14:59:51 -0700639
Casey Piperc574e082013-09-05 14:54:42 -0700640error_gcdb_display_init:
641 display_enable = ret ? 0 : 1;
642 return ret;
Arpita Banerjee841fa062013-05-24 14:59:51 -0700643}
644
645void gcdb_display_shutdown(void)
646{
647 if (display_enable)
648 msm_display_off();
649}