Siddhartha Agrawal | 7e2e215 | 2013-01-23 17:06:58 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -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 are |
| 5 | * 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 |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
Siddhartha Agrawal | 7e2e215 | 2013-01-23 17:06:58 -0800 | [diff] [blame] | 12 | * * Neither the name of The Linux Foundation nor the names of its |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 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 "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <err.h> |
| 31 | #include <msm_panel.h> |
| 32 | #include <mdp4.h> |
| 33 | #include <mipi_dsi.h> |
Amol Jadi | 5f0fab0 | 2013-03-18 14:50:52 -0700 | [diff] [blame] | 34 | #include <boot_stats.h> |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 35 | |
Ajay Singh Parmar | 7c1cd52 | 2013-02-13 20:33:49 +0530 | [diff] [blame] | 36 | #ifndef DISPLAY_TYPE_HDMI |
| 37 | static int hdmi_dtv_init(void) |
| 38 | { |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static int hdmi_dtv_on(void) |
| 43 | { |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static int hdmi_msm_turn_on(void) |
| 48 | { |
| 49 | return 0; |
| 50 | } |
| 51 | #endif |
| 52 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 53 | static struct msm_fb_panel_data *panel; |
| 54 | |
| 55 | extern int lvds_on(struct msm_fb_panel_data *pdata); |
| 56 | |
| 57 | static int msm_fb_alloc(struct fbcon_config *fb) |
| 58 | { |
| 59 | if (fb == NULL) |
| 60 | return ERROR; |
| 61 | |
| 62 | if (fb->base == NULL) |
| 63 | fb->base = memalign(4096, fb->width |
| 64 | * fb->height |
| 65 | * (fb->bpp / 8)); |
| 66 | |
| 67 | if (fb->base == NULL) |
| 68 | return ERROR; |
| 69 | |
| 70 | return NO_ERROR; |
| 71 | } |
| 72 | |
| 73 | int msm_display_config() |
| 74 | { |
| 75 | int ret = NO_ERROR; |
Terence Hampson | f49ff4e | 2013-06-18 15:11:31 -0400 | [diff] [blame] | 76 | int mdp_rev; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 77 | struct msm_panel_info *pinfo; |
| 78 | |
| 79 | if (!panel) |
| 80 | return ERR_INVALID_ARGS; |
| 81 | |
| 82 | pinfo = &(panel->panel_info); |
| 83 | |
| 84 | /* Set MDP revision */ |
| 85 | mdp_set_revision(panel->mdp_rev); |
| 86 | |
| 87 | switch (pinfo->type) { |
| 88 | case LVDS_PANEL: |
| 89 | dprintf(INFO, "Config LVDS_PANEL.\n"); |
| 90 | ret = mdp_lcdc_config(pinfo, &(panel->fb)); |
| 91 | if (ret) |
| 92 | goto msm_display_config_out; |
| 93 | break; |
| 94 | case MIPI_VIDEO_PANEL: |
| 95 | dprintf(INFO, "Config MIPI_VIDEO_PANEL.\n"); |
Siddhartha Agrawal | 7e2e215 | 2013-01-23 17:06:58 -0800 | [diff] [blame] | 96 | |
Terence Hampson | f49ff4e | 2013-06-18 15:11:31 -0400 | [diff] [blame] | 97 | mdp_rev = mdp_get_revision(); |
| 98 | if (mdp_rev == MDP_REV_50 || mdp_rev == MDP_REV_304) |
Siddhartha Agrawal | 7e2e215 | 2013-01-23 17:06:58 -0800 | [diff] [blame] | 99 | ret = mdss_dsi_config(panel); |
| 100 | else |
| 101 | ret = mipi_config(panel); |
| 102 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 103 | if (ret) |
| 104 | goto msm_display_config_out; |
Amir Samuelov | 2d4ba16 | 2012-07-22 11:53:14 +0300 | [diff] [blame] | 105 | |
| 106 | if (pinfo->early_config) |
| 107 | ret = pinfo->early_config((void *)pinfo); |
| 108 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 109 | ret = mdp_dsi_video_config(pinfo, &(panel->fb)); |
| 110 | if (ret) |
| 111 | goto msm_display_config_out; |
| 112 | break; |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 113 | case MIPI_CMD_PANEL: |
| 114 | dprintf(INFO, "Config MIPI_CMD_PANEL.\n"); |
Xiaoming Zhou | 8d534dd | 2013-07-29 15:49:19 -0400 | [diff] [blame] | 115 | mdp_rev = mdp_get_revision(); |
| 116 | if (mdp_rev == MDP_REV_50 || mdp_rev == MDP_REV_304) |
Siddhartha Agrawal | e900fdf | 2013-04-21 16:18:17 -0700 | [diff] [blame] | 117 | ret = mdss_dsi_config(panel); |
| 118 | else |
| 119 | ret = mipi_config(panel); |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 120 | if (ret) |
| 121 | goto msm_display_config_out; |
Siddhartha Agrawal | e900fdf | 2013-04-21 16:18:17 -0700 | [diff] [blame] | 122 | |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 123 | ret = mdp_dsi_cmd_config(pinfo, &(panel->fb)); |
| 124 | if (ret) |
| 125 | goto msm_display_config_out; |
| 126 | break; |
Channagoud Kadabi | 43000a6 | 2012-06-28 18:23:24 +0530 | [diff] [blame] | 127 | case LCDC_PANEL: |
| 128 | dprintf(INFO, "Config LCDC PANEL.\n"); |
| 129 | ret = mdp_lcdc_config(pinfo, &(panel->fb)); |
| 130 | if (ret) |
| 131 | goto msm_display_config_out; |
| 132 | break; |
Ajay Singh Parmar | 7c1cd52 | 2013-02-13 20:33:49 +0530 | [diff] [blame] | 133 | case HDMI_PANEL: |
| 134 | dprintf(INFO, "Config HDMI PANEL.\n"); |
| 135 | ret = hdmi_dtv_init(); |
| 136 | if (ret) |
| 137 | goto msm_display_config_out; |
| 138 | break; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 139 | default: |
| 140 | return ERR_INVALID_ARGS; |
| 141 | }; |
| 142 | |
| 143 | if (pinfo->config) |
| 144 | ret = pinfo->config((void *)pinfo); |
| 145 | |
| 146 | msm_display_config_out: |
| 147 | return ret; |
| 148 | } |
| 149 | |
| 150 | int msm_display_on() |
| 151 | { |
| 152 | int ret = NO_ERROR; |
Xiaoming Zhou | 8d534dd | 2013-07-29 15:49:19 -0400 | [diff] [blame] | 153 | int mdp_rev; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 154 | struct msm_panel_info *pinfo; |
| 155 | |
| 156 | if (!panel) |
| 157 | return ERR_INVALID_ARGS; |
| 158 | |
Amol Jadi | 5f0fab0 | 2013-03-18 14:50:52 -0700 | [diff] [blame] | 159 | bs_set_timestamp(BS_SPLASH_SCREEN_DISPLAY); |
| 160 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 161 | pinfo = &(panel->panel_info); |
| 162 | |
| 163 | switch (pinfo->type) { |
| 164 | case LVDS_PANEL: |
| 165 | dprintf(INFO, "Turn on LVDS PANEL.\n"); |
| 166 | ret = mdp_lcdc_on(panel); |
| 167 | if (ret) |
| 168 | goto msm_display_on_out; |
| 169 | ret = lvds_on(panel); |
| 170 | if (ret) |
| 171 | goto msm_display_on_out; |
| 172 | break; |
| 173 | case MIPI_VIDEO_PANEL: |
| 174 | dprintf(INFO, "Turn on MIPI_VIDEO_PANEL.\n"); |
| 175 | ret = mdp_dsi_video_on(); |
| 176 | if (ret) |
| 177 | goto msm_display_on_out; |
| 178 | ret = mipi_dsi_on(); |
| 179 | if (ret) |
| 180 | goto msm_display_on_out; |
| 181 | break; |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 182 | case MIPI_CMD_PANEL: |
| 183 | dprintf(INFO, "Turn on MIPI_CMD_PANEL.\n"); |
| 184 | ret = mdp_dma_on(); |
| 185 | if (ret) |
| 186 | goto msm_display_on_out; |
Xiaoming Zhou | 8d534dd | 2013-07-29 15:49:19 -0400 | [diff] [blame] | 187 | mdp_rev = mdp_get_revision(); |
| 188 | if (mdp_rev != MDP_REV_50 && mdp_rev != MDP_REV_304) { |
Siddhartha Agrawal | e900fdf | 2013-04-21 16:18:17 -0700 | [diff] [blame] | 189 | ret = mipi_cmd_trigger(); |
| 190 | if (ret) |
| 191 | goto msm_display_on_out; |
| 192 | } |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 193 | break; |
Channagoud Kadabi | 43000a6 | 2012-06-28 18:23:24 +0530 | [diff] [blame] | 194 | case LCDC_PANEL: |
| 195 | dprintf(INFO, "Turn on LCDC PANEL.\n"); |
| 196 | ret = mdp_lcdc_on(panel); |
| 197 | if (ret) |
| 198 | goto msm_display_on_out; |
| 199 | break; |
Ajay Singh Parmar | 7c1cd52 | 2013-02-13 20:33:49 +0530 | [diff] [blame] | 200 | case HDMI_PANEL: |
| 201 | dprintf(INFO, "Turn on HDMI PANEL.\n"); |
| 202 | ret = hdmi_dtv_on(); |
| 203 | if (ret) |
| 204 | goto msm_display_on_out; |
| 205 | |
| 206 | ret = hdmi_msm_turn_on(); |
| 207 | if (ret) |
| 208 | goto msm_display_on_out; |
| 209 | break; |
| 210 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 211 | default: |
| 212 | return ERR_INVALID_ARGS; |
| 213 | }; |
| 214 | |
| 215 | if (pinfo->on) |
| 216 | ret = pinfo->on(); |
| 217 | |
| 218 | msm_display_on_out: |
| 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | int msm_display_init(struct msm_fb_panel_data *pdata) |
| 223 | { |
| 224 | int ret = NO_ERROR; |
| 225 | |
| 226 | panel = pdata; |
| 227 | if (!panel) { |
| 228 | ret = ERR_INVALID_ARGS; |
| 229 | goto msm_display_init_out; |
| 230 | } |
| 231 | |
Chandan Uddaraju | 932723b | 2013-02-21 18:36:20 -0800 | [diff] [blame] | 232 | /* Turn on panel */ |
| 233 | if (pdata->power_func) |
| 234 | ret = pdata->power_func(1); |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 235 | |
| 236 | if (ret) |
| 237 | goto msm_display_init_out; |
| 238 | |
Chandan Uddaraju | 932723b | 2013-02-21 18:36:20 -0800 | [diff] [blame] | 239 | /* Enable clock */ |
| 240 | if (pdata->clk_func) |
| 241 | ret = pdata->clk_func(1); |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 242 | |
Arpita Banerjee | 2522bc6 | 2013-05-24 16:03:53 -0700 | [diff] [blame] | 243 | /* Only enabled for auto PLL calculation */ |
| 244 | if (pdata->pll_clk_func) |
| 245 | ret = pdata->pll_clk_func(1, &(panel->panel_info)); |
| 246 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 247 | if (ret) |
| 248 | goto msm_display_init_out; |
| 249 | |
| 250 | ret = msm_fb_alloc(&(panel->fb)); |
| 251 | if (ret) |
| 252 | goto msm_display_init_out; |
| 253 | |
| 254 | fbcon_setup(&(panel->fb)); |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 255 | display_image_on_screen(); |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 256 | ret = msm_display_config(); |
| 257 | if (ret) |
| 258 | goto msm_display_init_out; |
| 259 | |
| 260 | ret = msm_display_on(); |
| 261 | if (ret) |
| 262 | goto msm_display_init_out; |
| 263 | |
| 264 | msm_display_init_out: |
| 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | int msm_display_off() |
| 269 | { |
| 270 | int ret = NO_ERROR; |
| 271 | struct msm_panel_info *pinfo; |
| 272 | |
| 273 | if (!panel) |
| 274 | return ERR_INVALID_ARGS; |
| 275 | |
| 276 | pinfo = &(panel->panel_info); |
| 277 | |
| 278 | switch (pinfo->type) { |
| 279 | case LVDS_PANEL: |
| 280 | dprintf(INFO, "Turn off LVDS PANEL.\n"); |
| 281 | mdp_lcdc_off(); |
| 282 | break; |
| 283 | case MIPI_VIDEO_PANEL: |
| 284 | dprintf(INFO, "Turn off MIPI_VIDEO_PANEL.\n"); |
| 285 | ret = mdp_dsi_video_off(); |
| 286 | if (ret) |
| 287 | goto msm_display_off_out; |
Siddhartha Agrawal | 24d81b5 | 2013-07-01 11:13:32 -0700 | [diff] [blame] | 288 | ret = mipi_dsi_off(pinfo); |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 289 | if (ret) |
| 290 | goto msm_display_off_out; |
| 291 | break; |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 292 | case MIPI_CMD_PANEL: |
| 293 | dprintf(INFO, "Turn off MIPI_CMD_PANEL.\n"); |
| 294 | ret = mdp_dsi_cmd_off(); |
| 295 | if (ret) |
| 296 | goto msm_display_off_out; |
Siddhartha Agrawal | 24d81b5 | 2013-07-01 11:13:32 -0700 | [diff] [blame] | 297 | ret = mipi_dsi_off(pinfo); |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 298 | if (ret) |
| 299 | goto msm_display_off_out; |
| 300 | break; |
Channagoud Kadabi | 43000a6 | 2012-06-28 18:23:24 +0530 | [diff] [blame] | 301 | case LCDC_PANEL: |
| 302 | dprintf(INFO, "Turn off LCDC PANEL.\n"); |
| 303 | mdp_lcdc_off(); |
| 304 | break; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 305 | default: |
| 306 | return ERR_INVALID_ARGS; |
| 307 | }; |
| 308 | |
Siddhartha Agrawal | 03f6d21 | 2013-02-19 13:50:52 -0800 | [diff] [blame] | 309 | if (target_cont_splash_screen()) { |
| 310 | dprintf(INFO, "Continuous splash enabled, keeping panel alive.\n"); |
| 311 | return NO_ERROR; |
| 312 | } |
| 313 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 314 | if (pinfo->off) |
| 315 | ret = pinfo->off(); |
| 316 | |
| 317 | /* Disable clock */ |
| 318 | if (panel->clk_func) |
| 319 | ret = panel->clk_func(0); |
| 320 | |
Arpita Banerjee | 2522bc6 | 2013-05-24 16:03:53 -0700 | [diff] [blame] | 321 | /* Only for AUTO PLL calculation */ |
| 322 | if (panel->pll_clk_func) |
| 323 | ret = panel->pll_clk_func(0, pinfo); |
| 324 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 325 | if (ret) |
| 326 | goto msm_display_off_out; |
| 327 | |
| 328 | /* Disable panel */ |
| 329 | if (panel->power_func) |
| 330 | ret = panel->power_func(0); |
| 331 | |
| 332 | msm_display_off_out: |
| 333 | return ret; |
| 334 | } |