blob: 5f8ed5a3c7e1e849bc2dffa663c32cb7b7b8c38f [file] [log] [blame]
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -07001/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2 *
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>
39#include <board.h>
40#include <mdp5.h>
41#include <scm.h>
42#include <regulator.h>
43#include <platform/clock.h>
44#include <platform/gpio.h>
45#include <platform/iomap.h>
46#include <target/display.h>
47#include <qtimer.h>
48
49#include "include/panel.h"
50#include "include/display_resource.h"
51#include "gcdb_display.h"
52
53/*---------------------------------------------------------------------------*/
54/* GPIO configuration */
55/*---------------------------------------------------------------------------*/
56static struct gpio_pin reset_gpio = {
57 "msmgpio", 0, 3, 1, 0, 1
58};
59
60static struct gpio_pin enable_gpio = {
61 "msmgpio", 90, 3, 1, 0, 1
62};
63
64static struct gpio_pin bkl_gpio = {
65 "msmgpio", 91, 3, 1, 0, 1
66};
67
68#define VCO_DELAY_USEC 1000
69#define GPIO_STATE_LOW 0
70#define GPIO_STATE_HIGH 2
71#define RESET_GPIO_SEQ_LEN 3
72#define PMIC_WLED_SLAVE_ID 3
73
74static void mdss_dsi_uniphy_pll_sw_reset_8952(uint32_t pll_base)
75{
76 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
77 mdelay(1);
78 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
79 mdelay(1);
80}
81
82static void dsi_pll_toggle_lock_detect_8952(uint32_t pll_base)
83{
84 writel(0x04, pll_base + 0x0064); /* LKDetect CFG2 */
85 udelay(1);
86 writel(0x05, pll_base + 0x0064); /* LKDetect CFG2 */
87 udelay(512);
88}
89
90static void dsi_pll_sw_reset_8952(uint32_t pll_base)
91{
92 writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */
93 udelay(1);
94 writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */
Padmanabhan Komanduru6cf63522015-06-08 14:48:00 +053095 udelay(1);
96}
97
98static uint32_t dsi_pll_lock_status_8956(uint32_t pll_base)
99{
100 uint32_t counter, status;
101
102 status = readl(pll_base + 0x00c0) & 0x01;
103 for (counter = 0; counter < 5 && !status; counter++) {
104 udelay(100);
105 status = readl(pll_base + 0x00c0) & 0x01;
106 }
107
108 return status;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700109}
110
111static uint32_t gf_1_dsi_pll_enable_sequence_8952(uint32_t pll_base)
112{
113 uint32_t rc;
114
115 dsi_pll_sw_reset_8952(pll_base);
116
117 /*
118 * Add hardware recommended delays between register writes for
119 * the updates to take effect. These delays are necessary for the
120 * PLL to successfully lock
121 */
122 writel(0x14, pll_base + 0x0070); /* CAL CFG1*/
123 writel(0x01, pll_base + 0x0020); /* GLB CFG */
124 writel(0x05, pll_base + 0x0020); /* GLB CFG */
125 udelay(3);
126 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
127 udelay(500);
128
129 dsi_pll_toggle_lock_detect_8952(pll_base);
130 rc = readl(pll_base + 0x00c0) & 0x01;
131
132 return rc;
133}
134
135static uint32_t gf_2_dsi_pll_enable_sequence_8952(uint32_t pll_base)
136{
137 uint32_t rc;
138
139 dsi_pll_sw_reset_8952(pll_base);
140
141 /*
142 * Add hardware recommended delays between register writes for
143 * the updates to take effect. These delays are necessary for the
144 * PLL to successfully lock
145 */
146 writel(0x04, pll_base + 0x0070); /* CAL CFG1*/
147 writel(0x01, pll_base + 0x0020); /* GLB CFG */
148 writel(0x05, pll_base + 0x0020); /* GLB CFG */
149 udelay(3);
150 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
151 udelay(500);
152
153 dsi_pll_toggle_lock_detect_8952(pll_base);
154 rc = readl(pll_base + 0x00c0) & 0x01;
155
156 return rc;
157}
158
159static uint32_t tsmc_dsi_pll_enable_sequence_8952(uint32_t pll_base)
160{
161 uint32_t rc;
162
163 dsi_pll_sw_reset_8952(pll_base);
164 /*
165 * Add hardware recommended delays between register writes for
166 * the updates to take effect. These delays are necessary for the
167 * PLL to successfully lock
168 */
169
170 writel(0x34, pll_base + 0x0070); /* CAL CFG1*/
171 writel(0x01, pll_base + 0x0020); /* GLB CFG */
172 writel(0x05, pll_base + 0x0020); /* GLB CFG */
173 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
174 udelay(500);
175
176 dsi_pll_toggle_lock_detect_8952(pll_base);
177 rc = readl(pll_base + 0x00c0) & 0x01;
178
179 return rc;
180}
181
182
183static uint32_t dsi_pll_enable_seq_8952(uint32_t pll_base)
184{
185 uint32_t pll_locked = 0;
186 uint32_t counter = 0;
187
188 do {
189 pll_locked = tsmc_dsi_pll_enable_sequence_8952(pll_base);
190
191 dprintf(SPEW, "TSMC pll locked status is %d\n", pll_locked);
192 ++counter;
193 } while (!pll_locked && (counter < 3));
194
195 if(!pll_locked) {
196 counter = 0;
197 do {
198 pll_locked = gf_1_dsi_pll_enable_sequence_8952(pll_base);
199
200 dprintf(SPEW, "GF P1 pll locked status is %d\n", pll_locked);
201 ++counter;
202 } while (!pll_locked && (counter < 3));
203 }
204
205 if(!pll_locked) {
206 counter = 0;
207 do {
208 pll_locked = gf_2_dsi_pll_enable_sequence_8952(pll_base);
209
210 dprintf(SPEW, "GF P2 pll locked status is %d\n", pll_locked);
211 ++counter;
212 } while (!pll_locked && (counter < 3));
213 }
214
215 return pll_locked;
216}
217
Padmanabhan Komanduru6cf63522015-06-08 14:48:00 +0530218static uint32_t dsi_pll_enable_seq_8956(uint32_t pll_base)
219{
220 /*
221 * PLL power up sequence
222 * Add necessary delays recommended by h/w team
223 */
224
225 /* Lock Detect setting */
226 writel(0x0d, pll_base + 0x0064); /* LKDetect CFG2 */
227 writel(0x34, pll_base + 0x0070); /* PLL CAL_CFG1 */
228 writel(0x10, pll_base + 0x005c); /* LKDetect CFG0 */
229 writel(0x1a, pll_base + 0x0060); /* LKDetect CFG1 */
230
231 writel(0x01, pll_base + 0x0020); /* GLB CFG */
232 udelay(300);
233 writel(0x05, pll_base + 0x0020); /* GLB CFG */
234 udelay(300);
235 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
236 udelay(300);
237 writel(0x07, pll_base + 0x0020); /* GLB CFG */
238 udelay(300);
239 writel(0x0f, pll_base + 0x0020); /* GLB CFG */
240 udelay(1000);
241
242 return dsi_pll_lock_status_8956(pll_base);
243}
244
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700245static int msm8952_wled_backlight_ctrl(uint8_t enable)
246{
247 uint8_t slave_id = PMIC_WLED_SLAVE_ID; /* pmi */
248
249 pm8x41_wled_config_slave_id(slave_id);
250 qpnp_wled_enable_backlight(enable);
251 qpnp_ibb_enable(enable);
252 return NO_ERROR;
253}
254
255int target_backlight_ctrl(struct backlight *bl, uint8_t enable)
256{
257 uint32_t ret = NO_ERROR;
258
259 if (bl->bl_interface_type == BL_DCS)
260 return ret;
261
262 ret = msm8952_wled_backlight_ctrl(enable);
263
264 return ret;
265}
266
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530267static int32_t mdss_dsi_pll_config(uint32_t pll_base, uint32_t ctl_base,
268 struct mdss_dsi_pll_config *pll_data)
269{
270 int32_t ret = 0;
271 if (!platform_is_msm8956())
272 mdss_dsi_uniphy_pll_sw_reset_8952(pll_base);
273 else
274 dsi_pll_sw_reset_8952(pll_base);
275 mdss_dsi_auto_pll_config(pll_base, ctl_base, pll_data);
276 if (platform_is_msm8956())
277 ret = dsi_pll_enable_seq_8956(pll_base);
278 else
279 ret = dsi_pll_enable_seq_8952(pll_base);
280
281 return ret;
282}
283
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700284int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
285{
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530286 int32_t ret = 0, flags;
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700287 struct mdss_dsi_pll_config *pll_data;
288 dprintf(SPEW, "target_panel_clock\n");
289
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530290 if (pinfo->dest == DISPLAY_2) {
291 flags = MMSS_DSI_CLKS_FLAG_DSI1;
292 if (pinfo->mipi.dual_dsi)
293 flags |= MMSS_DSI_CLKS_FLAG_DSI0;
294 } else {
295 flags = MMSS_DSI_CLKS_FLAG_DSI0;
296 if (pinfo->mipi.dual_dsi)
297 flags |= MMSS_DSI_CLKS_FLAG_DSI1;
298 }
299
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700300 pll_data = pinfo->mipi.dsi_pll_config;
301 pll_data->vco_delay = VCO_DELAY_USEC;
302
303 if (enable) {
304 mdp_gdsc_ctrl(enable);
305 mdss_bus_clocks_enable();
306 mdp_clock_enable();
307 ret = restore_secure_cfg(SECURE_DEVICE_MDSS);
308 if (ret) {
309 dprintf(CRITICAL,
310 "%s: Failed to restore MDP security configs",
311 __func__);
312 mdp_clock_disable();
313 mdss_bus_clocks_disable();
314 mdp_gdsc_ctrl(0);
315 return ret;
316 }
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530317
318 ret = mdss_dsi_pll_config(pinfo->mipi.pll_base,
319 pinfo->mipi.ctl_base, pll_data);
Padmanabhan Komanduru6cf63522015-06-08 14:48:00 +0530320 if (!ret)
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530321 dprintf(CRITICAL, "Not able to enable master pll\n");
322
323 if (platform_is_msm8956() && pinfo->mipi.dual_dsi) {
324 ret = mdss_dsi_pll_config(pinfo->mipi.spll_base,
325 pinfo->mipi.sctl_base, pll_data);
326 if (!ret)
327 dprintf(CRITICAL, "Not able to enable second pll\n");
328 }
329
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530330 gcc_dsi_clocks_enable(flags, pll_data->pclk_m, pll_data->pclk_n,
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700331 pll_data->pclk_d);
332 } else if(!target_cont_splash_screen()) {
Padmanabhan Komanduru82ae7132015-06-08 15:46:33 +0530333 gcc_dsi_clocks_disable(flags);
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700334 mdp_clock_disable();
335 mdss_bus_clocks_disable();
336 mdp_gdsc_ctrl(enable);
337 }
338
339 return 0;
340}
341
342int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
343 struct msm_panel_info *pinfo)
344{
345 int ret = NO_ERROR;
346
347 if (enable) {
348 if (pinfo->mipi.use_enable_gpio) {
349 gpio_tlmm_config(enable_gpio.pin_id, 0,
350 enable_gpio.pin_direction, enable_gpio.pin_pull,
351 enable_gpio.pin_strength,
352 enable_gpio.pin_state);
353
354 gpio_set_dir(enable_gpio.pin_id, 2);
355 }
356
357 gpio_tlmm_config(bkl_gpio.pin_id, 0,
358 bkl_gpio.pin_direction, bkl_gpio.pin_pull,
359 bkl_gpio.pin_strength, bkl_gpio.pin_state);
360
361 gpio_set_dir(bkl_gpio.pin_id, 2);
362
363 gpio_tlmm_config(reset_gpio.pin_id, 0,
364 reset_gpio.pin_direction, reset_gpio.pin_pull,
365 reset_gpio.pin_strength, reset_gpio.pin_state);
366
367 gpio_set_dir(reset_gpio.pin_id, 2);
368
369 /* reset */
370 for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) {
371 if (resetseq->pin_state[i] == GPIO_STATE_LOW)
372 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_LOW);
373 else
374 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_HIGH);
375 mdelay(resetseq->sleep[i]);
376 }
377 } else if(!target_cont_splash_screen()) {
378 gpio_set_dir(reset_gpio.pin_id, 0);
379 if (pinfo->mipi.use_enable_gpio)
380 gpio_set_dir(enable_gpio.pin_id, 0);
381 }
382
383 return ret;
384}
385
386static void wled_init(struct msm_panel_info *pinfo)
387{
388 struct qpnp_wled_config_data config = {0};
389 struct labibb_desc *labibb;
390 int display_type = 0;
391
392 labibb = pinfo->labibb;
393
394 if (labibb)
395 display_type = labibb->amoled_panel;
396
397 config.display_type = display_type;
398 config.lab_init_volt = 4600000; /* fixed, see pmi register */
399 config.ibb_init_volt = 1400000; /* fixed, see pmi register */
400
401 if (labibb && labibb->force_config) {
402 config.lab_min_volt = labibb->lab_min_volt;
403 config.lab_max_volt = labibb->lab_max_volt;
404 config.ibb_min_volt = labibb->ibb_min_volt;
405 config.ibb_max_volt = labibb->ibb_max_volt;
406 config.pwr_up_delay = labibb->pwr_up_delay;
407 config.pwr_down_delay = labibb->pwr_down_delay;
408 config.ibb_discharge_en = labibb->ibb_discharge_en;
409 } else {
410 /* default */
411 config.pwr_up_delay = 3;
412 config.pwr_down_delay = 3;
413 config.ibb_discharge_en = 1;
414 if (display_type) { /* amoled */
415 config.lab_min_volt = 4600000;
416 config.lab_max_volt = 4600000;
417 config.ibb_min_volt = 4000000;
418 config.ibb_max_volt = 4000000;
419 } else { /* lcd */
420 config.lab_min_volt = 5500000;
421 config.lab_max_volt = 5500000;
422 config.ibb_min_volt = 5500000;
423 config.ibb_max_volt = 5500000;
424 }
425 }
426
427 dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d %d %d\n", __func__,
428 config.display_type,
429 config.lab_min_volt, config.lab_max_volt,
430 config.ibb_min_volt, config.ibb_max_volt,
431 config.lab_init_volt, config.ibb_init_volt,
432 config.pwr_up_delay, config.pwr_down_delay,
433 config.ibb_discharge_en);
434
435 /* QPNP WLED init for display backlight */
436 pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID);
437
438 qpnp_wled_init(&config);
439}
440
Dhaval Patel7709c412015-05-12 10:09:41 -0700441int target_dsi_phy_config(struct mdss_dsi_phy_ctrl *phy_db)
442{
443 memcpy(phy_db->regulator, panel_regulator_settings, REGULATOR_SIZE);
444 memcpy(phy_db->ctrl, panel_physical_ctrl, PHYSICAL_SIZE);
445 memcpy(phy_db->strength, panel_strength_ctrl, STRENGTH_SIZE);
446 memcpy(phy_db->bistCtrl, panel_bist_ctrl, BIST_SIZE);
447 memcpy(phy_db->laneCfg, panel_lane_config, LANE_SIZE);
448 return NO_ERROR;
449}
450
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700451int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
452{
453
454 if (enable) {
455 regulator_enable(REG_LDO2 | REG_LDO6 | REG_LDO17);
456 mdelay(10);
457 wled_init(pinfo);
458 qpnp_ibb_enable(true); /*5V boost*/
459 mdelay(50);
460 } else {
461 regulator_disable(REG_LDO2 | REG_LDO6 | REG_LDO17);
462 }
463
464 return NO_ERROR;
465}
466
467bool target_display_panel_node(char *panel_name, char *pbuf, uint16_t buf_size)
468{
469 return gcdb_display_cmdline_arg(panel_name, pbuf, buf_size);
470}
471
472void target_display_init(const char *panel_name)
473{
474 char cont_splash = '\0';
475
476 set_panel_cmd_string(panel_name, &cont_splash);
477 panel_name += strspn(panel_name, " ");
478
479 if (!strcmp(panel_name, NO_PANEL_CONFIG)
480 || !strcmp(panel_name, SIM_VIDEO_PANEL)
481 || !strcmp(panel_name, SIM_CMD_PANEL)) {
482 dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n",
483 panel_name);
484 return;
485 }
486
487 if (gcdb_display_init(panel_name, MDP_REV_50, (void *)MIPI_FB_ADDR)) {
488 target_force_cont_splash_disable(true);
489 msm_display_off();
490 }
491
492 if (cont_splash == '0') {
493 dprintf(INFO, "Forcing continuous splash disable\n");
494 target_force_cont_splash_disable(true);
495 }
496}
497
498void target_display_shutdown(void)
499{
500 gcdb_display_shutdown();
501}