Padmanabhan Komanduru | cd5645e | 2014-03-25 20:34:18 +0530 | [diff] [blame^] | 1 | /* Copyright (c) 2013-2014, 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 <smem.h> |
| 32 | #include <err.h> |
| 33 | #include <msm_panel.h> |
| 34 | #include <mipi_dsi.h> |
| 35 | #include <pm8x41.h> |
| 36 | #include <pm8x41_wled.h> |
| 37 | #include <board.h> |
| 38 | #include <mdp5.h> |
| 39 | #include <scm.h> |
| 40 | #include <platform/gpio.h> |
| 41 | #include <platform/iomap.h> |
| 42 | #include <target/display.h> |
| 43 | |
| 44 | #include "include/panel.h" |
| 45 | #include "include/display_resource.h" |
| 46 | |
| 47 | #define GPIO_STATE_LOW 0 |
| 48 | #define GPIO_STATE_HIGH 2 |
| 49 | #define RESET_GPIO_SEQ_LEN 3 |
| 50 | #define PWM_DUTY_US 13 |
| 51 | #define PWM_PERIOD_US 27 |
| 52 | |
| 53 | static uint32_t dsi_pll_enable_seq_m(uint32_t pll_base) |
| 54 | { |
| 55 | uint32_t i = 0; |
| 56 | uint32_t pll_locked = 0; |
| 57 | |
| 58 | mdss_dsi_uniphy_pll_sw_reset(pll_base); |
| 59 | |
| 60 | /* |
| 61 | * Add hardware recommended delays between register writes for |
| 62 | * the updates to take effect. These delays are necessary for the |
| 63 | * PLL to successfully lock |
| 64 | */ |
| 65 | writel(0x01, pll_base + 0x0020); /* GLB CFG */ |
| 66 | udelay(200); |
| 67 | writel(0x05, pll_base + 0x0020); /* GLB CFG */ |
| 68 | udelay(200); |
| 69 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 70 | udelay(1000); |
| 71 | |
| 72 | mdss_dsi_uniphy_pll_lock_detect_setting(pll_base); |
| 73 | pll_locked = readl(pll_base + 0x00c0) & 0x01; |
| 74 | for (i = 0; (i < 4) && !pll_locked; i++) { |
| 75 | writel(0x07, pll_base + 0x0020); /* GLB CFG */ |
| 76 | if (i != 0) |
| 77 | writel(0x34, pll_base + 0x00070); /* CAL CFG1*/ |
| 78 | udelay(1); |
| 79 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 80 | udelay(1000); |
| 81 | mdss_dsi_uniphy_pll_lock_detect_setting(pll_base); |
| 82 | pll_locked = readl(pll_base + 0x00c0) & 0x01; |
| 83 | } |
| 84 | |
| 85 | return pll_locked; |
| 86 | } |
| 87 | |
| 88 | static uint32_t dsi_pll_enable_seq_d(uint32_t pll_base) |
| 89 | { |
| 90 | uint32_t pll_locked = 0; |
| 91 | |
| 92 | mdss_dsi_uniphy_pll_sw_reset(pll_base); |
| 93 | |
| 94 | /* |
| 95 | * Add hardware recommended delays between register writes for |
| 96 | * the updates to take effect. These delays are necessary for the |
| 97 | * PLL to successfully lock |
| 98 | */ |
| 99 | writel(0x01, pll_base + 0x0020); /* GLB CFG */ |
| 100 | udelay(200); |
| 101 | writel(0x05, pll_base + 0x0020); /* GLB CFG */ |
| 102 | udelay(200); |
| 103 | writel(0x07, pll_base + 0x0020); /* GLB CFG */ |
| 104 | udelay(200); |
| 105 | writel(0x05, pll_base + 0x0020); /* GLB CFG */ |
| 106 | udelay(200); |
| 107 | writel(0x07, pll_base + 0x0020); /* GLB CFG */ |
| 108 | udelay(200); |
| 109 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 110 | udelay(1000); |
| 111 | |
| 112 | mdss_dsi_uniphy_pll_lock_detect_setting(pll_base); |
| 113 | pll_locked = readl(pll_base + 0x00c0) & 0x01; |
| 114 | |
| 115 | return pll_locked; |
| 116 | } |
| 117 | |
| 118 | static uint32_t dsi_pll_enable_seq_f1(uint32_t pll_base) |
| 119 | { |
| 120 | uint32_t pll_locked = 0; |
| 121 | |
| 122 | mdss_dsi_uniphy_pll_sw_reset(pll_base); |
| 123 | |
| 124 | /* |
| 125 | * Add hardware recommended delays between register writes for |
| 126 | * the updates to take effect. These delays are necessary for the |
| 127 | * PLL to successfully lock |
| 128 | */ |
| 129 | writel(0x01, pll_base + 0x0020); /* GLB CFG */ |
| 130 | udelay(200); |
| 131 | writel(0x05, pll_base + 0x0020); /* GLB CFG */ |
| 132 | udelay(200); |
| 133 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 134 | udelay(200); |
| 135 | writel(0x0d, pll_base + 0x0020); /* GLB CFG */ |
| 136 | udelay(200); |
| 137 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 138 | udelay(1000); |
| 139 | |
| 140 | mdss_dsi_uniphy_pll_lock_detect_setting(pll_base); |
| 141 | pll_locked = readl(pll_base + 0x00c0) & 0x01; |
| 142 | |
| 143 | return pll_locked; |
| 144 | } |
| 145 | |
| 146 | static uint32_t dsi_pll_enable_seq_c(uint32_t pll_base) |
| 147 | { |
| 148 | uint32_t pll_locked = 0; |
| 149 | |
| 150 | mdss_dsi_uniphy_pll_sw_reset(pll_base); |
| 151 | |
| 152 | /* |
| 153 | * Add hardware recommended delays between register writes for |
| 154 | * the updates to take effect. These delays are necessary for the |
| 155 | * PLL to successfully lock |
| 156 | */ |
| 157 | writel(0x01, pll_base + 0x0020); /* GLB CFG */ |
| 158 | udelay(200); |
| 159 | writel(0x05, pll_base + 0x0020); /* GLB CFG */ |
| 160 | udelay(200); |
| 161 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 162 | udelay(1000); |
| 163 | |
| 164 | mdss_dsi_uniphy_pll_lock_detect_setting(pll_base); |
| 165 | pll_locked = readl(pll_base + 0x00c0) & 0x01; |
| 166 | |
| 167 | return pll_locked; |
| 168 | } |
| 169 | |
| 170 | static uint32_t dsi_pll_enable_seq_e(uint32_t pll_base) |
| 171 | { |
| 172 | uint32_t pll_locked = 0; |
| 173 | |
| 174 | mdss_dsi_uniphy_pll_sw_reset(pll_base); |
| 175 | |
| 176 | /* |
| 177 | * Add hardware recommended delays between register writes for |
| 178 | * the updates to take effect. These delays are necessary for the |
| 179 | * PLL to successfully lock |
| 180 | */ |
| 181 | writel(0x01, pll_base + 0x0020); /* GLB CFG */ |
| 182 | udelay(200); |
| 183 | writel(0x05, pll_base + 0x0020); /* GLB CFG */ |
| 184 | udelay(200); |
| 185 | writel(0x0d, pll_base + 0x0020); /* GLB CFG */ |
| 186 | udelay(1); |
| 187 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 188 | udelay(1000); |
| 189 | |
| 190 | mdss_dsi_uniphy_pll_lock_detect_setting(pll_base); |
| 191 | pll_locked = readl(pll_base + 0x00c0) & 0x01; |
| 192 | |
| 193 | return pll_locked; |
| 194 | } |
| 195 | |
| 196 | int target_backlight_ctrl(struct backlight *bl, uint8_t enable) |
| 197 | { |
| 198 | struct pm8x41_mpp mpp; |
| 199 | int rc; |
| 200 | |
| 201 | mpp.base = PM8x41_MMP4_BASE; |
| 202 | mpp.vin = MPP_VIN0; |
| 203 | if (enable) { |
| 204 | pm_pwm_enable(false); |
| 205 | rc = pm_pwm_config(PWM_DUTY_US, PWM_PERIOD_US); |
| 206 | if (rc < 0) |
| 207 | mpp.mode = MPP_HIGH; |
| 208 | else { |
| 209 | mpp.mode = MPP_DTEST1; |
| 210 | pm_pwm_enable(true); |
| 211 | } |
| 212 | pm8x41_config_output_mpp(&mpp); |
| 213 | pm8x41_enable_mpp(&mpp, MPP_ENABLE); |
| 214 | } else { |
| 215 | pm_pwm_enable(false); |
| 216 | pm8x41_enable_mpp(&mpp, MPP_DISABLE); |
| 217 | } |
| 218 | mdelay(20); |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | static void dsi_pll_enable_seq(uint32_t pll_base) |
| 223 | { |
| 224 | if (dsi_pll_enable_seq_m(pll_base)) { |
| 225 | } else if (dsi_pll_enable_seq_d(pll_base)) { |
| 226 | } else if (dsi_pll_enable_seq_d(pll_base)) { |
| 227 | } else if (dsi_pll_enable_seq_f1(pll_base)) { |
| 228 | } else if (dsi_pll_enable_seq_c(pll_base)) { |
| 229 | } else if (dsi_pll_enable_seq_e(pll_base)) { |
| 230 | } else { |
| 231 | dprintf(CRITICAL, "Not able to enable the pll\n"); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo) |
| 236 | { |
| 237 | int32_t ret = 0; |
| 238 | struct mdss_dsi_pll_config *pll_data; |
| 239 | dprintf(SPEW, "target_panel_clock\n"); |
| 240 | |
| 241 | pll_data = pinfo->mipi.dsi_pll_config; |
| 242 | |
| 243 | if (enable) { |
| 244 | mdp_gdsc_ctrl(enable); |
| 245 | mdss_bus_clocks_enable(); |
| 246 | mdp_clock_enable(); |
| 247 | ret = restore_secure_cfg(SECURE_DEVICE_MDSS); |
| 248 | if (ret) { |
| 249 | dprintf(CRITICAL, |
| 250 | "%s: Failed to restore MDP security configs", |
| 251 | __func__); |
| 252 | mdp_clock_disable(); |
| 253 | mdss_bus_clocks_disable(); |
| 254 | mdp_gdsc_ctrl(0); |
| 255 | return ret; |
| 256 | } |
| 257 | mdss_dsi_auto_pll_config(DSI0_PLL_BASE, |
| 258 | MIPI_DSI0_BASE, pll_data); |
| 259 | dsi_pll_enable_seq(DSI0_PLL_BASE); |
| 260 | gcc_dsi_clocks_enable(pll_data->pclk_m, |
| 261 | pll_data->pclk_n, |
| 262 | pll_data->pclk_d); |
| 263 | } else if(!target_cont_splash_screen()) { |
| 264 | gcc_dsi_clocks_disable(); |
| 265 | mdp_clock_disable(); |
| 266 | mdss_bus_clocks_disable(); |
| 267 | mdp_gdsc_ctrl(enable); |
| 268 | } |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq, |
| 274 | struct msm_panel_info *pinfo) |
| 275 | { |
| 276 | int ret = NO_ERROR; |
| 277 | if (enable) { |
| 278 | if (pinfo->mipi.use_enable_gpio) { |
| 279 | gpio_tlmm_config(enable_gpio.pin_id, 0, |
| 280 | enable_gpio.pin_direction, enable_gpio.pin_pull, |
| 281 | enable_gpio.pin_strength, |
| 282 | enable_gpio.pin_state); |
| 283 | |
| 284 | gpio_set_dir(enable_gpio.pin_id, 2); |
| 285 | } |
| 286 | |
| 287 | gpio_tlmm_config(bkl_gpio.pin_id, 0, |
| 288 | bkl_gpio.pin_direction, bkl_gpio.pin_pull, |
| 289 | bkl_gpio.pin_strength, bkl_gpio.pin_state); |
| 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 | int target_ldo_ctrl(uint8_t enable) |
| 316 | { |
| 317 | uint32_t ret = NO_ERROR; |
| 318 | uint32_t ldocounter = 0; |
| 319 | uint32_t pm8x41_ldo_base = 0x13F00; |
| 320 | |
| 321 | while (ldocounter < TOTAL_LDO_DEFINED) { |
| 322 | dprintf(SPEW, "Setting %i\n", |
| 323 | ldo_entry_array[ldocounter].ldo_id); |
| 324 | struct pm8x41_ldo ldo_entry = LDO((pm8x41_ldo_base + |
| 325 | 0x100 * ldo_entry_array[ldocounter].ldo_id), |
| 326 | ldo_entry_array[ldocounter].ldo_type); |
| 327 | |
| 328 | |
| 329 | /* Set voltage during power on */ |
| 330 | if (enable) { |
| 331 | /* TODO: Set the LDO voltage before enabling it */ |
| 332 | pm8x41_ldo_control(&ldo_entry, enable); |
| 333 | |
| 334 | } else if(!target_cont_splash_screen()) { |
| 335 | pm8x41_ldo_control(&ldo_entry, enable); |
| 336 | } |
| 337 | ldocounter++; |
| 338 | } |
| 339 | |
| 340 | return ret; |
| 341 | } |
| 342 | |
| 343 | bool target_display_panel_node(char *panel_name, char *pbuf, uint16_t buf_size) |
| 344 | { |
| 345 | return gcdb_display_cmdline_arg(pbuf, buf_size); |
| 346 | } |
| 347 | |
| 348 | void target_display_init(const char *panel_name) |
| 349 | { |
| 350 | uint32_t ret = 0; |
| 351 | ret = gcdb_display_init(panel_name, MDP_REV_50, MIPI_FB_ADDR); |
| 352 | if (ret) { |
| 353 | msm_display_off(); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | void target_display_shutdown(void) |
| 358 | { |
| 359 | gcdb_display_shutdown(); |
| 360 | } |