2 * linux/drivers/video/omap2/dss/dispc.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
23 #define DSS_SUBSYS_NAME "DISPC"
25 #include <linux/kernel.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/vmalloc.h>
28 #include <linux/export.h>
29 #include <linux/clk.h>
31 #include <linux/jiffies.h>
32 #include <linux/seq_file.h>
33 #include <linux/delay.h>
34 #include <linux/workqueue.h>
35 #include <linux/hardirq.h>
36 #include <linux/platform_device.h>
37 #include <linux/pm_runtime.h>
38 #include <linux/sizes.h>
39 #include <linux/mfd/syscon.h>
40 #include <linux/regmap.h>
43 #include <video/omapdss.h>
46 #include "dss_features.h"
50 #define DISPC_SZ_REGS SZ_4K
52 enum omap_burst_size {
58 #define REG_GET(idx, start, end) \
59 FLD_GET(dispc_read_reg(idx), start, end)
61 #define REG_FLD_MOD(idx, val, start, end) \
62 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
64 struct dispc_features {
75 unsigned long max_lcd_pclk;
76 unsigned long max_tv_pclk;
77 int (*calc_scaling) (unsigned long pclk, unsigned long lclk,
78 const struct omap_video_timings *mgr_timings,
79 u16 width, u16 height, u16 out_width, u16 out_height,
80 enum omap_color_mode color_mode, bool *five_taps,
81 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
82 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
83 unsigned long (*calc_core_clk) (unsigned long pclk,
84 u16 width, u16 height, u16 out_width, u16 out_height,
88 /* swap GFX & WB fifos */
89 bool gfx_fifo_workaround:1;
91 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
92 bool no_framedone_tv:1;
94 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
95 bool mstandby_workaround:1;
97 bool set_max_preload:1;
100 #define DISPC_MAX_NR_FIFOS 5
103 struct platform_device *pdev;
107 irq_handler_t user_handler;
110 unsigned long core_clk_rate;
111 unsigned long tv_pclk_rate;
113 u32 fifo_size[DISPC_MAX_NR_FIFOS];
114 /* maps which plane is using a fifo. fifo-id -> plane-id */
115 int fifo_assignment[DISPC_MAX_NR_FIFOS];
118 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
120 const struct dispc_features *feat;
124 struct regmap *syscon_pol;
125 u32 syscon_pol_offset;
127 /* DISPC_CONTROL & DISPC_CONFIG lock*/
128 spinlock_t control_lock;
131 enum omap_color_component {
132 /* used for all color formats for OMAP3 and earlier
133 * and for RGB and Y color component on OMAP4
135 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
136 /* used for UV component for
137 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
138 * color formats on OMAP4
140 DISPC_COLOR_COMPONENT_UV = 1 << 1,
143 enum mgr_reg_fields {
144 DISPC_MGR_FLD_ENABLE,
145 DISPC_MGR_FLD_STNTFT,
147 DISPC_MGR_FLD_TFTDATALINES,
148 DISPC_MGR_FLD_STALLMODE,
149 DISPC_MGR_FLD_TCKENABLE,
150 DISPC_MGR_FLD_TCKSELECTION,
152 DISPC_MGR_FLD_FIFOHANDCHECK,
153 /* used to maintain a count of the above fields */
157 struct dispc_reg_field {
163 static const struct {
168 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
170 [OMAP_DSS_CHANNEL_LCD] = {
172 .vsync_irq = DISPC_IRQ_VSYNC,
173 .framedone_irq = DISPC_IRQ_FRAMEDONE,
174 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
176 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
177 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
178 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
179 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
180 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
181 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
182 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
183 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
184 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
187 [OMAP_DSS_CHANNEL_DIGIT] = {
189 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
190 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
191 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
193 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
194 [DISPC_MGR_FLD_STNTFT] = { },
195 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
196 [DISPC_MGR_FLD_TFTDATALINES] = { },
197 [DISPC_MGR_FLD_STALLMODE] = { },
198 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
199 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
200 [DISPC_MGR_FLD_CPR] = { },
201 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
204 [OMAP_DSS_CHANNEL_LCD2] = {
206 .vsync_irq = DISPC_IRQ_VSYNC2,
207 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
208 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
210 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
211 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
212 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
213 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
214 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
215 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
216 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
217 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
218 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
221 [OMAP_DSS_CHANNEL_LCD3] = {
223 .vsync_irq = DISPC_IRQ_VSYNC3,
224 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
225 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
227 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
228 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
229 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
230 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
231 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
232 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
233 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
234 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
235 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
240 struct color_conv_coef {
241 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
245 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
246 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
248 static inline void dispc_write_reg(const u16 idx, u32 val)
250 __raw_writel(val, dispc.base + idx);
253 static inline u32 dispc_read_reg(const u16 idx)
255 return __raw_readl(dispc.base + idx);
258 static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
260 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
261 return REG_GET(rfld.reg, rfld.high, rfld.low);
264 static void mgr_fld_write(enum omap_channel channel,
265 enum mgr_reg_fields regfld, int val) {
266 const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld];
267 const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG;
271 spin_lock_irqsave(&dispc.control_lock, flags);
273 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
276 spin_unlock_irqrestore(&dispc.control_lock, flags);
280 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
282 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
284 static void dispc_save_context(void)
288 DSSDBG("dispc_save_context\n");
294 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
295 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
297 if (dss_has_feature(FEAT_MGR_LCD2)) {
301 if (dss_has_feature(FEAT_MGR_LCD3)) {
306 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
307 SR(DEFAULT_COLOR(i));
310 if (i == OMAP_DSS_CHANNEL_DIGIT)
321 if (dss_has_feature(FEAT_CPR)) {
328 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
333 SR(OVL_ATTRIBUTES(i));
334 SR(OVL_FIFO_THRESHOLD(i));
336 SR(OVL_PIXEL_INC(i));
337 if (dss_has_feature(FEAT_PRELOAD))
339 if (i == OMAP_DSS_GFX) {
340 SR(OVL_WINDOW_SKIP(i));
345 SR(OVL_PICTURE_SIZE(i));
349 for (j = 0; j < 8; j++)
350 SR(OVL_FIR_COEF_H(i, j));
352 for (j = 0; j < 8; j++)
353 SR(OVL_FIR_COEF_HV(i, j));
355 for (j = 0; j < 5; j++)
356 SR(OVL_CONV_COEF(i, j));
358 if (dss_has_feature(FEAT_FIR_COEF_V)) {
359 for (j = 0; j < 8; j++)
360 SR(OVL_FIR_COEF_V(i, j));
363 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
370 for (j = 0; j < 8; j++)
371 SR(OVL_FIR_COEF_H2(i, j));
373 for (j = 0; j < 8; j++)
374 SR(OVL_FIR_COEF_HV2(i, j));
376 for (j = 0; j < 8; j++)
377 SR(OVL_FIR_COEF_V2(i, j));
379 if (dss_has_feature(FEAT_ATTR2))
380 SR(OVL_ATTRIBUTES2(i));
383 if (dss_has_feature(FEAT_CORE_CLK_DIV))
386 dispc.ctx_valid = true;
388 DSSDBG("context saved\n");
391 static void dispc_restore_context(void)
395 DSSDBG("dispc_restore_context\n");
397 if (!dispc.ctx_valid)
404 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
405 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
407 if (dss_has_feature(FEAT_MGR_LCD2))
409 if (dss_has_feature(FEAT_MGR_LCD3))
412 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
413 RR(DEFAULT_COLOR(i));
416 if (i == OMAP_DSS_CHANNEL_DIGIT)
427 if (dss_has_feature(FEAT_CPR)) {
434 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
439 RR(OVL_ATTRIBUTES(i));
440 RR(OVL_FIFO_THRESHOLD(i));
442 RR(OVL_PIXEL_INC(i));
443 if (dss_has_feature(FEAT_PRELOAD))
445 if (i == OMAP_DSS_GFX) {
446 RR(OVL_WINDOW_SKIP(i));
451 RR(OVL_PICTURE_SIZE(i));
455 for (j = 0; j < 8; j++)
456 RR(OVL_FIR_COEF_H(i, j));
458 for (j = 0; j < 8; j++)
459 RR(OVL_FIR_COEF_HV(i, j));
461 for (j = 0; j < 5; j++)
462 RR(OVL_CONV_COEF(i, j));
464 if (dss_has_feature(FEAT_FIR_COEF_V)) {
465 for (j = 0; j < 8; j++)
466 RR(OVL_FIR_COEF_V(i, j));
469 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
476 for (j = 0; j < 8; j++)
477 RR(OVL_FIR_COEF_H2(i, j));
479 for (j = 0; j < 8; j++)
480 RR(OVL_FIR_COEF_HV2(i, j));
482 for (j = 0; j < 8; j++)
483 RR(OVL_FIR_COEF_V2(i, j));
485 if (dss_has_feature(FEAT_ATTR2))
486 RR(OVL_ATTRIBUTES2(i));
489 if (dss_has_feature(FEAT_CORE_CLK_DIV))
492 /* enable last, because LCD & DIGIT enable are here */
494 if (dss_has_feature(FEAT_MGR_LCD2))
496 if (dss_has_feature(FEAT_MGR_LCD3))
498 /* clear spurious SYNC_LOST_DIGIT interrupts */
499 dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT);
502 * enable last so IRQs won't trigger before
503 * the context is fully restored
507 DSSDBG("context restored\n");
513 int dispc_runtime_get(void)
517 DSSDBG("dispc_runtime_get\n");
519 r = pm_runtime_get_sync(&dispc.pdev->dev);
521 return r < 0 ? r : 0;
523 EXPORT_SYMBOL(dispc_runtime_get);
525 void dispc_runtime_put(void)
529 DSSDBG("dispc_runtime_put\n");
531 r = pm_runtime_put_sync(&dispc.pdev->dev);
532 WARN_ON(r < 0 && r != -ENOSYS);
534 EXPORT_SYMBOL(dispc_runtime_put);
536 u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
538 return mgr_desc[channel].vsync_irq;
540 EXPORT_SYMBOL(dispc_mgr_get_vsync_irq);
542 u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
544 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv)
547 return mgr_desc[channel].framedone_irq;
549 EXPORT_SYMBOL(dispc_mgr_get_framedone_irq);
551 u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel)
553 return mgr_desc[channel].sync_lost_irq;
555 EXPORT_SYMBOL(dispc_mgr_get_sync_lost_irq);
557 u32 dispc_wb_get_framedone_irq(void)
559 return DISPC_IRQ_FRAMEDONEWB;
562 bool dispc_mgr_go_busy(enum omap_channel channel)
564 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
566 EXPORT_SYMBOL(dispc_mgr_go_busy);
568 void dispc_mgr_go(enum omap_channel channel)
570 WARN_ON(dispc_mgr_is_enabled(channel) == false);
571 WARN_ON(dispc_mgr_go_busy(channel));
573 DSSDBG("GO %s\n", mgr_desc[channel].name);
575 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
577 EXPORT_SYMBOL(dispc_mgr_go);
579 bool dispc_wb_go_busy(void)
581 return REG_GET(DISPC_CONTROL2, 6, 6) == 1;
584 void dispc_wb_go(void)
586 enum omap_plane plane = OMAP_DSS_WB;
589 enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
594 go = REG_GET(DISPC_CONTROL2, 6, 6) == 1;
596 DSSERR("GO bit not down for WB\n");
600 REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6);
603 static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
605 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
608 static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
610 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
613 static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
615 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
618 static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
620 BUG_ON(plane == OMAP_DSS_GFX);
622 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
625 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
628 BUG_ON(plane == OMAP_DSS_GFX);
630 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
633 static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
635 BUG_ON(plane == OMAP_DSS_GFX);
637 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
640 static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
641 int fir_vinc, int five_taps,
642 enum omap_color_component color_comp)
644 const struct dispc_coef *h_coef, *v_coef;
647 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
648 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
650 for (i = 0; i < 8; i++) {
653 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
654 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
655 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
656 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
657 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
658 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
659 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
660 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
662 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
663 dispc_ovl_write_firh_reg(plane, i, h);
664 dispc_ovl_write_firhv_reg(plane, i, hv);
666 dispc_ovl_write_firh2_reg(plane, i, h);
667 dispc_ovl_write_firhv2_reg(plane, i, hv);
673 for (i = 0; i < 8; i++) {
675 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
676 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
677 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
678 dispc_ovl_write_firv_reg(plane, i, v);
680 dispc_ovl_write_firv2_reg(plane, i, v);
686 static void dispc_ovl_write_color_conv_coef(enum omap_plane plane,
687 const struct color_conv_coef *ct)
689 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
691 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
692 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
693 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
694 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
695 dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
697 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
702 static void dispc_setup_color_conv_coef(void)
705 int num_ovl = dss_feat_get_num_ovls();
706 int num_wb = dss_feat_get_num_wbs();
707 const struct color_conv_coef ctbl_bt601_5_ovl = {
708 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
710 const struct color_conv_coef ctbl_bt601_5_wb = {
711 66, 112, -38, 129, -94, -74, 25, -18, 112, 0,
714 for (i = 1; i < num_ovl; i++)
715 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl);
717 for (; i < num_wb; i++)
718 dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_wb);
721 static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
723 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
726 static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
728 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
731 static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
733 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
736 static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
738 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
741 static void dispc_ovl_set_pos(enum omap_plane plane,
742 enum omap_overlay_caps caps, int x, int y)
746 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
749 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
751 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
754 static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
757 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
759 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
760 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
762 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
765 static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
770 BUG_ON(plane == OMAP_DSS_GFX);
772 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
774 if (plane == OMAP_DSS_WB)
775 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
777 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
780 static void dispc_ovl_set_zorder(enum omap_plane plane,
781 enum omap_overlay_caps caps, u8 zorder)
783 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
786 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
789 static void dispc_ovl_enable_zorder_planes(void)
793 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
796 for (i = 0; i < dss_feat_get_num_ovls(); i++)
797 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
800 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
801 enum omap_overlay_caps caps, bool enable)
803 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
806 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
809 static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
810 enum omap_overlay_caps caps, u8 global_alpha)
812 static const unsigned shifts[] = { 0, 8, 16, 24, };
815 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
818 shift = shifts[plane];
819 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
822 static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
824 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
827 static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
829 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
832 static void dispc_ovl_set_color_mode(enum omap_plane plane,
833 enum omap_color_mode color_mode)
836 if (plane != OMAP_DSS_GFX) {
837 switch (color_mode) {
838 case OMAP_DSS_COLOR_NV12:
840 case OMAP_DSS_COLOR_RGBX16:
842 case OMAP_DSS_COLOR_RGBA16:
844 case OMAP_DSS_COLOR_RGB12U:
846 case OMAP_DSS_COLOR_ARGB16:
848 case OMAP_DSS_COLOR_RGB16:
850 case OMAP_DSS_COLOR_ARGB16_1555:
852 case OMAP_DSS_COLOR_RGB24U:
854 case OMAP_DSS_COLOR_RGB24P:
856 case OMAP_DSS_COLOR_YUV2:
858 case OMAP_DSS_COLOR_UYVY:
860 case OMAP_DSS_COLOR_ARGB32:
862 case OMAP_DSS_COLOR_RGBA32:
864 case OMAP_DSS_COLOR_RGBX32:
866 case OMAP_DSS_COLOR_XRGB16_1555:
872 switch (color_mode) {
873 case OMAP_DSS_COLOR_CLUT1:
875 case OMAP_DSS_COLOR_CLUT2:
877 case OMAP_DSS_COLOR_CLUT4:
879 case OMAP_DSS_COLOR_CLUT8:
881 case OMAP_DSS_COLOR_RGB12U:
883 case OMAP_DSS_COLOR_ARGB16:
885 case OMAP_DSS_COLOR_RGB16:
887 case OMAP_DSS_COLOR_ARGB16_1555:
889 case OMAP_DSS_COLOR_RGB24U:
891 case OMAP_DSS_COLOR_RGB24P:
893 case OMAP_DSS_COLOR_RGBX16:
895 case OMAP_DSS_COLOR_RGBA16:
897 case OMAP_DSS_COLOR_ARGB32:
899 case OMAP_DSS_COLOR_RGBA32:
901 case OMAP_DSS_COLOR_RGBX32:
903 case OMAP_DSS_COLOR_XRGB16_1555:
910 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
913 static void dispc_ovl_configure_burst_type(enum omap_plane plane,
914 enum omap_dss_rotation_type rotation_type)
916 if (dss_has_feature(FEAT_BURST_2D) == 0)
919 if (rotation_type == OMAP_DSS_ROT_TILER)
920 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
922 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
925 void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
929 int chan = 0, chan2 = 0;
935 case OMAP_DSS_VIDEO1:
936 case OMAP_DSS_VIDEO2:
937 case OMAP_DSS_VIDEO3:
945 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
946 if (dss_has_feature(FEAT_MGR_LCD2)) {
948 case OMAP_DSS_CHANNEL_LCD:
952 case OMAP_DSS_CHANNEL_DIGIT:
956 case OMAP_DSS_CHANNEL_LCD2:
960 case OMAP_DSS_CHANNEL_LCD3:
961 if (dss_has_feature(FEAT_MGR_LCD3)) {
974 val = FLD_MOD(val, chan, shift, shift);
975 val = FLD_MOD(val, chan2, 31, 30);
977 val = FLD_MOD(val, channel, shift, shift);
979 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
981 EXPORT_SYMBOL(dispc_ovl_set_channel_out);
983 static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
987 enum omap_channel channel;
993 case OMAP_DSS_VIDEO1:
994 case OMAP_DSS_VIDEO2:
995 case OMAP_DSS_VIDEO3:
1003 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1005 if (dss_has_feature(FEAT_MGR_LCD3)) {
1006 if (FLD_GET(val, 31, 30) == 0)
1007 channel = FLD_GET(val, shift, shift);
1008 else if (FLD_GET(val, 31, 30) == 1)
1009 channel = OMAP_DSS_CHANNEL_LCD2;
1011 channel = OMAP_DSS_CHANNEL_LCD3;
1012 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
1013 if (FLD_GET(val, 31, 30) == 0)
1014 channel = FLD_GET(val, shift, shift);
1016 channel = OMAP_DSS_CHANNEL_LCD2;
1018 channel = FLD_GET(val, shift, shift);
1024 void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
1026 enum omap_plane plane = OMAP_DSS_WB;
1028 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
1031 static void dispc_ovl_set_burst_size(enum omap_plane plane,
1032 enum omap_burst_size burst_size)
1034 static const unsigned shifts[] = { 6, 14, 14, 14, 14, };
1037 shift = shifts[plane];
1038 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
1041 static void dispc_configure_burst_sizes(void)
1044 const int burst_size = BURST_SIZE_X8;
1046 /* Configure burst size always to maximum size */
1047 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
1048 dispc_ovl_set_burst_size(i, burst_size);
1051 static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
1053 unsigned unit = dss_feat_get_burst_size_unit();
1054 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1058 void dispc_enable_gamma_table(bool enable)
1061 * This is partially implemented to support only disabling of
1065 DSSWARN("Gamma table enabling for TV not yet supported");
1069 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1072 static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
1074 if (channel == OMAP_DSS_CHANNEL_DIGIT)
1077 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
1080 static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
1081 const struct omap_dss_cpr_coefs *coefs)
1083 u32 coef_r, coef_g, coef_b;
1085 if (!dss_mgr_is_lcd(channel))
1088 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1089 FLD_VAL(coefs->rb, 9, 0);
1090 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1091 FLD_VAL(coefs->gb, 9, 0);
1092 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1093 FLD_VAL(coefs->bb, 9, 0);
1095 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1096 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1097 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1100 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
1104 BUG_ON(plane == OMAP_DSS_GFX);
1106 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1107 val = FLD_MOD(val, enable, 9, 9);
1108 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
1111 static void dispc_ovl_enable_replication(enum omap_plane plane,
1112 enum omap_overlay_caps caps, bool enable)
1114 static const unsigned shifts[] = { 5, 10, 10, 10 };
1117 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1120 shift = shifts[plane];
1121 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
1124 static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
1129 val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) |
1130 FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0);
1132 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
1135 static void dispc_init_fifos(void)
1143 unit = dss_feat_get_buffer_size_unit();
1145 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1147 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1148 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
1150 dispc.fifo_size[fifo] = size;
1153 * By default fifos are mapped directly to overlays, fifo 0 to
1154 * ovl 0, fifo 1 to ovl 1, etc.
1156 dispc.fifo_assignment[fifo] = fifo;
1160 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1161 * causes problems with certain use cases, like using the tiler in 2D
1162 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1163 * giving GFX plane a larger fifo. WB but should work fine with a
1166 if (dispc.feat->gfx_fifo_workaround) {
1169 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1171 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1172 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1173 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1174 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1176 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1178 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1179 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1183 * Setup default fifo thresholds.
1185 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1187 const bool use_fifomerge = false;
1188 const bool manual_update = false;
1190 dispc_ovl_compute_fifo_thresholds(i, &low, &high,
1191 use_fifomerge, manual_update);
1193 dispc_ovl_set_fifo_threshold(i, low, high);
1197 static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1202 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1203 if (dispc.fifo_assignment[fifo] == plane)
1204 size += dispc.fifo_size[fifo];
1210 void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
1212 u8 hi_start, hi_end, lo_start, lo_end;
1215 unit = dss_feat_get_buffer_size_unit();
1217 WARN_ON(low % unit != 0);
1218 WARN_ON(high % unit != 0);
1223 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1224 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1226 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1228 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1229 lo_start, lo_end) * unit,
1230 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1231 hi_start, hi_end) * unit,
1232 low * unit, high * unit);
1234 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1235 FLD_VAL(high, hi_start, hi_end) |
1236 FLD_VAL(low, lo_start, lo_end));
1239 * configure the preload to the pipeline's high threhold, if HT it's too
1240 * large for the preload field, set the threshold to the maximum value
1241 * that can be held by the preload register
1243 if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload &&
1244 plane != OMAP_DSS_WB)
1245 dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu));
1247 EXPORT_SYMBOL(dispc_ovl_set_fifo_threshold);
1249 void dispc_enable_fifomerge(bool enable)
1251 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1256 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1257 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1260 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1261 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1265 * All sizes are in bytes. Both the buffer and burst are made of
1266 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1269 unsigned buf_unit = dss_feat_get_buffer_size_unit();
1270 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1273 burst_size = dispc_ovl_get_burst_size(plane);
1274 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
1276 if (use_fifomerge) {
1277 total_fifo_size = 0;
1278 for (i = 0; i < dss_feat_get_num_ovls(); ++i)
1279 total_fifo_size += dispc_ovl_get_fifo_size(i);
1281 total_fifo_size = ovl_fifo_size;
1285 * We use the same low threshold for both fifomerge and non-fifomerge
1286 * cases, but for fifomerge we calculate the high threshold using the
1287 * combined fifo size
1290 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1291 *fifo_low = ovl_fifo_size - burst_size * 2;
1292 *fifo_high = total_fifo_size - burst_size;
1293 } else if (plane == OMAP_DSS_WB) {
1295 * Most optimal configuration for writeback is to push out data
1296 * to the interconnect the moment writeback pushes enough pixels
1297 * in the FIFO to form a burst
1300 *fifo_high = burst_size;
1302 *fifo_low = ovl_fifo_size - burst_size;
1303 *fifo_high = total_fifo_size - buf_unit;
1306 EXPORT_SYMBOL(dispc_ovl_compute_fifo_thresholds);
1308 static void dispc_ovl_set_mflag(enum omap_plane plane, bool enable)
1312 if (plane == OMAP_DSS_GFX)
1317 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1320 static void dispc_ovl_set_mflag_threshold(enum omap_plane plane,
1323 dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane),
1324 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1327 static void dispc_init_mflag(void)
1332 * HACK: NV12 color format and MFLAG seem to have problems working
1333 * together: using two displays, and having an NV12 overlay on one of
1334 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1335 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1336 * remove the errors, but there doesn't seem to be a clear logic on
1337 * which values work and which not.
1339 * As a work-around, set force MFLAG to always on.
1341 dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE,
1342 (1 << 0) | /* MFLAG_CTRL = force always on */
1343 (0 << 2)); /* MFLAG_START = disable */
1345 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
1346 u32 size = dispc_ovl_get_fifo_size(i);
1347 u32 unit = dss_feat_get_buffer_size_unit();
1350 dispc_ovl_set_mflag(i, true);
1353 * Simulation team suggests below thesholds:
1354 * HT = fifosize * 5 / 8;
1355 * LT = fifosize * 4 / 8;
1358 low = size * 4 / 8 / unit;
1359 high = size * 5 / 8 / unit;
1361 dispc_ovl_set_mflag_threshold(i, low, high);
1365 static void dispc_ovl_set_fir(enum omap_plane plane,
1367 enum omap_color_component color_comp)
1371 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1372 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1374 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1375 &hinc_start, &hinc_end);
1376 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1377 &vinc_start, &vinc_end);
1378 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1379 FLD_VAL(hinc, hinc_start, hinc_end);
1381 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1383 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1384 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1388 static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1391 u8 hor_start, hor_end, vert_start, vert_end;
1393 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1394 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1396 val = FLD_VAL(vaccu, vert_start, vert_end) |
1397 FLD_VAL(haccu, hor_start, hor_end);
1399 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1402 static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1405 u8 hor_start, hor_end, vert_start, vert_end;
1407 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1408 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1410 val = FLD_VAL(vaccu, vert_start, vert_end) |
1411 FLD_VAL(haccu, hor_start, hor_end);
1413 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1416 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1421 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1422 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1425 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1430 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1431 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1434 static void dispc_ovl_set_scale_param(enum omap_plane plane,
1435 u16 orig_width, u16 orig_height,
1436 u16 out_width, u16 out_height,
1437 bool five_taps, u8 rotation,
1438 enum omap_color_component color_comp)
1440 int fir_hinc, fir_vinc;
1442 fir_hinc = 1024 * orig_width / out_width;
1443 fir_vinc = 1024 * orig_height / out_height;
1445 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1447 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1450 static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1451 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1452 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1454 int h_accu2_0, h_accu2_1;
1455 int v_accu2_0, v_accu2_1;
1456 int chroma_hinc, chroma_vinc;
1466 const struct accu *accu_table;
1467 const struct accu *accu_val;
1469 static const struct accu accu_nv12[4] = {
1470 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1471 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1472 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1473 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1476 static const struct accu accu_nv12_ilace[4] = {
1477 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1478 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1479 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1480 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1483 static const struct accu accu_yuv[4] = {
1484 { 0, 1, 0, 1, 0, 1, 0, 1 },
1485 { 0, 1, 0, 1, 0, 1, 0, 1 },
1486 { -1, 1, 0, 1, 0, 1, 0, 1 },
1487 { 0, 1, 0, 1, -1, 1, 0, 1 },
1491 case OMAP_DSS_ROT_0:
1494 case OMAP_DSS_ROT_90:
1497 case OMAP_DSS_ROT_180:
1500 case OMAP_DSS_ROT_270:
1508 switch (color_mode) {
1509 case OMAP_DSS_COLOR_NV12:
1511 accu_table = accu_nv12_ilace;
1513 accu_table = accu_nv12;
1515 case OMAP_DSS_COLOR_YUV2:
1516 case OMAP_DSS_COLOR_UYVY:
1517 accu_table = accu_yuv;
1524 accu_val = &accu_table[idx];
1526 chroma_hinc = 1024 * orig_width / out_width;
1527 chroma_vinc = 1024 * orig_height / out_height;
1529 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1530 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1531 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1532 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1534 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1535 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1538 static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1539 u16 orig_width, u16 orig_height,
1540 u16 out_width, u16 out_height,
1541 bool ilace, bool five_taps,
1542 bool fieldmode, enum omap_color_mode color_mode,
1549 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1550 out_width, out_height, five_taps,
1551 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1552 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1554 /* RESIZEENABLE and VERTICALTAPS */
1555 l &= ~((0x3 << 5) | (0x1 << 21));
1556 l |= (orig_width != out_width) ? (1 << 5) : 0;
1557 l |= (orig_height != out_height) ? (1 << 6) : 0;
1558 l |= five_taps ? (1 << 21) : 0;
1560 /* VRESIZECONF and HRESIZECONF */
1561 if (dss_has_feature(FEAT_RESIZECONF)) {
1563 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1564 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1567 /* LINEBUFFERSPLIT */
1568 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1570 l |= five_taps ? (1 << 22) : 0;
1573 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1576 * field 0 = even field = bottom field
1577 * field 1 = odd field = top field
1579 if (ilace && !fieldmode) {
1581 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1582 if (accu0 >= 1024/2) {
1588 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1589 dispc_ovl_set_vid_accu1(plane, 0, accu1);
1592 static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1593 u16 orig_width, u16 orig_height,
1594 u16 out_width, u16 out_height,
1595 bool ilace, bool five_taps,
1596 bool fieldmode, enum omap_color_mode color_mode,
1599 int scale_x = out_width != orig_width;
1600 int scale_y = out_height != orig_height;
1601 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
1603 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1605 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1606 color_mode != OMAP_DSS_COLOR_UYVY &&
1607 color_mode != OMAP_DSS_COLOR_NV12)) {
1608 /* reset chroma resampling for RGB formats */
1609 if (plane != OMAP_DSS_WB)
1610 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1614 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1615 out_height, ilace, color_mode, rotation);
1617 switch (color_mode) {
1618 case OMAP_DSS_COLOR_NV12:
1619 if (chroma_upscale) {
1620 /* UV is subsampled by 2 horizontally and vertically */
1624 /* UV is downsampled by 2 horizontally and vertically */
1630 case OMAP_DSS_COLOR_YUV2:
1631 case OMAP_DSS_COLOR_UYVY:
1632 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
1633 if (rotation == OMAP_DSS_ROT_0 ||
1634 rotation == OMAP_DSS_ROT_180) {
1636 /* UV is subsampled by 2 horizontally */
1639 /* UV is downsampled by 2 horizontally */
1643 /* must use FIR for YUV422 if rotated */
1644 if (rotation != OMAP_DSS_ROT_0)
1645 scale_x = scale_y = true;
1653 if (out_width != orig_width)
1655 if (out_height != orig_height)
1658 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1659 out_width, out_height, five_taps,
1660 rotation, DISPC_COLOR_COMPONENT_UV);
1662 if (plane != OMAP_DSS_WB)
1663 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1664 (scale_x || scale_y) ? 1 : 0, 8, 8);
1667 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1669 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1672 static void dispc_ovl_set_scaling(enum omap_plane plane,
1673 u16 orig_width, u16 orig_height,
1674 u16 out_width, u16 out_height,
1675 bool ilace, bool five_taps,
1676 bool fieldmode, enum omap_color_mode color_mode,
1679 BUG_ON(plane == OMAP_DSS_GFX);
1681 dispc_ovl_set_scaling_common(plane,
1682 orig_width, orig_height,
1683 out_width, out_height,
1685 fieldmode, color_mode,
1688 dispc_ovl_set_scaling_uv(plane,
1689 orig_width, orig_height,
1690 out_width, out_height,
1692 fieldmode, color_mode,
1696 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1697 enum omap_dss_rotation_type rotation_type,
1698 bool mirroring, enum omap_color_mode color_mode)
1700 bool row_repeat = false;
1703 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1704 color_mode == OMAP_DSS_COLOR_UYVY) {
1708 case OMAP_DSS_ROT_0:
1711 case OMAP_DSS_ROT_90:
1714 case OMAP_DSS_ROT_180:
1717 case OMAP_DSS_ROT_270:
1723 case OMAP_DSS_ROT_0:
1726 case OMAP_DSS_ROT_90:
1729 case OMAP_DSS_ROT_180:
1732 case OMAP_DSS_ROT_270:
1738 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1744 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1745 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1746 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1747 row_repeat ? 1 : 0, 18, 18);
1749 if (color_mode == OMAP_DSS_COLOR_NV12) {
1750 bool doublestride = (rotation_type == OMAP_DSS_ROT_TILER) &&
1751 (rotation == OMAP_DSS_ROT_0 ||
1752 rotation == OMAP_DSS_ROT_180);
1754 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22);
1759 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1761 switch (color_mode) {
1762 case OMAP_DSS_COLOR_CLUT1:
1764 case OMAP_DSS_COLOR_CLUT2:
1766 case OMAP_DSS_COLOR_CLUT4:
1768 case OMAP_DSS_COLOR_CLUT8:
1769 case OMAP_DSS_COLOR_NV12:
1771 case OMAP_DSS_COLOR_RGB12U:
1772 case OMAP_DSS_COLOR_RGB16:
1773 case OMAP_DSS_COLOR_ARGB16:
1774 case OMAP_DSS_COLOR_YUV2:
1775 case OMAP_DSS_COLOR_UYVY:
1776 case OMAP_DSS_COLOR_RGBA16:
1777 case OMAP_DSS_COLOR_RGBX16:
1778 case OMAP_DSS_COLOR_ARGB16_1555:
1779 case OMAP_DSS_COLOR_XRGB16_1555:
1781 case OMAP_DSS_COLOR_RGB24P:
1783 case OMAP_DSS_COLOR_RGB24U:
1784 case OMAP_DSS_COLOR_ARGB32:
1785 case OMAP_DSS_COLOR_RGBA32:
1786 case OMAP_DSS_COLOR_RGBX32:
1794 static s32 pixinc(int pixels, u8 ps)
1798 else if (pixels > 1)
1799 return 1 + (pixels - 1) * ps;
1800 else if (pixels < 0)
1801 return 1 - (-pixels + 1) * ps;
1807 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1809 u16 width, u16 height,
1810 enum omap_color_mode color_mode, bool fieldmode,
1811 unsigned int field_offset,
1812 unsigned *offset0, unsigned *offset1,
1813 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1817 /* FIXME CLUT formats */
1818 switch (color_mode) {
1819 case OMAP_DSS_COLOR_CLUT1:
1820 case OMAP_DSS_COLOR_CLUT2:
1821 case OMAP_DSS_COLOR_CLUT4:
1822 case OMAP_DSS_COLOR_CLUT8:
1825 case OMAP_DSS_COLOR_YUV2:
1826 case OMAP_DSS_COLOR_UYVY:
1830 ps = color_mode_to_bpp(color_mode) / 8;
1834 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1838 * field 0 = even field = bottom field
1839 * field 1 = odd field = top field
1841 switch (rotation + mirror * 4) {
1842 case OMAP_DSS_ROT_0:
1843 case OMAP_DSS_ROT_180:
1845 * If the pixel format is YUV or UYVY divide the width
1846 * of the image by 2 for 0 and 180 degree rotation.
1848 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1849 color_mode == OMAP_DSS_COLOR_UYVY)
1851 case OMAP_DSS_ROT_90:
1852 case OMAP_DSS_ROT_270:
1855 *offset0 = field_offset * screen_width * ps;
1859 *row_inc = pixinc(1 +
1860 (y_predecim * screen_width - x_predecim * width) +
1861 (fieldmode ? screen_width : 0), ps);
1862 *pix_inc = pixinc(x_predecim, ps);
1865 case OMAP_DSS_ROT_0 + 4:
1866 case OMAP_DSS_ROT_180 + 4:
1867 /* If the pixel format is YUV or UYVY divide the width
1868 * of the image by 2 for 0 degree and 180 degree
1870 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1871 color_mode == OMAP_DSS_COLOR_UYVY)
1873 case OMAP_DSS_ROT_90 + 4:
1874 case OMAP_DSS_ROT_270 + 4:
1877 *offset0 = field_offset * screen_width * ps;
1880 *row_inc = pixinc(1 -
1881 (y_predecim * screen_width + x_predecim * width) -
1882 (fieldmode ? screen_width : 0), ps);
1883 *pix_inc = pixinc(x_predecim, ps);
1892 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1894 u16 width, u16 height,
1895 enum omap_color_mode color_mode, bool fieldmode,
1896 unsigned int field_offset,
1897 unsigned *offset0, unsigned *offset1,
1898 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1903 /* FIXME CLUT formats */
1904 switch (color_mode) {
1905 case OMAP_DSS_COLOR_CLUT1:
1906 case OMAP_DSS_COLOR_CLUT2:
1907 case OMAP_DSS_COLOR_CLUT4:
1908 case OMAP_DSS_COLOR_CLUT8:
1912 ps = color_mode_to_bpp(color_mode) / 8;
1916 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1919 /* width & height are overlay sizes, convert to fb sizes */
1921 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1930 * field 0 = even field = bottom field
1931 * field 1 = odd field = top field
1933 switch (rotation + mirror * 4) {
1934 case OMAP_DSS_ROT_0:
1937 *offset0 = *offset1 + field_offset * screen_width * ps;
1939 *offset0 = *offset1;
1940 *row_inc = pixinc(1 +
1941 (y_predecim * screen_width - fbw * x_predecim) +
1942 (fieldmode ? screen_width : 0), ps);
1943 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1944 color_mode == OMAP_DSS_COLOR_UYVY)
1945 *pix_inc = pixinc(x_predecim, 2 * ps);
1947 *pix_inc = pixinc(x_predecim, ps);
1949 case OMAP_DSS_ROT_90:
1950 *offset1 = screen_width * (fbh - 1) * ps;
1952 *offset0 = *offset1 + field_offset * ps;
1954 *offset0 = *offset1;
1955 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1956 y_predecim + (fieldmode ? 1 : 0), ps);
1957 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1959 case OMAP_DSS_ROT_180:
1960 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1962 *offset0 = *offset1 - field_offset * screen_width * ps;
1964 *offset0 = *offset1;
1965 *row_inc = pixinc(-1 -
1966 (y_predecim * screen_width - fbw * x_predecim) -
1967 (fieldmode ? screen_width : 0), ps);
1968 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1969 color_mode == OMAP_DSS_COLOR_UYVY)
1970 *pix_inc = pixinc(-x_predecim, 2 * ps);
1972 *pix_inc = pixinc(-x_predecim, ps);
1974 case OMAP_DSS_ROT_270:
1975 *offset1 = (fbw - 1) * ps;
1977 *offset0 = *offset1 - field_offset * ps;
1979 *offset0 = *offset1;
1980 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1981 y_predecim - (fieldmode ? 1 : 0), ps);
1982 *pix_inc = pixinc(x_predecim * screen_width, ps);
1986 case OMAP_DSS_ROT_0 + 4:
1987 *offset1 = (fbw - 1) * ps;
1989 *offset0 = *offset1 + field_offset * screen_width * ps;
1991 *offset0 = *offset1;
1992 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
1993 (fieldmode ? screen_width : 0),
1995 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1996 color_mode == OMAP_DSS_COLOR_UYVY)
1997 *pix_inc = pixinc(-x_predecim, 2 * ps);
1999 *pix_inc = pixinc(-x_predecim, ps);
2002 case OMAP_DSS_ROT_90 + 4:
2005 *offset0 = *offset1 + field_offset * ps;
2007 *offset0 = *offset1;
2008 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
2009 y_predecim + (fieldmode ? 1 : 0),
2011 *pix_inc = pixinc(x_predecim * screen_width, ps);
2014 case OMAP_DSS_ROT_180 + 4:
2015 *offset1 = screen_width * (fbh - 1) * ps;
2017 *offset0 = *offset1 - field_offset * screen_width * ps;
2019 *offset0 = *offset1;
2020 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
2021 (fieldmode ? screen_width : 0),
2023 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2024 color_mode == OMAP_DSS_COLOR_UYVY)
2025 *pix_inc = pixinc(x_predecim, 2 * ps);
2027 *pix_inc = pixinc(x_predecim, ps);
2030 case OMAP_DSS_ROT_270 + 4:
2031 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
2033 *offset0 = *offset1 - field_offset * ps;
2035 *offset0 = *offset1;
2036 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
2037 y_predecim - (fieldmode ? 1 : 0),
2039 *pix_inc = pixinc(-x_predecim * screen_width, ps);
2048 static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
2049 enum omap_color_mode color_mode, bool fieldmode,
2050 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
2051 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
2055 switch (color_mode) {
2056 case OMAP_DSS_COLOR_CLUT1:
2057 case OMAP_DSS_COLOR_CLUT2:
2058 case OMAP_DSS_COLOR_CLUT4:
2059 case OMAP_DSS_COLOR_CLUT8:
2063 ps = color_mode_to_bpp(color_mode) / 8;
2067 DSSDBG("scrw %d, width %d\n", screen_width, width);
2070 * field 0 = even field = bottom field
2071 * field 1 = odd field = top field
2075 *offset0 = *offset1 + field_offset * screen_width * ps;
2077 *offset0 = *offset1;
2078 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2079 (fieldmode ? screen_width : 0), ps);
2080 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2081 color_mode == OMAP_DSS_COLOR_UYVY)
2082 *pix_inc = pixinc(x_predecim, 2 * ps);
2084 *pix_inc = pixinc(x_predecim, ps);
2088 * This function is used to avoid synclosts in OMAP3, because of some
2089 * undocumented horizontal position and timing related limitations.
2091 static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
2092 const struct omap_video_timings *t, u16 pos_x,
2093 u16 width, u16 height, u16 out_width, u16 out_height,
2096 const int ds = DIV_ROUND_UP(height, out_height);
2097 unsigned long nonactive;
2098 static const u8 limits[3] = { 8, 10, 20 };
2102 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
2105 if (out_height < height)
2107 if (out_width < width)
2109 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
2110 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2111 if (blank <= limits[i])
2114 /* FIXME add checks for 3-tap filter once the limitations are known */
2119 * Pixel data should be prepared before visible display point starts.
2120 * So, atleast DS-2 lines must have already been fetched by DISPC
2121 * during nonactive - pos_x period.
2123 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2124 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2125 val, max(0, ds - 2) * width);
2126 if (val < max(0, ds - 2) * width)
2130 * All lines need to be refilled during the nonactive period of which
2131 * only one line can be loaded during the active period. So, atleast
2132 * DS - 1 lines should be loaded during nonactive period.
2134 val = div_u64((u64)nonactive * lclk, pclk);
2135 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2136 val, max(0, ds - 1) * width);
2137 if (val < max(0, ds - 1) * width)
2143 static unsigned long calc_core_clk_five_taps(unsigned long pclk,
2144 const struct omap_video_timings *mgr_timings, u16 width,
2145 u16 height, u16 out_width, u16 out_height,
2146 enum omap_color_mode color_mode)
2151 if (height <= out_height && width <= out_width)
2152 return (unsigned long) pclk;
2154 if (height > out_height) {
2155 unsigned int ppl = mgr_timings->x_res;
2157 tmp = pclk * height * out_width;
2158 do_div(tmp, 2 * out_height * ppl);
2161 if (height > 2 * out_height) {
2162 if (ppl == out_width)
2165 tmp = pclk * (height - 2 * out_height) * out_width;
2166 do_div(tmp, 2 * out_height * (ppl - out_width));
2167 core_clk = max_t(u32, core_clk, tmp);
2171 if (width > out_width) {
2173 do_div(tmp, out_width);
2174 core_clk = max_t(u32, core_clk, tmp);
2176 if (color_mode == OMAP_DSS_COLOR_RGB24U)
2183 static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
2184 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2186 if (height > out_height && width > out_width)
2192 static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
2193 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2195 unsigned int hf, vf;
2198 * FIXME how to determine the 'A' factor
2199 * for the no downscaling case ?
2202 if (width > 3 * out_width)
2204 else if (width > 2 * out_width)
2206 else if (width > out_width)
2210 if (height > out_height)
2215 return pclk * vf * hf;
2218 static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
2219 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2222 * If the overlay/writeback is in mem to mem mode, there are no
2223 * downscaling limitations with respect to pixel clock, return 1 as
2224 * required core clock to represent that we have sufficient enough
2225 * core clock to do maximum downscaling
2230 if (width > out_width)
2231 return DIV_ROUND_UP(pclk, out_width) * width;
2236 static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk,
2237 const struct omap_video_timings *mgr_timings,
2238 u16 width, u16 height, u16 out_width, u16 out_height,
2239 enum omap_color_mode color_mode, bool *five_taps,
2240 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2241 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2244 u16 in_width, in_height;
2245 int min_factor = min(*decim_x, *decim_y);
2246 const int maxsinglelinewidth =
2247 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2252 in_height = height / *decim_y;
2253 in_width = width / *decim_x;
2254 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
2255 in_height, out_width, out_height, mem_to_mem);
2256 error = (in_width > maxsinglelinewidth || !*core_clk ||
2257 *core_clk > dispc_core_clk_rate());
2259 if (*decim_x == *decim_y) {
2260 *decim_x = min_factor;
2263 swap(*decim_x, *decim_y);
2264 if (*decim_x < *decim_y)
2268 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2270 if (in_width > maxsinglelinewidth) {
2271 DSSERR("Cannot scale max input width exceeded");
2277 static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk,
2278 const struct omap_video_timings *mgr_timings,
2279 u16 width, u16 height, u16 out_width, u16 out_height,
2280 enum omap_color_mode color_mode, bool *five_taps,
2281 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2282 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2285 u16 in_width, in_height;
2286 int min_factor = min(*decim_x, *decim_y);
2287 const int maxsinglelinewidth =
2288 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2291 in_height = height / *decim_y;
2292 in_width = width / *decim_x;
2293 *five_taps = in_height > out_height;
2295 if (in_width > maxsinglelinewidth)
2296 if (in_height > out_height &&
2297 in_height < out_height * 2)
2301 *core_clk = calc_core_clk_five_taps(pclk, mgr_timings,
2302 in_width, in_height, out_width,
2303 out_height, color_mode);
2305 *core_clk = dispc.feat->calc_core_clk(pclk, in_width,
2306 in_height, out_width, out_height,
2309 error = check_horiz_timing_omap3(pclk, lclk, mgr_timings,
2310 pos_x, in_width, in_height, out_width,
2311 out_height, *five_taps);
2312 if (error && *five_taps) {
2317 error = (error || in_width > maxsinglelinewidth * 2 ||
2318 (in_width > maxsinglelinewidth && *five_taps) ||
2319 !*core_clk || *core_clk > dispc_core_clk_rate());
2321 if (*decim_x == *decim_y) {
2322 *decim_x = min_factor;
2325 swap(*decim_x, *decim_y);
2326 if (*decim_x < *decim_y)
2330 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2332 if (check_horiz_timing_omap3(pclk, lclk, mgr_timings, pos_x, width,
2333 height, out_width, out_height, *five_taps)) {
2334 DSSERR("horizontal timing too tight\n");
2338 if (in_width > (maxsinglelinewidth * 2)) {
2339 DSSERR("Cannot setup scaling");
2340 DSSERR("width exceeds maximum width possible");
2344 if (in_width > maxsinglelinewidth && *five_taps) {
2345 DSSERR("cannot setup scaling with five taps");
2351 static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk,
2352 const struct omap_video_timings *mgr_timings,
2353 u16 width, u16 height, u16 out_width, u16 out_height,
2354 enum omap_color_mode color_mode, bool *five_taps,
2355 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2356 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2358 u16 in_width, in_width_max;
2359 int decim_x_min = *decim_x;
2360 u16 in_height = height / *decim_y;
2361 const int maxsinglelinewidth =
2362 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2363 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2366 in_width_max = out_width * maxdownscale;
2368 in_width_max = dispc_core_clk_rate() /
2369 DIV_ROUND_UP(pclk, out_width);
2372 *decim_x = DIV_ROUND_UP(width, in_width_max);
2374 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2375 if (*decim_x > *x_predecim)
2379 in_width = width / *decim_x;
2380 } while (*decim_x <= *x_predecim &&
2381 in_width > maxsinglelinewidth && ++*decim_x);
2383 if (in_width > maxsinglelinewidth) {
2384 DSSERR("Cannot scale width exceeds max line width");
2388 *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height,
2389 out_width, out_height, mem_to_mem);
2393 static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk,
2394 enum omap_overlay_caps caps,
2395 const struct omap_video_timings *mgr_timings,
2396 u16 width, u16 height, u16 out_width, u16 out_height,
2397 enum omap_color_mode color_mode, bool *five_taps,
2398 int *x_predecim, int *y_predecim, u16 pos_x,
2399 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
2401 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2402 const int max_decim_limit = 16;
2403 unsigned long core_clk = 0;
2404 int decim_x, decim_y, ret;
2406 if (width == out_width && height == out_height)
2409 if (pclk == 0 || mgr_timings->pixelclock == 0) {
2410 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2414 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
2418 *x_predecim = *y_predecim = 1;
2420 *x_predecim = max_decim_limit;
2421 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2422 dss_has_feature(FEAT_BURST_2D)) ?
2423 2 : max_decim_limit;
2426 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2427 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2428 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2429 color_mode == OMAP_DSS_COLOR_CLUT8) {
2436 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2437 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2439 if (decim_x > *x_predecim || out_width > width * 8)
2442 if (decim_y > *y_predecim || out_height > height * 8)
2445 ret = dispc.feat->calc_scaling(pclk, lclk, mgr_timings, width, height,
2446 out_width, out_height, color_mode, five_taps,
2447 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2452 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2453 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
2455 if (!core_clk || core_clk > dispc_core_clk_rate()) {
2456 DSSERR("failed to set up scaling, "
2457 "required core clk rate = %lu Hz, "
2458 "current core clk rate = %lu Hz\n",
2459 core_clk, dispc_core_clk_rate());
2463 *x_predecim = decim_x;
2464 *y_predecim = decim_y;
2468 int dispc_ovl_check(enum omap_plane plane, enum omap_channel channel,
2469 const struct omap_overlay_info *oi,
2470 const struct omap_video_timings *timings,
2471 int *x_predecim, int *y_predecim)
2473 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2474 bool five_taps = true;
2475 bool fieldmode = false;
2476 u16 in_height = oi->height;
2477 u16 in_width = oi->width;
2478 bool ilace = timings->interlace;
2479 u16 out_width, out_height;
2480 int pos_x = oi->pos_x;
2481 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2482 unsigned long lclk = dispc_mgr_lclk_rate(channel);
2484 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2485 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2487 if (ilace && oi->height == out_height)
2495 DSSDBG("adjusting for ilace: height %d, out_height %d\n",
2496 in_height, out_height);
2499 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2502 return dispc_ovl_calc_scaling(pclk, lclk, caps, timings, in_width,
2503 in_height, out_width, out_height, oi->color_mode,
2504 &five_taps, x_predecim, y_predecim, pos_x,
2505 oi->rotation_type, false);
2507 EXPORT_SYMBOL(dispc_ovl_check);
2509 static int dispc_ovl_setup_common(enum omap_plane plane,
2510 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2511 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2512 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2513 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2514 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
2515 bool replication, const struct omap_video_timings *mgr_timings,
2518 bool five_taps = true;
2519 bool fieldmode = false;
2521 unsigned offset0, offset1;
2524 u16 frame_width, frame_height;
2525 unsigned int field_offset = 0;
2526 u16 in_height = height;
2527 u16 in_width = width;
2528 int x_predecim = 1, y_predecim = 1;
2529 bool ilace = mgr_timings->interlace;
2530 unsigned long pclk = dispc_plane_pclk_rate(plane);
2531 unsigned long lclk = dispc_plane_lclk_rate(plane);
2533 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
2536 out_width = out_width == 0 ? width : out_width;
2537 out_height = out_height == 0 ? height : out_height;
2539 if (ilace && height == out_height)
2548 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2549 "out_height %d\n", in_height, pos_y,
2553 if (!dss_feat_color_mode_supported(plane, color_mode))
2556 r = dispc_ovl_calc_scaling(pclk, lclk, caps, mgr_timings, in_width,
2557 in_height, out_width, out_height, color_mode,
2558 &five_taps, &x_predecim, &y_predecim, pos_x,
2559 rotation_type, mem_to_mem);
2563 in_width = in_width / x_predecim;
2564 in_height = in_height / y_predecim;
2566 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2567 color_mode == OMAP_DSS_COLOR_UYVY ||
2568 color_mode == OMAP_DSS_COLOR_NV12)
2571 if (ilace && !fieldmode) {
2573 * when downscaling the bottom field may have to start several
2574 * source lines below the top field. Unfortunately ACCUI
2575 * registers will only hold the fractional part of the offset
2576 * so the integer part must be added to the base address of the
2579 if (!in_height || in_height == out_height)
2582 field_offset = in_height / out_height / 2;
2585 /* Fields are independent but interleaved in memory. */
2594 if (plane == OMAP_DSS_WB) {
2595 frame_width = out_width;
2596 frame_height = out_height;
2598 frame_width = in_width;
2599 frame_height = height;
2602 if (rotation_type == OMAP_DSS_ROT_TILER)
2603 calc_tiler_rotation_offset(screen_width, frame_width,
2604 color_mode, fieldmode, field_offset,
2605 &offset0, &offset1, &row_inc, &pix_inc,
2606 x_predecim, y_predecim);
2607 else if (rotation_type == OMAP_DSS_ROT_DMA)
2608 calc_dma_rotation_offset(rotation, mirror, screen_width,
2609 frame_width, frame_height,
2610 color_mode, fieldmode, field_offset,
2611 &offset0, &offset1, &row_inc, &pix_inc,
2612 x_predecim, y_predecim);
2614 calc_vrfb_rotation_offset(rotation, mirror,
2615 screen_width, frame_width, frame_height,
2616 color_mode, fieldmode, field_offset,
2617 &offset0, &offset1, &row_inc, &pix_inc,
2618 x_predecim, y_predecim);
2620 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2621 offset0, offset1, row_inc, pix_inc);
2623 dispc_ovl_set_color_mode(plane, color_mode);
2625 dispc_ovl_configure_burst_type(plane, rotation_type);
2627 dispc_ovl_set_ba0(plane, paddr + offset0);
2628 dispc_ovl_set_ba1(plane, paddr + offset1);
2630 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2631 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2632 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
2635 dispc_ovl_set_row_inc(plane, row_inc);
2636 dispc_ovl_set_pix_inc(plane, pix_inc);
2638 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
2639 in_height, out_width, out_height);
2641 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
2643 dispc_ovl_set_input_size(plane, in_width, in_height);
2645 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
2646 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2647 out_height, ilace, five_taps, fieldmode,
2648 color_mode, rotation);
2649 dispc_ovl_set_output_size(plane, out_width, out_height);
2650 dispc_ovl_set_vid_color_conv(plane, cconv);
2653 dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror,
2656 dispc_ovl_set_zorder(plane, caps, zorder);
2657 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2658 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
2660 dispc_ovl_enable_replication(plane, caps, replication);
2665 int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
2666 bool replication, const struct omap_video_timings *mgr_timings,
2670 enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane);
2671 enum omap_channel channel;
2673 channel = dispc_ovl_get_channel_out(plane);
2675 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2676 " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2677 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
2678 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2679 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2681 r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr,
2682 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2683 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2684 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
2685 oi->rotation_type, replication, mgr_timings, mem_to_mem);
2689 EXPORT_SYMBOL(dispc_ovl_setup);
2691 int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
2692 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
2696 enum omap_plane plane = OMAP_DSS_WB;
2697 const int pos_x = 0, pos_y = 0;
2698 const u8 zorder = 0, global_alpha = 0;
2699 const bool replication = false;
2701 int in_width = mgr_timings->x_res;
2702 int in_height = mgr_timings->y_res;
2703 enum omap_overlay_caps caps =
2704 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2706 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2707 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2708 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2711 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2712 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2713 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2714 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
2715 replication, mgr_timings, mem_to_mem);
2717 switch (wi->color_mode) {
2718 case OMAP_DSS_COLOR_RGB16:
2719 case OMAP_DSS_COLOR_RGB24P:
2720 case OMAP_DSS_COLOR_ARGB16:
2721 case OMAP_DSS_COLOR_RGBA16:
2722 case OMAP_DSS_COLOR_RGB12U:
2723 case OMAP_DSS_COLOR_ARGB16_1555:
2724 case OMAP_DSS_COLOR_XRGB16_1555:
2725 case OMAP_DSS_COLOR_RGBX16:
2733 /* setup extra DISPC_WB_ATTRIBUTES */
2734 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2735 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2736 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2737 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
2742 int dispc_ovl_enable(enum omap_plane plane, bool enable)
2744 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2746 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2750 EXPORT_SYMBOL(dispc_ovl_enable);
2752 bool dispc_ovl_enabled(enum omap_plane plane)
2754 return REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0);
2756 EXPORT_SYMBOL(dispc_ovl_enabled);
2758 void dispc_mgr_enable(enum omap_channel channel, bool enable)
2760 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2761 /* flush posted write */
2762 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2764 EXPORT_SYMBOL(dispc_mgr_enable);
2766 bool dispc_mgr_is_enabled(enum omap_channel channel)
2768 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2770 EXPORT_SYMBOL(dispc_mgr_is_enabled);
2772 void dispc_wb_enable(bool enable)
2774 dispc_ovl_enable(OMAP_DSS_WB, enable);
2777 bool dispc_wb_is_enabled(void)
2779 return dispc_ovl_enabled(OMAP_DSS_WB);
2782 static void dispc_lcd_enable_signal_polarity(bool act_high)
2784 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2787 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2790 void dispc_lcd_enable_signal(bool enable)
2792 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2795 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2798 void dispc_pck_free_enable(bool enable)
2800 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2803 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2806 static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2808 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
2812 static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
2814 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
2817 void dispc_set_loadmode(enum omap_dss_load_mode mode)
2819 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2823 static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2825 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2828 static void dispc_mgr_set_trans_key(enum omap_channel ch,
2829 enum omap_dss_trans_key_type type,
2832 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
2834 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2837 static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2839 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
2842 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2845 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
2848 if (ch == OMAP_DSS_CHANNEL_LCD)
2849 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2850 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2851 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2854 void dispc_mgr_setup(enum omap_channel channel,
2855 const struct omap_overlay_manager_info *info)
2857 dispc_mgr_set_default_color(channel, info->default_color);
2858 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2859 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2860 dispc_mgr_enable_alpha_fixed_zorder(channel,
2861 info->partial_alpha_enabled);
2862 if (dss_has_feature(FEAT_CPR)) {
2863 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2864 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2867 EXPORT_SYMBOL(dispc_mgr_setup);
2869 static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2873 switch (data_lines) {
2891 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
2894 static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
2900 case DSS_IO_PAD_MODE_RESET:
2904 case DSS_IO_PAD_MODE_RFBI:
2908 case DSS_IO_PAD_MODE_BYPASS:
2917 l = dispc_read_reg(DISPC_CONTROL);
2918 l = FLD_MOD(l, gpout0, 15, 15);
2919 l = FLD_MOD(l, gpout1, 16, 16);
2920 dispc_write_reg(DISPC_CONTROL, l);
2923 static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2925 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
2928 void dispc_mgr_set_lcd_config(enum omap_channel channel,
2929 const struct dss_lcd_mgr_config *config)
2931 dispc_mgr_set_io_pad_mode(config->io_pad_mode);
2933 dispc_mgr_enable_stallmode(channel, config->stallmode);
2934 dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck);
2936 dispc_mgr_set_clock_div(channel, &config->clock_info);
2938 dispc_mgr_set_tft_data_lines(channel, config->video_port_width);
2940 dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity);
2942 dispc_mgr_set_lcd_type_tft(channel);
2944 EXPORT_SYMBOL(dispc_mgr_set_lcd_config);
2946 static bool _dispc_mgr_size_ok(u16 width, u16 height)
2948 return width <= dispc.feat->mgr_width_max &&
2949 height <= dispc.feat->mgr_height_max;
2952 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2953 int vsw, int vfp, int vbp)
2955 if (hsw < 1 || hsw > dispc.feat->sw_max ||
2956 hfp < 1 || hfp > dispc.feat->hp_max ||
2957 hbp < 1 || hbp > dispc.feat->hp_max ||
2958 vsw < 1 || vsw > dispc.feat->sw_max ||
2959 vfp < 0 || vfp > dispc.feat->vp_max ||
2960 vbp < 0 || vbp > dispc.feat->vp_max)
2965 static bool _dispc_mgr_pclk_ok(enum omap_channel channel,
2968 if (dss_mgr_is_lcd(channel))
2969 return pclk <= dispc.feat->max_lcd_pclk ? true : false;
2971 return pclk <= dispc.feat->max_tv_pclk ? true : false;
2974 bool dispc_mgr_timings_ok(enum omap_channel channel,
2975 const struct omap_video_timings *timings)
2977 if (!_dispc_mgr_size_ok(timings->x_res, timings->y_res))
2980 if (!_dispc_mgr_pclk_ok(channel, timings->pixelclock))
2983 if (dss_mgr_is_lcd(channel)) {
2984 /* TODO: OMAP4+ supports interlace for LCD outputs */
2985 if (timings->interlace)
2988 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp,
2989 timings->hbp, timings->vsw, timings->vfp,
2997 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
2998 int hfp, int hbp, int vsw, int vfp, int vbp,
2999 enum omap_dss_signal_level vsync_level,
3000 enum omap_dss_signal_level hsync_level,
3001 enum omap_dss_signal_edge data_pclk_edge,
3002 enum omap_dss_signal_level de_level,
3003 enum omap_dss_signal_edge sync_pclk_edge)
3006 u32 timing_h, timing_v, l;
3007 bool onoff, rf, ipc, vs, hs, de;
3009 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
3010 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
3011 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
3012 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
3013 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
3014 FLD_VAL(vbp, dispc.feat->bp_start, 20);
3016 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
3017 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
3019 switch (vsync_level) {
3020 case OMAPDSS_SIG_ACTIVE_LOW:
3023 case OMAPDSS_SIG_ACTIVE_HIGH:
3030 switch (hsync_level) {
3031 case OMAPDSS_SIG_ACTIVE_LOW:
3034 case OMAPDSS_SIG_ACTIVE_HIGH:
3042 case OMAPDSS_SIG_ACTIVE_LOW:
3045 case OMAPDSS_SIG_ACTIVE_HIGH:
3052 switch (data_pclk_edge) {
3053 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3056 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3063 /* always use the 'rf' setting */
3066 switch (sync_pclk_edge) {
3067 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
3070 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
3077 l = FLD_VAL(onoff, 17, 17) |
3078 FLD_VAL(rf, 16, 16) |
3079 FLD_VAL(de, 15, 15) |
3080 FLD_VAL(ipc, 14, 14) |
3081 FLD_VAL(hs, 13, 13) |
3082 FLD_VAL(vs, 12, 12);
3084 dispc_write_reg(DISPC_POL_FREQ(channel), l);
3086 if (dispc.syscon_pol) {
3087 const int shifts[] = {
3088 [OMAP_DSS_CHANNEL_LCD] = 0,
3089 [OMAP_DSS_CHANNEL_LCD2] = 1,
3090 [OMAP_DSS_CHANNEL_LCD3] = 2,
3095 mask = (1 << 0) | (1 << 3) | (1 << 6);
3096 val = (rf << 0) | (ipc << 3) | (onoff << 6);
3098 mask <<= 16 + shifts[channel];
3099 val <<= 16 + shifts[channel];
3101 regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset,
3106 /* change name to mode? */
3107 void dispc_mgr_set_timings(enum omap_channel channel,
3108 const struct omap_video_timings *timings)
3110 unsigned xtot, ytot;
3111 unsigned long ht, vt;
3112 struct omap_video_timings t = *timings;
3114 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
3116 if (!dispc_mgr_timings_ok(channel, &t)) {
3121 if (dss_mgr_is_lcd(channel)) {
3122 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
3123 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
3124 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
3126 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
3127 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
3129 ht = timings->pixelclock / xtot;
3130 vt = timings->pixelclock / xtot / ytot;
3132 DSSDBG("pck %u\n", timings->pixelclock);
3133 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
3134 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
3135 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3136 t.vsync_level, t.hsync_level, t.data_pclk_edge,
3137 t.de_level, t.sync_pclk_edge);
3139 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
3141 if (t.interlace == true)
3145 dispc_mgr_set_size(channel, t.x_res, t.y_res);
3147 EXPORT_SYMBOL(dispc_mgr_set_timings);
3149 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
3152 BUG_ON(lck_div < 1);
3153 BUG_ON(pck_div < 1);
3155 dispc_write_reg(DISPC_DIVISORo(channel),
3156 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
3158 if (dss_has_feature(FEAT_CORE_CLK_DIV) == false &&
3159 channel == OMAP_DSS_CHANNEL_LCD)
3160 dispc.core_clk_rate = dispc_fclk_rate() / lck_div;
3163 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
3167 l = dispc_read_reg(DISPC_DIVISORo(channel));
3168 *lck_div = FLD_GET(l, 23, 16);
3169 *pck_div = FLD_GET(l, 7, 0);
3172 unsigned long dispc_fclk_rate(void)
3174 struct dss_pll *pll;
3175 unsigned long r = 0;
3177 switch (dss_get_dispc_clk_source()) {
3178 case OMAP_DSS_CLK_SRC_FCK:
3179 r = dss_get_dispc_clk_rate();
3181 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
3182 pll = dss_pll_find("dsi0");
3184 pll = dss_pll_find("video0");
3186 r = pll->cinfo.clkout[0];
3188 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3189 pll = dss_pll_find("dsi1");
3191 pll = dss_pll_find("video1");
3193 r = pll->cinfo.clkout[0];
3203 unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
3205 struct dss_pll *pll;
3210 if (dss_mgr_is_lcd(channel)) {
3211 l = dispc_read_reg(DISPC_DIVISORo(channel));
3213 lcd = FLD_GET(l, 23, 16);
3215 switch (dss_get_lcd_clk_source(channel)) {
3216 case OMAP_DSS_CLK_SRC_FCK:
3217 r = dss_get_dispc_clk_rate();
3219 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
3220 pll = dss_pll_find("dsi0");
3222 pll = dss_pll_find("video0");
3224 r = pll->cinfo.clkout[0];
3226 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3227 pll = dss_pll_find("dsi1");
3229 pll = dss_pll_find("video1");
3231 r = pll->cinfo.clkout[0];
3240 return dispc_fclk_rate();
3244 unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
3248 if (dss_mgr_is_lcd(channel)) {
3252 l = dispc_read_reg(DISPC_DIVISORo(channel));
3254 pcd = FLD_GET(l, 7, 0);
3256 r = dispc_mgr_lclk_rate(channel);
3260 return dispc.tv_pclk_rate;
3264 void dispc_set_tv_pclk(unsigned long pclk)
3266 dispc.tv_pclk_rate = pclk;
3269 unsigned long dispc_core_clk_rate(void)
3271 return dispc.core_clk_rate;
3274 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3276 enum omap_channel channel;
3278 if (plane == OMAP_DSS_WB)
3281 channel = dispc_ovl_get_channel_out(plane);
3283 return dispc_mgr_pclk_rate(channel);
3286 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3288 enum omap_channel channel;
3290 if (plane == OMAP_DSS_WB)
3293 channel = dispc_ovl_get_channel_out(plane);
3295 return dispc_mgr_lclk_rate(channel);
3298 static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
3301 enum omap_dss_clk_source lcd_clk_src;
3303 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3305 lcd_clk_src = dss_get_lcd_clk_source(channel);
3307 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3308 dss_get_generic_clk_source_name(lcd_clk_src),
3309 dss_feat_get_clk_source_name(lcd_clk_src));
3311 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3313 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3314 dispc_mgr_lclk_rate(channel), lcd);
3315 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3316 dispc_mgr_pclk_rate(channel), pcd);
3319 void dispc_dump_clocks(struct seq_file *s)
3323 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
3325 if (dispc_runtime_get())
3328 seq_printf(s, "- DISPC -\n");
3330 seq_printf(s, "dispc fclk source = %s (%s)\n",
3331 dss_get_generic_clk_source_name(dispc_clk_src),
3332 dss_feat_get_clk_source_name(dispc_clk_src));
3334 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
3336 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3337 seq_printf(s, "- DISPC-CORE-CLK -\n");
3338 l = dispc_read_reg(DISPC_DIVISOR);
3339 lcd = FLD_GET(l, 23, 16);
3341 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3342 (dispc_fclk_rate()/lcd), lcd);
3345 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
3347 if (dss_has_feature(FEAT_MGR_LCD2))
3348 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3349 if (dss_has_feature(FEAT_MGR_LCD3))
3350 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
3352 dispc_runtime_put();
3355 static void dispc_dump_regs(struct seq_file *s)
3358 const char *mgr_names[] = {
3359 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3360 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3361 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
3362 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
3364 const char *ovl_names[] = {
3365 [OMAP_DSS_GFX] = "GFX",
3366 [OMAP_DSS_VIDEO1] = "VID1",
3367 [OMAP_DSS_VIDEO2] = "VID2",
3368 [OMAP_DSS_VIDEO3] = "VID3",
3370 const char **p_names;
3372 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3374 if (dispc_runtime_get())
3377 /* DISPC common registers */
3378 DUMPREG(DISPC_REVISION);
3379 DUMPREG(DISPC_SYSCONFIG);
3380 DUMPREG(DISPC_SYSSTATUS);
3381 DUMPREG(DISPC_IRQSTATUS);
3382 DUMPREG(DISPC_IRQENABLE);
3383 DUMPREG(DISPC_CONTROL);
3384 DUMPREG(DISPC_CONFIG);
3385 DUMPREG(DISPC_CAPABLE);
3386 DUMPREG(DISPC_LINE_STATUS);
3387 DUMPREG(DISPC_LINE_NUMBER);
3388 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3389 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
3390 DUMPREG(DISPC_GLOBAL_ALPHA);
3391 if (dss_has_feature(FEAT_MGR_LCD2)) {
3392 DUMPREG(DISPC_CONTROL2);
3393 DUMPREG(DISPC_CONFIG2);
3395 if (dss_has_feature(FEAT_MGR_LCD3)) {
3396 DUMPREG(DISPC_CONTROL3);
3397 DUMPREG(DISPC_CONFIG3);
3399 if (dss_has_feature(FEAT_MFLAG))
3400 DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE);
3404 #define DISPC_REG(i, name) name(i)
3405 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3406 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
3407 dispc_read_reg(DISPC_REG(i, r)))
3409 p_names = mgr_names;
3411 /* DISPC channel specific registers */
3412 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3413 DUMPREG(i, DISPC_DEFAULT_COLOR);
3414 DUMPREG(i, DISPC_TRANS_COLOR);
3415 DUMPREG(i, DISPC_SIZE_MGR);
3417 if (i == OMAP_DSS_CHANNEL_DIGIT)
3420 DUMPREG(i, DISPC_TIMING_H);
3421 DUMPREG(i, DISPC_TIMING_V);
3422 DUMPREG(i, DISPC_POL_FREQ);
3423 DUMPREG(i, DISPC_DIVISORo);
3425 DUMPREG(i, DISPC_DATA_CYCLE1);
3426 DUMPREG(i, DISPC_DATA_CYCLE2);
3427 DUMPREG(i, DISPC_DATA_CYCLE3);
3429 if (dss_has_feature(FEAT_CPR)) {
3430 DUMPREG(i, DISPC_CPR_COEF_R);
3431 DUMPREG(i, DISPC_CPR_COEF_G);
3432 DUMPREG(i, DISPC_CPR_COEF_B);
3436 p_names = ovl_names;
3438 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3439 DUMPREG(i, DISPC_OVL_BA0);
3440 DUMPREG(i, DISPC_OVL_BA1);
3441 DUMPREG(i, DISPC_OVL_POSITION);
3442 DUMPREG(i, DISPC_OVL_SIZE);
3443 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3444 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3445 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3446 DUMPREG(i, DISPC_OVL_ROW_INC);
3447 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3449 if (dss_has_feature(FEAT_PRELOAD))
3450 DUMPREG(i, DISPC_OVL_PRELOAD);
3451 if (dss_has_feature(FEAT_MFLAG))
3452 DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD);
3454 if (i == OMAP_DSS_GFX) {
3455 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3456 DUMPREG(i, DISPC_OVL_TABLE_BA);
3460 DUMPREG(i, DISPC_OVL_FIR);
3461 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3462 DUMPREG(i, DISPC_OVL_ACCU0);
3463 DUMPREG(i, DISPC_OVL_ACCU1);
3464 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3465 DUMPREG(i, DISPC_OVL_BA0_UV);
3466 DUMPREG(i, DISPC_OVL_BA1_UV);
3467 DUMPREG(i, DISPC_OVL_FIR2);
3468 DUMPREG(i, DISPC_OVL_ACCU2_0);
3469 DUMPREG(i, DISPC_OVL_ACCU2_1);
3471 if (dss_has_feature(FEAT_ATTR2))
3472 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3478 #define DISPC_REG(plane, name, i) name(plane, i)
3479 #define DUMPREG(plane, name, i) \
3480 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3481 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
3482 dispc_read_reg(DISPC_REG(plane, name, i)))
3484 /* Video pipeline coefficient registers */
3486 /* start from OMAP_DSS_VIDEO1 */
3487 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3488 for (j = 0; j < 8; j++)
3489 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
3491 for (j = 0; j < 8; j++)
3492 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
3494 for (j = 0; j < 5; j++)
3495 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
3497 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3498 for (j = 0; j < 8; j++)
3499 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3502 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3503 for (j = 0; j < 8; j++)
3504 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
3506 for (j = 0; j < 8; j++)
3507 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
3509 for (j = 0; j < 8; j++)
3510 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3514 dispc_runtime_put();
3520 /* calculate clock rates using dividers in cinfo */
3521 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3522 struct dispc_clock_info *cinfo)
3524 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3526 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3529 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3530 cinfo->pck = cinfo->lck / cinfo->pck_div;
3535 bool dispc_div_calc(unsigned long dispc,
3536 unsigned long pck_min, unsigned long pck_max,
3537 dispc_div_calc_func func, void *data)
3539 int lckd, lckd_start, lckd_stop;
3540 int pckd, pckd_start, pckd_stop;
3541 unsigned long pck, lck;
3542 unsigned long lck_max;
3543 unsigned long pckd_hw_min, pckd_hw_max;
3544 unsigned min_fck_per_pck;
3547 #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3548 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3550 min_fck_per_pck = 0;
3553 pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3554 pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3556 lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
3558 pck_min = pck_min ? pck_min : 1;
3559 pck_max = pck_max ? pck_max : ULONG_MAX;
3561 lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul);
3562 lckd_stop = min(dispc / pck_min, 255ul);
3564 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3567 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3568 pckd_stop = min(lck / pck_min, pckd_hw_max);
3570 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3574 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3575 * clock, which means we're configuring DISPC fclk here
3576 * also. Thus we need to use the calculated lck. For
3577 * OMAP4+ the DISPC fclk is a separate clock.
3579 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3580 fck = dispc_core_clk_rate();
3584 if (fck < pck * min_fck_per_pck)
3587 if (func(lckd, pckd, lck, pck, data))
3595 void dispc_mgr_set_clock_div(enum omap_channel channel,
3596 const struct dispc_clock_info *cinfo)
3598 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3599 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3601 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
3604 int dispc_mgr_get_clock_div(enum omap_channel channel,
3605 struct dispc_clock_info *cinfo)
3609 fck = dispc_fclk_rate();
3611 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3612 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
3614 cinfo->lck = fck / cinfo->lck_div;
3615 cinfo->pck = cinfo->lck / cinfo->pck_div;
3620 u32 dispc_read_irqstatus(void)
3622 return dispc_read_reg(DISPC_IRQSTATUS);
3624 EXPORT_SYMBOL(dispc_read_irqstatus);
3626 void dispc_clear_irqstatus(u32 mask)
3628 dispc_write_reg(DISPC_IRQSTATUS, mask);
3630 EXPORT_SYMBOL(dispc_clear_irqstatus);
3632 u32 dispc_read_irqenable(void)
3634 return dispc_read_reg(DISPC_IRQENABLE);
3636 EXPORT_SYMBOL(dispc_read_irqenable);
3638 void dispc_write_irqenable(u32 mask)
3640 u32 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3642 /* clear the irqstatus for newly enabled irqs */
3643 dispc_clear_irqstatus((mask ^ old_mask) & mask);
3645 dispc_write_reg(DISPC_IRQENABLE, mask);
3647 EXPORT_SYMBOL(dispc_write_irqenable);
3649 void dispc_enable_sidle(void)
3651 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3654 void dispc_disable_sidle(void)
3656 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3659 static void _omap_dispc_initial_config(void)
3663 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3664 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3665 l = dispc_read_reg(DISPC_DIVISOR);
3666 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3667 l = FLD_MOD(l, 1, 0, 0);
3668 l = FLD_MOD(l, 1, 23, 16);
3669 dispc_write_reg(DISPC_DIVISOR, l);
3671 dispc.core_clk_rate = dispc_fclk_rate();
3675 if (dss_has_feature(FEAT_FUNCGATED))
3676 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3678 dispc_setup_color_conv_coef();
3680 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3684 dispc_configure_burst_sizes();
3686 dispc_ovl_enable_zorder_planes();
3688 if (dispc.feat->mstandby_workaround)
3689 REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0);
3691 if (dss_has_feature(FEAT_MFLAG))
3695 static const struct dispc_features omap24xx_dispc_feats __initconst = {
3702 .mgr_width_start = 10,
3703 .mgr_height_start = 26,
3704 .mgr_width_max = 2048,
3705 .mgr_height_max = 2048,
3706 .max_lcd_pclk = 66500000,
3707 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3708 .calc_core_clk = calc_core_clk_24xx,
3710 .no_framedone_tv = true,
3711 .set_max_preload = false,
3714 static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
3721 .mgr_width_start = 10,
3722 .mgr_height_start = 26,
3723 .mgr_width_max = 2048,
3724 .mgr_height_max = 2048,
3725 .max_lcd_pclk = 173000000,
3726 .max_tv_pclk = 59000000,
3727 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3728 .calc_core_clk = calc_core_clk_34xx,
3730 .no_framedone_tv = true,
3731 .set_max_preload = false,
3734 static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
3741 .mgr_width_start = 10,
3742 .mgr_height_start = 26,
3743 .mgr_width_max = 2048,
3744 .mgr_height_max = 2048,
3745 .max_lcd_pclk = 173000000,
3746 .max_tv_pclk = 59000000,
3747 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3748 .calc_core_clk = calc_core_clk_34xx,
3750 .no_framedone_tv = true,
3751 .set_max_preload = false,
3754 static const struct dispc_features omap44xx_dispc_feats __initconst = {
3761 .mgr_width_start = 10,
3762 .mgr_height_start = 26,
3763 .mgr_width_max = 2048,
3764 .mgr_height_max = 2048,
3765 .max_lcd_pclk = 170000000,
3766 .max_tv_pclk = 185625000,
3767 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3768 .calc_core_clk = calc_core_clk_44xx,
3770 .gfx_fifo_workaround = true,
3771 .set_max_preload = true,
3774 static const struct dispc_features omap54xx_dispc_feats __initconst = {
3781 .mgr_width_start = 11,
3782 .mgr_height_start = 27,
3783 .mgr_width_max = 4096,
3784 .mgr_height_max = 4096,
3785 .max_lcd_pclk = 170000000,
3786 .max_tv_pclk = 186000000,
3787 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3788 .calc_core_clk = calc_core_clk_44xx,
3790 .gfx_fifo_workaround = true,
3791 .mstandby_workaround = true,
3792 .set_max_preload = true,
3795 static int __init dispc_init_features(struct platform_device *pdev)
3797 const struct dispc_features *src;
3798 struct dispc_features *dst;
3800 dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL);
3802 dev_err(&pdev->dev, "Failed to allocate DISPC Features\n");
3806 switch (omapdss_get_version()) {
3807 case OMAPDSS_VER_OMAP24xx:
3808 src = &omap24xx_dispc_feats;
3811 case OMAPDSS_VER_OMAP34xx_ES1:
3812 src = &omap34xx_rev1_0_dispc_feats;
3815 case OMAPDSS_VER_OMAP34xx_ES3:
3816 case OMAPDSS_VER_OMAP3630:
3817 case OMAPDSS_VER_AM35xx:
3818 case OMAPDSS_VER_AM43xx:
3819 src = &omap34xx_rev3_0_dispc_feats;
3822 case OMAPDSS_VER_OMAP4430_ES1:
3823 case OMAPDSS_VER_OMAP4430_ES2:
3824 case OMAPDSS_VER_OMAP4:
3825 src = &omap44xx_dispc_feats;
3828 case OMAPDSS_VER_OMAP5:
3829 case OMAPDSS_VER_DRA7xx:
3830 src = &omap54xx_dispc_feats;
3837 memcpy(dst, src, sizeof(*dst));
3843 static irqreturn_t dispc_irq_handler(int irq, void *arg)
3845 if (!dispc.is_enabled)
3848 return dispc.user_handler(irq, dispc.user_data);
3851 int dispc_request_irq(irq_handler_t handler, void *dev_id)
3855 if (dispc.user_handler != NULL)
3858 dispc.user_handler = handler;
3859 dispc.user_data = dev_id;
3861 /* ensure the dispc_irq_handler sees the values above */
3864 r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler,
3865 IRQF_SHARED, "OMAP DISPC", &dispc);
3867 dispc.user_handler = NULL;
3868 dispc.user_data = NULL;
3873 EXPORT_SYMBOL(dispc_request_irq);
3875 void dispc_free_irq(void *dev_id)
3877 devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc);
3879 dispc.user_handler = NULL;
3880 dispc.user_data = NULL;
3882 EXPORT_SYMBOL(dispc_free_irq);
3884 /* DISPC HW IP initialisation */
3885 static int __init omap_dispchw_probe(struct platform_device *pdev)
3889 struct resource *dispc_mem;
3890 struct device_node *np = pdev->dev.of_node;
3894 spin_lock_init(&dispc.control_lock);
3896 r = dispc_init_features(dispc.pdev);
3900 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3902 DSSERR("can't get IORESOURCE_MEM DISPC\n");
3906 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3907 resource_size(dispc_mem));
3909 DSSERR("can't ioremap DISPC\n");
3913 dispc.irq = platform_get_irq(dispc.pdev, 0);
3914 if (dispc.irq < 0) {
3915 DSSERR("platform_get_irq failed\n");
3919 if (np && of_property_read_bool(np, "syscon-pol")) {
3920 dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
3921 if (IS_ERR(dispc.syscon_pol)) {
3922 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
3923 return PTR_ERR(dispc.syscon_pol);
3926 if (of_property_read_u32_index(np, "syscon-pol", 1,
3927 &dispc.syscon_pol_offset)) {
3928 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
3933 pm_runtime_enable(&pdev->dev);
3935 r = dispc_runtime_get();
3937 goto err_runtime_get;
3939 _omap_dispc_initial_config();
3941 rev = dispc_read_reg(DISPC_REVISION);
3942 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
3943 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3945 dispc_runtime_put();
3947 dss_init_overlay_managers();
3949 dss_debugfs_create_file("dispc", dispc_dump_regs);
3954 pm_runtime_disable(&pdev->dev);
3958 static int __exit omap_dispchw_remove(struct platform_device *pdev)
3960 pm_runtime_disable(&pdev->dev);
3962 dss_uninit_overlay_managers();
3967 static int dispc_runtime_suspend(struct device *dev)
3969 dispc.is_enabled = false;
3970 /* ensure the dispc_irq_handler sees the is_enabled value */
3972 /* wait for current handler to finish before turning the DISPC off */
3973 synchronize_irq(dispc.irq);
3975 dispc_save_context();
3980 static int dispc_runtime_resume(struct device *dev)
3983 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
3984 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
3985 * _omap_dispc_initial_config(). We can thus use it to detect if
3986 * we have lost register context.
3988 if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
3989 _omap_dispc_initial_config();
3991 dispc_restore_context();
3994 dispc.is_enabled = true;
3995 /* ensure the dispc_irq_handler sees the is_enabled value */
4001 static const struct dev_pm_ops dispc_pm_ops = {
4002 .runtime_suspend = dispc_runtime_suspend,
4003 .runtime_resume = dispc_runtime_resume,
4006 static const struct of_device_id dispc_of_match[] = {
4007 { .compatible = "ti,omap2-dispc", },
4008 { .compatible = "ti,omap3-dispc", },
4009 { .compatible = "ti,omap4-dispc", },
4010 { .compatible = "ti,omap5-dispc", },
4011 { .compatible = "ti,dra7-dispc", },
4015 static struct platform_driver omap_dispchw_driver = {
4016 .remove = __exit_p(omap_dispchw_remove),
4018 .name = "omapdss_dispc",
4019 .pm = &dispc_pm_ops,
4020 .of_match_table = dispc_of_match,
4021 .suppress_bind_attrs = true,
4025 int __init dispc_init_platform_driver(void)
4027 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
4030 void __exit dispc_uninit_platform_driver(void)
4032 platform_driver_unregister(&omap_dispchw_driver);