blob: 011fc1584e4462dc61778c297850d5907763629f [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;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -070097 default:
98 return ERR_INVALID_ARGS;
99 };
100
101 if (pinfo->config)
102 ret = pinfo->config((void *)pinfo);
103
104msm_display_config_out:
105 return ret;
106}
107
108int msm_display_on()
109{
110 int ret = NO_ERROR;
111 struct msm_panel_info *pinfo;
112
113 if (!panel)
114 return ERR_INVALID_ARGS;
115
116 pinfo = &(panel->panel_info);
117
118 switch (pinfo->type) {
119 case LVDS_PANEL:
120 dprintf(INFO, "Turn on LVDS PANEL.\n");
121 ret = mdp_lcdc_on(panel);
122 if (ret)
123 goto msm_display_on_out;
124 ret = lvds_on(panel);
125 if (ret)
126 goto msm_display_on_out;
127 break;
128 case MIPI_VIDEO_PANEL:
129 dprintf(INFO, "Turn on MIPI_VIDEO_PANEL.\n");
130 ret = mdp_dsi_video_on();
131 if (ret)
132 goto msm_display_on_out;
133 ret = mipi_dsi_on();
134 if (ret)
135 goto msm_display_on_out;
136 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530137 case MIPI_CMD_PANEL:
138 dprintf(INFO, "Turn on MIPI_CMD_PANEL.\n");
139 ret = mdp_dma_on();
140 if (ret)
141 goto msm_display_on_out;
142 ret = mipi_cmd_trigger();
143 if (ret)
144 goto msm_display_on_out;
145 break;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700146 default:
147 return ERR_INVALID_ARGS;
148 };
149
150 if (pinfo->on)
151 ret = pinfo->on();
152
153msm_display_on_out:
154 return ret;
155}
156
157int msm_display_init(struct msm_fb_panel_data *pdata)
158{
159 int ret = NO_ERROR;
160
161 panel = pdata;
162 if (!panel) {
163 ret = ERR_INVALID_ARGS;
164 goto msm_display_init_out;
165 }
166
167 /* Enable clock */
168 if (pdata->clk_func)
169 ret = pdata->clk_func(1);
170
171 if (ret)
172 goto msm_display_init_out;
173
174 /* Turn on panel */
175 if (pdata->power_func)
176 ret = pdata->power_func(1);
177
178 if (ret)
179 goto msm_display_init_out;
180
181 ret = msm_fb_alloc(&(panel->fb));
182 if (ret)
183 goto msm_display_init_out;
184
185 fbcon_setup(&(panel->fb));
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530186 display_image_on_screen();
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700187 ret = msm_display_config();
188 if (ret)
189 goto msm_display_init_out;
190
191 ret = msm_display_on();
192 if (ret)
193 goto msm_display_init_out;
194
195msm_display_init_out:
196 return ret;
197}
198
199int msm_display_off()
200{
201 int ret = NO_ERROR;
202 struct msm_panel_info *pinfo;
203
204 if (!panel)
205 return ERR_INVALID_ARGS;
206
207 pinfo = &(panel->panel_info);
208
209 switch (pinfo->type) {
210 case LVDS_PANEL:
211 dprintf(INFO, "Turn off LVDS PANEL.\n");
212 mdp_lcdc_off();
213 break;
214 case MIPI_VIDEO_PANEL:
215 dprintf(INFO, "Turn off MIPI_VIDEO_PANEL.\n");
216 ret = mdp_dsi_video_off();
217 if (ret)
218 goto msm_display_off_out;
219 ret = mipi_dsi_off();
220 if (ret)
221 goto msm_display_off_out;
222 break;
Channagoud Kadabi10189fd2012-05-25 13:33:39 +0530223 case MIPI_CMD_PANEL:
224 dprintf(INFO, "Turn off MIPI_CMD_PANEL.\n");
225 ret = mdp_dsi_cmd_off();
226 if (ret)
227 goto msm_display_off_out;
228 ret = mipi_dsi_off();
229 if (ret)
230 goto msm_display_off_out;
231 break;
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700232 default:
233 return ERR_INVALID_ARGS;
234 };
235
236 if (pinfo->off)
237 ret = pinfo->off();
238
239 /* Disable clock */
240 if (panel->clk_func)
241 ret = panel->clk_func(0);
242
243 if (ret)
244 goto msm_display_off_out;
245
246 /* Disable panel */
247 if (panel->power_func)
248 ret = panel->power_func(0);
249
250msm_display_off_out:
251 return ret;
252}