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);
134 static int dispc_get_ctx_loss_count(void)
136 struct device *dev = &dispc.pdev->dev;
137 struct omap_display_platform_data *pdata = dev->platform_data;
138 struct omap_dss_board_info *board_data = pdata->board_data;
141 if (!board_data->get_context_loss_count)
144 cnt = board_data->get_context_loss_count(dev);
146 WARN_ONCE(cnt < 0, "get_context_loss_count failed: %d\n", cnt);
152 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
154 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
156 static void dispc_save_context(void)
160 DSSDBG("dispc_save_context\n");
166 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
167 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
169 if (dss_has_feature(FEAT_MGR_LCD2)) {
174 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
175 SR(DEFAULT_COLOR(i));
178 if (i == OMAP_DSS_CHANNEL_DIGIT)
189 if (dss_has_feature(FEAT_CPR)) {
196 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
201 SR(OVL_ATTRIBUTES(i));
202 SR(OVL_FIFO_THRESHOLD(i));
204 SR(OVL_PIXEL_INC(i));
205 if (dss_has_feature(FEAT_PRELOAD))
207 if (i == OMAP_DSS_GFX) {
208 SR(OVL_WINDOW_SKIP(i));
213 SR(OVL_PICTURE_SIZE(i));
217 for (j = 0; j < 8; j++)
218 SR(OVL_FIR_COEF_H(i, j));
220 for (j = 0; j < 8; j++)
221 SR(OVL_FIR_COEF_HV(i, j));
223 for (j = 0; j < 5; j++)
224 SR(OVL_CONV_COEF(i, j));
226 if (dss_has_feature(FEAT_FIR_COEF_V)) {
227 for (j = 0; j < 8; j++)
228 SR(OVL_FIR_COEF_V(i, j));
231 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
238 for (j = 0; j < 8; j++)
239 SR(OVL_FIR_COEF_H2(i, j));
241 for (j = 0; j < 8; j++)
242 SR(OVL_FIR_COEF_HV2(i, j));
244 for (j = 0; j < 8; j++)
245 SR(OVL_FIR_COEF_V2(i, j));
247 if (dss_has_feature(FEAT_ATTR2))
248 SR(OVL_ATTRIBUTES2(i));
251 if (dss_has_feature(FEAT_CORE_CLK_DIV))
254 dispc.ctx_loss_cnt = dispc_get_ctx_loss_count();
255 dispc.ctx_valid = true;
257 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
260 static void dispc_restore_context(void)
264 DSSDBG("dispc_restore_context\n");
266 if (!dispc.ctx_valid)
269 ctx = dispc_get_ctx_loss_count();
271 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
274 DSSDBG("ctx_loss_count: saved %d, current %d\n",
275 dispc.ctx_loss_cnt, ctx);
281 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
282 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
284 if (dss_has_feature(FEAT_MGR_LCD2))
287 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
288 RR(DEFAULT_COLOR(i));
291 if (i == OMAP_DSS_CHANNEL_DIGIT)
302 if (dss_has_feature(FEAT_CPR)) {
309 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
314 RR(OVL_ATTRIBUTES(i));
315 RR(OVL_FIFO_THRESHOLD(i));
317 RR(OVL_PIXEL_INC(i));
318 if (dss_has_feature(FEAT_PRELOAD))
320 if (i == OMAP_DSS_GFX) {
321 RR(OVL_WINDOW_SKIP(i));
326 RR(OVL_PICTURE_SIZE(i));
330 for (j = 0; j < 8; j++)
331 RR(OVL_FIR_COEF_H(i, j));
333 for (j = 0; j < 8; j++)
334 RR(OVL_FIR_COEF_HV(i, j));
336 for (j = 0; j < 5; j++)
337 RR(OVL_CONV_COEF(i, j));
339 if (dss_has_feature(FEAT_FIR_COEF_V)) {
340 for (j = 0; j < 8; j++)
341 RR(OVL_FIR_COEF_V(i, j));
344 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
351 for (j = 0; j < 8; j++)
352 RR(OVL_FIR_COEF_H2(i, j));
354 for (j = 0; j < 8; j++)
355 RR(OVL_FIR_COEF_HV2(i, j));
357 for (j = 0; j < 8; j++)
358 RR(OVL_FIR_COEF_V2(i, j));
360 if (dss_has_feature(FEAT_ATTR2))
361 RR(OVL_ATTRIBUTES2(i));
364 if (dss_has_feature(FEAT_CORE_CLK_DIV))
367 /* enable last, because LCD & DIGIT enable are here */
369 if (dss_has_feature(FEAT_MGR_LCD2))
371 /* clear spurious SYNC_LOST_DIGIT interrupts */
372 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
375 * enable last so IRQs won't trigger before
376 * the context is fully restored
380 DSSDBG("context restored\n");
386 int dispc_runtime_get(void)
390 DSSDBG("dispc_runtime_get\n");
392 r = pm_runtime_get_sync(&dispc.pdev->dev);
394 return r < 0 ? r : 0;
397 void dispc_runtime_put(void)
401 DSSDBG("dispc_runtime_put\n");
403 r = pm_runtime_put_sync(&dispc.pdev->dev);
407 static inline bool dispc_mgr_is_lcd(enum omap_channel channel)
409 if (channel == OMAP_DSS_CHANNEL_LCD ||
410 channel == OMAP_DSS_CHANNEL_LCD2)
416 static struct omap_dss_device *dispc_mgr_get_device(enum omap_channel channel)
418 struct omap_overlay_manager *mgr =
419 omap_dss_get_overlay_manager(channel);
421 return mgr ? mgr->device : NULL;
424 u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
427 case OMAP_DSS_CHANNEL_LCD:
428 return DISPC_IRQ_VSYNC;
429 case OMAP_DSS_CHANNEL_LCD2:
430 return DISPC_IRQ_VSYNC2;
431 case OMAP_DSS_CHANNEL_DIGIT:
432 return DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
438 u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
441 case OMAP_DSS_CHANNEL_LCD:
442 return DISPC_IRQ_FRAMEDONE;
443 case OMAP_DSS_CHANNEL_LCD2:
444 return DISPC_IRQ_FRAMEDONE2;
445 case OMAP_DSS_CHANNEL_DIGIT:
452 bool dispc_mgr_go_busy(enum omap_channel channel)
456 if (dispc_mgr_is_lcd(channel))
459 bit = 6; /* GODIGIT */
461 if (channel == OMAP_DSS_CHANNEL_LCD2)
462 return REG_GET(DISPC_CONTROL2, bit, bit) == 1;
464 return REG_GET(DISPC_CONTROL, bit, bit) == 1;
467 void dispc_mgr_go(enum omap_channel channel)
470 bool enable_bit, go_bit;
472 if (dispc_mgr_is_lcd(channel))
473 bit = 0; /* LCDENABLE */
475 bit = 1; /* DIGITALENABLE */
477 /* if the channel is not enabled, we don't need GO */
478 if (channel == OMAP_DSS_CHANNEL_LCD2)
479 enable_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
481 enable_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
486 if (dispc_mgr_is_lcd(channel))
489 bit = 6; /* GODIGIT */
491 if (channel == OMAP_DSS_CHANNEL_LCD2)
492 go_bit = REG_GET(DISPC_CONTROL2, bit, bit) == 1;
494 go_bit = REG_GET(DISPC_CONTROL, bit, bit) == 1;
497 DSSERR("GO bit not down for channel %d\n", channel);
501 DSSDBG("GO %s\n", channel == OMAP_DSS_CHANNEL_LCD ? "LCD" :
502 (channel == OMAP_DSS_CHANNEL_LCD2 ? "LCD2" : "DIGIT"));
504 if (channel == OMAP_DSS_CHANNEL_LCD2)
505 REG_FLD_MOD(DISPC_CONTROL2, 1, bit, bit);
507 REG_FLD_MOD(DISPC_CONTROL, 1, bit, bit);
510 static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
512 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
515 static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
517 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
520 static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
522 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
525 static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
527 BUG_ON(plane == OMAP_DSS_GFX);
529 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
532 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
535 BUG_ON(plane == OMAP_DSS_GFX);
537 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
540 static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
542 BUG_ON(plane == OMAP_DSS_GFX);
544 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
547 static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
548 int fir_vinc, int five_taps,
549 enum omap_color_component color_comp)
551 const struct dispc_coef *h_coef, *v_coef;
554 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
555 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
557 for (i = 0; i < 8; i++) {
560 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
561 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
562 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
563 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
564 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
565 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
566 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
567 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
569 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
570 dispc_ovl_write_firh_reg(plane, i, h);
571 dispc_ovl_write_firhv_reg(plane, i, hv);
573 dispc_ovl_write_firh2_reg(plane, i, h);
574 dispc_ovl_write_firhv2_reg(plane, i, hv);
580 for (i = 0; i < 8; i++) {
582 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
583 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
584 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
585 dispc_ovl_write_firv_reg(plane, i, v);
587 dispc_ovl_write_firv2_reg(plane, i, v);
592 static void _dispc_setup_color_conv_coef(void)
595 const struct color_conv_coef {
596 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
599 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
602 const struct color_conv_coef *ct;
604 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
608 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
609 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 0),
610 CVAL(ct->rcr, ct->ry));
611 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 1),
612 CVAL(ct->gy, ct->rcb));
613 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 2),
614 CVAL(ct->gcb, ct->gcr));
615 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 3),
616 CVAL(ct->bcr, ct->by));
617 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 4),
620 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), ct->full_range,
628 static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
630 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
633 static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
635 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
638 static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
640 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
643 static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
645 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
648 static void dispc_ovl_set_pos(enum omap_plane plane, int x, int y)
650 u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
652 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
655 static void dispc_ovl_set_pic_size(enum omap_plane plane, int width, int height)
657 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
659 if (plane == OMAP_DSS_GFX)
660 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
662 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
665 static void dispc_ovl_set_vid_size(enum omap_plane plane, int width, int height)
669 BUG_ON(plane == OMAP_DSS_GFX);
671 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
673 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
676 static void dispc_ovl_set_zorder(enum omap_plane plane, u8 zorder)
678 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
680 if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
683 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
686 static void dispc_ovl_enable_zorder_planes(void)
690 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
693 for (i = 0; i < dss_feat_get_num_ovls(); i++)
694 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
697 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane, bool enable)
699 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
701 if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
704 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
707 static void dispc_ovl_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
709 static const unsigned shifts[] = { 0, 8, 16, 24, };
711 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
713 if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
716 shift = shifts[plane];
717 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
720 static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
722 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
725 static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
727 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
730 static void dispc_ovl_set_color_mode(enum omap_plane plane,
731 enum omap_color_mode color_mode)
734 if (plane != OMAP_DSS_GFX) {
735 switch (color_mode) {
736 case OMAP_DSS_COLOR_NV12:
738 case OMAP_DSS_COLOR_RGB12U:
740 case OMAP_DSS_COLOR_RGBA16:
742 case OMAP_DSS_COLOR_RGBX16:
744 case OMAP_DSS_COLOR_ARGB16:
746 case OMAP_DSS_COLOR_RGB16:
748 case OMAP_DSS_COLOR_ARGB16_1555:
750 case OMAP_DSS_COLOR_RGB24U:
752 case OMAP_DSS_COLOR_RGB24P:
754 case OMAP_DSS_COLOR_YUV2:
756 case OMAP_DSS_COLOR_UYVY:
758 case OMAP_DSS_COLOR_ARGB32:
760 case OMAP_DSS_COLOR_RGBA32:
762 case OMAP_DSS_COLOR_RGBX32:
764 case OMAP_DSS_COLOR_XRGB16_1555:
770 switch (color_mode) {
771 case OMAP_DSS_COLOR_CLUT1:
773 case OMAP_DSS_COLOR_CLUT2:
775 case OMAP_DSS_COLOR_CLUT4:
777 case OMAP_DSS_COLOR_CLUT8:
779 case OMAP_DSS_COLOR_RGB12U:
781 case OMAP_DSS_COLOR_ARGB16:
783 case OMAP_DSS_COLOR_RGB16:
785 case OMAP_DSS_COLOR_ARGB16_1555:
787 case OMAP_DSS_COLOR_RGB24U:
789 case OMAP_DSS_COLOR_RGB24P:
791 case OMAP_DSS_COLOR_YUV2:
793 case OMAP_DSS_COLOR_UYVY:
795 case OMAP_DSS_COLOR_ARGB32:
797 case OMAP_DSS_COLOR_RGBA32:
799 case OMAP_DSS_COLOR_RGBX32:
801 case OMAP_DSS_COLOR_XRGB16_1555:
808 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
811 void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
815 int chan = 0, chan2 = 0;
821 case OMAP_DSS_VIDEO1:
822 case OMAP_DSS_VIDEO2:
823 case OMAP_DSS_VIDEO3:
831 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
832 if (dss_has_feature(FEAT_MGR_LCD2)) {
834 case OMAP_DSS_CHANNEL_LCD:
838 case OMAP_DSS_CHANNEL_DIGIT:
842 case OMAP_DSS_CHANNEL_LCD2:
850 val = FLD_MOD(val, chan, shift, shift);
851 val = FLD_MOD(val, chan2, 31, 30);
853 val = FLD_MOD(val, channel, shift, shift);
855 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
858 static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
862 enum omap_channel channel;
868 case OMAP_DSS_VIDEO1:
869 case OMAP_DSS_VIDEO2:
870 case OMAP_DSS_VIDEO3:
877 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
879 if (dss_has_feature(FEAT_MGR_LCD2)) {
880 if (FLD_GET(val, 31, 30) == 0)
881 channel = FLD_GET(val, shift, shift);
883 channel = OMAP_DSS_CHANNEL_LCD2;
885 channel = FLD_GET(val, shift, shift);
891 static void dispc_ovl_set_burst_size(enum omap_plane plane,
892 enum omap_burst_size burst_size)
894 static const unsigned shifts[] = { 6, 14, 14, 14, };
897 shift = shifts[plane];
898 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
901 static void dispc_configure_burst_sizes(void)
904 const int burst_size = BURST_SIZE_X8;
906 /* Configure burst size always to maximum size */
907 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
908 dispc_ovl_set_burst_size(i, burst_size);
911 static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
913 unsigned unit = dss_feat_get_burst_size_unit();
914 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
918 void dispc_enable_gamma_table(bool enable)
921 * This is partially implemented to support only disabling of
925 DSSWARN("Gamma table enabling for TV not yet supported");
929 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
932 static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
936 if (channel == OMAP_DSS_CHANNEL_LCD)
938 else if (channel == OMAP_DSS_CHANNEL_LCD2)
943 REG_FLD_MOD(reg, enable, 15, 15);
946 static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
947 struct omap_dss_cpr_coefs *coefs)
949 u32 coef_r, coef_g, coef_b;
951 if (!dispc_mgr_is_lcd(channel))
954 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
955 FLD_VAL(coefs->rb, 9, 0);
956 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
957 FLD_VAL(coefs->gb, 9, 0);
958 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
959 FLD_VAL(coefs->bb, 9, 0);
961 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
962 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
963 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
966 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
970 BUG_ON(plane == OMAP_DSS_GFX);
972 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
973 val = FLD_MOD(val, enable, 9, 9);
974 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
977 static void dispc_ovl_enable_replication(enum omap_plane plane, bool enable)
979 static const unsigned shifts[] = { 5, 10, 10, 10 };
982 shift = shifts[plane];
983 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
986 void dispc_mgr_set_lcd_size(enum omap_channel channel, u16 width, u16 height)
989 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
990 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
991 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
994 void dispc_set_digit_size(u16 width, u16 height)
997 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
998 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
999 dispc_write_reg(DISPC_SIZE_MGR(OMAP_DSS_CHANNEL_DIGIT), val);
1002 static void dispc_read_plane_fifo_sizes(void)
1009 unit = dss_feat_get_buffer_size_unit();
1011 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1013 for (plane = 0; plane < dss_feat_get_num_ovls(); ++plane) {
1014 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(plane), start, end);
1016 dispc.fifo_size[plane] = size;
1020 static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1022 return dispc.fifo_size[plane];
1025 void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
1027 u8 hi_start, hi_end, lo_start, lo_end;
1030 unit = dss_feat_get_buffer_size_unit();
1032 WARN_ON(low % unit != 0);
1033 WARN_ON(high % unit != 0);
1038 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1039 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1041 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1043 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1044 lo_start, lo_end) * unit,
1045 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1046 hi_start, hi_end) * unit,
1047 low * unit, high * unit);
1049 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1050 FLD_VAL(high, hi_start, hi_end) |
1051 FLD_VAL(low, lo_start, lo_end));
1054 void dispc_enable_fifomerge(bool enable)
1056 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1061 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1062 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1065 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1066 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge)
1069 * All sizes are in bytes. Both the buffer and burst are made of
1070 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1073 unsigned buf_unit = dss_feat_get_buffer_size_unit();
1074 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1077 burst_size = dispc_ovl_get_burst_size(plane);
1078 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
1080 if (use_fifomerge) {
1081 total_fifo_size = 0;
1082 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1083 total_fifo_size += dispc_ovl_get_fifo_size(i);
1085 total_fifo_size = ovl_fifo_size;
1089 * We use the same low threshold for both fifomerge and non-fifomerge
1090 * cases, but for fifomerge we calculate the high threshold using the
1091 * combined fifo size
1094 if (dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1095 *fifo_low = ovl_fifo_size - burst_size * 2;
1096 *fifo_high = total_fifo_size - burst_size;
1098 *fifo_low = ovl_fifo_size - burst_size;
1099 *fifo_high = total_fifo_size - buf_unit;
1103 static void dispc_ovl_set_fir(enum omap_plane plane,
1105 enum omap_color_component color_comp)
1109 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1110 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1112 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1113 &hinc_start, &hinc_end);
1114 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1115 &vinc_start, &vinc_end);
1116 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1117 FLD_VAL(hinc, hinc_start, hinc_end);
1119 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1121 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1122 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1126 static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1129 u8 hor_start, hor_end, vert_start, vert_end;
1131 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1132 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1134 val = FLD_VAL(vaccu, vert_start, vert_end) |
1135 FLD_VAL(haccu, hor_start, hor_end);
1137 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1140 static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1143 u8 hor_start, hor_end, vert_start, vert_end;
1145 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1146 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1148 val = FLD_VAL(vaccu, vert_start, vert_end) |
1149 FLD_VAL(haccu, hor_start, hor_end);
1151 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1154 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1159 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1160 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1163 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1168 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1169 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1172 static void dispc_ovl_set_scale_param(enum omap_plane plane,
1173 u16 orig_width, u16 orig_height,
1174 u16 out_width, u16 out_height,
1175 bool five_taps, u8 rotation,
1176 enum omap_color_component color_comp)
1178 int fir_hinc, fir_vinc;
1180 fir_hinc = 1024 * orig_width / out_width;
1181 fir_vinc = 1024 * orig_height / out_height;
1183 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1185 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1188 static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1189 u16 orig_width, u16 orig_height,
1190 u16 out_width, u16 out_height,
1191 bool ilace, bool five_taps,
1192 bool fieldmode, enum omap_color_mode color_mode,
1199 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1200 out_width, out_height, five_taps,
1201 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1202 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1204 /* RESIZEENABLE and VERTICALTAPS */
1205 l &= ~((0x3 << 5) | (0x1 << 21));
1206 l |= (orig_width != out_width) ? (1 << 5) : 0;
1207 l |= (orig_height != out_height) ? (1 << 6) : 0;
1208 l |= five_taps ? (1 << 21) : 0;
1210 /* VRESIZECONF and HRESIZECONF */
1211 if (dss_has_feature(FEAT_RESIZECONF)) {
1213 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1214 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1217 /* LINEBUFFERSPLIT */
1218 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1220 l |= five_taps ? (1 << 22) : 0;
1223 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1226 * field 0 = even field = bottom field
1227 * field 1 = odd field = top field
1229 if (ilace && !fieldmode) {
1231 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1232 if (accu0 >= 1024/2) {
1238 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1239 dispc_ovl_set_vid_accu1(plane, 0, accu1);
1242 static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1243 u16 orig_width, u16 orig_height,
1244 u16 out_width, u16 out_height,
1245 bool ilace, bool five_taps,
1246 bool fieldmode, enum omap_color_mode color_mode,
1249 int scale_x = out_width != orig_width;
1250 int scale_y = out_height != orig_height;
1252 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1254 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1255 color_mode != OMAP_DSS_COLOR_UYVY &&
1256 color_mode != OMAP_DSS_COLOR_NV12)) {
1257 /* reset chroma resampling for RGB formats */
1258 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1261 switch (color_mode) {
1262 case OMAP_DSS_COLOR_NV12:
1263 /* UV is subsampled by 2 vertically*/
1265 /* UV is subsampled by 2 horz.*/
1268 case OMAP_DSS_COLOR_YUV2:
1269 case OMAP_DSS_COLOR_UYVY:
1270 /*For YUV422 with 90/270 rotation,
1271 *we don't upsample chroma
1273 if (rotation == OMAP_DSS_ROT_0 ||
1274 rotation == OMAP_DSS_ROT_180)
1275 /* UV is subsampled by 2 hrz*/
1277 /* must use FIR for YUV422 if rotated */
1278 if (rotation != OMAP_DSS_ROT_0)
1279 scale_x = scale_y = true;
1285 if (out_width != orig_width)
1287 if (out_height != orig_height)
1290 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1291 out_width, out_height, five_taps,
1292 rotation, DISPC_COLOR_COMPONENT_UV);
1294 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1295 (scale_x || scale_y) ? 1 : 0, 8, 8);
1297 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1299 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1301 dispc_ovl_set_vid_accu2_0(plane, 0x80, 0);
1302 dispc_ovl_set_vid_accu2_1(plane, 0x80, 0);
1305 static void dispc_ovl_set_scaling(enum omap_plane plane,
1306 u16 orig_width, u16 orig_height,
1307 u16 out_width, u16 out_height,
1308 bool ilace, bool five_taps,
1309 bool fieldmode, enum omap_color_mode color_mode,
1312 BUG_ON(plane == OMAP_DSS_GFX);
1314 dispc_ovl_set_scaling_common(plane,
1315 orig_width, orig_height,
1316 out_width, out_height,
1318 fieldmode, color_mode,
1321 dispc_ovl_set_scaling_uv(plane,
1322 orig_width, orig_height,
1323 out_width, out_height,
1325 fieldmode, color_mode,
1329 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1330 bool mirroring, enum omap_color_mode color_mode)
1332 bool row_repeat = false;
1335 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1336 color_mode == OMAP_DSS_COLOR_UYVY) {
1340 case OMAP_DSS_ROT_0:
1343 case OMAP_DSS_ROT_90:
1346 case OMAP_DSS_ROT_180:
1349 case OMAP_DSS_ROT_270:
1355 case OMAP_DSS_ROT_0:
1358 case OMAP_DSS_ROT_90:
1361 case OMAP_DSS_ROT_180:
1364 case OMAP_DSS_ROT_270:
1370 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1376 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1377 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1378 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1379 row_repeat ? 1 : 0, 18, 18);
1382 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1384 switch (color_mode) {
1385 case OMAP_DSS_COLOR_CLUT1:
1387 case OMAP_DSS_COLOR_CLUT2:
1389 case OMAP_DSS_COLOR_CLUT4:
1391 case OMAP_DSS_COLOR_CLUT8:
1392 case OMAP_DSS_COLOR_NV12:
1394 case OMAP_DSS_COLOR_RGB12U:
1395 case OMAP_DSS_COLOR_RGB16:
1396 case OMAP_DSS_COLOR_ARGB16:
1397 case OMAP_DSS_COLOR_YUV2:
1398 case OMAP_DSS_COLOR_UYVY:
1399 case OMAP_DSS_COLOR_RGBA16:
1400 case OMAP_DSS_COLOR_RGBX16:
1401 case OMAP_DSS_COLOR_ARGB16_1555:
1402 case OMAP_DSS_COLOR_XRGB16_1555:
1404 case OMAP_DSS_COLOR_RGB24P:
1406 case OMAP_DSS_COLOR_RGB24U:
1407 case OMAP_DSS_COLOR_ARGB32:
1408 case OMAP_DSS_COLOR_RGBA32:
1409 case OMAP_DSS_COLOR_RGBX32:
1416 static s32 pixinc(int pixels, u8 ps)
1420 else if (pixels > 1)
1421 return 1 + (pixels - 1) * ps;
1422 else if (pixels < 0)
1423 return 1 - (-pixels + 1) * ps;
1428 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1430 u16 width, u16 height,
1431 enum omap_color_mode color_mode, bool fieldmode,
1432 unsigned int field_offset,
1433 unsigned *offset0, unsigned *offset1,
1434 s32 *row_inc, s32 *pix_inc)
1438 /* FIXME CLUT formats */
1439 switch (color_mode) {
1440 case OMAP_DSS_COLOR_CLUT1:
1441 case OMAP_DSS_COLOR_CLUT2:
1442 case OMAP_DSS_COLOR_CLUT4:
1443 case OMAP_DSS_COLOR_CLUT8:
1446 case OMAP_DSS_COLOR_YUV2:
1447 case OMAP_DSS_COLOR_UYVY:
1451 ps = color_mode_to_bpp(color_mode) / 8;
1455 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1459 * field 0 = even field = bottom field
1460 * field 1 = odd field = top field
1462 switch (rotation + mirror * 4) {
1463 case OMAP_DSS_ROT_0:
1464 case OMAP_DSS_ROT_180:
1466 * If the pixel format is YUV or UYVY divide the width
1467 * of the image by 2 for 0 and 180 degree rotation.
1469 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1470 color_mode == OMAP_DSS_COLOR_UYVY)
1472 case OMAP_DSS_ROT_90:
1473 case OMAP_DSS_ROT_270:
1476 *offset0 = field_offset * screen_width * ps;
1480 *row_inc = pixinc(1 + (screen_width - width) +
1481 (fieldmode ? screen_width : 0),
1483 *pix_inc = pixinc(1, ps);
1486 case OMAP_DSS_ROT_0 + 4:
1487 case OMAP_DSS_ROT_180 + 4:
1488 /* If the pixel format is YUV or UYVY divide the width
1489 * of the image by 2 for 0 degree and 180 degree
1491 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1492 color_mode == OMAP_DSS_COLOR_UYVY)
1494 case OMAP_DSS_ROT_90 + 4:
1495 case OMAP_DSS_ROT_270 + 4:
1498 *offset0 = field_offset * screen_width * ps;
1501 *row_inc = pixinc(1 - (screen_width + width) -
1502 (fieldmode ? screen_width : 0),
1504 *pix_inc = pixinc(1, ps);
1512 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1514 u16 width, u16 height,
1515 enum omap_color_mode color_mode, bool fieldmode,
1516 unsigned int field_offset,
1517 unsigned *offset0, unsigned *offset1,
1518 s32 *row_inc, s32 *pix_inc)
1523 /* FIXME CLUT formats */
1524 switch (color_mode) {
1525 case OMAP_DSS_COLOR_CLUT1:
1526 case OMAP_DSS_COLOR_CLUT2:
1527 case OMAP_DSS_COLOR_CLUT4:
1528 case OMAP_DSS_COLOR_CLUT8:
1532 ps = color_mode_to_bpp(color_mode) / 8;
1536 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1539 /* width & height are overlay sizes, convert to fb sizes */
1541 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1550 * field 0 = even field = bottom field
1551 * field 1 = odd field = top field
1553 switch (rotation + mirror * 4) {
1554 case OMAP_DSS_ROT_0:
1557 *offset0 = *offset1 + field_offset * screen_width * ps;
1559 *offset0 = *offset1;
1560 *row_inc = pixinc(1 + (screen_width - fbw) +
1561 (fieldmode ? screen_width : 0),
1563 *pix_inc = pixinc(1, ps);
1565 case OMAP_DSS_ROT_90:
1566 *offset1 = screen_width * (fbh - 1) * ps;
1568 *offset0 = *offset1 + field_offset * ps;
1570 *offset0 = *offset1;
1571 *row_inc = pixinc(screen_width * (fbh - 1) + 1 +
1572 (fieldmode ? 1 : 0), ps);
1573 *pix_inc = pixinc(-screen_width, ps);
1575 case OMAP_DSS_ROT_180:
1576 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1578 *offset0 = *offset1 - field_offset * screen_width * ps;
1580 *offset0 = *offset1;
1581 *row_inc = pixinc(-1 -
1582 (screen_width - fbw) -
1583 (fieldmode ? screen_width : 0),
1585 *pix_inc = pixinc(-1, ps);
1587 case OMAP_DSS_ROT_270:
1588 *offset1 = (fbw - 1) * ps;
1590 *offset0 = *offset1 - field_offset * ps;
1592 *offset0 = *offset1;
1593 *row_inc = pixinc(-screen_width * (fbh - 1) - 1 -
1594 (fieldmode ? 1 : 0), ps);
1595 *pix_inc = pixinc(screen_width, ps);
1599 case OMAP_DSS_ROT_0 + 4:
1600 *offset1 = (fbw - 1) * ps;
1602 *offset0 = *offset1 + field_offset * screen_width * ps;
1604 *offset0 = *offset1;
1605 *row_inc = pixinc(screen_width * 2 - 1 +
1606 (fieldmode ? screen_width : 0),
1608 *pix_inc = pixinc(-1, ps);
1611 case OMAP_DSS_ROT_90 + 4:
1614 *offset0 = *offset1 + field_offset * ps;
1616 *offset0 = *offset1;
1617 *row_inc = pixinc(-screen_width * (fbh - 1) + 1 +
1618 (fieldmode ? 1 : 0),
1620 *pix_inc = pixinc(screen_width, ps);
1623 case OMAP_DSS_ROT_180 + 4:
1624 *offset1 = screen_width * (fbh - 1) * ps;
1626 *offset0 = *offset1 - field_offset * screen_width * ps;
1628 *offset0 = *offset1;
1629 *row_inc = pixinc(1 - screen_width * 2 -
1630 (fieldmode ? screen_width : 0),
1632 *pix_inc = pixinc(1, ps);
1635 case OMAP_DSS_ROT_270 + 4:
1636 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1638 *offset0 = *offset1 - field_offset * ps;
1640 *offset0 = *offset1;
1641 *row_inc = pixinc(screen_width * (fbh - 1) - 1 -
1642 (fieldmode ? 1 : 0),
1644 *pix_inc = pixinc(-screen_width, ps);
1652 static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width,
1653 u16 height, u16 out_width, u16 out_height,
1654 enum omap_color_mode color_mode)
1657 u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
1659 if (height <= out_height && width <= out_width)
1660 return (unsigned long) pclk;
1662 if (height > out_height) {
1663 struct omap_dss_device *dssdev = dispc_mgr_get_device(channel);
1664 unsigned int ppl = dssdev->panel.timings.x_res;
1666 tmp = pclk * height * out_width;
1667 do_div(tmp, 2 * out_height * ppl);
1670 if (height > 2 * out_height) {
1671 if (ppl == out_width)
1674 tmp = pclk * (height - 2 * out_height) * out_width;
1675 do_div(tmp, 2 * out_height * (ppl - out_width));
1676 fclk = max(fclk, (u32) tmp);
1680 if (width > out_width) {
1682 do_div(tmp, out_width);
1683 fclk = max(fclk, (u32) tmp);
1685 if (color_mode == OMAP_DSS_COLOR_RGB24U)
1692 static unsigned long calc_fclk(enum omap_channel channel, u16 width,
1693 u16 height, u16 out_width, u16 out_height)
1695 unsigned int hf, vf;
1696 unsigned long pclk = dispc_mgr_pclk_rate(channel);
1699 * FIXME how to determine the 'A' factor
1700 * for the no downscaling case ?
1703 if (width > 3 * out_width)
1705 else if (width > 2 * out_width)
1707 else if (width > out_width)
1712 if (height > out_height)
1717 if (cpu_is_omap24xx()) {
1718 if (vf > 1 && hf > 1)
1722 } else if (cpu_is_omap34xx()) {
1723 return pclk * vf * hf;
1726 return DIV_ROUND_UP(pclk, out_width) * width;
1732 static int dispc_ovl_calc_scaling(enum omap_plane plane,
1733 enum omap_channel channel, u16 width, u16 height,
1734 u16 out_width, u16 out_height,
1735 enum omap_color_mode color_mode, bool *five_taps)
1737 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
1738 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
1739 const int maxsinglelinewidth =
1740 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
1741 unsigned long fclk = 0;
1743 if (width == out_width && height == out_height)
1746 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
1749 if (out_width < width / maxdownscale ||
1750 out_width > width * 8)
1753 if (out_height < height / maxdownscale ||
1754 out_height > height * 8)
1757 if (cpu_is_omap24xx()) {
1758 if (width > maxsinglelinewidth)
1759 DSSERR("Cannot scale max input width exceeded");
1761 fclk = calc_fclk(channel, width, height, out_width,
1763 } else if (cpu_is_omap34xx()) {
1764 if (width > (maxsinglelinewidth * 2)) {
1765 DSSERR("Cannot setup scaling");
1766 DSSERR("width exceeds maximum width possible");
1769 fclk = calc_fclk_five_taps(channel, width, height, out_width,
1770 out_height, color_mode);
1771 if (width > maxsinglelinewidth) {
1772 if (height > out_height && height < out_height * 2)
1775 DSSERR("cannot setup scaling with five taps");
1780 fclk = calc_fclk(channel, width, height, out_width,
1783 if (width > maxsinglelinewidth) {
1784 DSSERR("Cannot scale width exceeds max line width");
1787 fclk = calc_fclk(channel, width, height, out_width,
1791 DSSDBG("required fclk rate = %lu Hz\n", fclk);
1792 DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate());
1794 if (!fclk || fclk > dispc_fclk_rate()) {
1795 DSSERR("failed to set up scaling, "
1796 "required fclk rate = %lu Hz, "
1797 "current fclk rate = %lu Hz\n",
1798 fclk, dispc_fclk_rate());
1805 int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
1806 bool ilace, bool replication)
1808 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
1809 bool five_taps = true;
1812 unsigned offset0, offset1;
1815 u16 frame_height = oi->height;
1816 unsigned int field_offset = 0;
1818 enum omap_channel channel;
1820 channel = dispc_ovl_get_channel_out(plane);
1822 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
1823 "%dx%d, cmode %x, rot %d, mir %d, ilace %d chan %d repl %d\n",
1824 plane, oi->paddr, oi->p_uv_addr,
1825 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
1826 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
1827 oi->mirror, ilace, channel, replication);
1832 outw = oi->out_width == 0 ? oi->width : oi->out_width;
1833 outh = oi->out_height == 0 ? oi->height : oi->out_height;
1835 if (ilace && oi->height == outh)
1844 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
1846 oi->height, oi->pos_y, outh);
1849 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
1852 r = dispc_ovl_calc_scaling(plane, channel, oi->width, oi->height,
1853 outw, outh, oi->color_mode,
1858 if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
1859 oi->color_mode == OMAP_DSS_COLOR_UYVY ||
1860 oi->color_mode == OMAP_DSS_COLOR_NV12)
1863 if (ilace && !fieldmode) {
1865 * when downscaling the bottom field may have to start several
1866 * source lines below the top field. Unfortunately ACCUI
1867 * registers will only hold the fractional part of the offset
1868 * so the integer part must be added to the base address of the
1871 if (!oi->height || oi->height == outh)
1874 field_offset = oi->height / outh / 2;
1877 /* Fields are independent but interleaved in memory. */
1881 if (oi->rotation_type == OMAP_DSS_ROT_DMA)
1882 calc_dma_rotation_offset(oi->rotation, oi->mirror,
1883 oi->screen_width, oi->width, frame_height,
1884 oi->color_mode, fieldmode, field_offset,
1885 &offset0, &offset1, &row_inc, &pix_inc);
1887 calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
1888 oi->screen_width, oi->width, frame_height,
1889 oi->color_mode, fieldmode, field_offset,
1890 &offset0, &offset1, &row_inc, &pix_inc);
1892 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
1893 offset0, offset1, row_inc, pix_inc);
1895 dispc_ovl_set_color_mode(plane, oi->color_mode);
1897 dispc_ovl_set_ba0(plane, oi->paddr + offset0);
1898 dispc_ovl_set_ba1(plane, oi->paddr + offset1);
1900 if (OMAP_DSS_COLOR_NV12 == oi->color_mode) {
1901 dispc_ovl_set_ba0_uv(plane, oi->p_uv_addr + offset0);
1902 dispc_ovl_set_ba1_uv(plane, oi->p_uv_addr + offset1);
1906 dispc_ovl_set_row_inc(plane, row_inc);
1907 dispc_ovl_set_pix_inc(plane, pix_inc);
1909 DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, oi->width,
1910 oi->height, outw, outh);
1912 dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y);
1914 dispc_ovl_set_pic_size(plane, oi->width, oi->height);
1916 if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) {
1917 dispc_ovl_set_scaling(plane, oi->width, oi->height,
1919 ilace, five_taps, fieldmode,
1920 oi->color_mode, oi->rotation);
1921 dispc_ovl_set_vid_size(plane, outw, outh);
1922 dispc_ovl_set_vid_color_conv(plane, cconv);
1925 dispc_ovl_set_rotation_attrs(plane, oi->rotation, oi->mirror,
1928 dispc_ovl_set_zorder(plane, oi->zorder);
1929 dispc_ovl_set_pre_mult_alpha(plane, oi->pre_mult_alpha);
1930 dispc_ovl_setup_global_alpha(plane, oi->global_alpha);
1932 dispc_ovl_enable_replication(plane, replication);
1937 int dispc_ovl_enable(enum omap_plane plane, bool enable)
1939 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
1941 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
1946 static void dispc_disable_isr(void *data, u32 mask)
1948 struct completion *compl = data;
1952 static void _enable_lcd_out(enum omap_channel channel, bool enable)
1954 if (channel == OMAP_DSS_CHANNEL_LCD2) {
1955 REG_FLD_MOD(DISPC_CONTROL2, enable ? 1 : 0, 0, 0);
1956 /* flush posted write */
1957 dispc_read_reg(DISPC_CONTROL2);
1959 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 0, 0);
1960 dispc_read_reg(DISPC_CONTROL);
1964 static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
1966 struct completion frame_done_completion;
1971 /* When we disable LCD output, we need to wait until frame is done.
1972 * Otherwise the DSS is still working, and turning off the clocks
1973 * prevents DSS from going to OFF mode */
1974 is_on = channel == OMAP_DSS_CHANNEL_LCD2 ?
1975 REG_GET(DISPC_CONTROL2, 0, 0) :
1976 REG_GET(DISPC_CONTROL, 0, 0);
1978 irq = channel == OMAP_DSS_CHANNEL_LCD2 ? DISPC_IRQ_FRAMEDONE2 :
1979 DISPC_IRQ_FRAMEDONE;
1981 if (!enable && is_on) {
1982 init_completion(&frame_done_completion);
1984 r = omap_dispc_register_isr(dispc_disable_isr,
1985 &frame_done_completion, irq);
1988 DSSERR("failed to register FRAMEDONE isr\n");
1991 _enable_lcd_out(channel, enable);
1993 if (!enable && is_on) {
1994 if (!wait_for_completion_timeout(&frame_done_completion,
1995 msecs_to_jiffies(100)))
1996 DSSERR("timeout waiting for FRAME DONE\n");
1998 r = omap_dispc_unregister_isr(dispc_disable_isr,
1999 &frame_done_completion, irq);
2002 DSSERR("failed to unregister FRAMEDONE isr\n");
2006 static void _enable_digit_out(bool enable)
2008 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
2009 /* flush posted write */
2010 dispc_read_reg(DISPC_CONTROL);
2013 static void dispc_mgr_enable_digit_out(bool enable)
2015 struct completion frame_done_completion;
2016 enum dss_hdmi_venc_clk_source_select src;
2021 if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
2024 src = dss_get_hdmi_venc_clk_source();
2027 unsigned long flags;
2028 /* When we enable digit output, we'll get an extra digit
2029 * sync lost interrupt, that we need to ignore */
2030 spin_lock_irqsave(&dispc.irq_lock, flags);
2031 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
2032 _omap_dispc_set_irqs();
2033 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2036 /* When we disable digit output, we need to wait until fields are done.
2037 * Otherwise the DSS is still working, and turning off the clocks
2038 * prevents DSS from going to OFF mode. And when enabling, we need to
2039 * wait for the extra sync losts */
2040 init_completion(&frame_done_completion);
2042 if (src == DSS_HDMI_M_PCLK && enable == false) {
2043 irq_mask = DISPC_IRQ_FRAMEDONETV;
2046 irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
2047 /* XXX I understand from TRM that we should only wait for the
2048 * current field to complete. But it seems we have to wait for
2053 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
2056 DSSERR("failed to register %x isr\n", irq_mask);
2058 _enable_digit_out(enable);
2060 for (i = 0; i < num_irqs; ++i) {
2061 if (!wait_for_completion_timeout(&frame_done_completion,
2062 msecs_to_jiffies(100)))
2063 DSSERR("timeout waiting for digit out to %s\n",
2064 enable ? "start" : "stop");
2067 r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
2070 DSSERR("failed to unregister %x isr\n", irq_mask);
2073 unsigned long flags;
2074 spin_lock_irqsave(&dispc.irq_lock, flags);
2075 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
2076 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
2077 _omap_dispc_set_irqs();
2078 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2082 bool dispc_mgr_is_enabled(enum omap_channel channel)
2084 if (channel == OMAP_DSS_CHANNEL_LCD)
2085 return !!REG_GET(DISPC_CONTROL, 0, 0);
2086 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2087 return !!REG_GET(DISPC_CONTROL, 1, 1);
2088 else if (channel == OMAP_DSS_CHANNEL_LCD2)
2089 return !!REG_GET(DISPC_CONTROL2, 0, 0);
2094 void dispc_mgr_enable(enum omap_channel channel, bool enable)
2096 if (dispc_mgr_is_lcd(channel))
2097 dispc_mgr_enable_lcd_out(channel, enable);
2098 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2099 dispc_mgr_enable_digit_out(enable);
2104 void dispc_lcd_enable_signal_polarity(bool act_high)
2106 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2109 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2112 void dispc_lcd_enable_signal(bool enable)
2114 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2117 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2120 void dispc_pck_free_enable(bool enable)
2122 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2125 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2128 void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2130 if (channel == OMAP_DSS_CHANNEL_LCD2)
2131 REG_FLD_MOD(DISPC_CONFIG2, enable ? 1 : 0, 16, 16);
2133 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 16, 16);
2137 void dispc_mgr_set_lcd_display_type(enum omap_channel channel,
2138 enum omap_lcd_display_type type)
2143 case OMAP_DSS_LCD_DISPLAY_STN:
2147 case OMAP_DSS_LCD_DISPLAY_TFT:
2156 if (channel == OMAP_DSS_CHANNEL_LCD2)
2157 REG_FLD_MOD(DISPC_CONTROL2, mode, 3, 3);
2159 REG_FLD_MOD(DISPC_CONTROL, mode, 3, 3);
2162 void dispc_set_loadmode(enum omap_dss_load_mode mode)
2164 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2168 static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2170 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2173 static void dispc_mgr_set_trans_key(enum omap_channel ch,
2174 enum omap_dss_trans_key_type type,
2177 if (ch == OMAP_DSS_CHANNEL_LCD)
2178 REG_FLD_MOD(DISPC_CONFIG, type, 11, 11);
2179 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2180 REG_FLD_MOD(DISPC_CONFIG, type, 13, 13);
2181 else /* OMAP_DSS_CHANNEL_LCD2 */
2182 REG_FLD_MOD(DISPC_CONFIG2, type, 11, 11);
2184 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2187 static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2189 if (ch == OMAP_DSS_CHANNEL_LCD)
2190 REG_FLD_MOD(DISPC_CONFIG, enable, 10, 10);
2191 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2192 REG_FLD_MOD(DISPC_CONFIG, enable, 12, 12);
2193 else /* OMAP_DSS_CHANNEL_LCD2 */
2194 REG_FLD_MOD(DISPC_CONFIG2, enable, 10, 10);
2197 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2200 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
2203 if (ch == OMAP_DSS_CHANNEL_LCD)
2204 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2205 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2206 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2209 void dispc_mgr_setup(enum omap_channel channel,
2210 struct omap_overlay_manager_info *info)
2212 dispc_mgr_set_default_color(channel, info->default_color);
2213 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2214 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2215 dispc_mgr_enable_alpha_fixed_zorder(channel,
2216 info->partial_alpha_enabled);
2217 if (dss_has_feature(FEAT_CPR)) {
2218 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2219 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2223 void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2227 switch (data_lines) {
2245 if (channel == OMAP_DSS_CHANNEL_LCD2)
2246 REG_FLD_MOD(DISPC_CONTROL2, code, 9, 8);
2248 REG_FLD_MOD(DISPC_CONTROL, code, 9, 8);
2251 void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
2257 case DSS_IO_PAD_MODE_RESET:
2261 case DSS_IO_PAD_MODE_RFBI:
2265 case DSS_IO_PAD_MODE_BYPASS:
2274 l = dispc_read_reg(DISPC_CONTROL);
2275 l = FLD_MOD(l, gpout0, 15, 15);
2276 l = FLD_MOD(l, gpout1, 16, 16);
2277 dispc_write_reg(DISPC_CONTROL, l);
2280 void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2282 if (channel == OMAP_DSS_CHANNEL_LCD2)
2283 REG_FLD_MOD(DISPC_CONTROL2, enable, 11, 11);
2285 REG_FLD_MOD(DISPC_CONTROL, enable, 11, 11);
2288 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2289 int vsw, int vfp, int vbp)
2291 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2292 if (hsw < 1 || hsw > 64 ||
2293 hfp < 1 || hfp > 256 ||
2294 hbp < 1 || hbp > 256 ||
2295 vsw < 1 || vsw > 64 ||
2296 vfp < 0 || vfp > 255 ||
2297 vbp < 0 || vbp > 255)
2300 if (hsw < 1 || hsw > 256 ||
2301 hfp < 1 || hfp > 4096 ||
2302 hbp < 1 || hbp > 4096 ||
2303 vsw < 1 || vsw > 256 ||
2304 vfp < 0 || vfp > 4095 ||
2305 vbp < 0 || vbp > 4095)
2312 bool dispc_lcd_timings_ok(struct omap_video_timings *timings)
2314 return _dispc_lcd_timings_ok(timings->hsw, timings->hfp,
2315 timings->hbp, timings->vsw,
2316 timings->vfp, timings->vbp);
2319 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
2320 int hfp, int hbp, int vsw, int vfp, int vbp)
2322 u32 timing_h, timing_v;
2324 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2325 timing_h = FLD_VAL(hsw-1, 5, 0) | FLD_VAL(hfp-1, 15, 8) |
2326 FLD_VAL(hbp-1, 27, 20);
2328 timing_v = FLD_VAL(vsw-1, 5, 0) | FLD_VAL(vfp, 15, 8) |
2329 FLD_VAL(vbp, 27, 20);
2331 timing_h = FLD_VAL(hsw-1, 7, 0) | FLD_VAL(hfp-1, 19, 8) |
2332 FLD_VAL(hbp-1, 31, 20);
2334 timing_v = FLD_VAL(vsw-1, 7, 0) | FLD_VAL(vfp, 19, 8) |
2335 FLD_VAL(vbp, 31, 20);
2338 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2339 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
2342 /* change name to mode? */
2343 void dispc_mgr_set_lcd_timings(enum omap_channel channel,
2344 struct omap_video_timings *timings)
2346 unsigned xtot, ytot;
2347 unsigned long ht, vt;
2349 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
2350 timings->hbp, timings->vsw,
2351 timings->vfp, timings->vbp))
2354 _dispc_mgr_set_lcd_timings(channel, timings->hsw, timings->hfp,
2355 timings->hbp, timings->vsw, timings->vfp,
2358 dispc_mgr_set_lcd_size(channel, timings->x_res, timings->y_res);
2360 xtot = timings->x_res + timings->hfp + timings->hsw + timings->hbp;
2361 ytot = timings->y_res + timings->vfp + timings->vsw + timings->vbp;
2363 ht = (timings->pixel_clock * 1000) / xtot;
2364 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2366 DSSDBG("channel %d xres %u yres %u\n", channel, timings->x_res,
2368 DSSDBG("pck %u\n", timings->pixel_clock);
2369 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2370 timings->hsw, timings->hfp, timings->hbp,
2371 timings->vsw, timings->vfp, timings->vbp);
2373 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2376 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
2379 BUG_ON(lck_div < 1);
2380 BUG_ON(pck_div < 1);
2382 dispc_write_reg(DISPC_DIVISORo(channel),
2383 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
2386 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
2390 l = dispc_read_reg(DISPC_DIVISORo(channel));
2391 *lck_div = FLD_GET(l, 23, 16);
2392 *pck_div = FLD_GET(l, 7, 0);
2395 unsigned long dispc_fclk_rate(void)
2397 struct platform_device *dsidev;
2398 unsigned long r = 0;
2400 switch (dss_get_dispc_clk_source()) {
2401 case OMAP_DSS_CLK_SRC_FCK:
2402 r = clk_get_rate(dispc.dss_clk);
2404 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2405 dsidev = dsi_get_dsidev_from_id(0);
2406 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2408 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2409 dsidev = dsi_get_dsidev_from_id(1);
2410 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2419 unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
2421 struct platform_device *dsidev;
2426 l = dispc_read_reg(DISPC_DIVISORo(channel));
2428 lcd = FLD_GET(l, 23, 16);
2430 switch (dss_get_lcd_clk_source(channel)) {
2431 case OMAP_DSS_CLK_SRC_FCK:
2432 r = clk_get_rate(dispc.dss_clk);
2434 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2435 dsidev = dsi_get_dsidev_from_id(0);
2436 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2438 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2439 dsidev = dsi_get_dsidev_from_id(1);
2440 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2449 unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
2453 if (dispc_mgr_is_lcd(channel)) {
2457 l = dispc_read_reg(DISPC_DIVISORo(channel));
2459 pcd = FLD_GET(l, 7, 0);
2461 r = dispc_mgr_lclk_rate(channel);
2465 struct omap_dss_device *dssdev =
2466 dispc_mgr_get_device(channel);
2468 switch (dssdev->type) {
2469 case OMAP_DISPLAY_TYPE_VENC:
2470 return venc_get_pixel_clock();
2471 case OMAP_DISPLAY_TYPE_HDMI:
2472 return hdmi_get_pixel_clock();
2479 void dispc_dump_clocks(struct seq_file *s)
2483 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
2484 enum omap_dss_clk_source lcd_clk_src;
2486 if (dispc_runtime_get())
2489 seq_printf(s, "- DISPC -\n");
2491 seq_printf(s, "dispc fclk source = %s (%s)\n",
2492 dss_get_generic_clk_source_name(dispc_clk_src),
2493 dss_feat_get_clk_source_name(dispc_clk_src));
2495 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
2497 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
2498 seq_printf(s, "- DISPC-CORE-CLK -\n");
2499 l = dispc_read_reg(DISPC_DIVISOR);
2500 lcd = FLD_GET(l, 23, 16);
2502 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2503 (dispc_fclk_rate()/lcd), lcd);
2505 seq_printf(s, "- LCD1 -\n");
2507 lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD);
2509 seq_printf(s, "lcd1_clk source = %s (%s)\n",
2510 dss_get_generic_clk_source_name(lcd_clk_src),
2511 dss_feat_get_clk_source_name(lcd_clk_src));
2513 dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD, &lcd, &pcd);
2515 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2516 dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD), lcd);
2517 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2518 dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD), pcd);
2519 if (dss_has_feature(FEAT_MGR_LCD2)) {
2520 seq_printf(s, "- LCD2 -\n");
2522 lcd_clk_src = dss_get_lcd_clk_source(OMAP_DSS_CHANNEL_LCD2);
2524 seq_printf(s, "lcd2_clk source = %s (%s)\n",
2525 dss_get_generic_clk_source_name(lcd_clk_src),
2526 dss_feat_get_clk_source_name(lcd_clk_src));
2528 dispc_mgr_get_lcd_divisor(OMAP_DSS_CHANNEL_LCD2, &lcd, &pcd);
2530 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2531 dispc_mgr_lclk_rate(OMAP_DSS_CHANNEL_LCD2), lcd);
2532 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2533 dispc_mgr_pclk_rate(OMAP_DSS_CHANNEL_LCD2), pcd);
2536 dispc_runtime_put();
2539 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
2540 void dispc_dump_irqs(struct seq_file *s)
2542 unsigned long flags;
2543 struct dispc_irq_stats stats;
2545 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
2547 stats = dispc.irq_stats;
2548 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
2549 dispc.irq_stats.last_reset = jiffies;
2551 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
2553 seq_printf(s, "period %u ms\n",
2554 jiffies_to_msecs(jiffies - stats.last_reset));
2556 seq_printf(s, "irqs %d\n", stats.irq_count);
2558 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
2564 PIS(ACBIAS_COUNT_STAT);
2566 PIS(GFX_FIFO_UNDERFLOW);
2568 PIS(PAL_GAMMA_MASK);
2570 PIS(VID1_FIFO_UNDERFLOW);
2572 PIS(VID2_FIFO_UNDERFLOW);
2574 if (dss_feat_get_num_ovls() > 3) {
2575 PIS(VID3_FIFO_UNDERFLOW);
2579 PIS(SYNC_LOST_DIGIT);
2581 if (dss_has_feature(FEAT_MGR_LCD2)) {
2584 PIS(ACBIAS_COUNT_STAT2);
2591 void dispc_dump_regs(struct seq_file *s)
2594 const char *mgr_names[] = {
2595 [OMAP_DSS_CHANNEL_LCD] = "LCD",
2596 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
2597 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
2599 const char *ovl_names[] = {
2600 [OMAP_DSS_GFX] = "GFX",
2601 [OMAP_DSS_VIDEO1] = "VID1",
2602 [OMAP_DSS_VIDEO2] = "VID2",
2603 [OMAP_DSS_VIDEO3] = "VID3",
2605 const char **p_names;
2607 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
2609 if (dispc_runtime_get())
2612 /* DISPC common registers */
2613 DUMPREG(DISPC_REVISION);
2614 DUMPREG(DISPC_SYSCONFIG);
2615 DUMPREG(DISPC_SYSSTATUS);
2616 DUMPREG(DISPC_IRQSTATUS);
2617 DUMPREG(DISPC_IRQENABLE);
2618 DUMPREG(DISPC_CONTROL);
2619 DUMPREG(DISPC_CONFIG);
2620 DUMPREG(DISPC_CAPABLE);
2621 DUMPREG(DISPC_LINE_STATUS);
2622 DUMPREG(DISPC_LINE_NUMBER);
2623 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
2624 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
2625 DUMPREG(DISPC_GLOBAL_ALPHA);
2626 if (dss_has_feature(FEAT_MGR_LCD2)) {
2627 DUMPREG(DISPC_CONTROL2);
2628 DUMPREG(DISPC_CONFIG2);
2633 #define DISPC_REG(i, name) name(i)
2634 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
2635 48 - strlen(#r) - strlen(p_names[i]), " ", \
2636 dispc_read_reg(DISPC_REG(i, r)))
2638 p_names = mgr_names;
2640 /* DISPC channel specific registers */
2641 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
2642 DUMPREG(i, DISPC_DEFAULT_COLOR);
2643 DUMPREG(i, DISPC_TRANS_COLOR);
2644 DUMPREG(i, DISPC_SIZE_MGR);
2646 if (i == OMAP_DSS_CHANNEL_DIGIT)
2649 DUMPREG(i, DISPC_DEFAULT_COLOR);
2650 DUMPREG(i, DISPC_TRANS_COLOR);
2651 DUMPREG(i, DISPC_TIMING_H);
2652 DUMPREG(i, DISPC_TIMING_V);
2653 DUMPREG(i, DISPC_POL_FREQ);
2654 DUMPREG(i, DISPC_DIVISORo);
2655 DUMPREG(i, DISPC_SIZE_MGR);
2657 DUMPREG(i, DISPC_DATA_CYCLE1);
2658 DUMPREG(i, DISPC_DATA_CYCLE2);
2659 DUMPREG(i, DISPC_DATA_CYCLE3);
2661 if (dss_has_feature(FEAT_CPR)) {
2662 DUMPREG(i, DISPC_CPR_COEF_R);
2663 DUMPREG(i, DISPC_CPR_COEF_G);
2664 DUMPREG(i, DISPC_CPR_COEF_B);
2668 p_names = ovl_names;
2670 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
2671 DUMPREG(i, DISPC_OVL_BA0);
2672 DUMPREG(i, DISPC_OVL_BA1);
2673 DUMPREG(i, DISPC_OVL_POSITION);
2674 DUMPREG(i, DISPC_OVL_SIZE);
2675 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
2676 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
2677 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
2678 DUMPREG(i, DISPC_OVL_ROW_INC);
2679 DUMPREG(i, DISPC_OVL_PIXEL_INC);
2680 if (dss_has_feature(FEAT_PRELOAD))
2681 DUMPREG(i, DISPC_OVL_PRELOAD);
2683 if (i == OMAP_DSS_GFX) {
2684 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
2685 DUMPREG(i, DISPC_OVL_TABLE_BA);
2689 DUMPREG(i, DISPC_OVL_FIR);
2690 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
2691 DUMPREG(i, DISPC_OVL_ACCU0);
2692 DUMPREG(i, DISPC_OVL_ACCU1);
2693 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
2694 DUMPREG(i, DISPC_OVL_BA0_UV);
2695 DUMPREG(i, DISPC_OVL_BA1_UV);
2696 DUMPREG(i, DISPC_OVL_FIR2);
2697 DUMPREG(i, DISPC_OVL_ACCU2_0);
2698 DUMPREG(i, DISPC_OVL_ACCU2_1);
2700 if (dss_has_feature(FEAT_ATTR2))
2701 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
2702 if (dss_has_feature(FEAT_PRELOAD))
2703 DUMPREG(i, DISPC_OVL_PRELOAD);
2709 #define DISPC_REG(plane, name, i) name(plane, i)
2710 #define DUMPREG(plane, name, i) \
2711 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
2712 46 - strlen(#name) - strlen(p_names[plane]), " ", \
2713 dispc_read_reg(DISPC_REG(plane, name, i)))
2715 /* Video pipeline coefficient registers */
2717 /* start from OMAP_DSS_VIDEO1 */
2718 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
2719 for (j = 0; j < 8; j++)
2720 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
2722 for (j = 0; j < 8; j++)
2723 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
2725 for (j = 0; j < 5; j++)
2726 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
2728 if (dss_has_feature(FEAT_FIR_COEF_V)) {
2729 for (j = 0; j < 8; j++)
2730 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
2733 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
2734 for (j = 0; j < 8; j++)
2735 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
2737 for (j = 0; j < 8; j++)
2738 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
2740 for (j = 0; j < 8; j++)
2741 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
2745 dispc_runtime_put();
2751 static void _dispc_mgr_set_pol_freq(enum omap_channel channel, bool onoff,
2752 bool rf, bool ieo, bool ipc, bool ihs, bool ivs, u8 acbi,
2757 DSSDBG("onoff %d rf %d ieo %d ipc %d ihs %d ivs %d acbi %d acb %d\n",
2758 onoff, rf, ieo, ipc, ihs, ivs, acbi, acb);
2760 l |= FLD_VAL(onoff, 17, 17);
2761 l |= FLD_VAL(rf, 16, 16);
2762 l |= FLD_VAL(ieo, 15, 15);
2763 l |= FLD_VAL(ipc, 14, 14);
2764 l |= FLD_VAL(ihs, 13, 13);
2765 l |= FLD_VAL(ivs, 12, 12);
2766 l |= FLD_VAL(acbi, 11, 8);
2767 l |= FLD_VAL(acb, 7, 0);
2769 dispc_write_reg(DISPC_POL_FREQ(channel), l);
2772 void dispc_mgr_set_pol_freq(enum omap_channel channel,
2773 enum omap_panel_config config, u8 acbi, u8 acb)
2775 _dispc_mgr_set_pol_freq(channel, (config & OMAP_DSS_LCD_ONOFF) != 0,
2776 (config & OMAP_DSS_LCD_RF) != 0,
2777 (config & OMAP_DSS_LCD_IEO) != 0,
2778 (config & OMAP_DSS_LCD_IPC) != 0,
2779 (config & OMAP_DSS_LCD_IHS) != 0,
2780 (config & OMAP_DSS_LCD_IVS) != 0,
2784 /* with fck as input clock rate, find dispc dividers that produce req_pck */
2785 void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
2786 struct dispc_clock_info *cinfo)
2788 u16 pcd_min, pcd_max;
2789 unsigned long best_pck;
2790 u16 best_ld, cur_ld;
2791 u16 best_pd, cur_pd;
2793 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
2794 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
2803 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
2804 unsigned long lck = fck / cur_ld;
2806 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
2807 unsigned long pck = lck / cur_pd;
2808 long old_delta = abs(best_pck - req_pck);
2809 long new_delta = abs(pck - req_pck);
2811 if (best_pck == 0 || new_delta < old_delta) {
2824 if (lck / pcd_min < req_pck)
2829 cinfo->lck_div = best_ld;
2830 cinfo->pck_div = best_pd;
2831 cinfo->lck = fck / cinfo->lck_div;
2832 cinfo->pck = cinfo->lck / cinfo->pck_div;
2835 /* calculate clock rates using dividers in cinfo */
2836 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
2837 struct dispc_clock_info *cinfo)
2839 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
2841 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
2844 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
2845 cinfo->pck = cinfo->lck / cinfo->pck_div;
2850 int dispc_mgr_set_clock_div(enum omap_channel channel,
2851 struct dispc_clock_info *cinfo)
2853 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
2854 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
2856 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
2861 int dispc_mgr_get_clock_div(enum omap_channel channel,
2862 struct dispc_clock_info *cinfo)
2866 fck = dispc_fclk_rate();
2868 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
2869 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
2871 cinfo->lck = fck / cinfo->lck_div;
2872 cinfo->pck = cinfo->lck / cinfo->pck_div;
2877 /* dispc.irq_lock has to be locked by the caller */
2878 static void _omap_dispc_set_irqs(void)
2883 struct omap_dispc_isr_data *isr_data;
2885 mask = dispc.irq_error_mask;
2887 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2888 isr_data = &dispc.registered_isr[i];
2890 if (isr_data->isr == NULL)
2893 mask |= isr_data->mask;
2896 old_mask = dispc_read_reg(DISPC_IRQENABLE);
2897 /* clear the irqstatus for newly enabled irqs */
2898 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
2900 dispc_write_reg(DISPC_IRQENABLE, mask);
2903 int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
2907 unsigned long flags;
2908 struct omap_dispc_isr_data *isr_data;
2913 spin_lock_irqsave(&dispc.irq_lock, flags);
2915 /* check for duplicate entry */
2916 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2917 isr_data = &dispc.registered_isr[i];
2918 if (isr_data->isr == isr && isr_data->arg == arg &&
2919 isr_data->mask == mask) {
2928 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2929 isr_data = &dispc.registered_isr[i];
2931 if (isr_data->isr != NULL)
2934 isr_data->isr = isr;
2935 isr_data->arg = arg;
2936 isr_data->mask = mask;
2945 _omap_dispc_set_irqs();
2947 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2951 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2955 EXPORT_SYMBOL(omap_dispc_register_isr);
2957 int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
2960 unsigned long flags;
2962 struct omap_dispc_isr_data *isr_data;
2964 spin_lock_irqsave(&dispc.irq_lock, flags);
2966 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
2967 isr_data = &dispc.registered_isr[i];
2968 if (isr_data->isr != isr || isr_data->arg != arg ||
2969 isr_data->mask != mask)
2972 /* found the correct isr */
2974 isr_data->isr = NULL;
2975 isr_data->arg = NULL;
2983 _omap_dispc_set_irqs();
2985 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2989 EXPORT_SYMBOL(omap_dispc_unregister_isr);
2992 static void print_irq_status(u32 status)
2994 if ((status & dispc.irq_error_mask) == 0)
2997 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
3000 if (status & DISPC_IRQ_##x) \
3002 PIS(GFX_FIFO_UNDERFLOW);
3004 PIS(VID1_FIFO_UNDERFLOW);
3005 PIS(VID2_FIFO_UNDERFLOW);
3006 if (dss_feat_get_num_ovls() > 3)
3007 PIS(VID3_FIFO_UNDERFLOW);
3009 PIS(SYNC_LOST_DIGIT);
3010 if (dss_has_feature(FEAT_MGR_LCD2))
3018 /* Called from dss.c. Note that we don't touch clocks here,
3019 * but we presume they are on because we got an IRQ. However,
3020 * an irq handler may turn the clocks off, so we may not have
3021 * clock later in the function. */
3022 static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
3025 u32 irqstatus, irqenable;
3026 u32 handledirqs = 0;
3027 u32 unhandled_errors;
3028 struct omap_dispc_isr_data *isr_data;
3029 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3031 spin_lock(&dispc.irq_lock);
3033 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
3034 irqenable = dispc_read_reg(DISPC_IRQENABLE);
3036 /* IRQ is not for us */
3037 if (!(irqstatus & irqenable)) {
3038 spin_unlock(&dispc.irq_lock);
3042 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3043 spin_lock(&dispc.irq_stats_lock);
3044 dispc.irq_stats.irq_count++;
3045 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3046 spin_unlock(&dispc.irq_stats_lock);
3051 print_irq_status(irqstatus);
3053 /* Ack the interrupt. Do it here before clocks are possibly turned
3055 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
3056 /* flush posted write */
3057 dispc_read_reg(DISPC_IRQSTATUS);
3059 /* make a copy and unlock, so that isrs can unregister
3061 memcpy(registered_isr, dispc.registered_isr,
3062 sizeof(registered_isr));
3064 spin_unlock(&dispc.irq_lock);
3066 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3067 isr_data = ®istered_isr[i];
3072 if (isr_data->mask & irqstatus) {
3073 isr_data->isr(isr_data->arg, irqstatus);
3074 handledirqs |= isr_data->mask;
3078 spin_lock(&dispc.irq_lock);
3080 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3082 if (unhandled_errors) {
3083 dispc.error_irqs |= unhandled_errors;
3085 dispc.irq_error_mask &= ~unhandled_errors;
3086 _omap_dispc_set_irqs();
3088 schedule_work(&dispc.error_work);
3091 spin_unlock(&dispc.irq_lock);
3096 static void dispc_error_worker(struct work_struct *work)
3100 unsigned long flags;
3101 static const unsigned fifo_underflow_bits[] = {
3102 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3103 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3104 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
3105 DISPC_IRQ_VID3_FIFO_UNDERFLOW,
3108 static const unsigned sync_lost_bits[] = {
3109 DISPC_IRQ_SYNC_LOST,
3110 DISPC_IRQ_SYNC_LOST_DIGIT,
3111 DISPC_IRQ_SYNC_LOST2,
3114 spin_lock_irqsave(&dispc.irq_lock, flags);
3115 errors = dispc.error_irqs;
3116 dispc.error_irqs = 0;
3117 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3119 dispc_runtime_get();
3121 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3122 struct omap_overlay *ovl;
3125 ovl = omap_dss_get_overlay(i);
3126 bit = fifo_underflow_bits[i];
3129 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3131 dispc_ovl_enable(ovl->id, false);
3132 dispc_mgr_go(ovl->manager->id);
3137 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3138 struct omap_overlay_manager *mgr;
3141 mgr = omap_dss_get_overlay_manager(i);
3142 bit = sync_lost_bits[i];
3145 struct omap_dss_device *dssdev = mgr->device;
3148 DSSERR("SYNC_LOST on channel %s, restarting the output "
3149 "with video overlays disabled\n",
3152 enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
3153 dssdev->driver->disable(dssdev);
3155 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3156 struct omap_overlay *ovl;
3157 ovl = omap_dss_get_overlay(i);
3159 if (ovl->id != OMAP_DSS_GFX &&
3160 ovl->manager == mgr)
3161 dispc_ovl_enable(ovl->id, false);
3164 dispc_mgr_go(mgr->id);
3168 dssdev->driver->enable(dssdev);
3172 if (errors & DISPC_IRQ_OCP_ERR) {
3173 DSSERR("OCP_ERR\n");
3174 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3175 struct omap_overlay_manager *mgr;
3176 mgr = omap_dss_get_overlay_manager(i);
3177 if (mgr->device && mgr->device->driver)
3178 mgr->device->driver->disable(mgr->device);
3182 spin_lock_irqsave(&dispc.irq_lock, flags);
3183 dispc.irq_error_mask |= errors;
3184 _omap_dispc_set_irqs();
3185 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3187 dispc_runtime_put();
3190 int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3192 void dispc_irq_wait_handler(void *data, u32 mask)
3194 complete((struct completion *)data);
3198 DECLARE_COMPLETION_ONSTACK(completion);
3200 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3206 timeout = wait_for_completion_timeout(&completion, timeout);
3208 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3213 if (timeout == -ERESTARTSYS)
3214 return -ERESTARTSYS;
3219 int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3220 unsigned long timeout)
3222 void dispc_irq_wait_handler(void *data, u32 mask)
3224 complete((struct completion *)data);
3228 DECLARE_COMPLETION_ONSTACK(completion);
3230 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3236 timeout = wait_for_completion_interruptible_timeout(&completion,
3239 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3244 if (timeout == -ERESTARTSYS)
3245 return -ERESTARTSYS;
3250 #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
3251 void dispc_fake_vsync_irq(void)
3253 u32 irqstatus = DISPC_IRQ_VSYNC;
3256 WARN_ON(!in_interrupt());
3258 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3259 struct omap_dispc_isr_data *isr_data;
3260 isr_data = &dispc.registered_isr[i];
3265 if (isr_data->mask & irqstatus)
3266 isr_data->isr(isr_data->arg, irqstatus);
3271 static void _omap_dispc_initialize_irq(void)
3273 unsigned long flags;
3275 spin_lock_irqsave(&dispc.irq_lock, flags);
3277 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3279 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
3280 if (dss_has_feature(FEAT_MGR_LCD2))
3281 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
3282 if (dss_feat_get_num_ovls() > 3)
3283 dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
3285 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3287 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3289 _omap_dispc_set_irqs();
3291 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3294 void dispc_enable_sidle(void)
3296 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3299 void dispc_disable_sidle(void)
3301 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3304 static void _omap_dispc_initial_config(void)
3308 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3309 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3310 l = dispc_read_reg(DISPC_DIVISOR);
3311 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3312 l = FLD_MOD(l, 1, 0, 0);
3313 l = FLD_MOD(l, 1, 23, 16);
3314 dispc_write_reg(DISPC_DIVISOR, l);
3318 if (dss_has_feature(FEAT_FUNCGATED))
3319 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3321 /* L3 firewall setting: enable access to OCM RAM */
3322 /* XXX this should be somewhere in plat-omap */
3323 if (cpu_is_omap24xx())
3324 __raw_writel(0x402000b0, OMAP2_L3_IO_ADDRESS(0x680050a0));
3326 _dispc_setup_color_conv_coef();
3328 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3330 dispc_read_plane_fifo_sizes();
3332 dispc_configure_burst_sizes();
3334 dispc_ovl_enable_zorder_planes();
3337 /* DISPC HW IP initialisation */
3338 static int omap_dispchw_probe(struct platform_device *pdev)
3342 struct resource *dispc_mem;
3347 spin_lock_init(&dispc.irq_lock);
3349 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3350 spin_lock_init(&dispc.irq_stats_lock);
3351 dispc.irq_stats.last_reset = jiffies;
3354 INIT_WORK(&dispc.error_work, dispc_error_worker);
3356 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3358 DSSERR("can't get IORESOURCE_MEM DISPC\n");
3362 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3363 resource_size(dispc_mem));
3365 DSSERR("can't ioremap DISPC\n");
3369 dispc.irq = platform_get_irq(dispc.pdev, 0);
3370 if (dispc.irq < 0) {
3371 DSSERR("platform_get_irq failed\n");
3375 r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
3376 IRQF_SHARED, "OMAP DISPC", dispc.pdev);
3378 DSSERR("request_irq failed\n");
3382 clk = clk_get(&pdev->dev, "fck");
3384 DSSERR("can't get fck\n");
3389 dispc.dss_clk = clk;
3391 pm_runtime_enable(&pdev->dev);
3393 r = dispc_runtime_get();
3395 goto err_runtime_get;
3397 _omap_dispc_initial_config();
3399 _omap_dispc_initialize_irq();
3401 rev = dispc_read_reg(DISPC_REVISION);
3402 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
3403 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3405 dispc_runtime_put();
3410 pm_runtime_disable(&pdev->dev);
3411 clk_put(dispc.dss_clk);
3415 static int omap_dispchw_remove(struct platform_device *pdev)
3417 pm_runtime_disable(&pdev->dev);
3419 clk_put(dispc.dss_clk);
3424 static int dispc_runtime_suspend(struct device *dev)
3426 dispc_save_context();
3432 static int dispc_runtime_resume(struct device *dev)
3436 r = dss_runtime_get();
3440 dispc_restore_context();
3445 static const struct dev_pm_ops dispc_pm_ops = {
3446 .runtime_suspend = dispc_runtime_suspend,
3447 .runtime_resume = dispc_runtime_resume,
3450 static struct platform_driver omap_dispchw_driver = {
3451 .probe = omap_dispchw_probe,
3452 .remove = omap_dispchw_remove,
3454 .name = "omapdss_dispc",
3455 .owner = THIS_MODULE,
3456 .pm = &dispc_pm_ops,
3460 int dispc_init_platform_driver(void)
3462 return platform_driver_register(&omap_dispchw_driver);
3465 void dispc_uninit_platform_driver(void)
3467 return platform_driver_unregister(&omap_dispchw_driver);