2 * linux/drivers/video/omap2/dss/dispc.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 "DISPC"
25 #include <linux/kernel.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/vmalloc.h>
28 #include <linux/clk.h>
30 #include <linux/jiffies.h>
31 #include <linux/seq_file.h>
32 #include <linux/delay.h>
33 #include <linux/workqueue.h>
34 #include <linux/hardirq.h>
35 #include <linux/interrupt.h>
37 #include <plat/sram.h>
38 #include <plat/clock.h>
40 #include <plat/display.h>
43 #include "dss_features.h"
46 #define DISPC_SZ_REGS SZ_4K
48 struct dispc_reg { u16 idx; };
50 #define DISPC_REG(idx) ((const struct dispc_reg) { idx })
53 * DISPC common registers and
54 * DISPC channel registers , ch = 0 for LCD, ch = 1 for
55 * DIGIT, and ch = 2 for LCD2
57 #define DISPC_REVISION DISPC_REG(0x0000)
58 #define DISPC_SYSCONFIG DISPC_REG(0x0010)
59 #define DISPC_SYSSTATUS DISPC_REG(0x0014)
60 #define DISPC_IRQSTATUS DISPC_REG(0x0018)
61 #define DISPC_IRQENABLE DISPC_REG(0x001C)
62 #define DISPC_CONTROL DISPC_REG(0x0040)
63 #define DISPC_CONTROL2 DISPC_REG(0x0238)
64 #define DISPC_CONFIG DISPC_REG(0x0044)
65 #define DISPC_CONFIG2 DISPC_REG(0x0620)
66 #define DISPC_CAPABLE DISPC_REG(0x0048)
67 #define DISPC_DEFAULT_COLOR(ch) DISPC_REG(ch == 0 ? 0x004C : \
68 (ch == 1 ? 0x0050 : 0x03AC))
69 #define DISPC_TRANS_COLOR(ch) DISPC_REG(ch == 0 ? 0x0054 : \
70 (ch == 1 ? 0x0058 : 0x03B0))
71 #define DISPC_LINE_STATUS DISPC_REG(0x005C)
72 #define DISPC_LINE_NUMBER DISPC_REG(0x0060)
73 #define DISPC_TIMING_H(ch) DISPC_REG(ch != 2 ? 0x0064 : 0x0400)
74 #define DISPC_TIMING_V(ch) DISPC_REG(ch != 2 ? 0x0068 : 0x0404)
75 #define DISPC_POL_FREQ(ch) DISPC_REG(ch != 2 ? 0x006C : 0x0408)
76 #define DISPC_DIVISORo(ch) DISPC_REG(ch != 2 ? 0x0070 : 0x040C)
77 #define DISPC_GLOBAL_ALPHA DISPC_REG(0x0074)
78 #define DISPC_SIZE_DIG DISPC_REG(0x0078)
79 #define DISPC_SIZE_LCD(ch) DISPC_REG(ch != 2 ? 0x007C : 0x03CC)
82 #define DISPC_GFX_BA0 DISPC_REG(0x0080)
83 #define DISPC_GFX_BA1 DISPC_REG(0x0084)
84 #define DISPC_GFX_POSITION DISPC_REG(0x0088)
85 #define DISPC_GFX_SIZE DISPC_REG(0x008C)
86 #define DISPC_GFX_ATTRIBUTES DISPC_REG(0x00A0)
87 #define DISPC_GFX_FIFO_THRESHOLD DISPC_REG(0x00A4)
88 #define DISPC_GFX_FIFO_SIZE_STATUS DISPC_REG(0x00A8)
89 #define DISPC_GFX_ROW_INC DISPC_REG(0x00AC)
90 #define DISPC_GFX_PIXEL_INC DISPC_REG(0x00B0)
91 #define DISPC_GFX_WINDOW_SKIP DISPC_REG(0x00B4)
92 #define DISPC_GFX_TABLE_BA DISPC_REG(0x00B8)
94 #define DISPC_DATA_CYCLE1(ch) DISPC_REG(ch != 2 ? 0x01D4 : 0x03C0)
95 #define DISPC_DATA_CYCLE2(ch) DISPC_REG(ch != 2 ? 0x01D8 : 0x03C4)
96 #define DISPC_DATA_CYCLE3(ch) DISPC_REG(ch != 2 ? 0x01DC : 0x03C8)
97 #define DISPC_CPR_COEF_R(ch) DISPC_REG(ch != 2 ? 0x0220 : 0x03BC)
98 #define DISPC_CPR_COEF_G(ch) DISPC_REG(ch != 2 ? 0x0224 : 0x03B8)
99 #define DISPC_CPR_COEF_B(ch) DISPC_REG(ch != 2 ? 0x0228 : 0x03B4)
101 #define DISPC_GFX_PRELOAD DISPC_REG(0x022C)
103 /* DISPC Video plane, n = 0 for VID1 and n = 1 for VID2 */
104 #define DISPC_VID_REG(n, idx) DISPC_REG(0x00BC + (n)*0x90 + idx)
106 #define DISPC_VID_BA0(n) DISPC_VID_REG(n, 0x0000)
107 #define DISPC_VID_BA1(n) DISPC_VID_REG(n, 0x0004)
108 #define DISPC_VID_POSITION(n) DISPC_VID_REG(n, 0x0008)
109 #define DISPC_VID_SIZE(n) DISPC_VID_REG(n, 0x000C)
110 #define DISPC_VID_ATTRIBUTES(n) DISPC_VID_REG(n, 0x0010)
111 #define DISPC_VID_FIFO_THRESHOLD(n) DISPC_VID_REG(n, 0x0014)
112 #define DISPC_VID_FIFO_SIZE_STATUS(n) DISPC_VID_REG(n, 0x0018)
113 #define DISPC_VID_ROW_INC(n) DISPC_VID_REG(n, 0x001C)
114 #define DISPC_VID_PIXEL_INC(n) DISPC_VID_REG(n, 0x0020)
115 #define DISPC_VID_FIR(n) DISPC_VID_REG(n, 0x0024)
116 #define DISPC_VID_PICTURE_SIZE(n) DISPC_VID_REG(n, 0x0028)
117 #define DISPC_VID_ACCU0(n) DISPC_VID_REG(n, 0x002C)
118 #define DISPC_VID_ACCU1(n) DISPC_VID_REG(n, 0x0030)
120 /* coef index i = {0, 1, 2, 3, 4, 5, 6, 7} */
121 #define DISPC_VID_FIR_COEF_H(n, i) DISPC_REG(0x00F0 + (n)*0x90 + (i)*0x8)
122 /* coef index i = {0, 1, 2, 3, 4, 5, 6, 7} */
123 #define DISPC_VID_FIR_COEF_HV(n, i) DISPC_REG(0x00F4 + (n)*0x90 + (i)*0x8)
124 /* coef index i = {0, 1, 2, 3, 4} */
125 #define DISPC_VID_CONV_COEF(n, i) DISPC_REG(0x0130 + (n)*0x90 + (i)*0x4)
126 /* coef index i = {0, 1, 2, 3, 4, 5, 6, 7} */
127 #define DISPC_VID_FIR_COEF_V(n, i) DISPC_REG(0x01E0 + (n)*0x20 + (i)*0x4)
129 #define DISPC_VID_PRELOAD(n) DISPC_REG(0x230 + (n)*0x04)
131 #define DISPC_DIVISOR DISPC_REG(0x0804)
133 #define DISPC_IRQ_MASK_ERROR (DISPC_IRQ_GFX_FIFO_UNDERFLOW | \
134 DISPC_IRQ_OCP_ERR | \
135 DISPC_IRQ_VID1_FIFO_UNDERFLOW | \
136 DISPC_IRQ_VID2_FIFO_UNDERFLOW | \
137 DISPC_IRQ_SYNC_LOST | \
138 DISPC_IRQ_SYNC_LOST_DIGIT)
140 #define DISPC_MAX_NR_ISRS 8
142 struct omap_dispc_isr_data {
143 omap_dispc_isr_t isr;
148 struct dispc_h_coef {
156 struct dispc_v_coef {
164 #define REG_GET(idx, start, end) \
165 FLD_GET(dispc_read_reg(idx), start, end)
167 #define REG_FLD_MOD(idx, val, start, end) \
168 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
170 static const struct dispc_reg dispc_reg_att[] = { DISPC_GFX_ATTRIBUTES,
171 DISPC_VID_ATTRIBUTES(0),
172 DISPC_VID_ATTRIBUTES(1) };
174 struct dispc_irq_stats {
175 unsigned long last_reset;
181 struct platform_device *pdev;
189 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
191 struct work_struct error_work;
193 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
195 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
196 spinlock_t irq_stats_lock;
197 struct dispc_irq_stats irq_stats;
201 static void _omap_dispc_set_irqs(void);
203 static inline void dispc_write_reg(const struct dispc_reg idx, u32 val)
205 __raw_writel(val, dispc.base + idx.idx);
208 static inline u32 dispc_read_reg(const struct dispc_reg idx)
210 return __raw_readl(dispc.base + idx.idx);
214 dispc.ctx[(DISPC_##reg).idx / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
216 dispc_write_reg(DISPC_##reg, dispc.ctx[(DISPC_##reg).idx / sizeof(u32)])
218 void dispc_save_context(void)
220 if (cpu_is_omap24xx())
227 SR(DEFAULT_COLOR(0));
228 SR(DEFAULT_COLOR(1));
239 if (dss_has_feature(FEAT_MGR_LCD2)) {
241 SR(DEFAULT_COLOR(2));
256 SR(GFX_FIFO_THRESHOLD);
269 if (dss_has_feature(FEAT_MGR_LCD2)) {
286 SR(VID_ATTRIBUTES(0));
287 SR(VID_FIFO_THRESHOLD(0));
289 SR(VID_PIXEL_INC(0));
291 SR(VID_PICTURE_SIZE(0));
295 SR(VID_FIR_COEF_H(0, 0));
296 SR(VID_FIR_COEF_H(0, 1));
297 SR(VID_FIR_COEF_H(0, 2));
298 SR(VID_FIR_COEF_H(0, 3));
299 SR(VID_FIR_COEF_H(0, 4));
300 SR(VID_FIR_COEF_H(0, 5));
301 SR(VID_FIR_COEF_H(0, 6));
302 SR(VID_FIR_COEF_H(0, 7));
304 SR(VID_FIR_COEF_HV(0, 0));
305 SR(VID_FIR_COEF_HV(0, 1));
306 SR(VID_FIR_COEF_HV(0, 2));
307 SR(VID_FIR_COEF_HV(0, 3));
308 SR(VID_FIR_COEF_HV(0, 4));
309 SR(VID_FIR_COEF_HV(0, 5));
310 SR(VID_FIR_COEF_HV(0, 6));
311 SR(VID_FIR_COEF_HV(0, 7));
313 SR(VID_CONV_COEF(0, 0));
314 SR(VID_CONV_COEF(0, 1));
315 SR(VID_CONV_COEF(0, 2));
316 SR(VID_CONV_COEF(0, 3));
317 SR(VID_CONV_COEF(0, 4));
319 SR(VID_FIR_COEF_V(0, 0));
320 SR(VID_FIR_COEF_V(0, 1));
321 SR(VID_FIR_COEF_V(0, 2));
322 SR(VID_FIR_COEF_V(0, 3));
323 SR(VID_FIR_COEF_V(0, 4));
324 SR(VID_FIR_COEF_V(0, 5));
325 SR(VID_FIR_COEF_V(0, 6));
326 SR(VID_FIR_COEF_V(0, 7));
335 SR(VID_ATTRIBUTES(1));
336 SR(VID_FIFO_THRESHOLD(1));
338 SR(VID_PIXEL_INC(1));
340 SR(VID_PICTURE_SIZE(1));
344 SR(VID_FIR_COEF_H(1, 0));
345 SR(VID_FIR_COEF_H(1, 1));
346 SR(VID_FIR_COEF_H(1, 2));
347 SR(VID_FIR_COEF_H(1, 3));
348 SR(VID_FIR_COEF_H(1, 4));
349 SR(VID_FIR_COEF_H(1, 5));
350 SR(VID_FIR_COEF_H(1, 6));
351 SR(VID_FIR_COEF_H(1, 7));
353 SR(VID_FIR_COEF_HV(1, 0));
354 SR(VID_FIR_COEF_HV(1, 1));
355 SR(VID_FIR_COEF_HV(1, 2));
356 SR(VID_FIR_COEF_HV(1, 3));
357 SR(VID_FIR_COEF_HV(1, 4));
358 SR(VID_FIR_COEF_HV(1, 5));
359 SR(VID_FIR_COEF_HV(1, 6));
360 SR(VID_FIR_COEF_HV(1, 7));
362 SR(VID_CONV_COEF(1, 0));
363 SR(VID_CONV_COEF(1, 1));
364 SR(VID_CONV_COEF(1, 2));
365 SR(VID_CONV_COEF(1, 3));
366 SR(VID_CONV_COEF(1, 4));
368 SR(VID_FIR_COEF_V(1, 0));
369 SR(VID_FIR_COEF_V(1, 1));
370 SR(VID_FIR_COEF_V(1, 2));
371 SR(VID_FIR_COEF_V(1, 3));
372 SR(VID_FIR_COEF_V(1, 4));
373 SR(VID_FIR_COEF_V(1, 5));
374 SR(VID_FIR_COEF_V(1, 6));
375 SR(VID_FIR_COEF_V(1, 7));
379 if (dss_has_feature(FEAT_CORE_CLK_DIV))
383 void dispc_restore_context(void)
389 RR(DEFAULT_COLOR(0));
390 RR(DEFAULT_COLOR(1));
401 if (dss_has_feature(FEAT_MGR_LCD2)) {
402 RR(DEFAULT_COLOR(2));
417 RR(GFX_FIFO_THRESHOLD);
430 if (dss_has_feature(FEAT_MGR_LCD2)) {
447 RR(VID_ATTRIBUTES(0));
448 RR(VID_FIFO_THRESHOLD(0));
450 RR(VID_PIXEL_INC(0));
452 RR(VID_PICTURE_SIZE(0));
456 RR(VID_FIR_COEF_H(0, 0));
457 RR(VID_FIR_COEF_H(0, 1));
458 RR(VID_FIR_COEF_H(0, 2));
459 RR(VID_FIR_COEF_H(0, 3));
460 RR(VID_FIR_COEF_H(0, 4));
461 RR(VID_FIR_COEF_H(0, 5));
462 RR(VID_FIR_COEF_H(0, 6));
463 RR(VID_FIR_COEF_H(0, 7));
465 RR(VID_FIR_COEF_HV(0, 0));
466 RR(VID_FIR_COEF_HV(0, 1));
467 RR(VID_FIR_COEF_HV(0, 2));
468 RR(VID_FIR_COEF_HV(0, 3));
469 RR(VID_FIR_COEF_HV(0, 4));
470 RR(VID_FIR_COEF_HV(0, 5));
471 RR(VID_FIR_COEF_HV(0, 6));
472 RR(VID_FIR_COEF_HV(0, 7));
474 RR(VID_CONV_COEF(0, 0));
475 RR(VID_CONV_COEF(0, 1));
476 RR(VID_CONV_COEF(0, 2));
477 RR(VID_CONV_COEF(0, 3));
478 RR(VID_CONV_COEF(0, 4));
480 RR(VID_FIR_COEF_V(0, 0));
481 RR(VID_FIR_COEF_V(0, 1));
482 RR(VID_FIR_COEF_V(0, 2));
483 RR(VID_FIR_COEF_V(0, 3));
484 RR(VID_FIR_COEF_V(0, 4));
485 RR(VID_FIR_COEF_V(0, 5));
486 RR(VID_FIR_COEF_V(0, 6));
487 RR(VID_FIR_COEF_V(0, 7));
496 RR(VID_ATTRIBUTES(1));
497 RR(VID_FIFO_THRESHOLD(1));
499 RR(VID_PIXEL_INC(1));
501 RR(VID_PICTURE_SIZE(1));
505 RR(VID_FIR_COEF_H(1, 0));
506 RR(VID_FIR_COEF_H(1, 1));
507 RR(VID_FIR_COEF_H(1, 2));
508 RR(VID_FIR_COEF_H(1, 3));
509 RR(VID_FIR_COEF_H(1, 4));
510 RR(VID_FIR_COEF_H(1, 5));
511 RR(VID_FIR_COEF_H(1, 6));
512 RR(VID_FIR_COEF_H(1, 7));
514 RR(VID_FIR_COEF_HV(1, 0));
515 RR(VID_FIR_COEF_HV(1, 1));
516 RR(VID_FIR_COEF_HV(1, 2));
517 RR(VID_FIR_COEF_HV(1, 3));
518 RR(VID_FIR_COEF_HV(1, 4));
519 RR(VID_FIR_COEF_HV(1, 5));
520 RR(VID_FIR_COEF_HV(1, 6));
521 RR(VID_FIR_COEF_HV(1, 7));
523 RR(VID_CONV_COEF(1, 0));
524 RR(VID_CONV_COEF(1, 1));
525 RR(VID_CONV_COEF(1, 2));
526 RR(VID_CONV_COEF(1, 3));
527 RR(VID_CONV_COEF(1, 4));
529 RR(VID_FIR_COEF_V(1, 0));
530 RR(VID_FIR_COEF_V(1, 1));
531 RR(VID_FIR_COEF_V(1, 2));
532 RR(VID_FIR_COEF_V(1, 3));
533 RR(VID_FIR_COEF_V(1, 4));
534 RR(VID_FIR_COEF_V(1, 5));
535 RR(VID_FIR_COEF_V(1, 6));
536 RR(VID_FIR_COEF_V(1, 7));
540 if (dss_has_feature(FEAT_CORE_CLK_DIV))
543 /* enable last, because LCD & DIGIT enable are here */
545 if (dss_has_feature(FEAT_MGR_LCD2))
547 /* clear spurious SYNC_LOST_DIGIT interrupts */
548 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
551 * enable last so IRQs won't trigger before
552 * the context is fully restored
560 static inline void enable_clocks(bool enable)
563 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
565 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
568 bool dispc_go_busy(enum omap_channel channel)
572 if (channel == OMAP_DSS_CHANNEL_LCD ||
573 channel == OMAP_DSS_CHANNEL_LCD2)
576 bit = 6; /* GODIGIT */
578 if (channel == OMAP_DSS_CHANNEL_LCD2)
579 return REG_GET(DISPC_CONTROL2, bit, bit) == 1;
581 return REG_GET(DISPC_CONTROL, bit, bit) == 1;
584 void dispc_go(enum omap_channel channel)
587 bool enable_bit, go_bit;
591 if (channel == OMAP_DSS_CHANNEL_LCD ||
592 channel == OMAP_DSS_CHANNEL_LCD2)
593 bit = 0; /* LCDENABLE */
595 bit = 1; /* DIGITALENABLE */
597 /* if the channel is not enabled, we don't need GO */
598 if (channel == OMAP_DSS_CHANNEL_LCD2)
599 enable_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
601 enable_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
606 if (channel == OMAP_DSS_CHANNEL_LCD ||
607 channel == OMAP_DSS_CHANNEL_LCD2)
610 bit = 6; /* GODIGIT */
612 if (channel == OMAP_DSS_CHANNEL_LCD2)
613 go_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
615 go_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
618 DSSERR("GO bit not down for channel %d\n", channel);
622 DSSDBG("GO %s\n", channel == OMAP_DSS_CHANNEL_LCD ? "LCD" :
623 (channel == OMAP_DSS_CHANNEL_LCD2 ? "LCD2" : "DIGIT"));
625 if (channel == OMAP_DSS_CHANNEL_LCD2)
626 REG_FLD_MOD(DISPC_CONTROL2, 1, bit, bit);
628 REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit);
633 static void _dispc_write_firh_reg(enum omap_plane plane, int reg, u32 value)
635 BUG_ON(plane == OMAP_DSS_GFX);
637 dispc_write_reg(DISPC_VID_FIR_COEF_H(plane-1, reg), value);
640 static void _dispc_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
642 BUG_ON(plane == OMAP_DSS_GFX);
644 dispc_write_reg(DISPC_VID_FIR_COEF_HV(plane-1, reg), value);
647 static void _dispc_write_firv_reg(enum omap_plane plane, int reg, u32 value)
649 BUG_ON(plane == OMAP_DSS_GFX);
651 dispc_write_reg(DISPC_VID_FIR_COEF_V(plane-1, reg), value);
654 static void _dispc_set_scale_coef(enum omap_plane plane, int hscaleup,
655 int vscaleup, int five_taps)
657 /* Coefficients for horizontal up-sampling */
658 static const struct dispc_h_coef coef_hup[8] = {
660 { -1, 13, 124, -8, 0 },
661 { -2, 30, 112, -11, -1 },
662 { -5, 51, 95, -11, -2 },
663 { 0, -9, 73, 73, -9 },
664 { -2, -11, 95, 51, -5 },
665 { -1, -11, 112, 30, -2 },
666 { 0, -8, 124, 13, -1 },
669 /* Coefficients for vertical up-sampling */
670 static const struct dispc_v_coef coef_vup_3tap[8] = {
673 { 0, 12, 111, 5, 0 },
677 { 0, 5, 111, 12, 0 },
681 static const struct dispc_v_coef coef_vup_5tap[8] = {
683 { -1, 13, 124, -8, 0 },
684 { -2, 30, 112, -11, -1 },
685 { -5, 51, 95, -11, -2 },
686 { 0, -9, 73, 73, -9 },
687 { -2, -11, 95, 51, -5 },
688 { -1, -11, 112, 30, -2 },
689 { 0, -8, 124, 13, -1 },
692 /* Coefficients for horizontal down-sampling */
693 static const struct dispc_h_coef coef_hdown[8] = {
694 { 0, 36, 56, 36, 0 },
695 { 4, 40, 55, 31, -2 },
696 { 8, 44, 54, 27, -5 },
697 { 12, 48, 53, 22, -7 },
698 { -9, 17, 52, 51, 17 },
699 { -7, 22, 53, 48, 12 },
700 { -5, 27, 54, 44, 8 },
701 { -2, 31, 55, 40, 4 },
704 /* Coefficients for vertical down-sampling */
705 static const struct dispc_v_coef coef_vdown_3tap[8] = {
706 { 0, 36, 56, 36, 0 },
707 { 0, 40, 57, 31, 0 },
708 { 0, 45, 56, 27, 0 },
709 { 0, 50, 55, 23, 0 },
710 { 0, 18, 55, 55, 0 },
711 { 0, 23, 55, 50, 0 },
712 { 0, 27, 56, 45, 0 },
713 { 0, 31, 57, 40, 0 },
716 static const struct dispc_v_coef coef_vdown_5tap[8] = {
717 { 0, 36, 56, 36, 0 },
718 { 4, 40, 55, 31, -2 },
719 { 8, 44, 54, 27, -5 },
720 { 12, 48, 53, 22, -7 },
721 { -9, 17, 52, 51, 17 },
722 { -7, 22, 53, 48, 12 },
723 { -5, 27, 54, 44, 8 },
724 { -2, 31, 55, 40, 4 },
727 const struct dispc_h_coef *h_coef;
728 const struct dispc_v_coef *v_coef;
737 v_coef = five_taps ? coef_vup_5tap : coef_vup_3tap;
739 v_coef = five_taps ? coef_vdown_5tap : coef_vdown_3tap;
741 for (i = 0; i < 8; i++) {
744 h = FLD_VAL(h_coef[i].hc0, 7, 0)
745 | FLD_VAL(h_coef[i].hc1, 15, 8)
746 | FLD_VAL(h_coef[i].hc2, 23, 16)
747 | FLD_VAL(h_coef[i].hc3, 31, 24);
748 hv = FLD_VAL(h_coef[i].hc4, 7, 0)
749 | FLD_VAL(v_coef[i].vc0, 15, 8)
750 | FLD_VAL(v_coef[i].vc1, 23, 16)
751 | FLD_VAL(v_coef[i].vc2, 31, 24);
753 _dispc_write_firh_reg(plane, i, h);
754 _dispc_write_firhv_reg(plane, i, hv);
758 for (i = 0; i < 8; i++) {
760 v = FLD_VAL(v_coef[i].vc00, 7, 0)
761 | FLD_VAL(v_coef[i].vc22, 15, 8);
762 _dispc_write_firv_reg(plane, i, v);
767 static void _dispc_setup_color_conv_coef(void)
769 const struct color_conv_coef {
770 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
773 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
776 const struct color_conv_coef *ct;
778 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
782 dispc_write_reg(DISPC_VID_CONV_COEF(0, 0), CVAL(ct->rcr, ct->ry));
783 dispc_write_reg(DISPC_VID_CONV_COEF(0, 1), CVAL(ct->gy, ct->rcb));
784 dispc_write_reg(DISPC_VID_CONV_COEF(0, 2), CVAL(ct->gcb, ct->gcr));
785 dispc_write_reg(DISPC_VID_CONV_COEF(0, 3), CVAL(ct->bcr, ct->by));
786 dispc_write_reg(DISPC_VID_CONV_COEF(0, 4), CVAL(0, ct->bcb));
788 dispc_write_reg(DISPC_VID_CONV_COEF(1, 0), CVAL(ct->rcr, ct->ry));
789 dispc_write_reg(DISPC_VID_CONV_COEF(1, 1), CVAL(ct->gy, ct->rcb));
790 dispc_write_reg(DISPC_VID_CONV_COEF(1, 2), CVAL(ct->gcb, ct->gcr));
791 dispc_write_reg(DISPC_VID_CONV_COEF(1, 3), CVAL(ct->bcr, ct->by));
792 dispc_write_reg(DISPC_VID_CONV_COEF(1, 4), CVAL(0, ct->bcb));
796 REG_FLD_MOD(DISPC_VID_ATTRIBUTES(0), ct->full_range, 11, 11);
797 REG_FLD_MOD(DISPC_VID_ATTRIBUTES(1), ct->full_range, 11, 11);
801 static void _dispc_set_plane_ba0(enum omap_plane plane, u32 paddr)
803 const struct dispc_reg ba0_reg[] = { DISPC_GFX_BA0,
807 dispc_write_reg(ba0_reg[plane], paddr);
810 static void _dispc_set_plane_ba1(enum omap_plane plane, u32 paddr)
812 const struct dispc_reg ba1_reg[] = { DISPC_GFX_BA1,
816 dispc_write_reg(ba1_reg[plane], paddr);
819 static void _dispc_set_plane_pos(enum omap_plane plane, int x, int y)
821 const struct dispc_reg pos_reg[] = { DISPC_GFX_POSITION,
822 DISPC_VID_POSITION(0),
823 DISPC_VID_POSITION(1) };
825 u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
826 dispc_write_reg(pos_reg[plane], val);
829 static void _dispc_set_pic_size(enum omap_plane plane, int width, int height)
831 const struct dispc_reg siz_reg[] = { DISPC_GFX_SIZE,
832 DISPC_VID_PICTURE_SIZE(0),
833 DISPC_VID_PICTURE_SIZE(1) };
834 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
835 dispc_write_reg(siz_reg[plane], val);
838 static void _dispc_set_vid_size(enum omap_plane plane, int width, int height)
841 const struct dispc_reg vsi_reg[] = { DISPC_VID_SIZE(0),
844 BUG_ON(plane == OMAP_DSS_GFX);
846 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
847 dispc_write_reg(vsi_reg[plane-1], val);
850 static void _dispc_set_pre_mult_alpha(enum omap_plane plane, bool enable)
852 if (!dss_has_feature(FEAT_PRE_MULT_ALPHA))
855 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
856 plane == OMAP_DSS_VIDEO1)
859 REG_FLD_MOD(dispc_reg_att[plane], enable ? 1 : 0, 28, 28);
862 static void _dispc_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
864 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
867 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
868 plane == OMAP_DSS_VIDEO1)
871 if (plane == OMAP_DSS_GFX)
872 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 7, 0);
873 else if (plane == OMAP_DSS_VIDEO2)
874 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, 23, 16);
877 static void _dispc_set_pix_inc(enum omap_plane plane, s32 inc)
879 const struct dispc_reg ri_reg[] = { DISPC_GFX_PIXEL_INC,
880 DISPC_VID_PIXEL_INC(0),
881 DISPC_VID_PIXEL_INC(1) };
883 dispc_write_reg(ri_reg[plane], inc);
886 static void _dispc_set_row_inc(enum omap_plane plane, s32 inc)
888 const struct dispc_reg ri_reg[] = { DISPC_GFX_ROW_INC,
889 DISPC_VID_ROW_INC(0),
890 DISPC_VID_ROW_INC(1) };
892 dispc_write_reg(ri_reg[plane], inc);
895 static void _dispc_set_color_mode(enum omap_plane plane,
896 enum omap_color_mode color_mode)
900 switch (color_mode) {
901 case OMAP_DSS_COLOR_CLUT1:
903 case OMAP_DSS_COLOR_CLUT2:
905 case OMAP_DSS_COLOR_CLUT4:
907 case OMAP_DSS_COLOR_CLUT8:
909 case OMAP_DSS_COLOR_RGB12U:
911 case OMAP_DSS_COLOR_ARGB16:
913 case OMAP_DSS_COLOR_RGB16:
915 case OMAP_DSS_COLOR_RGB24U:
917 case OMAP_DSS_COLOR_RGB24P:
919 case OMAP_DSS_COLOR_YUV2:
921 case OMAP_DSS_COLOR_UYVY:
923 case OMAP_DSS_COLOR_ARGB32:
925 case OMAP_DSS_COLOR_RGBA32:
927 case OMAP_DSS_COLOR_RGBX32:
933 REG_FLD_MOD(dispc_reg_att[plane], m, 4, 1);
936 static void _dispc_set_channel_out(enum omap_plane plane,
937 enum omap_channel channel)
941 int chan = 0, chan2 = 0;
947 case OMAP_DSS_VIDEO1:
948 case OMAP_DSS_VIDEO2:
956 val = dispc_read_reg(dispc_reg_att[plane]);
957 if (dss_has_feature(FEAT_MGR_LCD2)) {
959 case OMAP_DSS_CHANNEL_LCD:
963 case OMAP_DSS_CHANNEL_DIGIT:
967 case OMAP_DSS_CHANNEL_LCD2:
975 val = FLD_MOD(val, chan, shift, shift);
976 val = FLD_MOD(val, chan2, 31, 30);
978 val = FLD_MOD(val, channel, shift, shift);
980 dispc_write_reg(dispc_reg_att[plane], val);
983 void dispc_set_burst_size(enum omap_plane plane,
984 enum omap_burst_size burst_size)
995 case OMAP_DSS_VIDEO1:
996 case OMAP_DSS_VIDEO2:
1004 val = dispc_read_reg(dispc_reg_att[plane]);
1005 val = FLD_MOD(val, burst_size, shift+1, shift);
1006 dispc_write_reg(dispc_reg_att[plane], val);
1011 void dispc_enable_gamma_table(bool enable)
1014 * This is partially implemented to support only disabling of
1018 DSSWARN("Gamma table enabling for TV not yet supported");
1022 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1025 static void _dispc_set_vid_color_conv(enum omap_plane plane, bool enable)
1029 BUG_ON(plane == OMAP_DSS_GFX);
1031 val = dispc_read_reg(dispc_reg_att[plane]);
1032 val = FLD_MOD(val, enable, 9, 9);
1033 dispc_write_reg(dispc_reg_att[plane], val);
1036 void dispc_enable_replication(enum omap_plane plane, bool enable)
1040 if (plane == OMAP_DSS_GFX)
1046 REG_FLD_MOD(dispc_reg_att[plane], enable, bit, bit);
1050 void dispc_set_lcd_size(enum omap_channel channel, u16 width, u16 height)
1053 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
1054 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
1056 dispc_write_reg(DISPC_SIZE_LCD(channel), val);
1060 void dispc_set_digit_size(u16 width, u16 height)
1063 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
1064 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
1066 dispc_write_reg(DISPC_SIZE_DIG, val);
1070 static void dispc_read_plane_fifo_sizes(void)
1072 const struct dispc_reg fsz_reg[] = { DISPC_GFX_FIFO_SIZE_STATUS,
1073 DISPC_VID_FIFO_SIZE_STATUS(0),
1074 DISPC_VID_FIFO_SIZE_STATUS(1) };
1081 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1083 for (plane = 0; plane < ARRAY_SIZE(dispc.fifo_size); ++plane) {
1084 size = FLD_GET(dispc_read_reg(fsz_reg[plane]), start, end);
1085 dispc.fifo_size[plane] = size;
1091 u32 dispc_get_plane_fifo_size(enum omap_plane plane)
1093 return dispc.fifo_size[plane];
1096 void dispc_setup_plane_fifo(enum omap_plane plane, u32 low, u32 high)
1098 const struct dispc_reg ftrs_reg[] = { DISPC_GFX_FIFO_THRESHOLD,
1099 DISPC_VID_FIFO_THRESHOLD(0),
1100 DISPC_VID_FIFO_THRESHOLD(1) };
1101 u8 hi_start, hi_end, lo_start, lo_end;
1105 DSSDBG("fifo(%d) low/high old %u/%u, new %u/%u\n",
1107 REG_GET(ftrs_reg[plane], 11, 0),
1108 REG_GET(ftrs_reg[plane], 27, 16),
1111 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1112 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1114 dispc_write_reg(ftrs_reg[plane],
1115 FLD_VAL(high, hi_start, hi_end) |
1116 FLD_VAL(low, lo_start, lo_end));
1121 void dispc_enable_fifomerge(bool enable)
1125 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1126 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1131 static void _dispc_set_fir(enum omap_plane plane, int hinc, int vinc)
1134 const struct dispc_reg fir_reg[] = { DISPC_VID_FIR(0),
1136 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1138 BUG_ON(plane == OMAP_DSS_GFX);
1140 dss_feat_get_reg_field(FEAT_REG_FIRHINC, &hinc_start, &hinc_end);
1141 dss_feat_get_reg_field(FEAT_REG_FIRVINC, &vinc_start, &vinc_end);
1143 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1144 FLD_VAL(hinc, hinc_start, hinc_end);
1146 dispc_write_reg(fir_reg[plane-1], val);
1149 static void _dispc_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1152 const struct dispc_reg ac0_reg[] = { DISPC_VID_ACCU0(0),
1153 DISPC_VID_ACCU0(1) };
1154 u8 hor_start, hor_end, vert_start, vert_end;
1156 BUG_ON(plane == OMAP_DSS_GFX);
1158 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1159 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1161 val = FLD_VAL(vaccu, vert_start, vert_end) |
1162 FLD_VAL(haccu, hor_start, hor_end);
1164 dispc_write_reg(ac0_reg[plane-1], val);
1167 static void _dispc_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1170 const struct dispc_reg ac1_reg[] = { DISPC_VID_ACCU1(0),
1171 DISPC_VID_ACCU1(1) };
1172 u8 hor_start, hor_end, vert_start, vert_end;
1174 BUG_ON(plane == OMAP_DSS_GFX);
1176 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1177 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1179 val = FLD_VAL(vaccu, vert_start, vert_end) |
1180 FLD_VAL(haccu, hor_start, hor_end);
1182 dispc_write_reg(ac1_reg[plane-1], val);
1186 static void _dispc_set_scaling(enum omap_plane plane,
1187 u16 orig_width, u16 orig_height,
1188 u16 out_width, u16 out_height,
1189 bool ilace, bool five_taps,
1194 int hscaleup, vscaleup;
1199 BUG_ON(plane == OMAP_DSS_GFX);
1201 hscaleup = orig_width <= out_width;
1202 vscaleup = orig_height <= out_height;
1204 _dispc_set_scale_coef(plane, hscaleup, vscaleup, five_taps);
1206 if (!orig_width || orig_width == out_width)
1209 fir_hinc = 1024 * orig_width / out_width;
1211 if (!orig_height || orig_height == out_height)
1214 fir_vinc = 1024 * orig_height / out_height;
1216 _dispc_set_fir(plane, fir_hinc, fir_vinc);
1218 l = dispc_read_reg(dispc_reg_att[plane]);
1220 /* RESIZEENABLE and VERTICALTAPS */
1221 l &= ~((0x3 << 5) | (0x1 << 21));
1222 l |= fir_hinc ? (1 << 5) : 0;
1223 l |= fir_vinc ? (1 << 6) : 0;
1224 l |= five_taps ? (1 << 21) : 0;
1226 /* VRESIZECONF and HRESIZECONF */
1227 if (dss_has_feature(FEAT_RESIZECONF)) {
1229 l |= hscaleup ? 0 : (1 << 7);
1230 l |= vscaleup ? 0 : (1 << 8);
1233 /* LINEBUFFERSPLIT */
1234 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1236 l |= five_taps ? (1 << 22) : 0;
1239 dispc_write_reg(dispc_reg_att[plane], l);
1242 * field 0 = even field = bottom field
1243 * field 1 = odd field = top field
1245 if (ilace && !fieldmode) {
1247 accu0 = (fir_vinc / 2) & 0x3ff;
1248 if (accu0 >= 1024/2) {
1254 _dispc_set_vid_accu0(plane, 0, accu0);
1255 _dispc_set_vid_accu1(plane, 0, accu1);
1258 static void _dispc_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1259 bool mirroring, enum omap_color_mode color_mode)
1261 bool row_repeat = false;
1264 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1265 color_mode == OMAP_DSS_COLOR_UYVY) {
1269 case OMAP_DSS_ROT_0:
1272 case OMAP_DSS_ROT_90:
1275 case OMAP_DSS_ROT_180:
1278 case OMAP_DSS_ROT_270:
1284 case OMAP_DSS_ROT_0:
1287 case OMAP_DSS_ROT_90:
1290 case OMAP_DSS_ROT_180:
1293 case OMAP_DSS_ROT_270:
1299 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1305 REG_FLD_MOD(dispc_reg_att[plane], vidrot, 13, 12);
1306 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1307 REG_FLD_MOD(dispc_reg_att[plane], row_repeat ? 1 : 0, 18, 18);
1310 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1312 switch (color_mode) {
1313 case OMAP_DSS_COLOR_CLUT1:
1315 case OMAP_DSS_COLOR_CLUT2:
1317 case OMAP_DSS_COLOR_CLUT4:
1319 case OMAP_DSS_COLOR_CLUT8:
1321 case OMAP_DSS_COLOR_RGB12U:
1322 case OMAP_DSS_COLOR_RGB16:
1323 case OMAP_DSS_COLOR_ARGB16:
1324 case OMAP_DSS_COLOR_YUV2:
1325 case OMAP_DSS_COLOR_UYVY:
1327 case OMAP_DSS_COLOR_RGB24P:
1329 case OMAP_DSS_COLOR_RGB24U:
1330 case OMAP_DSS_COLOR_ARGB32:
1331 case OMAP_DSS_COLOR_RGBA32:
1332 case OMAP_DSS_COLOR_RGBX32:
1339 static s32 pixinc(int pixels, u8 ps)
1343 else if (pixels > 1)
1344 return 1 + (pixels - 1) * ps;
1345 else if (pixels < 0)
1346 return 1 - (-pixels + 1) * ps;
1351 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1353 u16 width, u16 height,
1354 enum omap_color_mode color_mode, bool fieldmode,
1355 unsigned int field_offset,
1356 unsigned *offset0, unsigned *offset1,
1357 s32 *row_inc, s32 *pix_inc)
1361 /* FIXME CLUT formats */
1362 switch (color_mode) {
1363 case OMAP_DSS_COLOR_CLUT1:
1364 case OMAP_DSS_COLOR_CLUT2:
1365 case OMAP_DSS_COLOR_CLUT4:
1366 case OMAP_DSS_COLOR_CLUT8:
1369 case OMAP_DSS_COLOR_YUV2:
1370 case OMAP_DSS_COLOR_UYVY:
1374 ps = color_mode_to_bpp(color_mode) / 8;
1378 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1382 * field 0 = even field = bottom field
1383 * field 1 = odd field = top field
1385 switch (rotation + mirror * 4) {
1386 case OMAP_DSS_ROT_0:
1387 case OMAP_DSS_ROT_180:
1389 * If the pixel format is YUV or UYVY divide the width
1390 * of the image by 2 for 0 and 180 degree rotation.
1392 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1393 color_mode == OMAP_DSS_COLOR_UYVY)
1395 case OMAP_DSS_ROT_90:
1396 case OMAP_DSS_ROT_270:
1399 *offset0 = field_offset * screen_width * ps;
1403 *row_inc = pixinc(1 + (screen_width - width) +
1404 (fieldmode ? screen_width : 0),
1406 *pix_inc = pixinc(1, ps);
1409 case OMAP_DSS_ROT_0 + 4:
1410 case OMAP_DSS_ROT_180 + 4:
1411 /* If the pixel format is YUV or UYVY divide the width
1412 * of the image by 2 for 0 degree and 180 degree
1414 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1415 color_mode == OMAP_DSS_COLOR_UYVY)
1417 case OMAP_DSS_ROT_90 + 4:
1418 case OMAP_DSS_ROT_270 + 4:
1421 *offset0 = field_offset * screen_width * ps;
1424 *row_inc = pixinc(1 - (screen_width + width) -
1425 (fieldmode ? screen_width : 0),
1427 *pix_inc = pixinc(1, ps);
1435 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1437 u16 width, u16 height,
1438 enum omap_color_mode color_mode, bool fieldmode,
1439 unsigned int field_offset,
1440 unsigned *offset0, unsigned *offset1,
1441 s32 *row_inc, s32 *pix_inc)
1446 /* FIXME CLUT formats */
1447 switch (color_mode) {
1448 case OMAP_DSS_COLOR_CLUT1:
1449 case OMAP_DSS_COLOR_CLUT2:
1450 case OMAP_DSS_COLOR_CLUT4:
1451 case OMAP_DSS_COLOR_CLUT8:
1455 ps = color_mode_to_bpp(color_mode) / 8;
1459 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1462 /* width & height are overlay sizes, convert to fb sizes */
1464 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1473 * field 0 = even field = bottom field
1474 * field 1 = odd field = top field
1476 switch (rotation + mirror * 4) {
1477 case OMAP_DSS_ROT_0:
1480 *offset0 = *offset1 + field_offset * screen_width * ps;
1482 *offset0 = *offset1;
1483 *row_inc = pixinc(1 + (screen_width - fbw) +
1484 (fieldmode ? screen_width : 0),
1486 *pix_inc = pixinc(1, ps);
1488 case OMAP_DSS_ROT_90:
1489 *offset1 = screen_width * (fbh - 1) * ps;
1491 *offset0 = *offset1 + field_offset * ps;
1493 *offset0 = *offset1;
1494 *row_inc = pixinc(screen_width * (fbh - 1) + 1 +
1495 (fieldmode ? 1 : 0), ps);
1496 *pix_inc = pixinc(-screen_width, ps);
1498 case OMAP_DSS_ROT_180:
1499 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1501 *offset0 = *offset1 - field_offset * screen_width * ps;
1503 *offset0 = *offset1;
1504 *row_inc = pixinc(-1 -
1505 (screen_width - fbw) -
1506 (fieldmode ? screen_width : 0),
1508 *pix_inc = pixinc(-1, ps);
1510 case OMAP_DSS_ROT_270:
1511 *offset1 = (fbw - 1) * ps;
1513 *offset0 = *offset1 - field_offset * ps;
1515 *offset0 = *offset1;
1516 *row_inc = pixinc(-screen_width * (fbh - 1) - 1 -
1517 (fieldmode ? 1 : 0), ps);
1518 *pix_inc = pixinc(screen_width, ps);
1522 case OMAP_DSS_ROT_0 + 4:
1523 *offset1 = (fbw - 1) * ps;
1525 *offset0 = *offset1 + field_offset * screen_width * ps;
1527 *offset0 = *offset1;
1528 *row_inc = pixinc(screen_width * 2 - 1 +
1529 (fieldmode ? screen_width : 0),
1531 *pix_inc = pixinc(-1, ps);
1534 case OMAP_DSS_ROT_90 + 4:
1537 *offset0 = *offset1 + field_offset * ps;
1539 *offset0 = *offset1;
1540 *row_inc = pixinc(-screen_width * (fbh - 1) + 1 +
1541 (fieldmode ? 1 : 0),
1543 *pix_inc = pixinc(screen_width, ps);
1546 case OMAP_DSS_ROT_180 + 4:
1547 *offset1 = screen_width * (fbh - 1) * ps;
1549 *offset0 = *offset1 - field_offset * screen_width * ps;
1551 *offset0 = *offset1;
1552 *row_inc = pixinc(1 - screen_width * 2 -
1553 (fieldmode ? screen_width : 0),
1555 *pix_inc = pixinc(1, ps);
1558 case OMAP_DSS_ROT_270 + 4:
1559 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1561 *offset0 = *offset1 - field_offset * ps;
1563 *offset0 = *offset1;
1564 *row_inc = pixinc(screen_width * (fbh - 1) - 1 -
1565 (fieldmode ? 1 : 0),
1567 *pix_inc = pixinc(-screen_width, ps);
1575 static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width,
1576 u16 height, u16 out_width, u16 out_height,
1577 enum omap_color_mode color_mode)
1580 /* FIXME venc pclk? */
1581 u64 tmp, pclk = dispc_pclk_rate(channel);
1583 if (height > out_height) {
1584 /* FIXME get real display PPL */
1585 unsigned int ppl = 800;
1587 tmp = pclk * height * out_width;
1588 do_div(tmp, 2 * out_height * ppl);
1591 if (height > 2 * out_height) {
1592 if (ppl == out_width)
1595 tmp = pclk * (height - 2 * out_height) * out_width;
1596 do_div(tmp, 2 * out_height * (ppl - out_width));
1597 fclk = max(fclk, (u32) tmp);
1601 if (width > out_width) {
1603 do_div(tmp, out_width);
1604 fclk = max(fclk, (u32) tmp);
1606 if (color_mode == OMAP_DSS_COLOR_RGB24U)
1613 static unsigned long calc_fclk(enum omap_channel channel, u16 width,
1614 u16 height, u16 out_width, u16 out_height)
1616 unsigned int hf, vf;
1619 * FIXME how to determine the 'A' factor
1620 * for the no downscaling case ?
1623 if (width > 3 * out_width)
1625 else if (width > 2 * out_width)
1627 else if (width > out_width)
1632 if (height > out_height)
1637 /* FIXME venc pclk? */
1638 return dispc_pclk_rate(channel) * vf * hf;
1641 void dispc_set_channel_out(enum omap_plane plane, enum omap_channel channel_out)
1644 _dispc_set_channel_out(plane, channel_out);
1648 static int _dispc_setup_plane(enum omap_plane plane,
1649 u32 paddr, u16 screen_width,
1650 u16 pos_x, u16 pos_y,
1651 u16 width, u16 height,
1652 u16 out_width, u16 out_height,
1653 enum omap_color_mode color_mode,
1655 enum omap_dss_rotation_type rotation_type,
1656 u8 rotation, int mirror,
1657 u8 global_alpha, u8 pre_mult_alpha,
1658 enum omap_channel channel)
1660 const int maxdownscale = cpu_is_omap34xx() ? 4 : 2;
1664 unsigned offset0, offset1;
1667 u16 frame_height = height;
1668 unsigned int field_offset = 0;
1673 if (ilace && height == out_height)
1682 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
1684 height, pos_y, out_height);
1687 if (!dss_feat_color_mode_supported(plane, color_mode))
1690 if (plane == OMAP_DSS_GFX) {
1691 if (width != out_width || height != out_height)
1696 unsigned long fclk = 0;
1698 if (out_width < width / maxdownscale ||
1699 out_width > width * 8)
1702 if (out_height < height / maxdownscale ||
1703 out_height > height * 8)
1706 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1707 color_mode == OMAP_DSS_COLOR_UYVY)
1710 /* Must use 5-tap filter? */
1711 five_taps = height > out_height * 2;
1714 fclk = calc_fclk(channel, width, height, out_width,
1717 /* Try 5-tap filter if 3-tap fclk is too high */
1718 if (cpu_is_omap34xx() && height > out_height &&
1719 fclk > dispc_fclk_rate())
1723 if (width > (2048 >> five_taps)) {
1724 DSSERR("failed to set up scaling, fclk too low\n");
1729 fclk = calc_fclk_five_taps(channel, width, height,
1730 out_width, out_height, color_mode);
1732 DSSDBG("required fclk rate = %lu Hz\n", fclk);
1733 DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate());
1735 if (!fclk || fclk > dispc_fclk_rate()) {
1736 DSSERR("failed to set up scaling, "
1737 "required fclk rate = %lu Hz, "
1738 "current fclk rate = %lu Hz\n",
1739 fclk, dispc_fclk_rate());
1744 if (ilace && !fieldmode) {
1746 * when downscaling the bottom field may have to start several
1747 * source lines below the top field. Unfortunately ACCUI
1748 * registers will only hold the fractional part of the offset
1749 * so the integer part must be added to the base address of the
1752 if (!height || height == out_height)
1755 field_offset = height / out_height / 2;
1758 /* Fields are independent but interleaved in memory. */
1762 if (rotation_type == OMAP_DSS_ROT_DMA)
1763 calc_dma_rotation_offset(rotation, mirror,
1764 screen_width, width, frame_height, color_mode,
1765 fieldmode, field_offset,
1766 &offset0, &offset1, &row_inc, &pix_inc);
1768 calc_vrfb_rotation_offset(rotation, mirror,
1769 screen_width, width, frame_height, color_mode,
1770 fieldmode, field_offset,
1771 &offset0, &offset1, &row_inc, &pix_inc);
1773 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
1774 offset0, offset1, row_inc, pix_inc);
1776 _dispc_set_color_mode(plane, color_mode);
1778 _dispc_set_plane_ba0(plane, paddr + offset0);
1779 _dispc_set_plane_ba1(plane, paddr + offset1);
1781 _dispc_set_row_inc(plane, row_inc);
1782 _dispc_set_pix_inc(plane, pix_inc);
1784 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, width, height,
1785 out_width, out_height);
1787 _dispc_set_plane_pos(plane, pos_x, pos_y);
1789 _dispc_set_pic_size(plane, width, height);
1791 if (plane != OMAP_DSS_GFX) {
1792 _dispc_set_scaling(plane, width, height,
1793 out_width, out_height,
1794 ilace, five_taps, fieldmode);
1795 _dispc_set_vid_size(plane, out_width, out_height);
1796 _dispc_set_vid_color_conv(plane, cconv);
1799 _dispc_set_rotation_attrs(plane, rotation, mirror, color_mode);
1801 _dispc_set_pre_mult_alpha(plane, pre_mult_alpha);
1802 _dispc_setup_global_alpha(plane, global_alpha);
1807 static void _dispc_enable_plane(enum omap_plane plane, bool enable)
1809 REG_FLD_MOD(dispc_reg_att[plane], enable ? 1 : 0, 0, 0);
1812 static void dispc_disable_isr(void *data, u32 mask)
1814 struct completion *compl = data;
1818 static void _enable_lcd_out(enum omap_channel channel, bool enable)
1820 if (channel == OMAP_DSS_CHANNEL_LCD2)
1821 REG_FLD_MOD(DISPC_CONTROL2, enable ? 1 : 0, 0, 0);
1823 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0);
1826 static void dispc_enable_lcd_out(enum omap_channel channel, bool enable)
1828 struct completion frame_done_completion;
1835 /* When we disable LCD output, we need to wait until frame is done.
1836 * Otherwise the DSS is still working, and turning off the clocks
1837 * prevents DSS from going to OFF mode */
1838 is_on = channel == OMAP_DSS_CHANNEL_LCD2 ?
1839 REG_GET(DISPC_CONTROL2, 0, 0) :
1840 REG_GET(DISPC_CONTROL, 0, 0);
1842 irq = channel == OMAP_DSS_CHANNEL_LCD2 ? DISPC_IRQ_FRAMEDONE2 :
1843 DISPC_IRQ_FRAMEDONE;
1845 if (!enable && is_on) {
1846 init_completion(&frame_done_completion);
1848 r = omap_dispc_register_isr(dispc_disable_isr,
1849 &frame_done_completion, irq);
1852 DSSERR("failed to register FRAMEDONE isr\n");
1855 _enable_lcd_out(channel, enable);
1857 if (!enable && is_on) {
1858 if (!wait_for_completion_timeout(&frame_done_completion,
1859 msecs_to_jiffies(100)))
1860 DSSERR("timeout waiting for FRAME DONE\n");
1862 r = omap_dispc_unregister_isr(dispc_disable_isr,
1863 &frame_done_completion, irq);
1866 DSSERR("failed to unregister FRAMEDONE isr\n");
1872 static void _enable_digit_out(bool enable)
1874 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
1877 static void dispc_enable_digit_out(bool enable)
1879 struct completion frame_done_completion;
1884 if (REG_GET(DISPC_CONTROL, 1, 1) == enable) {
1890 unsigned long flags;
1891 /* When we enable digit output, we'll get an extra digit
1892 * sync lost interrupt, that we need to ignore */
1893 spin_lock_irqsave(&dispc.irq_lock, flags);
1894 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
1895 _omap_dispc_set_irqs();
1896 spin_unlock_irqrestore(&dispc.irq_lock, flags);
1899 /* When we disable digit output, we need to wait until fields are done.
1900 * Otherwise the DSS is still working, and turning off the clocks
1901 * prevents DSS from going to OFF mode. And when enabling, we need to
1902 * wait for the extra sync losts */
1903 init_completion(&frame_done_completion);
1905 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
1906 DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD);
1908 DSSERR("failed to register EVSYNC isr\n");
1910 _enable_digit_out(enable);
1912 /* XXX I understand from TRM that we should only wait for the
1913 * current field to complete. But it seems we have to wait
1914 * for both fields */
1915 if (!wait_for_completion_timeout(&frame_done_completion,
1916 msecs_to_jiffies(100)))
1917 DSSERR("timeout waiting for EVSYNC\n");
1919 if (!wait_for_completion_timeout(&frame_done_completion,
1920 msecs_to_jiffies(100)))
1921 DSSERR("timeout waiting for EVSYNC\n");
1923 r = omap_dispc_unregister_isr(dispc_disable_isr,
1924 &frame_done_completion,
1925 DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD);
1927 DSSERR("failed to unregister EVSYNC isr\n");
1930 unsigned long flags;
1931 spin_lock_irqsave(&dispc.irq_lock, flags);
1932 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
1933 if (dss_has_feature(FEAT_MGR_LCD2))
1934 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
1935 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
1936 _omap_dispc_set_irqs();
1937 spin_unlock_irqrestore(&dispc.irq_lock, flags);
1943 bool dispc_is_channel_enabled(enum omap_channel channel)
1945 if (channel == OMAP_DSS_CHANNEL_LCD)
1946 return !!REG_GET(DISPC_CONTROL, 0, 0);
1947 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
1948 return !!REG_GET(DISPC_CONTROL, 1, 1);
1949 else if (channel == OMAP_DSS_CHANNEL_LCD2)
1950 return !!REG_GET(DISPC_CONTROL2, 0, 0);
1955 void dispc_enable_channel(enum omap_channel channel, bool enable)
1957 if (channel == OMAP_DSS_CHANNEL_LCD ||
1958 channel == OMAP_DSS_CHANNEL_LCD2)
1959 dispc_enable_lcd_out(channel, enable);
1960 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
1961 dispc_enable_digit_out(enable);
1966 void dispc_lcd_enable_signal_polarity(bool act_high)
1968 if (!dss_has_feature(FEAT_LCDENABLEPOL))
1972 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
1976 void dispc_lcd_enable_signal(bool enable)
1978 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
1982 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
1986 void dispc_pck_free_enable(bool enable)
1988 if (!dss_has_feature(FEAT_PCKFREEENABLE))
1992 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
1996 void dispc_enable_fifohandcheck(enum omap_channel channel, bool enable)
1999 if (channel == OMAP_DSS_CHANNEL_LCD2)
2000 REG_FLD_MOD(DISPC_CONFIG2, enable ? 1 : 0, 16, 16);
2002 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16);
2007 void dispc_set_lcd_display_type(enum omap_channel channel,
2008 enum omap_lcd_display_type type)
2013 case OMAP_DSS_LCD_DISPLAY_STN:
2017 case OMAP_DSS_LCD_DISPLAY_TFT:
2027 if (channel == OMAP_DSS_CHANNEL_LCD2)
2028 REG_FLD_MOD(DISPC_CONTROL2, mode, 3, 3);
2030 REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3);
2034 void dispc_set_loadmode(enum omap_dss_load_mode mode)
2037 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2042 void dispc_set_default_color(enum omap_channel channel, u32 color)
2045 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2049 u32 dispc_get_default_color(enum omap_channel channel)
2053 BUG_ON(channel != OMAP_DSS_CHANNEL_DIGIT &&
2054 channel != OMAP_DSS_CHANNEL_LCD &&
2055 channel != OMAP_DSS_CHANNEL_LCD2);
2058 l = dispc_read_reg(DISPC_DEFAULT_COLOR(channel));
2064 void dispc_set_trans_key(enum omap_channel ch,
2065 enum omap_dss_trans_key_type type,
2069 if (ch == OMAP_DSS_CHANNEL_LCD)
2070 REG_FLD_MOD(DISPC_CONFIG, type, 11, 11);
2071 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2072 REG_FLD_MOD(DISPC_CONFIG, type, 13, 13);
2073 else /* OMAP_DSS_CHANNEL_LCD2 */
2074 REG_FLD_MOD(DISPC_CONFIG2, type, 11, 11);
2076 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2080 void dispc_get_trans_key(enum omap_channel ch,
2081 enum omap_dss_trans_key_type *type,
2086 if (ch == OMAP_DSS_CHANNEL_LCD)
2087 *type = REG_GET(DISPC_CONFIG, 11, 11);
2088 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2089 *type = REG_GET(DISPC_CONFIG, 13, 13);
2090 else if (ch == OMAP_DSS_CHANNEL_LCD2)
2091 *type = REG_GET(DISPC_CONFIG2, 11, 11);
2097 *trans_key = dispc_read_reg(DISPC_TRANS_COLOR(ch));
2101 void dispc_enable_trans_key(enum omap_channel ch, bool enable)
2104 if (ch == OMAP_DSS_CHANNEL_LCD)
2105 REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10);
2106 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2107 REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12);
2108 else /* OMAP_DSS_CHANNEL_LCD2 */
2109 REG_FLD_MOD(DISPC_CONFIG2, enable, 10, 10);
2112 void dispc_enable_alpha_blending(enum omap_channel ch, bool enable)
2114 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
2118 if (ch == OMAP_DSS_CHANNEL_LCD)
2119 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2120 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2121 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2122 else /* OMAP_DSS_CHANNEL_LCD2 */
2123 REG_FLD_MOD(DISPC_CONFIG2, enable, 18, 18);
2126 bool dispc_alpha_blending_enabled(enum omap_channel ch)
2130 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
2134 if (ch == OMAP_DSS_CHANNEL_LCD)
2135 enabled = REG_GET(DISPC_CONFIG, 18, 18);
2136 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2137 enabled = REG_GET(DISPC_CONFIG, 19, 19);
2138 else if (ch == OMAP_DSS_CHANNEL_LCD2)
2139 enabled = REG_GET(DISPC_CONFIG2, 18, 18);
2148 bool dispc_trans_key_enabled(enum omap_channel ch)
2153 if (ch == OMAP_DSS_CHANNEL_LCD)
2154 enabled = REG_GET(DISPC_CONFIG, 10, 10);
2155 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2156 enabled = REG_GET(DISPC_CONFIG, 12, 12);
2157 else if (ch == OMAP_DSS_CHANNEL_LCD2)
2158 enabled = REG_GET(DISPC_CONFIG2, 10, 10);
2167 void dispc_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2171 switch (data_lines) {
2190 if (channel == OMAP_DSS_CHANNEL_LCD2)
2191 REG_FLD_MOD(DISPC_CONTROL2, code, 9, 8);
2193 REG_FLD_MOD(DISPC_CONTROL, code, 9, 8);
2197 void dispc_set_parallel_interface_mode(enum omap_channel channel,
2198 enum omap_parallel_interface_mode mode)
2206 case OMAP_DSS_PARALLELMODE_BYPASS:
2211 case OMAP_DSS_PARALLELMODE_RFBI:
2216 case OMAP_DSS_PARALLELMODE_DSI:
2228 if (channel == OMAP_DSS_CHANNEL_LCD2) {
2229 l = dispc_read_reg(DISPC_CONTROL2);
2230 l = FLD_MOD(l, stallmode, 11, 11);
2231 dispc_write_reg(DISPC_CONTROL2, l);
2233 l = dispc_read_reg(DISPC_CONTROL);
2234 l = FLD_MOD(l, stallmode, 11, 11);
2235 l = FLD_MOD(l, gpout0, 15, 15);
2236 l = FLD_MOD(l, gpout1, 16, 16);
2237 dispc_write_reg(DISPC_CONTROL, l);
2243 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2244 int vsw, int vfp, int vbp)
2246 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2247 if (hsw < 1 || hsw > 64 ||
2248 hfp < 1 || hfp > 256 ||
2249 hbp < 1 || hbp > 256 ||
2250 vsw < 1 || vsw > 64 ||
2251 vfp < 0 || vfp > 255 ||
2252 vbp < 0 || vbp > 255)
2255 if (hsw < 1 || hsw > 256 ||
2256 hfp < 1 || hfp > 4096 ||
2257 hbp < 1 || hbp > 4096 ||
2258 vsw < 1 || vsw > 256 ||
2259 vfp < 0 || vfp > 4095 ||
2260 vbp < 0 || vbp > 4095)
2267 bool dispc_lcd_timings_ok(struct omap_video_timings *timings)
2269 return _dispc_lcd_timings_ok(timings->hsw, timings->hfp,
2270 timings->hbp, timings->vsw,
2271 timings->vfp, timings->vbp);
2274 static void _dispc_set_lcd_timings(enum omap_channel channel, int hsw,
2275 int hfp, int hbp, int vsw, int vfp, int vbp)
2277 u32 timing_h, timing_v;
2279 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2280 timing_h = FLD_VAL(hsw-1, 5, 0) | FLD_VAL(hfp-1, 15, 8) |
2281 FLD_VAL(hbp-1, 27, 20);
2283 timing_v = FLD_VAL(vsw-1, 5, 0) | FLD_VAL(vfp, 15, 8) |
2284 FLD_VAL(vbp, 27, 20);
2286 timing_h = FLD_VAL(hsw-1, 7, 0) | FLD_VAL(hfp-1, 19, 8) |
2287 FLD_VAL(hbp-1, 31, 20);
2289 timing_v = FLD_VAL(vsw-1, 7, 0) | FLD_VAL(vfp, 19, 8) |
2290 FLD_VAL(vbp, 31, 20);
2294 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2295 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
2299 /* change name to mode? */
2300 void dispc_set_lcd_timings(enum omap_channel channel,
2301 struct omap_video_timings *timings)
2303 unsigned xtot, ytot;
2304 unsigned long ht, vt;
2306 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
2307 timings->hbp, timings->vsw,
2308 timings->vfp, timings->vbp))
2311 _dispc_set_lcd_timings(channel, timings->hsw, timings->hfp,
2312 timings->hbp, timings->vsw, timings->vfp,
2315 dispc_set_lcd_size(channel, timings->x_res, timings->y_res);
2317 xtot = timings->x_res + timings->hfp + timings->hsw + timings->hbp;
2318 ytot = timings->y_res + timings->vfp + timings->vsw + timings->vbp;
2320 ht = (timings->pixel_clock * 1000) / xtot;
2321 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2323 DSSDBG("channel %d xres %u yres %u\n", channel, timings->x_res,
2325 DSSDBG("pck %u\n", timings->pixel_clock);
2326 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2327 timings->hsw, timings->hfp, timings->hbp,
2328 timings->vsw, timings->vfp, timings->vbp);
2330 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2333 static void dispc_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
2336 BUG_ON(lck_div < 1);
2337 BUG_ON(pck_div < 2);
2340 dispc_write_reg(DISPC_DIVISORo(channel),
2341 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
2345 static void dispc_get_lcd_divisor(enum omap_channel channel, int *lck_div,
2349 l = dispc_read_reg(DISPC_DIVISORo(channel));
2350 *lck_div = FLD_GET(l, 23, 16);
2351 *pck_div = FLD_GET(l, 7, 0);
2354 unsigned long dispc_fclk_rate(void)
2356 unsigned long r = 0;
2358 switch (dss_get_dispc_clk_source()) {
2359 case DSS_CLK_SRC_FCK:
2360 r = dss_clk_get_rate(DSS_CLK_FCK);
2362 case DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2363 r = dsi_get_pll_hsdiv_dispc_rate();
2372 unsigned long dispc_lclk_rate(enum omap_channel channel)
2378 l = dispc_read_reg(DISPC_DIVISORo(channel));
2380 lcd = FLD_GET(l, 23, 16);
2382 switch (dss_get_lcd_clk_source(channel)) {
2383 case DSS_CLK_SRC_FCK:
2384 r = dss_clk_get_rate(DSS_CLK_FCK);
2386 case DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2387 r = dsi_get_pll_hsdiv_dispc_rate();
2396 unsigned long dispc_pclk_rate(enum omap_channel channel)
2402 l = dispc_read_reg(DISPC_DIVISORo(channel));
2404 pcd = FLD_GET(l, 7, 0);
2406 r = dispc_lclk_rate(channel);
2411 void dispc_dump_clocks(struct seq_file *s)
2415 enum dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
2416 enum dss_clk_source lcd_clk_src;
2420 seq_printf(s, "- DISPC -\n");
2422 seq_printf(s, "dispc fclk source = %s (%s)\n",
2423 dss_get_generic_clk_source_name(dispc_clk_src),
2424 dss_feat_get_clk_source_name(dispc_clk_src));
2426 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
2428 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
2429 seq_printf(s, "- DISPC-CORE-CLK -\n");
2430 l = dispc_read_reg(DISPC_DIVISOR);
2431 lcd = FLD_GET(l, 23, 16);
2433 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2434 (dispc_fclk_rate()/lcd), lcd);
2436 seq_printf(s, "- LCD1 -\n");
2438 lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD);
2440 seq_printf(s, "lcd1_clk source = %s (%s)\n",
2441 dss_get_generic_clk_source_name(lcd_clk_src),
2442 dss_feat_get_clk_source_name(lcd_clk_src));
2444 dispc_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd);
2446 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2447 dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd);
2448 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2449 dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd);
2450 if (dss_has_feature(FEAT_MGR_LCD2)) {
2451 seq_printf(s, "- LCD2 -\n");
2453 lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD2);
2455 seq_printf(s, "lcd2_clk source = %s (%s)\n",
2456 dss_get_generic_clk_source_name(lcd_clk_src),
2457 dss_feat_get_clk_source_name(lcd_clk_src));
2459 dispc_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd);
2461 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2462 dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd);
2463 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2464 dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd);
2469 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
2470 void dispc_dump_irqs(struct seq_file *s)
2472 unsigned long flags;
2473 struct dispc_irq_stats stats;
2475 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
2477 stats = dispc.irq_stats;
2478 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
2479 dispc.irq_stats.last_reset = jiffies;
2481 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
2483 seq_printf(s, "period %u ms\n",
2484 jiffies_to_msecs(jiffies - stats.last_reset));
2486 seq_printf(s, "irqs %d\n", stats.irq_count);
2488 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
2494 PIS(ACBIAS_COUNT_STAT);
2496 PIS(GFX_FIFO_UNDERFLOW);
2498 PIS(PAL_GAMMA_MASK);
2500 PIS(VID1_FIFO_UNDERFLOW);
2502 PIS(VID2_FIFO_UNDERFLOW);
2505 PIS(SYNC_LOST_DIGIT);
2507 if (dss_has_feature(FEAT_MGR_LCD2)) {
2510 PIS(ACBIAS_COUNT_STAT2);
2517 void dispc_dump_regs(struct seq_file *s)
2519 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dispc_read_reg(r))
2521 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
2523 DUMPREG(DISPC_REVISION);
2524 DUMPREG(DISPC_SYSCONFIG);
2525 DUMPREG(DISPC_SYSSTATUS);
2526 DUMPREG(DISPC_IRQSTATUS);
2527 DUMPREG(DISPC_IRQENABLE);
2528 DUMPREG(DISPC_CONTROL);
2529 DUMPREG(DISPC_CONFIG);
2530 DUMPREG(DISPC_CAPABLE);
2531 DUMPREG(DISPC_DEFAULT_COLOR(0));
2532 DUMPREG(DISPC_DEFAULT_COLOR(1));
2533 DUMPREG(DISPC_TRANS_COLOR(0));
2534 DUMPREG(DISPC_TRANS_COLOR(1));
2535 DUMPREG(DISPC_LINE_STATUS);
2536 DUMPREG(DISPC_LINE_NUMBER);
2537 DUMPREG(DISPC_TIMING_H(0));
2538 DUMPREG(DISPC_TIMING_V(0));
2539 DUMPREG(DISPC_POL_FREQ(0));
2540 DUMPREG(DISPC_DIVISORo(0));
2541 DUMPREG(DISPC_GLOBAL_ALPHA);
2542 DUMPREG(DISPC_SIZE_DIG);
2543 DUMPREG(DISPC_SIZE_LCD(0));
2544 if (dss_has_feature(FEAT_MGR_LCD2)) {
2545 DUMPREG(DISPC_CONTROL2);
2546 DUMPREG(DISPC_CONFIG2);
2547 DUMPREG(DISPC_DEFAULT_COLOR(2));
2548 DUMPREG(DISPC_TRANS_COLOR(2));
2549 DUMPREG(DISPC_TIMING_H(2));
2550 DUMPREG(DISPC_TIMING_V(2));
2551 DUMPREG(DISPC_POL_FREQ(2));
2552 DUMPREG(DISPC_DIVISORo(2));
2553 DUMPREG(DISPC_SIZE_LCD(2));
2556 DUMPREG(DISPC_GFX_BA0);
2557 DUMPREG(DISPC_GFX_BA1);
2558 DUMPREG(DISPC_GFX_POSITION);
2559 DUMPREG(DISPC_GFX_SIZE);
2560 DUMPREG(DISPC_GFX_ATTRIBUTES);
2561 DUMPREG(DISPC_GFX_FIFO_THRESHOLD);
2562 DUMPREG(DISPC_GFX_FIFO_SIZE_STATUS);
2563 DUMPREG(DISPC_GFX_ROW_INC);
2564 DUMPREG(DISPC_GFX_PIXEL_INC);
2565 DUMPREG(DISPC_GFX_WINDOW_SKIP);
2566 DUMPREG(DISPC_GFX_TABLE_BA);
2568 DUMPREG(DISPC_DATA_CYCLE1(0));
2569 DUMPREG(DISPC_DATA_CYCLE2(0));
2570 DUMPREG(DISPC_DATA_CYCLE3(0));
2572 DUMPREG(DISPC_CPR_COEF_R(0));
2573 DUMPREG(DISPC_CPR_COEF_G(0));
2574 DUMPREG(DISPC_CPR_COEF_B(0));
2575 if (dss_has_feature(FEAT_MGR_LCD2)) {
2576 DUMPREG(DISPC_DATA_CYCLE1(2));
2577 DUMPREG(DISPC_DATA_CYCLE2(2));
2578 DUMPREG(DISPC_DATA_CYCLE3(2));
2580 DUMPREG(DISPC_CPR_COEF_R(2));
2581 DUMPREG(DISPC_CPR_COEF_G(2));
2582 DUMPREG(DISPC_CPR_COEF_B(2));
2585 DUMPREG(DISPC_GFX_PRELOAD);
2587 DUMPREG(DISPC_VID_BA0(0));
2588 DUMPREG(DISPC_VID_BA1(0));
2589 DUMPREG(DISPC_VID_POSITION(0));
2590 DUMPREG(DISPC_VID_SIZE(0));
2591 DUMPREG(DISPC_VID_ATTRIBUTES(0));
2592 DUMPREG(DISPC_VID_FIFO_THRESHOLD(0));
2593 DUMPREG(DISPC_VID_FIFO_SIZE_STATUS(0));
2594 DUMPREG(DISPC_VID_ROW_INC(0));
2595 DUMPREG(DISPC_VID_PIXEL_INC(0));
2596 DUMPREG(DISPC_VID_FIR(0));
2597 DUMPREG(DISPC_VID_PICTURE_SIZE(0));
2598 DUMPREG(DISPC_VID_ACCU0(0));
2599 DUMPREG(DISPC_VID_ACCU1(0));
2601 DUMPREG(DISPC_VID_BA0(1));
2602 DUMPREG(DISPC_VID_BA1(1));
2603 DUMPREG(DISPC_VID_POSITION(1));
2604 DUMPREG(DISPC_VID_SIZE(1));
2605 DUMPREG(DISPC_VID_ATTRIBUTES(1));
2606 DUMPREG(DISPC_VID_FIFO_THRESHOLD(1));
2607 DUMPREG(DISPC_VID_FIFO_SIZE_STATUS(1));
2608 DUMPREG(DISPC_VID_ROW_INC(1));
2609 DUMPREG(DISPC_VID_PIXEL_INC(1));
2610 DUMPREG(DISPC_VID_FIR(1));
2611 DUMPREG(DISPC_VID_PICTURE_SIZE(1));
2612 DUMPREG(DISPC_VID_ACCU0(1));
2613 DUMPREG(DISPC_VID_ACCU1(1));
2615 DUMPREG(DISPC_VID_FIR_COEF_H(0, 0));
2616 DUMPREG(DISPC_VID_FIR_COEF_H(0, 1));
2617 DUMPREG(DISPC_VID_FIR_COEF_H(0, 2));
2618 DUMPREG(DISPC_VID_FIR_COEF_H(0, 3));
2619 DUMPREG(DISPC_VID_FIR_COEF_H(0, 4));
2620 DUMPREG(DISPC_VID_FIR_COEF_H(0, 5));
2621 DUMPREG(DISPC_VID_FIR_COEF_H(0, 6));
2622 DUMPREG(DISPC_VID_FIR_COEF_H(0, 7));
2623 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 0));
2624 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 1));
2625 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 2));
2626 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 3));
2627 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 4));
2628 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 5));
2629 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 6));
2630 DUMPREG(DISPC_VID_FIR_COEF_HV(0, 7));
2631 DUMPREG(DISPC_VID_CONV_COEF(0, 0));
2632 DUMPREG(DISPC_VID_CONV_COEF(0, 1));
2633 DUMPREG(DISPC_VID_CONV_COEF(0, 2));
2634 DUMPREG(DISPC_VID_CONV_COEF(0, 3));
2635 DUMPREG(DISPC_VID_CONV_COEF(0, 4));
2636 DUMPREG(DISPC_VID_FIR_COEF_V(0, 0));
2637 DUMPREG(DISPC_VID_FIR_COEF_V(0, 1));
2638 DUMPREG(DISPC_VID_FIR_COEF_V(0, 2));
2639 DUMPREG(DISPC_VID_FIR_COEF_V(0, 3));
2640 DUMPREG(DISPC_VID_FIR_COEF_V(0, 4));
2641 DUMPREG(DISPC_VID_FIR_COEF_V(0, 5));
2642 DUMPREG(DISPC_VID_FIR_COEF_V(0, 6));
2643 DUMPREG(DISPC_VID_FIR_COEF_V(0, 7));
2645 DUMPREG(DISPC_VID_FIR_COEF_H(1, 0));
2646 DUMPREG(DISPC_VID_FIR_COEF_H(1, 1));
2647 DUMPREG(DISPC_VID_FIR_COEF_H(1, 2));
2648 DUMPREG(DISPC_VID_FIR_COEF_H(1, 3));
2649 DUMPREG(DISPC_VID_FIR_COEF_H(1, 4));
2650 DUMPREG(DISPC_VID_FIR_COEF_H(1, 5));
2651 DUMPREG(DISPC_VID_FIR_COEF_H(1, 6));
2652 DUMPREG(DISPC_VID_FIR_COEF_H(1, 7));
2653 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 0));
2654 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 1));
2655 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 2));
2656 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 3));
2657 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 4));
2658 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 5));
2659 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 6));
2660 DUMPREG(DISPC_VID_FIR_COEF_HV(1, 7));
2661 DUMPREG(DISPC_VID_CONV_COEF(1, 0));
2662 DUMPREG(DISPC_VID_CONV_COEF(1, 1));
2663 DUMPREG(DISPC_VID_CONV_COEF(1, 2));
2664 DUMPREG(DISPC_VID_CONV_COEF(1, 3));
2665 DUMPREG(DISPC_VID_CONV_COEF(1, 4));
2666 DUMPREG(DISPC_VID_FIR_COEF_V(1, 0));
2667 DUMPREG(DISPC_VID_FIR_COEF_V(1, 1));
2668 DUMPREG(DISPC_VID_FIR_COEF_V(1, 2));
2669 DUMPREG(DISPC_VID_FIR_COEF_V(1, 3));
2670 DUMPREG(DISPC_VID_FIR_COEF_V(1, 4));
2671 DUMPREG(DISPC_VID_FIR_COEF_V(1, 5));
2672 DUMPREG(DISPC_VID_FIR_COEF_V(1, 6));
2673 DUMPREG(DISPC_VID_FIR_COEF_V(1, 7));
2675 DUMPREG(DISPC_VID_PRELOAD(0));
2676 DUMPREG(DISPC_VID_PRELOAD(1));
2678 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
2682 static void _dispc_set_pol_freq(enum omap_channel channel, bool onoff, bool rf,
2683 bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi, u8 acb)
2687 DSSDBG("onoff %d rf %d ieo %d ipc %d ihs %d ivs %d acbi %d acb %d\n",
2688 onoff, rf, ieo, ipc, ihs, ivs, acbi, acb);
2690 l |= FLD_VAL(onoff, 17, 17);
2691 l |= FLD_VAL(rf, 16, 16);
2692 l |= FLD_VAL(ieo, 15, 15);
2693 l |= FLD_VAL(ipc, 14, 14);
2694 l |= FLD_VAL(ihs, 13, 13);
2695 l |= FLD_VAL(ivs, 12, 12);
2696 l |= FLD_VAL(acbi, 11, 8);
2697 l |= FLD_VAL(acb, 7, 0);
2700 dispc_write_reg(DISPC_POL_FREQ(channel), l);
2704 void dispc_set_pol_freq(enum omap_channel channel,
2705 enum omap_panel_config config, u8 acbi, u8 acb)
2707 _dispc_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0,
2708 (config & OMAP_DSS_LCD_RF) != 0,
2709 (config & OMAP_DSS_LCD_IEO) != 0,
2710 (config & OMAP_DSS_LCD_IPC) != 0,
2711 (config & OMAP_DSS_LCD_IHS) != 0,
2712 (config & OMAP_DSS_LCD_IVS) != 0,
2716 /* with fck as input clock rate, find dispc dividers that produce req_pck */
2717 void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
2718 struct dispc_clock_info *cinfo)
2720 u16 pcd_min = is_tft ? 2 : 3;
2721 unsigned long best_pck;
2722 u16 best_ld, cur_ld;
2723 u16 best_pd, cur_pd;
2729 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
2730 unsigned long lck = fck / cur_ld;
2732 for (cur_pd = pcd_min; cur_pd <= 255; ++cur_pd) {
2733 unsigned long pck = lck / cur_pd;
2734 long old_delta = abs(best_pck - req_pck);
2735 long new_delta = abs(pck - req_pck);
2737 if (best_pck == 0 || new_delta < old_delta) {
2750 if (lck / pcd_min < req_pck)
2755 cinfo->lck_div = best_ld;
2756 cinfo->pck_div = best_pd;
2757 cinfo->lck = fck / cinfo->lck_div;
2758 cinfo->pck = cinfo->lck / cinfo->pck_div;
2761 /* calculate clock rates using dividers in cinfo */
2762 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
2763 struct dispc_clock_info *cinfo)
2765 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
2767 if (cinfo->pck_div < 2 || cinfo->pck_div > 255)
2770 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
2771 cinfo->pck = cinfo->lck / cinfo->pck_div;
2776 int dispc_set_clock_div(enum omap_channel channel,
2777 struct dispc_clock_info *cinfo)
2779 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
2780 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
2782 dispc_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
2787 int dispc_get_clock_div(enum omap_channel channel,
2788 struct dispc_clock_info *cinfo)
2792 fck = dispc_fclk_rate();
2794 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
2795 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
2797 cinfo->lck = fck / cinfo->lck_div;
2798 cinfo->pck = cinfo->lck / cinfo->pck_div;
2803 /* dispc.irq_lock has to be locked by the caller */
2804 static void _omap_dispc_set_irqs(void)
2809 struct omap_dispc_isr_data *isr_data;
2811 mask = dispc.irq_error_mask;
2813 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2814 isr_data = &dispc.registered_isr[i];
2816 if (isr_data->isr == NULL)
2819 mask |= isr_data->mask;
2824 old_mask = dispc_read_reg(DISPC_IRQENABLE);
2825 /* clear the irqstatus for newly enabled irqs */
2826 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
2828 dispc_write_reg(DISPC_IRQENABLE, mask);
2833 int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
2837 unsigned long flags;
2838 struct omap_dispc_isr_data *isr_data;
2843 spin_lock_irqsave(&dispc.irq_lock, flags);
2845 /* check for duplicate entry */
2846 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2847 isr_data = &dispc.registered_isr[i];
2848 if (isr_data->isr == isr && isr_data->arg == arg &&
2849 isr_data->mask == mask) {
2858 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2859 isr_data = &dispc.registered_isr[i];
2861 if (isr_data->isr != NULL)
2864 isr_data->isr = isr;
2865 isr_data->arg = arg;
2866 isr_data->mask = mask;
2875 _omap_dispc_set_irqs();
2877 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2881 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2885 EXPORT_SYMBOL(omap_dispc_register_isr);
2887 int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
2890 unsigned long flags;
2892 struct omap_dispc_isr_data *isr_data;
2894 spin_lock_irqsave(&dispc.irq_lock, flags);
2896 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2897 isr_data = &dispc.registered_isr[i];
2898 if (isr_data->isr != isr || isr_data->arg != arg ||
2899 isr_data->mask != mask)
2902 /* found the correct isr */
2904 isr_data->isr = NULL;
2905 isr_data->arg = NULL;
2913 _omap_dispc_set_irqs();
2915 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2919 EXPORT_SYMBOL(omap_dispc_unregister_isr);
2922 static void print_irq_status(u32 status)
2924 if ((status & dispc.irq_error_mask) == 0)
2927 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
2930 if (status & DISPC_IRQ_##x) \
2932 PIS(GFX_FIFO_UNDERFLOW);
2934 PIS(VID1_FIFO_UNDERFLOW);
2935 PIS(VID2_FIFO_UNDERFLOW);
2937 PIS(SYNC_LOST_DIGIT);
2938 if (dss_has_feature(FEAT_MGR_LCD2))
2946 /* Called from dss.c. Note that we don't touch clocks here,
2947 * but we presume they are on because we got an IRQ. However,
2948 * an irq handler may turn the clocks off, so we may not have
2949 * clock later in the function. */
2950 static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
2953 u32 irqstatus, irqenable;
2954 u32 handledirqs = 0;
2955 u32 unhandled_errors;
2956 struct omap_dispc_isr_data *isr_data;
2957 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
2959 spin_lock(&dispc.irq_lock);
2961 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
2962 irqenable = dispc_read_reg(DISPC_IRQENABLE);
2964 /* IRQ is not for us */
2965 if (!(irqstatus & irqenable)) {
2966 spin_unlock(&dispc.irq_lock);
2970 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
2971 spin_lock(&dispc.irq_stats_lock);
2972 dispc.irq_stats.irq_count++;
2973 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
2974 spin_unlock(&dispc.irq_stats_lock);
2979 print_irq_status(irqstatus);
2981 /* Ack the interrupt. Do it here before clocks are possibly turned
2983 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
2984 /* flush posted write */
2985 dispc_read_reg(DISPC_IRQSTATUS);
2987 /* make a copy and unlock, so that isrs can unregister
2989 memcpy(registered_isr, dispc.registered_isr,
2990 sizeof(registered_isr));
2992 spin_unlock(&dispc.irq_lock);
2994 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2995 isr_data = ®istered_isr[i];
3000 if (isr_data->mask & irqstatus) {
3001 isr_data->isr(isr_data->arg, irqstatus);
3002 handledirqs |= isr_data->mask;
3006 spin_lock(&dispc.irq_lock);
3008 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3010 if (unhandled_errors) {
3011 dispc.error_irqs |= unhandled_errors;
3013 dispc.irq_error_mask &= ~unhandled_errors;
3014 _omap_dispc_set_irqs();
3016 schedule_work(&dispc.error_work);
3019 spin_unlock(&dispc.irq_lock);
3024 static void dispc_error_worker(struct work_struct *work)
3028 unsigned long flags;
3030 spin_lock_irqsave(&dispc.irq_lock, flags);
3031 errors = dispc.error_irqs;
3032 dispc.error_irqs = 0;
3033 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3035 if (errors & DISPC_IRQ_GFX_FIFO_UNDERFLOW) {
3036 DSSERR("GFX_FIFO_UNDERFLOW, disabling GFX\n");
3037 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3038 struct omap_overlay *ovl;
3039 ovl = omap_dss_get_overlay(i);
3041 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
3045 dispc_enable_plane(ovl->id, 0);
3046 dispc_go(ovl->manager->id);
3053 if (errors & DISPC_IRQ_VID1_FIFO_UNDERFLOW) {
3054 DSSERR("VID1_FIFO_UNDERFLOW, disabling VID1\n");
3055 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3056 struct omap_overlay *ovl;
3057 ovl = omap_dss_get_overlay(i);
3059 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
3063 dispc_enable_plane(ovl->id, 0);
3064 dispc_go(ovl->manager->id);
3071 if (errors & DISPC_IRQ_VID2_FIFO_UNDERFLOW) {
3072 DSSERR("VID2_FIFO_UNDERFLOW, disabling VID2\n");
3073 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3074 struct omap_overlay *ovl;
3075 ovl = omap_dss_get_overlay(i);
3077 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
3081 dispc_enable_plane(ovl->id, 0);
3082 dispc_go(ovl->manager->id);
3089 if (errors & DISPC_IRQ_SYNC_LOST) {
3090 struct omap_overlay_manager *manager = NULL;
3091 bool enable = false;
3093 DSSERR("SYNC_LOST, disabling LCD\n");
3095 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3096 struct omap_overlay_manager *mgr;
3097 mgr = omap_dss_get_overlay_manager(i);
3099 if (mgr->id == OMAP_DSS_CHANNEL_LCD) {
3101 enable = mgr->device->state ==
3102 OMAP_DSS_DISPLAY_ACTIVE;
3103 mgr->device->driver->disable(mgr->device);
3109 struct omap_dss_device *dssdev = manager->device;
3110 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3111 struct omap_overlay *ovl;
3112 ovl = omap_dss_get_overlay(i);
3114 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
3117 if (ovl->id != 0 && ovl->manager == manager)
3118 dispc_enable_plane(ovl->id, 0);
3121 dispc_go(manager->id);
3124 dssdev->driver->enable(dssdev);
3128 if (errors & DISPC_IRQ_SYNC_LOST_DIGIT) {
3129 struct omap_overlay_manager *manager = NULL;
3130 bool enable = false;
3132 DSSERR("SYNC_LOST_DIGIT, disabling TV\n");
3134 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3135 struct omap_overlay_manager *mgr;
3136 mgr = omap_dss_get_overlay_manager(i);
3138 if (mgr->id == OMAP_DSS_CHANNEL_DIGIT) {
3140 enable = mgr->device->state ==
3141 OMAP_DSS_DISPLAY_ACTIVE;
3142 mgr->device->driver->disable(mgr->device);
3148 struct omap_dss_device *dssdev = manager->device;
3149 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3150 struct omap_overlay *ovl;
3151 ovl = omap_dss_get_overlay(i);
3153 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
3156 if (ovl->id != 0 && ovl->manager == manager)
3157 dispc_enable_plane(ovl->id, 0);
3160 dispc_go(manager->id);
3163 dssdev->driver->enable(dssdev);
3167 if (errors & DISPC_IRQ_SYNC_LOST2) {
3168 struct omap_overlay_manager *manager = NULL;
3169 bool enable = false;
3171 DSSERR("SYNC_LOST for LCD2, disabling LCD2\n");
3173 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3174 struct omap_overlay_manager *mgr;
3175 mgr = omap_dss_get_overlay_manager(i);
3177 if (mgr->id == OMAP_DSS_CHANNEL_LCD2) {
3179 enable = mgr->device->state ==
3180 OMAP_DSS_DISPLAY_ACTIVE;
3181 mgr->device->driver->disable(mgr->device);
3187 struct omap_dss_device *dssdev = manager->device;
3188 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3189 struct omap_overlay *ovl;
3190 ovl = omap_dss_get_overlay(i);
3192 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
3195 if (ovl->id != 0 && ovl->manager == manager)
3196 dispc_enable_plane(ovl->id, 0);
3199 dispc_go(manager->id);
3202 dssdev->driver->enable(dssdev);
3206 if (errors & DISPC_IRQ_OCP_ERR) {
3207 DSSERR("OCP_ERR\n");
3208 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3209 struct omap_overlay_manager *mgr;
3210 mgr = omap_dss_get_overlay_manager(i);
3212 if (mgr->caps & OMAP_DSS_OVL_CAP_DISPC)
3213 mgr->device->driver->disable(mgr->device);
3217 spin_lock_irqsave(&dispc.irq_lock, flags);
3218 dispc.irq_error_mask |= errors;
3219 _omap_dispc_set_irqs();
3220 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3223 int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3225 void dispc_irq_wait_handler(void *data, u32 mask)
3227 complete((struct completion *)data);
3231 DECLARE_COMPLETION_ONSTACK(completion);
3233 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3239 timeout = wait_for_completion_timeout(&completion, timeout);
3241 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3246 if (timeout == -ERESTARTSYS)
3247 return -ERESTARTSYS;
3252 int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3253 unsigned long timeout)
3255 void dispc_irq_wait_handler(void *data, u32 mask)
3257 complete((struct completion *)data);
3261 DECLARE_COMPLETION_ONSTACK(completion);
3263 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3269 timeout = wait_for_completion_interruptible_timeout(&completion,
3272 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3277 if (timeout == -ERESTARTSYS)
3278 return -ERESTARTSYS;
3283 #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
3284 void dispc_fake_vsync_irq(void)
3286 u32 irqstatus = DISPC_IRQ_VSYNC;
3289 WARN_ON(!in_interrupt());
3291 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3292 struct omap_dispc_isr_data *isr_data;
3293 isr_data = &dispc.registered_isr[i];
3298 if (isr_data->mask & irqstatus)
3299 isr_data->isr(isr_data->arg, irqstatus);
3304 static void _omap_dispc_initialize_irq(void)
3306 unsigned long flags;
3308 spin_lock_irqsave(&dispc.irq_lock, flags);
3310 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3312 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
3313 if (dss_has_feature(FEAT_MGR_LCD2))
3314 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
3316 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3318 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3320 _omap_dispc_set_irqs();
3322 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3325 void dispc_enable_sidle(void)
3327 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3330 void dispc_disable_sidle(void)
3332 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3335 static void _omap_dispc_initial_config(void)
3339 l = dispc_read_reg(DISPC_SYSCONFIG);
3340 l = FLD_MOD(l, 2, 13, 12); /* MIDLEMODE: smart standby */
3341 l = FLD_MOD(l, 2, 4, 3); /* SIDLEMODE: smart idle */
3342 l = FLD_MOD(l, 1, 2, 2); /* ENWAKEUP */
3343 l = FLD_MOD(l, 1, 0, 0); /* AUTOIDLE */
3344 dispc_write_reg(DISPC_SYSCONFIG, l);
3346 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3347 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3348 l = dispc_read_reg(DISPC_DIVISOR);
3349 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3350 l = FLD_MOD(l, 1, 0, 0);
3351 l = FLD_MOD(l, 1, 23, 16);
3352 dispc_write_reg(DISPC_DIVISOR, l);
3356 if (dss_has_feature(FEAT_FUNCGATED))
3357 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3359 /* L3 firewall setting: enable access to OCM RAM */
3360 /* XXX this should be somewhere in plat-omap */
3361 if (cpu_is_omap24xx())
3362 __raw_writel(0x402000b0, OMAP2_L3_IO_ADDRESS(0x680050a0));
3364 _dispc_setup_color_conv_coef();
3366 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3368 dispc_read_plane_fifo_sizes();
3371 int dispc_enable_plane(enum omap_plane plane, bool enable)
3373 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
3376 _dispc_enable_plane(plane, enable);
3382 int dispc_setup_plane(enum omap_plane plane,
3383 u32 paddr, u16 screen_width,
3384 u16 pos_x, u16 pos_y,
3385 u16 width, u16 height,
3386 u16 out_width, u16 out_height,
3387 enum omap_color_mode color_mode,
3389 enum omap_dss_rotation_type rotation_type,
3390 u8 rotation, bool mirror, u8 global_alpha,
3391 u8 pre_mult_alpha, enum omap_channel channel)
3395 DSSDBG("dispc_setup_plane %d, pa %x, sw %d, %d,%d, %dx%d -> "
3396 "%dx%d, ilace %d, cmode %x, rot %d, mir %d chan %d\n",
3397 plane, paddr, screen_width, pos_x, pos_y,
3399 out_width, out_height,
3401 rotation, mirror, channel);
3405 r = _dispc_setup_plane(plane,
3406 paddr, screen_width,
3409 out_width, out_height,
3414 pre_mult_alpha, channel);
3421 /* DISPC HW IP initialisation */
3422 static int omap_dispchw_probe(struct platform_device *pdev)
3426 struct resource *dispc_mem;
3430 spin_lock_init(&dispc.irq_lock);
3432 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3433 spin_lock_init(&dispc.irq_stats_lock);
3434 dispc.irq_stats.last_reset = jiffies;
3437 INIT_WORK(&dispc.error_work, dispc_error_worker);
3439 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3441 DSSERR("can't get IORESOURCE_MEM DISPC\n");
3445 dispc.base = ioremap(dispc_mem->start, resource_size(dispc_mem));
3447 DSSERR("can't ioremap DISPC\n");
3451 dispc.irq = platform_get_irq(dispc.pdev, 0);
3452 if (dispc.irq < 0) {
3453 DSSERR("platform_get_irq failed\n");
3458 r = request_irq(dispc.irq, omap_dispc_irq_handler, IRQF_SHARED,
3459 "OMAP DISPC", dispc.pdev);
3461 DSSERR("request_irq failed\n");
3467 _omap_dispc_initial_config();
3469 _omap_dispc_initialize_irq();
3471 dispc_save_context();
3473 rev = dispc_read_reg(DISPC_REVISION);
3474 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
3475 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3481 iounmap(dispc.base);
3486 static int omap_dispchw_remove(struct platform_device *pdev)
3488 free_irq(dispc.irq, dispc.pdev);
3489 iounmap(dispc.base);
3493 static struct platform_driver omap_dispchw_driver = {
3494 .probe = omap_dispchw_probe,
3495 .remove = omap_dispchw_remove,
3497 .name = "omapdss_dispc",
3498 .owner = THIS_MODULE,
3502 int dispc_init_platform_driver(void)
3504 return platform_driver_register(&omap_dispchw_driver);
3507 void dispc_uninit_platform_driver(void)
3509 return platform_driver_unregister(&omap_dispchw_driver);