Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 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. |
| 12 | * * Neither the name of Code Aurora Forum, Inc. 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 "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"); |
| 77 | ret = mipi_config(panel); |
| 78 | if (ret) |
| 79 | goto msm_display_config_out; |
| 80 | ret = mdp_dsi_video_config(pinfo, &(panel->fb)); |
| 81 | if (ret) |
| 82 | goto msm_display_config_out; |
| 83 | break; |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame^] | 84 | case MIPI_CMD_PANEL: |
| 85 | dprintf(INFO, "Config MIPI_CMD_PANEL.\n"); |
| 86 | ret = mipi_config(panel); |
| 87 | if (ret) |
| 88 | goto msm_display_config_out; |
| 89 | ret = mdp_dsi_cmd_config(pinfo, &(panel->fb)); |
| 90 | if (ret) |
| 91 | goto msm_display_config_out; |
| 92 | break; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 93 | default: |
| 94 | return ERR_INVALID_ARGS; |
| 95 | }; |
| 96 | |
| 97 | if (pinfo->config) |
| 98 | ret = pinfo->config((void *)pinfo); |
| 99 | |
| 100 | msm_display_config_out: |
| 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | int msm_display_on() |
| 105 | { |
| 106 | int ret = NO_ERROR; |
| 107 | struct msm_panel_info *pinfo; |
| 108 | |
| 109 | if (!panel) |
| 110 | return ERR_INVALID_ARGS; |
| 111 | |
| 112 | pinfo = &(panel->panel_info); |
| 113 | |
| 114 | switch (pinfo->type) { |
| 115 | case LVDS_PANEL: |
| 116 | dprintf(INFO, "Turn on LVDS PANEL.\n"); |
| 117 | ret = mdp_lcdc_on(panel); |
| 118 | if (ret) |
| 119 | goto msm_display_on_out; |
| 120 | ret = lvds_on(panel); |
| 121 | if (ret) |
| 122 | goto msm_display_on_out; |
| 123 | break; |
| 124 | case MIPI_VIDEO_PANEL: |
| 125 | dprintf(INFO, "Turn on MIPI_VIDEO_PANEL.\n"); |
| 126 | ret = mdp_dsi_video_on(); |
| 127 | if (ret) |
| 128 | goto msm_display_on_out; |
| 129 | ret = mipi_dsi_on(); |
| 130 | if (ret) |
| 131 | goto msm_display_on_out; |
| 132 | break; |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame^] | 133 | case MIPI_CMD_PANEL: |
| 134 | dprintf(INFO, "Turn on MIPI_CMD_PANEL.\n"); |
| 135 | ret = mdp_dma_on(); |
| 136 | if (ret) |
| 137 | goto msm_display_on_out; |
| 138 | ret = mipi_cmd_trigger(); |
| 139 | if (ret) |
| 140 | goto msm_display_on_out; |
| 141 | break; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 142 | default: |
| 143 | return ERR_INVALID_ARGS; |
| 144 | }; |
| 145 | |
| 146 | if (pinfo->on) |
| 147 | ret = pinfo->on(); |
| 148 | |
| 149 | msm_display_on_out: |
| 150 | return ret; |
| 151 | } |
| 152 | |
| 153 | int msm_display_init(struct msm_fb_panel_data *pdata) |
| 154 | { |
| 155 | int ret = NO_ERROR; |
| 156 | |
| 157 | panel = pdata; |
| 158 | if (!panel) { |
| 159 | ret = ERR_INVALID_ARGS; |
| 160 | goto msm_display_init_out; |
| 161 | } |
| 162 | |
| 163 | /* Enable clock */ |
| 164 | if (pdata->clk_func) |
| 165 | ret = pdata->clk_func(1); |
| 166 | |
| 167 | if (ret) |
| 168 | goto msm_display_init_out; |
| 169 | |
| 170 | /* Turn on panel */ |
| 171 | if (pdata->power_func) |
| 172 | ret = pdata->power_func(1); |
| 173 | |
| 174 | if (ret) |
| 175 | goto msm_display_init_out; |
| 176 | |
| 177 | ret = msm_fb_alloc(&(panel->fb)); |
| 178 | if (ret) |
| 179 | goto msm_display_init_out; |
| 180 | |
| 181 | fbcon_setup(&(panel->fb)); |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame^] | 182 | display_image_on_screen(); |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 183 | ret = msm_display_config(); |
| 184 | if (ret) |
| 185 | goto msm_display_init_out; |
| 186 | |
| 187 | ret = msm_display_on(); |
| 188 | if (ret) |
| 189 | goto msm_display_init_out; |
| 190 | |
| 191 | msm_display_init_out: |
| 192 | return ret; |
| 193 | } |
| 194 | |
| 195 | int msm_display_off() |
| 196 | { |
| 197 | int ret = NO_ERROR; |
| 198 | struct msm_panel_info *pinfo; |
| 199 | |
| 200 | if (!panel) |
| 201 | return ERR_INVALID_ARGS; |
| 202 | |
| 203 | pinfo = &(panel->panel_info); |
| 204 | |
| 205 | switch (pinfo->type) { |
| 206 | case LVDS_PANEL: |
| 207 | dprintf(INFO, "Turn off LVDS PANEL.\n"); |
| 208 | mdp_lcdc_off(); |
| 209 | break; |
| 210 | case MIPI_VIDEO_PANEL: |
| 211 | dprintf(INFO, "Turn off MIPI_VIDEO_PANEL.\n"); |
| 212 | ret = mdp_dsi_video_off(); |
| 213 | if (ret) |
| 214 | goto msm_display_off_out; |
| 215 | ret = mipi_dsi_off(); |
| 216 | if (ret) |
| 217 | goto msm_display_off_out; |
| 218 | break; |
Channagoud Kadabi | 10189fd | 2012-05-25 13:33:39 +0530 | [diff] [blame^] | 219 | case MIPI_CMD_PANEL: |
| 220 | dprintf(INFO, "Turn off MIPI_CMD_PANEL.\n"); |
| 221 | ret = mdp_dsi_cmd_off(); |
| 222 | if (ret) |
| 223 | goto msm_display_off_out; |
| 224 | ret = mipi_dsi_off(); |
| 225 | if (ret) |
| 226 | goto msm_display_off_out; |
| 227 | break; |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 228 | default: |
| 229 | return ERR_INVALID_ARGS; |
| 230 | }; |
| 231 | |
| 232 | if (pinfo->off) |
| 233 | ret = pinfo->off(); |
| 234 | |
| 235 | /* Disable clock */ |
| 236 | if (panel->clk_func) |
| 237 | ret = panel->clk_func(0); |
| 238 | |
| 239 | if (ret) |
| 240 | goto msm_display_off_out; |
| 241 | |
| 242 | /* Disable panel */ |
| 243 | if (panel->power_func) |
| 244 | ret = panel->power_func(0); |
| 245 | |
| 246 | msm_display_off_out: |
| 247 | return ret; |
| 248 | } |