blob: b74c4a5bc7764cedf14baf36aaaa192067f80609 [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;
shaoxing0534f8b2019-07-08 19:56:02 +0800367 } else if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w()) {
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
shaoxing0534f8b2019-07-08 19:56:02 +0800391 if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w()) {
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;
shaoxing0534f8b2019-07-08 19:56:02 +0800455 } else if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530456 reset_gpio.pin_id = 60;
shaoxing0534f8b2019-07-08 19:56:02 +0800457 if ((platform_is_sdm429() || platform_is_sdm429w()) && hw_subtype
Xipeng Gu5affb812019-06-18 14:59:17 +0800458 == HW_PLATFORM_SUBTYPE_429W_PM660) {
459 reset_gpio.pin_id = 60;
460 pinfo->mipi.use_enable_gpio = 1;
461 enable_gpio.pin_id = 69;
462 }
Sujeev Dias6bc9fa32015-08-03 23:13:44 -0700463 } else if ((hw_id == HW_PLATFORM_QRD) &&
464 (hw_subtype == HW_PLATFORM_SUBTYPE_POLARIS)) {
465 enable_gpio.pin_id = 19;
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530466 }
467
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700468 if (enable) {
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530469 if (pinfo->mipi.use_enable_gpio && !platform_is_msm8956()) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700470 gpio_tlmm_config(enable_gpio.pin_id, 0,
471 enable_gpio.pin_direction, enable_gpio.pin_pull,
472 enable_gpio.pin_strength,
473 enable_gpio.pin_state);
474
475 gpio_set_dir(enable_gpio.pin_id, 2);
476 }
477
shaoxing0534f8b2019-07-08 19:56:02 +0800478 if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530479 /* enable PM GPIO-4 for backlight enable */
480 struct pm8x41_gpio gpio_param = {
481 .direction = PM_GPIO_DIR_OUT,
482 .function = PM_GPIO_FUNC_HIGH,
483 .vin_sel = 0, /* VIN_0 */
484 .pull = PM_GPIO_NO_PULL,
485 .output_buffer = PM_GPIO_OUT_CMOS,
486 .out_strength = PM_GPIO_OUT_DRIVE_HIGH,
487 };
488
Xipeng Gudd4f96d2019-07-17 16:44:09 +0800489 if (((board_target_id() & VARIANT_MAJOR_MASK)) &&
490 platform_is_sdm429w()) {
491 /* enable PM660 GPIO-12 for backlight enable */
492 bkl_en_gpio.pin_id = 12;
493 gpio_param.inv_int_pol = PM_GPIO_INVERT;
494 }
495
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530496 dprintf(SPEW, "%s: gpio=%d enable=%d\n", __func__,
497 bkl_en_gpio.pin_id, enable);
498
499 pm8x41_gpio_config(bkl_en_gpio.pin_id, &gpio_param);
500 } else {
501 gpio_tlmm_config(bkl_gpio.pin_id, 0,
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700502 bkl_gpio.pin_direction, bkl_gpio.pin_pull,
503 bkl_gpio.pin_strength, bkl_gpio.pin_state);
504
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530505 gpio_set_dir(bkl_gpio.pin_id, 2);
506 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700507
508 gpio_tlmm_config(reset_gpio.pin_id, 0,
509 reset_gpio.pin_direction, reset_gpio.pin_pull,
510 reset_gpio.pin_strength, reset_gpio.pin_state);
511
512 gpio_set_dir(reset_gpio.pin_id, 2);
513
514 /* reset */
515 for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) {
516 if (resetseq->pin_state[i] == GPIO_STATE_LOW)
517 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_LOW);
518 else
519 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_HIGH);
520 mdelay(resetseq->sleep[i]);
521 }
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530522
523 if (platform_is_msm8956()) {
524 gpio_tlmm_config(lcd_mode_gpio.pin_id, 0,
525 lcd_mode_gpio.pin_direction, lcd_mode_gpio.pin_pull,
526 lcd_mode_gpio.pin_strength, lcd_mode_gpio.pin_state);
527
528 if (pinfo->lcdc.split_display || pinfo->lcdc.dst_split)
529 gpio_set_dir(lcd_mode_gpio.pin_id, GPIO_STATE_LOW);
530 else
531 gpio_set_dir(lcd_mode_gpio.pin_id, GPIO_STATE_HIGH);
532 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700533 } else if(!target_cont_splash_screen()) {
534 gpio_set_dir(reset_gpio.pin_id, 0);
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530535 if (pinfo->mipi.use_enable_gpio && !platform_is_msm8956())
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700536 gpio_set_dir(enable_gpio.pin_id, 0);
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530537 if (platform_is_msm8956())
538 gpio_set_dir(lcd_mode_gpio.pin_id, 0);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700539 }
540
541 return ret;
542}
543
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530544static int wled_init(struct msm_panel_info *pinfo)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700545{
546 struct qpnp_wled_config_data config = {0};
547 struct labibb_desc *labibb;
548 int display_type = 0;
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530549 bool swire_control = 0;
550 bool wled_avdd_control = 0;
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530551 int rc = NO_ERROR;
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530552 uint32_t pmic_type = target_get_pmic();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700553
Umang Agrawaldff10da2019-05-08 16:14:13 +0530554 if(pmic_type == PMIC_IS_PM8916 || pmic_type == PMIC_IS_PM660)
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530555 return NO_ERROR;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700556 labibb = pinfo->labibb;
557
558 if (labibb)
559 display_type = labibb->amoled_panel;
560
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530561 if (display_type) {
562 swire_control = labibb->swire_control;
563 wled_avdd_control = true;
564 } else {
565 swire_control = false;
566 wled_avdd_control = false;
567 }
568
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700569 config.display_type = display_type;
570 config.lab_init_volt = 4600000; /* fixed, see pmi register */
571 config.ibb_init_volt = 1400000; /* fixed, see pmi register */
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530572 config.lab_ibb_swire_control = swire_control;
573 config.wled_avdd_control = wled_avdd_control;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700574
Vishnuvardhan Prodduturi4aa8dc42015-10-20 21:20:43 +0530575 if(!swire_control) {
576 if (labibb && labibb->force_config) {
577 config.lab_min_volt = labibb->lab_min_volt;
578 config.lab_max_volt = labibb->lab_max_volt;
579 config.ibb_min_volt = labibb->ibb_min_volt;
580 config.ibb_max_volt = labibb->ibb_max_volt;
581 config.pwr_up_delay = labibb->pwr_up_delay;
582 config.pwr_down_delay = labibb->pwr_down_delay;
583 config.ibb_discharge_en = labibb->ibb_discharge_en;
584 } else {
585 /* default */
586 config.pwr_up_delay = 3;
587 config.pwr_down_delay = 3;
588 config.ibb_discharge_en = 1;
589 if (display_type) { /* amoled */
590 config.lab_min_volt = 4600000;
591 config.lab_max_volt = 4600000;
592 config.ibb_min_volt = 4000000;
593 config.ibb_max_volt = 4000000;
594 } else { /* lcd */
595 config.lab_min_volt = 5500000;
596 config.lab_max_volt = 5500000;
597 config.ibb_min_volt = 5500000;
598 config.ibb_max_volt = 5500000;
599 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700600 }
601 }
602
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530603 if (pmic_type == PMIC_IS_PMI632) {
Narender Ankambf2e2dd2018-05-30 17:48:11 +0530604 config.pwr_up_delay = 1;
605 config.pwr_down_delay = 0;
606 }
607
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700608 dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d %d %d\n", __func__,
609 config.display_type,
610 config.lab_min_volt, config.lab_max_volt,
611 config.ibb_min_volt, config.ibb_max_volt,
612 config.lab_init_volt, config.ibb_init_volt,
613 config.pwr_up_delay, config.pwr_down_delay,
614 config.ibb_discharge_en);
615
616 /* QPNP WLED init for display backlight */
617 pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID);
618
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530619 if (pmic_type == PMIC_IS_PMI632)
Umang Agrawald1939942018-02-13 16:23:58 +0530620 rc = qpnp_lcdb_init(&config);
621 else
622 rc = qpnp_wled_init(&config);
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530623
624 return rc;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700625}
626
Dhaval Patel7709c412015-05-12 10:09:41 -0700627int target_dsi_phy_config(struct mdss_dsi_phy_ctrl *phy_db)
628{
629 memcpy(phy_db->regulator, panel_regulator_settings, REGULATOR_SIZE);
630 memcpy(phy_db->ctrl, panel_physical_ctrl, PHYSICAL_SIZE);
631 memcpy(phy_db->strength, panel_strength_ctrl, STRENGTH_SIZE);
632 memcpy(phy_db->bistCtrl, panel_bist_ctrl, BIST_SIZE);
633 memcpy(phy_db->laneCfg, panel_lane_config, LANE_SIZE);
634 return NO_ERROR;
635}
636
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530637int target_display_get_base_offset(uint32_t base)
638{
shaoxing0534f8b2019-07-08 19:56:02 +0800639 if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w()) {
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530640 if (base == MIPI_DSI0_BASE)
641 return DSI0_BASE_ADJUST;
642 else if (base == DSI0_PHY_BASE)
643 return DSI0_PHY_BASE_ADJUST;
644 else if (base == DSI0_PLL_BASE)
645 return DSI0_12NM_PHY_PLL_BASE_ADJUST;
646 else if (base == DSI1_PLL_BASE)
647 return DSI1_12NM_PHY_PLL_BASE_ADJUST;
648 } else if (platform_is_msm8956() || platform_is_msm8937() ||
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530649 platform_is_msm8917() || platform_is_qm215()) {
Padmanabhan Komandurub3381932015-06-15 22:14:02 +0530650 if (base == MIPI_DSI0_BASE)
651 return DSI0_BASE_ADJUST;
652 else if (base == DSI0_PHY_BASE)
653 return DSI0_PHY_BASE_ADJUST;
654 else if (base == DSI0_PLL_BASE)
655 return DSI0_PHY_PLL_BASE_ADJUST;
656 else if (base == DSI0_REGULATOR_BASE)
657 return DSI0_PHY_REGULATOR_BASE_ADJUST;
658 }
659
660 return 0;
661}
662
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700663int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
664{
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530665 int rc = 0;
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530666 uint32_t ldo_num = REG_LDO6 | REG_LDO17;
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530667 uint32_t pmic_type = target_get_pmic();
Xipeng Gu5affb812019-06-18 14:59:17 +0800668 uint32_t hw_subtype = board_hardware_subtype();
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530669
670 if (platform_is_msm8956())
671 ldo_num |= REG_LDO1;
shaoxing0534f8b2019-07-08 19:56:02 +0800672 else if (platform_is_sdm439() || platform_is_sdm429() || platform_is_sdm429w())
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530673 ldo_num |= REG_LDO5; /* LDO23 is enable by default */
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530674 else
675 ldo_num |= REG_LDO2;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700676
shaoxing0534f8b2019-07-08 19:56:02 +0800677 if ((platform_is_sdm429() || platform_is_sdm429w()) && hw_subtype
Xipeng Gu5affb812019-06-18 14:59:17 +0800678 == HW_PLATFORM_SUBTYPE_429W_PM660)
679 ldo_num |= REG_LDO13 | REG_LDO15;
680
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700681 if (enable) {
Padmanabhan Komanduru3cb07662015-06-08 17:13:33 +0530682 regulator_enable(ldo_num);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700683 mdelay(10);
Frank Yi2b7e2b92018-04-25 16:24:45 +0800684 if(!pinfo->disable_wled_labibb) {
685 rc = wled_init(pinfo);
686 if (rc) {
687 dprintf(CRITICAL, "%s: wled init failed\n", __func__);
688 return rc;
689 }
Vishnuvardhan Prodduturia84a0e82018-10-25 12:55:55 +0530690 if (pmic_type == PMIC_IS_PMI632)
Frank Yi2b7e2b92018-04-25 16:24:45 +0800691 rc = qpnp_lcdb_enable(true);
Umang Agrawaldff10da2019-05-08 16:14:13 +0530692 else if(pmic_type != PMIC_IS_PM8916 && pmic_type != PMIC_IS_PM660)
Frank Yi2b7e2b92018-04-25 16:24:45 +0800693 rc = qpnp_ibb_enable(true); /*5V boost*/
694 if (rc) {
695 dprintf(CRITICAL, "%s: qpnp_ibb/lcdb failed\n", __func__);
696 return rc;
697 }
698 mdelay(50);
Sandeep Pandaaa4ea2f2016-07-05 13:52:25 +0530699 }
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700700 } else {
Padmanabhan Komandurufa2899b2015-06-30 16:25:33 +0530701 /*
Padmanabhan Komanduru2ab03a62018-05-17 14:38:59 +0530702 * LDO1, LDO2, LDO5 and LDO6 are shared with other subsystems.
Padmanabhan Komandurufa2899b2015-06-30 16:25:33 +0530703 * Do not disable them.
704 */
705 regulator_disable(REG_LDO17);
Xipeng Gu5affb812019-06-18 14:59:17 +0800706
shaoxing0534f8b2019-07-08 19:56:02 +0800707 if ((platform_is_sdm429() || platform_is_sdm429w()) && hw_subtype
Xipeng Gu5affb812019-06-18 14:59:17 +0800708 == HW_PLATFORM_SUBTYPE_429W_PM660)
709 regulator_disable(REG_LDO13 | REG_LDO15);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700710 }
711
712 return NO_ERROR;
713}
714
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530715bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700716{
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530717 int prefix_string_len = strlen(DISPLAY_CMDLINE_PREFIX);
718 bool ret = true;
719 struct oem_panel_data oem = mdss_dsi_get_oem_data();
720 uint32_t platform_subtype = board_hardware_subtype();
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530721 uint32_t platform = board_platform_id();
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530722
723 /* default to hdmi for apq iot */
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530724 if ((APQ8017 == platform) && ((HW_PLATFORM_SUBTYPE_SAP == platform_subtype) ||
725 (HW_PLATFORM_SUBTYPE_SAP_NOPMI == platform_subtype))) {
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530726 if (!strcmp(oem.panel, "")) {
727 if (buf_size < (prefix_string_len +
728 strlen(HDMI_ADV_PANEL_STRING))) {
729 dprintf(CRITICAL, "HDMI command line argument \
730 is greater than buffer size\n");
731 return false;
732 }
733 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
734 buf_size -= prefix_string_len;
735 pbuf += prefix_string_len;
736 strlcpy(pbuf, HDMI_ADV_PANEL_STRING, buf_size);
737 } else if (!strcmp(oem.panel, TRULY_720P_VID_PANEL)) {
738 if (buf_size < (prefix_string_len +
739 strlen(TRULY_VID_PANEL_STRING))) {
740 dprintf(CRITICAL, "TRULY VIDEO command line \
741 argument is greater than \
742 buffer size\n");
743 return false;
744 }
745 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
746 buf_size -= prefix_string_len;
747 pbuf += prefix_string_len;
748 strlcpy(pbuf, TRULY_VID_PANEL_STRING, buf_size);
749 } else if (!strcmp(oem.panel, TRULY_720P_CMD_PANEL)) {
750 if (buf_size < (prefix_string_len +
751 strlen(TRULY_CMD_PANEL_STRING))) {
752 dprintf(CRITICAL, "TRULY CMD command line argument \
753 argument is greater than \
754 buffer size\n");
755 return false;
756 }
757 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
758 buf_size -= prefix_string_len;
759 pbuf += prefix_string_len;
760 strlcpy(pbuf, TRULY_CMD_PANEL_STRING, buf_size);
761 }
762 } else {
763 ret = gcdb_display_cmdline_arg(pbuf, buf_size);
764 }
765
766 return ret;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700767}
768
769void target_display_init(const char *panel_name)
770{
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530771 struct oem_panel_data oem;
Ray Zhangf95f5b92015-06-25 15:34:29 +0800772 int32_t ret = 0;
773 uint32_t panel_loop = 0;
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530774 uint32_t platform_subtype = board_hardware_subtype();
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530775 uint32_t platform = board_platform_id();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700776
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530777 set_panel_cmd_string(panel_name);
778 oem = mdss_dsi_get_oem_data();
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700779
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530780 if (!strcmp(oem.panel, NO_PANEL_CONFIG)
781 || !strcmp(oem.panel, SIM_VIDEO_PANEL)
782 || !strcmp(oem.panel, SIM_CMD_PANEL)
783 || oem.skip) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700784 dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n",
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530785 oem.panel);
Vishnuvardhan Prodduturi4cd56382017-08-22 21:46:38 +0530786 oem.cont_splash = false;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700787 }
788
Sachin Bhayare0ad72772018-03-22 19:11:29 +0530789 if ((APQ8017 == platform) && ((HW_PLATFORM_SUBTYPE_SAP == platform_subtype) ||
790 (HW_PLATFORM_SUBTYPE_SAP_NOPMI == platform_subtype))) {
Ashish Garg9cfd6ca2016-12-20 01:41:54 +0530791 dprintf(INFO, "%s: Platform subtype %d\n",
792 __func__, platform_subtype);
793 return;
794 }
795
Ray Zhangf95f5b92015-06-25 15:34:29 +0800796 do {
797 target_force_cont_splash_disable(false);
798 ret = gcdb_display_init(oem.panel, MDP_REV_50, (void *)MIPI_FB_ADDR);
799 if (!ret || ret == ERR_NOT_SUPPORTED) {
800 break;
801 } else {
802 target_force_cont_splash_disable(true);
803 msm_display_off();
804 }
805 } while (++panel_loop <= oem_panel_max_auto_detect_panels());
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700806
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530807 if (!oem.cont_splash) {
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700808 dprintf(INFO, "Forcing continuous splash disable\n");
809 target_force_cont_splash_disable(true);
810 }
811}
812
813void target_display_shutdown(void)
814{
815 gcdb_display_shutdown();
816}