blob: 746f1b6dd89700f8c762b40eed8c11b8a010e35e [file] [log] [blame]
Tomi Valkeinen553c48c2009-08-07 13:15:50 +03001/*
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>
26#include <linux/clk.h>
27#include <linux/delay.h>
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +020028#include <linux/err.h>
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030029#include <linux/errno.h>
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +020030#include <linux/platform_device.h>
31#include <linux/regulator/consumer.h>
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030032
33#include <plat/display.h>
34#include <plat/cpu.h>
35
36#include "dss.h"
37
38static struct {
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +020039 struct regulator *vdds_dsi_reg;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030040} dpi;
41
42#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
Sumit Semwalff1b2cd2010-12-02 11:27:11 +000043static int dpi_set_dsi_clk(struct omap_dss_device *dssdev, bool is_tft,
44 unsigned long pck_req, unsigned long *fck, int *lck_div,
45 int *pck_div)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030046{
47 struct dsi_clock_info dsi_cinfo;
48 struct dispc_clock_info dispc_cinfo;
49 int r;
50
51 r = dsi_pll_calc_clock_div_pck(is_tft, pck_req, &dsi_cinfo,
52 &dispc_cinfo);
53 if (r)
54 return r;
55
56 r = dsi_pll_set_clock_div(&dsi_cinfo);
57 if (r)
58 return r;
59
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +020060 dss_select_dispc_clk_source(DSS_SRC_DSI1_PLL_FCLK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030061
Sumit Semwalff1b2cd2010-12-02 11:27:11 +000062 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030063 if (r)
64 return r;
65
66 *fck = dsi_cinfo.dsi1_pll_fclk;
67 *lck_div = dispc_cinfo.lck_div;
68 *pck_div = dispc_cinfo.pck_div;
69
70 return 0;
71}
72#else
Sumit Semwalff1b2cd2010-12-02 11:27:11 +000073static int dpi_set_dispc_clk(struct omap_dss_device *dssdev, bool is_tft,
74 unsigned long pck_req, unsigned long *fck, int *lck_div,
75 int *pck_div)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030076{
77 struct dss_clock_info dss_cinfo;
78 struct dispc_clock_info dispc_cinfo;
79 int r;
80
81 r = dss_calc_clock_div(is_tft, pck_req, &dss_cinfo, &dispc_cinfo);
82 if (r)
83 return r;
84
85 r = dss_set_clock_div(&dss_cinfo);
86 if (r)
87 return r;
88
Sumit Semwalff1b2cd2010-12-02 11:27:11 +000089 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030090 if (r)
91 return r;
92
93 *fck = dss_cinfo.fck;
94 *lck_div = dispc_cinfo.lck_div;
95 *pck_div = dispc_cinfo.pck_div;
96
97 return 0;
98}
99#endif
100
101static int dpi_set_mode(struct omap_dss_device *dssdev)
102{
103 struct omap_video_timings *t = &dssdev->panel.timings;
104 int lck_div, pck_div;
105 unsigned long fck;
106 unsigned long pck;
107 bool is_tft;
108 int r = 0;
109
Archit Taneja6af9cd12011-01-31 16:27:44 +0000110 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300111
Sumit Semwalff1b2cd2010-12-02 11:27:11 +0000112 dispc_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
113 dssdev->panel.acbi, dssdev->panel.acb);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300114
115 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
116
117#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
Sumit Semwalff1b2cd2010-12-02 11:27:11 +0000118 r = dpi_set_dsi_clk(dssdev, is_tft, t->pixel_clock * 1000, &fck,
119 &lck_div, &pck_div);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300120#else
Sumit Semwalff1b2cd2010-12-02 11:27:11 +0000121 r = dpi_set_dispc_clk(dssdev, is_tft, t->pixel_clock * 1000, &fck,
122 &lck_div, &pck_div);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300123#endif
124 if (r)
125 goto err0;
126
127 pck = fck / lck_div / pck_div / 1000;
128
129 if (pck != t->pixel_clock) {
130 DSSWARN("Could not find exact pixel clock. "
131 "Requested %d kHz, got %lu kHz\n",
132 t->pixel_clock, pck);
133
134 t->pixel_clock = pck;
135 }
136
Sumit Semwal64ba4f72010-12-02 11:27:10 +0000137 dispc_set_lcd_timings(dssdev->manager->id, t);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300138
139err0:
Archit Taneja6af9cd12011-01-31 16:27:44 +0000140 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300141 return r;
142}
143
144static int dpi_basic_init(struct omap_dss_device *dssdev)
145{
146 bool is_tft;
147
148 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
149
Sumit Semwal64ba4f72010-12-02 11:27:10 +0000150 dispc_set_parallel_interface_mode(dssdev->manager->id,
151 OMAP_DSS_PARALLELMODE_BYPASS);
152 dispc_set_lcd_display_type(dssdev->manager->id, is_tft ?
153 OMAP_DSS_LCD_DISPLAY_TFT : OMAP_DSS_LCD_DISPLAY_STN);
154 dispc_set_tft_data_lines(dssdev->manager->id,
155 dssdev->phy.dpi.data_lines);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300156
157 return 0;
158}
159
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200160int omapdss_dpi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300161{
162 int r;
163
164 r = omap_dss_start_device(dssdev);
165 if (r) {
166 DSSERR("failed to start device\n");
167 goto err0;
168 }
169
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200170 if (cpu_is_omap34xx()) {
171 r = regulator_enable(dpi.vdds_dsi_reg);
172 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200173 goto err1;
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200174 }
175
Archit Taneja6af9cd12011-01-31 16:27:44 +0000176 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300177
178 r = dpi_basic_init(dssdev);
179 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200180 goto err2;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300181
182#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
Archit Taneja6af9cd12011-01-31 16:27:44 +0000183 dss_clk_enable(DSS_CLK_SYSCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300184 r = dsi_pll_init(dssdev, 0, 1);
185 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200186 goto err3;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300187#endif
188 r = dpi_set_mode(dssdev);
189 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200190 goto err4;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300191
192 mdelay(2);
193
Tomi Valkeinena2faee82010-01-08 17:14:53 +0200194 dssdev->manager->enable(dssdev->manager);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300195
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300196 return 0;
197
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200198err4:
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300199#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
200 dsi_pll_uninit();
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200201err3:
Archit Taneja6af9cd12011-01-31 16:27:44 +0000202 dss_clk_disable(DSS_CLK_SYSCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300203#endif
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200204err2:
Archit Taneja6af9cd12011-01-31 16:27:44 +0000205 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200206 if (cpu_is_omap34xx())
207 regulator_disable(dpi.vdds_dsi_reg);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300208err1:
209 omap_dss_stop_device(dssdev);
210err0:
211 return r;
212}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200213EXPORT_SYMBOL(omapdss_dpi_display_enable);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300214
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200215void omapdss_dpi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300216{
Tomi Valkeinena2faee82010-01-08 17:14:53 +0200217 dssdev->manager->disable(dssdev->manager);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300218
219#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +0200220 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300221 dsi_pll_uninit();
Archit Taneja6af9cd12011-01-31 16:27:44 +0000222 dss_clk_disable(DSS_CLK_SYSCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300223#endif
224
Archit Taneja6af9cd12011-01-31 16:27:44 +0000225 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300226
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200227 if (cpu_is_omap34xx())
228 regulator_disable(dpi.vdds_dsi_reg);
229
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300230 omap_dss_stop_device(dssdev);
231}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200232EXPORT_SYMBOL(omapdss_dpi_display_disable);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300233
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200234void dpi_set_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300235 struct omap_video_timings *timings)
236{
237 DSSDBG("dpi_set_timings\n");
238 dssdev->panel.timings = *timings;
239 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
240 dpi_set_mode(dssdev);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000241 dispc_go(dssdev->manager->id);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300242 }
243}
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200244EXPORT_SYMBOL(dpi_set_timings);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300245
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200246int dpi_check_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300247 struct omap_video_timings *timings)
248{
249 bool is_tft;
250 int r;
251 int lck_div, pck_div;
252 unsigned long fck;
253 unsigned long pck;
254
255 if (!dispc_lcd_timings_ok(timings))
256 return -EINVAL;
257
258 if (timings->pixel_clock == 0)
259 return -EINVAL;
260
261 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
262
263#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
264 {
265 struct dsi_clock_info dsi_cinfo;
266 struct dispc_clock_info dispc_cinfo;
267 r = dsi_pll_calc_clock_div_pck(is_tft,
268 timings->pixel_clock * 1000,
269 &dsi_cinfo, &dispc_cinfo);
270
271 if (r)
272 return r;
273
274 fck = dsi_cinfo.dsi1_pll_fclk;
275 lck_div = dispc_cinfo.lck_div;
276 pck_div = dispc_cinfo.pck_div;
277 }
278#else
279 {
280 struct dss_clock_info dss_cinfo;
281 struct dispc_clock_info dispc_cinfo;
282 r = dss_calc_clock_div(is_tft, timings->pixel_clock * 1000,
283 &dss_cinfo, &dispc_cinfo);
284
285 if (r)
286 return r;
287
288 fck = dss_cinfo.fck;
289 lck_div = dispc_cinfo.lck_div;
290 pck_div = dispc_cinfo.pck_div;
291 }
292#endif
293
294 pck = fck / lck_div / pck_div / 1000;
295
296 timings->pixel_clock = pck;
297
298 return 0;
299}
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200300EXPORT_SYMBOL(dpi_check_timings);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300301
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300302int dpi_init_display(struct omap_dss_device *dssdev)
303{
304 DSSDBG("init_display\n");
305
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300306 return 0;
307}
308
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200309int dpi_init(struct platform_device *pdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300310{
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200311 if (cpu_is_omap34xx()) {
312 dpi.vdds_dsi_reg = dss_get_vdds_dsi();
313 if (IS_ERR(dpi.vdds_dsi_reg)) {
314 DSSERR("can't get VDDS_DSI regulator\n");
315 return PTR_ERR(dpi.vdds_dsi_reg);
316 }
317 }
318
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300319 return 0;
320}
321
322void dpi_exit(void)
323{
324}
325