blob: af3218684c14267e1508415a7376802d41b6b61f [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
Xipeng Gudd4f96d2019-07-17 16:44:09 +080066#define VARIANT_MAJOR_MASK (0x00ff0000)
67
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -070068/*---------------------------------------------------------------------------*/
69/* GPIO configuration */
70/*---------------------------------------------------------------------------*/
71static struct gpio_pin reset_gpio = {
72 "msmgpio", 0, 3, 1, 0, 1
73};
74
75static struct gpio_pin enable_gpio = {
76 "msmgpio", 90, 3, 1, 0, 1
77};
78
79static struct gpio_pin bkl_gpio = {
80 "msmgpio", 91, 3, 1, 0, 1
81};
82
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +053083static struct gpio_pin lcd_mode_gpio = {
84 "msmgpio", 107, 3, 1, 0, 1
85};
86
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +053087static struct gpio_pin bkl_en_gpio = {
88"pm8953", 4, 3, 1, 0, 1
89};
90
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -070091#define VCO_DELAY_USEC 1000
92#define GPIO_STATE_LOW 0
93#define GPIO_STATE_HIGH 2
94#define RESET_GPIO_SEQ_LEN 3
95#define PMIC_WLED_SLAVE_ID 3
96
Padmanabhan Komandurub3381932015-06-15 22:14:02 +053097#define DSI0_BASE_ADJUST -0x4000
98#define DSI0_PHY_BASE_ADJUST -0x4100
99#define DSI0_PHY_PLL_BASE_ADJUST -0x3900
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530100#define DSI0_12NM_PHY_PLL_BASE_ADJUST -0x3F00
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530101#define DSI0_PHY_REGULATOR_BASE_ADJUST -0x3C00
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530102#define DSI1_12NM_PHY_PLL_BASE_ADJUST -0x600
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530103
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700104static void mdss_dsi_uniphy_pll_sw_reset_8952(uint32_t pll_base)
105{
106 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
107 mdelay(1);
108 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
109 mdelay(1);
110}
111
112static void dsi_pll_toggle_lock_detect_8952(uint32_t pll_base)
113{
114 writel(0x04, pll_base + 0x0064); /* LKDetect CFG2 */
115 udelay(1);
116 writel(0x05, pll_base + 0x0064); /* LKDetect CFG2 */
117 udelay(512);
118}
119
120static void dsi_pll_sw_reset_8952(uint32_t pll_base)
121{
122 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
123 udelay(1);
124 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
Padmanabhan Komanduru6cf63522015-06-08 14:48:00 +0530125 udelay(1);
126}
127
128static uint32_t dsi_pll_lock_status_8956(uint32_t pll_base)
129{
130 uint32_t counter, status;
131
132 status = readl(pll_base + 0x00c0) & 0x01;
133 for (counter = 0; counter < 5 && !status; counter++) {
134 udelay(100);
135 status = readl(pll_base + 0x00c0) & 0x01;
136 }
137
138 return status;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700139}
140
141static uint32_t gf_1_dsi_pll_enable_sequence_8952(uint32_t pll_base)
142{
143 uint32_t rc;
144
145 dsi_pll_sw_reset_8952(pll_base);
146
147 /*
148 * Add hardware recommended delays between register writes for
149 * the updates to take effect. These delays are necessary for the
150 * PLL to successfully lock
151 */
152 writel(0x14, pll_base + 0x0070); /* CAL CFG1*/
153 writel(0x01, pll_base + 0x0020); /* GLB CFG */
154 writel(0x05, pll_base + 0x0020); /* GLB CFG */
155 udelay(3);
156 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
157 udelay(500);
158
159 dsi_pll_toggle_lock_detect_8952(pll_base);
160 rc = readl(pll_base + 0x00c0) & 0x01;
161
162 return rc;
163}
164
165static uint32_t gf_2_dsi_pll_enable_sequence_8952(uint32_t pll_base)
166{
167 uint32_t rc;
168
169 dsi_pll_sw_reset_8952(pll_base);
170
171 /*
172 * Add hardware recommended delays between register writes for
173 * the updates to take effect. These delays are necessary for the
174 * PLL to successfully lock
175 */
176 writel(0x04, pll_base + 0x0070); /* CAL CFG1*/
177 writel(0x01, pll_base + 0x0020); /* GLB CFG */
178 writel(0x05, pll_base + 0x0020); /* GLB CFG */
179 udelay(3);
180 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
181 udelay(500);
182
183 dsi_pll_toggle_lock_detect_8952(pll_base);
184 rc = readl(pll_base + 0x00c0) & 0x01;
185
186 return rc;
187}
188
189static uint32_t tsmc_dsi_pll_enable_sequence_8952(uint32_t pll_base)
190{
191 uint32_t rc;
192
193 dsi_pll_sw_reset_8952(pll_base);
194 /*
195 * Add hardware recommended delays between register writes for
196 * the updates to take effect. These delays are necessary for the
197 * PLL to successfully lock
198 */
199
200 writel(0x34, pll_base + 0x0070); /* CAL CFG1*/
201 writel(0x01, pll_base + 0x0020); /* GLB CFG */
202 writel(0x05, pll_base + 0x0020); /* GLB CFG */
203 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
204 udelay(500);
205
206 dsi_pll_toggle_lock_detect_8952(pll_base);
207 rc = readl(pll_base + 0x00c0) & 0x01;
208
209 return rc;
210}
211
212
213static uint32_t dsi_pll_enable_seq_8952(uint32_t pll_base)
214{
215 uint32_t pll_locked = 0;
216 uint32_t counter = 0;
217
218 do {
219 pll_locked = tsmc_dsi_pll_enable_sequence_8952(pll_base);
220
221 dprintf(SPEW, "TSMC pll locked status is %d\n", pll_locked);
222 ++counter;
223 } while (!pll_locked && (counter < 3));
224
225 if(!pll_locked) {
226 counter = 0;
227 do {
228 pll_locked = gf_1_dsi_pll_enable_sequence_8952(pll_base);
229
230 dprintf(SPEW, "GF P1 pll locked status is %d\n", pll_locked);
231 ++counter;
232 } while (!pll_locked && (counter < 3));
233 }
234
235 if(!pll_locked) {
236 counter = 0;
237 do {
238 pll_locked = gf_2_dsi_pll_enable_sequence_8952(pll_base);
239
240 dprintf(SPEW, "GF P2 pll locked status is %d\n", pll_locked);
241 ++counter;
242 } while (!pll_locked && (counter < 3));
243 }
244
245 return pll_locked;
246}
247
Padmanabhan Komanduru6cf63522015-06-08 14:48:00 +0530248static uint32_t dsi_pll_enable_seq_8956(uint32_t pll_base)
249{
250 /*
251 * PLL power up sequence
252 * Add necessary delays recommended by h/w team
253 */
254
255 /* Lock Detect setting */
256 writel(0x0d, pll_base + 0x0064); /* LKDetect CFG2 */
257 writel(0x34, pll_base + 0x0070); /* PLL CAL_CFG1 */
258 writel(0x10, pll_base + 0x005c); /* LKDetect CFG0 */
259 writel(0x1a, pll_base + 0x0060); /* LKDetect CFG1 */
260
261 writel(0x01, pll_base + 0x0020); /* GLB CFG */
262 udelay(300);
263 writel(0x05, pll_base + 0x0020); /* GLB CFG */
264 udelay(300);
265 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
266 udelay(300);
267 writel(0x07, pll_base + 0x0020); /* GLB CFG */
268 udelay(300);
269 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
270 udelay(1000);
271
272 return dsi_pll_lock_status_8956(pll_base);
273}
274
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700275static int msm8952_wled_backlight_ctrl(uint8_t enable)
276{
277 uint8_t slave_id = PMIC_WLED_SLAVE_ID; /* pmi */
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530278 uint32_t pmic_type = target_get_pmic();
279
Umang Agrawaldff10da2019-05-08 16:14:13 +0530280 if(pmic_type == PMIC_IS_PM8916 || pmic_type == PMIC_IS_PM660)
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530281 return NO_ERROR;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700282
283 pm8x41_wled_config_slave_id(slave_id);
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530284 if (pmic_type == PMIC_IS_PMI632) {
Umang Agrawald1939942018-02-13 16:23:58 +0530285 qpnp_lcdb_enable(enable);
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530286 } else {
Umang Agrawald1939942018-02-13 16:23:58 +0530287 qpnp_wled_enable_backlight(enable);
288 qpnp_ibb_enable(enable);
289 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700290 return NO_ERROR;
291}
292
Lei Chen2c11b462018-04-11 18:42:37 +0800293static int pwm_backlight_ctrl(uint8_t enable)
294{
295 if (enable) {
296 pm_pwm_enable(false);
297 pm_pwm_config(PWM_DUTY_US, PWM_PERIOD_US);
298 pm_pwm_enable(true);
299 } else {
300 pm_pwm_enable(false);
301 }
302
303 return NO_ERROR;
304}
305
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700306int target_backlight_ctrl(struct backlight *bl, uint8_t enable)
307{
308 uint32_t ret = NO_ERROR;
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530309 uint32_t pmic_type = target_get_pmic();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700310
311 if (bl->bl_interface_type == BL_DCS)
312 return ret;
313
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530314 if ((pmic_type == PMIC_IS_PMI632) &&
Lei Chen2c11b462018-04-11 18:42:37 +0800315 (bl->bl_interface_type == BL_PWM)) {
316 ret = pwm_backlight_ctrl(enable);
Umang Agrawaldff10da2019-05-08 16:14:13 +0530317 } else if (pmic_type == PMIC_IS_PM8916 || pmic_type == PMIC_IS_PM660) {
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530318 ret = pwm_backlight_ctrl(enable);
Lei Chen2c11b462018-04-11 18:42:37 +0800319 } else {
320 ret = msm8952_wled_backlight_ctrl(enable);
321 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700322 return ret;
323}
324
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530325static int32_t mdss_dsi_pll_config(uint32_t pll_base, uint32_t ctl_base,
326 struct mdss_dsi_pll_config *pll_data)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700327{
328 int32_t ret = 0;
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530329 if (!platform_is_msm8956())
330 mdss_dsi_uniphy_pll_sw_reset_8952(pll_base);
331 else
332 dsi_pll_sw_reset_8952(pll_base);
333 mdss_dsi_auto_pll_config(pll_base, ctl_base, pll_data);
334 if (platform_is_msm8956())
335 ret = dsi_pll_enable_seq_8956(pll_base);
336 else
337 ret = dsi_pll_enable_seq_8952(pll_base);
338
339 return ret;
340}
341
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700342int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
343{
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530344 int32_t ret = 0, flags;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700345 struct mdss_dsi_pll_config *pll_data;
346 dprintf(SPEW, "target_panel_clock\n");
347
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530348 if (pinfo->dest == DISPLAY_2) {
349 flags = MMSS_DSI_CLKS_FLAG_DSI1;
350 if (pinfo->mipi.dual_dsi)
351 flags |= MMSS_DSI_CLKS_FLAG_DSI0;
352 } else {
353 flags = MMSS_DSI_CLKS_FLAG_DSI0;
354 if (pinfo->mipi.dual_dsi)
355 flags |= MMSS_DSI_CLKS_FLAG_DSI1;
356 }
357
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700358 pll_data = pinfo->mipi.dsi_pll_config;
359 pll_data->vco_delay = VCO_DELAY_USEC;
360
Padmanabhan Komanduruf68f51b2015-12-21 18:32:12 +0530361 /* SSC parameters */
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530362 if (platform_is_msm8937() || platform_is_msm8917() || platform_is_qm215()) {
Padmanabhan Komanduruf68f51b2015-12-21 18:32:12 +0530363 pll_data->ssc_en = true;
364 pll_data->is_center_spread = false;
365 pll_data->ssc_freq = 30000;
366 pll_data->ssc_ppm = 5000;
Meng Jiang289a9812019-10-23 15:25:26 +0800367 } else if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w()) {
Padmanabhan Komandurue54f7612018-05-03 09:29:50 +0530368 pll_data->ssc_en = true;
369 pll_data->is_center_spread = false;
370 pll_data->ssc_freq = 31500;
371 pll_data->ssc_ppm = 5000;
Padmanabhan Komanduruf68f51b2015-12-21 18:32:12 +0530372 }
373
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700374 if (enable) {
375 mdp_gdsc_ctrl(enable);
376 mdss_bus_clocks_enable();
377 mdp_clock_enable();
378 ret = restore_secure_cfg(SECURE_DEVICE_MDSS);
379 if (ret) {
380 dprintf(CRITICAL,
381 "%s: Failed to restore MDP security configs",
382 __func__);
383 mdp_clock_disable();
384 mdss_bus_clocks_disable();
385 mdp_gdsc_ctrl(0);
386 return ret;
387 }
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530388
Padmanabhan Komanduru62eec852018-05-14 12:27:30 +0530389 gcc_dsi_lp_clock_enable(flags);
390
Meng Jiang289a9812019-10-23 15:25:26 +0800391 if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530392 mdss_dsi_auto_pll_12nm_config(pinfo);
393
394 /*
395 * enable clock/data lane in DSI controller
396 * before enabling DSI PLL for 12nm PHY
397 */
398 if (pinfo->lane_config)
399 pinfo->lane_config(pinfo);
400
401 ret = mdss_dsi_auto_pll_12nm_enable(pinfo);
402 if (!ret)
403 dprintf(CRITICAL, "unable to ON 12nm PLL\n");
404 } else {
405 ret = mdss_dsi_pll_config(pinfo->mipi.pll_base,
406 pinfo->mipi.ctl_base, pll_data);
407 if (!ret)
408 dprintf(CRITICAL, "unable to ON master pll\n");
409 }
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530410
Padmanabhan Komanduru2a6c3452015-09-09 18:46:06 +0530411 if (platform_is_msm8956() && pinfo->mipi.dual_dsi &&
412 !platform_is_msm8976_v_1_1()) {
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530413 ret = mdss_dsi_pll_config(pinfo->mipi.spll_base,
414 pinfo->mipi.sctl_base, pll_data);
415 if (!ret)
416 dprintf(CRITICAL, "Not able to enable second pll\n");
417 }
418
Padmanabhan Komanduru62eec852018-05-14 12:27:30 +0530419 gcc_dsi_hs_clocks_enable(flags, pinfo->mipi.use_dsi1_pll,
Padmanabhan Komanduru2a6c3452015-09-09 18:46:06 +0530420 pll_data->pclk_m, pll_data->pclk_n, pll_data->pclk_d);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700421 } else if(!target_cont_splash_screen()) {
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530422 gcc_dsi_clocks_disable(flags);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700423 mdp_clock_disable();
424 mdss_bus_clocks_disable();
425 mdp_gdsc_ctrl(enable);
426 }
427
428 return 0;
429}
430
431int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
432 struct msm_panel_info *pinfo)
433{
434 int ret = NO_ERROR;
Sujeev Dias6bc9fa32015-08-03 23:13:44 -0700435 uint32_t hw_id = board_hardware_id();
436 uint32_t hw_subtype = board_hardware_subtype();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700437
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530438 if (platform_is_msm8956()) {
439 reset_gpio.pin_id = 25;
440 bkl_gpio.pin_id = 66;
Padmanabhan Komandurub3231322015-11-12 16:54:21 +0530441 } else if (platform_is_msm8937()) {
442 reset_gpio.pin_id = 60;
443 bkl_gpio.pin_id = 98;
444 enable_gpio.pin_id = 99;
Parth Dixit05f3c9f2016-03-18 17:14:57 +0530445 } else if (platform_is_msm8917()) {
Jayant Shekhar9c0533e2016-01-28 11:17:18 +0530446 reset_gpio.pin_id = 60;
447 bkl_gpio.pin_id = 98;
448 pinfo->mipi.use_enable_gpio = 0;
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530449 } else if (platform_is_qm215()) {
450 dprintf(CRITICAL,"vproddut: coming here \n");
451 reset_gpio.pin_id = 60;
452 bkl_gpio.pin_id = 93;
453 enable_gpio.pin_id = 94;
454 pinfo->mipi.use_enable_gpio = 1;
Meng Jiang289a9812019-10-23 15:25:26 +0800455 } else if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530456 reset_gpio.pin_id = 60;
Meng Jiang289a9812019-10-23 15:25:26 +0800457 if ((platform_is_sdm429() && (board_hardware_subtype() == HW_PLATFORM_SUBTYPE_429W_PM660)) || platform_is_sdm429w() || platform_is_sda429w()) {
Bo Zhanga1a44c42019-08-13 09:12:46 +0800458 if (board_hardware_subtype() == HW_PLATFORM_SUBTYPE_429W_PM660_WDP) {
459 reset_gpio.pin_id = 60;
460 pinfo->mipi.use_enable_gpio = 0;
461 }
462 else {
463 reset_gpio.pin_id = 60;
464 pinfo->mipi.use_enable_gpio = 1;
465 enable_gpio.pin_id = 69;
466 }
Xipeng Gu5affb812019-06-18 14:59:17 +0800467 }
Sujeev Dias6bc9fa32015-08-03 23:13:44 -0700468 } else if ((hw_id == HW_PLATFORM_QRD) &&
469 (hw_subtype == HW_PLATFORM_SUBTYPE_POLARIS)) {
470 enable_gpio.pin_id = 19;
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530471 }
472
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700473 if (enable) {
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530474 if (pinfo->mipi.use_enable_gpio && !platform_is_msm8956()) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700475 gpio_tlmm_config(enable_gpio.pin_id, 0,
476 enable_gpio.pin_direction, enable_gpio.pin_pull,
477 enable_gpio.pin_strength,
478 enable_gpio.pin_state);
479
480 gpio_set_dir(enable_gpio.pin_id, 2);
481 }
482
Meng Jiang289a9812019-10-23 15:25:26 +0800483 if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530484 /* enable PM GPIO-4 for backlight enable */
485 struct pm8x41_gpio gpio_param = {
486 .direction = PM_GPIO_DIR_OUT,
487 .function = PM_GPIO_FUNC_HIGH,
488 .vin_sel = 0, /* VIN_0 */
489 .pull = PM_GPIO_NO_PULL,
490 .output_buffer = PM_GPIO_OUT_CMOS,
491 .out_strength = PM_GPIO_OUT_DRIVE_HIGH,
492 };
493
Xipeng Gudd4f96d2019-07-17 16:44:09 +0800494 if (((board_target_id() & VARIANT_MAJOR_MASK)) &&
Meng Jiang289a9812019-10-23 15:25:26 +0800495 (platform_is_sda429w() || platform_is_sdm429w())) {
Xipeng Gudd4f96d2019-07-17 16:44:09 +0800496 /* enable PM660 GPIO-12 for backlight enable */
497 bkl_en_gpio.pin_id = 12;
498 gpio_param.inv_int_pol = PM_GPIO_INVERT;
499 }
500
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530501 dprintf(SPEW, "%s: gpio=%d enable=%d\n", __func__,
502 bkl_en_gpio.pin_id, enable);
503
504 pm8x41_gpio_config(bkl_en_gpio.pin_id, &gpio_param);
505 } else {
506 gpio_tlmm_config(bkl_gpio.pin_id, 0,
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700507 bkl_gpio.pin_direction, bkl_gpio.pin_pull,
508 bkl_gpio.pin_strength, bkl_gpio.pin_state);
509
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530510 gpio_set_dir(bkl_gpio.pin_id, 2);
511 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700512
513 gpio_tlmm_config(reset_gpio.pin_id, 0,
514 reset_gpio.pin_direction, reset_gpio.pin_pull,
515 reset_gpio.pin_strength, reset_gpio.pin_state);
516
517 gpio_set_dir(reset_gpio.pin_id, 2);
518
519 /* reset */
520 for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) {
521 if (resetseq->pin_state[i] == GPIO_STATE_LOW)
522 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_LOW);
523 else
524 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_HIGH);
525 mdelay(resetseq->sleep[i]);
526 }
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530527
528 if (platform_is_msm8956()) {
529 gpio_tlmm_config(lcd_mode_gpio.pin_id, 0,
530 lcd_mode_gpio.pin_direction, lcd_mode_gpio.pin_pull,
531 lcd_mode_gpio.pin_strength, lcd_mode_gpio.pin_state);
532
533 if (pinfo->lcdc.split_display || pinfo->lcdc.dst_split)
534 gpio_set_dir(lcd_mode_gpio.pin_id, GPIO_STATE_LOW);
535 else
536 gpio_set_dir(lcd_mode_gpio.pin_id, GPIO_STATE_HIGH);
537 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700538 } else if(!target_cont_splash_screen()) {
539 gpio_set_dir(reset_gpio.pin_id, 0);
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530540 if (pinfo->mipi.use_enable_gpio && !platform_is_msm8956())
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700541 gpio_set_dir(enable_gpio.pin_id, 0);
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530542 if (platform_is_msm8956())
543 gpio_set_dir(lcd_mode_gpio.pin_id, 0);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700544 }
545
546 return ret;
547}
548
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530549static int wled_init(struct msm_panel_info *pinfo)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700550{
551 struct qpnp_wled_config_data config = {0};
552 struct labibb_desc *labibb;
553 int display_type = 0;
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530554 bool swire_control = 0;
555 bool wled_avdd_control = 0;
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530556 int rc = NO_ERROR;
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530557 uint32_t pmic_type = target_get_pmic();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700558
Umang Agrawaldff10da2019-05-08 16:14:13 +0530559 if(pmic_type == PMIC_IS_PM8916 || pmic_type == PMIC_IS_PM660)
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530560 return NO_ERROR;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700561 labibb = pinfo->labibb;
562
563 if (labibb)
564 display_type = labibb->amoled_panel;
565
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530566 if (display_type) {
567 swire_control = labibb->swire_control;
568 wled_avdd_control = true;
569 } else {
570 swire_control = false;
571 wled_avdd_control = false;
572 }
573
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700574 config.display_type = display_type;
575 config.lab_init_volt = 4600000; /* fixed, see pmi register */
576 config.ibb_init_volt = 1400000; /* fixed, see pmi register */
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530577 config.lab_ibb_swire_control = swire_control;
578 config.wled_avdd_control = wled_avdd_control;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700579
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530580 if(!swire_control) {
581 if (labibb && labibb->force_config) {
582 config.lab_min_volt = labibb->lab_min_volt;
583 config.lab_max_volt = labibb->lab_max_volt;
584 config.ibb_min_volt = labibb->ibb_min_volt;
585 config.ibb_max_volt = labibb->ibb_max_volt;
586 config.pwr_up_delay = labibb->pwr_up_delay;
587 config.pwr_down_delay = labibb->pwr_down_delay;
588 config.ibb_discharge_en = labibb->ibb_discharge_en;
589 } else {
590 /* default */
591 config.pwr_up_delay = 3;
592 config.pwr_down_delay = 3;
593 config.ibb_discharge_en = 1;
594 if (display_type) { /* amoled */
595 config.lab_min_volt = 4600000;
596 config.lab_max_volt = 4600000;
597 config.ibb_min_volt = 4000000;
598 config.ibb_max_volt = 4000000;
599 } else { /* lcd */
600 config.lab_min_volt = 5500000;
601 config.lab_max_volt = 5500000;
602 config.ibb_min_volt = 5500000;
603 config.ibb_max_volt = 5500000;
604 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700605 }
606 }
607
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530608 if (pmic_type == PMIC_IS_PMI632) {
Narender Ankambf2e2dd2018-05-30 17:48:11 +0530609 config.pwr_up_delay = 1;
610 config.pwr_down_delay = 0;
611 }
612
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700613 dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d %d %d\n", __func__,
614 config.display_type,
615 config.lab_min_volt, config.lab_max_volt,
616 config.ibb_min_volt, config.ibb_max_volt,
617 config.lab_init_volt, config.ibb_init_volt,
618 config.pwr_up_delay, config.pwr_down_delay,
619 config.ibb_discharge_en);
620
621 /* QPNP WLED init for display backlight */
622 pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID);
623
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530624 if (pmic_type == PMIC_IS_PMI632)
Umang Agrawald1939942018-02-13 16:23:58 +0530625 rc = qpnp_lcdb_init(&config);
626 else
627 rc = qpnp_wled_init(&config);
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530628
629 return rc;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700630}
631
Dhaval Patel7709c412015-05-12 10:09:41 -0700632int target_dsi_phy_config(struct mdss_dsi_phy_ctrl *phy_db)
633{
634 memcpy(phy_db->regulator, panel_regulator_settings, REGULATOR_SIZE);
635 memcpy(phy_db->ctrl, panel_physical_ctrl, PHYSICAL_SIZE);
636 memcpy(phy_db->strength, panel_strength_ctrl, STRENGTH_SIZE);
637 memcpy(phy_db->bistCtrl, panel_bist_ctrl, BIST_SIZE);
638 memcpy(phy_db->laneCfg, panel_lane_config, LANE_SIZE);
639 return NO_ERROR;
640}
641
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530642int target_display_get_base_offset(uint32_t base)
643{
Meng Jiang289a9812019-10-23 15:25:26 +0800644 if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530645 if (base == MIPI_DSI0_BASE)
646 return DSI0_BASE_ADJUST;
647 else if (base == DSI0_PHY_BASE)
648 return DSI0_PHY_BASE_ADJUST;
649 else if (base == DSI0_PLL_BASE)
650 return DSI0_12NM_PHY_PLL_BASE_ADJUST;
651 else if (base == DSI1_PLL_BASE)
652 return DSI1_12NM_PHY_PLL_BASE_ADJUST;
653 } else if (platform_is_msm8956() || platform_is_msm8937() ||
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530654 platform_is_msm8917() || platform_is_qm215()) {
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530655 if (base == MIPI_DSI0_BASE)
656 return DSI0_BASE_ADJUST;
657 else if (base == DSI0_PHY_BASE)
658 return DSI0_PHY_BASE_ADJUST;
659 else if (base == DSI0_PLL_BASE)
660 return DSI0_PHY_PLL_BASE_ADJUST;
661 else if (base == DSI0_REGULATOR_BASE)
662 return DSI0_PHY_REGULATOR_BASE_ADJUST;
663 }
664
665 return 0;
666}
667
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700668int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
669{
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530670 int rc = 0;
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530671 uint32_t ldo_num = REG_LDO6 | REG_LDO17;
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530672 uint32_t pmic_type = target_get_pmic();
Xipeng Gu5affb812019-06-18 14:59:17 +0800673 uint32_t hw_subtype = board_hardware_subtype();
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530674
675 if (platform_is_msm8956())
676 ldo_num |= REG_LDO1;
Meng Jiang289a9812019-10-23 15:25:26 +0800677 else if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w())
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530678 ldo_num |= REG_LDO5; /* LDO23 is enable by default */
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530679 else
680 ldo_num |= REG_LDO2;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700681
Meng Jiang289a9812019-10-23 15:25:26 +0800682 if ((platform_is_sdm429() && (board_hardware_subtype() == HW_PLATFORM_SUBTYPE_429W_PM660)) || platform_is_sdm429w() || platform_is_sda429w()) {
xiaolin6c9bbb82019-07-26 16:20:46 +0800683 ldo_num &= ~(REG_LDO17 | REG_LDO5);
684 ldo_num |= REG_LDO13 | REG_LDO15;
685 }
Xipeng Gu5affb812019-06-18 14:59:17 +0800686
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700687 if (enable) {
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530688 regulator_enable(ldo_num);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700689 mdelay(10);
Frank Yi2b7e2b92018-04-25 16:24:45 +0800690 if(!pinfo->disable_wled_labibb) {
691 rc = wled_init(pinfo);
692 if (rc) {
693 dprintf(CRITICAL, "%s: wled init failed\n", __func__);
694 return rc;
695 }
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530696 if (pmic_type == PMIC_IS_PMI632)
Frank Yi2b7e2b92018-04-25 16:24:45 +0800697 rc = qpnp_lcdb_enable(true);
Umang Agrawaldff10da2019-05-08 16:14:13 +0530698 else if(pmic_type != PMIC_IS_PM8916 && pmic_type != PMIC_IS_PM660)
Frank Yi2b7e2b92018-04-25 16:24:45 +0800699 rc = qpnp_ibb_enable(true); /*5V boost*/
700 if (rc) {
701 dprintf(CRITICAL, "%s: qpnp_ibb/lcdb failed\n", __func__);
702 return rc;
703 }
704 mdelay(50);
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530705 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700706 } else {
Padmanabhan Komandurufa2899b2015-06-30 16:25:33 +0530707 /*
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530708 * LDO1, LDO2, LDO5 and LDO6 are shared with other subsystems.
Padmanabhan Komandurufa2899b2015-06-30 16:25:33 +0530709 * Do not disable them.
710 */
711 regulator_disable(REG_LDO17);
Xipeng Gu5affb812019-06-18 14:59:17 +0800712
Meng Jiang289a9812019-10-23 15:25:26 +0800713 if ((platform_is_sdm429() || platform_is_sdm429w() || platform_is_sda429w()) && hw_subtype
Xipeng Gu5affb812019-06-18 14:59:17 +0800714 == HW_PLATFORM_SUBTYPE_429W_PM660)
715 regulator_disable(REG_LDO13 | REG_LDO15);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700716 }
717
718 return NO_ERROR;
719}
720
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530721bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700722{
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530723 int prefix_string_len = strlen(DISPLAY_CMDLINE_PREFIX);
724 bool ret = true;
725 struct oem_panel_data oem = mdss_dsi_get_oem_data();
726 uint32_t platform_subtype = board_hardware_subtype();
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530727 uint32_t platform = board_platform_id();
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530728
729 /* default to hdmi for apq iot */
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530730 if ((APQ8017 == platform) && ((HW_PLATFORM_SUBTYPE_SAP == platform_subtype) ||
731 (HW_PLATFORM_SUBTYPE_SAP_NOPMI == platform_subtype))) {
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530732 if (!strcmp(oem.panel, "")) {
733 if (buf_size < (prefix_string_len +
734 strlen(HDMI_ADV_PANEL_STRING))) {
735 dprintf(CRITICAL, "HDMI command line argument \
736 is greater than buffer size\n");
737 return false;
738 }
739 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
740 buf_size -= prefix_string_len;
741 pbuf += prefix_string_len;
742 strlcpy(pbuf, HDMI_ADV_PANEL_STRING, buf_size);
743 } else if (!strcmp(oem.panel, TRULY_720P_VID_PANEL)) {
744 if (buf_size < (prefix_string_len +
745 strlen(TRULY_VID_PANEL_STRING))) {
746 dprintf(CRITICAL, "TRULY VIDEO command line \
747 argument is greater than \
748 buffer size\n");
749 return false;
750 }
751 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
752 buf_size -= prefix_string_len;
753 pbuf += prefix_string_len;
754 strlcpy(pbuf, TRULY_VID_PANEL_STRING, buf_size);
755 } else if (!strcmp(oem.panel, TRULY_720P_CMD_PANEL)) {
756 if (buf_size < (prefix_string_len +
757 strlen(TRULY_CMD_PANEL_STRING))) {
758 dprintf(CRITICAL, "TRULY CMD command line argument \
759 argument is greater than \
760 buffer size\n");
761 return false;
762 }
763 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
764 buf_size -= prefix_string_len;
765 pbuf += prefix_string_len;
766 strlcpy(pbuf, TRULY_CMD_PANEL_STRING, buf_size);
767 }
768 } else {
769 ret = gcdb_display_cmdline_arg(pbuf, buf_size);
770 }
771
772 return ret;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700773}
774
775void target_display_init(const char *panel_name)
776{
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530777 struct oem_panel_data oem;
Ray Zhangf95f5b92015-06-25 15:34:29 +0800778 int32_t ret = 0;
779 uint32_t panel_loop = 0;
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530780 uint32_t platform_subtype = board_hardware_subtype();
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530781 uint32_t platform = board_platform_id();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700782
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530783 set_panel_cmd_string(panel_name);
784 oem = mdss_dsi_get_oem_data();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700785
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530786 if (!strcmp(oem.panel, NO_PANEL_CONFIG)
787 || !strcmp(oem.panel, SIM_VIDEO_PANEL)
788 || !strcmp(oem.panel, SIM_CMD_PANEL)
789 || oem.skip) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700790 dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n",
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530791 oem.panel);
Vishnuvardhan Prodduturi4cd56382017-08-22 21:46:38 +0530792 oem.cont_splash = false;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700793 }
794
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530795 if ((APQ8017 == platform) && ((HW_PLATFORM_SUBTYPE_SAP == platform_subtype) ||
796 (HW_PLATFORM_SUBTYPE_SAP_NOPMI == platform_subtype))) {
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530797 dprintf(INFO, "%s: Platform subtype %d\n",
798 __func__, platform_subtype);
799 return;
800 }
801
Ray Zhangf95f5b92015-06-25 15:34:29 +0800802 do {
803 target_force_cont_splash_disable(false);
804 ret = gcdb_display_init(oem.panel, MDP_REV_50, (void *)MIPI_FB_ADDR);
805 if (!ret || ret == ERR_NOT_SUPPORTED) {
806 break;
807 } else {
808 target_force_cont_splash_disable(true);
809 msm_display_off();
810 }
811 } while (++panel_loop <= oem_panel_max_auto_detect_panels());
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700812
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530813 if (!oem.cont_splash) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700814 dprintf(INFO, "Forcing continuous splash disable\n");
815 target_force_cont_splash_disable(true);
816 }
817}
818
819void target_display_shutdown(void)
820{
821 gcdb_display_shutdown();
822}