blob: c6d02c4f38794a8c191e348d03541321c798154d [file] [log] [blame]
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Shashank Mittal4bfb2e32012-04-16 10:56:27 -07002 *
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 Agrawal7e2e2152013-01-23 17:06:58 -080012 * * Neither the name of The Linux Foundation nor the names of its
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070013 * 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 Jadi5f0fab02013-03-18 14:50:52 -070034#include <boot_stats.h>
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070035
Ajay Singh Parmar7c1cd522013-02-13 20:33:49 +053036#ifndef DISPLAY_TYPE_HDMI
37static int hdmi_dtv_init(void)
38{
39 return 0;
40}
41
42static int hdmi_dtv_on(void)
43{
44 return 0;
45}
46
47static int hdmi_msm_turn_on(void)
48{
49 return 0;
50}
51#endif
52
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070053static struct msm_fb_panel_data *panel;
54
55extern int lvds_on(struct msm_fb_panel_data *pdata);
56
57static 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
73int msm_display_config()
74{
75 int ret = NO_ERROR;
76 struct msm_panel_info *pinfo;
77
78 if (!panel)
79 return ERR_INVALID_ARGS;
80
81 pinfo = &(panel->panel_info);
82
83 /* Set MDP revision */
84 mdp_set_revision(panel->mdp_rev);
85
86 switch (pinfo->type) {
87 case LVDS_PANEL:
88 dprintf(INFO, "Config LVDS_PANEL.\n");
89 ret = mdp_lcdc_config(pinfo, &(panel->fb));
90 if (ret)
91 goto msm_display_config_out;
92 break;
93 case MIPI_VIDEO_PANEL:
94 dprintf(INFO, "Config MIPI_VIDEO_PANEL.\n");
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -080095
96 if (mdp_get_revision() == MDP_REV_50)
97 ret = mdss_dsi_config(panel);
98 else
99 ret = mipi_config(panel);
100
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700101 if (ret)
102 goto msm_display_config_out;
Amir Samuelov2d4ba162012-07-22 11:53:14 +0300103
104 if (pinfo->early_config)
105 ret = pinfo->early_config((void *)pinfo);
106
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700107 ret = mdp_dsi_video_config(pinfo, &(panel->fb));
108 if (ret)
109 goto msm_display_config_out;
110 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530111 case MIPI_CMD_PANEL:
112 dprintf(INFO, "Config MIPI_CMD_PANEL.\n");
Siddhartha Agrawale900fdf2013-04-21 16:18:17 -0700113
114 if (mdp_get_revision() == MDP_REV_50)
115 ret = mdss_dsi_config(panel);
116 else
117 ret = mipi_config(panel);
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530118 if (ret)
119 goto msm_display_config_out;
Siddhartha Agrawale900fdf2013-04-21 16:18:17 -0700120
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530121 ret = mdp_dsi_cmd_config(pinfo, &(panel->fb));
122 if (ret)
123 goto msm_display_config_out;
124 break;
Channagoud Kadabi43000a62012-06-28 18:23:24 +0530125 case LCDC_PANEL:
126 dprintf(INFO, "Config LCDC PANEL.\n");
127 ret = mdp_lcdc_config(pinfo, &(panel->fb));
128 if (ret)
129 goto msm_display_config_out;
130 break;
Ajay Singh Parmar7c1cd522013-02-13 20:33:49 +0530131 case HDMI_PANEL:
132 dprintf(INFO, "Config HDMI PANEL.\n");
133 ret = hdmi_dtv_init();
134 if (ret)
135 goto msm_display_config_out;
136 break;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700137 default:
138 return ERR_INVALID_ARGS;
139 };
140
141 if (pinfo->config)
142 ret = pinfo->config((void *)pinfo);
143
144msm_display_config_out:
145 return ret;
146}
147
148int msm_display_on()
149{
150 int ret = NO_ERROR;
151 struct msm_panel_info *pinfo;
152
153 if (!panel)
154 return ERR_INVALID_ARGS;
155
Amol Jadi5f0fab02013-03-18 14:50:52 -0700156 bs_set_timestamp(BS_SPLASH_SCREEN_DISPLAY);
157
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700158 pinfo = &(panel->panel_info);
159
160 switch (pinfo->type) {
161 case LVDS_PANEL:
162 dprintf(INFO, "Turn on LVDS PANEL.\n");
163 ret = mdp_lcdc_on(panel);
164 if (ret)
165 goto msm_display_on_out;
166 ret = lvds_on(panel);
167 if (ret)
168 goto msm_display_on_out;
169 break;
170 case MIPI_VIDEO_PANEL:
171 dprintf(INFO, "Turn on MIPI_VIDEO_PANEL.\n");
172 ret = mdp_dsi_video_on();
173 if (ret)
174 goto msm_display_on_out;
175 ret = mipi_dsi_on();
176 if (ret)
177 goto msm_display_on_out;
178 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530179 case MIPI_CMD_PANEL:
180 dprintf(INFO, "Turn on MIPI_CMD_PANEL.\n");
181 ret = mdp_dma_on();
182 if (ret)
183 goto msm_display_on_out;
Siddhartha Agrawale900fdf2013-04-21 16:18:17 -0700184 if (mdp_get_revision() != MDP_REV_50) {
185 ret = mipi_cmd_trigger();
186 if (ret)
187 goto msm_display_on_out;
188 }
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530189 break;
Channagoud Kadabi43000a62012-06-28 18:23:24 +0530190 case LCDC_PANEL:
191 dprintf(INFO, "Turn on LCDC PANEL.\n");
192 ret = mdp_lcdc_on(panel);
193 if (ret)
194 goto msm_display_on_out;
195 break;
Ajay Singh Parmar7c1cd522013-02-13 20:33:49 +0530196 case HDMI_PANEL:
197 dprintf(INFO, "Turn on HDMI PANEL.\n");
198 ret = hdmi_dtv_on();
199 if (ret)
200 goto msm_display_on_out;
201
202 ret = hdmi_msm_turn_on();
203 if (ret)
204 goto msm_display_on_out;
205 break;
206
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700207 default:
208 return ERR_INVALID_ARGS;
209 };
210
211 if (pinfo->on)
212 ret = pinfo->on();
213
214msm_display_on_out:
215 return ret;
216}
217
218int msm_display_init(struct msm_fb_panel_data *pdata)
219{
220 int ret = NO_ERROR;
221
222 panel = pdata;
223 if (!panel) {
224 ret = ERR_INVALID_ARGS;
225 goto msm_display_init_out;
226 }
227
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800228 /* Turn on panel */
229 if (pdata->power_func)
230 ret = pdata->power_func(1);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700231
232 if (ret)
233 goto msm_display_init_out;
234
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800235 /* Enable clock */
236 if (pdata->clk_func)
237 ret = pdata->clk_func(1);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700238
239 if (ret)
240 goto msm_display_init_out;
241
242 ret = msm_fb_alloc(&(panel->fb));
243 if (ret)
244 goto msm_display_init_out;
245
246 fbcon_setup(&(panel->fb));
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530247 display_image_on_screen();
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700248 ret = msm_display_config();
249 if (ret)
250 goto msm_display_init_out;
251
252 ret = msm_display_on();
253 if (ret)
254 goto msm_display_init_out;
255
256msm_display_init_out:
257 return ret;
258}
259
260int msm_display_off()
261{
262 int ret = NO_ERROR;
263 struct msm_panel_info *pinfo;
264
265 if (!panel)
266 return ERR_INVALID_ARGS;
267
268 pinfo = &(panel->panel_info);
269
270 switch (pinfo->type) {
271 case LVDS_PANEL:
272 dprintf(INFO, "Turn off LVDS PANEL.\n");
273 mdp_lcdc_off();
274 break;
275 case MIPI_VIDEO_PANEL:
276 dprintf(INFO, "Turn off MIPI_VIDEO_PANEL.\n");
277 ret = mdp_dsi_video_off();
278 if (ret)
279 goto msm_display_off_out;
280 ret = mipi_dsi_off();
281 if (ret)
282 goto msm_display_off_out;
283 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530284 case MIPI_CMD_PANEL:
285 dprintf(INFO, "Turn off MIPI_CMD_PANEL.\n");
286 ret = mdp_dsi_cmd_off();
287 if (ret)
288 goto msm_display_off_out;
289 ret = mipi_dsi_off();
290 if (ret)
291 goto msm_display_off_out;
292 break;
Channagoud Kadabi43000a62012-06-28 18:23:24 +0530293 case LCDC_PANEL:
294 dprintf(INFO, "Turn off LCDC PANEL.\n");
295 mdp_lcdc_off();
296 break;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700297 default:
298 return ERR_INVALID_ARGS;
299 };
300
Siddhartha Agrawal03f6d212013-02-19 13:50:52 -0800301 if (target_cont_splash_screen()) {
302 dprintf(INFO, "Continuous splash enabled, keeping panel alive.\n");
303 return NO_ERROR;
304 }
305
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700306 if (pinfo->off)
307 ret = pinfo->off();
308
309 /* Disable clock */
310 if (panel->clk_func)
311 ret = panel->clk_func(0);
312
313 if (ret)
314 goto msm_display_off_out;
315
316 /* Disable panel */
317 if (panel->power_func)
318 ret = panel->power_func(0);
319
320msm_display_off_out:
321 return ret;
322}