blob: 5b92f9bc10c1ba71486edbddd71742fbb2b77469 [file] [log] [blame]
Umang Agrawald1939942018-02-13 16:23:58 +05301/* Copyright (c) 2015-2018, 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 */
276
277 pm8x41_wled_config_slave_id(slave_id);
Umang Agrawald1939942018-02-13 16:23:58 +0530278 if (target_get_pmic() == PMIC_IS_PMI632) {
279 qpnp_lcdb_enable(enable);
280 }
281 else {
282 qpnp_wled_enable_backlight(enable);
283 qpnp_ibb_enable(enable);
284 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700285 return NO_ERROR;
286}
287
Lei Chen2c11b462018-04-11 18:42:37 +0800288static int pwm_backlight_ctrl(uint8_t enable)
289{
290 if (enable) {
291 pm_pwm_enable(false);
292 pm_pwm_config(PWM_DUTY_US, PWM_PERIOD_US);
293 pm_pwm_enable(true);
294 } else {
295 pm_pwm_enable(false);
296 }
297
298 return NO_ERROR;
299}
300
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700301int target_backlight_ctrl(struct backlight *bl, uint8_t enable)
302{
303 uint32_t ret = NO_ERROR;
304
305 if (bl->bl_interface_type == BL_DCS)
306 return ret;
307
Lei Chen2c11b462018-04-11 18:42:37 +0800308 if ((target_get_pmic() == PMIC_IS_PMI632) &&
309 (bl->bl_interface_type == BL_PWM)) {
310 ret = pwm_backlight_ctrl(enable);
311 } else {
312 ret = msm8952_wled_backlight_ctrl(enable);
313 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700314 return ret;
315}
316
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530317static int32_t mdss_dsi_pll_config(uint32_t pll_base, uint32_t ctl_base,
318 struct mdss_dsi_pll_config *pll_data)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700319{
320 int32_t ret = 0;
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530321 if (!platform_is_msm8956())
322 mdss_dsi_uniphy_pll_sw_reset_8952(pll_base);
323 else
324 dsi_pll_sw_reset_8952(pll_base);
325 mdss_dsi_auto_pll_config(pll_base, ctl_base, pll_data);
326 if (platform_is_msm8956())
327 ret = dsi_pll_enable_seq_8956(pll_base);
328 else
329 ret = dsi_pll_enable_seq_8952(pll_base);
330
331 return ret;
332}
333
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700334int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
335{
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530336 int32_t ret = 0, flags;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700337 struct mdss_dsi_pll_config *pll_data;
338 dprintf(SPEW, "target_panel_clock\n");
339
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530340 if (pinfo->dest == DISPLAY_2) {
341 flags = MMSS_DSI_CLKS_FLAG_DSI1;
342 if (pinfo->mipi.dual_dsi)
343 flags |= MMSS_DSI_CLKS_FLAG_DSI0;
344 } else {
345 flags = MMSS_DSI_CLKS_FLAG_DSI0;
346 if (pinfo->mipi.dual_dsi)
347 flags |= MMSS_DSI_CLKS_FLAG_DSI1;
348 }
349
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700350 pll_data = pinfo->mipi.dsi_pll_config;
351 pll_data->vco_delay = VCO_DELAY_USEC;
352
Padmanabhan Komanduruf68f51b2015-12-21 18:32:12 +0530353 /* SSC parameters */
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530354 if (platform_is_msm8937() || platform_is_msm8917()) {
Padmanabhan Komanduruf68f51b2015-12-21 18:32:12 +0530355 pll_data->ssc_en = true;
356 pll_data->is_center_spread = false;
357 pll_data->ssc_freq = 30000;
358 pll_data->ssc_ppm = 5000;
Padmanabhan Komandurue54f7612018-05-03 09:29:50 +0530359 } else if (platform_is_sdm439() || platform_is_sdm429()) {
360 pll_data->ssc_en = true;
361 pll_data->is_center_spread = false;
362 pll_data->ssc_freq = 31500;
363 pll_data->ssc_ppm = 5000;
Padmanabhan Komanduruf68f51b2015-12-21 18:32:12 +0530364 }
365
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700366 if (enable) {
367 mdp_gdsc_ctrl(enable);
368 mdss_bus_clocks_enable();
369 mdp_clock_enable();
370 ret = restore_secure_cfg(SECURE_DEVICE_MDSS);
371 if (ret) {
372 dprintf(CRITICAL,
373 "%s: Failed to restore MDP security configs",
374 __func__);
375 mdp_clock_disable();
376 mdss_bus_clocks_disable();
377 mdp_gdsc_ctrl(0);
378 return ret;
379 }
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530380
Padmanabhan Komanduru62eec852018-05-14 12:27:30 +0530381 gcc_dsi_lp_clock_enable(flags);
382
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530383 if (platform_is_sdm439() || platform_is_sdm429()) {
384 mdss_dsi_auto_pll_12nm_config(pinfo);
385
386 /*
387 * enable clock/data lane in DSI controller
388 * before enabling DSI PLL for 12nm PHY
389 */
390 if (pinfo->lane_config)
391 pinfo->lane_config(pinfo);
392
393 ret = mdss_dsi_auto_pll_12nm_enable(pinfo);
394 if (!ret)
395 dprintf(CRITICAL, "unable to ON 12nm PLL\n");
396 } else {
397 ret = mdss_dsi_pll_config(pinfo->mipi.pll_base,
398 pinfo->mipi.ctl_base, pll_data);
399 if (!ret)
400 dprintf(CRITICAL, "unable to ON master pll\n");
401 }
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530402
Padmanabhan Komanduru2a6c3452015-09-09 18:46:06 +0530403 if (platform_is_msm8956() && pinfo->mipi.dual_dsi &&
404 !platform_is_msm8976_v_1_1()) {
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530405 ret = mdss_dsi_pll_config(pinfo->mipi.spll_base,
406 pinfo->mipi.sctl_base, pll_data);
407 if (!ret)
408 dprintf(CRITICAL, "Not able to enable second pll\n");
409 }
410
Padmanabhan Komanduru62eec852018-05-14 12:27:30 +0530411 gcc_dsi_hs_clocks_enable(flags, pinfo->mipi.use_dsi1_pll,
Padmanabhan Komanduru2a6c3452015-09-09 18:46:06 +0530412 pll_data->pclk_m, pll_data->pclk_n, pll_data->pclk_d);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700413 } else if(!target_cont_splash_screen()) {
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530414 gcc_dsi_clocks_disable(flags);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700415 mdp_clock_disable();
416 mdss_bus_clocks_disable();
417 mdp_gdsc_ctrl(enable);
418 }
419
420 return 0;
421}
422
423int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
424 struct msm_panel_info *pinfo)
425{
426 int ret = NO_ERROR;
Sujeev Dias6bc9fa32015-08-03 23:13:44 -0700427 uint32_t hw_id = board_hardware_id();
428 uint32_t hw_subtype = board_hardware_subtype();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700429
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530430 if (platform_is_msm8956()) {
431 reset_gpio.pin_id = 25;
432 bkl_gpio.pin_id = 66;
Padmanabhan Komandurub3231322015-11-12 16:54:21 +0530433 } else if (platform_is_msm8937()) {
434 reset_gpio.pin_id = 60;
435 bkl_gpio.pin_id = 98;
436 enable_gpio.pin_id = 99;
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530437 } else if (platform_is_msm8917()) {
Jayant Shekhar9c0533e2016-01-28 11:17:18 +0530438 reset_gpio.pin_id = 60;
439 bkl_gpio.pin_id = 98;
440 pinfo->mipi.use_enable_gpio = 0;
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530441 } else if (platform_is_sdm439() || platform_is_sdm429()) {
442 reset_gpio.pin_id = 60;
Sujeev Dias6bc9fa32015-08-03 23:13:44 -0700443 } else if ((hw_id == HW_PLATFORM_QRD) &&
444 (hw_subtype == HW_PLATFORM_SUBTYPE_POLARIS)) {
445 enable_gpio.pin_id = 19;
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530446 }
447
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700448 if (enable) {
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530449 if (pinfo->mipi.use_enable_gpio && !platform_is_msm8956()) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700450 gpio_tlmm_config(enable_gpio.pin_id, 0,
451 enable_gpio.pin_direction, enable_gpio.pin_pull,
452 enable_gpio.pin_strength,
453 enable_gpio.pin_state);
454
455 gpio_set_dir(enable_gpio.pin_id, 2);
456 }
457
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530458 if (platform_is_sdm439() || platform_is_sdm429()) {
459 /* enable PM GPIO-4 for backlight enable */
460 struct pm8x41_gpio gpio_param = {
461 .direction = PM_GPIO_DIR_OUT,
462 .function = PM_GPIO_FUNC_HIGH,
463 .vin_sel = 0, /* VIN_0 */
464 .pull = PM_GPIO_NO_PULL,
465 .output_buffer = PM_GPIO_OUT_CMOS,
466 .out_strength = PM_GPIO_OUT_DRIVE_HIGH,
467 };
468
469 dprintf(SPEW, "%s: gpio=%d enable=%d\n", __func__,
470 bkl_en_gpio.pin_id, enable);
471
472 pm8x41_gpio_config(bkl_en_gpio.pin_id, &gpio_param);
473 } else {
474 gpio_tlmm_config(bkl_gpio.pin_id, 0,
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700475 bkl_gpio.pin_direction, bkl_gpio.pin_pull,
476 bkl_gpio.pin_strength, bkl_gpio.pin_state);
477
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530478 gpio_set_dir(bkl_gpio.pin_id, 2);
479 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700480
481 gpio_tlmm_config(reset_gpio.pin_id, 0,
482 reset_gpio.pin_direction, reset_gpio.pin_pull,
483 reset_gpio.pin_strength, reset_gpio.pin_state);
484
485 gpio_set_dir(reset_gpio.pin_id, 2);
486
487 /* reset */
488 for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) {
489 if (resetseq->pin_state[i] == GPIO_STATE_LOW)
490 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_LOW);
491 else
492 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_HIGH);
493 mdelay(resetseq->sleep[i]);
494 }
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530495
496 if (platform_is_msm8956()) {
497 gpio_tlmm_config(lcd_mode_gpio.pin_id, 0,
498 lcd_mode_gpio.pin_direction, lcd_mode_gpio.pin_pull,
499 lcd_mode_gpio.pin_strength, lcd_mode_gpio.pin_state);
500
501 if (pinfo->lcdc.split_display || pinfo->lcdc.dst_split)
502 gpio_set_dir(lcd_mode_gpio.pin_id, GPIO_STATE_LOW);
503 else
504 gpio_set_dir(lcd_mode_gpio.pin_id, GPIO_STATE_HIGH);
505 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700506 } else if(!target_cont_splash_screen()) {
507 gpio_set_dir(reset_gpio.pin_id, 0);
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530508 if (pinfo->mipi.use_enable_gpio && !platform_is_msm8956())
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700509 gpio_set_dir(enable_gpio.pin_id, 0);
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530510 if (platform_is_msm8956())
511 gpio_set_dir(lcd_mode_gpio.pin_id, 0);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700512 }
513
514 return ret;
515}
516
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530517static int wled_init(struct msm_panel_info *pinfo)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700518{
519 struct qpnp_wled_config_data config = {0};
520 struct labibb_desc *labibb;
521 int display_type = 0;
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530522 bool swire_control = 0;
523 bool wled_avdd_control = 0;
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530524 int rc = NO_ERROR;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700525
526 labibb = pinfo->labibb;
527
528 if (labibb)
529 display_type = labibb->amoled_panel;
530
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530531 if (display_type) {
532 swire_control = labibb->swire_control;
533 wled_avdd_control = true;
534 } else {
535 swire_control = false;
536 wled_avdd_control = false;
537 }
538
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700539 config.display_type = display_type;
540 config.lab_init_volt = 4600000; /* fixed, see pmi register */
541 config.ibb_init_volt = 1400000; /* fixed, see pmi register */
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530542 config.lab_ibb_swire_control = swire_control;
543 config.wled_avdd_control = wled_avdd_control;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700544
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530545 if(!swire_control) {
546 if (labibb && labibb->force_config) {
547 config.lab_min_volt = labibb->lab_min_volt;
548 config.lab_max_volt = labibb->lab_max_volt;
549 config.ibb_min_volt = labibb->ibb_min_volt;
550 config.ibb_max_volt = labibb->ibb_max_volt;
551 config.pwr_up_delay = labibb->pwr_up_delay;
552 config.pwr_down_delay = labibb->pwr_down_delay;
553 config.ibb_discharge_en = labibb->ibb_discharge_en;
554 } else {
555 /* default */
556 config.pwr_up_delay = 3;
557 config.pwr_down_delay = 3;
558 config.ibb_discharge_en = 1;
559 if (display_type) { /* amoled */
560 config.lab_min_volt = 4600000;
561 config.lab_max_volt = 4600000;
562 config.ibb_min_volt = 4000000;
563 config.ibb_max_volt = 4000000;
564 } else { /* lcd */
565 config.lab_min_volt = 5500000;
566 config.lab_max_volt = 5500000;
567 config.ibb_min_volt = 5500000;
568 config.ibb_max_volt = 5500000;
569 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700570 }
571 }
572
Narender Ankambf2e2dd2018-05-30 17:48:11 +0530573 if (target_get_pmic() == PMIC_IS_PMI632) {
574 config.pwr_up_delay = 1;
575 config.pwr_down_delay = 0;
576 }
577
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700578 dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d %d %d\n", __func__,
579 config.display_type,
580 config.lab_min_volt, config.lab_max_volt,
581 config.ibb_min_volt, config.ibb_max_volt,
582 config.lab_init_volt, config.ibb_init_volt,
583 config.pwr_up_delay, config.pwr_down_delay,
584 config.ibb_discharge_en);
585
586 /* QPNP WLED init for display backlight */
587 pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID);
588
Umang Agrawald1939942018-02-13 16:23:58 +0530589 if (target_get_pmic() == PMIC_IS_PMI632)
590 rc = qpnp_lcdb_init(&config);
591 else
592 rc = qpnp_wled_init(&config);
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530593
594 return rc;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700595}
596
Dhaval Patel7709c412015-05-12 10:09:41 -0700597int target_dsi_phy_config(struct mdss_dsi_phy_ctrl *phy_db)
598{
599 memcpy(phy_db->regulator, panel_regulator_settings, REGULATOR_SIZE);
600 memcpy(phy_db->ctrl, panel_physical_ctrl, PHYSICAL_SIZE);
601 memcpy(phy_db->strength, panel_strength_ctrl, STRENGTH_SIZE);
602 memcpy(phy_db->bistCtrl, panel_bist_ctrl, BIST_SIZE);
603 memcpy(phy_db->laneCfg, panel_lane_config, LANE_SIZE);
604 return NO_ERROR;
605}
606
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530607int target_display_get_base_offset(uint32_t base)
608{
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530609 if (platform_is_sdm439() || platform_is_sdm429()) {
610 if (base == MIPI_DSI0_BASE)
611 return DSI0_BASE_ADJUST;
612 else if (base == DSI0_PHY_BASE)
613 return DSI0_PHY_BASE_ADJUST;
614 else if (base == DSI0_PLL_BASE)
615 return DSI0_12NM_PHY_PLL_BASE_ADJUST;
616 else if (base == DSI1_PLL_BASE)
617 return DSI1_12NM_PHY_PLL_BASE_ADJUST;
618 } else if (platform_is_msm8956() || platform_is_msm8937() ||
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530619 platform_is_msm8917()) {
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530620 if (base == MIPI_DSI0_BASE)
621 return DSI0_BASE_ADJUST;
622 else if (base == DSI0_PHY_BASE)
623 return DSI0_PHY_BASE_ADJUST;
624 else if (base == DSI0_PLL_BASE)
625 return DSI0_PHY_PLL_BASE_ADJUST;
626 else if (base == DSI0_REGULATOR_BASE)
627 return DSI0_PHY_REGULATOR_BASE_ADJUST;
628 }
629
630 return 0;
631}
632
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700633int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
634{
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530635 int rc = 0;
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530636 uint32_t ldo_num = REG_LDO6 | REG_LDO17;
637
638 if (platform_is_msm8956())
639 ldo_num |= REG_LDO1;
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530640 else if (platform_is_sdm439() || platform_is_sdm429())
641 ldo_num |= REG_LDO5; /* LDO23 is enable by default */
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530642 else
643 ldo_num |= REG_LDO2;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700644
645 if (enable) {
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530646 regulator_enable(ldo_num);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700647 mdelay(10);
Frank Yi2b7e2b92018-04-25 16:24:45 +0800648 if(!pinfo->disable_wled_labibb) {
649 rc = wled_init(pinfo);
650 if (rc) {
651 dprintf(CRITICAL, "%s: wled init failed\n", __func__);
652 return rc;
653 }
654 if (target_get_pmic() == PMIC_IS_PMI632)
655 rc = qpnp_lcdb_enable(true);
656 else
657 rc = qpnp_ibb_enable(true); /*5V boost*/
658 if (rc) {
659 dprintf(CRITICAL, "%s: qpnp_ibb/lcdb failed\n", __func__);
660 return rc;
661 }
662 mdelay(50);
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530663 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700664 } else {
Padmanabhan Komandurufa2899b2015-06-30 16:25:33 +0530665 /*
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530666 * LDO1, LDO2, LDO5 and LDO6 are shared with other subsystems.
Padmanabhan Komandurufa2899b2015-06-30 16:25:33 +0530667 * Do not disable them.
668 */
669 regulator_disable(REG_LDO17);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700670 }
671
672 return NO_ERROR;
673}
674
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530675bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700676{
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530677 int prefix_string_len = strlen(DISPLAY_CMDLINE_PREFIX);
678 bool ret = true;
679 struct oem_panel_data oem = mdss_dsi_get_oem_data();
680 uint32_t platform_subtype = board_hardware_subtype();
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530681 uint32_t platform = board_platform_id();
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530682
683 /* default to hdmi for apq iot */
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530684 if ((APQ8017 == platform) && ((HW_PLATFORM_SUBTYPE_SAP == platform_subtype) ||
685 (HW_PLATFORM_SUBTYPE_SAP_NOPMI == platform_subtype))) {
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530686 if (!strcmp(oem.panel, "")) {
687 if (buf_size < (prefix_string_len +
688 strlen(HDMI_ADV_PANEL_STRING))) {
689 dprintf(CRITICAL, "HDMI command line argument \
690 is greater than buffer size\n");
691 return false;
692 }
693 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
694 buf_size -= prefix_string_len;
695 pbuf += prefix_string_len;
696 strlcpy(pbuf, HDMI_ADV_PANEL_STRING, buf_size);
697 } else if (!strcmp(oem.panel, TRULY_720P_VID_PANEL)) {
698 if (buf_size < (prefix_string_len +
699 strlen(TRULY_VID_PANEL_STRING))) {
700 dprintf(CRITICAL, "TRULY VIDEO command line \
701 argument is greater than \
702 buffer size\n");
703 return false;
704 }
705 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
706 buf_size -= prefix_string_len;
707 pbuf += prefix_string_len;
708 strlcpy(pbuf, TRULY_VID_PANEL_STRING, buf_size);
709 } else if (!strcmp(oem.panel, TRULY_720P_CMD_PANEL)) {
710 if (buf_size < (prefix_string_len +
711 strlen(TRULY_CMD_PANEL_STRING))) {
712 dprintf(CRITICAL, "TRULY CMD command line argument \
713 argument is greater than \
714 buffer size\n");
715 return false;
716 }
717 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
718 buf_size -= prefix_string_len;
719 pbuf += prefix_string_len;
720 strlcpy(pbuf, TRULY_CMD_PANEL_STRING, buf_size);
721 }
722 } else {
723 ret = gcdb_display_cmdline_arg(pbuf, buf_size);
724 }
725
726 return ret;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700727}
728
729void target_display_init(const char *panel_name)
730{
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530731 struct oem_panel_data oem;
Ray Zhangf95f5b92015-06-25 15:34:29 +0800732 int32_t ret = 0;
733 uint32_t panel_loop = 0;
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530734 uint32_t platform_subtype = board_hardware_subtype();
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530735 uint32_t platform = board_platform_id();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700736
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530737 set_panel_cmd_string(panel_name);
738 oem = mdss_dsi_get_oem_data();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700739
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530740 if (!strcmp(oem.panel, NO_PANEL_CONFIG)
741 || !strcmp(oem.panel, SIM_VIDEO_PANEL)
742 || !strcmp(oem.panel, SIM_CMD_PANEL)
743 || oem.skip) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700744 dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n",
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530745 oem.panel);
Vishnuvardhan Prodduturi4cd56382017-08-22 21:46:38 +0530746 oem.cont_splash = false;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700747 }
748
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530749 if ((APQ8017 == platform) && ((HW_PLATFORM_SUBTYPE_SAP == platform_subtype) ||
750 (HW_PLATFORM_SUBTYPE_SAP_NOPMI == platform_subtype))) {
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530751 dprintf(INFO, "%s: Platform subtype %d\n",
752 __func__, platform_subtype);
753 return;
754 }
755
Ray Zhangf95f5b92015-06-25 15:34:29 +0800756 do {
757 target_force_cont_splash_disable(false);
758 ret = gcdb_display_init(oem.panel, MDP_REV_50, (void *)MIPI_FB_ADDR);
759 if (!ret || ret == ERR_NOT_SUPPORTED) {
760 break;
761 } else {
762 target_force_cont_splash_disable(true);
763 msm_display_off();
764 }
765 } while (++panel_loop <= oem_panel_max_auto_detect_panels());
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700766
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530767 if (!oem.cont_splash) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700768 dprintf(INFO, "Forcing continuous splash disable\n");
769 target_force_cont_splash_disable(true);
770 }
771}
772
773void target_display_shutdown(void)
774{
775 gcdb_display_shutdown();
776}