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 enum mgr_reg_fields {
123 DISPC_MGR_FLD_ENABLE,
124 DISPC_MGR_FLD_STNTFT,
126 DISPC_MGR_FLD_TFTDATALINES,
127 DISPC_MGR_FLD_STALLMODE,
128 DISPC_MGR_FLD_TCKENABLE,
129 DISPC_MGR_FLD_TCKSELECTION,
131 DISPC_MGR_FLD_FIFOHANDCHECK,
132 /* used to maintain a count of the above fields */
136 static const struct {
141 struct reg_field reg_desc[DISPC_MGR_FLD_NUM];
143 [OMAP_DSS_CHANNEL_LCD] = {
145 .vsync_irq = DISPC_IRQ_VSYNC,
146 .framedone_irq = DISPC_IRQ_FRAMEDONE,
147 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
149 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
150 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
151 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
152 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
153 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
154 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
155 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
156 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
157 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
160 [OMAP_DSS_CHANNEL_DIGIT] = {
162 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
164 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
166 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
167 [DISPC_MGR_FLD_STNTFT] = { },
168 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
169 [DISPC_MGR_FLD_TFTDATALINES] = { },
170 [DISPC_MGR_FLD_STALLMODE] = { },
171 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
172 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
173 [DISPC_MGR_FLD_CPR] = { },
174 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
177 [OMAP_DSS_CHANNEL_LCD2] = {
179 .vsync_irq = DISPC_IRQ_VSYNC2,
180 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
181 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
183 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
184 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
185 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
186 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
187 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
188 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
189 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
190 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
191 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
194 [OMAP_DSS_CHANNEL_LCD3] = {
196 .vsync_irq = DISPC_IRQ_VSYNC3,
197 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
198 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
200 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
201 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
202 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
203 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
204 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
205 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
206 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
207 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
208 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
213 static void _omap_dispc_set_irqs(void);
215 static inline void dispc_write_reg(const u16 idx, u32 val)
217 __raw_writel(val, dispc.base + idx);
220 static inline u32 dispc_read_reg(const u16 idx)
222 return __raw_readl(dispc.base + idx);
225 static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
227 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
228 return REG_GET(rfld.reg, rfld.high, rfld.low);
231 static void mgr_fld_write(enum omap_channel channel,
232 enum mgr_reg_fields regfld, int val) {
233 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
234 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
238 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
240 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
242 static void dispc_save_context(void)
246 DSSDBG("dispc_save_context\n");
252 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
253 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
255 if (dss_has_feature(FEAT_MGR_LCD2)) {
259 if (dss_has_feature(FEAT_MGR_LCD3)) {
264 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
265 SR(DEFAULT_COLOR(i));
268 if (i == OMAP_DSS_CHANNEL_DIGIT)
279 if (dss_has_feature(FEAT_CPR)) {
286 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
291 SR(OVL_ATTRIBUTES(i));
292 SR(OVL_FIFO_THRESHOLD(i));
294 SR(OVL_PIXEL_INC(i));
295 if (dss_has_feature(FEAT_PRELOAD))
297 if (i == OMAP_DSS_GFX) {
298 SR(OVL_WINDOW_SKIP(i));
303 SR(OVL_PICTURE_SIZE(i));
307 for (j = 0; j < 8; j++)
308 SR(OVL_FIR_COEF_H(i, j));
310 for (j = 0; j < 8; j++)
311 SR(OVL_FIR_COEF_HV(i, j));
313 for (j = 0; j < 5; j++)
314 SR(OVL_CONV_COEF(i, j));
316 if (dss_has_feature(FEAT_FIR_COEF_V)) {
317 for (j = 0; j < 8; j++)
318 SR(OVL_FIR_COEF_V(i, j));
321 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
328 for (j = 0; j < 8; j++)
329 SR(OVL_FIR_COEF_H2(i, j));
331 for (j = 0; j < 8; j++)
332 SR(OVL_FIR_COEF_HV2(i, j));
334 for (j = 0; j < 8; j++)
335 SR(OVL_FIR_COEF_V2(i, j));
337 if (dss_has_feature(FEAT_ATTR2))
338 SR(OVL_ATTRIBUTES2(i));
341 if (dss_has_feature(FEAT_CORE_CLK_DIV))
344 dispc.ctx_loss_cnt = dss_get_ctx_loss_count(&dispc.pdev->dev);
345 dispc.ctx_valid = true;
347 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
350 static void dispc_restore_context(void)
354 DSSDBG("dispc_restore_context\n");
356 if (!dispc.ctx_valid)
359 ctx = dss_get_ctx_loss_count(&dispc.pdev->dev);
361 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
364 DSSDBG("ctx_loss_count: saved %d, current %d\n",
365 dispc.ctx_loss_cnt, ctx);
371 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
372 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
374 if (dss_has_feature(FEAT_MGR_LCD2))
376 if (dss_has_feature(FEAT_MGR_LCD3))
379 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
380 RR(DEFAULT_COLOR(i));
383 if (i == OMAP_DSS_CHANNEL_DIGIT)
394 if (dss_has_feature(FEAT_CPR)) {
401 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
406 RR(OVL_ATTRIBUTES(i));
407 RR(OVL_FIFO_THRESHOLD(i));
409 RR(OVL_PIXEL_INC(i));
410 if (dss_has_feature(FEAT_PRELOAD))
412 if (i == OMAP_DSS_GFX) {
413 RR(OVL_WINDOW_SKIP(i));
418 RR(OVL_PICTURE_SIZE(i));
422 for (j = 0; j < 8; j++)
423 RR(OVL_FIR_COEF_H(i, j));
425 for (j = 0; j < 8; j++)
426 RR(OVL_FIR_COEF_HV(i, j));
428 for (j = 0; j < 5; j++)
429 RR(OVL_CONV_COEF(i, j));
431 if (dss_has_feature(FEAT_FIR_COEF_V)) {
432 for (j = 0; j < 8; j++)
433 RR(OVL_FIR_COEF_V(i, j));
436 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
443 for (j = 0; j < 8; j++)
444 RR(OVL_FIR_COEF_H2(i, j));
446 for (j = 0; j < 8; j++)
447 RR(OVL_FIR_COEF_HV2(i, j));
449 for (j = 0; j < 8; j++)
450 RR(OVL_FIR_COEF_V2(i, j));
452 if (dss_has_feature(FEAT_ATTR2))
453 RR(OVL_ATTRIBUTES2(i));
456 if (dss_has_feature(FEAT_CORE_CLK_DIV))
459 /* enable last, because LCD & DIGIT enable are here */
461 if (dss_has_feature(FEAT_MGR_LCD2))
463 if (dss_has_feature(FEAT_MGR_LCD3))
465 /* clear spurious SYNC_LOST_DIGIT interrupts */
466 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
469 * enable last so IRQs won't trigger before
470 * the context is fully restored
474 DSSDBG("context restored\n");
480 int dispc_runtime_get(void)
484 DSSDBG("dispc_runtime_get\n");
486 r = pm_runtime_get_sync(&dispc.pdev->dev);
488 return r < 0 ? r : 0;
491 void dispc_runtime_put(void)
495 DSSDBG("dispc_runtime_put\n");
497 r = pm_runtime_put_sync(&dispc.pdev->dev);
498 WARN_ON(r < 0 && r != -ENOSYS);
501 u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
503 return mgr_desc[channel].vsync_irq;
506 u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
508 return mgr_desc[channel].framedone_irq;
511 bool dispc_mgr_go_busy(enum omap_channel channel)
513 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
516 void dispc_mgr_go(enum omap_channel channel)
518 bool enable_bit, go_bit;
520 /* if the channel is not enabled, we don't need GO */
521 enable_bit = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE) == 1;
526 go_bit = mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
529 DSSERR("GO bit not down for channel %d\n", channel);
533 DSSDBG("GO %s\n", mgr_desc[channel].name);
535 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
538 static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
540 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
543 static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
545 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
548 static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
550 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
553 static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
555 BUG_ON(plane == OMAP_DSS_GFX);
557 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
560 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
563 BUG_ON(plane == OMAP_DSS_GFX);
565 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
568 static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
570 BUG_ON(plane == OMAP_DSS_GFX);
572 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
575 static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
576 int fir_vinc, int five_taps,
577 enum omap_color_component color_comp)
579 const struct dispc_coef *h_coef, *v_coef;
582 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
583 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
585 for (i = 0; i < 8; i++) {
588 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
589 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
590 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
591 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
592 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
593 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
594 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
595 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
597 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
598 dispc_ovl_write_firh_reg(plane, i, h);
599 dispc_ovl_write_firhv_reg(plane, i, hv);
601 dispc_ovl_write_firh2_reg(plane, i, h);
602 dispc_ovl_write_firhv2_reg(plane, i, hv);
608 for (i = 0; i < 8; i++) {
610 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
611 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
612 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
613 dispc_ovl_write_firv_reg(plane, i, v);
615 dispc_ovl_write_firv2_reg(plane, i, v);
620 static void _dispc_setup_color_conv_coef(void)
623 const struct color_conv_coef {
624 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
627 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
630 const struct color_conv_coef *ct;
632 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
636 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
637 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 0),
638 CVAL(ct->rcr, ct->ry));
639 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 1),
640 CVAL(ct->gy, ct->rcb));
641 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 2),
642 CVAL(ct->gcb, ct->gcr));
643 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 3),
644 CVAL(ct->bcr, ct->by));
645 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 4),
648 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), ct->full_range,
656 static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
658 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
661 static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
663 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
666 static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
668 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
671 static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
673 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
676 static void dispc_ovl_set_pos(enum omap_plane plane, int x, int y)
678 u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
680 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
683 static void dispc_ovl_set_pic_size(enum omap_plane plane, int width, int height)
685 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
687 if (plane == OMAP_DSS_GFX)
688 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
690 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
693 static void dispc_ovl_set_vid_size(enum omap_plane plane, int width, int height)
697 BUG_ON(plane == OMAP_DSS_GFX);
699 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
701 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
704 static void dispc_ovl_set_zorder(enum omap_plane plane, u8 zorder)
706 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
708 if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
711 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
714 static void dispc_ovl_enable_zorder_planes(void)
718 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
721 for (i = 0; i < dss_feat_get_num_ovls(); i++)
722 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
725 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane, bool enable)
727 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
729 if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
732 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
735 static void dispc_ovl_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
737 static const unsigned shifts[] = { 0, 8, 16, 24, };
739 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
741 if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
744 shift = shifts[plane];
745 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
748 static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
750 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
753 static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
755 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
758 static void dispc_ovl_set_color_mode(enum omap_plane plane,
759 enum omap_color_mode color_mode)
762 if (plane != OMAP_DSS_GFX) {
763 switch (color_mode) {
764 case OMAP_DSS_COLOR_NV12:
766 case OMAP_DSS_COLOR_RGBX16:
768 case OMAP_DSS_COLOR_RGBA16:
770 case OMAP_DSS_COLOR_RGB12U:
772 case OMAP_DSS_COLOR_ARGB16:
774 case OMAP_DSS_COLOR_RGB16:
776 case OMAP_DSS_COLOR_ARGB16_1555:
778 case OMAP_DSS_COLOR_RGB24U:
780 case OMAP_DSS_COLOR_RGB24P:
782 case OMAP_DSS_COLOR_YUV2:
784 case OMAP_DSS_COLOR_UYVY:
786 case OMAP_DSS_COLOR_ARGB32:
788 case OMAP_DSS_COLOR_RGBA32:
790 case OMAP_DSS_COLOR_RGBX32:
792 case OMAP_DSS_COLOR_XRGB16_1555:
798 switch (color_mode) {
799 case OMAP_DSS_COLOR_CLUT1:
801 case OMAP_DSS_COLOR_CLUT2:
803 case OMAP_DSS_COLOR_CLUT4:
805 case OMAP_DSS_COLOR_CLUT8:
807 case OMAP_DSS_COLOR_RGB12U:
809 case OMAP_DSS_COLOR_ARGB16:
811 case OMAP_DSS_COLOR_RGB16:
813 case OMAP_DSS_COLOR_ARGB16_1555:
815 case OMAP_DSS_COLOR_RGB24U:
817 case OMAP_DSS_COLOR_RGB24P:
819 case OMAP_DSS_COLOR_RGBX16:
821 case OMAP_DSS_COLOR_RGBA16:
823 case OMAP_DSS_COLOR_ARGB32:
825 case OMAP_DSS_COLOR_RGBA32:
827 case OMAP_DSS_COLOR_RGBX32:
829 case OMAP_DSS_COLOR_XRGB16_1555:
836 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
839 static void dispc_ovl_configure_burst_type(enum omap_plane plane,
840 enum omap_dss_rotation_type rotation_type)
842 if (dss_has_feature(FEAT_BURST_2D) == 0)
845 if (rotation_type == OMAP_DSS_ROT_TILER)
846 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
848 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
851 void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
855 int chan = 0, chan2 = 0;
861 case OMAP_DSS_VIDEO1:
862 case OMAP_DSS_VIDEO2:
863 case OMAP_DSS_VIDEO3:
871 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
872 if (dss_has_feature(FEAT_MGR_LCD2)) {
874 case OMAP_DSS_CHANNEL_LCD:
878 case OMAP_DSS_CHANNEL_DIGIT:
882 case OMAP_DSS_CHANNEL_LCD2:
886 case OMAP_DSS_CHANNEL_LCD3:
887 if (dss_has_feature(FEAT_MGR_LCD3)) {
900 val = FLD_MOD(val, chan, shift, shift);
901 val = FLD_MOD(val, chan2, 31, 30);
903 val = FLD_MOD(val, channel, shift, shift);
905 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
908 static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
912 enum omap_channel channel;
918 case OMAP_DSS_VIDEO1:
919 case OMAP_DSS_VIDEO2:
920 case OMAP_DSS_VIDEO3:
928 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
930 if (dss_has_feature(FEAT_MGR_LCD3)) {
931 if (FLD_GET(val, 31, 30) == 0)
932 channel = FLD_GET(val, shift, shift);
933 else if (FLD_GET(val, 31, 30) == 1)
934 channel = OMAP_DSS_CHANNEL_LCD2;
936 channel = OMAP_DSS_CHANNEL_LCD3;
937 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
938 if (FLD_GET(val, 31, 30) == 0)
939 channel = FLD_GET(val, shift, shift);
941 channel = OMAP_DSS_CHANNEL_LCD2;
943 channel = FLD_GET(val, shift, shift);
949 static void dispc_ovl_set_burst_size(enum omap_plane plane,
950 enum omap_burst_size burst_size)
952 static const unsigned shifts[] = { 6, 14, 14, 14, };
955 shift = shifts[plane];
956 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
959 static void dispc_configure_burst_sizes(void)
962 const int burst_size = BURST_SIZE_X8;
964 /* Configure burst size always to maximum size */
965 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
966 dispc_ovl_set_burst_size(i, burst_size);
969 static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
971 unsigned unit = dss_feat_get_burst_size_unit();
972 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
976 void dispc_enable_gamma_table(bool enable)
979 * This is partially implemented to support only disabling of
983 DSSWARN("Gamma table enabling for TV not yet supported");
987 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
990 static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
992 if (channel == OMAP_DSS_CHANNEL_DIGIT)
995 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
998 static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
999 struct omap_dss_cpr_coefs *coefs)
1001 u32 coef_r, coef_g, coef_b;
1003 if (!dss_mgr_is_lcd(channel))
1006 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1007 FLD_VAL(coefs->rb, 9, 0);
1008 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1009 FLD_VAL(coefs->gb, 9, 0);
1010 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1011 FLD_VAL(coefs->bb, 9, 0);
1013 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1014 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1015 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1018 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
1022 BUG_ON(plane == OMAP_DSS_GFX);
1024 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1025 val = FLD_MOD(val, enable, 9, 9);
1026 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
1029 static void dispc_ovl_enable_replication(enum omap_plane plane, bool enable)
1031 static const unsigned shifts[] = { 5, 10, 10, 10 };
1034 shift = shifts[plane];
1035 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
1038 static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
1043 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
1044 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
1047 static void dispc_read_plane_fifo_sizes(void)
1054 unit = dss_feat_get_buffer_size_unit();
1056 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1058 for (plane = 0; plane < dss_feat_get_num_ovls(); ++plane) {
1059 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(plane), start, end);
1061 dispc.fifo_size[plane] = size;
1065 static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1067 return dispc.fifo_size[plane];
1070 void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
1072 u8 hi_start, hi_end, lo_start, lo_end;
1075 unit = dss_feat_get_buffer_size_unit();
1077 WARN_ON(low % unit != 0);
1078 WARN_ON(high % unit != 0);
1083 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1084 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1086 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1088 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1089 lo_start, lo_end) * unit,
1090 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1091 hi_start, hi_end) * unit,
1092 low * unit, high * unit);
1094 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1095 FLD_VAL(high, hi_start, hi_end) |
1096 FLD_VAL(low, lo_start, lo_end));
1099 void dispc_enable_fifomerge(bool enable)
1101 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1106 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1107 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1110 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1111 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1115 * All sizes are in bytes. Both the buffer and burst are made of
1116 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1119 unsigned buf_unit = dss_feat_get_buffer_size_unit();
1120 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1123 burst_size = dispc_ovl_get_burst_size(plane);
1124 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
1126 if (use_fifomerge) {
1127 total_fifo_size = 0;
1128 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1129 total_fifo_size += dispc_ovl_get_fifo_size(i);
1131 total_fifo_size = ovl_fifo_size;
1135 * We use the same low threshold for both fifomerge and non-fifomerge
1136 * cases, but for fifomerge we calculate the high threshold using the
1137 * combined fifo size
1140 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1141 *fifo_low = ovl_fifo_size - burst_size * 2;
1142 *fifo_high = total_fifo_size - burst_size;
1144 *fifo_low = ovl_fifo_size - burst_size;
1145 *fifo_high = total_fifo_size - buf_unit;
1149 static void dispc_ovl_set_fir(enum omap_plane plane,
1151 enum omap_color_component color_comp)
1155 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1156 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1158 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1159 &hinc_start, &hinc_end);
1160 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1161 &vinc_start, &vinc_end);
1162 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1163 FLD_VAL(hinc, hinc_start, hinc_end);
1165 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1167 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1168 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1172 static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1175 u8 hor_start, hor_end, vert_start, vert_end;
1177 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1178 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1180 val = FLD_VAL(vaccu, vert_start, vert_end) |
1181 FLD_VAL(haccu, hor_start, hor_end);
1183 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1186 static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1189 u8 hor_start, hor_end, vert_start, vert_end;
1191 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1192 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1194 val = FLD_VAL(vaccu, vert_start, vert_end) |
1195 FLD_VAL(haccu, hor_start, hor_end);
1197 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1200 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1205 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1206 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1209 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1214 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1215 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1218 static void dispc_ovl_set_scale_param(enum omap_plane plane,
1219 u16 orig_width, u16 orig_height,
1220 u16 out_width, u16 out_height,
1221 bool five_taps, u8 rotation,
1222 enum omap_color_component color_comp)
1224 int fir_hinc, fir_vinc;
1226 fir_hinc = 1024 * orig_width / out_width;
1227 fir_vinc = 1024 * orig_height / out_height;
1229 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1231 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1234 static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1235 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1236 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1238 int h_accu2_0, h_accu2_1;
1239 int v_accu2_0, v_accu2_1;
1240 int chroma_hinc, chroma_vinc;
1250 const struct accu *accu_table;
1251 const struct accu *accu_val;
1253 static const struct accu accu_nv12[4] = {
1254 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1255 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1256 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1257 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1260 static const struct accu accu_nv12_ilace[4] = {
1261 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1262 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1263 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1264 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1267 static const struct accu accu_yuv[4] = {
1268 { 0, 1, 0, 1, 0, 1, 0, 1 },
1269 { 0, 1, 0, 1, 0, 1, 0, 1 },
1270 { -1, 1, 0, 1, 0, 1, 0, 1 },
1271 { 0, 1, 0, 1, -1, 1, 0, 1 },
1275 case OMAP_DSS_ROT_0:
1278 case OMAP_DSS_ROT_90:
1281 case OMAP_DSS_ROT_180:
1284 case OMAP_DSS_ROT_270:
1292 switch (color_mode) {
1293 case OMAP_DSS_COLOR_NV12:
1295 accu_table = accu_nv12_ilace;
1297 accu_table = accu_nv12;
1299 case OMAP_DSS_COLOR_YUV2:
1300 case OMAP_DSS_COLOR_UYVY:
1301 accu_table = accu_yuv;
1308 accu_val = &accu_table[idx];
1310 chroma_hinc = 1024 * orig_width / out_width;
1311 chroma_vinc = 1024 * orig_height / out_height;
1313 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1314 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1315 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1316 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1318 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1319 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1322 static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1323 u16 orig_width, u16 orig_height,
1324 u16 out_width, u16 out_height,
1325 bool ilace, bool five_taps,
1326 bool fieldmode, enum omap_color_mode color_mode,
1333 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1334 out_width, out_height, five_taps,
1335 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1336 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1338 /* RESIZEENABLE and VERTICALTAPS */
1339 l &= ~((0x3 << 5) | (0x1 << 21));
1340 l |= (orig_width != out_width) ? (1 << 5) : 0;
1341 l |= (orig_height != out_height) ? (1 << 6) : 0;
1342 l |= five_taps ? (1 << 21) : 0;
1344 /* VRESIZECONF and HRESIZECONF */
1345 if (dss_has_feature(FEAT_RESIZECONF)) {
1347 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1348 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1351 /* LINEBUFFERSPLIT */
1352 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1354 l |= five_taps ? (1 << 22) : 0;
1357 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1360 * field 0 = even field = bottom field
1361 * field 1 = odd field = top field
1363 if (ilace && !fieldmode) {
1365 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1366 if (accu0 >= 1024/2) {
1372 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1373 dispc_ovl_set_vid_accu1(plane, 0, accu1);
1376 static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1377 u16 orig_width, u16 orig_height,
1378 u16 out_width, u16 out_height,
1379 bool ilace, bool five_taps,
1380 bool fieldmode, enum omap_color_mode color_mode,
1383 int scale_x = out_width != orig_width;
1384 int scale_y = out_height != orig_height;
1386 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1388 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1389 color_mode != OMAP_DSS_COLOR_UYVY &&
1390 color_mode != OMAP_DSS_COLOR_NV12)) {
1391 /* reset chroma resampling for RGB formats */
1392 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1396 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1397 out_height, ilace, color_mode, rotation);
1399 switch (color_mode) {
1400 case OMAP_DSS_COLOR_NV12:
1401 /* UV is subsampled by 2 vertically*/
1403 /* UV is subsampled by 2 horz.*/
1406 case OMAP_DSS_COLOR_YUV2:
1407 case OMAP_DSS_COLOR_UYVY:
1408 /*For YUV422 with 90/270 rotation,
1409 *we don't upsample chroma
1411 if (rotation == OMAP_DSS_ROT_0 ||
1412 rotation == OMAP_DSS_ROT_180)
1413 /* UV is subsampled by 2 hrz*/
1415 /* must use FIR for YUV422 if rotated */
1416 if (rotation != OMAP_DSS_ROT_0)
1417 scale_x = scale_y = true;
1424 if (out_width != orig_width)
1426 if (out_height != orig_height)
1429 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1430 out_width, out_height, five_taps,
1431 rotation, DISPC_COLOR_COMPONENT_UV);
1433 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1434 (scale_x || scale_y) ? 1 : 0, 8, 8);
1436 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1438 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1441 static void dispc_ovl_set_scaling(enum omap_plane plane,
1442 u16 orig_width, u16 orig_height,
1443 u16 out_width, u16 out_height,
1444 bool ilace, bool five_taps,
1445 bool fieldmode, enum omap_color_mode color_mode,
1448 BUG_ON(plane == OMAP_DSS_GFX);
1450 dispc_ovl_set_scaling_common(plane,
1451 orig_width, orig_height,
1452 out_width, out_height,
1454 fieldmode, color_mode,
1457 dispc_ovl_set_scaling_uv(plane,
1458 orig_width, orig_height,
1459 out_width, out_height,
1461 fieldmode, color_mode,
1465 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1466 bool mirroring, enum omap_color_mode color_mode)
1468 bool row_repeat = false;
1471 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1472 color_mode == OMAP_DSS_COLOR_UYVY) {
1476 case OMAP_DSS_ROT_0:
1479 case OMAP_DSS_ROT_90:
1482 case OMAP_DSS_ROT_180:
1485 case OMAP_DSS_ROT_270:
1491 case OMAP_DSS_ROT_0:
1494 case OMAP_DSS_ROT_90:
1497 case OMAP_DSS_ROT_180:
1500 case OMAP_DSS_ROT_270:
1506 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1512 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1513 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1514 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1515 row_repeat ? 1 : 0, 18, 18);
1518 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1520 switch (color_mode) {
1521 case OMAP_DSS_COLOR_CLUT1:
1523 case OMAP_DSS_COLOR_CLUT2:
1525 case OMAP_DSS_COLOR_CLUT4:
1527 case OMAP_DSS_COLOR_CLUT8:
1528 case OMAP_DSS_COLOR_NV12:
1530 case OMAP_DSS_COLOR_RGB12U:
1531 case OMAP_DSS_COLOR_RGB16:
1532 case OMAP_DSS_COLOR_ARGB16:
1533 case OMAP_DSS_COLOR_YUV2:
1534 case OMAP_DSS_COLOR_UYVY:
1535 case OMAP_DSS_COLOR_RGBA16:
1536 case OMAP_DSS_COLOR_RGBX16:
1537 case OMAP_DSS_COLOR_ARGB16_1555:
1538 case OMAP_DSS_COLOR_XRGB16_1555:
1540 case OMAP_DSS_COLOR_RGB24P:
1542 case OMAP_DSS_COLOR_RGB24U:
1543 case OMAP_DSS_COLOR_ARGB32:
1544 case OMAP_DSS_COLOR_RGBA32:
1545 case OMAP_DSS_COLOR_RGBX32:
1553 static s32 pixinc(int pixels, u8 ps)
1557 else if (pixels > 1)
1558 return 1 + (pixels - 1) * ps;
1559 else if (pixels < 0)
1560 return 1 - (-pixels + 1) * ps;
1566 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1568 u16 width, u16 height,
1569 enum omap_color_mode color_mode, bool fieldmode,
1570 unsigned int field_offset,
1571 unsigned *offset0, unsigned *offset1,
1572 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1576 /* FIXME CLUT formats */
1577 switch (color_mode) {
1578 case OMAP_DSS_COLOR_CLUT1:
1579 case OMAP_DSS_COLOR_CLUT2:
1580 case OMAP_DSS_COLOR_CLUT4:
1581 case OMAP_DSS_COLOR_CLUT8:
1584 case OMAP_DSS_COLOR_YUV2:
1585 case OMAP_DSS_COLOR_UYVY:
1589 ps = color_mode_to_bpp(color_mode) / 8;
1593 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1597 * field 0 = even field = bottom field
1598 * field 1 = odd field = top field
1600 switch (rotation + mirror * 4) {
1601 case OMAP_DSS_ROT_0:
1602 case OMAP_DSS_ROT_180:
1604 * If the pixel format is YUV or UYVY divide the width
1605 * of the image by 2 for 0 and 180 degree rotation.
1607 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1608 color_mode == OMAP_DSS_COLOR_UYVY)
1610 case OMAP_DSS_ROT_90:
1611 case OMAP_DSS_ROT_270:
1614 *offset0 = field_offset * screen_width * ps;
1618 *row_inc = pixinc(1 +
1619 (y_predecim * screen_width - x_predecim * width) +
1620 (fieldmode ? screen_width : 0), ps);
1621 *pix_inc = pixinc(x_predecim, ps);
1624 case OMAP_DSS_ROT_0 + 4:
1625 case OMAP_DSS_ROT_180 + 4:
1626 /* If the pixel format is YUV or UYVY divide the width
1627 * of the image by 2 for 0 degree and 180 degree
1629 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1630 color_mode == OMAP_DSS_COLOR_UYVY)
1632 case OMAP_DSS_ROT_90 + 4:
1633 case OMAP_DSS_ROT_270 + 4:
1636 *offset0 = field_offset * screen_width * ps;
1639 *row_inc = pixinc(1 -
1640 (y_predecim * screen_width + x_predecim * width) -
1641 (fieldmode ? screen_width : 0), ps);
1642 *pix_inc = pixinc(x_predecim, ps);
1651 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1653 u16 width, u16 height,
1654 enum omap_color_mode color_mode, bool fieldmode,
1655 unsigned int field_offset,
1656 unsigned *offset0, unsigned *offset1,
1657 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1662 /* FIXME CLUT formats */
1663 switch (color_mode) {
1664 case OMAP_DSS_COLOR_CLUT1:
1665 case OMAP_DSS_COLOR_CLUT2:
1666 case OMAP_DSS_COLOR_CLUT4:
1667 case OMAP_DSS_COLOR_CLUT8:
1671 ps = color_mode_to_bpp(color_mode) / 8;
1675 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1678 /* width & height are overlay sizes, convert to fb sizes */
1680 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1689 * field 0 = even field = bottom field
1690 * field 1 = odd field = top field
1692 switch (rotation + mirror * 4) {
1693 case OMAP_DSS_ROT_0:
1696 *offset0 = *offset1 + field_offset * screen_width * ps;
1698 *offset0 = *offset1;
1699 *row_inc = pixinc(1 +
1700 (y_predecim * screen_width - fbw * x_predecim) +
1701 (fieldmode ? screen_width : 0), ps);
1702 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1703 color_mode == OMAP_DSS_COLOR_UYVY)
1704 *pix_inc = pixinc(x_predecim, 2 * ps);
1706 *pix_inc = pixinc(x_predecim, ps);
1708 case OMAP_DSS_ROT_90:
1709 *offset1 = screen_width * (fbh - 1) * ps;
1711 *offset0 = *offset1 + field_offset * ps;
1713 *offset0 = *offset1;
1714 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1715 y_predecim + (fieldmode ? 1 : 0), ps);
1716 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1718 case OMAP_DSS_ROT_180:
1719 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1721 *offset0 = *offset1 - field_offset * screen_width * ps;
1723 *offset0 = *offset1;
1724 *row_inc = pixinc(-1 -
1725 (y_predecim * screen_width - fbw * x_predecim) -
1726 (fieldmode ? screen_width : 0), ps);
1727 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1728 color_mode == OMAP_DSS_COLOR_UYVY)
1729 *pix_inc = pixinc(-x_predecim, 2 * ps);
1731 *pix_inc = pixinc(-x_predecim, ps);
1733 case OMAP_DSS_ROT_270:
1734 *offset1 = (fbw - 1) * ps;
1736 *offset0 = *offset1 - field_offset * ps;
1738 *offset0 = *offset1;
1739 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1740 y_predecim - (fieldmode ? 1 : 0), ps);
1741 *pix_inc = pixinc(x_predecim * screen_width, ps);
1745 case OMAP_DSS_ROT_0 + 4:
1746 *offset1 = (fbw - 1) * ps;
1748 *offset0 = *offset1 + field_offset * screen_width * ps;
1750 *offset0 = *offset1;
1751 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
1752 (fieldmode ? screen_width : 0),
1754 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1755 color_mode == OMAP_DSS_COLOR_UYVY)
1756 *pix_inc = pixinc(-x_predecim, 2 * ps);
1758 *pix_inc = pixinc(-x_predecim, ps);
1761 case OMAP_DSS_ROT_90 + 4:
1764 *offset0 = *offset1 + field_offset * ps;
1766 *offset0 = *offset1;
1767 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1768 y_predecim + (fieldmode ? 1 : 0),
1770 *pix_inc = pixinc(x_predecim * screen_width, ps);
1773 case OMAP_DSS_ROT_180 + 4:
1774 *offset1 = screen_width * (fbh - 1) * ps;
1776 *offset0 = *offset1 - field_offset * screen_width * ps;
1778 *offset0 = *offset1;
1779 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
1780 (fieldmode ? screen_width : 0),
1782 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1783 color_mode == OMAP_DSS_COLOR_UYVY)
1784 *pix_inc = pixinc(x_predecim, 2 * ps);
1786 *pix_inc = pixinc(x_predecim, ps);
1789 case OMAP_DSS_ROT_270 + 4:
1790 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1792 *offset0 = *offset1 - field_offset * ps;
1794 *offset0 = *offset1;
1795 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1796 y_predecim - (fieldmode ? 1 : 0),
1798 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1807 static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1808 enum omap_color_mode color_mode, bool fieldmode,
1809 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1810 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1814 switch (color_mode) {
1815 case OMAP_DSS_COLOR_CLUT1:
1816 case OMAP_DSS_COLOR_CLUT2:
1817 case OMAP_DSS_COLOR_CLUT4:
1818 case OMAP_DSS_COLOR_CLUT8:
1822 ps = color_mode_to_bpp(color_mode) / 8;
1826 DSSDBG("scrw %d, width %d\n", screen_width, width);
1829 * field 0 = even field = bottom field
1830 * field 1 = odd field = top field
1834 *offset0 = *offset1 + field_offset * screen_width * ps;
1836 *offset0 = *offset1;
1837 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1838 (fieldmode ? screen_width : 0), ps);
1839 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1840 color_mode == OMAP_DSS_COLOR_UYVY)
1841 *pix_inc = pixinc(x_predecim, 2 * ps);
1843 *pix_inc = pixinc(x_predecim, ps);
1847 * This function is used to avoid synclosts in OMAP3, because of some
1848 * undocumented horizontal position and timing related limitations.
1850 static int check_horiz_timing_omap3(enum omap_channel channel,
1851 const struct omap_video_timings *t, u16 pos_x,
1852 u16 width, u16 height, u16 out_width, u16 out_height)
1854 int DS = DIV_ROUND_UP(height, out_height);
1855 unsigned long nonactive, lclk, pclk;
1856 static const u8 limits[3] = { 8, 10, 20 };
1860 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
1861 pclk = dispc_mgr_pclk_rate(channel);
1862 if (dss_mgr_is_lcd(channel))
1863 lclk = dispc_mgr_lclk_rate(channel);
1865 lclk = dispc_fclk_rate();
1868 if (out_height < height)
1870 if (out_width < width)
1872 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
1873 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
1874 if (blank <= limits[i])
1878 * Pixel data should be prepared before visible display point starts.
1879 * So, atleast DS-2 lines must have already been fetched by DISPC
1880 * during nonactive - pos_x period.
1882 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
1883 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
1884 val, max(0, DS - 2) * width);
1885 if (val < max(0, DS - 2) * width)
1889 * All lines need to be refilled during the nonactive period of which
1890 * only one line can be loaded during the active period. So, atleast
1891 * DS - 1 lines should be loaded during nonactive period.
1893 val = div_u64((u64)nonactive * lclk, pclk);
1894 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
1895 val, max(0, DS - 1) * width);
1896 if (val < max(0, DS - 1) * width)
1902 static unsigned long calc_core_clk_five_taps(enum omap_channel channel,
1903 const struct omap_video_timings *mgr_timings, u16 width,
1904 u16 height, u16 out_width, u16 out_height,
1905 enum omap_color_mode color_mode)
1908 u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
1910 if (height <= out_height && width <= out_width)
1911 return (unsigned long) pclk;
1913 if (height > out_height) {
1914 unsigned int ppl = mgr_timings->x_res;
1916 tmp = pclk * height * out_width;
1917 do_div(tmp, 2 * out_height * ppl);
1920 if (height > 2 * out_height) {
1921 if (ppl == out_width)
1924 tmp = pclk * (height - 2 * out_height) * out_width;
1925 do_div(tmp, 2 * out_height * (ppl - out_width));
1926 core_clk = max_t(u32, core_clk, tmp);
1930 if (width > out_width) {
1932 do_div(tmp, out_width);
1933 core_clk = max_t(u32, core_clk, tmp);
1935 if (color_mode == OMAP_DSS_COLOR_RGB24U)
1942 static unsigned long calc_core_clk(enum omap_channel channel, u16 width,
1943 u16 height, u16 out_width, u16 out_height)
1945 unsigned int hf, vf;
1946 unsigned long pclk = dispc_mgr_pclk_rate(channel);
1949 * FIXME how to determine the 'A' factor
1950 * for the no downscaling case ?
1953 if (width > 3 * out_width)
1955 else if (width > 2 * out_width)
1957 else if (width > out_width)
1962 if (height > out_height)
1967 if (cpu_is_omap24xx()) {
1968 if (vf > 1 && hf > 1)
1972 } else if (cpu_is_omap34xx()) {
1973 return pclk * vf * hf;
1976 return DIV_ROUND_UP(pclk, out_width) * width;
1982 static int dispc_ovl_calc_scaling(enum omap_plane plane,
1983 enum omap_channel channel,
1984 const struct omap_video_timings *mgr_timings,
1985 u16 width, u16 height, u16 out_width, u16 out_height,
1986 enum omap_color_mode color_mode, bool *five_taps,
1987 int *x_predecim, int *y_predecim, u16 pos_x)
1989 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
1990 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
1991 const int maxsinglelinewidth =
1992 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
1993 const int max_decim_limit = 16;
1994 unsigned long core_clk = 0;
1995 int decim_x, decim_y, error, min_factor;
1996 u16 in_width, in_height, in_width_max = 0;
1998 if (width == out_width && height == out_height)
2001 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
2004 *x_predecim = max_decim_limit;
2005 *y_predecim = max_decim_limit;
2007 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2008 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2009 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2010 color_mode == OMAP_DSS_COLOR_CLUT8) {
2017 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2018 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2020 min_factor = min(decim_x, decim_y);
2022 if (decim_x > *x_predecim || out_width > width * 8)
2025 if (decim_y > *y_predecim || out_height > height * 8)
2028 if (cpu_is_omap24xx()) {
2032 in_height = DIV_ROUND_UP(height, decim_y);
2033 in_width = DIV_ROUND_UP(width, decim_x);
2034 core_clk = calc_core_clk(channel, in_width, in_height,
2035 out_width, out_height);
2036 error = (in_width > maxsinglelinewidth || !core_clk ||
2037 core_clk > dispc_core_clk_rate());
2039 if (decim_x == decim_y) {
2040 decim_x = min_factor;
2043 swap(decim_x, decim_y);
2044 if (decim_x < decim_y)
2048 } while (decim_x <= *x_predecim && decim_y <= *y_predecim &&
2051 if (in_width > maxsinglelinewidth) {
2052 DSSERR("Cannot scale max input width exceeded");
2055 } else if (cpu_is_omap34xx()) {
2058 in_height = DIV_ROUND_UP(height, decim_y);
2059 in_width = DIV_ROUND_UP(width, decim_x);
2060 core_clk = calc_core_clk_five_taps(channel, mgr_timings,
2061 in_width, in_height, out_width, out_height,
2064 error = check_horiz_timing_omap3(channel, mgr_timings,
2065 pos_x, in_width, in_height, out_width,
2068 if (in_width > maxsinglelinewidth)
2069 if (in_height > out_height &&
2070 in_height < out_height * 2)
2073 core_clk = calc_core_clk(channel, in_width,
2074 in_height, out_width, out_height);
2075 error = (error || in_width > maxsinglelinewidth * 2 ||
2076 (in_width > maxsinglelinewidth && *five_taps) ||
2077 !core_clk || core_clk > dispc_core_clk_rate());
2079 if (decim_x == decim_y) {
2080 decim_x = min_factor;
2083 swap(decim_x, decim_y);
2084 if (decim_x < decim_y)
2088 } while (decim_x <= *x_predecim && decim_y <= *y_predecim
2091 if (check_horiz_timing_omap3(channel, mgr_timings, pos_x, width,
2092 height, out_width, out_height)){
2093 DSSERR("horizontal timing too tight\n");
2097 if (in_width > (maxsinglelinewidth * 2)) {
2098 DSSERR("Cannot setup scaling");
2099 DSSERR("width exceeds maximum width possible");
2103 if (in_width > maxsinglelinewidth && *five_taps) {
2104 DSSERR("cannot setup scaling with five taps");
2108 int decim_x_min = decim_x;
2109 in_height = DIV_ROUND_UP(height, decim_y);
2110 in_width_max = dispc_core_clk_rate() /
2111 DIV_ROUND_UP(dispc_mgr_pclk_rate(channel),
2113 decim_x = DIV_ROUND_UP(width, in_width_max);
2115 decim_x = decim_x > decim_x_min ? decim_x : decim_x_min;
2116 if (decim_x > *x_predecim)
2120 in_width = DIV_ROUND_UP(width, decim_x);
2121 } while (decim_x <= *x_predecim &&
2122 in_width > maxsinglelinewidth && decim_x++);
2124 if (in_width > maxsinglelinewidth) {
2125 DSSERR("Cannot scale width exceeds max line width");
2129 core_clk = calc_core_clk(channel, in_width, in_height,
2130 out_width, out_height);
2133 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2134 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
2136 if (!core_clk || core_clk > dispc_core_clk_rate()) {
2137 DSSERR("failed to set up scaling, "
2138 "required core clk rate = %lu Hz, "
2139 "current core clk rate = %lu Hz\n",
2140 core_clk, dispc_core_clk_rate());
2144 *x_predecim = decim_x;
2145 *y_predecim = decim_y;
2149 int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
2150 bool replication, const struct omap_video_timings *mgr_timings)
2152 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
2153 bool five_taps = true;
2156 unsigned offset0, offset1;
2159 u16 frame_height = oi->height;
2160 unsigned int field_offset = 0;
2161 u16 in_height = oi->height;
2162 u16 in_width = oi->width;
2163 u16 out_width, out_height;
2164 enum omap_channel channel;
2165 int x_predecim = 1, y_predecim = 1;
2166 bool ilace = mgr_timings->interlace;
2168 channel = dispc_ovl_get_channel_out(plane);
2170 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
2171 "%dx%d, cmode %x, rot %d, mir %d, ilace %d chan %d repl %d\n",
2172 plane, oi->paddr, oi->p_uv_addr,
2173 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2174 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2175 oi->mirror, ilace, channel, replication);
2180 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2181 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2183 if (ilace && oi->height == out_height)
2192 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2194 in_height, oi->pos_y, out_height);
2197 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2200 r = dispc_ovl_calc_scaling(plane, channel, mgr_timings, in_width,
2201 in_height, out_width, out_height, oi->color_mode,
2202 &five_taps, &x_predecim, &y_predecim, oi->pos_x);
2206 in_width = DIV_ROUND_UP(in_width, x_predecim);
2207 in_height = DIV_ROUND_UP(in_height, y_predecim);
2209 if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
2210 oi->color_mode == OMAP_DSS_COLOR_UYVY ||
2211 oi->color_mode == OMAP_DSS_COLOR_NV12)
2214 if (ilace && !fieldmode) {
2216 * when downscaling the bottom field may have to start several
2217 * source lines below the top field. Unfortunately ACCUI
2218 * registers will only hold the fractional part of the offset
2219 * so the integer part must be added to the base address of the
2222 if (!in_height || in_height == out_height)
2225 field_offset = in_height / out_height / 2;
2228 /* Fields are independent but interleaved in memory. */
2237 if (oi->rotation_type == OMAP_DSS_ROT_TILER)
2238 calc_tiler_rotation_offset(oi->screen_width, in_width,
2239 oi->color_mode, fieldmode, field_offset,
2240 &offset0, &offset1, &row_inc, &pix_inc,
2241 x_predecim, y_predecim);
2242 else if (oi->rotation_type == OMAP_DSS_ROT_DMA)
2243 calc_dma_rotation_offset(oi->rotation, oi->mirror,
2244 oi->screen_width, in_width, frame_height,
2245 oi->color_mode, fieldmode, field_offset,
2246 &offset0, &offset1, &row_inc, &pix_inc,
2247 x_predecim, y_predecim);
2249 calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
2250 oi->screen_width, in_width, frame_height,
2251 oi->color_mode, fieldmode, field_offset,
2252 &offset0, &offset1, &row_inc, &pix_inc,
2253 x_predecim, y_predecim);
2255 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2256 offset0, offset1, row_inc, pix_inc);
2258 dispc_ovl_set_color_mode(plane, oi->color_mode);
2260 dispc_ovl_configure_burst_type(plane, oi->rotation_type);
2262 dispc_ovl_set_ba0(plane, oi->paddr + offset0);
2263 dispc_ovl_set_ba1(plane, oi->paddr + offset1);
2265 if (OMAP_DSS_COLOR_NV12 == oi->color_mode) {
2266 dispc_ovl_set_ba0_uv(plane, oi->p_uv_addr + offset0);
2267 dispc_ovl_set_ba1_uv(plane, oi->p_uv_addr + offset1);
2271 dispc_ovl_set_row_inc(plane, row_inc);
2272 dispc_ovl_set_pix_inc(plane, pix_inc);
2274 DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, in_width,
2275 in_height, out_width, out_height);
2277 dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y);
2279 dispc_ovl_set_pic_size(plane, in_width, in_height);
2281 if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) {
2282 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2283 out_height, ilace, five_taps, fieldmode,
2284 oi->color_mode, oi->rotation);
2285 dispc_ovl_set_vid_size(plane, out_width, out_height);
2286 dispc_ovl_set_vid_color_conv(plane, cconv);
2289 dispc_ovl_set_rotation_attrs(plane, oi->rotation, oi->mirror,
2292 dispc_ovl_set_zorder(plane, oi->zorder);
2293 dispc_ovl_set_pre_mult_alpha(plane, oi->pre_mult_alpha);
2294 dispc_ovl_setup_global_alpha(plane, oi->global_alpha);
2296 dispc_ovl_enable_replication(plane, replication);
2301 int dispc_ovl_enable(enum omap_plane plane, bool enable)
2303 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2305 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2310 static void dispc_disable_isr(void *data, u32 mask)
2312 struct completion *compl = data;
2316 static void _enable_lcd_out(enum omap_channel channel, bool enable)
2318 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2319 /* flush posted write */
2320 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2323 static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
2325 struct completion frame_done_completion;
2330 /* When we disable LCD output, we need to wait until frame is done.
2331 * Otherwise the DSS is still working, and turning off the clocks
2332 * prevents DSS from going to OFF mode */
2333 is_on = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2335 irq = mgr_desc[channel].framedone_irq;
2337 if (!enable && is_on) {
2338 init_completion(&frame_done_completion);
2340 r = omap_dispc_register_isr(dispc_disable_isr,
2341 &frame_done_completion, irq);
2344 DSSERR("failed to register FRAMEDONE isr\n");
2347 _enable_lcd_out(channel, enable);
2349 if (!enable && is_on) {
2350 if (!wait_for_completion_timeout(&frame_done_completion,
2351 msecs_to_jiffies(100)))
2352 DSSERR("timeout waiting for FRAME DONE\n");
2354 r = omap_dispc_unregister_isr(dispc_disable_isr,
2355 &frame_done_completion, irq);
2358 DSSERR("failed to unregister FRAMEDONE isr\n");
2362 static void _enable_digit_out(bool enable)
2364 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
2365 /* flush posted write */
2366 dispc_read_reg(DISPC_CONTROL);
2369 static void dispc_mgr_enable_digit_out(bool enable)
2371 struct completion frame_done_completion;
2372 enum dss_hdmi_venc_clk_source_select src;
2377 if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
2380 src = dss_get_hdmi_venc_clk_source();
2383 unsigned long flags;
2384 /* When we enable digit output, we'll get an extra digit
2385 * sync lost interrupt, that we need to ignore */
2386 spin_lock_irqsave(&dispc.irq_lock, flags);
2387 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
2388 _omap_dispc_set_irqs();
2389 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2392 /* When we disable digit output, we need to wait until fields are done.
2393 * Otherwise the DSS is still working, and turning off the clocks
2394 * prevents DSS from going to OFF mode. And when enabling, we need to
2395 * wait for the extra sync losts */
2396 init_completion(&frame_done_completion);
2398 if (src == DSS_HDMI_M_PCLK && enable == false) {
2399 irq_mask = DISPC_IRQ_FRAMEDONETV;
2402 irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
2403 /* XXX I understand from TRM that we should only wait for the
2404 * current field to complete. But it seems we have to wait for
2409 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
2412 DSSERR("failed to register %x isr\n", irq_mask);
2414 _enable_digit_out(enable);
2416 for (i = 0; i < num_irqs; ++i) {
2417 if (!wait_for_completion_timeout(&frame_done_completion,
2418 msecs_to_jiffies(100)))
2419 DSSERR("timeout waiting for digit out to %s\n",
2420 enable ? "start" : "stop");
2423 r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
2426 DSSERR("failed to unregister %x isr\n", irq_mask);
2429 unsigned long flags;
2430 spin_lock_irqsave(&dispc.irq_lock, flags);
2431 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
2432 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
2433 _omap_dispc_set_irqs();
2434 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2438 bool dispc_mgr_is_enabled(enum omap_channel channel)
2440 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2443 void dispc_mgr_enable(enum omap_channel channel, bool enable)
2445 if (dss_mgr_is_lcd(channel))
2446 dispc_mgr_enable_lcd_out(channel, enable);
2447 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2448 dispc_mgr_enable_digit_out(enable);
2453 void dispc_lcd_enable_signal_polarity(bool act_high)
2455 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2458 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2461 void dispc_lcd_enable_signal(bool enable)
2463 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2466 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2469 void dispc_pck_free_enable(bool enable)
2471 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2474 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2477 void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2479 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
2483 void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
2485 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
2488 void dispc_set_loadmode(enum omap_dss_load_mode mode)
2490 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2494 static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2496 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2499 static void dispc_mgr_set_trans_key(enum omap_channel ch,
2500 enum omap_dss_trans_key_type type,
2503 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
2505 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2508 static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2510 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
2513 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2516 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
2519 if (ch == OMAP_DSS_CHANNEL_LCD)
2520 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2521 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2522 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2525 void dispc_mgr_setup(enum omap_channel channel,
2526 struct omap_overlay_manager_info *info)
2528 dispc_mgr_set_default_color(channel, info->default_color);
2529 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2530 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2531 dispc_mgr_enable_alpha_fixed_zorder(channel,
2532 info->partial_alpha_enabled);
2533 if (dss_has_feature(FEAT_CPR)) {
2534 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2535 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2539 void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2543 switch (data_lines) {
2561 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
2564 void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
2570 case DSS_IO_PAD_MODE_RESET:
2574 case DSS_IO_PAD_MODE_RFBI:
2578 case DSS_IO_PAD_MODE_BYPASS:
2587 l = dispc_read_reg(DISPC_CONTROL);
2588 l = FLD_MOD(l, gpout0, 15, 15);
2589 l = FLD_MOD(l, gpout1, 16, 16);
2590 dispc_write_reg(DISPC_CONTROL, l);
2593 void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2595 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
2598 static bool _dispc_mgr_size_ok(u16 width, u16 height)
2600 return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
2601 height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
2604 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2605 int vsw, int vfp, int vbp)
2607 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2608 if (hsw < 1 || hsw > 64 ||
2609 hfp < 1 || hfp > 256 ||
2610 hbp < 1 || hbp > 256 ||
2611 vsw < 1 || vsw > 64 ||
2612 vfp < 0 || vfp > 255 ||
2613 vbp < 0 || vbp > 255)
2616 if (hsw < 1 || hsw > 256 ||
2617 hfp < 1 || hfp > 4096 ||
2618 hbp < 1 || hbp > 4096 ||
2619 vsw < 1 || vsw > 256 ||
2620 vfp < 0 || vfp > 4095 ||
2621 vbp < 0 || vbp > 4095)
2628 bool dispc_mgr_timings_ok(enum omap_channel channel,
2629 const struct omap_video_timings *timings)
2633 timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
2635 if (dss_mgr_is_lcd(channel))
2636 timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
2637 timings->hfp, timings->hbp,
2638 timings->vsw, timings->vfp,
2644 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
2645 int hfp, int hbp, int vsw, int vfp, int vbp,
2646 enum omap_dss_signal_level vsync_level,
2647 enum omap_dss_signal_level hsync_level,
2648 enum omap_dss_signal_edge data_pclk_edge,
2649 enum omap_dss_signal_level de_level,
2650 enum omap_dss_signal_edge sync_pclk_edge)
2653 u32 timing_h, timing_v, l;
2654 bool onoff, rf, ipc;
2656 if (cpu_is_omap24xx() || omap_rev() < OMAP3430_REV_ES3_0) {
2657 timing_h = FLD_VAL(hsw-1, 5, 0) | FLD_VAL(hfp-1, 15, 8) |
2658 FLD_VAL(hbp-1, 27, 20);
2660 timing_v = FLD_VAL(vsw-1, 5, 0) | FLD_VAL(vfp, 15, 8) |
2661 FLD_VAL(vbp, 27, 20);
2663 timing_h = FLD_VAL(hsw-1, 7, 0) | FLD_VAL(hfp-1, 19, 8) |
2664 FLD_VAL(hbp-1, 31, 20);
2666 timing_v = FLD_VAL(vsw-1, 7, 0) | FLD_VAL(vfp, 19, 8) |
2667 FLD_VAL(vbp, 31, 20);
2670 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2671 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
2673 switch (data_pclk_edge) {
2674 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2677 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2680 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2685 switch (sync_pclk_edge) {
2686 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2690 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2694 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2702 l = dispc_read_reg(DISPC_POL_FREQ(channel));
2703 l |= FLD_VAL(onoff, 17, 17);
2704 l |= FLD_VAL(rf, 16, 16);
2705 l |= FLD_VAL(de_level, 15, 15);
2706 l |= FLD_VAL(ipc, 14, 14);
2707 l |= FLD_VAL(hsync_level, 13, 13);
2708 l |= FLD_VAL(vsync_level, 12, 12);
2709 dispc_write_reg(DISPC_POL_FREQ(channel), l);
2712 /* change name to mode? */
2713 void dispc_mgr_set_timings(enum omap_channel channel,
2714 struct omap_video_timings *timings)
2716 unsigned xtot, ytot;
2717 unsigned long ht, vt;
2718 struct omap_video_timings t = *timings;
2720 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
2722 if (!dispc_mgr_timings_ok(channel, &t)) {
2727 if (dss_mgr_is_lcd(channel)) {
2728 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
2729 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
2730 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
2732 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
2733 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
2735 ht = (timings->pixel_clock * 1000) / xtot;
2736 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2738 DSSDBG("pck %u\n", timings->pixel_clock);
2739 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2740 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
2741 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
2742 t.vsync_level, t.hsync_level, t.data_pclk_edge,
2743 t.de_level, t.sync_pclk_edge);
2745 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2747 if (t.interlace == true)
2751 dispc_mgr_set_size(channel, t.x_res, t.y_res);
2754 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
2757 BUG_ON(lck_div < 1);
2758 BUG_ON(pck_div < 1);
2760 dispc_write_reg(DISPC_DIVISORo(channel),
2761 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
2764 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
2768 l = dispc_read_reg(DISPC_DIVISORo(channel));
2769 *lck_div = FLD_GET(l, 23, 16);
2770 *pck_div = FLD_GET(l, 7, 0);
2773 unsigned long dispc_fclk_rate(void)
2775 struct platform_device *dsidev;
2776 unsigned long r = 0;
2778 switch (dss_get_dispc_clk_source()) {
2779 case OMAP_DSS_CLK_SRC_FCK:
2780 r = clk_get_rate(dispc.dss_clk);
2782 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2783 dsidev = dsi_get_dsidev_from_id(0);
2784 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2786 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2787 dsidev = dsi_get_dsidev_from_id(1);
2788 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2798 unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
2800 struct platform_device *dsidev;
2805 l = dispc_read_reg(DISPC_DIVISORo(channel));
2807 lcd = FLD_GET(l, 23, 16);
2809 switch (dss_get_lcd_clk_source(channel)) {
2810 case OMAP_DSS_CLK_SRC_FCK:
2811 r = clk_get_rate(dispc.dss_clk);
2813 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2814 dsidev = dsi_get_dsidev_from_id(0);
2815 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2817 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2818 dsidev = dsi_get_dsidev_from_id(1);
2819 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2829 unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
2833 if (dss_mgr_is_lcd(channel)) {
2837 l = dispc_read_reg(DISPC_DIVISORo(channel));
2839 pcd = FLD_GET(l, 7, 0);
2841 r = dispc_mgr_lclk_rate(channel);
2845 enum dss_hdmi_venc_clk_source_select source;
2847 source = dss_get_hdmi_venc_clk_source();
2850 case DSS_VENC_TV_CLK:
2851 return venc_get_pixel_clock();
2852 case DSS_HDMI_M_PCLK:
2853 return hdmi_get_pixel_clock();
2861 unsigned long dispc_core_clk_rate(void)
2864 unsigned long fclk = dispc_fclk_rate();
2866 if (dss_has_feature(FEAT_CORE_CLK_DIV))
2867 lcd = REG_GET(DISPC_DIVISOR, 23, 16);
2869 lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
2874 static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
2877 enum omap_dss_clk_source lcd_clk_src;
2879 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
2881 lcd_clk_src = dss_get_lcd_clk_source(channel);
2883 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
2884 dss_get_generic_clk_source_name(lcd_clk_src),
2885 dss_feat_get_clk_source_name(lcd_clk_src));
2887 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
2889 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2890 dispc_mgr_lclk_rate(channel), lcd);
2891 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2892 dispc_mgr_pclk_rate(channel), pcd);
2895 void dispc_dump_clocks(struct seq_file *s)
2899 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
2901 if (dispc_runtime_get())
2904 seq_printf(s, "- DISPC -\n");
2906 seq_printf(s, "dispc fclk source = %s (%s)\n",
2907 dss_get_generic_clk_source_name(dispc_clk_src),
2908 dss_feat_get_clk_source_name(dispc_clk_src));
2910 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
2912 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
2913 seq_printf(s, "- DISPC-CORE-CLK -\n");
2914 l = dispc_read_reg(DISPC_DIVISOR);
2915 lcd = FLD_GET(l, 23, 16);
2917 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2918 (dispc_fclk_rate()/lcd), lcd);
2921 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
2923 if (dss_has_feature(FEAT_MGR_LCD2))
2924 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
2925 if (dss_has_feature(FEAT_MGR_LCD3))
2926 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
2928 dispc_runtime_put();
2931 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
2932 void dispc_dump_irqs(struct seq_file *s)
2934 unsigned long flags;
2935 struct dispc_irq_stats stats;
2937 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
2939 stats = dispc.irq_stats;
2940 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
2941 dispc.irq_stats.last_reset = jiffies;
2943 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
2945 seq_printf(s, "period %u ms\n",
2946 jiffies_to_msecs(jiffies - stats.last_reset));
2948 seq_printf(s, "irqs %d\n", stats.irq_count);
2950 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
2956 PIS(ACBIAS_COUNT_STAT);
2958 PIS(GFX_FIFO_UNDERFLOW);
2960 PIS(PAL_GAMMA_MASK);
2962 PIS(VID1_FIFO_UNDERFLOW);
2964 PIS(VID2_FIFO_UNDERFLOW);
2966 if (dss_feat_get_num_ovls() > 3) {
2967 PIS(VID3_FIFO_UNDERFLOW);
2971 PIS(SYNC_LOST_DIGIT);
2973 if (dss_has_feature(FEAT_MGR_LCD2)) {
2976 PIS(ACBIAS_COUNT_STAT2);
2979 if (dss_has_feature(FEAT_MGR_LCD3)) {
2982 PIS(ACBIAS_COUNT_STAT3);
2989 static void dispc_dump_regs(struct seq_file *s)
2992 const char *mgr_names[] = {
2993 [OMAP_DSS_CHANNEL_LCD] = "LCD",
2994 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
2995 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
2996 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
2998 const char *ovl_names[] = {
2999 [OMAP_DSS_GFX] = "GFX",
3000 [OMAP_DSS_VIDEO1] = "VID1",
3001 [OMAP_DSS_VIDEO2] = "VID2",
3002 [OMAP_DSS_VIDEO3] = "VID3",
3004 const char **p_names;
3006 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3008 if (dispc_runtime_get())
3011 /* DISPC common registers */
3012 DUMPREG(DISPC_REVISION);
3013 DUMPREG(DISPC_SYSCONFIG);
3014 DUMPREG(DISPC_SYSSTATUS);
3015 DUMPREG(DISPC_IRQSTATUS);
3016 DUMPREG(DISPC_IRQENABLE);
3017 DUMPREG(DISPC_CONTROL);
3018 DUMPREG(DISPC_CONFIG);
3019 DUMPREG(DISPC_CAPABLE);
3020 DUMPREG(DISPC_LINE_STATUS);
3021 DUMPREG(DISPC_LINE_NUMBER);
3022 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3023 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
3024 DUMPREG(DISPC_GLOBAL_ALPHA);
3025 if (dss_has_feature(FEAT_MGR_LCD2)) {
3026 DUMPREG(DISPC_CONTROL2);
3027 DUMPREG(DISPC_CONFIG2);
3029 if (dss_has_feature(FEAT_MGR_LCD3)) {
3030 DUMPREG(DISPC_CONTROL3);
3031 DUMPREG(DISPC_CONFIG3);
3036 #define DISPC_REG(i, name) name(i)
3037 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3038 48 - strlen(#r) - strlen(p_names[i]), " ", \
3039 dispc_read_reg(DISPC_REG(i, r)))
3041 p_names = mgr_names;
3043 /* DISPC channel specific registers */
3044 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3045 DUMPREG(i, DISPC_DEFAULT_COLOR);
3046 DUMPREG(i, DISPC_TRANS_COLOR);
3047 DUMPREG(i, DISPC_SIZE_MGR);
3049 if (i == OMAP_DSS_CHANNEL_DIGIT)
3052 DUMPREG(i, DISPC_DEFAULT_COLOR);
3053 DUMPREG(i, DISPC_TRANS_COLOR);
3054 DUMPREG(i, DISPC_TIMING_H);
3055 DUMPREG(i, DISPC_TIMING_V);
3056 DUMPREG(i, DISPC_POL_FREQ);
3057 DUMPREG(i, DISPC_DIVISORo);
3058 DUMPREG(i, DISPC_SIZE_MGR);
3060 DUMPREG(i, DISPC_DATA_CYCLE1);
3061 DUMPREG(i, DISPC_DATA_CYCLE2);
3062 DUMPREG(i, DISPC_DATA_CYCLE3);
3064 if (dss_has_feature(FEAT_CPR)) {
3065 DUMPREG(i, DISPC_CPR_COEF_R);
3066 DUMPREG(i, DISPC_CPR_COEF_G);
3067 DUMPREG(i, DISPC_CPR_COEF_B);
3071 p_names = ovl_names;
3073 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3074 DUMPREG(i, DISPC_OVL_BA0);
3075 DUMPREG(i, DISPC_OVL_BA1);
3076 DUMPREG(i, DISPC_OVL_POSITION);
3077 DUMPREG(i, DISPC_OVL_SIZE);
3078 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3079 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3080 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3081 DUMPREG(i, DISPC_OVL_ROW_INC);
3082 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3083 if (dss_has_feature(FEAT_PRELOAD))
3084 DUMPREG(i, DISPC_OVL_PRELOAD);
3086 if (i == OMAP_DSS_GFX) {
3087 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3088 DUMPREG(i, DISPC_OVL_TABLE_BA);
3092 DUMPREG(i, DISPC_OVL_FIR);
3093 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3094 DUMPREG(i, DISPC_OVL_ACCU0);
3095 DUMPREG(i, DISPC_OVL_ACCU1);
3096 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3097 DUMPREG(i, DISPC_OVL_BA0_UV);
3098 DUMPREG(i, DISPC_OVL_BA1_UV);
3099 DUMPREG(i, DISPC_OVL_FIR2);
3100 DUMPREG(i, DISPC_OVL_ACCU2_0);
3101 DUMPREG(i, DISPC_OVL_ACCU2_1);
3103 if (dss_has_feature(FEAT_ATTR2))
3104 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3105 if (dss_has_feature(FEAT_PRELOAD))
3106 DUMPREG(i, DISPC_OVL_PRELOAD);
3112 #define DISPC_REG(plane, name, i) name(plane, i)
3113 #define DUMPREG(plane, name, i) \
3114 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3115 46 - strlen(#name) - strlen(p_names[plane]), " ", \
3116 dispc_read_reg(DISPC_REG(plane, name, i)))
3118 /* Video pipeline coefficient registers */
3120 /* start from OMAP_DSS_VIDEO1 */
3121 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3122 for (j = 0; j < 8; j++)
3123 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
3125 for (j = 0; j < 8; j++)
3126 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
3128 for (j = 0; j < 5; j++)
3129 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
3131 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3132 for (j = 0; j < 8; j++)
3133 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3136 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3137 for (j = 0; j < 8; j++)
3138 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
3140 for (j = 0; j < 8; j++)
3141 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
3143 for (j = 0; j < 8; j++)
3144 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3148 dispc_runtime_put();
3154 /* with fck as input clock rate, find dispc dividers that produce req_pck */
3155 void dispc_find_clk_divs(unsigned long req_pck, unsigned long fck,
3156 struct dispc_clock_info *cinfo)
3158 u16 pcd_min, pcd_max;
3159 unsigned long best_pck;
3160 u16 best_ld, cur_ld;
3161 u16 best_pd, cur_pd;
3163 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3164 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3170 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
3171 unsigned long lck = fck / cur_ld;
3173 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
3174 unsigned long pck = lck / cur_pd;
3175 long old_delta = abs(best_pck - req_pck);
3176 long new_delta = abs(pck - req_pck);
3178 if (best_pck == 0 || new_delta < old_delta) {
3191 if (lck / pcd_min < req_pck)
3196 cinfo->lck_div = best_ld;
3197 cinfo->pck_div = best_pd;
3198 cinfo->lck = fck / cinfo->lck_div;
3199 cinfo->pck = cinfo->lck / cinfo->pck_div;
3202 /* calculate clock rates using dividers in cinfo */
3203 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3204 struct dispc_clock_info *cinfo)
3206 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3208 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3211 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3212 cinfo->pck = cinfo->lck / cinfo->pck_div;
3217 void dispc_mgr_set_clock_div(enum omap_channel channel,
3218 struct dispc_clock_info *cinfo)
3220 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3221 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3223 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
3226 int dispc_mgr_get_clock_div(enum omap_channel channel,
3227 struct dispc_clock_info *cinfo)
3231 fck = dispc_fclk_rate();
3233 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3234 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
3236 cinfo->lck = fck / cinfo->lck_div;
3237 cinfo->pck = cinfo->lck / cinfo->pck_div;
3242 /* dispc.irq_lock has to be locked by the caller */
3243 static void _omap_dispc_set_irqs(void)
3248 struct omap_dispc_isr_data *isr_data;
3250 mask = dispc.irq_error_mask;
3252 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3253 isr_data = &dispc.registered_isr[i];
3255 if (isr_data->isr == NULL)
3258 mask |= isr_data->mask;
3261 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3262 /* clear the irqstatus for newly enabled irqs */
3263 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
3265 dispc_write_reg(DISPC_IRQENABLE, mask);
3268 int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3272 unsigned long flags;
3273 struct omap_dispc_isr_data *isr_data;
3278 spin_lock_irqsave(&dispc.irq_lock, flags);
3280 /* check for duplicate entry */
3281 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3282 isr_data = &dispc.registered_isr[i];
3283 if (isr_data->isr == isr && isr_data->arg == arg &&
3284 isr_data->mask == mask) {
3293 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3294 isr_data = &dispc.registered_isr[i];
3296 if (isr_data->isr != NULL)
3299 isr_data->isr = isr;
3300 isr_data->arg = arg;
3301 isr_data->mask = mask;
3310 _omap_dispc_set_irqs();
3312 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3316 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3320 EXPORT_SYMBOL(omap_dispc_register_isr);
3322 int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3325 unsigned long flags;
3327 struct omap_dispc_isr_data *isr_data;
3329 spin_lock_irqsave(&dispc.irq_lock, flags);
3331 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3332 isr_data = &dispc.registered_isr[i];
3333 if (isr_data->isr != isr || isr_data->arg != arg ||
3334 isr_data->mask != mask)
3337 /* found the correct isr */
3339 isr_data->isr = NULL;
3340 isr_data->arg = NULL;
3348 _omap_dispc_set_irqs();
3350 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3354 EXPORT_SYMBOL(omap_dispc_unregister_isr);
3357 static void print_irq_status(u32 status)
3359 if ((status & dispc.irq_error_mask) == 0)
3362 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
3365 if (status & DISPC_IRQ_##x) \
3367 PIS(GFX_FIFO_UNDERFLOW);
3369 PIS(VID1_FIFO_UNDERFLOW);
3370 PIS(VID2_FIFO_UNDERFLOW);
3371 if (dss_feat_get_num_ovls() > 3)
3372 PIS(VID3_FIFO_UNDERFLOW);
3374 PIS(SYNC_LOST_DIGIT);
3375 if (dss_has_feature(FEAT_MGR_LCD2))
3377 if (dss_has_feature(FEAT_MGR_LCD3))
3385 /* Called from dss.c. Note that we don't touch clocks here,
3386 * but we presume they are on because we got an IRQ. However,
3387 * an irq handler may turn the clocks off, so we may not have
3388 * clock later in the function. */
3389 static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
3392 u32 irqstatus, irqenable;
3393 u32 handledirqs = 0;
3394 u32 unhandled_errors;
3395 struct omap_dispc_isr_data *isr_data;
3396 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3398 spin_lock(&dispc.irq_lock);
3400 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
3401 irqenable = dispc_read_reg(DISPC_IRQENABLE);
3403 /* IRQ is not for us */
3404 if (!(irqstatus & irqenable)) {
3405 spin_unlock(&dispc.irq_lock);
3409 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3410 spin_lock(&dispc.irq_stats_lock);
3411 dispc.irq_stats.irq_count++;
3412 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3413 spin_unlock(&dispc.irq_stats_lock);
3418 print_irq_status(irqstatus);
3420 /* Ack the interrupt. Do it here before clocks are possibly turned
3422 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
3423 /* flush posted write */
3424 dispc_read_reg(DISPC_IRQSTATUS);
3426 /* make a copy and unlock, so that isrs can unregister
3428 memcpy(registered_isr, dispc.registered_isr,
3429 sizeof(registered_isr));
3431 spin_unlock(&dispc.irq_lock);
3433 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3434 isr_data = ®istered_isr[i];
3439 if (isr_data->mask & irqstatus) {
3440 isr_data->isr(isr_data->arg, irqstatus);
3441 handledirqs |= isr_data->mask;
3445 spin_lock(&dispc.irq_lock);
3447 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3449 if (unhandled_errors) {
3450 dispc.error_irqs |= unhandled_errors;
3452 dispc.irq_error_mask &= ~unhandled_errors;
3453 _omap_dispc_set_irqs();
3455 schedule_work(&dispc.error_work);
3458 spin_unlock(&dispc.irq_lock);
3463 static void dispc_error_worker(struct work_struct *work)
3467 unsigned long flags;
3468 static const unsigned fifo_underflow_bits[] = {
3469 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3470 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3471 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
3472 DISPC_IRQ_VID3_FIFO_UNDERFLOW,
3475 spin_lock_irqsave(&dispc.irq_lock, flags);
3476 errors = dispc.error_irqs;
3477 dispc.error_irqs = 0;
3478 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3480 dispc_runtime_get();
3482 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3483 struct omap_overlay *ovl;
3486 ovl = omap_dss_get_overlay(i);
3487 bit = fifo_underflow_bits[i];
3490 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3492 dispc_ovl_enable(ovl->id, false);
3493 dispc_mgr_go(ovl->manager->id);
3498 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3499 struct omap_overlay_manager *mgr;
3502 mgr = omap_dss_get_overlay_manager(i);
3503 bit = mgr_desc[i].sync_lost_irq;
3506 struct omap_dss_device *dssdev = mgr->device;
3509 DSSERR("SYNC_LOST on channel %s, restarting the output "
3510 "with video overlays disabled\n",
3513 enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
3514 dssdev->driver->disable(dssdev);
3516 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3517 struct omap_overlay *ovl;
3518 ovl = omap_dss_get_overlay(i);
3520 if (ovl->id != OMAP_DSS_GFX &&
3521 ovl->manager == mgr)
3522 dispc_ovl_enable(ovl->id, false);
3525 dispc_mgr_go(mgr->id);
3529 dssdev->driver->enable(dssdev);
3533 if (errors & DISPC_IRQ_OCP_ERR) {
3534 DSSERR("OCP_ERR\n");
3535 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3536 struct omap_overlay_manager *mgr;
3537 mgr = omap_dss_get_overlay_manager(i);
3538 if (mgr->device && mgr->device->driver)
3539 mgr->device->driver->disable(mgr->device);
3543 spin_lock_irqsave(&dispc.irq_lock, flags);
3544 dispc.irq_error_mask |= errors;
3545 _omap_dispc_set_irqs();
3546 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3548 dispc_runtime_put();
3551 int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3553 void dispc_irq_wait_handler(void *data, u32 mask)
3555 complete((struct completion *)data);
3559 DECLARE_COMPLETION_ONSTACK(completion);
3561 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3567 timeout = wait_for_completion_timeout(&completion, timeout);
3569 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3574 if (timeout == -ERESTARTSYS)
3575 return -ERESTARTSYS;
3580 int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3581 unsigned long timeout)
3583 void dispc_irq_wait_handler(void *data, u32 mask)
3585 complete((struct completion *)data);
3589 DECLARE_COMPLETION_ONSTACK(completion);
3591 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3597 timeout = wait_for_completion_interruptible_timeout(&completion,
3600 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3605 if (timeout == -ERESTARTSYS)
3606 return -ERESTARTSYS;
3611 static void _omap_dispc_initialize_irq(void)
3613 unsigned long flags;
3615 spin_lock_irqsave(&dispc.irq_lock, flags);
3617 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3619 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
3620 if (dss_has_feature(FEAT_MGR_LCD2))
3621 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
3622 if (dss_has_feature(FEAT_MGR_LCD3))
3623 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST3;
3624 if (dss_feat_get_num_ovls() > 3)
3625 dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
3627 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3629 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3631 _omap_dispc_set_irqs();
3633 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3636 void dispc_enable_sidle(void)
3638 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3641 void dispc_disable_sidle(void)
3643 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3646 static void _omap_dispc_initial_config(void)
3650 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3651 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3652 l = dispc_read_reg(DISPC_DIVISOR);
3653 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3654 l = FLD_MOD(l, 1, 0, 0);
3655 l = FLD_MOD(l, 1, 23, 16);
3656 dispc_write_reg(DISPC_DIVISOR, l);
3660 if (dss_has_feature(FEAT_FUNCGATED))
3661 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3663 _dispc_setup_color_conv_coef();
3665 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3667 dispc_read_plane_fifo_sizes();
3669 dispc_configure_burst_sizes();
3671 dispc_ovl_enable_zorder_planes();
3674 /* DISPC HW IP initialisation */
3675 static int __init omap_dispchw_probe(struct platform_device *pdev)
3679 struct resource *dispc_mem;
3684 spin_lock_init(&dispc.irq_lock);
3686 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3687 spin_lock_init(&dispc.irq_stats_lock);
3688 dispc.irq_stats.last_reset = jiffies;
3691 INIT_WORK(&dispc.error_work, dispc_error_worker);
3693 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3695 DSSERR("can't get IORESOURCE_MEM DISPC\n");
3699 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3700 resource_size(dispc_mem));
3702 DSSERR("can't ioremap DISPC\n");
3706 dispc.irq = platform_get_irq(dispc.pdev, 0);
3707 if (dispc.irq < 0) {
3708 DSSERR("platform_get_irq failed\n");
3712 r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
3713 IRQF_SHARED, "OMAP DISPC", dispc.pdev);
3715 DSSERR("request_irq failed\n");
3719 clk = clk_get(&pdev->dev, "fck");
3721 DSSERR("can't get fck\n");
3726 dispc.dss_clk = clk;
3728 pm_runtime_enable(&pdev->dev);
3730 r = dispc_runtime_get();
3732 goto err_runtime_get;
3734 _omap_dispc_initial_config();
3736 _omap_dispc_initialize_irq();
3738 rev = dispc_read_reg(DISPC_REVISION);
3739 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
3740 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3742 dispc_runtime_put();
3744 dss_debugfs_create_file("dispc", dispc_dump_regs);
3746 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3747 dss_debugfs_create_file("dispc_irq", dispc_dump_irqs);
3752 pm_runtime_disable(&pdev->dev);
3753 clk_put(dispc.dss_clk);
3757 static int __exit omap_dispchw_remove(struct platform_device *pdev)
3759 pm_runtime_disable(&pdev->dev);
3761 clk_put(dispc.dss_clk);
3766 static int dispc_runtime_suspend(struct device *dev)
3768 dispc_save_context();
3773 static int dispc_runtime_resume(struct device *dev)
3775 dispc_restore_context();
3780 static const struct dev_pm_ops dispc_pm_ops = {
3781 .runtime_suspend = dispc_runtime_suspend,
3782 .runtime_resume = dispc_runtime_resume,
3785 static struct platform_driver omap_dispchw_driver = {
3786 .remove = __exit_p(omap_dispchw_remove),
3788 .name = "omapdss_dispc",
3789 .owner = THIS_MODULE,
3790 .pm = &dispc_pm_ops,
3794 int __init dispc_init_platform_driver(void)
3796 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
3799 void __exit dispc_uninit_platform_driver(void)
3801 platform_driver_unregister(&omap_dispchw_driver);