blob: a3d77ce62c19c7bf93b89f1194294e3999350c75 [file] [log] [blame]
Shashank Mittal4bfb2e32012-04-16 10:56:27 -07001/* 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
35static struct msm_fb_panel_data *panel;
36
37extern int lvds_on(struct msm_fb_panel_data *pdata);
38
39static 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
55int 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;
Amir Samuelov2d4ba162012-07-22 11:53:14 +030080
81 if (pinfo->early_config)
82 ret = pinfo->early_config((void *)pinfo);
83
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070084 ret = mdp_dsi_video_config(pinfo, &(panel->fb));
85 if (ret)
86 goto msm_display_config_out;
87 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +053088 case MIPI_CMD_PANEL:
89 dprintf(INFO, "Config MIPI_CMD_PANEL.\n");
90 ret = mipi_config(panel);
91 if (ret)
92 goto msm_display_config_out;
93 ret = mdp_dsi_cmd_config(pinfo, &(panel->fb));
94 if (ret)
95 goto msm_display_config_out;
96 break;
Channagoud Kadabi43000a62012-06-28 18:23:24 +053097 case LCDC_PANEL:
98 dprintf(INFO, "Config LCDC PANEL.\n");
99 ret = mdp_lcdc_config(pinfo, &(panel->fb));
100 if (ret)
101 goto msm_display_config_out;
102 break;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700103 default:
104 return ERR_INVALID_ARGS;
105 };
106
107 if (pinfo->config)
108 ret = pinfo->config((void *)pinfo);
109
110msm_display_config_out:
111 return ret;
112}
113
114int msm_display_on()
115{
116 int ret = NO_ERROR;
117 struct msm_panel_info *pinfo;
118
119 if (!panel)
120 return ERR_INVALID_ARGS;
121
122 pinfo = &(panel->panel_info);
123
124 switch (pinfo->type) {
125 case LVDS_PANEL:
126 dprintf(INFO, "Turn on LVDS PANEL.\n");
127 ret = mdp_lcdc_on(panel);
128 if (ret)
129 goto msm_display_on_out;
130 ret = lvds_on(panel);
131 if (ret)
132 goto msm_display_on_out;
133 break;
134 case MIPI_VIDEO_PANEL:
135 dprintf(INFO, "Turn on MIPI_VIDEO_PANEL.\n");
136 ret = mdp_dsi_video_on();
137 if (ret)
138 goto msm_display_on_out;
139 ret = mipi_dsi_on();
140 if (ret)
141 goto msm_display_on_out;
142 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530143 case MIPI_CMD_PANEL:
144 dprintf(INFO, "Turn on MIPI_CMD_PANEL.\n");
145 ret = mdp_dma_on();
146 if (ret)
147 goto msm_display_on_out;
148 ret = mipi_cmd_trigger();
149 if (ret)
150 goto msm_display_on_out;
151 break;
Channagoud Kadabi43000a62012-06-28 18:23:24 +0530152 case LCDC_PANEL:
153 dprintf(INFO, "Turn on LCDC PANEL.\n");
154 ret = mdp_lcdc_on(panel);
155 if (ret)
156 goto msm_display_on_out;
157 break;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700158 default:
159 return ERR_INVALID_ARGS;
160 };
161
162 if (pinfo->on)
163 ret = pinfo->on();
164
165msm_display_on_out:
166 return ret;
167}
168
169int msm_display_init(struct msm_fb_panel_data *pdata)
170{
171 int ret = NO_ERROR;
172
173 panel = pdata;
174 if (!panel) {
175 ret = ERR_INVALID_ARGS;
176 goto msm_display_init_out;
177 }
178
179 /* Enable clock */
180 if (pdata->clk_func)
181 ret = pdata->clk_func(1);
182
183 if (ret)
184 goto msm_display_init_out;
185
186 /* Turn on panel */
187 if (pdata->power_func)
188 ret = pdata->power_func(1);
189
190 if (ret)
191 goto msm_display_init_out;
192
193 ret = msm_fb_alloc(&(panel->fb));
194 if (ret)
195 goto msm_display_init_out;
196
197 fbcon_setup(&(panel->fb));
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530198 display_image_on_screen();
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700199 ret = msm_display_config();
200 if (ret)
201 goto msm_display_init_out;
202
203 ret = msm_display_on();
204 if (ret)
205 goto msm_display_init_out;
206
207msm_display_init_out:
208 return ret;
209}
210
211int msm_display_off()
212{
213 int ret = NO_ERROR;
214 struct msm_panel_info *pinfo;
215
216 if (!panel)
217 return ERR_INVALID_ARGS;
218
219 pinfo = &(panel->panel_info);
220
221 switch (pinfo->type) {
222 case LVDS_PANEL:
223 dprintf(INFO, "Turn off LVDS PANEL.\n");
224 mdp_lcdc_off();
225 break;
226 case MIPI_VIDEO_PANEL:
227 dprintf(INFO, "Turn off MIPI_VIDEO_PANEL.\n");
228 ret = mdp_dsi_video_off();
229 if (ret)
230 goto msm_display_off_out;
231 ret = mipi_dsi_off();
232 if (ret)
233 goto msm_display_off_out;
234 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530235 case MIPI_CMD_PANEL:
236 dprintf(INFO, "Turn off MIPI_CMD_PANEL.\n");
237 ret = mdp_dsi_cmd_off();
238 if (ret)
239 goto msm_display_off_out;
240 ret = mipi_dsi_off();
241 if (ret)
242 goto msm_display_off_out;
243 break;
Channagoud Kadabi43000a62012-06-28 18:23:24 +0530244 case LCDC_PANEL:
245 dprintf(INFO, "Turn off LCDC PANEL.\n");
246 mdp_lcdc_off();
247 break;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700248 default:
249 return ERR_INVALID_ARGS;
250 };
251
252 if (pinfo->off)
253 ret = pinfo->off();
254
255 /* Disable clock */
256 if (panel->clk_func)
257 ret = panel->clk_func(0);
258
259 if (ret)
260 goto msm_display_off_out;
261
262 /* Disable panel */
263 if (panel->power_func)
264 ret = panel->power_func(0);
265
266msm_display_off_out:
267 return ret;
268}