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