Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / drivers / video / omap2 / dss / dss.c
blobf2c21164b15bacb2c03d2325144dba2e8c2fe32b
1 /*
2 * linux/drivers/video/omap2/dss/dss.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 "DSS"
25 #include <linux/kernel.h>
26 #include <linux/io.h>
27 #include <linux/export.h>
28 #include <linux/err.h>
29 #include <linux/delay.h>
30 #include <linux/seq_file.h>
31 #include <linux/clk.h>
32 #include <linux/platform_device.h>
33 #include <linux/pm_runtime.h>
35 #include <video/omapdss.h>
36 #include <plat/clock.h>
37 #include "dss.h"
38 #include "dss_features.h"
40 #define DSS_SZ_REGS SZ_512
42 struct dss_reg {
43 u16 idx;
46 #define DSS_REG(idx) ((const struct dss_reg) { idx })
48 #define DSS_REVISION DSS_REG(0x0000)
49 #define DSS_SYSCONFIG DSS_REG(0x0010)
50 #define DSS_SYSSTATUS DSS_REG(0x0014)
51 #define DSS_CONTROL DSS_REG(0x0040)
52 #define DSS_SDI_CONTROL DSS_REG(0x0044)
53 #define DSS_PLL_CONTROL DSS_REG(0x0048)
54 #define DSS_SDI_STATUS DSS_REG(0x005C)
56 #define REG_GET(idx, start, end) \
57 FLD_GET(dss_read_reg(idx), start, end)
59 #define REG_FLD_MOD(idx, val, start, end) \
60 dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end))
62 static struct {
63 struct platform_device *pdev;
64 void __iomem *base;
66 struct clk *dpll4_m4_ck;
67 struct clk *dss_clk;
69 unsigned long cache_req_pck;
70 unsigned long cache_prate;
71 struct dss_clock_info cache_dss_cinfo;
72 struct dispc_clock_info cache_dispc_cinfo;
74 enum omap_dss_clk_source dsi_clk_source[MAX_NUM_DSI];
75 enum omap_dss_clk_source dispc_clk_source;
76 enum omap_dss_clk_source lcd_clk_source[MAX_DSS_LCD_MANAGERS];
78 bool ctx_valid;
79 u32 ctx[DSS_SZ_REGS / sizeof(u32)];
80 } dss;
82 static const char * const dss_generic_clk_source_names[] = {
83 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "DSI_PLL_HSDIV_DISPC",
84 [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "DSI_PLL_HSDIV_DSI",
85 [OMAP_DSS_CLK_SRC_FCK] = "DSS_FCK",
88 static inline void dss_write_reg(const struct dss_reg idx, u32 val)
90 __raw_writel(val, dss.base + idx.idx);
93 static inline u32 dss_read_reg(const struct dss_reg idx)
95 return __raw_readl(dss.base + idx.idx);
98 #define SR(reg) \
99 dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg)
100 #define RR(reg) \
101 dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)])
103 static void dss_save_context(void)
105 DSSDBG("dss_save_context\n");
107 SR(CONTROL);
109 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) &
110 OMAP_DISPLAY_TYPE_SDI) {
111 SR(SDI_CONTROL);
112 SR(PLL_CONTROL);
115 dss.ctx_valid = true;
117 DSSDBG("context saved\n");
120 static void dss_restore_context(void)
122 DSSDBG("dss_restore_context\n");
124 if (!dss.ctx_valid)
125 return;
127 RR(CONTROL);
129 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) &
130 OMAP_DISPLAY_TYPE_SDI) {
131 RR(SDI_CONTROL);
132 RR(PLL_CONTROL);
135 DSSDBG("context restored\n");
138 #undef SR
139 #undef RR
141 void dss_sdi_init(u8 datapairs)
143 u32 l;
145 BUG_ON(datapairs > 3 || datapairs < 1);
147 l = dss_read_reg(DSS_SDI_CONTROL);
148 l = FLD_MOD(l, 0xf, 19, 15); /* SDI_PDIV */
149 l = FLD_MOD(l, datapairs-1, 3, 2); /* SDI_PRSEL */
150 l = FLD_MOD(l, 2, 1, 0); /* SDI_BWSEL */
151 dss_write_reg(DSS_SDI_CONTROL, l);
153 l = dss_read_reg(DSS_PLL_CONTROL);
154 l = FLD_MOD(l, 0x7, 25, 22); /* SDI_PLL_FREQSEL */
155 l = FLD_MOD(l, 0xb, 16, 11); /* SDI_PLL_REGN */
156 l = FLD_MOD(l, 0xb4, 10, 1); /* SDI_PLL_REGM */
157 dss_write_reg(DSS_PLL_CONTROL, l);
160 int dss_sdi_enable(void)
162 unsigned long timeout;
164 dispc_pck_free_enable(1);
166 /* Reset SDI PLL */
167 REG_FLD_MOD(DSS_PLL_CONTROL, 1, 18, 18); /* SDI_PLL_SYSRESET */
168 udelay(1); /* wait 2x PCLK */
170 /* Lock SDI PLL */
171 REG_FLD_MOD(DSS_PLL_CONTROL, 1, 28, 28); /* SDI_PLL_GOBIT */
173 /* Waiting for PLL lock request to complete */
174 timeout = jiffies + msecs_to_jiffies(500);
175 while (dss_read_reg(DSS_SDI_STATUS) & (1 << 6)) {
176 if (time_after_eq(jiffies, timeout)) {
177 DSSERR("PLL lock request timed out\n");
178 goto err1;
182 /* Clearing PLL_GO bit */
183 REG_FLD_MOD(DSS_PLL_CONTROL, 0, 28, 28);
185 /* Waiting for PLL to lock */
186 timeout = jiffies + msecs_to_jiffies(500);
187 while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 5))) {
188 if (time_after_eq(jiffies, timeout)) {
189 DSSERR("PLL lock timed out\n");
190 goto err1;
194 dispc_lcd_enable_signal(1);
196 /* Waiting for SDI reset to complete */
197 timeout = jiffies + msecs_to_jiffies(500);
198 while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 2))) {
199 if (time_after_eq(jiffies, timeout)) {
200 DSSERR("SDI reset timed out\n");
201 goto err2;
205 return 0;
207 err2:
208 dispc_lcd_enable_signal(0);
209 err1:
210 /* Reset SDI PLL */
211 REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */
213 dispc_pck_free_enable(0);
215 return -ETIMEDOUT;
218 void dss_sdi_disable(void)
220 dispc_lcd_enable_signal(0);
222 dispc_pck_free_enable(0);
224 /* Reset SDI PLL */
225 REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */
228 const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src)
230 return dss_generic_clk_source_names[clk_src];
234 void dss_dump_clocks(struct seq_file *s)
236 unsigned long dpll4_ck_rate;
237 unsigned long dpll4_m4_ck_rate;
238 const char *fclk_name, *fclk_real_name;
239 unsigned long fclk_rate;
241 if (dss_runtime_get())
242 return;
244 seq_printf(s, "- DSS -\n");
246 fclk_name = dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_FCK);
247 fclk_real_name = dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_FCK);
248 fclk_rate = clk_get_rate(dss.dss_clk);
250 if (dss.dpll4_m4_ck) {
251 dpll4_ck_rate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck));
252 dpll4_m4_ck_rate = clk_get_rate(dss.dpll4_m4_ck);
254 seq_printf(s, "dpll4_ck %lu\n", dpll4_ck_rate);
256 if (cpu_is_omap3630() || cpu_is_omap44xx())
257 seq_printf(s, "%s (%s) = %lu / %lu = %lu\n",
258 fclk_name, fclk_real_name,
259 dpll4_ck_rate,
260 dpll4_ck_rate / dpll4_m4_ck_rate,
261 fclk_rate);
262 else
263 seq_printf(s, "%s (%s) = %lu / %lu * 2 = %lu\n",
264 fclk_name, fclk_real_name,
265 dpll4_ck_rate,
266 dpll4_ck_rate / dpll4_m4_ck_rate,
267 fclk_rate);
268 } else {
269 seq_printf(s, "%s (%s) = %lu\n",
270 fclk_name, fclk_real_name,
271 fclk_rate);
274 dss_runtime_put();
277 void dss_dump_regs(struct seq_file *s)
279 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r))
281 if (dss_runtime_get())
282 return;
284 DUMPREG(DSS_REVISION);
285 DUMPREG(DSS_SYSCONFIG);
286 DUMPREG(DSS_SYSSTATUS);
287 DUMPREG(DSS_CONTROL);
289 if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) &
290 OMAP_DISPLAY_TYPE_SDI) {
291 DUMPREG(DSS_SDI_CONTROL);
292 DUMPREG(DSS_PLL_CONTROL);
293 DUMPREG(DSS_SDI_STATUS);
296 dss_runtime_put();
297 #undef DUMPREG
300 void dss_select_dispc_clk_source(enum omap_dss_clk_source clk_src)
302 struct platform_device *dsidev;
303 int b;
304 u8 start, end;
306 switch (clk_src) {
307 case OMAP_DSS_CLK_SRC_FCK:
308 b = 0;
309 break;
310 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
311 b = 1;
312 dsidev = dsi_get_dsidev_from_id(0);
313 dsi_wait_pll_hsdiv_dispc_active(dsidev);
314 break;
315 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
316 b = 2;
317 dsidev = dsi_get_dsidev_from_id(1);
318 dsi_wait_pll_hsdiv_dispc_active(dsidev);
319 break;
320 default:
321 BUG();
324 dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH, &start, &end);
326 REG_FLD_MOD(DSS_CONTROL, b, start, end); /* DISPC_CLK_SWITCH */
328 dss.dispc_clk_source = clk_src;
331 void dss_select_dsi_clk_source(int dsi_module,
332 enum omap_dss_clk_source clk_src)
334 struct platform_device *dsidev;
335 int b;
337 switch (clk_src) {
338 case OMAP_DSS_CLK_SRC_FCK:
339 b = 0;
340 break;
341 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI:
342 BUG_ON(dsi_module != 0);
343 b = 1;
344 dsidev = dsi_get_dsidev_from_id(0);
345 dsi_wait_pll_hsdiv_dsi_active(dsidev);
346 break;
347 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI:
348 BUG_ON(dsi_module != 1);
349 b = 1;
350 dsidev = dsi_get_dsidev_from_id(1);
351 dsi_wait_pll_hsdiv_dsi_active(dsidev);
352 break;
353 default:
354 BUG();
357 REG_FLD_MOD(DSS_CONTROL, b, 1, 1); /* DSI_CLK_SWITCH */
359 dss.dsi_clk_source[dsi_module] = clk_src;
362 void dss_select_lcd_clk_source(enum omap_channel channel,
363 enum omap_dss_clk_source clk_src)
365 struct platform_device *dsidev;
366 int b, ix, pos;
368 if (!dss_has_feature(FEAT_LCD_CLK_SRC))
369 return;
371 switch (clk_src) {
372 case OMAP_DSS_CLK_SRC_FCK:
373 b = 0;
374 break;
375 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
376 BUG_ON(channel != OMAP_DSS_CHANNEL_LCD);
377 b = 1;
378 dsidev = dsi_get_dsidev_from_id(0);
379 dsi_wait_pll_hsdiv_dispc_active(dsidev);
380 break;
381 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
382 BUG_ON(channel != OMAP_DSS_CHANNEL_LCD2);
383 b = 1;
384 dsidev = dsi_get_dsidev_from_id(1);
385 dsi_wait_pll_hsdiv_dispc_active(dsidev);
386 break;
387 default:
388 BUG();
391 pos = channel == OMAP_DSS_CHANNEL_LCD ? 0 : 12;
392 REG_FLD_MOD(DSS_CONTROL, b, pos, pos); /* LCDx_CLK_SWITCH */
394 ix = channel == OMAP_DSS_CHANNEL_LCD ? 0 : 1;
395 dss.lcd_clk_source[ix] = clk_src;
398 enum omap_dss_clk_source dss_get_dispc_clk_source(void)
400 return dss.dispc_clk_source;
403 enum omap_dss_clk_source dss_get_dsi_clk_source(int dsi_module)
405 return dss.dsi_clk_source[dsi_module];
408 enum omap_dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel)
410 if (dss_has_feature(FEAT_LCD_CLK_SRC)) {
411 int ix = channel == OMAP_DSS_CHANNEL_LCD ? 0 : 1;
412 return dss.lcd_clk_source[ix];
413 } else {
414 /* LCD_CLK source is the same as DISPC_FCLK source for
415 * OMAP2 and OMAP3 */
416 return dss.dispc_clk_source;
420 /* calculate clock rates using dividers in cinfo */
421 int dss_calc_clock_rates(struct dss_clock_info *cinfo)
423 if (dss.dpll4_m4_ck) {
424 unsigned long prate;
425 u16 fck_div_max = 16;
427 if (cpu_is_omap3630() || cpu_is_omap44xx())
428 fck_div_max = 32;
430 if (cinfo->fck_div > fck_div_max || cinfo->fck_div == 0)
431 return -EINVAL;
433 prate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck));
435 cinfo->fck = prate / cinfo->fck_div;
436 } else {
437 if (cinfo->fck_div != 0)
438 return -EINVAL;
439 cinfo->fck = clk_get_rate(dss.dss_clk);
442 return 0;
445 int dss_set_clock_div(struct dss_clock_info *cinfo)
447 if (dss.dpll4_m4_ck) {
448 unsigned long prate;
449 int r;
451 prate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck));
452 DSSDBG("dpll4_m4 = %ld\n", prate);
454 r = clk_set_rate(dss.dpll4_m4_ck, prate / cinfo->fck_div);
455 if (r)
456 return r;
457 } else {
458 if (cinfo->fck_div != 0)
459 return -EINVAL;
462 DSSDBG("fck = %ld (%d)\n", cinfo->fck, cinfo->fck_div);
464 return 0;
467 int dss_get_clock_div(struct dss_clock_info *cinfo)
469 cinfo->fck = clk_get_rate(dss.dss_clk);
471 if (dss.dpll4_m4_ck) {
472 unsigned long prate;
474 prate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck));
476 if (cpu_is_omap3630() || cpu_is_omap44xx())
477 cinfo->fck_div = prate / (cinfo->fck);
478 else
479 cinfo->fck_div = prate / (cinfo->fck / 2);
480 } else {
481 cinfo->fck_div = 0;
484 return 0;
487 unsigned long dss_get_dpll4_rate(void)
489 if (dss.dpll4_m4_ck)
490 return clk_get_rate(clk_get_parent(dss.dpll4_m4_ck));
491 else
492 return 0;
495 int dss_calc_clock_div(bool is_tft, unsigned long req_pck,
496 struct dss_clock_info *dss_cinfo,
497 struct dispc_clock_info *dispc_cinfo)
499 unsigned long prate;
500 struct dss_clock_info best_dss;
501 struct dispc_clock_info best_dispc;
503 unsigned long fck, max_dss_fck;
505 u16 fck_div, fck_div_max = 16;
507 int match = 0;
508 int min_fck_per_pck;
510 prate = dss_get_dpll4_rate();
512 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
514 fck = clk_get_rate(dss.dss_clk);
515 if (req_pck == dss.cache_req_pck &&
516 ((cpu_is_omap34xx() && prate == dss.cache_prate) ||
517 dss.cache_dss_cinfo.fck == fck)) {
518 DSSDBG("dispc clock info found from cache.\n");
519 *dss_cinfo = dss.cache_dss_cinfo;
520 *dispc_cinfo = dss.cache_dispc_cinfo;
521 return 0;
524 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
526 if (min_fck_per_pck &&
527 req_pck * min_fck_per_pck > max_dss_fck) {
528 DSSERR("Requested pixel clock not possible with the current "
529 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
530 "the constraint off.\n");
531 min_fck_per_pck = 0;
534 retry:
535 memset(&best_dss, 0, sizeof(best_dss));
536 memset(&best_dispc, 0, sizeof(best_dispc));
538 if (dss.dpll4_m4_ck == NULL) {
539 struct dispc_clock_info cur_dispc;
540 /* XXX can we change the clock on omap2? */
541 fck = clk_get_rate(dss.dss_clk);
542 fck_div = 1;
544 dispc_find_clk_divs(is_tft, req_pck, fck, &cur_dispc);
545 match = 1;
547 best_dss.fck = fck;
548 best_dss.fck_div = fck_div;
550 best_dispc = cur_dispc;
552 goto found;
553 } else {
554 if (cpu_is_omap3630() || cpu_is_omap44xx())
555 fck_div_max = 32;
557 for (fck_div = fck_div_max; fck_div > 0; --fck_div) {
558 struct dispc_clock_info cur_dispc;
560 if (fck_div_max == 32)
561 fck = prate / fck_div;
562 else
563 fck = prate / fck_div * 2;
565 if (fck > max_dss_fck)
566 continue;
568 if (min_fck_per_pck &&
569 fck < req_pck * min_fck_per_pck)
570 continue;
572 match = 1;
574 dispc_find_clk_divs(is_tft, req_pck, fck, &cur_dispc);
576 if (abs(cur_dispc.pck - req_pck) <
577 abs(best_dispc.pck - req_pck)) {
579 best_dss.fck = fck;
580 best_dss.fck_div = fck_div;
582 best_dispc = cur_dispc;
584 if (cur_dispc.pck == req_pck)
585 goto found;
590 found:
591 if (!match) {
592 if (min_fck_per_pck) {
593 DSSERR("Could not find suitable clock settings.\n"
594 "Turning FCK/PCK constraint off and"
595 "trying again.\n");
596 min_fck_per_pck = 0;
597 goto retry;
600 DSSERR("Could not find suitable clock settings.\n");
602 return -EINVAL;
605 if (dss_cinfo)
606 *dss_cinfo = best_dss;
607 if (dispc_cinfo)
608 *dispc_cinfo = best_dispc;
610 dss.cache_req_pck = req_pck;
611 dss.cache_prate = prate;
612 dss.cache_dss_cinfo = best_dss;
613 dss.cache_dispc_cinfo = best_dispc;
615 return 0;
618 void dss_set_venc_output(enum omap_dss_venc_type type)
620 int l = 0;
622 if (type == OMAP_DSS_VENC_TYPE_COMPOSITE)
623 l = 0;
624 else if (type == OMAP_DSS_VENC_TYPE_SVIDEO)
625 l = 1;
626 else
627 BUG();
629 /* venc out selection. 0 = comp, 1 = svideo */
630 REG_FLD_MOD(DSS_CONTROL, l, 6, 6);
633 void dss_set_dac_pwrdn_bgz(bool enable)
635 REG_FLD_MOD(DSS_CONTROL, enable, 5, 5); /* DAC Power-Down Control */
638 void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select hdmi)
640 REG_FLD_MOD(DSS_CONTROL, hdmi, 15, 15); /* VENC_HDMI_SWITCH */
643 static int dss_get_clocks(void)
645 struct clk *clk;
646 int r;
648 clk = clk_get(&dss.pdev->dev, "fck");
649 if (IS_ERR(clk)) {
650 DSSERR("can't get clock fck\n");
651 r = PTR_ERR(clk);
652 goto err;
655 dss.dss_clk = clk;
657 if (cpu_is_omap34xx()) {
658 clk = clk_get(NULL, "dpll4_m4_ck");
659 if (IS_ERR(clk)) {
660 DSSERR("Failed to get dpll4_m4_ck\n");
661 r = PTR_ERR(clk);
662 goto err;
664 } else if (cpu_is_omap44xx()) {
665 clk = clk_get(NULL, "dpll_per_m5x2_ck");
666 if (IS_ERR(clk)) {
667 DSSERR("Failed to get dpll_per_m5x2_ck\n");
668 r = PTR_ERR(clk);
669 goto err;
671 } else { /* omap24xx */
672 clk = NULL;
675 dss.dpll4_m4_ck = clk;
677 return 0;
679 err:
680 if (dss.dss_clk)
681 clk_put(dss.dss_clk);
682 if (dss.dpll4_m4_ck)
683 clk_put(dss.dpll4_m4_ck);
685 return r;
688 static void dss_put_clocks(void)
690 if (dss.dpll4_m4_ck)
691 clk_put(dss.dpll4_m4_ck);
692 clk_put(dss.dss_clk);
695 struct clk *dss_get_ick(void)
697 return clk_get(&dss.pdev->dev, "ick");
700 int dss_runtime_get(void)
702 int r;
704 DSSDBG("dss_runtime_get\n");
706 r = pm_runtime_get_sync(&dss.pdev->dev);
707 WARN_ON(r < 0);
708 return r < 0 ? r : 0;
711 void dss_runtime_put(void)
713 int r;
715 DSSDBG("dss_runtime_put\n");
717 r = pm_runtime_put(&dss.pdev->dev);
718 WARN_ON(r < 0);
721 /* DEBUGFS */
722 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
723 void dss_debug_dump_clocks(struct seq_file *s)
725 dss_dump_clocks(s);
726 dispc_dump_clocks(s);
727 #ifdef CONFIG_OMAP2_DSS_DSI
728 dsi_dump_clocks(s);
729 #endif
731 #endif
733 /* DSS HW IP initialisation */
734 static int omap_dsshw_probe(struct platform_device *pdev)
736 struct resource *dss_mem;
737 u32 rev;
738 int r;
740 dss.pdev = pdev;
742 dss_mem = platform_get_resource(dss.pdev, IORESOURCE_MEM, 0);
743 if (!dss_mem) {
744 DSSERR("can't get IORESOURCE_MEM DSS\n");
745 r = -EINVAL;
746 goto err_ioremap;
748 dss.base = ioremap(dss_mem->start, resource_size(dss_mem));
749 if (!dss.base) {
750 DSSERR("can't ioremap DSS\n");
751 r = -ENOMEM;
752 goto err_ioremap;
755 r = dss_get_clocks();
756 if (r)
757 goto err_clocks;
759 pm_runtime_enable(&pdev->dev);
761 r = dss_runtime_get();
762 if (r)
763 goto err_runtime_get;
765 /* Select DPLL */
766 REG_FLD_MOD(DSS_CONTROL, 0, 0, 0);
768 #ifdef CONFIG_OMAP2_DSS_VENC
769 REG_FLD_MOD(DSS_CONTROL, 1, 4, 4); /* venc dac demen */
770 REG_FLD_MOD(DSS_CONTROL, 1, 3, 3); /* venc clock 4x enable */
771 REG_FLD_MOD(DSS_CONTROL, 0, 2, 2); /* venc clock mode = normal */
772 #endif
773 dss.dsi_clk_source[0] = OMAP_DSS_CLK_SRC_FCK;
774 dss.dsi_clk_source[1] = OMAP_DSS_CLK_SRC_FCK;
775 dss.dispc_clk_source = OMAP_DSS_CLK_SRC_FCK;
776 dss.lcd_clk_source[0] = OMAP_DSS_CLK_SRC_FCK;
777 dss.lcd_clk_source[1] = OMAP_DSS_CLK_SRC_FCK;
779 r = dpi_init();
780 if (r) {
781 DSSERR("Failed to initialize DPI\n");
782 goto err_dpi;
785 r = sdi_init();
786 if (r) {
787 DSSERR("Failed to initialize SDI\n");
788 goto err_sdi;
791 rev = dss_read_reg(DSS_REVISION);
792 printk(KERN_INFO "OMAP DSS rev %d.%d\n",
793 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
795 dss_runtime_put();
797 return 0;
798 err_sdi:
799 dpi_exit();
800 err_dpi:
801 dss_runtime_put();
802 err_runtime_get:
803 pm_runtime_disable(&pdev->dev);
804 dss_put_clocks();
805 err_clocks:
806 iounmap(dss.base);
807 err_ioremap:
808 return r;
811 static int omap_dsshw_remove(struct platform_device *pdev)
813 dpi_exit();
814 sdi_exit();
816 iounmap(dss.base);
818 pm_runtime_disable(&pdev->dev);
820 dss_put_clocks();
822 return 0;
825 static int dss_runtime_suspend(struct device *dev)
827 dss_save_context();
828 clk_disable(dss.dss_clk);
829 return 0;
832 static int dss_runtime_resume(struct device *dev)
834 clk_enable(dss.dss_clk);
835 dss_restore_context();
836 return 0;
839 static const struct dev_pm_ops dss_pm_ops = {
840 .runtime_suspend = dss_runtime_suspend,
841 .runtime_resume = dss_runtime_resume,
844 static struct platform_driver omap_dsshw_driver = {
845 .probe = omap_dsshw_probe,
846 .remove = omap_dsshw_remove,
847 .driver = {
848 .name = "omapdss_dss",
849 .owner = THIS_MODULE,
850 .pm = &dss_pm_ops,
854 int dss_init_platform_driver(void)
856 return platform_driver_register(&omap_dsshw_driver);
859 void dss_uninit_platform_driver(void)
861 return platform_driver_unregister(&omap_dsshw_driver);