Sandeep Panda | ae8d68e | 2014-12-29 20:07:22 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 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> |
Shivaraj Shetty | af4c607 | 2014-11-04 16:25:31 +0530 | [diff] [blame] | 36 | #include <pm8x41_wled.h> |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 37 | #include <board.h> |
| 38 | #include <mdp3.h> |
| 39 | #include <scm.h> |
| 40 | #include <platform/gpio.h> |
| 41 | #include <platform/iomap.h> |
| 42 | #include <target/display.h> |
Casey Piper | d2af07b | 2015-04-01 18:01:58 -0700 | [diff] [blame^] | 43 | #include <regulator.h> |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 44 | |
| 45 | #include "include/panel.h" |
| 46 | #include "include/display_resource.h" |
Veera Sundaram Sankaran | 87f8813 | 2015-01-28 11:32:44 -0800 | [diff] [blame] | 47 | #include "gcdb_display.h" |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 48 | |
| 49 | #define VCO_DELAY_USEC 1000 |
| 50 | #define GPIO_STATE_LOW 0 |
| 51 | #define GPIO_STATE_HIGH 2 |
| 52 | #define RESET_GPIO_SEQ_LEN 3 |
| 53 | #define PWM_DUTY_US 13 |
| 54 | #define PWM_PERIOD_US 27 |
Shivaraj Shetty | 89fc8ed | 2015-01-23 15:03:35 +0530 | [diff] [blame] | 55 | #define PM8916_VER 0x20000 |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 56 | |
| 57 | static void mdss_dsi_uniphy_pll_sw_reset_8909(uint32_t pll_base) |
| 58 | { |
| 59 | writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */ |
| 60 | mdelay(1); |
| 61 | writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */ |
| 62 | mdelay(1); |
| 63 | } |
| 64 | |
| 65 | static uint32_t dsi_pll_enable_seq_8909(uint32_t pll_base) |
| 66 | { |
| 67 | uint32_t pll_locked = 0; |
| 68 | |
| 69 | writel(0x01, pll_base + 0x0068); /* PLL TEST CFG */ |
| 70 | udelay(1); |
| 71 | writel(0x00, pll_base + 0x0068); /* PLL TEST CFG */ |
| 72 | |
| 73 | /* |
| 74 | * Add hardware recommended delays between register writes for |
| 75 | * the updates to take effect. These delays are necessary for the |
| 76 | * PLL to successfully lock |
| 77 | */ |
| 78 | writel(0x34, pll_base + 0x0070); /* CAL CFG1*/ |
| 79 | udelay(1); |
| 80 | writel(0x01, pll_base + 0x0020); /* GLB CFG */ |
| 81 | udelay(1); |
| 82 | writel(0x05, pll_base + 0x0020); /* GLB CFG */ |
| 83 | udelay(1); |
| 84 | writel(0x0f, pll_base + 0x0020); /* GLB CFG */ |
| 85 | udelay(1); |
| 86 | |
| 87 | writel(0x04, pll_base + 0x0064); /* LKDetect CFG2 */ |
| 88 | udelay(1); |
| 89 | writel(0x05, pll_base + 0x0064); /* LKDetect CFG2 */ |
| 90 | udelay(512); |
| 91 | pll_locked = readl(pll_base + 0x00c0) & 0x01; |
| 92 | |
| 93 | return pll_locked; |
| 94 | } |
| 95 | |
| 96 | int target_backlight_ctrl(struct backlight *bl, uint8_t enable) |
| 97 | { |
| 98 | struct pm8x41_mpp mpp; |
Shivaraj Shetty | be6b6fd | 2014-12-12 13:48:29 +0530 | [diff] [blame] | 99 | uint32_t hw_id = board_hardware_id(); |
Shivaraj Shetty | 89fc8ed | 2015-01-23 15:03:35 +0530 | [diff] [blame] | 100 | struct board_pmic_data pmic_info; |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 101 | int rc; |
| 102 | |
| 103 | if (bl->bl_interface_type == BL_DCS) |
| 104 | return 0; |
| 105 | |
Shivaraj Shetty | 89fc8ed | 2015-01-23 15:03:35 +0530 | [diff] [blame] | 106 | board_pmic_info(&pmic_info, 1); |
| 107 | if (pmic_info.pmic_version == PM8916_VER) |
Shivaraj Shetty | be6b6fd | 2014-12-12 13:48:29 +0530 | [diff] [blame] | 108 | mpp.base = PM8x41_MMP4_BASE; |
| 109 | else |
| 110 | mpp.base = PM8x41_MMP2_BASE; |
| 111 | |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 112 | mpp.vin = MPP_VIN0; |
| 113 | if (enable) { |
| 114 | pm_pwm_enable(false); |
| 115 | rc = pm_pwm_config(PWM_DUTY_US, PWM_PERIOD_US); |
| 116 | if (rc < 0) |
| 117 | mpp.mode = MPP_HIGH; |
| 118 | else { |
| 119 | mpp.mode = MPP_DTEST1; |
| 120 | pm_pwm_enable(true); |
| 121 | } |
| 122 | pm8x41_config_output_mpp(&mpp); |
| 123 | pm8x41_enable_mpp(&mpp, MPP_ENABLE); |
| 124 | } else { |
| 125 | pm_pwm_enable(false); |
| 126 | pm8x41_enable_mpp(&mpp, MPP_DISABLE); |
| 127 | } |
| 128 | mdelay(20); |
Sandeep Panda | ae8d68e | 2014-12-29 20:07:22 +0530 | [diff] [blame] | 129 | |
| 130 | if (enable) { |
| 131 | gpio_tlmm_config(bkl_gpio.pin_id, 0, |
| 132 | bkl_gpio.pin_direction, bkl_gpio.pin_pull, |
| 133 | bkl_gpio.pin_strength, bkl_gpio.pin_state); |
| 134 | gpio_set(bkl_gpio.pin_id, 2); |
| 135 | } |
| 136 | |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo) |
| 141 | { |
| 142 | int32_t ret = 0; |
| 143 | struct mdss_dsi_pll_config *pll_data; |
| 144 | dprintf(SPEW, "target_panel_clock\n"); |
| 145 | |
| 146 | pll_data = pinfo->mipi.dsi_pll_config; |
| 147 | pll_data->vco_delay = VCO_DELAY_USEC; |
| 148 | |
| 149 | if (enable) { |
| 150 | mdp_gdsc_ctrl(enable); |
| 151 | mdss_bus_clocks_enable(); |
| 152 | mdp_clock_enable(); |
Shivaraj Shetty | af4c607 | 2014-11-04 16:25:31 +0530 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * Enable auto functional gating |
| 156 | * on DSI CMD AXI fetch from DDR |
| 157 | */ |
| 158 | writel(0x3ffff, MDP_CGC_EN); |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 159 | ret = restore_secure_cfg(SECURE_DEVICE_MDSS); |
| 160 | if (ret) { |
| 161 | dprintf(CRITICAL, |
| 162 | "%s: Failed to restore MDP security configs", |
| 163 | __func__); |
| 164 | mdp_clock_disable(); |
| 165 | mdss_bus_clocks_disable(); |
| 166 | mdp_gdsc_ctrl(0); |
| 167 | return ret; |
| 168 | } |
| 169 | mdss_dsi_uniphy_pll_sw_reset_8909(DSI0_PLL_BASE); |
Jeevan Shriram | 2d3500b | 2014-12-29 16:25:06 -0800 | [diff] [blame] | 170 | mdss_dsi_auto_pll_config(pinfo->mipi.pll_0_base, |
| 171 | pinfo->mipi.ctl_base, pll_data); |
| 172 | if (!dsi_pll_enable_seq_8909(pinfo->mipi.pll_0_base)) |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 173 | dprintf(CRITICAL, "Not able to enable the pll\n"); |
| 174 | gcc_dsi_clocks_enable(pll_data->pclk_m, |
| 175 | pll_data->pclk_n, |
| 176 | pll_data->pclk_d); |
| 177 | } else if(!target_cont_splash_screen()) { |
| 178 | gcc_dsi_clocks_disable(); |
| 179 | mdp_clock_disable(); |
| 180 | mdss_bus_clocks_disable(); |
| 181 | mdp_gdsc_ctrl(enable); |
| 182 | } |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq, |
| 188 | struct msm_panel_info *pinfo) |
| 189 | { |
| 190 | int ret = NO_ERROR; |
| 191 | uint32_t hw_id = board_hardware_id(); |
| 192 | uint32_t hw_subtype = board_hardware_subtype(); |
| 193 | |
| 194 | if (enable) { |
| 195 | if (pinfo->mipi.use_enable_gpio) { |
| 196 | gpio_tlmm_config(enable_gpio.pin_id, 0, |
| 197 | enable_gpio.pin_direction, enable_gpio.pin_pull, |
| 198 | enable_gpio.pin_strength, |
| 199 | enable_gpio.pin_state); |
| 200 | |
Shivaraj Shetty | af4c607 | 2014-11-04 16:25:31 +0530 | [diff] [blame] | 201 | gpio_set(enable_gpio.pin_id, 2); |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 202 | } |
| 203 | |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 204 | gpio_tlmm_config(reset_gpio.pin_id, 0, |
| 205 | reset_gpio.pin_direction, reset_gpio.pin_pull, |
| 206 | reset_gpio.pin_strength, reset_gpio.pin_state); |
| 207 | |
Shivaraj Shetty | af4c607 | 2014-11-04 16:25:31 +0530 | [diff] [blame] | 208 | gpio_set(reset_gpio.pin_id, 2); |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 209 | |
| 210 | /* reset */ |
| 211 | for (int i = 0; i < RESET_GPIO_SEQ_LEN; i++) { |
| 212 | if (resetseq->pin_state[i] == GPIO_STATE_LOW) |
Shivaraj Shetty | af4c607 | 2014-11-04 16:25:31 +0530 | [diff] [blame] | 213 | gpio_set(reset_gpio.pin_id, GPIO_STATE_LOW); |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 214 | else |
Shivaraj Shetty | af4c607 | 2014-11-04 16:25:31 +0530 | [diff] [blame] | 215 | gpio_set(reset_gpio.pin_id, GPIO_STATE_HIGH); |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 216 | mdelay(resetseq->sleep[i]); |
| 217 | } |
| 218 | } else if(!target_cont_splash_screen()) { |
Shivaraj Shetty | af4c607 | 2014-11-04 16:25:31 +0530 | [diff] [blame] | 219 | gpio_set(reset_gpio.pin_id, 0); |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 220 | if (pinfo->mipi.use_enable_gpio) |
Shivaraj Shetty | af4c607 | 2014-11-04 16:25:31 +0530 | [diff] [blame] | 221 | gpio_set(enable_gpio.pin_id, 0); |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | return ret; |
| 225 | } |
| 226 | |
Veera Sundaram Sankaran | 87f8813 | 2015-01-28 11:32:44 -0800 | [diff] [blame] | 227 | int target_ldo_ctrl(uint8_t enable, struct msm_panel_info *pinfo) |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 228 | { |
Shivaraj Shetty | 01734d3 | 2014-11-20 12:24:01 +0530 | [diff] [blame] | 229 | if (enable) |
Casey Piper | d2af07b | 2015-04-01 18:01:58 -0700 | [diff] [blame^] | 230 | regulator_enable(REG_LDO2 | REG_LDO6 | REG_LDO17); |
Shivaraj Shetty | 01734d3 | 2014-11-20 12:24:01 +0530 | [diff] [blame] | 231 | |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 232 | return NO_ERROR; |
| 233 | } |
| 234 | |
| 235 | bool target_display_panel_node(char *panel_name, char *pbuf, uint16_t buf_size) |
| 236 | { |
Shivaraj Shetty | af4c607 | 2014-11-04 16:25:31 +0530 | [diff] [blame] | 237 | return gcdb_display_cmdline_arg(panel_name, pbuf, buf_size); |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | void target_display_init(const char *panel_name) |
| 241 | { |
| 242 | uint32_t panel_loop = 0; |
| 243 | uint32_t ret = 0; |
Veera Sundaram Sankaran | 7868d54 | 2015-01-02 14:48:47 -0800 | [diff] [blame] | 244 | char cont_splash = '\0'; |
| 245 | |
| 246 | set_panel_cmd_string(panel_name, &cont_splash); |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 247 | |
Sandeep Panda | 63933f9 | 2014-11-26 19:13:44 +0530 | [diff] [blame] | 248 | panel_name += strspn(panel_name, " "); |
| 249 | if (!strcmp(panel_name, NO_PANEL_CONFIG) |
| 250 | || !strcmp(panel_name, SIM_VIDEO_PANEL) |
| 251 | || !strcmp(panel_name, SIM_CMD_PANEL)) { |
| 252 | dprintf(INFO, "Selected %s: Skip panel configuration\n", |
| 253 | panel_name); |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 254 | return; |
| 255 | } |
| 256 | |
| 257 | do { |
| 258 | target_force_cont_splash_disable(false); |
| 259 | ret = gcdb_display_init(panel_name, MDP_REV_305, MIPI_FB_ADDR); |
| 260 | if (!ret || ret == ERR_NOT_SUPPORTED) { |
| 261 | break; |
| 262 | } else { |
| 263 | target_force_cont_splash_disable(true); |
| 264 | msm_display_off(); |
| 265 | } |
| 266 | } while (++panel_loop <= oem_panel_max_auto_detect_panels()); |
Veera Sundaram Sankaran | 7868d54 | 2015-01-02 14:48:47 -0800 | [diff] [blame] | 267 | |
| 268 | if (cont_splash == '0') { |
| 269 | dprintf(INFO, "Forcing continuous splash disable\n"); |
| 270 | target_force_cont_splash_disable(true); |
| 271 | } |
Shivaraj Shetty | f9e10c4 | 2014-09-17 04:21:15 +0530 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void target_display_shutdown(void) |
| 275 | { |
| 276 | gcdb_display_shutdown(); |
| 277 | } |