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>
36 #include <linux/platform_device.h>
37 #include <linux/pm_runtime.h>
39 #include <plat/sram.h>
40 #include <plat/clock.h>
42 #include <video/omapdss.h>
45 #include "dss_features.h"
49 #define DISPC_SZ_REGS SZ_4K
51 #define DISPC_IRQ_MASK_ERROR (DISPC_IRQ_GFX_FIFO_UNDERFLOW | \
53 DISPC_IRQ_VID1_FIFO_UNDERFLOW | \
54 DISPC_IRQ_VID2_FIFO_UNDERFLOW | \
55 DISPC_IRQ_SYNC_LOST | \
56 DISPC_IRQ_SYNC_LOST_DIGIT)
58 #define DISPC_MAX_NR_ISRS 8
60 struct omap_dispc_isr_data {
82 enum omap_burst_size {
88 #define REG_GET(idx, start, end) \
89 FLD_GET(dispc_read_reg(idx), start, end)
91 #define REG_FLD_MOD(idx, val, start, end) \
92 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
94 struct dispc_irq_stats {
95 unsigned long last_reset;
101 struct platform_device *pdev;
109 u32 fifo_size[MAX_DSS_OVERLAYS];
113 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
115 struct work_struct error_work;
118 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
120 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
121 spinlock_t irq_stats_lock;
122 struct dispc_irq_stats irq_stats;
126 enum omap_color_component {
127 /* used for all color formats for OMAP3 and earlier
128 * and for RGB and Y color component on OMAP4
130 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
131 /* used for UV component for
132 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
133 * color formats on OMAP4
135 DISPC_COLOR_COMPONENT_UV = 1 << 1,
138 static void _omap_dispc_set_irqs(void);
140 static inline void dispc_write_reg(const u16 idx, u32 val)
142 __raw_writel(val, dispc.base + idx);
145 static inline u32 dispc_read_reg(const u16 idx)
147 return __raw_readl(dispc.base + idx);
150 static int dispc_get_ctx_loss_count(void)
152 struct device *dev = &dispc.pdev->dev;
153 struct omap_display_platform_data *pdata = dev->platform_data;
154 struct omap_dss_board_info *board_data = pdata->board_data;
157 if (!board_data->get_context_loss_count)
160 cnt = board_data->get_context_loss_count(dev);
162 WARN_ONCE(cnt < 0, "get_context_loss_count failed: %d\n", cnt);
168 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
170 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
172 static void dispc_save_context(void)
176 DSSDBG("dispc_save_context\n");
182 if (dss_has_feature(FEAT_GLOBAL_ALPHA))
184 if (dss_has_feature(FEAT_MGR_LCD2)) {
189 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
190 SR(DEFAULT_COLOR(i));
193 if (i == OMAP_DSS_CHANNEL_DIGIT)
204 if (dss_has_feature(FEAT_CPR)) {
211 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
216 SR(OVL_ATTRIBUTES(i));
217 SR(OVL_FIFO_THRESHOLD(i));
219 SR(OVL_PIXEL_INC(i));
220 if (dss_has_feature(FEAT_PRELOAD))
222 if (i == OMAP_DSS_GFX) {
223 SR(OVL_WINDOW_SKIP(i));
228 SR(OVL_PICTURE_SIZE(i));
232 for (j = 0; j < 8; j++)
233 SR(OVL_FIR_COEF_H(i, j));
235 for (j = 0; j < 8; j++)
236 SR(OVL_FIR_COEF_HV(i, j));
238 for (j = 0; j < 5; j++)
239 SR(OVL_CONV_COEF(i, j));
241 if (dss_has_feature(FEAT_FIR_COEF_V)) {
242 for (j = 0; j < 8; j++)
243 SR(OVL_FIR_COEF_V(i, j));
246 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
253 for (j = 0; j < 8; j++)
254 SR(OVL_FIR_COEF_H2(i, j));
256 for (j = 0; j < 8; j++)
257 SR(OVL_FIR_COEF_HV2(i, j));
259 for (j = 0; j < 8; j++)
260 SR(OVL_FIR_COEF_V2(i, j));
262 if (dss_has_feature(FEAT_ATTR2))
263 SR(OVL_ATTRIBUTES2(i));
266 if (dss_has_feature(FEAT_CORE_CLK_DIV))
269 dispc.ctx_loss_cnt = dispc_get_ctx_loss_count();
270 dispc.ctx_valid = true;
272 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
275 static void dispc_restore_context(void)
279 DSSDBG("dispc_restore_context\n");
281 if (!dispc.ctx_valid)
284 ctx = dispc_get_ctx_loss_count();
286 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
289 DSSDBG("ctx_loss_count: saved %d, current %d\n",
290 dispc.ctx_loss_cnt, ctx);
296 if (dss_has_feature(FEAT_GLOBAL_ALPHA))
298 if (dss_has_feature(FEAT_MGR_LCD2))
301 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
302 RR(DEFAULT_COLOR(i));
305 if (i == OMAP_DSS_CHANNEL_DIGIT)
316 if (dss_has_feature(FEAT_CPR)) {
323 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
328 RR(OVL_ATTRIBUTES(i));
329 RR(OVL_FIFO_THRESHOLD(i));
331 RR(OVL_PIXEL_INC(i));
332 if (dss_has_feature(FEAT_PRELOAD))
334 if (i == OMAP_DSS_GFX) {
335 RR(OVL_WINDOW_SKIP(i));
340 RR(OVL_PICTURE_SIZE(i));
344 for (j = 0; j < 8; j++)
345 RR(OVL_FIR_COEF_H(i, j));
347 for (j = 0; j < 8; j++)
348 RR(OVL_FIR_COEF_HV(i, j));
350 for (j = 0; j < 5; j++)
351 RR(OVL_CONV_COEF(i, j));
353 if (dss_has_feature(FEAT_FIR_COEF_V)) {
354 for (j = 0; j < 8; j++)
355 RR(OVL_FIR_COEF_V(i, j));
358 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
365 for (j = 0; j < 8; j++)
366 RR(OVL_FIR_COEF_H2(i, j));
368 for (j = 0; j < 8; j++)
369 RR(OVL_FIR_COEF_HV2(i, j));
371 for (j = 0; j < 8; j++)
372 RR(OVL_FIR_COEF_V2(i, j));
374 if (dss_has_feature(FEAT_ATTR2))
375 RR(OVL_ATTRIBUTES2(i));
378 if (dss_has_feature(FEAT_CORE_CLK_DIV))
381 /* enable last, because LCD & DIGIT enable are here */
383 if (dss_has_feature(FEAT_MGR_LCD2))
385 /* clear spurious SYNC_LOST_DIGIT interrupts */
386 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
389 * enable last so IRQs won't trigger before
390 * the context is fully restored
394 DSSDBG("context restored\n");
400 int dispc_runtime_get(void)
404 DSSDBG("dispc_runtime_get\n");
406 r = pm_runtime_get_sync(&dispc.pdev->dev);
408 return r < 0 ? r : 0;
411 void dispc_runtime_put(void)
415 DSSDBG("dispc_runtime_put\n");
417 r = pm_runtime_put(&dispc.pdev->dev);
421 static inline bool dispc_mgr_is_lcd(enum omap_channel channel)
423 if (channel == OMAP_DSS_CHANNEL_LCD ||
424 channel == OMAP_DSS_CHANNEL_LCD2)
430 static struct omap_dss_device *dispc_mgr_get_device(enum omap_channel channel)
432 struct omap_overlay_manager *mgr =
433 omap_dss_get_overlay_manager(channel);
435 return mgr ? mgr->device : NULL;
438 bool dispc_mgr_go_busy(enum omap_channel channel)
442 if (dispc_mgr_is_lcd(channel))
445 bit = 6; /* GODIGIT */
447 if (channel == OMAP_DSS_CHANNEL_LCD2)
448 return REG_GET(DISPC_CONTROL2, bit, bit) == 1;
450 return REG_GET(DISPC_CONTROL, bit, bit) == 1;
453 void dispc_mgr_go(enum omap_channel channel)
456 bool enable_bit, go_bit;
458 if (dispc_mgr_is_lcd(channel))
459 bit = 0; /* LCDENABLE */
461 bit = 1; /* DIGITALENABLE */
463 /* if the channel is not enabled, we don't need GO */
464 if (channel == OMAP_DSS_CHANNEL_LCD2)
465 enable_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
467 enable_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
472 if (dispc_mgr_is_lcd(channel))
475 bit = 6; /* GODIGIT */
477 if (channel == OMAP_DSS_CHANNEL_LCD2)
478 go_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
480 go_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
483 DSSERR("GO bit not down for channel %d\n", channel);
487 DSSDBG("GO %s\n", channel == OMAP_DSS_CHANNEL_LCD ? "LCD" :
488 (channel == OMAP_DSS_CHANNEL_LCD2 ? "LCD2" : "DIGIT"));
490 if (channel == OMAP_DSS_CHANNEL_LCD2)
491 REG_FLD_MOD(DISPC_CONTROL2, 1, bit, bit);
493 REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit);
496 static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
498 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
501 static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
503 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
506 static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
508 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
511 static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
513 BUG_ON(plane == OMAP_DSS_GFX);
515 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
518 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
521 BUG_ON(plane == OMAP_DSS_GFX);
523 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
526 static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
528 BUG_ON(plane == OMAP_DSS_GFX);
530 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
533 static void dispc_ovl_set_scale_coef(enum omap_plane plane, int hscaleup,
534 int vscaleup, int five_taps,
535 enum omap_color_component color_comp)
537 /* Coefficients for horizontal up-sampling */
538 static const struct dispc_h_coef coef_hup[8] = {
540 { -1, 13, 124, -8, 0 },
541 { -2, 30, 112, -11, -1 },
542 { -5, 51, 95, -11, -2 },
543 { 0, -9, 73, 73, -9 },
544 { -2, -11, 95, 51, -5 },
545 { -1, -11, 112, 30, -2 },
546 { 0, -8, 124, 13, -1 },
549 /* Coefficients for vertical up-sampling */
550 static const struct dispc_v_coef coef_vup_3tap[8] = {
553 { 0, 12, 111, 5, 0 },
557 { 0, 5, 111, 12, 0 },
561 static const struct dispc_v_coef coef_vup_5tap[8] = {
563 { -1, 13, 124, -8, 0 },
564 { -2, 30, 112, -11, -1 },
565 { -5, 51, 95, -11, -2 },
566 { 0, -9, 73, 73, -9 },
567 { -2, -11, 95, 51, -5 },
568 { -1, -11, 112, 30, -2 },
569 { 0, -8, 124, 13, -1 },
572 /* Coefficients for horizontal down-sampling */
573 static const struct dispc_h_coef coef_hdown[8] = {
574 { 0, 36, 56, 36, 0 },
575 { 4, 40, 55, 31, -2 },
576 { 8, 44, 54, 27, -5 },
577 { 12, 48, 53, 22, -7 },
578 { -9, 17, 52, 51, 17 },
579 { -7, 22, 53, 48, 12 },
580 { -5, 27, 54, 44, 8 },
581 { -2, 31, 55, 40, 4 },
584 /* Coefficients for vertical down-sampling */
585 static const struct dispc_v_coef coef_vdown_3tap[8] = {
586 { 0, 36, 56, 36, 0 },
587 { 0, 40, 57, 31, 0 },
588 { 0, 45, 56, 27, 0 },
589 { 0, 50, 55, 23, 0 },
590 { 0, 18, 55, 55, 0 },
591 { 0, 23, 55, 50, 0 },
592 { 0, 27, 56, 45, 0 },
593 { 0, 31, 57, 40, 0 },
596 static const struct dispc_v_coef coef_vdown_5tap[8] = {
597 { 0, 36, 56, 36, 0 },
598 { 4, 40, 55, 31, -2 },
599 { 8, 44, 54, 27, -5 },
600 { 12, 48, 53, 22, -7 },
601 { -9, 17, 52, 51, 17 },
602 { -7, 22, 53, 48, 12 },
603 { -5, 27, 54, 44, 8 },
604 { -2, 31, 55, 40, 4 },
607 const struct dispc_h_coef *h_coef;
608 const struct dispc_v_coef *v_coef;
617 v_coef = five_taps ? coef_vup_5tap : coef_vup_3tap;
619 v_coef = five_taps ? coef_vdown_5tap : coef_vdown_3tap;
621 for (i = 0; i < 8; i++) {
624 h = FLD_VAL(h_coef[i].hc0, 7, 0)
625 | FLD_VAL(h_coef[i].hc1, 15, 8)
626 | FLD_VAL(h_coef[i].hc2, 23, 16)
627 | FLD_VAL(h_coef[i].hc3, 31, 24);
628 hv = FLD_VAL(h_coef[i].hc4, 7, 0)
629 | FLD_VAL(v_coef[i].vc0, 15, 8)
630 | FLD_VAL(v_coef[i].vc1, 23, 16)
631 | FLD_VAL(v_coef[i].vc2, 31, 24);
633 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
634 dispc_ovl_write_firh_reg(plane, i, h);
635 dispc_ovl_write_firhv_reg(plane, i, hv);
637 dispc_ovl_write_firh2_reg(plane, i, h);
638 dispc_ovl_write_firhv2_reg(plane, i, hv);
644 for (i = 0; i < 8; i++) {
646 v = FLD_VAL(v_coef[i].vc00, 7, 0)
647 | FLD_VAL(v_coef[i].vc22, 15, 8);
648 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
649 dispc_ovl_write_firv_reg(plane, i, v);
651 dispc_ovl_write_firv2_reg(plane, i, v);
656 static void _dispc_setup_color_conv_coef(void)
659 const struct color_conv_coef {
660 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
663 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
666 const struct color_conv_coef *ct;
668 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
672 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
673 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 0),
674 CVAL(ct->rcr, ct->ry));
675 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 1),
676 CVAL(ct->gy, ct->rcb));
677 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 2),
678 CVAL(ct->gcb, ct->gcr));
679 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 3),
680 CVAL(ct->bcr, ct->by));
681 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 4),
684 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), ct->full_range,
692 static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
694 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
697 static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
699 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
702 static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
704 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
707 static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
709 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
712 static void dispc_ovl_set_pos(enum omap_plane plane, int x, int y)
714 u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
716 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
719 static void dispc_ovl_set_pic_size(enum omap_plane plane, int width, int height)
721 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
723 if (plane == OMAP_DSS_GFX)
724 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
726 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
729 static void dispc_ovl_set_vid_size(enum omap_plane plane, int width, int height)
733 BUG_ON(plane == OMAP_DSS_GFX);
735 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
737 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
740 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane, bool enable)
742 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
744 if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
747 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
750 static void dispc_ovl_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
752 static const unsigned shifts[] = { 0, 8, 16, };
754 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
756 if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
759 shift = shifts[plane];
760 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
763 static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
765 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
768 static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
770 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
773 static void dispc_ovl_set_color_mode(enum omap_plane plane,
774 enum omap_color_mode color_mode)
777 if (plane != OMAP_DSS_GFX) {
778 switch (color_mode) {
779 case OMAP_DSS_COLOR_NV12:
781 case OMAP_DSS_COLOR_RGB12U:
783 case OMAP_DSS_COLOR_RGBA16:
785 case OMAP_DSS_COLOR_RGBX16:
787 case OMAP_DSS_COLOR_ARGB16:
789 case OMAP_DSS_COLOR_RGB16:
791 case OMAP_DSS_COLOR_ARGB16_1555:
793 case OMAP_DSS_COLOR_RGB24U:
795 case OMAP_DSS_COLOR_RGB24P:
797 case OMAP_DSS_COLOR_YUV2:
799 case OMAP_DSS_COLOR_UYVY:
801 case OMAP_DSS_COLOR_ARGB32:
803 case OMAP_DSS_COLOR_RGBA32:
805 case OMAP_DSS_COLOR_RGBX32:
807 case OMAP_DSS_COLOR_XRGB16_1555:
813 switch (color_mode) {
814 case OMAP_DSS_COLOR_CLUT1:
816 case OMAP_DSS_COLOR_CLUT2:
818 case OMAP_DSS_COLOR_CLUT4:
820 case OMAP_DSS_COLOR_CLUT8:
822 case OMAP_DSS_COLOR_RGB12U:
824 case OMAP_DSS_COLOR_ARGB16:
826 case OMAP_DSS_COLOR_RGB16:
828 case OMAP_DSS_COLOR_ARGB16_1555:
830 case OMAP_DSS_COLOR_RGB24U:
832 case OMAP_DSS_COLOR_RGB24P:
834 case OMAP_DSS_COLOR_YUV2:
836 case OMAP_DSS_COLOR_UYVY:
838 case OMAP_DSS_COLOR_ARGB32:
840 case OMAP_DSS_COLOR_RGBA32:
842 case OMAP_DSS_COLOR_RGBX32:
844 case OMAP_DSS_COLOR_XRGB16_1555:
851 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
854 static void dispc_ovl_set_channel_out(enum omap_plane plane,
855 enum omap_channel channel)
859 int chan = 0, chan2 = 0;
865 case OMAP_DSS_VIDEO1:
866 case OMAP_DSS_VIDEO2:
874 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
875 if (dss_has_feature(FEAT_MGR_LCD2)) {
877 case OMAP_DSS_CHANNEL_LCD:
881 case OMAP_DSS_CHANNEL_DIGIT:
885 case OMAP_DSS_CHANNEL_LCD2:
893 val = FLD_MOD(val, chan, shift, shift);
894 val = FLD_MOD(val, chan2, 31, 30);
896 val = FLD_MOD(val, channel, shift, shift);
898 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
901 static void dispc_ovl_set_burst_size(enum omap_plane plane,
902 enum omap_burst_size burst_size)
904 static const unsigned shifts[] = { 6, 14, 14, };
907 shift = shifts[plane];
908 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
911 static void dispc_configure_burst_sizes(void)
914 const int burst_size = BURST_SIZE_X8;
916 /* Configure burst size always to maximum size */
917 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
918 dispc_ovl_set_burst_size(i, burst_size);
921 u32 dispc_ovl_get_burst_size(enum omap_plane plane)
923 unsigned unit = dss_feat_get_burst_size_unit();
924 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
928 void dispc_enable_gamma_table(bool enable)
931 * This is partially implemented to support only disabling of
935 DSSWARN("Gamma table enabling for TV not yet supported");
939 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
942 void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
946 if (channel == OMAP_DSS_CHANNEL_LCD)
948 else if (channel == OMAP_DSS_CHANNEL_LCD2)
953 REG_FLD_MOD(reg, enable, 15, 15);
956 void dispc_mgr_set_cpr_coef(enum omap_channel channel,
957 struct omap_dss_cpr_coefs *coefs)
959 u32 coef_r, coef_g, coef_b;
961 if (!dispc_mgr_is_lcd(channel))
964 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
965 FLD_VAL(coefs->rb, 9, 0);
966 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
967 FLD_VAL(coefs->gb, 9, 0);
968 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
969 FLD_VAL(coefs->bb, 9, 0);
971 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
972 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
973 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
976 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
980 BUG_ON(plane == OMAP_DSS_GFX);
982 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
983 val = FLD_MOD(val, enable, 9, 9);
984 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
987 static void dispc_ovl_enable_replication(enum omap_plane plane, bool enable)
989 static const unsigned shifts[] = { 5, 10, 10 };
992 shift = shifts[plane];
993 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
996 void dispc_mgr_set_lcd_size(enum omap_channel channel, u16 width, u16 height)
999 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
1000 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
1001 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
1004 void dispc_set_digit_size(u16 width, u16 height)
1007 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
1008 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
1009 dispc_write_reg(DISPC_SIZE_MGR(OMAP_DSS_CHANNEL_DIGIT), val);
1012 static void dispc_read_plane_fifo_sizes(void)
1019 unit = dss_feat_get_buffer_size_unit();
1021 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1023 for (plane = 0; plane < dss_feat_get_num_ovls(); ++plane) {
1024 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(plane), start, end);
1026 dispc.fifo_size[plane] = size;
1030 u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1032 return dispc.fifo_size[plane];
1035 static void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low,
1038 u8 hi_start, hi_end, lo_start, lo_end;
1041 unit = dss_feat_get_buffer_size_unit();
1043 WARN_ON(low % unit != 0);
1044 WARN_ON(high % unit != 0);
1049 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1050 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1052 DSSDBG("fifo(%d) low/high old %u/%u, new %u/%u\n",
1054 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1056 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1060 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1061 FLD_VAL(high, hi_start, hi_end) |
1062 FLD_VAL(low, lo_start, lo_end));
1065 void dispc_enable_fifomerge(bool enable)
1067 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1068 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1071 static void dispc_ovl_set_fir(enum omap_plane plane,
1073 enum omap_color_component color_comp)
1077 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1078 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1080 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1081 &hinc_start, &hinc_end);
1082 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1083 &vinc_start, &vinc_end);
1084 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1085 FLD_VAL(hinc, hinc_start, hinc_end);
1087 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1089 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1090 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1094 static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1097 u8 hor_start, hor_end, vert_start, vert_end;
1099 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1100 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1102 val = FLD_VAL(vaccu, vert_start, vert_end) |
1103 FLD_VAL(haccu, hor_start, hor_end);
1105 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1108 static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1111 u8 hor_start, hor_end, vert_start, vert_end;
1113 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1114 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1116 val = FLD_VAL(vaccu, vert_start, vert_end) |
1117 FLD_VAL(haccu, hor_start, hor_end);
1119 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1122 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1127 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1128 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1131 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1136 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1137 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1140 static void dispc_ovl_set_scale_param(enum omap_plane plane,
1141 u16 orig_width, u16 orig_height,
1142 u16 out_width, u16 out_height,
1143 bool five_taps, u8 rotation,
1144 enum omap_color_component color_comp)
1146 int fir_hinc, fir_vinc;
1147 int hscaleup, vscaleup;
1149 hscaleup = orig_width <= out_width;
1150 vscaleup = orig_height <= out_height;
1152 dispc_ovl_set_scale_coef(plane, hscaleup, vscaleup, five_taps,
1155 fir_hinc = 1024 * orig_width / out_width;
1156 fir_vinc = 1024 * orig_height / out_height;
1158 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1161 static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1162 u16 orig_width, u16 orig_height,
1163 u16 out_width, u16 out_height,
1164 bool ilace, bool five_taps,
1165 bool fieldmode, enum omap_color_mode color_mode,
1172 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1173 out_width, out_height, five_taps,
1174 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1175 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1177 /* RESIZEENABLE and VERTICALTAPS */
1178 l &= ~((0x3 << 5) | (0x1 << 21));
1179 l |= (orig_width != out_width) ? (1 << 5) : 0;
1180 l |= (orig_height != out_height) ? (1 << 6) : 0;
1181 l |= five_taps ? (1 << 21) : 0;
1183 /* VRESIZECONF and HRESIZECONF */
1184 if (dss_has_feature(FEAT_RESIZECONF)) {
1186 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1187 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1190 /* LINEBUFFERSPLIT */
1191 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1193 l |= five_taps ? (1 << 22) : 0;
1196 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1199 * field 0 = even field = bottom field
1200 * field 1 = odd field = top field
1202 if (ilace && !fieldmode) {
1204 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1205 if (accu0 >= 1024/2) {
1211 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1212 dispc_ovl_set_vid_accu1(plane, 0, accu1);
1215 static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1216 u16 orig_width, u16 orig_height,
1217 u16 out_width, u16 out_height,
1218 bool ilace, bool five_taps,
1219 bool fieldmode, enum omap_color_mode color_mode,
1222 int scale_x = out_width != orig_width;
1223 int scale_y = out_height != orig_height;
1225 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1227 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1228 color_mode != OMAP_DSS_COLOR_UYVY &&
1229 color_mode != OMAP_DSS_COLOR_NV12)) {
1230 /* reset chroma resampling for RGB formats */
1231 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1234 switch (color_mode) {
1235 case OMAP_DSS_COLOR_NV12:
1236 /* UV is subsampled by 2 vertically*/
1238 /* UV is subsampled by 2 horz.*/
1241 case OMAP_DSS_COLOR_YUV2:
1242 case OMAP_DSS_COLOR_UYVY:
1243 /*For YUV422 with 90/270 rotation,
1244 *we don't upsample chroma
1246 if (rotation == OMAP_DSS_ROT_0 ||
1247 rotation == OMAP_DSS_ROT_180)
1248 /* UV is subsampled by 2 hrz*/
1250 /* must use FIR for YUV422 if rotated */
1251 if (rotation != OMAP_DSS_ROT_0)
1252 scale_x = scale_y = true;
1258 if (out_width != orig_width)
1260 if (out_height != orig_height)
1263 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1264 out_width, out_height, five_taps,
1265 rotation, DISPC_COLOR_COMPONENT_UV);
1267 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1268 (scale_x || scale_y) ? 1 : 0, 8, 8);
1270 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1272 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1274 dispc_ovl_set_vid_accu2_0(plane, 0x80, 0);
1275 dispc_ovl_set_vid_accu2_1(plane, 0x80, 0);
1278 static void dispc_ovl_set_scaling(enum omap_plane plane,
1279 u16 orig_width, u16 orig_height,
1280 u16 out_width, u16 out_height,
1281 bool ilace, bool five_taps,
1282 bool fieldmode, enum omap_color_mode color_mode,
1285 BUG_ON(plane == OMAP_DSS_GFX);
1287 dispc_ovl_set_scaling_common(plane,
1288 orig_width, orig_height,
1289 out_width, out_height,
1291 fieldmode, color_mode,
1294 dispc_ovl_set_scaling_uv(plane,
1295 orig_width, orig_height,
1296 out_width, out_height,
1298 fieldmode, color_mode,
1302 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1303 bool mirroring, enum omap_color_mode color_mode)
1305 bool row_repeat = false;
1308 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1309 color_mode == OMAP_DSS_COLOR_UYVY) {
1313 case OMAP_DSS_ROT_0:
1316 case OMAP_DSS_ROT_90:
1319 case OMAP_DSS_ROT_180:
1322 case OMAP_DSS_ROT_270:
1328 case OMAP_DSS_ROT_0:
1331 case OMAP_DSS_ROT_90:
1334 case OMAP_DSS_ROT_180:
1337 case OMAP_DSS_ROT_270:
1343 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1349 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1350 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1351 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1352 row_repeat ? 1 : 0, 18, 18);
1355 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1357 switch (color_mode) {
1358 case OMAP_DSS_COLOR_CLUT1:
1360 case OMAP_DSS_COLOR_CLUT2:
1362 case OMAP_DSS_COLOR_CLUT4:
1364 case OMAP_DSS_COLOR_CLUT8:
1365 case OMAP_DSS_COLOR_NV12:
1367 case OMAP_DSS_COLOR_RGB12U:
1368 case OMAP_DSS_COLOR_RGB16:
1369 case OMAP_DSS_COLOR_ARGB16:
1370 case OMAP_DSS_COLOR_YUV2:
1371 case OMAP_DSS_COLOR_UYVY:
1372 case OMAP_DSS_COLOR_RGBA16:
1373 case OMAP_DSS_COLOR_RGBX16:
1374 case OMAP_DSS_COLOR_ARGB16_1555:
1375 case OMAP_DSS_COLOR_XRGB16_1555:
1377 case OMAP_DSS_COLOR_RGB24P:
1379 case OMAP_DSS_COLOR_RGB24U:
1380 case OMAP_DSS_COLOR_ARGB32:
1381 case OMAP_DSS_COLOR_RGBA32:
1382 case OMAP_DSS_COLOR_RGBX32:
1389 static s32 pixinc(int pixels, u8 ps)
1393 else if (pixels > 1)
1394 return 1 + (pixels - 1) * ps;
1395 else if (pixels < 0)
1396 return 1 - (-pixels + 1) * ps;
1401 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1403 u16 width, u16 height,
1404 enum omap_color_mode color_mode, bool fieldmode,
1405 unsigned int field_offset,
1406 unsigned *offset0, unsigned *offset1,
1407 s32 *row_inc, s32 *pix_inc)
1411 /* FIXME CLUT formats */
1412 switch (color_mode) {
1413 case OMAP_DSS_COLOR_CLUT1:
1414 case OMAP_DSS_COLOR_CLUT2:
1415 case OMAP_DSS_COLOR_CLUT4:
1416 case OMAP_DSS_COLOR_CLUT8:
1419 case OMAP_DSS_COLOR_YUV2:
1420 case OMAP_DSS_COLOR_UYVY:
1424 ps = color_mode_to_bpp(color_mode) / 8;
1428 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1432 * field 0 = even field = bottom field
1433 * field 1 = odd field = top field
1435 switch (rotation + mirror * 4) {
1436 case OMAP_DSS_ROT_0:
1437 case OMAP_DSS_ROT_180:
1439 * If the pixel format is YUV or UYVY divide the width
1440 * of the image by 2 for 0 and 180 degree rotation.
1442 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1443 color_mode == OMAP_DSS_COLOR_UYVY)
1445 case OMAP_DSS_ROT_90:
1446 case OMAP_DSS_ROT_270:
1449 *offset0 = field_offset * screen_width * ps;
1453 *row_inc = pixinc(1 + (screen_width - width) +
1454 (fieldmode ? screen_width : 0),
1456 *pix_inc = pixinc(1, ps);
1459 case OMAP_DSS_ROT_0 + 4:
1460 case OMAP_DSS_ROT_180 + 4:
1461 /* If the pixel format is YUV or UYVY divide the width
1462 * of the image by 2 for 0 degree and 180 degree
1464 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1465 color_mode == OMAP_DSS_COLOR_UYVY)
1467 case OMAP_DSS_ROT_90 + 4:
1468 case OMAP_DSS_ROT_270 + 4:
1471 *offset0 = field_offset * screen_width * ps;
1474 *row_inc = pixinc(1 - (screen_width + width) -
1475 (fieldmode ? screen_width : 0),
1477 *pix_inc = pixinc(1, ps);
1485 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1487 u16 width, u16 height,
1488 enum omap_color_mode color_mode, bool fieldmode,
1489 unsigned int field_offset,
1490 unsigned *offset0, unsigned *offset1,
1491 s32 *row_inc, s32 *pix_inc)
1496 /* FIXME CLUT formats */
1497 switch (color_mode) {
1498 case OMAP_DSS_COLOR_CLUT1:
1499 case OMAP_DSS_COLOR_CLUT2:
1500 case OMAP_DSS_COLOR_CLUT4:
1501 case OMAP_DSS_COLOR_CLUT8:
1505 ps = color_mode_to_bpp(color_mode) / 8;
1509 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1512 /* width & height are overlay sizes, convert to fb sizes */
1514 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1523 * field 0 = even field = bottom field
1524 * field 1 = odd field = top field
1526 switch (rotation + mirror * 4) {
1527 case OMAP_DSS_ROT_0:
1530 *offset0 = *offset1 + field_offset * screen_width * ps;
1532 *offset0 = *offset1;
1533 *row_inc = pixinc(1 + (screen_width - fbw) +
1534 (fieldmode ? screen_width : 0),
1536 *pix_inc = pixinc(1, ps);
1538 case OMAP_DSS_ROT_90:
1539 *offset1 = screen_width * (fbh - 1) * ps;
1541 *offset0 = *offset1 + field_offset * ps;
1543 *offset0 = *offset1;
1544 *row_inc = pixinc(screen_width * (fbh - 1) + 1 +
1545 (fieldmode ? 1 : 0), ps);
1546 *pix_inc = pixinc(-screen_width, ps);
1548 case OMAP_DSS_ROT_180:
1549 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1551 *offset0 = *offset1 - field_offset * screen_width * ps;
1553 *offset0 = *offset1;
1554 *row_inc = pixinc(-1 -
1555 (screen_width - fbw) -
1556 (fieldmode ? screen_width : 0),
1558 *pix_inc = pixinc(-1, ps);
1560 case OMAP_DSS_ROT_270:
1561 *offset1 = (fbw - 1) * ps;
1563 *offset0 = *offset1 - field_offset * ps;
1565 *offset0 = *offset1;
1566 *row_inc = pixinc(-screen_width * (fbh - 1) - 1 -
1567 (fieldmode ? 1 : 0), ps);
1568 *pix_inc = pixinc(screen_width, ps);
1572 case OMAP_DSS_ROT_0 + 4:
1573 *offset1 = (fbw - 1) * ps;
1575 *offset0 = *offset1 + field_offset * screen_width * ps;
1577 *offset0 = *offset1;
1578 *row_inc = pixinc(screen_width * 2 - 1 +
1579 (fieldmode ? screen_width : 0),
1581 *pix_inc = pixinc(-1, ps);
1584 case OMAP_DSS_ROT_90 + 4:
1587 *offset0 = *offset1 + field_offset * ps;
1589 *offset0 = *offset1;
1590 *row_inc = pixinc(-screen_width * (fbh - 1) + 1 +
1591 (fieldmode ? 1 : 0),
1593 *pix_inc = pixinc(screen_width, ps);
1596 case OMAP_DSS_ROT_180 + 4:
1597 *offset1 = screen_width * (fbh - 1) * ps;
1599 *offset0 = *offset1 - field_offset * screen_width * ps;
1601 *offset0 = *offset1;
1602 *row_inc = pixinc(1 - screen_width * 2 -
1603 (fieldmode ? screen_width : 0),
1605 *pix_inc = pixinc(1, ps);
1608 case OMAP_DSS_ROT_270 + 4:
1609 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1611 *offset0 = *offset1 - field_offset * ps;
1613 *offset0 = *offset1;
1614 *row_inc = pixinc(screen_width * (fbh - 1) - 1 -
1615 (fieldmode ? 1 : 0),
1617 *pix_inc = pixinc(-screen_width, ps);
1625 static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width,
1626 u16 height, u16 out_width, u16 out_height,
1627 enum omap_color_mode color_mode)
1630 u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
1632 if (height > out_height) {
1633 struct omap_dss_device *dssdev = dispc_mgr_get_device(channel);
1634 unsigned int ppl = dssdev->panel.timings.x_res;
1636 tmp = pclk * height * out_width;
1637 do_div(tmp, 2 * out_height * ppl);
1640 if (height > 2 * out_height) {
1641 if (ppl == out_width)
1644 tmp = pclk * (height - 2 * out_height) * out_width;
1645 do_div(tmp, 2 * out_height * (ppl - out_width));
1646 fclk = max(fclk, (u32) tmp);
1650 if (width > out_width) {
1652 do_div(tmp, out_width);
1653 fclk = max(fclk, (u32) tmp);
1655 if (color_mode == OMAP_DSS_COLOR_RGB24U)
1662 static unsigned long calc_fclk(enum omap_channel channel, u16 width,
1663 u16 height, u16 out_width, u16 out_height)
1665 unsigned int hf, vf;
1668 * FIXME how to determine the 'A' factor
1669 * for the no downscaling case ?
1672 if (width > 3 * out_width)
1674 else if (width > 2 * out_width)
1676 else if (width > out_width)
1681 if (height > out_height)
1686 return dispc_mgr_pclk_rate(channel) * vf * hf;
1689 static int dispc_ovl_calc_scaling(enum omap_plane plane,
1690 enum omap_channel channel, u16 width, u16 height,
1691 u16 out_width, u16 out_height,
1692 enum omap_color_mode color_mode, bool *five_taps)
1694 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
1695 const int maxdownscale = cpu_is_omap34xx() ? 4 : 2;
1696 unsigned long fclk = 0;
1698 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
1699 if (width != out_width || height != out_height)
1705 if (out_width < width / maxdownscale ||
1706 out_width > width * 8)
1709 if (out_height < height / maxdownscale ||
1710 out_height > height * 8)
1713 /* Must use 5-tap filter? */
1714 *five_taps = height > out_height * 2;
1717 fclk = calc_fclk(channel, width, height, out_width,
1720 /* Try 5-tap filter if 3-tap fclk is too high */
1721 if (cpu_is_omap34xx() && height > out_height &&
1722 fclk > dispc_fclk_rate())
1726 if (width > (2048 >> *five_taps)) {
1727 DSSERR("failed to set up scaling, fclk too low\n");
1732 fclk = calc_fclk_five_taps(channel, width, height,
1733 out_width, out_height, color_mode);
1735 DSSDBG("required fclk rate = %lu Hz\n", fclk);
1736 DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate());
1738 if (!fclk || fclk > dispc_fclk_rate()) {
1739 DSSERR("failed to set up scaling, "
1740 "required fclk rate = %lu Hz, "
1741 "current fclk rate = %lu Hz\n",
1742 fclk, dispc_fclk_rate());
1749 int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
1750 bool ilace, enum omap_channel channel, bool replication,
1751 u32 fifo_low, u32 fifo_high)
1753 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
1754 bool five_taps = false;
1757 unsigned offset0, offset1;
1760 u16 frame_height = oi->height;
1761 unsigned int field_offset = 0;
1763 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
1764 "%dx%d, cmode %x, rot %d, mir %d, ilace %d chan %d repl %d "
1765 "fifo_low %d fifo high %d\n", plane, oi->paddr, oi->p_uv_addr,
1766 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
1767 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
1768 oi->mirror, ilace, channel, replication, fifo_low, fifo_high);
1773 if (ilace && oi->height == oi->out_height)
1780 oi->out_height /= 2;
1782 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
1784 oi->height, oi->pos_y, oi->out_height);
1787 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
1790 r = dispc_ovl_calc_scaling(plane, channel, oi->width, oi->height,
1791 oi->out_width, oi->out_height, oi->color_mode,
1796 if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
1797 oi->color_mode == OMAP_DSS_COLOR_UYVY ||
1798 oi->color_mode == OMAP_DSS_COLOR_NV12)
1801 if (ilace && !fieldmode) {
1803 * when downscaling the bottom field may have to start several
1804 * source lines below the top field. Unfortunately ACCUI
1805 * registers will only hold the fractional part of the offset
1806 * so the integer part must be added to the base address of the
1809 if (!oi->height || oi->height == oi->out_height)
1812 field_offset = oi->height / oi->out_height / 2;
1815 /* Fields are independent but interleaved in memory. */
1819 if (oi->rotation_type == OMAP_DSS_ROT_DMA)
1820 calc_dma_rotation_offset(oi->rotation, oi->mirror,
1821 oi->screen_width, oi->width, frame_height,
1822 oi->color_mode, fieldmode, field_offset,
1823 &offset0, &offset1, &row_inc, &pix_inc);
1825 calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
1826 oi->screen_width, oi->width, frame_height,
1827 oi->color_mode, fieldmode, field_offset,
1828 &offset0, &offset1, &row_inc, &pix_inc);
1830 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
1831 offset0, offset1, row_inc, pix_inc);
1833 dispc_ovl_set_color_mode(plane, oi->color_mode);
1835 dispc_ovl_set_ba0(plane, oi->paddr + offset0);
1836 dispc_ovl_set_ba1(plane, oi->paddr + offset1);
1838 if (OMAP_DSS_COLOR_NV12 == oi->color_mode) {
1839 dispc_ovl_set_ba0_uv(plane, oi->p_uv_addr + offset0);
1840 dispc_ovl_set_ba1_uv(plane, oi->p_uv_addr + offset1);
1844 dispc_ovl_set_row_inc(plane, row_inc);
1845 dispc_ovl_set_pix_inc(plane, pix_inc);
1847 DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, oi->width,
1848 oi->height, oi->out_width, oi->out_height);
1850 dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y);
1852 dispc_ovl_set_pic_size(plane, oi->width, oi->height);
1854 if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) {
1855 dispc_ovl_set_scaling(plane, oi->width, oi->height,
1856 oi->out_width, oi->out_height,
1857 ilace, five_taps, fieldmode,
1858 oi->color_mode, oi->rotation);
1859 dispc_ovl_set_vid_size(plane, oi->out_width, oi->out_height);
1860 dispc_ovl_set_vid_color_conv(plane, cconv);
1863 dispc_ovl_set_rotation_attrs(plane, oi->rotation, oi->mirror,
1866 dispc_ovl_set_pre_mult_alpha(plane, oi->pre_mult_alpha);
1867 dispc_ovl_setup_global_alpha(plane, oi->global_alpha);
1869 dispc_ovl_set_channel_out(plane, channel);
1871 dispc_ovl_enable_replication(plane, replication);
1872 dispc_ovl_set_fifo_threshold(plane, fifo_low, fifo_high);
1877 int dispc_ovl_enable(enum omap_plane plane, bool enable)
1879 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
1881 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
1886 static void dispc_disable_isr(void *data, u32 mask)
1888 struct completion *compl = data;
1892 static void _enable_lcd_out(enum omap_channel channel, bool enable)
1894 if (channel == OMAP_DSS_CHANNEL_LCD2)
1895 REG_FLD_MOD(DISPC_CONTROL2, enable ? 1 : 0, 0, 0);
1897 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0);
1900 static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
1902 struct completion frame_done_completion;
1907 /* When we disable LCD output, we need to wait until frame is done.
1908 * Otherwise the DSS is still working, and turning off the clocks
1909 * prevents DSS from going to OFF mode */
1910 is_on = channel == OMAP_DSS_CHANNEL_LCD2 ?
1911 REG_GET(DISPC_CONTROL2, 0, 0) :
1912 REG_GET(DISPC_CONTROL, 0, 0);
1914 irq = channel == OMAP_DSS_CHANNEL_LCD2 ? DISPC_IRQ_FRAMEDONE2 :
1915 DISPC_IRQ_FRAMEDONE;
1917 if (!enable && is_on) {
1918 init_completion(&frame_done_completion);
1920 r = omap_dispc_register_isr(dispc_disable_isr,
1921 &frame_done_completion, irq);
1924 DSSERR("failed to register FRAMEDONE isr\n");
1927 _enable_lcd_out(channel, enable);
1929 if (!enable && is_on) {
1930 if (!wait_for_completion_timeout(&frame_done_completion,
1931 msecs_to_jiffies(100)))
1932 DSSERR("timeout waiting for FRAME DONE\n");
1934 r = omap_dispc_unregister_isr(dispc_disable_isr,
1935 &frame_done_completion, irq);
1938 DSSERR("failed to unregister FRAMEDONE isr\n");
1942 static void _enable_digit_out(bool enable)
1944 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
1947 static void dispc_mgr_enable_digit_out(bool enable)
1949 struct completion frame_done_completion;
1950 enum dss_hdmi_venc_clk_source_select src;
1955 if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
1958 src = dss_get_hdmi_venc_clk_source();
1961 unsigned long flags;
1962 /* When we enable digit output, we'll get an extra digit
1963 * sync lost interrupt, that we need to ignore */
1964 spin_lock_irqsave(&dispc.irq_lock, flags);
1965 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
1966 _omap_dispc_set_irqs();
1967 spin_unlock_irqrestore(&dispc.irq_lock, flags);
1970 /* When we disable digit output, we need to wait until fields are done.
1971 * Otherwise the DSS is still working, and turning off the clocks
1972 * prevents DSS from going to OFF mode. And when enabling, we need to
1973 * wait for the extra sync losts */
1974 init_completion(&frame_done_completion);
1976 if (src == DSS_HDMI_M_PCLK && enable == false) {
1977 irq_mask = DISPC_IRQ_FRAMEDONETV;
1980 irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
1981 /* XXX I understand from TRM that we should only wait for the
1982 * current field to complete. But it seems we have to wait for
1987 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
1990 DSSERR("failed to register %x isr\n", irq_mask);
1992 _enable_digit_out(enable);
1994 for (i = 0; i < num_irqs; ++i) {
1995 if (!wait_for_completion_timeout(&frame_done_completion,
1996 msecs_to_jiffies(100)))
1997 DSSERR("timeout waiting for digit out to %s\n",
1998 enable ? "start" : "stop");
2001 r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
2004 DSSERR("failed to unregister %x isr\n", irq_mask);
2007 unsigned long flags;
2008 spin_lock_irqsave(&dispc.irq_lock, flags);
2009 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
2010 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
2011 _omap_dispc_set_irqs();
2012 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2016 bool dispc_mgr_is_enabled(enum omap_channel channel)
2018 if (channel == OMAP_DSS_CHANNEL_LCD)
2019 return !!REG_GET(DISPC_CONTROL, 0, 0);
2020 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2021 return !!REG_GET(DISPC_CONTROL, 1, 1);
2022 else if (channel == OMAP_DSS_CHANNEL_LCD2)
2023 return !!REG_GET(DISPC_CONTROL2, 0, 0);
2028 void dispc_mgr_enable(enum omap_channel channel, bool enable)
2030 if (dispc_mgr_is_lcd(channel))
2031 dispc_mgr_enable_lcd_out(channel, enable);
2032 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2033 dispc_mgr_enable_digit_out(enable);
2038 void dispc_lcd_enable_signal_polarity(bool act_high)
2040 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2043 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2046 void dispc_lcd_enable_signal(bool enable)
2048 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2051 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2054 void dispc_pck_free_enable(bool enable)
2056 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2059 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2062 void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2064 if (channel == OMAP_DSS_CHANNEL_LCD2)
2065 REG_FLD_MOD(DISPC_CONFIG2, enable ? 1 : 0, 16, 16);
2067 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16);
2071 void dispc_mgr_set_lcd_display_type(enum omap_channel channel,
2072 enum omap_lcd_display_type type)
2077 case OMAP_DSS_LCD_DISPLAY_STN:
2081 case OMAP_DSS_LCD_DISPLAY_TFT:
2090 if (channel == OMAP_DSS_CHANNEL_LCD2)
2091 REG_FLD_MOD(DISPC_CONTROL2, mode, 3, 3);
2093 REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3);
2096 void dispc_set_loadmode(enum omap_dss_load_mode mode)
2098 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2102 void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2104 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2107 u32 dispc_mgr_get_default_color(enum omap_channel channel)
2111 BUG_ON(channel != OMAP_DSS_CHANNEL_DIGIT &&
2112 channel != OMAP_DSS_CHANNEL_LCD &&
2113 channel != OMAP_DSS_CHANNEL_LCD2);
2115 l = dispc_read_reg(DISPC_DEFAULT_COLOR(channel));
2120 void dispc_mgr_set_trans_key(enum omap_channel ch,
2121 enum omap_dss_trans_key_type type,
2124 if (ch == OMAP_DSS_CHANNEL_LCD)
2125 REG_FLD_MOD(DISPC_CONFIG, type, 11, 11);
2126 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2127 REG_FLD_MOD(DISPC_CONFIG, type, 13, 13);
2128 else /* OMAP_DSS_CHANNEL_LCD2 */
2129 REG_FLD_MOD(DISPC_CONFIG2, type, 11, 11);
2131 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2134 void dispc_mgr_get_trans_key(enum omap_channel ch,
2135 enum omap_dss_trans_key_type *type,
2139 if (ch == OMAP_DSS_CHANNEL_LCD)
2140 *type = REG_GET(DISPC_CONFIG, 11, 11);
2141 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2142 *type = REG_GET(DISPC_CONFIG, 13, 13);
2143 else if (ch == OMAP_DSS_CHANNEL_LCD2)
2144 *type = REG_GET(DISPC_CONFIG2, 11, 11);
2150 *trans_key = dispc_read_reg(DISPC_TRANS_COLOR(ch));
2153 void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2155 if (ch == OMAP_DSS_CHANNEL_LCD)
2156 REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10);
2157 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2158 REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12);
2159 else /* OMAP_DSS_CHANNEL_LCD2 */
2160 REG_FLD_MOD(DISPC_CONFIG2, enable, 10, 10);
2162 void dispc_mgr_enable_alpha_blending(enum omap_channel ch, bool enable)
2164 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
2167 if (ch == OMAP_DSS_CHANNEL_LCD)
2168 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2169 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2170 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2171 else /* OMAP_DSS_CHANNEL_LCD2 */
2172 REG_FLD_MOD(DISPC_CONFIG2, enable, 18, 18);
2174 bool dispc_mgr_alpha_blending_enabled(enum omap_channel ch)
2178 if (!dss_has_feature(FEAT_GLOBAL_ALPHA))
2181 if (ch == OMAP_DSS_CHANNEL_LCD)
2182 enabled = REG_GET(DISPC_CONFIG, 18, 18);
2183 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2184 enabled = REG_GET(DISPC_CONFIG, 19, 19);
2185 else if (ch == OMAP_DSS_CHANNEL_LCD2)
2186 enabled = REG_GET(DISPC_CONFIG2, 18, 18);
2194 bool dispc_mgr_trans_key_enabled(enum omap_channel ch)
2198 if (ch == OMAP_DSS_CHANNEL_LCD)
2199 enabled = REG_GET(DISPC_CONFIG, 10, 10);
2200 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2201 enabled = REG_GET(DISPC_CONFIG, 12, 12);
2202 else if (ch == OMAP_DSS_CHANNEL_LCD2)
2203 enabled = REG_GET(DISPC_CONFIG2, 10, 10);
2211 void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2215 switch (data_lines) {
2233 if (channel == OMAP_DSS_CHANNEL_LCD2)
2234 REG_FLD_MOD(DISPC_CONTROL2, code, 9, 8);
2236 REG_FLD_MOD(DISPC_CONTROL, code, 9, 8);
2239 void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
2245 case DSS_IO_PAD_MODE_RESET:
2249 case DSS_IO_PAD_MODE_RFBI:
2253 case DSS_IO_PAD_MODE_BYPASS:
2262 l = dispc_read_reg(DISPC_CONTROL);
2263 l = FLD_MOD(l, gpout0, 15, 15);
2264 l = FLD_MOD(l, gpout1, 16, 16);
2265 dispc_write_reg(DISPC_CONTROL, l);
2268 void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2270 if (channel == OMAP_DSS_CHANNEL_LCD2)
2271 REG_FLD_MOD(DISPC_CONTROL2, enable, 11, 11);
2273 REG_FLD_MOD(DISPC_CONTROL, enable, 11, 11);
2276 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2277 int vsw, int vfp, int vbp)
2279 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2280 if (hsw < 1 || hsw > 64 ||
2281 hfp < 1 || hfp > 256 ||
2282 hbp < 1 || hbp > 256 ||
2283 vsw < 1 || vsw > 64 ||
2284 vfp < 0 || vfp > 255 ||
2285 vbp < 0 || vbp > 255)
2288 if (hsw < 1 || hsw > 256 ||
2289 hfp < 1 || hfp > 4096 ||
2290 hbp < 1 || hbp > 4096 ||
2291 vsw < 1 || vsw > 256 ||
2292 vfp < 0 || vfp > 4095 ||
2293 vbp < 0 || vbp > 4095)
2300 bool dispc_lcd_timings_ok(struct omap_video_timings *timings)
2302 return _dispc_lcd_timings_ok(timings->hsw, timings->hfp,
2303 timings->hbp, timings->vsw,
2304 timings->vfp, timings->vbp);
2307 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
2308 int hfp, int hbp, int vsw, int vfp, int vbp)
2310 u32 timing_h, timing_v;
2312 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2313 timing_h = FLD_VAL(hsw-1, 5, 0) | FLD_VAL(hfp-1, 15, 8) |
2314 FLD_VAL(hbp-1, 27, 20);
2316 timing_v = FLD_VAL(vsw-1, 5, 0) | FLD_VAL(vfp, 15, 8) |
2317 FLD_VAL(vbp, 27, 20);
2319 timing_h = FLD_VAL(hsw-1, 7, 0) | FLD_VAL(hfp-1, 19, 8) |
2320 FLD_VAL(hbp-1, 31, 20);
2322 timing_v = FLD_VAL(vsw-1, 7, 0) | FLD_VAL(vfp, 19, 8) |
2323 FLD_VAL(vbp, 31, 20);
2326 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2327 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
2330 /* change name to mode? */
2331 void dispc_mgr_set_lcd_timings(enum omap_channel channel,
2332 struct omap_video_timings *timings)
2334 unsigned xtot, ytot;
2335 unsigned long ht, vt;
2337 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
2338 timings->hbp, timings->vsw,
2339 timings->vfp, timings->vbp))
2342 _dispc_mgr_set_lcd_timings(channel, timings->hsw, timings->hfp,
2343 timings->hbp, timings->vsw, timings->vfp,
2346 dispc_mgr_set_lcd_size(channel, timings->x_res, timings->y_res);
2348 xtot = timings->x_res + timings->hfp + timings->hsw + timings->hbp;
2349 ytot = timings->y_res + timings->vfp + timings->vsw + timings->vbp;
2351 ht = (timings->pixel_clock * 1000) / xtot;
2352 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2354 DSSDBG("channel %d xres %u yres %u\n", channel, timings->x_res,
2356 DSSDBG("pck %u\n", timings->pixel_clock);
2357 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2358 timings->hsw, timings->hfp, timings->hbp,
2359 timings->vsw, timings->vfp, timings->vbp);
2361 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2364 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
2367 BUG_ON(lck_div < 1);
2368 BUG_ON(pck_div < 1);
2370 dispc_write_reg(DISPC_DIVISORo(channel),
2371 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
2374 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
2378 l = dispc_read_reg(DISPC_DIVISORo(channel));
2379 *lck_div = FLD_GET(l, 23, 16);
2380 *pck_div = FLD_GET(l, 7, 0);
2383 unsigned long dispc_fclk_rate(void)
2385 struct platform_device *dsidev;
2386 unsigned long r = 0;
2388 switch (dss_get_dispc_clk_source()) {
2389 case OMAP_DSS_CLK_SRC_FCK:
2390 r = clk_get_rate(dispc.dss_clk);
2392 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2393 dsidev = dsi_get_dsidev_from_id(0);
2394 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2396 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2397 dsidev = dsi_get_dsidev_from_id(1);
2398 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2407 unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
2409 struct platform_device *dsidev;
2414 l = dispc_read_reg(DISPC_DIVISORo(channel));
2416 lcd = FLD_GET(l, 23, 16);
2418 switch (dss_get_lcd_clk_source(channel)) {
2419 case OMAP_DSS_CLK_SRC_FCK:
2420 r = clk_get_rate(dispc.dss_clk);
2422 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2423 dsidev = dsi_get_dsidev_from_id(0);
2424 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2426 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2427 dsidev = dsi_get_dsidev_from_id(1);
2428 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2437 unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
2441 if (dispc_mgr_is_lcd(channel)) {
2445 l = dispc_read_reg(DISPC_DIVISORo(channel));
2447 pcd = FLD_GET(l, 7, 0);
2449 r = dispc_mgr_lclk_rate(channel);
2453 struct omap_dss_device *dssdev =
2454 dispc_mgr_get_device(channel);
2456 switch (dssdev->type) {
2457 case OMAP_DISPLAY_TYPE_VENC:
2458 return venc_get_pixel_clock();
2459 case OMAP_DISPLAY_TYPE_HDMI:
2460 return hdmi_get_pixel_clock();
2467 void dispc_dump_clocks(struct seq_file *s)
2471 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
2472 enum omap_dss_clk_source lcd_clk_src;
2474 if (dispc_runtime_get())
2477 seq_printf(s, "- DISPC -\n");
2479 seq_printf(s, "dispc fclk source = %s (%s)\n",
2480 dss_get_generic_clk_source_name(dispc_clk_src),
2481 dss_feat_get_clk_source_name(dispc_clk_src));
2483 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
2485 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
2486 seq_printf(s, "- DISPC-CORE-CLK -\n");
2487 l = dispc_read_reg(DISPC_DIVISOR);
2488 lcd = FLD_GET(l, 23, 16);
2490 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2491 (dispc_fclk_rate()/lcd), lcd);
2493 seq_printf(s, "- LCD1 -\n");
2495 lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD);
2497 seq_printf(s, "lcd1_clk source = %s (%s)\n",
2498 dss_get_generic_clk_source_name(lcd_clk_src),
2499 dss_feat_get_clk_source_name(lcd_clk_src));
2501 dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd);
2503 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2504 dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd);
2505 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2506 dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd);
2507 if (dss_has_feature(FEAT_MGR_LCD2)) {
2508 seq_printf(s, "- LCD2 -\n");
2510 lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD2);
2512 seq_printf(s, "lcd2_clk source = %s (%s)\n",
2513 dss_get_generic_clk_source_name(lcd_clk_src),
2514 dss_feat_get_clk_source_name(lcd_clk_src));
2516 dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd);
2518 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2519 dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd);
2520 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2521 dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd);
2524 dispc_runtime_put();
2527 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
2528 void dispc_dump_irqs(struct seq_file *s)
2530 unsigned long flags;
2531 struct dispc_irq_stats stats;
2533 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
2535 stats = dispc.irq_stats;
2536 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
2537 dispc.irq_stats.last_reset = jiffies;
2539 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
2541 seq_printf(s, "period %u ms\n",
2542 jiffies_to_msecs(jiffies - stats.last_reset));
2544 seq_printf(s, "irqs %d\n", stats.irq_count);
2546 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
2552 PIS(ACBIAS_COUNT_STAT);
2554 PIS(GFX_FIFO_UNDERFLOW);
2556 PIS(PAL_GAMMA_MASK);
2558 PIS(VID1_FIFO_UNDERFLOW);
2560 PIS(VID2_FIFO_UNDERFLOW);
2563 PIS(SYNC_LOST_DIGIT);
2565 if (dss_has_feature(FEAT_MGR_LCD2)) {
2568 PIS(ACBIAS_COUNT_STAT2);
2575 void dispc_dump_regs(struct seq_file *s)
2578 const char *mgr_names[] = {
2579 [OMAP_DSS_CHANNEL_LCD] = "LCD",
2580 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
2581 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
2583 const char *ovl_names[] = {
2584 [OMAP_DSS_GFX] = "GFX",
2585 [OMAP_DSS_VIDEO1] = "VID1",
2586 [OMAP_DSS_VIDEO2] = "VID2",
2588 const char **p_names;
2590 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
2592 if (dispc_runtime_get())
2595 /* DISPC common registers */
2596 DUMPREG(DISPC_REVISION);
2597 DUMPREG(DISPC_SYSCONFIG);
2598 DUMPREG(DISPC_SYSSTATUS);
2599 DUMPREG(DISPC_IRQSTATUS);
2600 DUMPREG(DISPC_IRQENABLE);
2601 DUMPREG(DISPC_CONTROL);
2602 DUMPREG(DISPC_CONFIG);
2603 DUMPREG(DISPC_CAPABLE);
2604 DUMPREG(DISPC_LINE_STATUS);
2605 DUMPREG(DISPC_LINE_NUMBER);
2606 if (dss_has_feature(FEAT_GLOBAL_ALPHA))
2607 DUMPREG(DISPC_GLOBAL_ALPHA);
2608 if (dss_has_feature(FEAT_MGR_LCD2)) {
2609 DUMPREG(DISPC_CONTROL2);
2610 DUMPREG(DISPC_CONFIG2);
2615 #define DISPC_REG(i, name) name(i)
2616 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
2617 48 - strlen(#r) - strlen(p_names[i]), " ", \
2618 dispc_read_reg(DISPC_REG(i, r)))
2620 p_names = mgr_names;
2622 /* DISPC channel specific registers */
2623 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
2624 DUMPREG(i, DISPC_DEFAULT_COLOR);
2625 DUMPREG(i, DISPC_TRANS_COLOR);
2626 DUMPREG(i, DISPC_SIZE_MGR);
2628 if (i == OMAP_DSS_CHANNEL_DIGIT)
2631 DUMPREG(i, DISPC_DEFAULT_COLOR);
2632 DUMPREG(i, DISPC_TRANS_COLOR);
2633 DUMPREG(i, DISPC_TIMING_H);
2634 DUMPREG(i, DISPC_TIMING_V);
2635 DUMPREG(i, DISPC_POL_FREQ);
2636 DUMPREG(i, DISPC_DIVISORo);
2637 DUMPREG(i, DISPC_SIZE_MGR);
2639 DUMPREG(i, DISPC_DATA_CYCLE1);
2640 DUMPREG(i, DISPC_DATA_CYCLE2);
2641 DUMPREG(i, DISPC_DATA_CYCLE3);
2643 if (dss_has_feature(FEAT_CPR)) {
2644 DUMPREG(i, DISPC_CPR_COEF_R);
2645 DUMPREG(i, DISPC_CPR_COEF_G);
2646 DUMPREG(i, DISPC_CPR_COEF_B);
2650 p_names = ovl_names;
2652 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
2653 DUMPREG(i, DISPC_OVL_BA0);
2654 DUMPREG(i, DISPC_OVL_BA1);
2655 DUMPREG(i, DISPC_OVL_POSITION);
2656 DUMPREG(i, DISPC_OVL_SIZE);
2657 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
2658 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
2659 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
2660 DUMPREG(i, DISPC_OVL_ROW_INC);
2661 DUMPREG(i, DISPC_OVL_PIXEL_INC);
2662 if (dss_has_feature(FEAT_PRELOAD))
2663 DUMPREG(i, DISPC_OVL_PRELOAD);
2665 if (i == OMAP_DSS_GFX) {
2666 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
2667 DUMPREG(i, DISPC_OVL_TABLE_BA);
2671 DUMPREG(i, DISPC_OVL_FIR);
2672 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
2673 DUMPREG(i, DISPC_OVL_ACCU0);
2674 DUMPREG(i, DISPC_OVL_ACCU1);
2675 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
2676 DUMPREG(i, DISPC_OVL_BA0_UV);
2677 DUMPREG(i, DISPC_OVL_BA1_UV);
2678 DUMPREG(i, DISPC_OVL_FIR2);
2679 DUMPREG(i, DISPC_OVL_ACCU2_0);
2680 DUMPREG(i, DISPC_OVL_ACCU2_1);
2682 if (dss_has_feature(FEAT_ATTR2))
2683 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
2684 if (dss_has_feature(FEAT_PRELOAD))
2685 DUMPREG(i, DISPC_OVL_PRELOAD);
2691 #define DISPC_REG(plane, name, i) name(plane, i)
2692 #define DUMPREG(plane, name, i) \
2693 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
2694 46 - strlen(#name) - strlen(p_names[plane]), " ", \
2695 dispc_read_reg(DISPC_REG(plane, name, i)))
2697 /* Video pipeline coefficient registers */
2699 /* start from OMAP_DSS_VIDEO1 */
2700 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
2701 for (j = 0; j < 8; j++)
2702 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
2704 for (j = 0; j < 8; j++)
2705 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
2707 for (j = 0; j < 5; j++)
2708 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
2710 if (dss_has_feature(FEAT_FIR_COEF_V)) {
2711 for (j = 0; j < 8; j++)
2712 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
2715 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
2716 for (j = 0; j < 8; j++)
2717 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
2719 for (j = 0; j < 8; j++)
2720 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
2722 for (j = 0; j < 8; j++)
2723 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
2727 dispc_runtime_put();
2733 static void _dispc_mgr_set_pol_freq(enum omap_channel channel, bool onoff,
2734 bool rf, bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi,
2739 DSSDBG("onoff %d rf %d ieo %d ipc %d ihs %d ivs %d acbi %d acb %d\n",
2740 onoff, rf, ieo, ipc, ihs, ivs, acbi, acb);
2742 l |= FLD_VAL(onoff, 17, 17);
2743 l |= FLD_VAL(rf, 16, 16);
2744 l |= FLD_VAL(ieo, 15, 15);
2745 l |= FLD_VAL(ipc, 14, 14);
2746 l |= FLD_VAL(ihs, 13, 13);
2747 l |= FLD_VAL(ivs, 12, 12);
2748 l |= FLD_VAL(acbi, 11, 8);
2749 l |= FLD_VAL(acb, 7, 0);
2751 dispc_write_reg(DISPC_POL_FREQ(channel), l);
2754 void dispc_mgr_set_pol_freq(enum omap_channel channel,
2755 enum omap_panel_config config, u8 acbi, u8 acb)
2757 _dispc_mgr_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0,
2758 (config & OMAP_DSS_LCD_RF) != 0,
2759 (config & OMAP_DSS_LCD_IEO) != 0,
2760 (config & OMAP_DSS_LCD_IPC) != 0,
2761 (config & OMAP_DSS_LCD_IHS) != 0,
2762 (config & OMAP_DSS_LCD_IVS) != 0,
2766 /* with fck as input clock rate, find dispc dividers that produce req_pck */
2767 void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
2768 struct dispc_clock_info *cinfo)
2770 u16 pcd_min, pcd_max;
2771 unsigned long best_pck;
2772 u16 best_ld, cur_ld;
2773 u16 best_pd, cur_pd;
2775 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
2776 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
2785 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
2786 unsigned long lck = fck / cur_ld;
2788 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
2789 unsigned long pck = lck / cur_pd;
2790 long old_delta = abs(best_pck - req_pck);
2791 long new_delta = abs(pck - req_pck);
2793 if (best_pck == 0 || new_delta < old_delta) {
2806 if (lck / pcd_min < req_pck)
2811 cinfo->lck_div = best_ld;
2812 cinfo->pck_div = best_pd;
2813 cinfo->lck = fck / cinfo->lck_div;
2814 cinfo->pck = cinfo->lck / cinfo->pck_div;
2817 /* calculate clock rates using dividers in cinfo */
2818 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
2819 struct dispc_clock_info *cinfo)
2821 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
2823 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
2826 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
2827 cinfo->pck = cinfo->lck / cinfo->pck_div;
2832 int dispc_mgr_set_clock_div(enum omap_channel channel,
2833 struct dispc_clock_info *cinfo)
2835 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
2836 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
2838 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
2843 int dispc_mgr_get_clock_div(enum omap_channel channel,
2844 struct dispc_clock_info *cinfo)
2848 fck = dispc_fclk_rate();
2850 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
2851 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
2853 cinfo->lck = fck / cinfo->lck_div;
2854 cinfo->pck = cinfo->lck / cinfo->pck_div;
2859 /* dispc.irq_lock has to be locked by the caller */
2860 static void _omap_dispc_set_irqs(void)
2865 struct omap_dispc_isr_data *isr_data;
2867 mask = dispc.irq_error_mask;
2869 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2870 isr_data = &dispc.registered_isr[i];
2872 if (isr_data->isr == NULL)
2875 mask |= isr_data->mask;
2878 old_mask = dispc_read_reg(DISPC_IRQENABLE);
2879 /* clear the irqstatus for newly enabled irqs */
2880 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
2882 dispc_write_reg(DISPC_IRQENABLE, mask);
2885 int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
2889 unsigned long flags;
2890 struct omap_dispc_isr_data *isr_data;
2895 spin_lock_irqsave(&dispc.irq_lock, flags);
2897 /* check for duplicate entry */
2898 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2899 isr_data = &dispc.registered_isr[i];
2900 if (isr_data->isr == isr && isr_data->arg == arg &&
2901 isr_data->mask == mask) {
2910 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2911 isr_data = &dispc.registered_isr[i];
2913 if (isr_data->isr != NULL)
2916 isr_data->isr = isr;
2917 isr_data->arg = arg;
2918 isr_data->mask = mask;
2927 _omap_dispc_set_irqs();
2929 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2933 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2937 EXPORT_SYMBOL(omap_dispc_register_isr);
2939 int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
2942 unsigned long flags;
2944 struct omap_dispc_isr_data *isr_data;
2946 spin_lock_irqsave(&dispc.irq_lock, flags);
2948 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2949 isr_data = &dispc.registered_isr[i];
2950 if (isr_data->isr != isr || isr_data->arg != arg ||
2951 isr_data->mask != mask)
2954 /* found the correct isr */
2956 isr_data->isr = NULL;
2957 isr_data->arg = NULL;
2965 _omap_dispc_set_irqs();
2967 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2971 EXPORT_SYMBOL(omap_dispc_unregister_isr);
2974 static void print_irq_status(u32 status)
2976 if ((status & dispc.irq_error_mask) == 0)
2979 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
2982 if (status & DISPC_IRQ_##x) \
2984 PIS(GFX_FIFO_UNDERFLOW);
2986 PIS(VID1_FIFO_UNDERFLOW);
2987 PIS(VID2_FIFO_UNDERFLOW);
2989 PIS(SYNC_LOST_DIGIT);
2990 if (dss_has_feature(FEAT_MGR_LCD2))
2998 /* Called from dss.c. Note that we don't touch clocks here,
2999 * but we presume they are on because we got an IRQ. However,
3000 * an irq handler may turn the clocks off, so we may not have
3001 * clock later in the function. */
3002 static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
3005 u32 irqstatus, irqenable;
3006 u32 handledirqs = 0;
3007 u32 unhandled_errors;
3008 struct omap_dispc_isr_data *isr_data;
3009 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3011 spin_lock(&dispc.irq_lock);
3013 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
3014 irqenable = dispc_read_reg(DISPC_IRQENABLE);
3016 /* IRQ is not for us */
3017 if (!(irqstatus & irqenable)) {
3018 spin_unlock(&dispc.irq_lock);
3022 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3023 spin_lock(&dispc.irq_stats_lock);
3024 dispc.irq_stats.irq_count++;
3025 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3026 spin_unlock(&dispc.irq_stats_lock);
3031 print_irq_status(irqstatus);
3033 /* Ack the interrupt. Do it here before clocks are possibly turned
3035 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
3036 /* flush posted write */
3037 dispc_read_reg(DISPC_IRQSTATUS);
3039 /* make a copy and unlock, so that isrs can unregister
3041 memcpy(registered_isr, dispc.registered_isr,
3042 sizeof(registered_isr));
3044 spin_unlock(&dispc.irq_lock);
3046 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3047 isr_data = ®istered_isr[i];
3052 if (isr_data->mask & irqstatus) {
3053 isr_data->isr(isr_data->arg, irqstatus);
3054 handledirqs |= isr_data->mask;
3058 spin_lock(&dispc.irq_lock);
3060 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3062 if (unhandled_errors) {
3063 dispc.error_irqs |= unhandled_errors;
3065 dispc.irq_error_mask &= ~unhandled_errors;
3066 _omap_dispc_set_irqs();
3068 schedule_work(&dispc.error_work);
3071 spin_unlock(&dispc.irq_lock);
3076 static void dispc_error_worker(struct work_struct *work)
3080 unsigned long flags;
3081 static const unsigned fifo_underflow_bits[] = {
3082 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3083 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3084 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
3087 static const unsigned sync_lost_bits[] = {
3088 DISPC_IRQ_SYNC_LOST,
3089 DISPC_IRQ_SYNC_LOST_DIGIT,
3090 DISPC_IRQ_SYNC_LOST2,
3093 spin_lock_irqsave(&dispc.irq_lock, flags);
3094 errors = dispc.error_irqs;
3095 dispc.error_irqs = 0;
3096 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3098 dispc_runtime_get();
3100 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3101 struct omap_overlay *ovl;
3104 ovl = omap_dss_get_overlay(i);
3105 bit = fifo_underflow_bits[i];
3108 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3110 dispc_ovl_enable(ovl->id, false);
3111 dispc_mgr_go(ovl->manager->id);
3116 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3117 struct omap_overlay_manager *mgr;
3120 mgr = omap_dss_get_overlay_manager(i);
3121 bit = sync_lost_bits[i];
3124 struct omap_dss_device *dssdev = mgr->device;
3127 DSSERR("SYNC_LOST on channel %s, restarting the output "
3128 "with video overlays disabled\n",
3131 enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
3132 dssdev->driver->disable(dssdev);
3134 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3135 struct omap_overlay *ovl;
3136 ovl = omap_dss_get_overlay(i);
3138 if (ovl->id != OMAP_DSS_GFX &&
3139 ovl->manager == mgr)
3140 dispc_ovl_enable(ovl->id, false);
3143 dispc_mgr_go(mgr->id);
3147 dssdev->driver->enable(dssdev);
3151 if (errors & DISPC_IRQ_OCP_ERR) {
3152 DSSERR("OCP_ERR\n");
3153 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3154 struct omap_overlay_manager *mgr;
3155 mgr = omap_dss_get_overlay_manager(i);
3156 mgr->device->driver->disable(mgr->device);
3160 spin_lock_irqsave(&dispc.irq_lock, flags);
3161 dispc.irq_error_mask |= errors;
3162 _omap_dispc_set_irqs();
3163 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3165 dispc_runtime_put();
3168 int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3170 void dispc_irq_wait_handler(void *data, u32 mask)
3172 complete((struct completion *)data);
3176 DECLARE_COMPLETION_ONSTACK(completion);
3178 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3184 timeout = wait_for_completion_timeout(&completion, timeout);
3186 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3191 if (timeout == -ERESTARTSYS)
3192 return -ERESTARTSYS;
3197 int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3198 unsigned long timeout)
3200 void dispc_irq_wait_handler(void *data, u32 mask)
3202 complete((struct completion *)data);
3206 DECLARE_COMPLETION_ONSTACK(completion);
3208 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3214 timeout = wait_for_completion_interruptible_timeout(&completion,
3217 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3222 if (timeout == -ERESTARTSYS)
3223 return -ERESTARTSYS;
3228 #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
3229 void dispc_fake_vsync_irq(void)
3231 u32 irqstatus = DISPC_IRQ_VSYNC;
3234 WARN_ON(!in_interrupt());
3236 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3237 struct omap_dispc_isr_data *isr_data;
3238 isr_data = &dispc.registered_isr[i];
3243 if (isr_data->mask & irqstatus)
3244 isr_data->isr(isr_data->arg, irqstatus);
3249 static void _omap_dispc_initialize_irq(void)
3251 unsigned long flags;
3253 spin_lock_irqsave(&dispc.irq_lock, flags);
3255 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3257 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
3258 if (dss_has_feature(FEAT_MGR_LCD2))
3259 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
3261 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3263 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3265 _omap_dispc_set_irqs();
3267 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3270 void dispc_enable_sidle(void)
3272 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3275 void dispc_disable_sidle(void)
3277 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3280 static void _omap_dispc_initial_config(void)
3284 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3285 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3286 l = dispc_read_reg(DISPC_DIVISOR);
3287 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3288 l = FLD_MOD(l, 1, 0, 0);
3289 l = FLD_MOD(l, 1, 23, 16);
3290 dispc_write_reg(DISPC_DIVISOR, l);
3294 if (dss_has_feature(FEAT_FUNCGATED))
3295 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3297 /* L3 firewall setting: enable access to OCM RAM */
3298 /* XXX this should be somewhere in plat-omap */
3299 if (cpu_is_omap24xx())
3300 __raw_writel(0x402000b0, OMAP2_L3_IO_ADDRESS(0x680050a0));
3302 _dispc_setup_color_conv_coef();
3304 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3306 dispc_read_plane_fifo_sizes();
3308 dispc_configure_burst_sizes();
3311 /* DISPC HW IP initialisation */
3312 static int omap_dispchw_probe(struct platform_device *pdev)
3316 struct resource *dispc_mem;
3321 clk = clk_get(&pdev->dev, "fck");
3323 DSSERR("can't get fck\n");
3328 dispc.dss_clk = clk;
3330 spin_lock_init(&dispc.irq_lock);
3332 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3333 spin_lock_init(&dispc.irq_stats_lock);
3334 dispc.irq_stats.last_reset = jiffies;
3337 INIT_WORK(&dispc.error_work, dispc_error_worker);
3339 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3341 DSSERR("can't get IORESOURCE_MEM DISPC\n");
3345 dispc.base = ioremap(dispc_mem->start, resource_size(dispc_mem));
3347 DSSERR("can't ioremap DISPC\n");
3351 dispc.irq = platform_get_irq(dispc.pdev, 0);
3352 if (dispc.irq < 0) {
3353 DSSERR("platform_get_irq failed\n");
3358 r = request_irq(dispc.irq, omap_dispc_irq_handler, IRQF_SHARED,
3359 "OMAP DISPC", dispc.pdev);
3361 DSSERR("request_irq failed\n");
3365 pm_runtime_enable(&pdev->dev);
3367 r = dispc_runtime_get();
3369 goto err_runtime_get;
3371 _omap_dispc_initial_config();
3373 _omap_dispc_initialize_irq();
3375 rev = dispc_read_reg(DISPC_REVISION);
3376 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
3377 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3379 dispc_runtime_put();
3384 pm_runtime_disable(&pdev->dev);
3385 free_irq(dispc.irq, dispc.pdev);
3387 iounmap(dispc.base);
3389 clk_put(dispc.dss_clk);
3394 static int omap_dispchw_remove(struct platform_device *pdev)
3396 pm_runtime_disable(&pdev->dev);
3398 clk_put(dispc.dss_clk);
3400 free_irq(dispc.irq, dispc.pdev);
3401 iounmap(dispc.base);
3405 static int dispc_runtime_suspend(struct device *dev)
3407 dispc_save_context();
3413 static int dispc_runtime_resume(struct device *dev)
3417 r = dss_runtime_get();
3421 dispc_restore_context();
3426 static const struct dev_pm_ops dispc_pm_ops = {
3427 .runtime_suspend = dispc_runtime_suspend,
3428 .runtime_resume = dispc_runtime_resume,
3431 static struct platform_driver omap_dispchw_driver = {
3432 .probe = omap_dispchw_probe,
3433 .remove = omap_dispchw_remove,
3435 .name = "omapdss_dispc",
3436 .owner = THIS_MODULE,
3437 .pm = &dispc_pm_ops,
3441 int dispc_init_platform_driver(void)
3443 return platform_driver_register(&omap_dispchw_driver);
3446 void dispc_uninit_platform_driver(void)
3448 return platform_driver_unregister(&omap_dispchw_driver);