Full support for Ginger Console
[linux-ginger.git] / drivers / video / omap2 / dss / dpi.c
blob2d71031baa2551d09b723f34781136ea80674467
1 /*
2 * linux/drivers/video/omap2/dss/dpi.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
23 #define DSS_SUBSYS_NAME "DPI"
25 #include <linux/kernel.h>
26 #include <linux/clk.h>
27 #include <linux/delay.h>
28 #include <linux/errno.h>
30 #include <plat/display.h>
31 #include <plat/cpu.h>
33 #include "dss.h"
35 static struct {
36 int update_enabled;
37 } dpi;
39 #ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
40 static int dpi_set_dsi_clk(bool is_tft, unsigned long pck_req,
41 unsigned long *fck, int *lck_div, int *pck_div)
43 struct dsi_clock_info dsi_cinfo;
44 struct dispc_clock_info dispc_cinfo;
45 int r;
47 r = dsi_pll_calc_clock_div_pck(is_tft, pck_req, &dsi_cinfo,
48 &dispc_cinfo);
49 if (r)
50 return r;
52 r = dsi_pll_set_clock_div(&dsi_cinfo);
53 if (r)
54 return r;
56 dss_select_clk_source(0, 1);
58 r = dispc_set_clock_div(&dispc_cinfo);
59 if (r)
60 return r;
62 *fck = dsi_cinfo.dsi1_pll_fclk;
63 *lck_div = dispc_cinfo.lck_div;
64 *pck_div = dispc_cinfo.pck_div;
66 return 0;
68 #else
69 static int dpi_set_dispc_clk(bool is_tft, unsigned long pck_req,
70 unsigned long *fck, int *lck_div, int *pck_div)
72 struct dss_clock_info dss_cinfo;
73 struct dispc_clock_info dispc_cinfo;
74 int r;
76 r = dss_calc_clock_div(is_tft, pck_req, &dss_cinfo, &dispc_cinfo);
77 if (r)
78 return r;
80 r = dss_set_clock_div(&dss_cinfo);
81 if (r)
82 return r;
84 r = dispc_set_clock_div(&dispc_cinfo);
85 if (r)
86 return r;
88 *fck = dss_cinfo.fck;
89 *lck_div = dispc_cinfo.lck_div;
90 *pck_div = dispc_cinfo.pck_div;
92 return 0;
94 #endif
96 static int dpi_set_mode(struct omap_dss_device *dssdev)
98 struct omap_video_timings *t = &dssdev->panel.timings;
99 int lck_div, pck_div;
100 unsigned long fck;
101 unsigned long pck;
102 bool is_tft;
103 int r = 0;
105 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
107 dispc_set_pol_freq(dssdev->panel.config, dssdev->panel.acbi,
108 dssdev->panel.acb);
110 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
112 #ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
113 r = dpi_set_dsi_clk(is_tft, t->pixel_clock * 1000,
114 &fck, &lck_div, &pck_div);
115 #else
116 r = dpi_set_dispc_clk(is_tft, t->pixel_clock * 1000,
117 &fck, &lck_div, &pck_div);
118 #endif
119 if (r)
120 goto err0;
122 pck = fck / lck_div / pck_div / 1000;
124 if (pck != t->pixel_clock) {
125 DSSWARN("Could not find exact pixel clock. "
126 "Requested %d kHz, got %lu kHz\n",
127 t->pixel_clock, pck);
129 t->pixel_clock = pck;
132 dispc_set_lcd_timings(t);
134 err0:
135 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
136 return r;
139 static int dpi_basic_init(struct omap_dss_device *dssdev)
141 bool is_tft;
143 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
145 dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_BYPASS);
146 dispc_set_lcd_display_type(is_tft ? OMAP_DSS_LCD_DISPLAY_TFT :
147 OMAP_DSS_LCD_DISPLAY_STN);
148 dispc_set_tft_data_lines(dssdev->phy.dpi.data_lines);
150 return 0;
153 static int dpi_display_enable(struct omap_dss_device *dssdev)
155 int r;
157 r = omap_dss_start_device(dssdev);
158 if (r) {
159 DSSERR("failed to start device\n");
160 goto err0;
163 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
164 DSSERR("display already enabled\n");
165 r = -EINVAL;
166 goto err1;
169 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
171 r = dpi_basic_init(dssdev);
172 if (r)
173 goto err2;
175 #ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
176 dss_clk_enable(DSS_CLK_FCK2);
177 r = dsi_pll_init(dssdev, 0, 1);
178 if (r)
179 goto err3;
180 #endif
181 r = dpi_set_mode(dssdev);
182 if (r)
183 goto err4;
185 mdelay(2);
187 dispc_enable_lcd_out(1);
189 r = dssdev->driver->enable(dssdev);
190 if (r)
191 goto err5;
193 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
195 return 0;
197 err5:
198 dispc_enable_lcd_out(0);
199 err4:
200 #ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
201 dsi_pll_uninit();
202 err3:
203 dss_clk_disable(DSS_CLK_FCK2);
204 #endif
205 err2:
206 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
207 err1:
208 omap_dss_stop_device(dssdev);
209 err0:
210 return r;
213 static int dpi_display_resume(struct omap_dss_device *dssdev);
215 static void dpi_display_disable(struct omap_dss_device *dssdev)
217 if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED)
218 return;
220 if (dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
221 dpi_display_resume(dssdev);
223 dssdev->driver->disable(dssdev);
225 dispc_enable_lcd_out(0);
227 #ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
228 dss_select_clk_source(0, 0);
229 dsi_pll_uninit();
230 dss_clk_disable(DSS_CLK_FCK2);
231 #endif
233 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
235 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
237 omap_dss_stop_device(dssdev);
240 static int dpi_display_suspend(struct omap_dss_device *dssdev)
242 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
243 return -EINVAL;
245 DSSDBG("dpi_display_suspend\n");
247 if (dssdev->driver->suspend)
248 dssdev->driver->suspend(dssdev);
250 dispc_enable_lcd_out(0);
252 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
254 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
256 return 0;
259 static int dpi_display_resume(struct omap_dss_device *dssdev)
261 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED)
262 return -EINVAL;
264 DSSDBG("dpi_display_resume\n");
266 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
268 dispc_enable_lcd_out(1);
270 if (dssdev->driver->resume)
271 dssdev->driver->resume(dssdev);
273 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
275 return 0;
278 static void dpi_set_timings(struct omap_dss_device *dssdev,
279 struct omap_video_timings *timings)
281 DSSDBG("dpi_set_timings\n");
282 dssdev->panel.timings = *timings;
283 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
284 dpi_set_mode(dssdev);
285 dispc_go(OMAP_DSS_CHANNEL_LCD);
289 static int dpi_check_timings(struct omap_dss_device *dssdev,
290 struct omap_video_timings *timings)
292 bool is_tft;
293 int r;
294 int lck_div, pck_div;
295 unsigned long fck;
296 unsigned long pck;
298 if (!dispc_lcd_timings_ok(timings))
299 return -EINVAL;
301 if (timings->pixel_clock == 0)
302 return -EINVAL;
304 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
306 #ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
308 struct dsi_clock_info dsi_cinfo;
309 struct dispc_clock_info dispc_cinfo;
310 r = dsi_pll_calc_clock_div_pck(is_tft,
311 timings->pixel_clock * 1000,
312 &dsi_cinfo, &dispc_cinfo);
314 if (r)
315 return r;
317 fck = dsi_cinfo.dsi1_pll_fclk;
318 lck_div = dispc_cinfo.lck_div;
319 pck_div = dispc_cinfo.pck_div;
321 #else
323 struct dss_clock_info dss_cinfo;
324 struct dispc_clock_info dispc_cinfo;
325 r = dss_calc_clock_div(is_tft, timings->pixel_clock * 1000,
326 &dss_cinfo, &dispc_cinfo);
328 if (r)
329 return r;
331 fck = dss_cinfo.fck;
332 lck_div = dispc_cinfo.lck_div;
333 pck_div = dispc_cinfo.pck_div;
335 #endif
337 pck = fck / lck_div / pck_div / 1000;
339 timings->pixel_clock = pck;
341 return 0;
344 static void dpi_get_timings(struct omap_dss_device *dssdev,
345 struct omap_video_timings *timings)
347 *timings = dssdev->panel.timings;
350 static int dpi_display_set_update_mode(struct omap_dss_device *dssdev,
351 enum omap_dss_update_mode mode)
353 if (mode == OMAP_DSS_UPDATE_MANUAL)
354 return -EINVAL;
356 if (mode == OMAP_DSS_UPDATE_DISABLED) {
357 dispc_enable_lcd_out(0);
358 dpi.update_enabled = 0;
359 } else {
360 dispc_enable_lcd_out(1);
361 dpi.update_enabled = 1;
364 return 0;
367 static enum omap_dss_update_mode dpi_display_get_update_mode(
368 struct omap_dss_device *dssdev)
370 return dpi.update_enabled ? OMAP_DSS_UPDATE_AUTO :
371 OMAP_DSS_UPDATE_DISABLED;
374 int dpi_init_display(struct omap_dss_device *dssdev)
376 DSSDBG("init_display\n");
378 dssdev->enable = dpi_display_enable;
379 dssdev->disable = dpi_display_disable;
380 dssdev->suspend = dpi_display_suspend;
381 dssdev->resume = dpi_display_resume;
382 dssdev->set_timings = dpi_set_timings;
383 dssdev->check_timings = dpi_check_timings;
384 dssdev->get_timings = dpi_get_timings;
385 dssdev->set_update_mode = dpi_display_set_update_mode;
386 dssdev->get_update_mode = dpi_display_get_update_mode;
388 return 0;
391 int dpi_init(void)
393 return 0;
396 void dpi_exit(void)