Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / drivers / video / omap2 / dss / dpi.c
blob9e16b13bbc1a10e87440e062b621fa7056794138
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/delay.h>
27 #include <linux/export.h>
28 #include <linux/err.h>
29 #include <linux/errno.h>
30 #include <linux/platform_device.h>
31 #include <linux/regulator/consumer.h>
33 #include <video/omapdss.h>
34 #include <plat/cpu.h>
36 #include "dss.h"
38 static struct {
39 struct regulator *vdds_dsi_reg;
40 struct platform_device *dsidev;
41 } dpi;
43 static struct platform_device *dpi_get_dsidev(enum omap_dss_clk_source clk)
45 int dsi_module;
47 dsi_module = clk == OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ? 0 : 1;
49 return dsi_get_dsidev_from_id(dsi_module);
52 static bool dpi_use_dsi_pll(struct omap_dss_device *dssdev)
54 if (dssdev->clocks.dispc.dispc_fclk_src ==
55 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ||
56 dssdev->clocks.dispc.dispc_fclk_src ==
57 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC ||
58 dssdev->clocks.dispc.channel.lcd_clk_src ==
59 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ||
60 dssdev->clocks.dispc.channel.lcd_clk_src ==
61 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC)
62 return true;
63 else
64 return false;
67 static int dpi_set_dsi_clk(struct omap_dss_device *dssdev, bool is_tft,
68 unsigned long pck_req, unsigned long *fck, int *lck_div,
69 int *pck_div)
71 struct dsi_clock_info dsi_cinfo;
72 struct dispc_clock_info dispc_cinfo;
73 int r;
75 r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft, pck_req,
76 &dsi_cinfo, &dispc_cinfo);
77 if (r)
78 return r;
80 r = dsi_pll_set_clock_div(dpi.dsidev, &dsi_cinfo);
81 if (r)
82 return r;
84 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
86 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
87 if (r)
88 return r;
90 *fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
91 *lck_div = dispc_cinfo.lck_div;
92 *pck_div = dispc_cinfo.pck_div;
94 return 0;
97 static int dpi_set_dispc_clk(struct omap_dss_device *dssdev, bool is_tft,
98 unsigned long pck_req, unsigned long *fck, int *lck_div,
99 int *pck_div)
101 struct dss_clock_info dss_cinfo;
102 struct dispc_clock_info dispc_cinfo;
103 int r;
105 r = dss_calc_clock_div(is_tft, pck_req, &dss_cinfo, &dispc_cinfo);
106 if (r)
107 return r;
109 r = dss_set_clock_div(&dss_cinfo);
110 if (r)
111 return r;
113 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
114 if (r)
115 return r;
117 *fck = dss_cinfo.fck;
118 *lck_div = dispc_cinfo.lck_div;
119 *pck_div = dispc_cinfo.pck_div;
121 return 0;
124 static int dpi_set_mode(struct omap_dss_device *dssdev)
126 struct omap_video_timings *t = &dssdev->panel.timings;
127 int lck_div = 0, pck_div = 0;
128 unsigned long fck = 0;
129 unsigned long pck;
130 bool is_tft;
131 int r = 0;
133 dispc_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
134 dssdev->panel.acbi, dssdev->panel.acb);
136 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
138 if (dpi_use_dsi_pll(dssdev))
139 r = dpi_set_dsi_clk(dssdev, is_tft, t->pixel_clock * 1000,
140 &fck, &lck_div, &pck_div);
141 else
142 r = dpi_set_dispc_clk(dssdev, is_tft, t->pixel_clock * 1000,
143 &fck, &lck_div, &pck_div);
144 if (r)
145 return r;
147 pck = fck / lck_div / pck_div / 1000;
149 if (pck != t->pixel_clock) {
150 DSSWARN("Could not find exact pixel clock. "
151 "Requested %d kHz, got %lu kHz\n",
152 t->pixel_clock, pck);
154 t->pixel_clock = pck;
157 dispc_set_lcd_timings(dssdev->manager->id, t);
159 return 0;
162 static void dpi_basic_init(struct omap_dss_device *dssdev)
164 bool is_tft;
166 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
168 dispc_set_parallel_interface_mode(dssdev->manager->id,
169 OMAP_DSS_PARALLELMODE_BYPASS);
170 dispc_set_lcd_display_type(dssdev->manager->id, is_tft ?
171 OMAP_DSS_LCD_DISPLAY_TFT : OMAP_DSS_LCD_DISPLAY_STN);
172 dispc_set_tft_data_lines(dssdev->manager->id,
173 dssdev->phy.dpi.data_lines);
176 int omapdss_dpi_display_enable(struct omap_dss_device *dssdev)
178 int r;
180 r = omap_dss_start_device(dssdev);
181 if (r) {
182 DSSERR("failed to start device\n");
183 goto err_start_dev;
186 if (cpu_is_omap34xx()) {
187 r = regulator_enable(dpi.vdds_dsi_reg);
188 if (r)
189 goto err_reg_enable;
192 r = dss_runtime_get();
193 if (r)
194 goto err_get_dss;
196 r = dispc_runtime_get();
197 if (r)
198 goto err_get_dispc;
200 dpi_basic_init(dssdev);
202 if (dpi_use_dsi_pll(dssdev)) {
203 r = dsi_runtime_get(dpi.dsidev);
204 if (r)
205 goto err_get_dsi;
207 r = dsi_pll_init(dpi.dsidev, 0, 1);
208 if (r)
209 goto err_dsi_pll_init;
212 r = dpi_set_mode(dssdev);
213 if (r)
214 goto err_set_mode;
216 mdelay(2);
218 dssdev->manager->enable(dssdev->manager);
220 return 0;
222 err_set_mode:
223 if (dpi_use_dsi_pll(dssdev))
224 dsi_pll_uninit(dpi.dsidev, true);
225 err_dsi_pll_init:
226 if (dpi_use_dsi_pll(dssdev))
227 dsi_runtime_put(dpi.dsidev);
228 err_get_dsi:
229 dispc_runtime_put();
230 err_get_dispc:
231 dss_runtime_put();
232 err_get_dss:
233 if (cpu_is_omap34xx())
234 regulator_disable(dpi.vdds_dsi_reg);
235 err_reg_enable:
236 omap_dss_stop_device(dssdev);
237 err_start_dev:
238 return r;
240 EXPORT_SYMBOL(omapdss_dpi_display_enable);
242 void omapdss_dpi_display_disable(struct omap_dss_device *dssdev)
244 dssdev->manager->disable(dssdev->manager);
246 if (dpi_use_dsi_pll(dssdev)) {
247 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
248 dsi_pll_uninit(dpi.dsidev, true);
249 dsi_runtime_put(dpi.dsidev);
252 dispc_runtime_put();
253 dss_runtime_put();
255 if (cpu_is_omap34xx())
256 regulator_disable(dpi.vdds_dsi_reg);
258 omap_dss_stop_device(dssdev);
260 EXPORT_SYMBOL(omapdss_dpi_display_disable);
262 void dpi_set_timings(struct omap_dss_device *dssdev,
263 struct omap_video_timings *timings)
265 int r;
267 DSSDBG("dpi_set_timings\n");
268 dssdev->panel.timings = *timings;
269 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
270 r = dss_runtime_get();
271 if (r)
272 return;
274 r = dispc_runtime_get();
275 if (r) {
276 dss_runtime_put();
277 return;
280 dpi_set_mode(dssdev);
281 dispc_go(dssdev->manager->id);
283 dispc_runtime_put();
284 dss_runtime_put();
287 EXPORT_SYMBOL(dpi_set_timings);
289 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;
297 struct dispc_clock_info dispc_cinfo;
299 if (!dispc_lcd_timings_ok(timings))
300 return -EINVAL;
302 if (timings->pixel_clock == 0)
303 return -EINVAL;
305 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
307 if (dpi_use_dsi_pll(dssdev)) {
308 struct dsi_clock_info dsi_cinfo;
309 r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft,
310 timings->pixel_clock * 1000,
311 &dsi_cinfo, &dispc_cinfo);
313 if (r)
314 return r;
316 fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
317 } else {
318 struct dss_clock_info dss_cinfo;
319 r = dss_calc_clock_div(is_tft, timings->pixel_clock * 1000,
320 &dss_cinfo, &dispc_cinfo);
322 if (r)
323 return r;
325 fck = dss_cinfo.fck;
328 lck_div = dispc_cinfo.lck_div;
329 pck_div = dispc_cinfo.pck_div;
331 pck = fck / lck_div / pck_div / 1000;
333 timings->pixel_clock = pck;
335 return 0;
337 EXPORT_SYMBOL(dpi_check_timings);
339 int dpi_init_display(struct omap_dss_device *dssdev)
341 DSSDBG("init_display\n");
343 if (cpu_is_omap34xx() && dpi.vdds_dsi_reg == NULL) {
344 struct regulator *vdds_dsi;
346 vdds_dsi = dss_get_vdds_dsi();
348 if (IS_ERR(vdds_dsi)) {
349 DSSERR("can't get VDDS_DSI regulator\n");
350 return PTR_ERR(vdds_dsi);
353 dpi.vdds_dsi_reg = vdds_dsi;
356 if (dpi_use_dsi_pll(dssdev)) {
357 enum omap_dss_clk_source dispc_fclk_src =
358 dssdev->clocks.dispc.dispc_fclk_src;
359 dpi.dsidev = dpi_get_dsidev(dispc_fclk_src);
362 return 0;
365 int dpi_init(void)
367 return 0;
370 void dpi_exit(void)