2 * linux/drivers/video/omap2/dss/dispc.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
23 #define DSS_SUBSYS_NAME "DISPC"
25 #include <linux/kernel.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/vmalloc.h>
28 #include <linux/export.h>
29 #include <linux/clk.h>
31 #include <linux/jiffies.h>
32 #include <linux/seq_file.h>
33 #include <linux/delay.h>
34 #include <linux/workqueue.h>
35 #include <linux/hardirq.h>
36 #include <linux/platform_device.h>
37 #include <linux/pm_runtime.h>
38 #include <linux/sizes.h>
40 #include <video/omapdss.h>
43 #include "dss_features.h"
47 #define DISPC_SZ_REGS SZ_4K
49 enum omap_burst_size
{
55 #define REG_GET(idx, start, end) \
56 FLD_GET(dispc_read_reg(idx), start, end)
58 #define REG_FLD_MOD(idx, val, start, end) \
59 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
61 struct dispc_features
{
72 unsigned long max_lcd_pclk
;
73 unsigned long max_tv_pclk
;
74 int (*calc_scaling
) (unsigned long pclk
, unsigned long lclk
,
75 const struct omap_video_timings
*mgr_timings
,
76 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
77 enum omap_color_mode color_mode
, bool *five_taps
,
78 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
79 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
);
80 unsigned long (*calc_core_clk
) (unsigned long pclk
,
81 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
85 /* swap GFX & WB fifos */
86 bool gfx_fifo_workaround
:1;
88 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
89 bool no_framedone_tv
:1;
91 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
92 bool mstandby_workaround
:1;
94 bool set_max_preload
:1;
97 #define DISPC_MAX_NR_FIFOS 5
100 struct platform_device
*pdev
;
107 unsigned long core_clk_rate
;
108 unsigned long tv_pclk_rate
;
110 u32 fifo_size
[DISPC_MAX_NR_FIFOS
];
111 /* maps which plane is using a fifo. fifo-id -> plane-id */
112 int fifo_assignment
[DISPC_MAX_NR_FIFOS
];
115 u32 ctx
[DISPC_SZ_REGS
/ sizeof(u32
)];
117 const struct dispc_features
*feat
;
120 enum omap_color_component
{
121 /* used for all color formats for OMAP3 and earlier
122 * and for RGB and Y color component on OMAP4
124 DISPC_COLOR_COMPONENT_RGB_Y
= 1 << 0,
125 /* used for UV component for
126 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
127 * color formats on OMAP4
129 DISPC_COLOR_COMPONENT_UV
= 1 << 1,
132 enum mgr_reg_fields
{
133 DISPC_MGR_FLD_ENABLE
,
134 DISPC_MGR_FLD_STNTFT
,
136 DISPC_MGR_FLD_TFTDATALINES
,
137 DISPC_MGR_FLD_STALLMODE
,
138 DISPC_MGR_FLD_TCKENABLE
,
139 DISPC_MGR_FLD_TCKSELECTION
,
141 DISPC_MGR_FLD_FIFOHANDCHECK
,
142 /* used to maintain a count of the above fields */
146 static const struct {
151 struct reg_field reg_desc
[DISPC_MGR_FLD_NUM
];
153 [OMAP_DSS_CHANNEL_LCD
] = {
155 .vsync_irq
= DISPC_IRQ_VSYNC
,
156 .framedone_irq
= DISPC_IRQ_FRAMEDONE
,
157 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST
,
159 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL
, 0, 0 },
160 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL
, 3, 3 },
161 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL
, 5, 5 },
162 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL
, 9, 8 },
163 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL
, 11, 11 },
164 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG
, 10, 10 },
165 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG
, 11, 11 },
166 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG
, 15, 15 },
167 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG
, 16, 16 },
170 [OMAP_DSS_CHANNEL_DIGIT
] = {
172 .vsync_irq
= DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_EVSYNC_EVEN
,
173 .framedone_irq
= DISPC_IRQ_FRAMEDONETV
,
174 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST_DIGIT
,
176 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL
, 1, 1 },
177 [DISPC_MGR_FLD_STNTFT
] = { },
178 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL
, 6, 6 },
179 [DISPC_MGR_FLD_TFTDATALINES
] = { },
180 [DISPC_MGR_FLD_STALLMODE
] = { },
181 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG
, 12, 12 },
182 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG
, 13, 13 },
183 [DISPC_MGR_FLD_CPR
] = { },
184 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG
, 16, 16 },
187 [OMAP_DSS_CHANNEL_LCD2
] = {
189 .vsync_irq
= DISPC_IRQ_VSYNC2
,
190 .framedone_irq
= DISPC_IRQ_FRAMEDONE2
,
191 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST2
,
193 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL2
, 0, 0 },
194 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL2
, 3, 3 },
195 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL2
, 5, 5 },
196 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL2
, 9, 8 },
197 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL2
, 11, 11 },
198 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG2
, 10, 10 },
199 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG2
, 11, 11 },
200 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG2
, 15, 15 },
201 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG2
, 16, 16 },
204 [OMAP_DSS_CHANNEL_LCD3
] = {
206 .vsync_irq
= DISPC_IRQ_VSYNC3
,
207 .framedone_irq
= DISPC_IRQ_FRAMEDONE3
,
208 .sync_lost_irq
= DISPC_IRQ_SYNC_LOST3
,
210 [DISPC_MGR_FLD_ENABLE
] = { DISPC_CONTROL3
, 0, 0 },
211 [DISPC_MGR_FLD_STNTFT
] = { DISPC_CONTROL3
, 3, 3 },
212 [DISPC_MGR_FLD_GO
] = { DISPC_CONTROL3
, 5, 5 },
213 [DISPC_MGR_FLD_TFTDATALINES
] = { DISPC_CONTROL3
, 9, 8 },
214 [DISPC_MGR_FLD_STALLMODE
] = { DISPC_CONTROL3
, 11, 11 },
215 [DISPC_MGR_FLD_TCKENABLE
] = { DISPC_CONFIG3
, 10, 10 },
216 [DISPC_MGR_FLD_TCKSELECTION
] = { DISPC_CONFIG3
, 11, 11 },
217 [DISPC_MGR_FLD_CPR
] = { DISPC_CONFIG3
, 15, 15 },
218 [DISPC_MGR_FLD_FIFOHANDCHECK
] = { DISPC_CONFIG3
, 16, 16 },
223 struct color_conv_coef
{
224 int ry
, rcr
, rcb
, gy
, gcr
, gcb
, by
, bcr
, bcb
;
228 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane
);
229 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane
);
231 static inline void dispc_write_reg(const u16 idx
, u32 val
)
233 __raw_writel(val
, dispc
.base
+ idx
);
236 static inline u32
dispc_read_reg(const u16 idx
)
238 return __raw_readl(dispc
.base
+ idx
);
241 static u32
mgr_fld_read(enum omap_channel channel
, enum mgr_reg_fields regfld
)
243 const struct reg_field rfld
= mgr_desc
[channel
].reg_desc
[regfld
];
244 return REG_GET(rfld
.reg
, rfld
.high
, rfld
.low
);
247 static void mgr_fld_write(enum omap_channel channel
,
248 enum mgr_reg_fields regfld
, int val
) {
249 const struct reg_field rfld
= mgr_desc
[channel
].reg_desc
[regfld
];
250 REG_FLD_MOD(rfld
.reg
, val
, rfld
.high
, rfld
.low
);
254 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
256 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
258 static void dispc_save_context(void)
262 DSSDBG("dispc_save_context\n");
268 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
269 dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
271 if (dss_has_feature(FEAT_MGR_LCD2
)) {
275 if (dss_has_feature(FEAT_MGR_LCD3
)) {
280 for (i
= 0; i
< dss_feat_get_num_mgrs(); i
++) {
281 SR(DEFAULT_COLOR(i
));
284 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
295 if (dss_has_feature(FEAT_CPR
)) {
302 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
307 SR(OVL_ATTRIBUTES(i
));
308 SR(OVL_FIFO_THRESHOLD(i
));
310 SR(OVL_PIXEL_INC(i
));
311 if (dss_has_feature(FEAT_PRELOAD
))
313 if (i
== OMAP_DSS_GFX
) {
314 SR(OVL_WINDOW_SKIP(i
));
319 SR(OVL_PICTURE_SIZE(i
));
323 for (j
= 0; j
< 8; j
++)
324 SR(OVL_FIR_COEF_H(i
, j
));
326 for (j
= 0; j
< 8; j
++)
327 SR(OVL_FIR_COEF_HV(i
, j
));
329 for (j
= 0; j
< 5; j
++)
330 SR(OVL_CONV_COEF(i
, j
));
332 if (dss_has_feature(FEAT_FIR_COEF_V
)) {
333 for (j
= 0; j
< 8; j
++)
334 SR(OVL_FIR_COEF_V(i
, j
));
337 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
344 for (j
= 0; j
< 8; j
++)
345 SR(OVL_FIR_COEF_H2(i
, j
));
347 for (j
= 0; j
< 8; j
++)
348 SR(OVL_FIR_COEF_HV2(i
, j
));
350 for (j
= 0; j
< 8; j
++)
351 SR(OVL_FIR_COEF_V2(i
, j
));
353 if (dss_has_feature(FEAT_ATTR2
))
354 SR(OVL_ATTRIBUTES2(i
));
357 if (dss_has_feature(FEAT_CORE_CLK_DIV
))
360 dispc
.ctx_loss_cnt
= dss_get_ctx_loss_count();
361 dispc
.ctx_valid
= true;
363 DSSDBG("context saved, ctx_loss_count %d\n", dispc
.ctx_loss_cnt
);
366 static void dispc_restore_context(void)
370 DSSDBG("dispc_restore_context\n");
372 if (!dispc
.ctx_valid
)
375 ctx
= dss_get_ctx_loss_count();
377 if (ctx
>= 0 && ctx
== dispc
.ctx_loss_cnt
)
380 DSSDBG("ctx_loss_count: saved %d, current %d\n",
381 dispc
.ctx_loss_cnt
, ctx
);
387 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
388 dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
390 if (dss_has_feature(FEAT_MGR_LCD2
))
392 if (dss_has_feature(FEAT_MGR_LCD3
))
395 for (i
= 0; i
< dss_feat_get_num_mgrs(); i
++) {
396 RR(DEFAULT_COLOR(i
));
399 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
410 if (dss_has_feature(FEAT_CPR
)) {
417 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
422 RR(OVL_ATTRIBUTES(i
));
423 RR(OVL_FIFO_THRESHOLD(i
));
425 RR(OVL_PIXEL_INC(i
));
426 if (dss_has_feature(FEAT_PRELOAD
))
428 if (i
== OMAP_DSS_GFX
) {
429 RR(OVL_WINDOW_SKIP(i
));
434 RR(OVL_PICTURE_SIZE(i
));
438 for (j
= 0; j
< 8; j
++)
439 RR(OVL_FIR_COEF_H(i
, j
));
441 for (j
= 0; j
< 8; j
++)
442 RR(OVL_FIR_COEF_HV(i
, j
));
444 for (j
= 0; j
< 5; j
++)
445 RR(OVL_CONV_COEF(i
, j
));
447 if (dss_has_feature(FEAT_FIR_COEF_V
)) {
448 for (j
= 0; j
< 8; j
++)
449 RR(OVL_FIR_COEF_V(i
, j
));
452 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
459 for (j
= 0; j
< 8; j
++)
460 RR(OVL_FIR_COEF_H2(i
, j
));
462 for (j
= 0; j
< 8; j
++)
463 RR(OVL_FIR_COEF_HV2(i
, j
));
465 for (j
= 0; j
< 8; j
++)
466 RR(OVL_FIR_COEF_V2(i
, j
));
468 if (dss_has_feature(FEAT_ATTR2
))
469 RR(OVL_ATTRIBUTES2(i
));
472 if (dss_has_feature(FEAT_CORE_CLK_DIV
))
475 /* enable last, because LCD & DIGIT enable are here */
477 if (dss_has_feature(FEAT_MGR_LCD2
))
479 if (dss_has_feature(FEAT_MGR_LCD3
))
481 /* clear spurious SYNC_LOST_DIGIT interrupts */
482 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT
);
485 * enable last so IRQs won't trigger before
486 * the context is fully restored
490 DSSDBG("context restored\n");
496 int dispc_runtime_get(void)
500 DSSDBG("dispc_runtime_get\n");
502 r
= pm_runtime_get_sync(&dispc
.pdev
->dev
);
504 return r
< 0 ? r
: 0;
506 EXPORT_SYMBOL(dispc_runtime_get
);
508 void dispc_runtime_put(void)
512 DSSDBG("dispc_runtime_put\n");
514 r
= pm_runtime_put_sync(&dispc
.pdev
->dev
);
515 WARN_ON(r
< 0 && r
!= -ENOSYS
);
517 EXPORT_SYMBOL(dispc_runtime_put
);
519 u32
dispc_mgr_get_vsync_irq(enum omap_channel channel
)
521 return mgr_desc
[channel
].vsync_irq
;
523 EXPORT_SYMBOL(dispc_mgr_get_vsync_irq
);
525 u32
dispc_mgr_get_framedone_irq(enum omap_channel channel
)
527 if (channel
== OMAP_DSS_CHANNEL_DIGIT
&& dispc
.feat
->no_framedone_tv
)
530 return mgr_desc
[channel
].framedone_irq
;
532 EXPORT_SYMBOL(dispc_mgr_get_framedone_irq
);
534 u32
dispc_mgr_get_sync_lost_irq(enum omap_channel channel
)
536 return mgr_desc
[channel
].sync_lost_irq
;
538 EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq
);
540 u32
dispc_wb_get_framedone_irq(void)
542 return DISPC_IRQ_FRAMEDONEWB
;
545 bool dispc_mgr_go_busy(enum omap_channel channel
)
547 return mgr_fld_read(channel
, DISPC_MGR_FLD_GO
) == 1;
549 EXPORT_SYMBOL(dispc_mgr_go_busy
);
551 void dispc_mgr_go(enum omap_channel channel
)
553 WARN_ON(dispc_mgr_is_enabled(channel
) == false);
554 WARN_ON(dispc_mgr_go_busy(channel
));
556 DSSDBG("GO %s\n", mgr_desc
[channel
].name
);
558 mgr_fld_write(channel
, DISPC_MGR_FLD_GO
, 1);
560 EXPORT_SYMBOL(dispc_mgr_go
);
562 bool dispc_wb_go_busy(void)
564 return REG_GET(DISPC_CONTROL2
, 6, 6) == 1;
567 void dispc_wb_go(void)
569 enum omap_plane plane
= OMAP_DSS_WB
;
572 enable
= REG_GET(DISPC_OVL_ATTRIBUTES(plane
), 0, 0) == 1;
577 go
= REG_GET(DISPC_CONTROL2
, 6, 6) == 1;
579 DSSERR("GO bit not down for WB\n");
583 REG_FLD_MOD(DISPC_CONTROL2
, 1, 6, 6);
586 static void dispc_ovl_write_firh_reg(enum omap_plane plane
, int reg
, u32 value
)
588 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane
, reg
), value
);
591 static void dispc_ovl_write_firhv_reg(enum omap_plane plane
, int reg
, u32 value
)
593 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane
, reg
), value
);
596 static void dispc_ovl_write_firv_reg(enum omap_plane plane
, int reg
, u32 value
)
598 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane
, reg
), value
);
601 static void dispc_ovl_write_firh2_reg(enum omap_plane plane
, int reg
, u32 value
)
603 BUG_ON(plane
== OMAP_DSS_GFX
);
605 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane
, reg
), value
);
608 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane
, int reg
,
611 BUG_ON(plane
== OMAP_DSS_GFX
);
613 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane
, reg
), value
);
616 static void dispc_ovl_write_firv2_reg(enum omap_plane plane
, int reg
, u32 value
)
618 BUG_ON(plane
== OMAP_DSS_GFX
);
620 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane
, reg
), value
);
623 static void dispc_ovl_set_scale_coef(enum omap_plane plane
, int fir_hinc
,
624 int fir_vinc
, int five_taps
,
625 enum omap_color_component color_comp
)
627 const struct dispc_coef
*h_coef
, *v_coef
;
630 h_coef
= dispc_ovl_get_scale_coef(fir_hinc
, true);
631 v_coef
= dispc_ovl_get_scale_coef(fir_vinc
, five_taps
);
633 for (i
= 0; i
< 8; i
++) {
636 h
= FLD_VAL(h_coef
[i
].hc0_vc00
, 7, 0)
637 | FLD_VAL(h_coef
[i
].hc1_vc0
, 15, 8)
638 | FLD_VAL(h_coef
[i
].hc2_vc1
, 23, 16)
639 | FLD_VAL(h_coef
[i
].hc3_vc2
, 31, 24);
640 hv
= FLD_VAL(h_coef
[i
].hc4_vc22
, 7, 0)
641 | FLD_VAL(v_coef
[i
].hc1_vc0
, 15, 8)
642 | FLD_VAL(v_coef
[i
].hc2_vc1
, 23, 16)
643 | FLD_VAL(v_coef
[i
].hc3_vc2
, 31, 24);
645 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
) {
646 dispc_ovl_write_firh_reg(plane
, i
, h
);
647 dispc_ovl_write_firhv_reg(plane
, i
, hv
);
649 dispc_ovl_write_firh2_reg(plane
, i
, h
);
650 dispc_ovl_write_firhv2_reg(plane
, i
, hv
);
656 for (i
= 0; i
< 8; i
++) {
658 v
= FLD_VAL(v_coef
[i
].hc0_vc00
, 7, 0)
659 | FLD_VAL(v_coef
[i
].hc4_vc22
, 15, 8);
660 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
)
661 dispc_ovl_write_firv_reg(plane
, i
, v
);
663 dispc_ovl_write_firv2_reg(plane
, i
, v
);
669 static void dispc_ovl_write_color_conv_coef(enum omap_plane plane
,
670 const struct color_conv_coef
*ct
)
672 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
674 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 0), CVAL(ct
->rcr
, ct
->ry
));
675 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 1), CVAL(ct
->gy
, ct
->rcb
));
676 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 2), CVAL(ct
->gcb
, ct
->gcr
));
677 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 3), CVAL(ct
->bcr
, ct
->by
));
678 dispc_write_reg(DISPC_OVL_CONV_COEF(plane
, 4), CVAL(0, ct
->bcb
));
680 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), ct
->full_range
, 11, 11);
685 static void dispc_setup_color_conv_coef(void)
688 int num_ovl
= dss_feat_get_num_ovls();
689 int num_wb
= dss_feat_get_num_wbs();
690 const struct color_conv_coef ctbl_bt601_5_ovl
= {
691 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
693 const struct color_conv_coef ctbl_bt601_5_wb
= {
694 66, 112, -38, 129, -94, -74, 25, -18, 112, 0,
697 for (i
= 1; i
< num_ovl
; i
++)
698 dispc_ovl_write_color_conv_coef(i
, &ctbl_bt601_5_ovl
);
700 for (; i
< num_wb
; i
++)
701 dispc_ovl_write_color_conv_coef(i
, &ctbl_bt601_5_wb
);
704 static void dispc_ovl_set_ba0(enum omap_plane plane
, u32 paddr
)
706 dispc_write_reg(DISPC_OVL_BA0(plane
), paddr
);
709 static void dispc_ovl_set_ba1(enum omap_plane plane
, u32 paddr
)
711 dispc_write_reg(DISPC_OVL_BA1(plane
), paddr
);
714 static void dispc_ovl_set_ba0_uv(enum omap_plane plane
, u32 paddr
)
716 dispc_write_reg(DISPC_OVL_BA0_UV(plane
), paddr
);
719 static void dispc_ovl_set_ba1_uv(enum omap_plane plane
, u32 paddr
)
721 dispc_write_reg(DISPC_OVL_BA1_UV(plane
), paddr
);
724 static void dispc_ovl_set_pos(enum omap_plane plane
,
725 enum omap_overlay_caps caps
, int x
, int y
)
729 if ((caps
& OMAP_DSS_OVL_CAP_POS
) == 0)
732 val
= FLD_VAL(y
, 26, 16) | FLD_VAL(x
, 10, 0);
734 dispc_write_reg(DISPC_OVL_POSITION(plane
), val
);
737 static void dispc_ovl_set_input_size(enum omap_plane plane
, int width
,
740 u32 val
= FLD_VAL(height
- 1, 26, 16) | FLD_VAL(width
- 1, 10, 0);
742 if (plane
== OMAP_DSS_GFX
|| plane
== OMAP_DSS_WB
)
743 dispc_write_reg(DISPC_OVL_SIZE(plane
), val
);
745 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane
), val
);
748 static void dispc_ovl_set_output_size(enum omap_plane plane
, int width
,
753 BUG_ON(plane
== OMAP_DSS_GFX
);
755 val
= FLD_VAL(height
- 1, 26, 16) | FLD_VAL(width
- 1, 10, 0);
757 if (plane
== OMAP_DSS_WB
)
758 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane
), val
);
760 dispc_write_reg(DISPC_OVL_SIZE(plane
), val
);
763 static void dispc_ovl_set_zorder(enum omap_plane plane
,
764 enum omap_overlay_caps caps
, u8 zorder
)
766 if ((caps
& OMAP_DSS_OVL_CAP_ZORDER
) == 0)
769 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), zorder
, 27, 26);
772 static void dispc_ovl_enable_zorder_planes(void)
776 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
779 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++)
780 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i
), 1, 25, 25);
783 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane
,
784 enum omap_overlay_caps caps
, bool enable
)
786 if ((caps
& OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
) == 0)
789 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
? 1 : 0, 28, 28);
792 static void dispc_ovl_setup_global_alpha(enum omap_plane plane
,
793 enum omap_overlay_caps caps
, u8 global_alpha
)
795 static const unsigned shifts
[] = { 0, 8, 16, 24, };
798 if ((caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
801 shift
= shifts
[plane
];
802 REG_FLD_MOD(DISPC_GLOBAL_ALPHA
, global_alpha
, shift
+ 7, shift
);
805 static void dispc_ovl_set_pix_inc(enum omap_plane plane
, s32 inc
)
807 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane
), inc
);
810 static void dispc_ovl_set_row_inc(enum omap_plane plane
, s32 inc
)
812 dispc_write_reg(DISPC_OVL_ROW_INC(plane
), inc
);
815 static void dispc_ovl_set_color_mode(enum omap_plane plane
,
816 enum omap_color_mode color_mode
)
819 if (plane
!= OMAP_DSS_GFX
) {
820 switch (color_mode
) {
821 case OMAP_DSS_COLOR_NV12
:
823 case OMAP_DSS_COLOR_RGBX16
:
825 case OMAP_DSS_COLOR_RGBA16
:
827 case OMAP_DSS_COLOR_RGB12U
:
829 case OMAP_DSS_COLOR_ARGB16
:
831 case OMAP_DSS_COLOR_RGB16
:
833 case OMAP_DSS_COLOR_ARGB16_1555
:
835 case OMAP_DSS_COLOR_RGB24U
:
837 case OMAP_DSS_COLOR_RGB24P
:
839 case OMAP_DSS_COLOR_YUV2
:
841 case OMAP_DSS_COLOR_UYVY
:
843 case OMAP_DSS_COLOR_ARGB32
:
845 case OMAP_DSS_COLOR_RGBA32
:
847 case OMAP_DSS_COLOR_RGBX32
:
849 case OMAP_DSS_COLOR_XRGB16_1555
:
855 switch (color_mode
) {
856 case OMAP_DSS_COLOR_CLUT1
:
858 case OMAP_DSS_COLOR_CLUT2
:
860 case OMAP_DSS_COLOR_CLUT4
:
862 case OMAP_DSS_COLOR_CLUT8
:
864 case OMAP_DSS_COLOR_RGB12U
:
866 case OMAP_DSS_COLOR_ARGB16
:
868 case OMAP_DSS_COLOR_RGB16
:
870 case OMAP_DSS_COLOR_ARGB16_1555
:
872 case OMAP_DSS_COLOR_RGB24U
:
874 case OMAP_DSS_COLOR_RGB24P
:
876 case OMAP_DSS_COLOR_RGBX16
:
878 case OMAP_DSS_COLOR_RGBA16
:
880 case OMAP_DSS_COLOR_ARGB32
:
882 case OMAP_DSS_COLOR_RGBA32
:
884 case OMAP_DSS_COLOR_RGBX32
:
886 case OMAP_DSS_COLOR_XRGB16_1555
:
893 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), m
, 4, 1);
896 static void dispc_ovl_configure_burst_type(enum omap_plane plane
,
897 enum omap_dss_rotation_type rotation_type
)
899 if (dss_has_feature(FEAT_BURST_2D
) == 0)
902 if (rotation_type
== OMAP_DSS_ROT_TILER
)
903 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), 1, 29, 29);
905 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), 0, 29, 29);
908 void dispc_ovl_set_channel_out(enum omap_plane plane
, enum omap_channel channel
)
912 int chan
= 0, chan2
= 0;
918 case OMAP_DSS_VIDEO1
:
919 case OMAP_DSS_VIDEO2
:
920 case OMAP_DSS_VIDEO3
:
928 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
929 if (dss_has_feature(FEAT_MGR_LCD2
)) {
931 case OMAP_DSS_CHANNEL_LCD
:
935 case OMAP_DSS_CHANNEL_DIGIT
:
939 case OMAP_DSS_CHANNEL_LCD2
:
943 case OMAP_DSS_CHANNEL_LCD3
:
944 if (dss_has_feature(FEAT_MGR_LCD3
)) {
957 val
= FLD_MOD(val
, chan
, shift
, shift
);
958 val
= FLD_MOD(val
, chan2
, 31, 30);
960 val
= FLD_MOD(val
, channel
, shift
, shift
);
962 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), val
);
964 EXPORT_SYMBOL(dispc_ovl_set_channel_out
);
966 static enum omap_channel
dispc_ovl_get_channel_out(enum omap_plane plane
)
970 enum omap_channel channel
;
976 case OMAP_DSS_VIDEO1
:
977 case OMAP_DSS_VIDEO2
:
978 case OMAP_DSS_VIDEO3
:
986 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
988 if (dss_has_feature(FEAT_MGR_LCD3
)) {
989 if (FLD_GET(val
, 31, 30) == 0)
990 channel
= FLD_GET(val
, shift
, shift
);
991 else if (FLD_GET(val
, 31, 30) == 1)
992 channel
= OMAP_DSS_CHANNEL_LCD2
;
994 channel
= OMAP_DSS_CHANNEL_LCD3
;
995 } else if (dss_has_feature(FEAT_MGR_LCD2
)) {
996 if (FLD_GET(val
, 31, 30) == 0)
997 channel
= FLD_GET(val
, shift
, shift
);
999 channel
= OMAP_DSS_CHANNEL_LCD2
;
1001 channel
= FLD_GET(val
, shift
, shift
);
1007 void dispc_wb_set_channel_in(enum dss_writeback_channel channel
)
1009 enum omap_plane plane
= OMAP_DSS_WB
;
1011 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), channel
, 18, 16);
1014 static void dispc_ovl_set_burst_size(enum omap_plane plane
,
1015 enum omap_burst_size burst_size
)
1017 static const unsigned shifts
[] = { 6, 14, 14, 14, 14, };
1020 shift
= shifts
[plane
];
1021 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), burst_size
, shift
+ 1, shift
);
1024 static void dispc_configure_burst_sizes(void)
1027 const int burst_size
= BURST_SIZE_X8
;
1029 /* Configure burst size always to maximum size */
1030 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
)
1031 dispc_ovl_set_burst_size(i
, burst_size
);
1034 static u32
dispc_ovl_get_burst_size(enum omap_plane plane
)
1036 unsigned unit
= dss_feat_get_burst_size_unit();
1037 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1041 void dispc_enable_gamma_table(bool enable
)
1044 * This is partially implemented to support only disabling of
1048 DSSWARN("Gamma table enabling for TV not yet supported");
1052 REG_FLD_MOD(DISPC_CONFIG
, enable
, 9, 9);
1055 static void dispc_mgr_enable_cpr(enum omap_channel channel
, bool enable
)
1057 if (channel
== OMAP_DSS_CHANNEL_DIGIT
)
1060 mgr_fld_write(channel
, DISPC_MGR_FLD_CPR
, enable
);
1063 static void dispc_mgr_set_cpr_coef(enum omap_channel channel
,
1064 const struct omap_dss_cpr_coefs
*coefs
)
1066 u32 coef_r
, coef_g
, coef_b
;
1068 if (!dss_mgr_is_lcd(channel
))
1071 coef_r
= FLD_VAL(coefs
->rr
, 31, 22) | FLD_VAL(coefs
->rg
, 20, 11) |
1072 FLD_VAL(coefs
->rb
, 9, 0);
1073 coef_g
= FLD_VAL(coefs
->gr
, 31, 22) | FLD_VAL(coefs
->gg
, 20, 11) |
1074 FLD_VAL(coefs
->gb
, 9, 0);
1075 coef_b
= FLD_VAL(coefs
->br
, 31, 22) | FLD_VAL(coefs
->bg
, 20, 11) |
1076 FLD_VAL(coefs
->bb
, 9, 0);
1078 dispc_write_reg(DISPC_CPR_COEF_R(channel
), coef_r
);
1079 dispc_write_reg(DISPC_CPR_COEF_G(channel
), coef_g
);
1080 dispc_write_reg(DISPC_CPR_COEF_B(channel
), coef_b
);
1083 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane
, bool enable
)
1087 BUG_ON(plane
== OMAP_DSS_GFX
);
1089 val
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1090 val
= FLD_MOD(val
, enable
, 9, 9);
1091 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), val
);
1094 static void dispc_ovl_enable_replication(enum omap_plane plane
,
1095 enum omap_overlay_caps caps
, bool enable
)
1097 static const unsigned shifts
[] = { 5, 10, 10, 10 };
1100 if ((caps
& OMAP_DSS_OVL_CAP_REPLICATION
) == 0)
1103 shift
= shifts
[plane
];
1104 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
, shift
, shift
);
1107 static void dispc_mgr_set_size(enum omap_channel channel
, u16 width
,
1112 val
= FLD_VAL(height
- 1, dispc
.feat
->mgr_height_start
, 16) |
1113 FLD_VAL(width
- 1, dispc
.feat
->mgr_width_start
, 0);
1115 dispc_write_reg(DISPC_SIZE_MGR(channel
), val
);
1118 static void dispc_init_fifos(void)
1125 unit
= dss_feat_get_buffer_size_unit();
1127 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE
, &start
, &end
);
1129 for (fifo
= 0; fifo
< dispc
.feat
->num_fifos
; ++fifo
) {
1130 size
= REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo
), start
, end
);
1132 dispc
.fifo_size
[fifo
] = size
;
1135 * By default fifos are mapped directly to overlays, fifo 0 to
1136 * ovl 0, fifo 1 to ovl 1, etc.
1138 dispc
.fifo_assignment
[fifo
] = fifo
;
1142 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1143 * causes problems with certain use cases, like using the tiler in 2D
1144 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1145 * giving GFX plane a larger fifo. WB but should work fine with a
1148 if (dispc
.feat
->gfx_fifo_workaround
) {
1151 v
= dispc_read_reg(DISPC_GLOBAL_BUFFER
);
1153 v
= FLD_MOD(v
, 4, 2, 0); /* GFX BUF top to WB */
1154 v
= FLD_MOD(v
, 4, 5, 3); /* GFX BUF bottom to WB */
1155 v
= FLD_MOD(v
, 0, 26, 24); /* WB BUF top to GFX */
1156 v
= FLD_MOD(v
, 0, 29, 27); /* WB BUF bottom to GFX */
1158 dispc_write_reg(DISPC_GLOBAL_BUFFER
, v
);
1160 dispc
.fifo_assignment
[OMAP_DSS_GFX
] = OMAP_DSS_WB
;
1161 dispc
.fifo_assignment
[OMAP_DSS_WB
] = OMAP_DSS_GFX
;
1165 static u32
dispc_ovl_get_fifo_size(enum omap_plane plane
)
1170 for (fifo
= 0; fifo
< dispc
.feat
->num_fifos
; ++fifo
) {
1171 if (dispc
.fifo_assignment
[fifo
] == plane
)
1172 size
+= dispc
.fifo_size
[fifo
];
1178 void dispc_ovl_set_fifo_threshold(enum omap_plane plane
, u32 low
, u32 high
)
1180 u8 hi_start
, hi_end
, lo_start
, lo_end
;
1183 unit
= dss_feat_get_buffer_size_unit();
1185 WARN_ON(low
% unit
!= 0);
1186 WARN_ON(high
% unit
!= 0);
1191 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD
, &hi_start
, &hi_end
);
1192 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD
, &lo_start
, &lo_end
);
1194 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1196 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane
),
1197 lo_start
, lo_end
) * unit
,
1198 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane
),
1199 hi_start
, hi_end
) * unit
,
1200 low
* unit
, high
* unit
);
1202 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane
),
1203 FLD_VAL(high
, hi_start
, hi_end
) |
1204 FLD_VAL(low
, lo_start
, lo_end
));
1207 * configure the preload to the pipeline's high threhold, if HT it's too
1208 * large for the preload field, set the threshold to the maximum value
1209 * that can be held by the preload register
1211 if (dss_has_feature(FEAT_PRELOAD
) && dispc
.feat
->set_max_preload
&&
1212 plane
!= OMAP_DSS_WB
)
1213 dispc_write_reg(DISPC_OVL_PRELOAD(plane
), min(high
, 0xfffu
));
1215 EXPORT_SYMBOL(dispc_ovl_set_fifo_threshold
);
1217 void dispc_enable_fifomerge(bool enable
)
1219 if (!dss_has_feature(FEAT_FIFO_MERGE
)) {
1224 DSSDBG("FIFO merge %s\n", enable
? "enabled" : "disabled");
1225 REG_FLD_MOD(DISPC_CONFIG
, enable
? 1 : 0, 14, 14);
1228 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane
,
1229 u32
*fifo_low
, u32
*fifo_high
, bool use_fifomerge
,
1233 * All sizes are in bytes. Both the buffer and burst are made of
1234 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1237 unsigned buf_unit
= dss_feat_get_buffer_size_unit();
1238 unsigned ovl_fifo_size
, total_fifo_size
, burst_size
;
1241 burst_size
= dispc_ovl_get_burst_size(plane
);
1242 ovl_fifo_size
= dispc_ovl_get_fifo_size(plane
);
1244 if (use_fifomerge
) {
1245 total_fifo_size
= 0;
1246 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
)
1247 total_fifo_size
+= dispc_ovl_get_fifo_size(i
);
1249 total_fifo_size
= ovl_fifo_size
;
1253 * We use the same low threshold for both fifomerge and non-fifomerge
1254 * cases, but for fifomerge we calculate the high threshold using the
1255 * combined fifo size
1258 if (manual_update
&& dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG
)) {
1259 *fifo_low
= ovl_fifo_size
- burst_size
* 2;
1260 *fifo_high
= total_fifo_size
- burst_size
;
1261 } else if (plane
== OMAP_DSS_WB
) {
1263 * Most optimal configuration for writeback is to push out data
1264 * to the interconnect the moment writeback pushes enough pixels
1265 * in the FIFO to form a burst
1268 *fifo_high
= burst_size
;
1270 *fifo_low
= ovl_fifo_size
- burst_size
;
1271 *fifo_high
= total_fifo_size
- buf_unit
;
1274 EXPORT_SYMBOL(dispc_ovl_compute_fifo_thresholds
);
1276 static void dispc_ovl_set_fir(enum omap_plane plane
,
1278 enum omap_color_component color_comp
)
1282 if (color_comp
== DISPC_COLOR_COMPONENT_RGB_Y
) {
1283 u8 hinc_start
, hinc_end
, vinc_start
, vinc_end
;
1285 dss_feat_get_reg_field(FEAT_REG_FIRHINC
,
1286 &hinc_start
, &hinc_end
);
1287 dss_feat_get_reg_field(FEAT_REG_FIRVINC
,
1288 &vinc_start
, &vinc_end
);
1289 val
= FLD_VAL(vinc
, vinc_start
, vinc_end
) |
1290 FLD_VAL(hinc
, hinc_start
, hinc_end
);
1292 dispc_write_reg(DISPC_OVL_FIR(plane
), val
);
1294 val
= FLD_VAL(vinc
, 28, 16) | FLD_VAL(hinc
, 12, 0);
1295 dispc_write_reg(DISPC_OVL_FIR2(plane
), val
);
1299 static void dispc_ovl_set_vid_accu0(enum omap_plane plane
, int haccu
, int vaccu
)
1302 u8 hor_start
, hor_end
, vert_start
, vert_end
;
1304 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU
, &hor_start
, &hor_end
);
1305 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU
, &vert_start
, &vert_end
);
1307 val
= FLD_VAL(vaccu
, vert_start
, vert_end
) |
1308 FLD_VAL(haccu
, hor_start
, hor_end
);
1310 dispc_write_reg(DISPC_OVL_ACCU0(plane
), val
);
1313 static void dispc_ovl_set_vid_accu1(enum omap_plane plane
, int haccu
, int vaccu
)
1316 u8 hor_start
, hor_end
, vert_start
, vert_end
;
1318 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU
, &hor_start
, &hor_end
);
1319 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU
, &vert_start
, &vert_end
);
1321 val
= FLD_VAL(vaccu
, vert_start
, vert_end
) |
1322 FLD_VAL(haccu
, hor_start
, hor_end
);
1324 dispc_write_reg(DISPC_OVL_ACCU1(plane
), val
);
1327 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane
, int haccu
,
1332 val
= FLD_VAL(vaccu
, 26, 16) | FLD_VAL(haccu
, 10, 0);
1333 dispc_write_reg(DISPC_OVL_ACCU2_0(plane
), val
);
1336 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane
, int haccu
,
1341 val
= FLD_VAL(vaccu
, 26, 16) | FLD_VAL(haccu
, 10, 0);
1342 dispc_write_reg(DISPC_OVL_ACCU2_1(plane
), val
);
1345 static void dispc_ovl_set_scale_param(enum omap_plane plane
,
1346 u16 orig_width
, u16 orig_height
,
1347 u16 out_width
, u16 out_height
,
1348 bool five_taps
, u8 rotation
,
1349 enum omap_color_component color_comp
)
1351 int fir_hinc
, fir_vinc
;
1353 fir_hinc
= 1024 * orig_width
/ out_width
;
1354 fir_vinc
= 1024 * orig_height
/ out_height
;
1356 dispc_ovl_set_scale_coef(plane
, fir_hinc
, fir_vinc
, five_taps
,
1358 dispc_ovl_set_fir(plane
, fir_hinc
, fir_vinc
, color_comp
);
1361 static void dispc_ovl_set_accu_uv(enum omap_plane plane
,
1362 u16 orig_width
, u16 orig_height
, u16 out_width
, u16 out_height
,
1363 bool ilace
, enum omap_color_mode color_mode
, u8 rotation
)
1365 int h_accu2_0
, h_accu2_1
;
1366 int v_accu2_0
, v_accu2_1
;
1367 int chroma_hinc
, chroma_vinc
;
1377 const struct accu
*accu_table
;
1378 const struct accu
*accu_val
;
1380 static const struct accu accu_nv12
[4] = {
1381 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1382 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1383 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1384 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1387 static const struct accu accu_nv12_ilace
[4] = {
1388 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1389 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1390 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1391 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1394 static const struct accu accu_yuv
[4] = {
1395 { 0, 1, 0, 1, 0, 1, 0, 1 },
1396 { 0, 1, 0, 1, 0, 1, 0, 1 },
1397 { -1, 1, 0, 1, 0, 1, 0, 1 },
1398 { 0, 1, 0, 1, -1, 1, 0, 1 },
1402 case OMAP_DSS_ROT_0
:
1405 case OMAP_DSS_ROT_90
:
1408 case OMAP_DSS_ROT_180
:
1411 case OMAP_DSS_ROT_270
:
1419 switch (color_mode
) {
1420 case OMAP_DSS_COLOR_NV12
:
1422 accu_table
= accu_nv12_ilace
;
1424 accu_table
= accu_nv12
;
1426 case OMAP_DSS_COLOR_YUV2
:
1427 case OMAP_DSS_COLOR_UYVY
:
1428 accu_table
= accu_yuv
;
1435 accu_val
= &accu_table
[idx
];
1437 chroma_hinc
= 1024 * orig_width
/ out_width
;
1438 chroma_vinc
= 1024 * orig_height
/ out_height
;
1440 h_accu2_0
= (accu_val
->h0_m
* chroma_hinc
/ accu_val
->h0_n
) % 1024;
1441 h_accu2_1
= (accu_val
->h1_m
* chroma_hinc
/ accu_val
->h1_n
) % 1024;
1442 v_accu2_0
= (accu_val
->v0_m
* chroma_vinc
/ accu_val
->v0_n
) % 1024;
1443 v_accu2_1
= (accu_val
->v1_m
* chroma_vinc
/ accu_val
->v1_n
) % 1024;
1445 dispc_ovl_set_vid_accu2_0(plane
, h_accu2_0
, v_accu2_0
);
1446 dispc_ovl_set_vid_accu2_1(plane
, h_accu2_1
, v_accu2_1
);
1449 static void dispc_ovl_set_scaling_common(enum omap_plane plane
,
1450 u16 orig_width
, u16 orig_height
,
1451 u16 out_width
, u16 out_height
,
1452 bool ilace
, bool five_taps
,
1453 bool fieldmode
, enum omap_color_mode color_mode
,
1460 dispc_ovl_set_scale_param(plane
, orig_width
, orig_height
,
1461 out_width
, out_height
, five_taps
,
1462 rotation
, DISPC_COLOR_COMPONENT_RGB_Y
);
1463 l
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
1465 /* RESIZEENABLE and VERTICALTAPS */
1466 l
&= ~((0x3 << 5) | (0x1 << 21));
1467 l
|= (orig_width
!= out_width
) ? (1 << 5) : 0;
1468 l
|= (orig_height
!= out_height
) ? (1 << 6) : 0;
1469 l
|= five_taps
? (1 << 21) : 0;
1471 /* VRESIZECONF and HRESIZECONF */
1472 if (dss_has_feature(FEAT_RESIZECONF
)) {
1474 l
|= (orig_width
<= out_width
) ? 0 : (1 << 7);
1475 l
|= (orig_height
<= out_height
) ? 0 : (1 << 8);
1478 /* LINEBUFFERSPLIT */
1479 if (dss_has_feature(FEAT_LINEBUFFERSPLIT
)) {
1481 l
|= five_taps
? (1 << 22) : 0;
1484 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), l
);
1487 * field 0 = even field = bottom field
1488 * field 1 = odd field = top field
1490 if (ilace
&& !fieldmode
) {
1492 accu0
= ((1024 * orig_height
/ out_height
) / 2) & 0x3ff;
1493 if (accu0
>= 1024/2) {
1499 dispc_ovl_set_vid_accu0(plane
, 0, accu0
);
1500 dispc_ovl_set_vid_accu1(plane
, 0, accu1
);
1503 static void dispc_ovl_set_scaling_uv(enum omap_plane plane
,
1504 u16 orig_width
, u16 orig_height
,
1505 u16 out_width
, u16 out_height
,
1506 bool ilace
, bool five_taps
,
1507 bool fieldmode
, enum omap_color_mode color_mode
,
1510 int scale_x
= out_width
!= orig_width
;
1511 int scale_y
= out_height
!= orig_height
;
1512 bool chroma_upscale
= plane
!= OMAP_DSS_WB
? true : false;
1514 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE
))
1516 if ((color_mode
!= OMAP_DSS_COLOR_YUV2
&&
1517 color_mode
!= OMAP_DSS_COLOR_UYVY
&&
1518 color_mode
!= OMAP_DSS_COLOR_NV12
)) {
1519 /* reset chroma resampling for RGB formats */
1520 if (plane
!= OMAP_DSS_WB
)
1521 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
), 0, 8, 8);
1525 dispc_ovl_set_accu_uv(plane
, orig_width
, orig_height
, out_width
,
1526 out_height
, ilace
, color_mode
, rotation
);
1528 switch (color_mode
) {
1529 case OMAP_DSS_COLOR_NV12
:
1530 if (chroma_upscale
) {
1531 /* UV is subsampled by 2 horizontally and vertically */
1535 /* UV is downsampled by 2 horizontally and vertically */
1541 case OMAP_DSS_COLOR_YUV2
:
1542 case OMAP_DSS_COLOR_UYVY
:
1543 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
1544 if (rotation
== OMAP_DSS_ROT_0
||
1545 rotation
== OMAP_DSS_ROT_180
) {
1547 /* UV is subsampled by 2 horizontally */
1550 /* UV is downsampled by 2 horizontally */
1554 /* must use FIR for YUV422 if rotated */
1555 if (rotation
!= OMAP_DSS_ROT_0
)
1556 scale_x
= scale_y
= true;
1564 if (out_width
!= orig_width
)
1566 if (out_height
!= orig_height
)
1569 dispc_ovl_set_scale_param(plane
, orig_width
, orig_height
,
1570 out_width
, out_height
, five_taps
,
1571 rotation
, DISPC_COLOR_COMPONENT_UV
);
1573 if (plane
!= OMAP_DSS_WB
)
1574 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane
),
1575 (scale_x
|| scale_y
) ? 1 : 0, 8, 8);
1578 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), scale_x
? 1 : 0, 5, 5);
1580 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), scale_y
? 1 : 0, 6, 6);
1583 static void dispc_ovl_set_scaling(enum omap_plane plane
,
1584 u16 orig_width
, u16 orig_height
,
1585 u16 out_width
, u16 out_height
,
1586 bool ilace
, bool five_taps
,
1587 bool fieldmode
, enum omap_color_mode color_mode
,
1590 BUG_ON(plane
== OMAP_DSS_GFX
);
1592 dispc_ovl_set_scaling_common(plane
,
1593 orig_width
, orig_height
,
1594 out_width
, out_height
,
1596 fieldmode
, color_mode
,
1599 dispc_ovl_set_scaling_uv(plane
,
1600 orig_width
, orig_height
,
1601 out_width
, out_height
,
1603 fieldmode
, color_mode
,
1607 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane
, u8 rotation
,
1608 enum omap_dss_rotation_type rotation_type
,
1609 bool mirroring
, enum omap_color_mode color_mode
)
1611 bool row_repeat
= false;
1614 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1615 color_mode
== OMAP_DSS_COLOR_UYVY
) {
1619 case OMAP_DSS_ROT_0
:
1622 case OMAP_DSS_ROT_90
:
1625 case OMAP_DSS_ROT_180
:
1628 case OMAP_DSS_ROT_270
:
1634 case OMAP_DSS_ROT_0
:
1637 case OMAP_DSS_ROT_90
:
1640 case OMAP_DSS_ROT_180
:
1643 case OMAP_DSS_ROT_270
:
1649 if (rotation
== OMAP_DSS_ROT_90
|| rotation
== OMAP_DSS_ROT_270
)
1655 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), vidrot
, 13, 12);
1656 if (dss_has_feature(FEAT_ROWREPEATENABLE
))
1657 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
),
1658 row_repeat
? 1 : 0, 18, 18);
1660 if (color_mode
== OMAP_DSS_COLOR_NV12
) {
1661 bool doublestride
= (rotation_type
== OMAP_DSS_ROT_TILER
) &&
1662 (rotation
== OMAP_DSS_ROT_0
||
1663 rotation
== OMAP_DSS_ROT_180
);
1665 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), doublestride
, 22, 22);
1670 static int color_mode_to_bpp(enum omap_color_mode color_mode
)
1672 switch (color_mode
) {
1673 case OMAP_DSS_COLOR_CLUT1
:
1675 case OMAP_DSS_COLOR_CLUT2
:
1677 case OMAP_DSS_COLOR_CLUT4
:
1679 case OMAP_DSS_COLOR_CLUT8
:
1680 case OMAP_DSS_COLOR_NV12
:
1682 case OMAP_DSS_COLOR_RGB12U
:
1683 case OMAP_DSS_COLOR_RGB16
:
1684 case OMAP_DSS_COLOR_ARGB16
:
1685 case OMAP_DSS_COLOR_YUV2
:
1686 case OMAP_DSS_COLOR_UYVY
:
1687 case OMAP_DSS_COLOR_RGBA16
:
1688 case OMAP_DSS_COLOR_RGBX16
:
1689 case OMAP_DSS_COLOR_ARGB16_1555
:
1690 case OMAP_DSS_COLOR_XRGB16_1555
:
1692 case OMAP_DSS_COLOR_RGB24P
:
1694 case OMAP_DSS_COLOR_RGB24U
:
1695 case OMAP_DSS_COLOR_ARGB32
:
1696 case OMAP_DSS_COLOR_RGBA32
:
1697 case OMAP_DSS_COLOR_RGBX32
:
1705 static s32
pixinc(int pixels
, u8 ps
)
1709 else if (pixels
> 1)
1710 return 1 + (pixels
- 1) * ps
;
1711 else if (pixels
< 0)
1712 return 1 - (-pixels
+ 1) * ps
;
1718 static void calc_vrfb_rotation_offset(u8 rotation
, bool mirror
,
1720 u16 width
, u16 height
,
1721 enum omap_color_mode color_mode
, bool fieldmode
,
1722 unsigned int field_offset
,
1723 unsigned *offset0
, unsigned *offset1
,
1724 s32
*row_inc
, s32
*pix_inc
, int x_predecim
, int y_predecim
)
1728 /* FIXME CLUT formats */
1729 switch (color_mode
) {
1730 case OMAP_DSS_COLOR_CLUT1
:
1731 case OMAP_DSS_COLOR_CLUT2
:
1732 case OMAP_DSS_COLOR_CLUT4
:
1733 case OMAP_DSS_COLOR_CLUT8
:
1736 case OMAP_DSS_COLOR_YUV2
:
1737 case OMAP_DSS_COLOR_UYVY
:
1741 ps
= color_mode_to_bpp(color_mode
) / 8;
1745 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation
, screen_width
,
1749 * field 0 = even field = bottom field
1750 * field 1 = odd field = top field
1752 switch (rotation
+ mirror
* 4) {
1753 case OMAP_DSS_ROT_0
:
1754 case OMAP_DSS_ROT_180
:
1756 * If the pixel format is YUV or UYVY divide the width
1757 * of the image by 2 for 0 and 180 degree rotation.
1759 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1760 color_mode
== OMAP_DSS_COLOR_UYVY
)
1762 case OMAP_DSS_ROT_90
:
1763 case OMAP_DSS_ROT_270
:
1766 *offset0
= field_offset
* screen_width
* ps
;
1770 *row_inc
= pixinc(1 +
1771 (y_predecim
* screen_width
- x_predecim
* width
) +
1772 (fieldmode
? screen_width
: 0), ps
);
1773 *pix_inc
= pixinc(x_predecim
, ps
);
1776 case OMAP_DSS_ROT_0
+ 4:
1777 case OMAP_DSS_ROT_180
+ 4:
1778 /* If the pixel format is YUV or UYVY divide the width
1779 * of the image by 2 for 0 degree and 180 degree
1781 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1782 color_mode
== OMAP_DSS_COLOR_UYVY
)
1784 case OMAP_DSS_ROT_90
+ 4:
1785 case OMAP_DSS_ROT_270
+ 4:
1788 *offset0
= field_offset
* screen_width
* ps
;
1791 *row_inc
= pixinc(1 -
1792 (y_predecim
* screen_width
+ x_predecim
* width
) -
1793 (fieldmode
? screen_width
: 0), ps
);
1794 *pix_inc
= pixinc(x_predecim
, ps
);
1803 static void calc_dma_rotation_offset(u8 rotation
, bool mirror
,
1805 u16 width
, u16 height
,
1806 enum omap_color_mode color_mode
, bool fieldmode
,
1807 unsigned int field_offset
,
1808 unsigned *offset0
, unsigned *offset1
,
1809 s32
*row_inc
, s32
*pix_inc
, int x_predecim
, int y_predecim
)
1814 /* FIXME CLUT formats */
1815 switch (color_mode
) {
1816 case OMAP_DSS_COLOR_CLUT1
:
1817 case OMAP_DSS_COLOR_CLUT2
:
1818 case OMAP_DSS_COLOR_CLUT4
:
1819 case OMAP_DSS_COLOR_CLUT8
:
1823 ps
= color_mode_to_bpp(color_mode
) / 8;
1827 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation
, screen_width
,
1830 /* width & height are overlay sizes, convert to fb sizes */
1832 if (rotation
== OMAP_DSS_ROT_0
|| rotation
== OMAP_DSS_ROT_180
) {
1841 * field 0 = even field = bottom field
1842 * field 1 = odd field = top field
1844 switch (rotation
+ mirror
* 4) {
1845 case OMAP_DSS_ROT_0
:
1848 *offset0
= *offset1
+ field_offset
* screen_width
* ps
;
1850 *offset0
= *offset1
;
1851 *row_inc
= pixinc(1 +
1852 (y_predecim
* screen_width
- fbw
* x_predecim
) +
1853 (fieldmode
? screen_width
: 0), ps
);
1854 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1855 color_mode
== OMAP_DSS_COLOR_UYVY
)
1856 *pix_inc
= pixinc(x_predecim
, 2 * ps
);
1858 *pix_inc
= pixinc(x_predecim
, ps
);
1860 case OMAP_DSS_ROT_90
:
1861 *offset1
= screen_width
* (fbh
- 1) * ps
;
1863 *offset0
= *offset1
+ field_offset
* ps
;
1865 *offset0
= *offset1
;
1866 *row_inc
= pixinc(screen_width
* (fbh
* x_predecim
- 1) +
1867 y_predecim
+ (fieldmode
? 1 : 0), ps
);
1868 *pix_inc
= pixinc(-x_predecim
* screen_width
, ps
);
1870 case OMAP_DSS_ROT_180
:
1871 *offset1
= (screen_width
* (fbh
- 1) + fbw
- 1) * ps
;
1873 *offset0
= *offset1
- field_offset
* screen_width
* ps
;
1875 *offset0
= *offset1
;
1876 *row_inc
= pixinc(-1 -
1877 (y_predecim
* screen_width
- fbw
* x_predecim
) -
1878 (fieldmode
? screen_width
: 0), ps
);
1879 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1880 color_mode
== OMAP_DSS_COLOR_UYVY
)
1881 *pix_inc
= pixinc(-x_predecim
, 2 * ps
);
1883 *pix_inc
= pixinc(-x_predecim
, ps
);
1885 case OMAP_DSS_ROT_270
:
1886 *offset1
= (fbw
- 1) * ps
;
1888 *offset0
= *offset1
- field_offset
* ps
;
1890 *offset0
= *offset1
;
1891 *row_inc
= pixinc(-screen_width
* (fbh
* x_predecim
- 1) -
1892 y_predecim
- (fieldmode
? 1 : 0), ps
);
1893 *pix_inc
= pixinc(x_predecim
* screen_width
, ps
);
1897 case OMAP_DSS_ROT_0
+ 4:
1898 *offset1
= (fbw
- 1) * ps
;
1900 *offset0
= *offset1
+ field_offset
* screen_width
* ps
;
1902 *offset0
= *offset1
;
1903 *row_inc
= pixinc(y_predecim
* screen_width
* 2 - 1 +
1904 (fieldmode
? screen_width
: 0),
1906 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1907 color_mode
== OMAP_DSS_COLOR_UYVY
)
1908 *pix_inc
= pixinc(-x_predecim
, 2 * ps
);
1910 *pix_inc
= pixinc(-x_predecim
, ps
);
1913 case OMAP_DSS_ROT_90
+ 4:
1916 *offset0
= *offset1
+ field_offset
* ps
;
1918 *offset0
= *offset1
;
1919 *row_inc
= pixinc(-screen_width
* (fbh
* x_predecim
- 1) +
1920 y_predecim
+ (fieldmode
? 1 : 0),
1922 *pix_inc
= pixinc(x_predecim
* screen_width
, ps
);
1925 case OMAP_DSS_ROT_180
+ 4:
1926 *offset1
= screen_width
* (fbh
- 1) * ps
;
1928 *offset0
= *offset1
- field_offset
* screen_width
* ps
;
1930 *offset0
= *offset1
;
1931 *row_inc
= pixinc(1 - y_predecim
* screen_width
* 2 -
1932 (fieldmode
? screen_width
: 0),
1934 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1935 color_mode
== OMAP_DSS_COLOR_UYVY
)
1936 *pix_inc
= pixinc(x_predecim
, 2 * ps
);
1938 *pix_inc
= pixinc(x_predecim
, ps
);
1941 case OMAP_DSS_ROT_270
+ 4:
1942 *offset1
= (screen_width
* (fbh
- 1) + fbw
- 1) * ps
;
1944 *offset0
= *offset1
- field_offset
* ps
;
1946 *offset0
= *offset1
;
1947 *row_inc
= pixinc(screen_width
* (fbh
* x_predecim
- 1) -
1948 y_predecim
- (fieldmode
? 1 : 0),
1950 *pix_inc
= pixinc(-x_predecim
* screen_width
, ps
);
1959 static void calc_tiler_rotation_offset(u16 screen_width
, u16 width
,
1960 enum omap_color_mode color_mode
, bool fieldmode
,
1961 unsigned int field_offset
, unsigned *offset0
, unsigned *offset1
,
1962 s32
*row_inc
, s32
*pix_inc
, int x_predecim
, int y_predecim
)
1966 switch (color_mode
) {
1967 case OMAP_DSS_COLOR_CLUT1
:
1968 case OMAP_DSS_COLOR_CLUT2
:
1969 case OMAP_DSS_COLOR_CLUT4
:
1970 case OMAP_DSS_COLOR_CLUT8
:
1974 ps
= color_mode_to_bpp(color_mode
) / 8;
1978 DSSDBG("scrw %d, width %d\n", screen_width
, width
);
1981 * field 0 = even field = bottom field
1982 * field 1 = odd field = top field
1986 *offset0
= *offset1
+ field_offset
* screen_width
* ps
;
1988 *offset0
= *offset1
;
1989 *row_inc
= pixinc(1 + (y_predecim
* screen_width
- width
* x_predecim
) +
1990 (fieldmode
? screen_width
: 0), ps
);
1991 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
1992 color_mode
== OMAP_DSS_COLOR_UYVY
)
1993 *pix_inc
= pixinc(x_predecim
, 2 * ps
);
1995 *pix_inc
= pixinc(x_predecim
, ps
);
1999 * This function is used to avoid synclosts in OMAP3, because of some
2000 * undocumented horizontal position and timing related limitations.
2002 static int check_horiz_timing_omap3(unsigned long pclk
, unsigned long lclk
,
2003 const struct omap_video_timings
*t
, u16 pos_x
,
2004 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2007 const int ds
= DIV_ROUND_UP(height
, out_height
);
2008 unsigned long nonactive
;
2009 static const u8 limits
[3] = { 8, 10, 20 };
2013 nonactive
= t
->x_res
+ t
->hfp
+ t
->hsw
+ t
->hbp
- out_width
;
2016 if (out_height
< height
)
2018 if (out_width
< width
)
2020 blank
= div_u64((u64
)(t
->hbp
+ t
->hsw
+ t
->hfp
) * lclk
, pclk
);
2021 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank
, limits
[i
]);
2022 if (blank
<= limits
[i
])
2025 /* FIXME add checks for 3-tap filter once the limitations are known */
2030 * Pixel data should be prepared before visible display point starts.
2031 * So, atleast DS-2 lines must have already been fetched by DISPC
2032 * during nonactive - pos_x period.
2034 val
= div_u64((u64
)(nonactive
- pos_x
) * lclk
, pclk
);
2035 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2036 val
, max(0, ds
- 2) * width
);
2037 if (val
< max(0, ds
- 2) * width
)
2041 * All lines need to be refilled during the nonactive period of which
2042 * only one line can be loaded during the active period. So, atleast
2043 * DS - 1 lines should be loaded during nonactive period.
2045 val
= div_u64((u64
)nonactive
* lclk
, pclk
);
2046 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2047 val
, max(0, ds
- 1) * width
);
2048 if (val
< max(0, ds
- 1) * width
)
2054 static unsigned long calc_core_clk_five_taps(unsigned long pclk
,
2055 const struct omap_video_timings
*mgr_timings
, u16 width
,
2056 u16 height
, u16 out_width
, u16 out_height
,
2057 enum omap_color_mode color_mode
)
2062 if (height
<= out_height
&& width
<= out_width
)
2063 return (unsigned long) pclk
;
2065 if (height
> out_height
) {
2066 unsigned int ppl
= mgr_timings
->x_res
;
2068 tmp
= pclk
* height
* out_width
;
2069 do_div(tmp
, 2 * out_height
* ppl
);
2072 if (height
> 2 * out_height
) {
2073 if (ppl
== out_width
)
2076 tmp
= pclk
* (height
- 2 * out_height
) * out_width
;
2077 do_div(tmp
, 2 * out_height
* (ppl
- out_width
));
2078 core_clk
= max_t(u32
, core_clk
, tmp
);
2082 if (width
> out_width
) {
2084 do_div(tmp
, out_width
);
2085 core_clk
= max_t(u32
, core_clk
, tmp
);
2087 if (color_mode
== OMAP_DSS_COLOR_RGB24U
)
2094 static unsigned long calc_core_clk_24xx(unsigned long pclk
, u16 width
,
2095 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2097 if (height
> out_height
&& width
> out_width
)
2103 static unsigned long calc_core_clk_34xx(unsigned long pclk
, u16 width
,
2104 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2106 unsigned int hf
, vf
;
2109 * FIXME how to determine the 'A' factor
2110 * for the no downscaling case ?
2113 if (width
> 3 * out_width
)
2115 else if (width
> 2 * out_width
)
2117 else if (width
> out_width
)
2121 if (height
> out_height
)
2126 return pclk
* vf
* hf
;
2129 static unsigned long calc_core_clk_44xx(unsigned long pclk
, u16 width
,
2130 u16 height
, u16 out_width
, u16 out_height
, bool mem_to_mem
)
2133 * If the overlay/writeback is in mem to mem mode, there are no
2134 * downscaling limitations with respect to pixel clock, return 1 as
2135 * required core clock to represent that we have sufficient enough
2136 * core clock to do maximum downscaling
2141 if (width
> out_width
)
2142 return DIV_ROUND_UP(pclk
, out_width
) * width
;
2147 static int dispc_ovl_calc_scaling_24xx(unsigned long pclk
, unsigned long lclk
,
2148 const struct omap_video_timings
*mgr_timings
,
2149 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2150 enum omap_color_mode color_mode
, bool *five_taps
,
2151 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2152 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2155 u16 in_width
, in_height
;
2156 int min_factor
= min(*decim_x
, *decim_y
);
2157 const int maxsinglelinewidth
=
2158 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH
);
2163 in_height
= DIV_ROUND_UP(height
, *decim_y
);
2164 in_width
= DIV_ROUND_UP(width
, *decim_x
);
2165 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
,
2166 in_height
, out_width
, out_height
, mem_to_mem
);
2167 error
= (in_width
> maxsinglelinewidth
|| !*core_clk
||
2168 *core_clk
> dispc_core_clk_rate());
2170 if (*decim_x
== *decim_y
) {
2171 *decim_x
= min_factor
;
2174 swap(*decim_x
, *decim_y
);
2175 if (*decim_x
< *decim_y
)
2179 } while (*decim_x
<= *x_predecim
&& *decim_y
<= *y_predecim
&& error
);
2181 if (in_width
> maxsinglelinewidth
) {
2182 DSSERR("Cannot scale max input width exceeded");
2188 static int dispc_ovl_calc_scaling_34xx(unsigned long pclk
, unsigned long lclk
,
2189 const struct omap_video_timings
*mgr_timings
,
2190 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2191 enum omap_color_mode color_mode
, bool *five_taps
,
2192 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2193 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2196 u16 in_width
, in_height
;
2197 int min_factor
= min(*decim_x
, *decim_y
);
2198 const int maxsinglelinewidth
=
2199 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH
);
2202 in_height
= DIV_ROUND_UP(height
, *decim_y
);
2203 in_width
= DIV_ROUND_UP(width
, *decim_x
);
2204 *five_taps
= in_height
> out_height
;
2206 if (in_width
> maxsinglelinewidth
)
2207 if (in_height
> out_height
&&
2208 in_height
< out_height
* 2)
2212 *core_clk
= calc_core_clk_five_taps(pclk
, mgr_timings
,
2213 in_width
, in_height
, out_width
,
2214 out_height
, color_mode
);
2216 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
,
2217 in_height
, out_width
, out_height
,
2220 error
= check_horiz_timing_omap3(pclk
, lclk
, mgr_timings
,
2221 pos_x
, in_width
, in_height
, out_width
,
2222 out_height
, *five_taps
);
2223 if (error
&& *five_taps
) {
2228 error
= (error
|| in_width
> maxsinglelinewidth
* 2 ||
2229 (in_width
> maxsinglelinewidth
&& *five_taps
) ||
2230 !*core_clk
|| *core_clk
> dispc_core_clk_rate());
2232 if (*decim_x
== *decim_y
) {
2233 *decim_x
= min_factor
;
2236 swap(*decim_x
, *decim_y
);
2237 if (*decim_x
< *decim_y
)
2241 } while (*decim_x
<= *x_predecim
&& *decim_y
<= *y_predecim
&& error
);
2243 if (check_horiz_timing_omap3(pclk
, lclk
, mgr_timings
, pos_x
, width
,
2244 height
, out_width
, out_height
, *five_taps
)) {
2245 DSSERR("horizontal timing too tight\n");
2249 if (in_width
> (maxsinglelinewidth
* 2)) {
2250 DSSERR("Cannot setup scaling");
2251 DSSERR("width exceeds maximum width possible");
2255 if (in_width
> maxsinglelinewidth
&& *five_taps
) {
2256 DSSERR("cannot setup scaling with five taps");
2262 static int dispc_ovl_calc_scaling_44xx(unsigned long pclk
, unsigned long lclk
,
2263 const struct omap_video_timings
*mgr_timings
,
2264 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2265 enum omap_color_mode color_mode
, bool *five_taps
,
2266 int *x_predecim
, int *y_predecim
, int *decim_x
, int *decim_y
,
2267 u16 pos_x
, unsigned long *core_clk
, bool mem_to_mem
)
2269 u16 in_width
, in_width_max
;
2270 int decim_x_min
= *decim_x
;
2271 u16 in_height
= DIV_ROUND_UP(height
, *decim_y
);
2272 const int maxsinglelinewidth
=
2273 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH
);
2274 const int maxdownscale
= dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE
);
2277 in_width_max
= out_width
* maxdownscale
;
2279 in_width_max
= dispc_core_clk_rate() /
2280 DIV_ROUND_UP(pclk
, out_width
);
2283 *decim_x
= DIV_ROUND_UP(width
, in_width_max
);
2285 *decim_x
= *decim_x
> decim_x_min
? *decim_x
: decim_x_min
;
2286 if (*decim_x
> *x_predecim
)
2290 in_width
= DIV_ROUND_UP(width
, *decim_x
);
2291 } while (*decim_x
<= *x_predecim
&&
2292 in_width
> maxsinglelinewidth
&& ++*decim_x
);
2294 if (in_width
> maxsinglelinewidth
) {
2295 DSSERR("Cannot scale width exceeds max line width");
2299 *core_clk
= dispc
.feat
->calc_core_clk(pclk
, in_width
, in_height
,
2300 out_width
, out_height
, mem_to_mem
);
2304 static int dispc_ovl_calc_scaling(unsigned long pclk
, unsigned long lclk
,
2305 enum omap_overlay_caps caps
,
2306 const struct omap_video_timings
*mgr_timings
,
2307 u16 width
, u16 height
, u16 out_width
, u16 out_height
,
2308 enum omap_color_mode color_mode
, bool *five_taps
,
2309 int *x_predecim
, int *y_predecim
, u16 pos_x
,
2310 enum omap_dss_rotation_type rotation_type
, bool mem_to_mem
)
2312 const int maxdownscale
= dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE
);
2313 const int max_decim_limit
= 16;
2314 unsigned long core_clk
= 0;
2315 int decim_x
, decim_y
, ret
;
2317 if (width
== out_width
&& height
== out_height
)
2320 if ((caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0)
2324 *x_predecim
= *y_predecim
= 1;
2326 *x_predecim
= max_decim_limit
;
2327 *y_predecim
= (rotation_type
== OMAP_DSS_ROT_TILER
&&
2328 dss_has_feature(FEAT_BURST_2D
)) ?
2329 2 : max_decim_limit
;
2332 if (color_mode
== OMAP_DSS_COLOR_CLUT1
||
2333 color_mode
== OMAP_DSS_COLOR_CLUT2
||
2334 color_mode
== OMAP_DSS_COLOR_CLUT4
||
2335 color_mode
== OMAP_DSS_COLOR_CLUT8
) {
2342 decim_x
= DIV_ROUND_UP(DIV_ROUND_UP(width
, out_width
), maxdownscale
);
2343 decim_y
= DIV_ROUND_UP(DIV_ROUND_UP(height
, out_height
), maxdownscale
);
2345 if (decim_x
> *x_predecim
|| out_width
> width
* 8)
2348 if (decim_y
> *y_predecim
|| out_height
> height
* 8)
2351 ret
= dispc
.feat
->calc_scaling(pclk
, lclk
, mgr_timings
, width
, height
,
2352 out_width
, out_height
, color_mode
, five_taps
,
2353 x_predecim
, y_predecim
, &decim_x
, &decim_y
, pos_x
, &core_clk
,
2358 DSSDBG("required core clk rate = %lu Hz\n", core_clk
);
2359 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
2361 if (!core_clk
|| core_clk
> dispc_core_clk_rate()) {
2362 DSSERR("failed to set up scaling, "
2363 "required core clk rate = %lu Hz, "
2364 "current core clk rate = %lu Hz\n",
2365 core_clk
, dispc_core_clk_rate());
2369 *x_predecim
= decim_x
;
2370 *y_predecim
= decim_y
;
2374 int dispc_ovl_check(enum omap_plane plane
, enum omap_channel channel
,
2375 const struct omap_overlay_info
*oi
,
2376 const struct omap_video_timings
*timings
,
2377 int *x_predecim
, int *y_predecim
)
2379 enum omap_overlay_caps caps
= dss_feat_get_overlay_caps(plane
);
2380 bool five_taps
= true;
2381 bool fieldmode
= false;
2382 u16 in_height
= oi
->height
;
2383 u16 in_width
= oi
->width
;
2384 bool ilace
= timings
->interlace
;
2385 u16 out_width
, out_height
;
2386 int pos_x
= oi
->pos_x
;
2387 unsigned long pclk
= dispc_mgr_pclk_rate(channel
);
2388 unsigned long lclk
= dispc_mgr_lclk_rate(channel
);
2390 out_width
= oi
->out_width
== 0 ? oi
->width
: oi
->out_width
;
2391 out_height
= oi
->out_height
== 0 ? oi
->height
: oi
->out_height
;
2393 if (ilace
&& oi
->height
== out_height
)
2401 DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2402 in_height
, out_height
);
2405 if (!dss_feat_color_mode_supported(plane
, oi
->color_mode
))
2408 return dispc_ovl_calc_scaling(pclk
, lclk
, caps
, timings
, in_width
,
2409 in_height
, out_width
, out_height
, oi
->color_mode
,
2410 &five_taps
, x_predecim
, y_predecim
, pos_x
,
2411 oi
->rotation_type
, false);
2413 EXPORT_SYMBOL(dispc_ovl_check
);
2415 static int dispc_ovl_setup_common(enum omap_plane plane
,
2416 enum omap_overlay_caps caps
, u32 paddr
, u32 p_uv_addr
,
2417 u16 screen_width
, int pos_x
, int pos_y
, u16 width
, u16 height
,
2418 u16 out_width
, u16 out_height
, enum omap_color_mode color_mode
,
2419 u8 rotation
, bool mirror
, u8 zorder
, u8 pre_mult_alpha
,
2420 u8 global_alpha
, enum omap_dss_rotation_type rotation_type
,
2421 bool replication
, const struct omap_video_timings
*mgr_timings
,
2424 bool five_taps
= true;
2425 bool fieldmode
= false;
2427 unsigned offset0
, offset1
;
2430 u16 frame_width
, frame_height
;
2431 unsigned int field_offset
= 0;
2432 u16 in_height
= height
;
2433 u16 in_width
= width
;
2434 int x_predecim
= 1, y_predecim
= 1;
2435 bool ilace
= mgr_timings
->interlace
;
2436 unsigned long pclk
= dispc_plane_pclk_rate(plane
);
2437 unsigned long lclk
= dispc_plane_lclk_rate(plane
);
2442 out_width
= out_width
== 0 ? width
: out_width
;
2443 out_height
= out_height
== 0 ? height
: out_height
;
2445 if (ilace
&& height
== out_height
)
2454 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2455 "out_height %d\n", in_height
, pos_y
,
2459 if (!dss_feat_color_mode_supported(plane
, color_mode
))
2462 r
= dispc_ovl_calc_scaling(pclk
, lclk
, caps
, mgr_timings
, in_width
,
2463 in_height
, out_width
, out_height
, color_mode
,
2464 &five_taps
, &x_predecim
, &y_predecim
, pos_x
,
2465 rotation_type
, mem_to_mem
);
2469 in_width
= DIV_ROUND_UP(in_width
, x_predecim
);
2470 in_height
= DIV_ROUND_UP(in_height
, y_predecim
);
2472 if (color_mode
== OMAP_DSS_COLOR_YUV2
||
2473 color_mode
== OMAP_DSS_COLOR_UYVY
||
2474 color_mode
== OMAP_DSS_COLOR_NV12
)
2477 if (ilace
&& !fieldmode
) {
2479 * when downscaling the bottom field may have to start several
2480 * source lines below the top field. Unfortunately ACCUI
2481 * registers will only hold the fractional part of the offset
2482 * so the integer part must be added to the base address of the
2485 if (!in_height
|| in_height
== out_height
)
2488 field_offset
= in_height
/ out_height
/ 2;
2491 /* Fields are independent but interleaved in memory. */
2500 if (plane
== OMAP_DSS_WB
) {
2501 frame_width
= out_width
;
2502 frame_height
= out_height
;
2504 frame_width
= in_width
;
2505 frame_height
= height
;
2508 if (rotation_type
== OMAP_DSS_ROT_TILER
)
2509 calc_tiler_rotation_offset(screen_width
, frame_width
,
2510 color_mode
, fieldmode
, field_offset
,
2511 &offset0
, &offset1
, &row_inc
, &pix_inc
,
2512 x_predecim
, y_predecim
);
2513 else if (rotation_type
== OMAP_DSS_ROT_DMA
)
2514 calc_dma_rotation_offset(rotation
, mirror
, screen_width
,
2515 frame_width
, frame_height
,
2516 color_mode
, fieldmode
, field_offset
,
2517 &offset0
, &offset1
, &row_inc
, &pix_inc
,
2518 x_predecim
, y_predecim
);
2520 calc_vrfb_rotation_offset(rotation
, mirror
,
2521 screen_width
, frame_width
, frame_height
,
2522 color_mode
, fieldmode
, field_offset
,
2523 &offset0
, &offset1
, &row_inc
, &pix_inc
,
2524 x_predecim
, y_predecim
);
2526 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2527 offset0
, offset1
, row_inc
, pix_inc
);
2529 dispc_ovl_set_color_mode(plane
, color_mode
);
2531 dispc_ovl_configure_burst_type(plane
, rotation_type
);
2533 dispc_ovl_set_ba0(plane
, paddr
+ offset0
);
2534 dispc_ovl_set_ba1(plane
, paddr
+ offset1
);
2536 if (OMAP_DSS_COLOR_NV12
== color_mode
) {
2537 dispc_ovl_set_ba0_uv(plane
, p_uv_addr
+ offset0
);
2538 dispc_ovl_set_ba1_uv(plane
, p_uv_addr
+ offset1
);
2541 dispc_ovl_set_row_inc(plane
, row_inc
);
2542 dispc_ovl_set_pix_inc(plane
, pix_inc
);
2544 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x
, pos_y
, in_width
,
2545 in_height
, out_width
, out_height
);
2547 dispc_ovl_set_pos(plane
, caps
, pos_x
, pos_y
);
2549 dispc_ovl_set_input_size(plane
, in_width
, in_height
);
2551 if (caps
& OMAP_DSS_OVL_CAP_SCALE
) {
2552 dispc_ovl_set_scaling(plane
, in_width
, in_height
, out_width
,
2553 out_height
, ilace
, five_taps
, fieldmode
,
2554 color_mode
, rotation
);
2555 dispc_ovl_set_output_size(plane
, out_width
, out_height
);
2556 dispc_ovl_set_vid_color_conv(plane
, cconv
);
2559 dispc_ovl_set_rotation_attrs(plane
, rotation
, rotation_type
, mirror
,
2562 dispc_ovl_set_zorder(plane
, caps
, zorder
);
2563 dispc_ovl_set_pre_mult_alpha(plane
, caps
, pre_mult_alpha
);
2564 dispc_ovl_setup_global_alpha(plane
, caps
, global_alpha
);
2566 dispc_ovl_enable_replication(plane
, caps
, replication
);
2571 int dispc_ovl_setup(enum omap_plane plane
, const struct omap_overlay_info
*oi
,
2572 bool replication
, const struct omap_video_timings
*mgr_timings
,
2576 enum omap_overlay_caps caps
= dss_feat_get_overlay_caps(plane
);
2577 enum omap_channel channel
;
2579 channel
= dispc_ovl_get_channel_out(plane
);
2581 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
2582 "%dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2583 plane
, oi
->paddr
, oi
->p_uv_addr
, oi
->screen_width
, oi
->pos_x
,
2584 oi
->pos_y
, oi
->width
, oi
->height
, oi
->out_width
, oi
->out_height
,
2585 oi
->color_mode
, oi
->rotation
, oi
->mirror
, channel
, replication
);
2587 r
= dispc_ovl_setup_common(plane
, caps
, oi
->paddr
, oi
->p_uv_addr
,
2588 oi
->screen_width
, oi
->pos_x
, oi
->pos_y
, oi
->width
, oi
->height
,
2589 oi
->out_width
, oi
->out_height
, oi
->color_mode
, oi
->rotation
,
2590 oi
->mirror
, oi
->zorder
, oi
->pre_mult_alpha
, oi
->global_alpha
,
2591 oi
->rotation_type
, replication
, mgr_timings
, mem_to_mem
);
2595 EXPORT_SYMBOL(dispc_ovl_setup
);
2597 int dispc_wb_setup(const struct omap_dss_writeback_info
*wi
,
2598 bool mem_to_mem
, const struct omap_video_timings
*mgr_timings
)
2602 enum omap_plane plane
= OMAP_DSS_WB
;
2603 const int pos_x
= 0, pos_y
= 0;
2604 const u8 zorder
= 0, global_alpha
= 0;
2605 const bool replication
= false;
2607 int in_width
= mgr_timings
->x_res
;
2608 int in_height
= mgr_timings
->y_res
;
2609 enum omap_overlay_caps caps
=
2610 OMAP_DSS_OVL_CAP_SCALE
| OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
;
2612 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2613 "rot %d, mir %d\n", wi
->paddr
, wi
->p_uv_addr
, in_width
,
2614 in_height
, wi
->width
, wi
->height
, wi
->color_mode
, wi
->rotation
,
2617 r
= dispc_ovl_setup_common(plane
, caps
, wi
->paddr
, wi
->p_uv_addr
,
2618 wi
->buf_width
, pos_x
, pos_y
, in_width
, in_height
, wi
->width
,
2619 wi
->height
, wi
->color_mode
, wi
->rotation
, wi
->mirror
, zorder
,
2620 wi
->pre_mult_alpha
, global_alpha
, wi
->rotation_type
,
2621 replication
, mgr_timings
, mem_to_mem
);
2623 switch (wi
->color_mode
) {
2624 case OMAP_DSS_COLOR_RGB16
:
2625 case OMAP_DSS_COLOR_RGB24P
:
2626 case OMAP_DSS_COLOR_ARGB16
:
2627 case OMAP_DSS_COLOR_RGBA16
:
2628 case OMAP_DSS_COLOR_RGB12U
:
2629 case OMAP_DSS_COLOR_ARGB16_1555
:
2630 case OMAP_DSS_COLOR_XRGB16_1555
:
2631 case OMAP_DSS_COLOR_RGBX16
:
2639 /* setup extra DISPC_WB_ATTRIBUTES */
2640 l
= dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane
));
2641 l
= FLD_MOD(l
, truncation
, 10, 10); /* TRUNCATIONENABLE */
2642 l
= FLD_MOD(l
, mem_to_mem
, 19, 19); /* WRITEBACKMODE */
2643 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane
), l
);
2648 int dispc_ovl_enable(enum omap_plane plane
, bool enable
)
2650 DSSDBG("dispc_enable_plane %d, %d\n", plane
, enable
);
2652 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane
), enable
? 1 : 0, 0, 0);
2656 EXPORT_SYMBOL(dispc_ovl_enable
);
2658 bool dispc_ovl_enabled(enum omap_plane plane
)
2660 return REG_GET(DISPC_OVL_ATTRIBUTES(plane
), 0, 0);
2662 EXPORT_SYMBOL(dispc_ovl_enabled
);
2664 void dispc_mgr_enable(enum omap_channel channel
, bool enable
)
2666 mgr_fld_write(channel
, DISPC_MGR_FLD_ENABLE
, enable
);
2667 /* flush posted write */
2668 mgr_fld_read(channel
, DISPC_MGR_FLD_ENABLE
);
2670 EXPORT_SYMBOL(dispc_mgr_enable
);
2672 bool dispc_mgr_is_enabled(enum omap_channel channel
)
2674 return !!mgr_fld_read(channel
, DISPC_MGR_FLD_ENABLE
);
2676 EXPORT_SYMBOL(dispc_mgr_is_enabled
);
2678 void dispc_wb_enable(bool enable
)
2680 dispc_ovl_enable(OMAP_DSS_WB
, enable
);
2683 bool dispc_wb_is_enabled(void)
2685 return dispc_ovl_enabled(OMAP_DSS_WB
);
2688 static void dispc_lcd_enable_signal_polarity(bool act_high
)
2690 if (!dss_has_feature(FEAT_LCDENABLEPOL
))
2693 REG_FLD_MOD(DISPC_CONTROL
, act_high
? 1 : 0, 29, 29);
2696 void dispc_lcd_enable_signal(bool enable
)
2698 if (!dss_has_feature(FEAT_LCDENABLESIGNAL
))
2701 REG_FLD_MOD(DISPC_CONTROL
, enable
? 1 : 0, 28, 28);
2704 void dispc_pck_free_enable(bool enable
)
2706 if (!dss_has_feature(FEAT_PCKFREEENABLE
))
2709 REG_FLD_MOD(DISPC_CONTROL
, enable
? 1 : 0, 27, 27);
2712 static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel
, bool enable
)
2714 mgr_fld_write(channel
, DISPC_MGR_FLD_FIFOHANDCHECK
, enable
);
2718 static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel
)
2720 mgr_fld_write(channel
, DISPC_MGR_FLD_STNTFT
, 1);
2723 void dispc_set_loadmode(enum omap_dss_load_mode mode
)
2725 REG_FLD_MOD(DISPC_CONFIG
, mode
, 2, 1);
2729 static void dispc_mgr_set_default_color(enum omap_channel channel
, u32 color
)
2731 dispc_write_reg(DISPC_DEFAULT_COLOR(channel
), color
);
2734 static void dispc_mgr_set_trans_key(enum omap_channel ch
,
2735 enum omap_dss_trans_key_type type
,
2738 mgr_fld_write(ch
, DISPC_MGR_FLD_TCKSELECTION
, type
);
2740 dispc_write_reg(DISPC_TRANS_COLOR(ch
), trans_key
);
2743 static void dispc_mgr_enable_trans_key(enum omap_channel ch
, bool enable
)
2745 mgr_fld_write(ch
, DISPC_MGR_FLD_TCKENABLE
, enable
);
2748 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch
,
2751 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
2754 if (ch
== OMAP_DSS_CHANNEL_LCD
)
2755 REG_FLD_MOD(DISPC_CONFIG
, enable
, 18, 18);
2756 else if (ch
== OMAP_DSS_CHANNEL_DIGIT
)
2757 REG_FLD_MOD(DISPC_CONFIG
, enable
, 19, 19);
2760 void dispc_mgr_setup(enum omap_channel channel
,
2761 const struct omap_overlay_manager_info
*info
)
2763 dispc_mgr_set_default_color(channel
, info
->default_color
);
2764 dispc_mgr_set_trans_key(channel
, info
->trans_key_type
, info
->trans_key
);
2765 dispc_mgr_enable_trans_key(channel
, info
->trans_enabled
);
2766 dispc_mgr_enable_alpha_fixed_zorder(channel
,
2767 info
->partial_alpha_enabled
);
2768 if (dss_has_feature(FEAT_CPR
)) {
2769 dispc_mgr_enable_cpr(channel
, info
->cpr_enable
);
2770 dispc_mgr_set_cpr_coef(channel
, &info
->cpr_coefs
);
2773 EXPORT_SYMBOL(dispc_mgr_setup
);
2775 static void dispc_mgr_set_tft_data_lines(enum omap_channel channel
, u8 data_lines
)
2779 switch (data_lines
) {
2797 mgr_fld_write(channel
, DISPC_MGR_FLD_TFTDATALINES
, code
);
2800 static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode
)
2806 case DSS_IO_PAD_MODE_RESET
:
2810 case DSS_IO_PAD_MODE_RFBI
:
2814 case DSS_IO_PAD_MODE_BYPASS
:
2823 l
= dispc_read_reg(DISPC_CONTROL
);
2824 l
= FLD_MOD(l
, gpout0
, 15, 15);
2825 l
= FLD_MOD(l
, gpout1
, 16, 16);
2826 dispc_write_reg(DISPC_CONTROL
, l
);
2829 static void dispc_mgr_enable_stallmode(enum omap_channel channel
, bool enable
)
2831 mgr_fld_write(channel
, DISPC_MGR_FLD_STALLMODE
, enable
);
2834 void dispc_mgr_set_lcd_config(enum omap_channel channel
,
2835 const struct dss_lcd_mgr_config
*config
)
2837 dispc_mgr_set_io_pad_mode(config
->io_pad_mode
);
2839 dispc_mgr_enable_stallmode(channel
, config
->stallmode
);
2840 dispc_mgr_enable_fifohandcheck(channel
, config
->fifohandcheck
);
2842 dispc_mgr_set_clock_div(channel
, &config
->clock_info
);
2844 dispc_mgr_set_tft_data_lines(channel
, config
->video_port_width
);
2846 dispc_lcd_enable_signal_polarity(config
->lcden_sig_polarity
);
2848 dispc_mgr_set_lcd_type_tft(channel
);
2850 EXPORT_SYMBOL(dispc_mgr_set_lcd_config
);
2852 static bool _dispc_mgr_size_ok(u16 width
, u16 height
)
2854 return width
<= dispc
.feat
->mgr_width_max
&&
2855 height
<= dispc
.feat
->mgr_height_max
;
2858 static bool _dispc_lcd_timings_ok(int hsw
, int hfp
, int hbp
,
2859 int vsw
, int vfp
, int vbp
)
2861 if (hsw
< 1 || hsw
> dispc
.feat
->sw_max
||
2862 hfp
< 1 || hfp
> dispc
.feat
->hp_max
||
2863 hbp
< 1 || hbp
> dispc
.feat
->hp_max
||
2864 vsw
< 1 || vsw
> dispc
.feat
->sw_max
||
2865 vfp
< 0 || vfp
> dispc
.feat
->vp_max
||
2866 vbp
< 0 || vbp
> dispc
.feat
->vp_max
)
2871 static bool _dispc_mgr_pclk_ok(enum omap_channel channel
,
2874 if (dss_mgr_is_lcd(channel
))
2875 return pclk
<= dispc
.feat
->max_lcd_pclk
? true : false;
2877 return pclk
<= dispc
.feat
->max_tv_pclk
? true : false;
2880 bool dispc_mgr_timings_ok(enum omap_channel channel
,
2881 const struct omap_video_timings
*timings
)
2885 timings_ok
= _dispc_mgr_size_ok(timings
->x_res
, timings
->y_res
);
2887 timings_ok
&= _dispc_mgr_pclk_ok(channel
, timings
->pixel_clock
* 1000);
2889 if (dss_mgr_is_lcd(channel
)) {
2890 timings_ok
&= _dispc_lcd_timings_ok(timings
->hsw
, timings
->hfp
,
2891 timings
->hbp
, timings
->vsw
, timings
->vfp
,
2898 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel
, int hsw
,
2899 int hfp
, int hbp
, int vsw
, int vfp
, int vbp
,
2900 enum omap_dss_signal_level vsync_level
,
2901 enum omap_dss_signal_level hsync_level
,
2902 enum omap_dss_signal_edge data_pclk_edge
,
2903 enum omap_dss_signal_level de_level
,
2904 enum omap_dss_signal_edge sync_pclk_edge
)
2907 u32 timing_h
, timing_v
, l
;
2908 bool onoff
, rf
, ipc
;
2910 timing_h
= FLD_VAL(hsw
-1, dispc
.feat
->sw_start
, 0) |
2911 FLD_VAL(hfp
-1, dispc
.feat
->fp_start
, 8) |
2912 FLD_VAL(hbp
-1, dispc
.feat
->bp_start
, 20);
2913 timing_v
= FLD_VAL(vsw
-1, dispc
.feat
->sw_start
, 0) |
2914 FLD_VAL(vfp
, dispc
.feat
->fp_start
, 8) |
2915 FLD_VAL(vbp
, dispc
.feat
->bp_start
, 20);
2917 dispc_write_reg(DISPC_TIMING_H(channel
), timing_h
);
2918 dispc_write_reg(DISPC_TIMING_V(channel
), timing_v
);
2920 switch (data_pclk_edge
) {
2921 case OMAPDSS_DRIVE_SIG_RISING_EDGE
:
2924 case OMAPDSS_DRIVE_SIG_FALLING_EDGE
:
2927 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES
:
2932 switch (sync_pclk_edge
) {
2933 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES
:
2937 case OMAPDSS_DRIVE_SIG_FALLING_EDGE
:
2941 case OMAPDSS_DRIVE_SIG_RISING_EDGE
:
2949 l
= dispc_read_reg(DISPC_POL_FREQ(channel
));
2950 l
|= FLD_VAL(onoff
, 17, 17);
2951 l
|= FLD_VAL(rf
, 16, 16);
2952 l
|= FLD_VAL(de_level
, 15, 15);
2953 l
|= FLD_VAL(ipc
, 14, 14);
2954 l
|= FLD_VAL(hsync_level
, 13, 13);
2955 l
|= FLD_VAL(vsync_level
, 12, 12);
2956 dispc_write_reg(DISPC_POL_FREQ(channel
), l
);
2959 /* change name to mode? */
2960 void dispc_mgr_set_timings(enum omap_channel channel
,
2961 const struct omap_video_timings
*timings
)
2963 unsigned xtot
, ytot
;
2964 unsigned long ht
, vt
;
2965 struct omap_video_timings t
= *timings
;
2967 DSSDBG("channel %d xres %u yres %u\n", channel
, t
.x_res
, t
.y_res
);
2969 if (!dispc_mgr_timings_ok(channel
, &t
)) {
2974 if (dss_mgr_is_lcd(channel
)) {
2975 _dispc_mgr_set_lcd_timings(channel
, t
.hsw
, t
.hfp
, t
.hbp
, t
.vsw
,
2976 t
.vfp
, t
.vbp
, t
.vsync_level
, t
.hsync_level
,
2977 t
.data_pclk_edge
, t
.de_level
, t
.sync_pclk_edge
);
2979 xtot
= t
.x_res
+ t
.hfp
+ t
.hsw
+ t
.hbp
;
2980 ytot
= t
.y_res
+ t
.vfp
+ t
.vsw
+ t
.vbp
;
2982 ht
= (timings
->pixel_clock
* 1000) / xtot
;
2983 vt
= (timings
->pixel_clock
* 1000) / xtot
/ ytot
;
2985 DSSDBG("pck %u\n", timings
->pixel_clock
);
2986 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2987 t
.hsw
, t
.hfp
, t
.hbp
, t
.vsw
, t
.vfp
, t
.vbp
);
2988 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
2989 t
.vsync_level
, t
.hsync_level
, t
.data_pclk_edge
,
2990 t
.de_level
, t
.sync_pclk_edge
);
2992 DSSDBG("hsync %luHz, vsync %luHz\n", ht
, vt
);
2994 if (t
.interlace
== true)
2998 dispc_mgr_set_size(channel
, t
.x_res
, t
.y_res
);
3000 EXPORT_SYMBOL(dispc_mgr_set_timings
);
3002 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel
, u16 lck_div
,
3005 BUG_ON(lck_div
< 1);
3006 BUG_ON(pck_div
< 1);
3008 dispc_write_reg(DISPC_DIVISORo(channel
),
3009 FLD_VAL(lck_div
, 23, 16) | FLD_VAL(pck_div
, 7, 0));
3011 if (dss_has_feature(FEAT_CORE_CLK_DIV
) == false &&
3012 channel
== OMAP_DSS_CHANNEL_LCD
)
3013 dispc
.core_clk_rate
= dispc_fclk_rate() / lck_div
;
3016 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel
, int *lck_div
,
3020 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3021 *lck_div
= FLD_GET(l
, 23, 16);
3022 *pck_div
= FLD_GET(l
, 7, 0);
3025 unsigned long dispc_fclk_rate(void)
3027 struct platform_device
*dsidev
;
3028 unsigned long r
= 0;
3030 switch (dss_get_dispc_clk_source()) {
3031 case OMAP_DSS_CLK_SRC_FCK
:
3032 r
= dss_get_dispc_clk_rate();
3034 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
3035 dsidev
= dsi_get_dsidev_from_id(0);
3036 r
= dsi_get_pll_hsdiv_dispc_rate(dsidev
);
3038 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
3039 dsidev
= dsi_get_dsidev_from_id(1);
3040 r
= dsi_get_pll_hsdiv_dispc_rate(dsidev
);
3050 unsigned long dispc_mgr_lclk_rate(enum omap_channel channel
)
3052 struct platform_device
*dsidev
;
3057 if (dss_mgr_is_lcd(channel
)) {
3058 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3060 lcd
= FLD_GET(l
, 23, 16);
3062 switch (dss_get_lcd_clk_source(channel
)) {
3063 case OMAP_DSS_CLK_SRC_FCK
:
3064 r
= dss_get_dispc_clk_rate();
3066 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC
:
3067 dsidev
= dsi_get_dsidev_from_id(0);
3068 r
= dsi_get_pll_hsdiv_dispc_rate(dsidev
);
3070 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC
:
3071 dsidev
= dsi_get_dsidev_from_id(1);
3072 r
= dsi_get_pll_hsdiv_dispc_rate(dsidev
);
3081 return dispc_fclk_rate();
3085 unsigned long dispc_mgr_pclk_rate(enum omap_channel channel
)
3089 if (dss_mgr_is_lcd(channel
)) {
3093 l
= dispc_read_reg(DISPC_DIVISORo(channel
));
3095 pcd
= FLD_GET(l
, 7, 0);
3097 r
= dispc_mgr_lclk_rate(channel
);
3101 return dispc
.tv_pclk_rate
;
3105 void dispc_set_tv_pclk(unsigned long pclk
)
3107 dispc
.tv_pclk_rate
= pclk
;
3110 unsigned long dispc_core_clk_rate(void)
3112 return dispc
.core_clk_rate
;
3115 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane
)
3117 enum omap_channel channel
;
3119 if (plane
== OMAP_DSS_WB
)
3122 channel
= dispc_ovl_get_channel_out(plane
);
3124 return dispc_mgr_pclk_rate(channel
);
3127 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane
)
3129 enum omap_channel channel
;
3131 if (plane
== OMAP_DSS_WB
)
3134 channel
= dispc_ovl_get_channel_out(plane
);
3136 return dispc_mgr_lclk_rate(channel
);
3139 static void dispc_dump_clocks_channel(struct seq_file
*s
, enum omap_channel channel
)
3142 enum omap_dss_clk_source lcd_clk_src
;
3144 seq_printf(s
, "- %s -\n", mgr_desc
[channel
].name
);
3146 lcd_clk_src
= dss_get_lcd_clk_source(channel
);
3148 seq_printf(s
, "%s clk source = %s (%s)\n", mgr_desc
[channel
].name
,
3149 dss_get_generic_clk_source_name(lcd_clk_src
),
3150 dss_feat_get_clk_source_name(lcd_clk_src
));
3152 dispc_mgr_get_lcd_divisor(channel
, &lcd
, &pcd
);
3154 seq_printf(s
, "lck\t\t%-16lulck div\t%u\n",
3155 dispc_mgr_lclk_rate(channel
), lcd
);
3156 seq_printf(s
, "pck\t\t%-16lupck div\t%u\n",
3157 dispc_mgr_pclk_rate(channel
), pcd
);
3160 void dispc_dump_clocks(struct seq_file
*s
)
3164 enum omap_dss_clk_source dispc_clk_src
= dss_get_dispc_clk_source();
3166 if (dispc_runtime_get())
3169 seq_printf(s
, "- DISPC -\n");
3171 seq_printf(s
, "dispc fclk source = %s (%s)\n",
3172 dss_get_generic_clk_source_name(dispc_clk_src
),
3173 dss_feat_get_clk_source_name(dispc_clk_src
));
3175 seq_printf(s
, "fck\t\t%-16lu\n", dispc_fclk_rate());
3177 if (dss_has_feature(FEAT_CORE_CLK_DIV
)) {
3178 seq_printf(s
, "- DISPC-CORE-CLK -\n");
3179 l
= dispc_read_reg(DISPC_DIVISOR
);
3180 lcd
= FLD_GET(l
, 23, 16);
3182 seq_printf(s
, "lck\t\t%-16lulck div\t%u\n",
3183 (dispc_fclk_rate()/lcd
), lcd
);
3186 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD
);
3188 if (dss_has_feature(FEAT_MGR_LCD2
))
3189 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD2
);
3190 if (dss_has_feature(FEAT_MGR_LCD3
))
3191 dispc_dump_clocks_channel(s
, OMAP_DSS_CHANNEL_LCD3
);
3193 dispc_runtime_put();
3196 static void dispc_dump_regs(struct seq_file
*s
)
3199 const char *mgr_names
[] = {
3200 [OMAP_DSS_CHANNEL_LCD
] = "LCD",
3201 [OMAP_DSS_CHANNEL_DIGIT
] = "TV",
3202 [OMAP_DSS_CHANNEL_LCD2
] = "LCD2",
3203 [OMAP_DSS_CHANNEL_LCD3
] = "LCD3",
3205 const char *ovl_names
[] = {
3206 [OMAP_DSS_GFX
] = "GFX",
3207 [OMAP_DSS_VIDEO1
] = "VID1",
3208 [OMAP_DSS_VIDEO2
] = "VID2",
3209 [OMAP_DSS_VIDEO3
] = "VID3",
3211 const char **p_names
;
3213 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3215 if (dispc_runtime_get())
3218 /* DISPC common registers */
3219 DUMPREG(DISPC_REVISION
);
3220 DUMPREG(DISPC_SYSCONFIG
);
3221 DUMPREG(DISPC_SYSSTATUS
);
3222 DUMPREG(DISPC_IRQSTATUS
);
3223 DUMPREG(DISPC_IRQENABLE
);
3224 DUMPREG(DISPC_CONTROL
);
3225 DUMPREG(DISPC_CONFIG
);
3226 DUMPREG(DISPC_CAPABLE
);
3227 DUMPREG(DISPC_LINE_STATUS
);
3228 DUMPREG(DISPC_LINE_NUMBER
);
3229 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
) ||
3230 dss_has_feature(FEAT_ALPHA_FREE_ZORDER
))
3231 DUMPREG(DISPC_GLOBAL_ALPHA
);
3232 if (dss_has_feature(FEAT_MGR_LCD2
)) {
3233 DUMPREG(DISPC_CONTROL2
);
3234 DUMPREG(DISPC_CONFIG2
);
3236 if (dss_has_feature(FEAT_MGR_LCD3
)) {
3237 DUMPREG(DISPC_CONTROL3
);
3238 DUMPREG(DISPC_CONFIG3
);
3240 if (dss_has_feature(FEAT_MFLAG
))
3241 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE
);
3245 #define DISPC_REG(i, name) name(i)
3246 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3247 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
3248 dispc_read_reg(DISPC_REG(i, r)))
3250 p_names
= mgr_names
;
3252 /* DISPC channel specific registers */
3253 for (i
= 0; i
< dss_feat_get_num_mgrs(); i
++) {
3254 DUMPREG(i
, DISPC_DEFAULT_COLOR
);
3255 DUMPREG(i
, DISPC_TRANS_COLOR
);
3256 DUMPREG(i
, DISPC_SIZE_MGR
);
3258 if (i
== OMAP_DSS_CHANNEL_DIGIT
)
3261 DUMPREG(i
, DISPC_DEFAULT_COLOR
);
3262 DUMPREG(i
, DISPC_TRANS_COLOR
);
3263 DUMPREG(i
, DISPC_TIMING_H
);
3264 DUMPREG(i
, DISPC_TIMING_V
);
3265 DUMPREG(i
, DISPC_POL_FREQ
);
3266 DUMPREG(i
, DISPC_DIVISORo
);
3267 DUMPREG(i
, DISPC_SIZE_MGR
);
3269 DUMPREG(i
, DISPC_DATA_CYCLE1
);
3270 DUMPREG(i
, DISPC_DATA_CYCLE2
);
3271 DUMPREG(i
, DISPC_DATA_CYCLE3
);
3273 if (dss_has_feature(FEAT_CPR
)) {
3274 DUMPREG(i
, DISPC_CPR_COEF_R
);
3275 DUMPREG(i
, DISPC_CPR_COEF_G
);
3276 DUMPREG(i
, DISPC_CPR_COEF_B
);
3280 p_names
= ovl_names
;
3282 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
3283 DUMPREG(i
, DISPC_OVL_BA0
);
3284 DUMPREG(i
, DISPC_OVL_BA1
);
3285 DUMPREG(i
, DISPC_OVL_POSITION
);
3286 DUMPREG(i
, DISPC_OVL_SIZE
);
3287 DUMPREG(i
, DISPC_OVL_ATTRIBUTES
);
3288 DUMPREG(i
, DISPC_OVL_FIFO_THRESHOLD
);
3289 DUMPREG(i
, DISPC_OVL_FIFO_SIZE_STATUS
);
3290 DUMPREG(i
, DISPC_OVL_ROW_INC
);
3291 DUMPREG(i
, DISPC_OVL_PIXEL_INC
);
3292 if (dss_has_feature(FEAT_PRELOAD
))
3293 DUMPREG(i
, DISPC_OVL_PRELOAD
);
3295 if (i
== OMAP_DSS_GFX
) {
3296 DUMPREG(i
, DISPC_OVL_WINDOW_SKIP
);
3297 DUMPREG(i
, DISPC_OVL_TABLE_BA
);
3301 DUMPREG(i
, DISPC_OVL_FIR
);
3302 DUMPREG(i
, DISPC_OVL_PICTURE_SIZE
);
3303 DUMPREG(i
, DISPC_OVL_ACCU0
);
3304 DUMPREG(i
, DISPC_OVL_ACCU1
);
3305 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3306 DUMPREG(i
, DISPC_OVL_BA0_UV
);
3307 DUMPREG(i
, DISPC_OVL_BA1_UV
);
3308 DUMPREG(i
, DISPC_OVL_FIR2
);
3309 DUMPREG(i
, DISPC_OVL_ACCU2_0
);
3310 DUMPREG(i
, DISPC_OVL_ACCU2_1
);
3312 if (dss_has_feature(FEAT_ATTR2
))
3313 DUMPREG(i
, DISPC_OVL_ATTRIBUTES2
);
3314 if (dss_has_feature(FEAT_PRELOAD
))
3315 DUMPREG(i
, DISPC_OVL_PRELOAD
);
3316 if (dss_has_feature(FEAT_MFLAG
))
3317 DUMPREG(i
, DISPC_OVL_MFLAG_THRESHOLD
);
3323 #define DISPC_REG(plane, name, i) name(plane, i)
3324 #define DUMPREG(plane, name, i) \
3325 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3326 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
3327 dispc_read_reg(DISPC_REG(plane, name, i)))
3329 /* Video pipeline coefficient registers */
3331 /* start from OMAP_DSS_VIDEO1 */
3332 for (i
= 1; i
< dss_feat_get_num_ovls(); i
++) {
3333 for (j
= 0; j
< 8; j
++)
3334 DUMPREG(i
, DISPC_OVL_FIR_COEF_H
, j
);
3336 for (j
= 0; j
< 8; j
++)
3337 DUMPREG(i
, DISPC_OVL_FIR_COEF_HV
, j
);
3339 for (j
= 0; j
< 5; j
++)
3340 DUMPREG(i
, DISPC_OVL_CONV_COEF
, j
);
3342 if (dss_has_feature(FEAT_FIR_COEF_V
)) {
3343 for (j
= 0; j
< 8; j
++)
3344 DUMPREG(i
, DISPC_OVL_FIR_COEF_V
, j
);
3347 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE
)) {
3348 for (j
= 0; j
< 8; j
++)
3349 DUMPREG(i
, DISPC_OVL_FIR_COEF_H2
, j
);
3351 for (j
= 0; j
< 8; j
++)
3352 DUMPREG(i
, DISPC_OVL_FIR_COEF_HV2
, j
);
3354 for (j
= 0; j
< 8; j
++)
3355 DUMPREG(i
, DISPC_OVL_FIR_COEF_V2
, j
);
3359 dispc_runtime_put();
3365 /* calculate clock rates using dividers in cinfo */
3366 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate
,
3367 struct dispc_clock_info
*cinfo
)
3369 if (cinfo
->lck_div
> 255 || cinfo
->lck_div
== 0)
3371 if (cinfo
->pck_div
< 1 || cinfo
->pck_div
> 255)
3374 cinfo
->lck
= dispc_fclk_rate
/ cinfo
->lck_div
;
3375 cinfo
->pck
= cinfo
->lck
/ cinfo
->pck_div
;
3380 bool dispc_div_calc(unsigned long dispc
,
3381 unsigned long pck_min
, unsigned long pck_max
,
3382 dispc_div_calc_func func
, void *data
)
3384 int lckd
, lckd_start
, lckd_stop
;
3385 int pckd
, pckd_start
, pckd_stop
;
3386 unsigned long pck
, lck
;
3387 unsigned long lck_max
;
3388 unsigned long pckd_hw_min
, pckd_hw_max
;
3389 unsigned min_fck_per_pck
;
3392 #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3393 min_fck_per_pck
= CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
;
3395 min_fck_per_pck
= 0;
3398 pckd_hw_min
= dss_feat_get_param_min(FEAT_PARAM_DSS_PCD
);
3399 pckd_hw_max
= dss_feat_get_param_max(FEAT_PARAM_DSS_PCD
);
3401 lck_max
= dss_feat_get_param_max(FEAT_PARAM_DSS_FCK
);
3403 pck_min
= pck_min
? pck_min
: 1;
3404 pck_max
= pck_max
? pck_max
: ULONG_MAX
;
3406 lckd_start
= max(DIV_ROUND_UP(dispc
, lck_max
), 1ul);
3407 lckd_stop
= min(dispc
/ pck_min
, 255ul);
3409 for (lckd
= lckd_start
; lckd
<= lckd_stop
; ++lckd
) {
3412 pckd_start
= max(DIV_ROUND_UP(lck
, pck_max
), pckd_hw_min
);
3413 pckd_stop
= min(lck
/ pck_min
, pckd_hw_max
);
3415 for (pckd
= pckd_start
; pckd
<= pckd_stop
; ++pckd
) {
3419 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3420 * clock, which means we're configuring DISPC fclk here
3421 * also. Thus we need to use the calculated lck. For
3422 * OMAP4+ the DISPC fclk is a separate clock.
3424 if (dss_has_feature(FEAT_CORE_CLK_DIV
))
3425 fck
= dispc_core_clk_rate();
3429 if (fck
< pck
* min_fck_per_pck
)
3432 if (func(lckd
, pckd
, lck
, pck
, data
))
3440 void dispc_mgr_set_clock_div(enum omap_channel channel
,
3441 const struct dispc_clock_info
*cinfo
)
3443 DSSDBG("lck = %lu (%u)\n", cinfo
->lck
, cinfo
->lck_div
);
3444 DSSDBG("pck = %lu (%u)\n", cinfo
->pck
, cinfo
->pck_div
);
3446 dispc_mgr_set_lcd_divisor(channel
, cinfo
->lck_div
, cinfo
->pck_div
);
3449 int dispc_mgr_get_clock_div(enum omap_channel channel
,
3450 struct dispc_clock_info
*cinfo
)
3454 fck
= dispc_fclk_rate();
3456 cinfo
->lck_div
= REG_GET(DISPC_DIVISORo(channel
), 23, 16);
3457 cinfo
->pck_div
= REG_GET(DISPC_DIVISORo(channel
), 7, 0);
3459 cinfo
->lck
= fck
/ cinfo
->lck_div
;
3460 cinfo
->pck
= cinfo
->lck
/ cinfo
->pck_div
;
3465 u32
dispc_read_irqstatus(void)
3467 return dispc_read_reg(DISPC_IRQSTATUS
);
3469 EXPORT_SYMBOL(dispc_read_irqstatus
);
3471 void dispc_clear_irqstatus(u32 mask
)
3473 dispc_write_reg(DISPC_IRQSTATUS
, mask
);
3475 EXPORT_SYMBOL(dispc_clear_irqstatus
);
3477 u32
dispc_read_irqenable(void)
3479 return dispc_read_reg(DISPC_IRQENABLE
);
3481 EXPORT_SYMBOL(dispc_read_irqenable
);
3483 void dispc_write_irqenable(u32 mask
)
3485 u32 old_mask
= dispc_read_reg(DISPC_IRQENABLE
);
3487 /* clear the irqstatus for newly enabled irqs */
3488 dispc_clear_irqstatus((mask
^ old_mask
) & mask
);
3490 dispc_write_reg(DISPC_IRQENABLE
, mask
);
3492 EXPORT_SYMBOL(dispc_write_irqenable
);
3494 void dispc_enable_sidle(void)
3496 REG_FLD_MOD(DISPC_SYSCONFIG
, 2, 4, 3); /* SIDLEMODE: smart idle */
3499 void dispc_disable_sidle(void)
3501 REG_FLD_MOD(DISPC_SYSCONFIG
, 1, 4, 3); /* SIDLEMODE: no idle */
3504 static void _omap_dispc_initial_config(void)
3508 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3509 if (dss_has_feature(FEAT_CORE_CLK_DIV
)) {
3510 l
= dispc_read_reg(DISPC_DIVISOR
);
3511 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3512 l
= FLD_MOD(l
, 1, 0, 0);
3513 l
= FLD_MOD(l
, 1, 23, 16);
3514 dispc_write_reg(DISPC_DIVISOR
, l
);
3516 dispc
.core_clk_rate
= dispc_fclk_rate();
3520 if (dss_has_feature(FEAT_FUNCGATED
))
3521 REG_FLD_MOD(DISPC_CONFIG
, 1, 9, 9);
3523 dispc_setup_color_conv_coef();
3525 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY
);
3529 dispc_configure_burst_sizes();
3531 dispc_ovl_enable_zorder_planes();
3533 if (dispc
.feat
->mstandby_workaround
)
3534 REG_FLD_MOD(DISPC_MSTANDBY_CTRL
, 1, 0, 0);
3537 static const struct dispc_features omap24xx_dispc_feats __initconst
= {
3544 .mgr_width_start
= 10,
3545 .mgr_height_start
= 26,
3546 .mgr_width_max
= 2048,
3547 .mgr_height_max
= 2048,
3548 .max_lcd_pclk
= 66500000,
3549 .calc_scaling
= dispc_ovl_calc_scaling_24xx
,
3550 .calc_core_clk
= calc_core_clk_24xx
,
3552 .no_framedone_tv
= true,
3553 .set_max_preload
= false,
3556 static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst
= {
3563 .mgr_width_start
= 10,
3564 .mgr_height_start
= 26,
3565 .mgr_width_max
= 2048,
3566 .mgr_height_max
= 2048,
3567 .max_lcd_pclk
= 173000000,
3568 .max_tv_pclk
= 59000000,
3569 .calc_scaling
= dispc_ovl_calc_scaling_34xx
,
3570 .calc_core_clk
= calc_core_clk_34xx
,
3572 .no_framedone_tv
= true,
3573 .set_max_preload
= false,
3576 static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst
= {
3583 .mgr_width_start
= 10,
3584 .mgr_height_start
= 26,
3585 .mgr_width_max
= 2048,
3586 .mgr_height_max
= 2048,
3587 .max_lcd_pclk
= 173000000,
3588 .max_tv_pclk
= 59000000,
3589 .calc_scaling
= dispc_ovl_calc_scaling_34xx
,
3590 .calc_core_clk
= calc_core_clk_34xx
,
3592 .no_framedone_tv
= true,
3593 .set_max_preload
= false,
3596 static const struct dispc_features omap44xx_dispc_feats __initconst
= {
3603 .mgr_width_start
= 10,
3604 .mgr_height_start
= 26,
3605 .mgr_width_max
= 2048,
3606 .mgr_height_max
= 2048,
3607 .max_lcd_pclk
= 170000000,
3608 .max_tv_pclk
= 185625000,
3609 .calc_scaling
= dispc_ovl_calc_scaling_44xx
,
3610 .calc_core_clk
= calc_core_clk_44xx
,
3612 .gfx_fifo_workaround
= true,
3613 .set_max_preload
= true,
3616 static const struct dispc_features omap54xx_dispc_feats __initconst
= {
3623 .mgr_width_start
= 11,
3624 .mgr_height_start
= 27,
3625 .mgr_width_max
= 4096,
3626 .mgr_height_max
= 4096,
3627 .max_lcd_pclk
= 170000000,
3628 .max_tv_pclk
= 186000000,
3629 .calc_scaling
= dispc_ovl_calc_scaling_44xx
,
3630 .calc_core_clk
= calc_core_clk_44xx
,
3632 .gfx_fifo_workaround
= true,
3633 .mstandby_workaround
= true,
3634 .set_max_preload
= true,
3637 static int __init
dispc_init_features(struct platform_device
*pdev
)
3639 const struct dispc_features
*src
;
3640 struct dispc_features
*dst
;
3642 dst
= devm_kzalloc(&pdev
->dev
, sizeof(*dst
), GFP_KERNEL
);
3644 dev_err(&pdev
->dev
, "Failed to allocate DISPC Features\n");
3648 switch (omapdss_get_version()) {
3649 case OMAPDSS_VER_OMAP24xx
:
3650 src
= &omap24xx_dispc_feats
;
3653 case OMAPDSS_VER_OMAP34xx_ES1
:
3654 src
= &omap34xx_rev1_0_dispc_feats
;
3657 case OMAPDSS_VER_OMAP34xx_ES3
:
3658 case OMAPDSS_VER_OMAP3630
:
3659 case OMAPDSS_VER_AM35xx
:
3660 src
= &omap34xx_rev3_0_dispc_feats
;
3663 case OMAPDSS_VER_OMAP4430_ES1
:
3664 case OMAPDSS_VER_OMAP4430_ES2
:
3665 case OMAPDSS_VER_OMAP4
:
3666 src
= &omap44xx_dispc_feats
;
3669 case OMAPDSS_VER_OMAP5
:
3670 src
= &omap54xx_dispc_feats
;
3677 memcpy(dst
, src
, sizeof(*dst
));
3683 int dispc_request_irq(irq_handler_t handler
, void *dev_id
)
3685 return devm_request_irq(&dispc
.pdev
->dev
, dispc
.irq
, handler
,
3686 IRQF_SHARED
, "OMAP DISPC", dev_id
);
3688 EXPORT_SYMBOL(dispc_request_irq
);
3690 void dispc_free_irq(void *dev_id
)
3692 devm_free_irq(&dispc
.pdev
->dev
, dispc
.irq
, dev_id
);
3694 EXPORT_SYMBOL(dispc_free_irq
);
3696 /* DISPC HW IP initialisation */
3697 static int __init
omap_dispchw_probe(struct platform_device
*pdev
)
3701 struct resource
*dispc_mem
;
3705 r
= dispc_init_features(dispc
.pdev
);
3709 dispc_mem
= platform_get_resource(dispc
.pdev
, IORESOURCE_MEM
, 0);
3711 DSSERR("can't get IORESOURCE_MEM DISPC\n");
3715 dispc
.base
= devm_ioremap(&pdev
->dev
, dispc_mem
->start
,
3716 resource_size(dispc_mem
));
3718 DSSERR("can't ioremap DISPC\n");
3722 dispc
.irq
= platform_get_irq(dispc
.pdev
, 0);
3723 if (dispc
.irq
< 0) {
3724 DSSERR("platform_get_irq failed\n");
3728 pm_runtime_enable(&pdev
->dev
);
3730 r
= dispc_runtime_get();
3732 goto err_runtime_get
;
3734 _omap_dispc_initial_config();
3736 rev
= dispc_read_reg(DISPC_REVISION
);
3737 dev_dbg(&pdev
->dev
, "OMAP DISPC rev %d.%d\n",
3738 FLD_GET(rev
, 7, 4), FLD_GET(rev
, 3, 0));
3740 dispc_runtime_put();
3742 dss_init_overlay_managers();
3744 dss_debugfs_create_file("dispc", dispc_dump_regs
);
3749 pm_runtime_disable(&pdev
->dev
);
3753 static int __exit
omap_dispchw_remove(struct platform_device
*pdev
)
3755 pm_runtime_disable(&pdev
->dev
);
3757 dss_uninit_overlay_managers();
3762 static int dispc_runtime_suspend(struct device
*dev
)
3764 dispc_save_context();
3769 static int dispc_runtime_resume(struct device
*dev
)
3771 _omap_dispc_initial_config();
3773 dispc_restore_context();
3778 static const struct dev_pm_ops dispc_pm_ops
= {
3779 .runtime_suspend
= dispc_runtime_suspend
,
3780 .runtime_resume
= dispc_runtime_resume
,
3783 static struct platform_driver omap_dispchw_driver
= {
3784 .remove
= __exit_p(omap_dispchw_remove
),
3786 .name
= "omapdss_dispc",
3787 .owner
= THIS_MODULE
,
3788 .pm
= &dispc_pm_ops
,
3792 int __init
dispc_init_platform_driver(void)
3794 return platform_driver_probe(&omap_dispchw_driver
, omap_dispchw_probe
);
3797 void __exit
dispc_uninit_platform_driver(void)
3799 platform_driver_unregister(&omap_dispchw_driver
);