ARM: omap: fix oops in arch/arm/mach-omap2/vp.c when pmic is not found
[deliverable/linux.git] / drivers / video / omap2 / dss / dpi.c
CommitLineData
553c48cf
TV
1/*
2 * linux/drivers/video/omap2/dss/dpi.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
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.
13 *
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.
18 *
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/>.
21 */
22
23#define DSS_SUBSYS_NAME "DPI"
24
25#include <linux/kernel.h>
553c48cf 26#include <linux/delay.h>
a8a35931 27#include <linux/export.h>
8a2cfea8 28#include <linux/err.h>
553c48cf 29#include <linux/errno.h>
8a2cfea8
TV
30#include <linux/platform_device.h>
31#include <linux/regulator/consumer.h>
553c48cf 32
a0b38cc4 33#include <video/omapdss.h>
553c48cf
TV
34#include <plat/cpu.h>
35
36#include "dss.h"
37
38static struct {
8a2cfea8 39 struct regulator *vdds_dsi_reg;
a72b64b9 40 struct platform_device *dsidev;
553c48cf
TV
41} dpi;
42
a72b64b9
AT
43static struct platform_device *dpi_get_dsidev(enum omap_dss_clk_source clk)
44{
45 int dsi_module;
46
47 dsi_module = clk == OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ? 0 : 1;
48
49 return dsi_get_dsidev_from_id(dsi_module);
50}
51
7636b3b4
AT
52static bool dpi_use_dsi_pll(struct omap_dss_device *dssdev)
53{
54 if (dssdev->clocks.dispc.dispc_fclk_src ==
55 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ||
5a8b572d
AT
56 dssdev->clocks.dispc.dispc_fclk_src ==
57 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC ||
7636b3b4 58 dssdev->clocks.dispc.channel.lcd_clk_src ==
5a8b572d
AT
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)
7636b3b4
AT
62 return true;
63 else
64 return false;
65}
66
ff1b2cde
SS
67static 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)
553c48cf
TV
70{
71 struct dsi_clock_info dsi_cinfo;
72 struct dispc_clock_info dispc_cinfo;
73 int r;
74
a72b64b9
AT
75 r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft, pck_req,
76 &dsi_cinfo, &dispc_cinfo);
553c48cf
TV
77 if (r)
78 return r;
79
a72b64b9 80 r = dsi_pll_set_clock_div(dpi.dsidev, &dsi_cinfo);
553c48cf
TV
81 if (r)
82 return r;
83
e8881662 84 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
553c48cf 85
26d9dd0d 86 r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
5e785091
TV
87 if (r) {
88 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
553c48cf 89 return r;
5e785091 90 }
553c48cf 91
1bb47835 92 *fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
553c48cf
TV
93 *lck_div = dispc_cinfo.lck_div;
94 *pck_div = dispc_cinfo.pck_div;
95
96 return 0;
97}
7636b3b4 98
ff1b2cde
SS
99static int dpi_set_dispc_clk(struct omap_dss_device *dssdev, bool is_tft,
100 unsigned long pck_req, unsigned long *fck, int *lck_div,
101 int *pck_div)
553c48cf
TV
102{
103 struct dss_clock_info dss_cinfo;
104 struct dispc_clock_info dispc_cinfo;
105 int r;
106
107 r = dss_calc_clock_div(is_tft, pck_req, &dss_cinfo, &dispc_cinfo);
108 if (r)
109 return r;
110
111 r = dss_set_clock_div(&dss_cinfo);
112 if (r)
113 return r;
114
26d9dd0d 115 r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
553c48cf
TV
116 if (r)
117 return r;
118
119 *fck = dss_cinfo.fck;
120 *lck_div = dispc_cinfo.lck_div;
121 *pck_div = dispc_cinfo.pck_div;
122
123 return 0;
124}
553c48cf
TV
125
126static int dpi_set_mode(struct omap_dss_device *dssdev)
127{
128 struct omap_video_timings *t = &dssdev->panel.timings;
7636b3b4
AT
129 int lck_div = 0, pck_div = 0;
130 unsigned long fck = 0;
553c48cf
TV
131 unsigned long pck;
132 bool is_tft;
133 int r = 0;
134
26d9dd0d 135 dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
ff1b2cde 136 dssdev->panel.acbi, dssdev->panel.acb);
553c48cf
TV
137
138 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
139
7636b3b4
AT
140 if (dpi_use_dsi_pll(dssdev))
141 r = dpi_set_dsi_clk(dssdev, is_tft, t->pixel_clock * 1000,
142 &fck, &lck_div, &pck_div);
143 else
144 r = dpi_set_dispc_clk(dssdev, is_tft, t->pixel_clock * 1000,
145 &fck, &lck_div, &pck_div);
553c48cf 146 if (r)
4fbafaf3 147 return r;
553c48cf
TV
148
149 pck = fck / lck_div / pck_div / 1000;
150
151 if (pck != t->pixel_clock) {
152 DSSWARN("Could not find exact pixel clock. "
153 "Requested %d kHz, got %lu kHz\n",
154 t->pixel_clock, pck);
155
156 t->pixel_clock = pck;
157 }
158
26d9dd0d 159 dispc_mgr_set_lcd_timings(dssdev->manager->id, t);
553c48cf 160
4fbafaf3 161 return 0;
553c48cf
TV
162}
163
4fbafaf3 164static void dpi_basic_init(struct omap_dss_device *dssdev)
553c48cf
TV
165{
166 bool is_tft;
167
168 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
169
569969d6
AT
170 dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_BYPASS);
171 dispc_mgr_enable_stallmode(dssdev->manager->id, false);
172
26d9dd0d 173 dispc_mgr_set_lcd_display_type(dssdev->manager->id, is_tft ?
64ba4f74 174 OMAP_DSS_LCD_DISPLAY_TFT : OMAP_DSS_LCD_DISPLAY_STN);
26d9dd0d 175 dispc_mgr_set_tft_data_lines(dssdev->manager->id,
64ba4f74 176 dssdev->phy.dpi.data_lines);
553c48cf
TV
177}
178
37ac60e4 179int omapdss_dpi_display_enable(struct omap_dss_device *dssdev)
553c48cf
TV
180{
181 int r;
182
05e1d606
TV
183 if (dssdev->manager == NULL) {
184 DSSERR("failed to enable display: no manager\n");
185 return -ENODEV;
186 }
187
553c48cf
TV
188 r = omap_dss_start_device(dssdev);
189 if (r) {
190 DSSERR("failed to start device\n");
4fbafaf3 191 goto err_start_dev;
553c48cf
TV
192 }
193
8a2cfea8
TV
194 if (cpu_is_omap34xx()) {
195 r = regulator_enable(dpi.vdds_dsi_reg);
196 if (r)
4fbafaf3 197 goto err_reg_enable;
8a2cfea8
TV
198 }
199
4fbafaf3
TV
200 r = dss_runtime_get();
201 if (r)
202 goto err_get_dss;
553c48cf 203
4fbafaf3 204 r = dispc_runtime_get();
553c48cf 205 if (r)
4fbafaf3
TV
206 goto err_get_dispc;
207
208 dpi_basic_init(dssdev);
553c48cf 209
7636b3b4 210 if (dpi_use_dsi_pll(dssdev)) {
4fbafaf3
TV
211 r = dsi_runtime_get(dpi.dsidev);
212 if (r)
213 goto err_get_dsi;
214
a72b64b9 215 r = dsi_pll_init(dpi.dsidev, 0, 1);
7636b3b4 216 if (r)
4fbafaf3 217 goto err_dsi_pll_init;
7636b3b4
AT
218 }
219
553c48cf
TV
220 r = dpi_set_mode(dssdev);
221 if (r)
4fbafaf3 222 goto err_set_mode;
553c48cf
TV
223
224 mdelay(2);
225
33ca237f
TV
226 r = dss_mgr_enable(dssdev->manager);
227 if (r)
228 goto err_mgr_enable;
553c48cf 229
553c48cf
TV
230 return 0;
231
33ca237f 232err_mgr_enable:
4fbafaf3 233err_set_mode:
7636b3b4 234 if (dpi_use_dsi_pll(dssdev))
19077a73 235 dsi_pll_uninit(dpi.dsidev, true);
4fbafaf3
TV
236err_dsi_pll_init:
237 if (dpi_use_dsi_pll(dssdev))
238 dsi_runtime_put(dpi.dsidev);
239err_get_dsi:
240 dispc_runtime_put();
241err_get_dispc:
242 dss_runtime_put();
243err_get_dss:
8a2cfea8
TV
244 if (cpu_is_omap34xx())
245 regulator_disable(dpi.vdds_dsi_reg);
4fbafaf3 246err_reg_enable:
553c48cf 247 omap_dss_stop_device(dssdev);
4fbafaf3 248err_start_dev:
553c48cf
TV
249 return r;
250}
37ac60e4 251EXPORT_SYMBOL(omapdss_dpi_display_enable);
553c48cf 252
37ac60e4 253void omapdss_dpi_display_disable(struct omap_dss_device *dssdev)
553c48cf 254{
7797c6da 255 dss_mgr_disable(dssdev->manager);
553c48cf 256
7636b3b4
AT
257 if (dpi_use_dsi_pll(dssdev)) {
258 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
a72b64b9 259 dsi_pll_uninit(dpi.dsidev, true);
4fbafaf3 260 dsi_runtime_put(dpi.dsidev);
7636b3b4 261 }
553c48cf 262
4fbafaf3
TV
263 dispc_runtime_put();
264 dss_runtime_put();
553c48cf 265
8a2cfea8
TV
266 if (cpu_is_omap34xx())
267 regulator_disable(dpi.vdds_dsi_reg);
268
553c48cf
TV
269 omap_dss_stop_device(dssdev);
270}
37ac60e4 271EXPORT_SYMBOL(omapdss_dpi_display_disable);
553c48cf 272
69b2048f 273void dpi_set_timings(struct omap_dss_device *dssdev,
553c48cf
TV
274 struct omap_video_timings *timings)
275{
4fbafaf3
TV
276 int r;
277
553c48cf
TV
278 DSSDBG("dpi_set_timings\n");
279 dssdev->panel.timings = *timings;
280 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
4fbafaf3
TV
281 r = dss_runtime_get();
282 if (r)
283 return;
284
285 r = dispc_runtime_get();
286 if (r) {
287 dss_runtime_put();
288 return;
289 }
290
553c48cf 291 dpi_set_mode(dssdev);
26d9dd0d 292 dispc_mgr_go(dssdev->manager->id);
4fbafaf3
TV
293
294 dispc_runtime_put();
295 dss_runtime_put();
553c48cf
TV
296 }
297}
69b2048f 298EXPORT_SYMBOL(dpi_set_timings);
553c48cf 299
69b2048f 300int dpi_check_timings(struct omap_dss_device *dssdev,
553c48cf
TV
301 struct omap_video_timings *timings)
302{
303 bool is_tft;
304 int r;
305 int lck_div, pck_div;
306 unsigned long fck;
307 unsigned long pck;
7636b3b4 308 struct dispc_clock_info dispc_cinfo;
553c48cf
TV
309
310 if (!dispc_lcd_timings_ok(timings))
311 return -EINVAL;
312
313 if (timings->pixel_clock == 0)
314 return -EINVAL;
315
316 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
317
7636b3b4 318 if (dpi_use_dsi_pll(dssdev)) {
553c48cf 319 struct dsi_clock_info dsi_cinfo;
a72b64b9 320 r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft,
553c48cf
TV
321 timings->pixel_clock * 1000,
322 &dsi_cinfo, &dispc_cinfo);
323
324 if (r)
325 return r;
326
1bb47835 327 fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
7636b3b4 328 } else {
553c48cf 329 struct dss_clock_info dss_cinfo;
553c48cf
TV
330 r = dss_calc_clock_div(is_tft, timings->pixel_clock * 1000,
331 &dss_cinfo, &dispc_cinfo);
332
333 if (r)
334 return r;
335
336 fck = dss_cinfo.fck;
553c48cf 337 }
7636b3b4
AT
338
339 lck_div = dispc_cinfo.lck_div;
340 pck_div = dispc_cinfo.pck_div;
553c48cf
TV
341
342 pck = fck / lck_div / pck_div / 1000;
343
344 timings->pixel_clock = pck;
345
346 return 0;
347}
69b2048f 348EXPORT_SYMBOL(dpi_check_timings);
553c48cf 349
553c48cf
TV
350int dpi_init_display(struct omap_dss_device *dssdev)
351{
352 DSSDBG("init_display\n");
353
5f42f2ce
TV
354 if (cpu_is_omap34xx() && dpi.vdds_dsi_reg == NULL) {
355 struct regulator *vdds_dsi;
553c48cf 356
5f42f2ce
TV
357 vdds_dsi = dss_get_vdds_dsi();
358
359 if (IS_ERR(vdds_dsi)) {
8a2cfea8 360 DSSERR("can't get VDDS_DSI regulator\n");
5f42f2ce 361 return PTR_ERR(vdds_dsi);
8a2cfea8 362 }
5f42f2ce
TV
363
364 dpi.vdds_dsi_reg = vdds_dsi;
8a2cfea8
TV
365 }
366
a72b64b9
AT
367 if (dpi_use_dsi_pll(dssdev)) {
368 enum omap_dss_clk_source dispc_fclk_src =
369 dssdev->clocks.dispc.dispc_fclk_src;
370 dpi.dsidev = dpi_get_dsidev(dispc_fclk_src);
371 }
372
553c48cf
TV
373 return 0;
374}
375
277b2881 376int dpi_init(void)
5f42f2ce
TV
377{
378 return 0;
379}
380
553c48cf
TV
381void dpi_exit(void)
382{
383}
384
This page took 0.188902 seconds and 5 git commands to generate.