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/export.h>
29 #include <linux/clk.h>
31 #include <linux/jiffies.h>
32 #include <linux/seq_file.h>
33 #include <linux/delay.h>
34 #include <linux/workqueue.h>
35 #include <linux/hardirq.h>
36 #include <linux/interrupt.h>
37 #include <linux/platform_device.h>
38 #include <linux/pm_runtime.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 {
66 enum omap_burst_size {
72 #define REG_GET(idx, start, end) \
73 FLD_GET(dispc_read_reg(idx), start, end)
75 #define REG_FLD_MOD(idx, val, start, end) \
76 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
78 struct dispc_irq_stats {
79 unsigned long last_reset;
85 struct platform_device *pdev;
93 u32 fifo_size[MAX_DSS_OVERLAYS];
97 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
99 struct work_struct error_work;
102 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
104 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
105 spinlock_t irq_stats_lock;
106 struct dispc_irq_stats irq_stats;
110 enum omap_color_component {
111 /* used for all color formats for OMAP3 and earlier
112 * and for RGB and Y color component on OMAP4
114 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
115 /* used for UV component for
116 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
117 * color formats on OMAP4
119 DISPC_COLOR_COMPONENT_UV = 1 << 1,
122 static void _omap_dispc_set_irqs(void);
124 static inline void dispc_write_reg(const u16 idx, u32 val)
126 __raw_writel(val, dispc.base + idx);
129 static inline u32 dispc_read_reg(const u16 idx)
131 return __raw_readl(dispc.base + idx);
135 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
137 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
139 static void dispc_save_context(void)
143 DSSDBG("dispc_save_context\n");
149 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
150 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
152 if (dss_has_feature(FEAT_MGR_LCD2)) {
157 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
158 SR(DEFAULT_COLOR(i));
161 if (i == OMAP_DSS_CHANNEL_DIGIT)
172 if (dss_has_feature(FEAT_CPR)) {
179 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
184 SR(OVL_ATTRIBUTES(i));
185 SR(OVL_FIFO_THRESHOLD(i));
187 SR(OVL_PIXEL_INC(i));
188 if (dss_has_feature(FEAT_PRELOAD))
190 if (i == OMAP_DSS_GFX) {
191 SR(OVL_WINDOW_SKIP(i));
196 SR(OVL_PICTURE_SIZE(i));
200 for (j = 0; j < 8; j++)
201 SR(OVL_FIR_COEF_H(i, j));
203 for (j = 0; j < 8; j++)
204 SR(OVL_FIR_COEF_HV(i, j));
206 for (j = 0; j < 5; j++)
207 SR(OVL_CONV_COEF(i, j));
209 if (dss_has_feature(FEAT_FIR_COEF_V)) {
210 for (j = 0; j < 8; j++)
211 SR(OVL_FIR_COEF_V(i, j));
214 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
221 for (j = 0; j < 8; j++)
222 SR(OVL_FIR_COEF_H2(i, j));
224 for (j = 0; j < 8; j++)
225 SR(OVL_FIR_COEF_HV2(i, j));
227 for (j = 0; j < 8; j++)
228 SR(OVL_FIR_COEF_V2(i, j));
230 if (dss_has_feature(FEAT_ATTR2))
231 SR(OVL_ATTRIBUTES2(i));
234 if (dss_has_feature(FEAT_CORE_CLK_DIV))
237 dispc.ctx_loss_cnt = dss_get_ctx_loss_count(&dispc.pdev->dev);
238 dispc.ctx_valid = true;
240 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
243 static void dispc_restore_context(void)
247 DSSDBG("dispc_restore_context\n");
249 if (!dispc.ctx_valid)
252 ctx = dss_get_ctx_loss_count(&dispc.pdev->dev);
254 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
257 DSSDBG("ctx_loss_count: saved %d, current %d\n",
258 dispc.ctx_loss_cnt, ctx);
264 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
265 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
267 if (dss_has_feature(FEAT_MGR_LCD2))
270 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
271 RR(DEFAULT_COLOR(i));
274 if (i == OMAP_DSS_CHANNEL_DIGIT)
285 if (dss_has_feature(FEAT_CPR)) {
292 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
297 RR(OVL_ATTRIBUTES(i));
298 RR(OVL_FIFO_THRESHOLD(i));
300 RR(OVL_PIXEL_INC(i));
301 if (dss_has_feature(FEAT_PRELOAD))
303 if (i == OMAP_DSS_GFX) {
304 RR(OVL_WINDOW_SKIP(i));
309 RR(OVL_PICTURE_SIZE(i));
313 for (j = 0; j < 8; j++)
314 RR(OVL_FIR_COEF_H(i, j));
316 for (j = 0; j < 8; j++)
317 RR(OVL_FIR_COEF_HV(i, j));
319 for (j = 0; j < 5; j++)
320 RR(OVL_CONV_COEF(i, j));
322 if (dss_has_feature(FEAT_FIR_COEF_V)) {
323 for (j = 0; j < 8; j++)
324 RR(OVL_FIR_COEF_V(i, j));
327 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
334 for (j = 0; j < 8; j++)
335 RR(OVL_FIR_COEF_H2(i, j));
337 for (j = 0; j < 8; j++)
338 RR(OVL_FIR_COEF_HV2(i, j));
340 for (j = 0; j < 8; j++)
341 RR(OVL_FIR_COEF_V2(i, j));
343 if (dss_has_feature(FEAT_ATTR2))
344 RR(OVL_ATTRIBUTES2(i));
347 if (dss_has_feature(FEAT_CORE_CLK_DIV))
350 /* enable last, because LCD & DIGIT enable are here */
352 if (dss_has_feature(FEAT_MGR_LCD2))
354 /* clear spurious SYNC_LOST_DIGIT interrupts */
355 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
358 * enable last so IRQs won't trigger before
359 * the context is fully restored
363 DSSDBG("context restored\n");
369 int dispc_runtime_get(void)
373 DSSDBG("dispc_runtime_get\n");
375 r = pm_runtime_get_sync(&dispc.pdev->dev);
377 return r < 0 ? r : 0;
380 void dispc_runtime_put(void)
384 DSSDBG("dispc_runtime_put\n");
386 r = pm_runtime_put_sync(&dispc.pdev->dev);
390 static inline bool dispc_mgr_is_lcd(enum omap_channel channel)
392 if (channel == OMAP_DSS_CHANNEL_LCD ||
393 channel == OMAP_DSS_CHANNEL_LCD2)
399 u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
402 case OMAP_DSS_CHANNEL_LCD:
403 return DISPC_IRQ_VSYNC;
404 case OMAP_DSS_CHANNEL_LCD2:
405 return DISPC_IRQ_VSYNC2;
406 case OMAP_DSS_CHANNEL_DIGIT:
407 return DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
414 u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
417 case OMAP_DSS_CHANNEL_LCD:
418 return DISPC_IRQ_FRAMEDONE;
419 case OMAP_DSS_CHANNEL_LCD2:
420 return DISPC_IRQ_FRAMEDONE2;
421 case OMAP_DSS_CHANNEL_DIGIT:
429 bool dispc_mgr_go_busy(enum omap_channel channel)
433 if (dispc_mgr_is_lcd(channel))
436 bit = 6; /* GODIGIT */
438 if (channel == OMAP_DSS_CHANNEL_LCD2)
439 return REG_GET(DISPC_CONTROL2, bit, bit) == 1;
441 return REG_GET(DISPC_CONTROL, bit, bit) == 1;
444 void dispc_mgr_go(enum omap_channel channel)
447 bool enable_bit, go_bit;
449 if (dispc_mgr_is_lcd(channel))
450 bit = 0; /* LCDENABLE */
452 bit = 1; /* DIGITALENABLE */
454 /* if the channel is not enabled, we don't need GO */
455 if (channel == OMAP_DSS_CHANNEL_LCD2)
456 enable_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
458 enable_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
463 if (dispc_mgr_is_lcd(channel))
466 bit = 6; /* GODIGIT */
468 if (channel == OMAP_DSS_CHANNEL_LCD2)
469 go_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
471 go_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
474 DSSERR("GO bit not down for channel %d\n", channel);
478 DSSDBG("GO %s\n", channel == OMAP_DSS_CHANNEL_LCD ? "LCD" :
479 (channel == OMAP_DSS_CHANNEL_LCD2 ? "LCD2" : "DIGIT"));
481 if (channel == OMAP_DSS_CHANNEL_LCD2)
482 REG_FLD_MOD(DISPC_CONTROL2, 1, bit, bit);
484 REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit);
487 static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
489 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
492 static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
494 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
497 static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
499 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
502 static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
504 BUG_ON(plane == OMAP_DSS_GFX);
506 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
509 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
512 BUG_ON(plane == OMAP_DSS_GFX);
514 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
517 static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
519 BUG_ON(plane == OMAP_DSS_GFX);
521 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
524 static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
525 int fir_vinc, int five_taps,
526 enum omap_color_component color_comp)
528 const struct dispc_coef *h_coef, *v_coef;
531 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
532 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
534 for (i = 0; i < 8; i++) {
537 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
538 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
539 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
540 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
541 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
542 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
543 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
544 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
546 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
547 dispc_ovl_write_firh_reg(plane, i, h);
548 dispc_ovl_write_firhv_reg(plane, i, hv);
550 dispc_ovl_write_firh2_reg(plane, i, h);
551 dispc_ovl_write_firhv2_reg(plane, i, hv);
557 for (i = 0; i < 8; i++) {
559 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
560 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
561 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
562 dispc_ovl_write_firv_reg(plane, i, v);
564 dispc_ovl_write_firv2_reg(plane, i, v);
569 static void _dispc_setup_color_conv_coef(void)
572 const struct color_conv_coef {
573 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
576 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
579 const struct color_conv_coef *ct;
581 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
585 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
586 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 0),
587 CVAL(ct->rcr, ct->ry));
588 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 1),
589 CVAL(ct->gy, ct->rcb));
590 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 2),
591 CVAL(ct->gcb, ct->gcr));
592 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 3),
593 CVAL(ct->bcr, ct->by));
594 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 4),
597 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), ct->full_range,
605 static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
607 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
610 static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
612 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
615 static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
617 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
620 static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
622 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
625 static void dispc_ovl_set_pos(enum omap_plane plane, int x, int y)
627 u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
629 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
632 static void dispc_ovl_set_pic_size(enum omap_plane plane, int width, int height)
634 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
636 if (plane == OMAP_DSS_GFX)
637 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
639 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
642 static void dispc_ovl_set_vid_size(enum omap_plane plane, int width, int height)
646 BUG_ON(plane == OMAP_DSS_GFX);
648 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
650 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
653 static void dispc_ovl_set_zorder(enum omap_plane plane, u8 zorder)
655 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
657 if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
660 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
663 static void dispc_ovl_enable_zorder_planes(void)
667 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
670 for (i = 0; i < dss_feat_get_num_ovls(); i++)
671 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
674 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane, bool enable)
676 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
678 if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
681 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
684 static void dispc_ovl_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
686 static const unsigned shifts[] = { 0, 8, 16, 24, };
688 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
690 if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
693 shift = shifts[plane];
694 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
697 static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
699 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
702 static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
704 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
707 static void dispc_ovl_set_color_mode(enum omap_plane plane,
708 enum omap_color_mode color_mode)
711 if (plane != OMAP_DSS_GFX) {
712 switch (color_mode) {
713 case OMAP_DSS_COLOR_NV12:
715 case OMAP_DSS_COLOR_RGBX16:
717 case OMAP_DSS_COLOR_RGBA16:
719 case OMAP_DSS_COLOR_RGB12U:
721 case OMAP_DSS_COLOR_ARGB16:
723 case OMAP_DSS_COLOR_RGB16:
725 case OMAP_DSS_COLOR_ARGB16_1555:
727 case OMAP_DSS_COLOR_RGB24U:
729 case OMAP_DSS_COLOR_RGB24P:
731 case OMAP_DSS_COLOR_YUV2:
733 case OMAP_DSS_COLOR_UYVY:
735 case OMAP_DSS_COLOR_ARGB32:
737 case OMAP_DSS_COLOR_RGBA32:
739 case OMAP_DSS_COLOR_RGBX32:
741 case OMAP_DSS_COLOR_XRGB16_1555:
747 switch (color_mode) {
748 case OMAP_DSS_COLOR_CLUT1:
750 case OMAP_DSS_COLOR_CLUT2:
752 case OMAP_DSS_COLOR_CLUT4:
754 case OMAP_DSS_COLOR_CLUT8:
756 case OMAP_DSS_COLOR_RGB12U:
758 case OMAP_DSS_COLOR_ARGB16:
760 case OMAP_DSS_COLOR_RGB16:
762 case OMAP_DSS_COLOR_ARGB16_1555:
764 case OMAP_DSS_COLOR_RGB24U:
766 case OMAP_DSS_COLOR_RGB24P:
768 case OMAP_DSS_COLOR_RGBX16:
770 case OMAP_DSS_COLOR_RGBA16:
772 case OMAP_DSS_COLOR_ARGB32:
774 case OMAP_DSS_COLOR_RGBA32:
776 case OMAP_DSS_COLOR_RGBX32:
778 case OMAP_DSS_COLOR_XRGB16_1555:
785 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
788 static void dispc_ovl_configure_burst_type(enum omap_plane plane,
789 enum omap_dss_rotation_type rotation_type)
791 if (dss_has_feature(FEAT_BURST_2D) == 0)
794 if (rotation_type == OMAP_DSS_ROT_TILER)
795 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
797 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
800 void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
804 int chan = 0, chan2 = 0;
810 case OMAP_DSS_VIDEO1:
811 case OMAP_DSS_VIDEO2:
812 case OMAP_DSS_VIDEO3:
820 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
821 if (dss_has_feature(FEAT_MGR_LCD2)) {
823 case OMAP_DSS_CHANNEL_LCD:
827 case OMAP_DSS_CHANNEL_DIGIT:
831 case OMAP_DSS_CHANNEL_LCD2:
840 val = FLD_MOD(val, chan, shift, shift);
841 val = FLD_MOD(val, chan2, 31, 30);
843 val = FLD_MOD(val, channel, shift, shift);
845 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
848 static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
852 enum omap_channel channel;
858 case OMAP_DSS_VIDEO1:
859 case OMAP_DSS_VIDEO2:
860 case OMAP_DSS_VIDEO3:
868 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
870 if (dss_has_feature(FEAT_MGR_LCD2)) {
871 if (FLD_GET(val, 31, 30) == 0)
872 channel = FLD_GET(val, shift, shift);
874 channel = OMAP_DSS_CHANNEL_LCD2;
876 channel = FLD_GET(val, shift, shift);
882 static void dispc_ovl_set_burst_size(enum omap_plane plane,
883 enum omap_burst_size burst_size)
885 static const unsigned shifts[] = { 6, 14, 14, 14, };
888 shift = shifts[plane];
889 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
892 static void dispc_configure_burst_sizes(void)
895 const int burst_size = BURST_SIZE_X8;
897 /* Configure burst size always to maximum size */
898 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
899 dispc_ovl_set_burst_size(i, burst_size);
902 static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
904 unsigned unit = dss_feat_get_burst_size_unit();
905 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
909 void dispc_enable_gamma_table(bool enable)
912 * This is partially implemented to support only disabling of
916 DSSWARN("Gamma table enabling for TV not yet supported");
920 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
923 static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
927 if (channel == OMAP_DSS_CHANNEL_LCD)
929 else if (channel == OMAP_DSS_CHANNEL_LCD2)
934 REG_FLD_MOD(reg, enable, 15, 15);
937 static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
938 struct omap_dss_cpr_coefs *coefs)
940 u32 coef_r, coef_g, coef_b;
942 if (!dispc_mgr_is_lcd(channel))
945 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
946 FLD_VAL(coefs->rb, 9, 0);
947 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
948 FLD_VAL(coefs->gb, 9, 0);
949 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
950 FLD_VAL(coefs->bb, 9, 0);
952 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
953 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
954 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
957 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
961 BUG_ON(plane == OMAP_DSS_GFX);
963 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
964 val = FLD_MOD(val, enable, 9, 9);
965 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
968 static void dispc_ovl_enable_replication(enum omap_plane plane, bool enable)
970 static const unsigned shifts[] = { 5, 10, 10, 10 };
973 shift = shifts[plane];
974 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
977 static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
982 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
983 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
986 static void dispc_read_plane_fifo_sizes(void)
993 unit = dss_feat_get_buffer_size_unit();
995 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
997 for (plane = 0; plane < dss_feat_get_num_ovls(); ++plane) {
998 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(plane), start, end);
1000 dispc.fifo_size[plane] = size;
1004 static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1006 return dispc.fifo_size[plane];
1009 void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
1011 u8 hi_start, hi_end, lo_start, lo_end;
1014 unit = dss_feat_get_buffer_size_unit();
1016 WARN_ON(low % unit != 0);
1017 WARN_ON(high % unit != 0);
1022 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1023 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1025 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1027 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1028 lo_start, lo_end) * unit,
1029 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1030 hi_start, hi_end) * unit,
1031 low * unit, high * unit);
1033 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1034 FLD_VAL(high, hi_start, hi_end) |
1035 FLD_VAL(low, lo_start, lo_end));
1038 void dispc_enable_fifomerge(bool enable)
1040 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1045 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1046 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1049 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1050 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1054 * All sizes are in bytes. Both the buffer and burst are made of
1055 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1058 unsigned buf_unit = dss_feat_get_buffer_size_unit();
1059 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1062 burst_size = dispc_ovl_get_burst_size(plane);
1063 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
1065 if (use_fifomerge) {
1066 total_fifo_size = 0;
1067 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1068 total_fifo_size += dispc_ovl_get_fifo_size(i);
1070 total_fifo_size = ovl_fifo_size;
1074 * We use the same low threshold for both fifomerge and non-fifomerge
1075 * cases, but for fifomerge we calculate the high threshold using the
1076 * combined fifo size
1079 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1080 *fifo_low = ovl_fifo_size - burst_size * 2;
1081 *fifo_high = total_fifo_size - burst_size;
1083 *fifo_low = ovl_fifo_size - burst_size;
1084 *fifo_high = total_fifo_size - buf_unit;
1088 static void dispc_ovl_set_fir(enum omap_plane plane,
1090 enum omap_color_component color_comp)
1094 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1095 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1097 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1098 &hinc_start, &hinc_end);
1099 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1100 &vinc_start, &vinc_end);
1101 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1102 FLD_VAL(hinc, hinc_start, hinc_end);
1104 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1106 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1107 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1111 static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1114 u8 hor_start, hor_end, vert_start, vert_end;
1116 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1117 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1119 val = FLD_VAL(vaccu, vert_start, vert_end) |
1120 FLD_VAL(haccu, hor_start, hor_end);
1122 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1125 static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1128 u8 hor_start, hor_end, vert_start, vert_end;
1130 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1131 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1133 val = FLD_VAL(vaccu, vert_start, vert_end) |
1134 FLD_VAL(haccu, hor_start, hor_end);
1136 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1139 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1144 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1145 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1148 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1153 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1154 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1157 static void dispc_ovl_set_scale_param(enum omap_plane plane,
1158 u16 orig_width, u16 orig_height,
1159 u16 out_width, u16 out_height,
1160 bool five_taps, u8 rotation,
1161 enum omap_color_component color_comp)
1163 int fir_hinc, fir_vinc;
1165 fir_hinc = 1024 * orig_width / out_width;
1166 fir_vinc = 1024 * orig_height / out_height;
1168 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1170 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1173 static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1174 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1175 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1177 int h_accu2_0, h_accu2_1;
1178 int v_accu2_0, v_accu2_1;
1179 int chroma_hinc, chroma_vinc;
1189 const struct accu *accu_table;
1190 const struct accu *accu_val;
1192 static const struct accu accu_nv12[4] = {
1193 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1194 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1195 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1196 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1199 static const struct accu accu_nv12_ilace[4] = {
1200 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1201 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1202 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1203 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1206 static const struct accu accu_yuv[4] = {
1207 { 0, 1, 0, 1, 0, 1, 0, 1 },
1208 { 0, 1, 0, 1, 0, 1, 0, 1 },
1209 { -1, 1, 0, 1, 0, 1, 0, 1 },
1210 { 0, 1, 0, 1, -1, 1, 0, 1 },
1214 case OMAP_DSS_ROT_0:
1217 case OMAP_DSS_ROT_90:
1220 case OMAP_DSS_ROT_180:
1223 case OMAP_DSS_ROT_270:
1231 switch (color_mode) {
1232 case OMAP_DSS_COLOR_NV12:
1234 accu_table = accu_nv12_ilace;
1236 accu_table = accu_nv12;
1238 case OMAP_DSS_COLOR_YUV2:
1239 case OMAP_DSS_COLOR_UYVY:
1240 accu_table = accu_yuv;
1247 accu_val = &accu_table[idx];
1249 chroma_hinc = 1024 * orig_width / out_width;
1250 chroma_vinc = 1024 * orig_height / out_height;
1252 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1253 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1254 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1255 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1257 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1258 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1261 static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1262 u16 orig_width, u16 orig_height,
1263 u16 out_width, u16 out_height,
1264 bool ilace, bool five_taps,
1265 bool fieldmode, enum omap_color_mode color_mode,
1272 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1273 out_width, out_height, five_taps,
1274 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1275 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1277 /* RESIZEENABLE and VERTICALTAPS */
1278 l &= ~((0x3 << 5) | (0x1 << 21));
1279 l |= (orig_width != out_width) ? (1 << 5) : 0;
1280 l |= (orig_height != out_height) ? (1 << 6) : 0;
1281 l |= five_taps ? (1 << 21) : 0;
1283 /* VRESIZECONF and HRESIZECONF */
1284 if (dss_has_feature(FEAT_RESIZECONF)) {
1286 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1287 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1290 /* LINEBUFFERSPLIT */
1291 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1293 l |= five_taps ? (1 << 22) : 0;
1296 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1299 * field 0 = even field = bottom field
1300 * field 1 = odd field = top field
1302 if (ilace && !fieldmode) {
1304 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1305 if (accu0 >= 1024/2) {
1311 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1312 dispc_ovl_set_vid_accu1(plane, 0, accu1);
1315 static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1316 u16 orig_width, u16 orig_height,
1317 u16 out_width, u16 out_height,
1318 bool ilace, bool five_taps,
1319 bool fieldmode, enum omap_color_mode color_mode,
1322 int scale_x = out_width != orig_width;
1323 int scale_y = out_height != orig_height;
1325 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1327 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1328 color_mode != OMAP_DSS_COLOR_UYVY &&
1329 color_mode != OMAP_DSS_COLOR_NV12)) {
1330 /* reset chroma resampling for RGB formats */
1331 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1335 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1336 out_height, ilace, color_mode, rotation);
1338 switch (color_mode) {
1339 case OMAP_DSS_COLOR_NV12:
1340 /* UV is subsampled by 2 vertically*/
1342 /* UV is subsampled by 2 horz.*/
1345 case OMAP_DSS_COLOR_YUV2:
1346 case OMAP_DSS_COLOR_UYVY:
1347 /*For YUV422 with 90/270 rotation,
1348 *we don't upsample chroma
1350 if (rotation == OMAP_DSS_ROT_0 ||
1351 rotation == OMAP_DSS_ROT_180)
1352 /* UV is subsampled by 2 hrz*/
1354 /* must use FIR for YUV422 if rotated */
1355 if (rotation != OMAP_DSS_ROT_0)
1356 scale_x = scale_y = true;
1363 if (out_width != orig_width)
1365 if (out_height != orig_height)
1368 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1369 out_width, out_height, five_taps,
1370 rotation, DISPC_COLOR_COMPONENT_UV);
1372 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1373 (scale_x || scale_y) ? 1 : 0, 8, 8);
1375 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1377 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1380 static void dispc_ovl_set_scaling(enum omap_plane plane,
1381 u16 orig_width, u16 orig_height,
1382 u16 out_width, u16 out_height,
1383 bool ilace, bool five_taps,
1384 bool fieldmode, enum omap_color_mode color_mode,
1387 BUG_ON(plane == OMAP_DSS_GFX);
1389 dispc_ovl_set_scaling_common(plane,
1390 orig_width, orig_height,
1391 out_width, out_height,
1393 fieldmode, color_mode,
1396 dispc_ovl_set_scaling_uv(plane,
1397 orig_width, orig_height,
1398 out_width, out_height,
1400 fieldmode, color_mode,
1404 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1405 bool mirroring, enum omap_color_mode color_mode)
1407 bool row_repeat = false;
1410 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1411 color_mode == OMAP_DSS_COLOR_UYVY) {
1415 case OMAP_DSS_ROT_0:
1418 case OMAP_DSS_ROT_90:
1421 case OMAP_DSS_ROT_180:
1424 case OMAP_DSS_ROT_270:
1430 case OMAP_DSS_ROT_0:
1433 case OMAP_DSS_ROT_90:
1436 case OMAP_DSS_ROT_180:
1439 case OMAP_DSS_ROT_270:
1445 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1451 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1452 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1453 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1454 row_repeat ? 1 : 0, 18, 18);
1457 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1459 switch (color_mode) {
1460 case OMAP_DSS_COLOR_CLUT1:
1462 case OMAP_DSS_COLOR_CLUT2:
1464 case OMAP_DSS_COLOR_CLUT4:
1466 case OMAP_DSS_COLOR_CLUT8:
1467 case OMAP_DSS_COLOR_NV12:
1469 case OMAP_DSS_COLOR_RGB12U:
1470 case OMAP_DSS_COLOR_RGB16:
1471 case OMAP_DSS_COLOR_ARGB16:
1472 case OMAP_DSS_COLOR_YUV2:
1473 case OMAP_DSS_COLOR_UYVY:
1474 case OMAP_DSS_COLOR_RGBA16:
1475 case OMAP_DSS_COLOR_RGBX16:
1476 case OMAP_DSS_COLOR_ARGB16_1555:
1477 case OMAP_DSS_COLOR_XRGB16_1555:
1479 case OMAP_DSS_COLOR_RGB24P:
1481 case OMAP_DSS_COLOR_RGB24U:
1482 case OMAP_DSS_COLOR_ARGB32:
1483 case OMAP_DSS_COLOR_RGBA32:
1484 case OMAP_DSS_COLOR_RGBX32:
1492 static s32 pixinc(int pixels, u8 ps)
1496 else if (pixels > 1)
1497 return 1 + (pixels - 1) * ps;
1498 else if (pixels < 0)
1499 return 1 - (-pixels + 1) * ps;
1505 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1507 u16 width, u16 height,
1508 enum omap_color_mode color_mode, bool fieldmode,
1509 unsigned int field_offset,
1510 unsigned *offset0, unsigned *offset1,
1511 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1515 /* FIXME CLUT formats */
1516 switch (color_mode) {
1517 case OMAP_DSS_COLOR_CLUT1:
1518 case OMAP_DSS_COLOR_CLUT2:
1519 case OMAP_DSS_COLOR_CLUT4:
1520 case OMAP_DSS_COLOR_CLUT8:
1523 case OMAP_DSS_COLOR_YUV2:
1524 case OMAP_DSS_COLOR_UYVY:
1528 ps = color_mode_to_bpp(color_mode) / 8;
1532 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1536 * field 0 = even field = bottom field
1537 * field 1 = odd field = top field
1539 switch (rotation + mirror * 4) {
1540 case OMAP_DSS_ROT_0:
1541 case OMAP_DSS_ROT_180:
1543 * If the pixel format is YUV or UYVY divide the width
1544 * of the image by 2 for 0 and 180 degree rotation.
1546 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1547 color_mode == OMAP_DSS_COLOR_UYVY)
1549 case OMAP_DSS_ROT_90:
1550 case OMAP_DSS_ROT_270:
1553 *offset0 = field_offset * screen_width * ps;
1557 *row_inc = pixinc(1 +
1558 (y_predecim * screen_width - x_predecim * width) +
1559 (fieldmode ? screen_width : 0), ps);
1560 *pix_inc = pixinc(x_predecim, ps);
1563 case OMAP_DSS_ROT_0 + 4:
1564 case OMAP_DSS_ROT_180 + 4:
1565 /* If the pixel format is YUV or UYVY divide the width
1566 * of the image by 2 for 0 degree and 180 degree
1568 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1569 color_mode == OMAP_DSS_COLOR_UYVY)
1571 case OMAP_DSS_ROT_90 + 4:
1572 case OMAP_DSS_ROT_270 + 4:
1575 *offset0 = field_offset * screen_width * ps;
1578 *row_inc = pixinc(1 -
1579 (y_predecim * screen_width + x_predecim * width) -
1580 (fieldmode ? screen_width : 0), ps);
1581 *pix_inc = pixinc(x_predecim, ps);
1590 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1592 u16 width, u16 height,
1593 enum omap_color_mode color_mode, bool fieldmode,
1594 unsigned int field_offset,
1595 unsigned *offset0, unsigned *offset1,
1596 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1601 /* FIXME CLUT formats */
1602 switch (color_mode) {
1603 case OMAP_DSS_COLOR_CLUT1:
1604 case OMAP_DSS_COLOR_CLUT2:
1605 case OMAP_DSS_COLOR_CLUT4:
1606 case OMAP_DSS_COLOR_CLUT8:
1610 ps = color_mode_to_bpp(color_mode) / 8;
1614 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1617 /* width & height are overlay sizes, convert to fb sizes */
1619 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1628 * field 0 = even field = bottom field
1629 * field 1 = odd field = top field
1631 switch (rotation + mirror * 4) {
1632 case OMAP_DSS_ROT_0:
1635 *offset0 = *offset1 + field_offset * screen_width * ps;
1637 *offset0 = *offset1;
1638 *row_inc = pixinc(1 +
1639 (y_predecim * screen_width - fbw * x_predecim) +
1640 (fieldmode ? screen_width : 0), ps);
1641 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1642 color_mode == OMAP_DSS_COLOR_UYVY)
1643 *pix_inc = pixinc(x_predecim, 2 * ps);
1645 *pix_inc = pixinc(x_predecim, ps);
1647 case OMAP_DSS_ROT_90:
1648 *offset1 = screen_width * (fbh - 1) * ps;
1650 *offset0 = *offset1 + field_offset * ps;
1652 *offset0 = *offset1;
1653 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1654 y_predecim + (fieldmode ? 1 : 0), ps);
1655 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1657 case OMAP_DSS_ROT_180:
1658 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1660 *offset0 = *offset1 - field_offset * screen_width * ps;
1662 *offset0 = *offset1;
1663 *row_inc = pixinc(-1 -
1664 (y_predecim * screen_width - fbw * x_predecim) -
1665 (fieldmode ? screen_width : 0), ps);
1666 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1667 color_mode == OMAP_DSS_COLOR_UYVY)
1668 *pix_inc = pixinc(-x_predecim, 2 * ps);
1670 *pix_inc = pixinc(-x_predecim, ps);
1672 case OMAP_DSS_ROT_270:
1673 *offset1 = (fbw - 1) * ps;
1675 *offset0 = *offset1 - field_offset * ps;
1677 *offset0 = *offset1;
1678 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1679 y_predecim - (fieldmode ? 1 : 0), ps);
1680 *pix_inc = pixinc(x_predecim * screen_width, ps);
1684 case OMAP_DSS_ROT_0 + 4:
1685 *offset1 = (fbw - 1) * ps;
1687 *offset0 = *offset1 + field_offset * screen_width * ps;
1689 *offset0 = *offset1;
1690 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
1691 (fieldmode ? screen_width : 0),
1693 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1694 color_mode == OMAP_DSS_COLOR_UYVY)
1695 *pix_inc = pixinc(-x_predecim, 2 * ps);
1697 *pix_inc = pixinc(-x_predecim, ps);
1700 case OMAP_DSS_ROT_90 + 4:
1703 *offset0 = *offset1 + field_offset * ps;
1705 *offset0 = *offset1;
1706 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1707 y_predecim + (fieldmode ? 1 : 0),
1709 *pix_inc = pixinc(x_predecim * screen_width, ps);
1712 case OMAP_DSS_ROT_180 + 4:
1713 *offset1 = screen_width * (fbh - 1) * ps;
1715 *offset0 = *offset1 - field_offset * screen_width * ps;
1717 *offset0 = *offset1;
1718 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
1719 (fieldmode ? screen_width : 0),
1721 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1722 color_mode == OMAP_DSS_COLOR_UYVY)
1723 *pix_inc = pixinc(x_predecim, 2 * ps);
1725 *pix_inc = pixinc(x_predecim, ps);
1728 case OMAP_DSS_ROT_270 + 4:
1729 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1731 *offset0 = *offset1 - field_offset * ps;
1733 *offset0 = *offset1;
1734 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1735 y_predecim - (fieldmode ? 1 : 0),
1737 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1746 static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1747 enum omap_color_mode color_mode, bool fieldmode,
1748 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1749 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1753 switch (color_mode) {
1754 case OMAP_DSS_COLOR_CLUT1:
1755 case OMAP_DSS_COLOR_CLUT2:
1756 case OMAP_DSS_COLOR_CLUT4:
1757 case OMAP_DSS_COLOR_CLUT8:
1761 ps = color_mode_to_bpp(color_mode) / 8;
1765 DSSDBG("scrw %d, width %d\n", screen_width, width);
1768 * field 0 = even field = bottom field
1769 * field 1 = odd field = top field
1773 *offset0 = *offset1 + field_offset * screen_width * ps;
1775 *offset0 = *offset1;
1776 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1777 (fieldmode ? screen_width : 0), ps);
1778 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1779 color_mode == OMAP_DSS_COLOR_UYVY)
1780 *pix_inc = pixinc(x_predecim, 2 * ps);
1782 *pix_inc = pixinc(x_predecim, ps);
1786 * This function is used to avoid synclosts in OMAP3, because of some
1787 * undocumented horizontal position and timing related limitations.
1789 static int check_horiz_timing_omap3(enum omap_channel channel,
1790 const struct omap_video_timings *t, u16 pos_x,
1791 u16 width, u16 height, u16 out_width, u16 out_height)
1793 int DS = DIV_ROUND_UP(height, out_height);
1794 unsigned long nonactive, lclk, pclk;
1795 static const u8 limits[3] = { 8, 10, 20 };
1799 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
1800 pclk = dispc_mgr_pclk_rate(channel);
1801 if (dispc_mgr_is_lcd(channel))
1802 lclk = dispc_mgr_lclk_rate(channel);
1804 lclk = dispc_fclk_rate();
1807 if (out_height < height)
1809 if (out_width < width)
1811 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
1812 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
1813 if (blank <= limits[i])
1817 * Pixel data should be prepared before visible display point starts.
1818 * So, atleast DS-2 lines must have already been fetched by DISPC
1819 * during nonactive - pos_x period.
1821 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
1822 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
1823 val, max(0, DS - 2) * width);
1824 if (val < max(0, DS - 2) * width)
1828 * All lines need to be refilled during the nonactive period of which
1829 * only one line can be loaded during the active period. So, atleast
1830 * DS - 1 lines should be loaded during nonactive period.
1832 val = div_u64((u64)nonactive * lclk, pclk);
1833 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
1834 val, max(0, DS - 1) * width);
1835 if (val < max(0, DS - 1) * width)
1841 static unsigned long calc_core_clk_five_taps(enum omap_channel channel,
1842 const struct omap_video_timings *mgr_timings, u16 width,
1843 u16 height, u16 out_width, u16 out_height,
1844 enum omap_color_mode color_mode)
1847 u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
1849 if (height <= out_height && width <= out_width)
1850 return (unsigned long) pclk;
1852 if (height > out_height) {
1853 unsigned int ppl = mgr_timings->x_res;
1855 tmp = pclk * height * out_width;
1856 do_div(tmp, 2 * out_height * ppl);
1859 if (height > 2 * out_height) {
1860 if (ppl == out_width)
1863 tmp = pclk * (height - 2 * out_height) * out_width;
1864 do_div(tmp, 2 * out_height * (ppl - out_width));
1865 core_clk = max_t(u32, core_clk, tmp);
1869 if (width > out_width) {
1871 do_div(tmp, out_width);
1872 core_clk = max_t(u32, core_clk, tmp);
1874 if (color_mode == OMAP_DSS_COLOR_RGB24U)
1881 static unsigned long calc_core_clk(enum omap_channel channel, u16 width,
1882 u16 height, u16 out_width, u16 out_height)
1884 unsigned int hf, vf;
1885 unsigned long pclk = dispc_mgr_pclk_rate(channel);
1888 * FIXME how to determine the 'A' factor
1889 * for the no downscaling case ?
1892 if (width > 3 * out_width)
1894 else if (width > 2 * out_width)
1896 else if (width > out_width)
1901 if (height > out_height)
1906 if (cpu_is_omap24xx()) {
1907 if (vf > 1 && hf > 1)
1911 } else if (cpu_is_omap34xx()) {
1912 return pclk * vf * hf;
1915 return DIV_ROUND_UP(pclk, out_width) * width;
1921 static int dispc_ovl_calc_scaling(enum omap_plane plane,
1922 enum omap_channel channel,
1923 const struct omap_video_timings *mgr_timings,
1924 u16 width, u16 height, u16 out_width, u16 out_height,
1925 enum omap_color_mode color_mode, bool *five_taps,
1926 int *x_predecim, int *y_predecim, u16 pos_x)
1928 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
1929 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
1930 const int maxsinglelinewidth =
1931 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
1932 const int max_decim_limit = 16;
1933 unsigned long core_clk = 0;
1934 int decim_x, decim_y, error, min_factor;
1935 u16 in_width, in_height, in_width_max = 0;
1937 if (width == out_width && height == out_height)
1940 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
1943 *x_predecim = max_decim_limit;
1944 *y_predecim = max_decim_limit;
1946 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
1947 color_mode == OMAP_DSS_COLOR_CLUT2 ||
1948 color_mode == OMAP_DSS_COLOR_CLUT4 ||
1949 color_mode == OMAP_DSS_COLOR_CLUT8) {
1956 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
1957 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
1959 min_factor = min(decim_x, decim_y);
1961 if (decim_x > *x_predecim || out_width > width * 8)
1964 if (decim_y > *y_predecim || out_height > height * 8)
1967 if (cpu_is_omap24xx()) {
1971 in_height = DIV_ROUND_UP(height, decim_y);
1972 in_width = DIV_ROUND_UP(width, decim_x);
1973 core_clk = calc_core_clk(channel, in_width, in_height,
1974 out_width, out_height);
1975 error = (in_width > maxsinglelinewidth || !core_clk ||
1976 core_clk > dispc_core_clk_rate());
1978 if (decim_x == decim_y) {
1979 decim_x = min_factor;
1982 swap(decim_x, decim_y);
1983 if (decim_x < decim_y)
1987 } while (decim_x <= *x_predecim && decim_y <= *y_predecim &&
1990 if (in_width > maxsinglelinewidth) {
1991 DSSERR("Cannot scale max input width exceeded");
1994 } else if (cpu_is_omap34xx()) {
1997 in_height = DIV_ROUND_UP(height, decim_y);
1998 in_width = DIV_ROUND_UP(width, decim_x);
1999 core_clk = calc_core_clk_five_taps(channel, mgr_timings,
2000 in_width, in_height, out_width, out_height,
2003 error = check_horiz_timing_omap3(channel, mgr_timings,
2004 pos_x, in_width, in_height, out_width,
2007 if (in_width > maxsinglelinewidth)
2008 if (in_height > out_height &&
2009 in_height < out_height * 2)
2012 core_clk = calc_core_clk(channel, in_width,
2013 in_height, out_width, out_height);
2014 error = (error || in_width > maxsinglelinewidth * 2 ||
2015 (in_width > maxsinglelinewidth && *five_taps) ||
2016 !core_clk || core_clk > dispc_core_clk_rate());
2018 if (decim_x == decim_y) {
2019 decim_x = min_factor;
2022 swap(decim_x, decim_y);
2023 if (decim_x < decim_y)
2027 } while (decim_x <= *x_predecim && decim_y <= *y_predecim
2030 if (check_horiz_timing_omap3(channel, mgr_timings, pos_x, width,
2031 height, out_width, out_height)){
2032 DSSERR("horizontal timing too tight\n");
2036 if (in_width > (maxsinglelinewidth * 2)) {
2037 DSSERR("Cannot setup scaling");
2038 DSSERR("width exceeds maximum width possible");
2042 if (in_width > maxsinglelinewidth && *five_taps) {
2043 DSSERR("cannot setup scaling with five taps");
2047 int decim_x_min = decim_x;
2048 in_height = DIV_ROUND_UP(height, decim_y);
2049 in_width_max = dispc_core_clk_rate() /
2050 DIV_ROUND_UP(dispc_mgr_pclk_rate(channel),
2052 decim_x = DIV_ROUND_UP(width, in_width_max);
2054 decim_x = decim_x > decim_x_min ? decim_x : decim_x_min;
2055 if (decim_x > *x_predecim)
2059 in_width = DIV_ROUND_UP(width, decim_x);
2060 } while (decim_x <= *x_predecim &&
2061 in_width > maxsinglelinewidth && decim_x++);
2063 if (in_width > maxsinglelinewidth) {
2064 DSSERR("Cannot scale width exceeds max line width");
2068 core_clk = calc_core_clk(channel, in_width, in_height,
2069 out_width, out_height);
2072 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2073 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
2075 if (!core_clk || core_clk > dispc_core_clk_rate()) {
2076 DSSERR("failed to set up scaling, "
2077 "required core clk rate = %lu Hz, "
2078 "current core clk rate = %lu Hz\n",
2079 core_clk, dispc_core_clk_rate());
2083 *x_predecim = decim_x;
2084 *y_predecim = decim_y;
2088 int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
2089 bool ilace, bool replication,
2090 const struct omap_video_timings *mgr_timings)
2092 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
2093 bool five_taps = true;
2096 unsigned offset0, offset1;
2099 u16 frame_height = oi->height;
2100 unsigned int field_offset = 0;
2101 u16 in_height = oi->height;
2102 u16 in_width = oi->width;
2103 u16 out_width, out_height;
2104 enum omap_channel channel;
2105 int x_predecim = 1, y_predecim = 1;
2107 channel = dispc_ovl_get_channel_out(plane);
2109 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
2110 "%dx%d, cmode %x, rot %d, mir %d, ilace %d chan %d repl %d\n",
2111 plane, oi->paddr, oi->p_uv_addr,
2112 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2113 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2114 oi->mirror, ilace, channel, replication);
2119 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2120 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2122 if (ilace && oi->height == out_height)
2131 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2133 in_height, oi->pos_y, out_height);
2136 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2139 r = dispc_ovl_calc_scaling(plane, channel, mgr_timings, in_width,
2140 in_height, out_width, out_height, oi->color_mode,
2141 &five_taps, &x_predecim, &y_predecim, oi->pos_x);
2145 in_width = DIV_ROUND_UP(in_width, x_predecim);
2146 in_height = DIV_ROUND_UP(in_height, y_predecim);
2148 if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
2149 oi->color_mode == OMAP_DSS_COLOR_UYVY ||
2150 oi->color_mode == OMAP_DSS_COLOR_NV12)
2153 if (ilace && !fieldmode) {
2155 * when downscaling the bottom field may have to start several
2156 * source lines below the top field. Unfortunately ACCUI
2157 * registers will only hold the fractional part of the offset
2158 * so the integer part must be added to the base address of the
2161 if (!in_height || in_height == out_height)
2164 field_offset = in_height / out_height / 2;
2167 /* Fields are independent but interleaved in memory. */
2176 if (oi->rotation_type == OMAP_DSS_ROT_TILER)
2177 calc_tiler_rotation_offset(oi->screen_width, in_width,
2178 oi->color_mode, fieldmode, field_offset,
2179 &offset0, &offset1, &row_inc, &pix_inc,
2180 x_predecim, y_predecim);
2181 else if (oi->rotation_type == OMAP_DSS_ROT_DMA)
2182 calc_dma_rotation_offset(oi->rotation, oi->mirror,
2183 oi->screen_width, in_width, frame_height,
2184 oi->color_mode, fieldmode, field_offset,
2185 &offset0, &offset1, &row_inc, &pix_inc,
2186 x_predecim, y_predecim);
2188 calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
2189 oi->screen_width, in_width, frame_height,
2190 oi->color_mode, fieldmode, field_offset,
2191 &offset0, &offset1, &row_inc, &pix_inc,
2192 x_predecim, y_predecim);
2194 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2195 offset0, offset1, row_inc, pix_inc);
2197 dispc_ovl_set_color_mode(plane, oi->color_mode);
2199 dispc_ovl_configure_burst_type(plane, oi->rotation_type);
2201 dispc_ovl_set_ba0(plane, oi->paddr + offset0);
2202 dispc_ovl_set_ba1(plane, oi->paddr + offset1);
2204 if (OMAP_DSS_COLOR_NV12 == oi->color_mode) {
2205 dispc_ovl_set_ba0_uv(plane, oi->p_uv_addr + offset0);
2206 dispc_ovl_set_ba1_uv(plane, oi->p_uv_addr + offset1);
2210 dispc_ovl_set_row_inc(plane, row_inc);
2211 dispc_ovl_set_pix_inc(plane, pix_inc);
2213 DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, in_width,
2214 in_height, out_width, out_height);
2216 dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y);
2218 dispc_ovl_set_pic_size(plane, in_width, in_height);
2220 if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) {
2221 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2222 out_height, ilace, five_taps, fieldmode,
2223 oi->color_mode, oi->rotation);
2224 dispc_ovl_set_vid_size(plane, out_width, out_height);
2225 dispc_ovl_set_vid_color_conv(plane, cconv);
2228 dispc_ovl_set_rotation_attrs(plane, oi->rotation, oi->mirror,
2231 dispc_ovl_set_zorder(plane, oi->zorder);
2232 dispc_ovl_set_pre_mult_alpha(plane, oi->pre_mult_alpha);
2233 dispc_ovl_setup_global_alpha(plane, oi->global_alpha);
2235 dispc_ovl_enable_replication(plane, replication);
2240 int dispc_ovl_enable(enum omap_plane plane, bool enable)
2242 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2244 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2249 static void dispc_disable_isr(void *data, u32 mask)
2251 struct completion *compl = data;
2255 static void _enable_lcd_out(enum omap_channel channel, bool enable)
2257 if (channel == OMAP_DSS_CHANNEL_LCD2) {
2258 REG_FLD_MOD(DISPC_CONTROL2, enable ? 1 : 0, 0, 0);
2259 /* flush posted write */
2260 dispc_read_reg(DISPC_CONTROL2);
2262 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0);
2263 dispc_read_reg(DISPC_CONTROL);
2267 static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
2269 struct completion frame_done_completion;
2274 /* When we disable LCD output, we need to wait until frame is done.
2275 * Otherwise the DSS is still working, and turning off the clocks
2276 * prevents DSS from going to OFF mode */
2277 is_on = channel == OMAP_DSS_CHANNEL_LCD2 ?
2278 REG_GET(DISPC_CONTROL2, 0, 0) :
2279 REG_GET(DISPC_CONTROL, 0, 0);
2281 irq = channel == OMAP_DSS_CHANNEL_LCD2 ? DISPC_IRQ_FRAMEDONE2 :
2282 DISPC_IRQ_FRAMEDONE;
2284 if (!enable && is_on) {
2285 init_completion(&frame_done_completion);
2287 r = omap_dispc_register_isr(dispc_disable_isr,
2288 &frame_done_completion, irq);
2291 DSSERR("failed to register FRAMEDONE isr\n");
2294 _enable_lcd_out(channel, enable);
2296 if (!enable && is_on) {
2297 if (!wait_for_completion_timeout(&frame_done_completion,
2298 msecs_to_jiffies(100)))
2299 DSSERR("timeout waiting for FRAME DONE\n");
2301 r = omap_dispc_unregister_isr(dispc_disable_isr,
2302 &frame_done_completion, irq);
2305 DSSERR("failed to unregister FRAMEDONE isr\n");
2309 static void _enable_digit_out(bool enable)
2311 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
2312 /* flush posted write */
2313 dispc_read_reg(DISPC_CONTROL);
2316 static void dispc_mgr_enable_digit_out(bool enable)
2318 struct completion frame_done_completion;
2319 enum dss_hdmi_venc_clk_source_select src;
2324 if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
2327 src = dss_get_hdmi_venc_clk_source();
2330 unsigned long flags;
2331 /* When we enable digit output, we'll get an extra digit
2332 * sync lost interrupt, that we need to ignore */
2333 spin_lock_irqsave(&dispc.irq_lock, flags);
2334 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
2335 _omap_dispc_set_irqs();
2336 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2339 /* When we disable digit output, we need to wait until fields are done.
2340 * Otherwise the DSS is still working, and turning off the clocks
2341 * prevents DSS from going to OFF mode. And when enabling, we need to
2342 * wait for the extra sync losts */
2343 init_completion(&frame_done_completion);
2345 if (src == DSS_HDMI_M_PCLK && enable == false) {
2346 irq_mask = DISPC_IRQ_FRAMEDONETV;
2349 irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
2350 /* XXX I understand from TRM that we should only wait for the
2351 * current field to complete. But it seems we have to wait for
2356 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
2359 DSSERR("failed to register %x isr\n", irq_mask);
2361 _enable_digit_out(enable);
2363 for (i = 0; i < num_irqs; ++i) {
2364 if (!wait_for_completion_timeout(&frame_done_completion,
2365 msecs_to_jiffies(100)))
2366 DSSERR("timeout waiting for digit out to %s\n",
2367 enable ? "start" : "stop");
2370 r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
2373 DSSERR("failed to unregister %x isr\n", irq_mask);
2376 unsigned long flags;
2377 spin_lock_irqsave(&dispc.irq_lock, flags);
2378 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
2379 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
2380 _omap_dispc_set_irqs();
2381 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2385 bool dispc_mgr_is_enabled(enum omap_channel channel)
2387 if (channel == OMAP_DSS_CHANNEL_LCD)
2388 return !!REG_GET(DISPC_CONTROL, 0, 0);
2389 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2390 return !!REG_GET(DISPC_CONTROL, 1, 1);
2391 else if (channel == OMAP_DSS_CHANNEL_LCD2)
2392 return !!REG_GET(DISPC_CONTROL2, 0, 0);
2399 void dispc_mgr_enable(enum omap_channel channel, bool enable)
2401 if (dispc_mgr_is_lcd(channel))
2402 dispc_mgr_enable_lcd_out(channel, enable);
2403 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2404 dispc_mgr_enable_digit_out(enable);
2409 void dispc_lcd_enable_signal_polarity(bool act_high)
2411 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2414 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2417 void dispc_lcd_enable_signal(bool enable)
2419 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2422 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2425 void dispc_pck_free_enable(bool enable)
2427 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2430 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2433 void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2435 if (channel == OMAP_DSS_CHANNEL_LCD2)
2436 REG_FLD_MOD(DISPC_CONFIG2, enable ? 1 : 0, 16, 16);
2438 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16);
2442 void dispc_mgr_set_lcd_display_type(enum omap_channel channel,
2443 enum omap_lcd_display_type type)
2448 case OMAP_DSS_LCD_DISPLAY_STN:
2452 case OMAP_DSS_LCD_DISPLAY_TFT:
2461 if (channel == OMAP_DSS_CHANNEL_LCD2)
2462 REG_FLD_MOD(DISPC_CONTROL2, mode, 3, 3);
2464 REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3);
2467 void dispc_set_loadmode(enum omap_dss_load_mode mode)
2469 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2473 static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2475 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2478 static void dispc_mgr_set_trans_key(enum omap_channel ch,
2479 enum omap_dss_trans_key_type type,
2482 if (ch == OMAP_DSS_CHANNEL_LCD)
2483 REG_FLD_MOD(DISPC_CONFIG, type, 11, 11);
2484 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2485 REG_FLD_MOD(DISPC_CONFIG, type, 13, 13);
2486 else /* OMAP_DSS_CHANNEL_LCD2 */
2487 REG_FLD_MOD(DISPC_CONFIG2, type, 11, 11);
2489 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2492 static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2494 if (ch == OMAP_DSS_CHANNEL_LCD)
2495 REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10);
2496 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2497 REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12);
2498 else /* OMAP_DSS_CHANNEL_LCD2 */
2499 REG_FLD_MOD(DISPC_CONFIG2, enable, 10, 10);
2502 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2505 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
2508 if (ch == OMAP_DSS_CHANNEL_LCD)
2509 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2510 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2511 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2514 void dispc_mgr_setup(enum omap_channel channel,
2515 struct omap_overlay_manager_info *info)
2517 dispc_mgr_set_default_color(channel, info->default_color);
2518 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2519 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2520 dispc_mgr_enable_alpha_fixed_zorder(channel,
2521 info->partial_alpha_enabled);
2522 if (dss_has_feature(FEAT_CPR)) {
2523 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2524 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2528 void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2532 switch (data_lines) {
2550 if (channel == OMAP_DSS_CHANNEL_LCD2)
2551 REG_FLD_MOD(DISPC_CONTROL2, code, 9, 8);
2553 REG_FLD_MOD(DISPC_CONTROL, code, 9, 8);
2556 void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
2562 case DSS_IO_PAD_MODE_RESET:
2566 case DSS_IO_PAD_MODE_RFBI:
2570 case DSS_IO_PAD_MODE_BYPASS:
2579 l = dispc_read_reg(DISPC_CONTROL);
2580 l = FLD_MOD(l, gpout0, 15, 15);
2581 l = FLD_MOD(l, gpout1, 16, 16);
2582 dispc_write_reg(DISPC_CONTROL, l);
2585 void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2587 if (channel == OMAP_DSS_CHANNEL_LCD2)
2588 REG_FLD_MOD(DISPC_CONTROL2, enable, 11, 11);
2590 REG_FLD_MOD(DISPC_CONTROL, enable, 11, 11);
2593 static bool _dispc_mgr_size_ok(u16 width, u16 height)
2595 return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
2596 height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
2599 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2600 int vsw, int vfp, int vbp)
2602 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2603 if (hsw < 1 || hsw > 64 ||
2604 hfp < 1 || hfp > 256 ||
2605 hbp < 1 || hbp > 256 ||
2606 vsw < 1 || vsw > 64 ||
2607 vfp < 0 || vfp > 255 ||
2608 vbp < 0 || vbp > 255)
2611 if (hsw < 1 || hsw > 256 ||
2612 hfp < 1 || hfp > 4096 ||
2613 hbp < 1 || hbp > 4096 ||
2614 vsw < 1 || vsw > 256 ||
2615 vfp < 0 || vfp > 4095 ||
2616 vbp < 0 || vbp > 4095)
2623 bool dispc_mgr_timings_ok(enum omap_channel channel,
2624 const struct omap_video_timings *timings)
2628 timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
2630 if (dispc_mgr_is_lcd(channel))
2631 timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
2632 timings->hfp, timings->hbp,
2633 timings->vsw, timings->vfp,
2639 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
2640 int hfp, int hbp, int vsw, int vfp, int vbp)
2642 u32 timing_h, timing_v;
2644 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2645 timing_h = FLD_VAL(hsw-1, 5, 0) | FLD_VAL(hfp-1, 15, 8) |
2646 FLD_VAL(hbp-1, 27, 20);
2648 timing_v = FLD_VAL(vsw-1, 5, 0) | FLD_VAL(vfp, 15, 8) |
2649 FLD_VAL(vbp, 27, 20);
2651 timing_h = FLD_VAL(hsw-1, 7, 0) | FLD_VAL(hfp-1, 19, 8) |
2652 FLD_VAL(hbp-1, 31, 20);
2654 timing_v = FLD_VAL(vsw-1, 7, 0) | FLD_VAL(vfp, 19, 8) |
2655 FLD_VAL(vbp, 31, 20);
2658 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2659 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
2662 /* change name to mode? */
2663 void dispc_mgr_set_timings(enum omap_channel channel,
2664 struct omap_video_timings *timings)
2666 unsigned xtot, ytot;
2667 unsigned long ht, vt;
2668 struct omap_video_timings t = *timings;
2670 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
2672 if (!dispc_mgr_timings_ok(channel, &t)) {
2677 if (dispc_mgr_is_lcd(channel)) {
2678 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
2681 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
2682 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
2684 ht = (timings->pixel_clock * 1000) / xtot;
2685 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2687 DSSDBG("pck %u\n", timings->pixel_clock);
2688 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2689 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
2691 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2693 enum dss_hdmi_venc_clk_source_select source;
2695 source = dss_get_hdmi_venc_clk_source();
2697 if (source == DSS_VENC_TV_CLK)
2701 dispc_mgr_set_size(channel, t.x_res, t.y_res);
2704 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
2707 BUG_ON(lck_div < 1);
2708 BUG_ON(pck_div < 1);
2710 dispc_write_reg(DISPC_DIVISORo(channel),
2711 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
2714 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
2718 l = dispc_read_reg(DISPC_DIVISORo(channel));
2719 *lck_div = FLD_GET(l, 23, 16);
2720 *pck_div = FLD_GET(l, 7, 0);
2723 unsigned long dispc_fclk_rate(void)
2725 struct platform_device *dsidev;
2726 unsigned long r = 0;
2728 switch (dss_get_dispc_clk_source()) {
2729 case OMAP_DSS_CLK_SRC_FCK:
2730 r = clk_get_rate(dispc.dss_clk);
2732 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2733 dsidev = dsi_get_dsidev_from_id(0);
2734 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2736 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2737 dsidev = dsi_get_dsidev_from_id(1);
2738 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2748 unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
2750 struct platform_device *dsidev;
2755 l = dispc_read_reg(DISPC_DIVISORo(channel));
2757 lcd = FLD_GET(l, 23, 16);
2759 switch (dss_get_lcd_clk_source(channel)) {
2760 case OMAP_DSS_CLK_SRC_FCK:
2761 r = clk_get_rate(dispc.dss_clk);
2763 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2764 dsidev = dsi_get_dsidev_from_id(0);
2765 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2767 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2768 dsidev = dsi_get_dsidev_from_id(1);
2769 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2779 unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
2783 if (dispc_mgr_is_lcd(channel)) {
2787 l = dispc_read_reg(DISPC_DIVISORo(channel));
2789 pcd = FLD_GET(l, 7, 0);
2791 r = dispc_mgr_lclk_rate(channel);
2795 enum dss_hdmi_venc_clk_source_select source;
2797 source = dss_get_hdmi_venc_clk_source();
2800 case DSS_VENC_TV_CLK:
2801 return venc_get_pixel_clock();
2802 case DSS_HDMI_M_PCLK:
2803 return hdmi_get_pixel_clock();
2811 unsigned long dispc_core_clk_rate(void)
2814 unsigned long fclk = dispc_fclk_rate();
2816 if (dss_has_feature(FEAT_CORE_CLK_DIV))
2817 lcd = REG_GET(DISPC_DIVISOR, 23, 16);
2819 lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
2824 void dispc_dump_clocks(struct seq_file *s)
2828 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
2829 enum omap_dss_clk_source lcd_clk_src;
2831 if (dispc_runtime_get())
2834 seq_printf(s, "- DISPC -\n");
2836 seq_printf(s, "dispc fclk source = %s (%s)\n",
2837 dss_get_generic_clk_source_name(dispc_clk_src),
2838 dss_feat_get_clk_source_name(dispc_clk_src));
2840 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
2842 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
2843 seq_printf(s, "- DISPC-CORE-CLK -\n");
2844 l = dispc_read_reg(DISPC_DIVISOR);
2845 lcd = FLD_GET(l, 23, 16);
2847 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2848 (dispc_fclk_rate()/lcd), lcd);
2850 seq_printf(s, "- LCD1 -\n");
2852 lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD);
2854 seq_printf(s, "lcd1_clk source = %s (%s)\n",
2855 dss_get_generic_clk_source_name(lcd_clk_src),
2856 dss_feat_get_clk_source_name(lcd_clk_src));
2858 dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd);
2860 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2861 dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd);
2862 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2863 dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd);
2864 if (dss_has_feature(FEAT_MGR_LCD2)) {
2865 seq_printf(s, "- LCD2 -\n");
2867 lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD2);
2869 seq_printf(s, "lcd2_clk source = %s (%s)\n",
2870 dss_get_generic_clk_source_name(lcd_clk_src),
2871 dss_feat_get_clk_source_name(lcd_clk_src));
2873 dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd);
2875 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2876 dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd);
2877 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2878 dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd);
2881 dispc_runtime_put();
2884 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
2885 void dispc_dump_irqs(struct seq_file *s)
2887 unsigned long flags;
2888 struct dispc_irq_stats stats;
2890 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
2892 stats = dispc.irq_stats;
2893 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
2894 dispc.irq_stats.last_reset = jiffies;
2896 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
2898 seq_printf(s, "period %u ms\n",
2899 jiffies_to_msecs(jiffies - stats.last_reset));
2901 seq_printf(s, "irqs %d\n", stats.irq_count);
2903 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
2909 PIS(ACBIAS_COUNT_STAT);
2911 PIS(GFX_FIFO_UNDERFLOW);
2913 PIS(PAL_GAMMA_MASK);
2915 PIS(VID1_FIFO_UNDERFLOW);
2917 PIS(VID2_FIFO_UNDERFLOW);
2919 if (dss_feat_get_num_ovls() > 3) {
2920 PIS(VID3_FIFO_UNDERFLOW);
2924 PIS(SYNC_LOST_DIGIT);
2926 if (dss_has_feature(FEAT_MGR_LCD2)) {
2929 PIS(ACBIAS_COUNT_STAT2);
2936 static void dispc_dump_regs(struct seq_file *s)
2939 const char *mgr_names[] = {
2940 [OMAP_DSS_CHANNEL_LCD] = "LCD",
2941 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
2942 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
2944 const char *ovl_names[] = {
2945 [OMAP_DSS_GFX] = "GFX",
2946 [OMAP_DSS_VIDEO1] = "VID1",
2947 [OMAP_DSS_VIDEO2] = "VID2",
2948 [OMAP_DSS_VIDEO3] = "VID3",
2950 const char **p_names;
2952 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
2954 if (dispc_runtime_get())
2957 /* DISPC common registers */
2958 DUMPREG(DISPC_REVISION);
2959 DUMPREG(DISPC_SYSCONFIG);
2960 DUMPREG(DISPC_SYSSTATUS);
2961 DUMPREG(DISPC_IRQSTATUS);
2962 DUMPREG(DISPC_IRQENABLE);
2963 DUMPREG(DISPC_CONTROL);
2964 DUMPREG(DISPC_CONFIG);
2965 DUMPREG(DISPC_CAPABLE);
2966 DUMPREG(DISPC_LINE_STATUS);
2967 DUMPREG(DISPC_LINE_NUMBER);
2968 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
2969 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
2970 DUMPREG(DISPC_GLOBAL_ALPHA);
2971 if (dss_has_feature(FEAT_MGR_LCD2)) {
2972 DUMPREG(DISPC_CONTROL2);
2973 DUMPREG(DISPC_CONFIG2);
2978 #define DISPC_REG(i, name) name(i)
2979 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
2980 48 - strlen(#r) - strlen(p_names[i]), " ", \
2981 dispc_read_reg(DISPC_REG(i, r)))
2983 p_names = mgr_names;
2985 /* DISPC channel specific registers */
2986 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
2987 DUMPREG(i, DISPC_DEFAULT_COLOR);
2988 DUMPREG(i, DISPC_TRANS_COLOR);
2989 DUMPREG(i, DISPC_SIZE_MGR);
2991 if (i == OMAP_DSS_CHANNEL_DIGIT)
2994 DUMPREG(i, DISPC_DEFAULT_COLOR);
2995 DUMPREG(i, DISPC_TRANS_COLOR);
2996 DUMPREG(i, DISPC_TIMING_H);
2997 DUMPREG(i, DISPC_TIMING_V);
2998 DUMPREG(i, DISPC_POL_FREQ);
2999 DUMPREG(i, DISPC_DIVISORo);
3000 DUMPREG(i, DISPC_SIZE_MGR);
3002 DUMPREG(i, DISPC_DATA_CYCLE1);
3003 DUMPREG(i, DISPC_DATA_CYCLE2);
3004 DUMPREG(i, DISPC_DATA_CYCLE3);
3006 if (dss_has_feature(FEAT_CPR)) {
3007 DUMPREG(i, DISPC_CPR_COEF_R);
3008 DUMPREG(i, DISPC_CPR_COEF_G);
3009 DUMPREG(i, DISPC_CPR_COEF_B);
3013 p_names = ovl_names;
3015 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3016 DUMPREG(i, DISPC_OVL_BA0);
3017 DUMPREG(i, DISPC_OVL_BA1);
3018 DUMPREG(i, DISPC_OVL_POSITION);
3019 DUMPREG(i, DISPC_OVL_SIZE);
3020 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3021 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3022 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3023 DUMPREG(i, DISPC_OVL_ROW_INC);
3024 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3025 if (dss_has_feature(FEAT_PRELOAD))
3026 DUMPREG(i, DISPC_OVL_PRELOAD);
3028 if (i == OMAP_DSS_GFX) {
3029 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3030 DUMPREG(i, DISPC_OVL_TABLE_BA);
3034 DUMPREG(i, DISPC_OVL_FIR);
3035 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3036 DUMPREG(i, DISPC_OVL_ACCU0);
3037 DUMPREG(i, DISPC_OVL_ACCU1);
3038 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3039 DUMPREG(i, DISPC_OVL_BA0_UV);
3040 DUMPREG(i, DISPC_OVL_BA1_UV);
3041 DUMPREG(i, DISPC_OVL_FIR2);
3042 DUMPREG(i, DISPC_OVL_ACCU2_0);
3043 DUMPREG(i, DISPC_OVL_ACCU2_1);
3045 if (dss_has_feature(FEAT_ATTR2))
3046 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3047 if (dss_has_feature(FEAT_PRELOAD))
3048 DUMPREG(i, DISPC_OVL_PRELOAD);
3054 #define DISPC_REG(plane, name, i) name(plane, i)
3055 #define DUMPREG(plane, name, i) \
3056 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3057 46 - strlen(#name) - strlen(p_names[plane]), " ", \
3058 dispc_read_reg(DISPC_REG(plane, name, i)))
3060 /* Video pipeline coefficient registers */
3062 /* start from OMAP_DSS_VIDEO1 */
3063 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3064 for (j = 0; j < 8; j++)
3065 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
3067 for (j = 0; j < 8; j++)
3068 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
3070 for (j = 0; j < 5; j++)
3071 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
3073 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3074 for (j = 0; j < 8; j++)
3075 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3078 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3079 for (j = 0; j < 8; j++)
3080 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
3082 for (j = 0; j < 8; j++)
3083 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
3085 for (j = 0; j < 8; j++)
3086 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3090 dispc_runtime_put();
3096 static void _dispc_mgr_set_pol_freq(enum omap_channel channel, bool onoff,
3097 bool rf, bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi,
3102 DSSDBG("onoff %d rf %d ieo %d ipc %d ihs %d ivs %d acbi %d acb %d\n",
3103 onoff, rf, ieo, ipc, ihs, ivs, acbi, acb);
3105 l |= FLD_VAL(onoff, 17, 17);
3106 l |= FLD_VAL(rf, 16, 16);
3107 l |= FLD_VAL(ieo, 15, 15);
3108 l |= FLD_VAL(ipc, 14, 14);
3109 l |= FLD_VAL(ihs, 13, 13);
3110 l |= FLD_VAL(ivs, 12, 12);
3111 l |= FLD_VAL(acbi, 11, 8);
3112 l |= FLD_VAL(acb, 7, 0);
3114 dispc_write_reg(DISPC_POL_FREQ(channel), l);
3117 void dispc_mgr_set_pol_freq(enum omap_channel channel,
3118 enum omap_panel_config config, u8 acbi, u8 acb)
3120 _dispc_mgr_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0,
3121 (config & OMAP_DSS_LCD_RF) != 0,
3122 (config & OMAP_DSS_LCD_IEO) != 0,
3123 (config & OMAP_DSS_LCD_IPC) != 0,
3124 (config & OMAP_DSS_LCD_IHS) != 0,
3125 (config & OMAP_DSS_LCD_IVS) != 0,
3129 /* with fck as input clock rate, find dispc dividers that produce req_pck */
3130 void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
3131 struct dispc_clock_info *cinfo)
3133 u16 pcd_min, pcd_max;
3134 unsigned long best_pck;
3135 u16 best_ld, cur_ld;
3136 u16 best_pd, cur_pd;
3138 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3139 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3148 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
3149 unsigned long lck = fck / cur_ld;
3151 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
3152 unsigned long pck = lck / cur_pd;
3153 long old_delta = abs(best_pck - req_pck);
3154 long new_delta = abs(pck - req_pck);
3156 if (best_pck == 0 || new_delta < old_delta) {
3169 if (lck / pcd_min < req_pck)
3174 cinfo->lck_div = best_ld;
3175 cinfo->pck_div = best_pd;
3176 cinfo->lck = fck / cinfo->lck_div;
3177 cinfo->pck = cinfo->lck / cinfo->pck_div;
3180 /* calculate clock rates using dividers in cinfo */
3181 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3182 struct dispc_clock_info *cinfo)
3184 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3186 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3189 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3190 cinfo->pck = cinfo->lck / cinfo->pck_div;
3195 int dispc_mgr_set_clock_div(enum omap_channel channel,
3196 struct dispc_clock_info *cinfo)
3198 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3199 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3201 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
3206 int dispc_mgr_get_clock_div(enum omap_channel channel,
3207 struct dispc_clock_info *cinfo)
3211 fck = dispc_fclk_rate();
3213 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3214 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
3216 cinfo->lck = fck / cinfo->lck_div;
3217 cinfo->pck = cinfo->lck / cinfo->pck_div;
3222 /* dispc.irq_lock has to be locked by the caller */
3223 static void _omap_dispc_set_irqs(void)
3228 struct omap_dispc_isr_data *isr_data;
3230 mask = dispc.irq_error_mask;
3232 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3233 isr_data = &dispc.registered_isr[i];
3235 if (isr_data->isr == NULL)
3238 mask |= isr_data->mask;
3241 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3242 /* clear the irqstatus for newly enabled irqs */
3243 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
3245 dispc_write_reg(DISPC_IRQENABLE, mask);
3248 int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3252 unsigned long flags;
3253 struct omap_dispc_isr_data *isr_data;
3258 spin_lock_irqsave(&dispc.irq_lock, flags);
3260 /* check for duplicate entry */
3261 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3262 isr_data = &dispc.registered_isr[i];
3263 if (isr_data->isr == isr && isr_data->arg == arg &&
3264 isr_data->mask == mask) {
3273 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3274 isr_data = &dispc.registered_isr[i];
3276 if (isr_data->isr != NULL)
3279 isr_data->isr = isr;
3280 isr_data->arg = arg;
3281 isr_data->mask = mask;
3290 _omap_dispc_set_irqs();
3292 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3296 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3300 EXPORT_SYMBOL(omap_dispc_register_isr);
3302 int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3305 unsigned long flags;
3307 struct omap_dispc_isr_data *isr_data;
3309 spin_lock_irqsave(&dispc.irq_lock, flags);
3311 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3312 isr_data = &dispc.registered_isr[i];
3313 if (isr_data->isr != isr || isr_data->arg != arg ||
3314 isr_data->mask != mask)
3317 /* found the correct isr */
3319 isr_data->isr = NULL;
3320 isr_data->arg = NULL;
3328 _omap_dispc_set_irqs();
3330 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3334 EXPORT_SYMBOL(omap_dispc_unregister_isr);
3337 static void print_irq_status(u32 status)
3339 if ((status & dispc.irq_error_mask) == 0)
3342 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
3345 if (status & DISPC_IRQ_##x) \
3347 PIS(GFX_FIFO_UNDERFLOW);
3349 PIS(VID1_FIFO_UNDERFLOW);
3350 PIS(VID2_FIFO_UNDERFLOW);
3351 if (dss_feat_get_num_ovls() > 3)
3352 PIS(VID3_FIFO_UNDERFLOW);
3354 PIS(SYNC_LOST_DIGIT);
3355 if (dss_has_feature(FEAT_MGR_LCD2))
3363 /* Called from dss.c. Note that we don't touch clocks here,
3364 * but we presume they are on because we got an IRQ. However,
3365 * an irq handler may turn the clocks off, so we may not have
3366 * clock later in the function. */
3367 static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
3370 u32 irqstatus, irqenable;
3371 u32 handledirqs = 0;
3372 u32 unhandled_errors;
3373 struct omap_dispc_isr_data *isr_data;
3374 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3376 spin_lock(&dispc.irq_lock);
3378 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
3379 irqenable = dispc_read_reg(DISPC_IRQENABLE);
3381 /* IRQ is not for us */
3382 if (!(irqstatus & irqenable)) {
3383 spin_unlock(&dispc.irq_lock);
3387 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3388 spin_lock(&dispc.irq_stats_lock);
3389 dispc.irq_stats.irq_count++;
3390 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3391 spin_unlock(&dispc.irq_stats_lock);
3396 print_irq_status(irqstatus);
3398 /* Ack the interrupt. Do it here before clocks are possibly turned
3400 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
3401 /* flush posted write */
3402 dispc_read_reg(DISPC_IRQSTATUS);
3404 /* make a copy and unlock, so that isrs can unregister
3406 memcpy(registered_isr, dispc.registered_isr,
3407 sizeof(registered_isr));
3409 spin_unlock(&dispc.irq_lock);
3411 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3412 isr_data = ®istered_isr[i];
3417 if (isr_data->mask & irqstatus) {
3418 isr_data->isr(isr_data->arg, irqstatus);
3419 handledirqs |= isr_data->mask;
3423 spin_lock(&dispc.irq_lock);
3425 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3427 if (unhandled_errors) {
3428 dispc.error_irqs |= unhandled_errors;
3430 dispc.irq_error_mask &= ~unhandled_errors;
3431 _omap_dispc_set_irqs();
3433 schedule_work(&dispc.error_work);
3436 spin_unlock(&dispc.irq_lock);
3441 static void dispc_error_worker(struct work_struct *work)
3445 unsigned long flags;
3446 static const unsigned fifo_underflow_bits[] = {
3447 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3448 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3449 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
3450 DISPC_IRQ_VID3_FIFO_UNDERFLOW,
3453 static const unsigned sync_lost_bits[] = {
3454 DISPC_IRQ_SYNC_LOST,
3455 DISPC_IRQ_SYNC_LOST_DIGIT,
3456 DISPC_IRQ_SYNC_LOST2,
3459 spin_lock_irqsave(&dispc.irq_lock, flags);
3460 errors = dispc.error_irqs;
3461 dispc.error_irqs = 0;
3462 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3464 dispc_runtime_get();
3466 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3467 struct omap_overlay *ovl;
3470 ovl = omap_dss_get_overlay(i);
3471 bit = fifo_underflow_bits[i];
3474 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3476 dispc_ovl_enable(ovl->id, false);
3477 dispc_mgr_go(ovl->manager->id);
3482 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3483 struct omap_overlay_manager *mgr;
3486 mgr = omap_dss_get_overlay_manager(i);
3487 bit = sync_lost_bits[i];
3490 struct omap_dss_device *dssdev = mgr->device;
3493 DSSERR("SYNC_LOST on channel %s, restarting the output "
3494 "with video overlays disabled\n",
3497 enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
3498 dssdev->driver->disable(dssdev);
3500 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3501 struct omap_overlay *ovl;
3502 ovl = omap_dss_get_overlay(i);
3504 if (ovl->id != OMAP_DSS_GFX &&
3505 ovl->manager == mgr)
3506 dispc_ovl_enable(ovl->id, false);
3509 dispc_mgr_go(mgr->id);
3513 dssdev->driver->enable(dssdev);
3517 if (errors & DISPC_IRQ_OCP_ERR) {
3518 DSSERR("OCP_ERR\n");
3519 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3520 struct omap_overlay_manager *mgr;
3521 mgr = omap_dss_get_overlay_manager(i);
3522 if (mgr->device && mgr->device->driver)
3523 mgr->device->driver->disable(mgr->device);
3527 spin_lock_irqsave(&dispc.irq_lock, flags);
3528 dispc.irq_error_mask |= errors;
3529 _omap_dispc_set_irqs();
3530 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3532 dispc_runtime_put();
3535 int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3537 void dispc_irq_wait_handler(void *data, u32 mask)
3539 complete((struct completion *)data);
3543 DECLARE_COMPLETION_ONSTACK(completion);
3545 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3551 timeout = wait_for_completion_timeout(&completion, timeout);
3553 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3558 if (timeout == -ERESTARTSYS)
3559 return -ERESTARTSYS;
3564 int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3565 unsigned long timeout)
3567 void dispc_irq_wait_handler(void *data, u32 mask)
3569 complete((struct completion *)data);
3573 DECLARE_COMPLETION_ONSTACK(completion);
3575 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3581 timeout = wait_for_completion_interruptible_timeout(&completion,
3584 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3589 if (timeout == -ERESTARTSYS)
3590 return -ERESTARTSYS;
3595 static void _omap_dispc_initialize_irq(void)
3597 unsigned long flags;
3599 spin_lock_irqsave(&dispc.irq_lock, flags);
3601 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3603 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
3604 if (dss_has_feature(FEAT_MGR_LCD2))
3605 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
3606 if (dss_feat_get_num_ovls() > 3)
3607 dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
3609 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3611 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3613 _omap_dispc_set_irqs();
3615 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3618 void dispc_enable_sidle(void)
3620 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3623 void dispc_disable_sidle(void)
3625 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3628 static void _omap_dispc_initial_config(void)
3632 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3633 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3634 l = dispc_read_reg(DISPC_DIVISOR);
3635 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3636 l = FLD_MOD(l, 1, 0, 0);
3637 l = FLD_MOD(l, 1, 23, 16);
3638 dispc_write_reg(DISPC_DIVISOR, l);
3642 if (dss_has_feature(FEAT_FUNCGATED))
3643 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3645 _dispc_setup_color_conv_coef();
3647 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3649 dispc_read_plane_fifo_sizes();
3651 dispc_configure_burst_sizes();
3653 dispc_ovl_enable_zorder_planes();
3656 /* DISPC HW IP initialisation */
3657 static int __init omap_dispchw_probe(struct platform_device *pdev)
3661 struct resource *dispc_mem;
3666 spin_lock_init(&dispc.irq_lock);
3668 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3669 spin_lock_init(&dispc.irq_stats_lock);
3670 dispc.irq_stats.last_reset = jiffies;
3673 INIT_WORK(&dispc.error_work, dispc_error_worker);
3675 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3677 DSSERR("can't get IORESOURCE_MEM DISPC\n");
3681 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3682 resource_size(dispc_mem));
3684 DSSERR("can't ioremap DISPC\n");
3688 dispc.irq = platform_get_irq(dispc.pdev, 0);
3689 if (dispc.irq < 0) {
3690 DSSERR("platform_get_irq failed\n");
3694 r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
3695 IRQF_SHARED, "OMAP DISPC", dispc.pdev);
3697 DSSERR("request_irq failed\n");
3701 clk = clk_get(&pdev->dev, "fck");
3703 DSSERR("can't get fck\n");
3708 dispc.dss_clk = clk;
3710 pm_runtime_enable(&pdev->dev);
3712 r = dispc_runtime_get();
3714 goto err_runtime_get;
3716 _omap_dispc_initial_config();
3718 _omap_dispc_initialize_irq();
3720 rev = dispc_read_reg(DISPC_REVISION);
3721 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
3722 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3724 dispc_runtime_put();
3726 dss_debugfs_create_file("dispc", dispc_dump_regs);
3728 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3729 dss_debugfs_create_file("dispc_irq", dispc_dump_irqs);
3734 pm_runtime_disable(&pdev->dev);
3735 clk_put(dispc.dss_clk);
3739 static int __exit omap_dispchw_remove(struct platform_device *pdev)
3741 pm_runtime_disable(&pdev->dev);
3743 clk_put(dispc.dss_clk);
3748 static int dispc_runtime_suspend(struct device *dev)
3750 dispc_save_context();
3755 static int dispc_runtime_resume(struct device *dev)
3757 dispc_restore_context();
3762 static const struct dev_pm_ops dispc_pm_ops = {
3763 .runtime_suspend = dispc_runtime_suspend,
3764 .runtime_resume = dispc_runtime_resume,
3767 static struct platform_driver omap_dispchw_driver = {
3768 .remove = __exit_p(omap_dispchw_remove),
3770 .name = "omapdss_dispc",
3771 .owner = THIS_MODULE,
3772 .pm = &dispc_pm_ops,
3776 int __init dispc_init_platform_driver(void)
3778 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
3781 void __exit dispc_uninit_platform_driver(void)
3783 platform_driver_unregister(&omap_dispchw_driver);