blob: 4d661a949b89540a7ddb62214989c204ccf4026d [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
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030033#include <video/omapdss.h>
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030034#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;
Archit Tanejaa72b64b2011-05-12 17:26:26 +053040 struct platform_device *dsidev;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030041} dpi;
42
Archit Tanejaa72b64b2011-05-12 17:26:26 +053043static 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
Archit Taneja7636b3b2011-04-12 13:52:26 +053052static 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 ||
56 dssdev->clocks.dispc.channel.lcd_clk_src ==
57 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC)
58 return true;
59 else
60 return false;
61}
62
Sumit Semwalff1b2cd2010-12-02 11:27:11 +000063static int dpi_set_dsi_clk(struct omap_dss_device *dssdev, bool is_tft,
64 unsigned long pck_req, unsigned long *fck, int *lck_div,
65 int *pck_div)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030066{
67 struct dsi_clock_info dsi_cinfo;
68 struct dispc_clock_info dispc_cinfo;
69 int r;
70
Archit Tanejaa72b64b2011-05-12 17:26:26 +053071 r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft, pck_req,
72 &dsi_cinfo, &dispc_cinfo);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030073 if (r)
74 return r;
75
Archit Tanejaa72b64b2011-05-12 17:26:26 +053076 r = dsi_pll_set_clock_div(dpi.dsidev, &dsi_cinfo);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030077 if (r)
78 return r;
79
Archit Tanejae8881662011-04-12 13:52:24 +053080 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030081
Sumit Semwalff1b2cd2010-12-02 11:27:11 +000082 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030083 if (r)
84 return r;
85
Archit Taneja1bb47832011-02-24 14:17:30 +053086 *fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030087 *lck_div = dispc_cinfo.lck_div;
88 *pck_div = dispc_cinfo.pck_div;
89
90 return 0;
91}
Archit Taneja7636b3b2011-04-12 13:52:26 +053092
Sumit Semwalff1b2cd2010-12-02 11:27:11 +000093static int dpi_set_dispc_clk(struct omap_dss_device *dssdev, bool is_tft,
94 unsigned long pck_req, unsigned long *fck, int *lck_div,
95 int *pck_div)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +030096{
97 struct dss_clock_info dss_cinfo;
98 struct dispc_clock_info dispc_cinfo;
99 int r;
100
101 r = dss_calc_clock_div(is_tft, pck_req, &dss_cinfo, &dispc_cinfo);
102 if (r)
103 return r;
104
105 r = dss_set_clock_div(&dss_cinfo);
106 if (r)
107 return r;
108
Sumit Semwalff1b2cd2010-12-02 11:27:11 +0000109 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300110 if (r)
111 return r;
112
113 *fck = dss_cinfo.fck;
114 *lck_div = dispc_cinfo.lck_div;
115 *pck_div = dispc_cinfo.pck_div;
116
117 return 0;
118}
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300119
120static int dpi_set_mode(struct omap_dss_device *dssdev)
121{
122 struct omap_video_timings *t = &dssdev->panel.timings;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530123 int lck_div = 0, pck_div = 0;
124 unsigned long fck = 0;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300125 unsigned long pck;
126 bool is_tft;
127 int r = 0;
128
Archit Taneja6af9cd12011-01-31 16:27:44 +0000129 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300130
Sumit Semwalff1b2cd2010-12-02 11:27:11 +0000131 dispc_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
132 dssdev->panel.acbi, dssdev->panel.acb);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300133
134 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
135
Archit Taneja7636b3b2011-04-12 13:52:26 +0530136 if (dpi_use_dsi_pll(dssdev))
137 r = dpi_set_dsi_clk(dssdev, is_tft, t->pixel_clock * 1000,
138 &fck, &lck_div, &pck_div);
139 else
140 r = dpi_set_dispc_clk(dssdev, is_tft, t->pixel_clock * 1000,
141 &fck, &lck_div, &pck_div);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300142 if (r)
143 goto err0;
144
145 pck = fck / lck_div / pck_div / 1000;
146
147 if (pck != t->pixel_clock) {
148 DSSWARN("Could not find exact pixel clock. "
149 "Requested %d kHz, got %lu kHz\n",
150 t->pixel_clock, pck);
151
152 t->pixel_clock = pck;
153 }
154
Sumit Semwal64ba4f72010-12-02 11:27:10 +0000155 dispc_set_lcd_timings(dssdev->manager->id, t);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300156
157err0:
Archit Taneja6af9cd12011-01-31 16:27:44 +0000158 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300159 return r;
160}
161
162static int dpi_basic_init(struct omap_dss_device *dssdev)
163{
164 bool is_tft;
165
166 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
167
Sumit Semwal64ba4f72010-12-02 11:27:10 +0000168 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);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300174
175 return 0;
176}
177
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200178int omapdss_dpi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300179{
180 int r;
181
182 r = omap_dss_start_device(dssdev);
183 if (r) {
184 DSSERR("failed to start device\n");
185 goto err0;
186 }
187
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200188 if (cpu_is_omap34xx()) {
189 r = regulator_enable(dpi.vdds_dsi_reg);
190 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200191 goto err1;
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200192 }
193
Archit Taneja6af9cd12011-01-31 16:27:44 +0000194 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300195
196 r = dpi_basic_init(dssdev);
197 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200198 goto err2;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300199
Archit Taneja7636b3b2011-04-12 13:52:26 +0530200 if (dpi_use_dsi_pll(dssdev)) {
201 dss_clk_enable(DSS_CLK_SYSCK);
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530202 r = dsi_pll_init(dpi.dsidev, 0, 1);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530203 if (r)
204 goto err3;
205 }
206
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300207 r = dpi_set_mode(dssdev);
208 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200209 goto err4;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300210
211 mdelay(2);
212
Tomi Valkeinena2faee82010-01-08 17:14:53 +0200213 dssdev->manager->enable(dssdev->manager);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300214
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300215 return 0;
216
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200217err4:
Archit Taneja7636b3b2011-04-12 13:52:26 +0530218 if (dpi_use_dsi_pll(dssdev))
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530219 dsi_pll_uninit(dpi.dsidev, true);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200220err3:
Archit Taneja7636b3b2011-04-12 13:52:26 +0530221 if (dpi_use_dsi_pll(dssdev))
222 dss_clk_disable(DSS_CLK_SYSCK);
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200223err2:
Archit Taneja6af9cd12011-01-31 16:27:44 +0000224 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200225 if (cpu_is_omap34xx())
226 regulator_disable(dpi.vdds_dsi_reg);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300227err1:
228 omap_dss_stop_device(dssdev);
229err0:
230 return r;
231}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200232EXPORT_SYMBOL(omapdss_dpi_display_enable);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300233
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200234void omapdss_dpi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300235{
Tomi Valkeinena2faee82010-01-08 17:14:53 +0200236 dssdev->manager->disable(dssdev->manager);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300237
Archit Taneja7636b3b2011-04-12 13:52:26 +0530238 if (dpi_use_dsi_pll(dssdev)) {
239 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530240 dsi_pll_uninit(dpi.dsidev, true);
Archit Taneja7636b3b2011-04-12 13:52:26 +0530241 dss_clk_disable(DSS_CLK_SYSCK);
242 }
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300243
Archit Taneja6af9cd12011-01-31 16:27:44 +0000244 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300245
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +0200246 if (cpu_is_omap34xx())
247 regulator_disable(dpi.vdds_dsi_reg);
248
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300249 omap_dss_stop_device(dssdev);
250}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200251EXPORT_SYMBOL(omapdss_dpi_display_disable);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300252
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200253void dpi_set_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300254 struct omap_video_timings *timings)
255{
256 DSSDBG("dpi_set_timings\n");
257 dssdev->panel.timings = *timings;
258 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
259 dpi_set_mode(dssdev);
Sumit Semwal2a205f32010-12-02 11:27:12 +0000260 dispc_go(dssdev->manager->id);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300261 }
262}
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200263EXPORT_SYMBOL(dpi_set_timings);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300264
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200265int dpi_check_timings(struct omap_dss_device *dssdev,
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300266 struct omap_video_timings *timings)
267{
268 bool is_tft;
269 int r;
270 int lck_div, pck_div;
271 unsigned long fck;
272 unsigned long pck;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530273 struct dispc_clock_info dispc_cinfo;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300274
275 if (!dispc_lcd_timings_ok(timings))
276 return -EINVAL;
277
278 if (timings->pixel_clock == 0)
279 return -EINVAL;
280
281 is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
282
Archit Taneja7636b3b2011-04-12 13:52:26 +0530283 if (dpi_use_dsi_pll(dssdev)) {
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300284 struct dsi_clock_info dsi_cinfo;
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530285 r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft,
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300286 timings->pixel_clock * 1000,
287 &dsi_cinfo, &dispc_cinfo);
288
289 if (r)
290 return r;
291
Archit Taneja1bb47832011-02-24 14:17:30 +0530292 fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
Archit Taneja7636b3b2011-04-12 13:52:26 +0530293 } else {
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300294 struct dss_clock_info dss_cinfo;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300295 r = dss_calc_clock_div(is_tft, timings->pixel_clock * 1000,
296 &dss_cinfo, &dispc_cinfo);
297
298 if (r)
299 return r;
300
301 fck = dss_cinfo.fck;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300302 }
Archit Taneja7636b3b2011-04-12 13:52:26 +0530303
304 lck_div = dispc_cinfo.lck_div;
305 pck_div = dispc_cinfo.pck_div;
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300306
307 pck = fck / lck_div / pck_div / 1000;
308
309 timings->pixel_clock = pck;
310
311 return 0;
312}
Tomi Valkeinen69b20482010-01-20 12:11:25 +0200313EXPORT_SYMBOL(dpi_check_timings);
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300314
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300315int dpi_init_display(struct omap_dss_device *dssdev)
316{
317 DSSDBG("init_display\n");
318
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +0200319 if (cpu_is_omap34xx() && dpi.vdds_dsi_reg == NULL) {
320 struct regulator *vdds_dsi;
321
322 vdds_dsi = dss_get_vdds_dsi();
323
324 if (IS_ERR(vdds_dsi)) {
325 DSSERR("can't get VDDS_DSI regulator\n");
326 return PTR_ERR(vdds_dsi);
327 }
328
329 dpi.vdds_dsi_reg = vdds_dsi;
330 }
331
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530332 if (dpi_use_dsi_pll(dssdev)) {
333 enum omap_dss_clk_source dispc_fclk_src =
334 dssdev->clocks.dispc.dispc_fclk_src;
335 dpi.dsidev = dpi_get_dsidev(dispc_fclk_src);
336 }
337
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300338 return 0;
339}
340
Tomi Valkeinen277b2882011-03-02 12:32:48 +0200341int dpi_init(void)
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300342{
Tomi Valkeinen553c48c2009-08-07 13:15:50 +0300343 return 0;
344}
345
346void dpi_exit(void)
347{
348}
349