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> |
| 34 | |
Ajay Singh Parmar | 7c1cd52 | 2013-02-13 20:33:49 +0530 | [diff] [blame] | 35 | #ifndef DISPLAY_TYPE_HDMI |
| 36 | static int hdmi_dtv_init(void) |
| 37 | { |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static int hdmi_dtv_on(void) |
| 42 | { |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | static int hdmi_msm_turn_on(void) |
| 47 | { |
| 48 | return 0; |
| 49 | } |
| 50 | #endif |
| 51 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 52 | static struct msm_fb_panel_data *panel; |
| 53 | |
| 54 | extern int lvds_on(struct msm_fb_panel_data *pdata); |
| 55 | |
| 56 | static int msm_fb_alloc(struct fbcon_config *fb) |
| 57 | { |
| 58 | if (fb == NULL) |
| 59 | return ERROR; |
| 60 | |
| 61 | if (fb->base == NULL) |
| 62 | fb->base = memalign(4096, fb->width |
| 63 | * fb->height |
| 64 | * (fb->bpp / 8)); |
| 65 | |
| 66 | if (fb->base == NULL) |
| 67 | return ERROR; |
| 68 | |
| 69 | return NO_ERROR; |
| 70 | } |
| 71 | |
| 72 | int msm_display_config() |
| 73 | { |
| 74 | int ret = NO_ERROR; |
| 75 | struct msm_panel_info *pinfo; |
| 76 | |
| 77 | if (!panel) |
| 78 | return ERR_INVALID_ARGS; |
| 79 | |
| 80 | pinfo = &(panel->panel_info); |
| 81 | |
| 82 | /* Set MDP revision */ |
| 83 | mdp_set_revision(panel->mdp_rev); |
| 84 | |
| 85 | switch (pinfo->type) { |
| 86 | case LVDS_PANEL: |
| 87 | dprintf(INFO, "Config LVDS_PANEL.\n"); |
| 88 | ret = mdp_lcdc_config(pinfo, &(panel->fb)); |
| 89 | if (ret) |
| 90 | goto msm_display_config_out; |
| 91 | break; |
| 92 | case MIPI_VIDEO_PANEL: |
| 93 | dprintf(INFO, "Config MIPI_VIDEO_PANEL.\n"); |
Siddhartha Agrawal | 7e2e215 | 2013-01-23 17:06:58 -0800 | [diff] [blame] | 94 | |
| 95 | if (mdp_get_revision() == MDP_REV_50) |
| 96 | ret = mdss_dsi_config(panel); |
| 97 | else |
| 98 | ret = mipi_config(panel); |
| 99 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 100 | if (ret) |
| 101 | goto msm_display_config_out; |
Amir Samuelov | 2d4ba16 | 2012-07-22 11:53:14 +0300 | [diff] [blame] | 102 | |
| 103 | if (pinfo->early_config) |
| 104 | ret = pinfo->early_config((void *)pinfo); |
| 105 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 106 | ret = mdp_dsi_video_config(pinfo, &(panel->fb)); |
| 107 | if (ret) |
| 108 | goto msm_display_config_out; |
| 109 | break; |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 110 | case MIPI_CMD_PANEL: |
| 111 | dprintf(INFO, "Config MIPI_CMD_PANEL.\n"); |
| 112 | ret = mipi_config(panel); |
| 113 | if (ret) |
| 114 | goto msm_display_config_out; |
| 115 | ret = mdp_dsi_cmd_config(pinfo, &(panel->fb)); |
| 116 | if (ret) |
| 117 | goto msm_display_config_out; |
| 118 | break; |
Channagoud Kadabi | 43000a6 | 2012-06-28 18:23:24 +0530 | [diff] [blame] | 119 | case LCDC_PANEL: |
| 120 | dprintf(INFO, "Config LCDC PANEL.\n"); |
| 121 | ret = mdp_lcdc_config(pinfo, &(panel->fb)); |
| 122 | if (ret) |
| 123 | goto msm_display_config_out; |
| 124 | break; |
Ajay Singh Parmar | 7c1cd52 | 2013-02-13 20:33:49 +0530 | [diff] [blame] | 125 | case HDMI_PANEL: |
| 126 | dprintf(INFO, "Config HDMI PANEL.\n"); |
| 127 | ret = hdmi_dtv_init(); |
| 128 | if (ret) |
| 129 | goto msm_display_config_out; |
| 130 | break; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 131 | default: |
| 132 | return ERR_INVALID_ARGS; |
| 133 | }; |
| 134 | |
| 135 | if (pinfo->config) |
| 136 | ret = pinfo->config((void *)pinfo); |
| 137 | |
| 138 | msm_display_config_out: |
| 139 | return ret; |
| 140 | } |
| 141 | |
| 142 | int msm_display_on() |
| 143 | { |
| 144 | int ret = NO_ERROR; |
| 145 | struct msm_panel_info *pinfo; |
| 146 | |
| 147 | if (!panel) |
| 148 | return ERR_INVALID_ARGS; |
| 149 | |
| 150 | pinfo = &(panel->panel_info); |
| 151 | |
| 152 | switch (pinfo->type) { |
| 153 | case LVDS_PANEL: |
| 154 | dprintf(INFO, "Turn on LVDS PANEL.\n"); |
| 155 | ret = mdp_lcdc_on(panel); |
| 156 | if (ret) |
| 157 | goto msm_display_on_out; |
| 158 | ret = lvds_on(panel); |
| 159 | if (ret) |
| 160 | goto msm_display_on_out; |
| 161 | break; |
| 162 | case MIPI_VIDEO_PANEL: |
| 163 | dprintf(INFO, "Turn on MIPI_VIDEO_PANEL.\n"); |
| 164 | ret = mdp_dsi_video_on(); |
| 165 | if (ret) |
| 166 | goto msm_display_on_out; |
| 167 | ret = mipi_dsi_on(); |
| 168 | if (ret) |
| 169 | goto msm_display_on_out; |
| 170 | break; |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 171 | case MIPI_CMD_PANEL: |
| 172 | dprintf(INFO, "Turn on MIPI_CMD_PANEL.\n"); |
| 173 | ret = mdp_dma_on(); |
| 174 | if (ret) |
| 175 | goto msm_display_on_out; |
| 176 | ret = mipi_cmd_trigger(); |
| 177 | if (ret) |
| 178 | goto msm_display_on_out; |
| 179 | break; |
Channagoud Kadabi | 43000a6 | 2012-06-28 18:23:24 +0530 | [diff] [blame] | 180 | case LCDC_PANEL: |
| 181 | dprintf(INFO, "Turn on LCDC PANEL.\n"); |
| 182 | ret = mdp_lcdc_on(panel); |
| 183 | if (ret) |
| 184 | goto msm_display_on_out; |
| 185 | break; |
Ajay Singh Parmar | 7c1cd52 | 2013-02-13 20:33:49 +0530 | [diff] [blame] | 186 | case HDMI_PANEL: |
| 187 | dprintf(INFO, "Turn on HDMI PANEL.\n"); |
| 188 | ret = hdmi_dtv_on(); |
| 189 | if (ret) |
| 190 | goto msm_display_on_out; |
| 191 | |
| 192 | ret = hdmi_msm_turn_on(); |
| 193 | if (ret) |
| 194 | goto msm_display_on_out; |
| 195 | break; |
| 196 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 197 | default: |
| 198 | return ERR_INVALID_ARGS; |
| 199 | }; |
| 200 | |
| 201 | if (pinfo->on) |
| 202 | ret = pinfo->on(); |
| 203 | |
| 204 | msm_display_on_out: |
| 205 | return ret; |
| 206 | } |
| 207 | |
| 208 | int msm_display_init(struct msm_fb_panel_data *pdata) |
| 209 | { |
| 210 | int ret = NO_ERROR; |
| 211 | |
| 212 | panel = pdata; |
| 213 | if (!panel) { |
| 214 | ret = ERR_INVALID_ARGS; |
| 215 | goto msm_display_init_out; |
| 216 | } |
| 217 | |
| 218 | /* Enable clock */ |
| 219 | if (pdata->clk_func) |
| 220 | ret = pdata->clk_func(1); |
| 221 | |
| 222 | if (ret) |
| 223 | goto msm_display_init_out; |
| 224 | |
| 225 | /* Turn on panel */ |
| 226 | if (pdata->power_func) |
| 227 | ret = pdata->power_func(1); |
| 228 | |
| 229 | if (ret) |
| 230 | goto msm_display_init_out; |
| 231 | |
| 232 | ret = msm_fb_alloc(&(panel->fb)); |
| 233 | if (ret) |
| 234 | goto msm_display_init_out; |
| 235 | |
| 236 | fbcon_setup(&(panel->fb)); |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 237 | display_image_on_screen(); |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 238 | ret = msm_display_config(); |
| 239 | if (ret) |
| 240 | goto msm_display_init_out; |
| 241 | |
| 242 | ret = msm_display_on(); |
| 243 | if (ret) |
| 244 | goto msm_display_init_out; |
| 245 | |
| 246 | msm_display_init_out: |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | int msm_display_off() |
| 251 | { |
| 252 | int ret = NO_ERROR; |
| 253 | struct msm_panel_info *pinfo; |
| 254 | |
| 255 | if (!panel) |
| 256 | return ERR_INVALID_ARGS; |
| 257 | |
| 258 | pinfo = &(panel->panel_info); |
| 259 | |
| 260 | switch (pinfo->type) { |
| 261 | case LVDS_PANEL: |
| 262 | dprintf(INFO, "Turn off LVDS PANEL.\n"); |
| 263 | mdp_lcdc_off(); |
| 264 | break; |
| 265 | case MIPI_VIDEO_PANEL: |
| 266 | dprintf(INFO, "Turn off MIPI_VIDEO_PANEL.\n"); |
| 267 | ret = mdp_dsi_video_off(); |
| 268 | if (ret) |
| 269 | goto msm_display_off_out; |
| 270 | ret = mipi_dsi_off(); |
| 271 | if (ret) |
| 272 | goto msm_display_off_out; |
| 273 | break; |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame] | 274 | case MIPI_CMD_PANEL: |
| 275 | dprintf(INFO, "Turn off MIPI_CMD_PANEL.\n"); |
| 276 | ret = mdp_dsi_cmd_off(); |
| 277 | if (ret) |
| 278 | goto msm_display_off_out; |
| 279 | ret = mipi_dsi_off(); |
| 280 | if (ret) |
| 281 | goto msm_display_off_out; |
| 282 | break; |
Channagoud Kadabi | 43000a6 | 2012-06-28 18:23:24 +0530 | [diff] [blame] | 283 | case LCDC_PANEL: |
| 284 | dprintf(INFO, "Turn off LCDC PANEL.\n"); |
| 285 | mdp_lcdc_off(); |
| 286 | break; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 287 | default: |
| 288 | return ERR_INVALID_ARGS; |
| 289 | }; |
| 290 | |
Siddhartha Agrawal | 03f6d21 | 2013-02-19 13:50:52 -0800 | [diff] [blame^] | 291 | if (target_cont_splash_screen()) { |
| 292 | dprintf(INFO, "Continuous splash enabled, keeping panel alive.\n"); |
| 293 | return NO_ERROR; |
| 294 | } |
| 295 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 296 | if (pinfo->off) |
| 297 | ret = pinfo->off(); |
| 298 | |
| 299 | /* Disable clock */ |
| 300 | if (panel->clk_func) |
| 301 | ret = panel->clk_func(0); |
| 302 | |
| 303 | if (ret) |
| 304 | goto msm_display_off_out; |
| 305 | |
| 306 | /* Disable panel */ |
| 307 | if (panel->power_func) |
| 308 | ret = panel->power_func(0); |
| 309 | |
| 310 | msm_display_off_out: |
| 311 | return ret; |
| 312 | } |