2 * Copyright (C) 2009 Nokia Corporation
3 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
5 * Some code and ideas taken from drivers/video/omap/ driver
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
21 #define DSS_SUBSYS_NAME "DISPC"
23 #include <linux/kernel.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/vmalloc.h>
26 #include <linux/export.h>
27 #include <linux/clk.h>
29 #include <linux/jiffies.h>
30 #include <linux/seq_file.h>
31 #include <linux/delay.h>
32 #include <linux/workqueue.h>
33 #include <linux/hardirq.h>
34 #include <linux/platform_device.h>
35 #include <linux/pm_runtime.h>
36 #include <linux/sizes.h>
37 #include <linux/mfd/syscon.h>
38 #include <linux/regmap.h>
40 #include <linux/of_device.h>
41 #include <linux/component.h>
42 #include <linux/sys_soc.h>
43 #include <drm/drm_fourcc.h>
44 #include <drm/drm_blend.h>
51 #define DISPC_SZ_REGS SZ_4K
53 enum omap_burst_size
{
59 #define REG_GET(idx, start, end) \
60 FLD_GET(dispc_read_reg(idx), start, end)
62 #define REG_FLD_MOD(idx, val, start, end) \
63 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
65 /* DISPC has feature id */
66 enum dispc_feature_id
{
76 /* Independent core clk divider */
78 FEAT_HANDLE_UV_SEPARATE
,
83 FEAT_ALPHA_FIXED_ZORDER
,
84 FEAT_ALPHA_FREE_ZORDER
,
86 /* An unknown HW bug causing the normal FIFO thresholds not to work */
87 FEAT_OMAP3_DSI_FIFO_BUG
,
92 struct dispc_features
{
103 unsigned long max_lcd_pclk
;
104 unsigned long max_tv_pclk
;
105 unsigned int max_downscale
;
106 unsigned int max_line_width
;
107 unsigned int min_pcd
;
108 int (*calc_scaling
) (unsigned long pclk
, unsigned long lclk
,
109 const struct videomode
*vm
,
110 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
111 u32 fourcc
, bool *five_taps
,
112 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
113 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
);
114 unsigned long (*calc_core_clk
) (unsigned long pclk
,
115 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
118 const enum dispc_feature_id
*features
;
119 unsigned int num_features
;
120 const struct dss_reg_field
*reg_fields
;
121 const unsigned int num_reg_fields
;
122 const enum omap_overlay_caps
*overlay_caps
;
123 const u32
**supported_color_modes
;
124 unsigned int num_mgrs
;
125 unsigned int num_ovls
;
126 unsigned int buffer_size_unit
;
127 unsigned int burst_size_unit
;
129 /* swap GFX & WB fifos */
130 bool gfx_fifo_workaround
:1;
132 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
133 bool no_framedone_tv
:1;
135 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
136 bool mstandby_workaround
:1;
138 bool set_max_preload
:1;
140 /* PIXEL_INC is not added to the last pixel of a line */
141 bool last_pixel_inc_missing
:1;
143 /* POL_FREQ has ALIGN bit */
144 bool supports_sync_align
:1;
146 bool has_writeback
:1;
148 bool supports_double_pixel
:1;
151 * Field order for VENC is different than HDMI. We should handle this in
152 * some intelligent manner, but as the SoCs have either HDMI or VENC,
153 * never both, we can just use this flag for now.
155 bool reverse_ilace_field_order
:1;
157 bool has_gamma_table
:1;
159 bool has_gamma_i734_bug
:1;
162 #define DISPC_MAX_NR_FIFOS 5
163 #define DISPC_MAX_CHANNEL_GAMMA 4
166 struct platform_device
*pdev
;
170 irq_handler_t user_handler
;
173 unsigned long core_clk_rate
;
174 unsigned long tv_pclk_rate
;
176 u32 fifo_size
[DISPC_MAX_NR_FIFOS
];
177 /* maps which plane is using a fifo. fifo-id -> plane-id */
178 int fifo_assignment
[DISPC_MAX_NR_FIFOS
];
181 u32 ctx
[DISPC_SZ_REGS
/ sizeof(u32
)];
183 u32
*gamma_table
[DISPC_MAX_CHANNEL_GAMMA
];
185 const struct dispc_features
*feat
;
189 struct regmap
*syscon_pol
;
190 u32 syscon_pol_offset
;
192 /* DISPC_CONTROL & DISPC_CONFIG lock*/
193 spinlock_t control_lock
;
196 enum omap_color_component
{
197 /* used for all color formats for OMAP3 and earlier
198 * and for RGB and Y color component on OMAP4
200 DISPC_COLOR_COMPONENT_RGB_Y
= 1 << 0,
201 /* used for UV component for
202 * DRM_FORMAT_YUYV, DRM_FORMAT_UYVY, DRM_FORMAT_NV12
203 * color formats on OMAP4
205 DISPC_COLOR_COMPONENT_UV
= 1 << 1,
208 enum mgr_reg_fields
{
209 DISPC_MGR_FLD_ENABLE
,
210 DISPC_MGR_FLD_STNTFT
,
212 DISPC_MGR_FLD_TFTDATALINES
,
213 DISPC_MGR_FLD_STALLMODE
,
214 DISPC_MGR_FLD_TCKENABLE
,
215 DISPC_MGR_FLD_TCKSELECTION
,
217 DISPC_MGR_FLD_FIFOHANDCHECK
,
218 /* used to maintain a count of the above fields */
222 /* DISPC register field id */
223 enum dispc_feat_reg_field
{
226 FEAT_REG_FIFOHIGHTHRESHOLD
,
227 FEAT_REG_FIFOLOWTHRESHOLD
,
229 FEAT_REG_HORIZONTALACCU
,
230 FEAT_REG_VERTICALACCU
,
233 struct dispc_reg_field
{
239 struct dispc_gamma_desc
{
246 static const struct {
251 struct dispc_gamma_desc gamma
;
252 struct dispc_reg_field reg_desc
[DISPC_MGR_FLD_NUM
];
254 [OMAP_DSS_CHANNEL_LCD
] = {
256 .vsync_irq
= DISPC_IRQ_VSYNC
,
257 .framedone_irq
= DISPC_IRQ_FRAMEDONE
,
258 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST
,
262 .reg
= DISPC_GAMMA_TABLE0
,
266 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL
, 0, 0 },
267 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL
, 3, 3 },
268 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL
, 5, 5 },
269 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL
, 9, 8 },
270 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL
, 11, 11 },
271 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG
, 10, 10 },
272 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG
, 11, 11 },
273 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG
, 15, 15 },
274 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG
, 16, 16 },
277 [OMAP_DSS_CHANNEL_DIGIT
] = {
279 .vsync_irq
= DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_EVSYNC_EVEN
,
280 .framedone_irq
= DISPC_IRQ_FRAMEDONETV
,
281 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST_DIGIT
,
285 .reg
= DISPC_GAMMA_TABLE2
,
289 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL
, 1, 1 },
290 [DISPC_MGR_FLD_STNTFT
] = { },
291 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL
, 6, 6 },
292 [DISPC_MGR_FLD_TFTDATALINES
] = { },
293 [DISPC_MGR_FLD_STALLMODE
] = { },
294 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG
, 12, 12 },
295 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG
, 13, 13 },
296 [DISPC_MGR_FLD_CPR
] = { },
297 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG
, 16, 16 },
300 [OMAP_DSS_CHANNEL_LCD2
] = {
302 .vsync_irq
= DISPC_IRQ_VSYNC2
,
303 .framedone_irq
= DISPC_IRQ_FRAMEDONE2
,
304 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST2
,
308 .reg
= DISPC_GAMMA_TABLE1
,
312 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL2
, 0, 0 },
313 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL2
, 3, 3 },
314 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL2
, 5, 5 },
315 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL2
, 9, 8 },
316 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL2
, 11, 11 },
317 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG2
, 10, 10 },
318 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG2
, 11, 11 },
319 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG2
, 15, 15 },
320 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG2
, 16, 16 },
323 [OMAP_DSS_CHANNEL_LCD3
] = {
325 .vsync_irq
= DISPC_IRQ_VSYNC3
,
326 .framedone_irq
= DISPC_IRQ_FRAMEDONE3
,
327 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST3
,
331 .reg
= DISPC_GAMMA_TABLE3
,
335 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL3
, 0, 0 },
336 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL3
, 3, 3 },
337 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL3
, 5, 5 },
338 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL3
, 9, 8 },
339 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL3
, 11, 11 },
340 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG3
, 10, 10 },
341 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG3
, 11, 11 },
342 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG3
, 15, 15 },
343 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG3
, 16, 16 },
348 struct color_conv_coef
{
349 int ry
, rcr
, rcb
, gy
, gcr
, gcb
, by
, bcr
, bcb
;
353 static unsigned long dispc_fclk_rate(void);
354 static unsigned long dispc_core_clk_rate(void);
355 static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel
);
356 static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel
);
358 static unsigned long dispc_plane_pclk_rate(enum omap_plane_id plane
);
359 static unsigned long dispc_plane_lclk_rate(enum omap_plane_id plane
);
361 static void dispc_clear_irqstatus(u32 mask
);
362 static bool dispc_mgr_is_enabled(enum omap_channel channel
);
363 static void dispc_clear_irqstatus(u32 mask
);
365 static inline void dispc_write_reg(const u16 idx
, u32 val
)
367 __raw_writel(val
, dispc
.base
+ idx
);
370 static inline u32
dispc_read_reg(const u16 idx
)
372 return __raw_readl(dispc
.base
+ idx
);
375 static u32
mgr_fld_read(enum omap_channel channel
, enum mgr_reg_fields regfld
)
377 const struct dispc_reg_field rfld
= mgr_desc
[channel
].reg_desc
[regfld
];
378 return REG_GET(rfld
.reg
, rfld
.high
, rfld
.low
);
381 static void mgr_fld_write(enum omap_channel channel
,
382 enum mgr_reg_fields regfld
, int val
) {
383 const struct dispc_reg_field rfld
= mgr_desc
[channel
].reg_desc
[regfld
];
384 const bool need_lock
= rfld
.reg
== DISPC_CONTROL
|| rfld
.reg
== DISPC_CONFIG
;
388 spin_lock_irqsave(&dispc
.control_lock
, flags
);
390 REG_FLD_MOD(rfld
.reg
, val
, rfld
.high
, rfld
.low
);
393 spin_unlock_irqrestore(&dispc
.control_lock
, flags
);
396 static int dispc_get_num_ovls(void)
398 return dispc
.feat
->num_ovls
;
401 static int dispc_get_num_mgrs(void)
403 return dispc
.feat
->num_mgrs
;
406 static void dispc_get_reg_field(enum dispc_feat_reg_field id
,
409 if (id
>= dispc
.feat
->num_reg_fields
)
412 *start
= dispc
.feat
->reg_fields
[id
].start
;
413 *end
= dispc
.feat
->reg_fields
[id
].end
;
416 static bool dispc_has_feature(enum dispc_feature_id id
)
420 for (i
= 0; i
< dispc
.feat
->num_features
; i
++) {
421 if (dispc
.feat
->features
[i
] == id
)
429 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
431 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
433 static void dispc_save_context(void)
437 DSSDBG("dispc_save_context\n");
443 if (dispc_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
444 dispc_has_feature(FEAT_ALPHA_FREE_ZORDER
))
446 if (dispc_has_feature(FEAT_MGR_LCD2
)) {
450 if (dispc_has_feature(FEAT_MGR_LCD3
)) {
455 for (i
= 0; i
< dispc_get_num_mgrs(); i
++) {
456 SR(DEFAULT_COLOR(i
));
459 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
470 if (dispc_has_feature(FEAT_CPR
)) {
477 for (i
= 0; i
< dispc_get_num_ovls(); i
++) {
482 SR(OVL_ATTRIBUTES(i
));
483 SR(OVL_FIFO_THRESHOLD(i
));
485 SR(OVL_PIXEL_INC(i
));
486 if (dispc_has_feature(FEAT_PRELOAD
))
488 if (i
== OMAP_DSS_GFX
) {
489 SR(OVL_WINDOW_SKIP(i
));
494 SR(OVL_PICTURE_SIZE(i
));
498 for (j
= 0; j
< 8; j
++)
499 SR(OVL_FIR_COEF_H(i
, j
));
501 for (j
= 0; j
< 8; j
++)
502 SR(OVL_FIR_COEF_HV(i
, j
));
504 for (j
= 0; j
< 5; j
++)
505 SR(OVL_CONV_COEF(i
, j
));
507 if (dispc_has_feature(FEAT_FIR_COEF_V
)) {
508 for (j
= 0; j
< 8; j
++)
509 SR(OVL_FIR_COEF_V(i
, j
));
512 if (dispc_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
519 for (j
= 0; j
< 8; j
++)
520 SR(OVL_FIR_COEF_H2(i
, j
));
522 for (j
= 0; j
< 8; j
++)
523 SR(OVL_FIR_COEF_HV2(i
, j
));
525 for (j
= 0; j
< 8; j
++)
526 SR(OVL_FIR_COEF_V2(i
, j
));
528 if (dispc_has_feature(FEAT_ATTR2
))
529 SR(OVL_ATTRIBUTES2(i
));
532 if (dispc_has_feature(FEAT_CORE_CLK_DIV
))
535 dispc
.ctx_valid
= true;
537 DSSDBG("context saved\n");
540 static void dispc_restore_context(void)
544 DSSDBG("dispc_restore_context\n");
546 if (!dispc
.ctx_valid
)
553 if (dispc_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
554 dispc_has_feature(FEAT_ALPHA_FREE_ZORDER
))
556 if (dispc_has_feature(FEAT_MGR_LCD2
))
558 if (dispc_has_feature(FEAT_MGR_LCD3
))
561 for (i
= 0; i
< dispc_get_num_mgrs(); i
++) {
562 RR(DEFAULT_COLOR(i
));
565 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
576 if (dispc_has_feature(FEAT_CPR
)) {
583 for (i
= 0; i
< dispc_get_num_ovls(); i
++) {
588 RR(OVL_ATTRIBUTES(i
));
589 RR(OVL_FIFO_THRESHOLD(i
));
591 RR(OVL_PIXEL_INC(i
));
592 if (dispc_has_feature(FEAT_PRELOAD
))
594 if (i
== OMAP_DSS_GFX
) {
595 RR(OVL_WINDOW_SKIP(i
));
600 RR(OVL_PICTURE_SIZE(i
));
604 for (j
= 0; j
< 8; j
++)
605 RR(OVL_FIR_COEF_H(i
, j
));
607 for (j
= 0; j
< 8; j
++)
608 RR(OVL_FIR_COEF_HV(i
, j
));
610 for (j
= 0; j
< 5; j
++)
611 RR(OVL_CONV_COEF(i
, j
));
613 if (dispc_has_feature(FEAT_FIR_COEF_V
)) {
614 for (j
= 0; j
< 8; j
++)
615 RR(OVL_FIR_COEF_V(i
, j
));
618 if (dispc_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
625 for (j
= 0; j
< 8; j
++)
626 RR(OVL_FIR_COEF_H2(i
, j
));
628 for (j
= 0; j
< 8; j
++)
629 RR(OVL_FIR_COEF_HV2(i
, j
));
631 for (j
= 0; j
< 8; j
++)
632 RR(OVL_FIR_COEF_V2(i
, j
));
634 if (dispc_has_feature(FEAT_ATTR2
))
635 RR(OVL_ATTRIBUTES2(i
));
638 if (dispc_has_feature(FEAT_CORE_CLK_DIV
))
641 /* enable last, because LCD & DIGIT enable are here */
643 if (dispc_has_feature(FEAT_MGR_LCD2
))
645 if (dispc_has_feature(FEAT_MGR_LCD3
))
647 /* clear spurious SYNC_LOST_DIGIT interrupts */
648 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT
);
651 * enable last so IRQs won't trigger before
652 * the context is fully restored
656 DSSDBG("context restored\n");
662 int dispc_runtime_get(void)
666 DSSDBG("dispc_runtime_get\n");
668 r
= pm_runtime_get_sync(&dispc
.pdev
->dev
);
670 return r
< 0 ? r
: 0;
673 void dispc_runtime_put(void)
677 DSSDBG("dispc_runtime_put\n");
679 r
= pm_runtime_put_sync(&dispc
.pdev
->dev
);
680 WARN_ON(r
< 0 && r
!= -ENOSYS
);
683 static u32
dispc_mgr_get_vsync_irq(enum omap_channel channel
)
685 return mgr_desc
[channel
].vsync_irq
;
688 static u32
dispc_mgr_get_framedone_irq(enum omap_channel channel
)
690 if (channel
== OMAP_DSS_CHANNEL_DIGIT
&& dispc
.feat
->no_framedone_tv
)
693 return mgr_desc
[channel
].framedone_irq
;
696 static u32
dispc_mgr_get_sync_lost_irq(enum omap_channel channel
)
698 return mgr_desc
[channel
].sync_lost_irq
;
701 u32
dispc_wb_get_framedone_irq(void)
703 return DISPC_IRQ_FRAMEDONEWB
;
706 static void dispc_mgr_enable(enum omap_channel channel
, bool enable
)
708 mgr_fld_write(channel
, DISPC_MGR_FLD_ENABLE
, enable
);
709 /* flush posted write */
710 mgr_fld_read(channel
, DISPC_MGR_FLD_ENABLE
);
713 static bool dispc_mgr_is_enabled(enum omap_channel channel
)
715 return !!mgr_fld_read(channel
, DISPC_MGR_FLD_ENABLE
);
718 static bool dispc_mgr_go_busy(enum omap_channel channel
)
720 return mgr_fld_read(channel
, DISPC_MGR_FLD_GO
) == 1;
723 static void dispc_mgr_go(enum omap_channel channel
)
725 WARN_ON(!dispc_mgr_is_enabled(channel
));
726 WARN_ON(dispc_mgr_go_busy(channel
));
728 DSSDBG("GO %s\n", mgr_desc
[channel
].name
);
730 mgr_fld_write(channel
, DISPC_MGR_FLD_GO
, 1);
733 bool dispc_wb_go_busy(void)
735 return REG_GET(DISPC_CONTROL2
, 6, 6) == 1;
738 void dispc_wb_go(void)
740 enum omap_plane_id plane
= OMAP_DSS_WB
;
743 enable
= REG_GET(DISPC_OVL_ATTRIBUTES(plane
), 0, 0) == 1;
748 go
= REG_GET(DISPC_CONTROL2
, 6, 6) == 1;
750 DSSERR("GO bit not down for WB\n");
754 REG_FLD_MOD(DISPC_CONTROL2
, 1, 6, 6);
757 static void dispc_ovl_write_firh_reg(enum omap_plane_id plane
, int reg
,
760 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane
, reg
), value
);
763 static void dispc_ovl_write_firhv_reg(enum omap_plane_id plane
, int reg
,
766 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane
, reg
), value
);
769 static void dispc_ovl_write_firv_reg(enum omap_plane_id plane
, int reg
,
772 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane
, reg
), value
);
775 static void dispc_ovl_write_firh2_reg(enum omap_plane_id plane
, int reg
,
778 BUG_ON(plane
== OMAP_DSS_GFX
);
780 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane
, reg
), value
);
783 static void dispc_ovl_write_firhv2_reg(enum omap_plane_id plane
, int reg
,
786 BUG_ON(plane
== OMAP_DSS_GFX
);
788 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane
, reg
), value
);
791 static void dispc_ovl_write_firv2_reg(enum omap_plane_id plane
, int reg
,
794 BUG_ON(plane
== OMAP_DSS_GFX
);
796 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane
, reg
), value
);
799 static void dispc_ovl_set_scale_coef(enum omap_plane_id plane
, int fir_hinc
,
800 int fir_vinc
, int five_taps
,
801 enum omap_color_component color_comp
)
803 const struct dispc_coef
*h_coef
, *v_coef
;
806 h_coef
= dispc_ovl_get_scale_coef(fir_hinc
, true);
807 v_coef
= dispc_ovl_get_scale_coef(fir_vinc
, five_taps
);
809 for (i
= 0; i
< 8; i
++) {
812 h
= FLD_VAL(h_coef
[i
].hc0_vc00
, 7, 0)
813 | FLD_VAL(h_coef
[i
].hc1_vc0
, 15, 8)
814 | FLD_VAL(h_coef
[i
].hc2_vc1
, 23, 16)
815 | FLD_VAL(h_coef
[i
].hc3_vc2
, 31, 24);
816 hv
= FLD_VAL(h_coef
[i
].hc4_vc22
, 7, 0)
817 | FLD_VAL(v_coef
[i
].hc1_vc0
, 15, 8)
818 | FLD_VAL(v_coef
[i
].hc2_vc1
, 23, 16)
819 | FLD_VAL(v_coef
[i
].hc3_vc2
, 31, 24);
821 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
) {
822 dispc_ovl_write_firh_reg(plane
, i
, h
);
823 dispc_ovl_write_firhv_reg(plane
, i
, hv
);
825 dispc_ovl_write_firh2_reg(plane
, i
, h
);
826 dispc_ovl_write_firhv2_reg(plane
, i
, hv
);
832 for (i
= 0; i
< 8; i
++) {
834 v
= FLD_VAL(v_coef
[i
].hc0_vc00
, 7, 0)
835 | FLD_VAL(v_coef
[i
].hc4_vc22
, 15, 8);
836 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
)
837 dispc_ovl_write_firv_reg(plane
, i
, v
);
839 dispc_ovl_write_firv2_reg(plane
, i
, v
);
845 static void dispc_ovl_write_color_conv_coef(enum omap_plane_id plane
,
846 const struct color_conv_coef
*ct
)
848 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
850 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 0), CVAL(ct
->rcr
, ct
->ry
));
851 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 1), CVAL(ct
->gy
, ct
->rcb
));
852 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 2), CVAL(ct
->gcb
, ct
->gcr
));
853 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 3), CVAL(ct
->bcr
, ct
->by
));
854 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 4), CVAL(0, ct
->bcb
));
856 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), ct
->full_range
, 11, 11);
861 static void dispc_setup_color_conv_coef(void)
864 int num_ovl
= dispc_get_num_ovls();
865 const struct color_conv_coef ctbl_bt601_5_ovl
= {
867 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
869 const struct color_conv_coef ctbl_bt601_5_wb
= {
871 66, 129, 25, 112, -94, -18, -38, -74, 112, 0,
874 for (i
= 1; i
< num_ovl
; i
++)
875 dispc_ovl_write_color_conv_coef(i
, &ctbl_bt601_5_ovl
);
877 if (dispc
.feat
->has_writeback
)
878 dispc_ovl_write_color_conv_coef(OMAP_DSS_WB
, &ctbl_bt601_5_wb
);
881 static void dispc_ovl_set_ba0(enum omap_plane_id plane
, u32 paddr
)
883 dispc_write_reg(DISPC_OVL_BA0(plane
), paddr
);
886 static void dispc_ovl_set_ba1(enum omap_plane_id plane
, u32 paddr
)
888 dispc_write_reg(DISPC_OVL_BA1(plane
), paddr
);
891 static void dispc_ovl_set_ba0_uv(enum omap_plane_id plane
, u32 paddr
)
893 dispc_write_reg(DISPC_OVL_BA0_UV(plane
), paddr
);
896 static void dispc_ovl_set_ba1_uv(enum omap_plane_id plane
, u32 paddr
)
898 dispc_write_reg(DISPC_OVL_BA1_UV(plane
), paddr
);
901 static void dispc_ovl_set_pos(enum omap_plane_id plane
,
902 enum omap_overlay_caps caps
, int x
, int y
)
906 if ((caps
& OMAP_DSS_OVL_CAP_POS
) == 0)
909 val
= FLD_VAL(y
, 26, 16) | FLD_VAL(x
, 10, 0);
911 dispc_write_reg(DISPC_OVL_POSITION(plane
), val
);
914 static void dispc_ovl_set_input_size(enum omap_plane_id plane
, int width
,
917 u32 val
= FLD_VAL(height
- 1, 26, 16) | FLD_VAL(width
- 1, 10, 0);
919 if (plane
== OMAP_DSS_GFX
|| plane
== OMAP_DSS_WB
)
920 dispc_write_reg(DISPC_OVL_SIZE(plane
), val
);
922 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane
), val
);
925 static void dispc_ovl_set_output_size(enum omap_plane_id plane
, int width
,
930 BUG_ON(plane
== OMAP_DSS_GFX
);
932 val
= FLD_VAL(height
- 1, 26, 16) | FLD_VAL(width
- 1, 10, 0);
934 if (plane
== OMAP_DSS_WB
)
935 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane
), val
);
937 dispc_write_reg(DISPC_OVL_SIZE(plane
), val
);
940 static void dispc_ovl_set_zorder(enum omap_plane_id plane
,
941 enum omap_overlay_caps caps
, u8 zorder
)
943 if ((caps
& OMAP_DSS_OVL_CAP_ZORDER
) == 0)
946 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), zorder
, 27, 26);
949 static void dispc_ovl_enable_zorder_planes(void)
953 if (!dispc_has_feature(FEAT_ALPHA_FREE_ZORDER
))
956 for (i
= 0; i
< dispc_get_num_ovls(); i
++)
957 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i
), 1, 25, 25);
960 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane_id plane
,
961 enum omap_overlay_caps caps
, bool enable
)
963 if ((caps
& OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
) == 0)
966 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
? 1 : 0, 28, 28);
969 static void dispc_ovl_setup_global_alpha(enum omap_plane_id plane
,
970 enum omap_overlay_caps caps
, u8 global_alpha
)
972 static const unsigned shifts
[] = { 0, 8, 16, 24, };
975 if ((caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
978 shift
= shifts
[plane
];
979 REG_FLD_MOD(DISPC_GLOBAL_ALPHA
, global_alpha
, shift
+ 7, shift
);
982 static void dispc_ovl_set_pix_inc(enum omap_plane_id plane
, s32 inc
)
984 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane
), inc
);
987 static void dispc_ovl_set_row_inc(enum omap_plane_id plane
, s32 inc
)
989 dispc_write_reg(DISPC_OVL_ROW_INC(plane
), inc
);
992 static void dispc_ovl_set_color_mode(enum omap_plane_id plane
, u32 fourcc
)
995 if (plane
!= OMAP_DSS_GFX
) {
997 case DRM_FORMAT_NV12
:
999 case DRM_FORMAT_XRGB4444
:
1001 case DRM_FORMAT_RGBA4444
:
1003 case DRM_FORMAT_RGBX4444
:
1005 case DRM_FORMAT_ARGB4444
:
1007 case DRM_FORMAT_RGB565
:
1009 case DRM_FORMAT_ARGB1555
:
1011 case DRM_FORMAT_XRGB8888
:
1013 case DRM_FORMAT_RGB888
:
1015 case DRM_FORMAT_YUYV
:
1017 case DRM_FORMAT_UYVY
:
1019 case DRM_FORMAT_ARGB8888
:
1021 case DRM_FORMAT_RGBA8888
:
1023 case DRM_FORMAT_RGBX8888
:
1025 case DRM_FORMAT_XRGB1555
:
1032 case DRM_FORMAT_RGBX4444
:
1034 case DRM_FORMAT_ARGB4444
:
1036 case DRM_FORMAT_RGB565
:
1038 case DRM_FORMAT_ARGB1555
:
1040 case DRM_FORMAT_XRGB8888
:
1042 case DRM_FORMAT_RGB888
:
1044 case DRM_FORMAT_XRGB4444
:
1046 case DRM_FORMAT_RGBA4444
:
1048 case DRM_FORMAT_ARGB8888
:
1050 case DRM_FORMAT_RGBA8888
:
1052 case DRM_FORMAT_RGBX8888
:
1054 case DRM_FORMAT_XRGB1555
:
1061 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), m
, 4, 1);
1064 static bool format_is_yuv(u32 fourcc
)
1067 case DRM_FORMAT_YUYV
:
1068 case DRM_FORMAT_UYVY
:
1069 case DRM_FORMAT_NV12
:
1076 static void dispc_ovl_configure_burst_type(enum omap_plane_id plane
,
1077 enum omap_dss_rotation_type rotation_type
)
1079 if (dispc_has_feature(FEAT_BURST_2D
) == 0)
1082 if (rotation_type
== OMAP_DSS_ROT_TILER
)
1083 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), 1, 29, 29);
1085 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), 0, 29, 29);
1088 static void dispc_ovl_set_channel_out(enum omap_plane_id plane
,
1089 enum omap_channel channel
)
1093 int chan
= 0, chan2
= 0;
1099 case OMAP_DSS_VIDEO1
:
1100 case OMAP_DSS_VIDEO2
:
1101 case OMAP_DSS_VIDEO3
:
1109 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1110 if (dispc_has_feature(FEAT_MGR_LCD2
)) {
1112 case OMAP_DSS_CHANNEL_LCD
:
1116 case OMAP_DSS_CHANNEL_DIGIT
:
1120 case OMAP_DSS_CHANNEL_LCD2
:
1124 case OMAP_DSS_CHANNEL_LCD3
:
1125 if (dispc_has_feature(FEAT_MGR_LCD3
)) {
1133 case OMAP_DSS_CHANNEL_WB
:
1142 val
= FLD_MOD(val
, chan
, shift
, shift
);
1143 val
= FLD_MOD(val
, chan2
, 31, 30);
1145 val
= FLD_MOD(val
, channel
, shift
, shift
);
1147 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), val
);
1150 static enum omap_channel
dispc_ovl_get_channel_out(enum omap_plane_id plane
)
1159 case OMAP_DSS_VIDEO1
:
1160 case OMAP_DSS_VIDEO2
:
1161 case OMAP_DSS_VIDEO3
:
1169 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1171 if (FLD_GET(val
, shift
, shift
) == 1)
1172 return OMAP_DSS_CHANNEL_DIGIT
;
1174 if (!dispc_has_feature(FEAT_MGR_LCD2
))
1175 return OMAP_DSS_CHANNEL_LCD
;
1177 switch (FLD_GET(val
, 31, 30)) {
1180 return OMAP_DSS_CHANNEL_LCD
;
1182 return OMAP_DSS_CHANNEL_LCD2
;
1184 return OMAP_DSS_CHANNEL_LCD3
;
1186 return OMAP_DSS_CHANNEL_WB
;
1190 void dispc_wb_set_channel_in(enum dss_writeback_channel channel
)
1192 enum omap_plane_id plane
= OMAP_DSS_WB
;
1194 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), channel
, 18, 16);
1197 static void dispc_ovl_set_burst_size(enum omap_plane_id plane
,
1198 enum omap_burst_size burst_size
)
1200 static const unsigned shifts
[] = { 6, 14, 14, 14, 14, };
1203 shift
= shifts
[plane
];
1204 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), burst_size
, shift
+ 1, shift
);
1207 static void dispc_configure_burst_sizes(void)
1210 const int burst_size
= BURST_SIZE_X8
;
1212 /* Configure burst size always to maximum size */
1213 for (i
= 0; i
< dispc_get_num_ovls(); ++i
)
1214 dispc_ovl_set_burst_size(i
, burst_size
);
1215 if (dispc
.feat
->has_writeback
)
1216 dispc_ovl_set_burst_size(OMAP_DSS_WB
, burst_size
);
1219 static u32
dispc_ovl_get_burst_size(enum omap_plane_id plane
)
1221 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1222 return dispc
.feat
->burst_size_unit
* 8;
1225 static bool dispc_ovl_color_mode_supported(enum omap_plane_id plane
, u32 fourcc
)
1230 modes
= dispc
.feat
->supported_color_modes
[plane
];
1232 for (i
= 0; modes
[i
]; ++i
) {
1233 if (modes
[i
] == fourcc
)
1240 static const u32
*dispc_ovl_get_color_modes(enum omap_plane_id plane
)
1242 return dispc
.feat
->supported_color_modes
[plane
];
1245 static void dispc_mgr_enable_cpr(enum omap_channel channel
, bool enable
)
1247 if (channel
== OMAP_DSS_CHANNEL_DIGIT
)
1250 mgr_fld_write(channel
, DISPC_MGR_FLD_CPR
, enable
);
1253 static void dispc_mgr_set_cpr_coef(enum omap_channel channel
,
1254 const struct omap_dss_cpr_coefs
*coefs
)
1256 u32 coef_r
, coef_g
, coef_b
;
1258 if (!dss_mgr_is_lcd(channel
))
1261 coef_r
= FLD_VAL(coefs
->rr
, 31, 22) | FLD_VAL(coefs
->rg
, 20, 11) |
1262 FLD_VAL(coefs
->rb
, 9, 0);
1263 coef_g
= FLD_VAL(coefs
->gr
, 31, 22) | FLD_VAL(coefs
->gg
, 20, 11) |
1264 FLD_VAL(coefs
->gb
, 9, 0);
1265 coef_b
= FLD_VAL(coefs
->br
, 31, 22) | FLD_VAL(coefs
->bg
, 20, 11) |
1266 FLD_VAL(coefs
->bb
, 9, 0);
1268 dispc_write_reg(DISPC_CPR_COEF_R(channel
), coef_r
);
1269 dispc_write_reg(DISPC_CPR_COEF_G(channel
), coef_g
);
1270 dispc_write_reg(DISPC_CPR_COEF_B(channel
), coef_b
);
1273 static void dispc_ovl_set_vid_color_conv(enum omap_plane_id plane
,
1278 BUG_ON(plane
== OMAP_DSS_GFX
);
1280 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1281 val
= FLD_MOD(val
, enable
, 9, 9);
1282 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), val
);
1285 static void dispc_ovl_enable_replication(enum omap_plane_id plane
,
1286 enum omap_overlay_caps caps
, bool enable
)
1288 static const unsigned shifts
[] = { 5, 10, 10, 10 };
1291 if ((caps
& OMAP_DSS_OVL_CAP_REPLICATION
) == 0)
1294 shift
= shifts
[plane
];
1295 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
, shift
, shift
);
1298 static void dispc_mgr_set_size(enum omap_channel channel
, u16 width
,
1303 val
= FLD_VAL(height
- 1, dispc
.feat
->mgr_height_start
, 16) |
1304 FLD_VAL(width
- 1, dispc
.feat
->mgr_width_start
, 0);
1306 dispc_write_reg(DISPC_SIZE_MGR(channel
), val
);
1309 static void dispc_init_fifos(void)
1317 unit
= dispc
.feat
->buffer_size_unit
;
1319 dispc_get_reg_field(FEAT_REG_FIFOSIZE
, &start
, &end
);
1321 for (fifo
= 0; fifo
< dispc
.feat
->num_fifos
; ++fifo
) {
1322 size
= REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo
), start
, end
);
1324 dispc
.fifo_size
[fifo
] = size
;
1327 * By default fifos are mapped directly to overlays, fifo 0 to
1328 * ovl 0, fifo 1 to ovl 1, etc.
1330 dispc
.fifo_assignment
[fifo
] = fifo
;
1334 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1335 * causes problems with certain use cases, like using the tiler in 2D
1336 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1337 * giving GFX plane a larger fifo. WB but should work fine with a
1340 if (dispc
.feat
->gfx_fifo_workaround
) {
1343 v
= dispc_read_reg(DISPC_GLOBAL_BUFFER
);
1345 v
= FLD_MOD(v
, 4, 2, 0); /* GFX BUF top to WB */
1346 v
= FLD_MOD(v
, 4, 5, 3); /* GFX BUF bottom to WB */
1347 v
= FLD_MOD(v
, 0, 26, 24); /* WB BUF top to GFX */
1348 v
= FLD_MOD(v
, 0, 29, 27); /* WB BUF bottom to GFX */
1350 dispc_write_reg(DISPC_GLOBAL_BUFFER
, v
);
1352 dispc
.fifo_assignment
[OMAP_DSS_GFX
] = OMAP_DSS_WB
;
1353 dispc
.fifo_assignment
[OMAP_DSS_WB
] = OMAP_DSS_GFX
;
1357 * Setup default fifo thresholds.
1359 for (i
= 0; i
< dispc_get_num_ovls(); ++i
) {
1361 const bool use_fifomerge
= false;
1362 const bool manual_update
= false;
1364 dispc_ovl_compute_fifo_thresholds(i
, &low
, &high
,
1365 use_fifomerge
, manual_update
);
1367 dispc_ovl_set_fifo_threshold(i
, low
, high
);
1370 if (dispc
.feat
->has_writeback
) {
1372 const bool use_fifomerge
= false;
1373 const bool manual_update
= false;
1375 dispc_ovl_compute_fifo_thresholds(OMAP_DSS_WB
, &low
, &high
,
1376 use_fifomerge
, manual_update
);
1378 dispc_ovl_set_fifo_threshold(OMAP_DSS_WB
, low
, high
);
1382 static u32
dispc_ovl_get_fifo_size(enum omap_plane_id plane
)
1387 for (fifo
= 0; fifo
< dispc
.feat
->num_fifos
; ++fifo
) {
1388 if (dispc
.fifo_assignment
[fifo
] == plane
)
1389 size
+= dispc
.fifo_size
[fifo
];
1395 void dispc_ovl_set_fifo_threshold(enum omap_plane_id plane
, u32 low
,
1398 u8 hi_start
, hi_end
, lo_start
, lo_end
;
1401 unit
= dispc
.feat
->buffer_size_unit
;
1403 WARN_ON(low
% unit
!= 0);
1404 WARN_ON(high
% unit
!= 0);
1409 dispc_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD
, &hi_start
, &hi_end
);
1410 dispc_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD
, &lo_start
, &lo_end
);
1412 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1414 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane
),
1415 lo_start
, lo_end
) * unit
,
1416 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane
),
1417 hi_start
, hi_end
) * unit
,
1418 low
* unit
, high
* unit
);
1420 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane
),
1421 FLD_VAL(high
, hi_start
, hi_end
) |
1422 FLD_VAL(low
, lo_start
, lo_end
));
1425 * configure the preload to the pipeline's high threhold, if HT it's too
1426 * large for the preload field, set the threshold to the maximum value
1427 * that can be held by the preload register
1429 if (dispc_has_feature(FEAT_PRELOAD
) && dispc
.feat
->set_max_preload
&&
1430 plane
!= OMAP_DSS_WB
)
1431 dispc_write_reg(DISPC_OVL_PRELOAD(plane
), min(high
, 0xfffu
));
1434 void dispc_enable_fifomerge(bool enable
)
1436 if (!dispc_has_feature(FEAT_FIFO_MERGE
)) {
1441 DSSDBG("FIFO merge %s\n", enable
? "enabled" : "disabled");
1442 REG_FLD_MOD(DISPC_CONFIG
, enable
? 1 : 0, 14, 14);
1445 void dispc_ovl_compute_fifo_thresholds(enum omap_plane_id plane
,
1446 u32
*fifo_low
, u32
*fifo_high
, bool use_fifomerge
,
1450 * All sizes are in bytes. Both the buffer and burst are made of
1451 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1454 unsigned buf_unit
= dispc
.feat
->buffer_size_unit
;
1455 unsigned ovl_fifo_size
, total_fifo_size
, burst_size
;
1458 burst_size
= dispc_ovl_get_burst_size(plane
);
1459 ovl_fifo_size
= dispc_ovl_get_fifo_size(plane
);
1461 if (use_fifomerge
) {
1462 total_fifo_size
= 0;
1463 for (i
= 0; i
< dispc_get_num_ovls(); ++i
)
1464 total_fifo_size
+= dispc_ovl_get_fifo_size(i
);
1466 total_fifo_size
= ovl_fifo_size
;
1470 * We use the same low threshold for both fifomerge and non-fifomerge
1471 * cases, but for fifomerge we calculate the high threshold using the
1472 * combined fifo size
1475 if (manual_update
&& dispc_has_feature(FEAT_OMAP3_DSI_FIFO_BUG
)) {
1476 *fifo_low
= ovl_fifo_size
- burst_size
* 2;
1477 *fifo_high
= total_fifo_size
- burst_size
;
1478 } else if (plane
== OMAP_DSS_WB
) {
1480 * Most optimal configuration for writeback is to push out data
1481 * to the interconnect the moment writeback pushes enough pixels
1482 * in the FIFO to form a burst
1485 *fifo_high
= burst_size
;
1487 *fifo_low
= ovl_fifo_size
- burst_size
;
1488 *fifo_high
= total_fifo_size
- buf_unit
;
1492 static void dispc_ovl_set_mflag(enum omap_plane_id plane
, bool enable
)
1496 if (plane
== OMAP_DSS_GFX
)
1501 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
, bit
, bit
);
1504 static void dispc_ovl_set_mflag_threshold(enum omap_plane_id plane
,
1507 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane
),
1508 FLD_VAL(high
, 31, 16) | FLD_VAL(low
, 15, 0));
1511 static void dispc_init_mflag(void)
1516 * HACK: NV12 color format and MFLAG seem to have problems working
1517 * together: using two displays, and having an NV12 overlay on one of
1518 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1519 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1520 * remove the errors, but there doesn't seem to be a clear logic on
1521 * which values work and which not.
1523 * As a work-around, set force MFLAG to always on.
1525 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE
,
1526 (1 << 0) | /* MFLAG_CTRL = force always on */
1527 (0 << 2)); /* MFLAG_START = disable */
1529 for (i
= 0; i
< dispc_get_num_ovls(); ++i
) {
1530 u32 size
= dispc_ovl_get_fifo_size(i
);
1531 u32 unit
= dispc
.feat
->buffer_size_unit
;
1534 dispc_ovl_set_mflag(i
, true);
1537 * Simulation team suggests below thesholds:
1538 * HT = fifosize * 5 / 8;
1539 * LT = fifosize * 4 / 8;
1542 low
= size
* 4 / 8 / unit
;
1543 high
= size
* 5 / 8 / unit
;
1545 dispc_ovl_set_mflag_threshold(i
, low
, high
);
1548 if (dispc
.feat
->has_writeback
) {
1549 u32 size
= dispc_ovl_get_fifo_size(OMAP_DSS_WB
);
1550 u32 unit
= dispc
.feat
->buffer_size_unit
;
1553 dispc_ovl_set_mflag(OMAP_DSS_WB
, true);
1556 * Simulation team suggests below thesholds:
1557 * HT = fifosize * 5 / 8;
1558 * LT = fifosize * 4 / 8;
1561 low
= size
* 4 / 8 / unit
;
1562 high
= size
* 5 / 8 / unit
;
1564 dispc_ovl_set_mflag_threshold(OMAP_DSS_WB
, low
, high
);
1568 static void dispc_ovl_set_fir(enum omap_plane_id plane
,
1570 enum omap_color_component color_comp
)
1574 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
) {
1575 u8 hinc_start
, hinc_end
, vinc_start
, vinc_end
;
1577 dispc_get_reg_field(FEAT_REG_FIRHINC
, &hinc_start
, &hinc_end
);
1578 dispc_get_reg_field(FEAT_REG_FIRVINC
, &vinc_start
, &vinc_end
);
1579 val
= FLD_VAL(vinc
, vinc_start
, vinc_end
) |
1580 FLD_VAL(hinc
, hinc_start
, hinc_end
);
1582 dispc_write_reg(DISPC_OVL_FIR(plane
), val
);
1584 val
= FLD_VAL(vinc
, 28, 16) | FLD_VAL(hinc
, 12, 0);
1585 dispc_write_reg(DISPC_OVL_FIR2(plane
), val
);
1589 static void dispc_ovl_set_vid_accu0(enum omap_plane_id plane
, int haccu
,
1593 u8 hor_start
, hor_end
, vert_start
, vert_end
;
1595 dispc_get_reg_field(FEAT_REG_HORIZONTALACCU
, &hor_start
, &hor_end
);
1596 dispc_get_reg_field(FEAT_REG_VERTICALACCU
, &vert_start
, &vert_end
);
1598 val
= FLD_VAL(vaccu
, vert_start
, vert_end
) |
1599 FLD_VAL(haccu
, hor_start
, hor_end
);
1601 dispc_write_reg(DISPC_OVL_ACCU0(plane
), val
);
1604 static void dispc_ovl_set_vid_accu1(enum omap_plane_id plane
, int haccu
,
1608 u8 hor_start
, hor_end
, vert_start
, vert_end
;
1610 dispc_get_reg_field(FEAT_REG_HORIZONTALACCU
, &hor_start
, &hor_end
);
1611 dispc_get_reg_field(FEAT_REG_VERTICALACCU
, &vert_start
, &vert_end
);
1613 val
= FLD_VAL(vaccu
, vert_start
, vert_end
) |
1614 FLD_VAL(haccu
, hor_start
, hor_end
);
1616 dispc_write_reg(DISPC_OVL_ACCU1(plane
), val
);
1619 static void dispc_ovl_set_vid_accu2_0(enum omap_plane_id plane
, int haccu
,
1624 val
= FLD_VAL(vaccu
, 26, 16) | FLD_VAL(haccu
, 10, 0);
1625 dispc_write_reg(DISPC_OVL_ACCU2_0(plane
), val
);
1628 static void dispc_ovl_set_vid_accu2_1(enum omap_plane_id plane
, int haccu
,
1633 val
= FLD_VAL(vaccu
, 26, 16) | FLD_VAL(haccu
, 10, 0);
1634 dispc_write_reg(DISPC_OVL_ACCU2_1(plane
), val
);
1637 static void dispc_ovl_set_scale_param(enum omap_plane_id plane
,
1638 u16 orig_width
, u16 orig_height
,
1639 u16 out_width
, u16 out_height
,
1640 bool five_taps
, u8 rotation
,
1641 enum omap_color_component color_comp
)
1643 int fir_hinc
, fir_vinc
;
1645 fir_hinc
= 1024 * orig_width
/ out_width
;
1646 fir_vinc
= 1024 * orig_height
/ out_height
;
1648 dispc_ovl_set_scale_coef(plane
, fir_hinc
, fir_vinc
, five_taps
,
1650 dispc_ovl_set_fir(plane
, fir_hinc
, fir_vinc
, color_comp
);
1653 static void dispc_ovl_set_accu_uv(enum omap_plane_id plane
,
1654 u16 orig_width
, u16 orig_height
, u16 out_width
, u16 out_height
,
1655 bool ilace
, u32 fourcc
, u8 rotation
)
1657 int h_accu2_0
, h_accu2_1
;
1658 int v_accu2_0
, v_accu2_1
;
1659 int chroma_hinc
, chroma_vinc
;
1669 const struct accu
*accu_table
;
1670 const struct accu
*accu_val
;
1672 static const struct accu accu_nv12
[4] = {
1673 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1674 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1675 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1676 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1679 static const struct accu accu_nv12_ilace
[4] = {
1680 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1681 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1682 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1683 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1686 static const struct accu accu_yuv
[4] = {
1687 { 0, 1, 0, 1, 0, 1, 0, 1 },
1688 { 0, 1, 0, 1, 0, 1, 0, 1 },
1689 { -1, 1, 0, 1, 0, 1, 0, 1 },
1690 { 0, 1, 0, 1, -1, 1, 0, 1 },
1693 /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
1694 switch (rotation
& DRM_MODE_ROTATE_MASK
) {
1696 case DRM_MODE_ROTATE_0
:
1699 case DRM_MODE_ROTATE_90
:
1702 case DRM_MODE_ROTATE_180
:
1705 case DRM_MODE_ROTATE_270
:
1711 case DRM_FORMAT_NV12
:
1713 accu_table
= accu_nv12_ilace
;
1715 accu_table
= accu_nv12
;
1717 case DRM_FORMAT_YUYV
:
1718 case DRM_FORMAT_UYVY
:
1719 accu_table
= accu_yuv
;
1726 accu_val
= &accu_table
[idx
];
1728 chroma_hinc
= 1024 * orig_width
/ out_width
;
1729 chroma_vinc
= 1024 * orig_height
/ out_height
;
1731 h_accu2_0
= (accu_val
->h0_m
* chroma_hinc
/ accu_val
->h0_n
) % 1024;
1732 h_accu2_1
= (accu_val
->h1_m
* chroma_hinc
/ accu_val
->h1_n
) % 1024;
1733 v_accu2_0
= (accu_val
->v0_m
* chroma_vinc
/ accu_val
->v0_n
) % 1024;
1734 v_accu2_1
= (accu_val
->v1_m
* chroma_vinc
/ accu_val
->v1_n
) % 1024;
1736 dispc_ovl_set_vid_accu2_0(plane
, h_accu2_0
, v_accu2_0
);
1737 dispc_ovl_set_vid_accu2_1(plane
, h_accu2_1
, v_accu2_1
);
1740 static void dispc_ovl_set_scaling_common(enum omap_plane_id plane
,
1741 u16 orig_width
, u16 orig_height
,
1742 u16 out_width
, u16 out_height
,
1743 bool ilace
, bool five_taps
,
1744 bool fieldmode
, u32 fourcc
,
1751 dispc_ovl_set_scale_param(plane
, orig_width
, orig_height
,
1752 out_width
, out_height
, five_taps
,
1753 rotation
, DISPC_COLOR_COMPONENT_RGB_Y
);
1754 l
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1756 /* RESIZEENABLE and VERTICALTAPS */
1757 l
&= ~((0x3 << 5) | (0x1 << 21));
1758 l
|= (orig_width
!= out_width
) ? (1 << 5) : 0;
1759 l
|= (orig_height
!= out_height
) ? (1 << 6) : 0;
1760 l
|= five_taps
? (1 << 21) : 0;
1762 /* VRESIZECONF and HRESIZECONF */
1763 if (dispc_has_feature(FEAT_RESIZECONF
)) {
1765 l
|= (orig_width
<= out_width
) ? 0 : (1 << 7);
1766 l
|= (orig_height
<= out_height
) ? 0 : (1 << 8);
1769 /* LINEBUFFERSPLIT */
1770 if (dispc_has_feature(FEAT_LINEBUFFERSPLIT
)) {
1772 l
|= five_taps
? (1 << 22) : 0;
1775 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), l
);
1778 * field 0 = even field = bottom field
1779 * field 1 = odd field = top field
1781 if (ilace
&& !fieldmode
) {
1783 accu0
= ((1024 * orig_height
/ out_height
) / 2) & 0x3ff;
1784 if (accu0
>= 1024/2) {
1790 dispc_ovl_set_vid_accu0(plane
, 0, accu0
);
1791 dispc_ovl_set_vid_accu1(plane
, 0, accu1
);
1794 static void dispc_ovl_set_scaling_uv(enum omap_plane_id plane
,
1795 u16 orig_width
, u16 orig_height
,
1796 u16 out_width
, u16 out_height
,
1797 bool ilace
, bool five_taps
,
1798 bool fieldmode
, u32 fourcc
,
1801 int scale_x
= out_width
!= orig_width
;
1802 int scale_y
= out_height
!= orig_height
;
1803 bool chroma_upscale
= plane
!= OMAP_DSS_WB
;
1805 if (!dispc_has_feature(FEAT_HANDLE_UV_SEPARATE
))
1808 if (!format_is_yuv(fourcc
)) {
1809 /* reset chroma resampling for RGB formats */
1810 if (plane
!= OMAP_DSS_WB
)
1811 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
), 0, 8, 8);
1815 dispc_ovl_set_accu_uv(plane
, orig_width
, orig_height
, out_width
,
1816 out_height
, ilace
, fourcc
, rotation
);
1819 case DRM_FORMAT_NV12
:
1820 if (chroma_upscale
) {
1821 /* UV is subsampled by 2 horizontally and vertically */
1825 /* UV is downsampled by 2 horizontally and vertically */
1831 case DRM_FORMAT_YUYV
:
1832 case DRM_FORMAT_UYVY
:
1833 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
1834 if (!drm_rotation_90_or_270(rotation
)) {
1836 /* UV is subsampled by 2 horizontally */
1839 /* UV is downsampled by 2 horizontally */
1843 /* must use FIR for YUV422 if rotated */
1844 if ((rotation
& DRM_MODE_ROTATE_MASK
) != DRM_MODE_ROTATE_0
)
1845 scale_x
= scale_y
= true;
1853 if (out_width
!= orig_width
)
1855 if (out_height
!= orig_height
)
1858 dispc_ovl_set_scale_param(plane
, orig_width
, orig_height
,
1859 out_width
, out_height
, five_taps
,
1860 rotation
, DISPC_COLOR_COMPONENT_UV
);
1862 if (plane
!= OMAP_DSS_WB
)
1863 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
),
1864 (scale_x
|| scale_y
) ? 1 : 0, 8, 8);
1867 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), scale_x
? 1 : 0, 5, 5);
1869 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), scale_y
? 1 : 0, 6, 6);
1872 static void dispc_ovl_set_scaling(enum omap_plane_id plane
,
1873 u16 orig_width
, u16 orig_height
,
1874 u16 out_width
, u16 out_height
,
1875 bool ilace
, bool five_taps
,
1876 bool fieldmode
, u32 fourcc
,
1879 BUG_ON(plane
== OMAP_DSS_GFX
);
1881 dispc_ovl_set_scaling_common(plane
,
1882 orig_width
, orig_height
,
1883 out_width
, out_height
,
1888 dispc_ovl_set_scaling_uv(plane
,
1889 orig_width
, orig_height
,
1890 out_width
, out_height
,
1896 static void dispc_ovl_set_rotation_attrs(enum omap_plane_id plane
, u8 rotation
,
1897 enum omap_dss_rotation_type rotation_type
, u32 fourcc
)
1899 bool row_repeat
= false;
1902 /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
1903 if (fourcc
== DRM_FORMAT_YUYV
|| fourcc
== DRM_FORMAT_UYVY
) {
1905 if (rotation
& DRM_MODE_REFLECT_X
) {
1906 switch (rotation
& DRM_MODE_ROTATE_MASK
) {
1907 case DRM_MODE_ROTATE_0
:
1910 case DRM_MODE_ROTATE_90
:
1913 case DRM_MODE_ROTATE_180
:
1916 case DRM_MODE_ROTATE_270
:
1921 switch (rotation
& DRM_MODE_ROTATE_MASK
) {
1922 case DRM_MODE_ROTATE_0
:
1925 case DRM_MODE_ROTATE_90
:
1928 case DRM_MODE_ROTATE_180
:
1931 case DRM_MODE_ROTATE_270
:
1937 if (drm_rotation_90_or_270(rotation
))
1944 * OMAP4/5 Errata i631:
1945 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1946 * rows beyond the framebuffer, which may cause OCP error.
1948 if (fourcc
== DRM_FORMAT_NV12
&& rotation_type
!= OMAP_DSS_ROT_TILER
)
1951 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), vidrot
, 13, 12);
1952 if (dispc_has_feature(FEAT_ROWREPEATENABLE
))
1953 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
),
1954 row_repeat
? 1 : 0, 18, 18);
1956 if (dispc_ovl_color_mode_supported(plane
, DRM_FORMAT_NV12
)) {
1958 fourcc
== DRM_FORMAT_NV12
&&
1959 rotation_type
== OMAP_DSS_ROT_TILER
&&
1960 !drm_rotation_90_or_270(rotation
);
1963 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), doublestride
, 22, 22);
1967 static int color_mode_to_bpp(u32 fourcc
)
1970 case DRM_FORMAT_NV12
:
1972 case DRM_FORMAT_RGBX4444
:
1973 case DRM_FORMAT_RGB565
:
1974 case DRM_FORMAT_ARGB4444
:
1975 case DRM_FORMAT_YUYV
:
1976 case DRM_FORMAT_UYVY
:
1977 case DRM_FORMAT_RGBA4444
:
1978 case DRM_FORMAT_XRGB4444
:
1979 case DRM_FORMAT_ARGB1555
:
1980 case DRM_FORMAT_XRGB1555
:
1982 case DRM_FORMAT_RGB888
:
1984 case DRM_FORMAT_XRGB8888
:
1985 case DRM_FORMAT_ARGB8888
:
1986 case DRM_FORMAT_RGBA8888
:
1987 case DRM_FORMAT_RGBX8888
:
1995 static s32
pixinc(int pixels
, u8 ps
)
1999 else if (pixels
> 1)
2000 return 1 + (pixels
- 1) * ps
;
2001 else if (pixels
< 0)
2002 return 1 - (-pixels
+ 1) * ps
;
2008 static void calc_offset(u16 screen_width
, u16 width
,
2009 u32 fourcc
, bool fieldmode
,
2010 unsigned int field_offset
, unsigned *offset0
, unsigned *offset1
,
2011 s32
*row_inc
, s32
*pix_inc
, int x_predecim
, int y_predecim
,
2012 enum omap_dss_rotation_type rotation_type
, u8 rotation
)
2016 ps
= color_mode_to_bpp(fourcc
) / 8;
2018 DSSDBG("scrw %d, width %d\n", screen_width
, width
);
2020 if (rotation_type
== OMAP_DSS_ROT_TILER
&&
2021 (fourcc
== DRM_FORMAT_UYVY
|| fourcc
== DRM_FORMAT_YUYV
) &&
2022 drm_rotation_90_or_270(rotation
)) {
2024 * HACK: ROW_INC needs to be calculated with TILER units.
2025 * We get such 'screen_width' that multiplying it with the
2026 * YUV422 pixel size gives the correct TILER container width.
2027 * However, 'width' is in pixels and multiplying it with YUV422
2028 * pixel size gives incorrect result. We thus multiply it here
2029 * with 2 to match the 32 bit TILER unit size.
2035 * field 0 = even field = bottom field
2036 * field 1 = odd field = top field
2038 *offset0
= field_offset
* screen_width
* ps
;
2041 *row_inc
= pixinc(1 + (y_predecim
* screen_width
- width
* x_predecim
) +
2042 (fieldmode
? screen_width
: 0), ps
);
2043 if (fourcc
== DRM_FORMAT_YUYV
|| fourcc
== DRM_FORMAT_UYVY
)
2044 *pix_inc
= pixinc(x_predecim
, 2 * ps
);
2046 *pix_inc
= pixinc(x_predecim
, ps
);
2050 * This function is used to avoid synclosts in OMAP3, because of some
2051 * undocumented horizontal position and timing related limitations.
2053 static int check_horiz_timing_omap3(unsigned long pclk
, unsigned long lclk
,
2054 const struct videomode
*vm
, u16 pos_x
,
2055 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2058 const int ds
= DIV_ROUND_UP(height
, out_height
);
2059 unsigned long nonactive
;
2060 static const u8 limits
[3] = { 8, 10, 20 };
2064 nonactive
= vm
->hactive
+ vm
->hfront_porch
+ vm
->hsync_len
+
2065 vm
->hback_porch
- out_width
;
2068 if (out_height
< height
)
2070 if (out_width
< width
)
2072 blank
= div_u64((u64
)(vm
->hback_porch
+ vm
->hsync_len
+ vm
->hfront_porch
) *
2074 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank
, limits
[i
]);
2075 if (blank
<= limits
[i
])
2078 /* FIXME add checks for 3-tap filter once the limitations are known */
2083 * Pixel data should be prepared before visible display point starts.
2084 * So, atleast DS-2 lines must have already been fetched by DISPC
2085 * during nonactive - pos_x period.
2087 val
= div_u64((u64
)(nonactive
- pos_x
) * lclk
, pclk
);
2088 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2089 val
, max(0, ds
- 2) * width
);
2090 if (val
< max(0, ds
- 2) * width
)
2094 * All lines need to be refilled during the nonactive period of which
2095 * only one line can be loaded during the active period. So, atleast
2096 * DS - 1 lines should be loaded during nonactive period.
2098 val
= div_u64((u64
)nonactive
* lclk
, pclk
);
2099 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2100 val
, max(0, ds
- 1) * width
);
2101 if (val
< max(0, ds
- 1) * width
)
2107 static unsigned long calc_core_clk_five_taps(unsigned long pclk
,
2108 const struct videomode
*vm
, u16 width
,
2109 u16 height
, u16 out_width
, u16 out_height
,
2115 if (height
<= out_height
&& width
<= out_width
)
2116 return (unsigned long) pclk
;
2118 if (height
> out_height
) {
2119 unsigned int ppl
= vm
->hactive
;
2121 tmp
= (u64
)pclk
* height
* out_width
;
2122 do_div(tmp
, 2 * out_height
* ppl
);
2125 if (height
> 2 * out_height
) {
2126 if (ppl
== out_width
)
2129 tmp
= (u64
)pclk
* (height
- 2 * out_height
) * out_width
;
2130 do_div(tmp
, 2 * out_height
* (ppl
- out_width
));
2131 core_clk
= max_t(u32
, core_clk
, tmp
);
2135 if (width
> out_width
) {
2136 tmp
= (u64
)pclk
* width
;
2137 do_div(tmp
, out_width
);
2138 core_clk
= max_t(u32
, core_clk
, tmp
);
2140 if (fourcc
== DRM_FORMAT_XRGB8888
)
2147 static unsigned long calc_core_clk_24xx(unsigned long pclk
, u16 width
,
2148 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2150 if (height
> out_height
&& width
> out_width
)
2156 static unsigned long calc_core_clk_34xx(unsigned long pclk
, u16 width
,
2157 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2159 unsigned int hf
, vf
;
2162 * FIXME how to determine the 'A' factor
2163 * for the no downscaling case ?
2166 if (width
> 3 * out_width
)
2168 else if (width
> 2 * out_width
)
2170 else if (width
> out_width
)
2174 if (height
> out_height
)
2179 return pclk
* vf
* hf
;
2182 static unsigned long calc_core_clk_44xx(unsigned long pclk
, u16 width
,
2183 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2186 * If the overlay/writeback is in mem to mem mode, there are no
2187 * downscaling limitations with respect to pixel clock, return 1 as
2188 * required core clock to represent that we have sufficient enough
2189 * core clock to do maximum downscaling
2194 if (width
> out_width
)
2195 return DIV_ROUND_UP(pclk
, out_width
) * width
;
2200 static int dispc_ovl_calc_scaling_24xx(unsigned long pclk
, unsigned long lclk
,
2201 const struct videomode
*vm
,
2202 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2203 u32 fourcc
, bool *five_taps
,
2204 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2205 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2208 u16 in_width
, in_height
;
2209 int min_factor
= min(*decim_x
, *decim_y
);
2210 const int maxsinglelinewidth
= dispc
.feat
->max_line_width
;
2215 in_height
= height
/ *decim_y
;
2216 in_width
= width
/ *decim_x
;
2217 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
,
2218 in_height
, out_width
, out_height
, mem_to_mem
);
2219 error
= (in_width
> maxsinglelinewidth
|| !*core_clk
||
2220 *core_clk
> dispc_core_clk_rate());
2222 if (*decim_x
== *decim_y
) {
2223 *decim_x
= min_factor
;
2226 swap(*decim_x
, *decim_y
);
2227 if (*decim_x
< *decim_y
)
2231 } while (*decim_x
<= *x_predecim
&& *decim_y
<= *y_predecim
&& error
);
2234 DSSERR("failed to find scaling settings\n");
2238 if (in_width
> maxsinglelinewidth
) {
2239 DSSERR("Cannot scale max input width exceeded");
2245 static int dispc_ovl_calc_scaling_34xx(unsigned long pclk
, unsigned long lclk
,
2246 const struct videomode
*vm
,
2247 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2248 u32 fourcc
, bool *five_taps
,
2249 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2250 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2253 u16 in_width
, in_height
;
2254 const int maxsinglelinewidth
= dispc
.feat
->max_line_width
;
2257 in_height
= height
/ *decim_y
;
2258 in_width
= width
/ *decim_x
;
2259 *five_taps
= in_height
> out_height
;
2261 if (in_width
> maxsinglelinewidth
)
2262 if (in_height
> out_height
&&
2263 in_height
< out_height
* 2)
2267 *core_clk
= calc_core_clk_five_taps(pclk
, vm
,
2268 in_width
, in_height
, out_width
,
2269 out_height
, fourcc
);
2271 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
,
2272 in_height
, out_width
, out_height
,
2275 error
= check_horiz_timing_omap3(pclk
, lclk
, vm
,
2276 pos_x
, in_width
, in_height
, out_width
,
2277 out_height
, *five_taps
);
2278 if (error
&& *five_taps
) {
2283 error
= (error
|| in_width
> maxsinglelinewidth
* 2 ||
2284 (in_width
> maxsinglelinewidth
&& *five_taps
) ||
2285 !*core_clk
|| *core_clk
> dispc_core_clk_rate());
2288 /* verify that we're inside the limits of scaler */
2289 if (in_width
/ 4 > out_width
)
2293 if (in_height
/ 4 > out_height
)
2296 if (in_height
/ 2 > out_height
)
2303 } while (*decim_x
<= *x_predecim
&& *decim_y
<= *y_predecim
&& error
);
2306 DSSERR("failed to find scaling settings\n");
2310 if (check_horiz_timing_omap3(pclk
, lclk
, vm
, pos_x
, in_width
,
2311 in_height
, out_width
, out_height
, *five_taps
)) {
2312 DSSERR("horizontal timing too tight\n");
2316 if (in_width
> (maxsinglelinewidth
* 2)) {
2317 DSSERR("Cannot setup scaling");
2318 DSSERR("width exceeds maximum width possible");
2322 if (in_width
> maxsinglelinewidth
&& *five_taps
) {
2323 DSSERR("cannot setup scaling with five taps");
2329 static int dispc_ovl_calc_scaling_44xx(unsigned long pclk
, unsigned long lclk
,
2330 const struct videomode
*vm
,
2331 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2332 u32 fourcc
, bool *five_taps
,
2333 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2334 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2336 u16 in_width
, in_width_max
;
2337 int decim_x_min
= *decim_x
;
2338 u16 in_height
= height
/ *decim_y
;
2339 const int maxsinglelinewidth
= dispc
.feat
->max_line_width
;
2340 const int maxdownscale
= dispc
.feat
->max_downscale
;
2343 in_width_max
= out_width
* maxdownscale
;
2345 in_width_max
= dispc_core_clk_rate() /
2346 DIV_ROUND_UP(pclk
, out_width
);
2349 *decim_x
= DIV_ROUND_UP(width
, in_width_max
);
2351 *decim_x
= *decim_x
> decim_x_min
? *decim_x
: decim_x_min
;
2352 if (*decim_x
> *x_predecim
)
2356 in_width
= width
/ *decim_x
;
2357 } while (*decim_x
<= *x_predecim
&&
2358 in_width
> maxsinglelinewidth
&& ++*decim_x
);
2360 if (in_width
> maxsinglelinewidth
) {
2361 DSSERR("Cannot scale width exceeds max line width");
2365 if (*decim_x
> 4 && fourcc
!= DRM_FORMAT_NV12
) {
2367 * Let's disable all scaling that requires horizontal
2368 * decimation with higher factor than 4, until we have
2369 * better estimates of what we can and can not
2370 * do. However, NV12 color format appears to work Ok
2371 * with all decimation factors.
2373 * When decimating horizontally by more that 4 the dss
2374 * is not able to fetch the data in burst mode. When
2375 * this happens it is hard to tell if there enough
2376 * bandwidth. Despite what theory says this appears to
2377 * be true also for 16-bit color formats.
2379 DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)", *decim_x
);
2384 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
, in_height
,
2385 out_width
, out_height
, mem_to_mem
);
2389 #define DIV_FRAC(dividend, divisor) \
2390 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2392 static int dispc_ovl_calc_scaling(unsigned long pclk
, unsigned long lclk
,
2393 enum omap_overlay_caps caps
,
2394 const struct videomode
*vm
,
2395 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2396 u32 fourcc
, bool *five_taps
,
2397 int *x_predecim
, int *y_predecim
, u16 pos_x
,
2398 enum omap_dss_rotation_type rotation_type
, bool mem_to_mem
)
2400 const int maxdownscale
= dispc
.feat
->max_downscale
;
2401 const int max_decim_limit
= 16;
2402 unsigned long core_clk
= 0;
2403 int decim_x
, decim_y
, ret
;
2405 if (width
== out_width
&& height
== out_height
)
2408 if (!mem_to_mem
&& (pclk
== 0 || vm
->pixelclock
== 0)) {
2409 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2413 if ((caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0)
2417 *x_predecim
= *y_predecim
= 1;
2419 *x_predecim
= max_decim_limit
;
2420 *y_predecim
= (rotation_type
== OMAP_DSS_ROT_TILER
&&
2421 dispc_has_feature(FEAT_BURST_2D
)) ?
2422 2 : max_decim_limit
;
2425 decim_x
= DIV_ROUND_UP(DIV_ROUND_UP(width
, out_width
), maxdownscale
);
2426 decim_y
= DIV_ROUND_UP(DIV_ROUND_UP(height
, out_height
), maxdownscale
);
2428 if (decim_x
> *x_predecim
|| out_width
> width
* 8)
2431 if (decim_y
> *y_predecim
|| out_height
> height
* 8)
2434 ret
= dispc
.feat
->calc_scaling(pclk
, lclk
, vm
, width
, height
,
2435 out_width
, out_height
, fourcc
, five_taps
,
2436 x_predecim
, y_predecim
, &decim_x
, &decim_y
, pos_x
, &core_clk
,
2441 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",
2443 out_width
, out_height
,
2444 out_width
/ width
, DIV_FRAC(out_width
, width
),
2445 out_height
/ height
, DIV_FRAC(out_height
, height
),
2448 width
/ decim_x
, height
/ decim_y
,
2449 out_width
/ (width
/ decim_x
), DIV_FRAC(out_width
, width
/ decim_x
),
2450 out_height
/ (height
/ decim_y
), DIV_FRAC(out_height
, height
/ decim_y
),
2453 core_clk
, dispc_core_clk_rate());
2455 if (!core_clk
|| core_clk
> dispc_core_clk_rate()) {
2456 DSSERR("failed to set up scaling, "
2457 "required core clk rate = %lu Hz, "
2458 "current core clk rate = %lu Hz\n",
2459 core_clk
, dispc_core_clk_rate());
2463 *x_predecim
= decim_x
;
2464 *y_predecim
= decim_y
;
2468 static int dispc_ovl_setup_common(enum omap_plane_id plane
,
2469 enum omap_overlay_caps caps
, u32 paddr
, u32 p_uv_addr
,
2470 u16 screen_width
, int pos_x
, int pos_y
, u16 width
, u16 height
,
2471 u16 out_width
, u16 out_height
, u32 fourcc
,
2472 u8 rotation
, u8 zorder
, u8 pre_mult_alpha
,
2473 u8 global_alpha
, enum omap_dss_rotation_type rotation_type
,
2474 bool replication
, const struct videomode
*vm
,
2477 bool five_taps
= true;
2478 bool fieldmode
= false;
2480 unsigned offset0
, offset1
;
2483 u16 frame_width
, frame_height
;
2484 unsigned int field_offset
= 0;
2485 u16 in_height
= height
;
2486 u16 in_width
= width
;
2487 int x_predecim
= 1, y_predecim
= 1;
2488 bool ilace
= !!(vm
->flags
& DISPLAY_FLAGS_INTERLACED
);
2489 unsigned long pclk
= dispc_plane_pclk_rate(plane
);
2490 unsigned long lclk
= dispc_plane_lclk_rate(plane
);
2492 if (paddr
== 0 && rotation_type
!= OMAP_DSS_ROT_TILER
)
2495 if (format_is_yuv(fourcc
) && (in_width
& 1)) {
2496 DSSERR("input width %d is not even for YUV format\n", in_width
);
2500 out_width
= out_width
== 0 ? width
: out_width
;
2501 out_height
= out_height
== 0 ? height
: out_height
;
2503 if (ilace
&& height
== out_height
)
2512 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2513 "out_height %d\n", in_height
, pos_y
,
2517 if (!dispc_ovl_color_mode_supported(plane
, fourcc
))
2520 r
= dispc_ovl_calc_scaling(pclk
, lclk
, caps
, vm
, in_width
,
2521 in_height
, out_width
, out_height
, fourcc
,
2522 &five_taps
, &x_predecim
, &y_predecim
, pos_x
,
2523 rotation_type
, mem_to_mem
);
2527 in_width
= in_width
/ x_predecim
;
2528 in_height
= in_height
/ y_predecim
;
2530 if (x_predecim
> 1 || y_predecim
> 1)
2531 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2532 x_predecim
, y_predecim
, in_width
, in_height
);
2534 if (format_is_yuv(fourcc
) && (in_width
& 1)) {
2535 DSSDBG("predecimated input width is not even for YUV format\n");
2536 DSSDBG("adjusting input width %d -> %d\n",
2537 in_width
, in_width
& ~1);
2542 if (format_is_yuv(fourcc
))
2545 if (ilace
&& !fieldmode
) {
2547 * when downscaling the bottom field may have to start several
2548 * source lines below the top field. Unfortunately ACCUI
2549 * registers will only hold the fractional part of the offset
2550 * so the integer part must be added to the base address of the
2553 if (!in_height
|| in_height
== out_height
)
2556 field_offset
= in_height
/ out_height
/ 2;
2559 /* Fields are independent but interleaved in memory. */
2568 if (plane
== OMAP_DSS_WB
) {
2569 frame_width
= out_width
;
2570 frame_height
= out_height
;
2572 frame_width
= in_width
;
2573 frame_height
= height
;
2576 calc_offset(screen_width
, frame_width
,
2577 fourcc
, fieldmode
, field_offset
,
2578 &offset0
, &offset1
, &row_inc
, &pix_inc
,
2579 x_predecim
, y_predecim
,
2580 rotation_type
, rotation
);
2582 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2583 offset0
, offset1
, row_inc
, pix_inc
);
2585 dispc_ovl_set_color_mode(plane
, fourcc
);
2587 dispc_ovl_configure_burst_type(plane
, rotation_type
);
2589 if (dispc
.feat
->reverse_ilace_field_order
)
2590 swap(offset0
, offset1
);
2592 dispc_ovl_set_ba0(plane
, paddr
+ offset0
);
2593 dispc_ovl_set_ba1(plane
, paddr
+ offset1
);
2595 if (fourcc
== DRM_FORMAT_NV12
) {
2596 dispc_ovl_set_ba0_uv(plane
, p_uv_addr
+ offset0
);
2597 dispc_ovl_set_ba1_uv(plane
, p_uv_addr
+ offset1
);
2600 if (dispc
.feat
->last_pixel_inc_missing
)
2601 row_inc
+= pix_inc
- 1;
2603 dispc_ovl_set_row_inc(plane
, row_inc
);
2604 dispc_ovl_set_pix_inc(plane
, pix_inc
);
2606 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x
, pos_y
, in_width
,
2607 in_height
, out_width
, out_height
);
2609 dispc_ovl_set_pos(plane
, caps
, pos_x
, pos_y
);
2611 dispc_ovl_set_input_size(plane
, in_width
, in_height
);
2613 if (caps
& OMAP_DSS_OVL_CAP_SCALE
) {
2614 dispc_ovl_set_scaling(plane
, in_width
, in_height
, out_width
,
2615 out_height
, ilace
, five_taps
, fieldmode
,
2617 dispc_ovl_set_output_size(plane
, out_width
, out_height
);
2618 dispc_ovl_set_vid_color_conv(plane
, cconv
);
2621 dispc_ovl_set_rotation_attrs(plane
, rotation
, rotation_type
, fourcc
);
2623 dispc_ovl_set_zorder(plane
, caps
, zorder
);
2624 dispc_ovl_set_pre_mult_alpha(plane
, caps
, pre_mult_alpha
);
2625 dispc_ovl_setup_global_alpha(plane
, caps
, global_alpha
);
2627 dispc_ovl_enable_replication(plane
, caps
, replication
);
2632 static int dispc_ovl_setup(enum omap_plane_id plane
,
2633 const struct omap_overlay_info
*oi
,
2634 const struct videomode
*vm
, bool mem_to_mem
,
2635 enum omap_channel channel
)
2638 enum omap_overlay_caps caps
= dispc
.feat
->overlay_caps
[plane
];
2639 const bool replication
= true;
2641 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2642 " %dx%d, cmode %x, rot %d, chan %d repl %d\n",
2643 plane
, &oi
->paddr
, &oi
->p_uv_addr
, oi
->screen_width
, oi
->pos_x
,
2644 oi
->pos_y
, oi
->width
, oi
->height
, oi
->out_width
, oi
->out_height
,
2645 oi
->fourcc
, oi
->rotation
, channel
, replication
);
2647 dispc_ovl_set_channel_out(plane
, channel
);
2649 r
= dispc_ovl_setup_common(plane
, caps
, oi
->paddr
, oi
->p_uv_addr
,
2650 oi
->screen_width
, oi
->pos_x
, oi
->pos_y
, oi
->width
, oi
->height
,
2651 oi
->out_width
, oi
->out_height
, oi
->fourcc
, oi
->rotation
,
2652 oi
->zorder
, oi
->pre_mult_alpha
, oi
->global_alpha
,
2653 oi
->rotation_type
, replication
, vm
, mem_to_mem
);
2658 int dispc_wb_setup(const struct omap_dss_writeback_info
*wi
,
2659 bool mem_to_mem
, const struct videomode
*vm
)
2663 enum omap_plane_id plane
= OMAP_DSS_WB
;
2664 const int pos_x
= 0, pos_y
= 0;
2665 const u8 zorder
= 0, global_alpha
= 0;
2666 const bool replication
= true;
2668 int in_width
= vm
->hactive
;
2669 int in_height
= vm
->vactive
;
2670 enum omap_overlay_caps caps
=
2671 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
;
2673 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2674 "rot %d\n", wi
->paddr
, wi
->p_uv_addr
, in_width
,
2675 in_height
, wi
->width
, wi
->height
, wi
->fourcc
, wi
->rotation
);
2677 r
= dispc_ovl_setup_common(plane
, caps
, wi
->paddr
, wi
->p_uv_addr
,
2678 wi
->buf_width
, pos_x
, pos_y
, in_width
, in_height
, wi
->width
,
2679 wi
->height
, wi
->fourcc
, wi
->rotation
, zorder
,
2680 wi
->pre_mult_alpha
, global_alpha
, wi
->rotation_type
,
2681 replication
, vm
, mem_to_mem
);
2683 switch (wi
->fourcc
) {
2684 case DRM_FORMAT_RGB565
:
2685 case DRM_FORMAT_RGB888
:
2686 case DRM_FORMAT_ARGB4444
:
2687 case DRM_FORMAT_RGBA4444
:
2688 case DRM_FORMAT_RGBX4444
:
2689 case DRM_FORMAT_ARGB1555
:
2690 case DRM_FORMAT_XRGB1555
:
2691 case DRM_FORMAT_XRGB4444
:
2699 /* setup extra DISPC_WB_ATTRIBUTES */
2700 l
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
2701 l
= FLD_MOD(l
, truncation
, 10, 10); /* TRUNCATIONENABLE */
2702 l
= FLD_MOD(l
, mem_to_mem
, 19, 19); /* WRITEBACKMODE */
2704 l
= FLD_MOD(l
, 1, 26, 24); /* CAPTUREMODE */
2706 l
= FLD_MOD(l
, 0, 26, 24); /* CAPTUREMODE */
2707 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), l
);
2711 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
), 0, 7, 0);
2715 wbdelay
= min(vm
->vfront_porch
+
2716 vm
->vsync_len
+ vm
->vback_porch
, (u32
)255);
2719 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
), wbdelay
, 7, 0);
2725 static int dispc_ovl_enable(enum omap_plane_id plane
, bool enable
)
2727 DSSDBG("dispc_enable_plane %d, %d\n", plane
, enable
);
2729 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
? 1 : 0, 0, 0);
2734 static enum omap_dss_output_id
dispc_mgr_get_supported_outputs(enum omap_channel channel
)
2736 return dss_get_supported_outputs(channel
);
2739 static void dispc_lcd_enable_signal_polarity(bool act_high
)
2741 if (!dispc_has_feature(FEAT_LCDENABLEPOL
))
2744 REG_FLD_MOD(DISPC_CONTROL
, act_high
? 1 : 0, 29, 29);
2747 void dispc_lcd_enable_signal(bool enable
)
2749 if (!dispc_has_feature(FEAT_LCDENABLESIGNAL
))
2752 REG_FLD_MOD(DISPC_CONTROL
, enable
? 1 : 0, 28, 28);
2755 void dispc_pck_free_enable(bool enable
)
2757 if (!dispc_has_feature(FEAT_PCKFREEENABLE
))
2760 REG_FLD_MOD(DISPC_CONTROL
, enable
? 1 : 0, 27, 27);
2763 static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel
, bool enable
)
2765 mgr_fld_write(channel
, DISPC_MGR_FLD_FIFOHANDCHECK
, enable
);
2769 static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel
)
2771 mgr_fld_write(channel
, DISPC_MGR_FLD_STNTFT
, 1);
2774 static void dispc_set_loadmode(enum omap_dss_load_mode mode
)
2776 REG_FLD_MOD(DISPC_CONFIG
, mode
, 2, 1);
2780 static void dispc_mgr_set_default_color(enum omap_channel channel
, u32 color
)
2782 dispc_write_reg(DISPC_DEFAULT_COLOR(channel
), color
);
2785 static void dispc_mgr_set_trans_key(enum omap_channel ch
,
2786 enum omap_dss_trans_key_type type
,
2789 mgr_fld_write(ch
, DISPC_MGR_FLD_TCKSELECTION
, type
);
2791 dispc_write_reg(DISPC_TRANS_COLOR(ch
), trans_key
);
2794 static void dispc_mgr_enable_trans_key(enum omap_channel ch
, bool enable
)
2796 mgr_fld_write(ch
, DISPC_MGR_FLD_TCKENABLE
, enable
);
2799 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch
,
2802 if (!dispc_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
2805 if (ch
== OMAP_DSS_CHANNEL_LCD
)
2806 REG_FLD_MOD(DISPC_CONFIG
, enable
, 18, 18);
2807 else if (ch
== OMAP_DSS_CHANNEL_DIGIT
)
2808 REG_FLD_MOD(DISPC_CONFIG
, enable
, 19, 19);
2811 static void dispc_mgr_setup(enum omap_channel channel
,
2812 const struct omap_overlay_manager_info
*info
)
2814 dispc_mgr_set_default_color(channel
, info
->default_color
);
2815 dispc_mgr_set_trans_key(channel
, info
->trans_key_type
, info
->trans_key
);
2816 dispc_mgr_enable_trans_key(channel
, info
->trans_enabled
);
2817 dispc_mgr_enable_alpha_fixed_zorder(channel
,
2818 info
->partial_alpha_enabled
);
2819 if (dispc_has_feature(FEAT_CPR
)) {
2820 dispc_mgr_enable_cpr(channel
, info
->cpr_enable
);
2821 dispc_mgr_set_cpr_coef(channel
, &info
->cpr_coefs
);
2825 static void dispc_mgr_set_tft_data_lines(enum omap_channel channel
, u8 data_lines
)
2829 switch (data_lines
) {
2847 mgr_fld_write(channel
, DISPC_MGR_FLD_TFTDATALINES
, code
);
2850 static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode
)
2856 case DSS_IO_PAD_MODE_RESET
:
2860 case DSS_IO_PAD_MODE_RFBI
:
2864 case DSS_IO_PAD_MODE_BYPASS
:
2873 l
= dispc_read_reg(DISPC_CONTROL
);
2874 l
= FLD_MOD(l
, gpout0
, 15, 15);
2875 l
= FLD_MOD(l
, gpout1
, 16, 16);
2876 dispc_write_reg(DISPC_CONTROL
, l
);
2879 static void dispc_mgr_enable_stallmode(enum omap_channel channel
, bool enable
)
2881 mgr_fld_write(channel
, DISPC_MGR_FLD_STALLMODE
, enable
);
2884 static void dispc_mgr_set_lcd_config(enum omap_channel channel
,
2885 const struct dss_lcd_mgr_config
*config
)
2887 dispc_mgr_set_io_pad_mode(config
->io_pad_mode
);
2889 dispc_mgr_enable_stallmode(channel
, config
->stallmode
);
2890 dispc_mgr_enable_fifohandcheck(channel
, config
->fifohandcheck
);
2892 dispc_mgr_set_clock_div(channel
, &config
->clock_info
);
2894 dispc_mgr_set_tft_data_lines(channel
, config
->video_port_width
);
2896 dispc_lcd_enable_signal_polarity(config
->lcden_sig_polarity
);
2898 dispc_mgr_set_lcd_type_tft(channel
);
2901 static bool _dispc_mgr_size_ok(u16 width
, u16 height
)
2903 return width
<= dispc
.feat
->mgr_width_max
&&
2904 height
<= dispc
.feat
->mgr_height_max
;
2907 static bool _dispc_lcd_timings_ok(int hsync_len
, int hfp
, int hbp
,
2908 int vsw
, int vfp
, int vbp
)
2910 if (hsync_len
< 1 || hsync_len
> dispc
.feat
->sw_max
||
2911 hfp
< 1 || hfp
> dispc
.feat
->hp_max
||
2912 hbp
< 1 || hbp
> dispc
.feat
->hp_max
||
2913 vsw
< 1 || vsw
> dispc
.feat
->sw_max
||
2914 vfp
< 0 || vfp
> dispc
.feat
->vp_max
||
2915 vbp
< 0 || vbp
> dispc
.feat
->vp_max
)
2920 static bool _dispc_mgr_pclk_ok(enum omap_channel channel
,
2923 if (dss_mgr_is_lcd(channel
))
2924 return pclk
<= dispc
.feat
->max_lcd_pclk
;
2926 return pclk
<= dispc
.feat
->max_tv_pclk
;
2929 bool dispc_mgr_timings_ok(enum omap_channel channel
, const struct videomode
*vm
)
2931 if (!_dispc_mgr_size_ok(vm
->hactive
, vm
->vactive
))
2934 if (!_dispc_mgr_pclk_ok(channel
, vm
->pixelclock
))
2937 if (dss_mgr_is_lcd(channel
)) {
2938 /* TODO: OMAP4+ supports interlace for LCD outputs */
2939 if (vm
->flags
& DISPLAY_FLAGS_INTERLACED
)
2942 if (!_dispc_lcd_timings_ok(vm
->hsync_len
,
2943 vm
->hfront_porch
, vm
->hback_porch
,
2944 vm
->vsync_len
, vm
->vfront_porch
,
2952 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel
,
2953 const struct videomode
*vm
)
2955 u32 timing_h
, timing_v
, l
;
2956 bool onoff
, rf
, ipc
, vs
, hs
, de
;
2958 timing_h
= FLD_VAL(vm
->hsync_len
- 1, dispc
.feat
->sw_start
, 0) |
2959 FLD_VAL(vm
->hfront_porch
- 1, dispc
.feat
->fp_start
, 8) |
2960 FLD_VAL(vm
->hback_porch
- 1, dispc
.feat
->bp_start
, 20);
2961 timing_v
= FLD_VAL(vm
->vsync_len
- 1, dispc
.feat
->sw_start
, 0) |
2962 FLD_VAL(vm
->vfront_porch
, dispc
.feat
->fp_start
, 8) |
2963 FLD_VAL(vm
->vback_porch
, dispc
.feat
->bp_start
, 20);
2965 dispc_write_reg(DISPC_TIMING_H(channel
), timing_h
);
2966 dispc_write_reg(DISPC_TIMING_V(channel
), timing_v
);
2968 if (vm
->flags
& DISPLAY_FLAGS_VSYNC_HIGH
)
2973 if (vm
->flags
& DISPLAY_FLAGS_HSYNC_HIGH
)
2978 if (vm
->flags
& DISPLAY_FLAGS_DE_HIGH
)
2983 if (vm
->flags
& DISPLAY_FLAGS_PIXDATA_POSEDGE
)
2988 /* always use the 'rf' setting */
2991 if (vm
->flags
& DISPLAY_FLAGS_SYNC_POSEDGE
)
2996 l
= FLD_VAL(onoff
, 17, 17) |
2997 FLD_VAL(rf
, 16, 16) |
2998 FLD_VAL(de
, 15, 15) |
2999 FLD_VAL(ipc
, 14, 14) |
3000 FLD_VAL(hs
, 13, 13) |
3001 FLD_VAL(vs
, 12, 12);
3003 /* always set ALIGN bit when available */
3004 if (dispc
.feat
->supports_sync_align
)
3007 dispc_write_reg(DISPC_POL_FREQ(channel
), l
);
3009 if (dispc
.syscon_pol
) {
3010 const int shifts
[] = {
3011 [OMAP_DSS_CHANNEL_LCD
] = 0,
3012 [OMAP_DSS_CHANNEL_LCD2
] = 1,
3013 [OMAP_DSS_CHANNEL_LCD3
] = 2,
3018 mask
= (1 << 0) | (1 << 3) | (1 << 6);
3019 val
= (rf
<< 0) | (ipc
<< 3) | (onoff
<< 6);
3021 mask
<<= 16 + shifts
[channel
];
3022 val
<<= 16 + shifts
[channel
];
3024 regmap_update_bits(dispc
.syscon_pol
, dispc
.syscon_pol_offset
,
3029 static int vm_flag_to_int(enum display_flags flags
, enum display_flags high
,
3030 enum display_flags low
)
3039 /* change name to mode? */
3040 static void dispc_mgr_set_timings(enum omap_channel channel
,
3041 const struct videomode
*vm
)
3043 unsigned xtot
, ytot
;
3044 unsigned long ht
, vt
;
3045 struct videomode t
= *vm
;
3047 DSSDBG("channel %d xres %u yres %u\n", channel
, t
.hactive
, t
.vactive
);
3049 if (!dispc_mgr_timings_ok(channel
, &t
)) {
3054 if (dss_mgr_is_lcd(channel
)) {
3055 _dispc_mgr_set_lcd_timings(channel
, &t
);
3057 xtot
= t
.hactive
+ t
.hfront_porch
+ t
.hsync_len
+ t
.hback_porch
;
3058 ytot
= t
.vactive
+ t
.vfront_porch
+ t
.vsync_len
+ t
.vback_porch
;
3060 ht
= vm
->pixelclock
/ xtot
;
3061 vt
= vm
->pixelclock
/ xtot
/ ytot
;
3063 DSSDBG("pck %lu\n", vm
->pixelclock
);
3064 DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
3065 t
.hsync_len
, t
.hfront_porch
, t
.hback_porch
,
3066 t
.vsync_len
, t
.vfront_porch
, t
.vback_porch
);
3067 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3068 vm_flag_to_int(t
.flags
, DISPLAY_FLAGS_VSYNC_HIGH
, DISPLAY_FLAGS_VSYNC_LOW
),
3069 vm_flag_to_int(t
.flags
, DISPLAY_FLAGS_HSYNC_HIGH
, DISPLAY_FLAGS_HSYNC_LOW
),
3070 vm_flag_to_int(t
.flags
, DISPLAY_FLAGS_PIXDATA_POSEDGE
, DISPLAY_FLAGS_PIXDATA_NEGEDGE
),
3071 vm_flag_to_int(t
.flags
, DISPLAY_FLAGS_DE_HIGH
, DISPLAY_FLAGS_DE_LOW
),
3072 vm_flag_to_int(t
.flags
, DISPLAY_FLAGS_SYNC_POSEDGE
, DISPLAY_FLAGS_SYNC_NEGEDGE
));
3074 DSSDBG("hsync %luHz, vsync %luHz\n", ht
, vt
);
3076 if (t
.flags
& DISPLAY_FLAGS_INTERLACED
)
3079 if (dispc
.feat
->supports_double_pixel
)
3080 REG_FLD_MOD(DISPC_CONTROL
,
3081 !!(t
.flags
& DISPLAY_FLAGS_DOUBLECLK
),
3085 dispc_mgr_set_size(channel
, t
.hactive
, t
.vactive
);
3088 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel
, u16 lck_div
,
3091 BUG_ON(lck_div
< 1);
3092 BUG_ON(pck_div
< 1);
3094 dispc_write_reg(DISPC_DIVISORo(channel
),
3095 FLD_VAL(lck_div
, 23, 16) | FLD_VAL(pck_div
, 7, 0));
3097 if (!dispc_has_feature(FEAT_CORE_CLK_DIV
) &&
3098 channel
== OMAP_DSS_CHANNEL_LCD
)
3099 dispc
.core_clk_rate
= dispc_fclk_rate() / lck_div
;
3102 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel
, int *lck_div
,
3106 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3107 *lck_div
= FLD_GET(l
, 23, 16);
3108 *pck_div
= FLD_GET(l
, 7, 0);
3111 static unsigned long dispc_fclk_rate(void)
3114 enum dss_clk_source src
;
3116 src
= dss_get_dispc_clk_source();
3118 if (src
== DSS_CLK_SRC_FCK
) {
3119 r
= dss_get_dispc_clk_rate();
3121 struct dss_pll
*pll
;
3122 unsigned clkout_idx
;
3124 pll
= dss_pll_find_by_src(src
);
3125 clkout_idx
= dss_pll_get_clkout_idx_for_src(src
);
3127 r
= pll
->cinfo
.clkout
[clkout_idx
];
3133 static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel
)
3137 enum dss_clk_source src
;
3139 /* for TV, LCLK rate is the FCLK rate */
3140 if (!dss_mgr_is_lcd(channel
))
3141 return dispc_fclk_rate();
3143 src
= dss_get_lcd_clk_source(channel
);
3145 if (src
== DSS_CLK_SRC_FCK
) {
3146 r
= dss_get_dispc_clk_rate();
3148 struct dss_pll
*pll
;
3149 unsigned clkout_idx
;
3151 pll
= dss_pll_find_by_src(src
);
3152 clkout_idx
= dss_pll_get_clkout_idx_for_src(src
);
3154 r
= pll
->cinfo
.clkout
[clkout_idx
];
3157 lcd
= REG_GET(DISPC_DIVISORo(channel
), 23, 16);
3162 static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel
)
3166 if (dss_mgr_is_lcd(channel
)) {
3170 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3172 pcd
= FLD_GET(l
, 7, 0);
3174 r
= dispc_mgr_lclk_rate(channel
);
3178 return dispc
.tv_pclk_rate
;
3182 void dispc_set_tv_pclk(unsigned long pclk
)
3184 dispc
.tv_pclk_rate
= pclk
;
3187 static unsigned long dispc_core_clk_rate(void)
3189 return dispc
.core_clk_rate
;
3192 static unsigned long dispc_plane_pclk_rate(enum omap_plane_id plane
)
3194 enum omap_channel channel
;
3196 if (plane
== OMAP_DSS_WB
)
3199 channel
= dispc_ovl_get_channel_out(plane
);
3201 return dispc_mgr_pclk_rate(channel
);
3204 static unsigned long dispc_plane_lclk_rate(enum omap_plane_id plane
)
3206 enum omap_channel channel
;
3208 if (plane
== OMAP_DSS_WB
)
3211 channel
= dispc_ovl_get_channel_out(plane
);
3213 return dispc_mgr_lclk_rate(channel
);
3216 static void dispc_dump_clocks_channel(struct seq_file
*s
, enum omap_channel channel
)
3219 enum dss_clk_source lcd_clk_src
;
3221 seq_printf(s
, "- %s -\n", mgr_desc
[channel
].name
);
3223 lcd_clk_src
= dss_get_lcd_clk_source(channel
);
3225 seq_printf(s
, "%s clk source = %s\n", mgr_desc
[channel
].name
,
3226 dss_get_clk_source_name(lcd_clk_src
));
3228 dispc_mgr_get_lcd_divisor(channel
, &lcd
, &pcd
);
3230 seq_printf(s
, "lck\t\t%-16lulck div\t%u\n",
3231 dispc_mgr_lclk_rate(channel
), lcd
);
3232 seq_printf(s
, "pck\t\t%-16lupck div\t%u\n",
3233 dispc_mgr_pclk_rate(channel
), pcd
);
3236 void dispc_dump_clocks(struct seq_file
*s
)
3240 enum dss_clk_source dispc_clk_src
= dss_get_dispc_clk_source();
3242 if (dispc_runtime_get())
3245 seq_printf(s
, "- DISPC -\n");
3247 seq_printf(s
, "dispc fclk source = %s\n",
3248 dss_get_clk_source_name(dispc_clk_src
));
3250 seq_printf(s
, "fck\t\t%-16lu\n", dispc_fclk_rate());
3252 if (dispc_has_feature(FEAT_CORE_CLK_DIV
)) {
3253 seq_printf(s
, "- DISPC-CORE-CLK -\n");
3254 l
= dispc_read_reg(DISPC_DIVISOR
);
3255 lcd
= FLD_GET(l
, 23, 16);
3257 seq_printf(s
, "lck\t\t%-16lulck div\t%u\n",
3258 (dispc_fclk_rate()/lcd
), lcd
);
3261 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD
);
3263 if (dispc_has_feature(FEAT_MGR_LCD2
))
3264 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD2
);
3265 if (dispc_has_feature(FEAT_MGR_LCD3
))
3266 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD3
);
3268 dispc_runtime_put();
3271 static void dispc_dump_regs(struct seq_file
*s
)
3274 const char *mgr_names
[] = {
3275 [OMAP_DSS_CHANNEL_LCD
] = "LCD",
3276 [OMAP_DSS_CHANNEL_DIGIT
] = "TV",
3277 [OMAP_DSS_CHANNEL_LCD2
] = "LCD2",
3278 [OMAP_DSS_CHANNEL_LCD3
] = "LCD3",
3280 const char *ovl_names
[] = {
3281 [OMAP_DSS_GFX
] = "GFX",
3282 [OMAP_DSS_VIDEO1
] = "VID1",
3283 [OMAP_DSS_VIDEO2
] = "VID2",
3284 [OMAP_DSS_VIDEO3
] = "VID3",
3285 [OMAP_DSS_WB
] = "WB",
3287 const char **p_names
;
3289 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3291 if (dispc_runtime_get())
3294 /* DISPC common registers */
3295 DUMPREG(DISPC_REVISION
);
3296 DUMPREG(DISPC_SYSCONFIG
);
3297 DUMPREG(DISPC_SYSSTATUS
);
3298 DUMPREG(DISPC_IRQSTATUS
);
3299 DUMPREG(DISPC_IRQENABLE
);
3300 DUMPREG(DISPC_CONTROL
);
3301 DUMPREG(DISPC_CONFIG
);
3302 DUMPREG(DISPC_CAPABLE
);
3303 DUMPREG(DISPC_LINE_STATUS
);
3304 DUMPREG(DISPC_LINE_NUMBER
);
3305 if (dispc_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
3306 dispc_has_feature(FEAT_ALPHA_FREE_ZORDER
))
3307 DUMPREG(DISPC_GLOBAL_ALPHA
);
3308 if (dispc_has_feature(FEAT_MGR_LCD2
)) {
3309 DUMPREG(DISPC_CONTROL2
);
3310 DUMPREG(DISPC_CONFIG2
);
3312 if (dispc_has_feature(FEAT_MGR_LCD3
)) {
3313 DUMPREG(DISPC_CONTROL3
);
3314 DUMPREG(DISPC_CONFIG3
);
3316 if (dispc_has_feature(FEAT_MFLAG
))
3317 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE
);
3321 #define DISPC_REG(i, name) name(i)
3322 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3323 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
3324 dispc_read_reg(DISPC_REG(i, r)))
3326 p_names
= mgr_names
;
3328 /* DISPC channel specific registers */
3329 for (i
= 0; i
< dispc_get_num_mgrs(); i
++) {
3330 DUMPREG(i
, DISPC_DEFAULT_COLOR
);
3331 DUMPREG(i
, DISPC_TRANS_COLOR
);
3332 DUMPREG(i
, DISPC_SIZE_MGR
);
3334 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
3337 DUMPREG(i
, DISPC_TIMING_H
);
3338 DUMPREG(i
, DISPC_TIMING_V
);
3339 DUMPREG(i
, DISPC_POL_FREQ
);
3340 DUMPREG(i
, DISPC_DIVISORo
);
3342 DUMPREG(i
, DISPC_DATA_CYCLE1
);
3343 DUMPREG(i
, DISPC_DATA_CYCLE2
);
3344 DUMPREG(i
, DISPC_DATA_CYCLE3
);
3346 if (dispc_has_feature(FEAT_CPR
)) {
3347 DUMPREG(i
, DISPC_CPR_COEF_R
);
3348 DUMPREG(i
, DISPC_CPR_COEF_G
);
3349 DUMPREG(i
, DISPC_CPR_COEF_B
);
3353 p_names
= ovl_names
;
3355 for (i
= 0; i
< dispc_get_num_ovls(); i
++) {
3356 DUMPREG(i
, DISPC_OVL_BA0
);
3357 DUMPREG(i
, DISPC_OVL_BA1
);
3358 DUMPREG(i
, DISPC_OVL_POSITION
);
3359 DUMPREG(i
, DISPC_OVL_SIZE
);
3360 DUMPREG(i
, DISPC_OVL_ATTRIBUTES
);
3361 DUMPREG(i
, DISPC_OVL_FIFO_THRESHOLD
);
3362 DUMPREG(i
, DISPC_OVL_FIFO_SIZE_STATUS
);
3363 DUMPREG(i
, DISPC_OVL_ROW_INC
);
3364 DUMPREG(i
, DISPC_OVL_PIXEL_INC
);
3366 if (dispc_has_feature(FEAT_PRELOAD
))
3367 DUMPREG(i
, DISPC_OVL_PRELOAD
);
3368 if (dispc_has_feature(FEAT_MFLAG
))
3369 DUMPREG(i
, DISPC_OVL_MFLAG_THRESHOLD
);
3371 if (i
== OMAP_DSS_GFX
) {
3372 DUMPREG(i
, DISPC_OVL_WINDOW_SKIP
);
3373 DUMPREG(i
, DISPC_OVL_TABLE_BA
);
3377 DUMPREG(i
, DISPC_OVL_FIR
);
3378 DUMPREG(i
, DISPC_OVL_PICTURE_SIZE
);
3379 DUMPREG(i
, DISPC_OVL_ACCU0
);
3380 DUMPREG(i
, DISPC_OVL_ACCU1
);
3381 if (dispc_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3382 DUMPREG(i
, DISPC_OVL_BA0_UV
);
3383 DUMPREG(i
, DISPC_OVL_BA1_UV
);
3384 DUMPREG(i
, DISPC_OVL_FIR2
);
3385 DUMPREG(i
, DISPC_OVL_ACCU2_0
);
3386 DUMPREG(i
, DISPC_OVL_ACCU2_1
);
3388 if (dispc_has_feature(FEAT_ATTR2
))
3389 DUMPREG(i
, DISPC_OVL_ATTRIBUTES2
);
3392 if (dispc
.feat
->has_writeback
) {
3394 DUMPREG(i
, DISPC_OVL_BA0
);
3395 DUMPREG(i
, DISPC_OVL_BA1
);
3396 DUMPREG(i
, DISPC_OVL_SIZE
);
3397 DUMPREG(i
, DISPC_OVL_ATTRIBUTES
);
3398 DUMPREG(i
, DISPC_OVL_FIFO_THRESHOLD
);
3399 DUMPREG(i
, DISPC_OVL_FIFO_SIZE_STATUS
);
3400 DUMPREG(i
, DISPC_OVL_ROW_INC
);
3401 DUMPREG(i
, DISPC_OVL_PIXEL_INC
);
3403 if (dispc_has_feature(FEAT_MFLAG
))
3404 DUMPREG(i
, DISPC_OVL_MFLAG_THRESHOLD
);
3406 DUMPREG(i
, DISPC_OVL_FIR
);
3407 DUMPREG(i
, DISPC_OVL_PICTURE_SIZE
);
3408 DUMPREG(i
, DISPC_OVL_ACCU0
);
3409 DUMPREG(i
, DISPC_OVL_ACCU1
);
3410 if (dispc_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3411 DUMPREG(i
, DISPC_OVL_BA0_UV
);
3412 DUMPREG(i
, DISPC_OVL_BA1_UV
);
3413 DUMPREG(i
, DISPC_OVL_FIR2
);
3414 DUMPREG(i
, DISPC_OVL_ACCU2_0
);
3415 DUMPREG(i
, DISPC_OVL_ACCU2_1
);
3417 if (dispc_has_feature(FEAT_ATTR2
))
3418 DUMPREG(i
, DISPC_OVL_ATTRIBUTES2
);
3424 #define DISPC_REG(plane, name, i) name(plane, i)
3425 #define DUMPREG(plane, name, i) \
3426 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3427 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
3428 dispc_read_reg(DISPC_REG(plane, name, i)))
3430 /* Video pipeline coefficient registers */
3432 /* start from OMAP_DSS_VIDEO1 */
3433 for (i
= 1; i
< dispc_get_num_ovls(); i
++) {
3434 for (j
= 0; j
< 8; j
++)
3435 DUMPREG(i
, DISPC_OVL_FIR_COEF_H
, j
);
3437 for (j
= 0; j
< 8; j
++)
3438 DUMPREG(i
, DISPC_OVL_FIR_COEF_HV
, j
);
3440 for (j
= 0; j
< 5; j
++)
3441 DUMPREG(i
, DISPC_OVL_CONV_COEF
, j
);
3443 if (dispc_has_feature(FEAT_FIR_COEF_V
)) {
3444 for (j
= 0; j
< 8; j
++)
3445 DUMPREG(i
, DISPC_OVL_FIR_COEF_V
, j
);
3448 if (dispc_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3449 for (j
= 0; j
< 8; j
++)
3450 DUMPREG(i
, DISPC_OVL_FIR_COEF_H2
, j
);
3452 for (j
= 0; j
< 8; j
++)
3453 DUMPREG(i
, DISPC_OVL_FIR_COEF_HV2
, j
);
3455 for (j
= 0; j
< 8; j
++)
3456 DUMPREG(i
, DISPC_OVL_FIR_COEF_V2
, j
);
3460 dispc_runtime_put();
3466 /* calculate clock rates using dividers in cinfo */
3467 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate
,
3468 struct dispc_clock_info
*cinfo
)
3470 if (cinfo
->lck_div
> 255 || cinfo
->lck_div
== 0)
3472 if (cinfo
->pck_div
< 1 || cinfo
->pck_div
> 255)
3475 cinfo
->lck
= dispc_fclk_rate
/ cinfo
->lck_div
;
3476 cinfo
->pck
= cinfo
->lck
/ cinfo
->pck_div
;
3481 bool dispc_div_calc(unsigned long dispc_freq
,
3482 unsigned long pck_min
, unsigned long pck_max
,
3483 dispc_div_calc_func func
, void *data
)
3485 int lckd
, lckd_start
, lckd_stop
;
3486 int pckd
, pckd_start
, pckd_stop
;
3487 unsigned long pck
, lck
;
3488 unsigned long lck_max
;
3489 unsigned long pckd_hw_min
, pckd_hw_max
;
3490 unsigned min_fck_per_pck
;
3493 #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3494 min_fck_per_pck
= CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
;
3496 min_fck_per_pck
= 0;
3499 pckd_hw_min
= dispc
.feat
->min_pcd
;
3502 lck_max
= dss_get_max_fck_rate();
3504 pck_min
= pck_min
? pck_min
: 1;
3505 pck_max
= pck_max
? pck_max
: ULONG_MAX
;
3507 lckd_start
= max(DIV_ROUND_UP(dispc_freq
, lck_max
), 1ul);
3508 lckd_stop
= min(dispc_freq
/ pck_min
, 255ul);
3510 for (lckd
= lckd_start
; lckd
<= lckd_stop
; ++lckd
) {
3511 lck
= dispc_freq
/ lckd
;
3513 pckd_start
= max(DIV_ROUND_UP(lck
, pck_max
), pckd_hw_min
);
3514 pckd_stop
= min(lck
/ pck_min
, pckd_hw_max
);
3516 for (pckd
= pckd_start
; pckd
<= pckd_stop
; ++pckd
) {
3520 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3521 * clock, which means we're configuring DISPC fclk here
3522 * also. Thus we need to use the calculated lck. For
3523 * OMAP4+ the DISPC fclk is a separate clock.
3525 if (dispc_has_feature(FEAT_CORE_CLK_DIV
))
3526 fck
= dispc_core_clk_rate();
3530 if (fck
< pck
* min_fck_per_pck
)
3533 if (func(lckd
, pckd
, lck
, pck
, data
))
3541 void dispc_mgr_set_clock_div(enum omap_channel channel
,
3542 const struct dispc_clock_info
*cinfo
)
3544 DSSDBG("lck = %lu (%u)\n", cinfo
->lck
, cinfo
->lck_div
);
3545 DSSDBG("pck = %lu (%u)\n", cinfo
->pck
, cinfo
->pck_div
);
3547 dispc_mgr_set_lcd_divisor(channel
, cinfo
->lck_div
, cinfo
->pck_div
);
3550 int dispc_mgr_get_clock_div(enum omap_channel channel
,
3551 struct dispc_clock_info
*cinfo
)
3555 fck
= dispc_fclk_rate();
3557 cinfo
->lck_div
= REG_GET(DISPC_DIVISORo(channel
), 23, 16);
3558 cinfo
->pck_div
= REG_GET(DISPC_DIVISORo(channel
), 7, 0);
3560 cinfo
->lck
= fck
/ cinfo
->lck_div
;
3561 cinfo
->pck
= cinfo
->lck
/ cinfo
->pck_div
;
3566 static u32
dispc_read_irqstatus(void)
3568 return dispc_read_reg(DISPC_IRQSTATUS
);
3571 static void dispc_clear_irqstatus(u32 mask
)
3573 dispc_write_reg(DISPC_IRQSTATUS
, mask
);
3576 static void dispc_write_irqenable(u32 mask
)
3578 u32 old_mask
= dispc_read_reg(DISPC_IRQENABLE
);
3580 /* clear the irqstatus for newly enabled irqs */
3581 dispc_clear_irqstatus((mask
^ old_mask
) & mask
);
3583 dispc_write_reg(DISPC_IRQENABLE
, mask
);
3585 /* flush posted write */
3586 dispc_read_reg(DISPC_IRQENABLE
);
3589 void dispc_enable_sidle(void)
3591 REG_FLD_MOD(DISPC_SYSCONFIG
, 2, 4, 3); /* SIDLEMODE: smart idle */
3594 void dispc_disable_sidle(void)
3596 REG_FLD_MOD(DISPC_SYSCONFIG
, 1, 4, 3); /* SIDLEMODE: no idle */
3599 static u32
dispc_mgr_gamma_size(enum omap_channel channel
)
3601 const struct dispc_gamma_desc
*gdesc
= &mgr_desc
[channel
].gamma
;
3603 if (!dispc
.feat
->has_gamma_table
)
3609 static void dispc_mgr_write_gamma_table(enum omap_channel channel
)
3611 const struct dispc_gamma_desc
*gdesc
= &mgr_desc
[channel
].gamma
;
3612 u32
*table
= dispc
.gamma_table
[channel
];
3615 DSSDBG("%s: channel %d\n", __func__
, channel
);
3617 for (i
= 0; i
< gdesc
->len
; ++i
) {
3620 if (gdesc
->has_index
)
3625 dispc_write_reg(gdesc
->reg
, v
);
3629 static void dispc_restore_gamma_tables(void)
3631 DSSDBG("%s()\n", __func__
);
3633 if (!dispc
.feat
->has_gamma_table
)
3636 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD
);
3638 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_DIGIT
);
3640 if (dispc_has_feature(FEAT_MGR_LCD2
))
3641 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD2
);
3643 if (dispc_has_feature(FEAT_MGR_LCD3
))
3644 dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD3
);
3647 static const struct drm_color_lut dispc_mgr_gamma_default_lut
[] = {
3648 { .red
= 0, .green
= 0, .blue
= 0, },
3649 { .red
= U16_MAX
, .green
= U16_MAX
, .blue
= U16_MAX
, },
3652 static void dispc_mgr_set_gamma(enum omap_channel channel
,
3653 const struct drm_color_lut
*lut
,
3654 unsigned int length
)
3656 const struct dispc_gamma_desc
*gdesc
= &mgr_desc
[channel
].gamma
;
3657 u32
*table
= dispc
.gamma_table
[channel
];
3660 DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__
,
3661 channel
, length
, gdesc
->len
);
3663 if (!dispc
.feat
->has_gamma_table
)
3666 if (lut
== NULL
|| length
< 2) {
3667 lut
= dispc_mgr_gamma_default_lut
;
3668 length
= ARRAY_SIZE(dispc_mgr_gamma_default_lut
);
3671 for (i
= 0; i
< length
- 1; ++i
) {
3672 uint first
= i
* (gdesc
->len
- 1) / (length
- 1);
3673 uint last
= (i
+ 1) * (gdesc
->len
- 1) / (length
- 1);
3674 uint w
= last
- first
;
3681 for (j
= 0; j
<= w
; j
++) {
3682 r
= (lut
[i
].red
* (w
- j
) + lut
[i
+1].red
* j
) / w
;
3683 g
= (lut
[i
].green
* (w
- j
) + lut
[i
+1].green
* j
) / w
;
3684 b
= (lut
[i
].blue
* (w
- j
) + lut
[i
+1].blue
* j
) / w
;
3686 r
>>= 16 - gdesc
->bits
;
3687 g
>>= 16 - gdesc
->bits
;
3688 b
>>= 16 - gdesc
->bits
;
3690 table
[first
+ j
] = (r
<< (gdesc
->bits
* 2)) |
3691 (g
<< gdesc
->bits
) | b
;
3695 if (dispc
.is_enabled
)
3696 dispc_mgr_write_gamma_table(channel
);
3699 static int dispc_init_gamma_tables(void)
3703 if (!dispc
.feat
->has_gamma_table
)
3706 for (channel
= 0; channel
< ARRAY_SIZE(dispc
.gamma_table
); channel
++) {
3707 const struct dispc_gamma_desc
*gdesc
= &mgr_desc
[channel
].gamma
;
3710 if (channel
== OMAP_DSS_CHANNEL_LCD2
&&
3711 !dispc_has_feature(FEAT_MGR_LCD2
))
3714 if (channel
== OMAP_DSS_CHANNEL_LCD3
&&
3715 !dispc_has_feature(FEAT_MGR_LCD3
))
3718 gt
= devm_kmalloc_array(&dispc
.pdev
->dev
, gdesc
->len
,
3719 sizeof(u32
), GFP_KERNEL
);
3723 dispc
.gamma_table
[channel
] = gt
;
3725 dispc_mgr_set_gamma(channel
, NULL
, 0);
3730 static void _omap_dispc_initial_config(void)
3734 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3735 if (dispc_has_feature(FEAT_CORE_CLK_DIV
)) {
3736 l
= dispc_read_reg(DISPC_DIVISOR
);
3737 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3738 l
= FLD_MOD(l
, 1, 0, 0);
3739 l
= FLD_MOD(l
, 1, 23, 16);
3740 dispc_write_reg(DISPC_DIVISOR
, l
);
3742 dispc
.core_clk_rate
= dispc_fclk_rate();
3745 /* Use gamma table mode, instead of palette mode */
3746 if (dispc
.feat
->has_gamma_table
)
3747 REG_FLD_MOD(DISPC_CONFIG
, 1, 3, 3);
3749 /* For older DSS versions (FEAT_FUNCGATED) this enables
3750 * func-clock auto-gating. For newer versions
3751 * (dispc.feat->has_gamma_table) this enables tv-out gamma tables.
3753 if (dispc_has_feature(FEAT_FUNCGATED
) || dispc
.feat
->has_gamma_table
)
3754 REG_FLD_MOD(DISPC_CONFIG
, 1, 9, 9);
3756 dispc_setup_color_conv_coef();
3758 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY
);
3762 dispc_configure_burst_sizes();
3764 dispc_ovl_enable_zorder_planes();
3766 if (dispc
.feat
->mstandby_workaround
)
3767 REG_FLD_MOD(DISPC_MSTANDBY_CTRL
, 1, 0, 0);
3769 if (dispc_has_feature(FEAT_MFLAG
))
3773 static const enum dispc_feature_id omap2_dispc_features_list
[] = {
3775 FEAT_LCDENABLESIGNAL
,
3778 FEAT_ROWREPEATENABLE
,
3782 static const enum dispc_feature_id omap3_dispc_features_list
[] = {
3784 FEAT_LCDENABLESIGNAL
,
3787 FEAT_LINEBUFFERSPLIT
,
3788 FEAT_ROWREPEATENABLE
,
3793 FEAT_ALPHA_FIXED_ZORDER
,
3795 FEAT_OMAP3_DSI_FIFO_BUG
,
3798 static const enum dispc_feature_id am43xx_dispc_features_list
[] = {
3800 FEAT_LCDENABLESIGNAL
,
3803 FEAT_LINEBUFFERSPLIT
,
3804 FEAT_ROWREPEATENABLE
,
3809 FEAT_ALPHA_FIXED_ZORDER
,
3813 static const enum dispc_feature_id omap4_dispc_features_list
[] = {
3816 FEAT_HANDLE_UV_SEPARATE
,
3821 FEAT_ALPHA_FREE_ZORDER
,
3826 static const enum dispc_feature_id omap5_dispc_features_list
[] = {
3830 FEAT_HANDLE_UV_SEPARATE
,
3835 FEAT_ALPHA_FREE_ZORDER
,
3841 static const struct dss_reg_field omap2_dispc_reg_fields
[] = {
3842 [FEAT_REG_FIRHINC
] = { 11, 0 },
3843 [FEAT_REG_FIRVINC
] = { 27, 16 },
3844 [FEAT_REG_FIFOLOWTHRESHOLD
] = { 8, 0 },
3845 [FEAT_REG_FIFOHIGHTHRESHOLD
] = { 24, 16 },
3846 [FEAT_REG_FIFOSIZE
] = { 8, 0 },
3847 [FEAT_REG_HORIZONTALACCU
] = { 9, 0 },
3848 [FEAT_REG_VERTICALACCU
] = { 25, 16 },
3851 static const struct dss_reg_field omap3_dispc_reg_fields
[] = {
3852 [FEAT_REG_FIRHINC
] = { 12, 0 },
3853 [FEAT_REG_FIRVINC
] = { 28, 16 },
3854 [FEAT_REG_FIFOLOWTHRESHOLD
] = { 11, 0 },
3855 [FEAT_REG_FIFOHIGHTHRESHOLD
] = { 27, 16 },
3856 [FEAT_REG_FIFOSIZE
] = { 10, 0 },
3857 [FEAT_REG_HORIZONTALACCU
] = { 9, 0 },
3858 [FEAT_REG_VERTICALACCU
] = { 25, 16 },
3861 static const struct dss_reg_field omap4_dispc_reg_fields
[] = {
3862 [FEAT_REG_FIRHINC
] = { 12, 0 },
3863 [FEAT_REG_FIRVINC
] = { 28, 16 },
3864 [FEAT_REG_FIFOLOWTHRESHOLD
] = { 15, 0 },
3865 [FEAT_REG_FIFOHIGHTHRESHOLD
] = { 31, 16 },
3866 [FEAT_REG_FIFOSIZE
] = { 15, 0 },
3867 [FEAT_REG_HORIZONTALACCU
] = { 10, 0 },
3868 [FEAT_REG_VERTICALACCU
] = { 26, 16 },
3871 static const enum omap_overlay_caps omap2_dispc_overlay_caps
[] = {
3873 OMAP_DSS_OVL_CAP_POS
| OMAP_DSS_OVL_CAP_REPLICATION
,
3875 /* OMAP_DSS_VIDEO1 */
3876 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_POS
|
3877 OMAP_DSS_OVL_CAP_REPLICATION
,
3879 /* OMAP_DSS_VIDEO2 */
3880 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_POS
|
3881 OMAP_DSS_OVL_CAP_REPLICATION
,
3884 static const enum omap_overlay_caps omap3430_dispc_overlay_caps
[] = {
3886 OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
| OMAP_DSS_OVL_CAP_POS
|
3887 OMAP_DSS_OVL_CAP_REPLICATION
,
3889 /* OMAP_DSS_VIDEO1 */
3890 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_POS
|
3891 OMAP_DSS_OVL_CAP_REPLICATION
,
3893 /* OMAP_DSS_VIDEO2 */
3894 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
|
3895 OMAP_DSS_OVL_CAP_POS
| OMAP_DSS_OVL_CAP_REPLICATION
,
3898 static const enum omap_overlay_caps omap3630_dispc_overlay_caps
[] = {
3900 OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
| OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
|
3901 OMAP_DSS_OVL_CAP_POS
| OMAP_DSS_OVL_CAP_REPLICATION
,
3903 /* OMAP_DSS_VIDEO1 */
3904 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_POS
|
3905 OMAP_DSS_OVL_CAP_REPLICATION
,
3907 /* OMAP_DSS_VIDEO2 */
3908 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
|
3909 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
| OMAP_DSS_OVL_CAP_POS
|
3910 OMAP_DSS_OVL_CAP_REPLICATION
,
3913 static const enum omap_overlay_caps omap4_dispc_overlay_caps
[] = {
3915 OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
| OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
|
3916 OMAP_DSS_OVL_CAP_ZORDER
| OMAP_DSS_OVL_CAP_POS
|
3917 OMAP_DSS_OVL_CAP_REPLICATION
,
3919 /* OMAP_DSS_VIDEO1 */
3920 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
|
3921 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
| OMAP_DSS_OVL_CAP_ZORDER
|
3922 OMAP_DSS_OVL_CAP_POS
| OMAP_DSS_OVL_CAP_REPLICATION
,
3924 /* OMAP_DSS_VIDEO2 */
3925 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
|
3926 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
| OMAP_DSS_OVL_CAP_ZORDER
|
3927 OMAP_DSS_OVL_CAP_POS
| OMAP_DSS_OVL_CAP_REPLICATION
,
3929 /* OMAP_DSS_VIDEO3 */
3930 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
|
3931 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
| OMAP_DSS_OVL_CAP_ZORDER
|
3932 OMAP_DSS_OVL_CAP_POS
| OMAP_DSS_OVL_CAP_REPLICATION
,
3935 #define COLOR_ARRAY(arr...) (const u32[]) { arr, 0 }
3937 static const u32
*omap2_dispc_supported_color_modes
[] = {
3941 DRM_FORMAT_RGBX4444
, DRM_FORMAT_RGB565
,
3942 DRM_FORMAT_XRGB8888
, DRM_FORMAT_RGB888
),
3944 /* OMAP_DSS_VIDEO1 */
3946 DRM_FORMAT_RGB565
, DRM_FORMAT_XRGB8888
,
3947 DRM_FORMAT_RGB888
, DRM_FORMAT_YUYV
,
3950 /* OMAP_DSS_VIDEO2 */
3952 DRM_FORMAT_RGB565
, DRM_FORMAT_XRGB8888
,
3953 DRM_FORMAT_RGB888
, DRM_FORMAT_YUYV
,
3957 static const u32
*omap3_dispc_supported_color_modes
[] = {
3960 DRM_FORMAT_RGBX4444
, DRM_FORMAT_ARGB4444
,
3961 DRM_FORMAT_RGB565
, DRM_FORMAT_XRGB8888
,
3962 DRM_FORMAT_RGB888
, DRM_FORMAT_ARGB8888
,
3963 DRM_FORMAT_RGBA8888
, DRM_FORMAT_RGBX8888
),
3965 /* OMAP_DSS_VIDEO1 */
3967 DRM_FORMAT_XRGB8888
, DRM_FORMAT_RGB888
,
3968 DRM_FORMAT_RGBX4444
, DRM_FORMAT_RGB565
,
3969 DRM_FORMAT_YUYV
, DRM_FORMAT_UYVY
),
3971 /* OMAP_DSS_VIDEO2 */
3973 DRM_FORMAT_RGBX4444
, DRM_FORMAT_ARGB4444
,
3974 DRM_FORMAT_RGB565
, DRM_FORMAT_XRGB8888
,
3975 DRM_FORMAT_RGB888
, DRM_FORMAT_YUYV
,
3976 DRM_FORMAT_UYVY
, DRM_FORMAT_ARGB8888
,
3977 DRM_FORMAT_RGBA8888
, DRM_FORMAT_RGBX8888
),
3980 static const u32
*omap4_dispc_supported_color_modes
[] = {
3983 DRM_FORMAT_RGBX4444
, DRM_FORMAT_ARGB4444
,
3984 DRM_FORMAT_RGB565
, DRM_FORMAT_XRGB8888
,
3985 DRM_FORMAT_RGB888
, DRM_FORMAT_ARGB8888
,
3986 DRM_FORMAT_RGBA8888
, DRM_FORMAT_RGBX8888
,
3987 DRM_FORMAT_ARGB1555
, DRM_FORMAT_XRGB4444
,
3988 DRM_FORMAT_RGBA4444
, DRM_FORMAT_XRGB1555
),
3990 /* OMAP_DSS_VIDEO1 */
3992 DRM_FORMAT_RGB565
, DRM_FORMAT_RGBX4444
,
3993 DRM_FORMAT_YUYV
, DRM_FORMAT_ARGB1555
,
3994 DRM_FORMAT_RGBA8888
, DRM_FORMAT_NV12
,
3995 DRM_FORMAT_RGBA4444
, DRM_FORMAT_XRGB8888
,
3996 DRM_FORMAT_RGB888
, DRM_FORMAT_UYVY
,
3997 DRM_FORMAT_ARGB4444
, DRM_FORMAT_XRGB1555
,
3998 DRM_FORMAT_ARGB8888
, DRM_FORMAT_XRGB4444
,
3999 DRM_FORMAT_RGBX8888
),
4001 /* OMAP_DSS_VIDEO2 */
4003 DRM_FORMAT_RGB565
, DRM_FORMAT_RGBX4444
,
4004 DRM_FORMAT_YUYV
, DRM_FORMAT_ARGB1555
,
4005 DRM_FORMAT_RGBA8888
, DRM_FORMAT_NV12
,
4006 DRM_FORMAT_RGBA4444
, DRM_FORMAT_XRGB8888
,
4007 DRM_FORMAT_RGB888
, DRM_FORMAT_UYVY
,
4008 DRM_FORMAT_ARGB4444
, DRM_FORMAT_XRGB1555
,
4009 DRM_FORMAT_ARGB8888
, DRM_FORMAT_XRGB4444
,
4010 DRM_FORMAT_RGBX8888
),
4012 /* OMAP_DSS_VIDEO3 */
4014 DRM_FORMAT_RGB565
, DRM_FORMAT_RGBX4444
,
4015 DRM_FORMAT_YUYV
, DRM_FORMAT_ARGB1555
,
4016 DRM_FORMAT_RGBA8888
, DRM_FORMAT_NV12
,
4017 DRM_FORMAT_RGBA4444
, DRM_FORMAT_XRGB8888
,
4018 DRM_FORMAT_RGB888
, DRM_FORMAT_UYVY
,
4019 DRM_FORMAT_ARGB4444
, DRM_FORMAT_XRGB1555
,
4020 DRM_FORMAT_ARGB8888
, DRM_FORMAT_XRGB4444
,
4021 DRM_FORMAT_RGBX8888
),
4025 DRM_FORMAT_RGB565
, DRM_FORMAT_RGBX4444
,
4026 DRM_FORMAT_YUYV
, DRM_FORMAT_ARGB1555
,
4027 DRM_FORMAT_RGBA8888
, DRM_FORMAT_NV12
,
4028 DRM_FORMAT_RGBA4444
, DRM_FORMAT_XRGB8888
,
4029 DRM_FORMAT_RGB888
, DRM_FORMAT_UYVY
,
4030 DRM_FORMAT_ARGB4444
, DRM_FORMAT_XRGB1555
,
4031 DRM_FORMAT_ARGB8888
, DRM_FORMAT_XRGB4444
,
4032 DRM_FORMAT_RGBX8888
),
4035 static const struct dispc_features omap24xx_dispc_feats
= {
4042 .mgr_width_start
= 10,
4043 .mgr_height_start
= 26,
4044 .mgr_width_max
= 2048,
4045 .mgr_height_max
= 2048,
4046 .max_lcd_pclk
= 66500000,
4049 * Assume the line width buffer to be 768 pixels as OMAP2 DISPC scaler
4050 * cannot scale an image width larger than 768.
4052 .max_line_width
= 768,
4054 .calc_scaling
= dispc_ovl_calc_scaling_24xx
,
4055 .calc_core_clk
= calc_core_clk_24xx
,
4057 .features
= omap2_dispc_features_list
,
4058 .num_features
= ARRAY_SIZE(omap2_dispc_features_list
),
4059 .reg_fields
= omap2_dispc_reg_fields
,
4060 .num_reg_fields
= ARRAY_SIZE(omap2_dispc_reg_fields
),
4061 .overlay_caps
= omap2_dispc_overlay_caps
,
4062 .supported_color_modes
= omap2_dispc_supported_color_modes
,
4065 .buffer_size_unit
= 1,
4066 .burst_size_unit
= 8,
4067 .no_framedone_tv
= true,
4068 .set_max_preload
= false,
4069 .last_pixel_inc_missing
= true,
4072 static const struct dispc_features omap34xx_rev1_0_dispc_feats
= {
4079 .mgr_width_start
= 10,
4080 .mgr_height_start
= 26,
4081 .mgr_width_max
= 2048,
4082 .mgr_height_max
= 2048,
4083 .max_lcd_pclk
= 173000000,
4084 .max_tv_pclk
= 59000000,
4086 .max_line_width
= 1024,
4088 .calc_scaling
= dispc_ovl_calc_scaling_34xx
,
4089 .calc_core_clk
= calc_core_clk_34xx
,
4091 .features
= omap3_dispc_features_list
,
4092 .num_features
= ARRAY_SIZE(omap3_dispc_features_list
),
4093 .reg_fields
= omap3_dispc_reg_fields
,
4094 .num_reg_fields
= ARRAY_SIZE(omap3_dispc_reg_fields
),
4095 .overlay_caps
= omap3430_dispc_overlay_caps
,
4096 .supported_color_modes
= omap3_dispc_supported_color_modes
,
4099 .buffer_size_unit
= 1,
4100 .burst_size_unit
= 8,
4101 .no_framedone_tv
= true,
4102 .set_max_preload
= false,
4103 .last_pixel_inc_missing
= true,
4106 static const struct dispc_features omap34xx_rev3_0_dispc_feats
= {
4113 .mgr_width_start
= 10,
4114 .mgr_height_start
= 26,
4115 .mgr_width_max
= 2048,
4116 .mgr_height_max
= 2048,
4117 .max_lcd_pclk
= 173000000,
4118 .max_tv_pclk
= 59000000,
4120 .max_line_width
= 1024,
4122 .calc_scaling
= dispc_ovl_calc_scaling_34xx
,
4123 .calc_core_clk
= calc_core_clk_34xx
,
4125 .features
= omap3_dispc_features_list
,
4126 .num_features
= ARRAY_SIZE(omap3_dispc_features_list
),
4127 .reg_fields
= omap3_dispc_reg_fields
,
4128 .num_reg_fields
= ARRAY_SIZE(omap3_dispc_reg_fields
),
4129 .overlay_caps
= omap3430_dispc_overlay_caps
,
4130 .supported_color_modes
= omap3_dispc_supported_color_modes
,
4133 .buffer_size_unit
= 1,
4134 .burst_size_unit
= 8,
4135 .no_framedone_tv
= true,
4136 .set_max_preload
= false,
4137 .last_pixel_inc_missing
= true,
4140 static const struct dispc_features omap36xx_dispc_feats
= {
4147 .mgr_width_start
= 10,
4148 .mgr_height_start
= 26,
4149 .mgr_width_max
= 2048,
4150 .mgr_height_max
= 2048,
4151 .max_lcd_pclk
= 173000000,
4152 .max_tv_pclk
= 59000000,
4154 .max_line_width
= 1024,
4156 .calc_scaling
= dispc_ovl_calc_scaling_34xx
,
4157 .calc_core_clk
= calc_core_clk_34xx
,
4159 .features
= omap3_dispc_features_list
,
4160 .num_features
= ARRAY_SIZE(omap3_dispc_features_list
),
4161 .reg_fields
= omap3_dispc_reg_fields
,
4162 .num_reg_fields
= ARRAY_SIZE(omap3_dispc_reg_fields
),
4163 .overlay_caps
= omap3630_dispc_overlay_caps
,
4164 .supported_color_modes
= omap3_dispc_supported_color_modes
,
4167 .buffer_size_unit
= 1,
4168 .burst_size_unit
= 8,
4169 .no_framedone_tv
= true,
4170 .set_max_preload
= false,
4171 .last_pixel_inc_missing
= true,
4174 static const struct dispc_features am43xx_dispc_feats
= {
4181 .mgr_width_start
= 10,
4182 .mgr_height_start
= 26,
4183 .mgr_width_max
= 2048,
4184 .mgr_height_max
= 2048,
4185 .max_lcd_pclk
= 173000000,
4186 .max_tv_pclk
= 59000000,
4188 .max_line_width
= 1024,
4190 .calc_scaling
= dispc_ovl_calc_scaling_34xx
,
4191 .calc_core_clk
= calc_core_clk_34xx
,
4193 .features
= am43xx_dispc_features_list
,
4194 .num_features
= ARRAY_SIZE(am43xx_dispc_features_list
),
4195 .reg_fields
= omap3_dispc_reg_fields
,
4196 .num_reg_fields
= ARRAY_SIZE(omap3_dispc_reg_fields
),
4197 .overlay_caps
= omap3430_dispc_overlay_caps
,
4198 .supported_color_modes
= omap3_dispc_supported_color_modes
,
4201 .buffer_size_unit
= 1,
4202 .burst_size_unit
= 8,
4203 .no_framedone_tv
= true,
4204 .set_max_preload
= false,
4205 .last_pixel_inc_missing
= true,
4208 static const struct dispc_features omap44xx_dispc_feats
= {
4215 .mgr_width_start
= 10,
4216 .mgr_height_start
= 26,
4217 .mgr_width_max
= 2048,
4218 .mgr_height_max
= 2048,
4219 .max_lcd_pclk
= 170000000,
4220 .max_tv_pclk
= 185625000,
4222 .max_line_width
= 2048,
4224 .calc_scaling
= dispc_ovl_calc_scaling_44xx
,
4225 .calc_core_clk
= calc_core_clk_44xx
,
4227 .features
= omap4_dispc_features_list
,
4228 .num_features
= ARRAY_SIZE(omap4_dispc_features_list
),
4229 .reg_fields
= omap4_dispc_reg_fields
,
4230 .num_reg_fields
= ARRAY_SIZE(omap4_dispc_reg_fields
),
4231 .overlay_caps
= omap4_dispc_overlay_caps
,
4232 .supported_color_modes
= omap4_dispc_supported_color_modes
,
4235 .buffer_size_unit
= 16,
4236 .burst_size_unit
= 16,
4237 .gfx_fifo_workaround
= true,
4238 .set_max_preload
= true,
4239 .supports_sync_align
= true,
4240 .has_writeback
= true,
4241 .supports_double_pixel
= true,
4242 .reverse_ilace_field_order
= true,
4243 .has_gamma_table
= true,
4244 .has_gamma_i734_bug
= true,
4247 static const struct dispc_features omap54xx_dispc_feats
= {
4254 .mgr_width_start
= 11,
4255 .mgr_height_start
= 27,
4256 .mgr_width_max
= 4096,
4257 .mgr_height_max
= 4096,
4258 .max_lcd_pclk
= 170000000,
4259 .max_tv_pclk
= 186000000,
4261 .max_line_width
= 2048,
4263 .calc_scaling
= dispc_ovl_calc_scaling_44xx
,
4264 .calc_core_clk
= calc_core_clk_44xx
,
4266 .features
= omap5_dispc_features_list
,
4267 .num_features
= ARRAY_SIZE(omap5_dispc_features_list
),
4268 .reg_fields
= omap4_dispc_reg_fields
,
4269 .num_reg_fields
= ARRAY_SIZE(omap4_dispc_reg_fields
),
4270 .overlay_caps
= omap4_dispc_overlay_caps
,
4271 .supported_color_modes
= omap4_dispc_supported_color_modes
,
4274 .buffer_size_unit
= 16,
4275 .burst_size_unit
= 16,
4276 .gfx_fifo_workaround
= true,
4277 .mstandby_workaround
= true,
4278 .set_max_preload
= true,
4279 .supports_sync_align
= true,
4280 .has_writeback
= true,
4281 .supports_double_pixel
= true,
4282 .reverse_ilace_field_order
= true,
4283 .has_gamma_table
= true,
4284 .has_gamma_i734_bug
= true,
4287 static irqreturn_t
dispc_irq_handler(int irq
, void *arg
)
4289 if (!dispc
.is_enabled
)
4292 return dispc
.user_handler(irq
, dispc
.user_data
);
4295 static int dispc_request_irq(irq_handler_t handler
, void *dev_id
)
4299 if (dispc
.user_handler
!= NULL
)
4302 dispc
.user_handler
= handler
;
4303 dispc
.user_data
= dev_id
;
4305 /* ensure the dispc_irq_handler sees the values above */
4308 r
= devm_request_irq(&dispc
.pdev
->dev
, dispc
.irq
, dispc_irq_handler
,
4309 IRQF_SHARED
, "OMAP DISPC", &dispc
);
4311 dispc
.user_handler
= NULL
;
4312 dispc
.user_data
= NULL
;
4318 static void dispc_free_irq(void *dev_id
)
4320 devm_free_irq(&dispc
.pdev
->dev
, dispc
.irq
, &dispc
);
4322 dispc
.user_handler
= NULL
;
4323 dispc
.user_data
= NULL
;
4326 static u32
dispc_get_memory_bandwidth_limit(void)
4330 /* Optional maximum memory bandwidth */
4331 of_property_read_u32(dispc
.pdev
->dev
.of_node
, "max-memory-bandwidth",
4338 * Workaround for errata i734 in DSS dispc
4339 * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
4341 * For gamma tables to work on LCD1 the GFX plane has to be used at
4342 * least once after DSS HW has come out of reset. The workaround
4343 * sets up a minimal LCD setup with GFX plane and waits for one
4344 * vertical sync irq before disabling the setup and continuing with
4345 * the context restore. The physical outputs are gated during the
4346 * operation. This workaround requires that gamma table's LOADMODE
4347 * is set to 0x2 in DISPC_CONTROL1 register.
4350 * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
4351 * Literature Number: SWPZ037E
4352 * Or some other relevant errata document for the DSS IP version.
4355 static const struct dispc_errata_i734_data
{
4356 struct videomode vm
;
4357 struct omap_overlay_info ovli
;
4358 struct omap_overlay_manager_info mgri
;
4359 struct dss_lcd_mgr_config lcd_conf
;
4362 .hactive
= 8, .vactive
= 1,
4363 .pixelclock
= 16000000,
4364 .hsync_len
= 8, .hfront_porch
= 4, .hback_porch
= 4,
4365 .vsync_len
= 1, .vfront_porch
= 1, .vback_porch
= 1,
4367 .flags
= DISPLAY_FLAGS_HSYNC_LOW
| DISPLAY_FLAGS_VSYNC_LOW
|
4368 DISPLAY_FLAGS_DE_HIGH
| DISPLAY_FLAGS_SYNC_POSEDGE
|
4369 DISPLAY_FLAGS_PIXDATA_POSEDGE
,
4373 .width
= 1, .height
= 1,
4374 .fourcc
= DRM_FORMAT_XRGB8888
,
4375 .rotation
= DRM_MODE_ROTATE_0
,
4376 .rotation_type
= OMAP_DSS_ROT_NONE
,
4377 .pos_x
= 0, .pos_y
= 0,
4378 .out_width
= 0, .out_height
= 0,
4379 .global_alpha
= 0xff,
4380 .pre_mult_alpha
= 0,
4385 .trans_enabled
= false,
4386 .partial_alpha_enabled
= false,
4387 .cpr_enable
= false,
4390 .io_pad_mode
= DSS_IO_PAD_MODE_BYPASS
,
4392 .fifohandcheck
= false,
4397 .video_port_width
= 24,
4398 .lcden_sig_polarity
= 0,
4402 static struct i734_buf
{
4408 static int dispc_errata_i734_wa_init(void)
4410 if (!dispc
.feat
->has_gamma_i734_bug
)
4413 i734_buf
.size
= i734
.ovli
.width
* i734
.ovli
.height
*
4414 color_mode_to_bpp(i734
.ovli
.fourcc
) / 8;
4416 i734_buf
.vaddr
= dma_alloc_writecombine(&dispc
.pdev
->dev
, i734_buf
.size
,
4417 &i734_buf
.paddr
, GFP_KERNEL
);
4418 if (!i734_buf
.vaddr
) {
4419 dev_err(&dispc
.pdev
->dev
, "%s: dma_alloc_writecombine failed",
4427 static void dispc_errata_i734_wa_fini(void)
4429 if (!dispc
.feat
->has_gamma_i734_bug
)
4432 dma_free_writecombine(&dispc
.pdev
->dev
, i734_buf
.size
, i734_buf
.vaddr
,
4436 static void dispc_errata_i734_wa(void)
4438 u32 framedone_irq
= dispc_mgr_get_framedone_irq(OMAP_DSS_CHANNEL_LCD
);
4439 struct omap_overlay_info ovli
;
4440 struct dss_lcd_mgr_config lcd_conf
;
4444 if (!dispc
.feat
->has_gamma_i734_bug
)
4447 gatestate
= REG_GET(DISPC_CONFIG
, 8, 4);
4450 ovli
.paddr
= i734_buf
.paddr
;
4451 lcd_conf
= i734
.lcd_conf
;
4453 /* Gate all LCD1 outputs */
4454 REG_FLD_MOD(DISPC_CONFIG
, 0x1f, 8, 4);
4456 /* Setup and enable GFX plane */
4457 dispc_ovl_setup(OMAP_DSS_GFX
, &ovli
, &i734
.vm
, false,
4458 OMAP_DSS_CHANNEL_LCD
);
4459 dispc_ovl_enable(OMAP_DSS_GFX
, true);
4461 /* Set up and enable display manager for LCD1 */
4462 dispc_mgr_setup(OMAP_DSS_CHANNEL_LCD
, &i734
.mgri
);
4463 dispc_calc_clock_rates(dss_get_dispc_clk_rate(),
4464 &lcd_conf
.clock_info
);
4465 dispc_mgr_set_lcd_config(OMAP_DSS_CHANNEL_LCD
, &lcd_conf
);
4466 dispc_mgr_set_timings(OMAP_DSS_CHANNEL_LCD
, &i734
.vm
);
4468 dispc_clear_irqstatus(framedone_irq
);
4470 /* Enable and shut the channel to produce just one frame */
4471 dispc_mgr_enable(OMAP_DSS_CHANNEL_LCD
, true);
4472 dispc_mgr_enable(OMAP_DSS_CHANNEL_LCD
, false);
4474 /* Busy wait for framedone. We can't fiddle with irq handlers
4475 * in PM resume. Typically the loop runs less than 5 times and
4476 * waits less than a micro second.
4479 while (!(dispc_read_irqstatus() & framedone_irq
)) {
4480 if (count
++ > 10000) {
4481 dev_err(&dispc
.pdev
->dev
, "%s: framedone timeout\n",
4486 dispc_ovl_enable(OMAP_DSS_GFX
, false);
4488 /* Clear all irq bits before continuing */
4489 dispc_clear_irqstatus(0xffffffff);
4491 /* Restore the original state to LCD1 output gates */
4492 REG_FLD_MOD(DISPC_CONFIG
, gatestate
, 8, 4);
4495 static const struct dispc_ops dispc_ops
= {
4496 .read_irqstatus
= dispc_read_irqstatus
,
4497 .clear_irqstatus
= dispc_clear_irqstatus
,
4498 .write_irqenable
= dispc_write_irqenable
,
4500 .request_irq
= dispc_request_irq
,
4501 .free_irq
= dispc_free_irq
,
4503 .runtime_get
= dispc_runtime_get
,
4504 .runtime_put
= dispc_runtime_put
,
4506 .get_num_ovls
= dispc_get_num_ovls
,
4507 .get_num_mgrs
= dispc_get_num_mgrs
,
4509 .get_memory_bandwidth_limit
= dispc_get_memory_bandwidth_limit
,
4511 .mgr_enable
= dispc_mgr_enable
,
4512 .mgr_is_enabled
= dispc_mgr_is_enabled
,
4513 .mgr_get_vsync_irq
= dispc_mgr_get_vsync_irq
,
4514 .mgr_get_framedone_irq
= dispc_mgr_get_framedone_irq
,
4515 .mgr_get_sync_lost_irq
= dispc_mgr_get_sync_lost_irq
,
4516 .mgr_go_busy
= dispc_mgr_go_busy
,
4517 .mgr_go
= dispc_mgr_go
,
4518 .mgr_set_lcd_config
= dispc_mgr_set_lcd_config
,
4519 .mgr_set_timings
= dispc_mgr_set_timings
,
4520 .mgr_setup
= dispc_mgr_setup
,
4521 .mgr_get_supported_outputs
= dispc_mgr_get_supported_outputs
,
4522 .mgr_gamma_size
= dispc_mgr_gamma_size
,
4523 .mgr_set_gamma
= dispc_mgr_set_gamma
,
4525 .ovl_enable
= dispc_ovl_enable
,
4526 .ovl_setup
= dispc_ovl_setup
,
4527 .ovl_get_color_modes
= dispc_ovl_get_color_modes
,
4530 /* DISPC HW IP initialisation */
4531 static const struct of_device_id dispc_of_match
[] = {
4532 { .compatible
= "ti,omap2-dispc", .data
= &omap24xx_dispc_feats
},
4533 { .compatible
= "ti,omap3-dispc", .data
= &omap36xx_dispc_feats
},
4534 { .compatible
= "ti,omap4-dispc", .data
= &omap44xx_dispc_feats
},
4535 { .compatible
= "ti,omap5-dispc", .data
= &omap54xx_dispc_feats
},
4536 { .compatible
= "ti,dra7-dispc", .data
= &omap54xx_dispc_feats
},
4540 static const struct soc_device_attribute dispc_soc_devices
[] = {
4541 { .machine
= "OMAP3[45]*",
4542 .revision
= "ES[12].?", .data
= &omap34xx_rev1_0_dispc_feats
},
4543 { .machine
= "OMAP3[45]*", .data
= &omap34xx_rev3_0_dispc_feats
},
4544 { .machine
= "AM35*", .data
= &omap34xx_rev3_0_dispc_feats
},
4545 { .machine
= "AM43*", .data
= &am43xx_dispc_feats
},
4549 static int dispc_bind(struct device
*dev
, struct device
*master
, void *data
)
4551 struct platform_device
*pdev
= to_platform_device(dev
);
4552 const struct soc_device_attribute
*soc
;
4555 struct resource
*dispc_mem
;
4556 struct device_node
*np
= pdev
->dev
.of_node
;
4560 spin_lock_init(&dispc
.control_lock
);
4563 * The OMAP3-based models can't be told apart using the compatible
4564 * string, use SoC device matching.
4566 soc
= soc_device_match(dispc_soc_devices
);
4568 dispc
.feat
= soc
->data
;
4570 dispc
.feat
= of_match_device(dispc_of_match
, &pdev
->dev
)->data
;
4572 r
= dispc_errata_i734_wa_init();
4576 dispc_mem
= platform_get_resource(dispc
.pdev
, IORESOURCE_MEM
, 0);
4577 dispc
.base
= devm_ioremap_resource(&pdev
->dev
, dispc_mem
);
4578 if (IS_ERR(dispc
.base
))
4579 return PTR_ERR(dispc
.base
);
4581 dispc
.irq
= platform_get_irq(dispc
.pdev
, 0);
4582 if (dispc
.irq
< 0) {
4583 DSSERR("platform_get_irq failed\n");
4587 if (np
&& of_property_read_bool(np
, "syscon-pol")) {
4588 dispc
.syscon_pol
= syscon_regmap_lookup_by_phandle(np
, "syscon-pol");
4589 if (IS_ERR(dispc
.syscon_pol
)) {
4590 dev_err(&pdev
->dev
, "failed to get syscon-pol regmap\n");
4591 return PTR_ERR(dispc
.syscon_pol
);
4594 if (of_property_read_u32_index(np
, "syscon-pol", 1,
4595 &dispc
.syscon_pol_offset
)) {
4596 dev_err(&pdev
->dev
, "failed to get syscon-pol offset\n");
4601 r
= dispc_init_gamma_tables();
4605 pm_runtime_enable(&pdev
->dev
);
4607 r
= dispc_runtime_get();
4609 goto err_runtime_get
;
4611 _omap_dispc_initial_config();
4613 rev
= dispc_read_reg(DISPC_REVISION
);
4614 dev_dbg(&pdev
->dev
, "OMAP DISPC rev %d.%d\n",
4615 FLD_GET(rev
, 7, 4), FLD_GET(rev
, 3, 0));
4617 dispc_runtime_put();
4619 dispc_set_ops(&dispc_ops
);
4621 dss_debugfs_create_file("dispc", dispc_dump_regs
);
4626 pm_runtime_disable(&pdev
->dev
);
4630 static void dispc_unbind(struct device
*dev
, struct device
*master
,
4633 dispc_set_ops(NULL
);
4635 pm_runtime_disable(dev
);
4637 dispc_errata_i734_wa_fini();
4640 static const struct component_ops dispc_component_ops
= {
4642 .unbind
= dispc_unbind
,
4645 static int dispc_probe(struct platform_device
*pdev
)
4647 return component_add(&pdev
->dev
, &dispc_component_ops
);
4650 static int dispc_remove(struct platform_device
*pdev
)
4652 component_del(&pdev
->dev
, &dispc_component_ops
);
4656 static int dispc_runtime_suspend(struct device
*dev
)
4658 dispc
.is_enabled
= false;
4659 /* ensure the dispc_irq_handler sees the is_enabled value */
4661 /* wait for current handler to finish before turning the DISPC off */
4662 synchronize_irq(dispc
.irq
);
4664 dispc_save_context();
4669 static int dispc_runtime_resume(struct device
*dev
)
4672 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4673 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4674 * _omap_dispc_initial_config(). We can thus use it to detect if
4675 * we have lost register context.
4677 if (REG_GET(DISPC_CONFIG
, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY
) {
4678 _omap_dispc_initial_config();
4680 dispc_errata_i734_wa();
4682 dispc_restore_context();
4684 dispc_restore_gamma_tables();
4687 dispc
.is_enabled
= true;
4688 /* ensure the dispc_irq_handler sees the is_enabled value */
4694 static const struct dev_pm_ops dispc_pm_ops
= {
4695 .runtime_suspend
= dispc_runtime_suspend
,
4696 .runtime_resume
= dispc_runtime_resume
,
4699 struct platform_driver omap_dispchw_driver
= {
4700 .probe
= dispc_probe
,
4701 .remove
= dispc_remove
,
4703 .name
= "omapdss_dispc",
4704 .pm
= &dispc_pm_ops
,
4705 .of_match_table
= dispc_of_match
,
4706 .suppress_bind_attrs
= true,