1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/video/omap2/dss/dispc.c
5 * Copyright (C) 2009 Nokia Corporation
6 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
8 * Some code and ideas taken from drivers/video/omap/ driver
12 #define DSS_SUBSYS_NAME "DISPC"
14 #include <linux/kernel.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/vmalloc.h>
17 #include <linux/export.h>
18 #include <linux/clk.h>
20 #include <linux/jiffies.h>
21 #include <linux/seq_file.h>
22 #include <linux/delay.h>
23 #include <linux/workqueue.h>
24 #include <linux/hardirq.h>
25 #include <linux/platform_device.h>
26 #include <linux/pm_runtime.h>
27 #include <linux/sizes.h>
28 #include <linux/mfd/syscon.h>
29 #include <linux/regmap.h>
31 #include <linux/component.h>
33 #include <video/omapfb_dss.h>
36 #include "dss_features.h"
40 #define DISPC_SZ_REGS SZ_4K
42 enum omap_burst_size {
48 #define REG_GET(idx, start, end) \
49 FLD_GET(dispc_read_reg(idx), start, end)
51 #define REG_FLD_MOD(idx, val, start, end) \
52 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
54 struct dispc_features {
65 unsigned long max_lcd_pclk;
66 unsigned long max_tv_pclk;
67 int (*calc_scaling) (unsigned long pclk, unsigned long lclk,
68 const struct omap_video_timings *mgr_timings,
69 u16 width, u16 height, u16 out_width, u16 out_height,
70 enum omap_color_mode color_mode, bool *five_taps,
71 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
72 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
73 unsigned long (*calc_core_clk) (unsigned long pclk,
74 u16 width, u16 height, u16 out_width, u16 out_height,
78 /* swap GFX & WB fifos */
79 bool gfx_fifo_workaround:1;
81 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
82 bool no_framedone_tv:1;
84 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
85 bool mstandby_workaround:1;
87 bool set_max_preload:1;
89 /* PIXEL_INC is not added to the last pixel of a line */
90 bool last_pixel_inc_missing:1;
92 /* POL_FREQ has ALIGN bit */
93 bool supports_sync_align:1;
98 #define DISPC_MAX_NR_FIFOS 5
101 struct platform_device *pdev;
105 irq_handler_t user_handler;
108 unsigned long core_clk_rate;
109 unsigned long tv_pclk_rate;
111 u32 fifo_size[DISPC_MAX_NR_FIFOS];
112 /* maps which plane is using a fifo. fifo-id -> plane-id */
113 int fifo_assignment[DISPC_MAX_NR_FIFOS];
116 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
118 const struct dispc_features *feat;
122 struct regmap *syscon_pol;
123 u32 syscon_pol_offset;
125 /* DISPC_CONTROL & DISPC_CONFIG lock*/
126 spinlock_t control_lock;
129 enum omap_color_component {
130 /* used for all color formats for OMAP3 and earlier
131 * and for RGB and Y color component on OMAP4
133 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
134 /* used for UV component for
135 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
136 * color formats on OMAP4
138 DISPC_COLOR_COMPONENT_UV = 1 << 1,
141 enum mgr_reg_fields {
142 DISPC_MGR_FLD_ENABLE,
143 DISPC_MGR_FLD_STNTFT,
145 DISPC_MGR_FLD_TFTDATALINES,
146 DISPC_MGR_FLD_STALLMODE,
147 DISPC_MGR_FLD_TCKENABLE,
148 DISPC_MGR_FLD_TCKSELECTION,
150 DISPC_MGR_FLD_FIFOHANDCHECK,
151 /* used to maintain a count of the above fields */
155 struct dispc_reg_field {
161 static const struct {
166 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
168 [OMAP_DSS_CHANNEL_LCD] = {
170 .vsync_irq = DISPC_IRQ_VSYNC,
171 .framedone_irq = DISPC_IRQ_FRAMEDONE,
172 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
174 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
175 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
176 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
177 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
178 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
179 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
180 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
181 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
182 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
185 [OMAP_DSS_CHANNEL_DIGIT] = {
187 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
188 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
189 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
191 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
192 [DISPC_MGR_FLD_STNTFT] = { },
193 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
194 [DISPC_MGR_FLD_TFTDATALINES] = { },
195 [DISPC_MGR_FLD_STALLMODE] = { },
196 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
197 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
198 [DISPC_MGR_FLD_CPR] = { },
199 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
202 [OMAP_DSS_CHANNEL_LCD2] = {
204 .vsync_irq = DISPC_IRQ_VSYNC2,
205 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
206 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
208 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
209 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
210 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
211 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
212 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
213 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
214 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
215 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
216 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
219 [OMAP_DSS_CHANNEL_LCD3] = {
221 .vsync_irq = DISPC_IRQ_VSYNC3,
222 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
223 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
225 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
226 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
227 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
228 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
229 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
230 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
231 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
232 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
233 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
238 struct color_conv_coef {
239 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
243 static unsigned long dispc_fclk_rate(void);
244 static unsigned long dispc_core_clk_rate(void);
245 static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel);
246 static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel);
248 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
249 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
251 static inline void dispc_write_reg(const u16 idx, u32 val)
253 __raw_writel(val, dispc.base + idx);
256 static inline u32 dispc_read_reg(const u16 idx)
258 return __raw_readl(dispc.base + idx);
261 static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
263 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
264 return REG_GET(rfld.reg, rfld.high, rfld.low);
267 static void mgr_fld_write(enum omap_channel channel,
268 enum mgr_reg_fields regfld, int val) {
269 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
270 const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
274 spin_lock_irqsave(&dispc.control_lock, flags);
276 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
279 spin_unlock_irqrestore(&dispc.control_lock, flags);
283 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
285 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
287 static void dispc_save_context(void)
291 DSSDBG("dispc_save_context\n");
297 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
298 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
300 if (dss_has_feature(FEAT_MGR_LCD2)) {
304 if (dss_has_feature(FEAT_MGR_LCD3)) {
309 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
310 SR(DEFAULT_COLOR(i));
313 if (i == OMAP_DSS_CHANNEL_DIGIT)
324 if (dss_has_feature(FEAT_CPR)) {
331 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
336 SR(OVL_ATTRIBUTES(i));
337 SR(OVL_FIFO_THRESHOLD(i));
339 SR(OVL_PIXEL_INC(i));
340 if (dss_has_feature(FEAT_PRELOAD))
342 if (i == OMAP_DSS_GFX) {
343 SR(OVL_WINDOW_SKIP(i));
348 SR(OVL_PICTURE_SIZE(i));
352 for (j = 0; j < 8; j++)
353 SR(OVL_FIR_COEF_H(i, j));
355 for (j = 0; j < 8; j++)
356 SR(OVL_FIR_COEF_HV(i, j));
358 for (j = 0; j < 5; j++)
359 SR(OVL_CONV_COEF(i, j));
361 if (dss_has_feature(FEAT_FIR_COEF_V)) {
362 for (j = 0; j < 8; j++)
363 SR(OVL_FIR_COEF_V(i, j));
366 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
373 for (j = 0; j < 8; j++)
374 SR(OVL_FIR_COEF_H2(i, j));
376 for (j = 0; j < 8; j++)
377 SR(OVL_FIR_COEF_HV2(i, j));
379 for (j = 0; j < 8; j++)
380 SR(OVL_FIR_COEF_V2(i, j));
382 if (dss_has_feature(FEAT_ATTR2))
383 SR(OVL_ATTRIBUTES2(i));
386 if (dss_has_feature(FEAT_CORE_CLK_DIV))
389 dispc.ctx_valid = true;
391 DSSDBG("context saved\n");
394 static void dispc_restore_context(void)
398 DSSDBG("dispc_restore_context\n");
400 if (!dispc.ctx_valid)
407 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
408 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
410 if (dss_has_feature(FEAT_MGR_LCD2))
412 if (dss_has_feature(FEAT_MGR_LCD3))
415 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
416 RR(DEFAULT_COLOR(i));
419 if (i == OMAP_DSS_CHANNEL_DIGIT)
430 if (dss_has_feature(FEAT_CPR)) {
437 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
442 RR(OVL_ATTRIBUTES(i));
443 RR(OVL_FIFO_THRESHOLD(i));
445 RR(OVL_PIXEL_INC(i));
446 if (dss_has_feature(FEAT_PRELOAD))
448 if (i == OMAP_DSS_GFX) {
449 RR(OVL_WINDOW_SKIP(i));
454 RR(OVL_PICTURE_SIZE(i));
458 for (j = 0; j < 8; j++)
459 RR(OVL_FIR_COEF_H(i, j));
461 for (j = 0; j < 8; j++)
462 RR(OVL_FIR_COEF_HV(i, j));
464 for (j = 0; j < 5; j++)
465 RR(OVL_CONV_COEF(i, j));
467 if (dss_has_feature(FEAT_FIR_COEF_V)) {
468 for (j = 0; j < 8; j++)
469 RR(OVL_FIR_COEF_V(i, j));
472 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
479 for (j = 0; j < 8; j++)
480 RR(OVL_FIR_COEF_H2(i, j));
482 for (j = 0; j < 8; j++)
483 RR(OVL_FIR_COEF_HV2(i, j));
485 for (j = 0; j < 8; j++)
486 RR(OVL_FIR_COEF_V2(i, j));
488 if (dss_has_feature(FEAT_ATTR2))
489 RR(OVL_ATTRIBUTES2(i));
492 if (dss_has_feature(FEAT_CORE_CLK_DIV))
495 /* enable last, because LCD & DIGIT enable are here */
497 if (dss_has_feature(FEAT_MGR_LCD2))
499 if (dss_has_feature(FEAT_MGR_LCD3))
501 /* clear spurious SYNC_LOST_DIGIT interrupts */
502 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
505 * enable last so IRQs won't trigger before
506 * the context is fully restored
510 DSSDBG("context restored\n");
516 int dispc_runtime_get(void)
520 DSSDBG("dispc_runtime_get\n");
522 r = pm_runtime_get_sync(&dispc.pdev->dev);
524 return r < 0 ? r : 0;
526 EXPORT_SYMBOL(dispc_runtime_get);
528 void dispc_runtime_put(void)
532 DSSDBG("dispc_runtime_put\n");
534 r = pm_runtime_put_sync(&dispc.pdev->dev);
535 WARN_ON(r < 0 && r != -ENOSYS);
537 EXPORT_SYMBOL(dispc_runtime_put);
539 u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
541 return mgr_desc[channel].vsync_irq;
543 EXPORT_SYMBOL(dispc_mgr_get_vsync_irq);
545 u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
547 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
550 return mgr_desc[channel].framedone_irq;
552 EXPORT_SYMBOL(dispc_mgr_get_framedone_irq);
554 u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
556 return mgr_desc[channel].sync_lost_irq;
558 EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq);
560 u32 dispc_wb_get_framedone_irq(void)
562 return DISPC_IRQ_FRAMEDONEWB;
565 bool dispc_mgr_go_busy(enum omap_channel channel)
567 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
569 EXPORT_SYMBOL(dispc_mgr_go_busy);
571 void dispc_mgr_go(enum omap_channel channel)
573 WARN_ON(!dispc_mgr_is_enabled(channel));
574 WARN_ON(dispc_mgr_go_busy(channel));
576 DSSDBG("GO %s\n", mgr_desc[channel].name);
578 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
580 EXPORT_SYMBOL(dispc_mgr_go);
582 bool dispc_wb_go_busy(void)
584 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
587 void dispc_wb_go(void)
589 enum omap_plane plane = OMAP_DSS_WB;
592 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
597 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
599 DSSERR("GO bit not down for WB\n");
603 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
606 static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
608 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
611 static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
613 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
616 static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
618 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
621 static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
623 BUG_ON(plane == OMAP_DSS_GFX);
625 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
628 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
631 BUG_ON(plane == OMAP_DSS_GFX);
633 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
636 static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
638 BUG_ON(plane == OMAP_DSS_GFX);
640 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
643 static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
644 int fir_vinc, int five_taps,
645 enum omap_color_component color_comp)
647 const struct dispc_coef *h_coef, *v_coef;
650 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
651 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
653 for (i = 0; i < 8; i++) {
656 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
657 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
658 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
659 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
660 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
661 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
662 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
663 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
665 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
666 dispc_ovl_write_firh_reg(plane, i, h);
667 dispc_ovl_write_firhv_reg(plane, i, hv);
669 dispc_ovl_write_firh2_reg(plane, i, h);
670 dispc_ovl_write_firhv2_reg(plane, i, hv);
676 for (i = 0; i < 8; i++) {
678 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
679 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
680 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
681 dispc_ovl_write_firv_reg(plane, i, v);
683 dispc_ovl_write_firv2_reg(plane, i, v);
689 static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
690 const struct color_conv_coef *ct)
692 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
694 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
695 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
696 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
697 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
698 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
700 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
705 static void dispc_setup_color_conv_coef(void)
708 int num_ovl = dss_feat_get_num_ovls();
709 const struct color_conv_coef ctbl_bt601_5_ovl = {
711 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
713 const struct color_conv_coef ctbl_bt601_5_wb = {
715 66, 129, 25, 112, -94, -18, -38, -74, 112, 0,
718 for (i = 1; i < num_ovl; i++)
719 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
721 if (dispc.feat->has_writeback)
722 dispc_ovl_write_color_conv_coef(OMAP_DSS_WB, &ctbl_bt601_5_wb);
725 static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
727 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
730 static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
732 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
735 static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
737 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
740 static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
742 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
745 static void dispc_ovl_set_pos(enum omap_plane plane,
746 enum omap_overlay_caps caps, int x, int y)
750 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
753 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
755 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
758 static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
761 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
763 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
764 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
766 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
769 static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
774 BUG_ON(plane == OMAP_DSS_GFX);
776 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
778 if (plane == OMAP_DSS_WB)
779 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
781 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
784 static void dispc_ovl_set_zorder(enum omap_plane plane,
785 enum omap_overlay_caps caps, u8 zorder)
787 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
790 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
793 static void dispc_ovl_enable_zorder_planes(void)
797 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
800 for (i = 0; i < dss_feat_get_num_ovls(); i++)
801 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
804 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
805 enum omap_overlay_caps caps, bool enable)
807 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
810 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
813 static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
814 enum omap_overlay_caps caps, u8 global_alpha)
816 static const unsigned shifts[] = { 0, 8, 16, 24, };
819 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
822 shift = shifts[plane];
823 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
826 static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
828 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
831 static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
833 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
836 static void dispc_ovl_set_color_mode(enum omap_plane plane,
837 enum omap_color_mode color_mode)
840 if (plane != OMAP_DSS_GFX) {
841 switch (color_mode) {
842 case OMAP_DSS_COLOR_NV12:
844 case OMAP_DSS_COLOR_RGBX16:
846 case OMAP_DSS_COLOR_RGBA16:
848 case OMAP_DSS_COLOR_RGB12U:
850 case OMAP_DSS_COLOR_ARGB16:
852 case OMAP_DSS_COLOR_RGB16:
854 case OMAP_DSS_COLOR_ARGB16_1555:
856 case OMAP_DSS_COLOR_RGB24U:
858 case OMAP_DSS_COLOR_RGB24P:
860 case OMAP_DSS_COLOR_YUV2:
862 case OMAP_DSS_COLOR_UYVY:
864 case OMAP_DSS_COLOR_ARGB32:
866 case OMAP_DSS_COLOR_RGBA32:
868 case OMAP_DSS_COLOR_RGBX32:
870 case OMAP_DSS_COLOR_XRGB16_1555:
876 switch (color_mode) {
877 case OMAP_DSS_COLOR_CLUT1:
879 case OMAP_DSS_COLOR_CLUT2:
881 case OMAP_DSS_COLOR_CLUT4:
883 case OMAP_DSS_COLOR_CLUT8:
885 case OMAP_DSS_COLOR_RGB12U:
887 case OMAP_DSS_COLOR_ARGB16:
889 case OMAP_DSS_COLOR_RGB16:
891 case OMAP_DSS_COLOR_ARGB16_1555:
893 case OMAP_DSS_COLOR_RGB24U:
895 case OMAP_DSS_COLOR_RGB24P:
897 case OMAP_DSS_COLOR_RGBX16:
899 case OMAP_DSS_COLOR_RGBA16:
901 case OMAP_DSS_COLOR_ARGB32:
903 case OMAP_DSS_COLOR_RGBA32:
905 case OMAP_DSS_COLOR_RGBX32:
907 case OMAP_DSS_COLOR_XRGB16_1555:
914 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
917 static void dispc_ovl_configure_burst_type(enum omap_plane plane,
918 enum omap_dss_rotation_type rotation_type)
920 if (dss_has_feature(FEAT_BURST_2D) == 0)
923 if (rotation_type == OMAP_DSS_ROT_TILER)
924 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
926 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
929 void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
933 int chan = 0, chan2 = 0;
939 case OMAP_DSS_VIDEO1:
940 case OMAP_DSS_VIDEO2:
941 case OMAP_DSS_VIDEO3:
949 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
950 if (dss_has_feature(FEAT_MGR_LCD2)) {
952 case OMAP_DSS_CHANNEL_LCD:
956 case OMAP_DSS_CHANNEL_DIGIT:
960 case OMAP_DSS_CHANNEL_LCD2:
964 case OMAP_DSS_CHANNEL_LCD3:
965 if (dss_has_feature(FEAT_MGR_LCD3)) {
973 case OMAP_DSS_CHANNEL_WB:
982 val = FLD_MOD(val, chan, shift, shift);
983 val = FLD_MOD(val, chan2, 31, 30);
985 val = FLD_MOD(val, channel, shift, shift);
987 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
989 EXPORT_SYMBOL(dispc_ovl_set_channel_out);
991 static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
1000 case OMAP_DSS_VIDEO1:
1001 case OMAP_DSS_VIDEO2:
1002 case OMAP_DSS_VIDEO3:
1010 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1012 if (FLD_GET(val, shift, shift) == 1)
1013 return OMAP_DSS_CHANNEL_DIGIT;
1015 if (!dss_has_feature(FEAT_MGR_LCD2))
1016 return OMAP_DSS_CHANNEL_LCD;
1018 switch (FLD_GET(val, 31, 30)) {
1021 return OMAP_DSS_CHANNEL_LCD;
1023 return OMAP_DSS_CHANNEL_LCD2;
1025 return OMAP_DSS_CHANNEL_LCD3;
1027 return OMAP_DSS_CHANNEL_WB;
1031 void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1033 enum omap_plane plane = OMAP_DSS_WB;
1035 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1038 static void dispc_ovl_set_burst_size(enum omap_plane plane,
1039 enum omap_burst_size burst_size)
1041 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
1044 shift = shifts[plane];
1045 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
1048 static void dispc_configure_burst_sizes(void)
1051 const int burst_size = BURST_SIZE_X8;
1053 /* Configure burst size always to maximum size */
1054 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
1055 dispc_ovl_set_burst_size(i, burst_size);
1056 if (dispc.feat->has_writeback)
1057 dispc_ovl_set_burst_size(OMAP_DSS_WB, burst_size);
1060 static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
1062 unsigned unit = dss_feat_get_burst_size_unit();
1063 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1067 void dispc_enable_gamma_table(bool enable)
1070 * This is partially implemented to support only disabling of
1074 DSSWARN("Gamma table enabling for TV not yet supported");
1078 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1081 static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
1083 if (channel == OMAP_DSS_CHANNEL_DIGIT)
1086 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
1089 static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
1090 const struct omap_dss_cpr_coefs *coefs)
1092 u32 coef_r, coef_g, coef_b;
1094 if (!dss_mgr_is_lcd(channel))
1097 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1098 FLD_VAL(coefs->rb, 9, 0);
1099 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1100 FLD_VAL(coefs->gb, 9, 0);
1101 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1102 FLD_VAL(coefs->bb, 9, 0);
1104 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1105 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1106 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1109 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
1113 BUG_ON(plane == OMAP_DSS_GFX);
1115 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1116 val = FLD_MOD(val, enable, 9, 9);
1117 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
1120 static void dispc_ovl_enable_replication(enum omap_plane plane,
1121 enum omap_overlay_caps caps, bool enable)
1123 static const unsigned shifts[] = { 5, 10, 10, 10 };
1126 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1129 shift = shifts[plane];
1130 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
1133 static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
1138 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1139 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1141 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
1144 static void dispc_init_fifos(void)
1152 unit = dss_feat_get_buffer_size_unit();
1154 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1156 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1157 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
1159 dispc.fifo_size[fifo] = size;
1162 * By default fifos are mapped directly to overlays, fifo 0 to
1163 * ovl 0, fifo 1 to ovl 1, etc.
1165 dispc.fifo_assignment[fifo] = fifo;
1169 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1170 * causes problems with certain use cases, like using the tiler in 2D
1171 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1172 * giving GFX plane a larger fifo. WB but should work fine with a
1175 if (dispc.feat->gfx_fifo_workaround) {
1178 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1180 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1181 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1182 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1183 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1185 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1187 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1188 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1192 * Setup default fifo thresholds.
1194 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1196 const bool use_fifomerge = false;
1197 const bool manual_update = false;
1199 dispc_ovl_compute_fifo_thresholds(i, &low, &high,
1200 use_fifomerge, manual_update);
1202 dispc_ovl_set_fifo_threshold(i, low, high);
1205 if (dispc.feat->has_writeback) {
1207 const bool use_fifomerge = false;
1208 const bool manual_update = false;
1210 dispc_ovl_compute_fifo_thresholds(OMAP_DSS_WB, &low, &high,
1211 use_fifomerge, manual_update);
1213 dispc_ovl_set_fifo_threshold(OMAP_DSS_WB, low, high);
1217 static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1222 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1223 if (dispc.fifo_assignment[fifo] == plane)
1224 size += dispc.fifo_size[fifo];
1230 void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
1232 u8 hi_start, hi_end, lo_start, lo_end;
1235 unit = dss_feat_get_buffer_size_unit();
1237 WARN_ON(low % unit != 0);
1238 WARN_ON(high % unit != 0);
1243 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1244 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1246 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1248 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1249 lo_start, lo_end) * unit,
1250 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1251 hi_start, hi_end) * unit,
1252 low * unit, high * unit);
1254 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1255 FLD_VAL(high, hi_start, hi_end) |
1256 FLD_VAL(low, lo_start, lo_end));
1259 * configure the preload to the pipeline's high threhold, if HT it's too
1260 * large for the preload field, set the threshold to the maximum value
1261 * that can be held by the preload register
1263 if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1264 plane != OMAP_DSS_WB)
1265 dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
1268 void dispc_enable_fifomerge(bool enable)
1270 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1275 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1276 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1279 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1280 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1284 * All sizes are in bytes. Both the buffer and burst are made of
1285 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1288 unsigned buf_unit = dss_feat_get_buffer_size_unit();
1289 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1292 burst_size = dispc_ovl_get_burst_size(plane);
1293 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
1295 if (use_fifomerge) {
1296 total_fifo_size = 0;
1297 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
1298 total_fifo_size += dispc_ovl_get_fifo_size(i);
1300 total_fifo_size = ovl_fifo_size;
1304 * We use the same low threshold for both fifomerge and non-fifomerge
1305 * cases, but for fifomerge we calculate the high threshold using the
1306 * combined fifo size
1309 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1310 *fifo_low = ovl_fifo_size - burst_size * 2;
1311 *fifo_high = total_fifo_size - burst_size;
1312 } else if (plane == OMAP_DSS_WB) {
1314 * Most optimal configuration for writeback is to push out data
1315 * to the interconnect the moment writeback pushes enough pixels
1316 * in the FIFO to form a burst
1319 *fifo_high = burst_size;
1321 *fifo_low = ovl_fifo_size - burst_size;
1322 *fifo_high = total_fifo_size - buf_unit;
1326 static void dispc_ovl_set_mflag(enum omap_plane plane, bool enable)
1330 if (plane == OMAP_DSS_GFX)
1335 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1338 static void dispc_ovl_set_mflag_threshold(enum omap_plane plane,
1341 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane),
1342 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1345 static void dispc_init_mflag(void)
1350 * HACK: NV12 color format and MFLAG seem to have problems working
1351 * together: using two displays, and having an NV12 overlay on one of
1352 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1353 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1354 * remove the errors, but there doesn't seem to be a clear logic on
1355 * which values work and which not.
1357 * As a work-around, set force MFLAG to always on.
1359 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE,
1360 (1 << 0) | /* MFLAG_CTRL = force always on */
1361 (0 << 2)); /* MFLAG_START = disable */
1363 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1364 u32 size = dispc_ovl_get_fifo_size(i);
1365 u32 unit = dss_feat_get_buffer_size_unit();
1368 dispc_ovl_set_mflag(i, true);
1371 * Simulation team suggests below thesholds:
1372 * HT = fifosize * 5 / 8;
1373 * LT = fifosize * 4 / 8;
1376 low = size * 4 / 8 / unit;
1377 high = size * 5 / 8 / unit;
1379 dispc_ovl_set_mflag_threshold(i, low, high);
1382 if (dispc.feat->has_writeback) {
1383 u32 size = dispc_ovl_get_fifo_size(OMAP_DSS_WB);
1384 u32 unit = dss_feat_get_buffer_size_unit();
1387 dispc_ovl_set_mflag(OMAP_DSS_WB, 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(OMAP_DSS_WB, low, high);
1402 static void dispc_ovl_set_fir(enum omap_plane plane,
1404 enum omap_color_component color_comp)
1408 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1409 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1411 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1412 &hinc_start, &hinc_end);
1413 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1414 &vinc_start, &vinc_end);
1415 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1416 FLD_VAL(hinc, hinc_start, hinc_end);
1418 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1420 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1421 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1425 static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1428 u8 hor_start, hor_end, vert_start, vert_end;
1430 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1431 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1433 val = FLD_VAL(vaccu, vert_start, vert_end) |
1434 FLD_VAL(haccu, hor_start, hor_end);
1436 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1439 static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1442 u8 hor_start, hor_end, vert_start, vert_end;
1444 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1445 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1447 val = FLD_VAL(vaccu, vert_start, vert_end) |
1448 FLD_VAL(haccu, hor_start, hor_end);
1450 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1453 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1458 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1459 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1462 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1467 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1468 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1471 static void dispc_ovl_set_scale_param(enum omap_plane plane,
1472 u16 orig_width, u16 orig_height,
1473 u16 out_width, u16 out_height,
1474 bool five_taps, u8 rotation,
1475 enum omap_color_component color_comp)
1477 int fir_hinc, fir_vinc;
1479 fir_hinc = 1024 * orig_width / out_width;
1480 fir_vinc = 1024 * orig_height / out_height;
1482 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1484 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1487 static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1488 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1489 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1491 int h_accu2_0, h_accu2_1;
1492 int v_accu2_0, v_accu2_1;
1493 int chroma_hinc, chroma_vinc;
1503 const struct accu *accu_table;
1504 const struct accu *accu_val;
1506 static const struct accu accu_nv12[4] = {
1507 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1508 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1509 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1510 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1513 static const struct accu accu_nv12_ilace[4] = {
1514 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1515 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1516 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1517 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1520 static const struct accu accu_yuv[4] = {
1521 { 0, 1, 0, 1, 0, 1, 0, 1 },
1522 { 0, 1, 0, 1, 0, 1, 0, 1 },
1523 { -1, 1, 0, 1, 0, 1, 0, 1 },
1524 { 0, 1, 0, 1, -1, 1, 0, 1 },
1528 case OMAP_DSS_ROT_0:
1531 case OMAP_DSS_ROT_90:
1534 case OMAP_DSS_ROT_180:
1537 case OMAP_DSS_ROT_270:
1545 switch (color_mode) {
1546 case OMAP_DSS_COLOR_NV12:
1548 accu_table = accu_nv12_ilace;
1550 accu_table = accu_nv12;
1552 case OMAP_DSS_COLOR_YUV2:
1553 case OMAP_DSS_COLOR_UYVY:
1554 accu_table = accu_yuv;
1561 accu_val = &accu_table[idx];
1563 chroma_hinc = 1024 * orig_width / out_width;
1564 chroma_vinc = 1024 * orig_height / out_height;
1566 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1567 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1568 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1569 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1571 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1572 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1575 static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1576 u16 orig_width, u16 orig_height,
1577 u16 out_width, u16 out_height,
1578 bool ilace, bool five_taps,
1579 bool fieldmode, enum omap_color_mode color_mode,
1586 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1587 out_width, out_height, five_taps,
1588 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1589 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1591 /* RESIZEENABLE and VERTICALTAPS */
1592 l &= ~((0x3 << 5) | (0x1 << 21));
1593 l |= (orig_width != out_width) ? (1 << 5) : 0;
1594 l |= (orig_height != out_height) ? (1 << 6) : 0;
1595 l |= five_taps ? (1 << 21) : 0;
1597 /* VRESIZECONF and HRESIZECONF */
1598 if (dss_has_feature(FEAT_RESIZECONF)) {
1600 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1601 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1604 /* LINEBUFFERSPLIT */
1605 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1607 l |= five_taps ? (1 << 22) : 0;
1610 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1613 * field 0 = even field = bottom field
1614 * field 1 = odd field = top field
1616 if (ilace && !fieldmode) {
1618 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1619 if (accu0 >= 1024/2) {
1625 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1626 dispc_ovl_set_vid_accu1(plane, 0, accu1);
1629 static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1630 u16 orig_width, u16 orig_height,
1631 u16 out_width, u16 out_height,
1632 bool ilace, bool five_taps,
1633 bool fieldmode, enum omap_color_mode color_mode,
1636 int scale_x = out_width != orig_width;
1637 int scale_y = out_height != orig_height;
1638 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
1640 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1642 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1643 color_mode != OMAP_DSS_COLOR_UYVY &&
1644 color_mode != OMAP_DSS_COLOR_NV12)) {
1645 /* reset chroma resampling for RGB formats */
1646 if (plane != OMAP_DSS_WB)
1647 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1651 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1652 out_height, ilace, color_mode, rotation);
1654 switch (color_mode) {
1655 case OMAP_DSS_COLOR_NV12:
1656 if (chroma_upscale) {
1657 /* UV is subsampled by 2 horizontally and vertically */
1661 /* UV is downsampled by 2 horizontally and vertically */
1667 case OMAP_DSS_COLOR_YUV2:
1668 case OMAP_DSS_COLOR_UYVY:
1669 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
1670 if (rotation == OMAP_DSS_ROT_0 ||
1671 rotation == OMAP_DSS_ROT_180) {
1673 /* UV is subsampled by 2 horizontally */
1676 /* UV is downsampled by 2 horizontally */
1680 /* must use FIR for YUV422 if rotated */
1681 if (rotation != OMAP_DSS_ROT_0)
1682 scale_x = scale_y = true;
1690 if (out_width != orig_width)
1692 if (out_height != orig_height)
1695 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1696 out_width, out_height, five_taps,
1697 rotation, DISPC_COLOR_COMPONENT_UV);
1699 if (plane != OMAP_DSS_WB)
1700 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1701 (scale_x || scale_y) ? 1 : 0, 8, 8);
1704 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1706 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1709 static void dispc_ovl_set_scaling(enum omap_plane plane,
1710 u16 orig_width, u16 orig_height,
1711 u16 out_width, u16 out_height,
1712 bool ilace, bool five_taps,
1713 bool fieldmode, enum omap_color_mode color_mode,
1716 BUG_ON(plane == OMAP_DSS_GFX);
1718 dispc_ovl_set_scaling_common(plane,
1719 orig_width, orig_height,
1720 out_width, out_height,
1722 fieldmode, color_mode,
1725 dispc_ovl_set_scaling_uv(plane,
1726 orig_width, orig_height,
1727 out_width, out_height,
1729 fieldmode, color_mode,
1733 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1734 enum omap_dss_rotation_type rotation_type,
1735 bool mirroring, enum omap_color_mode color_mode)
1737 bool row_repeat = false;
1740 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1741 color_mode == OMAP_DSS_COLOR_UYVY) {
1745 case OMAP_DSS_ROT_0:
1748 case OMAP_DSS_ROT_90:
1751 case OMAP_DSS_ROT_180:
1754 case OMAP_DSS_ROT_270:
1760 case OMAP_DSS_ROT_0:
1763 case OMAP_DSS_ROT_90:
1766 case OMAP_DSS_ROT_180:
1769 case OMAP_DSS_ROT_270:
1775 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1782 * OMAP4/5 Errata i631:
1783 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
1784 * rows beyond the framebuffer, which may cause OCP error.
1786 if (color_mode == OMAP_DSS_COLOR_NV12 &&
1787 rotation_type != OMAP_DSS_ROT_TILER)
1790 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1791 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1792 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1793 row_repeat ? 1 : 0, 18, 18);
1795 if (color_mode == OMAP_DSS_COLOR_NV12) {
1796 bool doublestride = (rotation_type == OMAP_DSS_ROT_TILER) &&
1797 (rotation == OMAP_DSS_ROT_0 ||
1798 rotation == OMAP_DSS_ROT_180);
1800 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1805 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1807 switch (color_mode) {
1808 case OMAP_DSS_COLOR_CLUT1:
1810 case OMAP_DSS_COLOR_CLUT2:
1812 case OMAP_DSS_COLOR_CLUT4:
1814 case OMAP_DSS_COLOR_CLUT8:
1815 case OMAP_DSS_COLOR_NV12:
1817 case OMAP_DSS_COLOR_RGB12U:
1818 case OMAP_DSS_COLOR_RGB16:
1819 case OMAP_DSS_COLOR_ARGB16:
1820 case OMAP_DSS_COLOR_YUV2:
1821 case OMAP_DSS_COLOR_UYVY:
1822 case OMAP_DSS_COLOR_RGBA16:
1823 case OMAP_DSS_COLOR_RGBX16:
1824 case OMAP_DSS_COLOR_ARGB16_1555:
1825 case OMAP_DSS_COLOR_XRGB16_1555:
1827 case OMAP_DSS_COLOR_RGB24P:
1829 case OMAP_DSS_COLOR_RGB24U:
1830 case OMAP_DSS_COLOR_ARGB32:
1831 case OMAP_DSS_COLOR_RGBA32:
1832 case OMAP_DSS_COLOR_RGBX32:
1840 static s32 pixinc(int pixels, u8 ps)
1844 else if (pixels > 1)
1845 return 1 + (pixels - 1) * ps;
1846 else if (pixels < 0)
1847 return 1 - (-pixels + 1) * ps;
1853 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1855 u16 width, u16 height,
1856 enum omap_color_mode color_mode, bool fieldmode,
1857 unsigned int field_offset,
1858 unsigned *offset0, unsigned *offset1,
1859 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1863 /* FIXME CLUT formats */
1864 switch (color_mode) {
1865 case OMAP_DSS_COLOR_CLUT1:
1866 case OMAP_DSS_COLOR_CLUT2:
1867 case OMAP_DSS_COLOR_CLUT4:
1868 case OMAP_DSS_COLOR_CLUT8:
1871 case OMAP_DSS_COLOR_YUV2:
1872 case OMAP_DSS_COLOR_UYVY:
1876 ps = color_mode_to_bpp(color_mode) / 8;
1880 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1884 * field 0 = even field = bottom field
1885 * field 1 = odd field = top field
1887 switch (rotation + mirror * 4) {
1888 case OMAP_DSS_ROT_0:
1889 case OMAP_DSS_ROT_180:
1891 * If the pixel format is YUV or UYVY divide the width
1892 * of the image by 2 for 0 and 180 degree rotation.
1894 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1895 color_mode == OMAP_DSS_COLOR_UYVY)
1898 case OMAP_DSS_ROT_90:
1899 case OMAP_DSS_ROT_270:
1902 *offset0 = field_offset * screen_width * ps;
1906 *row_inc = pixinc(1 +
1907 (y_predecim * screen_width - x_predecim * width) +
1908 (fieldmode ? screen_width : 0), ps);
1909 *pix_inc = pixinc(x_predecim, ps);
1912 case OMAP_DSS_ROT_0 + 4:
1913 case OMAP_DSS_ROT_180 + 4:
1914 /* If the pixel format is YUV or UYVY divide the width
1915 * of the image by 2 for 0 degree and 180 degree
1917 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1918 color_mode == OMAP_DSS_COLOR_UYVY)
1921 case OMAP_DSS_ROT_90 + 4:
1922 case OMAP_DSS_ROT_270 + 4:
1925 *offset0 = field_offset * screen_width * ps;
1928 *row_inc = pixinc(1 -
1929 (y_predecim * screen_width + x_predecim * width) -
1930 (fieldmode ? screen_width : 0), ps);
1931 *pix_inc = pixinc(x_predecim, ps);
1940 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1942 u16 width, u16 height,
1943 enum omap_color_mode color_mode, bool fieldmode,
1944 unsigned int field_offset,
1945 unsigned *offset0, unsigned *offset1,
1946 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1951 /* FIXME CLUT formats */
1952 switch (color_mode) {
1953 case OMAP_DSS_COLOR_CLUT1:
1954 case OMAP_DSS_COLOR_CLUT2:
1955 case OMAP_DSS_COLOR_CLUT4:
1956 case OMAP_DSS_COLOR_CLUT8:
1960 ps = color_mode_to_bpp(color_mode) / 8;
1964 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1967 /* width & height are overlay sizes, convert to fb sizes */
1969 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1978 * field 0 = even field = bottom field
1979 * field 1 = odd field = top field
1981 switch (rotation + mirror * 4) {
1982 case OMAP_DSS_ROT_0:
1985 *offset0 = *offset1 + field_offset * screen_width * ps;
1987 *offset0 = *offset1;
1988 *row_inc = pixinc(1 +
1989 (y_predecim * screen_width - fbw * x_predecim) +
1990 (fieldmode ? screen_width : 0), ps);
1991 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1992 color_mode == OMAP_DSS_COLOR_UYVY)
1993 *pix_inc = pixinc(x_predecim, 2 * ps);
1995 *pix_inc = pixinc(x_predecim, ps);
1997 case OMAP_DSS_ROT_90:
1998 *offset1 = screen_width * (fbh - 1) * ps;
2000 *offset0 = *offset1 + field_offset * ps;
2002 *offset0 = *offset1;
2003 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
2004 y_predecim + (fieldmode ? 1 : 0), ps);
2005 *pix_inc = pixinc(-x_predecim * screen_width, ps);
2007 case OMAP_DSS_ROT_180:
2008 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2010 *offset0 = *offset1 - field_offset * screen_width * ps;
2012 *offset0 = *offset1;
2013 *row_inc = pixinc(-1 -
2014 (y_predecim * screen_width - fbw * x_predecim) -
2015 (fieldmode ? screen_width : 0), ps);
2016 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2017 color_mode == OMAP_DSS_COLOR_UYVY)
2018 *pix_inc = pixinc(-x_predecim, 2 * ps);
2020 *pix_inc = pixinc(-x_predecim, ps);
2022 case OMAP_DSS_ROT_270:
2023 *offset1 = (fbw - 1) * ps;
2025 *offset0 = *offset1 - field_offset * ps;
2027 *offset0 = *offset1;
2028 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
2029 y_predecim - (fieldmode ? 1 : 0), ps);
2030 *pix_inc = pixinc(x_predecim * screen_width, ps);
2034 case OMAP_DSS_ROT_0 + 4:
2035 *offset1 = (fbw - 1) * ps;
2037 *offset0 = *offset1 + field_offset * screen_width * ps;
2039 *offset0 = *offset1;
2040 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
2041 (fieldmode ? screen_width : 0),
2043 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2044 color_mode == OMAP_DSS_COLOR_UYVY)
2045 *pix_inc = pixinc(-x_predecim, 2 * ps);
2047 *pix_inc = pixinc(-x_predecim, ps);
2050 case OMAP_DSS_ROT_90 + 4:
2053 *offset0 = *offset1 + field_offset * ps;
2055 *offset0 = *offset1;
2056 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
2057 y_predecim + (fieldmode ? 1 : 0),
2059 *pix_inc = pixinc(x_predecim * screen_width, ps);
2062 case OMAP_DSS_ROT_180 + 4:
2063 *offset1 = screen_width * (fbh - 1) * ps;
2065 *offset0 = *offset1 - field_offset * screen_width * ps;
2067 *offset0 = *offset1;
2068 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
2069 (fieldmode ? screen_width : 0),
2071 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2072 color_mode == OMAP_DSS_COLOR_UYVY)
2073 *pix_inc = pixinc(x_predecim, 2 * ps);
2075 *pix_inc = pixinc(x_predecim, ps);
2078 case OMAP_DSS_ROT_270 + 4:
2079 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2081 *offset0 = *offset1 - field_offset * ps;
2083 *offset0 = *offset1;
2084 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
2085 y_predecim - (fieldmode ? 1 : 0),
2087 *pix_inc = pixinc(-x_predecim * screen_width, ps);
2096 static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
2097 enum omap_color_mode color_mode, bool fieldmode,
2098 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
2099 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
2103 switch (color_mode) {
2104 case OMAP_DSS_COLOR_CLUT1:
2105 case OMAP_DSS_COLOR_CLUT2:
2106 case OMAP_DSS_COLOR_CLUT4:
2107 case OMAP_DSS_COLOR_CLUT8:
2111 ps = color_mode_to_bpp(color_mode) / 8;
2115 DSSDBG("scrw %d, width %d\n", screen_width, width);
2118 * field 0 = even field = bottom field
2119 * field 1 = odd field = top field
2123 *offset0 = *offset1 + field_offset * screen_width * ps;
2125 *offset0 = *offset1;
2126 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2127 (fieldmode ? screen_width : 0), ps);
2128 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2129 color_mode == OMAP_DSS_COLOR_UYVY)
2130 *pix_inc = pixinc(x_predecim, 2 * ps);
2132 *pix_inc = pixinc(x_predecim, ps);
2136 * This function is used to avoid synclosts in OMAP3, because of some
2137 * undocumented horizontal position and timing related limitations.
2139 static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
2140 const struct omap_video_timings *t, u16 pos_x,
2141 u16 width, u16 height, u16 out_width, u16 out_height,
2144 const int ds = DIV_ROUND_UP(height, out_height);
2145 unsigned long nonactive;
2146 static const u8 limits[3] = { 8, 10, 20 };
2150 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
2153 if (out_height < height)
2155 if (out_width < width)
2157 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
2158 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2159 if (blank <= limits[i])
2162 /* FIXME add checks for 3-tap filter once the limitations are known */
2167 * Pixel data should be prepared before visible display point starts.
2168 * So, atleast DS-2 lines must have already been fetched by DISPC
2169 * during nonactive - pos_x period.
2171 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2172 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2173 val, max(0, ds - 2) * width);
2174 if (val < max(0, ds - 2) * width)
2178 * All lines need to be refilled during the nonactive period of which
2179 * only one line can be loaded during the active period. So, atleast
2180 * DS - 1 lines should be loaded during nonactive period.
2182 val = div_u64((u64)nonactive * lclk, pclk);
2183 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2184 val, max(0, ds - 1) * width);
2185 if (val < max(0, ds - 1) * width)
2191 static unsigned long calc_core_clk_five_taps(unsigned long pclk,
2192 const struct omap_video_timings *mgr_timings, u16 width,
2193 u16 height, u16 out_width, u16 out_height,
2194 enum omap_color_mode color_mode)
2199 if (height <= out_height && width <= out_width)
2200 return (unsigned long) pclk;
2202 if (height > out_height) {
2203 unsigned int ppl = mgr_timings->x_res;
2205 tmp = (u64)pclk * height * out_width;
2206 do_div(tmp, 2 * out_height * ppl);
2209 if (height > 2 * out_height) {
2210 if (ppl == out_width)
2213 tmp = (u64)pclk * (height - 2 * out_height) * out_width;
2214 do_div(tmp, 2 * out_height * (ppl - out_width));
2215 core_clk = max_t(u32, core_clk, tmp);
2219 if (width > out_width) {
2220 tmp = (u64)pclk * width;
2221 do_div(tmp, out_width);
2222 core_clk = max_t(u32, core_clk, tmp);
2224 if (color_mode == OMAP_DSS_COLOR_RGB24U)
2231 static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
2232 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2234 if (height > out_height && width > out_width)
2240 static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
2241 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2243 unsigned int hf, vf;
2246 * FIXME how to determine the 'A' factor
2247 * for the no downscaling case ?
2250 if (width > 3 * out_width)
2252 else if (width > 2 * out_width)
2254 else if (width > out_width)
2258 if (height > out_height)
2263 return pclk * vf * hf;
2266 static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
2267 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2270 * If the overlay/writeback is in mem to mem mode, there are no
2271 * downscaling limitations with respect to pixel clock, return 1 as
2272 * required core clock to represent that we have sufficient enough
2273 * core clock to do maximum downscaling
2278 if (width > out_width)
2279 return DIV_ROUND_UP(pclk, out_width) * width;
2284 static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
2285 const struct omap_video_timings *mgr_timings,
2286 u16 width, u16 height, u16 out_width, u16 out_height,
2287 enum omap_color_mode color_mode, bool *five_taps,
2288 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2289 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2292 u16 in_width, in_height;
2293 int min_factor = min(*decim_x, *decim_y);
2294 const int maxsinglelinewidth =
2295 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2300 in_height = height / *decim_y;
2301 in_width = width / *decim_x;
2302 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
2303 in_height, out_width, out_height, mem_to_mem);
2304 error = (in_width > maxsinglelinewidth || !*core_clk ||
2305 *core_clk > dispc_core_clk_rate());
2307 if (*decim_x == *decim_y) {
2308 *decim_x = min_factor;
2311 swap(*decim_x, *decim_y);
2312 if (*decim_x < *decim_y)
2316 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2319 DSSERR("failed to find scaling settings\n");
2323 if (in_width > maxsinglelinewidth) {
2324 DSSERR("Cannot scale max input width exceeded");
2330 static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
2331 const struct omap_video_timings *mgr_timings,
2332 u16 width, u16 height, u16 out_width, u16 out_height,
2333 enum omap_color_mode color_mode, bool *five_taps,
2334 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2335 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2338 u16 in_width, in_height;
2339 const int maxsinglelinewidth =
2340 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2343 in_height = height / *decim_y;
2344 in_width = width / *decim_x;
2345 *five_taps = in_height > out_height;
2347 if (in_width > maxsinglelinewidth)
2348 if (in_height > out_height &&
2349 in_height < out_height * 2)
2353 *core_clk = calc_core_clk_five_taps(pclk, mgr_timings,
2354 in_width, in_height, out_width,
2355 out_height, color_mode);
2357 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
2358 in_height, out_width, out_height,
2361 error = check_horiz_timing_omap3(pclk, lclk, mgr_timings,
2362 pos_x, in_width, in_height, out_width,
2363 out_height, *five_taps);
2364 if (error && *five_taps) {
2369 error = (error || in_width > maxsinglelinewidth * 2 ||
2370 (in_width > maxsinglelinewidth && *five_taps) ||
2371 !*core_clk || *core_clk > dispc_core_clk_rate());
2374 /* verify that we're inside the limits of scaler */
2375 if (in_width / 4 > out_width)
2379 if (in_height / 4 > out_height)
2382 if (in_height / 2 > out_height)
2389 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2392 DSSERR("failed to find scaling settings\n");
2396 if (check_horiz_timing_omap3(pclk, lclk, mgr_timings, pos_x, in_width,
2397 in_height, out_width, out_height, *five_taps)) {
2398 DSSERR("horizontal timing too tight\n");
2402 if (in_width > (maxsinglelinewidth * 2)) {
2403 DSSERR("Cannot setup scaling");
2404 DSSERR("width exceeds maximum width possible");
2408 if (in_width > maxsinglelinewidth && *five_taps) {
2409 DSSERR("cannot setup scaling with five taps");
2415 static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
2416 const struct omap_video_timings *mgr_timings,
2417 u16 width, u16 height, u16 out_width, u16 out_height,
2418 enum omap_color_mode color_mode, bool *five_taps,
2419 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2420 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2422 u16 in_width, in_width_max;
2423 int decim_x_min = *decim_x;
2424 u16 in_height = height / *decim_y;
2425 const int maxsinglelinewidth =
2426 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2427 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2430 in_width_max = out_width * maxdownscale;
2432 in_width_max = dispc_core_clk_rate() /
2433 DIV_ROUND_UP(pclk, out_width);
2436 *decim_x = DIV_ROUND_UP(width, in_width_max);
2438 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2439 if (*decim_x > *x_predecim)
2443 in_width = width / *decim_x;
2444 } while (*decim_x <= *x_predecim &&
2445 in_width > maxsinglelinewidth && ++*decim_x);
2447 if (in_width > maxsinglelinewidth) {
2448 DSSERR("Cannot scale width exceeds max line width");
2452 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
2453 out_width, out_height, mem_to_mem);
2457 #define DIV_FRAC(dividend, divisor) \
2458 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2460 static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
2461 enum omap_overlay_caps caps,
2462 const struct omap_video_timings *mgr_timings,
2463 u16 width, u16 height, u16 out_width, u16 out_height,
2464 enum omap_color_mode color_mode, bool *five_taps,
2465 int *x_predecim, int *y_predecim, u16 pos_x,
2466 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
2468 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2469 const int max_decim_limit = 16;
2470 unsigned long core_clk = 0;
2471 int decim_x, decim_y, ret;
2473 if (width == out_width && height == out_height)
2476 if (!mem_to_mem && (pclk == 0 || mgr_timings->pixelclock == 0)) {
2477 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2481 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
2485 *x_predecim = *y_predecim = 1;
2487 *x_predecim = max_decim_limit;
2488 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2489 dss_has_feature(FEAT_BURST_2D)) ?
2490 2 : max_decim_limit;
2493 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2494 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2495 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2496 color_mode == OMAP_DSS_COLOR_CLUT8) {
2503 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2504 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2506 if (decim_x > *x_predecim || out_width > width * 8)
2509 if (decim_y > *y_predecim || out_height > height * 8)
2512 ret = dispc.feat->calc_scaling(pclk, lclk, mgr_timings, width, height,
2513 out_width, out_height, color_mode, five_taps,
2514 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2519 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",
2521 out_width, out_height,
2522 out_width / width, DIV_FRAC(out_width, width),
2523 out_height / height, DIV_FRAC(out_height, height),
2526 width / decim_x, height / decim_y,
2527 out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
2528 out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
2531 core_clk, dispc_core_clk_rate());
2533 if (!core_clk || core_clk > dispc_core_clk_rate()) {
2534 DSSERR("failed to set up scaling, "
2535 "required core clk rate = %lu Hz, "
2536 "current core clk rate = %lu Hz\n",
2537 core_clk, dispc_core_clk_rate());
2541 *x_predecim = decim_x;
2542 *y_predecim = decim_y;
2546 int dispc_ovl_check(enum omap_plane plane, enum omap_channel channel,
2547 const struct omap_overlay_info *oi,
2548 const struct omap_video_timings *timings,
2549 int *x_predecim, int *y_predecim)
2551 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2552 bool five_taps = true;
2553 bool fieldmode = false;
2554 u16 in_height = oi->height;
2555 u16 in_width = oi->width;
2556 bool ilace = timings->interlace;
2557 u16 out_width, out_height;
2558 int pos_x = oi->pos_x;
2559 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2560 unsigned long lclk = dispc_mgr_lclk_rate(channel);
2562 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2563 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2565 if (ilace && oi->height == out_height)
2573 DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2574 in_height, out_height);
2577 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2580 return dispc_ovl_calc_scaling(pclk, lclk, caps, timings, in_width,
2581 in_height, out_width, out_height, oi->color_mode,
2582 &five_taps, x_predecim, y_predecim, pos_x,
2583 oi->rotation_type, false);
2585 EXPORT_SYMBOL(dispc_ovl_check);
2587 static int dispc_ovl_setup_common(enum omap_plane plane,
2588 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2589 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2590 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2591 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2592 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
2593 bool replication, const struct omap_video_timings *mgr_timings,
2596 bool five_taps = true;
2597 bool fieldmode = false;
2599 unsigned offset0, offset1;
2602 u16 frame_width, frame_height;
2603 unsigned int field_offset = 0;
2604 u16 in_height = height;
2605 u16 in_width = width;
2606 int x_predecim = 1, y_predecim = 1;
2607 bool ilace = mgr_timings->interlace;
2608 unsigned long pclk = dispc_plane_pclk_rate(plane);
2609 unsigned long lclk = dispc_plane_lclk_rate(plane);
2611 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
2614 switch (color_mode) {
2615 case OMAP_DSS_COLOR_YUV2:
2616 case OMAP_DSS_COLOR_UYVY:
2617 case OMAP_DSS_COLOR_NV12:
2619 DSSERR("input width %d is not even for YUV format\n",
2629 out_width = out_width == 0 ? width : out_width;
2630 out_height = out_height == 0 ? height : out_height;
2632 if (ilace && height == out_height)
2641 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2642 "out_height %d\n", in_height, pos_y,
2646 if (!dss_feat_color_mode_supported(plane, color_mode))
2649 r = dispc_ovl_calc_scaling(pclk, lclk, caps, mgr_timings, in_width,
2650 in_height, out_width, out_height, color_mode,
2651 &five_taps, &x_predecim, &y_predecim, pos_x,
2652 rotation_type, mem_to_mem);
2656 in_width = in_width / x_predecim;
2657 in_height = in_height / y_predecim;
2659 if (x_predecim > 1 || y_predecim > 1)
2660 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2661 x_predecim, y_predecim, in_width, in_height);
2663 switch (color_mode) {
2664 case OMAP_DSS_COLOR_YUV2:
2665 case OMAP_DSS_COLOR_UYVY:
2666 case OMAP_DSS_COLOR_NV12:
2668 DSSDBG("predecimated input width is not even for YUV format\n");
2669 DSSDBG("adjusting input width %d -> %d\n",
2670 in_width, in_width & ~1);
2680 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2681 color_mode == OMAP_DSS_COLOR_UYVY ||
2682 color_mode == OMAP_DSS_COLOR_NV12)
2685 if (ilace && !fieldmode) {
2687 * when downscaling the bottom field may have to start several
2688 * source lines below the top field. Unfortunately ACCUI
2689 * registers will only hold the fractional part of the offset
2690 * so the integer part must be added to the base address of the
2693 if (!in_height || in_height == out_height)
2696 field_offset = in_height / out_height / 2;
2699 /* Fields are independent but interleaved in memory. */
2708 if (plane == OMAP_DSS_WB) {
2709 frame_width = out_width;
2710 frame_height = out_height;
2712 frame_width = in_width;
2713 frame_height = height;
2716 if (rotation_type == OMAP_DSS_ROT_TILER)
2717 calc_tiler_rotation_offset(screen_width, frame_width,
2718 color_mode, fieldmode, field_offset,
2719 &offset0, &offset1, &row_inc, &pix_inc,
2720 x_predecim, y_predecim);
2721 else if (rotation_type == OMAP_DSS_ROT_DMA)
2722 calc_dma_rotation_offset(rotation, mirror, screen_width,
2723 frame_width, frame_height,
2724 color_mode, fieldmode, field_offset,
2725 &offset0, &offset1, &row_inc, &pix_inc,
2726 x_predecim, y_predecim);
2728 calc_vrfb_rotation_offset(rotation, mirror,
2729 screen_width, frame_width, frame_height,
2730 color_mode, fieldmode, field_offset,
2731 &offset0, &offset1, &row_inc, &pix_inc,
2732 x_predecim, y_predecim);
2734 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2735 offset0, offset1, row_inc, pix_inc);
2737 dispc_ovl_set_color_mode(plane, color_mode);
2739 dispc_ovl_configure_burst_type(plane, rotation_type);
2741 dispc_ovl_set_ba0(plane, paddr + offset0);
2742 dispc_ovl_set_ba1(plane, paddr + offset1);
2744 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2745 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2746 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
2749 if (dispc.feat->last_pixel_inc_missing)
2750 row_inc += pix_inc - 1;
2752 dispc_ovl_set_row_inc(plane, row_inc);
2753 dispc_ovl_set_pix_inc(plane, pix_inc);
2755 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
2756 in_height, out_width, out_height);
2758 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
2760 dispc_ovl_set_input_size(plane, in_width, in_height);
2762 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
2763 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2764 out_height, ilace, five_taps, fieldmode,
2765 color_mode, rotation);
2766 dispc_ovl_set_output_size(plane, out_width, out_height);
2767 dispc_ovl_set_vid_color_conv(plane, cconv);
2770 dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror,
2773 dispc_ovl_set_zorder(plane, caps, zorder);
2774 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2775 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
2777 dispc_ovl_enable_replication(plane, caps, replication);
2782 int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
2783 bool replication, const struct omap_video_timings *mgr_timings,
2787 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2788 enum omap_channel channel;
2790 channel = dispc_ovl_get_channel_out(plane);
2792 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2793 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2794 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
2795 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2796 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2798 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
2799 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2800 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2801 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
2802 oi->rotation_type, replication, mgr_timings, mem_to_mem);
2806 EXPORT_SYMBOL(dispc_ovl_setup);
2808 int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
2809 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
2813 enum omap_plane plane = OMAP_DSS_WB;
2814 const int pos_x = 0, pos_y = 0;
2815 const u8 zorder = 0, global_alpha = 0;
2816 const bool replication = false;
2818 int in_width = mgr_timings->x_res;
2819 int in_height = mgr_timings->y_res;
2820 enum omap_overlay_caps caps =
2821 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2823 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2824 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2825 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2828 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2829 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2830 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2831 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
2832 replication, mgr_timings, mem_to_mem);
2834 switch (wi->color_mode) {
2835 case OMAP_DSS_COLOR_RGB16:
2836 case OMAP_DSS_COLOR_RGB24P:
2837 case OMAP_DSS_COLOR_ARGB16:
2838 case OMAP_DSS_COLOR_RGBA16:
2839 case OMAP_DSS_COLOR_RGB12U:
2840 case OMAP_DSS_COLOR_ARGB16_1555:
2841 case OMAP_DSS_COLOR_XRGB16_1555:
2842 case OMAP_DSS_COLOR_RGBX16:
2850 /* setup extra DISPC_WB_ATTRIBUTES */
2851 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2852 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2853 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2855 l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */
2857 l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */
2858 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
2862 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
2866 wbdelay = min(mgr_timings->vfp + mgr_timings->vsw +
2867 mgr_timings->vbp, 255);
2870 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
2876 int dispc_ovl_enable(enum omap_plane plane, bool enable)
2878 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2880 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2884 EXPORT_SYMBOL(dispc_ovl_enable);
2886 bool dispc_ovl_enabled(enum omap_plane plane)
2888 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2890 EXPORT_SYMBOL(dispc_ovl_enabled);
2892 void dispc_mgr_enable(enum omap_channel channel, bool enable)
2894 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2895 /* flush posted write */
2896 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2898 EXPORT_SYMBOL(dispc_mgr_enable);
2900 bool dispc_mgr_is_enabled(enum omap_channel channel)
2902 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2904 EXPORT_SYMBOL(dispc_mgr_is_enabled);
2906 void dispc_wb_enable(bool enable)
2908 dispc_ovl_enable(OMAP_DSS_WB, enable);
2911 bool dispc_wb_is_enabled(void)
2913 return dispc_ovl_enabled(OMAP_DSS_WB);
2916 static void dispc_lcd_enable_signal_polarity(bool act_high)
2918 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2921 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2924 void dispc_lcd_enable_signal(bool enable)
2926 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2929 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2932 void dispc_pck_free_enable(bool enable)
2934 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2937 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2940 static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2942 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
2946 static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
2948 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
2951 static void dispc_set_loadmode(enum omap_dss_load_mode mode)
2953 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2957 static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2959 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2962 static void dispc_mgr_set_trans_key(enum omap_channel ch,
2963 enum omap_dss_trans_key_type type,
2966 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
2968 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2971 static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2973 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
2976 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2979 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
2982 if (ch == OMAP_DSS_CHANNEL_LCD)
2983 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2984 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2985 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2988 void dispc_mgr_setup(enum omap_channel channel,
2989 const struct omap_overlay_manager_info *info)
2991 dispc_mgr_set_default_color(channel, info->default_color);
2992 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2993 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2994 dispc_mgr_enable_alpha_fixed_zorder(channel,
2995 info->partial_alpha_enabled);
2996 if (dss_has_feature(FEAT_CPR)) {
2997 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2998 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
3001 EXPORT_SYMBOL(dispc_mgr_setup);
3003 static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
3007 switch (data_lines) {
3025 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
3028 static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
3034 case DSS_IO_PAD_MODE_RESET:
3038 case DSS_IO_PAD_MODE_RFBI:
3042 case DSS_IO_PAD_MODE_BYPASS:
3051 l = dispc_read_reg(DISPC_CONTROL);
3052 l = FLD_MOD(l, gpout0, 15, 15);
3053 l = FLD_MOD(l, gpout1, 16, 16);
3054 dispc_write_reg(DISPC_CONTROL, l);
3057 static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
3059 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
3062 void dispc_mgr_set_lcd_config(enum omap_channel channel,
3063 const struct dss_lcd_mgr_config *config)
3065 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
3067 dispc_mgr_enable_stallmode(channel, config->stallmode);
3068 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
3070 dispc_mgr_set_clock_div(channel, &config->clock_info);
3072 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
3074 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
3076 dispc_mgr_set_lcd_type_tft(channel);
3078 EXPORT_SYMBOL(dispc_mgr_set_lcd_config);
3080 static bool _dispc_mgr_size_ok(u16 width, u16 height)
3082 return width <= dispc.feat->mgr_width_max &&
3083 height <= dispc.feat->mgr_height_max;
3086 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
3087 int vsw, int vfp, int vbp)
3089 if (hsw < 1 || hsw > dispc.feat->sw_max ||
3090 hfp < 1 || hfp > dispc.feat->hp_max ||
3091 hbp < 1 || hbp > dispc.feat->hp_max ||
3092 vsw < 1 || vsw > dispc.feat->sw_max ||
3093 vfp < 0 || vfp > dispc.feat->vp_max ||
3094 vbp < 0 || vbp > dispc.feat->vp_max)
3099 static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
3102 if (dss_mgr_is_lcd(channel))
3103 return pclk <= dispc.feat->max_lcd_pclk ? true : false;
3105 return pclk <= dispc.feat->max_tv_pclk ? true : false;
3108 bool dispc_mgr_timings_ok(enum omap_channel channel,
3109 const struct omap_video_timings *timings)
3111 if (!_dispc_mgr_size_ok(timings->x_res, timings->y_res))
3114 if (!_dispc_mgr_pclk_ok(channel, timings->pixelclock))
3117 if (dss_mgr_is_lcd(channel)) {
3118 /* TODO: OMAP4+ supports interlace for LCD outputs */
3119 if (timings->interlace)
3122 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
3123 timings->hbp, timings->vsw, timings->vfp,
3131 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
3132 int hfp, int hbp, int vsw, int vfp, int vbp,
3133 enum omap_dss_signal_level vsync_level,
3134 enum omap_dss_signal_level hsync_level,
3135 enum omap_dss_signal_edge data_pclk_edge,
3136 enum omap_dss_signal_level de_level,
3137 enum omap_dss_signal_edge sync_pclk_edge)
3140 u32 timing_h, timing_v, l;
3141 bool onoff, rf, ipc, vs, hs, de;
3143 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
3144 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
3145 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
3146 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
3147 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
3148 FLD_VAL(vbp, dispc.feat->bp_start, 20);
3150 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
3151 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
3153 switch (vsync_level) {
3154 case OMAPDSS_SIG_ACTIVE_LOW:
3157 case OMAPDSS_SIG_ACTIVE_HIGH:
3164 switch (hsync_level) {
3165 case OMAPDSS_SIG_ACTIVE_LOW:
3168 case OMAPDSS_SIG_ACTIVE_HIGH:
3176 case OMAPDSS_SIG_ACTIVE_LOW:
3179 case OMAPDSS_SIG_ACTIVE_HIGH:
3186 switch (data_pclk_edge) {
3187 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3190 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3197 /* always use the 'rf' setting */
3200 switch (sync_pclk_edge) {
3201 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3204 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3211 l = FLD_VAL(onoff, 17, 17) |
3212 FLD_VAL(rf, 16, 16) |
3213 FLD_VAL(de, 15, 15) |
3214 FLD_VAL(ipc, 14, 14) |
3215 FLD_VAL(hs, 13, 13) |
3216 FLD_VAL(vs, 12, 12);
3218 /* always set ALIGN bit when available */
3219 if (dispc.feat->supports_sync_align)
3222 dispc_write_reg(DISPC_POL_FREQ(channel), l);
3224 if (dispc.syscon_pol) {
3225 const int shifts[] = {
3226 [OMAP_DSS_CHANNEL_LCD] = 0,
3227 [OMAP_DSS_CHANNEL_LCD2] = 1,
3228 [OMAP_DSS_CHANNEL_LCD3] = 2,
3233 mask = (1 << 0) | (1 << 3) | (1 << 6);
3234 val = (rf << 0) | (ipc << 3) | (onoff << 6);
3236 mask <<= 16 + shifts[channel];
3237 val <<= 16 + shifts[channel];
3239 regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
3244 /* change name to mode? */
3245 void dispc_mgr_set_timings(enum omap_channel channel,
3246 const struct omap_video_timings *timings)
3248 unsigned xtot, ytot;
3249 unsigned long ht, vt;
3250 struct omap_video_timings t = *timings;
3252 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
3254 if (!dispc_mgr_timings_ok(channel, &t)) {
3259 if (dss_mgr_is_lcd(channel)) {
3260 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
3261 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
3262 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
3264 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
3265 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
3267 ht = timings->pixelclock / xtot;
3268 vt = timings->pixelclock / xtot / ytot;
3270 DSSDBG("pck %u\n", timings->pixelclock);
3271 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
3272 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
3273 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3274 t.vsync_level, t.hsync_level, t.data_pclk_edge,
3275 t.de_level, t.sync_pclk_edge);
3277 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
3283 dispc_mgr_set_size(channel, t.x_res, t.y_res);
3285 EXPORT_SYMBOL(dispc_mgr_set_timings);
3287 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
3290 BUG_ON(lck_div < 1);
3291 BUG_ON(pck_div < 1);
3293 dispc_write_reg(DISPC_DIVISORo(channel),
3294 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
3296 if (!dss_has_feature(FEAT_CORE_CLK_DIV) &&
3297 channel == OMAP_DSS_CHANNEL_LCD)
3298 dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
3301 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
3305 l = dispc_read_reg(DISPC_DIVISORo(channel));
3306 *lck_div = FLD_GET(l, 23, 16);
3307 *pck_div = FLD_GET(l, 7, 0);
3310 static unsigned long dispc_fclk_rate(void)
3312 struct dss_pll *pll;
3313 unsigned long r = 0;
3315 switch (dss_get_dispc_clk_source()) {
3316 case OMAP_DSS_CLK_SRC_FCK:
3317 r = dss_get_dispc_clk_rate();
3319 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
3320 pll = dss_pll_find("dsi0");
3322 pll = dss_pll_find("video0");
3324 r = pll->cinfo.clkout[0];
3326 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3327 pll = dss_pll_find("dsi1");
3329 pll = dss_pll_find("video1");
3331 r = pll->cinfo.clkout[0];
3341 static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
3343 struct dss_pll *pll;
3348 if (dss_mgr_is_lcd(channel)) {
3349 l = dispc_read_reg(DISPC_DIVISORo(channel));
3351 lcd = FLD_GET(l, 23, 16);
3353 switch (dss_get_lcd_clk_source(channel)) {
3354 case OMAP_DSS_CLK_SRC_FCK:
3355 r = dss_get_dispc_clk_rate();
3357 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
3358 pll = dss_pll_find("dsi0");
3360 pll = dss_pll_find("video0");
3362 r = pll->cinfo.clkout[0];
3364 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3365 pll = dss_pll_find("dsi1");
3367 pll = dss_pll_find("video1");
3369 r = pll->cinfo.clkout[0];
3378 return dispc_fclk_rate();
3382 static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
3386 if (dss_mgr_is_lcd(channel)) {
3390 l = dispc_read_reg(DISPC_DIVISORo(channel));
3392 pcd = FLD_GET(l, 7, 0);
3394 r = dispc_mgr_lclk_rate(channel);
3398 return dispc.tv_pclk_rate;
3402 void dispc_set_tv_pclk(unsigned long pclk)
3404 dispc.tv_pclk_rate = pclk;
3407 static unsigned long dispc_core_clk_rate(void)
3409 return dispc.core_clk_rate;
3412 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3414 enum omap_channel channel;
3416 if (plane == OMAP_DSS_WB)
3419 channel = dispc_ovl_get_channel_out(plane);
3421 return dispc_mgr_pclk_rate(channel);
3424 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3426 enum omap_channel channel;
3428 if (plane == OMAP_DSS_WB)
3431 channel = dispc_ovl_get_channel_out(plane);
3433 return dispc_mgr_lclk_rate(channel);
3436 static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
3439 enum omap_dss_clk_source lcd_clk_src;
3441 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3443 lcd_clk_src = dss_get_lcd_clk_source(channel);
3445 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3446 dss_get_generic_clk_source_name(lcd_clk_src),
3447 dss_feat_get_clk_source_name(lcd_clk_src));
3449 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3451 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3452 dispc_mgr_lclk_rate(channel), lcd);
3453 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3454 dispc_mgr_pclk_rate(channel), pcd);
3457 void dispc_dump_clocks(struct seq_file *s)
3461 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
3463 if (dispc_runtime_get())
3466 seq_printf(s, "- DISPC -\n");
3468 seq_printf(s, "dispc fclk source = %s (%s)\n",
3469 dss_get_generic_clk_source_name(dispc_clk_src),
3470 dss_feat_get_clk_source_name(dispc_clk_src));
3472 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
3474 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3475 seq_printf(s, "- DISPC-CORE-CLK -\n");
3476 l = dispc_read_reg(DISPC_DIVISOR);
3477 lcd = FLD_GET(l, 23, 16);
3479 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3480 (dispc_fclk_rate()/lcd), lcd);
3483 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
3485 if (dss_has_feature(FEAT_MGR_LCD2))
3486 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3487 if (dss_has_feature(FEAT_MGR_LCD3))
3488 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
3490 dispc_runtime_put();
3493 static void dispc_dump_regs(struct seq_file *s)
3496 const char *mgr_names[] = {
3497 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3498 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3499 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
3500 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
3502 const char *ovl_names[] = {
3503 [OMAP_DSS_GFX] = "GFX",
3504 [OMAP_DSS_VIDEO1] = "VID1",
3505 [OMAP_DSS_VIDEO2] = "VID2",
3506 [OMAP_DSS_VIDEO3] = "VID3",
3507 [OMAP_DSS_WB] = "WB",
3509 const char **p_names;
3511 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3513 if (dispc_runtime_get())
3516 /* DISPC common registers */
3517 DUMPREG(DISPC_REVISION);
3518 DUMPREG(DISPC_SYSCONFIG);
3519 DUMPREG(DISPC_SYSSTATUS);
3520 DUMPREG(DISPC_IRQSTATUS);
3521 DUMPREG(DISPC_IRQENABLE);
3522 DUMPREG(DISPC_CONTROL);
3523 DUMPREG(DISPC_CONFIG);
3524 DUMPREG(DISPC_CAPABLE);
3525 DUMPREG(DISPC_LINE_STATUS);
3526 DUMPREG(DISPC_LINE_NUMBER);
3527 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3528 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
3529 DUMPREG(DISPC_GLOBAL_ALPHA);
3530 if (dss_has_feature(FEAT_MGR_LCD2)) {
3531 DUMPREG(DISPC_CONTROL2);
3532 DUMPREG(DISPC_CONFIG2);
3534 if (dss_has_feature(FEAT_MGR_LCD3)) {
3535 DUMPREG(DISPC_CONTROL3);
3536 DUMPREG(DISPC_CONFIG3);
3538 if (dss_has_feature(FEAT_MFLAG))
3539 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
3543 #define DISPC_REG(i, name) name(i)
3544 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3545 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
3546 dispc_read_reg(DISPC_REG(i, r)))
3548 p_names = mgr_names;
3550 /* DISPC channel specific registers */
3551 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3552 DUMPREG(i, DISPC_DEFAULT_COLOR);
3553 DUMPREG(i, DISPC_TRANS_COLOR);
3554 DUMPREG(i, DISPC_SIZE_MGR);
3556 if (i == OMAP_DSS_CHANNEL_DIGIT)
3559 DUMPREG(i, DISPC_TIMING_H);
3560 DUMPREG(i, DISPC_TIMING_V);
3561 DUMPREG(i, DISPC_POL_FREQ);
3562 DUMPREG(i, DISPC_DIVISORo);
3564 DUMPREG(i, DISPC_DATA_CYCLE1);
3565 DUMPREG(i, DISPC_DATA_CYCLE2);
3566 DUMPREG(i, DISPC_DATA_CYCLE3);
3568 if (dss_has_feature(FEAT_CPR)) {
3569 DUMPREG(i, DISPC_CPR_COEF_R);
3570 DUMPREG(i, DISPC_CPR_COEF_G);
3571 DUMPREG(i, DISPC_CPR_COEF_B);
3575 p_names = ovl_names;
3577 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3578 DUMPREG(i, DISPC_OVL_BA0);
3579 DUMPREG(i, DISPC_OVL_BA1);
3580 DUMPREG(i, DISPC_OVL_POSITION);
3581 DUMPREG(i, DISPC_OVL_SIZE);
3582 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3583 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3584 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3585 DUMPREG(i, DISPC_OVL_ROW_INC);
3586 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3588 if (dss_has_feature(FEAT_PRELOAD))
3589 DUMPREG(i, DISPC_OVL_PRELOAD);
3590 if (dss_has_feature(FEAT_MFLAG))
3591 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
3593 if (i == OMAP_DSS_GFX) {
3594 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3595 DUMPREG(i, DISPC_OVL_TABLE_BA);
3599 DUMPREG(i, DISPC_OVL_FIR);
3600 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3601 DUMPREG(i, DISPC_OVL_ACCU0);
3602 DUMPREG(i, DISPC_OVL_ACCU1);
3603 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3604 DUMPREG(i, DISPC_OVL_BA0_UV);
3605 DUMPREG(i, DISPC_OVL_BA1_UV);
3606 DUMPREG(i, DISPC_OVL_FIR2);
3607 DUMPREG(i, DISPC_OVL_ACCU2_0);
3608 DUMPREG(i, DISPC_OVL_ACCU2_1);
3610 if (dss_has_feature(FEAT_ATTR2))
3611 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3614 if (dispc.feat->has_writeback) {
3616 DUMPREG(i, DISPC_OVL_BA0);
3617 DUMPREG(i, DISPC_OVL_BA1);
3618 DUMPREG(i, DISPC_OVL_SIZE);
3619 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3620 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3621 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3622 DUMPREG(i, DISPC_OVL_ROW_INC);
3623 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3625 if (dss_has_feature(FEAT_MFLAG))
3626 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
3628 DUMPREG(i, DISPC_OVL_FIR);
3629 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3630 DUMPREG(i, DISPC_OVL_ACCU0);
3631 DUMPREG(i, DISPC_OVL_ACCU1);
3632 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3633 DUMPREG(i, DISPC_OVL_BA0_UV);
3634 DUMPREG(i, DISPC_OVL_BA1_UV);
3635 DUMPREG(i, DISPC_OVL_FIR2);
3636 DUMPREG(i, DISPC_OVL_ACCU2_0);
3637 DUMPREG(i, DISPC_OVL_ACCU2_1);
3639 if (dss_has_feature(FEAT_ATTR2))
3640 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3646 #define DISPC_REG(plane, name, i) name(plane, i)
3647 #define DUMPREG(plane, name, i) \
3648 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3649 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
3650 dispc_read_reg(DISPC_REG(plane, name, i)))
3652 /* Video pipeline coefficient registers */
3654 /* start from OMAP_DSS_VIDEO1 */
3655 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3656 for (j = 0; j < 8; j++)
3657 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
3659 for (j = 0; j < 8; j++)
3660 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
3662 for (j = 0; j < 5; j++)
3663 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
3665 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3666 for (j = 0; j < 8; j++)
3667 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3670 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3671 for (j = 0; j < 8; j++)
3672 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
3674 for (j = 0; j < 8; j++)
3675 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
3677 for (j = 0; j < 8; j++)
3678 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3682 dispc_runtime_put();
3688 /* calculate clock rates using dividers in cinfo */
3689 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3690 struct dispc_clock_info *cinfo)
3692 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3694 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3697 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3698 cinfo->pck = cinfo->lck / cinfo->pck_div;
3703 bool dispc_div_calc(unsigned long dispc,
3704 unsigned long pck_min, unsigned long pck_max,
3705 dispc_div_calc_func func, void *data)
3707 int lckd, lckd_start, lckd_stop;
3708 int pckd, pckd_start, pckd_stop;
3709 unsigned long pck, lck;
3710 unsigned long lck_max;
3711 unsigned long pckd_hw_min, pckd_hw_max;
3712 unsigned min_fck_per_pck;
3715 #ifdef CONFIG_FB_OMAP2_DSS_MIN_FCK_PER_PCK
3716 min_fck_per_pck = CONFIG_FB_OMAP2_DSS_MIN_FCK_PER_PCK;
3718 min_fck_per_pck = 0;
3721 pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3722 pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3724 lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3726 pck_min = pck_min ? pck_min : 1;
3727 pck_max = pck_max ? pck_max : ULONG_MAX;
3729 lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3730 lckd_stop = min(dispc / pck_min, 255ul);
3732 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3735 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3736 pckd_stop = min(lck / pck_min, pckd_hw_max);
3738 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3742 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3743 * clock, which means we're configuring DISPC fclk here
3744 * also. Thus we need to use the calculated lck. For
3745 * OMAP4+ the DISPC fclk is a separate clock.
3747 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3748 fck = dispc_core_clk_rate();
3752 if (fck < pck * min_fck_per_pck)
3755 if (func(lckd, pckd, lck, pck, data))
3763 void dispc_mgr_set_clock_div(enum omap_channel channel,
3764 const struct dispc_clock_info *cinfo)
3766 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3767 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3769 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
3772 int dispc_mgr_get_clock_div(enum omap_channel channel,
3773 struct dispc_clock_info *cinfo)
3777 fck = dispc_fclk_rate();
3779 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3780 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
3782 cinfo->lck = fck / cinfo->lck_div;
3783 cinfo->pck = cinfo->lck / cinfo->pck_div;
3788 u32 dispc_read_irqstatus(void)
3790 return dispc_read_reg(DISPC_IRQSTATUS);
3792 EXPORT_SYMBOL(dispc_read_irqstatus);
3794 void dispc_clear_irqstatus(u32 mask)
3796 dispc_write_reg(DISPC_IRQSTATUS, mask);
3798 EXPORT_SYMBOL(dispc_clear_irqstatus);
3800 u32 dispc_read_irqenable(void)
3802 return dispc_read_reg(DISPC_IRQENABLE);
3804 EXPORT_SYMBOL(dispc_read_irqenable);
3806 void dispc_write_irqenable(u32 mask)
3808 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3810 /* clear the irqstatus for newly enabled irqs */
3811 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3813 dispc_write_reg(DISPC_IRQENABLE, mask);
3815 EXPORT_SYMBOL(dispc_write_irqenable);
3817 void dispc_enable_sidle(void)
3819 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3822 void dispc_disable_sidle(void)
3824 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3827 static void _omap_dispc_initial_config(void)
3831 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3832 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3833 l = dispc_read_reg(DISPC_DIVISOR);
3834 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3835 l = FLD_MOD(l, 1, 0, 0);
3836 l = FLD_MOD(l, 1, 23, 16);
3837 dispc_write_reg(DISPC_DIVISOR, l);
3839 dispc.core_clk_rate = dispc_fclk_rate();
3843 if (dss_has_feature(FEAT_FUNCGATED))
3844 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3846 dispc_setup_color_conv_coef();
3848 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3852 dispc_configure_burst_sizes();
3854 dispc_ovl_enable_zorder_planes();
3856 if (dispc.feat->mstandby_workaround)
3857 REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
3859 if (dss_has_feature(FEAT_MFLAG))
3863 static const struct dispc_features omap24xx_dispc_feats = {
3870 .mgr_width_start = 10,
3871 .mgr_height_start = 26,
3872 .mgr_width_max = 2048,
3873 .mgr_height_max = 2048,
3874 .max_lcd_pclk = 66500000,
3875 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3876 .calc_core_clk = calc_core_clk_24xx,
3878 .no_framedone_tv = true,
3879 .set_max_preload = false,
3880 .last_pixel_inc_missing = true,
3883 static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
3890 .mgr_width_start = 10,
3891 .mgr_height_start = 26,
3892 .mgr_width_max = 2048,
3893 .mgr_height_max = 2048,
3894 .max_lcd_pclk = 173000000,
3895 .max_tv_pclk = 59000000,
3896 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3897 .calc_core_clk = calc_core_clk_34xx,
3899 .no_framedone_tv = true,
3900 .set_max_preload = false,
3901 .last_pixel_inc_missing = true,
3904 static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
3911 .mgr_width_start = 10,
3912 .mgr_height_start = 26,
3913 .mgr_width_max = 2048,
3914 .mgr_height_max = 2048,
3915 .max_lcd_pclk = 173000000,
3916 .max_tv_pclk = 59000000,
3917 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3918 .calc_core_clk = calc_core_clk_34xx,
3920 .no_framedone_tv = true,
3921 .set_max_preload = false,
3922 .last_pixel_inc_missing = true,
3925 static const struct dispc_features omap44xx_dispc_feats = {
3932 .mgr_width_start = 10,
3933 .mgr_height_start = 26,
3934 .mgr_width_max = 2048,
3935 .mgr_height_max = 2048,
3936 .max_lcd_pclk = 170000000,
3937 .max_tv_pclk = 185625000,
3938 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3939 .calc_core_clk = calc_core_clk_44xx,
3941 .gfx_fifo_workaround = true,
3942 .set_max_preload = true,
3943 .supports_sync_align = true,
3944 .has_writeback = true,
3947 static const struct dispc_features omap54xx_dispc_feats = {
3954 .mgr_width_start = 11,
3955 .mgr_height_start = 27,
3956 .mgr_width_max = 4096,
3957 .mgr_height_max = 4096,
3958 .max_lcd_pclk = 170000000,
3959 .max_tv_pclk = 186000000,
3960 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3961 .calc_core_clk = calc_core_clk_44xx,
3963 .gfx_fifo_workaround = true,
3964 .mstandby_workaround = true,
3965 .set_max_preload = true,
3966 .supports_sync_align = true,
3967 .has_writeback = true,
3970 static const struct dispc_features *dispc_get_features(void)
3972 switch (omapdss_get_version()) {
3973 case OMAPDSS_VER_OMAP24xx:
3974 return &omap24xx_dispc_feats;
3976 case OMAPDSS_VER_OMAP34xx_ES1:
3977 return &omap34xx_rev1_0_dispc_feats;
3979 case OMAPDSS_VER_OMAP34xx_ES3:
3980 case OMAPDSS_VER_OMAP3630:
3981 case OMAPDSS_VER_AM35xx:
3982 case OMAPDSS_VER_AM43xx:
3983 return &omap34xx_rev3_0_dispc_feats;
3985 case OMAPDSS_VER_OMAP4430_ES1:
3986 case OMAPDSS_VER_OMAP4430_ES2:
3987 case OMAPDSS_VER_OMAP4:
3988 return &omap44xx_dispc_feats;
3990 case OMAPDSS_VER_OMAP5:
3991 case OMAPDSS_VER_DRA7xx:
3992 return &omap54xx_dispc_feats;
3999 static irqreturn_t dispc_irq_handler(int irq, void *arg)
4001 if (!dispc.is_enabled)
4004 return dispc.user_handler(irq, dispc.user_data);
4007 int dispc_request_irq(irq_handler_t handler, void *dev_id)
4011 if (dispc.user_handler != NULL)
4014 dispc.user_handler = handler;
4015 dispc.user_data = dev_id;
4017 /* ensure the dispc_irq_handler sees the values above */
4020 r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
4021 IRQF_SHARED, "OMAP DISPC", &dispc);
4023 dispc.user_handler = NULL;
4024 dispc.user_data = NULL;
4029 EXPORT_SYMBOL(dispc_request_irq);
4031 void dispc_free_irq(void *dev_id)
4033 devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
4035 dispc.user_handler = NULL;
4036 dispc.user_data = NULL;
4038 EXPORT_SYMBOL(dispc_free_irq);
4040 /* DISPC HW IP initialisation */
4041 static int dispc_bind(struct device *dev, struct device *master, void *data)
4043 struct platform_device *pdev = to_platform_device(dev);
4046 struct resource *dispc_mem;
4047 struct device_node *np = pdev->dev.of_node;
4051 spin_lock_init(&dispc.control_lock);
4053 dispc.feat = dispc_get_features();
4057 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
4059 DSSERR("can't get IORESOURCE_MEM DISPC\n");
4063 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
4064 resource_size(dispc_mem));
4066 DSSERR("can't ioremap DISPC\n");
4070 dispc.irq = platform_get_irq(dispc.pdev, 0);
4071 if (dispc.irq < 0) {
4072 DSSERR("platform_get_irq failed\n");
4076 if (np && of_property_read_bool(np, "syscon-pol")) {
4077 dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
4078 if (IS_ERR(dispc.syscon_pol)) {
4079 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
4080 return PTR_ERR(dispc.syscon_pol);
4083 if (of_property_read_u32_index(np, "syscon-pol", 1,
4084 &dispc.syscon_pol_offset)) {
4085 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
4090 pm_runtime_enable(&pdev->dev);
4092 r = dispc_runtime_get();
4094 goto err_runtime_get;
4096 _omap_dispc_initial_config();
4098 rev = dispc_read_reg(DISPC_REVISION);
4099 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
4100 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4102 dispc_runtime_put();
4104 dss_init_overlay_managers();
4106 dss_debugfs_create_file("dispc", dispc_dump_regs);
4111 pm_runtime_disable(&pdev->dev);
4115 static void dispc_unbind(struct device *dev, struct device *master,
4118 pm_runtime_disable(dev);
4120 dss_uninit_overlay_managers();
4123 static const struct component_ops dispc_component_ops = {
4125 .unbind = dispc_unbind,
4128 static int dispc_probe(struct platform_device *pdev)
4130 return component_add(&pdev->dev, &dispc_component_ops);
4133 static int dispc_remove(struct platform_device *pdev)
4135 component_del(&pdev->dev, &dispc_component_ops);
4139 static int dispc_runtime_suspend(struct device *dev)
4141 dispc.is_enabled = false;
4142 /* ensure the dispc_irq_handler sees the is_enabled value */
4144 /* wait for current handler to finish before turning the DISPC off */
4145 synchronize_irq(dispc.irq);
4147 dispc_save_context();
4152 static int dispc_runtime_resume(struct device *dev)
4155 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4156 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4157 * _omap_dispc_initial_config(). We can thus use it to detect if
4158 * we have lost register context.
4160 if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4161 _omap_dispc_initial_config();
4163 dispc_restore_context();
4166 dispc.is_enabled = true;
4167 /* ensure the dispc_irq_handler sees the is_enabled value */
4173 static const struct dev_pm_ops dispc_pm_ops = {
4174 .runtime_suspend = dispc_runtime_suspend,
4175 .runtime_resume = dispc_runtime_resume,
4178 static const struct of_device_id dispc_of_match[] = {
4179 { .compatible = "ti,omap2-dispc", },
4180 { .compatible = "ti,omap3-dispc", },
4181 { .compatible = "ti,omap4-dispc", },
4182 { .compatible = "ti,omap5-dispc", },
4183 { .compatible = "ti,dra7-dispc", },
4187 static struct platform_driver omap_dispchw_driver = {
4188 .probe = dispc_probe,
4189 .remove = dispc_remove,
4191 .name = "omapdss_dispc",
4192 .pm = &dispc_pm_ops,
4193 .of_match_table = dispc_of_match,
4194 .suppress_bind_attrs = true,
4198 int __init dispc_init_platform_driver(void)
4200 return platform_driver_register(&omap_dispchw_driver);
4203 void dispc_uninit_platform_driver(void)
4205 platform_driver_unregister(&omap_dispchw_driver);