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
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
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>
39 struct regulator
*vdds_dsi_reg
;
40 struct platform_device
*dsidev
;
43 static struct platform_device
*dpi_get_dsidev(enum omap_dss_clk_source clk
)
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
)
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
,
71 struct dsi_clock_info dsi_cinfo
;
72 struct dispc_clock_info dispc_cinfo
;
75 r
= dsi_pll_calc_clock_div_pck(dpi
.dsidev
, is_tft
, pck_req
,
76 &dsi_cinfo
, &dispc_cinfo
);
80 r
= dsi_pll_set_clock_div(dpi
.dsidev
, &dsi_cinfo
);
84 dss_select_dispc_clk_source(dssdev
->clocks
.dispc
.dispc_fclk_src
);
86 r
= dispc_set_clock_div(dssdev
->manager
->id
, &dispc_cinfo
);
90 *fck
= dsi_cinfo
.dsi_pll_hsdiv_dispc_clk
;
91 *lck_div
= dispc_cinfo
.lck_div
;
92 *pck_div
= dispc_cinfo
.pck_div
;
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
,
101 struct dss_clock_info dss_cinfo
;
102 struct dispc_clock_info dispc_cinfo
;
105 r
= dss_calc_clock_div(is_tft
, pck_req
, &dss_cinfo
, &dispc_cinfo
);
109 r
= dss_set_clock_div(&dss_cinfo
);
113 r
= dispc_set_clock_div(dssdev
->manager
->id
, &dispc_cinfo
);
117 *fck
= dss_cinfo
.fck
;
118 *lck_div
= dispc_cinfo
.lck_div
;
119 *pck_div
= dispc_cinfo
.pck_div
;
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;
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
);
142 r
= dpi_set_dispc_clk(dssdev
, is_tft
, t
->pixel_clock
* 1000,
143 &fck
, &lck_div
, &pck_div
);
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
);
162 static void dpi_basic_init(struct omap_dss_device
*dssdev
)
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
)
180 r
= omap_dss_start_device(dssdev
);
182 DSSERR("failed to start device\n");
186 if (cpu_is_omap34xx()) {
187 r
= regulator_enable(dpi
.vdds_dsi_reg
);
192 r
= dss_runtime_get();
196 r
= dispc_runtime_get();
200 dpi_basic_init(dssdev
);
202 if (dpi_use_dsi_pll(dssdev
)) {
203 r
= dsi_runtime_get(dpi
.dsidev
);
207 r
= dsi_pll_init(dpi
.dsidev
, 0, 1);
209 goto err_dsi_pll_init
;
212 r
= dpi_set_mode(dssdev
);
218 dssdev
->manager
->enable(dssdev
->manager
);
223 if (dpi_use_dsi_pll(dssdev
))
224 dsi_pll_uninit(dpi
.dsidev
, true);
226 if (dpi_use_dsi_pll(dssdev
))
227 dsi_runtime_put(dpi
.dsidev
);
233 if (cpu_is_omap34xx())
234 regulator_disable(dpi
.vdds_dsi_reg
);
236 omap_dss_stop_device(dssdev
);
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
);
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
)
267 DSSDBG("dpi_set_timings\n");
268 dssdev
->panel
.timings
= *timings
;
269 if (dssdev
->state
== OMAP_DSS_DISPLAY_ACTIVE
) {
270 r
= dss_runtime_get();
274 r
= dispc_runtime_get();
280 dpi_set_mode(dssdev
);
281 dispc_go(dssdev
->manager
->id
);
287 EXPORT_SYMBOL(dpi_set_timings
);
289 int dpi_check_timings(struct omap_dss_device
*dssdev
,
290 struct omap_video_timings
*timings
)
294 int lck_div
, pck_div
;
297 struct dispc_clock_info dispc_cinfo
;
299 if (!dispc_lcd_timings_ok(timings
))
302 if (timings
->pixel_clock
== 0)
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
);
316 fck
= dsi_cinfo
.dsi_pll_hsdiv_dispc_clk
;
318 struct dss_clock_info dss_cinfo
;
319 r
= dss_calc_clock_div(is_tft
, timings
->pixel_clock
* 1000,
320 &dss_cinfo
, &dispc_cinfo
);
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
;
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
);