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/platform_device.h>
37 #include <linux/pm_runtime.h>
38 #include <linux/sizes.h>
39 #include <linux/mfd/syscon.h>
40 #include <linux/regmap.h>
42 #include <linux/component.h>
44 #include <video/omapfb_dss.h>
47 #include "dss_features.h"
51 #define DISPC_SZ_REGS SZ_4K
53 enum omap_burst_size
{
59 #define REG_GET(idx, start, end) \
60 FLD_GET(dispc_read_reg(idx), start, end)
62 #define REG_FLD_MOD(idx, val, start, end) \
63 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
65 struct dispc_features
{
76 unsigned long max_lcd_pclk
;
77 unsigned long max_tv_pclk
;
78 int (*calc_scaling
) (unsigned long pclk
, unsigned long lclk
,
79 const struct omap_video_timings
*mgr_timings
,
80 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
81 enum omap_color_mode color_mode
, bool *five_taps
,
82 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
83 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
);
84 unsigned long (*calc_core_clk
) (unsigned long pclk
,
85 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
89 /* swap GFX & WB fifos */
90 bool gfx_fifo_workaround
:1;
92 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
93 bool no_framedone_tv
:1;
95 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
96 bool mstandby_workaround
:1;
98 bool set_max_preload
:1;
100 /* PIXEL_INC is not added to the last pixel of a line */
101 bool last_pixel_inc_missing
:1;
103 /* POL_FREQ has ALIGN bit */
104 bool supports_sync_align
:1;
106 bool has_writeback
:1;
109 #define DISPC_MAX_NR_FIFOS 5
112 struct platform_device
*pdev
;
116 irq_handler_t user_handler
;
119 unsigned long core_clk_rate
;
120 unsigned long tv_pclk_rate
;
122 u32 fifo_size
[DISPC_MAX_NR_FIFOS
];
123 /* maps which plane is using a fifo. fifo-id -> plane-id */
124 int fifo_assignment
[DISPC_MAX_NR_FIFOS
];
127 u32 ctx
[DISPC_SZ_REGS
/ sizeof(u32
)];
129 const struct dispc_features
*feat
;
133 struct regmap
*syscon_pol
;
134 u32 syscon_pol_offset
;
136 /* DISPC_CONTROL & DISPC_CONFIG lock*/
137 spinlock_t control_lock
;
140 enum omap_color_component
{
141 /* used for all color formats for OMAP3 and earlier
142 * and for RGB and Y color component on OMAP4
144 DISPC_COLOR_COMPONENT_RGB_Y
= 1 << 0,
145 /* used for UV component for
146 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
147 * color formats on OMAP4
149 DISPC_COLOR_COMPONENT_UV
= 1 << 1,
152 enum mgr_reg_fields
{
153 DISPC_MGR_FLD_ENABLE
,
154 DISPC_MGR_FLD_STNTFT
,
156 DISPC_MGR_FLD_TFTDATALINES
,
157 DISPC_MGR_FLD_STALLMODE
,
158 DISPC_MGR_FLD_TCKENABLE
,
159 DISPC_MGR_FLD_TCKSELECTION
,
161 DISPC_MGR_FLD_FIFOHANDCHECK
,
162 /* used to maintain a count of the above fields */
166 struct dispc_reg_field
{
172 static const struct {
177 struct dispc_reg_field reg_desc
[DISPC_MGR_FLD_NUM
];
179 [OMAP_DSS_CHANNEL_LCD
] = {
181 .vsync_irq
= DISPC_IRQ_VSYNC
,
182 .framedone_irq
= DISPC_IRQ_FRAMEDONE
,
183 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST
,
185 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL
, 0, 0 },
186 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL
, 3, 3 },
187 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL
, 5, 5 },
188 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL
, 9, 8 },
189 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL
, 11, 11 },
190 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG
, 10, 10 },
191 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG
, 11, 11 },
192 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG
, 15, 15 },
193 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG
, 16, 16 },
196 [OMAP_DSS_CHANNEL_DIGIT
] = {
198 .vsync_irq
= DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_EVSYNC_EVEN
,
199 .framedone_irq
= DISPC_IRQ_FRAMEDONETV
,
200 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST_DIGIT
,
202 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL
, 1, 1 },
203 [DISPC_MGR_FLD_STNTFT
] = { },
204 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL
, 6, 6 },
205 [DISPC_MGR_FLD_TFTDATALINES
] = { },
206 [DISPC_MGR_FLD_STALLMODE
] = { },
207 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG
, 12, 12 },
208 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG
, 13, 13 },
209 [DISPC_MGR_FLD_CPR
] = { },
210 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG
, 16, 16 },
213 [OMAP_DSS_CHANNEL_LCD2
] = {
215 .vsync_irq
= DISPC_IRQ_VSYNC2
,
216 .framedone_irq
= DISPC_IRQ_FRAMEDONE2
,
217 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST2
,
219 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL2
, 0, 0 },
220 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL2
, 3, 3 },
221 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL2
, 5, 5 },
222 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL2
, 9, 8 },
223 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL2
, 11, 11 },
224 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG2
, 10, 10 },
225 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG2
, 11, 11 },
226 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG2
, 15, 15 },
227 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG2
, 16, 16 },
230 [OMAP_DSS_CHANNEL_LCD3
] = {
232 .vsync_irq
= DISPC_IRQ_VSYNC3
,
233 .framedone_irq
= DISPC_IRQ_FRAMEDONE3
,
234 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST3
,
236 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL3
, 0, 0 },
237 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL3
, 3, 3 },
238 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL3
, 5, 5 },
239 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL3
, 9, 8 },
240 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL3
, 11, 11 },
241 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG3
, 10, 10 },
242 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG3
, 11, 11 },
243 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG3
, 15, 15 },
244 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG3
, 16, 16 },
249 struct color_conv_coef
{
250 int ry
, rcr
, rcb
, gy
, gcr
, gcb
, by
, bcr
, bcb
;
254 static unsigned long dispc_fclk_rate(void);
255 static unsigned long dispc_core_clk_rate(void);
256 static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel
);
257 static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel
);
259 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane
);
260 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane
);
262 static inline void dispc_write_reg(const u16 idx
, u32 val
)
264 __raw_writel(val
, dispc
.base
+ idx
);
267 static inline u32
dispc_read_reg(const u16 idx
)
269 return __raw_readl(dispc
.base
+ idx
);
272 static u32
mgr_fld_read(enum omap_channel channel
, enum mgr_reg_fields regfld
)
274 const struct dispc_reg_field rfld
= mgr_desc
[channel
].reg_desc
[regfld
];
275 return REG_GET(rfld
.reg
, rfld
.high
, rfld
.low
);
278 static void mgr_fld_write(enum omap_channel channel
,
279 enum mgr_reg_fields regfld
, int val
) {
280 const struct dispc_reg_field rfld
= mgr_desc
[channel
].reg_desc
[regfld
];
281 const bool need_lock
= rfld
.reg
== DISPC_CONTROL
|| rfld
.reg
== DISPC_CONFIG
;
285 spin_lock_irqsave(&dispc
.control_lock
, flags
);
287 REG_FLD_MOD(rfld
.reg
, val
, rfld
.high
, rfld
.low
);
290 spin_unlock_irqrestore(&dispc
.control_lock
, flags
);
294 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
296 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
298 static void dispc_save_context(void)
302 DSSDBG("dispc_save_context\n");
308 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
309 dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
311 if (dss_has_feature(FEAT_MGR_LCD2
)) {
315 if (dss_has_feature(FEAT_MGR_LCD3
)) {
320 for (i
= 0; i
< dss_feat_get_num_mgrs(); i
++) {
321 SR(DEFAULT_COLOR(i
));
324 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
335 if (dss_has_feature(FEAT_CPR
)) {
342 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
347 SR(OVL_ATTRIBUTES(i
));
348 SR(OVL_FIFO_THRESHOLD(i
));
350 SR(OVL_PIXEL_INC(i
));
351 if (dss_has_feature(FEAT_PRELOAD
))
353 if (i
== OMAP_DSS_GFX
) {
354 SR(OVL_WINDOW_SKIP(i
));
359 SR(OVL_PICTURE_SIZE(i
));
363 for (j
= 0; j
< 8; j
++)
364 SR(OVL_FIR_COEF_H(i
, j
));
366 for (j
= 0; j
< 8; j
++)
367 SR(OVL_FIR_COEF_HV(i
, j
));
369 for (j
= 0; j
< 5; j
++)
370 SR(OVL_CONV_COEF(i
, j
));
372 if (dss_has_feature(FEAT_FIR_COEF_V
)) {
373 for (j
= 0; j
< 8; j
++)
374 SR(OVL_FIR_COEF_V(i
, j
));
377 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
384 for (j
= 0; j
< 8; j
++)
385 SR(OVL_FIR_COEF_H2(i
, j
));
387 for (j
= 0; j
< 8; j
++)
388 SR(OVL_FIR_COEF_HV2(i
, j
));
390 for (j
= 0; j
< 8; j
++)
391 SR(OVL_FIR_COEF_V2(i
, j
));
393 if (dss_has_feature(FEAT_ATTR2
))
394 SR(OVL_ATTRIBUTES2(i
));
397 if (dss_has_feature(FEAT_CORE_CLK_DIV
))
400 dispc
.ctx_valid
= true;
402 DSSDBG("context saved\n");
405 static void dispc_restore_context(void)
409 DSSDBG("dispc_restore_context\n");
411 if (!dispc
.ctx_valid
)
418 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
419 dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
421 if (dss_has_feature(FEAT_MGR_LCD2
))
423 if (dss_has_feature(FEAT_MGR_LCD3
))
426 for (i
= 0; i
< dss_feat_get_num_mgrs(); i
++) {
427 RR(DEFAULT_COLOR(i
));
430 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
441 if (dss_has_feature(FEAT_CPR
)) {
448 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
453 RR(OVL_ATTRIBUTES(i
));
454 RR(OVL_FIFO_THRESHOLD(i
));
456 RR(OVL_PIXEL_INC(i
));
457 if (dss_has_feature(FEAT_PRELOAD
))
459 if (i
== OMAP_DSS_GFX
) {
460 RR(OVL_WINDOW_SKIP(i
));
465 RR(OVL_PICTURE_SIZE(i
));
469 for (j
= 0; j
< 8; j
++)
470 RR(OVL_FIR_COEF_H(i
, j
));
472 for (j
= 0; j
< 8; j
++)
473 RR(OVL_FIR_COEF_HV(i
, j
));
475 for (j
= 0; j
< 5; j
++)
476 RR(OVL_CONV_COEF(i
, j
));
478 if (dss_has_feature(FEAT_FIR_COEF_V
)) {
479 for (j
= 0; j
< 8; j
++)
480 RR(OVL_FIR_COEF_V(i
, j
));
483 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
490 for (j
= 0; j
< 8; j
++)
491 RR(OVL_FIR_COEF_H2(i
, j
));
493 for (j
= 0; j
< 8; j
++)
494 RR(OVL_FIR_COEF_HV2(i
, j
));
496 for (j
= 0; j
< 8; j
++)
497 RR(OVL_FIR_COEF_V2(i
, j
));
499 if (dss_has_feature(FEAT_ATTR2
))
500 RR(OVL_ATTRIBUTES2(i
));
503 if (dss_has_feature(FEAT_CORE_CLK_DIV
))
506 /* enable last, because LCD & DIGIT enable are here */
508 if (dss_has_feature(FEAT_MGR_LCD2
))
510 if (dss_has_feature(FEAT_MGR_LCD3
))
512 /* clear spurious SYNC_LOST_DIGIT interrupts */
513 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT
);
516 * enable last so IRQs won't trigger before
517 * the context is fully restored
521 DSSDBG("context restored\n");
527 int dispc_runtime_get(void)
531 DSSDBG("dispc_runtime_get\n");
533 r
= pm_runtime_get_sync(&dispc
.pdev
->dev
);
535 return r
< 0 ? r
: 0;
537 EXPORT_SYMBOL(dispc_runtime_get
);
539 void dispc_runtime_put(void)
543 DSSDBG("dispc_runtime_put\n");
545 r
= pm_runtime_put_sync(&dispc
.pdev
->dev
);
546 WARN_ON(r
< 0 && r
!= -ENOSYS
);
548 EXPORT_SYMBOL(dispc_runtime_put
);
550 u32
dispc_mgr_get_vsync_irq(enum omap_channel channel
)
552 return mgr_desc
[channel
].vsync_irq
;
554 EXPORT_SYMBOL(dispc_mgr_get_vsync_irq
);
556 u32
dispc_mgr_get_framedone_irq(enum omap_channel channel
)
558 if (channel
== OMAP_DSS_CHANNEL_DIGIT
&& dispc
.feat
->no_framedone_tv
)
561 return mgr_desc
[channel
].framedone_irq
;
563 EXPORT_SYMBOL(dispc_mgr_get_framedone_irq
);
565 u32
dispc_mgr_get_sync_lost_irq(enum omap_channel channel
)
567 return mgr_desc
[channel
].sync_lost_irq
;
569 EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq
);
571 u32
dispc_wb_get_framedone_irq(void)
573 return DISPC_IRQ_FRAMEDONEWB
;
576 bool dispc_mgr_go_busy(enum omap_channel channel
)
578 return mgr_fld_read(channel
, DISPC_MGR_FLD_GO
) == 1;
580 EXPORT_SYMBOL(dispc_mgr_go_busy
);
582 void dispc_mgr_go(enum omap_channel channel
)
584 WARN_ON(!dispc_mgr_is_enabled(channel
));
585 WARN_ON(dispc_mgr_go_busy(channel
));
587 DSSDBG("GO %s\n", mgr_desc
[channel
].name
);
589 mgr_fld_write(channel
, DISPC_MGR_FLD_GO
, 1);
591 EXPORT_SYMBOL(dispc_mgr_go
);
593 bool dispc_wb_go_busy(void)
595 return REG_GET(DISPC_CONTROL2
, 6, 6) == 1;
598 void dispc_wb_go(void)
600 enum omap_plane plane
= OMAP_DSS_WB
;
603 enable
= REG_GET(DISPC_OVL_ATTRIBUTES(plane
), 0, 0) == 1;
608 go
= REG_GET(DISPC_CONTROL2
, 6, 6) == 1;
610 DSSERR("GO bit not down for WB\n");
614 REG_FLD_MOD(DISPC_CONTROL2
, 1, 6, 6);
617 static void dispc_ovl_write_firh_reg(enum omap_plane plane
, int reg
, u32 value
)
619 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane
, reg
), value
);
622 static void dispc_ovl_write_firhv_reg(enum omap_plane plane
, int reg
, u32 value
)
624 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane
, reg
), value
);
627 static void dispc_ovl_write_firv_reg(enum omap_plane plane
, int reg
, u32 value
)
629 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane
, reg
), value
);
632 static void dispc_ovl_write_firh2_reg(enum omap_plane plane
, int reg
, u32 value
)
634 BUG_ON(plane
== OMAP_DSS_GFX
);
636 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane
, reg
), value
);
639 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane
, int reg
,
642 BUG_ON(plane
== OMAP_DSS_GFX
);
644 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane
, reg
), value
);
647 static void dispc_ovl_write_firv2_reg(enum omap_plane plane
, int reg
, u32 value
)
649 BUG_ON(plane
== OMAP_DSS_GFX
);
651 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane
, reg
), value
);
654 static void dispc_ovl_set_scale_coef(enum omap_plane plane
, int fir_hinc
,
655 int fir_vinc
, int five_taps
,
656 enum omap_color_component color_comp
)
658 const struct dispc_coef
*h_coef
, *v_coef
;
661 h_coef
= dispc_ovl_get_scale_coef(fir_hinc
, true);
662 v_coef
= dispc_ovl_get_scale_coef(fir_vinc
, five_taps
);
664 for (i
= 0; i
< 8; i
++) {
667 h
= FLD_VAL(h_coef
[i
].hc0_vc00
, 7, 0)
668 | FLD_VAL(h_coef
[i
].hc1_vc0
, 15, 8)
669 | FLD_VAL(h_coef
[i
].hc2_vc1
, 23, 16)
670 | FLD_VAL(h_coef
[i
].hc3_vc2
, 31, 24);
671 hv
= FLD_VAL(h_coef
[i
].hc4_vc22
, 7, 0)
672 | FLD_VAL(v_coef
[i
].hc1_vc0
, 15, 8)
673 | FLD_VAL(v_coef
[i
].hc2_vc1
, 23, 16)
674 | FLD_VAL(v_coef
[i
].hc3_vc2
, 31, 24);
676 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
) {
677 dispc_ovl_write_firh_reg(plane
, i
, h
);
678 dispc_ovl_write_firhv_reg(plane
, i
, hv
);
680 dispc_ovl_write_firh2_reg(plane
, i
, h
);
681 dispc_ovl_write_firhv2_reg(plane
, i
, hv
);
687 for (i
= 0; i
< 8; i
++) {
689 v
= FLD_VAL(v_coef
[i
].hc0_vc00
, 7, 0)
690 | FLD_VAL(v_coef
[i
].hc4_vc22
, 15, 8);
691 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
)
692 dispc_ovl_write_firv_reg(plane
, i
, v
);
694 dispc_ovl_write_firv2_reg(plane
, i
, v
);
700 static void dispc_ovl_write_color_conv_coef(enum omap_plane plane
,
701 const struct color_conv_coef
*ct
)
703 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
705 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 0), CVAL(ct
->rcr
, ct
->ry
));
706 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 1), CVAL(ct
->gy
, ct
->rcb
));
707 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 2), CVAL(ct
->gcb
, ct
->gcr
));
708 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 3), CVAL(ct
->bcr
, ct
->by
));
709 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 4), CVAL(0, ct
->bcb
));
711 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), ct
->full_range
, 11, 11);
716 static void dispc_setup_color_conv_coef(void)
719 int num_ovl
= dss_feat_get_num_ovls();
720 const struct color_conv_coef ctbl_bt601_5_ovl
= {
722 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
724 const struct color_conv_coef ctbl_bt601_5_wb
= {
726 66, 129, 25, 112, -94, -18, -38, -74, 112, 0,
729 for (i
= 1; i
< num_ovl
; i
++)
730 dispc_ovl_write_color_conv_coef(i
, &ctbl_bt601_5_ovl
);
732 if (dispc
.feat
->has_writeback
)
733 dispc_ovl_write_color_conv_coef(OMAP_DSS_WB
, &ctbl_bt601_5_wb
);
736 static void dispc_ovl_set_ba0(enum omap_plane plane
, u32 paddr
)
738 dispc_write_reg(DISPC_OVL_BA0(plane
), paddr
);
741 static void dispc_ovl_set_ba1(enum omap_plane plane
, u32 paddr
)
743 dispc_write_reg(DISPC_OVL_BA1(plane
), paddr
);
746 static void dispc_ovl_set_ba0_uv(enum omap_plane plane
, u32 paddr
)
748 dispc_write_reg(DISPC_OVL_BA0_UV(plane
), paddr
);
751 static void dispc_ovl_set_ba1_uv(enum omap_plane plane
, u32 paddr
)
753 dispc_write_reg(DISPC_OVL_BA1_UV(plane
), paddr
);
756 static void dispc_ovl_set_pos(enum omap_plane plane
,
757 enum omap_overlay_caps caps
, int x
, int y
)
761 if ((caps
& OMAP_DSS_OVL_CAP_POS
) == 0)
764 val
= FLD_VAL(y
, 26, 16) | FLD_VAL(x
, 10, 0);
766 dispc_write_reg(DISPC_OVL_POSITION(plane
), val
);
769 static void dispc_ovl_set_input_size(enum omap_plane plane
, int width
,
772 u32 val
= FLD_VAL(height
- 1, 26, 16) | FLD_VAL(width
- 1, 10, 0);
774 if (plane
== OMAP_DSS_GFX
|| plane
== OMAP_DSS_WB
)
775 dispc_write_reg(DISPC_OVL_SIZE(plane
), val
);
777 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane
), val
);
780 static void dispc_ovl_set_output_size(enum omap_plane plane
, int width
,
785 BUG_ON(plane
== OMAP_DSS_GFX
);
787 val
= FLD_VAL(height
- 1, 26, 16) | FLD_VAL(width
- 1, 10, 0);
789 if (plane
== OMAP_DSS_WB
)
790 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane
), val
);
792 dispc_write_reg(DISPC_OVL_SIZE(plane
), val
);
795 static void dispc_ovl_set_zorder(enum omap_plane plane
,
796 enum omap_overlay_caps caps
, u8 zorder
)
798 if ((caps
& OMAP_DSS_OVL_CAP_ZORDER
) == 0)
801 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), zorder
, 27, 26);
804 static void dispc_ovl_enable_zorder_planes(void)
808 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
811 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++)
812 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i
), 1, 25, 25);
815 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane
,
816 enum omap_overlay_caps caps
, bool enable
)
818 if ((caps
& OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
) == 0)
821 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
? 1 : 0, 28, 28);
824 static void dispc_ovl_setup_global_alpha(enum omap_plane plane
,
825 enum omap_overlay_caps caps
, u8 global_alpha
)
827 static const unsigned shifts
[] = { 0, 8, 16, 24, };
830 if ((caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
833 shift
= shifts
[plane
];
834 REG_FLD_MOD(DISPC_GLOBAL_ALPHA
, global_alpha
, shift
+ 7, shift
);
837 static void dispc_ovl_set_pix_inc(enum omap_plane plane
, s32 inc
)
839 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane
), inc
);
842 static void dispc_ovl_set_row_inc(enum omap_plane plane
, s32 inc
)
844 dispc_write_reg(DISPC_OVL_ROW_INC(plane
), inc
);
847 static void dispc_ovl_set_color_mode(enum omap_plane plane
,
848 enum omap_color_mode color_mode
)
851 if (plane
!= OMAP_DSS_GFX
) {
852 switch (color_mode
) {
853 case OMAP_DSS_COLOR_NV12
:
855 case OMAP_DSS_COLOR_RGBX16
:
857 case OMAP_DSS_COLOR_RGBA16
:
859 case OMAP_DSS_COLOR_RGB12U
:
861 case OMAP_DSS_COLOR_ARGB16
:
863 case OMAP_DSS_COLOR_RGB16
:
865 case OMAP_DSS_COLOR_ARGB16_1555
:
867 case OMAP_DSS_COLOR_RGB24U
:
869 case OMAP_DSS_COLOR_RGB24P
:
871 case OMAP_DSS_COLOR_YUV2
:
873 case OMAP_DSS_COLOR_UYVY
:
875 case OMAP_DSS_COLOR_ARGB32
:
877 case OMAP_DSS_COLOR_RGBA32
:
879 case OMAP_DSS_COLOR_RGBX32
:
881 case OMAP_DSS_COLOR_XRGB16_1555
:
887 switch (color_mode
) {
888 case OMAP_DSS_COLOR_CLUT1
:
890 case OMAP_DSS_COLOR_CLUT2
:
892 case OMAP_DSS_COLOR_CLUT4
:
894 case OMAP_DSS_COLOR_CLUT8
:
896 case OMAP_DSS_COLOR_RGB12U
:
898 case OMAP_DSS_COLOR_ARGB16
:
900 case OMAP_DSS_COLOR_RGB16
:
902 case OMAP_DSS_COLOR_ARGB16_1555
:
904 case OMAP_DSS_COLOR_RGB24U
:
906 case OMAP_DSS_COLOR_RGB24P
:
908 case OMAP_DSS_COLOR_RGBX16
:
910 case OMAP_DSS_COLOR_RGBA16
:
912 case OMAP_DSS_COLOR_ARGB32
:
914 case OMAP_DSS_COLOR_RGBA32
:
916 case OMAP_DSS_COLOR_RGBX32
:
918 case OMAP_DSS_COLOR_XRGB16_1555
:
925 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), m
, 4, 1);
928 static void dispc_ovl_configure_burst_type(enum omap_plane plane
,
929 enum omap_dss_rotation_type rotation_type
)
931 if (dss_has_feature(FEAT_BURST_2D
) == 0)
934 if (rotation_type
== OMAP_DSS_ROT_TILER
)
935 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), 1, 29, 29);
937 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), 0, 29, 29);
940 void dispc_ovl_set_channel_out(enum omap_plane plane
, enum omap_channel channel
)
944 int chan
= 0, chan2
= 0;
950 case OMAP_DSS_VIDEO1
:
951 case OMAP_DSS_VIDEO2
:
952 case OMAP_DSS_VIDEO3
:
960 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
961 if (dss_has_feature(FEAT_MGR_LCD2
)) {
963 case OMAP_DSS_CHANNEL_LCD
:
967 case OMAP_DSS_CHANNEL_DIGIT
:
971 case OMAP_DSS_CHANNEL_LCD2
:
975 case OMAP_DSS_CHANNEL_LCD3
:
976 if (dss_has_feature(FEAT_MGR_LCD3
)) {
984 case OMAP_DSS_CHANNEL_WB
:
993 val
= FLD_MOD(val
, chan
, shift
, shift
);
994 val
= FLD_MOD(val
, chan2
, 31, 30);
996 val
= FLD_MOD(val
, channel
, shift
, shift
);
998 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), val
);
1000 EXPORT_SYMBOL(dispc_ovl_set_channel_out
);
1002 static enum omap_channel
dispc_ovl_get_channel_out(enum omap_plane plane
)
1011 case OMAP_DSS_VIDEO1
:
1012 case OMAP_DSS_VIDEO2
:
1013 case OMAP_DSS_VIDEO3
:
1021 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1023 if (FLD_GET(val
, shift
, shift
) == 1)
1024 return OMAP_DSS_CHANNEL_DIGIT
;
1026 if (!dss_has_feature(FEAT_MGR_LCD2
))
1027 return OMAP_DSS_CHANNEL_LCD
;
1029 switch (FLD_GET(val
, 31, 30)) {
1032 return OMAP_DSS_CHANNEL_LCD
;
1034 return OMAP_DSS_CHANNEL_LCD2
;
1036 return OMAP_DSS_CHANNEL_LCD3
;
1038 return OMAP_DSS_CHANNEL_WB
;
1042 void dispc_wb_set_channel_in(enum dss_writeback_channel channel
)
1044 enum omap_plane plane
= OMAP_DSS_WB
;
1046 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), channel
, 18, 16);
1049 static void dispc_ovl_set_burst_size(enum omap_plane plane
,
1050 enum omap_burst_size burst_size
)
1052 static const unsigned shifts
[] = { 6, 14, 14, 14, 14, };
1055 shift
= shifts
[plane
];
1056 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), burst_size
, shift
+ 1, shift
);
1059 static void dispc_configure_burst_sizes(void)
1062 const int burst_size
= BURST_SIZE_X8
;
1064 /* Configure burst size always to maximum size */
1065 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
)
1066 dispc_ovl_set_burst_size(i
, burst_size
);
1067 if (dispc
.feat
->has_writeback
)
1068 dispc_ovl_set_burst_size(OMAP_DSS_WB
, burst_size
);
1071 static u32
dispc_ovl_get_burst_size(enum omap_plane plane
)
1073 unsigned unit
= dss_feat_get_burst_size_unit();
1074 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1078 void dispc_enable_gamma_table(bool enable
)
1081 * This is partially implemented to support only disabling of
1085 DSSWARN("Gamma table enabling for TV not yet supported");
1089 REG_FLD_MOD(DISPC_CONFIG
, enable
, 9, 9);
1092 static void dispc_mgr_enable_cpr(enum omap_channel channel
, bool enable
)
1094 if (channel
== OMAP_DSS_CHANNEL_DIGIT
)
1097 mgr_fld_write(channel
, DISPC_MGR_FLD_CPR
, enable
);
1100 static void dispc_mgr_set_cpr_coef(enum omap_channel channel
,
1101 const struct omap_dss_cpr_coefs
*coefs
)
1103 u32 coef_r
, coef_g
, coef_b
;
1105 if (!dss_mgr_is_lcd(channel
))
1108 coef_r
= FLD_VAL(coefs
->rr
, 31, 22) | FLD_VAL(coefs
->rg
, 20, 11) |
1109 FLD_VAL(coefs
->rb
, 9, 0);
1110 coef_g
= FLD_VAL(coefs
->gr
, 31, 22) | FLD_VAL(coefs
->gg
, 20, 11) |
1111 FLD_VAL(coefs
->gb
, 9, 0);
1112 coef_b
= FLD_VAL(coefs
->br
, 31, 22) | FLD_VAL(coefs
->bg
, 20, 11) |
1113 FLD_VAL(coefs
->bb
, 9, 0);
1115 dispc_write_reg(DISPC_CPR_COEF_R(channel
), coef_r
);
1116 dispc_write_reg(DISPC_CPR_COEF_G(channel
), coef_g
);
1117 dispc_write_reg(DISPC_CPR_COEF_B(channel
), coef_b
);
1120 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane
, bool enable
)
1124 BUG_ON(plane
== OMAP_DSS_GFX
);
1126 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1127 val
= FLD_MOD(val
, enable
, 9, 9);
1128 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), val
);
1131 static void dispc_ovl_enable_replication(enum omap_plane plane
,
1132 enum omap_overlay_caps caps
, bool enable
)
1134 static const unsigned shifts
[] = { 5, 10, 10, 10 };
1137 if ((caps
& OMAP_DSS_OVL_CAP_REPLICATION
) == 0)
1140 shift
= shifts
[plane
];
1141 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
, shift
, shift
);
1144 static void dispc_mgr_set_size(enum omap_channel channel
, u16 width
,
1149 val
= FLD_VAL(height
- 1, dispc
.feat
->mgr_height_start
, 16) |
1150 FLD_VAL(width
- 1, dispc
.feat
->mgr_width_start
, 0);
1152 dispc_write_reg(DISPC_SIZE_MGR(channel
), val
);
1155 static void dispc_init_fifos(void)
1163 unit
= dss_feat_get_buffer_size_unit();
1165 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE
, &start
, &end
);
1167 for (fifo
= 0; fifo
< dispc
.feat
->num_fifos
; ++fifo
) {
1168 size
= REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo
), start
, end
);
1170 dispc
.fifo_size
[fifo
] = size
;
1173 * By default fifos are mapped directly to overlays, fifo 0 to
1174 * ovl 0, fifo 1 to ovl 1, etc.
1176 dispc
.fifo_assignment
[fifo
] = fifo
;
1180 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1181 * causes problems with certain use cases, like using the tiler in 2D
1182 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1183 * giving GFX plane a larger fifo. WB but should work fine with a
1186 if (dispc
.feat
->gfx_fifo_workaround
) {
1189 v
= dispc_read_reg(DISPC_GLOBAL_BUFFER
);
1191 v
= FLD_MOD(v
, 4, 2, 0); /* GFX BUF top to WB */
1192 v
= FLD_MOD(v
, 4, 5, 3); /* GFX BUF bottom to WB */
1193 v
= FLD_MOD(v
, 0, 26, 24); /* WB BUF top to GFX */
1194 v
= FLD_MOD(v
, 0, 29, 27); /* WB BUF bottom to GFX */
1196 dispc_write_reg(DISPC_GLOBAL_BUFFER
, v
);
1198 dispc
.fifo_assignment
[OMAP_DSS_GFX
] = OMAP_DSS_WB
;
1199 dispc
.fifo_assignment
[OMAP_DSS_WB
] = OMAP_DSS_GFX
;
1203 * Setup default fifo thresholds.
1205 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
) {
1207 const bool use_fifomerge
= false;
1208 const bool manual_update
= false;
1210 dispc_ovl_compute_fifo_thresholds(i
, &low
, &high
,
1211 use_fifomerge
, manual_update
);
1213 dispc_ovl_set_fifo_threshold(i
, low
, high
);
1216 if (dispc
.feat
->has_writeback
) {
1218 const bool use_fifomerge
= false;
1219 const bool manual_update
= false;
1221 dispc_ovl_compute_fifo_thresholds(OMAP_DSS_WB
, &low
, &high
,
1222 use_fifomerge
, manual_update
);
1224 dispc_ovl_set_fifo_threshold(OMAP_DSS_WB
, low
, high
);
1228 static u32
dispc_ovl_get_fifo_size(enum omap_plane plane
)
1233 for (fifo
= 0; fifo
< dispc
.feat
->num_fifos
; ++fifo
) {
1234 if (dispc
.fifo_assignment
[fifo
] == plane
)
1235 size
+= dispc
.fifo_size
[fifo
];
1241 void dispc_ovl_set_fifo_threshold(enum omap_plane plane
, u32 low
, u32 high
)
1243 u8 hi_start
, hi_end
, lo_start
, lo_end
;
1246 unit
= dss_feat_get_buffer_size_unit();
1248 WARN_ON(low
% unit
!= 0);
1249 WARN_ON(high
% unit
!= 0);
1254 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD
, &hi_start
, &hi_end
);
1255 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD
, &lo_start
, &lo_end
);
1257 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1259 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane
),
1260 lo_start
, lo_end
) * unit
,
1261 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane
),
1262 hi_start
, hi_end
) * unit
,
1263 low
* unit
, high
* unit
);
1265 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane
),
1266 FLD_VAL(high
, hi_start
, hi_end
) |
1267 FLD_VAL(low
, lo_start
, lo_end
));
1270 * configure the preload to the pipeline's high threhold, if HT it's too
1271 * large for the preload field, set the threshold to the maximum value
1272 * that can be held by the preload register
1274 if (dss_has_feature(FEAT_PRELOAD
) && dispc
.feat
->set_max_preload
&&
1275 plane
!= OMAP_DSS_WB
)
1276 dispc_write_reg(DISPC_OVL_PRELOAD(plane
), min(high
, 0xfffu
));
1279 void dispc_enable_fifomerge(bool enable
)
1281 if (!dss_has_feature(FEAT_FIFO_MERGE
)) {
1286 DSSDBG("FIFO merge %s\n", enable
? "enabled" : "disabled");
1287 REG_FLD_MOD(DISPC_CONFIG
, enable
? 1 : 0, 14, 14);
1290 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane
,
1291 u32
*fifo_low
, u32
*fifo_high
, bool use_fifomerge
,
1295 * All sizes are in bytes. Both the buffer and burst are made of
1296 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1299 unsigned buf_unit
= dss_feat_get_buffer_size_unit();
1300 unsigned ovl_fifo_size
, total_fifo_size
, burst_size
;
1303 burst_size
= dispc_ovl_get_burst_size(plane
);
1304 ovl_fifo_size
= dispc_ovl_get_fifo_size(plane
);
1306 if (use_fifomerge
) {
1307 total_fifo_size
= 0;
1308 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
)
1309 total_fifo_size
+= dispc_ovl_get_fifo_size(i
);
1311 total_fifo_size
= ovl_fifo_size
;
1315 * We use the same low threshold for both fifomerge and non-fifomerge
1316 * cases, but for fifomerge we calculate the high threshold using the
1317 * combined fifo size
1320 if (manual_update
&& dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG
)) {
1321 *fifo_low
= ovl_fifo_size
- burst_size
* 2;
1322 *fifo_high
= total_fifo_size
- burst_size
;
1323 } else if (plane
== OMAP_DSS_WB
) {
1325 * Most optimal configuration for writeback is to push out data
1326 * to the interconnect the moment writeback pushes enough pixels
1327 * in the FIFO to form a burst
1330 *fifo_high
= burst_size
;
1332 *fifo_low
= ovl_fifo_size
- burst_size
;
1333 *fifo_high
= total_fifo_size
- buf_unit
;
1337 static void dispc_ovl_set_mflag(enum omap_plane plane
, bool enable
)
1341 if (plane
== OMAP_DSS_GFX
)
1346 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
, bit
, bit
);
1349 static void dispc_ovl_set_mflag_threshold(enum omap_plane plane
,
1352 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane
),
1353 FLD_VAL(high
, 31, 16) | FLD_VAL(low
, 15, 0));
1356 static void dispc_init_mflag(void)
1361 * HACK: NV12 color format and MFLAG seem to have problems working
1362 * together: using two displays, and having an NV12 overlay on one of
1363 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1364 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1365 * remove the errors, but there doesn't seem to be a clear logic on
1366 * which values work and which not.
1368 * As a work-around, set force MFLAG to always on.
1370 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE
,
1371 (1 << 0) | /* MFLAG_CTRL = force always on */
1372 (0 << 2)); /* MFLAG_START = disable */
1374 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
) {
1375 u32 size
= dispc_ovl_get_fifo_size(i
);
1376 u32 unit
= dss_feat_get_buffer_size_unit();
1379 dispc_ovl_set_mflag(i
, true);
1382 * Simulation team suggests below thesholds:
1383 * HT = fifosize * 5 / 8;
1384 * LT = fifosize * 4 / 8;
1387 low
= size
* 4 / 8 / unit
;
1388 high
= size
* 5 / 8 / unit
;
1390 dispc_ovl_set_mflag_threshold(i
, low
, high
);
1393 if (dispc
.feat
->has_writeback
) {
1394 u32 size
= dispc_ovl_get_fifo_size(OMAP_DSS_WB
);
1395 u32 unit
= dss_feat_get_buffer_size_unit();
1398 dispc_ovl_set_mflag(OMAP_DSS_WB
, true);
1401 * Simulation team suggests below thesholds:
1402 * HT = fifosize * 5 / 8;
1403 * LT = fifosize * 4 / 8;
1406 low
= size
* 4 / 8 / unit
;
1407 high
= size
* 5 / 8 / unit
;
1409 dispc_ovl_set_mflag_threshold(OMAP_DSS_WB
, low
, high
);
1413 static void dispc_ovl_set_fir(enum omap_plane plane
,
1415 enum omap_color_component color_comp
)
1419 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
) {
1420 u8 hinc_start
, hinc_end
, vinc_start
, vinc_end
;
1422 dss_feat_get_reg_field(FEAT_REG_FIRHINC
,
1423 &hinc_start
, &hinc_end
);
1424 dss_feat_get_reg_field(FEAT_REG_FIRVINC
,
1425 &vinc_start
, &vinc_end
);
1426 val
= FLD_VAL(vinc
, vinc_start
, vinc_end
) |
1427 FLD_VAL(hinc
, hinc_start
, hinc_end
);
1429 dispc_write_reg(DISPC_OVL_FIR(plane
), val
);
1431 val
= FLD_VAL(vinc
, 28, 16) | FLD_VAL(hinc
, 12, 0);
1432 dispc_write_reg(DISPC_OVL_FIR2(plane
), val
);
1436 static void dispc_ovl_set_vid_accu0(enum omap_plane plane
, int haccu
, int vaccu
)
1439 u8 hor_start
, hor_end
, vert_start
, vert_end
;
1441 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU
, &hor_start
, &hor_end
);
1442 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU
, &vert_start
, &vert_end
);
1444 val
= FLD_VAL(vaccu
, vert_start
, vert_end
) |
1445 FLD_VAL(haccu
, hor_start
, hor_end
);
1447 dispc_write_reg(DISPC_OVL_ACCU0(plane
), val
);
1450 static void dispc_ovl_set_vid_accu1(enum omap_plane plane
, int haccu
, int vaccu
)
1453 u8 hor_start
, hor_end
, vert_start
, vert_end
;
1455 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU
, &hor_start
, &hor_end
);
1456 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU
, &vert_start
, &vert_end
);
1458 val
= FLD_VAL(vaccu
, vert_start
, vert_end
) |
1459 FLD_VAL(haccu
, hor_start
, hor_end
);
1461 dispc_write_reg(DISPC_OVL_ACCU1(plane
), val
);
1464 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane
, int haccu
,
1469 val
= FLD_VAL(vaccu
, 26, 16) | FLD_VAL(haccu
, 10, 0);
1470 dispc_write_reg(DISPC_OVL_ACCU2_0(plane
), val
);
1473 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane
, int haccu
,
1478 val
= FLD_VAL(vaccu
, 26, 16) | FLD_VAL(haccu
, 10, 0);
1479 dispc_write_reg(DISPC_OVL_ACCU2_1(plane
), val
);
1482 static void dispc_ovl_set_scale_param(enum omap_plane plane
,
1483 u16 orig_width
, u16 orig_height
,
1484 u16 out_width
, u16 out_height
,
1485 bool five_taps
, u8 rotation
,
1486 enum omap_color_component color_comp
)
1488 int fir_hinc
, fir_vinc
;
1490 fir_hinc
= 1024 * orig_width
/ out_width
;
1491 fir_vinc
= 1024 * orig_height
/ out_height
;
1493 dispc_ovl_set_scale_coef(plane
, fir_hinc
, fir_vinc
, five_taps
,
1495 dispc_ovl_set_fir(plane
, fir_hinc
, fir_vinc
, color_comp
);
1498 static void dispc_ovl_set_accu_uv(enum omap_plane plane
,
1499 u16 orig_width
, u16 orig_height
, u16 out_width
, u16 out_height
,
1500 bool ilace
, enum omap_color_mode color_mode
, u8 rotation
)
1502 int h_accu2_0
, h_accu2_1
;
1503 int v_accu2_0
, v_accu2_1
;
1504 int chroma_hinc
, chroma_vinc
;
1514 const struct accu
*accu_table
;
1515 const struct accu
*accu_val
;
1517 static const struct accu accu_nv12
[4] = {
1518 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1519 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1520 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1521 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1524 static const struct accu accu_nv12_ilace
[4] = {
1525 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1526 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1527 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1528 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1531 static const struct accu accu_yuv
[4] = {
1532 { 0, 1, 0, 1, 0, 1, 0, 1 },
1533 { 0, 1, 0, 1, 0, 1, 0, 1 },
1534 { -1, 1, 0, 1, 0, 1, 0, 1 },
1535 { 0, 1, 0, 1, -1, 1, 0, 1 },
1539 case OMAP_DSS_ROT_0
:
1542 case OMAP_DSS_ROT_90
:
1545 case OMAP_DSS_ROT_180
:
1548 case OMAP_DSS_ROT_270
:
1556 switch (color_mode
) {
1557 case OMAP_DSS_COLOR_NV12
:
1559 accu_table
= accu_nv12_ilace
;
1561 accu_table
= accu_nv12
;
1563 case OMAP_DSS_COLOR_YUV2
:
1564 case OMAP_DSS_COLOR_UYVY
:
1565 accu_table
= accu_yuv
;
1572 accu_val
= &accu_table
[idx
];
1574 chroma_hinc
= 1024 * orig_width
/ out_width
;
1575 chroma_vinc
= 1024 * orig_height
/ out_height
;
1577 h_accu2_0
= (accu_val
->h0_m
* chroma_hinc
/ accu_val
->h0_n
) % 1024;
1578 h_accu2_1
= (accu_val
->h1_m
* chroma_hinc
/ accu_val
->h1_n
) % 1024;
1579 v_accu2_0
= (accu_val
->v0_m
* chroma_vinc
/ accu_val
->v0_n
) % 1024;
1580 v_accu2_1
= (accu_val
->v1_m
* chroma_vinc
/ accu_val
->v1_n
) % 1024;
1582 dispc_ovl_set_vid_accu2_0(plane
, h_accu2_0
, v_accu2_0
);
1583 dispc_ovl_set_vid_accu2_1(plane
, h_accu2_1
, v_accu2_1
);
1586 static void dispc_ovl_set_scaling_common(enum omap_plane plane
,
1587 u16 orig_width
, u16 orig_height
,
1588 u16 out_width
, u16 out_height
,
1589 bool ilace
, bool five_taps
,
1590 bool fieldmode
, enum omap_color_mode color_mode
,
1597 dispc_ovl_set_scale_param(plane
, orig_width
, orig_height
,
1598 out_width
, out_height
, five_taps
,
1599 rotation
, DISPC_COLOR_COMPONENT_RGB_Y
);
1600 l
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1602 /* RESIZEENABLE and VERTICALTAPS */
1603 l
&= ~((0x3 << 5) | (0x1 << 21));
1604 l
|= (orig_width
!= out_width
) ? (1 << 5) : 0;
1605 l
|= (orig_height
!= out_height
) ? (1 << 6) : 0;
1606 l
|= five_taps
? (1 << 21) : 0;
1608 /* VRESIZECONF and HRESIZECONF */
1609 if (dss_has_feature(FEAT_RESIZECONF
)) {
1611 l
|= (orig_width
<= out_width
) ? 0 : (1 << 7);
1612 l
|= (orig_height
<= out_height
) ? 0 : (1 << 8);
1615 /* LINEBUFFERSPLIT */
1616 if (dss_has_feature(FEAT_LINEBUFFERSPLIT
)) {
1618 l
|= five_taps
? (1 << 22) : 0;
1621 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), l
);
1624 * field 0 = even field = bottom field
1625 * field 1 = odd field = top field
1627 if (ilace
&& !fieldmode
) {
1629 accu0
= ((1024 * orig_height
/ out_height
) / 2) & 0x3ff;
1630 if (accu0
>= 1024/2) {
1636 dispc_ovl_set_vid_accu0(plane
, 0, accu0
);
1637 dispc_ovl_set_vid_accu1(plane
, 0, accu1
);
1640 static void dispc_ovl_set_scaling_uv(enum omap_plane plane
,
1641 u16 orig_width
, u16 orig_height
,
1642 u16 out_width
, u16 out_height
,
1643 bool ilace
, bool five_taps
,
1644 bool fieldmode
, enum omap_color_mode color_mode
,
1647 int scale_x
= out_width
!= orig_width
;
1648 int scale_y
= out_height
!= orig_height
;
1649 bool chroma_upscale
= plane
!= OMAP_DSS_WB
? true : false;
1651 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE
))
1653 if ((color_mode
!= OMAP_DSS_COLOR_YUV2
&&
1654 color_mode
!= OMAP_DSS_COLOR_UYVY
&&
1655 color_mode
!= OMAP_DSS_COLOR_NV12
)) {
1656 /* reset chroma resampling for RGB formats */
1657 if (plane
!= OMAP_DSS_WB
)
1658 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
), 0, 8, 8);
1662 dispc_ovl_set_accu_uv(plane
, orig_width
, orig_height
, out_width
,
1663 out_height
, ilace
, color_mode
, rotation
);
1665 switch (color_mode
) {
1666 case OMAP_DSS_COLOR_NV12
:
1667 if (chroma_upscale
) {
1668 /* UV is subsampled by 2 horizontally and vertically */
1672 /* UV is downsampled by 2 horizontally and vertically */
1678 case OMAP_DSS_COLOR_YUV2
:
1679 case OMAP_DSS_COLOR_UYVY
:
1680 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
1681 if (rotation
== OMAP_DSS_ROT_0
||
1682 rotation
== OMAP_DSS_ROT_180
) {
1684 /* UV is subsampled by 2 horizontally */
1687 /* UV is downsampled by 2 horizontally */
1691 /* must use FIR for YUV422 if rotated */
1692 if (rotation
!= OMAP_DSS_ROT_0
)
1693 scale_x
= scale_y
= true;
1701 if (out_width
!= orig_width
)
1703 if (out_height
!= orig_height
)
1706 dispc_ovl_set_scale_param(plane
, orig_width
, orig_height
,
1707 out_width
, out_height
, five_taps
,
1708 rotation
, DISPC_COLOR_COMPONENT_UV
);
1710 if (plane
!= OMAP_DSS_WB
)
1711 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
),
1712 (scale_x
|| scale_y
) ? 1 : 0, 8, 8);
1715 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), scale_x
? 1 : 0, 5, 5);
1717 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), scale_y
? 1 : 0, 6, 6);
1720 static void dispc_ovl_set_scaling(enum omap_plane plane
,
1721 u16 orig_width
, u16 orig_height
,
1722 u16 out_width
, u16 out_height
,
1723 bool ilace
, bool five_taps
,
1724 bool fieldmode
, enum omap_color_mode color_mode
,
1727 BUG_ON(plane
== OMAP_DSS_GFX
);
1729 dispc_ovl_set_scaling_common(plane
,
1730 orig_width
, orig_height
,
1731 out_width
, out_height
,
1733 fieldmode
, color_mode
,
1736 dispc_ovl_set_scaling_uv(plane
,
1737 orig_width
, orig_height
,
1738 out_width
, out_height
,
1740 fieldmode
, color_mode
,
1744 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane
, u8 rotation
,
1745 enum omap_dss_rotation_type rotation_type
,
1746 bool mirroring
, enum omap_color_mode color_mode
)
1748 bool row_repeat
= false;
1751 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1752 color_mode
== OMAP_DSS_COLOR_UYVY
) {
1756 case OMAP_DSS_ROT_0
:
1759 case OMAP_DSS_ROT_90
:
1762 case OMAP_DSS_ROT_180
:
1765 case OMAP_DSS_ROT_270
:
1771 case OMAP_DSS_ROT_0
:
1774 case OMAP_DSS_ROT_90
:
1777 case OMAP_DSS_ROT_180
:
1780 case OMAP_DSS_ROT_270
:
1786 if (rotation
== OMAP_DSS_ROT_90
|| rotation
== OMAP_DSS_ROT_270
)
1793 * OMAP4/5 Errata i631:
1794 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1795 * rows beyond the framebuffer, which may cause OCP error.
1797 if (color_mode
== OMAP_DSS_COLOR_NV12
&&
1798 rotation_type
!= OMAP_DSS_ROT_TILER
)
1801 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), vidrot
, 13, 12);
1802 if (dss_has_feature(FEAT_ROWREPEATENABLE
))
1803 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
),
1804 row_repeat
? 1 : 0, 18, 18);
1806 if (color_mode
== OMAP_DSS_COLOR_NV12
) {
1807 bool doublestride
= (rotation_type
== OMAP_DSS_ROT_TILER
) &&
1808 (rotation
== OMAP_DSS_ROT_0
||
1809 rotation
== OMAP_DSS_ROT_180
);
1811 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), doublestride
, 22, 22);
1816 static int color_mode_to_bpp(enum omap_color_mode color_mode
)
1818 switch (color_mode
) {
1819 case OMAP_DSS_COLOR_CLUT1
:
1821 case OMAP_DSS_COLOR_CLUT2
:
1823 case OMAP_DSS_COLOR_CLUT4
:
1825 case OMAP_DSS_COLOR_CLUT8
:
1826 case OMAP_DSS_COLOR_NV12
:
1828 case OMAP_DSS_COLOR_RGB12U
:
1829 case OMAP_DSS_COLOR_RGB16
:
1830 case OMAP_DSS_COLOR_ARGB16
:
1831 case OMAP_DSS_COLOR_YUV2
:
1832 case OMAP_DSS_COLOR_UYVY
:
1833 case OMAP_DSS_COLOR_RGBA16
:
1834 case OMAP_DSS_COLOR_RGBX16
:
1835 case OMAP_DSS_COLOR_ARGB16_1555
:
1836 case OMAP_DSS_COLOR_XRGB16_1555
:
1838 case OMAP_DSS_COLOR_RGB24P
:
1840 case OMAP_DSS_COLOR_RGB24U
:
1841 case OMAP_DSS_COLOR_ARGB32
:
1842 case OMAP_DSS_COLOR_RGBA32
:
1843 case OMAP_DSS_COLOR_RGBX32
:
1851 static s32
pixinc(int pixels
, u8 ps
)
1855 else if (pixels
> 1)
1856 return 1 + (pixels
- 1) * ps
;
1857 else if (pixels
< 0)
1858 return 1 - (-pixels
+ 1) * ps
;
1864 static void calc_vrfb_rotation_offset(u8 rotation
, bool mirror
,
1866 u16 width
, u16 height
,
1867 enum omap_color_mode color_mode
, bool fieldmode
,
1868 unsigned int field_offset
,
1869 unsigned *offset0
, unsigned *offset1
,
1870 s32
*row_inc
, s32
*pix_inc
, int x_predecim
, int y_predecim
)
1874 /* FIXME CLUT formats */
1875 switch (color_mode
) {
1876 case OMAP_DSS_COLOR_CLUT1
:
1877 case OMAP_DSS_COLOR_CLUT2
:
1878 case OMAP_DSS_COLOR_CLUT4
:
1879 case OMAP_DSS_COLOR_CLUT8
:
1882 case OMAP_DSS_COLOR_YUV2
:
1883 case OMAP_DSS_COLOR_UYVY
:
1887 ps
= color_mode_to_bpp(color_mode
) / 8;
1891 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation
, screen_width
,
1895 * field 0 = even field = bottom field
1896 * field 1 = odd field = top field
1898 switch (rotation
+ mirror
* 4) {
1899 case OMAP_DSS_ROT_0
:
1900 case OMAP_DSS_ROT_180
:
1902 * If the pixel format is YUV or UYVY divide the width
1903 * of the image by 2 for 0 and 180 degree rotation.
1905 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1906 color_mode
== OMAP_DSS_COLOR_UYVY
)
1908 case OMAP_DSS_ROT_90
:
1909 case OMAP_DSS_ROT_270
:
1912 *offset0
= field_offset
* screen_width
* ps
;
1916 *row_inc
= pixinc(1 +
1917 (y_predecim
* screen_width
- x_predecim
* width
) +
1918 (fieldmode
? screen_width
: 0), ps
);
1919 *pix_inc
= pixinc(x_predecim
, ps
);
1922 case OMAP_DSS_ROT_0
+ 4:
1923 case OMAP_DSS_ROT_180
+ 4:
1924 /* If the pixel format is YUV or UYVY divide the width
1925 * of the image by 2 for 0 degree and 180 degree
1927 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1928 color_mode
== OMAP_DSS_COLOR_UYVY
)
1930 case OMAP_DSS_ROT_90
+ 4:
1931 case OMAP_DSS_ROT_270
+ 4:
1934 *offset0
= field_offset
* screen_width
* ps
;
1937 *row_inc
= pixinc(1 -
1938 (y_predecim
* screen_width
+ x_predecim
* width
) -
1939 (fieldmode
? screen_width
: 0), ps
);
1940 *pix_inc
= pixinc(x_predecim
, ps
);
1949 static void calc_dma_rotation_offset(u8 rotation
, bool mirror
,
1951 u16 width
, u16 height
,
1952 enum omap_color_mode color_mode
, bool fieldmode
,
1953 unsigned int field_offset
,
1954 unsigned *offset0
, unsigned *offset1
,
1955 s32
*row_inc
, s32
*pix_inc
, int x_predecim
, int y_predecim
)
1960 /* FIXME CLUT formats */
1961 switch (color_mode
) {
1962 case OMAP_DSS_COLOR_CLUT1
:
1963 case OMAP_DSS_COLOR_CLUT2
:
1964 case OMAP_DSS_COLOR_CLUT4
:
1965 case OMAP_DSS_COLOR_CLUT8
:
1969 ps
= color_mode_to_bpp(color_mode
) / 8;
1973 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation
, screen_width
,
1976 /* width & height are overlay sizes, convert to fb sizes */
1978 if (rotation
== OMAP_DSS_ROT_0
|| rotation
== OMAP_DSS_ROT_180
) {
1987 * field 0 = even field = bottom field
1988 * field 1 = odd field = top field
1990 switch (rotation
+ mirror
* 4) {
1991 case OMAP_DSS_ROT_0
:
1994 *offset0
= *offset1
+ field_offset
* screen_width
* ps
;
1996 *offset0
= *offset1
;
1997 *row_inc
= pixinc(1 +
1998 (y_predecim
* screen_width
- fbw
* x_predecim
) +
1999 (fieldmode
? screen_width
: 0), ps
);
2000 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
2001 color_mode
== OMAP_DSS_COLOR_UYVY
)
2002 *pix_inc
= pixinc(x_predecim
, 2 * ps
);
2004 *pix_inc
= pixinc(x_predecim
, ps
);
2006 case OMAP_DSS_ROT_90
:
2007 *offset1
= screen_width
* (fbh
- 1) * ps
;
2009 *offset0
= *offset1
+ field_offset
* ps
;
2011 *offset0
= *offset1
;
2012 *row_inc
= pixinc(screen_width
* (fbh
* x_predecim
- 1) +
2013 y_predecim
+ (fieldmode
? 1 : 0), ps
);
2014 *pix_inc
= pixinc(-x_predecim
* screen_width
, ps
);
2016 case OMAP_DSS_ROT_180
:
2017 *offset1
= (screen_width
* (fbh
- 1) + fbw
- 1) * ps
;
2019 *offset0
= *offset1
- field_offset
* screen_width
* ps
;
2021 *offset0
= *offset1
;
2022 *row_inc
= pixinc(-1 -
2023 (y_predecim
* screen_width
- fbw
* x_predecim
) -
2024 (fieldmode
? screen_width
: 0), ps
);
2025 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
2026 color_mode
== OMAP_DSS_COLOR_UYVY
)
2027 *pix_inc
= pixinc(-x_predecim
, 2 * ps
);
2029 *pix_inc
= pixinc(-x_predecim
, ps
);
2031 case OMAP_DSS_ROT_270
:
2032 *offset1
= (fbw
- 1) * ps
;
2034 *offset0
= *offset1
- field_offset
* ps
;
2036 *offset0
= *offset1
;
2037 *row_inc
= pixinc(-screen_width
* (fbh
* x_predecim
- 1) -
2038 y_predecim
- (fieldmode
? 1 : 0), ps
);
2039 *pix_inc
= pixinc(x_predecim
* screen_width
, ps
);
2043 case OMAP_DSS_ROT_0
+ 4:
2044 *offset1
= (fbw
- 1) * ps
;
2046 *offset0
= *offset1
+ field_offset
* screen_width
* ps
;
2048 *offset0
= *offset1
;
2049 *row_inc
= pixinc(y_predecim
* screen_width
* 2 - 1 +
2050 (fieldmode
? screen_width
: 0),
2052 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
2053 color_mode
== OMAP_DSS_COLOR_UYVY
)
2054 *pix_inc
= pixinc(-x_predecim
, 2 * ps
);
2056 *pix_inc
= pixinc(-x_predecim
, ps
);
2059 case OMAP_DSS_ROT_90
+ 4:
2062 *offset0
= *offset1
+ field_offset
* ps
;
2064 *offset0
= *offset1
;
2065 *row_inc
= pixinc(-screen_width
* (fbh
* x_predecim
- 1) +
2066 y_predecim
+ (fieldmode
? 1 : 0),
2068 *pix_inc
= pixinc(x_predecim
* screen_width
, ps
);
2071 case OMAP_DSS_ROT_180
+ 4:
2072 *offset1
= screen_width
* (fbh
- 1) * ps
;
2074 *offset0
= *offset1
- field_offset
* screen_width
* ps
;
2076 *offset0
= *offset1
;
2077 *row_inc
= pixinc(1 - y_predecim
* screen_width
* 2 -
2078 (fieldmode
? screen_width
: 0),
2080 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
2081 color_mode
== OMAP_DSS_COLOR_UYVY
)
2082 *pix_inc
= pixinc(x_predecim
, 2 * ps
);
2084 *pix_inc
= pixinc(x_predecim
, ps
);
2087 case OMAP_DSS_ROT_270
+ 4:
2088 *offset1
= (screen_width
* (fbh
- 1) + fbw
- 1) * ps
;
2090 *offset0
= *offset1
- field_offset
* ps
;
2092 *offset0
= *offset1
;
2093 *row_inc
= pixinc(screen_width
* (fbh
* x_predecim
- 1) -
2094 y_predecim
- (fieldmode
? 1 : 0),
2096 *pix_inc
= pixinc(-x_predecim
* screen_width
, ps
);
2105 static void calc_tiler_rotation_offset(u16 screen_width
, u16 width
,
2106 enum omap_color_mode color_mode
, bool fieldmode
,
2107 unsigned int field_offset
, unsigned *offset0
, unsigned *offset1
,
2108 s32
*row_inc
, s32
*pix_inc
, int x_predecim
, int y_predecim
)
2112 switch (color_mode
) {
2113 case OMAP_DSS_COLOR_CLUT1
:
2114 case OMAP_DSS_COLOR_CLUT2
:
2115 case OMAP_DSS_COLOR_CLUT4
:
2116 case OMAP_DSS_COLOR_CLUT8
:
2120 ps
= color_mode_to_bpp(color_mode
) / 8;
2124 DSSDBG("scrw %d, width %d\n", screen_width
, width
);
2127 * field 0 = even field = bottom field
2128 * field 1 = odd field = top field
2132 *offset0
= *offset1
+ field_offset
* screen_width
* ps
;
2134 *offset0
= *offset1
;
2135 *row_inc
= pixinc(1 + (y_predecim
* screen_width
- width
* x_predecim
) +
2136 (fieldmode
? screen_width
: 0), ps
);
2137 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
2138 color_mode
== OMAP_DSS_COLOR_UYVY
)
2139 *pix_inc
= pixinc(x_predecim
, 2 * ps
);
2141 *pix_inc
= pixinc(x_predecim
, ps
);
2145 * This function is used to avoid synclosts in OMAP3, because of some
2146 * undocumented horizontal position and timing related limitations.
2148 static int check_horiz_timing_omap3(unsigned long pclk
, unsigned long lclk
,
2149 const struct omap_video_timings
*t
, u16 pos_x
,
2150 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2153 const int ds
= DIV_ROUND_UP(height
, out_height
);
2154 unsigned long nonactive
;
2155 static const u8 limits
[3] = { 8, 10, 20 };
2159 nonactive
= t
->x_res
+ t
->hfp
+ t
->hsw
+ t
->hbp
- out_width
;
2162 if (out_height
< height
)
2164 if (out_width
< width
)
2166 blank
= div_u64((u64
)(t
->hbp
+ t
->hsw
+ t
->hfp
) * lclk
, pclk
);
2167 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank
, limits
[i
]);
2168 if (blank
<= limits
[i
])
2171 /* FIXME add checks for 3-tap filter once the limitations are known */
2176 * Pixel data should be prepared before visible display point starts.
2177 * So, atleast DS-2 lines must have already been fetched by DISPC
2178 * during nonactive - pos_x period.
2180 val
= div_u64((u64
)(nonactive
- pos_x
) * lclk
, pclk
);
2181 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2182 val
, max(0, ds
- 2) * width
);
2183 if (val
< max(0, ds
- 2) * width
)
2187 * All lines need to be refilled during the nonactive period of which
2188 * only one line can be loaded during the active period. So, atleast
2189 * DS - 1 lines should be loaded during nonactive period.
2191 val
= div_u64((u64
)nonactive
* lclk
, pclk
);
2192 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2193 val
, max(0, ds
- 1) * width
);
2194 if (val
< max(0, ds
- 1) * width
)
2200 static unsigned long calc_core_clk_five_taps(unsigned long pclk
,
2201 const struct omap_video_timings
*mgr_timings
, u16 width
,
2202 u16 height
, u16 out_width
, u16 out_height
,
2203 enum omap_color_mode color_mode
)
2208 if (height
<= out_height
&& width
<= out_width
)
2209 return (unsigned long) pclk
;
2211 if (height
> out_height
) {
2212 unsigned int ppl
= mgr_timings
->x_res
;
2214 tmp
= (u64
)pclk
* height
* out_width
;
2215 do_div(tmp
, 2 * out_height
* ppl
);
2218 if (height
> 2 * out_height
) {
2219 if (ppl
== out_width
)
2222 tmp
= (u64
)pclk
* (height
- 2 * out_height
) * out_width
;
2223 do_div(tmp
, 2 * out_height
* (ppl
- out_width
));
2224 core_clk
= max_t(u32
, core_clk
, tmp
);
2228 if (width
> out_width
) {
2229 tmp
= (u64
)pclk
* width
;
2230 do_div(tmp
, out_width
);
2231 core_clk
= max_t(u32
, core_clk
, tmp
);
2233 if (color_mode
== OMAP_DSS_COLOR_RGB24U
)
2240 static unsigned long calc_core_clk_24xx(unsigned long pclk
, u16 width
,
2241 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2243 if (height
> out_height
&& width
> out_width
)
2249 static unsigned long calc_core_clk_34xx(unsigned long pclk
, u16 width
,
2250 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2252 unsigned int hf
, vf
;
2255 * FIXME how to determine the 'A' factor
2256 * for the no downscaling case ?
2259 if (width
> 3 * out_width
)
2261 else if (width
> 2 * out_width
)
2263 else if (width
> out_width
)
2267 if (height
> out_height
)
2272 return pclk
* vf
* hf
;
2275 static unsigned long calc_core_clk_44xx(unsigned long pclk
, u16 width
,
2276 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2279 * If the overlay/writeback is in mem to mem mode, there are no
2280 * downscaling limitations with respect to pixel clock, return 1 as
2281 * required core clock to represent that we have sufficient enough
2282 * core clock to do maximum downscaling
2287 if (width
> out_width
)
2288 return DIV_ROUND_UP(pclk
, out_width
) * width
;
2293 static int dispc_ovl_calc_scaling_24xx(unsigned long pclk
, unsigned long lclk
,
2294 const struct omap_video_timings
*mgr_timings
,
2295 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2296 enum omap_color_mode color_mode
, bool *five_taps
,
2297 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2298 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2301 u16 in_width
, in_height
;
2302 int min_factor
= min(*decim_x
, *decim_y
);
2303 const int maxsinglelinewidth
=
2304 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH
);
2309 in_height
= height
/ *decim_y
;
2310 in_width
= width
/ *decim_x
;
2311 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
,
2312 in_height
, out_width
, out_height
, mem_to_mem
);
2313 error
= (in_width
> maxsinglelinewidth
|| !*core_clk
||
2314 *core_clk
> dispc_core_clk_rate());
2316 if (*decim_x
== *decim_y
) {
2317 *decim_x
= min_factor
;
2320 swap(*decim_x
, *decim_y
);
2321 if (*decim_x
< *decim_y
)
2325 } while (*decim_x
<= *x_predecim
&& *decim_y
<= *y_predecim
&& error
);
2328 DSSERR("failed to find scaling settings\n");
2332 if (in_width
> maxsinglelinewidth
) {
2333 DSSERR("Cannot scale max input width exceeded");
2339 static int dispc_ovl_calc_scaling_34xx(unsigned long pclk
, unsigned long lclk
,
2340 const struct omap_video_timings
*mgr_timings
,
2341 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2342 enum omap_color_mode color_mode
, bool *five_taps
,
2343 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2344 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2347 u16 in_width
, in_height
;
2348 const int maxsinglelinewidth
=
2349 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH
);
2352 in_height
= height
/ *decim_y
;
2353 in_width
= width
/ *decim_x
;
2354 *five_taps
= in_height
> out_height
;
2356 if (in_width
> maxsinglelinewidth
)
2357 if (in_height
> out_height
&&
2358 in_height
< out_height
* 2)
2362 *core_clk
= calc_core_clk_five_taps(pclk
, mgr_timings
,
2363 in_width
, in_height
, out_width
,
2364 out_height
, color_mode
);
2366 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
,
2367 in_height
, out_width
, out_height
,
2370 error
= check_horiz_timing_omap3(pclk
, lclk
, mgr_timings
,
2371 pos_x
, in_width
, in_height
, out_width
,
2372 out_height
, *five_taps
);
2373 if (error
&& *five_taps
) {
2378 error
= (error
|| in_width
> maxsinglelinewidth
* 2 ||
2379 (in_width
> maxsinglelinewidth
&& *five_taps
) ||
2380 !*core_clk
|| *core_clk
> dispc_core_clk_rate());
2383 /* verify that we're inside the limits of scaler */
2384 if (in_width
/ 4 > out_width
)
2388 if (in_height
/ 4 > out_height
)
2391 if (in_height
/ 2 > out_height
)
2398 } while (*decim_x
<= *x_predecim
&& *decim_y
<= *y_predecim
&& error
);
2401 DSSERR("failed to find scaling settings\n");
2405 if (check_horiz_timing_omap3(pclk
, lclk
, mgr_timings
, pos_x
, in_width
,
2406 in_height
, out_width
, out_height
, *five_taps
)) {
2407 DSSERR("horizontal timing too tight\n");
2411 if (in_width
> (maxsinglelinewidth
* 2)) {
2412 DSSERR("Cannot setup scaling");
2413 DSSERR("width exceeds maximum width possible");
2417 if (in_width
> maxsinglelinewidth
&& *five_taps
) {
2418 DSSERR("cannot setup scaling with five taps");
2424 static int dispc_ovl_calc_scaling_44xx(unsigned long pclk
, unsigned long lclk
,
2425 const struct omap_video_timings
*mgr_timings
,
2426 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2427 enum omap_color_mode color_mode
, bool *five_taps
,
2428 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2429 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2431 u16 in_width
, in_width_max
;
2432 int decim_x_min
= *decim_x
;
2433 u16 in_height
= height
/ *decim_y
;
2434 const int maxsinglelinewidth
=
2435 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH
);
2436 const int maxdownscale
= dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE
);
2439 in_width_max
= out_width
* maxdownscale
;
2441 in_width_max
= dispc_core_clk_rate() /
2442 DIV_ROUND_UP(pclk
, out_width
);
2445 *decim_x
= DIV_ROUND_UP(width
, in_width_max
);
2447 *decim_x
= *decim_x
> decim_x_min
? *decim_x
: decim_x_min
;
2448 if (*decim_x
> *x_predecim
)
2452 in_width
= width
/ *decim_x
;
2453 } while (*decim_x
<= *x_predecim
&&
2454 in_width
> maxsinglelinewidth
&& ++*decim_x
);
2456 if (in_width
> maxsinglelinewidth
) {
2457 DSSERR("Cannot scale width exceeds max line width");
2461 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
, in_height
,
2462 out_width
, out_height
, mem_to_mem
);
2466 #define DIV_FRAC(dividend, divisor) \
2467 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2469 static int dispc_ovl_calc_scaling(unsigned long pclk
, unsigned long lclk
,
2470 enum omap_overlay_caps caps
,
2471 const struct omap_video_timings
*mgr_timings
,
2472 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2473 enum omap_color_mode color_mode
, bool *five_taps
,
2474 int *x_predecim
, int *y_predecim
, u16 pos_x
,
2475 enum omap_dss_rotation_type rotation_type
, bool mem_to_mem
)
2477 const int maxdownscale
= dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE
);
2478 const int max_decim_limit
= 16;
2479 unsigned long core_clk
= 0;
2480 int decim_x
, decim_y
, ret
;
2482 if (width
== out_width
&& height
== out_height
)
2485 if (!mem_to_mem
&& (pclk
== 0 || mgr_timings
->pixelclock
== 0)) {
2486 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2490 if ((caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0)
2494 *x_predecim
= *y_predecim
= 1;
2496 *x_predecim
= max_decim_limit
;
2497 *y_predecim
= (rotation_type
== OMAP_DSS_ROT_TILER
&&
2498 dss_has_feature(FEAT_BURST_2D
)) ?
2499 2 : max_decim_limit
;
2502 if (color_mode
== OMAP_DSS_COLOR_CLUT1
||
2503 color_mode
== OMAP_DSS_COLOR_CLUT2
||
2504 color_mode
== OMAP_DSS_COLOR_CLUT4
||
2505 color_mode
== OMAP_DSS_COLOR_CLUT8
) {
2512 decim_x
= DIV_ROUND_UP(DIV_ROUND_UP(width
, out_width
), maxdownscale
);
2513 decim_y
= DIV_ROUND_UP(DIV_ROUND_UP(height
, out_height
), maxdownscale
);
2515 if (decim_x
> *x_predecim
|| out_width
> width
* 8)
2518 if (decim_y
> *y_predecim
|| out_height
> height
* 8)
2521 ret
= dispc
.feat
->calc_scaling(pclk
, lclk
, mgr_timings
, width
, height
,
2522 out_width
, out_height
, color_mode
, five_taps
,
2523 x_predecim
, y_predecim
, &decim_x
, &decim_y
, pos_x
, &core_clk
,
2528 DSSDBG("%dx%d -> %dx%d (%d.%02d x %d.%02d), decim %dx%d %dx%d (%d.%02d x %d.%02d), taps %d, req clk %lu, cur clk %lu\n",
2530 out_width
, out_height
,
2531 out_width
/ width
, DIV_FRAC(out_width
, width
),
2532 out_height
/ height
, DIV_FRAC(out_height
, height
),
2535 width
/ decim_x
, height
/ decim_y
,
2536 out_width
/ (width
/ decim_x
), DIV_FRAC(out_width
, width
/ decim_x
),
2537 out_height
/ (height
/ decim_y
), DIV_FRAC(out_height
, height
/ decim_y
),
2540 core_clk
, dispc_core_clk_rate());
2542 if (!core_clk
|| core_clk
> dispc_core_clk_rate()) {
2543 DSSERR("failed to set up scaling, "
2544 "required core clk rate = %lu Hz, "
2545 "current core clk rate = %lu Hz\n",
2546 core_clk
, dispc_core_clk_rate());
2550 *x_predecim
= decim_x
;
2551 *y_predecim
= decim_y
;
2555 int dispc_ovl_check(enum omap_plane plane
, enum omap_channel channel
,
2556 const struct omap_overlay_info
*oi
,
2557 const struct omap_video_timings
*timings
,
2558 int *x_predecim
, int *y_predecim
)
2560 enum omap_overlay_caps caps
= dss_feat_get_overlay_caps(plane
);
2561 bool five_taps
= true;
2562 bool fieldmode
= false;
2563 u16 in_height
= oi
->height
;
2564 u16 in_width
= oi
->width
;
2565 bool ilace
= timings
->interlace
;
2566 u16 out_width
, out_height
;
2567 int pos_x
= oi
->pos_x
;
2568 unsigned long pclk
= dispc_mgr_pclk_rate(channel
);
2569 unsigned long lclk
= dispc_mgr_lclk_rate(channel
);
2571 out_width
= oi
->out_width
== 0 ? oi
->width
: oi
->out_width
;
2572 out_height
= oi
->out_height
== 0 ? oi
->height
: oi
->out_height
;
2574 if (ilace
&& oi
->height
== out_height
)
2582 DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2583 in_height
, out_height
);
2586 if (!dss_feat_color_mode_supported(plane
, oi
->color_mode
))
2589 return dispc_ovl_calc_scaling(pclk
, lclk
, caps
, timings
, in_width
,
2590 in_height
, out_width
, out_height
, oi
->color_mode
,
2591 &five_taps
, x_predecim
, y_predecim
, pos_x
,
2592 oi
->rotation_type
, false);
2594 EXPORT_SYMBOL(dispc_ovl_check
);
2596 static int dispc_ovl_setup_common(enum omap_plane plane
,
2597 enum omap_overlay_caps caps
, u32 paddr
, u32 p_uv_addr
,
2598 u16 screen_width
, int pos_x
, int pos_y
, u16 width
, u16 height
,
2599 u16 out_width
, u16 out_height
, enum omap_color_mode color_mode
,
2600 u8 rotation
, bool mirror
, u8 zorder
, u8 pre_mult_alpha
,
2601 u8 global_alpha
, enum omap_dss_rotation_type rotation_type
,
2602 bool replication
, const struct omap_video_timings
*mgr_timings
,
2605 bool five_taps
= true;
2606 bool fieldmode
= false;
2608 unsigned offset0
, offset1
;
2611 u16 frame_width
, frame_height
;
2612 unsigned int field_offset
= 0;
2613 u16 in_height
= height
;
2614 u16 in_width
= width
;
2615 int x_predecim
= 1, y_predecim
= 1;
2616 bool ilace
= mgr_timings
->interlace
;
2617 unsigned long pclk
= dispc_plane_pclk_rate(plane
);
2618 unsigned long lclk
= dispc_plane_lclk_rate(plane
);
2620 if (paddr
== 0 && rotation_type
!= OMAP_DSS_ROT_TILER
)
2623 switch (color_mode
) {
2624 case OMAP_DSS_COLOR_YUV2
:
2625 case OMAP_DSS_COLOR_UYVY
:
2626 case OMAP_DSS_COLOR_NV12
:
2628 DSSERR("input width %d is not even for YUV format\n",
2638 out_width
= out_width
== 0 ? width
: out_width
;
2639 out_height
= out_height
== 0 ? height
: out_height
;
2641 if (ilace
&& height
== out_height
)
2650 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2651 "out_height %d\n", in_height
, pos_y
,
2655 if (!dss_feat_color_mode_supported(plane
, color_mode
))
2658 r
= dispc_ovl_calc_scaling(pclk
, lclk
, caps
, mgr_timings
, in_width
,
2659 in_height
, out_width
, out_height
, color_mode
,
2660 &five_taps
, &x_predecim
, &y_predecim
, pos_x
,
2661 rotation_type
, mem_to_mem
);
2665 in_width
= in_width
/ x_predecim
;
2666 in_height
= in_height
/ y_predecim
;
2668 if (x_predecim
> 1 || y_predecim
> 1)
2669 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2670 x_predecim
, y_predecim
, in_width
, in_height
);
2672 switch (color_mode
) {
2673 case OMAP_DSS_COLOR_YUV2
:
2674 case OMAP_DSS_COLOR_UYVY
:
2675 case OMAP_DSS_COLOR_NV12
:
2677 DSSDBG("predecimated input width is not even for YUV format\n");
2678 DSSDBG("adjusting input width %d -> %d\n",
2679 in_width
, in_width
& ~1);
2689 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
2690 color_mode
== OMAP_DSS_COLOR_UYVY
||
2691 color_mode
== OMAP_DSS_COLOR_NV12
)
2694 if (ilace
&& !fieldmode
) {
2696 * when downscaling the bottom field may have to start several
2697 * source lines below the top field. Unfortunately ACCUI
2698 * registers will only hold the fractional part of the offset
2699 * so the integer part must be added to the base address of the
2702 if (!in_height
|| in_height
== out_height
)
2705 field_offset
= in_height
/ out_height
/ 2;
2708 /* Fields are independent but interleaved in memory. */
2717 if (plane
== OMAP_DSS_WB
) {
2718 frame_width
= out_width
;
2719 frame_height
= out_height
;
2721 frame_width
= in_width
;
2722 frame_height
= height
;
2725 if (rotation_type
== OMAP_DSS_ROT_TILER
)
2726 calc_tiler_rotation_offset(screen_width
, frame_width
,
2727 color_mode
, fieldmode
, field_offset
,
2728 &offset0
, &offset1
, &row_inc
, &pix_inc
,
2729 x_predecim
, y_predecim
);
2730 else if (rotation_type
== OMAP_DSS_ROT_DMA
)
2731 calc_dma_rotation_offset(rotation
, mirror
, screen_width
,
2732 frame_width
, frame_height
,
2733 color_mode
, fieldmode
, field_offset
,
2734 &offset0
, &offset1
, &row_inc
, &pix_inc
,
2735 x_predecim
, y_predecim
);
2737 calc_vrfb_rotation_offset(rotation
, mirror
,
2738 screen_width
, frame_width
, frame_height
,
2739 color_mode
, fieldmode
, field_offset
,
2740 &offset0
, &offset1
, &row_inc
, &pix_inc
,
2741 x_predecim
, y_predecim
);
2743 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2744 offset0
, offset1
, row_inc
, pix_inc
);
2746 dispc_ovl_set_color_mode(plane
, color_mode
);
2748 dispc_ovl_configure_burst_type(plane
, rotation_type
);
2750 dispc_ovl_set_ba0(plane
, paddr
+ offset0
);
2751 dispc_ovl_set_ba1(plane
, paddr
+ offset1
);
2753 if (OMAP_DSS_COLOR_NV12
== color_mode
) {
2754 dispc_ovl_set_ba0_uv(plane
, p_uv_addr
+ offset0
);
2755 dispc_ovl_set_ba1_uv(plane
, p_uv_addr
+ offset1
);
2758 if (dispc
.feat
->last_pixel_inc_missing
)
2759 row_inc
+= pix_inc
- 1;
2761 dispc_ovl_set_row_inc(plane
, row_inc
);
2762 dispc_ovl_set_pix_inc(plane
, pix_inc
);
2764 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x
, pos_y
, in_width
,
2765 in_height
, out_width
, out_height
);
2767 dispc_ovl_set_pos(plane
, caps
, pos_x
, pos_y
);
2769 dispc_ovl_set_input_size(plane
, in_width
, in_height
);
2771 if (caps
& OMAP_DSS_OVL_CAP_SCALE
) {
2772 dispc_ovl_set_scaling(plane
, in_width
, in_height
, out_width
,
2773 out_height
, ilace
, five_taps
, fieldmode
,
2774 color_mode
, rotation
);
2775 dispc_ovl_set_output_size(plane
, out_width
, out_height
);
2776 dispc_ovl_set_vid_color_conv(plane
, cconv
);
2779 dispc_ovl_set_rotation_attrs(plane
, rotation
, rotation_type
, mirror
,
2782 dispc_ovl_set_zorder(plane
, caps
, zorder
);
2783 dispc_ovl_set_pre_mult_alpha(plane
, caps
, pre_mult_alpha
);
2784 dispc_ovl_setup_global_alpha(plane
, caps
, global_alpha
);
2786 dispc_ovl_enable_replication(plane
, caps
, replication
);
2791 int dispc_ovl_setup(enum omap_plane plane
, const struct omap_overlay_info
*oi
,
2792 bool replication
, const struct omap_video_timings
*mgr_timings
,
2796 enum omap_overlay_caps caps
= dss_feat_get_overlay_caps(plane
);
2797 enum omap_channel channel
;
2799 channel
= dispc_ovl_get_channel_out(plane
);
2801 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2802 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2803 plane
, &oi
->paddr
, &oi
->p_uv_addr
, oi
->screen_width
, oi
->pos_x
,
2804 oi
->pos_y
, oi
->width
, oi
->height
, oi
->out_width
, oi
->out_height
,
2805 oi
->color_mode
, oi
->rotation
, oi
->mirror
, channel
, replication
);
2807 r
= dispc_ovl_setup_common(plane
, caps
, oi
->paddr
, oi
->p_uv_addr
,
2808 oi
->screen_width
, oi
->pos_x
, oi
->pos_y
, oi
->width
, oi
->height
,
2809 oi
->out_width
, oi
->out_height
, oi
->color_mode
, oi
->rotation
,
2810 oi
->mirror
, oi
->zorder
, oi
->pre_mult_alpha
, oi
->global_alpha
,
2811 oi
->rotation_type
, replication
, mgr_timings
, mem_to_mem
);
2815 EXPORT_SYMBOL(dispc_ovl_setup
);
2817 int dispc_wb_setup(const struct omap_dss_writeback_info
*wi
,
2818 bool mem_to_mem
, const struct omap_video_timings
*mgr_timings
)
2822 enum omap_plane plane
= OMAP_DSS_WB
;
2823 const int pos_x
= 0, pos_y
= 0;
2824 const u8 zorder
= 0, global_alpha
= 0;
2825 const bool replication
= false;
2827 int in_width
= mgr_timings
->x_res
;
2828 int in_height
= mgr_timings
->y_res
;
2829 enum omap_overlay_caps caps
=
2830 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
;
2832 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2833 "rot %d, mir %d\n", wi
->paddr
, wi
->p_uv_addr
, in_width
,
2834 in_height
, wi
->width
, wi
->height
, wi
->color_mode
, wi
->rotation
,
2837 r
= dispc_ovl_setup_common(plane
, caps
, wi
->paddr
, wi
->p_uv_addr
,
2838 wi
->buf_width
, pos_x
, pos_y
, in_width
, in_height
, wi
->width
,
2839 wi
->height
, wi
->color_mode
, wi
->rotation
, wi
->mirror
, zorder
,
2840 wi
->pre_mult_alpha
, global_alpha
, wi
->rotation_type
,
2841 replication
, mgr_timings
, mem_to_mem
);
2843 switch (wi
->color_mode
) {
2844 case OMAP_DSS_COLOR_RGB16
:
2845 case OMAP_DSS_COLOR_RGB24P
:
2846 case OMAP_DSS_COLOR_ARGB16
:
2847 case OMAP_DSS_COLOR_RGBA16
:
2848 case OMAP_DSS_COLOR_RGB12U
:
2849 case OMAP_DSS_COLOR_ARGB16_1555
:
2850 case OMAP_DSS_COLOR_XRGB16_1555
:
2851 case OMAP_DSS_COLOR_RGBX16
:
2859 /* setup extra DISPC_WB_ATTRIBUTES */
2860 l
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
2861 l
= FLD_MOD(l
, truncation
, 10, 10); /* TRUNCATIONENABLE */
2862 l
= FLD_MOD(l
, mem_to_mem
, 19, 19); /* WRITEBACKMODE */
2864 l
= FLD_MOD(l
, 1, 26, 24); /* CAPTUREMODE */
2866 l
= FLD_MOD(l
, 0, 26, 24); /* CAPTUREMODE */
2867 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), l
);
2871 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
), 0, 7, 0);
2875 wbdelay
= min(mgr_timings
->vfp
+ mgr_timings
->vsw
+
2876 mgr_timings
->vbp
, 255);
2879 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
), wbdelay
, 7, 0);
2885 int dispc_ovl_enable(enum omap_plane plane
, bool enable
)
2887 DSSDBG("dispc_enable_plane %d, %d\n", plane
, enable
);
2889 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
? 1 : 0, 0, 0);
2893 EXPORT_SYMBOL(dispc_ovl_enable
);
2895 bool dispc_ovl_enabled(enum omap_plane plane
)
2897 return REG_GET(DISPC_OVL_ATTRIBUTES(plane
), 0, 0);
2899 EXPORT_SYMBOL(dispc_ovl_enabled
);
2901 void dispc_mgr_enable(enum omap_channel channel
, bool enable
)
2903 mgr_fld_write(channel
, DISPC_MGR_FLD_ENABLE
, enable
);
2904 /* flush posted write */
2905 mgr_fld_read(channel
, DISPC_MGR_FLD_ENABLE
);
2907 EXPORT_SYMBOL(dispc_mgr_enable
);
2909 bool dispc_mgr_is_enabled(enum omap_channel channel
)
2911 return !!mgr_fld_read(channel
, DISPC_MGR_FLD_ENABLE
);
2913 EXPORT_SYMBOL(dispc_mgr_is_enabled
);
2915 void dispc_wb_enable(bool enable
)
2917 dispc_ovl_enable(OMAP_DSS_WB
, enable
);
2920 bool dispc_wb_is_enabled(void)
2922 return dispc_ovl_enabled(OMAP_DSS_WB
);
2925 static void dispc_lcd_enable_signal_polarity(bool act_high
)
2927 if (!dss_has_feature(FEAT_LCDENABLEPOL
))
2930 REG_FLD_MOD(DISPC_CONTROL
, act_high
? 1 : 0, 29, 29);
2933 void dispc_lcd_enable_signal(bool enable
)
2935 if (!dss_has_feature(FEAT_LCDENABLESIGNAL
))
2938 REG_FLD_MOD(DISPC_CONTROL
, enable
? 1 : 0, 28, 28);
2941 void dispc_pck_free_enable(bool enable
)
2943 if (!dss_has_feature(FEAT_PCKFREEENABLE
))
2946 REG_FLD_MOD(DISPC_CONTROL
, enable
? 1 : 0, 27, 27);
2949 static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel
, bool enable
)
2951 mgr_fld_write(channel
, DISPC_MGR_FLD_FIFOHANDCHECK
, enable
);
2955 static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel
)
2957 mgr_fld_write(channel
, DISPC_MGR_FLD_STNTFT
, 1);
2960 static void dispc_set_loadmode(enum omap_dss_load_mode mode
)
2962 REG_FLD_MOD(DISPC_CONFIG
, mode
, 2, 1);
2966 static void dispc_mgr_set_default_color(enum omap_channel channel
, u32 color
)
2968 dispc_write_reg(DISPC_DEFAULT_COLOR(channel
), color
);
2971 static void dispc_mgr_set_trans_key(enum omap_channel ch
,
2972 enum omap_dss_trans_key_type type
,
2975 mgr_fld_write(ch
, DISPC_MGR_FLD_TCKSELECTION
, type
);
2977 dispc_write_reg(DISPC_TRANS_COLOR(ch
), trans_key
);
2980 static void dispc_mgr_enable_trans_key(enum omap_channel ch
, bool enable
)
2982 mgr_fld_write(ch
, DISPC_MGR_FLD_TCKENABLE
, enable
);
2985 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch
,
2988 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
2991 if (ch
== OMAP_DSS_CHANNEL_LCD
)
2992 REG_FLD_MOD(DISPC_CONFIG
, enable
, 18, 18);
2993 else if (ch
== OMAP_DSS_CHANNEL_DIGIT
)
2994 REG_FLD_MOD(DISPC_CONFIG
, enable
, 19, 19);
2997 void dispc_mgr_setup(enum omap_channel channel
,
2998 const struct omap_overlay_manager_info
*info
)
3000 dispc_mgr_set_default_color(channel
, info
->default_color
);
3001 dispc_mgr_set_trans_key(channel
, info
->trans_key_type
, info
->trans_key
);
3002 dispc_mgr_enable_trans_key(channel
, info
->trans_enabled
);
3003 dispc_mgr_enable_alpha_fixed_zorder(channel
,
3004 info
->partial_alpha_enabled
);
3005 if (dss_has_feature(FEAT_CPR
)) {
3006 dispc_mgr_enable_cpr(channel
, info
->cpr_enable
);
3007 dispc_mgr_set_cpr_coef(channel
, &info
->cpr_coefs
);
3010 EXPORT_SYMBOL(dispc_mgr_setup
);
3012 static void dispc_mgr_set_tft_data_lines(enum omap_channel channel
, u8 data_lines
)
3016 switch (data_lines
) {
3034 mgr_fld_write(channel
, DISPC_MGR_FLD_TFTDATALINES
, code
);
3037 static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode
)
3043 case DSS_IO_PAD_MODE_RESET
:
3047 case DSS_IO_PAD_MODE_RFBI
:
3051 case DSS_IO_PAD_MODE_BYPASS
:
3060 l
= dispc_read_reg(DISPC_CONTROL
);
3061 l
= FLD_MOD(l
, gpout0
, 15, 15);
3062 l
= FLD_MOD(l
, gpout1
, 16, 16);
3063 dispc_write_reg(DISPC_CONTROL
, l
);
3066 static void dispc_mgr_enable_stallmode(enum omap_channel channel
, bool enable
)
3068 mgr_fld_write(channel
, DISPC_MGR_FLD_STALLMODE
, enable
);
3071 void dispc_mgr_set_lcd_config(enum omap_channel channel
,
3072 const struct dss_lcd_mgr_config
*config
)
3074 dispc_mgr_set_io_pad_mode(config
->io_pad_mode
);
3076 dispc_mgr_enable_stallmode(channel
, config
->stallmode
);
3077 dispc_mgr_enable_fifohandcheck(channel
, config
->fifohandcheck
);
3079 dispc_mgr_set_clock_div(channel
, &config
->clock_info
);
3081 dispc_mgr_set_tft_data_lines(channel
, config
->video_port_width
);
3083 dispc_lcd_enable_signal_polarity(config
->lcden_sig_polarity
);
3085 dispc_mgr_set_lcd_type_tft(channel
);
3087 EXPORT_SYMBOL(dispc_mgr_set_lcd_config
);
3089 static bool _dispc_mgr_size_ok(u16 width
, u16 height
)
3091 return width
<= dispc
.feat
->mgr_width_max
&&
3092 height
<= dispc
.feat
->mgr_height_max
;
3095 static bool _dispc_lcd_timings_ok(int hsw
, int hfp
, int hbp
,
3096 int vsw
, int vfp
, int vbp
)
3098 if (hsw
< 1 || hsw
> dispc
.feat
->sw_max
||
3099 hfp
< 1 || hfp
> dispc
.feat
->hp_max
||
3100 hbp
< 1 || hbp
> dispc
.feat
->hp_max
||
3101 vsw
< 1 || vsw
> dispc
.feat
->sw_max
||
3102 vfp
< 0 || vfp
> dispc
.feat
->vp_max
||
3103 vbp
< 0 || vbp
> dispc
.feat
->vp_max
)
3108 static bool _dispc_mgr_pclk_ok(enum omap_channel channel
,
3111 if (dss_mgr_is_lcd(channel
))
3112 return pclk
<= dispc
.feat
->max_lcd_pclk
? true : false;
3114 return pclk
<= dispc
.feat
->max_tv_pclk
? true : false;
3117 bool dispc_mgr_timings_ok(enum omap_channel channel
,
3118 const struct omap_video_timings
*timings
)
3120 if (!_dispc_mgr_size_ok(timings
->x_res
, timings
->y_res
))
3123 if (!_dispc_mgr_pclk_ok(channel
, timings
->pixelclock
))
3126 if (dss_mgr_is_lcd(channel
)) {
3127 /* TODO: OMAP4+ supports interlace for LCD outputs */
3128 if (timings
->interlace
)
3131 if (!_dispc_lcd_timings_ok(timings
->hsw
, timings
->hfp
,
3132 timings
->hbp
, timings
->vsw
, timings
->vfp
,
3140 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel
, int hsw
,
3141 int hfp
, int hbp
, int vsw
, int vfp
, int vbp
,
3142 enum omap_dss_signal_level vsync_level
,
3143 enum omap_dss_signal_level hsync_level
,
3144 enum omap_dss_signal_edge data_pclk_edge
,
3145 enum omap_dss_signal_level de_level
,
3146 enum omap_dss_signal_edge sync_pclk_edge
)
3149 u32 timing_h
, timing_v
, l
;
3150 bool onoff
, rf
, ipc
, vs
, hs
, de
;
3152 timing_h
= FLD_VAL(hsw
-1, dispc
.feat
->sw_start
, 0) |
3153 FLD_VAL(hfp
-1, dispc
.feat
->fp_start
, 8) |
3154 FLD_VAL(hbp
-1, dispc
.feat
->bp_start
, 20);
3155 timing_v
= FLD_VAL(vsw
-1, dispc
.feat
->sw_start
, 0) |
3156 FLD_VAL(vfp
, dispc
.feat
->fp_start
, 8) |
3157 FLD_VAL(vbp
, dispc
.feat
->bp_start
, 20);
3159 dispc_write_reg(DISPC_TIMING_H(channel
), timing_h
);
3160 dispc_write_reg(DISPC_TIMING_V(channel
), timing_v
);
3162 switch (vsync_level
) {
3163 case OMAPDSS_SIG_ACTIVE_LOW
:
3166 case OMAPDSS_SIG_ACTIVE_HIGH
:
3173 switch (hsync_level
) {
3174 case OMAPDSS_SIG_ACTIVE_LOW
:
3177 case OMAPDSS_SIG_ACTIVE_HIGH
:
3185 case OMAPDSS_SIG_ACTIVE_LOW
:
3188 case OMAPDSS_SIG_ACTIVE_HIGH
:
3195 switch (data_pclk_edge
) {
3196 case OMAPDSS_DRIVE_SIG_RISING_EDGE
:
3199 case OMAPDSS_DRIVE_SIG_FALLING_EDGE
:
3206 /* always use the 'rf' setting */
3209 switch (sync_pclk_edge
) {
3210 case OMAPDSS_DRIVE_SIG_FALLING_EDGE
:
3213 case OMAPDSS_DRIVE_SIG_RISING_EDGE
:
3220 l
= FLD_VAL(onoff
, 17, 17) |
3221 FLD_VAL(rf
, 16, 16) |
3222 FLD_VAL(de
, 15, 15) |
3223 FLD_VAL(ipc
, 14, 14) |
3224 FLD_VAL(hs
, 13, 13) |
3225 FLD_VAL(vs
, 12, 12);
3227 /* always set ALIGN bit when available */
3228 if (dispc
.feat
->supports_sync_align
)
3231 dispc_write_reg(DISPC_POL_FREQ(channel
), l
);
3233 if (dispc
.syscon_pol
) {
3234 const int shifts
[] = {
3235 [OMAP_DSS_CHANNEL_LCD
] = 0,
3236 [OMAP_DSS_CHANNEL_LCD2
] = 1,
3237 [OMAP_DSS_CHANNEL_LCD3
] = 2,
3242 mask
= (1 << 0) | (1 << 3) | (1 << 6);
3243 val
= (rf
<< 0) | (ipc
<< 3) | (onoff
<< 6);
3245 mask
<<= 16 + shifts
[channel
];
3246 val
<<= 16 + shifts
[channel
];
3248 regmap_update_bits(dispc
.syscon_pol
, dispc
.syscon_pol_offset
,
3253 /* change name to mode? */
3254 void dispc_mgr_set_timings(enum omap_channel channel
,
3255 const struct omap_video_timings
*timings
)
3257 unsigned xtot
, ytot
;
3258 unsigned long ht
, vt
;
3259 struct omap_video_timings t
= *timings
;
3261 DSSDBG("channel %d xres %u yres %u\n", channel
, t
.x_res
, t
.y_res
);
3263 if (!dispc_mgr_timings_ok(channel
, &t
)) {
3268 if (dss_mgr_is_lcd(channel
)) {
3269 _dispc_mgr_set_lcd_timings(channel
, t
.hsw
, t
.hfp
, t
.hbp
, t
.vsw
,
3270 t
.vfp
, t
.vbp
, t
.vsync_level
, t
.hsync_level
,
3271 t
.data_pclk_edge
, t
.de_level
, t
.sync_pclk_edge
);
3273 xtot
= t
.x_res
+ t
.hfp
+ t
.hsw
+ t
.hbp
;
3274 ytot
= t
.y_res
+ t
.vfp
+ t
.vsw
+ t
.vbp
;
3276 ht
= timings
->pixelclock
/ xtot
;
3277 vt
= timings
->pixelclock
/ xtot
/ ytot
;
3279 DSSDBG("pck %u\n", timings
->pixelclock
);
3280 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
3281 t
.hsw
, t
.hfp
, t
.hbp
, t
.vsw
, t
.vfp
, t
.vbp
);
3282 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3283 t
.vsync_level
, t
.hsync_level
, t
.data_pclk_edge
,
3284 t
.de_level
, t
.sync_pclk_edge
);
3286 DSSDBG("hsync %luHz, vsync %luHz\n", ht
, vt
);
3292 dispc_mgr_set_size(channel
, t
.x_res
, t
.y_res
);
3294 EXPORT_SYMBOL(dispc_mgr_set_timings
);
3296 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel
, u16 lck_div
,
3299 BUG_ON(lck_div
< 1);
3300 BUG_ON(pck_div
< 1);
3302 dispc_write_reg(DISPC_DIVISORo(channel
),
3303 FLD_VAL(lck_div
, 23, 16) | FLD_VAL(pck_div
, 7, 0));
3305 if (!dss_has_feature(FEAT_CORE_CLK_DIV
) &&
3306 channel
== OMAP_DSS_CHANNEL_LCD
)
3307 dispc
.core_clk_rate
= dispc_fclk_rate() / lck_div
;
3310 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel
, int *lck_div
,
3314 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3315 *lck_div
= FLD_GET(l
, 23, 16);
3316 *pck_div
= FLD_GET(l
, 7, 0);
3319 static unsigned long dispc_fclk_rate(void)
3321 struct dss_pll
*pll
;
3322 unsigned long r
= 0;
3324 switch (dss_get_dispc_clk_source()) {
3325 case OMAP_DSS_CLK_SRC_FCK
:
3326 r
= dss_get_dispc_clk_rate();
3328 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
3329 pll
= dss_pll_find("dsi0");
3331 pll
= dss_pll_find("video0");
3333 r
= pll
->cinfo
.clkout
[0];
3335 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
3336 pll
= dss_pll_find("dsi1");
3338 pll
= dss_pll_find("video1");
3340 r
= pll
->cinfo
.clkout
[0];
3350 static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel
)
3352 struct dss_pll
*pll
;
3357 if (dss_mgr_is_lcd(channel
)) {
3358 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3360 lcd
= FLD_GET(l
, 23, 16);
3362 switch (dss_get_lcd_clk_source(channel
)) {
3363 case OMAP_DSS_CLK_SRC_FCK
:
3364 r
= dss_get_dispc_clk_rate();
3366 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
3367 pll
= dss_pll_find("dsi0");
3369 pll
= dss_pll_find("video0");
3371 r
= pll
->cinfo
.clkout
[0];
3373 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
3374 pll
= dss_pll_find("dsi1");
3376 pll
= dss_pll_find("video1");
3378 r
= pll
->cinfo
.clkout
[0];
3387 return dispc_fclk_rate();
3391 static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel
)
3395 if (dss_mgr_is_lcd(channel
)) {
3399 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3401 pcd
= FLD_GET(l
, 7, 0);
3403 r
= dispc_mgr_lclk_rate(channel
);
3407 return dispc
.tv_pclk_rate
;
3411 void dispc_set_tv_pclk(unsigned long pclk
)
3413 dispc
.tv_pclk_rate
= pclk
;
3416 static unsigned long dispc_core_clk_rate(void)
3418 return dispc
.core_clk_rate
;
3421 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane
)
3423 enum omap_channel channel
;
3425 if (plane
== OMAP_DSS_WB
)
3428 channel
= dispc_ovl_get_channel_out(plane
);
3430 return dispc_mgr_pclk_rate(channel
);
3433 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane
)
3435 enum omap_channel channel
;
3437 if (plane
== OMAP_DSS_WB
)
3440 channel
= dispc_ovl_get_channel_out(plane
);
3442 return dispc_mgr_lclk_rate(channel
);
3445 static void dispc_dump_clocks_channel(struct seq_file
*s
, enum omap_channel channel
)
3448 enum omap_dss_clk_source lcd_clk_src
;
3450 seq_printf(s
, "- %s -\n", mgr_desc
[channel
].name
);
3452 lcd_clk_src
= dss_get_lcd_clk_source(channel
);
3454 seq_printf(s
, "%s clk source = %s (%s)\n", mgr_desc
[channel
].name
,
3455 dss_get_generic_clk_source_name(lcd_clk_src
),
3456 dss_feat_get_clk_source_name(lcd_clk_src
));
3458 dispc_mgr_get_lcd_divisor(channel
, &lcd
, &pcd
);
3460 seq_printf(s
, "lck\t\t%-16lulck div\t%u\n",
3461 dispc_mgr_lclk_rate(channel
), lcd
);
3462 seq_printf(s
, "pck\t\t%-16lupck div\t%u\n",
3463 dispc_mgr_pclk_rate(channel
), pcd
);
3466 void dispc_dump_clocks(struct seq_file
*s
)
3470 enum omap_dss_clk_source dispc_clk_src
= dss_get_dispc_clk_source();
3472 if (dispc_runtime_get())
3475 seq_printf(s
, "- DISPC -\n");
3477 seq_printf(s
, "dispc fclk source = %s (%s)\n",
3478 dss_get_generic_clk_source_name(dispc_clk_src
),
3479 dss_feat_get_clk_source_name(dispc_clk_src
));
3481 seq_printf(s
, "fck\t\t%-16lu\n", dispc_fclk_rate());
3483 if (dss_has_feature(FEAT_CORE_CLK_DIV
)) {
3484 seq_printf(s
, "- DISPC-CORE-CLK -\n");
3485 l
= dispc_read_reg(DISPC_DIVISOR
);
3486 lcd
= FLD_GET(l
, 23, 16);
3488 seq_printf(s
, "lck\t\t%-16lulck div\t%u\n",
3489 (dispc_fclk_rate()/lcd
), lcd
);
3492 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD
);
3494 if (dss_has_feature(FEAT_MGR_LCD2
))
3495 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD2
);
3496 if (dss_has_feature(FEAT_MGR_LCD3
))
3497 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD3
);
3499 dispc_runtime_put();
3502 static void dispc_dump_regs(struct seq_file
*s
)
3505 const char *mgr_names
[] = {
3506 [OMAP_DSS_CHANNEL_LCD
] = "LCD",
3507 [OMAP_DSS_CHANNEL_DIGIT
] = "TV",
3508 [OMAP_DSS_CHANNEL_LCD2
] = "LCD2",
3509 [OMAP_DSS_CHANNEL_LCD3
] = "LCD3",
3511 const char *ovl_names
[] = {
3512 [OMAP_DSS_GFX
] = "GFX",
3513 [OMAP_DSS_VIDEO1
] = "VID1",
3514 [OMAP_DSS_VIDEO2
] = "VID2",
3515 [OMAP_DSS_VIDEO3
] = "VID3",
3516 [OMAP_DSS_WB
] = "WB",
3518 const char **p_names
;
3520 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3522 if (dispc_runtime_get())
3525 /* DISPC common registers */
3526 DUMPREG(DISPC_REVISION
);
3527 DUMPREG(DISPC_SYSCONFIG
);
3528 DUMPREG(DISPC_SYSSTATUS
);
3529 DUMPREG(DISPC_IRQSTATUS
);
3530 DUMPREG(DISPC_IRQENABLE
);
3531 DUMPREG(DISPC_CONTROL
);
3532 DUMPREG(DISPC_CONFIG
);
3533 DUMPREG(DISPC_CAPABLE
);
3534 DUMPREG(DISPC_LINE_STATUS
);
3535 DUMPREG(DISPC_LINE_NUMBER
);
3536 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
3537 dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
3538 DUMPREG(DISPC_GLOBAL_ALPHA
);
3539 if (dss_has_feature(FEAT_MGR_LCD2
)) {
3540 DUMPREG(DISPC_CONTROL2
);
3541 DUMPREG(DISPC_CONFIG2
);
3543 if (dss_has_feature(FEAT_MGR_LCD3
)) {
3544 DUMPREG(DISPC_CONTROL3
);
3545 DUMPREG(DISPC_CONFIG3
);
3547 if (dss_has_feature(FEAT_MFLAG
))
3548 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE
);
3552 #define DISPC_REG(i, name) name(i)
3553 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3554 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
3555 dispc_read_reg(DISPC_REG(i, r)))
3557 p_names
= mgr_names
;
3559 /* DISPC channel specific registers */
3560 for (i
= 0; i
< dss_feat_get_num_mgrs(); i
++) {
3561 DUMPREG(i
, DISPC_DEFAULT_COLOR
);
3562 DUMPREG(i
, DISPC_TRANS_COLOR
);
3563 DUMPREG(i
, DISPC_SIZE_MGR
);
3565 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
3568 DUMPREG(i
, DISPC_TIMING_H
);
3569 DUMPREG(i
, DISPC_TIMING_V
);
3570 DUMPREG(i
, DISPC_POL_FREQ
);
3571 DUMPREG(i
, DISPC_DIVISORo
);
3573 DUMPREG(i
, DISPC_DATA_CYCLE1
);
3574 DUMPREG(i
, DISPC_DATA_CYCLE2
);
3575 DUMPREG(i
, DISPC_DATA_CYCLE3
);
3577 if (dss_has_feature(FEAT_CPR
)) {
3578 DUMPREG(i
, DISPC_CPR_COEF_R
);
3579 DUMPREG(i
, DISPC_CPR_COEF_G
);
3580 DUMPREG(i
, DISPC_CPR_COEF_B
);
3584 p_names
= ovl_names
;
3586 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
3587 DUMPREG(i
, DISPC_OVL_BA0
);
3588 DUMPREG(i
, DISPC_OVL_BA1
);
3589 DUMPREG(i
, DISPC_OVL_POSITION
);
3590 DUMPREG(i
, DISPC_OVL_SIZE
);
3591 DUMPREG(i
, DISPC_OVL_ATTRIBUTES
);
3592 DUMPREG(i
, DISPC_OVL_FIFO_THRESHOLD
);
3593 DUMPREG(i
, DISPC_OVL_FIFO_SIZE_STATUS
);
3594 DUMPREG(i
, DISPC_OVL_ROW_INC
);
3595 DUMPREG(i
, DISPC_OVL_PIXEL_INC
);
3597 if (dss_has_feature(FEAT_PRELOAD
))
3598 DUMPREG(i
, DISPC_OVL_PRELOAD
);
3599 if (dss_has_feature(FEAT_MFLAG
))
3600 DUMPREG(i
, DISPC_OVL_MFLAG_THRESHOLD
);
3602 if (i
== OMAP_DSS_GFX
) {
3603 DUMPREG(i
, DISPC_OVL_WINDOW_SKIP
);
3604 DUMPREG(i
, DISPC_OVL_TABLE_BA
);
3608 DUMPREG(i
, DISPC_OVL_FIR
);
3609 DUMPREG(i
, DISPC_OVL_PICTURE_SIZE
);
3610 DUMPREG(i
, DISPC_OVL_ACCU0
);
3611 DUMPREG(i
, DISPC_OVL_ACCU1
);
3612 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3613 DUMPREG(i
, DISPC_OVL_BA0_UV
);
3614 DUMPREG(i
, DISPC_OVL_BA1_UV
);
3615 DUMPREG(i
, DISPC_OVL_FIR2
);
3616 DUMPREG(i
, DISPC_OVL_ACCU2_0
);
3617 DUMPREG(i
, DISPC_OVL_ACCU2_1
);
3619 if (dss_has_feature(FEAT_ATTR2
))
3620 DUMPREG(i
, DISPC_OVL_ATTRIBUTES2
);
3623 if (dispc
.feat
->has_writeback
) {
3625 DUMPREG(i
, DISPC_OVL_BA0
);
3626 DUMPREG(i
, DISPC_OVL_BA1
);
3627 DUMPREG(i
, DISPC_OVL_SIZE
);
3628 DUMPREG(i
, DISPC_OVL_ATTRIBUTES
);
3629 DUMPREG(i
, DISPC_OVL_FIFO_THRESHOLD
);
3630 DUMPREG(i
, DISPC_OVL_FIFO_SIZE_STATUS
);
3631 DUMPREG(i
, DISPC_OVL_ROW_INC
);
3632 DUMPREG(i
, DISPC_OVL_PIXEL_INC
);
3634 if (dss_has_feature(FEAT_MFLAG
))
3635 DUMPREG(i
, DISPC_OVL_MFLAG_THRESHOLD
);
3637 DUMPREG(i
, DISPC_OVL_FIR
);
3638 DUMPREG(i
, DISPC_OVL_PICTURE_SIZE
);
3639 DUMPREG(i
, DISPC_OVL_ACCU0
);
3640 DUMPREG(i
, DISPC_OVL_ACCU1
);
3641 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3642 DUMPREG(i
, DISPC_OVL_BA0_UV
);
3643 DUMPREG(i
, DISPC_OVL_BA1_UV
);
3644 DUMPREG(i
, DISPC_OVL_FIR2
);
3645 DUMPREG(i
, DISPC_OVL_ACCU2_0
);
3646 DUMPREG(i
, DISPC_OVL_ACCU2_1
);
3648 if (dss_has_feature(FEAT_ATTR2
))
3649 DUMPREG(i
, DISPC_OVL_ATTRIBUTES2
);
3655 #define DISPC_REG(plane, name, i) name(plane, i)
3656 #define DUMPREG(plane, name, i) \
3657 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3658 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
3659 dispc_read_reg(DISPC_REG(plane, name, i)))
3661 /* Video pipeline coefficient registers */
3663 /* start from OMAP_DSS_VIDEO1 */
3664 for (i
= 1; i
< dss_feat_get_num_ovls(); i
++) {
3665 for (j
= 0; j
< 8; j
++)
3666 DUMPREG(i
, DISPC_OVL_FIR_COEF_H
, j
);
3668 for (j
= 0; j
< 8; j
++)
3669 DUMPREG(i
, DISPC_OVL_FIR_COEF_HV
, j
);
3671 for (j
= 0; j
< 5; j
++)
3672 DUMPREG(i
, DISPC_OVL_CONV_COEF
, j
);
3674 if (dss_has_feature(FEAT_FIR_COEF_V
)) {
3675 for (j
= 0; j
< 8; j
++)
3676 DUMPREG(i
, DISPC_OVL_FIR_COEF_V
, j
);
3679 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3680 for (j
= 0; j
< 8; j
++)
3681 DUMPREG(i
, DISPC_OVL_FIR_COEF_H2
, j
);
3683 for (j
= 0; j
< 8; j
++)
3684 DUMPREG(i
, DISPC_OVL_FIR_COEF_HV2
, j
);
3686 for (j
= 0; j
< 8; j
++)
3687 DUMPREG(i
, DISPC_OVL_FIR_COEF_V2
, j
);
3691 dispc_runtime_put();
3697 /* calculate clock rates using dividers in cinfo */
3698 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate
,
3699 struct dispc_clock_info
*cinfo
)
3701 if (cinfo
->lck_div
> 255 || cinfo
->lck_div
== 0)
3703 if (cinfo
->pck_div
< 1 || cinfo
->pck_div
> 255)
3706 cinfo
->lck
= dispc_fclk_rate
/ cinfo
->lck_div
;
3707 cinfo
->pck
= cinfo
->lck
/ cinfo
->pck_div
;
3712 bool dispc_div_calc(unsigned long dispc
,
3713 unsigned long pck_min
, unsigned long pck_max
,
3714 dispc_div_calc_func func
, void *data
)
3716 int lckd
, lckd_start
, lckd_stop
;
3717 int pckd
, pckd_start
, pckd_stop
;
3718 unsigned long pck
, lck
;
3719 unsigned long lck_max
;
3720 unsigned long pckd_hw_min
, pckd_hw_max
;
3721 unsigned min_fck_per_pck
;
3724 #ifdef CONFIG_FB_OMAP2_DSS_MIN_FCK_PER_PCK
3725 min_fck_per_pck
= CONFIG_FB_OMAP2_DSS_MIN_FCK_PER_PCK
;
3727 min_fck_per_pck
= 0;
3730 pckd_hw_min
= dss_feat_get_param_min(FEAT_PARAM_DSS_PCD
);
3731 pckd_hw_max
= dss_feat_get_param_max(FEAT_PARAM_DSS_PCD
);
3733 lck_max
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
3735 pck_min
= pck_min
? pck_min
: 1;
3736 pck_max
= pck_max
? pck_max
: ULONG_MAX
;
3738 lckd_start
= max(DIV_ROUND_UP(dispc
, lck_max
), 1ul);
3739 lckd_stop
= min(dispc
/ pck_min
, 255ul);
3741 for (lckd
= lckd_start
; lckd
<= lckd_stop
; ++lckd
) {
3744 pckd_start
= max(DIV_ROUND_UP(lck
, pck_max
), pckd_hw_min
);
3745 pckd_stop
= min(lck
/ pck_min
, pckd_hw_max
);
3747 for (pckd
= pckd_start
; pckd
<= pckd_stop
; ++pckd
) {
3751 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3752 * clock, which means we're configuring DISPC fclk here
3753 * also. Thus we need to use the calculated lck. For
3754 * OMAP4+ the DISPC fclk is a separate clock.
3756 if (dss_has_feature(FEAT_CORE_CLK_DIV
))
3757 fck
= dispc_core_clk_rate();
3761 if (fck
< pck
* min_fck_per_pck
)
3764 if (func(lckd
, pckd
, lck
, pck
, data
))
3772 void dispc_mgr_set_clock_div(enum omap_channel channel
,
3773 const struct dispc_clock_info
*cinfo
)
3775 DSSDBG("lck = %lu (%u)\n", cinfo
->lck
, cinfo
->lck_div
);
3776 DSSDBG("pck = %lu (%u)\n", cinfo
->pck
, cinfo
->pck_div
);
3778 dispc_mgr_set_lcd_divisor(channel
, cinfo
->lck_div
, cinfo
->pck_div
);
3781 int dispc_mgr_get_clock_div(enum omap_channel channel
,
3782 struct dispc_clock_info
*cinfo
)
3786 fck
= dispc_fclk_rate();
3788 cinfo
->lck_div
= REG_GET(DISPC_DIVISORo(channel
), 23, 16);
3789 cinfo
->pck_div
= REG_GET(DISPC_DIVISORo(channel
), 7, 0);
3791 cinfo
->lck
= fck
/ cinfo
->lck_div
;
3792 cinfo
->pck
= cinfo
->lck
/ cinfo
->pck_div
;
3797 u32
dispc_read_irqstatus(void)
3799 return dispc_read_reg(DISPC_IRQSTATUS
);
3801 EXPORT_SYMBOL(dispc_read_irqstatus
);
3803 void dispc_clear_irqstatus(u32 mask
)
3805 dispc_write_reg(DISPC_IRQSTATUS
, mask
);
3807 EXPORT_SYMBOL(dispc_clear_irqstatus
);
3809 u32
dispc_read_irqenable(void)
3811 return dispc_read_reg(DISPC_IRQENABLE
);
3813 EXPORT_SYMBOL(dispc_read_irqenable
);
3815 void dispc_write_irqenable(u32 mask
)
3817 u32 old_mask
= dispc_read_reg(DISPC_IRQENABLE
);
3819 /* clear the irqstatus for newly enabled irqs */
3820 dispc_clear_irqstatus((mask
^ old_mask
) & mask
);
3822 dispc_write_reg(DISPC_IRQENABLE
, mask
);
3824 EXPORT_SYMBOL(dispc_write_irqenable
);
3826 void dispc_enable_sidle(void)
3828 REG_FLD_MOD(DISPC_SYSCONFIG
, 2, 4, 3); /* SIDLEMODE: smart idle */
3831 void dispc_disable_sidle(void)
3833 REG_FLD_MOD(DISPC_SYSCONFIG
, 1, 4, 3); /* SIDLEMODE: no idle */
3836 static void _omap_dispc_initial_config(void)
3840 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3841 if (dss_has_feature(FEAT_CORE_CLK_DIV
)) {
3842 l
= dispc_read_reg(DISPC_DIVISOR
);
3843 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3844 l
= FLD_MOD(l
, 1, 0, 0);
3845 l
= FLD_MOD(l
, 1, 23, 16);
3846 dispc_write_reg(DISPC_DIVISOR
, l
);
3848 dispc
.core_clk_rate
= dispc_fclk_rate();
3852 if (dss_has_feature(FEAT_FUNCGATED
))
3853 REG_FLD_MOD(DISPC_CONFIG
, 1, 9, 9);
3855 dispc_setup_color_conv_coef();
3857 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY
);
3861 dispc_configure_burst_sizes();
3863 dispc_ovl_enable_zorder_planes();
3865 if (dispc
.feat
->mstandby_workaround
)
3866 REG_FLD_MOD(DISPC_MSTANDBY_CTRL
, 1, 0, 0);
3868 if (dss_has_feature(FEAT_MFLAG
))
3872 static const struct dispc_features omap24xx_dispc_feats
= {
3879 .mgr_width_start
= 10,
3880 .mgr_height_start
= 26,
3881 .mgr_width_max
= 2048,
3882 .mgr_height_max
= 2048,
3883 .max_lcd_pclk
= 66500000,
3884 .calc_scaling
= dispc_ovl_calc_scaling_24xx
,
3885 .calc_core_clk
= calc_core_clk_24xx
,
3887 .no_framedone_tv
= true,
3888 .set_max_preload
= false,
3889 .last_pixel_inc_missing
= true,
3892 static const struct dispc_features omap34xx_rev1_0_dispc_feats
= {
3899 .mgr_width_start
= 10,
3900 .mgr_height_start
= 26,
3901 .mgr_width_max
= 2048,
3902 .mgr_height_max
= 2048,
3903 .max_lcd_pclk
= 173000000,
3904 .max_tv_pclk
= 59000000,
3905 .calc_scaling
= dispc_ovl_calc_scaling_34xx
,
3906 .calc_core_clk
= calc_core_clk_34xx
,
3908 .no_framedone_tv
= true,
3909 .set_max_preload
= false,
3910 .last_pixel_inc_missing
= true,
3913 static const struct dispc_features omap34xx_rev3_0_dispc_feats
= {
3920 .mgr_width_start
= 10,
3921 .mgr_height_start
= 26,
3922 .mgr_width_max
= 2048,
3923 .mgr_height_max
= 2048,
3924 .max_lcd_pclk
= 173000000,
3925 .max_tv_pclk
= 59000000,
3926 .calc_scaling
= dispc_ovl_calc_scaling_34xx
,
3927 .calc_core_clk
= calc_core_clk_34xx
,
3929 .no_framedone_tv
= true,
3930 .set_max_preload
= false,
3931 .last_pixel_inc_missing
= true,
3934 static const struct dispc_features omap44xx_dispc_feats
= {
3941 .mgr_width_start
= 10,
3942 .mgr_height_start
= 26,
3943 .mgr_width_max
= 2048,
3944 .mgr_height_max
= 2048,
3945 .max_lcd_pclk
= 170000000,
3946 .max_tv_pclk
= 185625000,
3947 .calc_scaling
= dispc_ovl_calc_scaling_44xx
,
3948 .calc_core_clk
= calc_core_clk_44xx
,
3950 .gfx_fifo_workaround
= true,
3951 .set_max_preload
= true,
3952 .supports_sync_align
= true,
3953 .has_writeback
= true,
3956 static const struct dispc_features omap54xx_dispc_feats
= {
3963 .mgr_width_start
= 11,
3964 .mgr_height_start
= 27,
3965 .mgr_width_max
= 4096,
3966 .mgr_height_max
= 4096,
3967 .max_lcd_pclk
= 170000000,
3968 .max_tv_pclk
= 186000000,
3969 .calc_scaling
= dispc_ovl_calc_scaling_44xx
,
3970 .calc_core_clk
= calc_core_clk_44xx
,
3972 .gfx_fifo_workaround
= true,
3973 .mstandby_workaround
= true,
3974 .set_max_preload
= true,
3975 .supports_sync_align
= true,
3976 .has_writeback
= true,
3979 static const struct dispc_features
*dispc_get_features(void)
3981 switch (omapdss_get_version()) {
3982 case OMAPDSS_VER_OMAP24xx
:
3983 return &omap24xx_dispc_feats
;
3985 case OMAPDSS_VER_OMAP34xx_ES1
:
3986 return &omap34xx_rev1_0_dispc_feats
;
3988 case OMAPDSS_VER_OMAP34xx_ES3
:
3989 case OMAPDSS_VER_OMAP3630
:
3990 case OMAPDSS_VER_AM35xx
:
3991 case OMAPDSS_VER_AM43xx
:
3992 return &omap34xx_rev3_0_dispc_feats
;
3994 case OMAPDSS_VER_OMAP4430_ES1
:
3995 case OMAPDSS_VER_OMAP4430_ES2
:
3996 case OMAPDSS_VER_OMAP4
:
3997 return &omap44xx_dispc_feats
;
3999 case OMAPDSS_VER_OMAP5
:
4000 case OMAPDSS_VER_DRA7xx
:
4001 return &omap54xx_dispc_feats
;
4008 static irqreturn_t
dispc_irq_handler(int irq
, void *arg
)
4010 if (!dispc
.is_enabled
)
4013 return dispc
.user_handler(irq
, dispc
.user_data
);
4016 int dispc_request_irq(irq_handler_t handler
, void *dev_id
)
4020 if (dispc
.user_handler
!= NULL
)
4023 dispc
.user_handler
= handler
;
4024 dispc
.user_data
= dev_id
;
4026 /* ensure the dispc_irq_handler sees the values above */
4029 r
= devm_request_irq(&dispc
.pdev
->dev
, dispc
.irq
, dispc_irq_handler
,
4030 IRQF_SHARED
, "OMAP DISPC", &dispc
);
4032 dispc
.user_handler
= NULL
;
4033 dispc
.user_data
= NULL
;
4038 EXPORT_SYMBOL(dispc_request_irq
);
4040 void dispc_free_irq(void *dev_id
)
4042 devm_free_irq(&dispc
.pdev
->dev
, dispc
.irq
, &dispc
);
4044 dispc
.user_handler
= NULL
;
4045 dispc
.user_data
= NULL
;
4047 EXPORT_SYMBOL(dispc_free_irq
);
4049 /* DISPC HW IP initialisation */
4050 static int dispc_bind(struct device
*dev
, struct device
*master
, void *data
)
4052 struct platform_device
*pdev
= to_platform_device(dev
);
4055 struct resource
*dispc_mem
;
4056 struct device_node
*np
= pdev
->dev
.of_node
;
4060 spin_lock_init(&dispc
.control_lock
);
4062 dispc
.feat
= dispc_get_features();
4066 dispc_mem
= platform_get_resource(dispc
.pdev
, IORESOURCE_MEM
, 0);
4068 DSSERR("can't get IORESOURCE_MEM DISPC\n");
4072 dispc
.base
= devm_ioremap(&pdev
->dev
, dispc_mem
->start
,
4073 resource_size(dispc_mem
));
4075 DSSERR("can't ioremap DISPC\n");
4079 dispc
.irq
= platform_get_irq(dispc
.pdev
, 0);
4080 if (dispc
.irq
< 0) {
4081 DSSERR("platform_get_irq failed\n");
4085 if (np
&& of_property_read_bool(np
, "syscon-pol")) {
4086 dispc
.syscon_pol
= syscon_regmap_lookup_by_phandle(np
, "syscon-pol");
4087 if (IS_ERR(dispc
.syscon_pol
)) {
4088 dev_err(&pdev
->dev
, "failed to get syscon-pol regmap\n");
4089 return PTR_ERR(dispc
.syscon_pol
);
4092 if (of_property_read_u32_index(np
, "syscon-pol", 1,
4093 &dispc
.syscon_pol_offset
)) {
4094 dev_err(&pdev
->dev
, "failed to get syscon-pol offset\n");
4099 pm_runtime_enable(&pdev
->dev
);
4101 r
= dispc_runtime_get();
4103 goto err_runtime_get
;
4105 _omap_dispc_initial_config();
4107 rev
= dispc_read_reg(DISPC_REVISION
);
4108 dev_dbg(&pdev
->dev
, "OMAP DISPC rev %d.%d\n",
4109 FLD_GET(rev
, 7, 4), FLD_GET(rev
, 3, 0));
4111 dispc_runtime_put();
4113 dss_init_overlay_managers();
4115 dss_debugfs_create_file("dispc", dispc_dump_regs
);
4120 pm_runtime_disable(&pdev
->dev
);
4124 static void dispc_unbind(struct device
*dev
, struct device
*master
,
4127 pm_runtime_disable(dev
);
4129 dss_uninit_overlay_managers();
4132 static const struct component_ops dispc_component_ops
= {
4134 .unbind
= dispc_unbind
,
4137 static int dispc_probe(struct platform_device
*pdev
)
4139 return component_add(&pdev
->dev
, &dispc_component_ops
);
4142 static int dispc_remove(struct platform_device
*pdev
)
4144 component_del(&pdev
->dev
, &dispc_component_ops
);
4148 static int dispc_runtime_suspend(struct device
*dev
)
4150 dispc
.is_enabled
= false;
4151 /* ensure the dispc_irq_handler sees the is_enabled value */
4153 /* wait for current handler to finish before turning the DISPC off */
4154 synchronize_irq(dispc
.irq
);
4156 dispc_save_context();
4161 static int dispc_runtime_resume(struct device
*dev
)
4164 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4165 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4166 * _omap_dispc_initial_config(). We can thus use it to detect if
4167 * we have lost register context.
4169 if (REG_GET(DISPC_CONFIG
, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY
) {
4170 _omap_dispc_initial_config();
4172 dispc_restore_context();
4175 dispc
.is_enabled
= true;
4176 /* ensure the dispc_irq_handler sees the is_enabled value */
4182 static const struct dev_pm_ops dispc_pm_ops
= {
4183 .runtime_suspend
= dispc_runtime_suspend
,
4184 .runtime_resume
= dispc_runtime_resume
,
4187 static const struct of_device_id dispc_of_match
[] = {
4188 { .compatible
= "ti,omap2-dispc", },
4189 { .compatible
= "ti,omap3-dispc", },
4190 { .compatible
= "ti,omap4-dispc", },
4191 { .compatible
= "ti,omap5-dispc", },
4192 { .compatible
= "ti,dra7-dispc", },
4196 static struct platform_driver omap_dispchw_driver
= {
4197 .probe
= dispc_probe
,
4198 .remove
= dispc_remove
,
4200 .name
= "omapdss_dispc",
4201 .pm
= &dispc_pm_ops
,
4202 .of_match_table
= dispc_of_match
,
4203 .suppress_bind_attrs
= true,
4207 int __init
dispc_init_platform_driver(void)
4209 return platform_driver_register(&omap_dispchw_driver
);
4212 void dispc_uninit_platform_driver(void)
4214 platform_driver_unregister(&omap_dispchw_driver
);