Wenjun Zhang | 4e63ce4 | 2017-11-28 05:11:34 -0500 | [diff] [blame] | 1 | /* Copyright (c) 2013-2018 The Linux Foundation. All rights reserved. |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [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 <err.h> |
| 32 | #include <smem.h> |
Veera Sundaram Sankaran | 824e6fa | 2014-12-09 11:32:58 -0800 | [diff] [blame] | 33 | #include <clock.h> |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 34 | #include <msm_panel.h> |
Dhaval Patel | 9f61f13 | 2013-07-18 14:45:11 -0700 | [diff] [blame] | 35 | #include <string.h> |
| 36 | #include <stdlib.h> |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 37 | #include <board.h> |
| 38 | #include <mdp5.h> |
Veera Sundaram Sankaran | 824e6fa | 2014-12-09 11:32:58 -0800 | [diff] [blame] | 39 | #include <qtimer.h> |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 40 | #include <platform/gpio.h> |
| 41 | #include <mipi_dsi.h> |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 42 | #include <partition_parser.h> |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 43 | |
| 44 | #include "include/display_resource.h" |
| 45 | #include "include/panel.h" |
| 46 | #include "panel_display.h" |
| 47 | #include "gcdb_display.h" |
| 48 | #include "target/display.h" |
Arpita Banerjee | da0c39a | 2013-05-24 16:12:45 -0700 | [diff] [blame] | 49 | #include "gcdb_autopll.h" |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 50 | |
| 51 | /*---------------------------------------------------------------------------*/ |
| 52 | /* static */ |
| 53 | /*---------------------------------------------------------------------------*/ |
| 54 | static struct msm_fb_panel_data panel; |
| 55 | struct panel_struct panelstruct; |
| 56 | static uint8_t display_enable; |
| 57 | static struct mdss_dsi_phy_ctrl dsi_video_mode_phy_db; |
| 58 | |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 59 | /*---------------------------------------------------------------------------*/ |
| 60 | /* Extern */ |
| 61 | /*---------------------------------------------------------------------------*/ |
| 62 | extern int msm_display_init(struct msm_fb_panel_data *pdata); |
| 63 | extern int msm_display_off(); |
| 64 | |
| 65 | static uint32_t panel_backlight_ctrl(uint8_t enable) |
| 66 | { |
Vineet Bajaj | 2244234 | 2015-04-29 16:55:18 +0530 | [diff] [blame] | 67 | uint32_t ret = NO_ERROR; |
| 68 | if (panelstruct.backlightinfo) |
| 69 | ret = target_backlight_ctrl(panelstruct.backlightinfo, enable); |
| 70 | return ret; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static uint32_t mdss_dsi_panel_reset(uint8_t enable) |
| 74 | { |
| 75 | uint32_t ret = NO_ERROR; |
Vineet Bajaj | 2244234 | 2015-04-29 16:55:18 +0530 | [diff] [blame] | 76 | if (panelstruct.panelresetseq) |
| 77 | ret = target_panel_reset(enable, panelstruct.panelresetseq, |
| 78 | &panel.panel_info); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 79 | return ret; |
| 80 | } |
| 81 | |
Arpita Banerjee | da0c39a | 2013-05-24 16:12:45 -0700 | [diff] [blame] | 82 | static uint32_t mdss_dsi_panel_clock(uint8_t enable, |
| 83 | struct msm_panel_info *pinfo) |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 84 | { |
| 85 | uint32_t ret = NO_ERROR; |
| 86 | |
Arpita Banerjee | da0c39a | 2013-05-24 16:12:45 -0700 | [diff] [blame] | 87 | ret = calculate_clock_config(pinfo); |
Huaibin Yang | cbec39b | 2014-11-07 13:54:38 -0800 | [diff] [blame] | 88 | if (ret) |
| 89 | dprintf(CRITICAL, "Clock calculation failed\n"); |
| 90 | else |
| 91 | ret = target_panel_clock(enable, pinfo); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 92 | |
| 93 | return ret; |
| 94 | } |
| 95 | |
Kuogee Hsieh | 93bcff6 | 2014-08-22 14:02:08 -0700 | [diff] [blame] | 96 | static int mdss_dsi_panel_power(uint8_t enable, |
| 97 | struct msm_panel_info *pinfo) |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 98 | { |
| 99 | int ret = NO_ERROR; |
| 100 | |
| 101 | if (enable) { |
Kuogee Hsieh | 93bcff6 | 2014-08-22 14:02:08 -0700 | [diff] [blame] | 102 | ret = target_ldo_ctrl(enable, pinfo); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 103 | if (ret) { |
Jayant Shekhar | c9611a9 | 2013-11-20 16:59:27 +0530 | [diff] [blame] | 104 | dprintf(CRITICAL, "LDO control enable failed\n"); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | /* Panel Reset */ |
Jayant Shekhar | c9611a9 | 2013-11-20 16:59:27 +0530 | [diff] [blame] | 109 | if (!panelstruct.paneldata->panel_lp11_init) { |
| 110 | ret = mdss_dsi_panel_reset(enable); |
| 111 | if (ret) { |
| 112 | dprintf(CRITICAL, "panel reset failed\n"); |
| 113 | return ret; |
| 114 | } |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 115 | } |
| 116 | dprintf(SPEW, "Panel power on done\n"); |
| 117 | } else { |
Casey Piper | 1bbd157 | 2013-09-11 16:23:18 -0700 | [diff] [blame] | 118 | /* Disable panel and ldo */ |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 119 | ret = mdss_dsi_panel_reset(enable); |
| 120 | if (ret) { |
Jayant Shekhar | c9611a9 | 2013-11-20 16:59:27 +0530 | [diff] [blame] | 121 | dprintf(CRITICAL, "panel reset disable failed\n"); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 122 | return ret; |
| 123 | } |
| 124 | |
Kuogee Hsieh | 93bcff6 | 2014-08-22 14:02:08 -0700 | [diff] [blame] | 125 | ret = target_ldo_ctrl(enable, pinfo); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 126 | if (ret) { |
Jayant Shekhar | c9611a9 | 2013-11-20 16:59:27 +0530 | [diff] [blame] | 127 | dprintf(CRITICAL, "ldo control disable failed\n"); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 128 | return ret; |
| 129 | } |
| 130 | dprintf(SPEW, "Panel power off done\n"); |
| 131 | } |
| 132 | |
| 133 | return ret; |
| 134 | } |
| 135 | |
Ray Zhang | eb462f6 | 2013-12-03 17:16:08 +0800 | [diff] [blame] | 136 | static int mdss_dsi_panel_pre_init(void) |
Jayant Shekhar | c9611a9 | 2013-11-20 16:59:27 +0530 | [diff] [blame] | 137 | { |
| 138 | int ret = NO_ERROR; |
| 139 | |
Ray Zhang | eb462f6 | 2013-12-03 17:16:08 +0800 | [diff] [blame] | 140 | if (panelstruct.paneldata->panel_lp11_init) { |
| 141 | ret = mdss_dsi_panel_reset(1); |
| 142 | if (ret) { |
| 143 | dprintf(CRITICAL, "panel reset failed\n"); |
| 144 | return ret; |
Jayant Shekhar | c9611a9 | 2013-11-20 16:59:27 +0530 | [diff] [blame] | 145 | } |
Jayant Shekhar | c9611a9 | 2013-11-20 16:59:27 +0530 | [diff] [blame] | 146 | } |
| 147 | |
Ray Zhang | eb462f6 | 2013-12-03 17:16:08 +0800 | [diff] [blame] | 148 | if(panelstruct.paneldata->panel_init_delay) |
| 149 | udelay(panelstruct.paneldata->panel_init_delay); |
| 150 | |
| 151 | dprintf(SPEW, "Panel pre init done\n"); |
Jayant Shekhar | c9611a9 | 2013-11-20 16:59:27 +0530 | [diff] [blame] | 152 | return ret; |
| 153 | } |
| 154 | |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 155 | static int mdss_dsi_dfps_get_pll_codes_cal(struct msm_panel_info *pinfo) |
Huaibin Yang | cbec39b | 2014-11-07 13:54:38 -0800 | [diff] [blame] | 156 | { |
| 157 | int ret = NO_ERROR; |
| 158 | uint32_t fps_bak; |
| 159 | uint32_t i; |
| 160 | |
| 161 | fps_bak = pinfo->mipi.frame_rate; |
| 162 | |
| 163 | for (i = 0; i < pinfo->dfps.panel_dfps.frame_rate_cnt; i++) { |
| 164 | int err; |
| 165 | pinfo->mipi.frame_rate = pinfo->dfps.panel_dfps.frame_rate[i]; |
| 166 | |
| 167 | err = mdss_dsi_panel_clock(1, pinfo); |
| 168 | if (!err) { |
Jeevan Shriram | e201466 | 2015-08-03 15:11:27 -0700 | [diff] [blame] | 169 | dprintf(SPEW, "frame_rate=%d, vcorate=%d success!\n", |
| 170 | pinfo->mipi.frame_rate, |
| 171 | pinfo->mipi.dsi_pll_config->vco_clock); |
Huaibin Yang | cbec39b | 2014-11-07 13:54:38 -0800 | [diff] [blame] | 172 | pinfo->dfps.codes_dfps[i].is_valid = 1; |
| 173 | pinfo->dfps.codes_dfps[i].frame_rate = |
| 174 | pinfo->mipi.frame_rate; |
Huaibin Yang | cbec39b | 2014-11-07 13:54:38 -0800 | [diff] [blame] | 175 | pinfo->dfps.codes_dfps[i].clk_rate = |
| 176 | pinfo->mipi.dsi_pll_config->vco_clock; |
| 177 | pinfo->dfps.codes_dfps[i].pll_codes = |
| 178 | pinfo->mipi.pll_codes; |
| 179 | |
| 180 | mdss_dsi_panel_clock(0, pinfo); |
| 181 | } else { |
| 182 | ret = err; |
| 183 | pinfo->dfps.codes_dfps[i].is_valid = 0; |
| 184 | dprintf(CRITICAL, "frame_rate=%d failed!\n", |
| 185 | pinfo->mipi.frame_rate); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | pinfo->mipi.frame_rate = fps_bak; |
| 190 | |
| 191 | return ret; |
| 192 | } |
| 193 | |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 194 | static int mdss_dsi_dfps_get_stored_pll_codes(struct msm_panel_info *pinfo) |
| 195 | { |
| 196 | int ret = NO_ERROR; |
| 197 | int index; |
| 198 | unsigned long long ptn; |
| 199 | uint32_t blocksize; |
| 200 | struct dfps_info *dfps; |
| 201 | |
| 202 | index = partition_get_index("splash"); |
Casey Piper | 69f9568 | 2015-03-30 16:19:45 -0700 | [diff] [blame] | 203 | if (index == INVALID_PTN) { |
| 204 | dprintf(INFO, "%s: splash partition table not found\n", __func__); |
Jeevan Shriram | e201466 | 2015-08-03 15:11:27 -0700 | [diff] [blame] | 205 | ret = ERROR; |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 206 | goto splash_err; |
| 207 | } |
| 208 | |
| 209 | ptn = partition_get_offset(index); |
| 210 | if (ptn == 0) { |
| 211 | dprintf(CRITICAL, "ERROR: splash Partition invalid offset\n"); |
| 212 | ret = ERROR; |
| 213 | goto splash_err; |
| 214 | } |
| 215 | |
Channagoud Kadabi | 7f66637 | 2015-02-24 14:37:32 -0800 | [diff] [blame] | 216 | mmc_set_lun(partition_get_lun(index)); |
| 217 | |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 218 | blocksize = mmc_get_device_blocksize(); |
| 219 | if (blocksize == 0) { |
| 220 | dprintf(CRITICAL, "ERROR:splash Partition invalid blocksize\n"); |
| 221 | ret = ERROR; |
| 222 | goto splash_err; |
| 223 | } |
| 224 | |
| 225 | dfps = (struct dfps_info *)memalign(CACHE_LINE, ROUNDUP(PAGE_SIZE, |
| 226 | CACHE_LINE)); |
| 227 | if (!dfps) { |
| 228 | dprintf(CRITICAL, "ERROR:splash Partition invalid memory\n"); |
| 229 | ret = ERROR; |
| 230 | goto splash_err; |
| 231 | } |
| 232 | |
| 233 | if (mmc_read(ptn, (uint32_t *) dfps, blocksize)) { |
| 234 | dprintf(CRITICAL, "mmc read splash failure%d\n", PAGE_SIZE); |
| 235 | ret = ERROR; |
| 236 | free(dfps); |
| 237 | goto splash_err; |
| 238 | } |
| 239 | |
| 240 | dprintf(SPEW, "enable=%d cnt=%d\n", dfps->panel_dfps.enabled, |
| 241 | dfps->panel_dfps.frame_rate_cnt); |
| 242 | |
Ashish Garg | 342420a | 2017-04-24 18:00:12 +0530 | [diff] [blame] | 243 | dprintf(CRITICAL, "chip serial splash =%d\n", dfps->chip_serial); |
| 244 | dprintf(CRITICAL, "chip serial pinfo =%d\n", pinfo->dfps.chip_serial); |
| 245 | |
| 246 | if (!dfps->panel_dfps.enabled || |
| 247 | (dfps->panel_dfps.frame_rate_cnt > DFPS_MAX_FRAME_RATE) || |
| 248 | (dfps->dfps_fb_base != pinfo->dfps.dfps_fb_base) || |
| 249 | (pinfo->dfps.chip_serial != dfps->chip_serial)) { |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 250 | ret = ERROR; |
| 251 | free(dfps); |
| 252 | goto splash_err; |
| 253 | } |
| 254 | |
| 255 | pinfo->dfps = *dfps; |
| 256 | free(dfps); |
| 257 | |
| 258 | splash_err: |
| 259 | return ret; |
| 260 | } |
| 261 | |
| 262 | static int mdss_dsi_dfps_store_pll_codes(struct msm_panel_info *pinfo) |
| 263 | { |
| 264 | int ret = NO_ERROR; |
| 265 | int index; |
| 266 | unsigned long long ptn; |
| 267 | |
| 268 | index = partition_get_index("splash"); |
Casey Piper | 69f9568 | 2015-03-30 16:19:45 -0700 | [diff] [blame] | 269 | if (index == INVALID_PTN) { |
| 270 | dprintf(INFO, "%s: splash partition table not found\n", __func__); |
Jeevan Shriram | e201466 | 2015-08-03 15:11:27 -0700 | [diff] [blame] | 271 | ret = ERROR; |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 272 | goto store_err; |
| 273 | } |
| 274 | |
| 275 | ptn = partition_get_offset(index); |
| 276 | if (ptn == 0) { |
| 277 | dprintf(CRITICAL, "ERROR: splash Partition invalid offset\n"); |
| 278 | ret = ERROR; |
| 279 | goto store_err; |
| 280 | } |
| 281 | |
Channagoud Kadabi | 7f66637 | 2015-02-24 14:37:32 -0800 | [diff] [blame] | 282 | mmc_set_lun(partition_get_lun(index)); |
| 283 | |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 284 | ret = mmc_write(ptn, sizeof(uint32_t), &pinfo->dfps); |
| 285 | if (ret) |
| 286 | dprintf(CRITICAL, "mmc write failed!\n"); |
| 287 | |
| 288 | store_err: |
| 289 | return ret; |
| 290 | } |
| 291 | |
Huaibin Yang | cbec39b | 2014-11-07 13:54:38 -0800 | [diff] [blame] | 292 | static int mdss_dsi_mipi_dfps_config(struct msm_panel_info *pinfo) |
| 293 | { |
| 294 | int ret = NO_ERROR; |
| 295 | |
| 296 | if (!pinfo) |
| 297 | return ERROR; |
| 298 | |
| 299 | if (!pinfo->dfps.panel_dfps.enabled) |
| 300 | goto dfps_done; |
| 301 | |
Ashish Garg | 342420a | 2017-04-24 18:00:12 +0530 | [diff] [blame] | 302 | pinfo->dfps.chip_serial = board_chip_serial(); |
| 303 | |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 304 | if (!mdss_dsi_dfps_get_stored_pll_codes(pinfo)) { |
Ashish Garg | 342420a | 2017-04-24 18:00:12 +0530 | [diff] [blame] | 305 | dprintf(CRITICAL, "Found stored PLL codes!\n"); |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 306 | goto dfps_cal_done; |
| 307 | } |
Huaibin Yang | cbec39b | 2014-11-07 13:54:38 -0800 | [diff] [blame] | 308 | |
Ashish Garg | 342420a | 2017-04-24 18:00:12 +0530 | [diff] [blame] | 309 | dprintf(CRITICAL, "Calculate PLL codes!\n"); |
Huaibin Yang | b6fa92b | 2015-01-28 16:21:37 -0800 | [diff] [blame] | 310 | ret = mdss_dsi_dfps_get_pll_codes_cal(pinfo); |
| 311 | if (ret) { |
| 312 | dprintf(CRITICAL, "Cannot cal pll codes!\n"); |
| 313 | goto dfps_done; |
| 314 | } else { |
| 315 | dprintf(SPEW, "Calibrate all pll codes!\n"); |
| 316 | } |
| 317 | |
| 318 | ret = mdss_dsi_dfps_store_pll_codes(pinfo); |
| 319 | if (ret) |
| 320 | dprintf(CRITICAL, "Cannot store pll codes!\n"); |
| 321 | |
| 322 | dfps_cal_done: |
Huaibin Yang | b9f15e5 | 2015-01-22 10:34:47 -0800 | [diff] [blame] | 323 | if (pinfo->dfps.dfps_fb_base) |
| 324 | memcpy(pinfo->dfps.dfps_fb_base, &pinfo->dfps, |
| 325 | sizeof(struct dfps_info)); |
Huaibin Yang | cbec39b | 2014-11-07 13:54:38 -0800 | [diff] [blame] | 326 | dfps_done: |
| 327 | return ret; |
| 328 | } |
| 329 | |
Casey Piper | 1bbd157 | 2013-09-11 16:23:18 -0700 | [diff] [blame] | 330 | static int mdss_dsi_bl_enable(uint8_t enable) |
| 331 | { |
| 332 | int ret = NO_ERROR; |
| 333 | |
| 334 | ret = panel_backlight_ctrl(enable); |
| 335 | if (ret) |
| 336 | dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" : |
| 337 | "disable"); |
| 338 | return ret; |
| 339 | } |
| 340 | |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 341 | static void mdss_edp_panel_init(struct msm_panel_info *pinfo) |
| 342 | { |
| 343 | return target_edp_panel_init(pinfo); |
| 344 | } |
| 345 | |
| 346 | static uint32_t mdss_edp_panel_clock(uint8_t enable, |
| 347 | struct msm_panel_info *pinfo) |
| 348 | { |
| 349 | return target_edp_panel_clock(enable, pinfo); |
| 350 | } |
| 351 | |
| 352 | static uint32_t mdss_edp_panel_enable(void) |
| 353 | { |
| 354 | return target_edp_panel_enable(); |
| 355 | } |
| 356 | |
| 357 | static uint32_t mdss_edp_panel_disable(void) |
| 358 | { |
| 359 | return target_edp_panel_disable(); |
| 360 | } |
| 361 | |
Kuogee Hsieh | 93bcff6 | 2014-08-22 14:02:08 -0700 | [diff] [blame] | 362 | static int mdss_edp_panel_power(uint8_t enable, |
| 363 | struct msm_panel_info *pinfo) |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 364 | { |
Casey Piper | c574e08 | 2013-09-05 14:54:42 -0700 | [diff] [blame] | 365 | int ret = NO_ERROR; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 366 | |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 367 | if (enable) { |
Kuogee Hsieh | 93bcff6 | 2014-08-22 14:02:08 -0700 | [diff] [blame] | 368 | ret = target_ldo_ctrl(enable, pinfo); |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 369 | if (ret) { |
| 370 | dprintf(CRITICAL, "LDO control enable failed\n"); |
| 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | ret = mdss_edp_panel_enable(); |
| 375 | if (ret) { |
| 376 | dprintf(CRITICAL, "%s: panel enable failed\n", __func__); |
| 377 | return ret; |
| 378 | } |
| 379 | dprintf(SPEW, "EDP Panel power on done\n"); |
| 380 | } else { |
| 381 | /* Disable panel and ldo */ |
| 382 | ret = mdss_edp_panel_disable(); |
| 383 | if (ret) { |
| 384 | dprintf(CRITICAL, "%s: panel disable failed\n", __func__); |
| 385 | return ret; |
| 386 | } |
| 387 | |
Kuogee Hsieh | 93bcff6 | 2014-08-22 14:02:08 -0700 | [diff] [blame] | 388 | ret = target_ldo_ctrl(enable, pinfo); |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 389 | if (ret) { |
| 390 | dprintf(CRITICAL, "%s: ldo control disable failed\n", __func__); |
| 391 | return ret; |
| 392 | } |
| 393 | dprintf(SPEW, "EDP Panel power off done\n"); |
| 394 | } |
| 395 | |
| 396 | return ret; |
| 397 | } |
| 398 | |
| 399 | static int mdss_edp_bl_enable(uint8_t enable) |
| 400 | { |
| 401 | int ret = NO_ERROR; |
| 402 | |
| 403 | ret = target_edp_bl_ctrl(enable); |
| 404 | if (ret) |
| 405 | dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" : |
| 406 | "disable"); |
| 407 | return ret; |
| 408 | } |
| 409 | |
Vineet Bajaj | c227246 | 2015-05-07 17:35:03 +0530 | [diff] [blame] | 410 | static int mdss_dsi2HDMI_config (struct msm_panel_info *pinfo) |
| 411 | { |
| 412 | return target_display_dsi2hdmi_config(pinfo); |
| 413 | } |
| 414 | |
Padmanabhan Komanduru | bccbcdc | 2015-06-30 16:19:24 +0530 | [diff] [blame] | 415 | struct panel_struct mdss_dsi_get_panel_data(void) |
| 416 | { |
| 417 | return panelstruct; |
| 418 | } |
| 419 | |
Padmanabhan Komanduru | dc0eaca | 2015-08-28 16:29:59 +0530 | [diff] [blame] | 420 | static void mdss_dsi_check_swap_status(void) |
| 421 | { |
| 422 | char *panel_dest, *dsi_controller; |
| 423 | struct oem_panel_data *oem_data = mdss_dsi_get_oem_data_ptr(); |
| 424 | |
| 425 | if (!oem_data->swap_dsi_ctrl) |
| 426 | return; |
| 427 | |
| 428 | if (panelstruct.paneldata->panel_operating_mode & |
| 429 | (SPLIT_DISPLAY_FLAG | DUAL_DSI_FLAG)) { |
| 430 | dprintf(CRITICAL, "DSI swap invalid for split DSI panel!\n"); |
| 431 | return; |
| 432 | } |
| 433 | |
| 434 | /* Swap the panel destination and use appropriate PLL */ |
| 435 | if (!strcmp(panelstruct.paneldata->panel_destination, "DISPLAY_1")) { |
| 436 | panel_dest = "DISPLAY_2"; |
| 437 | dsi_controller = "dsi:1:"; |
| 438 | panelstruct.paneldata->panel_operating_mode |= USE_DSI1_PLL_FLAG; |
| 439 | } else { |
| 440 | panel_dest = "DISPLAY_1"; |
| 441 | dsi_controller = "dsi:0:"; |
| 442 | panelstruct.paneldata->panel_operating_mode &= ~USE_DSI1_PLL_FLAG; |
| 443 | } |
| 444 | panelstruct.paneldata->panel_destination = panel_dest; |
| 445 | panelstruct.paneldata->panel_controller = dsi_controller; |
| 446 | } |
| 447 | |
Padmanabhan Komanduru | 75f5b3b | 2015-07-06 18:28:51 +0530 | [diff] [blame] | 448 | static void mdss_dsi_set_pll_src(void) |
| 449 | { |
| 450 | struct oem_panel_data *oem_data = mdss_dsi_get_oem_data_ptr(); |
| 451 | |
Padmanabhan Komanduru | aa1e683 | 2015-08-28 14:55:24 +0530 | [diff] [blame] | 452 | /* Set PLL_SRC to PLL1 for non dual-DSI cases only */ |
| 453 | if (!is_dsi_config_dual() && |
| 454 | (panelstruct.paneldata->panel_operating_mode & |
| 455 | USE_DSI1_PLL_FLAG)) |
Padmanabhan Komanduru | 75f5b3b | 2015-07-06 18:28:51 +0530 | [diff] [blame] | 456 | oem_data->dsi_pll_src = DSI_PLL1; |
| 457 | |
Padmanabhan Komanduru | aa1e683 | 2015-08-28 14:55:24 +0530 | [diff] [blame] | 458 | if (is_dsi_config_dual()) { |
Padmanabhan Komanduru | 75f5b3b | 2015-07-06 18:28:51 +0530 | [diff] [blame] | 459 | if (oem_data->dsi_pll_src != DSI_PLL_DEFAULT) { |
| 460 | dprintf(CRITICAL, "Dual DSI config detected!" |
| 461 | "Use default PLL\n"); |
| 462 | oem_data->dsi_pll_src = DSI_PLL_DEFAULT; |
| 463 | } |
Padmanabhan Komanduru | aa1e683 | 2015-08-28 14:55:24 +0530 | [diff] [blame] | 464 | } else if (is_dsi_config_split()) { |
Padmanabhan Komanduru | 75f5b3b | 2015-07-06 18:28:51 +0530 | [diff] [blame] | 465 | if((dsi_video_mode_phy_db.pll_type != DSI_PLL_TYPE_THULIUM) |
| 466 | && (oem_data->dsi_pll_src == DSI_PLL1)) { |
| 467 | dprintf(CRITICAL, "Split DSI on 28nm/20nm!" |
| 468 | "Use DSI PLL0\n"); |
| 469 | oem_data->dsi_pll_src = DSI_PLL0; |
| 470 | } |
| 471 | } else { |
| 472 | if ((dsi_video_mode_phy_db.pll_type != DSI_PLL_TYPE_THULIUM) |
| 473 | && !strcmp(panelstruct.paneldata->panel_destination, |
| 474 | "DISPLAY_1") && (oem_data->dsi_pll_src == DSI_PLL1)) { |
| 475 | dprintf(CRITICAL, "Single DSI with DSI-0 on 28nm/20nm!" |
| 476 | "Use DSI PLL0\n"); |
| 477 | oem_data->dsi_pll_src = DSI_PLL0; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | if (oem_data->dsi_pll_src == DSI_PLL1) |
| 482 | panelstruct.paneldata->panel_operating_mode |= |
| 483 | USE_DSI1_PLL_FLAG; |
Padmanabhan Komanduru | aa1e683 | 2015-08-28 14:55:24 +0530 | [diff] [blame] | 484 | else if (oem_data->dsi_pll_src == DSI_PLL0) |
Padmanabhan Komanduru | 75f5b3b | 2015-07-06 18:28:51 +0530 | [diff] [blame] | 485 | panelstruct.paneldata->panel_operating_mode &= |
| 486 | ~USE_DSI1_PLL_FLAG; |
Padmanabhan Komanduru | 75f5b3b | 2015-07-06 18:28:51 +0530 | [diff] [blame] | 487 | } |
| 488 | |
Wenjun Zhang | 4e63ce4 | 2017-11-28 05:11:34 -0500 | [diff] [blame] | 489 | static int mdss_spi_bl_enable(uint8_t enable) |
| 490 | { |
| 491 | int ret = NO_ERROR; |
| 492 | |
| 493 | ret = panel_backlight_ctrl(enable); |
| 494 | if (ret) |
| 495 | dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" : "disable"); |
| 496 | return ret; |
| 497 | } |
| 498 | |
| 499 | static int mdss_spi_panel_power(uint8_t enable, struct msm_panel_info *pinfo) |
| 500 | { |
| 501 | int ret = NO_ERROR; |
| 502 | |
| 503 | if (enable) { |
| 504 | ret = target_ldo_ctrl(enable, pinfo); |
| 505 | if (ret) { |
| 506 | dprintf(CRITICAL, "LDO control enable failed\n"); |
| 507 | return ret; |
| 508 | } |
| 509 | |
| 510 | /*Panel Reset*/ |
| 511 | ret = target_panel_reset(enable,panelstruct.panelresetseq, &panel.panel_info); |
| 512 | if (ret) { |
| 513 | dprintf(CRITICAL, "panel reset failed\n"); |
| 514 | return ret; |
| 515 | } |
| 516 | dprintf(INFO, "Panel power on done\n"); |
| 517 | } else { |
| 518 | /*Disable panel and ldo*/ |
| 519 | ret = target_panel_reset(enable, panelstruct.panelresetseq, &panel.panel_info); |
| 520 | if (ret) { |
| 521 | dprintf(CRITICAL, "panel reset disable failed \n"); |
| 522 | return ret; |
| 523 | } |
| 524 | |
| 525 | ret = target_ldo_ctrl(enable, pinfo); |
| 526 | if (ret) { |
| 527 | dprintf(CRITICAL, "panel reset disable failed \n"); |
| 528 | return ret; |
| 529 | } |
| 530 | dprintf(INFO, "Panel power off done\n"); |
| 531 | } |
| 532 | |
| 533 | return ret; |
| 534 | } |
| 535 | |
Dhaval Patel | d96d092 | 2015-10-20 16:06:21 -0700 | [diff] [blame] | 536 | static int update_dsi_display_config() |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 537 | { |
| 538 | int ret = NO_ERROR; |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 539 | |
Ujwal Patel | 41a665a | 2015-07-17 13:51:30 -0700 | [diff] [blame] | 540 | if ((panel.panel_info.lm_split[0] > 0) && |
| 541 | (panel.panel_info.lm_split[1] > 0)) |
| 542 | panelstruct.paneldata->panel_operating_mode |= DUAL_PIPE_FLAG; |
| 543 | |
| 544 | if (panelstruct.paneldata->panel_operating_mode & DUAL_PIPE_FLAG) { |
| 545 | if ((panel.panel_info.lm_split[0] <= 0) || |
| 546 | (panel.panel_info.lm_split[1] <= 0)) { |
| 547 | panel.panel_info.lm_split[0] = |
| 548 | panelstruct.panelres->panel_width / 2; |
| 549 | panel.panel_info.lm_split[1] = |
| 550 | panel.panel_info.lm_split[0]; |
| 551 | } |
| 552 | } |
| 553 | |
Ujwal Patel | 5c3227b | 2015-08-12 14:48:02 -0700 | [diff] [blame] | 554 | if (panelstruct.config && panelstruct.config->use_pingpong_split) |
| 555 | panelstruct.paneldata->panel_operating_mode |= DST_SPLIT_FLAG; |
| 556 | |
| 557 | if ((panelstruct.paneldata->panel_operating_mode & DUAL_PIPE_FLAG) && |
| 558 | (panelstruct.paneldata->panel_operating_mode & DST_SPLIT_FLAG)) { |
| 559 | dprintf(CRITICAL, "DUAL_PIPE_FLAG and DST_SPLIT_FLAG cannot be selected togather\n"); |
| 560 | ret = ERROR; |
Ujwal Patel | 5c3227b | 2015-08-12 14:48:02 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Dhaval Patel | d96d092 | 2015-10-20 16:06:21 -0700 | [diff] [blame] | 563 | return ret; |
| 564 | } |
| 565 | |
| 566 | int gcdb_display_init(const char *panel_name, uint32_t rev, void *base) |
| 567 | { |
| 568 | int ret = NO_ERROR; |
| 569 | int pan_type; |
| 570 | |
| 571 | dsi_video_mode_phy_db.pll_type = DSI_PLL_TYPE_28NM; |
Frank Yi | 2b7e2b9 | 2018-04-25 16:24:45 +0800 | [diff] [blame] | 572 | panel.panel_info.disable_wled_labibb = false; |
Dhaval Patel | d96d092 | 2015-10-20 16:06:21 -0700 | [diff] [blame] | 573 | pan_type = oem_panel_select(panel_name, &panelstruct, &(panel.panel_info), |
| 574 | &dsi_video_mode_phy_db); |
| 575 | |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 576 | if (pan_type == PANEL_TYPE_DSI) { |
Dhaval Patel | d96d092 | 2015-10-20 16:06:21 -0700 | [diff] [blame] | 577 | if (update_dsi_display_config()) |
| 578 | goto error_gcdb_display_init; |
Dhaval Patel | 7709c41 | 2015-05-12 10:09:41 -0700 | [diff] [blame] | 579 | target_dsi_phy_config(&dsi_video_mode_phy_db); |
Padmanabhan Komanduru | dc0eaca | 2015-08-28 16:29:59 +0530 | [diff] [blame] | 580 | mdss_dsi_check_swap_status(); |
Padmanabhan Komanduru | 75f5b3b | 2015-07-06 18:28:51 +0530 | [diff] [blame] | 581 | mdss_dsi_set_pll_src(); |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 582 | if (dsi_panel_init(&(panel.panel_info), &panelstruct)) { |
| 583 | dprintf(CRITICAL, "DSI panel init failed!\n"); |
| 584 | ret = ERROR; |
| 585 | goto error_gcdb_display_init; |
| 586 | } |
| 587 | |
| 588 | panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db; |
| 589 | panel.pll_clk_func = mdss_dsi_panel_clock; |
Huaibin Yang | cbec39b | 2014-11-07 13:54:38 -0800 | [diff] [blame] | 590 | panel.dfps_func = mdss_dsi_mipi_dfps_config; |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 591 | panel.power_func = mdss_dsi_panel_power; |
| 592 | panel.pre_init_func = mdss_dsi_panel_pre_init; |
| 593 | panel.bl_func = mdss_dsi_bl_enable; |
Vineet Bajaj | c227246 | 2015-05-07 17:35:03 +0530 | [diff] [blame] | 594 | panel.dsi2HDMI_config = mdss_dsi2HDMI_config; |
Huaibin Yang | b9f15e5 | 2015-01-22 10:34:47 -0800 | [diff] [blame] | 595 | /* |
Padmanabhan Komanduru | 53c2e97 | 2016-02-18 19:00:34 +0530 | [diff] [blame] | 596 | * Reserve fb memory to store pll codes and pass |
| 597 | * pll codes values to kernel. |
Huaibin Yang | b9f15e5 | 2015-01-22 10:34:47 -0800 | [diff] [blame] | 598 | */ |
Padmanabhan Komanduru | 53c2e97 | 2016-02-18 19:00:34 +0530 | [diff] [blame] | 599 | panel.panel_info.dfps.dfps_fb_base = base; |
| 600 | base += DFPS_PLL_CODES_SIZE; |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 601 | panel.fb.base = base; |
Padmanabhan Komanduru | 53c2e97 | 2016-02-18 19:00:34 +0530 | [diff] [blame] | 602 | dprintf(SPEW, "dfps base=0x%p,d, fb_base=0x%p!\n", |
| 603 | panel.panel_info.dfps.dfps_fb_base, base); |
| 604 | |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 605 | panel.fb.width = panel.panel_info.xres; |
| 606 | panel.fb.height = panel.panel_info.yres; |
| 607 | panel.fb.stride = panel.panel_info.xres; |
| 608 | panel.fb.bpp = panel.panel_info.bpp; |
| 609 | panel.fb.format = panel.panel_info.mipi.dst_format; |
| 610 | } else if (pan_type == PANEL_TYPE_EDP) { |
| 611 | mdss_edp_panel_init(&(panel.panel_info)); |
| 612 | /* prepare func is set up at edp_panel_init */ |
| 613 | panel.clk_func = mdss_edp_panel_clock; |
| 614 | panel.power_func = mdss_edp_panel_power; |
| 615 | panel.bl_func = mdss_edp_bl_enable; |
| 616 | panel.fb.format = FB_FORMAT_RGB888; |
Wenjun Zhang | 4e63ce4 | 2017-11-28 05:11:34 -0500 | [diff] [blame] | 617 | } else if (pan_type == PANEL_TYPE_SPI) { |
| 618 | panel.panel_info.xres = panelstruct.panelres->panel_width; |
| 619 | panel.panel_info.yres = panelstruct.panelres->panel_height; |
| 620 | panel.panel_info.bpp = panelstruct.color->color_format; |
| 621 | panel.power_func = mdss_spi_panel_power; |
| 622 | panel.bl_func = mdss_spi_bl_enable; |
| 623 | panel.fb.base = base; |
| 624 | panel.fb.width = panel.panel_info.xres; |
| 625 | panel.fb.height = panel.panel_info.yres; |
| 626 | panel.fb.bpp = panel.panel_info.bpp; |
| 627 | panel.fb.format = FB_FORMAT_RGB565; |
| 628 | panel.panel_info.type = SPI_PANEL; |
Kuogee Hsieh | 80b8a6c | 2014-06-09 17:25:38 -0700 | [diff] [blame] | 629 | } else { |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 630 | dprintf(CRITICAL, "Target panel init not found!\n"); |
Casey Piper | c574e08 | 2013-09-05 14:54:42 -0700 | [diff] [blame] | 631 | ret = ERR_NOT_SUPPORTED; |
| 632 | goto error_gcdb_display_init; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 635 | panel.fb.base = base; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 636 | panel.mdp_rev = rev; |
| 637 | |
Casey Piper | c574e08 | 2013-09-05 14:54:42 -0700 | [diff] [blame] | 638 | ret = msm_display_init(&panel); |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 639 | |
Casey Piper | c574e08 | 2013-09-05 14:54:42 -0700 | [diff] [blame] | 640 | error_gcdb_display_init: |
| 641 | display_enable = ret ? 0 : 1; |
| 642 | return ret; |
Arpita Banerjee | 841fa06 | 2013-05-24 14:59:51 -0700 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | void gcdb_display_shutdown(void) |
| 646 | { |
| 647 | if (display_enable) |
| 648 | msm_display_off(); |
| 649 | } |