blob: 7061b1ab5bc400f812f2e57f8f44510541be9ed7 [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;
Terence Hampsonf49ff4e2013-06-18 15:11:31 -040076 int mdp_rev;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070077 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 Agrawal7e2e2152013-01-23 17:06:58 -080096
Terence Hampsonf49ff4e2013-06-18 15:11:31 -040097 mdp_rev = mdp_get_revision();
98 if (mdp_rev == MDP_REV_50 || mdp_rev == MDP_REV_304)
Siddhartha Agrawal7e2e2152013-01-23 17:06:58 -080099 ret = mdss_dsi_config(panel);
100 else
101 ret = mipi_config(panel);
102
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700103 if (ret)
104 goto msm_display_config_out;
Amir Samuelov2d4ba162012-07-22 11:53:14 +0300105
106 if (pinfo->early_config)
107 ret = pinfo->early_config((void *)pinfo);
108
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700109 ret = mdp_dsi_video_config(pinfo, &(panel->fb));
110 if (ret)
111 goto msm_display_config_out;
112 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530113 case MIPI_CMD_PANEL:
114 dprintf(INFO, "Config MIPI_CMD_PANEL.\n");
Siddhartha Agrawale900fdf2013-04-21 16:18:17 -0700115
116 if (mdp_get_revision() == MDP_REV_50)
117 ret = mdss_dsi_config(panel);
118 else
119 ret = mipi_config(panel);
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530120 if (ret)
121 goto msm_display_config_out;
Siddhartha Agrawale900fdf2013-04-21 16:18:17 -0700122
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530123 ret = mdp_dsi_cmd_config(pinfo, &(panel->fb));
124 if (ret)
125 goto msm_display_config_out;
126 break;
Channagoud Kadabi43000a62012-06-28 18:23:24 +0530127 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 Parmar7c1cd522013-02-13 20:33:49 +0530133 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 Mittal4bfb2e32012-04-16 10:56:27 -0700139 default:
140 return ERR_INVALID_ARGS;
141 };
142
143 if (pinfo->config)
144 ret = pinfo->config((void *)pinfo);
145
146msm_display_config_out:
147 return ret;
148}
149
150int msm_display_on()
151{
152 int ret = NO_ERROR;
153 struct msm_panel_info *pinfo;
154
155 if (!panel)
156 return ERR_INVALID_ARGS;
157
Amol Jadi5f0fab02013-03-18 14:50:52 -0700158 bs_set_timestamp(BS_SPLASH_SCREEN_DISPLAY);
159
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700160 pinfo = &(panel->panel_info);
161
162 switch (pinfo->type) {
163 case LVDS_PANEL:
164 dprintf(INFO, "Turn on LVDS PANEL.\n");
165 ret = mdp_lcdc_on(panel);
166 if (ret)
167 goto msm_display_on_out;
168 ret = lvds_on(panel);
169 if (ret)
170 goto msm_display_on_out;
171 break;
172 case MIPI_VIDEO_PANEL:
173 dprintf(INFO, "Turn on MIPI_VIDEO_PANEL.\n");
174 ret = mdp_dsi_video_on();
175 if (ret)
176 goto msm_display_on_out;
177 ret = mipi_dsi_on();
178 if (ret)
179 goto msm_display_on_out;
180 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530181 case MIPI_CMD_PANEL:
182 dprintf(INFO, "Turn on MIPI_CMD_PANEL.\n");
183 ret = mdp_dma_on();
184 if (ret)
185 goto msm_display_on_out;
Siddhartha Agrawale900fdf2013-04-21 16:18:17 -0700186 if (mdp_get_revision() != MDP_REV_50) {
187 ret = mipi_cmd_trigger();
188 if (ret)
189 goto msm_display_on_out;
190 }
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530191 break;
Channagoud Kadabi43000a62012-06-28 18:23:24 +0530192 case LCDC_PANEL:
193 dprintf(INFO, "Turn on LCDC PANEL.\n");
194 ret = mdp_lcdc_on(panel);
195 if (ret)
196 goto msm_display_on_out;
197 break;
Ajay Singh Parmar7c1cd522013-02-13 20:33:49 +0530198 case HDMI_PANEL:
199 dprintf(INFO, "Turn on HDMI PANEL.\n");
200 ret = hdmi_dtv_on();
201 if (ret)
202 goto msm_display_on_out;
203
204 ret = hdmi_msm_turn_on();
205 if (ret)
206 goto msm_display_on_out;
207 break;
208
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700209 default:
210 return ERR_INVALID_ARGS;
211 };
212
213 if (pinfo->on)
214 ret = pinfo->on();
215
216msm_display_on_out:
217 return ret;
218}
219
220int msm_display_init(struct msm_fb_panel_data *pdata)
221{
222 int ret = NO_ERROR;
223
224 panel = pdata;
225 if (!panel) {
226 ret = ERR_INVALID_ARGS;
227 goto msm_display_init_out;
228 }
229
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800230 /* Turn on panel */
231 if (pdata->power_func)
232 ret = pdata->power_func(1);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700233
234 if (ret)
235 goto msm_display_init_out;
236
Chandan Uddaraju932723b2013-02-21 18:36:20 -0800237 /* Enable clock */
238 if (pdata->clk_func)
239 ret = pdata->clk_func(1);
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700240
241 if (ret)
242 goto msm_display_init_out;
243
244 ret = msm_fb_alloc(&(panel->fb));
245 if (ret)
246 goto msm_display_init_out;
247
248 fbcon_setup(&(panel->fb));
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530249 display_image_on_screen();
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700250 ret = msm_display_config();
251 if (ret)
252 goto msm_display_init_out;
253
254 ret = msm_display_on();
255 if (ret)
256 goto msm_display_init_out;
257
258msm_display_init_out:
259 return ret;
260}
261
262int msm_display_off()
263{
264 int ret = NO_ERROR;
265 struct msm_panel_info *pinfo;
266
267 if (!panel)
268 return ERR_INVALID_ARGS;
269
270 pinfo = &(panel->panel_info);
271
272 switch (pinfo->type) {
273 case LVDS_PANEL:
274 dprintf(INFO, "Turn off LVDS PANEL.\n");
275 mdp_lcdc_off();
276 break;
277 case MIPI_VIDEO_PANEL:
278 dprintf(INFO, "Turn off MIPI_VIDEO_PANEL.\n");
279 ret = mdp_dsi_video_off();
280 if (ret)
281 goto msm_display_off_out;
282 ret = mipi_dsi_off();
283 if (ret)
284 goto msm_display_off_out;
285 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530286 case MIPI_CMD_PANEL:
287 dprintf(INFO, "Turn off MIPI_CMD_PANEL.\n");
288 ret = mdp_dsi_cmd_off();
289 if (ret)
290 goto msm_display_off_out;
291 ret = mipi_dsi_off();
292 if (ret)
293 goto msm_display_off_out;
294 break;
Channagoud Kadabi43000a62012-06-28 18:23:24 +0530295 case LCDC_PANEL:
296 dprintf(INFO, "Turn off LCDC PANEL.\n");
297 mdp_lcdc_off();
298 break;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700299 default:
300 return ERR_INVALID_ARGS;
301 };
302
Siddhartha Agrawal03f6d212013-02-19 13:50:52 -0800303 if (target_cont_splash_screen()) {
304 dprintf(INFO, "Continuous splash enabled, keeping panel alive.\n");
305 return NO_ERROR;
306 }
307
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700308 if (pinfo->off)
309 ret = pinfo->off();
310
311 /* Disable clock */
312 if (panel->clk_func)
313 ret = panel->clk_func(0);
314
315 if (ret)
316 goto msm_display_off_out;
317
318 /* Disable panel */
319 if (panel->power_func)
320 ret = panel->power_func(0);
321
322msm_display_off_out:
323 return ret;
324}