blob: 4940086e88e365cc58617a8805baa57514d67e58 [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{
286 int32_t ret = 0;
287 struct mdss_dsi_pll_config *pll_data;
288 dprintf(SPEW, "target_panel_clock\n");
289
290 pll_data = pinfo->mipi.dsi_pll_config;
291 pll_data->vco_delay = VCO_DELAY_USEC;
292
293 if (enable) {
294 mdp_gdsc_ctrl(enable);
295 mdss_bus_clocks_enable();
296 mdp_clock_enable();
297 ret = restore_secure_cfg(SECURE_DEVICE_MDSS);
298 if (ret) {
299 dprintf(CRITICAL,
300 "%s: Failed to restore MDP security configs",
301 __func__);
302 mdp_clock_disable();
303 mdss_bus_clocks_disable();
304 mdp_gdsc_ctrl(0);
305 return ret;
306 }
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530307
308 ret = mdss_dsi_pll_config(pinfo->mipi.pll_base,
309 pinfo->mipi.ctl_base, pll_data);
Padmanabhan Komanduru6cf63522015-06-08 14:48:00 +0530310 if (!ret)
Padmanabhan Komanduru77a979a2015-06-15 15:03:23 +0530311 dprintf(CRITICAL, "Not able to enable master pll\n");
312
313 if (platform_is_msm8956() && pinfo->mipi.dual_dsi) {
314 ret = mdss_dsi_pll_config(pinfo->mipi.spll_base,
315 pinfo->mipi.sctl_base, pll_data);
316 if (!ret)
317 dprintf(CRITICAL, "Not able to enable second pll\n");
318 }
319
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700320 gcc_dsi_clocks_enable(pll_data->pclk_m, pll_data->pclk_n,
321 pll_data->pclk_d);
322 } else if(!target_cont_splash_screen()) {
323 gcc_dsi_clocks_disable();
324 mdp_clock_disable();
325 mdss_bus_clocks_disable();
326 mdp_gdsc_ctrl(enable);
327 }
328
329 return 0;
330}
331
332int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
333 struct msm_panel_info *pinfo)
334{
335 int ret = NO_ERROR;
336
337 if (enable) {
338 if (pinfo->mipi.use_enable_gpio) {
339 gpio_tlmm_config(enable_gpio.pin_id, 0,
340 enable_gpio.pin_direction, enable_gpio.pin_pull,
341 enable_gpio.pin_strength,
342 enable_gpio.pin_state);
343
344 gpio_set_dir(enable_gpio.pin_id, 2);
345 }
346
347 gpio_tlmm_config(bkl_gpio.pin_id, 0,
348 bkl_gpio.pin_direction, bkl_gpio.pin_pull,
349 bkl_gpio.pin_strength, bkl_gpio.pin_state);
350
351 gpio_set_dir(bkl_gpio.pin_id, 2);
352
353 gpio_tlmm_config(reset_gpio.pin_id, 0,
354 reset_gpio.pin_direction, reset_gpio.pin_pull,
355 reset_gpio.pin_strength, reset_gpio.pin_state);
356
357 gpio_set_dir(reset_gpio.pin_id, 2);
358
359 /* reset */
360 for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) {
361 if (resetseq->pin_state[i] == GPIO_STATE_LOW)
362 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_LOW);
363 else
364 gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_HIGH);
365 mdelay(resetseq->sleep[i]);
366 }
367 } else if(!target_cont_splash_screen()) {
368 gpio_set_dir(reset_gpio.pin_id, 0);
369 if (pinfo->mipi.use_enable_gpio)
370 gpio_set_dir(enable_gpio.pin_id, 0);
371 }
372
373 return ret;
374}
375
376static void wled_init(struct msm_panel_info *pinfo)
377{
378 struct qpnp_wled_config_data config = {0};
379 struct labibb_desc *labibb;
380 int display_type = 0;
381
382 labibb = pinfo->labibb;
383
384 if (labibb)
385 display_type = labibb->amoled_panel;
386
387 config.display_type = display_type;
388 config.lab_init_volt = 4600000; /* fixed, see pmi register */
389 config.ibb_init_volt = 1400000; /* fixed, see pmi register */
390
391 if (labibb && labibb->force_config) {
392 config.lab_min_volt = labibb->lab_min_volt;
393 config.lab_max_volt = labibb->lab_max_volt;
394 config.ibb_min_volt = labibb->ibb_min_volt;
395 config.ibb_max_volt = labibb->ibb_max_volt;
396 config.pwr_up_delay = labibb->pwr_up_delay;
397 config.pwr_down_delay = labibb->pwr_down_delay;
398 config.ibb_discharge_en = labibb->ibb_discharge_en;
399 } else {
400 /* default */
401 config.pwr_up_delay = 3;
402 config.pwr_down_delay = 3;
403 config.ibb_discharge_en = 1;
404 if (display_type) { /* amoled */
405 config.lab_min_volt = 4600000;
406 config.lab_max_volt = 4600000;
407 config.ibb_min_volt = 4000000;
408 config.ibb_max_volt = 4000000;
409 } else { /* lcd */
410 config.lab_min_volt = 5500000;
411 config.lab_max_volt = 5500000;
412 config.ibb_min_volt = 5500000;
413 config.ibb_max_volt = 5500000;
414 }
415 }
416
417 dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d %d %d\n", __func__,
418 config.display_type,
419 config.lab_min_volt, config.lab_max_volt,
420 config.ibb_min_volt, config.ibb_max_volt,
421 config.lab_init_volt, config.ibb_init_volt,
422 config.pwr_up_delay, config.pwr_down_delay,
423 config.ibb_discharge_en);
424
425 /* QPNP WLED init for display backlight */
426 pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID);
427
428 qpnp_wled_init(&config);
429}
430
Dhaval Patel7709c412015-05-12 10:09:41 -0700431int target_dsi_phy_config(struct mdss_dsi_phy_ctrl *phy_db)
432{
433 memcpy(phy_db->regulator, panel_regulator_settings, REGULATOR_SIZE);
434 memcpy(phy_db->ctrl, panel_physical_ctrl, PHYSICAL_SIZE);
435 memcpy(phy_db->strength, panel_strength_ctrl, STRENGTH_SIZE);
436 memcpy(phy_db->bistCtrl, panel_bist_ctrl, BIST_SIZE);
437 memcpy(phy_db->laneCfg, panel_lane_config, LANE_SIZE);
438 return NO_ERROR;
439}
440
Padmanabhan Komanduru9d49f892015-04-10 12:58:46 -0700441int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
442{
443
444 if (enable) {
445 regulator_enable(REG_LDO2 | REG_LDO6 | REG_LDO17);
446 mdelay(10);
447 wled_init(pinfo);
448 qpnp_ibb_enable(true); /*5V boost*/
449 mdelay(50);
450 } else {
451 regulator_disable(REG_LDO2 | REG_LDO6 | REG_LDO17);
452 }
453
454 return NO_ERROR;
455}
456
457bool target_display_panel_node(char *panel_name, char *pbuf, uint16_t buf_size)
458{
459 return gcdb_display_cmdline_arg(panel_name, pbuf, buf_size);
460}
461
462void target_display_init(const char *panel_name)
463{
464 char cont_splash = '\0';
465
466 set_panel_cmd_string(panel_name, &cont_splash);
467 panel_name += strspn(panel_name, " ");
468
469 if (!strcmp(panel_name, NO_PANEL_CONFIG)
470 || !strcmp(panel_name, SIM_VIDEO_PANEL)
471 || !strcmp(panel_name, SIM_CMD_PANEL)) {
472 dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n",
473 panel_name);
474 return;
475 }
476
477 if (gcdb_display_init(panel_name, MDP_REV_50, (void *)MIPI_FB_ADDR)) {
478 target_force_cont_splash_disable(true);
479 msm_display_off();
480 }
481
482 if (cont_splash == '0') {
483 dprintf(INFO, "Forcing continuous splash disable\n");
484 target_force_cont_splash_disable(true);
485 }
486}
487
488void target_display_shutdown(void)
489{
490 gcdb_display_shutdown();
491}