1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/video/omap2/dss/dispc.c
5 * Copyright (C) 2009 Nokia Corporation
6 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
8 * Some code and ideas taken from drivers/video/omap/ driver
12 #define DSS_SUBSYS_NAME "DISPC"
14 #include <linux/kernel.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/vmalloc.h>
17 #include <linux/export.h>
18 #include <linux/clk.h>
20 #include <linux/jiffies.h>
21 #include <linux/seq_file.h>
22 #include <linux/delay.h>
23 #include <linux/workqueue.h>
24 #include <linux/hardirq.h>
25 #include <linux/platform_device.h>
26 #include <linux/pm_runtime.h>
27 #include <linux/sizes.h>
28 #include <linux/mfd/syscon.h>
29 #include <linux/regmap.h>
31 #include <linux/component.h>
33 #include <video/omapfb_dss.h>
36 #include "dss_features.h"
40 #define DISPC_SZ_REGS SZ_4K
42 enum omap_burst_size
{
48 #define REG_GET(idx, start, end) \
49 FLD_GET(dispc_read_reg(idx), start, end)
51 #define REG_FLD_MOD(idx, val, start, end) \
52 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
54 struct dispc_features
{
65 unsigned long max_lcd_pclk
;
66 unsigned long max_tv_pclk
;
67 int (*calc_scaling
) (unsigned long pclk
, unsigned long lclk
,
68 const struct omap_video_timings
*mgr_timings
,
69 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
70 enum omap_color_mode color_mode
, bool *five_taps
,
71 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
72 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
);
73 unsigned long (*calc_core_clk
) (unsigned long pclk
,
74 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
78 /* swap GFX & WB fifos */
79 bool gfx_fifo_workaround
:1;
81 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
82 bool no_framedone_tv
:1;
84 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
85 bool mstandby_workaround
:1;
87 bool set_max_preload
:1;
89 /* PIXEL_INC is not added to the last pixel of a line */
90 bool last_pixel_inc_missing
:1;
92 /* POL_FREQ has ALIGN bit */
93 bool supports_sync_align
:1;
98 #define DISPC_MAX_NR_FIFOS 5
101 struct platform_device
*pdev
;
105 irq_handler_t user_handler
;
108 unsigned long core_clk_rate
;
109 unsigned long tv_pclk_rate
;
111 u32 fifo_size
[DISPC_MAX_NR_FIFOS
];
112 /* maps which plane is using a fifo. fifo-id -> plane-id */
113 int fifo_assignment
[DISPC_MAX_NR_FIFOS
];
116 u32 ctx
[DISPC_SZ_REGS
/ sizeof(u32
)];
118 const struct dispc_features
*feat
;
122 struct regmap
*syscon_pol
;
123 u32 syscon_pol_offset
;
125 /* DISPC_CONTROL & DISPC_CONFIG lock*/
126 spinlock_t control_lock
;
129 enum omap_color_component
{
130 /* used for all color formats for OMAP3 and earlier
131 * and for RGB and Y color component on OMAP4
133 DISPC_COLOR_COMPONENT_RGB_Y
= 1 << 0,
134 /* used for UV component for
135 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
136 * color formats on OMAP4
138 DISPC_COLOR_COMPONENT_UV
= 1 << 1,
141 enum mgr_reg_fields
{
142 DISPC_MGR_FLD_ENABLE
,
143 DISPC_MGR_FLD_STNTFT
,
145 DISPC_MGR_FLD_TFTDATALINES
,
146 DISPC_MGR_FLD_STALLMODE
,
147 DISPC_MGR_FLD_TCKENABLE
,
148 DISPC_MGR_FLD_TCKSELECTION
,
150 DISPC_MGR_FLD_FIFOHANDCHECK
,
151 /* used to maintain a count of the above fields */
155 struct dispc_reg_field
{
161 static const struct {
166 struct dispc_reg_field reg_desc
[DISPC_MGR_FLD_NUM
];
168 [OMAP_DSS_CHANNEL_LCD
] = {
170 .vsync_irq
= DISPC_IRQ_VSYNC
,
171 .framedone_irq
= DISPC_IRQ_FRAMEDONE
,
172 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST
,
174 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL
, 0, 0 },
175 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL
, 3, 3 },
176 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL
, 5, 5 },
177 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL
, 9, 8 },
178 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL
, 11, 11 },
179 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG
, 10, 10 },
180 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG
, 11, 11 },
181 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG
, 15, 15 },
182 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG
, 16, 16 },
185 [OMAP_DSS_CHANNEL_DIGIT
] = {
187 .vsync_irq
= DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_EVSYNC_EVEN
,
188 .framedone_irq
= DISPC_IRQ_FRAMEDONETV
,
189 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST_DIGIT
,
191 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL
, 1, 1 },
192 [DISPC_MGR_FLD_STNTFT
] = { },
193 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL
, 6, 6 },
194 [DISPC_MGR_FLD_TFTDATALINES
] = { },
195 [DISPC_MGR_FLD_STALLMODE
] = { },
196 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG
, 12, 12 },
197 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG
, 13, 13 },
198 [DISPC_MGR_FLD_CPR
] = { },
199 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG
, 16, 16 },
202 [OMAP_DSS_CHANNEL_LCD2
] = {
204 .vsync_irq
= DISPC_IRQ_VSYNC2
,
205 .framedone_irq
= DISPC_IRQ_FRAMEDONE2
,
206 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST2
,
208 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL2
, 0, 0 },
209 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL2
, 3, 3 },
210 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL2
, 5, 5 },
211 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL2
, 9, 8 },
212 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL2
, 11, 11 },
213 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG2
, 10, 10 },
214 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG2
, 11, 11 },
215 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG2
, 15, 15 },
216 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG2
, 16, 16 },
219 [OMAP_DSS_CHANNEL_LCD3
] = {
221 .vsync_irq
= DISPC_IRQ_VSYNC3
,
222 .framedone_irq
= DISPC_IRQ_FRAMEDONE3
,
223 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST3
,
225 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL3
, 0, 0 },
226 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL3
, 3, 3 },
227 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL3
, 5, 5 },
228 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL3
, 9, 8 },
229 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL3
, 11, 11 },
230 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG3
, 10, 10 },
231 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG3
, 11, 11 },
232 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG3
, 15, 15 },
233 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG3
, 16, 16 },
238 struct color_conv_coef
{
239 int ry
, rcr
, rcb
, gy
, gcr
, gcb
, by
, bcr
, bcb
;
243 static unsigned long dispc_fclk_rate(void);
244 static unsigned long dispc_core_clk_rate(void);
245 static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel
);
246 static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel
);
248 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane
);
249 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane
);
251 static inline void dispc_write_reg(const u16 idx
, u32 val
)
253 __raw_writel(val
, dispc
.base
+ idx
);
256 static inline u32
dispc_read_reg(const u16 idx
)
258 return __raw_readl(dispc
.base
+ idx
);
261 static u32
mgr_fld_read(enum omap_channel channel
, enum mgr_reg_fields regfld
)
263 const struct dispc_reg_field rfld
= mgr_desc
[channel
].reg_desc
[regfld
];
264 return REG_GET(rfld
.reg
, rfld
.high
, rfld
.low
);
267 static void mgr_fld_write(enum omap_channel channel
,
268 enum mgr_reg_fields regfld
, int val
) {
269 const struct dispc_reg_field rfld
= mgr_desc
[channel
].reg_desc
[regfld
];
270 const bool need_lock
= rfld
.reg
== DISPC_CONTROL
|| rfld
.reg
== DISPC_CONFIG
;
274 spin_lock_irqsave(&dispc
.control_lock
, flags
);
276 REG_FLD_MOD(rfld
.reg
, val
, rfld
.high
, rfld
.low
);
279 spin_unlock_irqrestore(&dispc
.control_lock
, flags
);
283 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
285 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
287 static void dispc_save_context(void)
291 DSSDBG("dispc_save_context\n");
297 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
298 dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
300 if (dss_has_feature(FEAT_MGR_LCD2
)) {
304 if (dss_has_feature(FEAT_MGR_LCD3
)) {
309 for (i
= 0; i
< dss_feat_get_num_mgrs(); i
++) {
310 SR(DEFAULT_COLOR(i
));
313 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
324 if (dss_has_feature(FEAT_CPR
)) {
331 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
336 SR(OVL_ATTRIBUTES(i
));
337 SR(OVL_FIFO_THRESHOLD(i
));
339 SR(OVL_PIXEL_INC(i
));
340 if (dss_has_feature(FEAT_PRELOAD
))
342 if (i
== OMAP_DSS_GFX
) {
343 SR(OVL_WINDOW_SKIP(i
));
348 SR(OVL_PICTURE_SIZE(i
));
352 for (j
= 0; j
< 8; j
++)
353 SR(OVL_FIR_COEF_H(i
, j
));
355 for (j
= 0; j
< 8; j
++)
356 SR(OVL_FIR_COEF_HV(i
, j
));
358 for (j
= 0; j
< 5; j
++)
359 SR(OVL_CONV_COEF(i
, j
));
361 if (dss_has_feature(FEAT_FIR_COEF_V
)) {
362 for (j
= 0; j
< 8; j
++)
363 SR(OVL_FIR_COEF_V(i
, j
));
366 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
373 for (j
= 0; j
< 8; j
++)
374 SR(OVL_FIR_COEF_H2(i
, j
));
376 for (j
= 0; j
< 8; j
++)
377 SR(OVL_FIR_COEF_HV2(i
, j
));
379 for (j
= 0; j
< 8; j
++)
380 SR(OVL_FIR_COEF_V2(i
, j
));
382 if (dss_has_feature(FEAT_ATTR2
))
383 SR(OVL_ATTRIBUTES2(i
));
386 if (dss_has_feature(FEAT_CORE_CLK_DIV
))
389 dispc
.ctx_valid
= true;
391 DSSDBG("context saved\n");
394 static void dispc_restore_context(void)
398 DSSDBG("dispc_restore_context\n");
400 if (!dispc
.ctx_valid
)
407 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
408 dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
410 if (dss_has_feature(FEAT_MGR_LCD2
))
412 if (dss_has_feature(FEAT_MGR_LCD3
))
415 for (i
= 0; i
< dss_feat_get_num_mgrs(); i
++) {
416 RR(DEFAULT_COLOR(i
));
419 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
430 if (dss_has_feature(FEAT_CPR
)) {
437 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
442 RR(OVL_ATTRIBUTES(i
));
443 RR(OVL_FIFO_THRESHOLD(i
));
445 RR(OVL_PIXEL_INC(i
));
446 if (dss_has_feature(FEAT_PRELOAD
))
448 if (i
== OMAP_DSS_GFX
) {
449 RR(OVL_WINDOW_SKIP(i
));
454 RR(OVL_PICTURE_SIZE(i
));
458 for (j
= 0; j
< 8; j
++)
459 RR(OVL_FIR_COEF_H(i
, j
));
461 for (j
= 0; j
< 8; j
++)
462 RR(OVL_FIR_COEF_HV(i
, j
));
464 for (j
= 0; j
< 5; j
++)
465 RR(OVL_CONV_COEF(i
, j
));
467 if (dss_has_feature(FEAT_FIR_COEF_V
)) {
468 for (j
= 0; j
< 8; j
++)
469 RR(OVL_FIR_COEF_V(i
, j
));
472 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
479 for (j
= 0; j
< 8; j
++)
480 RR(OVL_FIR_COEF_H2(i
, j
));
482 for (j
= 0; j
< 8; j
++)
483 RR(OVL_FIR_COEF_HV2(i
, j
));
485 for (j
= 0; j
< 8; j
++)
486 RR(OVL_FIR_COEF_V2(i
, j
));
488 if (dss_has_feature(FEAT_ATTR2
))
489 RR(OVL_ATTRIBUTES2(i
));
492 if (dss_has_feature(FEAT_CORE_CLK_DIV
))
495 /* enable last, because LCD & DIGIT enable are here */
497 if (dss_has_feature(FEAT_MGR_LCD2
))
499 if (dss_has_feature(FEAT_MGR_LCD3
))
501 /* clear spurious SYNC_LOST_DIGIT interrupts */
502 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT
);
505 * enable last so IRQs won't trigger before
506 * the context is fully restored
510 DSSDBG("context restored\n");
516 int dispc_runtime_get(void)
520 DSSDBG("dispc_runtime_get\n");
522 r
= pm_runtime_resume_and_get(&dispc
.pdev
->dev
);
527 EXPORT_SYMBOL(dispc_runtime_get
);
529 void dispc_runtime_put(void)
533 DSSDBG("dispc_runtime_put\n");
535 r
= pm_runtime_put_sync(&dispc
.pdev
->dev
);
536 WARN_ON(r
< 0 && r
!= -ENOSYS
);
538 EXPORT_SYMBOL(dispc_runtime_put
);
540 u32
dispc_mgr_get_vsync_irq(enum omap_channel channel
)
542 return mgr_desc
[channel
].vsync_irq
;
544 EXPORT_SYMBOL(dispc_mgr_get_vsync_irq
);
546 u32
dispc_mgr_get_framedone_irq(enum omap_channel channel
)
548 if (channel
== OMAP_DSS_CHANNEL_DIGIT
&& dispc
.feat
->no_framedone_tv
)
551 return mgr_desc
[channel
].framedone_irq
;
553 EXPORT_SYMBOL(dispc_mgr_get_framedone_irq
);
555 u32
dispc_mgr_get_sync_lost_irq(enum omap_channel channel
)
557 return mgr_desc
[channel
].sync_lost_irq
;
559 EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq
);
561 bool dispc_mgr_go_busy(enum omap_channel channel
)
563 return mgr_fld_read(channel
, DISPC_MGR_FLD_GO
) == 1;
565 EXPORT_SYMBOL(dispc_mgr_go_busy
);
567 void dispc_mgr_go(enum omap_channel channel
)
569 WARN_ON(!dispc_mgr_is_enabled(channel
));
570 WARN_ON(dispc_mgr_go_busy(channel
));
572 DSSDBG("GO %s\n", mgr_desc
[channel
].name
);
574 mgr_fld_write(channel
, DISPC_MGR_FLD_GO
, 1);
576 EXPORT_SYMBOL(dispc_mgr_go
);
578 static void dispc_ovl_write_firh_reg(enum omap_plane plane
, int reg
, u32 value
)
580 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane
, reg
), value
);
583 static void dispc_ovl_write_firhv_reg(enum omap_plane plane
, int reg
, u32 value
)
585 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane
, reg
), value
);
588 static void dispc_ovl_write_firv_reg(enum omap_plane plane
, int reg
, u32 value
)
590 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane
, reg
), value
);
593 static void dispc_ovl_write_firh2_reg(enum omap_plane plane
, int reg
, u32 value
)
595 BUG_ON(plane
== OMAP_DSS_GFX
);
597 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane
, reg
), value
);
600 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane
, int reg
,
603 BUG_ON(plane
== OMAP_DSS_GFX
);
605 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane
, reg
), value
);
608 static void dispc_ovl_write_firv2_reg(enum omap_plane plane
, int reg
, u32 value
)
610 BUG_ON(plane
== OMAP_DSS_GFX
);
612 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane
, reg
), value
);
615 static void dispc_ovl_set_scale_coef(enum omap_plane plane
, int fir_hinc
,
616 int fir_vinc
, int five_taps
,
617 enum omap_color_component color_comp
)
619 const struct dispc_coef
*h_coef
, *v_coef
;
622 h_coef
= dispc_ovl_get_scale_coef(fir_hinc
, true);
623 v_coef
= dispc_ovl_get_scale_coef(fir_vinc
, five_taps
);
625 for (i
= 0; i
< 8; i
++) {
628 h
= FLD_VAL(h_coef
[i
].hc0_vc00
, 7, 0)
629 | FLD_VAL(h_coef
[i
].hc1_vc0
, 15, 8)
630 | FLD_VAL(h_coef
[i
].hc2_vc1
, 23, 16)
631 | FLD_VAL(h_coef
[i
].hc3_vc2
, 31, 24);
632 hv
= FLD_VAL(h_coef
[i
].hc4_vc22
, 7, 0)
633 | FLD_VAL(v_coef
[i
].hc1_vc0
, 15, 8)
634 | FLD_VAL(v_coef
[i
].hc2_vc1
, 23, 16)
635 | FLD_VAL(v_coef
[i
].hc3_vc2
, 31, 24);
637 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
) {
638 dispc_ovl_write_firh_reg(plane
, i
, h
);
639 dispc_ovl_write_firhv_reg(plane
, i
, hv
);
641 dispc_ovl_write_firh2_reg(plane
, i
, h
);
642 dispc_ovl_write_firhv2_reg(plane
, i
, hv
);
648 for (i
= 0; i
< 8; i
++) {
650 v
= FLD_VAL(v_coef
[i
].hc0_vc00
, 7, 0)
651 | FLD_VAL(v_coef
[i
].hc4_vc22
, 15, 8);
652 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
)
653 dispc_ovl_write_firv_reg(plane
, i
, v
);
655 dispc_ovl_write_firv2_reg(plane
, i
, v
);
661 static void dispc_ovl_write_color_conv_coef(enum omap_plane plane
,
662 const struct color_conv_coef
*ct
)
664 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
666 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 0), CVAL(ct
->rcr
, ct
->ry
));
667 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 1), CVAL(ct
->gy
, ct
->rcb
));
668 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 2), CVAL(ct
->gcb
, ct
->gcr
));
669 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 3), CVAL(ct
->bcr
, ct
->by
));
670 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 4), CVAL(0, ct
->bcb
));
672 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), ct
->full_range
, 11, 11);
677 static void dispc_setup_color_conv_coef(void)
680 int num_ovl
= dss_feat_get_num_ovls();
681 const struct color_conv_coef ctbl_bt601_5_ovl
= {
683 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
685 const struct color_conv_coef ctbl_bt601_5_wb
= {
687 66, 129, 25, 112, -94, -18, -38, -74, 112, 0,
690 for (i
= 1; i
< num_ovl
; i
++)
691 dispc_ovl_write_color_conv_coef(i
, &ctbl_bt601_5_ovl
);
693 if (dispc
.feat
->has_writeback
)
694 dispc_ovl_write_color_conv_coef(OMAP_DSS_WB
, &ctbl_bt601_5_wb
);
697 static void dispc_ovl_set_ba0(enum omap_plane plane
, u32 paddr
)
699 dispc_write_reg(DISPC_OVL_BA0(plane
), paddr
);
702 static void dispc_ovl_set_ba1(enum omap_plane plane
, u32 paddr
)
704 dispc_write_reg(DISPC_OVL_BA1(plane
), paddr
);
707 static void dispc_ovl_set_ba0_uv(enum omap_plane plane
, u32 paddr
)
709 dispc_write_reg(DISPC_OVL_BA0_UV(plane
), paddr
);
712 static void dispc_ovl_set_ba1_uv(enum omap_plane plane
, u32 paddr
)
714 dispc_write_reg(DISPC_OVL_BA1_UV(plane
), paddr
);
717 static void dispc_ovl_set_pos(enum omap_plane plane
,
718 enum omap_overlay_caps caps
, int x
, int y
)
722 if ((caps
& OMAP_DSS_OVL_CAP_POS
) == 0)
725 val
= FLD_VAL(y
, 26, 16) | FLD_VAL(x
, 10, 0);
727 dispc_write_reg(DISPC_OVL_POSITION(plane
), val
);
730 static void dispc_ovl_set_input_size(enum omap_plane plane
, int width
,
733 u32 val
= FLD_VAL(height
- 1, 26, 16) | FLD_VAL(width
- 1, 10, 0);
735 if (plane
== OMAP_DSS_GFX
|| plane
== OMAP_DSS_WB
)
736 dispc_write_reg(DISPC_OVL_SIZE(plane
), val
);
738 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane
), val
);
741 static void dispc_ovl_set_output_size(enum omap_plane plane
, int width
,
746 BUG_ON(plane
== OMAP_DSS_GFX
);
748 val
= FLD_VAL(height
- 1, 26, 16) | FLD_VAL(width
- 1, 10, 0);
750 if (plane
== OMAP_DSS_WB
)
751 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane
), val
);
753 dispc_write_reg(DISPC_OVL_SIZE(plane
), val
);
756 static void dispc_ovl_set_zorder(enum omap_plane plane
,
757 enum omap_overlay_caps caps
, u8 zorder
)
759 if ((caps
& OMAP_DSS_OVL_CAP_ZORDER
) == 0)
762 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), zorder
, 27, 26);
765 static void dispc_ovl_enable_zorder_planes(void)
769 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
772 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++)
773 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i
), 1, 25, 25);
776 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane
,
777 enum omap_overlay_caps caps
, bool enable
)
779 if ((caps
& OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
) == 0)
782 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
? 1 : 0, 28, 28);
785 static void dispc_ovl_setup_global_alpha(enum omap_plane plane
,
786 enum omap_overlay_caps caps
, u8 global_alpha
)
788 static const unsigned shifts
[] = { 0, 8, 16, 24, };
791 if ((caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
794 shift
= shifts
[plane
];
795 REG_FLD_MOD(DISPC_GLOBAL_ALPHA
, global_alpha
, shift
+ 7, shift
);
798 static void dispc_ovl_set_pix_inc(enum omap_plane plane
, s32 inc
)
800 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane
), inc
);
803 static void dispc_ovl_set_row_inc(enum omap_plane plane
, s32 inc
)
805 dispc_write_reg(DISPC_OVL_ROW_INC(plane
), inc
);
808 static void dispc_ovl_set_color_mode(enum omap_plane plane
,
809 enum omap_color_mode color_mode
)
812 if (plane
!= OMAP_DSS_GFX
) {
813 switch (color_mode
) {
814 case OMAP_DSS_COLOR_NV12
:
816 case OMAP_DSS_COLOR_RGBX16
:
818 case OMAP_DSS_COLOR_RGBA16
:
820 case OMAP_DSS_COLOR_RGB12U
:
822 case OMAP_DSS_COLOR_ARGB16
:
824 case OMAP_DSS_COLOR_RGB16
:
826 case OMAP_DSS_COLOR_ARGB16_1555
:
828 case OMAP_DSS_COLOR_RGB24U
:
830 case OMAP_DSS_COLOR_RGB24P
:
832 case OMAP_DSS_COLOR_YUV2
:
834 case OMAP_DSS_COLOR_UYVY
:
836 case OMAP_DSS_COLOR_ARGB32
:
838 case OMAP_DSS_COLOR_RGBA32
:
840 case OMAP_DSS_COLOR_RGBX32
:
842 case OMAP_DSS_COLOR_XRGB16_1555
:
848 switch (color_mode
) {
849 case OMAP_DSS_COLOR_CLUT1
:
851 case OMAP_DSS_COLOR_CLUT2
:
853 case OMAP_DSS_COLOR_CLUT4
:
855 case OMAP_DSS_COLOR_CLUT8
:
857 case OMAP_DSS_COLOR_RGB12U
:
859 case OMAP_DSS_COLOR_ARGB16
:
861 case OMAP_DSS_COLOR_RGB16
:
863 case OMAP_DSS_COLOR_ARGB16_1555
:
865 case OMAP_DSS_COLOR_RGB24U
:
867 case OMAP_DSS_COLOR_RGB24P
:
869 case OMAP_DSS_COLOR_RGBX16
:
871 case OMAP_DSS_COLOR_RGBA16
:
873 case OMAP_DSS_COLOR_ARGB32
:
875 case OMAP_DSS_COLOR_RGBA32
:
877 case OMAP_DSS_COLOR_RGBX32
:
879 case OMAP_DSS_COLOR_XRGB16_1555
:
886 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), m
, 4, 1);
889 static void dispc_ovl_configure_burst_type(enum omap_plane plane
,
890 enum omap_dss_rotation_type rotation_type
)
892 if (!dss_has_feature(FEAT_BURST_2D
))
895 if (rotation_type
== OMAP_DSS_ROT_TILER
)
896 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), 1, 29, 29);
898 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), 0, 29, 29);
901 void dispc_ovl_set_channel_out(enum omap_plane plane
, enum omap_channel channel
)
905 int chan
= 0, chan2
= 0;
911 case OMAP_DSS_VIDEO1
:
912 case OMAP_DSS_VIDEO2
:
913 case OMAP_DSS_VIDEO3
:
921 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
922 if (dss_has_feature(FEAT_MGR_LCD2
)) {
924 case OMAP_DSS_CHANNEL_LCD
:
928 case OMAP_DSS_CHANNEL_DIGIT
:
932 case OMAP_DSS_CHANNEL_LCD2
:
936 case OMAP_DSS_CHANNEL_LCD3
:
937 if (dss_has_feature(FEAT_MGR_LCD3
)) {
945 case OMAP_DSS_CHANNEL_WB
:
954 val
= FLD_MOD(val
, chan
, shift
, shift
);
955 val
= FLD_MOD(val
, chan2
, 31, 30);
957 val
= FLD_MOD(val
, channel
, shift
, shift
);
959 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), val
);
961 EXPORT_SYMBOL(dispc_ovl_set_channel_out
);
963 static enum omap_channel
dispc_ovl_get_channel_out(enum omap_plane plane
)
972 case OMAP_DSS_VIDEO1
:
973 case OMAP_DSS_VIDEO2
:
974 case OMAP_DSS_VIDEO3
:
982 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
984 if (FLD_GET(val
, shift
, shift
) == 1)
985 return OMAP_DSS_CHANNEL_DIGIT
;
987 if (!dss_has_feature(FEAT_MGR_LCD2
))
988 return OMAP_DSS_CHANNEL_LCD
;
990 switch (FLD_GET(val
, 31, 30)) {
993 return OMAP_DSS_CHANNEL_LCD
;
995 return OMAP_DSS_CHANNEL_LCD2
;
997 return OMAP_DSS_CHANNEL_LCD3
;
999 return OMAP_DSS_CHANNEL_WB
;
1003 static void dispc_ovl_set_burst_size(enum omap_plane plane
,
1004 enum omap_burst_size burst_size
)
1006 static const unsigned shifts
[] = { 6, 14, 14, 14, 14, };
1009 shift
= shifts
[plane
];
1010 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), burst_size
, shift
+ 1, shift
);
1013 static void dispc_configure_burst_sizes(void)
1016 const int burst_size
= BURST_SIZE_X8
;
1018 /* Configure burst size always to maximum size */
1019 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
)
1020 dispc_ovl_set_burst_size(i
, burst_size
);
1021 if (dispc
.feat
->has_writeback
)
1022 dispc_ovl_set_burst_size(OMAP_DSS_WB
, burst_size
);
1025 static u32
dispc_ovl_get_burst_size(enum omap_plane plane
)
1027 unsigned unit
= dss_feat_get_burst_size_unit();
1028 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1032 void dispc_enable_gamma_table(bool enable
)
1035 * This is partially implemented to support only disabling of
1039 DSSWARN("Gamma table enabling for TV not yet supported");
1043 REG_FLD_MOD(DISPC_CONFIG
, enable
, 9, 9);
1046 static void dispc_mgr_enable_cpr(enum omap_channel channel
, bool enable
)
1048 if (channel
== OMAP_DSS_CHANNEL_DIGIT
)
1051 mgr_fld_write(channel
, DISPC_MGR_FLD_CPR
, enable
);
1054 static void dispc_mgr_set_cpr_coef(enum omap_channel channel
,
1055 const struct omap_dss_cpr_coefs
*coefs
)
1057 u32 coef_r
, coef_g
, coef_b
;
1059 if (!dss_mgr_is_lcd(channel
))
1062 coef_r
= FLD_VAL(coefs
->rr
, 31, 22) | FLD_VAL(coefs
->rg
, 20, 11) |
1063 FLD_VAL(coefs
->rb
, 9, 0);
1064 coef_g
= FLD_VAL(coefs
->gr
, 31, 22) | FLD_VAL(coefs
->gg
, 20, 11) |
1065 FLD_VAL(coefs
->gb
, 9, 0);
1066 coef_b
= FLD_VAL(coefs
->br
, 31, 22) | FLD_VAL(coefs
->bg
, 20, 11) |
1067 FLD_VAL(coefs
->bb
, 9, 0);
1069 dispc_write_reg(DISPC_CPR_COEF_R(channel
), coef_r
);
1070 dispc_write_reg(DISPC_CPR_COEF_G(channel
), coef_g
);
1071 dispc_write_reg(DISPC_CPR_COEF_B(channel
), coef_b
);
1074 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane
, bool enable
)
1078 BUG_ON(plane
== OMAP_DSS_GFX
);
1080 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1081 val
= FLD_MOD(val
, enable
, 9, 9);
1082 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), val
);
1085 static void dispc_ovl_enable_replication(enum omap_plane plane
,
1086 enum omap_overlay_caps caps
, bool enable
)
1088 static const unsigned shifts
[] = { 5, 10, 10, 10 };
1091 if ((caps
& OMAP_DSS_OVL_CAP_REPLICATION
) == 0)
1094 shift
= shifts
[plane
];
1095 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
, shift
, shift
);
1098 static void dispc_mgr_set_size(enum omap_channel channel
, u16 width
,
1103 val
= FLD_VAL(height
- 1, dispc
.feat
->mgr_height_start
, 16) |
1104 FLD_VAL(width
- 1, dispc
.feat
->mgr_width_start
, 0);
1106 dispc_write_reg(DISPC_SIZE_MGR(channel
), val
);
1109 static void dispc_init_fifos(void)
1117 unit
= dss_feat_get_buffer_size_unit();
1119 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE
, &start
, &end
);
1121 for (fifo
= 0; fifo
< dispc
.feat
->num_fifos
; ++fifo
) {
1122 size
= REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo
), start
, end
);
1124 dispc
.fifo_size
[fifo
] = size
;
1127 * By default fifos are mapped directly to overlays, fifo 0 to
1128 * ovl 0, fifo 1 to ovl 1, etc.
1130 dispc
.fifo_assignment
[fifo
] = fifo
;
1134 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1135 * causes problems with certain use cases, like using the tiler in 2D
1136 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1137 * giving GFX plane a larger fifo. WB but should work fine with a
1140 if (dispc
.feat
->gfx_fifo_workaround
) {
1143 v
= dispc_read_reg(DISPC_GLOBAL_BUFFER
);
1145 v
= FLD_MOD(v
, 4, 2, 0); /* GFX BUF top to WB */
1146 v
= FLD_MOD(v
, 4, 5, 3); /* GFX BUF bottom to WB */
1147 v
= FLD_MOD(v
, 0, 26, 24); /* WB BUF top to GFX */
1148 v
= FLD_MOD(v
, 0, 29, 27); /* WB BUF bottom to GFX */
1150 dispc_write_reg(DISPC_GLOBAL_BUFFER
, v
);
1152 dispc
.fifo_assignment
[OMAP_DSS_GFX
] = OMAP_DSS_WB
;
1153 dispc
.fifo_assignment
[OMAP_DSS_WB
] = OMAP_DSS_GFX
;
1157 * Setup default fifo thresholds.
1159 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
) {
1161 const bool use_fifomerge
= false;
1162 const bool manual_update
= false;
1164 dispc_ovl_compute_fifo_thresholds(i
, &low
, &high
,
1165 use_fifomerge
, manual_update
);
1167 dispc_ovl_set_fifo_threshold(i
, low
, high
);
1170 if (dispc
.feat
->has_writeback
) {
1172 const bool use_fifomerge
= false;
1173 const bool manual_update
= false;
1175 dispc_ovl_compute_fifo_thresholds(OMAP_DSS_WB
, &low
, &high
,
1176 use_fifomerge
, manual_update
);
1178 dispc_ovl_set_fifo_threshold(OMAP_DSS_WB
, low
, high
);
1182 static u32
dispc_ovl_get_fifo_size(enum omap_plane plane
)
1187 for (fifo
= 0; fifo
< dispc
.feat
->num_fifos
; ++fifo
) {
1188 if (dispc
.fifo_assignment
[fifo
] == plane
)
1189 size
+= dispc
.fifo_size
[fifo
];
1195 void dispc_ovl_set_fifo_threshold(enum omap_plane plane
, u32 low
, u32 high
)
1197 u8 hi_start
, hi_end
, lo_start
, lo_end
;
1200 unit
= dss_feat_get_buffer_size_unit();
1202 WARN_ON(low
% unit
!= 0);
1203 WARN_ON(high
% unit
!= 0);
1208 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD
, &hi_start
, &hi_end
);
1209 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD
, &lo_start
, &lo_end
);
1211 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1213 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane
),
1214 lo_start
, lo_end
) * unit
,
1215 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane
),
1216 hi_start
, hi_end
) * unit
,
1217 low
* unit
, high
* unit
);
1219 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane
),
1220 FLD_VAL(high
, hi_start
, hi_end
) |
1221 FLD_VAL(low
, lo_start
, lo_end
));
1224 * configure the preload to the pipeline's high threhold, if HT it's too
1225 * large for the preload field, set the threshold to the maximum value
1226 * that can be held by the preload register
1228 if (dss_has_feature(FEAT_PRELOAD
) && dispc
.feat
->set_max_preload
&&
1229 plane
!= OMAP_DSS_WB
)
1230 dispc_write_reg(DISPC_OVL_PRELOAD(plane
), min(high
, 0xfffu
));
1233 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane
,
1234 u32
*fifo_low
, u32
*fifo_high
, bool use_fifomerge
,
1238 * All sizes are in bytes. Both the buffer and burst are made of
1239 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1242 unsigned buf_unit
= dss_feat_get_buffer_size_unit();
1243 unsigned ovl_fifo_size
, total_fifo_size
, burst_size
;
1246 burst_size
= dispc_ovl_get_burst_size(plane
);
1247 ovl_fifo_size
= dispc_ovl_get_fifo_size(plane
);
1249 if (use_fifomerge
) {
1250 total_fifo_size
= 0;
1251 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
)
1252 total_fifo_size
+= dispc_ovl_get_fifo_size(i
);
1254 total_fifo_size
= ovl_fifo_size
;
1258 * We use the same low threshold for both fifomerge and non-fifomerge
1259 * cases, but for fifomerge we calculate the high threshold using the
1260 * combined fifo size
1263 if (manual_update
&& dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG
)) {
1264 *fifo_low
= ovl_fifo_size
- burst_size
* 2;
1265 *fifo_high
= total_fifo_size
- burst_size
;
1266 } else if (plane
== OMAP_DSS_WB
) {
1268 * Most optimal configuration for writeback is to push out data
1269 * to the interconnect the moment writeback pushes enough pixels
1270 * in the FIFO to form a burst
1273 *fifo_high
= burst_size
;
1275 *fifo_low
= ovl_fifo_size
- burst_size
;
1276 *fifo_high
= total_fifo_size
- buf_unit
;
1280 static void dispc_ovl_set_mflag(enum omap_plane plane
, bool enable
)
1284 if (plane
== OMAP_DSS_GFX
)
1289 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
, bit
, bit
);
1292 static void dispc_ovl_set_mflag_threshold(enum omap_plane plane
,
1295 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane
),
1296 FLD_VAL(high
, 31, 16) | FLD_VAL(low
, 15, 0));
1299 static void dispc_init_mflag(void)
1304 * HACK: NV12 color format and MFLAG seem to have problems working
1305 * together: using two displays, and having an NV12 overlay on one of
1306 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1307 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1308 * remove the errors, but there doesn't seem to be a clear logic on
1309 * which values work and which not.
1311 * As a work-around, set force MFLAG to always on.
1313 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE
,
1314 (1 << 0) | /* MFLAG_CTRL = force always on */
1315 (0 << 2)); /* MFLAG_START = disable */
1317 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
) {
1318 u32 size
= dispc_ovl_get_fifo_size(i
);
1319 u32 unit
= dss_feat_get_buffer_size_unit();
1322 dispc_ovl_set_mflag(i
, true);
1325 * Simulation team suggests below thesholds:
1326 * HT = fifosize * 5 / 8;
1327 * LT = fifosize * 4 / 8;
1330 low
= size
* 4 / 8 / unit
;
1331 high
= size
* 5 / 8 / unit
;
1333 dispc_ovl_set_mflag_threshold(i
, low
, high
);
1336 if (dispc
.feat
->has_writeback
) {
1337 u32 size
= dispc_ovl_get_fifo_size(OMAP_DSS_WB
);
1338 u32 unit
= dss_feat_get_buffer_size_unit();
1341 dispc_ovl_set_mflag(OMAP_DSS_WB
, true);
1344 * Simulation team suggests below thesholds:
1345 * HT = fifosize * 5 / 8;
1346 * LT = fifosize * 4 / 8;
1349 low
= size
* 4 / 8 / unit
;
1350 high
= size
* 5 / 8 / unit
;
1352 dispc_ovl_set_mflag_threshold(OMAP_DSS_WB
, low
, high
);
1356 static void dispc_ovl_set_fir(enum omap_plane plane
,
1358 enum omap_color_component color_comp
)
1362 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
) {
1363 u8 hinc_start
, hinc_end
, vinc_start
, vinc_end
;
1365 dss_feat_get_reg_field(FEAT_REG_FIRHINC
,
1366 &hinc_start
, &hinc_end
);
1367 dss_feat_get_reg_field(FEAT_REG_FIRVINC
,
1368 &vinc_start
, &vinc_end
);
1369 val
= FLD_VAL(vinc
, vinc_start
, vinc_end
) |
1370 FLD_VAL(hinc
, hinc_start
, hinc_end
);
1372 dispc_write_reg(DISPC_OVL_FIR(plane
), val
);
1374 val
= FLD_VAL(vinc
, 28, 16) | FLD_VAL(hinc
, 12, 0);
1375 dispc_write_reg(DISPC_OVL_FIR2(plane
), val
);
1379 static void dispc_ovl_set_vid_accu0(enum omap_plane plane
, int haccu
, int vaccu
)
1382 u8 hor_start
, hor_end
, vert_start
, vert_end
;
1384 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU
, &hor_start
, &hor_end
);
1385 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU
, &vert_start
, &vert_end
);
1387 val
= FLD_VAL(vaccu
, vert_start
, vert_end
) |
1388 FLD_VAL(haccu
, hor_start
, hor_end
);
1390 dispc_write_reg(DISPC_OVL_ACCU0(plane
), val
);
1393 static void dispc_ovl_set_vid_accu1(enum omap_plane plane
, int haccu
, int vaccu
)
1396 u8 hor_start
, hor_end
, vert_start
, vert_end
;
1398 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU
, &hor_start
, &hor_end
);
1399 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU
, &vert_start
, &vert_end
);
1401 val
= FLD_VAL(vaccu
, vert_start
, vert_end
) |
1402 FLD_VAL(haccu
, hor_start
, hor_end
);
1404 dispc_write_reg(DISPC_OVL_ACCU1(plane
), val
);
1407 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane
, int haccu
,
1412 val
= FLD_VAL(vaccu
, 26, 16) | FLD_VAL(haccu
, 10, 0);
1413 dispc_write_reg(DISPC_OVL_ACCU2_0(plane
), val
);
1416 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane
, int haccu
,
1421 val
= FLD_VAL(vaccu
, 26, 16) | FLD_VAL(haccu
, 10, 0);
1422 dispc_write_reg(DISPC_OVL_ACCU2_1(plane
), val
);
1425 static void dispc_ovl_set_scale_param(enum omap_plane plane
,
1426 u16 orig_width
, u16 orig_height
,
1427 u16 out_width
, u16 out_height
,
1428 bool five_taps
, u8 rotation
,
1429 enum omap_color_component color_comp
)
1431 int fir_hinc
, fir_vinc
;
1433 fir_hinc
= 1024 * orig_width
/ out_width
;
1434 fir_vinc
= 1024 * orig_height
/ out_height
;
1436 dispc_ovl_set_scale_coef(plane
, fir_hinc
, fir_vinc
, five_taps
,
1438 dispc_ovl_set_fir(plane
, fir_hinc
, fir_vinc
, color_comp
);
1441 static void dispc_ovl_set_accu_uv(enum omap_plane plane
,
1442 u16 orig_width
, u16 orig_height
, u16 out_width
, u16 out_height
,
1443 bool ilace
, enum omap_color_mode color_mode
, u8 rotation
)
1445 int h_accu2_0
, h_accu2_1
;
1446 int v_accu2_0
, v_accu2_1
;
1447 int chroma_hinc
, chroma_vinc
;
1457 const struct accu
*accu_table
;
1458 const struct accu
*accu_val
;
1460 static const struct accu accu_nv12
[4] = {
1461 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1462 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1463 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1464 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1467 static const struct accu accu_nv12_ilace
[4] = {
1468 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1469 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1470 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1471 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1474 static const struct accu accu_yuv
[4] = {
1475 { 0, 1, 0, 1, 0, 1, 0, 1 },
1476 { 0, 1, 0, 1, 0, 1, 0, 1 },
1477 { -1, 1, 0, 1, 0, 1, 0, 1 },
1478 { 0, 1, 0, 1, -1, 1, 0, 1 },
1482 case OMAP_DSS_ROT_0
:
1485 case OMAP_DSS_ROT_90
:
1488 case OMAP_DSS_ROT_180
:
1491 case OMAP_DSS_ROT_270
:
1499 switch (color_mode
) {
1500 case OMAP_DSS_COLOR_NV12
:
1502 accu_table
= accu_nv12_ilace
;
1504 accu_table
= accu_nv12
;
1506 case OMAP_DSS_COLOR_YUV2
:
1507 case OMAP_DSS_COLOR_UYVY
:
1508 accu_table
= accu_yuv
;
1515 accu_val
= &accu_table
[idx
];
1517 chroma_hinc
= 1024 * orig_width
/ out_width
;
1518 chroma_vinc
= 1024 * orig_height
/ out_height
;
1520 h_accu2_0
= (accu_val
->h0_m
* chroma_hinc
/ accu_val
->h0_n
) % 1024;
1521 h_accu2_1
= (accu_val
->h1_m
* chroma_hinc
/ accu_val
->h1_n
) % 1024;
1522 v_accu2_0
= (accu_val
->v0_m
* chroma_vinc
/ accu_val
->v0_n
) % 1024;
1523 v_accu2_1
= (accu_val
->v1_m
* chroma_vinc
/ accu_val
->v1_n
) % 1024;
1525 dispc_ovl_set_vid_accu2_0(plane
, h_accu2_0
, v_accu2_0
);
1526 dispc_ovl_set_vid_accu2_1(plane
, h_accu2_1
, v_accu2_1
);
1529 static void dispc_ovl_set_scaling_common(enum omap_plane plane
,
1530 u16 orig_width
, u16 orig_height
,
1531 u16 out_width
, u16 out_height
,
1532 bool ilace
, bool five_taps
,
1533 bool fieldmode
, enum omap_color_mode color_mode
,
1540 dispc_ovl_set_scale_param(plane
, orig_width
, orig_height
,
1541 out_width
, out_height
, five_taps
,
1542 rotation
, DISPC_COLOR_COMPONENT_RGB_Y
);
1543 l
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1545 /* RESIZEENABLE and VERTICALTAPS */
1546 l
&= ~((0x3 << 5) | (0x1 << 21));
1547 l
|= (orig_width
!= out_width
) ? (1 << 5) : 0;
1548 l
|= (orig_height
!= out_height
) ? (1 << 6) : 0;
1549 l
|= five_taps
? (1 << 21) : 0;
1551 /* VRESIZECONF and HRESIZECONF */
1552 if (dss_has_feature(FEAT_RESIZECONF
)) {
1554 l
|= (orig_width
<= out_width
) ? 0 : (1 << 7);
1555 l
|= (orig_height
<= out_height
) ? 0 : (1 << 8);
1558 /* LINEBUFFERSPLIT */
1559 if (dss_has_feature(FEAT_LINEBUFFERSPLIT
)) {
1561 l
|= five_taps
? (1 << 22) : 0;
1564 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), l
);
1567 * field 0 = even field = bottom field
1568 * field 1 = odd field = top field
1570 if (ilace
&& !fieldmode
) {
1572 accu0
= ((1024 * orig_height
/ out_height
) / 2) & 0x3ff;
1573 if (accu0
>= 1024/2) {
1579 dispc_ovl_set_vid_accu0(plane
, 0, accu0
);
1580 dispc_ovl_set_vid_accu1(plane
, 0, accu1
);
1583 static void dispc_ovl_set_scaling_uv(enum omap_plane plane
,
1584 u16 orig_width
, u16 orig_height
,
1585 u16 out_width
, u16 out_height
,
1586 bool ilace
, bool five_taps
,
1587 bool fieldmode
, enum omap_color_mode color_mode
,
1590 int scale_x
= out_width
!= orig_width
;
1591 int scale_y
= out_height
!= orig_height
;
1592 bool chroma_upscale
= plane
!= OMAP_DSS_WB
;
1594 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE
))
1596 if ((color_mode
!= OMAP_DSS_COLOR_YUV2
&&
1597 color_mode
!= OMAP_DSS_COLOR_UYVY
&&
1598 color_mode
!= OMAP_DSS_COLOR_NV12
)) {
1599 /* reset chroma resampling for RGB formats */
1600 if (plane
!= OMAP_DSS_WB
)
1601 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
), 0, 8, 8);
1605 dispc_ovl_set_accu_uv(plane
, orig_width
, orig_height
, out_width
,
1606 out_height
, ilace
, color_mode
, rotation
);
1608 switch (color_mode
) {
1609 case OMAP_DSS_COLOR_NV12
:
1610 if (chroma_upscale
) {
1611 /* UV is subsampled by 2 horizontally and vertically */
1615 /* UV is downsampled by 2 horizontally and vertically */
1621 case OMAP_DSS_COLOR_YUV2
:
1622 case OMAP_DSS_COLOR_UYVY
:
1623 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
1624 if (rotation
== OMAP_DSS_ROT_0
||
1625 rotation
== OMAP_DSS_ROT_180
) {
1627 /* UV is subsampled by 2 horizontally */
1630 /* UV is downsampled by 2 horizontally */
1634 /* must use FIR for YUV422 if rotated */
1635 if (rotation
!= OMAP_DSS_ROT_0
)
1636 scale_x
= scale_y
= true;
1644 if (out_width
!= orig_width
)
1646 if (out_height
!= orig_height
)
1649 dispc_ovl_set_scale_param(plane
, orig_width
, orig_height
,
1650 out_width
, out_height
, five_taps
,
1651 rotation
, DISPC_COLOR_COMPONENT_UV
);
1653 if (plane
!= OMAP_DSS_WB
)
1654 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
),
1655 (scale_x
|| scale_y
) ? 1 : 0, 8, 8);
1658 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), scale_x
? 1 : 0, 5, 5);
1660 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), scale_y
? 1 : 0, 6, 6);
1663 static void dispc_ovl_set_scaling(enum omap_plane plane
,
1664 u16 orig_width
, u16 orig_height
,
1665 u16 out_width
, u16 out_height
,
1666 bool ilace
, bool five_taps
,
1667 bool fieldmode
, enum omap_color_mode color_mode
,
1670 BUG_ON(plane
== OMAP_DSS_GFX
);
1672 dispc_ovl_set_scaling_common(plane
,
1673 orig_width
, orig_height
,
1674 out_width
, out_height
,
1676 fieldmode
, color_mode
,
1679 dispc_ovl_set_scaling_uv(plane
,
1680 orig_width
, orig_height
,
1681 out_width
, out_height
,
1683 fieldmode
, color_mode
,
1687 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane
, u8 rotation
,
1688 enum omap_dss_rotation_type rotation_type
,
1689 bool mirroring
, enum omap_color_mode color_mode
)
1691 bool row_repeat
= false;
1694 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1695 color_mode
== OMAP_DSS_COLOR_UYVY
) {
1699 case OMAP_DSS_ROT_0
:
1702 case OMAP_DSS_ROT_90
:
1705 case OMAP_DSS_ROT_180
:
1708 case OMAP_DSS_ROT_270
:
1714 case OMAP_DSS_ROT_0
:
1717 case OMAP_DSS_ROT_90
:
1720 case OMAP_DSS_ROT_180
:
1723 case OMAP_DSS_ROT_270
:
1729 if (rotation
== OMAP_DSS_ROT_90
|| rotation
== OMAP_DSS_ROT_270
)
1736 * OMAP4/5 Errata i631:
1737 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1738 * rows beyond the framebuffer, which may cause OCP error.
1740 if (color_mode
== OMAP_DSS_COLOR_NV12
&&
1741 rotation_type
!= OMAP_DSS_ROT_TILER
)
1744 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), vidrot
, 13, 12);
1745 if (dss_has_feature(FEAT_ROWREPEATENABLE
))
1746 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
),
1747 row_repeat
? 1 : 0, 18, 18);
1749 if (color_mode
== OMAP_DSS_COLOR_NV12
) {
1750 bool doublestride
= (rotation_type
== OMAP_DSS_ROT_TILER
) &&
1751 (rotation
== OMAP_DSS_ROT_0
||
1752 rotation
== OMAP_DSS_ROT_180
);
1754 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), doublestride
, 22, 22);
1759 static int color_mode_to_bpp(enum omap_color_mode color_mode
)
1761 switch (color_mode
) {
1762 case OMAP_DSS_COLOR_CLUT1
:
1764 case OMAP_DSS_COLOR_CLUT2
:
1766 case OMAP_DSS_COLOR_CLUT4
:
1768 case OMAP_DSS_COLOR_CLUT8
:
1769 case OMAP_DSS_COLOR_NV12
:
1771 case OMAP_DSS_COLOR_RGB12U
:
1772 case OMAP_DSS_COLOR_RGB16
:
1773 case OMAP_DSS_COLOR_ARGB16
:
1774 case OMAP_DSS_COLOR_YUV2
:
1775 case OMAP_DSS_COLOR_UYVY
:
1776 case OMAP_DSS_COLOR_RGBA16
:
1777 case OMAP_DSS_COLOR_RGBX16
:
1778 case OMAP_DSS_COLOR_ARGB16_1555
:
1779 case OMAP_DSS_COLOR_XRGB16_1555
:
1781 case OMAP_DSS_COLOR_RGB24P
:
1783 case OMAP_DSS_COLOR_RGB24U
:
1784 case OMAP_DSS_COLOR_ARGB32
:
1785 case OMAP_DSS_COLOR_RGBA32
:
1786 case OMAP_DSS_COLOR_RGBX32
:
1794 static s32
pixinc(int pixels
, u8 ps
)
1798 else if (pixels
> 1)
1799 return 1 + (pixels
- 1) * ps
;
1800 else if (pixels
< 0)
1801 return 1 - (-pixels
+ 1) * ps
;
1807 static void calc_vrfb_rotation_offset(u8 rotation
, bool mirror
,
1809 u16 width
, u16 height
,
1810 enum omap_color_mode color_mode
, bool fieldmode
,
1811 unsigned int field_offset
,
1812 unsigned *offset0
, unsigned *offset1
,
1813 s32
*row_inc
, s32
*pix_inc
, int x_predecim
, int y_predecim
)
1817 /* FIXME CLUT formats */
1818 switch (color_mode
) {
1819 case OMAP_DSS_COLOR_CLUT1
:
1820 case OMAP_DSS_COLOR_CLUT2
:
1821 case OMAP_DSS_COLOR_CLUT4
:
1822 case OMAP_DSS_COLOR_CLUT8
:
1825 case OMAP_DSS_COLOR_YUV2
:
1826 case OMAP_DSS_COLOR_UYVY
:
1830 ps
= color_mode_to_bpp(color_mode
) / 8;
1834 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation
, screen_width
,
1838 * field 0 = even field = bottom field
1839 * field 1 = odd field = top field
1841 switch (rotation
+ mirror
* 4) {
1842 case OMAP_DSS_ROT_0
:
1843 case OMAP_DSS_ROT_180
:
1845 * If the pixel format is YUV or UYVY divide the width
1846 * of the image by 2 for 0 and 180 degree rotation.
1848 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1849 color_mode
== OMAP_DSS_COLOR_UYVY
)
1852 case OMAP_DSS_ROT_90
:
1853 case OMAP_DSS_ROT_270
:
1856 *offset0
= field_offset
* screen_width
* ps
;
1860 *row_inc
= pixinc(1 +
1861 (y_predecim
* screen_width
- x_predecim
* width
) +
1862 (fieldmode
? screen_width
: 0), ps
);
1863 *pix_inc
= pixinc(x_predecim
, ps
);
1866 case OMAP_DSS_ROT_0
+ 4:
1867 case OMAP_DSS_ROT_180
+ 4:
1868 /* If the pixel format is YUV or UYVY divide the width
1869 * of the image by 2 for 0 degree and 180 degree
1871 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1872 color_mode
== OMAP_DSS_COLOR_UYVY
)
1875 case OMAP_DSS_ROT_90
+ 4:
1876 case OMAP_DSS_ROT_270
+ 4:
1879 *offset0
= field_offset
* screen_width
* ps
;
1882 *row_inc
= pixinc(1 -
1883 (y_predecim
* screen_width
+ x_predecim
* width
) -
1884 (fieldmode
? screen_width
: 0), ps
);
1885 *pix_inc
= pixinc(x_predecim
, ps
);
1894 static void calc_dma_rotation_offset(u8 rotation
, bool mirror
,
1896 u16 width
, u16 height
,
1897 enum omap_color_mode color_mode
, bool fieldmode
,
1898 unsigned int field_offset
,
1899 unsigned *offset0
, unsigned *offset1
,
1900 s32
*row_inc
, s32
*pix_inc
, int x_predecim
, int y_predecim
)
1905 /* FIXME CLUT formats */
1906 switch (color_mode
) {
1907 case OMAP_DSS_COLOR_CLUT1
:
1908 case OMAP_DSS_COLOR_CLUT2
:
1909 case OMAP_DSS_COLOR_CLUT4
:
1910 case OMAP_DSS_COLOR_CLUT8
:
1914 ps
= color_mode_to_bpp(color_mode
) / 8;
1918 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation
, screen_width
,
1921 /* width & height are overlay sizes, convert to fb sizes */
1923 if (rotation
== OMAP_DSS_ROT_0
|| rotation
== OMAP_DSS_ROT_180
) {
1932 * field 0 = even field = bottom field
1933 * field 1 = odd field = top field
1935 switch (rotation
+ mirror
* 4) {
1936 case OMAP_DSS_ROT_0
:
1939 *offset0
= *offset1
+ field_offset
* screen_width
* ps
;
1941 *offset0
= *offset1
;
1942 *row_inc
= pixinc(1 +
1943 (y_predecim
* screen_width
- fbw
* x_predecim
) +
1944 (fieldmode
? screen_width
: 0), ps
);
1945 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1946 color_mode
== OMAP_DSS_COLOR_UYVY
)
1947 *pix_inc
= pixinc(x_predecim
, 2 * ps
);
1949 *pix_inc
= pixinc(x_predecim
, ps
);
1951 case OMAP_DSS_ROT_90
:
1952 *offset1
= screen_width
* (fbh
- 1) * ps
;
1954 *offset0
= *offset1
+ field_offset
* ps
;
1956 *offset0
= *offset1
;
1957 *row_inc
= pixinc(screen_width
* (fbh
* x_predecim
- 1) +
1958 y_predecim
+ (fieldmode
? 1 : 0), ps
);
1959 *pix_inc
= pixinc(-x_predecim
* screen_width
, ps
);
1961 case OMAP_DSS_ROT_180
:
1962 *offset1
= (screen_width
* (fbh
- 1) + fbw
- 1) * ps
;
1964 *offset0
= *offset1
- field_offset
* screen_width
* ps
;
1966 *offset0
= *offset1
;
1967 *row_inc
= pixinc(-1 -
1968 (y_predecim
* screen_width
- fbw
* x_predecim
) -
1969 (fieldmode
? screen_width
: 0), ps
);
1970 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1971 color_mode
== OMAP_DSS_COLOR_UYVY
)
1972 *pix_inc
= pixinc(-x_predecim
, 2 * ps
);
1974 *pix_inc
= pixinc(-x_predecim
, ps
);
1976 case OMAP_DSS_ROT_270
:
1977 *offset1
= (fbw
- 1) * ps
;
1979 *offset0
= *offset1
- field_offset
* ps
;
1981 *offset0
= *offset1
;
1982 *row_inc
= pixinc(-screen_width
* (fbh
* x_predecim
- 1) -
1983 y_predecim
- (fieldmode
? 1 : 0), ps
);
1984 *pix_inc
= pixinc(x_predecim
* screen_width
, ps
);
1988 case OMAP_DSS_ROT_0
+ 4:
1989 *offset1
= (fbw
- 1) * ps
;
1991 *offset0
= *offset1
+ field_offset
* screen_width
* ps
;
1993 *offset0
= *offset1
;
1994 *row_inc
= pixinc(y_predecim
* screen_width
* 2 - 1 +
1995 (fieldmode
? screen_width
: 0),
1997 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1998 color_mode
== OMAP_DSS_COLOR_UYVY
)
1999 *pix_inc
= pixinc(-x_predecim
, 2 * ps
);
2001 *pix_inc
= pixinc(-x_predecim
, ps
);
2004 case OMAP_DSS_ROT_90
+ 4:
2007 *offset0
= *offset1
+ field_offset
* ps
;
2009 *offset0
= *offset1
;
2010 *row_inc
= pixinc(-screen_width
* (fbh
* x_predecim
- 1) +
2011 y_predecim
+ (fieldmode
? 1 : 0),
2013 *pix_inc
= pixinc(x_predecim
* screen_width
, ps
);
2016 case OMAP_DSS_ROT_180
+ 4:
2017 *offset1
= screen_width
* (fbh
- 1) * ps
;
2019 *offset0
= *offset1
- field_offset
* screen_width
* ps
;
2021 *offset0
= *offset1
;
2022 *row_inc
= pixinc(1 - y_predecim
* screen_width
* 2 -
2023 (fieldmode
? screen_width
: 0),
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
);
2032 case OMAP_DSS_ROT_270
+ 4:
2033 *offset1
= (screen_width
* (fbh
- 1) + fbw
- 1) * ps
;
2035 *offset0
= *offset1
- field_offset
* ps
;
2037 *offset0
= *offset1
;
2038 *row_inc
= pixinc(screen_width
* (fbh
* x_predecim
- 1) -
2039 y_predecim
- (fieldmode
? 1 : 0),
2041 *pix_inc
= pixinc(-x_predecim
* screen_width
, ps
);
2050 static void calc_tiler_rotation_offset(u16 screen_width
, u16 width
,
2051 enum omap_color_mode color_mode
, bool fieldmode
,
2052 unsigned int field_offset
, unsigned *offset0
, unsigned *offset1
,
2053 s32
*row_inc
, s32
*pix_inc
, int x_predecim
, int y_predecim
)
2057 switch (color_mode
) {
2058 case OMAP_DSS_COLOR_CLUT1
:
2059 case OMAP_DSS_COLOR_CLUT2
:
2060 case OMAP_DSS_COLOR_CLUT4
:
2061 case OMAP_DSS_COLOR_CLUT8
:
2065 ps
= color_mode_to_bpp(color_mode
) / 8;
2069 DSSDBG("scrw %d, width %d\n", screen_width
, width
);
2072 * field 0 = even field = bottom field
2073 * field 1 = odd field = top field
2077 *offset0
= *offset1
+ field_offset
* screen_width
* ps
;
2079 *offset0
= *offset1
;
2080 *row_inc
= pixinc(1 + (y_predecim
* screen_width
- width
* x_predecim
) +
2081 (fieldmode
? screen_width
: 0), ps
);
2082 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
2083 color_mode
== OMAP_DSS_COLOR_UYVY
)
2084 *pix_inc
= pixinc(x_predecim
, 2 * ps
);
2086 *pix_inc
= pixinc(x_predecim
, ps
);
2090 * This function is used to avoid synclosts in OMAP3, because of some
2091 * undocumented horizontal position and timing related limitations.
2093 static int check_horiz_timing_omap3(unsigned long pclk
, unsigned long lclk
,
2094 const struct omap_video_timings
*t
, u16 pos_x
,
2095 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2098 const int ds
= DIV_ROUND_UP(height
, out_height
);
2099 unsigned long nonactive
;
2100 static const u8 limits
[3] = { 8, 10, 20 };
2104 nonactive
= t
->x_res
+ t
->hfp
+ t
->hsw
+ t
->hbp
- out_width
;
2107 if (out_height
< height
)
2109 if (out_width
< width
)
2111 blank
= div_u64((u64
)(t
->hbp
+ t
->hsw
+ t
->hfp
) * lclk
, pclk
);
2112 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank
, limits
[i
]);
2113 if (blank
<= limits
[i
])
2116 /* FIXME add checks for 3-tap filter once the limitations are known */
2121 * Pixel data should be prepared before visible display point starts.
2122 * So, atleast DS-2 lines must have already been fetched by DISPC
2123 * during nonactive - pos_x period.
2125 val
= div_u64((u64
)(nonactive
- pos_x
) * lclk
, pclk
);
2126 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2127 val
, max(0, ds
- 2) * width
);
2128 if (val
< max(0, ds
- 2) * width
)
2132 * All lines need to be refilled during the nonactive period of which
2133 * only one line can be loaded during the active period. So, atleast
2134 * DS - 1 lines should be loaded during nonactive period.
2136 val
= div_u64((u64
)nonactive
* lclk
, pclk
);
2137 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2138 val
, max(0, ds
- 1) * width
);
2139 if (val
< max(0, ds
- 1) * width
)
2145 static unsigned long calc_core_clk_five_taps(unsigned long pclk
,
2146 const struct omap_video_timings
*mgr_timings
, u16 width
,
2147 u16 height
, u16 out_width
, u16 out_height
,
2148 enum omap_color_mode color_mode
)
2153 if (height
<= out_height
&& width
<= out_width
)
2154 return (unsigned long) pclk
;
2156 if (height
> out_height
) {
2157 unsigned int ppl
= mgr_timings
->x_res
;
2159 tmp
= (u64
)pclk
* height
* out_width
;
2160 do_div(tmp
, 2 * out_height
* ppl
);
2163 if (height
> 2 * out_height
) {
2164 if (ppl
== out_width
)
2167 tmp
= (u64
)pclk
* (height
- 2 * out_height
) * out_width
;
2168 do_div(tmp
, 2 * out_height
* (ppl
- out_width
));
2169 core_clk
= max_t(u32
, core_clk
, tmp
);
2173 if (width
> out_width
) {
2174 tmp
= (u64
)pclk
* width
;
2175 do_div(tmp
, out_width
);
2176 core_clk
= max_t(u32
, core_clk
, tmp
);
2178 if (color_mode
== OMAP_DSS_COLOR_RGB24U
)
2185 static unsigned long calc_core_clk_24xx(unsigned long pclk
, u16 width
,
2186 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2188 if (height
> out_height
&& width
> out_width
)
2194 static unsigned long calc_core_clk_34xx(unsigned long pclk
, u16 width
,
2195 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2197 unsigned int hf
, vf
;
2200 * FIXME how to determine the 'A' factor
2201 * for the no downscaling case ?
2204 if (width
> 3 * out_width
)
2206 else if (width
> 2 * out_width
)
2208 else if (width
> out_width
)
2212 if (height
> out_height
)
2217 return pclk
* vf
* hf
;
2220 static unsigned long calc_core_clk_44xx(unsigned long pclk
, u16 width
,
2221 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2224 * If the overlay/writeback is in mem to mem mode, there are no
2225 * downscaling limitations with respect to pixel clock, return 1 as
2226 * required core clock to represent that we have sufficient enough
2227 * core clock to do maximum downscaling
2232 if (width
> out_width
)
2233 return DIV_ROUND_UP(pclk
, out_width
) * width
;
2238 static int dispc_ovl_calc_scaling_24xx(unsigned long pclk
, unsigned long lclk
,
2239 const struct omap_video_timings
*mgr_timings
,
2240 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2241 enum omap_color_mode color_mode
, bool *five_taps
,
2242 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2243 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2246 u16 in_width
, in_height
;
2247 int min_factor
= min(*decim_x
, *decim_y
);
2248 const int maxsinglelinewidth
=
2249 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH
);
2254 in_height
= height
/ *decim_y
;
2255 in_width
= width
/ *decim_x
;
2256 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
,
2257 in_height
, out_width
, out_height
, mem_to_mem
);
2258 error
= (in_width
> maxsinglelinewidth
|| !*core_clk
||
2259 *core_clk
> dispc_core_clk_rate());
2261 if (*decim_x
== *decim_y
) {
2262 *decim_x
= min_factor
;
2265 swap(*decim_x
, *decim_y
);
2266 if (*decim_x
< *decim_y
)
2270 } while (*decim_x
<= *x_predecim
&& *decim_y
<= *y_predecim
&& error
);
2273 DSSERR("failed to find scaling settings\n");
2277 if (in_width
> maxsinglelinewidth
) {
2278 DSSERR("Cannot scale max input width exceeded");
2284 static int dispc_ovl_calc_scaling_34xx(unsigned long pclk
, unsigned long lclk
,
2285 const struct omap_video_timings
*mgr_timings
,
2286 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2287 enum omap_color_mode color_mode
, bool *five_taps
,
2288 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2289 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2292 u16 in_width
, in_height
;
2293 const int maxsinglelinewidth
=
2294 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH
);
2297 in_height
= height
/ *decim_y
;
2298 in_width
= width
/ *decim_x
;
2299 *five_taps
= in_height
> out_height
;
2301 if (in_width
> maxsinglelinewidth
)
2302 if (in_height
> out_height
&&
2303 in_height
< out_height
* 2)
2307 *core_clk
= calc_core_clk_five_taps(pclk
, mgr_timings
,
2308 in_width
, in_height
, out_width
,
2309 out_height
, color_mode
);
2311 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
,
2312 in_height
, out_width
, out_height
,
2315 error
= check_horiz_timing_omap3(pclk
, lclk
, mgr_timings
,
2316 pos_x
, in_width
, in_height
, out_width
,
2317 out_height
, *five_taps
);
2318 if (error
&& *five_taps
) {
2323 error
= (error
|| in_width
> maxsinglelinewidth
* 2 ||
2324 (in_width
> maxsinglelinewidth
&& *five_taps
) ||
2325 !*core_clk
|| *core_clk
> dispc_core_clk_rate());
2328 /* verify that we're inside the limits of scaler */
2329 if (in_width
/ 4 > out_width
)
2333 if (in_height
/ 4 > out_height
)
2336 if (in_height
/ 2 > out_height
)
2343 } while (*decim_x
<= *x_predecim
&& *decim_y
<= *y_predecim
&& error
);
2346 DSSERR("failed to find scaling settings\n");
2350 if (check_horiz_timing_omap3(pclk
, lclk
, mgr_timings
, pos_x
, in_width
,
2351 in_height
, out_width
, out_height
, *five_taps
)) {
2352 DSSERR("horizontal timing too tight\n");
2356 if (in_width
> (maxsinglelinewidth
* 2)) {
2357 DSSERR("Cannot setup scaling");
2358 DSSERR("width exceeds maximum width possible");
2362 if (in_width
> maxsinglelinewidth
&& *five_taps
) {
2363 DSSERR("cannot setup scaling with five taps");
2369 static int dispc_ovl_calc_scaling_44xx(unsigned long pclk
, unsigned long lclk
,
2370 const struct omap_video_timings
*mgr_timings
,
2371 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2372 enum omap_color_mode color_mode
, bool *five_taps
,
2373 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2374 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2376 u16 in_width
, in_width_max
;
2377 int decim_x_min
= *decim_x
;
2378 u16 in_height
= height
/ *decim_y
;
2379 const int maxsinglelinewidth
=
2380 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH
);
2381 const int maxdownscale
= dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE
);
2384 in_width_max
= out_width
* maxdownscale
;
2386 in_width_max
= dispc_core_clk_rate() /
2387 DIV_ROUND_UP(pclk
, out_width
);
2390 *decim_x
= DIV_ROUND_UP(width
, in_width_max
);
2392 *decim_x
= *decim_x
> decim_x_min
? *decim_x
: decim_x_min
;
2393 if (*decim_x
> *x_predecim
)
2397 in_width
= width
/ *decim_x
;
2398 } while (*decim_x
<= *x_predecim
&&
2399 in_width
> maxsinglelinewidth
&& ++*decim_x
);
2401 if (in_width
> maxsinglelinewidth
) {
2402 DSSERR("Cannot scale width exceeds max line width");
2406 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
, in_height
,
2407 out_width
, out_height
, mem_to_mem
);
2411 #define DIV_FRAC(dividend, divisor) \
2412 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2414 static int dispc_ovl_calc_scaling(unsigned long pclk
, unsigned long lclk
,
2415 enum omap_overlay_caps caps
,
2416 const struct omap_video_timings
*mgr_timings
,
2417 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2418 enum omap_color_mode color_mode
, bool *five_taps
,
2419 int *x_predecim
, int *y_predecim
, u16 pos_x
,
2420 enum omap_dss_rotation_type rotation_type
, bool mem_to_mem
)
2422 const int maxdownscale
= dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE
);
2423 const int max_decim_limit
= 16;
2424 unsigned long core_clk
= 0;
2425 int decim_x
, decim_y
, ret
;
2427 if (width
== out_width
&& height
== out_height
)
2430 if (!mem_to_mem
&& (pclk
== 0 || mgr_timings
->pixelclock
== 0)) {
2431 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2435 if ((caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0)
2439 *x_predecim
= *y_predecim
= 1;
2441 *x_predecim
= max_decim_limit
;
2442 *y_predecim
= (rotation_type
== OMAP_DSS_ROT_TILER
&&
2443 dss_has_feature(FEAT_BURST_2D
)) ?
2444 2 : max_decim_limit
;
2447 if (color_mode
== OMAP_DSS_COLOR_CLUT1
||
2448 color_mode
== OMAP_DSS_COLOR_CLUT2
||
2449 color_mode
== OMAP_DSS_COLOR_CLUT4
||
2450 color_mode
== OMAP_DSS_COLOR_CLUT8
) {
2457 decim_x
= DIV_ROUND_UP(DIV_ROUND_UP(width
, out_width
), maxdownscale
);
2458 decim_y
= DIV_ROUND_UP(DIV_ROUND_UP(height
, out_height
), maxdownscale
);
2460 if (decim_x
> *x_predecim
|| out_width
> width
* 8)
2463 if (decim_y
> *y_predecim
|| out_height
> height
* 8)
2466 ret
= dispc
.feat
->calc_scaling(pclk
, lclk
, mgr_timings
, width
, height
,
2467 out_width
, out_height
, color_mode
, five_taps
,
2468 x_predecim
, y_predecim
, &decim_x
, &decim_y
, pos_x
, &core_clk
,
2473 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",
2475 out_width
, out_height
,
2476 out_width
/ width
, DIV_FRAC(out_width
, width
),
2477 out_height
/ height
, DIV_FRAC(out_height
, height
),
2480 width
/ decim_x
, height
/ decim_y
,
2481 out_width
/ (width
/ decim_x
), DIV_FRAC(out_width
, width
/ decim_x
),
2482 out_height
/ (height
/ decim_y
), DIV_FRAC(out_height
, height
/ decim_y
),
2485 core_clk
, dispc_core_clk_rate());
2487 if (!core_clk
|| core_clk
> dispc_core_clk_rate()) {
2488 DSSERR("failed to set up scaling, "
2489 "required core clk rate = %lu Hz, "
2490 "current core clk rate = %lu Hz\n",
2491 core_clk
, dispc_core_clk_rate());
2495 *x_predecim
= decim_x
;
2496 *y_predecim
= decim_y
;
2500 int dispc_ovl_check(enum omap_plane plane
, enum omap_channel channel
,
2501 const struct omap_overlay_info
*oi
,
2502 const struct omap_video_timings
*timings
,
2503 int *x_predecim
, int *y_predecim
)
2505 enum omap_overlay_caps caps
= dss_feat_get_overlay_caps(plane
);
2506 bool five_taps
= true;
2507 bool fieldmode
= false;
2508 u16 in_height
= oi
->height
;
2509 u16 in_width
= oi
->width
;
2510 bool ilace
= timings
->interlace
;
2511 u16 out_width
, out_height
;
2512 int pos_x
= oi
->pos_x
;
2513 unsigned long pclk
= dispc_mgr_pclk_rate(channel
);
2514 unsigned long lclk
= dispc_mgr_lclk_rate(channel
);
2516 out_width
= oi
->out_width
== 0 ? oi
->width
: oi
->out_width
;
2517 out_height
= oi
->out_height
== 0 ? oi
->height
: oi
->out_height
;
2519 if (ilace
&& oi
->height
== out_height
)
2527 DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2528 in_height
, out_height
);
2531 if (!dss_feat_color_mode_supported(plane
, oi
->color_mode
))
2534 return dispc_ovl_calc_scaling(pclk
, lclk
, caps
, timings
, in_width
,
2535 in_height
, out_width
, out_height
, oi
->color_mode
,
2536 &five_taps
, x_predecim
, y_predecim
, pos_x
,
2537 oi
->rotation_type
, false);
2539 EXPORT_SYMBOL(dispc_ovl_check
);
2541 static int dispc_ovl_setup_common(enum omap_plane plane
,
2542 enum omap_overlay_caps caps
, u32 paddr
, u32 p_uv_addr
,
2543 u16 screen_width
, int pos_x
, int pos_y
, u16 width
, u16 height
,
2544 u16 out_width
, u16 out_height
, enum omap_color_mode color_mode
,
2545 u8 rotation
, bool mirror
, u8 zorder
, u8 pre_mult_alpha
,
2546 u8 global_alpha
, enum omap_dss_rotation_type rotation_type
,
2547 bool replication
, const struct omap_video_timings
*mgr_timings
,
2550 bool five_taps
= true;
2551 bool fieldmode
= false;
2553 unsigned offset0
, offset1
;
2556 u16 frame_width
, frame_height
;
2557 unsigned int field_offset
= 0;
2558 u16 in_height
= height
;
2559 u16 in_width
= width
;
2560 int x_predecim
= 1, y_predecim
= 1;
2561 bool ilace
= mgr_timings
->interlace
;
2562 unsigned long pclk
= dispc_plane_pclk_rate(plane
);
2563 unsigned long lclk
= dispc_plane_lclk_rate(plane
);
2565 if (paddr
== 0 && rotation_type
!= OMAP_DSS_ROT_TILER
)
2568 switch (color_mode
) {
2569 case OMAP_DSS_COLOR_YUV2
:
2570 case OMAP_DSS_COLOR_UYVY
:
2571 case OMAP_DSS_COLOR_NV12
:
2573 DSSERR("input width %d is not even for YUV format\n",
2583 out_width
= out_width
== 0 ? width
: out_width
;
2584 out_height
= out_height
== 0 ? height
: out_height
;
2586 if (ilace
&& height
== out_height
)
2595 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2596 "out_height %d\n", in_height
, pos_y
,
2600 if (!dss_feat_color_mode_supported(plane
, color_mode
))
2603 r
= dispc_ovl_calc_scaling(pclk
, lclk
, caps
, mgr_timings
, in_width
,
2604 in_height
, out_width
, out_height
, color_mode
,
2605 &five_taps
, &x_predecim
, &y_predecim
, pos_x
,
2606 rotation_type
, mem_to_mem
);
2610 in_width
= in_width
/ x_predecim
;
2611 in_height
= in_height
/ y_predecim
;
2613 if (x_predecim
> 1 || y_predecim
> 1)
2614 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2615 x_predecim
, y_predecim
, in_width
, in_height
);
2617 switch (color_mode
) {
2618 case OMAP_DSS_COLOR_YUV2
:
2619 case OMAP_DSS_COLOR_UYVY
:
2620 case OMAP_DSS_COLOR_NV12
:
2622 DSSDBG("predecimated input width is not even for YUV format\n");
2623 DSSDBG("adjusting input width %d -> %d\n",
2624 in_width
, in_width
& ~1);
2634 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
2635 color_mode
== OMAP_DSS_COLOR_UYVY
||
2636 color_mode
== OMAP_DSS_COLOR_NV12
)
2639 if (ilace
&& !fieldmode
) {
2641 * when downscaling the bottom field may have to start several
2642 * source lines below the top field. Unfortunately ACCUI
2643 * registers will only hold the fractional part of the offset
2644 * so the integer part must be added to the base address of the
2647 if (!in_height
|| in_height
== out_height
)
2650 field_offset
= in_height
/ out_height
/ 2;
2653 /* Fields are independent but interleaved in memory. */
2662 if (plane
== OMAP_DSS_WB
) {
2663 frame_width
= out_width
;
2664 frame_height
= out_height
;
2666 frame_width
= in_width
;
2667 frame_height
= height
;
2670 if (rotation_type
== OMAP_DSS_ROT_TILER
)
2671 calc_tiler_rotation_offset(screen_width
, frame_width
,
2672 color_mode
, fieldmode
, field_offset
,
2673 &offset0
, &offset1
, &row_inc
, &pix_inc
,
2674 x_predecim
, y_predecim
);
2675 else if (rotation_type
== OMAP_DSS_ROT_DMA
)
2676 calc_dma_rotation_offset(rotation
, mirror
, screen_width
,
2677 frame_width
, frame_height
,
2678 color_mode
, fieldmode
, field_offset
,
2679 &offset0
, &offset1
, &row_inc
, &pix_inc
,
2680 x_predecim
, y_predecim
);
2682 calc_vrfb_rotation_offset(rotation
, mirror
,
2683 screen_width
, frame_width
, frame_height
,
2684 color_mode
, fieldmode
, field_offset
,
2685 &offset0
, &offset1
, &row_inc
, &pix_inc
,
2686 x_predecim
, y_predecim
);
2688 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2689 offset0
, offset1
, row_inc
, pix_inc
);
2691 dispc_ovl_set_color_mode(plane
, color_mode
);
2693 dispc_ovl_configure_burst_type(plane
, rotation_type
);
2695 dispc_ovl_set_ba0(plane
, paddr
+ offset0
);
2696 dispc_ovl_set_ba1(plane
, paddr
+ offset1
);
2698 if (OMAP_DSS_COLOR_NV12
== color_mode
) {
2699 dispc_ovl_set_ba0_uv(plane
, p_uv_addr
+ offset0
);
2700 dispc_ovl_set_ba1_uv(plane
, p_uv_addr
+ offset1
);
2703 if (dispc
.feat
->last_pixel_inc_missing
)
2704 row_inc
+= pix_inc
- 1;
2706 dispc_ovl_set_row_inc(plane
, row_inc
);
2707 dispc_ovl_set_pix_inc(plane
, pix_inc
);
2709 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x
, pos_y
, in_width
,
2710 in_height
, out_width
, out_height
);
2712 dispc_ovl_set_pos(plane
, caps
, pos_x
, pos_y
);
2714 dispc_ovl_set_input_size(plane
, in_width
, in_height
);
2716 if (caps
& OMAP_DSS_OVL_CAP_SCALE
) {
2717 dispc_ovl_set_scaling(plane
, in_width
, in_height
, out_width
,
2718 out_height
, ilace
, five_taps
, fieldmode
,
2719 color_mode
, rotation
);
2720 dispc_ovl_set_output_size(plane
, out_width
, out_height
);
2721 dispc_ovl_set_vid_color_conv(plane
, cconv
);
2724 dispc_ovl_set_rotation_attrs(plane
, rotation
, rotation_type
, mirror
,
2727 dispc_ovl_set_zorder(plane
, caps
, zorder
);
2728 dispc_ovl_set_pre_mult_alpha(plane
, caps
, pre_mult_alpha
);
2729 dispc_ovl_setup_global_alpha(plane
, caps
, global_alpha
);
2731 dispc_ovl_enable_replication(plane
, caps
, replication
);
2736 int dispc_ovl_setup(enum omap_plane plane
, const struct omap_overlay_info
*oi
,
2737 bool replication
, const struct omap_video_timings
*mgr_timings
,
2741 enum omap_overlay_caps caps
= dss_feat_get_overlay_caps(plane
);
2742 enum omap_channel channel
;
2744 channel
= dispc_ovl_get_channel_out(plane
);
2746 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2747 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2748 plane
, &oi
->paddr
, &oi
->p_uv_addr
, oi
->screen_width
, oi
->pos_x
,
2749 oi
->pos_y
, oi
->width
, oi
->height
, oi
->out_width
, oi
->out_height
,
2750 oi
->color_mode
, oi
->rotation
, oi
->mirror
, channel
, replication
);
2752 r
= dispc_ovl_setup_common(plane
, caps
, oi
->paddr
, oi
->p_uv_addr
,
2753 oi
->screen_width
, oi
->pos_x
, oi
->pos_y
, oi
->width
, oi
->height
,
2754 oi
->out_width
, oi
->out_height
, oi
->color_mode
, oi
->rotation
,
2755 oi
->mirror
, oi
->zorder
, oi
->pre_mult_alpha
, oi
->global_alpha
,
2756 oi
->rotation_type
, replication
, mgr_timings
, mem_to_mem
);
2760 EXPORT_SYMBOL(dispc_ovl_setup
);
2762 int dispc_ovl_enable(enum omap_plane plane
, bool enable
)
2764 DSSDBG("dispc_enable_plane %d, %d\n", plane
, enable
);
2766 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
? 1 : 0, 0, 0);
2770 EXPORT_SYMBOL(dispc_ovl_enable
);
2772 bool dispc_ovl_enabled(enum omap_plane plane
)
2774 return REG_GET(DISPC_OVL_ATTRIBUTES(plane
), 0, 0);
2776 EXPORT_SYMBOL(dispc_ovl_enabled
);
2778 void dispc_mgr_enable(enum omap_channel channel
, bool enable
)
2780 mgr_fld_write(channel
, DISPC_MGR_FLD_ENABLE
, enable
);
2781 /* flush posted write */
2782 mgr_fld_read(channel
, DISPC_MGR_FLD_ENABLE
);
2784 EXPORT_SYMBOL(dispc_mgr_enable
);
2786 bool dispc_mgr_is_enabled(enum omap_channel channel
)
2788 return !!mgr_fld_read(channel
, DISPC_MGR_FLD_ENABLE
);
2790 EXPORT_SYMBOL(dispc_mgr_is_enabled
);
2792 static void dispc_lcd_enable_signal_polarity(bool act_high
)
2794 if (!dss_has_feature(FEAT_LCDENABLEPOL
))
2797 REG_FLD_MOD(DISPC_CONTROL
, act_high
? 1 : 0, 29, 29);
2800 void dispc_lcd_enable_signal(bool enable
)
2802 if (!dss_has_feature(FEAT_LCDENABLESIGNAL
))
2805 REG_FLD_MOD(DISPC_CONTROL
, enable
? 1 : 0, 28, 28);
2808 void dispc_pck_free_enable(bool enable
)
2810 if (!dss_has_feature(FEAT_PCKFREEENABLE
))
2813 REG_FLD_MOD(DISPC_CONTROL
, enable
? 1 : 0, 27, 27);
2816 static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel
, bool enable
)
2818 mgr_fld_write(channel
, DISPC_MGR_FLD_FIFOHANDCHECK
, enable
);
2822 static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel
)
2824 mgr_fld_write(channel
, DISPC_MGR_FLD_STNTFT
, 1);
2827 static void dispc_set_loadmode(enum omap_dss_load_mode mode
)
2829 REG_FLD_MOD(DISPC_CONFIG
, mode
, 2, 1);
2833 static void dispc_mgr_set_default_color(enum omap_channel channel
, u32 color
)
2835 dispc_write_reg(DISPC_DEFAULT_COLOR(channel
), color
);
2838 static void dispc_mgr_set_trans_key(enum omap_channel ch
,
2839 enum omap_dss_trans_key_type type
,
2842 mgr_fld_write(ch
, DISPC_MGR_FLD_TCKSELECTION
, type
);
2844 dispc_write_reg(DISPC_TRANS_COLOR(ch
), trans_key
);
2847 static void dispc_mgr_enable_trans_key(enum omap_channel ch
, bool enable
)
2849 mgr_fld_write(ch
, DISPC_MGR_FLD_TCKENABLE
, enable
);
2852 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch
,
2855 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
2858 if (ch
== OMAP_DSS_CHANNEL_LCD
)
2859 REG_FLD_MOD(DISPC_CONFIG
, enable
, 18, 18);
2860 else if (ch
== OMAP_DSS_CHANNEL_DIGIT
)
2861 REG_FLD_MOD(DISPC_CONFIG
, enable
, 19, 19);
2864 void dispc_mgr_setup(enum omap_channel channel
,
2865 const struct omap_overlay_manager_info
*info
)
2867 dispc_mgr_set_default_color(channel
, info
->default_color
);
2868 dispc_mgr_set_trans_key(channel
, info
->trans_key_type
, info
->trans_key
);
2869 dispc_mgr_enable_trans_key(channel
, info
->trans_enabled
);
2870 dispc_mgr_enable_alpha_fixed_zorder(channel
,
2871 info
->partial_alpha_enabled
);
2872 if (dss_has_feature(FEAT_CPR
)) {
2873 dispc_mgr_enable_cpr(channel
, info
->cpr_enable
);
2874 dispc_mgr_set_cpr_coef(channel
, &info
->cpr_coefs
);
2877 EXPORT_SYMBOL(dispc_mgr_setup
);
2879 static void dispc_mgr_set_tft_data_lines(enum omap_channel channel
, u8 data_lines
)
2883 switch (data_lines
) {
2901 mgr_fld_write(channel
, DISPC_MGR_FLD_TFTDATALINES
, code
);
2904 static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode
)
2910 case DSS_IO_PAD_MODE_RESET
:
2914 case DSS_IO_PAD_MODE_RFBI
:
2918 case DSS_IO_PAD_MODE_BYPASS
:
2927 l
= dispc_read_reg(DISPC_CONTROL
);
2928 l
= FLD_MOD(l
, gpout0
, 15, 15);
2929 l
= FLD_MOD(l
, gpout1
, 16, 16);
2930 dispc_write_reg(DISPC_CONTROL
, l
);
2933 static void dispc_mgr_enable_stallmode(enum omap_channel channel
, bool enable
)
2935 mgr_fld_write(channel
, DISPC_MGR_FLD_STALLMODE
, enable
);
2938 void dispc_mgr_set_lcd_config(enum omap_channel channel
,
2939 const struct dss_lcd_mgr_config
*config
)
2941 dispc_mgr_set_io_pad_mode(config
->io_pad_mode
);
2943 dispc_mgr_enable_stallmode(channel
, config
->stallmode
);
2944 dispc_mgr_enable_fifohandcheck(channel
, config
->fifohandcheck
);
2946 dispc_mgr_set_clock_div(channel
, &config
->clock_info
);
2948 dispc_mgr_set_tft_data_lines(channel
, config
->video_port_width
);
2950 dispc_lcd_enable_signal_polarity(config
->lcden_sig_polarity
);
2952 dispc_mgr_set_lcd_type_tft(channel
);
2954 EXPORT_SYMBOL(dispc_mgr_set_lcd_config
);
2956 static bool _dispc_mgr_size_ok(u16 width
, u16 height
)
2958 return width
<= dispc
.feat
->mgr_width_max
&&
2959 height
<= dispc
.feat
->mgr_height_max
;
2962 static bool _dispc_lcd_timings_ok(int hsw
, int hfp
, int hbp
,
2963 int vsw
, int vfp
, int vbp
)
2965 if (hsw
< 1 || hsw
> dispc
.feat
->sw_max
||
2966 hfp
< 1 || hfp
> dispc
.feat
->hp_max
||
2967 hbp
< 1 || hbp
> dispc
.feat
->hp_max
||
2968 vsw
< 1 || vsw
> dispc
.feat
->sw_max
||
2969 vfp
< 0 || vfp
> dispc
.feat
->vp_max
||
2970 vbp
< 0 || vbp
> dispc
.feat
->vp_max
)
2975 static bool _dispc_mgr_pclk_ok(enum omap_channel channel
,
2978 if (dss_mgr_is_lcd(channel
))
2979 return pclk
<= dispc
.feat
->max_lcd_pclk
;
2981 return pclk
<= dispc
.feat
->max_tv_pclk
;
2984 bool dispc_mgr_timings_ok(enum omap_channel channel
,
2985 const struct omap_video_timings
*timings
)
2987 if (!_dispc_mgr_size_ok(timings
->x_res
, timings
->y_res
))
2990 if (!_dispc_mgr_pclk_ok(channel
, timings
->pixelclock
))
2993 if (dss_mgr_is_lcd(channel
)) {
2994 /* TODO: OMAP4+ supports interlace for LCD outputs */
2995 if (timings
->interlace
)
2998 if (!_dispc_lcd_timings_ok(timings
->hsw
, timings
->hfp
,
2999 timings
->hbp
, timings
->vsw
, timings
->vfp
,
3007 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel
, int hsw
,
3008 int hfp
, int hbp
, int vsw
, int vfp
, int vbp
,
3009 enum omap_dss_signal_level vsync_level
,
3010 enum omap_dss_signal_level hsync_level
,
3011 enum omap_dss_signal_edge data_pclk_edge
,
3012 enum omap_dss_signal_level de_level
,
3013 enum omap_dss_signal_edge sync_pclk_edge
)
3016 u32 timing_h
, timing_v
, l
;
3017 bool onoff
, rf
, ipc
, vs
, hs
, de
;
3019 timing_h
= FLD_VAL(hsw
-1, dispc
.feat
->sw_start
, 0) |
3020 FLD_VAL(hfp
-1, dispc
.feat
->fp_start
, 8) |
3021 FLD_VAL(hbp
-1, dispc
.feat
->bp_start
, 20);
3022 timing_v
= FLD_VAL(vsw
-1, dispc
.feat
->sw_start
, 0) |
3023 FLD_VAL(vfp
, dispc
.feat
->fp_start
, 8) |
3024 FLD_VAL(vbp
, dispc
.feat
->bp_start
, 20);
3026 dispc_write_reg(DISPC_TIMING_H(channel
), timing_h
);
3027 dispc_write_reg(DISPC_TIMING_V(channel
), timing_v
);
3029 switch (vsync_level
) {
3030 case OMAPDSS_SIG_ACTIVE_LOW
:
3033 case OMAPDSS_SIG_ACTIVE_HIGH
:
3040 switch (hsync_level
) {
3041 case OMAPDSS_SIG_ACTIVE_LOW
:
3044 case OMAPDSS_SIG_ACTIVE_HIGH
:
3052 case OMAPDSS_SIG_ACTIVE_LOW
:
3055 case OMAPDSS_SIG_ACTIVE_HIGH
:
3062 switch (data_pclk_edge
) {
3063 case OMAPDSS_DRIVE_SIG_RISING_EDGE
:
3066 case OMAPDSS_DRIVE_SIG_FALLING_EDGE
:
3073 /* always use the 'rf' setting */
3076 switch (sync_pclk_edge
) {
3077 case OMAPDSS_DRIVE_SIG_FALLING_EDGE
:
3080 case OMAPDSS_DRIVE_SIG_RISING_EDGE
:
3087 l
= FLD_VAL(onoff
, 17, 17) |
3088 FLD_VAL(rf
, 16, 16) |
3089 FLD_VAL(de
, 15, 15) |
3090 FLD_VAL(ipc
, 14, 14) |
3091 FLD_VAL(hs
, 13, 13) |
3092 FLD_VAL(vs
, 12, 12);
3094 /* always set ALIGN bit when available */
3095 if (dispc
.feat
->supports_sync_align
)
3098 dispc_write_reg(DISPC_POL_FREQ(channel
), l
);
3100 if (dispc
.syscon_pol
) {
3101 const int shifts
[] = {
3102 [OMAP_DSS_CHANNEL_LCD
] = 0,
3103 [OMAP_DSS_CHANNEL_LCD2
] = 1,
3104 [OMAP_DSS_CHANNEL_LCD3
] = 2,
3109 mask
= (1 << 0) | (1 << 3) | (1 << 6);
3110 val
= (rf
<< 0) | (ipc
<< 3) | (onoff
<< 6);
3112 mask
<<= 16 + shifts
[channel
];
3113 val
<<= 16 + shifts
[channel
];
3115 regmap_update_bits(dispc
.syscon_pol
, dispc
.syscon_pol_offset
,
3120 /* change name to mode? */
3121 void dispc_mgr_set_timings(enum omap_channel channel
,
3122 const struct omap_video_timings
*timings
)
3124 unsigned xtot
, ytot
;
3125 unsigned long ht
, vt
;
3126 struct omap_video_timings t
= *timings
;
3128 DSSDBG("channel %d xres %u yres %u\n", channel
, t
.x_res
, t
.y_res
);
3130 if (!dispc_mgr_timings_ok(channel
, &t
)) {
3135 if (dss_mgr_is_lcd(channel
)) {
3136 _dispc_mgr_set_lcd_timings(channel
, t
.hsw
, t
.hfp
, t
.hbp
, t
.vsw
,
3137 t
.vfp
, t
.vbp
, t
.vsync_level
, t
.hsync_level
,
3138 t
.data_pclk_edge
, t
.de_level
, t
.sync_pclk_edge
);
3140 xtot
= t
.x_res
+ t
.hfp
+ t
.hsw
+ t
.hbp
;
3141 ytot
= t
.y_res
+ t
.vfp
+ t
.vsw
+ t
.vbp
;
3143 ht
= timings
->pixelclock
/ xtot
;
3144 vt
= timings
->pixelclock
/ xtot
/ ytot
;
3146 DSSDBG("pck %u\n", timings
->pixelclock
);
3147 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
3148 t
.hsw
, t
.hfp
, t
.hbp
, t
.vsw
, t
.vfp
, t
.vbp
);
3149 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3150 t
.vsync_level
, t
.hsync_level
, t
.data_pclk_edge
,
3151 t
.de_level
, t
.sync_pclk_edge
);
3153 DSSDBG("hsync %luHz, vsync %luHz\n", ht
, vt
);
3159 dispc_mgr_set_size(channel
, t
.x_res
, t
.y_res
);
3161 EXPORT_SYMBOL(dispc_mgr_set_timings
);
3163 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel
, u16 lck_div
,
3166 BUG_ON(lck_div
< 1);
3167 BUG_ON(pck_div
< 1);
3169 dispc_write_reg(DISPC_DIVISORo(channel
),
3170 FLD_VAL(lck_div
, 23, 16) | FLD_VAL(pck_div
, 7, 0));
3172 if (!dss_has_feature(FEAT_CORE_CLK_DIV
) &&
3173 channel
== OMAP_DSS_CHANNEL_LCD
)
3174 dispc
.core_clk_rate
= dispc_fclk_rate() / lck_div
;
3177 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel
, int *lck_div
,
3181 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3182 *lck_div
= FLD_GET(l
, 23, 16);
3183 *pck_div
= FLD_GET(l
, 7, 0);
3186 static unsigned long dispc_fclk_rate(void)
3188 struct dss_pll
*pll
;
3189 unsigned long r
= 0;
3191 switch (dss_get_dispc_clk_source()) {
3192 case OMAP_DSS_CLK_SRC_FCK
:
3193 r
= dss_get_dispc_clk_rate();
3195 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
3196 pll
= dss_pll_find("dsi0");
3198 pll
= dss_pll_find("video0");
3200 r
= pll
->cinfo
.clkout
[0];
3202 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
3203 pll
= dss_pll_find("dsi1");
3205 pll
= dss_pll_find("video1");
3207 r
= pll
->cinfo
.clkout
[0];
3217 static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel
)
3219 struct dss_pll
*pll
;
3224 if (dss_mgr_is_lcd(channel
)) {
3225 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3227 lcd
= FLD_GET(l
, 23, 16);
3229 switch (dss_get_lcd_clk_source(channel
)) {
3230 case OMAP_DSS_CLK_SRC_FCK
:
3231 r
= dss_get_dispc_clk_rate();
3233 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
3234 pll
= dss_pll_find("dsi0");
3236 pll
= dss_pll_find("video0");
3238 r
= pll
->cinfo
.clkout
[0];
3240 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
3241 pll
= dss_pll_find("dsi1");
3243 pll
= dss_pll_find("video1");
3245 r
= pll
->cinfo
.clkout
[0];
3254 return dispc_fclk_rate();
3258 static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel
)
3262 if (dss_mgr_is_lcd(channel
)) {
3266 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3268 pcd
= FLD_GET(l
, 7, 0);
3270 r
= dispc_mgr_lclk_rate(channel
);
3274 return dispc
.tv_pclk_rate
;
3278 void dispc_set_tv_pclk(unsigned long pclk
)
3280 dispc
.tv_pclk_rate
= pclk
;
3283 static unsigned long dispc_core_clk_rate(void)
3285 return dispc
.core_clk_rate
;
3288 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane
)
3290 enum omap_channel channel
;
3292 if (plane
== OMAP_DSS_WB
)
3295 channel
= dispc_ovl_get_channel_out(plane
);
3297 return dispc_mgr_pclk_rate(channel
);
3300 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane
)
3302 enum omap_channel channel
;
3304 if (plane
== OMAP_DSS_WB
)
3307 channel
= dispc_ovl_get_channel_out(plane
);
3309 return dispc_mgr_lclk_rate(channel
);
3312 static void dispc_dump_clocks_channel(struct seq_file
*s
, enum omap_channel channel
)
3315 enum omap_dss_clk_source lcd_clk_src
;
3317 seq_printf(s
, "- %s -\n", mgr_desc
[channel
].name
);
3319 lcd_clk_src
= dss_get_lcd_clk_source(channel
);
3321 seq_printf(s
, "%s clk source = %s (%s)\n", mgr_desc
[channel
].name
,
3322 dss_get_generic_clk_source_name(lcd_clk_src
),
3323 dss_feat_get_clk_source_name(lcd_clk_src
));
3325 dispc_mgr_get_lcd_divisor(channel
, &lcd
, &pcd
);
3327 seq_printf(s
, "lck\t\t%-16lulck div\t%u\n",
3328 dispc_mgr_lclk_rate(channel
), lcd
);
3329 seq_printf(s
, "pck\t\t%-16lupck div\t%u\n",
3330 dispc_mgr_pclk_rate(channel
), pcd
);
3333 void dispc_dump_clocks(struct seq_file
*s
)
3337 enum omap_dss_clk_source dispc_clk_src
= dss_get_dispc_clk_source();
3339 if (dispc_runtime_get())
3342 seq_printf(s
, "- DISPC -\n");
3344 seq_printf(s
, "dispc fclk source = %s (%s)\n",
3345 dss_get_generic_clk_source_name(dispc_clk_src
),
3346 dss_feat_get_clk_source_name(dispc_clk_src
));
3348 seq_printf(s
, "fck\t\t%-16lu\n", dispc_fclk_rate());
3350 if (dss_has_feature(FEAT_CORE_CLK_DIV
)) {
3351 seq_printf(s
, "- DISPC-CORE-CLK -\n");
3352 l
= dispc_read_reg(DISPC_DIVISOR
);
3353 lcd
= FLD_GET(l
, 23, 16);
3355 seq_printf(s
, "lck\t\t%-16lulck div\t%u\n",
3356 (dispc_fclk_rate()/lcd
), lcd
);
3359 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD
);
3361 if (dss_has_feature(FEAT_MGR_LCD2
))
3362 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD2
);
3363 if (dss_has_feature(FEAT_MGR_LCD3
))
3364 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD3
);
3366 dispc_runtime_put();
3369 static void dispc_dump_regs(struct seq_file
*s
)
3372 const char *mgr_names
[] = {
3373 [OMAP_DSS_CHANNEL_LCD
] = "LCD",
3374 [OMAP_DSS_CHANNEL_DIGIT
] = "TV",
3375 [OMAP_DSS_CHANNEL_LCD2
] = "LCD2",
3376 [OMAP_DSS_CHANNEL_LCD3
] = "LCD3",
3378 const char *ovl_names
[] = {
3379 [OMAP_DSS_GFX
] = "GFX",
3380 [OMAP_DSS_VIDEO1
] = "VID1",
3381 [OMAP_DSS_VIDEO2
] = "VID2",
3382 [OMAP_DSS_VIDEO3
] = "VID3",
3383 [OMAP_DSS_WB
] = "WB",
3385 const char **p_names
;
3387 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3389 if (dispc_runtime_get())
3392 /* DISPC common registers */
3393 DUMPREG(DISPC_REVISION
);
3394 DUMPREG(DISPC_SYSCONFIG
);
3395 DUMPREG(DISPC_SYSSTATUS
);
3396 DUMPREG(DISPC_IRQSTATUS
);
3397 DUMPREG(DISPC_IRQENABLE
);
3398 DUMPREG(DISPC_CONTROL
);
3399 DUMPREG(DISPC_CONFIG
);
3400 DUMPREG(DISPC_CAPABLE
);
3401 DUMPREG(DISPC_LINE_STATUS
);
3402 DUMPREG(DISPC_LINE_NUMBER
);
3403 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
3404 dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
3405 DUMPREG(DISPC_GLOBAL_ALPHA
);
3406 if (dss_has_feature(FEAT_MGR_LCD2
)) {
3407 DUMPREG(DISPC_CONTROL2
);
3408 DUMPREG(DISPC_CONFIG2
);
3410 if (dss_has_feature(FEAT_MGR_LCD3
)) {
3411 DUMPREG(DISPC_CONTROL3
);
3412 DUMPREG(DISPC_CONFIG3
);
3414 if (dss_has_feature(FEAT_MFLAG
))
3415 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE
);
3419 #define DISPC_REG(i, name) name(i)
3420 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3421 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
3422 dispc_read_reg(DISPC_REG(i, r)))
3424 p_names
= mgr_names
;
3426 /* DISPC channel specific registers */
3427 for (i
= 0; i
< dss_feat_get_num_mgrs(); i
++) {
3428 DUMPREG(i
, DISPC_DEFAULT_COLOR
);
3429 DUMPREG(i
, DISPC_TRANS_COLOR
);
3430 DUMPREG(i
, DISPC_SIZE_MGR
);
3432 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
3435 DUMPREG(i
, DISPC_TIMING_H
);
3436 DUMPREG(i
, DISPC_TIMING_V
);
3437 DUMPREG(i
, DISPC_POL_FREQ
);
3438 DUMPREG(i
, DISPC_DIVISORo
);
3440 DUMPREG(i
, DISPC_DATA_CYCLE1
);
3441 DUMPREG(i
, DISPC_DATA_CYCLE2
);
3442 DUMPREG(i
, DISPC_DATA_CYCLE3
);
3444 if (dss_has_feature(FEAT_CPR
)) {
3445 DUMPREG(i
, DISPC_CPR_COEF_R
);
3446 DUMPREG(i
, DISPC_CPR_COEF_G
);
3447 DUMPREG(i
, DISPC_CPR_COEF_B
);
3451 p_names
= ovl_names
;
3453 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
3454 DUMPREG(i
, DISPC_OVL_BA0
);
3455 DUMPREG(i
, DISPC_OVL_BA1
);
3456 DUMPREG(i
, DISPC_OVL_POSITION
);
3457 DUMPREG(i
, DISPC_OVL_SIZE
);
3458 DUMPREG(i
, DISPC_OVL_ATTRIBUTES
);
3459 DUMPREG(i
, DISPC_OVL_FIFO_THRESHOLD
);
3460 DUMPREG(i
, DISPC_OVL_FIFO_SIZE_STATUS
);
3461 DUMPREG(i
, DISPC_OVL_ROW_INC
);
3462 DUMPREG(i
, DISPC_OVL_PIXEL_INC
);
3464 if (dss_has_feature(FEAT_PRELOAD
))
3465 DUMPREG(i
, DISPC_OVL_PRELOAD
);
3466 if (dss_has_feature(FEAT_MFLAG
))
3467 DUMPREG(i
, DISPC_OVL_MFLAG_THRESHOLD
);
3469 if (i
== OMAP_DSS_GFX
) {
3470 DUMPREG(i
, DISPC_OVL_WINDOW_SKIP
);
3471 DUMPREG(i
, DISPC_OVL_TABLE_BA
);
3475 DUMPREG(i
, DISPC_OVL_FIR
);
3476 DUMPREG(i
, DISPC_OVL_PICTURE_SIZE
);
3477 DUMPREG(i
, DISPC_OVL_ACCU0
);
3478 DUMPREG(i
, DISPC_OVL_ACCU1
);
3479 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3480 DUMPREG(i
, DISPC_OVL_BA0_UV
);
3481 DUMPREG(i
, DISPC_OVL_BA1_UV
);
3482 DUMPREG(i
, DISPC_OVL_FIR2
);
3483 DUMPREG(i
, DISPC_OVL_ACCU2_0
);
3484 DUMPREG(i
, DISPC_OVL_ACCU2_1
);
3486 if (dss_has_feature(FEAT_ATTR2
))
3487 DUMPREG(i
, DISPC_OVL_ATTRIBUTES2
);
3490 if (dispc
.feat
->has_writeback
) {
3492 DUMPREG(i
, DISPC_OVL_BA0
);
3493 DUMPREG(i
, DISPC_OVL_BA1
);
3494 DUMPREG(i
, DISPC_OVL_SIZE
);
3495 DUMPREG(i
, DISPC_OVL_ATTRIBUTES
);
3496 DUMPREG(i
, DISPC_OVL_FIFO_THRESHOLD
);
3497 DUMPREG(i
, DISPC_OVL_FIFO_SIZE_STATUS
);
3498 DUMPREG(i
, DISPC_OVL_ROW_INC
);
3499 DUMPREG(i
, DISPC_OVL_PIXEL_INC
);
3501 if (dss_has_feature(FEAT_MFLAG
))
3502 DUMPREG(i
, DISPC_OVL_MFLAG_THRESHOLD
);
3504 DUMPREG(i
, DISPC_OVL_FIR
);
3505 DUMPREG(i
, DISPC_OVL_PICTURE_SIZE
);
3506 DUMPREG(i
, DISPC_OVL_ACCU0
);
3507 DUMPREG(i
, DISPC_OVL_ACCU1
);
3508 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3509 DUMPREG(i
, DISPC_OVL_BA0_UV
);
3510 DUMPREG(i
, DISPC_OVL_BA1_UV
);
3511 DUMPREG(i
, DISPC_OVL_FIR2
);
3512 DUMPREG(i
, DISPC_OVL_ACCU2_0
);
3513 DUMPREG(i
, DISPC_OVL_ACCU2_1
);
3515 if (dss_has_feature(FEAT_ATTR2
))
3516 DUMPREG(i
, DISPC_OVL_ATTRIBUTES2
);
3522 #define DISPC_REG(plane, name, i) name(plane, i)
3523 #define DUMPREG(plane, name, i) \
3524 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3525 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
3526 dispc_read_reg(DISPC_REG(plane, name, i)))
3528 /* Video pipeline coefficient registers */
3530 /* start from OMAP_DSS_VIDEO1 */
3531 for (i
= 1; i
< dss_feat_get_num_ovls(); i
++) {
3532 for (j
= 0; j
< 8; j
++)
3533 DUMPREG(i
, DISPC_OVL_FIR_COEF_H
, j
);
3535 for (j
= 0; j
< 8; j
++)
3536 DUMPREG(i
, DISPC_OVL_FIR_COEF_HV
, j
);
3538 for (j
= 0; j
< 5; j
++)
3539 DUMPREG(i
, DISPC_OVL_CONV_COEF
, j
);
3541 if (dss_has_feature(FEAT_FIR_COEF_V
)) {
3542 for (j
= 0; j
< 8; j
++)
3543 DUMPREG(i
, DISPC_OVL_FIR_COEF_V
, j
);
3546 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3547 for (j
= 0; j
< 8; j
++)
3548 DUMPREG(i
, DISPC_OVL_FIR_COEF_H2
, j
);
3550 for (j
= 0; j
< 8; j
++)
3551 DUMPREG(i
, DISPC_OVL_FIR_COEF_HV2
, j
);
3553 for (j
= 0; j
< 8; j
++)
3554 DUMPREG(i
, DISPC_OVL_FIR_COEF_V2
, j
);
3558 dispc_runtime_put();
3564 /* calculate clock rates using dividers in cinfo */
3565 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate
,
3566 struct dispc_clock_info
*cinfo
)
3568 if (cinfo
->lck_div
> 255 || cinfo
->lck_div
== 0)
3570 if (cinfo
->pck_div
< 1 || cinfo
->pck_div
> 255)
3573 cinfo
->lck
= dispc_fclk_rate
/ cinfo
->lck_div
;
3574 cinfo
->pck
= cinfo
->lck
/ cinfo
->pck_div
;
3579 bool dispc_div_calc(unsigned long dispc
,
3580 unsigned long pck_min
, unsigned long pck_max
,
3581 dispc_div_calc_func func
, void *data
)
3583 int lckd
, lckd_start
, lckd_stop
;
3584 int pckd
, pckd_start
, pckd_stop
;
3585 unsigned long pck
, lck
;
3586 unsigned long lck_max
;
3587 unsigned long pckd_hw_min
, pckd_hw_max
;
3588 unsigned min_fck_per_pck
;
3591 #ifdef CONFIG_FB_OMAP2_DSS_MIN_FCK_PER_PCK
3592 min_fck_per_pck
= CONFIG_FB_OMAP2_DSS_MIN_FCK_PER_PCK
;
3594 min_fck_per_pck
= 0;
3597 pckd_hw_min
= dss_feat_get_param_min(FEAT_PARAM_DSS_PCD
);
3598 pckd_hw_max
= dss_feat_get_param_max(FEAT_PARAM_DSS_PCD
);
3600 lck_max
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
3602 pck_min
= pck_min
? pck_min
: 1;
3603 pck_max
= pck_max
? pck_max
: ULONG_MAX
;
3605 lckd_start
= max(DIV_ROUND_UP(dispc
, lck_max
), 1ul);
3606 lckd_stop
= min(dispc
/ pck_min
, 255ul);
3608 for (lckd
= lckd_start
; lckd
<= lckd_stop
; ++lckd
) {
3611 pckd_start
= max(DIV_ROUND_UP(lck
, pck_max
), pckd_hw_min
);
3612 pckd_stop
= min(lck
/ pck_min
, pckd_hw_max
);
3614 for (pckd
= pckd_start
; pckd
<= pckd_stop
; ++pckd
) {
3618 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3619 * clock, which means we're configuring DISPC fclk here
3620 * also. Thus we need to use the calculated lck. For
3621 * OMAP4+ the DISPC fclk is a separate clock.
3623 if (dss_has_feature(FEAT_CORE_CLK_DIV
))
3624 fck
= dispc_core_clk_rate();
3628 if (fck
< pck
* min_fck_per_pck
)
3631 if (func(lckd
, pckd
, lck
, pck
, data
))
3639 void dispc_mgr_set_clock_div(enum omap_channel channel
,
3640 const struct dispc_clock_info
*cinfo
)
3642 DSSDBG("lck = %lu (%u)\n", cinfo
->lck
, cinfo
->lck_div
);
3643 DSSDBG("pck = %lu (%u)\n", cinfo
->pck
, cinfo
->pck_div
);
3645 dispc_mgr_set_lcd_divisor(channel
, cinfo
->lck_div
, cinfo
->pck_div
);
3648 u32
dispc_read_irqstatus(void)
3650 return dispc_read_reg(DISPC_IRQSTATUS
);
3652 EXPORT_SYMBOL(dispc_read_irqstatus
);
3654 void dispc_clear_irqstatus(u32 mask
)
3656 dispc_write_reg(DISPC_IRQSTATUS
, mask
);
3658 EXPORT_SYMBOL(dispc_clear_irqstatus
);
3660 u32
dispc_read_irqenable(void)
3662 return dispc_read_reg(DISPC_IRQENABLE
);
3664 EXPORT_SYMBOL(dispc_read_irqenable
);
3666 void dispc_write_irqenable(u32 mask
)
3668 u32 old_mask
= dispc_read_reg(DISPC_IRQENABLE
);
3670 /* clear the irqstatus for newly enabled irqs */
3671 dispc_clear_irqstatus((mask
^ old_mask
) & mask
);
3673 dispc_write_reg(DISPC_IRQENABLE
, mask
);
3675 EXPORT_SYMBOL(dispc_write_irqenable
);
3677 void dispc_enable_sidle(void)
3679 REG_FLD_MOD(DISPC_SYSCONFIG
, 2, 4, 3); /* SIDLEMODE: smart idle */
3682 void dispc_disable_sidle(void)
3684 REG_FLD_MOD(DISPC_SYSCONFIG
, 1, 4, 3); /* SIDLEMODE: no idle */
3687 static void _omap_dispc_initial_config(void)
3691 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3692 if (dss_has_feature(FEAT_CORE_CLK_DIV
)) {
3693 l
= dispc_read_reg(DISPC_DIVISOR
);
3694 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3695 l
= FLD_MOD(l
, 1, 0, 0);
3696 l
= FLD_MOD(l
, 1, 23, 16);
3697 dispc_write_reg(DISPC_DIVISOR
, l
);
3699 dispc
.core_clk_rate
= dispc_fclk_rate();
3703 if (dss_has_feature(FEAT_FUNCGATED
))
3704 REG_FLD_MOD(DISPC_CONFIG
, 1, 9, 9);
3706 dispc_setup_color_conv_coef();
3708 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY
);
3712 dispc_configure_burst_sizes();
3714 dispc_ovl_enable_zorder_planes();
3716 if (dispc
.feat
->mstandby_workaround
)
3717 REG_FLD_MOD(DISPC_MSTANDBY_CTRL
, 1, 0, 0);
3719 if (dss_has_feature(FEAT_MFLAG
))
3723 static const struct dispc_features omap24xx_dispc_feats
= {
3730 .mgr_width_start
= 10,
3731 .mgr_height_start
= 26,
3732 .mgr_width_max
= 2048,
3733 .mgr_height_max
= 2048,
3734 .max_lcd_pclk
= 66500000,
3735 .calc_scaling
= dispc_ovl_calc_scaling_24xx
,
3736 .calc_core_clk
= calc_core_clk_24xx
,
3738 .no_framedone_tv
= true,
3739 .set_max_preload
= false,
3740 .last_pixel_inc_missing
= true,
3743 static const struct dispc_features omap34xx_rev1_0_dispc_feats
= {
3750 .mgr_width_start
= 10,
3751 .mgr_height_start
= 26,
3752 .mgr_width_max
= 2048,
3753 .mgr_height_max
= 2048,
3754 .max_lcd_pclk
= 173000000,
3755 .max_tv_pclk
= 59000000,
3756 .calc_scaling
= dispc_ovl_calc_scaling_34xx
,
3757 .calc_core_clk
= calc_core_clk_34xx
,
3759 .no_framedone_tv
= true,
3760 .set_max_preload
= false,
3761 .last_pixel_inc_missing
= true,
3764 static const struct dispc_features omap34xx_rev3_0_dispc_feats
= {
3771 .mgr_width_start
= 10,
3772 .mgr_height_start
= 26,
3773 .mgr_width_max
= 2048,
3774 .mgr_height_max
= 2048,
3775 .max_lcd_pclk
= 173000000,
3776 .max_tv_pclk
= 59000000,
3777 .calc_scaling
= dispc_ovl_calc_scaling_34xx
,
3778 .calc_core_clk
= calc_core_clk_34xx
,
3780 .no_framedone_tv
= true,
3781 .set_max_preload
= false,
3782 .last_pixel_inc_missing
= true,
3785 static const struct dispc_features omap44xx_dispc_feats
= {
3792 .mgr_width_start
= 10,
3793 .mgr_height_start
= 26,
3794 .mgr_width_max
= 2048,
3795 .mgr_height_max
= 2048,
3796 .max_lcd_pclk
= 170000000,
3797 .max_tv_pclk
= 185625000,
3798 .calc_scaling
= dispc_ovl_calc_scaling_44xx
,
3799 .calc_core_clk
= calc_core_clk_44xx
,
3801 .gfx_fifo_workaround
= true,
3802 .set_max_preload
= true,
3803 .supports_sync_align
= true,
3804 .has_writeback
= true,
3807 static const struct dispc_features omap54xx_dispc_feats
= {
3814 .mgr_width_start
= 11,
3815 .mgr_height_start
= 27,
3816 .mgr_width_max
= 4096,
3817 .mgr_height_max
= 4096,
3818 .max_lcd_pclk
= 170000000,
3819 .max_tv_pclk
= 186000000,
3820 .calc_scaling
= dispc_ovl_calc_scaling_44xx
,
3821 .calc_core_clk
= calc_core_clk_44xx
,
3823 .gfx_fifo_workaround
= true,
3824 .mstandby_workaround
= true,
3825 .set_max_preload
= true,
3826 .supports_sync_align
= true,
3827 .has_writeback
= true,
3830 static const struct dispc_features
*dispc_get_features(void)
3832 switch (omapdss_get_version()) {
3833 case OMAPDSS_VER_OMAP24xx
:
3834 return &omap24xx_dispc_feats
;
3836 case OMAPDSS_VER_OMAP34xx_ES1
:
3837 return &omap34xx_rev1_0_dispc_feats
;
3839 case OMAPDSS_VER_OMAP34xx_ES3
:
3840 case OMAPDSS_VER_OMAP3630
:
3841 case OMAPDSS_VER_AM35xx
:
3842 case OMAPDSS_VER_AM43xx
:
3843 return &omap34xx_rev3_0_dispc_feats
;
3845 case OMAPDSS_VER_OMAP4430_ES1
:
3846 case OMAPDSS_VER_OMAP4430_ES2
:
3847 case OMAPDSS_VER_OMAP4
:
3848 return &omap44xx_dispc_feats
;
3850 case OMAPDSS_VER_OMAP5
:
3851 case OMAPDSS_VER_DRA7xx
:
3852 return &omap54xx_dispc_feats
;
3859 static irqreturn_t
dispc_irq_handler(int irq
, void *arg
)
3861 if (!dispc
.is_enabled
)
3864 return dispc
.user_handler(irq
, dispc
.user_data
);
3867 int dispc_request_irq(irq_handler_t handler
, void *dev_id
)
3871 if (dispc
.user_handler
!= NULL
)
3874 dispc
.user_handler
= handler
;
3875 dispc
.user_data
= dev_id
;
3877 /* ensure the dispc_irq_handler sees the values above */
3880 r
= devm_request_irq(&dispc
.pdev
->dev
, dispc
.irq
, dispc_irq_handler
,
3881 IRQF_SHARED
, "OMAP DISPC", &dispc
);
3883 dispc
.user_handler
= NULL
;
3884 dispc
.user_data
= NULL
;
3889 EXPORT_SYMBOL(dispc_request_irq
);
3891 void dispc_free_irq(void *dev_id
)
3893 devm_free_irq(&dispc
.pdev
->dev
, dispc
.irq
, &dispc
);
3895 dispc
.user_handler
= NULL
;
3896 dispc
.user_data
= NULL
;
3898 EXPORT_SYMBOL(dispc_free_irq
);
3900 /* DISPC HW IP initialisation */
3901 static int dispc_bind(struct device
*dev
, struct device
*master
, void *data
)
3903 struct platform_device
*pdev
= to_platform_device(dev
);
3906 struct resource
*dispc_mem
;
3907 struct device_node
*np
= pdev
->dev
.of_node
;
3911 spin_lock_init(&dispc
.control_lock
);
3913 dispc
.feat
= dispc_get_features();
3917 dispc_mem
= platform_get_resource(dispc
.pdev
, IORESOURCE_MEM
, 0);
3919 DSSERR("can't get IORESOURCE_MEM DISPC\n");
3923 dispc
.base
= devm_ioremap(&pdev
->dev
, dispc_mem
->start
,
3924 resource_size(dispc_mem
));
3926 DSSERR("can't ioremap DISPC\n");
3930 dispc
.irq
= platform_get_irq(dispc
.pdev
, 0);
3931 if (dispc
.irq
< 0) {
3932 DSSERR("platform_get_irq failed\n");
3936 if (np
&& of_property_read_bool(np
, "syscon-pol")) {
3937 dispc
.syscon_pol
= syscon_regmap_lookup_by_phandle(np
, "syscon-pol");
3938 if (IS_ERR(dispc
.syscon_pol
)) {
3939 dev_err(&pdev
->dev
, "failed to get syscon-pol regmap\n");
3940 return PTR_ERR(dispc
.syscon_pol
);
3943 if (of_property_read_u32_index(np
, "syscon-pol", 1,
3944 &dispc
.syscon_pol_offset
)) {
3945 dev_err(&pdev
->dev
, "failed to get syscon-pol offset\n");
3950 pm_runtime_enable(&pdev
->dev
);
3952 r
= dispc_runtime_get();
3954 goto err_runtime_get
;
3956 _omap_dispc_initial_config();
3958 rev
= dispc_read_reg(DISPC_REVISION
);
3959 dev_dbg(&pdev
->dev
, "OMAP DISPC rev %d.%d\n",
3960 FLD_GET(rev
, 7, 4), FLD_GET(rev
, 3, 0));
3962 dispc_runtime_put();
3964 dss_init_overlay_managers();
3966 dss_debugfs_create_file("dispc", dispc_dump_regs
);
3971 pm_runtime_disable(&pdev
->dev
);
3975 static void dispc_unbind(struct device
*dev
, struct device
*master
,
3978 pm_runtime_disable(dev
);
3980 dss_uninit_overlay_managers();
3983 static const struct component_ops dispc_component_ops
= {
3985 .unbind
= dispc_unbind
,
3988 static int dispc_probe(struct platform_device
*pdev
)
3990 return component_add(&pdev
->dev
, &dispc_component_ops
);
3993 static void dispc_remove(struct platform_device
*pdev
)
3995 component_del(&pdev
->dev
, &dispc_component_ops
);
3998 static int dispc_runtime_suspend(struct device
*dev
)
4000 dispc
.is_enabled
= false;
4001 /* ensure the dispc_irq_handler sees the is_enabled value */
4003 /* wait for current handler to finish before turning the DISPC off */
4004 synchronize_irq(dispc
.irq
);
4006 dispc_save_context();
4011 static int dispc_runtime_resume(struct device
*dev
)
4014 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4015 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4016 * _omap_dispc_initial_config(). We can thus use it to detect if
4017 * we have lost register context.
4019 if (REG_GET(DISPC_CONFIG
, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY
) {
4020 _omap_dispc_initial_config();
4022 dispc_restore_context();
4025 dispc
.is_enabled
= true;
4026 /* ensure the dispc_irq_handler sees the is_enabled value */
4032 static const struct dev_pm_ops dispc_pm_ops
= {
4033 .runtime_suspend
= dispc_runtime_suspend
,
4034 .runtime_resume
= dispc_runtime_resume
,
4037 static const struct of_device_id dispc_of_match
[] = {
4038 { .compatible
= "ti,omap2-dispc", },
4039 { .compatible
= "ti,omap3-dispc", },
4040 { .compatible
= "ti,omap4-dispc", },
4041 { .compatible
= "ti,omap5-dispc", },
4042 { .compatible
= "ti,dra7-dispc", },
4046 static struct platform_driver omap_dispchw_driver
= {
4047 .probe
= dispc_probe
,
4048 .remove
= dispc_remove
,
4050 .name
= "omapdss_dispc",
4051 .pm
= &dispc_pm_ops
,
4052 .of_match_table
= dispc_of_match
,
4053 .suppress_bind_attrs
= true,
4057 int __init
dispc_init_platform_driver(void)
4059 return platform_driver_register(&omap_dispchw_driver
);
4062 void dispc_uninit_platform_driver(void)
4064 platform_driver_unregister(&omap_dispchw_driver
);