blob: 6a49e1e0ce7e9d39b952040655062f94624bd2d7 [file] [log] [blame]
Xipeng Gu5affb812019-06-18 14:59:17 +08001/* Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -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 <string.h>
32#include <smem.h>
33#include <err.h>
34#include <msm_panel.h>
35#include <mipi_dsi.h>
36#include <pm8x41.h>
37#include <pm8x41_wled.h>
38#include <qpnp_wled.h>
Umang Agrawald1939942018-02-13 16:23:58 +053039#include <qpnp_lcdb.h>
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -070040#include <board.h>
41#include <mdp5.h>
42#include <scm.h>
43#include <regulator.h>
44#include <platform/clock.h>
45#include <platform/gpio.h>
46#include <platform/iomap.h>
47#include <target/display.h>
48#include <qtimer.h>
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +053049#include <platform.h>
Umang Agrawald1939942018-02-13 16:23:58 +053050#include <target.h>
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -070051
52#include "include/panel.h"
53#include "include/display_resource.h"
54#include "gcdb_display.h"
55
Lei Chen2c11b462018-04-11 18:42:37 +080056#define PWM_DUTY_US 13
57#define PWM_PERIOD_US 27
58
Ashish Garg9cfd6ca2016-12-20 01:41:54 +053059#define TRULY_720P_VID_PANEL "truly_720p_video"
60#define TRULY_720P_CMD_PANEL "truly_720p_cmd"
61
62#define HDMI_ADV_PANEL_STRING "1:dsi:0:qcom,mdss_dsi_adv7533_1080p:1:none:cfg:single_dsi"
63#define TRULY_VID_PANEL_STRING "1:dsi:0:qcom,mdss_dsi_truly_720p_video:1:none:cfg:single_dsi"
64#define TRULY_CMD_PANEL_STRING "1:dsi:0:qcom,mdss_dsi_truly_720p_cmd:1:none:cfg:single_dsi"
65
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -070066/*---------------------------------------------------------------------------*/
67/* GPIO configuration */
68/*---------------------------------------------------------------------------*/
69static struct gpio_pin reset_gpio = {
70 "msmgpio", 0, 3, 1, 0, 1
71};
72
73static struct gpio_pin enable_gpio = {
74 "msmgpio", 90, 3, 1, 0, 1
75};
76
77static struct gpio_pin bkl_gpio = {
78 "msmgpio", 91, 3, 1, 0, 1
79};
80
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +053081static struct gpio_pin lcd_mode_gpio = {
82 "msmgpio", 107, 3, 1, 0, 1
83};
84
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +053085static struct gpio_pin bkl_en_gpio = {
86"pm8953", 4, 3, 1, 0, 1
87};
88
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -070089#define VCO_DELAY_USEC 1000
90#define GPIO_STATE_LOW 0
91#define GPIO_STATE_HIGH 2
92#define RESET_GPIO_SEQ_LEN 3
93#define PMIC_WLED_SLAVE_ID 3
94
Padmanabhan Komandurub3381932015-06-15 22:14:02 +053095#define DSI0_BASE_ADJUST -0x4000
96#define DSI0_PHY_BASE_ADJUST -0x4100
97#define DSI0_PHY_PLL_BASE_ADJUST -0x3900
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +053098#define DSI0_12NM_PHY_PLL_BASE_ADJUST -0x3F00
Padmanabhan Komandurub3381932015-06-15 22:14:02 +053099#define DSI0_PHY_REGULATOR_BASE_ADJUST -0x3C00
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530100#define DSI1_12NM_PHY_PLL_BASE_ADJUST -0x600
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530101
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700102static void mdss_dsi_uniphy_pll_sw_reset_8952(uint32_t pll_base)
103{
104 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
105 mdelay(1);
106 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
107 mdelay(1);
108}
109
110static void dsi_pll_toggle_lock_detect_8952(uint32_t pll_base)
111{
112 writel(0x04, pll_base + 0x0064); /* LKDetect CFG2 */
113 udelay(1);
114 writel(0x05, pll_base + 0x0064); /* LKDetect CFG2 */
115 udelay(512);
116}
117
118static void dsi_pll_sw_reset_8952(uint32_t pll_base)
119{
120 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
121 udelay(1);
122 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
Padmanabhan Komanduru6cf63522015-06-08 14:48:00 +0530123 udelay(1);
124}
125
126static uint32_t dsi_pll_lock_status_8956(uint32_t pll_base)
127{
128 uint32_t counter, status;
129
130 status = readl(pll_base + 0x00c0) & 0x01;
131 for (counter = 0; counter < 5 && !status; counter++) {
132 udelay(100);
133 status = readl(pll_base + 0x00c0) & 0x01;
134 }
135
136 return status;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700137}
138
139static uint32_t gf_1_dsi_pll_enable_sequence_8952(uint32_t pll_base)
140{
141 uint32_t rc;
142
143 dsi_pll_sw_reset_8952(pll_base);
144
145 /*
146 * Add hardware recommended delays between register writes for
147 * the updates to take effect. These delays are necessary for the
148 * PLL to successfully lock
149 */
150 writel(0x14, pll_base + 0x0070); /* CAL CFG1*/
151 writel(0x01, pll_base + 0x0020); /* GLB CFG */
152 writel(0x05, pll_base + 0x0020); /* GLB CFG */
153 udelay(3);
154 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
155 udelay(500);
156
157 dsi_pll_toggle_lock_detect_8952(pll_base);
158 rc = readl(pll_base + 0x00c0) & 0x01;
159
160 return rc;
161}
162
163static uint32_t gf_2_dsi_pll_enable_sequence_8952(uint32_t pll_base)
164{
165 uint32_t rc;
166
167 dsi_pll_sw_reset_8952(pll_base);
168
169 /*
170 * Add hardware recommended delays between register writes for
171 * the updates to take effect. These delays are necessary for the
172 * PLL to successfully lock
173 */
174 writel(0x04, pll_base + 0x0070); /* CAL CFG1*/
175 writel(0x01, pll_base + 0x0020); /* GLB CFG */
176 writel(0x05, pll_base + 0x0020); /* GLB CFG */
177 udelay(3);
178 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
179 udelay(500);
180
181 dsi_pll_toggle_lock_detect_8952(pll_base);
182 rc = readl(pll_base + 0x00c0) & 0x01;
183
184 return rc;
185}
186
187static uint32_t tsmc_dsi_pll_enable_sequence_8952(uint32_t pll_base)
188{
189 uint32_t rc;
190
191 dsi_pll_sw_reset_8952(pll_base);
192 /*
193 * Add hardware recommended delays between register writes for
194 * the updates to take effect. These delays are necessary for the
195 * PLL to successfully lock
196 */
197
198 writel(0x34, pll_base + 0x0070); /* CAL CFG1*/
199 writel(0x01, pll_base + 0x0020); /* GLB CFG */
200 writel(0x05, pll_base + 0x0020); /* GLB CFG */
201 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
202 udelay(500);
203
204 dsi_pll_toggle_lock_detect_8952(pll_base);
205 rc = readl(pll_base + 0x00c0) & 0x01;
206
207 return rc;
208}
209
210
211static uint32_t dsi_pll_enable_seq_8952(uint32_t pll_base)
212{
213 uint32_t pll_locked = 0;
214 uint32_t counter = 0;
215
216 do {
217 pll_locked = tsmc_dsi_pll_enable_sequence_8952(pll_base);
218
219 dprintf(SPEW, "TSMC pll locked status is %d\n", pll_locked);
220 ++counter;
221 } while (!pll_locked && (counter < 3));
222
223 if(!pll_locked) {
224 counter = 0;
225 do {
226 pll_locked = gf_1_dsi_pll_enable_sequence_8952(pll_base);
227
228 dprintf(SPEW, "GF P1 pll locked status is %d\n", pll_locked);
229 ++counter;
230 } while (!pll_locked && (counter < 3));
231 }
232
233 if(!pll_locked) {
234 counter = 0;
235 do {
236 pll_locked = gf_2_dsi_pll_enable_sequence_8952(pll_base);
237
238 dprintf(SPEW, "GF P2 pll locked status is %d\n", pll_locked);
239 ++counter;
240 } while (!pll_locked && (counter < 3));
241 }
242
243 return pll_locked;
244}
245
Padmanabhan Komanduru6cf63522015-06-08 14:48:00 +0530246static uint32_t dsi_pll_enable_seq_8956(uint32_t pll_base)
247{
248 /*
249 * PLL power up sequence
250 * Add necessary delays recommended by h/w team
251 */
252
253 /* Lock Detect setting */
254 writel(0x0d, pll_base + 0x0064); /* LKDetect CFG2 */
255 writel(0x34, pll_base + 0x0070); /* PLL CAL_CFG1 */
256 writel(0x10, pll_base + 0x005c); /* LKDetect CFG0 */
257 writel(0x1a, pll_base + 0x0060); /* LKDetect CFG1 */
258
259 writel(0x01, pll_base + 0x0020); /* GLB CFG */
260 udelay(300);
261 writel(0x05, pll_base + 0x0020); /* GLB CFG */
262 udelay(300);
263 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
264 udelay(300);
265 writel(0x07, pll_base + 0x0020); /* GLB CFG */
266 udelay(300);
267 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
268 udelay(1000);
269
270 return dsi_pll_lock_status_8956(pll_base);
271}
272
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700273static int msm8952_wled_backlight_ctrl(uint8_t enable)
274{
275 uint8_t slave_id = PMIC_WLED_SLAVE_ID; /* pmi */
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530276 uint32_t pmic_type = target_get_pmic();
277
Umang Agrawaldff10da2019-05-08 16:14:13 +0530278 if(pmic_type == PMIC_IS_PM8916 || pmic_type == PMIC_IS_PM660)
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530279 return NO_ERROR;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700280
281 pm8x41_wled_config_slave_id(slave_id);
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530282 if (pmic_type == PMIC_IS_PMI632) {
Umang Agrawald1939942018-02-13 16:23:58 +0530283 qpnp_lcdb_enable(enable);
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530284 } else {
Umang Agrawald1939942018-02-13 16:23:58 +0530285 qpnp_wled_enable_backlight(enable);
286 qpnp_ibb_enable(enable);
287 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700288 return NO_ERROR;
289}
290
Lei Chen2c11b462018-04-11 18:42:37 +0800291static int pwm_backlight_ctrl(uint8_t enable)
292{
293 if (enable) {
294 pm_pwm_enable(false);
295 pm_pwm_config(PWM_DUTY_US, PWM_PERIOD_US);
296 pm_pwm_enable(true);
297 } else {
298 pm_pwm_enable(false);
299 }
300
301 return NO_ERROR;
302}
303
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700304int target_backlight_ctrl(struct backlight *bl, uint8_t enable)
305{
306 uint32_t ret = NO_ERROR;
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530307 uint32_t pmic_type = target_get_pmic();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700308
309 if (bl->bl_interface_type == BL_DCS)
310 return ret;
311
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530312 if ((pmic_type == PMIC_IS_PMI632) &&
Lei Chen2c11b462018-04-11 18:42:37 +0800313 (bl->bl_interface_type == BL_PWM)) {
314 ret = pwm_backlight_ctrl(enable);
Umang Agrawaldff10da2019-05-08 16:14:13 +0530315 } else if (pmic_type == PMIC_IS_PM8916 || pmic_type == PMIC_IS_PM660) {
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530316 ret = pwm_backlight_ctrl(enable);
Lei Chen2c11b462018-04-11 18:42:37 +0800317 } else {
318 ret = msm8952_wled_backlight_ctrl(enable);
319 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700320 return ret;
321}
322
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530323static int32_t mdss_dsi_pll_config(uint32_t pll_base, uint32_t ctl_base,
324 struct mdss_dsi_pll_config *pll_data)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700325{
326 int32_t ret = 0;
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530327 if (!platform_is_msm8956())
328 mdss_dsi_uniphy_pll_sw_reset_8952(pll_base);
329 else
330 dsi_pll_sw_reset_8952(pll_base);
331 mdss_dsi_auto_pll_config(pll_base, ctl_base, pll_data);
332 if (platform_is_msm8956())
333 ret = dsi_pll_enable_seq_8956(pll_base);
334 else
335 ret = dsi_pll_enable_seq_8952(pll_base);
336
337 return ret;
338}
339
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700340int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
341{
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530342 int32_t ret = 0, flags;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700343 struct mdss_dsi_pll_config *pll_data;
344 dprintf(SPEW, "target_panel_clock\n");
345
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530346 if (pinfo->dest == DISPLAY_2) {
347 flags = MMSS_DSI_CLKS_FLAG_DSI1;
348 if (pinfo->mipi.dual_dsi)
349 flags |= MMSS_DSI_CLKS_FLAG_DSI0;
350 } else {
351 flags = MMSS_DSI_CLKS_FLAG_DSI0;
352 if (pinfo->mipi.dual_dsi)
353 flags |= MMSS_DSI_CLKS_FLAG_DSI1;
354 }
355
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700356 pll_data = pinfo->mipi.dsi_pll_config;
357 pll_data->vco_delay = VCO_DELAY_USEC;
358
Padmanabhan Komanduruf68f51b2015-12-21 18:32:12 +0530359 /* SSC parameters */
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530360 if (platform_is_msm8937() || platform_is_msm8917() || platform_is_qm215()) {
Padmanabhan Komanduruf68f51b2015-12-21 18:32:12 +0530361 pll_data->ssc_en = true;
362 pll_data->is_center_spread = false;
363 pll_data->ssc_freq = 30000;
364 pll_data->ssc_ppm = 5000;
shaoxing0534f8b2019-07-08 19:56:02 +0800365 } else if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w()) {
Padmanabhan Komandurue54f7612018-05-03 09:29:50 +0530366 pll_data->ssc_en = true;
367 pll_data->is_center_spread = false;
368 pll_data->ssc_freq = 31500;
369 pll_data->ssc_ppm = 5000;
Padmanabhan Komanduruf68f51b2015-12-21 18:32:12 +0530370 }
371
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700372 if (enable) {
373 mdp_gdsc_ctrl(enable);
374 mdss_bus_clocks_enable();
375 mdp_clock_enable();
376 ret = restore_secure_cfg(SECURE_DEVICE_MDSS);
377 if (ret) {
378 dprintf(CRITICAL,
379 "%s: Failed to restore MDP security configs",
380 __func__);
381 mdp_clock_disable();
382 mdss_bus_clocks_disable();
383 mdp_gdsc_ctrl(0);
384 return ret;
385 }
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530386
Padmanabhan Komanduru62eec852018-05-14 12:27:30 +0530387 gcc_dsi_lp_clock_enable(flags);
388
shaoxing0534f8b2019-07-08 19:56:02 +0800389 if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530390 mdss_dsi_auto_pll_12nm_config(pinfo);
391
392 /*
393 * enable clock/data lane in DSI controller
394 * before enabling DSI PLL for 12nm PHY
395 */
396 if (pinfo->lane_config)
397 pinfo->lane_config(pinfo);
398
399 ret = mdss_dsi_auto_pll_12nm_enable(pinfo);
400 if (!ret)
401 dprintf(CRITICAL, "unable to ON 12nm PLL\n");
402 } else {
403 ret = mdss_dsi_pll_config(pinfo->mipi.pll_base,
404 pinfo->mipi.ctl_base, pll_data);
405 if (!ret)
406 dprintf(CRITICAL, "unable to ON master pll\n");
407 }
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530408
Padmanabhan Komanduru2a6c3452015-09-09 18:46:06 +0530409 if (platform_is_msm8956() && pinfo->mipi.dual_dsi &&
410 !platform_is_msm8976_v_1_1()) {
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530411 ret = mdss_dsi_pll_config(pinfo->mipi.spll_base,
412 pinfo->mipi.sctl_base, pll_data);
413 if (!ret)
414 dprintf(CRITICAL, "Not able to enable second pll\n");
415 }
416
Padmanabhan Komanduru62eec852018-05-14 12:27:30 +0530417 gcc_dsi_hs_clocks_enable(flags, pinfo->mipi.use_dsi1_pll,
Padmanabhan Komanduru2a6c3452015-09-09 18:46:06 +0530418 pll_data->pclk_m, pll_data->pclk_n, pll_data->pclk_d);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700419 } else if(!target_cont_splash_screen()) {
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530420 gcc_dsi_clocks_disable(flags);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700421 mdp_clock_disable();
422 mdss_bus_clocks_disable();
423 mdp_gdsc_ctrl(enable);
424 }
425
426 return 0;
427}
428
429int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
430 struct msm_panel_info *pinfo)
431{
432 int ret = NO_ERROR;
Sujeev Dias6bc9fa32015-08-03 23:13:44 -0700433 uint32_t hw_id = board_hardware_id();
434 uint32_t hw_subtype = board_hardware_subtype();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700435
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530436 if (platform_is_msm8956()) {
437 reset_gpio.pin_id = 25;
438 bkl_gpio.pin_id = 66;
Padmanabhan Komandurub3231322015-11-12 16:54:21 +0530439 } else if (platform_is_msm8937()) {
440 reset_gpio.pin_id = 60;
441 bkl_gpio.pin_id = 98;
442 enable_gpio.pin_id = 99;
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530443 } else if (platform_is_msm8917()) {
Jayant Shekhar9c0533e2016-01-28 11:17:18 +0530444 reset_gpio.pin_id = 60;
445 bkl_gpio.pin_id = 98;
446 pinfo->mipi.use_enable_gpio = 0;
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530447 } else if (platform_is_qm215()) {
448 dprintf(CRITICAL,"vproddut: coming here \n");
449 reset_gpio.pin_id = 60;
450 bkl_gpio.pin_id = 93;
451 enable_gpio.pin_id = 94;
452 pinfo->mipi.use_enable_gpio = 1;
shaoxing0534f8b2019-07-08 19:56:02 +0800453 } else if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530454 reset_gpio.pin_id = 60;
shaoxing0534f8b2019-07-08 19:56:02 +0800455 if ((platform_is_sdm429() || platform_is_sdm429w()) && hw_subtype
Xipeng Gu5affb812019-06-18 14:59:17 +0800456 == HW_PLATFORM_SUBTYPE_429W_PM660) {
457 reset_gpio.pin_id = 60;
458 pinfo->mipi.use_enable_gpio = 1;
459 enable_gpio.pin_id = 69;
460 }
Sujeev Dias6bc9fa32015-08-03 23:13:44 -0700461 } else if ((hw_id == HW_PLATFORM_QRD) &&
462 (hw_subtype == HW_PLATFORM_SUBTYPE_POLARIS)) {
463 enable_gpio.pin_id = 19;
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530464 }
465
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700466 if (enable) {
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530467 if (pinfo->mipi.use_enable_gpio && !platform_is_msm8956()) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700468 gpio_tlmm_config(enable_gpio.pin_id, 0,
469 enable_gpio.pin_direction, enable_gpio.pin_pull,
470 enable_gpio.pin_strength,
471 enable_gpio.pin_state);
472
473 gpio_set_dir(enable_gpio.pin_id, 2);
474 }
475
shaoxing0534f8b2019-07-08 19:56:02 +0800476 if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530477 /* enable PM GPIO-4 for backlight enable */
478 struct pm8x41_gpio gpio_param = {
479 .direction = PM_GPIO_DIR_OUT,
480 .function = PM_GPIO_FUNC_HIGH,
481 .vin_sel = 0, /* VIN_0 */
482 .pull = PM_GPIO_NO_PULL,
483 .output_buffer = PM_GPIO_OUT_CMOS,
484 .out_strength = PM_GPIO_OUT_DRIVE_HIGH,
485 };
486
487 dprintf(SPEW, "%s: gpio=%d enable=%d\n", __func__,
488 bkl_en_gpio.pin_id, enable);
489
490 pm8x41_gpio_config(bkl_en_gpio.pin_id, &gpio_param);
491 } else {
492 gpio_tlmm_config(bkl_gpio.pin_id, 0,
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700493 bkl_gpio.pin_direction, bkl_gpio.pin_pull,
494 bkl_gpio.pin_strength, bkl_gpio.pin_state);
495
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530496 gpio_set_dir(bkl_gpio.pin_id, 2);
497 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700498
499 gpio_tlmm_config(reset_gpio.pin_id, 0,
500 reset_gpio.pin_direction, reset_gpio.pin_pull,
501 reset_gpio.pin_strength, reset_gpio.pin_state);
502
503 gpio_set_dir(reset_gpio.pin_id, 2);
504
505 /* reset */
506 for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) {
507 if (resetseq->pin_state[i] == GPIO_STATE_LOW)
508 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_LOW);
509 else
510 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_HIGH);
511 mdelay(resetseq->sleep[i]);
512 }
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530513
514 if (platform_is_msm8956()) {
515 gpio_tlmm_config(lcd_mode_gpio.pin_id, 0,
516 lcd_mode_gpio.pin_direction, lcd_mode_gpio.pin_pull,
517 lcd_mode_gpio.pin_strength, lcd_mode_gpio.pin_state);
518
519 if (pinfo->lcdc.split_display || pinfo->lcdc.dst_split)
520 gpio_set_dir(lcd_mode_gpio.pin_id, GPIO_STATE_LOW);
521 else
522 gpio_set_dir(lcd_mode_gpio.pin_id, GPIO_STATE_HIGH);
523 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700524 } else if(!target_cont_splash_screen()) {
525 gpio_set_dir(reset_gpio.pin_id, 0);
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530526 if (pinfo->mipi.use_enable_gpio && !platform_is_msm8956())
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700527 gpio_set_dir(enable_gpio.pin_id, 0);
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530528 if (platform_is_msm8956())
529 gpio_set_dir(lcd_mode_gpio.pin_id, 0);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700530 }
531
532 return ret;
533}
534
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530535static int wled_init(struct msm_panel_info *pinfo)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700536{
537 struct qpnp_wled_config_data config = {0};
538 struct labibb_desc *labibb;
539 int display_type = 0;
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530540 bool swire_control = 0;
541 bool wled_avdd_control = 0;
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530542 int rc = NO_ERROR;
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530543 uint32_t pmic_type = target_get_pmic();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700544
Umang Agrawaldff10da2019-05-08 16:14:13 +0530545 if(pmic_type == PMIC_IS_PM8916 || pmic_type == PMIC_IS_PM660)
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530546 return NO_ERROR;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700547 labibb = pinfo->labibb;
548
549 if (labibb)
550 display_type = labibb->amoled_panel;
551
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530552 if (display_type) {
553 swire_control = labibb->swire_control;
554 wled_avdd_control = true;
555 } else {
556 swire_control = false;
557 wled_avdd_control = false;
558 }
559
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700560 config.display_type = display_type;
561 config.lab_init_volt = 4600000; /* fixed, see pmi register */
562 config.ibb_init_volt = 1400000; /* fixed, see pmi register */
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530563 config.lab_ibb_swire_control = swire_control;
564 config.wled_avdd_control = wled_avdd_control;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700565
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530566 if(!swire_control) {
567 if (labibb && labibb->force_config) {
568 config.lab_min_volt = labibb->lab_min_volt;
569 config.lab_max_volt = labibb->lab_max_volt;
570 config.ibb_min_volt = labibb->ibb_min_volt;
571 config.ibb_max_volt = labibb->ibb_max_volt;
572 config.pwr_up_delay = labibb->pwr_up_delay;
573 config.pwr_down_delay = labibb->pwr_down_delay;
574 config.ibb_discharge_en = labibb->ibb_discharge_en;
575 } else {
576 /* default */
577 config.pwr_up_delay = 3;
578 config.pwr_down_delay = 3;
579 config.ibb_discharge_en = 1;
580 if (display_type) { /* amoled */
581 config.lab_min_volt = 4600000;
582 config.lab_max_volt = 4600000;
583 config.ibb_min_volt = 4000000;
584 config.ibb_max_volt = 4000000;
585 } else { /* lcd */
586 config.lab_min_volt = 5500000;
587 config.lab_max_volt = 5500000;
588 config.ibb_min_volt = 5500000;
589 config.ibb_max_volt = 5500000;
590 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700591 }
592 }
593
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530594 if (pmic_type == PMIC_IS_PMI632) {
Narender Ankambf2e2dd2018-05-30 17:48:11 +0530595 config.pwr_up_delay = 1;
596 config.pwr_down_delay = 0;
597 }
598
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700599 dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d %d %d\n", __func__,
600 config.display_type,
601 config.lab_min_volt, config.lab_max_volt,
602 config.ibb_min_volt, config.ibb_max_volt,
603 config.lab_init_volt, config.ibb_init_volt,
604 config.pwr_up_delay, config.pwr_down_delay,
605 config.ibb_discharge_en);
606
607 /* QPNP WLED init for display backlight */
608 pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID);
609
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530610 if (pmic_type == PMIC_IS_PMI632)
Umang Agrawald1939942018-02-13 16:23:58 +0530611 rc = qpnp_lcdb_init(&config);
612 else
613 rc = qpnp_wled_init(&config);
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530614
615 return rc;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700616}
617
Dhaval Patel7709c412015-05-12 10:09:41 -0700618int target_dsi_phy_config(struct mdss_dsi_phy_ctrl *phy_db)
619{
620 memcpy(phy_db->regulator, panel_regulator_settings, REGULATOR_SIZE);
621 memcpy(phy_db->ctrl, panel_physical_ctrl, PHYSICAL_SIZE);
622 memcpy(phy_db->strength, panel_strength_ctrl, STRENGTH_SIZE);
623 memcpy(phy_db->bistCtrl, panel_bist_ctrl, BIST_SIZE);
624 memcpy(phy_db->laneCfg, panel_lane_config, LANE_SIZE);
625 return NO_ERROR;
626}
627
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530628int target_display_get_base_offset(uint32_t base)
629{
shaoxing0534f8b2019-07-08 19:56:02 +0800630 if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530631 if (base == MIPI_DSI0_BASE)
632 return DSI0_BASE_ADJUST;
633 else if (base == DSI0_PHY_BASE)
634 return DSI0_PHY_BASE_ADJUST;
635 else if (base == DSI0_PLL_BASE)
636 return DSI0_12NM_PHY_PLL_BASE_ADJUST;
637 else if (base == DSI1_PLL_BASE)
638 return DSI1_12NM_PHY_PLL_BASE_ADJUST;
639 } else if (platform_is_msm8956() || platform_is_msm8937() ||
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530640 platform_is_msm8917() || platform_is_qm215()) {
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530641 if (base == MIPI_DSI0_BASE)
642 return DSI0_BASE_ADJUST;
643 else if (base == DSI0_PHY_BASE)
644 return DSI0_PHY_BASE_ADJUST;
645 else if (base == DSI0_PLL_BASE)
646 return DSI0_PHY_PLL_BASE_ADJUST;
647 else if (base == DSI0_REGULATOR_BASE)
648 return DSI0_PHY_REGULATOR_BASE_ADJUST;
649 }
650
651 return 0;
652}
653
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700654int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
655{
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530656 int rc = 0;
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530657 uint32_t ldo_num = REG_LDO6 | REG_LDO17;
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530658 uint32_t pmic_type = target_get_pmic();
Xipeng Gu5affb812019-06-18 14:59:17 +0800659 uint32_t hw_subtype = board_hardware_subtype();
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530660
661 if (platform_is_msm8956())
662 ldo_num |= REG_LDO1;
shaoxing0534f8b2019-07-08 19:56:02 +0800663 else if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w())
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530664 ldo_num |= REG_LDO5; /* LDO23 is enable by default */
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530665 else
666 ldo_num |= REG_LDO2;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700667
shaoxing0534f8b2019-07-08 19:56:02 +0800668 if ((platform_is_sdm429() || platform_is_sdm429w()) && hw_subtype
xiaolin6c9bbb82019-07-26 16:20:46 +0800669 == HW_PLATFORM_SUBTYPE_429W_PM660) {
670 ldo_num &= ~(REG_LDO17 | REG_LDO5);
671 ldo_num |= REG_LDO13 | REG_LDO15;
672 }
Xipeng Gu5affb812019-06-18 14:59:17 +0800673
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700674 if (enable) {
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530675 regulator_enable(ldo_num);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700676 mdelay(10);
Frank Yi2b7e2b92018-04-25 16:24:45 +0800677 if(!pinfo->disable_wled_labibb) {
678 rc = wled_init(pinfo);
679 if (rc) {
680 dprintf(CRITICAL, "%s: wled init failed\n", __func__);
681 return rc;
682 }
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530683 if (pmic_type == PMIC_IS_PMI632)
Frank Yi2b7e2b92018-04-25 16:24:45 +0800684 rc = qpnp_lcdb_enable(true);
Umang Agrawaldff10da2019-05-08 16:14:13 +0530685 else if(pmic_type != PMIC_IS_PM8916 && pmic_type != PMIC_IS_PM660)
Frank Yi2b7e2b92018-04-25 16:24:45 +0800686 rc = qpnp_ibb_enable(true); /*5V boost*/
687 if (rc) {
688 dprintf(CRITICAL, "%s: qpnp_ibb/lcdb failed\n", __func__);
689 return rc;
690 }
691 mdelay(50);
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530692 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700693 } else {
Padmanabhan Komandurufa2899b2015-06-30 16:25:33 +0530694 /*
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530695 * LDO1, LDO2, LDO5 and LDO6 are shared with other subsystems.
Padmanabhan Komandurufa2899b2015-06-30 16:25:33 +0530696 * Do not disable them.
697 */
698 regulator_disable(REG_LDO17);
Xipeng Gu5affb812019-06-18 14:59:17 +0800699
shaoxing0534f8b2019-07-08 19:56:02 +0800700 if ((platform_is_sdm429() || platform_is_sdm429w()) && hw_subtype
Xipeng Gu5affb812019-06-18 14:59:17 +0800701 == HW_PLATFORM_SUBTYPE_429W_PM660)
702 regulator_disable(REG_LDO13 | REG_LDO15);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700703 }
704
705 return NO_ERROR;
706}
707
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530708bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700709{
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530710 int prefix_string_len = strlen(DISPLAY_CMDLINE_PREFIX);
711 bool ret = true;
712 struct oem_panel_data oem = mdss_dsi_get_oem_data();
713 uint32_t platform_subtype = board_hardware_subtype();
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530714 uint32_t platform = board_platform_id();
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530715
716 /* default to hdmi for apq iot */
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530717 if ((APQ8017 == platform) && ((HW_PLATFORM_SUBTYPE_SAP == platform_subtype) ||
718 (HW_PLATFORM_SUBTYPE_SAP_NOPMI == platform_subtype))) {
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530719 if (!strcmp(oem.panel, "")) {
720 if (buf_size < (prefix_string_len +
721 strlen(HDMI_ADV_PANEL_STRING))) {
722 dprintf(CRITICAL, "HDMI command line argument \
723 is greater than buffer size\n");
724 return false;
725 }
726 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
727 buf_size -= prefix_string_len;
728 pbuf += prefix_string_len;
729 strlcpy(pbuf, HDMI_ADV_PANEL_STRING, buf_size);
730 } else if (!strcmp(oem.panel, TRULY_720P_VID_PANEL)) {
731 if (buf_size < (prefix_string_len +
732 strlen(TRULY_VID_PANEL_STRING))) {
733 dprintf(CRITICAL, "TRULY VIDEO command line \
734 argument is greater than \
735 buffer size\n");
736 return false;
737 }
738 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
739 buf_size -= prefix_string_len;
740 pbuf += prefix_string_len;
741 strlcpy(pbuf, TRULY_VID_PANEL_STRING, buf_size);
742 } else if (!strcmp(oem.panel, TRULY_720P_CMD_PANEL)) {
743 if (buf_size < (prefix_string_len +
744 strlen(TRULY_CMD_PANEL_STRING))) {
745 dprintf(CRITICAL, "TRULY CMD command line argument \
746 argument is greater than \
747 buffer size\n");
748 return false;
749 }
750 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
751 buf_size -= prefix_string_len;
752 pbuf += prefix_string_len;
753 strlcpy(pbuf, TRULY_CMD_PANEL_STRING, buf_size);
754 }
755 } else {
756 ret = gcdb_display_cmdline_arg(pbuf, buf_size);
757 }
758
759 return ret;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700760}
761
762void target_display_init(const char *panel_name)
763{
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530764 struct oem_panel_data oem;
Ray Zhangf95f5b92015-06-25 15:34:29 +0800765 int32_t ret = 0;
766 uint32_t panel_loop = 0;
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530767 uint32_t platform_subtype = board_hardware_subtype();
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530768 uint32_t platform = board_platform_id();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700769
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530770 set_panel_cmd_string(panel_name);
771 oem = mdss_dsi_get_oem_data();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700772
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530773 if (!strcmp(oem.panel, NO_PANEL_CONFIG)
774 || !strcmp(oem.panel, SIM_VIDEO_PANEL)
775 || !strcmp(oem.panel, SIM_CMD_PANEL)
776 || oem.skip) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700777 dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n",
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530778 oem.panel);
Vishnuvardhan Prodduturi4cd56382017-08-22 21:46:38 +0530779 oem.cont_splash = false;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700780 }
781
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530782 if ((APQ8017 == platform) && ((HW_PLATFORM_SUBTYPE_SAP == platform_subtype) ||
783 (HW_PLATFORM_SUBTYPE_SAP_NOPMI == platform_subtype))) {
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530784 dprintf(INFO, "%s: Platform subtype %d\n",
785 __func__, platform_subtype);
786 return;
787 }
788
Ray Zhangf95f5b92015-06-25 15:34:29 +0800789 do {
790 target_force_cont_splash_disable(false);
791 ret = gcdb_display_init(oem.panel, MDP_REV_50, (void *)MIPI_FB_ADDR);
792 if (!ret || ret == ERR_NOT_SUPPORTED) {
793 break;
794 } else {
795 target_force_cont_splash_disable(true);
796 msm_display_off();
797 }
798 } while (++panel_loop <= oem_panel_max_auto_detect_panels());
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700799
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530800 if (!oem.cont_splash) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700801 dprintf(INFO, "Forcing continuous splash disable\n");
802 target_force_cont_splash_disable(true);
803 }
804}
805
806void target_display_shutdown(void)
807{
808 gcdb_display_shutdown();
809}