Padmanabhan Komanduru | 9d49f89 | 2015-04-10 12:58:46 -0700 | [diff] [blame] | 1 | /* 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 | /*---------------------------------------------------------------------------*/ |
| 56 | static struct gpio_pin reset_gpio = { |
| 57 | "msmgpio", 0, 3, 1, 0, 1 |
| 58 | }; |
| 59 | |
| 60 | static struct gpio_pin enable_gpio = { |
| 61 | "msmgpio", 90, 3, 1, 0, 1 |
| 62 | }; |
| 63 | |
| 64 | static 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 | |
Padmanabhan Komanduru | b338193 | 2015-06-15 22:14:02 +0530 | [diff] [blame^] | 74 | #define DSI0_BASE_ADJUST -0x4000 |
| 75 | #define DSI0_PHY_BASE_ADJUST -0x4100 |
| 76 | #define DSI0_PHY_PLL_BASE_ADJUST -0x3900 |
| 77 | #define DSI0_PHY_REGULATOR_BASE_ADJUST -0x3C00 |
| 78 | |
Padmanabhan Komanduru | 9d49f89 | 2015-04-10 12:58:46 -0700 | [diff] [blame] | 79 | static void mdss_dsi_uniphy_pll_sw_reset_8952(uint32_t pll_base) |
| 80 | { |
| 81 | writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */ |
| 82 | mdelay(1); |
| 83 | writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */ |
| 84 | mdelay(1); |
| 85 | } |
| 86 | |
| 87 | static void dsi_pll_toggle_lock_detect_8952(uint32_t pll_base) |
| 88 | { |
| 89 | writel(0x04, pll_base + 0x0064); /* LKDetect CFG2 */ |
| 90 | udelay(1); |
| 91 | writel(0x05, pll_base + 0x0064); /* LKDetect CFG2 */ |
| 92 | udelay(512); |
| 93 | } |
| 94 | |
| 95 | static void dsi_pll_sw_reset_8952(uint32_t pll_base) |
| 96 | { |
| 97 | writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */ |
| 98 | udelay(1); |
| 99 | writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */ |
| 100 | } |
| 101 | |
| 102 | static uint32_t gf_1_dsi_pll_enable_sequence_8952(uint32_t pll_base) |
| 103 | { |
| 104 | uint32_t rc; |
| 105 | |
| 106 | dsi_pll_sw_reset_8952(pll_base); |
| 107 | |
| 108 | /* |
| 109 | * Add hardware recommended delays between register writes for |
| 110 | * the updates to take effect. These delays are necessary for the |
| 111 | * PLL to successfully lock |
| 112 | */ |
| 113 | writel(0x14, pll_base + 0x0070); /* CAL CFG1*/ |
| 114 | writel(0x01, pll_base + 0x0020); /* GLB CFG */ |
| 115 | writel(0x05, pll_base + 0x0020); /* GLB CFG */ |
| 116 | udelay(3); |
| 117 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 118 | udelay(500); |
| 119 | |
| 120 | dsi_pll_toggle_lock_detect_8952(pll_base); |
| 121 | rc = readl(pll_base + 0x00c0) & 0x01; |
| 122 | |
| 123 | return rc; |
| 124 | } |
| 125 | |
| 126 | static uint32_t gf_2_dsi_pll_enable_sequence_8952(uint32_t pll_base) |
| 127 | { |
| 128 | uint32_t rc; |
| 129 | |
| 130 | dsi_pll_sw_reset_8952(pll_base); |
| 131 | |
| 132 | /* |
| 133 | * Add hardware recommended delays between register writes for |
| 134 | * the updates to take effect. These delays are necessary for the |
| 135 | * PLL to successfully lock |
| 136 | */ |
| 137 | writel(0x04, pll_base + 0x0070); /* CAL CFG1*/ |
| 138 | writel(0x01, pll_base + 0x0020); /* GLB CFG */ |
| 139 | writel(0x05, pll_base + 0x0020); /* GLB CFG */ |
| 140 | udelay(3); |
| 141 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 142 | udelay(500); |
| 143 | |
| 144 | dsi_pll_toggle_lock_detect_8952(pll_base); |
| 145 | rc = readl(pll_base + 0x00c0) & 0x01; |
| 146 | |
| 147 | return rc; |
| 148 | } |
| 149 | |
| 150 | static uint32_t tsmc_dsi_pll_enable_sequence_8952(uint32_t pll_base) |
| 151 | { |
| 152 | uint32_t rc; |
| 153 | |
| 154 | dsi_pll_sw_reset_8952(pll_base); |
| 155 | /* |
| 156 | * Add hardware recommended delays between register writes for |
| 157 | * the updates to take effect. These delays are necessary for the |
| 158 | * PLL to successfully lock |
| 159 | */ |
| 160 | |
| 161 | writel(0x34, pll_base + 0x0070); /* CAL CFG1*/ |
| 162 | writel(0x01, pll_base + 0x0020); /* GLB CFG */ |
| 163 | writel(0x05, pll_base + 0x0020); /* GLB CFG */ |
| 164 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 165 | udelay(500); |
| 166 | |
| 167 | dsi_pll_toggle_lock_detect_8952(pll_base); |
| 168 | rc = readl(pll_base + 0x00c0) & 0x01; |
| 169 | |
| 170 | return rc; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | static uint32_t dsi_pll_enable_seq_8952(uint32_t pll_base) |
| 175 | { |
| 176 | uint32_t pll_locked = 0; |
| 177 | uint32_t counter = 0; |
| 178 | |
| 179 | do { |
| 180 | pll_locked = tsmc_dsi_pll_enable_sequence_8952(pll_base); |
| 181 | |
| 182 | dprintf(SPEW, "TSMC pll locked status is %d\n", pll_locked); |
| 183 | ++counter; |
| 184 | } while (!pll_locked && (counter < 3)); |
| 185 | |
| 186 | if(!pll_locked) { |
| 187 | counter = 0; |
| 188 | do { |
| 189 | pll_locked = gf_1_dsi_pll_enable_sequence_8952(pll_base); |
| 190 | |
| 191 | dprintf(SPEW, "GF P1 pll locked status is %d\n", pll_locked); |
| 192 | ++counter; |
| 193 | } while (!pll_locked && (counter < 3)); |
| 194 | } |
| 195 | |
| 196 | if(!pll_locked) { |
| 197 | counter = 0; |
| 198 | do { |
| 199 | pll_locked = gf_2_dsi_pll_enable_sequence_8952(pll_base); |
| 200 | |
| 201 | dprintf(SPEW, "GF P2 pll locked status is %d\n", pll_locked); |
| 202 | ++counter; |
| 203 | } while (!pll_locked && (counter < 3)); |
| 204 | } |
| 205 | |
| 206 | return pll_locked; |
| 207 | } |
| 208 | |
| 209 | static int msm8952_wled_backlight_ctrl(uint8_t enable) |
| 210 | { |
| 211 | uint8_t slave_id = PMIC_WLED_SLAVE_ID; /* pmi */ |
| 212 | |
| 213 | pm8x41_wled_config_slave_id(slave_id); |
| 214 | qpnp_wled_enable_backlight(enable); |
| 215 | qpnp_ibb_enable(enable); |
| 216 | return NO_ERROR; |
| 217 | } |
| 218 | |
| 219 | int target_backlight_ctrl(struct backlight *bl, uint8_t enable) |
| 220 | { |
| 221 | uint32_t ret = NO_ERROR; |
| 222 | |
| 223 | if (bl->bl_interface_type == BL_DCS) |
| 224 | return ret; |
| 225 | |
| 226 | ret = msm8952_wled_backlight_ctrl(enable); |
| 227 | |
| 228 | return ret; |
| 229 | } |
| 230 | |
| 231 | int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo) |
| 232 | { |
| 233 | int32_t ret = 0; |
| 234 | struct mdss_dsi_pll_config *pll_data; |
| 235 | dprintf(SPEW, "target_panel_clock\n"); |
| 236 | |
| 237 | pll_data = pinfo->mipi.dsi_pll_config; |
| 238 | pll_data->vco_delay = VCO_DELAY_USEC; |
| 239 | |
| 240 | if (enable) { |
| 241 | mdp_gdsc_ctrl(enable); |
| 242 | mdss_bus_clocks_enable(); |
| 243 | mdp_clock_enable(); |
| 244 | ret = restore_secure_cfg(SECURE_DEVICE_MDSS); |
| 245 | if (ret) { |
| 246 | dprintf(CRITICAL, |
| 247 | "%s: Failed to restore MDP security configs", |
| 248 | __func__); |
| 249 | mdp_clock_disable(); |
| 250 | mdss_bus_clocks_disable(); |
| 251 | mdp_gdsc_ctrl(0); |
| 252 | return ret; |
| 253 | } |
Padmanabhan Komanduru | c0766c8 | 2015-04-27 16:39:15 -0700 | [diff] [blame] | 254 | mdss_dsi_uniphy_pll_sw_reset_8952(pinfo->mipi.pll_base); |
| 255 | mdss_dsi_auto_pll_config(pinfo->mipi.pll_base, |
Padmanabhan Komanduru | 9d49f89 | 2015-04-10 12:58:46 -0700 | [diff] [blame] | 256 | pinfo->mipi.ctl_base, pll_data); |
Padmanabhan Komanduru | c0766c8 | 2015-04-27 16:39:15 -0700 | [diff] [blame] | 257 | if (!dsi_pll_enable_seq_8952(pinfo->mipi.pll_base)) |
Padmanabhan Komanduru | 9d49f89 | 2015-04-10 12:58:46 -0700 | [diff] [blame] | 258 | dprintf(CRITICAL, "Not able to enable the pll\n"); |
| 259 | gcc_dsi_clocks_enable(pll_data->pclk_m, pll_data->pclk_n, |
| 260 | pll_data->pclk_d); |
| 261 | } else if(!target_cont_splash_screen()) { |
| 262 | gcc_dsi_clocks_disable(); |
| 263 | mdp_clock_disable(); |
| 264 | mdss_bus_clocks_disable(); |
| 265 | mdp_gdsc_ctrl(enable); |
| 266 | } |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq, |
| 272 | struct msm_panel_info *pinfo) |
| 273 | { |
| 274 | int ret = NO_ERROR; |
| 275 | |
| 276 | if (enable) { |
| 277 | if (pinfo->mipi.use_enable_gpio) { |
| 278 | gpio_tlmm_config(enable_gpio.pin_id, 0, |
| 279 | enable_gpio.pin_direction, enable_gpio.pin_pull, |
| 280 | enable_gpio.pin_strength, |
| 281 | enable_gpio.pin_state); |
| 282 | |
| 283 | gpio_set_dir(enable_gpio.pin_id, 2); |
| 284 | } |
| 285 | |
| 286 | gpio_tlmm_config(bkl_gpio.pin_id, 0, |
| 287 | bkl_gpio.pin_direction, bkl_gpio.pin_pull, |
| 288 | bkl_gpio.pin_strength, bkl_gpio.pin_state); |
| 289 | |
| 290 | gpio_set_dir(bkl_gpio.pin_id, 2); |
| 291 | |
| 292 | gpio_tlmm_config(reset_gpio.pin_id, 0, |
| 293 | reset_gpio.pin_direction, reset_gpio.pin_pull, |
| 294 | reset_gpio.pin_strength, reset_gpio.pin_state); |
| 295 | |
| 296 | gpio_set_dir(reset_gpio.pin_id, 2); |
| 297 | |
| 298 | /* reset */ |
| 299 | for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) { |
| 300 | if (resetseq->pin_state[i] == GPIO_STATE_LOW) |
| 301 | gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_LOW); |
| 302 | else |
| 303 | gpio_set_dir(reset_gpio.pin_id, GPIO_STATE_HIGH); |
| 304 | mdelay(resetseq->sleep[i]); |
| 305 | } |
| 306 | } else if(!target_cont_splash_screen()) { |
| 307 | gpio_set_dir(reset_gpio.pin_id, 0); |
| 308 | if (pinfo->mipi.use_enable_gpio) |
| 309 | gpio_set_dir(enable_gpio.pin_id, 0); |
| 310 | } |
| 311 | |
| 312 | return ret; |
| 313 | } |
| 314 | |
| 315 | static void wled_init(struct msm_panel_info *pinfo) |
| 316 | { |
| 317 | struct qpnp_wled_config_data config = {0}; |
| 318 | struct labibb_desc *labibb; |
| 319 | int display_type = 0; |
| 320 | |
| 321 | labibb = pinfo->labibb; |
| 322 | |
| 323 | if (labibb) |
| 324 | display_type = labibb->amoled_panel; |
| 325 | |
| 326 | config.display_type = display_type; |
| 327 | config.lab_init_volt = 4600000; /* fixed, see pmi register */ |
| 328 | config.ibb_init_volt = 1400000; /* fixed, see pmi register */ |
| 329 | |
| 330 | if (labibb && labibb->force_config) { |
| 331 | config.lab_min_volt = labibb->lab_min_volt; |
| 332 | config.lab_max_volt = labibb->lab_max_volt; |
| 333 | config.ibb_min_volt = labibb->ibb_min_volt; |
| 334 | config.ibb_max_volt = labibb->ibb_max_volt; |
| 335 | config.pwr_up_delay = labibb->pwr_up_delay; |
| 336 | config.pwr_down_delay = labibb->pwr_down_delay; |
| 337 | config.ibb_discharge_en = labibb->ibb_discharge_en; |
| 338 | } else { |
| 339 | /* default */ |
| 340 | config.pwr_up_delay = 3; |
| 341 | config.pwr_down_delay = 3; |
| 342 | config.ibb_discharge_en = 1; |
| 343 | if (display_type) { /* amoled */ |
| 344 | config.lab_min_volt = 4600000; |
| 345 | config.lab_max_volt = 4600000; |
| 346 | config.ibb_min_volt = 4000000; |
| 347 | config.ibb_max_volt = 4000000; |
| 348 | } else { /* lcd */ |
| 349 | config.lab_min_volt = 5500000; |
| 350 | config.lab_max_volt = 5500000; |
| 351 | config.ibb_min_volt = 5500000; |
| 352 | config.ibb_max_volt = 5500000; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | dprintf(SPEW, "%s: %d %d %d %d %d %d %d %d %d %d\n", __func__, |
| 357 | config.display_type, |
| 358 | config.lab_min_volt, config.lab_max_volt, |
| 359 | config.ibb_min_volt, config.ibb_max_volt, |
| 360 | config.lab_init_volt, config.ibb_init_volt, |
| 361 | config.pwr_up_delay, config.pwr_down_delay, |
| 362 | config.ibb_discharge_en); |
| 363 | |
| 364 | /* QPNP WLED init for display backlight */ |
| 365 | pm8x41_wled_config_slave_id(PMIC_WLED_SLAVE_ID); |
| 366 | |
| 367 | qpnp_wled_init(&config); |
| 368 | } |
| 369 | |
Dhaval Patel | 7709c41 | 2015-05-12 10:09:41 -0700 | [diff] [blame] | 370 | int target_dsi_phy_config(struct mdss_dsi_phy_ctrl *phy_db) |
| 371 | { |
| 372 | memcpy(phy_db->regulator, panel_regulator_settings, REGULATOR_SIZE); |
| 373 | memcpy(phy_db->ctrl, panel_physical_ctrl, PHYSICAL_SIZE); |
| 374 | memcpy(phy_db->strength, panel_strength_ctrl, STRENGTH_SIZE); |
| 375 | memcpy(phy_db->bistCtrl, panel_bist_ctrl, BIST_SIZE); |
| 376 | memcpy(phy_db->laneCfg, panel_lane_config, LANE_SIZE); |
| 377 | return NO_ERROR; |
| 378 | } |
| 379 | |
Padmanabhan Komanduru | b338193 | 2015-06-15 22:14:02 +0530 | [diff] [blame^] | 380 | int target_display_get_base_offset(uint32_t base) |
| 381 | { |
| 382 | if(platform_is_msm8956()) { |
| 383 | if (base == MIPI_DSI0_BASE) |
| 384 | return DSI0_BASE_ADJUST; |
| 385 | else if (base == DSI0_PHY_BASE) |
| 386 | return DSI0_PHY_BASE_ADJUST; |
| 387 | else if (base == DSI0_PLL_BASE) |
| 388 | return DSI0_PHY_PLL_BASE_ADJUST; |
| 389 | else if (base == DSI0_REGULATOR_BASE) |
| 390 | return DSI0_PHY_REGULATOR_BASE_ADJUST; |
| 391 | } |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
Padmanabhan Komanduru | 9d49f89 | 2015-04-10 12:58:46 -0700 | [diff] [blame] | 396 | int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo) |
| 397 | { |
| 398 | |
| 399 | if (enable) { |
| 400 | regulator_enable(REG_LDO2 | REG_LDO6 | REG_LDO17); |
| 401 | mdelay(10); |
| 402 | wled_init(pinfo); |
| 403 | qpnp_ibb_enable(true); /*5V boost*/ |
| 404 | mdelay(50); |
| 405 | } else { |
| 406 | regulator_disable(REG_LDO2 | REG_LDO6 | REG_LDO17); |
| 407 | } |
| 408 | |
| 409 | return NO_ERROR; |
| 410 | } |
| 411 | |
| 412 | bool target_display_panel_node(char *panel_name, char *pbuf, uint16_t buf_size) |
| 413 | { |
| 414 | return gcdb_display_cmdline_arg(panel_name, pbuf, buf_size); |
| 415 | } |
| 416 | |
| 417 | void target_display_init(const char *panel_name) |
| 418 | { |
| 419 | char cont_splash = '\0'; |
| 420 | |
| 421 | set_panel_cmd_string(panel_name, &cont_splash); |
| 422 | panel_name += strspn(panel_name, " "); |
| 423 | |
| 424 | if (!strcmp(panel_name, NO_PANEL_CONFIG) |
| 425 | || !strcmp(panel_name, SIM_VIDEO_PANEL) |
| 426 | || !strcmp(panel_name, SIM_CMD_PANEL)) { |
| 427 | dprintf(INFO, "Selected panel: %s\nSkip panel configuration\n", |
| 428 | panel_name); |
| 429 | return; |
| 430 | } |
| 431 | |
| 432 | if (gcdb_display_init(panel_name, MDP_REV_50, (void *)MIPI_FB_ADDR)) { |
| 433 | target_force_cont_splash_disable(true); |
| 434 | msm_display_off(); |
| 435 | } |
| 436 | |
| 437 | if (cont_splash == '0') { |
| 438 | dprintf(INFO, "Forcing continuous splash disable\n"); |
| 439 | target_force_cont_splash_disable(true); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | void target_display_shutdown(void) |
| 444 | { |
| 445 | gcdb_display_shutdown(); |
| 446 | } |