2 * linux/drivers/video/omap2/dss/dispc.c
4 * Copyright (C) 2009 Nokia Corporation
7 * Some code and ideas taken from drivers/video/omap/ driver
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
23 #define DSS_SUBSYS_NAME "DISPC"
25 #include <linux/kernel.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/vmalloc.h>
28 #include <linux/export.h>
29 #include <linux/clk.h>
31 #include <linux/jiffies.h>
32 #include <linux/seq_file.h>
33 #include <linux/delay.h>
34 #include <linux/workqueue.h>
35 #include <linux/hardirq.h>
36 #include <linux/platform_device.h>
37 #include <linux/pm_runtime.h>
38 #include <linux/sizes.h>
39 #include <linux/mfd/syscon.h>
40 #include <linux/regmap.h>
42 #include <linux/component.h>
46 #include "dss_features.h"
50 #define DISPC_SZ_REGS SZ_4K
52 enum omap_burst_size {
58 #define REG_GET(idx, start, end) \
59 FLD_GET(dispc_read_reg(idx), start, end)
61 #define REG_FLD_MOD(idx, val, start, end) \
62 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
64 struct dispc_features {
75 unsigned long max_lcd_pclk;
76 unsigned long max_tv_pclk;
77 int (*calc_scaling) (unsigned long pclk, unsigned long lclk,
78 const struct omap_video_timings *mgr_timings,
79 u16 width, u16 height, u16 out_width, u16 out_height,
80 enum omap_color_mode color_mode, bool *five_taps,
81 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
82 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
83 unsigned long (*calc_core_clk) (unsigned long pclk,
84 u16 width, u16 height, u16 out_width, u16 out_height,
88 /* swap GFX & WB fifos */
89 bool gfx_fifo_workaround:1;
91 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
92 bool no_framedone_tv:1;
94 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
95 bool mstandby_workaround:1;
97 bool set_max_preload:1;
99 /* PIXEL_INC is not added to the last pixel of a line */
100 bool last_pixel_inc_missing:1;
102 /* POL_FREQ has ALIGN bit */
103 bool supports_sync_align:1;
105 bool has_writeback:1;
107 bool supports_double_pixel:1;
110 * Field order for VENC is different than HDMI. We should handle this in
111 * some intelligent manner, but as the SoCs have either HDMI or VENC,
112 * never both, we can just use this flag for now.
114 bool reverse_ilace_field_order:1;
117 #define DISPC_MAX_NR_FIFOS 5
120 struct platform_device *pdev;
124 irq_handler_t user_handler;
127 unsigned long core_clk_rate;
128 unsigned long tv_pclk_rate;
130 u32 fifo_size[DISPC_MAX_NR_FIFOS];
131 /* maps which plane is using a fifo. fifo-id -> plane-id */
132 int fifo_assignment[DISPC_MAX_NR_FIFOS];
135 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
137 const struct dispc_features *feat;
141 struct regmap *syscon_pol;
142 u32 syscon_pol_offset;
144 /* DISPC_CONTROL & DISPC_CONFIG lock*/
145 spinlock_t control_lock;
148 enum omap_color_component {
149 /* used for all color formats for OMAP3 and earlier
150 * and for RGB and Y color component on OMAP4
152 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
153 /* used for UV component for
154 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
155 * color formats on OMAP4
157 DISPC_COLOR_COMPONENT_UV = 1 << 1,
160 enum mgr_reg_fields {
161 DISPC_MGR_FLD_ENABLE,
162 DISPC_MGR_FLD_STNTFT,
164 DISPC_MGR_FLD_TFTDATALINES,
165 DISPC_MGR_FLD_STALLMODE,
166 DISPC_MGR_FLD_TCKENABLE,
167 DISPC_MGR_FLD_TCKSELECTION,
169 DISPC_MGR_FLD_FIFOHANDCHECK,
170 /* used to maintain a count of the above fields */
174 struct dispc_reg_field {
180 static const struct {
185 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
187 [OMAP_DSS_CHANNEL_LCD] = {
189 .vsync_irq = DISPC_IRQ_VSYNC,
190 .framedone_irq = DISPC_IRQ_FRAMEDONE,
191 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
193 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
194 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
195 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
196 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
197 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
198 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
199 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
200 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
201 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
204 [OMAP_DSS_CHANNEL_DIGIT] = {
206 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
207 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
208 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
210 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
211 [DISPC_MGR_FLD_STNTFT] = { },
212 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
213 [DISPC_MGR_FLD_TFTDATALINES] = { },
214 [DISPC_MGR_FLD_STALLMODE] = { },
215 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
216 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
217 [DISPC_MGR_FLD_CPR] = { },
218 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
221 [OMAP_DSS_CHANNEL_LCD2] = {
223 .vsync_irq = DISPC_IRQ_VSYNC2,
224 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
225 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
227 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
228 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
229 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
230 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
231 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
232 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
233 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
234 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
235 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
238 [OMAP_DSS_CHANNEL_LCD3] = {
240 .vsync_irq = DISPC_IRQ_VSYNC3,
241 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
242 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
244 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
245 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
246 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
247 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
248 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
249 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
250 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
251 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
252 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
257 struct color_conv_coef {
258 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
262 static unsigned long dispc_fclk_rate(void);
263 static unsigned long dispc_core_clk_rate(void);
264 static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel);
265 static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel);
267 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
268 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
270 static inline void dispc_write_reg(const u16 idx, u32 val)
272 __raw_writel(val, dispc.base + idx);
275 static inline u32 dispc_read_reg(const u16 idx)
277 return __raw_readl(dispc.base + idx);
280 static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
282 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
283 return REG_GET(rfld.reg, rfld.high, rfld.low);
286 static void mgr_fld_write(enum omap_channel channel,
287 enum mgr_reg_fields regfld, int val) {
288 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
289 const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
293 spin_lock_irqsave(&dispc.control_lock, flags);
295 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
298 spin_unlock_irqrestore(&dispc.control_lock, flags);
302 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
304 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
306 static void dispc_save_context(void)
310 DSSDBG("dispc_save_context\n");
316 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
317 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
319 if (dss_has_feature(FEAT_MGR_LCD2)) {
323 if (dss_has_feature(FEAT_MGR_LCD3)) {
328 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
329 SR(DEFAULT_COLOR(i));
332 if (i == OMAP_DSS_CHANNEL_DIGIT)
343 if (dss_has_feature(FEAT_CPR)) {
350 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
355 SR(OVL_ATTRIBUTES(i));
356 SR(OVL_FIFO_THRESHOLD(i));
358 SR(OVL_PIXEL_INC(i));
359 if (dss_has_feature(FEAT_PRELOAD))
361 if (i == OMAP_DSS_GFX) {
362 SR(OVL_WINDOW_SKIP(i));
367 SR(OVL_PICTURE_SIZE(i));
371 for (j = 0; j < 8; j++)
372 SR(OVL_FIR_COEF_H(i, j));
374 for (j = 0; j < 8; j++)
375 SR(OVL_FIR_COEF_HV(i, j));
377 for (j = 0; j < 5; j++)
378 SR(OVL_CONV_COEF(i, j));
380 if (dss_has_feature(FEAT_FIR_COEF_V)) {
381 for (j = 0; j < 8; j++)
382 SR(OVL_FIR_COEF_V(i, j));
385 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
392 for (j = 0; j < 8; j++)
393 SR(OVL_FIR_COEF_H2(i, j));
395 for (j = 0; j < 8; j++)
396 SR(OVL_FIR_COEF_HV2(i, j));
398 for (j = 0; j < 8; j++)
399 SR(OVL_FIR_COEF_V2(i, j));
401 if (dss_has_feature(FEAT_ATTR2))
402 SR(OVL_ATTRIBUTES2(i));
405 if (dss_has_feature(FEAT_CORE_CLK_DIV))
408 dispc.ctx_valid = true;
410 DSSDBG("context saved\n");
413 static void dispc_restore_context(void)
417 DSSDBG("dispc_restore_context\n");
419 if (!dispc.ctx_valid)
426 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
427 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
429 if (dss_has_feature(FEAT_MGR_LCD2))
431 if (dss_has_feature(FEAT_MGR_LCD3))
434 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
435 RR(DEFAULT_COLOR(i));
438 if (i == OMAP_DSS_CHANNEL_DIGIT)
449 if (dss_has_feature(FEAT_CPR)) {
456 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
461 RR(OVL_ATTRIBUTES(i));
462 RR(OVL_FIFO_THRESHOLD(i));
464 RR(OVL_PIXEL_INC(i));
465 if (dss_has_feature(FEAT_PRELOAD))
467 if (i == OMAP_DSS_GFX) {
468 RR(OVL_WINDOW_SKIP(i));
473 RR(OVL_PICTURE_SIZE(i));
477 for (j = 0; j < 8; j++)
478 RR(OVL_FIR_COEF_H(i, j));
480 for (j = 0; j < 8; j++)
481 RR(OVL_FIR_COEF_HV(i, j));
483 for (j = 0; j < 5; j++)
484 RR(OVL_CONV_COEF(i, j));
486 if (dss_has_feature(FEAT_FIR_COEF_V)) {
487 for (j = 0; j < 8; j++)
488 RR(OVL_FIR_COEF_V(i, j));
491 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
498 for (j = 0; j < 8; j++)
499 RR(OVL_FIR_COEF_H2(i, j));
501 for (j = 0; j < 8; j++)
502 RR(OVL_FIR_COEF_HV2(i, j));
504 for (j = 0; j < 8; j++)
505 RR(OVL_FIR_COEF_V2(i, j));
507 if (dss_has_feature(FEAT_ATTR2))
508 RR(OVL_ATTRIBUTES2(i));
511 if (dss_has_feature(FEAT_CORE_CLK_DIV))
514 /* enable last, because LCD & DIGIT enable are here */
516 if (dss_has_feature(FEAT_MGR_LCD2))
518 if (dss_has_feature(FEAT_MGR_LCD3))
520 /* clear spurious SYNC_LOST_DIGIT interrupts */
521 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
524 * enable last so IRQs won't trigger before
525 * the context is fully restored
529 DSSDBG("context restored\n");
535 int dispc_runtime_get(void)
539 DSSDBG("dispc_runtime_get\n");
541 r = pm_runtime_get_sync(&dispc.pdev->dev);
543 return r < 0 ? r : 0;
545 EXPORT_SYMBOL(dispc_runtime_get);
547 void dispc_runtime_put(void)
551 DSSDBG("dispc_runtime_put\n");
553 r = pm_runtime_put_sync(&dispc.pdev->dev);
554 WARN_ON(r < 0 && r != -ENOSYS);
556 EXPORT_SYMBOL(dispc_runtime_put);
558 u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
560 return mgr_desc[channel].vsync_irq;
562 EXPORT_SYMBOL(dispc_mgr_get_vsync_irq);
564 u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
566 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
569 return mgr_desc[channel].framedone_irq;
571 EXPORT_SYMBOL(dispc_mgr_get_framedone_irq);
573 u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
575 return mgr_desc[channel].sync_lost_irq;
577 EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq);
579 u32 dispc_wb_get_framedone_irq(void)
581 return DISPC_IRQ_FRAMEDONEWB;
584 bool dispc_mgr_go_busy(enum omap_channel channel)
586 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
588 EXPORT_SYMBOL(dispc_mgr_go_busy);
590 void dispc_mgr_go(enum omap_channel channel)
592 WARN_ON(!dispc_mgr_is_enabled(channel));
593 WARN_ON(dispc_mgr_go_busy(channel));
595 DSSDBG("GO %s\n", mgr_desc[channel].name);
597 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
599 EXPORT_SYMBOL(dispc_mgr_go);
601 bool dispc_wb_go_busy(void)
603 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
606 void dispc_wb_go(void)
608 enum omap_plane plane = OMAP_DSS_WB;
611 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
616 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
618 DSSERR("GO bit not down for WB\n");
622 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
625 static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
627 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
630 static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
632 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
635 static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
637 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
640 static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
642 BUG_ON(plane == OMAP_DSS_GFX);
644 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
647 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
650 BUG_ON(plane == OMAP_DSS_GFX);
652 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
655 static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
657 BUG_ON(plane == OMAP_DSS_GFX);
659 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
662 static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
663 int fir_vinc, int five_taps,
664 enum omap_color_component color_comp)
666 const struct dispc_coef *h_coef, *v_coef;
669 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
670 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
672 for (i = 0; i < 8; i++) {
675 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
676 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
677 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
678 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
679 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
680 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
681 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
682 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
684 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
685 dispc_ovl_write_firh_reg(plane, i, h);
686 dispc_ovl_write_firhv_reg(plane, i, hv);
688 dispc_ovl_write_firh2_reg(plane, i, h);
689 dispc_ovl_write_firhv2_reg(plane, i, hv);
695 for (i = 0; i < 8; i++) {
697 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
698 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
699 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
700 dispc_ovl_write_firv_reg(plane, i, v);
702 dispc_ovl_write_firv2_reg(plane, i, v);
708 static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
709 const struct color_conv_coef *ct)
711 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
713 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
714 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
715 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
716 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
717 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
719 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
724 static void dispc_setup_color_conv_coef(void)
727 int num_ovl = dss_feat_get_num_ovls();
728 const struct color_conv_coef ctbl_bt601_5_ovl = {
730 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
732 const struct color_conv_coef ctbl_bt601_5_wb = {
734 66, 129, 25, 112, -94, -18, -38, -74, 112, 0,
737 for (i = 1; i < num_ovl; i++)
738 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
740 if (dispc.feat->has_writeback)
741 dispc_ovl_write_color_conv_coef(OMAP_DSS_WB, &ctbl_bt601_5_wb);
744 static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
746 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
749 static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
751 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
754 static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
756 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
759 static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
761 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
764 static void dispc_ovl_set_pos(enum omap_plane plane,
765 enum omap_overlay_caps caps, int x, int y)
769 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
772 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
774 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
777 static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
780 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
782 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
783 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
785 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
788 static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
793 BUG_ON(plane == OMAP_DSS_GFX);
795 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
797 if (plane == OMAP_DSS_WB)
798 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
800 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
803 static void dispc_ovl_set_zorder(enum omap_plane plane,
804 enum omap_overlay_caps caps, u8 zorder)
806 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
809 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
812 static void dispc_ovl_enable_zorder_planes(void)
816 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
819 for (i = 0; i < dss_feat_get_num_ovls(); i++)
820 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
823 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
824 enum omap_overlay_caps caps, bool enable)
826 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
829 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
832 static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
833 enum omap_overlay_caps caps, u8 global_alpha)
835 static const unsigned shifts[] = { 0, 8, 16, 24, };
838 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
841 shift = shifts[plane];
842 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
845 static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
847 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
850 static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
852 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
855 static void dispc_ovl_set_color_mode(enum omap_plane plane,
856 enum omap_color_mode color_mode)
859 if (plane != OMAP_DSS_GFX) {
860 switch (color_mode) {
861 case OMAP_DSS_COLOR_NV12:
863 case OMAP_DSS_COLOR_RGBX16:
865 case OMAP_DSS_COLOR_RGBA16:
867 case OMAP_DSS_COLOR_RGB12U:
869 case OMAP_DSS_COLOR_ARGB16:
871 case OMAP_DSS_COLOR_RGB16:
873 case OMAP_DSS_COLOR_ARGB16_1555:
875 case OMAP_DSS_COLOR_RGB24U:
877 case OMAP_DSS_COLOR_RGB24P:
879 case OMAP_DSS_COLOR_YUV2:
881 case OMAP_DSS_COLOR_UYVY:
883 case OMAP_DSS_COLOR_ARGB32:
885 case OMAP_DSS_COLOR_RGBA32:
887 case OMAP_DSS_COLOR_RGBX32:
889 case OMAP_DSS_COLOR_XRGB16_1555:
895 switch (color_mode) {
896 case OMAP_DSS_COLOR_CLUT1:
898 case OMAP_DSS_COLOR_CLUT2:
900 case OMAP_DSS_COLOR_CLUT4:
902 case OMAP_DSS_COLOR_CLUT8:
904 case OMAP_DSS_COLOR_RGB12U:
906 case OMAP_DSS_COLOR_ARGB16:
908 case OMAP_DSS_COLOR_RGB16:
910 case OMAP_DSS_COLOR_ARGB16_1555:
912 case OMAP_DSS_COLOR_RGB24U:
914 case OMAP_DSS_COLOR_RGB24P:
916 case OMAP_DSS_COLOR_RGBX16:
918 case OMAP_DSS_COLOR_RGBA16:
920 case OMAP_DSS_COLOR_ARGB32:
922 case OMAP_DSS_COLOR_RGBA32:
924 case OMAP_DSS_COLOR_RGBX32:
926 case OMAP_DSS_COLOR_XRGB16_1555:
933 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
936 static void dispc_ovl_configure_burst_type(enum omap_plane plane,
937 enum omap_dss_rotation_type rotation_type)
939 if (dss_has_feature(FEAT_BURST_2D) == 0)
942 if (rotation_type == OMAP_DSS_ROT_TILER)
943 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
945 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
948 void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
952 int chan = 0, chan2 = 0;
958 case OMAP_DSS_VIDEO1:
959 case OMAP_DSS_VIDEO2:
960 case OMAP_DSS_VIDEO3:
968 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
969 if (dss_has_feature(FEAT_MGR_LCD2)) {
971 case OMAP_DSS_CHANNEL_LCD:
975 case OMAP_DSS_CHANNEL_DIGIT:
979 case OMAP_DSS_CHANNEL_LCD2:
983 case OMAP_DSS_CHANNEL_LCD3:
984 if (dss_has_feature(FEAT_MGR_LCD3)) {
992 case OMAP_DSS_CHANNEL_WB:
1001 val = FLD_MOD(val, chan, shift, shift);
1002 val = FLD_MOD(val, chan2, 31, 30);
1004 val = FLD_MOD(val, channel, shift, shift);
1006 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
1008 EXPORT_SYMBOL(dispc_ovl_set_channel_out);
1010 static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
1019 case OMAP_DSS_VIDEO1:
1020 case OMAP_DSS_VIDEO2:
1021 case OMAP_DSS_VIDEO3:
1029 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1031 if (FLD_GET(val, shift, shift) == 1)
1032 return OMAP_DSS_CHANNEL_DIGIT;
1034 if (!dss_has_feature(FEAT_MGR_LCD2))
1035 return OMAP_DSS_CHANNEL_LCD;
1037 switch (FLD_GET(val, 31, 30)) {
1040 return OMAP_DSS_CHANNEL_LCD;
1042 return OMAP_DSS_CHANNEL_LCD2;
1044 return OMAP_DSS_CHANNEL_LCD3;
1046 return OMAP_DSS_CHANNEL_WB;
1050 void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1052 enum omap_plane plane = OMAP_DSS_WB;
1054 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1057 static void dispc_ovl_set_burst_size(enum omap_plane plane,
1058 enum omap_burst_size burst_size)
1060 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
1063 shift = shifts[plane];
1064 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
1067 static void dispc_configure_burst_sizes(void)
1070 const int burst_size = BURST_SIZE_X8;
1072 /* Configure burst size always to maximum size */
1073 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
1074 dispc_ovl_set_burst_size(i, burst_size);
1075 if (dispc.feat->has_writeback)
1076 dispc_ovl_set_burst_size(OMAP_DSS_WB, burst_size);
1079 static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
1081 unsigned unit = dss_feat_get_burst_size_unit();
1082 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1086 void dispc_enable_gamma_table(bool enable)
1089 * This is partially implemented to support only disabling of
1093 DSSWARN("Gamma table enabling for TV not yet supported");
1097 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1100 static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
1102 if (channel == OMAP_DSS_CHANNEL_DIGIT)
1105 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
1108 static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
1109 const struct omap_dss_cpr_coefs *coefs)
1111 u32 coef_r, coef_g, coef_b;
1113 if (!dss_mgr_is_lcd(channel))
1116 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1117 FLD_VAL(coefs->rb, 9, 0);
1118 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1119 FLD_VAL(coefs->gb, 9, 0);
1120 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1121 FLD_VAL(coefs->bb, 9, 0);
1123 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1124 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1125 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1128 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
1132 BUG_ON(plane == OMAP_DSS_GFX);
1134 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1135 val = FLD_MOD(val, enable, 9, 9);
1136 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
1139 static void dispc_ovl_enable_replication(enum omap_plane plane,
1140 enum omap_overlay_caps caps, bool enable)
1142 static const unsigned shifts[] = { 5, 10, 10, 10 };
1145 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1148 shift = shifts[plane];
1149 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
1152 static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
1157 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1158 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1160 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
1163 static void dispc_init_fifos(void)
1171 unit = dss_feat_get_buffer_size_unit();
1173 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1175 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1176 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
1178 dispc.fifo_size[fifo] = size;
1181 * By default fifos are mapped directly to overlays, fifo 0 to
1182 * ovl 0, fifo 1 to ovl 1, etc.
1184 dispc.fifo_assignment[fifo] = fifo;
1188 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1189 * causes problems with certain use cases, like using the tiler in 2D
1190 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1191 * giving GFX plane a larger fifo. WB but should work fine with a
1194 if (dispc.feat->gfx_fifo_workaround) {
1197 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1199 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1200 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1201 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1202 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1204 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1206 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1207 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1211 * Setup default fifo thresholds.
1213 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1215 const bool use_fifomerge = false;
1216 const bool manual_update = false;
1218 dispc_ovl_compute_fifo_thresholds(i, &low, &high,
1219 use_fifomerge, manual_update);
1221 dispc_ovl_set_fifo_threshold(i, low, high);
1224 if (dispc.feat->has_writeback) {
1226 const bool use_fifomerge = false;
1227 const bool manual_update = false;
1229 dispc_ovl_compute_fifo_thresholds(OMAP_DSS_WB, &low, &high,
1230 use_fifomerge, manual_update);
1232 dispc_ovl_set_fifo_threshold(OMAP_DSS_WB, low, high);
1236 static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1241 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1242 if (dispc.fifo_assignment[fifo] == plane)
1243 size += dispc.fifo_size[fifo];
1249 void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
1251 u8 hi_start, hi_end, lo_start, lo_end;
1254 unit = dss_feat_get_buffer_size_unit();
1256 WARN_ON(low % unit != 0);
1257 WARN_ON(high % unit != 0);
1262 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1263 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1265 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1267 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1268 lo_start, lo_end) * unit,
1269 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1270 hi_start, hi_end) * unit,
1271 low * unit, high * unit);
1273 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1274 FLD_VAL(high, hi_start, hi_end) |
1275 FLD_VAL(low, lo_start, lo_end));
1278 * configure the preload to the pipeline's high threhold, if HT it's too
1279 * large for the preload field, set the threshold to the maximum value
1280 * that can be held by the preload register
1282 if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1283 plane != OMAP_DSS_WB)
1284 dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
1287 void dispc_enable_fifomerge(bool enable)
1289 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1294 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1295 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1298 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1299 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1303 * All sizes are in bytes. Both the buffer and burst are made of
1304 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1307 unsigned buf_unit = dss_feat_get_buffer_size_unit();
1308 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1311 burst_size = dispc_ovl_get_burst_size(plane);
1312 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
1314 if (use_fifomerge) {
1315 total_fifo_size = 0;
1316 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
1317 total_fifo_size += dispc_ovl_get_fifo_size(i);
1319 total_fifo_size = ovl_fifo_size;
1323 * We use the same low threshold for both fifomerge and non-fifomerge
1324 * cases, but for fifomerge we calculate the high threshold using the
1325 * combined fifo size
1328 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1329 *fifo_low = ovl_fifo_size - burst_size * 2;
1330 *fifo_high = total_fifo_size - burst_size;
1331 } else if (plane == OMAP_DSS_WB) {
1333 * Most optimal configuration for writeback is to push out data
1334 * to the interconnect the moment writeback pushes enough pixels
1335 * in the FIFO to form a burst
1338 *fifo_high = burst_size;
1340 *fifo_low = ovl_fifo_size - burst_size;
1341 *fifo_high = total_fifo_size - buf_unit;
1345 static void dispc_ovl_set_mflag(enum omap_plane plane, bool enable)
1349 if (plane == OMAP_DSS_GFX)
1354 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1357 static void dispc_ovl_set_mflag_threshold(enum omap_plane plane,
1360 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane),
1361 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1364 static void dispc_init_mflag(void)
1369 * HACK: NV12 color format and MFLAG seem to have problems working
1370 * together: using two displays, and having an NV12 overlay on one of
1371 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1372 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1373 * remove the errors, but there doesn't seem to be a clear logic on
1374 * which values work and which not.
1376 * As a work-around, set force MFLAG to always on.
1378 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE,
1379 (1 << 0) | /* MFLAG_CTRL = force always on */
1380 (0 << 2)); /* MFLAG_START = disable */
1382 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1383 u32 size = dispc_ovl_get_fifo_size(i);
1384 u32 unit = dss_feat_get_buffer_size_unit();
1387 dispc_ovl_set_mflag(i, true);
1390 * Simulation team suggests below thesholds:
1391 * HT = fifosize * 5 / 8;
1392 * LT = fifosize * 4 / 8;
1395 low = size * 4 / 8 / unit;
1396 high = size * 5 / 8 / unit;
1398 dispc_ovl_set_mflag_threshold(i, low, high);
1401 if (dispc.feat->has_writeback) {
1402 u32 size = dispc_ovl_get_fifo_size(OMAP_DSS_WB);
1403 u32 unit = dss_feat_get_buffer_size_unit();
1406 dispc_ovl_set_mflag(OMAP_DSS_WB, true);
1409 * Simulation team suggests below thesholds:
1410 * HT = fifosize * 5 / 8;
1411 * LT = fifosize * 4 / 8;
1414 low = size * 4 / 8 / unit;
1415 high = size * 5 / 8 / unit;
1417 dispc_ovl_set_mflag_threshold(OMAP_DSS_WB, low, high);
1421 static void dispc_ovl_set_fir(enum omap_plane plane,
1423 enum omap_color_component color_comp)
1427 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1428 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1430 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1431 &hinc_start, &hinc_end);
1432 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1433 &vinc_start, &vinc_end);
1434 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1435 FLD_VAL(hinc, hinc_start, hinc_end);
1437 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1439 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1440 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1444 static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1447 u8 hor_start, hor_end, vert_start, vert_end;
1449 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1450 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1452 val = FLD_VAL(vaccu, vert_start, vert_end) |
1453 FLD_VAL(haccu, hor_start, hor_end);
1455 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1458 static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1461 u8 hor_start, hor_end, vert_start, vert_end;
1463 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1464 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1466 val = FLD_VAL(vaccu, vert_start, vert_end) |
1467 FLD_VAL(haccu, hor_start, hor_end);
1469 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1472 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1477 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1478 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1481 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1486 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1487 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1490 static void dispc_ovl_set_scale_param(enum omap_plane plane,
1491 u16 orig_width, u16 orig_height,
1492 u16 out_width, u16 out_height,
1493 bool five_taps, u8 rotation,
1494 enum omap_color_component color_comp)
1496 int fir_hinc, fir_vinc;
1498 fir_hinc = 1024 * orig_width / out_width;
1499 fir_vinc = 1024 * orig_height / out_height;
1501 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1503 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1506 static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1507 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1508 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1510 int h_accu2_0, h_accu2_1;
1511 int v_accu2_0, v_accu2_1;
1512 int chroma_hinc, chroma_vinc;
1522 const struct accu *accu_table;
1523 const struct accu *accu_val;
1525 static const struct accu accu_nv12[4] = {
1526 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1527 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1528 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1529 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1532 static const struct accu accu_nv12_ilace[4] = {
1533 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1534 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1535 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1536 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1539 static const struct accu accu_yuv[4] = {
1540 { 0, 1, 0, 1, 0, 1, 0, 1 },
1541 { 0, 1, 0, 1, 0, 1, 0, 1 },
1542 { -1, 1, 0, 1, 0, 1, 0, 1 },
1543 { 0, 1, 0, 1, -1, 1, 0, 1 },
1547 case OMAP_DSS_ROT_0:
1550 case OMAP_DSS_ROT_90:
1553 case OMAP_DSS_ROT_180:
1556 case OMAP_DSS_ROT_270:
1564 switch (color_mode) {
1565 case OMAP_DSS_COLOR_NV12:
1567 accu_table = accu_nv12_ilace;
1569 accu_table = accu_nv12;
1571 case OMAP_DSS_COLOR_YUV2:
1572 case OMAP_DSS_COLOR_UYVY:
1573 accu_table = accu_yuv;
1580 accu_val = &accu_table[idx];
1582 chroma_hinc = 1024 * orig_width / out_width;
1583 chroma_vinc = 1024 * orig_height / out_height;
1585 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1586 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1587 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1588 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1590 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1591 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1594 static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1595 u16 orig_width, u16 orig_height,
1596 u16 out_width, u16 out_height,
1597 bool ilace, bool five_taps,
1598 bool fieldmode, enum omap_color_mode color_mode,
1605 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1606 out_width, out_height, five_taps,
1607 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1608 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1610 /* RESIZEENABLE and VERTICALTAPS */
1611 l &= ~((0x3 << 5) | (0x1 << 21));
1612 l |= (orig_width != out_width) ? (1 << 5) : 0;
1613 l |= (orig_height != out_height) ? (1 << 6) : 0;
1614 l |= five_taps ? (1 << 21) : 0;
1616 /* VRESIZECONF and HRESIZECONF */
1617 if (dss_has_feature(FEAT_RESIZECONF)) {
1619 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1620 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1623 /* LINEBUFFERSPLIT */
1624 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1626 l |= five_taps ? (1 << 22) : 0;
1629 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1632 * field 0 = even field = bottom field
1633 * field 1 = odd field = top field
1635 if (ilace && !fieldmode) {
1637 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1638 if (accu0 >= 1024/2) {
1644 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1645 dispc_ovl_set_vid_accu1(plane, 0, accu1);
1648 static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1649 u16 orig_width, u16 orig_height,
1650 u16 out_width, u16 out_height,
1651 bool ilace, bool five_taps,
1652 bool fieldmode, enum omap_color_mode color_mode,
1655 int scale_x = out_width != orig_width;
1656 int scale_y = out_height != orig_height;
1657 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
1659 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1661 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1662 color_mode != OMAP_DSS_COLOR_UYVY &&
1663 color_mode != OMAP_DSS_COLOR_NV12)) {
1664 /* reset chroma resampling for RGB formats */
1665 if (plane != OMAP_DSS_WB)
1666 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1670 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1671 out_height, ilace, color_mode, rotation);
1673 switch (color_mode) {
1674 case OMAP_DSS_COLOR_NV12:
1675 if (chroma_upscale) {
1676 /* UV is subsampled by 2 horizontally and vertically */
1680 /* UV is downsampled by 2 horizontally and vertically */
1686 case OMAP_DSS_COLOR_YUV2:
1687 case OMAP_DSS_COLOR_UYVY:
1688 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
1689 if (rotation == OMAP_DSS_ROT_0 ||
1690 rotation == OMAP_DSS_ROT_180) {
1692 /* UV is subsampled by 2 horizontally */
1695 /* UV is downsampled by 2 horizontally */
1699 /* must use FIR for YUV422 if rotated */
1700 if (rotation != OMAP_DSS_ROT_0)
1701 scale_x = scale_y = true;
1709 if (out_width != orig_width)
1711 if (out_height != orig_height)
1714 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1715 out_width, out_height, five_taps,
1716 rotation, DISPC_COLOR_COMPONENT_UV);
1718 if (plane != OMAP_DSS_WB)
1719 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1720 (scale_x || scale_y) ? 1 : 0, 8, 8);
1723 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1725 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1728 static void dispc_ovl_set_scaling(enum omap_plane plane,
1729 u16 orig_width, u16 orig_height,
1730 u16 out_width, u16 out_height,
1731 bool ilace, bool five_taps,
1732 bool fieldmode, enum omap_color_mode color_mode,
1735 BUG_ON(plane == OMAP_DSS_GFX);
1737 dispc_ovl_set_scaling_common(plane,
1738 orig_width, orig_height,
1739 out_width, out_height,
1741 fieldmode, color_mode,
1744 dispc_ovl_set_scaling_uv(plane,
1745 orig_width, orig_height,
1746 out_width, out_height,
1748 fieldmode, color_mode,
1752 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1753 enum omap_dss_rotation_type rotation_type,
1754 bool mirroring, enum omap_color_mode color_mode)
1756 bool row_repeat = false;
1759 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1760 color_mode == OMAP_DSS_COLOR_UYVY) {
1764 case OMAP_DSS_ROT_0:
1767 case OMAP_DSS_ROT_90:
1770 case OMAP_DSS_ROT_180:
1773 case OMAP_DSS_ROT_270:
1779 case OMAP_DSS_ROT_0:
1782 case OMAP_DSS_ROT_90:
1785 case OMAP_DSS_ROT_180:
1788 case OMAP_DSS_ROT_270:
1794 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1801 * OMAP4/5 Errata i631:
1802 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1803 * rows beyond the framebuffer, which may cause OCP error.
1805 if (color_mode == OMAP_DSS_COLOR_NV12 &&
1806 rotation_type != OMAP_DSS_ROT_TILER)
1809 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1810 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1811 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1812 row_repeat ? 1 : 0, 18, 18);
1814 if (color_mode == OMAP_DSS_COLOR_NV12) {
1815 bool doublestride = (rotation_type == OMAP_DSS_ROT_TILER) &&
1816 (rotation == OMAP_DSS_ROT_0 ||
1817 rotation == OMAP_DSS_ROT_180);
1819 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1824 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1826 switch (color_mode) {
1827 case OMAP_DSS_COLOR_CLUT1:
1829 case OMAP_DSS_COLOR_CLUT2:
1831 case OMAP_DSS_COLOR_CLUT4:
1833 case OMAP_DSS_COLOR_CLUT8:
1834 case OMAP_DSS_COLOR_NV12:
1836 case OMAP_DSS_COLOR_RGB12U:
1837 case OMAP_DSS_COLOR_RGB16:
1838 case OMAP_DSS_COLOR_ARGB16:
1839 case OMAP_DSS_COLOR_YUV2:
1840 case OMAP_DSS_COLOR_UYVY:
1841 case OMAP_DSS_COLOR_RGBA16:
1842 case OMAP_DSS_COLOR_RGBX16:
1843 case OMAP_DSS_COLOR_ARGB16_1555:
1844 case OMAP_DSS_COLOR_XRGB16_1555:
1846 case OMAP_DSS_COLOR_RGB24P:
1848 case OMAP_DSS_COLOR_RGB24U:
1849 case OMAP_DSS_COLOR_ARGB32:
1850 case OMAP_DSS_COLOR_RGBA32:
1851 case OMAP_DSS_COLOR_RGBX32:
1859 static s32 pixinc(int pixels, u8 ps)
1863 else if (pixels > 1)
1864 return 1 + (pixels - 1) * ps;
1865 else if (pixels < 0)
1866 return 1 - (-pixels + 1) * ps;
1872 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1874 u16 width, u16 height,
1875 enum omap_color_mode color_mode, bool fieldmode,
1876 unsigned int field_offset,
1877 unsigned *offset0, unsigned *offset1,
1878 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1882 /* FIXME CLUT formats */
1883 switch (color_mode) {
1884 case OMAP_DSS_COLOR_CLUT1:
1885 case OMAP_DSS_COLOR_CLUT2:
1886 case OMAP_DSS_COLOR_CLUT4:
1887 case OMAP_DSS_COLOR_CLUT8:
1890 case OMAP_DSS_COLOR_YUV2:
1891 case OMAP_DSS_COLOR_UYVY:
1895 ps = color_mode_to_bpp(color_mode) / 8;
1899 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1903 * field 0 = even field = bottom field
1904 * field 1 = odd field = top field
1906 switch (rotation + mirror * 4) {
1907 case OMAP_DSS_ROT_0:
1908 case OMAP_DSS_ROT_180:
1910 * If the pixel format is YUV or UYVY divide the width
1911 * of the image by 2 for 0 and 180 degree rotation.
1913 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1914 color_mode == OMAP_DSS_COLOR_UYVY)
1916 case OMAP_DSS_ROT_90:
1917 case OMAP_DSS_ROT_270:
1920 *offset0 = field_offset * screen_width * ps;
1924 *row_inc = pixinc(1 +
1925 (y_predecim * screen_width - x_predecim * width) +
1926 (fieldmode ? screen_width : 0), ps);
1927 *pix_inc = pixinc(x_predecim, ps);
1930 case OMAP_DSS_ROT_0 + 4:
1931 case OMAP_DSS_ROT_180 + 4:
1932 /* If the pixel format is YUV or UYVY divide the width
1933 * of the image by 2 for 0 degree and 180 degree
1935 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1936 color_mode == OMAP_DSS_COLOR_UYVY)
1938 case OMAP_DSS_ROT_90 + 4:
1939 case OMAP_DSS_ROT_270 + 4:
1942 *offset0 = field_offset * screen_width * ps;
1945 *row_inc = pixinc(1 -
1946 (y_predecim * screen_width + x_predecim * width) -
1947 (fieldmode ? screen_width : 0), ps);
1948 *pix_inc = pixinc(x_predecim, ps);
1957 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1959 u16 width, u16 height,
1960 enum omap_color_mode color_mode, bool fieldmode,
1961 unsigned int field_offset,
1962 unsigned *offset0, unsigned *offset1,
1963 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1968 /* FIXME CLUT formats */
1969 switch (color_mode) {
1970 case OMAP_DSS_COLOR_CLUT1:
1971 case OMAP_DSS_COLOR_CLUT2:
1972 case OMAP_DSS_COLOR_CLUT4:
1973 case OMAP_DSS_COLOR_CLUT8:
1977 ps = color_mode_to_bpp(color_mode) / 8;
1981 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1984 /* width & height are overlay sizes, convert to fb sizes */
1986 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1995 * field 0 = even field = bottom field
1996 * field 1 = odd field = top field
1998 switch (rotation + mirror * 4) {
1999 case OMAP_DSS_ROT_0:
2002 *offset0 = *offset1 + field_offset * screen_width * ps;
2004 *offset0 = *offset1;
2005 *row_inc = pixinc(1 +
2006 (y_predecim * screen_width - fbw * x_predecim) +
2007 (fieldmode ? screen_width : 0), ps);
2008 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2009 color_mode == OMAP_DSS_COLOR_UYVY)
2010 *pix_inc = pixinc(x_predecim, 2 * ps);
2012 *pix_inc = pixinc(x_predecim, ps);
2014 case OMAP_DSS_ROT_90:
2015 *offset1 = screen_width * (fbh - 1) * ps;
2017 *offset0 = *offset1 + field_offset * ps;
2019 *offset0 = *offset1;
2020 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
2021 y_predecim + (fieldmode ? 1 : 0), ps);
2022 *pix_inc = pixinc(-x_predecim * screen_width, ps);
2024 case OMAP_DSS_ROT_180:
2025 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2027 *offset0 = *offset1 - field_offset * screen_width * ps;
2029 *offset0 = *offset1;
2030 *row_inc = pixinc(-1 -
2031 (y_predecim * screen_width - fbw * x_predecim) -
2032 (fieldmode ? screen_width : 0), ps);
2033 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2034 color_mode == OMAP_DSS_COLOR_UYVY)
2035 *pix_inc = pixinc(-x_predecim, 2 * ps);
2037 *pix_inc = pixinc(-x_predecim, ps);
2039 case OMAP_DSS_ROT_270:
2040 *offset1 = (fbw - 1) * ps;
2042 *offset0 = *offset1 - field_offset * ps;
2044 *offset0 = *offset1;
2045 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
2046 y_predecim - (fieldmode ? 1 : 0), ps);
2047 *pix_inc = pixinc(x_predecim * screen_width, ps);
2051 case OMAP_DSS_ROT_0 + 4:
2052 *offset1 = (fbw - 1) * ps;
2054 *offset0 = *offset1 + field_offset * screen_width * ps;
2056 *offset0 = *offset1;
2057 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
2058 (fieldmode ? screen_width : 0),
2060 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2061 color_mode == OMAP_DSS_COLOR_UYVY)
2062 *pix_inc = pixinc(-x_predecim, 2 * ps);
2064 *pix_inc = pixinc(-x_predecim, ps);
2067 case OMAP_DSS_ROT_90 + 4:
2070 *offset0 = *offset1 + field_offset * ps;
2072 *offset0 = *offset1;
2073 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
2074 y_predecim + (fieldmode ? 1 : 0),
2076 *pix_inc = pixinc(x_predecim * screen_width, ps);
2079 case OMAP_DSS_ROT_180 + 4:
2080 *offset1 = screen_width * (fbh - 1) * ps;
2082 *offset0 = *offset1 - field_offset * screen_width * ps;
2084 *offset0 = *offset1;
2085 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
2086 (fieldmode ? screen_width : 0),
2088 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2089 color_mode == OMAP_DSS_COLOR_UYVY)
2090 *pix_inc = pixinc(x_predecim, 2 * ps);
2092 *pix_inc = pixinc(x_predecim, ps);
2095 case OMAP_DSS_ROT_270 + 4:
2096 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2098 *offset0 = *offset1 - field_offset * ps;
2100 *offset0 = *offset1;
2101 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
2102 y_predecim - (fieldmode ? 1 : 0),
2104 *pix_inc = pixinc(-x_predecim * screen_width, ps);
2113 static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
2114 enum omap_color_mode color_mode, bool fieldmode,
2115 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
2116 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
2120 switch (color_mode) {
2121 case OMAP_DSS_COLOR_CLUT1:
2122 case OMAP_DSS_COLOR_CLUT2:
2123 case OMAP_DSS_COLOR_CLUT4:
2124 case OMAP_DSS_COLOR_CLUT8:
2128 ps = color_mode_to_bpp(color_mode) / 8;
2132 DSSDBG("scrw %d, width %d\n", screen_width, width);
2135 * field 0 = even field = bottom field
2136 * field 1 = odd field = top field
2140 *offset0 = *offset1 + field_offset * screen_width * ps;
2142 *offset0 = *offset1;
2143 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2144 (fieldmode ? screen_width : 0), ps);
2145 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2146 color_mode == OMAP_DSS_COLOR_UYVY)
2147 *pix_inc = pixinc(x_predecim, 2 * ps);
2149 *pix_inc = pixinc(x_predecim, ps);
2153 * This function is used to avoid synclosts in OMAP3, because of some
2154 * undocumented horizontal position and timing related limitations.
2156 static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
2157 const struct omap_video_timings *t, u16 pos_x,
2158 u16 width, u16 height, u16 out_width, u16 out_height,
2161 const int ds = DIV_ROUND_UP(height, out_height);
2162 unsigned long nonactive;
2163 static const u8 limits[3] = { 8, 10, 20 };
2167 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
2170 if (out_height < height)
2172 if (out_width < width)
2174 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
2175 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2176 if (blank <= limits[i])
2179 /* FIXME add checks for 3-tap filter once the limitations are known */
2184 * Pixel data should be prepared before visible display point starts.
2185 * So, atleast DS-2 lines must have already been fetched by DISPC
2186 * during nonactive - pos_x period.
2188 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2189 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2190 val, max(0, ds - 2) * width);
2191 if (val < max(0, ds - 2) * width)
2195 * All lines need to be refilled during the nonactive period of which
2196 * only one line can be loaded during the active period. So, atleast
2197 * DS - 1 lines should be loaded during nonactive period.
2199 val = div_u64((u64)nonactive * lclk, pclk);
2200 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2201 val, max(0, ds - 1) * width);
2202 if (val < max(0, ds - 1) * width)
2208 static unsigned long calc_core_clk_five_taps(unsigned long pclk,
2209 const struct omap_video_timings *mgr_timings, u16 width,
2210 u16 height, u16 out_width, u16 out_height,
2211 enum omap_color_mode color_mode)
2216 if (height <= out_height && width <= out_width)
2217 return (unsigned long) pclk;
2219 if (height > out_height) {
2220 unsigned int ppl = mgr_timings->x_res;
2222 tmp = (u64)pclk * height * out_width;
2223 do_div(tmp, 2 * out_height * ppl);
2226 if (height > 2 * out_height) {
2227 if (ppl == out_width)
2230 tmp = (u64)pclk * (height - 2 * out_height) * out_width;
2231 do_div(tmp, 2 * out_height * (ppl - out_width));
2232 core_clk = max_t(u32, core_clk, tmp);
2236 if (width > out_width) {
2237 tmp = (u64)pclk * width;
2238 do_div(tmp, out_width);
2239 core_clk = max_t(u32, core_clk, tmp);
2241 if (color_mode == OMAP_DSS_COLOR_RGB24U)
2248 static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
2249 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2251 if (height > out_height && width > out_width)
2257 static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
2258 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2260 unsigned int hf, vf;
2263 * FIXME how to determine the 'A' factor
2264 * for the no downscaling case ?
2267 if (width > 3 * out_width)
2269 else if (width > 2 * out_width)
2271 else if (width > out_width)
2275 if (height > out_height)
2280 return pclk * vf * hf;
2283 static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
2284 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2287 * If the overlay/writeback is in mem to mem mode, there are no
2288 * downscaling limitations with respect to pixel clock, return 1 as
2289 * required core clock to represent that we have sufficient enough
2290 * core clock to do maximum downscaling
2295 if (width > out_width)
2296 return DIV_ROUND_UP(pclk, out_width) * width;
2301 static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
2302 const struct omap_video_timings *mgr_timings,
2303 u16 width, u16 height, u16 out_width, u16 out_height,
2304 enum omap_color_mode color_mode, bool *five_taps,
2305 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2306 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2309 u16 in_width, in_height;
2310 int min_factor = min(*decim_x, *decim_y);
2311 const int maxsinglelinewidth =
2312 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2317 in_height = height / *decim_y;
2318 in_width = width / *decim_x;
2319 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
2320 in_height, out_width, out_height, mem_to_mem);
2321 error = (in_width > maxsinglelinewidth || !*core_clk ||
2322 *core_clk > dispc_core_clk_rate());
2324 if (*decim_x == *decim_y) {
2325 *decim_x = min_factor;
2328 swap(*decim_x, *decim_y);
2329 if (*decim_x < *decim_y)
2333 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2336 DSSERR("failed to find scaling settings\n");
2340 if (in_width > maxsinglelinewidth) {
2341 DSSERR("Cannot scale max input width exceeded");
2347 static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
2348 const struct omap_video_timings *mgr_timings,
2349 u16 width, u16 height, u16 out_width, u16 out_height,
2350 enum omap_color_mode color_mode, bool *five_taps,
2351 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2352 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2355 u16 in_width, in_height;
2356 const int maxsinglelinewidth =
2357 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2360 in_height = height / *decim_y;
2361 in_width = width / *decim_x;
2362 *five_taps = in_height > out_height;
2364 if (in_width > maxsinglelinewidth)
2365 if (in_height > out_height &&
2366 in_height < out_height * 2)
2370 *core_clk = calc_core_clk_five_taps(pclk, mgr_timings,
2371 in_width, in_height, out_width,
2372 out_height, color_mode);
2374 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
2375 in_height, out_width, out_height,
2378 error = check_horiz_timing_omap3(pclk, lclk, mgr_timings,
2379 pos_x, in_width, in_height, out_width,
2380 out_height, *five_taps);
2381 if (error && *five_taps) {
2386 error = (error || in_width > maxsinglelinewidth * 2 ||
2387 (in_width > maxsinglelinewidth && *five_taps) ||
2388 !*core_clk || *core_clk > dispc_core_clk_rate());
2391 /* verify that we're inside the limits of scaler */
2392 if (in_width / 4 > out_width)
2396 if (in_height / 4 > out_height)
2399 if (in_height / 2 > out_height)
2406 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2409 DSSERR("failed to find scaling settings\n");
2413 if (check_horiz_timing_omap3(pclk, lclk, mgr_timings, pos_x, in_width,
2414 in_height, out_width, out_height, *five_taps)) {
2415 DSSERR("horizontal timing too tight\n");
2419 if (in_width > (maxsinglelinewidth * 2)) {
2420 DSSERR("Cannot setup scaling");
2421 DSSERR("width exceeds maximum width possible");
2425 if (in_width > maxsinglelinewidth && *five_taps) {
2426 DSSERR("cannot setup scaling with five taps");
2432 static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
2433 const struct omap_video_timings *mgr_timings,
2434 u16 width, u16 height, u16 out_width, u16 out_height,
2435 enum omap_color_mode color_mode, bool *five_taps,
2436 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2437 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2439 u16 in_width, in_width_max;
2440 int decim_x_min = *decim_x;
2441 u16 in_height = height / *decim_y;
2442 const int maxsinglelinewidth =
2443 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2444 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2447 in_width_max = out_width * maxdownscale;
2449 in_width_max = dispc_core_clk_rate() /
2450 DIV_ROUND_UP(pclk, out_width);
2453 *decim_x = DIV_ROUND_UP(width, in_width_max);
2455 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2456 if (*decim_x > *x_predecim)
2460 in_width = width / *decim_x;
2461 } while (*decim_x <= *x_predecim &&
2462 in_width > maxsinglelinewidth && ++*decim_x);
2464 if (in_width > maxsinglelinewidth) {
2465 DSSERR("Cannot scale width exceeds max line width");
2469 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
2470 out_width, out_height, mem_to_mem);
2474 #define DIV_FRAC(dividend, divisor) \
2475 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2477 static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
2478 enum omap_overlay_caps caps,
2479 const struct omap_video_timings *mgr_timings,
2480 u16 width, u16 height, u16 out_width, u16 out_height,
2481 enum omap_color_mode color_mode, bool *five_taps,
2482 int *x_predecim, int *y_predecim, u16 pos_x,
2483 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
2485 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2486 const int max_decim_limit = 16;
2487 unsigned long core_clk = 0;
2488 int decim_x, decim_y, ret;
2490 if (width == out_width && height == out_height)
2493 if (!mem_to_mem && (pclk == 0 || mgr_timings->pixelclock == 0)) {
2494 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2498 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
2502 *x_predecim = *y_predecim = 1;
2504 *x_predecim = max_decim_limit;
2505 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2506 dss_has_feature(FEAT_BURST_2D)) ?
2507 2 : max_decim_limit;
2510 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2511 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2512 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2513 color_mode == OMAP_DSS_COLOR_CLUT8) {
2520 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2521 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2523 if (decim_x > *x_predecim || out_width > width * 8)
2526 if (decim_y > *y_predecim || out_height > height * 8)
2529 ret = dispc.feat->calc_scaling(pclk, lclk, mgr_timings, width, height,
2530 out_width, out_height, color_mode, five_taps,
2531 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2536 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",
2538 out_width, out_height,
2539 out_width / width, DIV_FRAC(out_width, width),
2540 out_height / height, DIV_FRAC(out_height, height),
2543 width / decim_x, height / decim_y,
2544 out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
2545 out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
2548 core_clk, dispc_core_clk_rate());
2550 if (!core_clk || core_clk > dispc_core_clk_rate()) {
2551 DSSERR("failed to set up scaling, "
2552 "required core clk rate = %lu Hz, "
2553 "current core clk rate = %lu Hz\n",
2554 core_clk, dispc_core_clk_rate());
2558 *x_predecim = decim_x;
2559 *y_predecim = decim_y;
2563 static int dispc_ovl_setup_common(enum omap_plane plane,
2564 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2565 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2566 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2567 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2568 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
2569 bool replication, const struct omap_video_timings *mgr_timings,
2572 bool five_taps = true;
2573 bool fieldmode = false;
2575 unsigned offset0, offset1;
2578 u16 frame_width, frame_height;
2579 unsigned int field_offset = 0;
2580 u16 in_height = height;
2581 u16 in_width = width;
2582 int x_predecim = 1, y_predecim = 1;
2583 bool ilace = mgr_timings->interlace;
2584 unsigned long pclk = dispc_plane_pclk_rate(plane);
2585 unsigned long lclk = dispc_plane_lclk_rate(plane);
2587 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
2590 switch (color_mode) {
2591 case OMAP_DSS_COLOR_YUV2:
2592 case OMAP_DSS_COLOR_UYVY:
2593 case OMAP_DSS_COLOR_NV12:
2595 DSSERR("input width %d is not even for YUV format\n",
2605 out_width = out_width == 0 ? width : out_width;
2606 out_height = out_height == 0 ? height : out_height;
2608 if (ilace && height == out_height)
2617 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2618 "out_height %d\n", in_height, pos_y,
2622 if (!dss_feat_color_mode_supported(plane, color_mode))
2625 r = dispc_ovl_calc_scaling(pclk, lclk, caps, mgr_timings, in_width,
2626 in_height, out_width, out_height, color_mode,
2627 &five_taps, &x_predecim, &y_predecim, pos_x,
2628 rotation_type, mem_to_mem);
2632 in_width = in_width / x_predecim;
2633 in_height = in_height / y_predecim;
2635 if (x_predecim > 1 || y_predecim > 1)
2636 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2637 x_predecim, y_predecim, in_width, in_height);
2639 switch (color_mode) {
2640 case OMAP_DSS_COLOR_YUV2:
2641 case OMAP_DSS_COLOR_UYVY:
2642 case OMAP_DSS_COLOR_NV12:
2644 DSSDBG("predecimated input width is not even for YUV format\n");
2645 DSSDBG("adjusting input width %d -> %d\n",
2646 in_width, in_width & ~1);
2656 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2657 color_mode == OMAP_DSS_COLOR_UYVY ||
2658 color_mode == OMAP_DSS_COLOR_NV12)
2661 if (ilace && !fieldmode) {
2663 * when downscaling the bottom field may have to start several
2664 * source lines below the top field. Unfortunately ACCUI
2665 * registers will only hold the fractional part of the offset
2666 * so the integer part must be added to the base address of the
2669 if (!in_height || in_height == out_height)
2672 field_offset = in_height / out_height / 2;
2675 /* Fields are independent but interleaved in memory. */
2684 if (plane == OMAP_DSS_WB) {
2685 frame_width = out_width;
2686 frame_height = out_height;
2688 frame_width = in_width;
2689 frame_height = height;
2692 if (rotation_type == OMAP_DSS_ROT_TILER)
2693 calc_tiler_rotation_offset(screen_width, frame_width,
2694 color_mode, fieldmode, field_offset,
2695 &offset0, &offset1, &row_inc, &pix_inc,
2696 x_predecim, y_predecim);
2697 else if (rotation_type == OMAP_DSS_ROT_DMA)
2698 calc_dma_rotation_offset(rotation, mirror, screen_width,
2699 frame_width, frame_height,
2700 color_mode, fieldmode, field_offset,
2701 &offset0, &offset1, &row_inc, &pix_inc,
2702 x_predecim, y_predecim);
2704 calc_vrfb_rotation_offset(rotation, mirror,
2705 screen_width, frame_width, frame_height,
2706 color_mode, fieldmode, field_offset,
2707 &offset0, &offset1, &row_inc, &pix_inc,
2708 x_predecim, y_predecim);
2710 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2711 offset0, offset1, row_inc, pix_inc);
2713 dispc_ovl_set_color_mode(plane, color_mode);
2715 dispc_ovl_configure_burst_type(plane, rotation_type);
2717 if (dispc.feat->reverse_ilace_field_order)
2718 swap(offset0, offset1);
2720 dispc_ovl_set_ba0(plane, paddr + offset0);
2721 dispc_ovl_set_ba1(plane, paddr + offset1);
2723 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2724 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2725 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
2728 if (dispc.feat->last_pixel_inc_missing)
2729 row_inc += pix_inc - 1;
2731 dispc_ovl_set_row_inc(plane, row_inc);
2732 dispc_ovl_set_pix_inc(plane, pix_inc);
2734 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
2735 in_height, out_width, out_height);
2737 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
2739 dispc_ovl_set_input_size(plane, in_width, in_height);
2741 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
2742 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2743 out_height, ilace, five_taps, fieldmode,
2744 color_mode, rotation);
2745 dispc_ovl_set_output_size(plane, out_width, out_height);
2746 dispc_ovl_set_vid_color_conv(plane, cconv);
2749 dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror,
2752 dispc_ovl_set_zorder(plane, caps, zorder);
2753 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2754 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
2756 dispc_ovl_enable_replication(plane, caps, replication);
2761 int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
2762 bool replication, const struct omap_video_timings *mgr_timings,
2766 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2767 enum omap_channel channel;
2769 channel = dispc_ovl_get_channel_out(plane);
2771 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2772 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2773 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
2774 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2775 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2777 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
2778 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2779 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2780 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
2781 oi->rotation_type, replication, mgr_timings, mem_to_mem);
2785 EXPORT_SYMBOL(dispc_ovl_setup);
2787 int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
2788 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
2792 enum omap_plane plane = OMAP_DSS_WB;
2793 const int pos_x = 0, pos_y = 0;
2794 const u8 zorder = 0, global_alpha = 0;
2795 const bool replication = false;
2797 int in_width = mgr_timings->x_res;
2798 int in_height = mgr_timings->y_res;
2799 enum omap_overlay_caps caps =
2800 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2802 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2803 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2804 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2807 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2808 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2809 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2810 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
2811 replication, mgr_timings, mem_to_mem);
2813 switch (wi->color_mode) {
2814 case OMAP_DSS_COLOR_RGB16:
2815 case OMAP_DSS_COLOR_RGB24P:
2816 case OMAP_DSS_COLOR_ARGB16:
2817 case OMAP_DSS_COLOR_RGBA16:
2818 case OMAP_DSS_COLOR_RGB12U:
2819 case OMAP_DSS_COLOR_ARGB16_1555:
2820 case OMAP_DSS_COLOR_XRGB16_1555:
2821 case OMAP_DSS_COLOR_RGBX16:
2829 /* setup extra DISPC_WB_ATTRIBUTES */
2830 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2831 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2832 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2834 l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */
2836 l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */
2837 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
2841 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
2845 wbdelay = min(mgr_timings->vfp + mgr_timings->vsw +
2846 mgr_timings->vbp, 255);
2849 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
2855 int dispc_ovl_enable(enum omap_plane plane, bool enable)
2857 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2859 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2863 EXPORT_SYMBOL(dispc_ovl_enable);
2865 bool dispc_ovl_enabled(enum omap_plane plane)
2867 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2869 EXPORT_SYMBOL(dispc_ovl_enabled);
2871 enum omap_dss_output_id dispc_mgr_get_supported_outputs(enum omap_channel channel)
2873 return dss_feat_get_supported_outputs(channel);
2875 EXPORT_SYMBOL(dispc_mgr_get_supported_outputs);
2877 void dispc_mgr_enable(enum omap_channel channel, bool enable)
2879 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2880 /* flush posted write */
2881 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2883 EXPORT_SYMBOL(dispc_mgr_enable);
2885 bool dispc_mgr_is_enabled(enum omap_channel channel)
2887 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2889 EXPORT_SYMBOL(dispc_mgr_is_enabled);
2891 void dispc_wb_enable(bool enable)
2893 dispc_ovl_enable(OMAP_DSS_WB, enable);
2896 bool dispc_wb_is_enabled(void)
2898 return dispc_ovl_enabled(OMAP_DSS_WB);
2901 static void dispc_lcd_enable_signal_polarity(bool act_high)
2903 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2906 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2909 void dispc_lcd_enable_signal(bool enable)
2911 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2914 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2917 void dispc_pck_free_enable(bool enable)
2919 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2922 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2925 static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2927 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
2931 static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
2933 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
2936 static void dispc_set_loadmode(enum omap_dss_load_mode mode)
2938 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2942 static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2944 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2947 static void dispc_mgr_set_trans_key(enum omap_channel ch,
2948 enum omap_dss_trans_key_type type,
2951 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
2953 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2956 static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2958 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
2961 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2964 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
2967 if (ch == OMAP_DSS_CHANNEL_LCD)
2968 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2969 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2970 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2973 void dispc_mgr_setup(enum omap_channel channel,
2974 const struct omap_overlay_manager_info *info)
2976 dispc_mgr_set_default_color(channel, info->default_color);
2977 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2978 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2979 dispc_mgr_enable_alpha_fixed_zorder(channel,
2980 info->partial_alpha_enabled);
2981 if (dss_has_feature(FEAT_CPR)) {
2982 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2983 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2986 EXPORT_SYMBOL(dispc_mgr_setup);
2988 static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2992 switch (data_lines) {
3010 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
3013 static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
3019 case DSS_IO_PAD_MODE_RESET:
3023 case DSS_IO_PAD_MODE_RFBI:
3027 case DSS_IO_PAD_MODE_BYPASS:
3036 l = dispc_read_reg(DISPC_CONTROL);
3037 l = FLD_MOD(l, gpout0, 15, 15);
3038 l = FLD_MOD(l, gpout1, 16, 16);
3039 dispc_write_reg(DISPC_CONTROL, l);
3042 static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
3044 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
3047 void dispc_mgr_set_lcd_config(enum omap_channel channel,
3048 const struct dss_lcd_mgr_config *config)
3050 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
3052 dispc_mgr_enable_stallmode(channel, config->stallmode);
3053 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
3055 dispc_mgr_set_clock_div(channel, &config->clock_info);
3057 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
3059 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
3061 dispc_mgr_set_lcd_type_tft(channel);
3063 EXPORT_SYMBOL(dispc_mgr_set_lcd_config);
3065 static bool _dispc_mgr_size_ok(u16 width, u16 height)
3067 return width <= dispc.feat->mgr_width_max &&
3068 height <= dispc.feat->mgr_height_max;
3071 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
3072 int vsw, int vfp, int vbp)
3074 if (hsw < 1 || hsw > dispc.feat->sw_max ||
3075 hfp < 1 || hfp > dispc.feat->hp_max ||
3076 hbp < 1 || hbp > dispc.feat->hp_max ||
3077 vsw < 1 || vsw > dispc.feat->sw_max ||
3078 vfp < 0 || vfp > dispc.feat->vp_max ||
3079 vbp < 0 || vbp > dispc.feat->vp_max)
3084 static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
3087 if (dss_mgr_is_lcd(channel))
3088 return pclk <= dispc.feat->max_lcd_pclk ? true : false;
3090 return pclk <= dispc.feat->max_tv_pclk ? true : false;
3093 bool dispc_mgr_timings_ok(enum omap_channel channel,
3094 const struct omap_video_timings *timings)
3096 if (!_dispc_mgr_size_ok(timings->x_res, timings->y_res))
3099 if (!_dispc_mgr_pclk_ok(channel, timings->pixelclock))
3102 if (dss_mgr_is_lcd(channel)) {
3103 /* TODO: OMAP4+ supports interlace for LCD outputs */
3104 if (timings->interlace)
3107 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
3108 timings->hbp, timings->vsw, timings->vfp,
3116 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
3117 int hfp, int hbp, int vsw, int vfp, int vbp,
3118 enum omap_dss_signal_level vsync_level,
3119 enum omap_dss_signal_level hsync_level,
3120 enum omap_dss_signal_edge data_pclk_edge,
3121 enum omap_dss_signal_level de_level,
3122 enum omap_dss_signal_edge sync_pclk_edge)
3125 u32 timing_h, timing_v, l;
3126 bool onoff, rf, ipc, vs, hs, de;
3128 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
3129 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
3130 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
3131 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
3132 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
3133 FLD_VAL(vbp, dispc.feat->bp_start, 20);
3135 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
3136 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
3138 switch (vsync_level) {
3139 case OMAPDSS_SIG_ACTIVE_LOW:
3142 case OMAPDSS_SIG_ACTIVE_HIGH:
3149 switch (hsync_level) {
3150 case OMAPDSS_SIG_ACTIVE_LOW:
3153 case OMAPDSS_SIG_ACTIVE_HIGH:
3161 case OMAPDSS_SIG_ACTIVE_LOW:
3164 case OMAPDSS_SIG_ACTIVE_HIGH:
3171 switch (data_pclk_edge) {
3172 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3175 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3182 /* always use the 'rf' setting */
3185 switch (sync_pclk_edge) {
3186 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3189 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3196 l = FLD_VAL(onoff, 17, 17) |
3197 FLD_VAL(rf, 16, 16) |
3198 FLD_VAL(de, 15, 15) |
3199 FLD_VAL(ipc, 14, 14) |
3200 FLD_VAL(hs, 13, 13) |
3201 FLD_VAL(vs, 12, 12);
3203 /* always set ALIGN bit when available */
3204 if (dispc.feat->supports_sync_align)
3207 dispc_write_reg(DISPC_POL_FREQ(channel), l);
3209 if (dispc.syscon_pol) {
3210 const int shifts[] = {
3211 [OMAP_DSS_CHANNEL_LCD] = 0,
3212 [OMAP_DSS_CHANNEL_LCD2] = 1,
3213 [OMAP_DSS_CHANNEL_LCD3] = 2,
3218 mask = (1 << 0) | (1 << 3) | (1 << 6);
3219 val = (rf << 0) | (ipc << 3) | (onoff << 6);
3221 mask <<= 16 + shifts[channel];
3222 val <<= 16 + shifts[channel];
3224 regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
3229 /* change name to mode? */
3230 void dispc_mgr_set_timings(enum omap_channel channel,
3231 const struct omap_video_timings *timings)
3233 unsigned xtot, ytot;
3234 unsigned long ht, vt;
3235 struct omap_video_timings t = *timings;
3237 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
3239 if (!dispc_mgr_timings_ok(channel, &t)) {
3244 if (dss_mgr_is_lcd(channel)) {
3245 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
3246 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
3247 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
3249 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
3250 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
3252 ht = timings->pixelclock / xtot;
3253 vt = timings->pixelclock / xtot / ytot;
3255 DSSDBG("pck %u\n", timings->pixelclock);
3256 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
3257 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
3258 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3259 t.vsync_level, t.hsync_level, t.data_pclk_edge,
3260 t.de_level, t.sync_pclk_edge);
3262 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
3267 if (dispc.feat->supports_double_pixel)
3268 REG_FLD_MOD(DISPC_CONTROL, t.double_pixel ? 1 : 0,
3272 dispc_mgr_set_size(channel, t.x_res, t.y_res);
3274 EXPORT_SYMBOL(dispc_mgr_set_timings);
3276 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
3279 BUG_ON(lck_div < 1);
3280 BUG_ON(pck_div < 1);
3282 dispc_write_reg(DISPC_DIVISORo(channel),
3283 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
3285 if (!dss_has_feature(FEAT_CORE_CLK_DIV) &&
3286 channel == OMAP_DSS_CHANNEL_LCD)
3287 dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
3290 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
3294 l = dispc_read_reg(DISPC_DIVISORo(channel));
3295 *lck_div = FLD_GET(l, 23, 16);
3296 *pck_div = FLD_GET(l, 7, 0);
3299 static unsigned long dispc_fclk_rate(void)
3302 enum dss_clk_source src;
3304 src = dss_get_dispc_clk_source();
3306 if (src == DSS_CLK_SRC_FCK) {
3307 r = dss_get_dispc_clk_rate();
3309 struct dss_pll *pll;
3310 unsigned clkout_idx;
3312 pll = dss_pll_find_by_src(src);
3313 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
3315 r = pll->cinfo.clkout[clkout_idx];
3321 static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
3325 enum dss_clk_source src;
3327 /* for TV, LCLK rate is the FCLK rate */
3328 if (!dss_mgr_is_lcd(channel))
3329 return dispc_fclk_rate();
3331 src = dss_get_lcd_clk_source(channel);
3333 if (src == DSS_CLK_SRC_FCK) {
3334 r = dss_get_dispc_clk_rate();
3336 struct dss_pll *pll;
3337 unsigned clkout_idx;
3339 pll = dss_pll_find_by_src(src);
3340 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
3342 r = pll->cinfo.clkout[clkout_idx];
3345 lcd = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3350 static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
3354 if (dss_mgr_is_lcd(channel)) {
3358 l = dispc_read_reg(DISPC_DIVISORo(channel));
3360 pcd = FLD_GET(l, 7, 0);
3362 r = dispc_mgr_lclk_rate(channel);
3366 return dispc.tv_pclk_rate;
3370 void dispc_set_tv_pclk(unsigned long pclk)
3372 dispc.tv_pclk_rate = pclk;
3375 static unsigned long dispc_core_clk_rate(void)
3377 return dispc.core_clk_rate;
3380 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3382 enum omap_channel channel;
3384 if (plane == OMAP_DSS_WB)
3387 channel = dispc_ovl_get_channel_out(plane);
3389 return dispc_mgr_pclk_rate(channel);
3392 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3394 enum omap_channel channel;
3396 if (plane == OMAP_DSS_WB)
3399 channel = dispc_ovl_get_channel_out(plane);
3401 return dispc_mgr_lclk_rate(channel);
3404 static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
3407 enum dss_clk_source lcd_clk_src;
3409 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3411 lcd_clk_src = dss_get_lcd_clk_source(channel);
3413 seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
3414 dss_get_clk_source_name(lcd_clk_src));
3416 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3418 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3419 dispc_mgr_lclk_rate(channel), lcd);
3420 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3421 dispc_mgr_pclk_rate(channel), pcd);
3424 void dispc_dump_clocks(struct seq_file *s)
3428 enum dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
3430 if (dispc_runtime_get())
3433 seq_printf(s, "- DISPC -\n");
3435 seq_printf(s, "dispc fclk source = %s\n",
3436 dss_get_clk_source_name(dispc_clk_src));
3438 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
3440 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3441 seq_printf(s, "- DISPC-CORE-CLK -\n");
3442 l = dispc_read_reg(DISPC_DIVISOR);
3443 lcd = FLD_GET(l, 23, 16);
3445 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3446 (dispc_fclk_rate()/lcd), lcd);
3449 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
3451 if (dss_has_feature(FEAT_MGR_LCD2))
3452 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3453 if (dss_has_feature(FEAT_MGR_LCD3))
3454 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
3456 dispc_runtime_put();
3459 static void dispc_dump_regs(struct seq_file *s)
3462 const char *mgr_names[] = {
3463 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3464 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3465 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
3466 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
3468 const char *ovl_names[] = {
3469 [OMAP_DSS_GFX] = "GFX",
3470 [OMAP_DSS_VIDEO1] = "VID1",
3471 [OMAP_DSS_VIDEO2] = "VID2",
3472 [OMAP_DSS_VIDEO3] = "VID3",
3473 [OMAP_DSS_WB] = "WB",
3475 const char **p_names;
3477 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3479 if (dispc_runtime_get())
3482 /* DISPC common registers */
3483 DUMPREG(DISPC_REVISION);
3484 DUMPREG(DISPC_SYSCONFIG);
3485 DUMPREG(DISPC_SYSSTATUS);
3486 DUMPREG(DISPC_IRQSTATUS);
3487 DUMPREG(DISPC_IRQENABLE);
3488 DUMPREG(DISPC_CONTROL);
3489 DUMPREG(DISPC_CONFIG);
3490 DUMPREG(DISPC_CAPABLE);
3491 DUMPREG(DISPC_LINE_STATUS);
3492 DUMPREG(DISPC_LINE_NUMBER);
3493 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3494 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
3495 DUMPREG(DISPC_GLOBAL_ALPHA);
3496 if (dss_has_feature(FEAT_MGR_LCD2)) {
3497 DUMPREG(DISPC_CONTROL2);
3498 DUMPREG(DISPC_CONFIG2);
3500 if (dss_has_feature(FEAT_MGR_LCD3)) {
3501 DUMPREG(DISPC_CONTROL3);
3502 DUMPREG(DISPC_CONFIG3);
3504 if (dss_has_feature(FEAT_MFLAG))
3505 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
3509 #define DISPC_REG(i, name) name(i)
3510 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3511 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
3512 dispc_read_reg(DISPC_REG(i, r)))
3514 p_names = mgr_names;
3516 /* DISPC channel specific registers */
3517 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3518 DUMPREG(i, DISPC_DEFAULT_COLOR);
3519 DUMPREG(i, DISPC_TRANS_COLOR);
3520 DUMPREG(i, DISPC_SIZE_MGR);
3522 if (i == OMAP_DSS_CHANNEL_DIGIT)
3525 DUMPREG(i, DISPC_TIMING_H);
3526 DUMPREG(i, DISPC_TIMING_V);
3527 DUMPREG(i, DISPC_POL_FREQ);
3528 DUMPREG(i, DISPC_DIVISORo);
3530 DUMPREG(i, DISPC_DATA_CYCLE1);
3531 DUMPREG(i, DISPC_DATA_CYCLE2);
3532 DUMPREG(i, DISPC_DATA_CYCLE3);
3534 if (dss_has_feature(FEAT_CPR)) {
3535 DUMPREG(i, DISPC_CPR_COEF_R);
3536 DUMPREG(i, DISPC_CPR_COEF_G);
3537 DUMPREG(i, DISPC_CPR_COEF_B);
3541 p_names = ovl_names;
3543 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3544 DUMPREG(i, DISPC_OVL_BA0);
3545 DUMPREG(i, DISPC_OVL_BA1);
3546 DUMPREG(i, DISPC_OVL_POSITION);
3547 DUMPREG(i, DISPC_OVL_SIZE);
3548 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3549 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3550 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3551 DUMPREG(i, DISPC_OVL_ROW_INC);
3552 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3554 if (dss_has_feature(FEAT_PRELOAD))
3555 DUMPREG(i, DISPC_OVL_PRELOAD);
3556 if (dss_has_feature(FEAT_MFLAG))
3557 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
3559 if (i == OMAP_DSS_GFX) {
3560 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3561 DUMPREG(i, DISPC_OVL_TABLE_BA);
3565 DUMPREG(i, DISPC_OVL_FIR);
3566 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3567 DUMPREG(i, DISPC_OVL_ACCU0);
3568 DUMPREG(i, DISPC_OVL_ACCU1);
3569 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3570 DUMPREG(i, DISPC_OVL_BA0_UV);
3571 DUMPREG(i, DISPC_OVL_BA1_UV);
3572 DUMPREG(i, DISPC_OVL_FIR2);
3573 DUMPREG(i, DISPC_OVL_ACCU2_0);
3574 DUMPREG(i, DISPC_OVL_ACCU2_1);
3576 if (dss_has_feature(FEAT_ATTR2))
3577 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3580 if (dispc.feat->has_writeback) {
3582 DUMPREG(i, DISPC_OVL_BA0);
3583 DUMPREG(i, DISPC_OVL_BA1);
3584 DUMPREG(i, DISPC_OVL_SIZE);
3585 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3586 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3587 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3588 DUMPREG(i, DISPC_OVL_ROW_INC);
3589 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3591 if (dss_has_feature(FEAT_MFLAG))
3592 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
3594 DUMPREG(i, DISPC_OVL_FIR);
3595 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3596 DUMPREG(i, DISPC_OVL_ACCU0);
3597 DUMPREG(i, DISPC_OVL_ACCU1);
3598 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3599 DUMPREG(i, DISPC_OVL_BA0_UV);
3600 DUMPREG(i, DISPC_OVL_BA1_UV);
3601 DUMPREG(i, DISPC_OVL_FIR2);
3602 DUMPREG(i, DISPC_OVL_ACCU2_0);
3603 DUMPREG(i, DISPC_OVL_ACCU2_1);
3605 if (dss_has_feature(FEAT_ATTR2))
3606 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3612 #define DISPC_REG(plane, name, i) name(plane, i)
3613 #define DUMPREG(plane, name, i) \
3614 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3615 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
3616 dispc_read_reg(DISPC_REG(plane, name, i)))
3618 /* Video pipeline coefficient registers */
3620 /* start from OMAP_DSS_VIDEO1 */
3621 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3622 for (j = 0; j < 8; j++)
3623 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
3625 for (j = 0; j < 8; j++)
3626 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
3628 for (j = 0; j < 5; j++)
3629 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
3631 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3632 for (j = 0; j < 8; j++)
3633 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3636 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3637 for (j = 0; j < 8; j++)
3638 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
3640 for (j = 0; j < 8; j++)
3641 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
3643 for (j = 0; j < 8; j++)
3644 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3648 dispc_runtime_put();
3654 /* calculate clock rates using dividers in cinfo */
3655 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3656 struct dispc_clock_info *cinfo)
3658 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3660 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3663 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3664 cinfo->pck = cinfo->lck / cinfo->pck_div;
3669 bool dispc_div_calc(unsigned long dispc,
3670 unsigned long pck_min, unsigned long pck_max,
3671 dispc_div_calc_func func, void *data)
3673 int lckd, lckd_start, lckd_stop;
3674 int pckd, pckd_start, pckd_stop;
3675 unsigned long pck, lck;
3676 unsigned long lck_max;
3677 unsigned long pckd_hw_min, pckd_hw_max;
3678 unsigned min_fck_per_pck;
3681 #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3682 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3684 min_fck_per_pck = 0;
3687 pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3688 pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3690 lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3692 pck_min = pck_min ? pck_min : 1;
3693 pck_max = pck_max ? pck_max : ULONG_MAX;
3695 lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3696 lckd_stop = min(dispc / pck_min, 255ul);
3698 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3701 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3702 pckd_stop = min(lck / pck_min, pckd_hw_max);
3704 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3708 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3709 * clock, which means we're configuring DISPC fclk here
3710 * also. Thus we need to use the calculated lck. For
3711 * OMAP4+ the DISPC fclk is a separate clock.
3713 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3714 fck = dispc_core_clk_rate();
3718 if (fck < pck * min_fck_per_pck)
3721 if (func(lckd, pckd, lck, pck, data))
3729 void dispc_mgr_set_clock_div(enum omap_channel channel,
3730 const struct dispc_clock_info *cinfo)
3732 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3733 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3735 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
3738 int dispc_mgr_get_clock_div(enum omap_channel channel,
3739 struct dispc_clock_info *cinfo)
3743 fck = dispc_fclk_rate();
3745 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3746 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
3748 cinfo->lck = fck / cinfo->lck_div;
3749 cinfo->pck = cinfo->lck / cinfo->pck_div;
3754 u32 dispc_read_irqstatus(void)
3756 return dispc_read_reg(DISPC_IRQSTATUS);
3758 EXPORT_SYMBOL(dispc_read_irqstatus);
3760 void dispc_clear_irqstatus(u32 mask)
3762 dispc_write_reg(DISPC_IRQSTATUS, mask);
3764 EXPORT_SYMBOL(dispc_clear_irqstatus);
3766 u32 dispc_read_irqenable(void)
3768 return dispc_read_reg(DISPC_IRQENABLE);
3770 EXPORT_SYMBOL(dispc_read_irqenable);
3772 void dispc_write_irqenable(u32 mask)
3774 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3776 /* clear the irqstatus for newly enabled irqs */
3777 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3779 dispc_write_reg(DISPC_IRQENABLE, mask);
3781 EXPORT_SYMBOL(dispc_write_irqenable);
3783 void dispc_enable_sidle(void)
3785 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3788 void dispc_disable_sidle(void)
3790 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3793 static void _omap_dispc_initial_config(void)
3797 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3798 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3799 l = dispc_read_reg(DISPC_DIVISOR);
3800 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3801 l = FLD_MOD(l, 1, 0, 0);
3802 l = FLD_MOD(l, 1, 23, 16);
3803 dispc_write_reg(DISPC_DIVISOR, l);
3805 dispc.core_clk_rate = dispc_fclk_rate();
3809 if (dss_has_feature(FEAT_FUNCGATED))
3810 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3812 dispc_setup_color_conv_coef();
3814 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3818 dispc_configure_burst_sizes();
3820 dispc_ovl_enable_zorder_planes();
3822 if (dispc.feat->mstandby_workaround)
3823 REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
3825 if (dss_has_feature(FEAT_MFLAG))
3829 static const struct dispc_features omap24xx_dispc_feats = {
3836 .mgr_width_start = 10,
3837 .mgr_height_start = 26,
3838 .mgr_width_max = 2048,
3839 .mgr_height_max = 2048,
3840 .max_lcd_pclk = 66500000,
3841 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3842 .calc_core_clk = calc_core_clk_24xx,
3844 .no_framedone_tv = true,
3845 .set_max_preload = false,
3846 .last_pixel_inc_missing = true,
3849 static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
3856 .mgr_width_start = 10,
3857 .mgr_height_start = 26,
3858 .mgr_width_max = 2048,
3859 .mgr_height_max = 2048,
3860 .max_lcd_pclk = 173000000,
3861 .max_tv_pclk = 59000000,
3862 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3863 .calc_core_clk = calc_core_clk_34xx,
3865 .no_framedone_tv = true,
3866 .set_max_preload = false,
3867 .last_pixel_inc_missing = true,
3870 static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
3877 .mgr_width_start = 10,
3878 .mgr_height_start = 26,
3879 .mgr_width_max = 2048,
3880 .mgr_height_max = 2048,
3881 .max_lcd_pclk = 173000000,
3882 .max_tv_pclk = 59000000,
3883 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3884 .calc_core_clk = calc_core_clk_34xx,
3886 .no_framedone_tv = true,
3887 .set_max_preload = false,
3888 .last_pixel_inc_missing = true,
3891 static const struct dispc_features omap44xx_dispc_feats = {
3898 .mgr_width_start = 10,
3899 .mgr_height_start = 26,
3900 .mgr_width_max = 2048,
3901 .mgr_height_max = 2048,
3902 .max_lcd_pclk = 170000000,
3903 .max_tv_pclk = 185625000,
3904 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3905 .calc_core_clk = calc_core_clk_44xx,
3907 .gfx_fifo_workaround = true,
3908 .set_max_preload = true,
3909 .supports_sync_align = true,
3910 .has_writeback = true,
3911 .supports_double_pixel = true,
3912 .reverse_ilace_field_order = true,
3915 static const struct dispc_features omap54xx_dispc_feats = {
3922 .mgr_width_start = 11,
3923 .mgr_height_start = 27,
3924 .mgr_width_max = 4096,
3925 .mgr_height_max = 4096,
3926 .max_lcd_pclk = 170000000,
3927 .max_tv_pclk = 186000000,
3928 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3929 .calc_core_clk = calc_core_clk_44xx,
3931 .gfx_fifo_workaround = true,
3932 .mstandby_workaround = true,
3933 .set_max_preload = true,
3934 .supports_sync_align = true,
3935 .has_writeback = true,
3936 .supports_double_pixel = true,
3937 .reverse_ilace_field_order = true,
3940 static int dispc_init_features(struct platform_device *pdev)
3942 const struct dispc_features *src;
3943 struct dispc_features *dst;
3945 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
3947 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
3951 switch (omapdss_get_version()) {
3952 case OMAPDSS_VER_OMAP24xx:
3953 src = &omap24xx_dispc_feats;
3956 case OMAPDSS_VER_OMAP34xx_ES1:
3957 src = &omap34xx_rev1_0_dispc_feats;
3960 case OMAPDSS_VER_OMAP34xx_ES3:
3961 case OMAPDSS_VER_OMAP3630:
3962 case OMAPDSS_VER_AM35xx:
3963 case OMAPDSS_VER_AM43xx:
3964 src = &omap34xx_rev3_0_dispc_feats;
3967 case OMAPDSS_VER_OMAP4430_ES1:
3968 case OMAPDSS_VER_OMAP4430_ES2:
3969 case OMAPDSS_VER_OMAP4:
3970 src = &omap44xx_dispc_feats;
3973 case OMAPDSS_VER_OMAP5:
3974 case OMAPDSS_VER_DRA7xx:
3975 src = &omap54xx_dispc_feats;
3982 memcpy(dst, src, sizeof(*dst));
3988 static irqreturn_t dispc_irq_handler(int irq, void *arg)
3990 if (!dispc.is_enabled)
3993 return dispc.user_handler(irq, dispc.user_data);
3996 int dispc_request_irq(irq_handler_t handler, void *dev_id)
4000 if (dispc.user_handler != NULL)
4003 dispc.user_handler = handler;
4004 dispc.user_data = dev_id;
4006 /* ensure the dispc_irq_handler sees the values above */
4009 r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
4010 IRQF_SHARED, "OMAP DISPC", &dispc);
4012 dispc.user_handler = NULL;
4013 dispc.user_data = NULL;
4018 EXPORT_SYMBOL(dispc_request_irq);
4020 void dispc_free_irq(void *dev_id)
4022 devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
4024 dispc.user_handler = NULL;
4025 dispc.user_data = NULL;
4027 EXPORT_SYMBOL(dispc_free_irq);
4029 /* DISPC HW IP initialisation */
4030 static int dispc_bind(struct device *dev, struct device *master, void *data)
4032 struct platform_device *pdev = to_platform_device(dev);
4035 struct resource *dispc_mem;
4036 struct device_node *np = pdev->dev.of_node;
4040 spin_lock_init(&dispc.control_lock);
4042 r = dispc_init_features(dispc.pdev);
4046 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
4048 DSSERR("can't get IORESOURCE_MEM DISPC\n");
4052 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
4053 resource_size(dispc_mem));
4055 DSSERR("can't ioremap DISPC\n");
4059 dispc.irq = platform_get_irq(dispc.pdev, 0);
4060 if (dispc.irq < 0) {
4061 DSSERR("platform_get_irq failed\n");
4065 if (np && of_property_read_bool(np, "syscon-pol")) {
4066 dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
4067 if (IS_ERR(dispc.syscon_pol)) {
4068 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
4069 return PTR_ERR(dispc.syscon_pol);
4072 if (of_property_read_u32_index(np, "syscon-pol", 1,
4073 &dispc.syscon_pol_offset)) {
4074 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
4079 pm_runtime_enable(&pdev->dev);
4081 r = dispc_runtime_get();
4083 goto err_runtime_get;
4085 _omap_dispc_initial_config();
4087 rev = dispc_read_reg(DISPC_REVISION);
4088 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
4089 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4091 dispc_runtime_put();
4093 dss_debugfs_create_file("dispc", dispc_dump_regs);
4098 pm_runtime_disable(&pdev->dev);
4102 static void dispc_unbind(struct device *dev, struct device *master,
4105 pm_runtime_disable(dev);
4108 static const struct component_ops dispc_component_ops = {
4110 .unbind = dispc_unbind,
4113 static int dispc_probe(struct platform_device *pdev)
4115 return component_add(&pdev->dev, &dispc_component_ops);
4118 static int dispc_remove(struct platform_device *pdev)
4120 component_del(&pdev->dev, &dispc_component_ops);
4124 static int dispc_runtime_suspend(struct device *dev)
4126 dispc.is_enabled = false;
4127 /* ensure the dispc_irq_handler sees the is_enabled value */
4129 /* wait for current handler to finish before turning the DISPC off */
4130 synchronize_irq(dispc.irq);
4132 dispc_save_context();
4137 static int dispc_runtime_resume(struct device *dev)
4140 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4141 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4142 * _omap_dispc_initial_config(). We can thus use it to detect if
4143 * we have lost register context.
4145 if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4146 _omap_dispc_initial_config();
4148 dispc_restore_context();
4151 dispc.is_enabled = true;
4152 /* ensure the dispc_irq_handler sees the is_enabled value */
4158 static const struct dev_pm_ops dispc_pm_ops = {
4159 .runtime_suspend = dispc_runtime_suspend,
4160 .runtime_resume = dispc_runtime_resume,
4163 static const struct of_device_id dispc_of_match[] = {
4164 { .compatible = "ti,omap2-dispc", },
4165 { .compatible = "ti,omap3-dispc", },
4166 { .compatible = "ti,omap4-dispc", },
4167 { .compatible = "ti,omap5-dispc", },
4168 { .compatible = "ti,dra7-dispc", },
4172 static struct platform_driver omap_dispchw_driver = {
4173 .probe = dispc_probe,
4174 .remove = dispc_remove,
4176 .name = "omapdss_dispc",
4177 .pm = &dispc_pm_ops,
4178 .of_match_table = dispc_of_match,
4179 .suppress_bind_attrs = true,
4183 int __init dispc_init_platform_driver(void)
4185 return platform_driver_register(&omap_dispchw_driver);
4188 void dispc_uninit_platform_driver(void)
4190 platform_driver_unregister(&omap_dispchw_driver);