blob: 439ec146fb1b99b6fc0660c225af807e8163710b [file] [log] [blame]
Dhaval Patelb95039c2015-03-16 11:14:06 -07001/* Copyright (c) 2014-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 <endian.h>
42#include <regulator.h>
43#include <qtimer.h>
44#include <arch/defines.h>
45#include <platform/gpio.h>
46#include <platform/clock.h>
47#include <platform/iomap.h>
48#include <target/display.h>
49#include <mipi_dsi_autopll_thulium.h>
50
51#include "include/panel.h"
52#include "include/display_resource.h"
53#include "gcdb_display.h"
54
55#define GPIO_STATE_LOW 0
56#define GPIO_STATE_HIGH 2
57#define RESET_GPIO_SEQ_LEN 3
58
59#define PWM_DUTY_US 13
60#define PWM_PERIOD_US 27
61#define PMIC_WLED_SLAVE_ID 3
62#define PMIC_MPP_SLAVE_ID 2
63
64#define MAX_POLL_READS 15
65#define POLL_TIMEOUT_US 1000
66
67#define STRENGTH_SIZE_IN_BYTES_8996 10
68#define REGULATOR_SIZE_IN_BYTES_8996 5
69#define LANE_SIZE_IN_BYTES_8996 20
70
71/*---------------------------------------------------------------------------*/
72/* GPIO configuration */
73/*---------------------------------------------------------------------------*/
74static struct gpio_pin reset_gpio = {
75 "msmgpio", 8, 3, 1, 0, 1
76};
77
78static struct gpio_pin lcd_reg_en = { /* boost regulator */
79 "pmi8994_gpios", 8, 3, 1, 0, 1
80};
81
82static struct gpio_pin bklt_gpio = { /* lcd_bklt_reg_en */
83 "pm8994_gpios", 14, 3, 1, 0, 1
84};
85
86static uint32_t thulium_dsi_pll_lock_status(uint32_t pll_base, uint32_t off,
87 uint32_t bit)
88{
89 uint32_t cnt, status;
90
91 /* check pll lock first */
92 for (cnt = 0; cnt < MAX_POLL_READS; cnt++) {
93 status = readl(pll_base + off);
94 dprintf(SPEW, "%s: pll_base=%x cnt=%d status=%x\n",
95 __func__, pll_base, cnt, status);
96 status &= BIT(bit); /* bit 5 */
97 if (status)
98 break;
99 udelay(POLL_TIMEOUT_US);
100 }
101
102 return status;
103}
104
105static uint32_t thulium_dsi_pll_enable_seq(uint32_t phy_base, uint32_t pll_base)
106{
107 uint32_t pll_locked;
108
Dhaval Patela9959bf2015-10-13 11:43:54 -0700109 writel(0x10, phy_base + 0x45c);
Dhaval Patelb95039c2015-03-16 11:14:06 -0700110 writel(0x01, phy_base + 0x48);
111 dmb();
112
113 pll_locked = thulium_dsi_pll_lock_status(pll_base, 0xcc, 5);
114 if (pll_locked)
115 pll_locked = thulium_dsi_pll_lock_status(pll_base, 0xcc, 0);
116
117 if (!pll_locked)
118 dprintf(ERROR, "%s: DSI PLL lock failed\n", __func__);
119 else
120 dprintf(SPEW, "%s: DSI PLL lock Success\n", __func__);
121
122 return pll_locked;
123}
124
125static int thulium_wled_backlight_ctrl(uint8_t enable)
126{
127 qpnp_wled_enable_backlight(enable);
Dhaval Patelb95039c2015-03-16 11:14:06 -0700128 return NO_ERROR;
129}
130
131static int thulium_pwm_backlight_ctrl(uint8_t enable)
132{
133 uint8_t slave_id = 3; /* lpg at pmi */
134
135 if (enable) {
136 /* lpg channel 4 */
137
138 /* LPG_ENABLE_CONTROL */
139 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0x46, 0x0);
140 mdelay(100);
141
142 /* LPG_VALUE_LSB, duty cycle = 0x80/0x200 = 1/4 */
143 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0x44, 0x80);
144 /* LPG_VALUE_MSB */
145 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0x45, 0x00);
146 /* LPG_PWM_SYNC */
147 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0x47, 0x01);
148
149 /* LPG_PWM_SIZE_CLK, */
150 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0x41, 0x13);
151 /* LPG_PWM_FREQ_PREDIV */
152 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0x42, 0x02);
153 /* LPG_PWM_TYPE_CONFIG */
154 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0x43, 0x20);
155 /* LPG_ENABLE_CONTROL */
156 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0x46, 0x04);
157
158 /* SEC_ACCESS */
159 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0xD0, 0xA5);
160 /* DTEST4, OUT_HI */
161 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0xE5, 0x01);
162 /* LPG_ENABLE_CONTROL */
163 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0x46, 0xA4);
164 } else {
165 /* LPG_ENABLE_CONTROL */
166 pm8x41_lpg_write_sid(slave_id, PWM_BL_LPG_CHAN_ID, 0x46, 0x0);
167 }
168
169 return NO_ERROR;
170}
171
172static void lcd_reg_enable(void)
173{
174 uint8_t slave_id = 2; /* gpio at pmi */
175
176 struct pm8x41_gpio gpio = {
177 .direction = PM_GPIO_DIR_OUT,
178 .function = PM_GPIO_FUNC_HIGH,
179 .vin_sel = 2, /* VIN_2 */
180 .output_buffer = PM_GPIO_OUT_CMOS,
181 .out_strength = PM_GPIO_OUT_DRIVE_MED,
182 };
183
184 pm8x41_gpio_config_sid(slave_id, lcd_reg_en.pin_id, &gpio);
185 pm8x41_gpio_set_sid(slave_id, lcd_reg_en.pin_id, 1);
186}
187
188static void lcd_reg_disable(void)
189{
190 uint8_t slave_id = 2; /* gpio at pmi */
191
192 pm8x41_gpio_set_sid(slave_id, lcd_reg_en.pin_id, 0);
193}
194
195static void lcd_bklt_reg_enable(void)
196{
197 struct pm8x41_gpio gpio = {
198 .direction = PM_GPIO_DIR_OUT,
199 .function = PM_GPIO_FUNC_HIGH,
200 .vin_sel = 2, /* VIN_2 */
201 .output_buffer = PM_GPIO_OUT_CMOS,
202 .out_strength = PM_GPIO_OUT_DRIVE_LOW,
203 };
204
205 pm8x41_gpio_config(bklt_gpio.pin_id, &gpio);
206 pm8x41_gpio_set(bklt_gpio.pin_id, 1);
207}
208
209static void lcd_bklt_reg_disable(void)
210{
211 pm8x41_gpio_set(bklt_gpio.pin_id, 0);
212}
213
214int target_backlight_ctrl(struct backlight *bl, uint8_t enable)
215{
216 uint32_t ret = NO_ERROR;
217 struct pm8x41_mpp mpp;
218 int rc;
219
220 if (!bl) {
221 dprintf(CRITICAL, "backlight structure is not available\n");
222 return ERR_INVALID_ARGS;
223 }
224
225 switch (bl->bl_interface_type) {
226 case BL_WLED:
227 /* Enable MPP4 */
228 pmi8994_config_mpp_slave_id(PMIC_MPP_SLAVE_ID);
229 mpp.base = PM8x41_MMP4_BASE;
230 mpp.vin = MPP_VIN2;
231 if (enable) {
232 pm_pwm_enable(false);
233 rc = pm_pwm_config(PWM_DUTY_US, PWM_PERIOD_US);
234 if (rc < 0) {
235 mpp.mode = MPP_HIGH;
236 } else {
237 mpp.mode = MPP_DTEST1;
238 pm_pwm_enable(true);
239 }
240 pm8x41_config_output_mpp(&mpp);
241 pm8x41_enable_mpp(&mpp, MPP_ENABLE);
242 } else {
243 pm_pwm_enable(false);
244 pm8x41_enable_mpp(&mpp, MPP_DISABLE);
245 }
Dhaval Patelb95039c2015-03-16 11:14:06 -0700246 /* Enable WLED backlight control */
247 ret = thulium_wled_backlight_ctrl(enable);
248 break;
249 case BL_PWM:
250 /* Enable MPP1 */
251 pmi8994_config_mpp_slave_id(PMIC_MPP_SLAVE_ID);
252 mpp.base = PM8x41_MMP1_BASE;
253 mpp.vin = MPP_VIN2;
254 mpp.mode = MPP_DTEST4;
255 if (enable) {
256 pm8x41_config_output_mpp(&mpp);
257 pm8x41_enable_mpp(&mpp, MPP_ENABLE);
258 } else {
259 pm8x41_enable_mpp(&mpp, MPP_DISABLE);
260 }
Dhaval Patelb95039c2015-03-16 11:14:06 -0700261 ret = thulium_pwm_backlight_ctrl(enable);
262 break;
263 default:
264 dprintf(CRITICAL, "backlight type:%d not supported\n",
265 bl->bl_interface_type);
266 return ERR_NOT_SUPPORTED;
267 }
268
269 return ret;
270}
271
272int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
273{
Aravind Venkateswaran9586be62015-05-20 00:51:06 -0700274 uint32_t flags, dsi_phy_pll_out;
Dhaval Patelb95039c2015-03-16 11:14:06 -0700275 uint32_t ret = NO_ERROR;
276 uint32_t board_version = board_soc_version();
Jeevan Shrirama3860092015-08-03 15:16:57 -0700277 struct dfps_pll_codes *pll_codes = &pinfo->mipi.pll_codes;
Dhaval Patelb95039c2015-03-16 11:14:06 -0700278
279 if (pinfo->dest == DISPLAY_2) {
280 flags = MMSS_DSI_CLKS_FLAG_DSI1;
281 if (pinfo->mipi.dual_dsi)
282 flags |= MMSS_DSI_CLKS_FLAG_DSI0;
283 } else {
284 flags = MMSS_DSI_CLKS_FLAG_DSI0;
285 if (pinfo->mipi.dual_dsi)
286 flags |= MMSS_DSI_CLKS_FLAG_DSI1;
287 }
288
289 if (!enable) {
290 /* stop pll */
291 writel(0x0, pinfo->mipi.phy_base + 0x48);
292 dmb();
293
294 mmss_dsi_clock_disable(flags);
295 goto clks_disable;
296 }
297
298 if (board_version == 0x20000 || board_version == 0x20001)
299 video_gdsc_enable();
300 mmss_gdsc_enable();
301 mmss_bus_clock_enable();
302 mdp_clock_enable();
303 mdss_dsi_auto_pll_thulium_config(pinfo);
304
305 if (!thulium_dsi_pll_enable_seq(pinfo->mipi.phy_base,
306 pinfo->mipi.pll_base)) {
307 ret = ERROR;
308 dprintf(CRITICAL, "PLL failed to lock!\n");
309 goto clks_disable;
310 }
Aravind Venkateswaran9586be62015-05-20 00:51:06 -0700311
Jeevan Shrirama3860092015-08-03 15:16:57 -0700312 pll_codes->codes[0] = readl_relaxed(pinfo->mipi.pll_base +
313 MMSS_DSI_PHY_PLL_CORE_KVCO_CODE);
314 pll_codes->codes[1] = readl_relaxed(pinfo->mipi.pll_base +
315 MMSS_DSI_PHY_PLL_CORE_VCO_TUNE);
316 dprintf(SPEW, "codes %d %d\n", pll_codes->codes[0],
317 pll_codes->codes[1]);
318
Aravind Venkateswaran9586be62015-05-20 00:51:06 -0700319 if (pinfo->mipi.use_dsi1_pll)
320 dsi_phy_pll_out = DSI1_PHY_PLL_OUT;
321 else
322 dsi_phy_pll_out = DSI0_PHY_PLL_OUT;
323 mmss_dsi_clock_enable(dsi_phy_pll_out, flags);
324
Dhaval Patelb95039c2015-03-16 11:14:06 -0700325 return NO_ERROR;
326
327clks_disable:
328 mdp_clock_disable();
329 mmss_bus_clock_disable();
330 mmss_gdsc_disable();
331 if (board_version == 0x20000 || board_version == 0x20001)
332 video_gdsc_disable();
333
334 return ret;
335}
336
337int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
338 struct msm_panel_info *pinfo)
339{
340 uint32_t i = 0;
341
342 if (enable) {
343 gpio_tlmm_config(reset_gpio.pin_id, 0,
344 reset_gpio.pin_direction, reset_gpio.pin_pull,
345 reset_gpio.pin_strength, reset_gpio.pin_state);
346 /* reset */
347 for (i = 0; i < RESET_GPIO_SEQ_LEN; i++) {
348 if (resetseq->pin_state[i] == GPIO_STATE_LOW)
349 gpio_set(reset_gpio.pin_id, GPIO_STATE_LOW);
350 else
351 gpio_set(reset_gpio.pin_id, GPIO_STATE_HIGH);
352 mdelay(resetseq->sleep[i]);
353 }
354 lcd_bklt_reg_enable();
355 } else {
356 lcd_bklt_reg_disable();
357 gpio_set(reset_gpio.pin_id, 0);
358 }
359
360 return NO_ERROR;
361}
362
363static void wled_init(struct msm_panel_info *pinfo)
364{
365 struct qpnp_wled_config_data config = {0};
366 struct labibb_desc *labibb;
367 int display_type = 0;
368
369 labibb = pinfo->labibb;
370
371 if (labibb)
372 display_type = labibb->amoled_panel;
373
374 config.display_type = display_type;
375 config.lab_init_volt = 4600000; /* fixed, see pmi register */
376 config.ibb_init_volt = 1400000; /* fixed, see pmi register */
377
378 if (labibb && labibb->force_config) {
379 config.lab_min_volt = labibb->lab_min_volt;
380 config.lab_max_volt = labibb->lab_max_volt;
381 config.ibb_min_volt = labibb->ibb_min_volt;
382 config.ibb_max_volt = labibb->ibb_max_volt;
383 config.pwr_up_delay = labibb->pwr_up_delay;
384 config.pwr_down_delay = labibb->pwr_down_delay;
385 config.ibb_discharge_en = labibb->ibb_discharge_en;
386 } else {
387 /* default */
388 config.pwr_up_delay = 3;
389 config.pwr_down_delay = 3;
390 config.ibb_discharge_en = 1;
391 if (display_type) { /* amoled */
392 config.lab_min_volt = 4600000;
393 config.lab_max_volt = 4600000;
394 config.ibb_min_volt = 4000000;
395 config.ibb_max_volt = 4000000;
396 } else { /* lcd */
397 config.lab_min_volt = 5500000;
398 config.lab_max_volt = 5500000;
399 config.ibb_min_volt = 5500000;
400 config.ibb_max_volt = 5500000;
401 }
402 }
403
404 dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d %d %d\n", __func__,
405 config.display_type,
406 config.lab_min_volt, config.lab_max_volt,
407 config.ibb_min_volt, config.ibb_max_volt,
408 config.lab_init_volt, config.ibb_init_volt,
409 config.pwr_up_delay, config.pwr_down_delay,
410 config.ibb_discharge_en);
411
412
413 /* QPNP WLED init for display backlight */
414 pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID);
415
416 qpnp_wled_init(&config);
417}
418
419int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo)
420{
421 uint32_t val = BIT(1) | BIT(13) | BIT(27);
422
423 if (enable) {
424 regulator_enable(val);
425 mdelay(10);
426 wled_init(pinfo);
427 qpnp_ibb_enable(true); /* +5V and -5V */
Dhaval Patel77d06852015-08-04 11:00:01 -0700428 mdelay(20);
Dhaval Patelb95039c2015-03-16 11:14:06 -0700429
430 if (pinfo->lcd_reg_en)
431 lcd_reg_enable();
432 } else {
433 if (pinfo->lcd_reg_en)
434 lcd_reg_disable();
435
436 regulator_disable(val);
437 }
438
439 return NO_ERROR;
440}
441
442int target_display_pre_on()
443{
444 writel(0xC0000CCC, MDP_CLK_CTRL0);
445 writel(0xC0000CCC, MDP_CLK_CTRL1);
446 writel(0x00CCCCCC, MDP_CLK_CTRL2);
447 writel(0x000000CC, MDP_CLK_CTRL6);
448 writel(0x0CCCC0C0, MDP_CLK_CTRL3);
449 writel(0xCCCCC0C0, MDP_CLK_CTRL4);
450 writel(0xCCCCC0C0, MDP_CLK_CTRL5);
451 writel(0x00CCC000, MDP_CLK_CTRL7);
452
453 return NO_ERROR;
454}
455
456int target_dsi_phy_config(struct mdss_dsi_phy_ctrl *phy_db)
457{
458 memcpy(phy_db->strength, panel_strength_ctrl, STRENGTH_SIZE_IN_BYTES_8996 *
459 sizeof(uint32_t));
460 memcpy(phy_db->regulator, panel_regulator_settings,
461 REGULATOR_SIZE_IN_BYTES_8996 * sizeof(uint32_t));
462 memcpy(phy_db->laneCfg, panel_lane_config, LANE_SIZE_IN_BYTES_8996);
463 return NO_ERROR;
464}
465
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530466bool target_display_panel_node(char *pbuf, uint16_t buf_size)
Dhaval Patelb95039c2015-03-16 11:14:06 -0700467{
468 int prefix_string_len = strlen(DISPLAY_CMDLINE_PREFIX);
469 bool ret = true;
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530470 struct oem_panel_data oem = mdss_dsi_get_oem_data();
Dhaval Patelb95039c2015-03-16 11:14:06 -0700471
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530472 if (!strcmp(oem.panel, HDMI_PANEL_NAME)) {
Dhaval Patelb95039c2015-03-16 11:14:06 -0700473 if (buf_size < (prefix_string_len + LK_OVERRIDE_PANEL_LEN +
474 strlen(HDMI_CONTROLLER_STRING))) {
475 dprintf(CRITICAL, "command line argument is greater than buffer size\n");
476 return false;
477 }
478
479 strlcpy(pbuf, DISPLAY_CMDLINE_PREFIX, buf_size);
480 buf_size -= prefix_string_len;
481 strlcat(pbuf, LK_OVERRIDE_PANEL, buf_size);
482 buf_size -= LK_OVERRIDE_PANEL_LEN;
483 strlcat(pbuf, HDMI_CONTROLLER_STRING, buf_size);
484 } else {
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530485 ret = gcdb_display_cmdline_arg(pbuf, buf_size);
Dhaval Patelb95039c2015-03-16 11:14:06 -0700486 }
487
488 return ret;
489}
490
491void target_display_init(const char *panel_name)
492{
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530493 struct oem_panel_data oem;
Dhaval Patelb95039c2015-03-16 11:14:06 -0700494
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530495 set_panel_cmd_string(panel_name);
496 oem = mdss_dsi_get_oem_data();
497 if (!strcmp(oem.panel, NO_PANEL_CONFIG)
498 || !strcmp(oem.panel, SIM_VIDEO_PANEL)
499 || !strcmp(oem.panel, SIM_DUALDSI_VIDEO_PANEL)
500 || !strcmp(oem.panel, SIM_CMD_PANEL)
501 || !strcmp(oem.panel, SIM_DUALDSI_CMD_PANEL)
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530502 || oem.skip) {
Dhaval Patelb95039c2015-03-16 11:14:06 -0700503 dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n",
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530504 oem.panel);
Dhaval Patelb95039c2015-03-16 11:14:06 -0700505 return;
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530506 } else if (!strcmp(oem.panel, HDMI_PANEL_NAME)) {
Dhaval Patelb95039c2015-03-16 11:14:06 -0700507 return;
508 }
509
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530510 if (gcdb_display_init(oem.panel, MDP_REV_50, (void *)MIPI_FB_ADDR)) {
Dhaval Patelb95039c2015-03-16 11:14:06 -0700511 target_force_cont_splash_disable(true);
512 msm_display_off();
513 }
514
Padmanabhan Komandurubccbcdc2015-06-30 16:19:24 +0530515 if (!oem.cont_splash) {
Dhaval Patelb95039c2015-03-16 11:14:06 -0700516 dprintf(INFO, "Forcing continuous splash disable\n");
517 target_force_cont_splash_disable(true);
518 }
519}
520
521void target_display_shutdown(void)
522{
523 gcdb_display_shutdown();
524}