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/interrupt.h>
37 #include <linux/platform_device.h>
38 #include <linux/pm_runtime.h>
40 #include <video/omapdss.h>
43 #include "dss_features.h"
47 #define DISPC_SZ_REGS SZ_4K
49 #define DISPC_IRQ_MASK_ERROR (DISPC_IRQ_GFX_FIFO_UNDERFLOW | \
51 DISPC_IRQ_VID1_FIFO_UNDERFLOW | \
52 DISPC_IRQ_VID2_FIFO_UNDERFLOW | \
53 DISPC_IRQ_SYNC_LOST | \
54 DISPC_IRQ_SYNC_LOST_DIGIT)
56 #define DISPC_MAX_NR_ISRS 8
58 struct omap_dispc_isr_data {
64 enum omap_burst_size {
70 #define REG_GET(idx, start, end) \
71 FLD_GET(dispc_read_reg(idx), start, end)
73 #define REG_FLD_MOD(idx, val, start, end) \
74 dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end))
76 struct dispc_irq_stats {
77 unsigned long last_reset;
82 struct dispc_features {
89 int (*calc_scaling) (enum omap_plane plane,
90 const struct omap_video_timings *mgr_timings,
91 u16 width, u16 height, u16 out_width, u16 out_height,
92 enum omap_color_mode color_mode, bool *five_taps,
93 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
94 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
95 unsigned long (*calc_core_clk) (enum omap_plane plane,
96 u16 width, u16 height, u16 out_width, u16 out_height,
100 /* swap GFX & WB fifos */
101 bool gfx_fifo_workaround:1;
104 #define DISPC_MAX_NR_FIFOS 5
107 struct platform_device *pdev;
115 u32 fifo_size[DISPC_MAX_NR_FIFOS];
116 /* maps which plane is using a fifo. fifo-id -> plane-id */
117 int fifo_assignment[DISPC_MAX_NR_FIFOS];
121 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
123 struct work_struct error_work;
126 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
128 const struct dispc_features *feat;
130 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
131 spinlock_t irq_stats_lock;
132 struct dispc_irq_stats irq_stats;
136 enum omap_color_component {
137 /* used for all color formats for OMAP3 and earlier
138 * and for RGB and Y color component on OMAP4
140 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
141 /* used for UV component for
142 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
143 * color formats on OMAP4
145 DISPC_COLOR_COMPONENT_UV = 1 << 1,
148 enum mgr_reg_fields {
149 DISPC_MGR_FLD_ENABLE,
150 DISPC_MGR_FLD_STNTFT,
152 DISPC_MGR_FLD_TFTDATALINES,
153 DISPC_MGR_FLD_STALLMODE,
154 DISPC_MGR_FLD_TCKENABLE,
155 DISPC_MGR_FLD_TCKSELECTION,
157 DISPC_MGR_FLD_FIFOHANDCHECK,
158 /* used to maintain a count of the above fields */
162 static const struct {
167 struct reg_field reg_desc[DISPC_MGR_FLD_NUM];
169 [OMAP_DSS_CHANNEL_LCD] = {
171 .vsync_irq = DISPC_IRQ_VSYNC,
172 .framedone_irq = DISPC_IRQ_FRAMEDONE,
173 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
175 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
176 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
177 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
178 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
179 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
180 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
181 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
182 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
183 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
186 [OMAP_DSS_CHANNEL_DIGIT] = {
188 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
190 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
192 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
193 [DISPC_MGR_FLD_STNTFT] = { },
194 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
195 [DISPC_MGR_FLD_TFTDATALINES] = { },
196 [DISPC_MGR_FLD_STALLMODE] = { },
197 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
198 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
199 [DISPC_MGR_FLD_CPR] = { },
200 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
203 [OMAP_DSS_CHANNEL_LCD2] = {
205 .vsync_irq = DISPC_IRQ_VSYNC2,
206 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
207 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
209 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
210 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
211 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
212 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
213 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
214 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
215 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
216 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
217 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
220 [OMAP_DSS_CHANNEL_LCD3] = {
222 .vsync_irq = DISPC_IRQ_VSYNC3,
223 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
224 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
226 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
227 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
228 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
229 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
230 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
231 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
232 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
233 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
234 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
239 static void _omap_dispc_set_irqs(void);
240 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane);
241 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane);
243 static inline void dispc_write_reg(const u16 idx, u32 val)
245 __raw_writel(val, dispc.base + idx);
248 static inline u32 dispc_read_reg(const u16 idx)
250 return __raw_readl(dispc.base + idx);
253 static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
255 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
256 return REG_GET(rfld.reg, rfld.high, rfld.low);
259 static void mgr_fld_write(enum omap_channel channel,
260 enum mgr_reg_fields regfld, int val) {
261 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
262 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
266 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
268 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
270 static void dispc_save_context(void)
274 DSSDBG("dispc_save_context\n");
280 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
281 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
283 if (dss_has_feature(FEAT_MGR_LCD2)) {
287 if (dss_has_feature(FEAT_MGR_LCD3)) {
292 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
293 SR(DEFAULT_COLOR(i));
296 if (i == OMAP_DSS_CHANNEL_DIGIT)
307 if (dss_has_feature(FEAT_CPR)) {
314 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
319 SR(OVL_ATTRIBUTES(i));
320 SR(OVL_FIFO_THRESHOLD(i));
322 SR(OVL_PIXEL_INC(i));
323 if (dss_has_feature(FEAT_PRELOAD))
325 if (i == OMAP_DSS_GFX) {
326 SR(OVL_WINDOW_SKIP(i));
331 SR(OVL_PICTURE_SIZE(i));
335 for (j = 0; j < 8; j++)
336 SR(OVL_FIR_COEF_H(i, j));
338 for (j = 0; j < 8; j++)
339 SR(OVL_FIR_COEF_HV(i, j));
341 for (j = 0; j < 5; j++)
342 SR(OVL_CONV_COEF(i, j));
344 if (dss_has_feature(FEAT_FIR_COEF_V)) {
345 for (j = 0; j < 8; j++)
346 SR(OVL_FIR_COEF_V(i, j));
349 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
356 for (j = 0; j < 8; j++)
357 SR(OVL_FIR_COEF_H2(i, j));
359 for (j = 0; j < 8; j++)
360 SR(OVL_FIR_COEF_HV2(i, j));
362 for (j = 0; j < 8; j++)
363 SR(OVL_FIR_COEF_V2(i, j));
365 if (dss_has_feature(FEAT_ATTR2))
366 SR(OVL_ATTRIBUTES2(i));
369 if (dss_has_feature(FEAT_CORE_CLK_DIV))
372 dispc.ctx_loss_cnt = dss_get_ctx_loss_count(&dispc.pdev->dev);
373 dispc.ctx_valid = true;
375 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
378 static void dispc_restore_context(void)
382 DSSDBG("dispc_restore_context\n");
384 if (!dispc.ctx_valid)
387 ctx = dss_get_ctx_loss_count(&dispc.pdev->dev);
389 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
392 DSSDBG("ctx_loss_count: saved %d, current %d\n",
393 dispc.ctx_loss_cnt, ctx);
399 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
400 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
402 if (dss_has_feature(FEAT_MGR_LCD2))
404 if (dss_has_feature(FEAT_MGR_LCD3))
407 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
408 RR(DEFAULT_COLOR(i));
411 if (i == OMAP_DSS_CHANNEL_DIGIT)
422 if (dss_has_feature(FEAT_CPR)) {
429 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
434 RR(OVL_ATTRIBUTES(i));
435 RR(OVL_FIFO_THRESHOLD(i));
437 RR(OVL_PIXEL_INC(i));
438 if (dss_has_feature(FEAT_PRELOAD))
440 if (i == OMAP_DSS_GFX) {
441 RR(OVL_WINDOW_SKIP(i));
446 RR(OVL_PICTURE_SIZE(i));
450 for (j = 0; j < 8; j++)
451 RR(OVL_FIR_COEF_H(i, j));
453 for (j = 0; j < 8; j++)
454 RR(OVL_FIR_COEF_HV(i, j));
456 for (j = 0; j < 5; j++)
457 RR(OVL_CONV_COEF(i, j));
459 if (dss_has_feature(FEAT_FIR_COEF_V)) {
460 for (j = 0; j < 8; j++)
461 RR(OVL_FIR_COEF_V(i, j));
464 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
471 for (j = 0; j < 8; j++)
472 RR(OVL_FIR_COEF_H2(i, j));
474 for (j = 0; j < 8; j++)
475 RR(OVL_FIR_COEF_HV2(i, j));
477 for (j = 0; j < 8; j++)
478 RR(OVL_FIR_COEF_V2(i, j));
480 if (dss_has_feature(FEAT_ATTR2))
481 RR(OVL_ATTRIBUTES2(i));
484 if (dss_has_feature(FEAT_CORE_CLK_DIV))
487 /* enable last, because LCD & DIGIT enable are here */
489 if (dss_has_feature(FEAT_MGR_LCD2))
491 if (dss_has_feature(FEAT_MGR_LCD3))
493 /* clear spurious SYNC_LOST_DIGIT interrupts */
494 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
497 * enable last so IRQs won't trigger before
498 * the context is fully restored
502 DSSDBG("context restored\n");
508 int dispc_runtime_get(void)
512 DSSDBG("dispc_runtime_get\n");
514 r = pm_runtime_get_sync(&dispc.pdev->dev);
516 return r < 0 ? r : 0;
519 void dispc_runtime_put(void)
523 DSSDBG("dispc_runtime_put\n");
525 r = pm_runtime_put_sync(&dispc.pdev->dev);
526 WARN_ON(r < 0 && r != -ENOSYS);
529 u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
531 return mgr_desc[channel].vsync_irq;
534 u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
536 return mgr_desc[channel].framedone_irq;
539 bool dispc_mgr_go_busy(enum omap_channel channel)
541 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
544 void dispc_mgr_go(enum omap_channel channel)
546 bool enable_bit, go_bit;
548 /* if the channel is not enabled, we don't need GO */
549 enable_bit = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE) == 1;
554 go_bit = mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
557 DSSERR("GO bit not down for channel %d\n", channel);
561 DSSDBG("GO %s\n", mgr_desc[channel].name);
563 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
566 static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
568 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
571 static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
573 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
576 static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
578 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
581 static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
583 BUG_ON(plane == OMAP_DSS_GFX);
585 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
588 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
591 BUG_ON(plane == OMAP_DSS_GFX);
593 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
596 static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
598 BUG_ON(plane == OMAP_DSS_GFX);
600 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
603 static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
604 int fir_vinc, int five_taps,
605 enum omap_color_component color_comp)
607 const struct dispc_coef *h_coef, *v_coef;
610 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
611 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
613 for (i = 0; i < 8; i++) {
616 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
617 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
618 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
619 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
620 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
621 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
622 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
623 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
625 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
626 dispc_ovl_write_firh_reg(plane, i, h);
627 dispc_ovl_write_firhv_reg(plane, i, hv);
629 dispc_ovl_write_firh2_reg(plane, i, h);
630 dispc_ovl_write_firhv2_reg(plane, i, hv);
636 for (i = 0; i < 8; i++) {
638 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
639 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
640 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
641 dispc_ovl_write_firv_reg(plane, i, v);
643 dispc_ovl_write_firv2_reg(plane, i, v);
648 static void _dispc_setup_color_conv_coef(void)
651 const struct color_conv_coef {
652 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
655 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
658 const struct color_conv_coef *ct;
660 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
664 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
665 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 0),
666 CVAL(ct->rcr, ct->ry));
667 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 1),
668 CVAL(ct->gy, ct->rcb));
669 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 2),
670 CVAL(ct->gcb, ct->gcr));
671 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 3),
672 CVAL(ct->bcr, ct->by));
673 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 4),
676 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), ct->full_range,
684 static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
686 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
689 static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
691 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
694 static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
696 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
699 static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
701 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
704 static void dispc_ovl_set_pos(enum omap_plane plane,
705 enum omap_overlay_caps caps, int x, int y)
709 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
712 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
714 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
717 static void dispc_ovl_set_input_size(enum omap_plane plane, int width,
720 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
722 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
723 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
725 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
728 static void dispc_ovl_set_output_size(enum omap_plane plane, int width,
733 BUG_ON(plane == OMAP_DSS_GFX);
735 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
737 if (plane == OMAP_DSS_WB)
738 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
740 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
743 static void dispc_ovl_set_zorder(enum omap_plane plane,
744 enum omap_overlay_caps caps, u8 zorder)
746 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
749 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
752 static void dispc_ovl_enable_zorder_planes(void)
756 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
759 for (i = 0; i < dss_feat_get_num_ovls(); i++)
760 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
763 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
764 enum omap_overlay_caps caps, bool enable)
766 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
769 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
772 static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
773 enum omap_overlay_caps caps, u8 global_alpha)
775 static const unsigned shifts[] = { 0, 8, 16, 24, };
778 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
781 shift = shifts[plane];
782 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
785 static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
787 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
790 static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
792 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
795 static void dispc_ovl_set_color_mode(enum omap_plane plane,
796 enum omap_color_mode color_mode)
799 if (plane != OMAP_DSS_GFX) {
800 switch (color_mode) {
801 case OMAP_DSS_COLOR_NV12:
803 case OMAP_DSS_COLOR_RGBX16:
805 case OMAP_DSS_COLOR_RGBA16:
807 case OMAP_DSS_COLOR_RGB12U:
809 case OMAP_DSS_COLOR_ARGB16:
811 case OMAP_DSS_COLOR_RGB16:
813 case OMAP_DSS_COLOR_ARGB16_1555:
815 case OMAP_DSS_COLOR_RGB24U:
817 case OMAP_DSS_COLOR_RGB24P:
819 case OMAP_DSS_COLOR_YUV2:
821 case OMAP_DSS_COLOR_UYVY:
823 case OMAP_DSS_COLOR_ARGB32:
825 case OMAP_DSS_COLOR_RGBA32:
827 case OMAP_DSS_COLOR_RGBX32:
829 case OMAP_DSS_COLOR_XRGB16_1555:
835 switch (color_mode) {
836 case OMAP_DSS_COLOR_CLUT1:
838 case OMAP_DSS_COLOR_CLUT2:
840 case OMAP_DSS_COLOR_CLUT4:
842 case OMAP_DSS_COLOR_CLUT8:
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_RGBX16:
858 case OMAP_DSS_COLOR_RGBA16:
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:
873 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
876 static void dispc_ovl_configure_burst_type(enum omap_plane plane,
877 enum omap_dss_rotation_type rotation_type)
879 if (dss_has_feature(FEAT_BURST_2D) == 0)
882 if (rotation_type == OMAP_DSS_ROT_TILER)
883 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
885 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
888 void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
892 int chan = 0, chan2 = 0;
898 case OMAP_DSS_VIDEO1:
899 case OMAP_DSS_VIDEO2:
900 case OMAP_DSS_VIDEO3:
908 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
909 if (dss_has_feature(FEAT_MGR_LCD2)) {
911 case OMAP_DSS_CHANNEL_LCD:
915 case OMAP_DSS_CHANNEL_DIGIT:
919 case OMAP_DSS_CHANNEL_LCD2:
923 case OMAP_DSS_CHANNEL_LCD3:
924 if (dss_has_feature(FEAT_MGR_LCD3)) {
937 val = FLD_MOD(val, chan, shift, shift);
938 val = FLD_MOD(val, chan2, 31, 30);
940 val = FLD_MOD(val, channel, shift, shift);
942 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
945 static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
949 enum omap_channel channel;
955 case OMAP_DSS_VIDEO1:
956 case OMAP_DSS_VIDEO2:
957 case OMAP_DSS_VIDEO3:
965 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
967 if (dss_has_feature(FEAT_MGR_LCD3)) {
968 if (FLD_GET(val, 31, 30) == 0)
969 channel = FLD_GET(val, shift, shift);
970 else if (FLD_GET(val, 31, 30) == 1)
971 channel = OMAP_DSS_CHANNEL_LCD2;
973 channel = OMAP_DSS_CHANNEL_LCD3;
974 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
975 if (FLD_GET(val, 31, 30) == 0)
976 channel = FLD_GET(val, shift, shift);
978 channel = OMAP_DSS_CHANNEL_LCD2;
980 channel = FLD_GET(val, shift, shift);
986 void dispc_wb_set_channel_in(enum dss_writeback_channel channel)
988 enum omap_plane plane = OMAP_DSS_WB;
990 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16);
993 static void dispc_ovl_set_burst_size(enum omap_plane plane,
994 enum omap_burst_size burst_size)
996 static const unsigned shifts[] = { 6, 14, 14, 14, };
999 shift = shifts[plane];
1000 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
1003 static void dispc_configure_burst_sizes(void)
1006 const int burst_size = BURST_SIZE_X8;
1008 /* Configure burst size always to maximum size */
1009 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1010 dispc_ovl_set_burst_size(i, burst_size);
1013 static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
1015 unsigned unit = dss_feat_get_burst_size_unit();
1016 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1020 void dispc_enable_gamma_table(bool enable)
1023 * This is partially implemented to support only disabling of
1027 DSSWARN("Gamma table enabling for TV not yet supported");
1031 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1034 static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
1036 if (channel == OMAP_DSS_CHANNEL_DIGIT)
1039 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
1042 static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
1043 struct omap_dss_cpr_coefs *coefs)
1045 u32 coef_r, coef_g, coef_b;
1047 if (!dss_mgr_is_lcd(channel))
1050 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1051 FLD_VAL(coefs->rb, 9, 0);
1052 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1053 FLD_VAL(coefs->gb, 9, 0);
1054 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1055 FLD_VAL(coefs->bb, 9, 0);
1057 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1058 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1059 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1062 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
1066 BUG_ON(plane == OMAP_DSS_GFX);
1068 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1069 val = FLD_MOD(val, enable, 9, 9);
1070 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
1073 static void dispc_ovl_enable_replication(enum omap_plane plane,
1074 enum omap_overlay_caps caps, bool enable)
1076 static const unsigned shifts[] = { 5, 10, 10, 10 };
1079 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1082 shift = shifts[plane];
1083 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
1086 static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
1091 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
1092 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
1095 static void dispc_init_fifos(void)
1102 unit = dss_feat_get_buffer_size_unit();
1104 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1106 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1107 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
1109 dispc.fifo_size[fifo] = size;
1112 * By default fifos are mapped directly to overlays, fifo 0 to
1113 * ovl 0, fifo 1 to ovl 1, etc.
1115 dispc.fifo_assignment[fifo] = fifo;
1119 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1120 * causes problems with certain use cases, like using the tiler in 2D
1121 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1122 * giving GFX plane a larger fifo. WB but should work fine with a
1125 if (dispc.feat->gfx_fifo_workaround) {
1128 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1130 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1131 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1132 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1133 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1135 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1137 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1138 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1142 static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1147 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1148 if (dispc.fifo_assignment[fifo] == plane)
1149 size += dispc.fifo_size[fifo];
1155 void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
1157 u8 hi_start, hi_end, lo_start, lo_end;
1160 unit = dss_feat_get_buffer_size_unit();
1162 WARN_ON(low % unit != 0);
1163 WARN_ON(high % unit != 0);
1168 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1169 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1171 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1173 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1174 lo_start, lo_end) * unit,
1175 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1176 hi_start, hi_end) * unit,
1177 low * unit, high * unit);
1179 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1180 FLD_VAL(high, hi_start, hi_end) |
1181 FLD_VAL(low, lo_start, lo_end));
1184 void dispc_enable_fifomerge(bool enable)
1186 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1191 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1192 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1195 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1196 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1200 * All sizes are in bytes. Both the buffer and burst are made of
1201 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1204 unsigned buf_unit = dss_feat_get_buffer_size_unit();
1205 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1208 burst_size = dispc_ovl_get_burst_size(plane);
1209 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
1211 if (use_fifomerge) {
1212 total_fifo_size = 0;
1213 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1214 total_fifo_size += dispc_ovl_get_fifo_size(i);
1216 total_fifo_size = ovl_fifo_size;
1220 * We use the same low threshold for both fifomerge and non-fifomerge
1221 * cases, but for fifomerge we calculate the high threshold using the
1222 * combined fifo size
1225 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1226 *fifo_low = ovl_fifo_size - burst_size * 2;
1227 *fifo_high = total_fifo_size - burst_size;
1229 *fifo_low = ovl_fifo_size - burst_size;
1230 *fifo_high = total_fifo_size - buf_unit;
1234 static void dispc_ovl_set_fir(enum omap_plane plane,
1236 enum omap_color_component color_comp)
1240 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1241 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1243 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1244 &hinc_start, &hinc_end);
1245 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1246 &vinc_start, &vinc_end);
1247 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1248 FLD_VAL(hinc, hinc_start, hinc_end);
1250 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1252 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1253 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1257 static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1260 u8 hor_start, hor_end, vert_start, vert_end;
1262 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1263 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1265 val = FLD_VAL(vaccu, vert_start, vert_end) |
1266 FLD_VAL(haccu, hor_start, hor_end);
1268 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1271 static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1274 u8 hor_start, hor_end, vert_start, vert_end;
1276 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1277 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1279 val = FLD_VAL(vaccu, vert_start, vert_end) |
1280 FLD_VAL(haccu, hor_start, hor_end);
1282 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1285 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1290 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1291 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1294 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1299 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1300 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1303 static void dispc_ovl_set_scale_param(enum omap_plane plane,
1304 u16 orig_width, u16 orig_height,
1305 u16 out_width, u16 out_height,
1306 bool five_taps, u8 rotation,
1307 enum omap_color_component color_comp)
1309 int fir_hinc, fir_vinc;
1311 fir_hinc = 1024 * orig_width / out_width;
1312 fir_vinc = 1024 * orig_height / out_height;
1314 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1316 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1319 static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1320 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1321 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1323 int h_accu2_0, h_accu2_1;
1324 int v_accu2_0, v_accu2_1;
1325 int chroma_hinc, chroma_vinc;
1335 const struct accu *accu_table;
1336 const struct accu *accu_val;
1338 static const struct accu accu_nv12[4] = {
1339 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1340 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1341 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1342 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1345 static const struct accu accu_nv12_ilace[4] = {
1346 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1347 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1348 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1349 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1352 static const struct accu accu_yuv[4] = {
1353 { 0, 1, 0, 1, 0, 1, 0, 1 },
1354 { 0, 1, 0, 1, 0, 1, 0, 1 },
1355 { -1, 1, 0, 1, 0, 1, 0, 1 },
1356 { 0, 1, 0, 1, -1, 1, 0, 1 },
1360 case OMAP_DSS_ROT_0:
1363 case OMAP_DSS_ROT_90:
1366 case OMAP_DSS_ROT_180:
1369 case OMAP_DSS_ROT_270:
1377 switch (color_mode) {
1378 case OMAP_DSS_COLOR_NV12:
1380 accu_table = accu_nv12_ilace;
1382 accu_table = accu_nv12;
1384 case OMAP_DSS_COLOR_YUV2:
1385 case OMAP_DSS_COLOR_UYVY:
1386 accu_table = accu_yuv;
1393 accu_val = &accu_table[idx];
1395 chroma_hinc = 1024 * orig_width / out_width;
1396 chroma_vinc = 1024 * orig_height / out_height;
1398 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1399 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1400 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1401 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1403 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1404 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1407 static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1408 u16 orig_width, u16 orig_height,
1409 u16 out_width, u16 out_height,
1410 bool ilace, bool five_taps,
1411 bool fieldmode, enum omap_color_mode color_mode,
1418 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1419 out_width, out_height, five_taps,
1420 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1421 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1423 /* RESIZEENABLE and VERTICALTAPS */
1424 l &= ~((0x3 << 5) | (0x1 << 21));
1425 l |= (orig_width != out_width) ? (1 << 5) : 0;
1426 l |= (orig_height != out_height) ? (1 << 6) : 0;
1427 l |= five_taps ? (1 << 21) : 0;
1429 /* VRESIZECONF and HRESIZECONF */
1430 if (dss_has_feature(FEAT_RESIZECONF)) {
1432 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1433 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1436 /* LINEBUFFERSPLIT */
1437 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1439 l |= five_taps ? (1 << 22) : 0;
1442 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1445 * field 0 = even field = bottom field
1446 * field 1 = odd field = top field
1448 if (ilace && !fieldmode) {
1450 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1451 if (accu0 >= 1024/2) {
1457 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1458 dispc_ovl_set_vid_accu1(plane, 0, accu1);
1461 static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1462 u16 orig_width, u16 orig_height,
1463 u16 out_width, u16 out_height,
1464 bool ilace, bool five_taps,
1465 bool fieldmode, enum omap_color_mode color_mode,
1468 int scale_x = out_width != orig_width;
1469 int scale_y = out_height != orig_height;
1470 bool chroma_upscale = plane != OMAP_DSS_WB ? true : false;
1472 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1474 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1475 color_mode != OMAP_DSS_COLOR_UYVY &&
1476 color_mode != OMAP_DSS_COLOR_NV12)) {
1477 /* reset chroma resampling for RGB formats */
1478 if (plane != OMAP_DSS_WB)
1479 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1483 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1484 out_height, ilace, color_mode, rotation);
1486 switch (color_mode) {
1487 case OMAP_DSS_COLOR_NV12:
1488 if (chroma_upscale) {
1489 /* UV is subsampled by 2 horizontally and vertically */
1493 /* UV is downsampled by 2 horizontally and vertically */
1499 case OMAP_DSS_COLOR_YUV2:
1500 case OMAP_DSS_COLOR_UYVY:
1501 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
1502 if (rotation == OMAP_DSS_ROT_0 ||
1503 rotation == OMAP_DSS_ROT_180) {
1505 /* UV is subsampled by 2 horizontally */
1508 /* UV is downsampled by 2 horizontally */
1512 /* must use FIR for YUV422 if rotated */
1513 if (rotation != OMAP_DSS_ROT_0)
1514 scale_x = scale_y = true;
1522 if (out_width != orig_width)
1524 if (out_height != orig_height)
1527 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1528 out_width, out_height, five_taps,
1529 rotation, DISPC_COLOR_COMPONENT_UV);
1531 if (plane != OMAP_DSS_WB)
1532 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1533 (scale_x || scale_y) ? 1 : 0, 8, 8);
1536 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1538 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1541 static void dispc_ovl_set_scaling(enum omap_plane plane,
1542 u16 orig_width, u16 orig_height,
1543 u16 out_width, u16 out_height,
1544 bool ilace, bool five_taps,
1545 bool fieldmode, enum omap_color_mode color_mode,
1548 BUG_ON(plane == OMAP_DSS_GFX);
1550 dispc_ovl_set_scaling_common(plane,
1551 orig_width, orig_height,
1552 out_width, out_height,
1554 fieldmode, color_mode,
1557 dispc_ovl_set_scaling_uv(plane,
1558 orig_width, orig_height,
1559 out_width, out_height,
1561 fieldmode, color_mode,
1565 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1566 bool mirroring, enum omap_color_mode color_mode)
1568 bool row_repeat = false;
1571 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1572 color_mode == OMAP_DSS_COLOR_UYVY) {
1576 case OMAP_DSS_ROT_0:
1579 case OMAP_DSS_ROT_90:
1582 case OMAP_DSS_ROT_180:
1585 case OMAP_DSS_ROT_270:
1591 case OMAP_DSS_ROT_0:
1594 case OMAP_DSS_ROT_90:
1597 case OMAP_DSS_ROT_180:
1600 case OMAP_DSS_ROT_270:
1606 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1612 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1613 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1614 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1615 row_repeat ? 1 : 0, 18, 18);
1618 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1620 switch (color_mode) {
1621 case OMAP_DSS_COLOR_CLUT1:
1623 case OMAP_DSS_COLOR_CLUT2:
1625 case OMAP_DSS_COLOR_CLUT4:
1627 case OMAP_DSS_COLOR_CLUT8:
1628 case OMAP_DSS_COLOR_NV12:
1630 case OMAP_DSS_COLOR_RGB12U:
1631 case OMAP_DSS_COLOR_RGB16:
1632 case OMAP_DSS_COLOR_ARGB16:
1633 case OMAP_DSS_COLOR_YUV2:
1634 case OMAP_DSS_COLOR_UYVY:
1635 case OMAP_DSS_COLOR_RGBA16:
1636 case OMAP_DSS_COLOR_RGBX16:
1637 case OMAP_DSS_COLOR_ARGB16_1555:
1638 case OMAP_DSS_COLOR_XRGB16_1555:
1640 case OMAP_DSS_COLOR_RGB24P:
1642 case OMAP_DSS_COLOR_RGB24U:
1643 case OMAP_DSS_COLOR_ARGB32:
1644 case OMAP_DSS_COLOR_RGBA32:
1645 case OMAP_DSS_COLOR_RGBX32:
1653 static s32 pixinc(int pixels, u8 ps)
1657 else if (pixels > 1)
1658 return 1 + (pixels - 1) * ps;
1659 else if (pixels < 0)
1660 return 1 - (-pixels + 1) * ps;
1666 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1668 u16 width, u16 height,
1669 enum omap_color_mode color_mode, bool fieldmode,
1670 unsigned int field_offset,
1671 unsigned *offset0, unsigned *offset1,
1672 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1676 /* FIXME CLUT formats */
1677 switch (color_mode) {
1678 case OMAP_DSS_COLOR_CLUT1:
1679 case OMAP_DSS_COLOR_CLUT2:
1680 case OMAP_DSS_COLOR_CLUT4:
1681 case OMAP_DSS_COLOR_CLUT8:
1684 case OMAP_DSS_COLOR_YUV2:
1685 case OMAP_DSS_COLOR_UYVY:
1689 ps = color_mode_to_bpp(color_mode) / 8;
1693 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1697 * field 0 = even field = bottom field
1698 * field 1 = odd field = top field
1700 switch (rotation + mirror * 4) {
1701 case OMAP_DSS_ROT_0:
1702 case OMAP_DSS_ROT_180:
1704 * If the pixel format is YUV or UYVY divide the width
1705 * of the image by 2 for 0 and 180 degree rotation.
1707 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1708 color_mode == OMAP_DSS_COLOR_UYVY)
1710 case OMAP_DSS_ROT_90:
1711 case OMAP_DSS_ROT_270:
1714 *offset0 = field_offset * screen_width * ps;
1718 *row_inc = pixinc(1 +
1719 (y_predecim * screen_width - x_predecim * width) +
1720 (fieldmode ? screen_width : 0), ps);
1721 *pix_inc = pixinc(x_predecim, ps);
1724 case OMAP_DSS_ROT_0 + 4:
1725 case OMAP_DSS_ROT_180 + 4:
1726 /* If the pixel format is YUV or UYVY divide the width
1727 * of the image by 2 for 0 degree and 180 degree
1729 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1730 color_mode == OMAP_DSS_COLOR_UYVY)
1732 case OMAP_DSS_ROT_90 + 4:
1733 case OMAP_DSS_ROT_270 + 4:
1736 *offset0 = field_offset * screen_width * ps;
1739 *row_inc = pixinc(1 -
1740 (y_predecim * screen_width + x_predecim * width) -
1741 (fieldmode ? screen_width : 0), ps);
1742 *pix_inc = pixinc(x_predecim, ps);
1751 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1753 u16 width, u16 height,
1754 enum omap_color_mode color_mode, bool fieldmode,
1755 unsigned int field_offset,
1756 unsigned *offset0, unsigned *offset1,
1757 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1762 /* FIXME CLUT formats */
1763 switch (color_mode) {
1764 case OMAP_DSS_COLOR_CLUT1:
1765 case OMAP_DSS_COLOR_CLUT2:
1766 case OMAP_DSS_COLOR_CLUT4:
1767 case OMAP_DSS_COLOR_CLUT8:
1771 ps = color_mode_to_bpp(color_mode) / 8;
1775 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1778 /* width & height are overlay sizes, convert to fb sizes */
1780 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1789 * field 0 = even field = bottom field
1790 * field 1 = odd field = top field
1792 switch (rotation + mirror * 4) {
1793 case OMAP_DSS_ROT_0:
1796 *offset0 = *offset1 + field_offset * screen_width * ps;
1798 *offset0 = *offset1;
1799 *row_inc = pixinc(1 +
1800 (y_predecim * screen_width - fbw * x_predecim) +
1801 (fieldmode ? screen_width : 0), ps);
1802 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1803 color_mode == OMAP_DSS_COLOR_UYVY)
1804 *pix_inc = pixinc(x_predecim, 2 * ps);
1806 *pix_inc = pixinc(x_predecim, ps);
1808 case OMAP_DSS_ROT_90:
1809 *offset1 = screen_width * (fbh - 1) * ps;
1811 *offset0 = *offset1 + field_offset * ps;
1813 *offset0 = *offset1;
1814 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1815 y_predecim + (fieldmode ? 1 : 0), ps);
1816 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1818 case OMAP_DSS_ROT_180:
1819 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1821 *offset0 = *offset1 - field_offset * screen_width * ps;
1823 *offset0 = *offset1;
1824 *row_inc = pixinc(-1 -
1825 (y_predecim * screen_width - fbw * x_predecim) -
1826 (fieldmode ? screen_width : 0), ps);
1827 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1828 color_mode == OMAP_DSS_COLOR_UYVY)
1829 *pix_inc = pixinc(-x_predecim, 2 * ps);
1831 *pix_inc = pixinc(-x_predecim, ps);
1833 case OMAP_DSS_ROT_270:
1834 *offset1 = (fbw - 1) * ps;
1836 *offset0 = *offset1 - field_offset * ps;
1838 *offset0 = *offset1;
1839 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1840 y_predecim - (fieldmode ? 1 : 0), ps);
1841 *pix_inc = pixinc(x_predecim * screen_width, ps);
1845 case OMAP_DSS_ROT_0 + 4:
1846 *offset1 = (fbw - 1) * ps;
1848 *offset0 = *offset1 + field_offset * screen_width * ps;
1850 *offset0 = *offset1;
1851 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
1852 (fieldmode ? screen_width : 0),
1854 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1855 color_mode == OMAP_DSS_COLOR_UYVY)
1856 *pix_inc = pixinc(-x_predecim, 2 * ps);
1858 *pix_inc = pixinc(-x_predecim, ps);
1861 case OMAP_DSS_ROT_90 + 4:
1864 *offset0 = *offset1 + field_offset * ps;
1866 *offset0 = *offset1;
1867 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1868 y_predecim + (fieldmode ? 1 : 0),
1870 *pix_inc = pixinc(x_predecim * screen_width, ps);
1873 case OMAP_DSS_ROT_180 + 4:
1874 *offset1 = screen_width * (fbh - 1) * ps;
1876 *offset0 = *offset1 - field_offset * screen_width * ps;
1878 *offset0 = *offset1;
1879 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
1880 (fieldmode ? screen_width : 0),
1882 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1883 color_mode == OMAP_DSS_COLOR_UYVY)
1884 *pix_inc = pixinc(x_predecim, 2 * ps);
1886 *pix_inc = pixinc(x_predecim, ps);
1889 case OMAP_DSS_ROT_270 + 4:
1890 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1892 *offset0 = *offset1 - field_offset * ps;
1894 *offset0 = *offset1;
1895 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1896 y_predecim - (fieldmode ? 1 : 0),
1898 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1907 static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1908 enum omap_color_mode color_mode, bool fieldmode,
1909 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1910 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1914 switch (color_mode) {
1915 case OMAP_DSS_COLOR_CLUT1:
1916 case OMAP_DSS_COLOR_CLUT2:
1917 case OMAP_DSS_COLOR_CLUT4:
1918 case OMAP_DSS_COLOR_CLUT8:
1922 ps = color_mode_to_bpp(color_mode) / 8;
1926 DSSDBG("scrw %d, width %d\n", screen_width, width);
1929 * field 0 = even field = bottom field
1930 * field 1 = odd field = top field
1934 *offset0 = *offset1 + field_offset * screen_width * ps;
1936 *offset0 = *offset1;
1937 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1938 (fieldmode ? screen_width : 0), ps);
1939 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1940 color_mode == OMAP_DSS_COLOR_UYVY)
1941 *pix_inc = pixinc(x_predecim, 2 * ps);
1943 *pix_inc = pixinc(x_predecim, ps);
1947 * This function is used to avoid synclosts in OMAP3, because of some
1948 * undocumented horizontal position and timing related limitations.
1950 static int check_horiz_timing_omap3(enum omap_plane plane,
1951 const struct omap_video_timings *t, u16 pos_x,
1952 u16 width, u16 height, u16 out_width, u16 out_height)
1954 int DS = DIV_ROUND_UP(height, out_height);
1955 unsigned long nonactive;
1956 static const u8 limits[3] = { 8, 10, 20 };
1958 unsigned long pclk = dispc_plane_pclk_rate(plane);
1959 unsigned long lclk = dispc_plane_lclk_rate(plane);
1962 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
1965 if (out_height < height)
1967 if (out_width < width)
1969 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
1970 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
1971 if (blank <= limits[i])
1975 * Pixel data should be prepared before visible display point starts.
1976 * So, atleast DS-2 lines must have already been fetched by DISPC
1977 * during nonactive - pos_x period.
1979 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
1980 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
1981 val, max(0, DS - 2) * width);
1982 if (val < max(0, DS - 2) * width)
1986 * All lines need to be refilled during the nonactive period of which
1987 * only one line can be loaded during the active period. So, atleast
1988 * DS - 1 lines should be loaded during nonactive period.
1990 val = div_u64((u64)nonactive * lclk, pclk);
1991 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
1992 val, max(0, DS - 1) * width);
1993 if (val < max(0, DS - 1) * width)
1999 static unsigned long calc_core_clk_five_taps(enum omap_plane plane,
2000 const struct omap_video_timings *mgr_timings, u16 width,
2001 u16 height, u16 out_width, u16 out_height,
2002 enum omap_color_mode color_mode)
2006 unsigned long pclk = dispc_plane_pclk_rate(plane);
2008 if (height <= out_height && width <= out_width)
2009 return (unsigned long) pclk;
2011 if (height > out_height) {
2012 unsigned int ppl = mgr_timings->x_res;
2014 tmp = pclk * height * out_width;
2015 do_div(tmp, 2 * out_height * ppl);
2018 if (height > 2 * out_height) {
2019 if (ppl == out_width)
2022 tmp = pclk * (height - 2 * out_height) * out_width;
2023 do_div(tmp, 2 * out_height * (ppl - out_width));
2024 core_clk = max_t(u32, core_clk, tmp);
2028 if (width > out_width) {
2030 do_div(tmp, out_width);
2031 core_clk = max_t(u32, core_clk, tmp);
2033 if (color_mode == OMAP_DSS_COLOR_RGB24U)
2040 static unsigned long calc_core_clk_24xx(enum omap_plane plane, u16 width,
2041 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2043 unsigned long pclk = dispc_plane_pclk_rate(plane);
2045 if (height > out_height && width > out_width)
2051 static unsigned long calc_core_clk_34xx(enum omap_plane plane, u16 width,
2052 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2054 unsigned int hf, vf;
2055 unsigned long pclk = dispc_plane_pclk_rate(plane);
2058 * FIXME how to determine the 'A' factor
2059 * for the no downscaling case ?
2062 if (width > 3 * out_width)
2064 else if (width > 2 * out_width)
2066 else if (width > out_width)
2070 if (height > out_height)
2075 return pclk * vf * hf;
2078 static unsigned long calc_core_clk_44xx(enum omap_plane plane, u16 width,
2079 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2084 * If the overlay/writeback is in mem to mem mode, there are no
2085 * downscaling limitations with respect to pixel clock, return 1 as
2086 * required core clock to represent that we have sufficient enough
2087 * core clock to do maximum downscaling
2092 pclk = dispc_plane_pclk_rate(plane);
2094 if (width > out_width)
2095 return DIV_ROUND_UP(pclk, out_width) * width;
2100 static int dispc_ovl_calc_scaling_24xx(enum omap_plane plane,
2101 const struct omap_video_timings *mgr_timings,
2102 u16 width, u16 height, u16 out_width, u16 out_height,
2103 enum omap_color_mode color_mode, bool *five_taps,
2104 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2105 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2108 u16 in_width, in_height;
2109 int min_factor = min(*decim_x, *decim_y);
2110 const int maxsinglelinewidth =
2111 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2116 in_height = DIV_ROUND_UP(height, *decim_y);
2117 in_width = DIV_ROUND_UP(width, *decim_x);
2118 *core_clk = dispc.feat->calc_core_clk(plane, in_width,
2119 in_height, out_width, out_height, mem_to_mem);
2120 error = (in_width > maxsinglelinewidth || !*core_clk ||
2121 *core_clk > dispc_core_clk_rate());
2123 if (*decim_x == *decim_y) {
2124 *decim_x = min_factor;
2127 swap(*decim_x, *decim_y);
2128 if (*decim_x < *decim_y)
2132 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2134 if (in_width > maxsinglelinewidth) {
2135 DSSERR("Cannot scale max input width exceeded");
2141 static int dispc_ovl_calc_scaling_34xx(enum omap_plane plane,
2142 const struct omap_video_timings *mgr_timings,
2143 u16 width, u16 height, u16 out_width, u16 out_height,
2144 enum omap_color_mode color_mode, bool *five_taps,
2145 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2146 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2149 u16 in_width, in_height;
2150 int min_factor = min(*decim_x, *decim_y);
2151 const int maxsinglelinewidth =
2152 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2155 in_height = DIV_ROUND_UP(height, *decim_y);
2156 in_width = DIV_ROUND_UP(width, *decim_x);
2157 *core_clk = calc_core_clk_five_taps(plane, mgr_timings,
2158 in_width, in_height, out_width, out_height, color_mode);
2160 error = check_horiz_timing_omap3(plane, mgr_timings,
2161 pos_x, in_width, in_height, out_width,
2164 if (in_width > maxsinglelinewidth)
2165 if (in_height > out_height &&
2166 in_height < out_height * 2)
2169 *core_clk = dispc.feat->calc_core_clk(plane, in_width,
2170 in_height, out_width, out_height,
2173 error = (error || in_width > maxsinglelinewidth * 2 ||
2174 (in_width > maxsinglelinewidth && *five_taps) ||
2175 !*core_clk || *core_clk > dispc_core_clk_rate());
2177 if (*decim_x == *decim_y) {
2178 *decim_x = min_factor;
2181 swap(*decim_x, *decim_y);
2182 if (*decim_x < *decim_y)
2186 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2188 if (check_horiz_timing_omap3(plane, mgr_timings, pos_x, width, height,
2189 out_width, out_height)){
2190 DSSERR("horizontal timing too tight\n");
2194 if (in_width > (maxsinglelinewidth * 2)) {
2195 DSSERR("Cannot setup scaling");
2196 DSSERR("width exceeds maximum width possible");
2200 if (in_width > maxsinglelinewidth && *five_taps) {
2201 DSSERR("cannot setup scaling with five taps");
2207 static int dispc_ovl_calc_scaling_44xx(enum omap_plane plane,
2208 const struct omap_video_timings *mgr_timings,
2209 u16 width, u16 height, u16 out_width, u16 out_height,
2210 enum omap_color_mode color_mode, bool *five_taps,
2211 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2212 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2214 u16 in_width, in_width_max;
2215 int decim_x_min = *decim_x;
2216 u16 in_height = DIV_ROUND_UP(height, *decim_y);
2217 const int maxsinglelinewidth =
2218 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2219 unsigned long pclk = dispc_plane_pclk_rate(plane);
2220 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2223 in_width_max = DIV_ROUND_UP(out_width, maxdownscale);
2225 in_width_max = dispc_core_clk_rate() /
2226 DIV_ROUND_UP(pclk, out_width);
2228 *decim_x = DIV_ROUND_UP(width, in_width_max);
2230 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2231 if (*decim_x > *x_predecim)
2235 in_width = DIV_ROUND_UP(width, *decim_x);
2236 } while (*decim_x <= *x_predecim &&
2237 in_width > maxsinglelinewidth && ++*decim_x);
2239 if (in_width > maxsinglelinewidth) {
2240 DSSERR("Cannot scale width exceeds max line width");
2244 *core_clk = dispc.feat->calc_core_clk(plane, in_width, in_height,
2245 out_width, out_height, mem_to_mem);
2249 static int dispc_ovl_calc_scaling(enum omap_plane plane,
2250 enum omap_overlay_caps caps,
2251 const struct omap_video_timings *mgr_timings,
2252 u16 width, u16 height, u16 out_width, u16 out_height,
2253 enum omap_color_mode color_mode, bool *five_taps,
2254 int *x_predecim, int *y_predecim, u16 pos_x,
2255 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
2257 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2258 const int max_decim_limit = 16;
2259 unsigned long core_clk = 0;
2260 int decim_x, decim_y, ret;
2262 if (width == out_width && height == out_height)
2265 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
2268 *x_predecim = max_decim_limit;
2269 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2270 dss_has_feature(FEAT_BURST_2D)) ? 2 : max_decim_limit;
2272 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2273 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2274 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2275 color_mode == OMAP_DSS_COLOR_CLUT8) {
2282 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2283 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2285 if (decim_x > *x_predecim || out_width > width * 8)
2288 if (decim_y > *y_predecim || out_height > height * 8)
2291 ret = dispc.feat->calc_scaling(plane, mgr_timings, width, height,
2292 out_width, out_height, color_mode, five_taps,
2293 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2298 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2299 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
2301 if (!core_clk || core_clk > dispc_core_clk_rate()) {
2302 DSSERR("failed to set up scaling, "
2303 "required core clk rate = %lu Hz, "
2304 "current core clk rate = %lu Hz\n",
2305 core_clk, dispc_core_clk_rate());
2309 *x_predecim = decim_x;
2310 *y_predecim = decim_y;
2314 static int dispc_ovl_setup_common(enum omap_plane plane,
2315 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2316 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2317 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2318 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2319 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
2320 bool replication, const struct omap_video_timings *mgr_timings,
2323 bool five_taps = true;
2326 unsigned offset0, offset1;
2329 u16 frame_height = height;
2330 unsigned int field_offset = 0;
2331 u16 in_height = height;
2332 u16 in_width = width;
2333 int x_predecim = 1, y_predecim = 1;
2334 bool ilace = mgr_timings->interlace;
2339 out_width = out_width == 0 ? width : out_width;
2340 out_height = out_height == 0 ? height : out_height;
2342 if (ilace && height == out_height)
2351 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2352 "out_height %d\n", in_height, pos_y,
2356 if (!dss_feat_color_mode_supported(plane, color_mode))
2359 r = dispc_ovl_calc_scaling(plane, caps, mgr_timings, in_width,
2360 in_height, out_width, out_height, color_mode,
2361 &five_taps, &x_predecim, &y_predecim, pos_x,
2362 rotation_type, mem_to_mem);
2366 in_width = DIV_ROUND_UP(in_width, x_predecim);
2367 in_height = DIV_ROUND_UP(in_height, y_predecim);
2369 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2370 color_mode == OMAP_DSS_COLOR_UYVY ||
2371 color_mode == OMAP_DSS_COLOR_NV12)
2374 if (ilace && !fieldmode) {
2376 * when downscaling the bottom field may have to start several
2377 * source lines below the top field. Unfortunately ACCUI
2378 * registers will only hold the fractional part of the offset
2379 * so the integer part must be added to the base address of the
2382 if (!in_height || in_height == out_height)
2385 field_offset = in_height / out_height / 2;
2388 /* Fields are independent but interleaved in memory. */
2397 if (rotation_type == OMAP_DSS_ROT_TILER)
2398 calc_tiler_rotation_offset(screen_width, in_width,
2399 color_mode, fieldmode, field_offset,
2400 &offset0, &offset1, &row_inc, &pix_inc,
2401 x_predecim, y_predecim);
2402 else if (rotation_type == OMAP_DSS_ROT_DMA)
2403 calc_dma_rotation_offset(rotation, mirror,
2404 screen_width, in_width, frame_height,
2405 color_mode, fieldmode, field_offset,
2406 &offset0, &offset1, &row_inc, &pix_inc,
2407 x_predecim, y_predecim);
2409 calc_vrfb_rotation_offset(rotation, mirror,
2410 screen_width, in_width, frame_height,
2411 color_mode, fieldmode, field_offset,
2412 &offset0, &offset1, &row_inc, &pix_inc,
2413 x_predecim, y_predecim);
2415 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2416 offset0, offset1, row_inc, pix_inc);
2418 dispc_ovl_set_color_mode(plane, color_mode);
2420 dispc_ovl_configure_burst_type(plane, rotation_type);
2422 dispc_ovl_set_ba0(plane, paddr + offset0);
2423 dispc_ovl_set_ba1(plane, paddr + offset1);
2425 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2426 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2427 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
2430 dispc_ovl_set_row_inc(plane, row_inc);
2431 dispc_ovl_set_pix_inc(plane, pix_inc);
2433 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
2434 in_height, out_width, out_height);
2436 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
2438 dispc_ovl_set_input_size(plane, in_width, in_height);
2440 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
2441 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2442 out_height, ilace, five_taps, fieldmode,
2443 color_mode, rotation);
2444 dispc_ovl_set_output_size(plane, out_width, out_height);
2445 dispc_ovl_set_vid_color_conv(plane, cconv);
2448 dispc_ovl_set_rotation_attrs(plane, rotation, mirror, color_mode);
2450 dispc_ovl_set_zorder(plane, caps, zorder);
2451 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2452 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
2454 dispc_ovl_enable_replication(plane, caps, replication);
2459 int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
2460 bool replication, const struct omap_video_timings *mgr_timings,
2464 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
2465 enum omap_channel channel;
2467 channel = dispc_ovl_get_channel_out(plane);
2469 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
2470 "%dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2471 plane, oi->paddr, oi->p_uv_addr, oi->screen_width, oi->pos_x,
2472 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2473 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2475 r = dispc_ovl_setup_common(plane, ovl->caps, oi->paddr, oi->p_uv_addr,
2476 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2477 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2478 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
2479 oi->rotation_type, replication, mgr_timings, mem_to_mem);
2484 int dispc_wb_setup(const struct omap_dss_writeback_info *wi,
2485 bool mem_to_mem, const struct omap_video_timings *mgr_timings)
2489 enum omap_plane plane = OMAP_DSS_WB;
2490 const int pos_x = 0, pos_y = 0;
2491 const u8 zorder = 0, global_alpha = 0;
2492 const bool replication = false;
2494 int in_width = mgr_timings->x_res;
2495 int in_height = mgr_timings->y_res;
2496 enum omap_overlay_caps caps =
2497 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2499 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2500 "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width,
2501 in_height, wi->width, wi->height, wi->color_mode, wi->rotation,
2504 r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr,
2505 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2506 wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder,
2507 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
2508 replication, mgr_timings, mem_to_mem);
2510 switch (wi->color_mode) {
2511 case OMAP_DSS_COLOR_RGB16:
2512 case OMAP_DSS_COLOR_RGB24P:
2513 case OMAP_DSS_COLOR_ARGB16:
2514 case OMAP_DSS_COLOR_RGBA16:
2515 case OMAP_DSS_COLOR_RGB12U:
2516 case OMAP_DSS_COLOR_ARGB16_1555:
2517 case OMAP_DSS_COLOR_XRGB16_1555:
2518 case OMAP_DSS_COLOR_RGBX16:
2526 /* setup extra DISPC_WB_ATTRIBUTES */
2527 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
2528 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2529 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2530 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
2535 int dispc_ovl_enable(enum omap_plane plane, bool enable)
2537 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2539 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2544 static void dispc_disable_isr(void *data, u32 mask)
2546 struct completion *compl = data;
2550 static void _enable_lcd_out(enum omap_channel channel, bool enable)
2552 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2553 /* flush posted write */
2554 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2557 static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
2559 struct completion frame_done_completion;
2564 /* When we disable LCD output, we need to wait until frame is done.
2565 * Otherwise the DSS is still working, and turning off the clocks
2566 * prevents DSS from going to OFF mode */
2567 is_on = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2569 irq = mgr_desc[channel].framedone_irq;
2571 if (!enable && is_on) {
2572 init_completion(&frame_done_completion);
2574 r = omap_dispc_register_isr(dispc_disable_isr,
2575 &frame_done_completion, irq);
2578 DSSERR("failed to register FRAMEDONE isr\n");
2581 _enable_lcd_out(channel, enable);
2583 if (!enable && is_on) {
2584 if (!wait_for_completion_timeout(&frame_done_completion,
2585 msecs_to_jiffies(100)))
2586 DSSERR("timeout waiting for FRAME DONE\n");
2588 r = omap_dispc_unregister_isr(dispc_disable_isr,
2589 &frame_done_completion, irq);
2592 DSSERR("failed to unregister FRAMEDONE isr\n");
2596 static void _enable_digit_out(bool enable)
2598 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
2599 /* flush posted write */
2600 dispc_read_reg(DISPC_CONTROL);
2603 static void dispc_mgr_enable_digit_out(bool enable)
2605 struct completion frame_done_completion;
2606 enum dss_hdmi_venc_clk_source_select src;
2611 if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
2614 src = dss_get_hdmi_venc_clk_source();
2617 unsigned long flags;
2618 /* When we enable digit output, we'll get an extra digit
2619 * sync lost interrupt, that we need to ignore */
2620 spin_lock_irqsave(&dispc.irq_lock, flags);
2621 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
2622 _omap_dispc_set_irqs();
2623 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2626 /* When we disable digit output, we need to wait until fields are done.
2627 * Otherwise the DSS is still working, and turning off the clocks
2628 * prevents DSS from going to OFF mode. And when enabling, we need to
2629 * wait for the extra sync losts */
2630 init_completion(&frame_done_completion);
2632 if (src == DSS_HDMI_M_PCLK && enable == false) {
2633 irq_mask = DISPC_IRQ_FRAMEDONETV;
2636 irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
2637 /* XXX I understand from TRM that we should only wait for the
2638 * current field to complete. But it seems we have to wait for
2643 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
2646 DSSERR("failed to register %x isr\n", irq_mask);
2648 _enable_digit_out(enable);
2650 for (i = 0; i < num_irqs; ++i) {
2651 if (!wait_for_completion_timeout(&frame_done_completion,
2652 msecs_to_jiffies(100)))
2653 DSSERR("timeout waiting for digit out to %s\n",
2654 enable ? "start" : "stop");
2657 r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
2660 DSSERR("failed to unregister %x isr\n", irq_mask);
2663 unsigned long flags;
2664 spin_lock_irqsave(&dispc.irq_lock, flags);
2665 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
2666 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
2667 _omap_dispc_set_irqs();
2668 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2672 bool dispc_mgr_is_enabled(enum omap_channel channel)
2674 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2677 void dispc_mgr_enable(enum omap_channel channel, bool enable)
2679 if (dss_mgr_is_lcd(channel))
2680 dispc_mgr_enable_lcd_out(channel, enable);
2681 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2682 dispc_mgr_enable_digit_out(enable);
2687 void dispc_lcd_enable_signal_polarity(bool act_high)
2689 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2692 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2695 void dispc_lcd_enable_signal(bool enable)
2697 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2700 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2703 void dispc_pck_free_enable(bool enable)
2705 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2708 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2711 void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2713 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
2717 void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
2719 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
2722 void dispc_set_loadmode(enum omap_dss_load_mode mode)
2724 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2728 static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2730 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2733 static void dispc_mgr_set_trans_key(enum omap_channel ch,
2734 enum omap_dss_trans_key_type type,
2737 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
2739 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2742 static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2744 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
2747 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2750 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
2753 if (ch == OMAP_DSS_CHANNEL_LCD)
2754 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2755 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2756 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2759 void dispc_mgr_setup(enum omap_channel channel,
2760 struct omap_overlay_manager_info *info)
2762 dispc_mgr_set_default_color(channel, info->default_color);
2763 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2764 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2765 dispc_mgr_enable_alpha_fixed_zorder(channel,
2766 info->partial_alpha_enabled);
2767 if (dss_has_feature(FEAT_CPR)) {
2768 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2769 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2773 void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2777 switch (data_lines) {
2795 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
2798 void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
2804 case DSS_IO_PAD_MODE_RESET:
2808 case DSS_IO_PAD_MODE_RFBI:
2812 case DSS_IO_PAD_MODE_BYPASS:
2821 l = dispc_read_reg(DISPC_CONTROL);
2822 l = FLD_MOD(l, gpout0, 15, 15);
2823 l = FLD_MOD(l, gpout1, 16, 16);
2824 dispc_write_reg(DISPC_CONTROL, l);
2827 void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2829 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
2832 static bool _dispc_mgr_size_ok(u16 width, u16 height)
2834 return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
2835 height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
2838 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2839 int vsw, int vfp, int vbp)
2841 if (hsw < 1 || hsw > dispc.feat->sw_max ||
2842 hfp < 1 || hfp > dispc.feat->hp_max ||
2843 hbp < 1 || hbp > dispc.feat->hp_max ||
2844 vsw < 1 || vsw > dispc.feat->sw_max ||
2845 vfp < 0 || vfp > dispc.feat->vp_max ||
2846 vbp < 0 || vbp > dispc.feat->vp_max)
2851 bool dispc_mgr_timings_ok(enum omap_channel channel,
2852 const struct omap_video_timings *timings)
2856 timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
2858 if (dss_mgr_is_lcd(channel))
2859 timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
2860 timings->hfp, timings->hbp,
2861 timings->vsw, timings->vfp,
2867 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
2868 int hfp, int hbp, int vsw, int vfp, int vbp,
2869 enum omap_dss_signal_level vsync_level,
2870 enum omap_dss_signal_level hsync_level,
2871 enum omap_dss_signal_edge data_pclk_edge,
2872 enum omap_dss_signal_level de_level,
2873 enum omap_dss_signal_edge sync_pclk_edge)
2876 u32 timing_h, timing_v, l;
2877 bool onoff, rf, ipc;
2879 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
2880 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
2881 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
2882 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
2883 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
2884 FLD_VAL(vbp, dispc.feat->bp_start, 20);
2886 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2887 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
2889 switch (data_pclk_edge) {
2890 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2893 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2896 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2901 switch (sync_pclk_edge) {
2902 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2906 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2910 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2918 l = dispc_read_reg(DISPC_POL_FREQ(channel));
2919 l |= FLD_VAL(onoff, 17, 17);
2920 l |= FLD_VAL(rf, 16, 16);
2921 l |= FLD_VAL(de_level, 15, 15);
2922 l |= FLD_VAL(ipc, 14, 14);
2923 l |= FLD_VAL(hsync_level, 13, 13);
2924 l |= FLD_VAL(vsync_level, 12, 12);
2925 dispc_write_reg(DISPC_POL_FREQ(channel), l);
2928 /* change name to mode? */
2929 void dispc_mgr_set_timings(enum omap_channel channel,
2930 struct omap_video_timings *timings)
2932 unsigned xtot, ytot;
2933 unsigned long ht, vt;
2934 struct omap_video_timings t = *timings;
2936 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
2938 if (!dispc_mgr_timings_ok(channel, &t)) {
2943 if (dss_mgr_is_lcd(channel)) {
2944 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
2945 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
2946 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
2948 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
2949 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
2951 ht = (timings->pixel_clock * 1000) / xtot;
2952 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2954 DSSDBG("pck %u\n", timings->pixel_clock);
2955 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2956 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
2957 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
2958 t.vsync_level, t.hsync_level, t.data_pclk_edge,
2959 t.de_level, t.sync_pclk_edge);
2961 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2963 if (t.interlace == true)
2967 dispc_mgr_set_size(channel, t.x_res, t.y_res);
2970 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
2973 BUG_ON(lck_div < 1);
2974 BUG_ON(pck_div < 1);
2976 dispc_write_reg(DISPC_DIVISORo(channel),
2977 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
2980 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
2984 l = dispc_read_reg(DISPC_DIVISORo(channel));
2985 *lck_div = FLD_GET(l, 23, 16);
2986 *pck_div = FLD_GET(l, 7, 0);
2989 unsigned long dispc_fclk_rate(void)
2991 struct platform_device *dsidev;
2992 unsigned long r = 0;
2994 switch (dss_get_dispc_clk_source()) {
2995 case OMAP_DSS_CLK_SRC_FCK:
2996 r = clk_get_rate(dispc.dss_clk);
2998 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2999 dsidev = dsi_get_dsidev_from_id(0);
3000 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
3002 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3003 dsidev = dsi_get_dsidev_from_id(1);
3004 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
3014 unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
3016 struct platform_device *dsidev;
3021 l = dispc_read_reg(DISPC_DIVISORo(channel));
3023 lcd = FLD_GET(l, 23, 16);
3025 switch (dss_get_lcd_clk_source(channel)) {
3026 case OMAP_DSS_CLK_SRC_FCK:
3027 r = clk_get_rate(dispc.dss_clk);
3029 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
3030 dsidev = dsi_get_dsidev_from_id(0);
3031 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
3033 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
3034 dsidev = dsi_get_dsidev_from_id(1);
3035 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
3045 unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
3049 if (dss_mgr_is_lcd(channel)) {
3053 l = dispc_read_reg(DISPC_DIVISORo(channel));
3055 pcd = FLD_GET(l, 7, 0);
3057 r = dispc_mgr_lclk_rate(channel);
3061 enum dss_hdmi_venc_clk_source_select source;
3063 source = dss_get_hdmi_venc_clk_source();
3066 case DSS_VENC_TV_CLK:
3067 return venc_get_pixel_clock();
3068 case DSS_HDMI_M_PCLK:
3069 return hdmi_get_pixel_clock();
3077 unsigned long dispc_core_clk_rate(void)
3080 unsigned long fclk = dispc_fclk_rate();
3082 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3083 lcd = REG_GET(DISPC_DIVISOR, 23, 16);
3085 lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
3090 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3092 enum omap_channel channel = dispc_ovl_get_channel_out(plane);
3094 return dispc_mgr_pclk_rate(channel);
3097 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3099 enum omap_channel channel = dispc_ovl_get_channel_out(plane);
3101 if (dss_mgr_is_lcd(channel))
3102 return dispc_mgr_lclk_rate(channel);
3104 return dispc_fclk_rate();
3107 static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
3110 enum omap_dss_clk_source lcd_clk_src;
3112 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3114 lcd_clk_src = dss_get_lcd_clk_source(channel);
3116 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3117 dss_get_generic_clk_source_name(lcd_clk_src),
3118 dss_feat_get_clk_source_name(lcd_clk_src));
3120 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3122 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3123 dispc_mgr_lclk_rate(channel), lcd);
3124 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3125 dispc_mgr_pclk_rate(channel), pcd);
3128 void dispc_dump_clocks(struct seq_file *s)
3132 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
3134 if (dispc_runtime_get())
3137 seq_printf(s, "- DISPC -\n");
3139 seq_printf(s, "dispc fclk source = %s (%s)\n",
3140 dss_get_generic_clk_source_name(dispc_clk_src),
3141 dss_feat_get_clk_source_name(dispc_clk_src));
3143 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
3145 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3146 seq_printf(s, "- DISPC-CORE-CLK -\n");
3147 l = dispc_read_reg(DISPC_DIVISOR);
3148 lcd = FLD_GET(l, 23, 16);
3150 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3151 (dispc_fclk_rate()/lcd), lcd);
3154 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
3156 if (dss_has_feature(FEAT_MGR_LCD2))
3157 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3158 if (dss_has_feature(FEAT_MGR_LCD3))
3159 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
3161 dispc_runtime_put();
3164 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3165 void dispc_dump_irqs(struct seq_file *s)
3167 unsigned long flags;
3168 struct dispc_irq_stats stats;
3170 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
3172 stats = dispc.irq_stats;
3173 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
3174 dispc.irq_stats.last_reset = jiffies;
3176 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
3178 seq_printf(s, "period %u ms\n",
3179 jiffies_to_msecs(jiffies - stats.last_reset));
3181 seq_printf(s, "irqs %d\n", stats.irq_count);
3183 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
3189 PIS(ACBIAS_COUNT_STAT);
3191 PIS(GFX_FIFO_UNDERFLOW);
3193 PIS(PAL_GAMMA_MASK);
3195 PIS(VID1_FIFO_UNDERFLOW);
3197 PIS(VID2_FIFO_UNDERFLOW);
3199 if (dss_feat_get_num_ovls() > 3) {
3200 PIS(VID3_FIFO_UNDERFLOW);
3204 PIS(SYNC_LOST_DIGIT);
3206 if (dss_has_feature(FEAT_MGR_LCD2)) {
3209 PIS(ACBIAS_COUNT_STAT2);
3212 if (dss_has_feature(FEAT_MGR_LCD3)) {
3215 PIS(ACBIAS_COUNT_STAT3);
3222 static void dispc_dump_regs(struct seq_file *s)
3225 const char *mgr_names[] = {
3226 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3227 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3228 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
3229 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
3231 const char *ovl_names[] = {
3232 [OMAP_DSS_GFX] = "GFX",
3233 [OMAP_DSS_VIDEO1] = "VID1",
3234 [OMAP_DSS_VIDEO2] = "VID2",
3235 [OMAP_DSS_VIDEO3] = "VID3",
3237 const char **p_names;
3239 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3241 if (dispc_runtime_get())
3244 /* DISPC common registers */
3245 DUMPREG(DISPC_REVISION);
3246 DUMPREG(DISPC_SYSCONFIG);
3247 DUMPREG(DISPC_SYSSTATUS);
3248 DUMPREG(DISPC_IRQSTATUS);
3249 DUMPREG(DISPC_IRQENABLE);
3250 DUMPREG(DISPC_CONTROL);
3251 DUMPREG(DISPC_CONFIG);
3252 DUMPREG(DISPC_CAPABLE);
3253 DUMPREG(DISPC_LINE_STATUS);
3254 DUMPREG(DISPC_LINE_NUMBER);
3255 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3256 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
3257 DUMPREG(DISPC_GLOBAL_ALPHA);
3258 if (dss_has_feature(FEAT_MGR_LCD2)) {
3259 DUMPREG(DISPC_CONTROL2);
3260 DUMPREG(DISPC_CONFIG2);
3262 if (dss_has_feature(FEAT_MGR_LCD3)) {
3263 DUMPREG(DISPC_CONTROL3);
3264 DUMPREG(DISPC_CONFIG3);
3269 #define DISPC_REG(i, name) name(i)
3270 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3271 48 - strlen(#r) - strlen(p_names[i]), " ", \
3272 dispc_read_reg(DISPC_REG(i, r)))
3274 p_names = mgr_names;
3276 /* DISPC channel specific registers */
3277 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3278 DUMPREG(i, DISPC_DEFAULT_COLOR);
3279 DUMPREG(i, DISPC_TRANS_COLOR);
3280 DUMPREG(i, DISPC_SIZE_MGR);
3282 if (i == OMAP_DSS_CHANNEL_DIGIT)
3285 DUMPREG(i, DISPC_DEFAULT_COLOR);
3286 DUMPREG(i, DISPC_TRANS_COLOR);
3287 DUMPREG(i, DISPC_TIMING_H);
3288 DUMPREG(i, DISPC_TIMING_V);
3289 DUMPREG(i, DISPC_POL_FREQ);
3290 DUMPREG(i, DISPC_DIVISORo);
3291 DUMPREG(i, DISPC_SIZE_MGR);
3293 DUMPREG(i, DISPC_DATA_CYCLE1);
3294 DUMPREG(i, DISPC_DATA_CYCLE2);
3295 DUMPREG(i, DISPC_DATA_CYCLE3);
3297 if (dss_has_feature(FEAT_CPR)) {
3298 DUMPREG(i, DISPC_CPR_COEF_R);
3299 DUMPREG(i, DISPC_CPR_COEF_G);
3300 DUMPREG(i, DISPC_CPR_COEF_B);
3304 p_names = ovl_names;
3306 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3307 DUMPREG(i, DISPC_OVL_BA0);
3308 DUMPREG(i, DISPC_OVL_BA1);
3309 DUMPREG(i, DISPC_OVL_POSITION);
3310 DUMPREG(i, DISPC_OVL_SIZE);
3311 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3312 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3313 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3314 DUMPREG(i, DISPC_OVL_ROW_INC);
3315 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3316 if (dss_has_feature(FEAT_PRELOAD))
3317 DUMPREG(i, DISPC_OVL_PRELOAD);
3319 if (i == OMAP_DSS_GFX) {
3320 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3321 DUMPREG(i, DISPC_OVL_TABLE_BA);
3325 DUMPREG(i, DISPC_OVL_FIR);
3326 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3327 DUMPREG(i, DISPC_OVL_ACCU0);
3328 DUMPREG(i, DISPC_OVL_ACCU1);
3329 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3330 DUMPREG(i, DISPC_OVL_BA0_UV);
3331 DUMPREG(i, DISPC_OVL_BA1_UV);
3332 DUMPREG(i, DISPC_OVL_FIR2);
3333 DUMPREG(i, DISPC_OVL_ACCU2_0);
3334 DUMPREG(i, DISPC_OVL_ACCU2_1);
3336 if (dss_has_feature(FEAT_ATTR2))
3337 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3338 if (dss_has_feature(FEAT_PRELOAD))
3339 DUMPREG(i, DISPC_OVL_PRELOAD);
3345 #define DISPC_REG(plane, name, i) name(plane, i)
3346 #define DUMPREG(plane, name, i) \
3347 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3348 46 - strlen(#name) - strlen(p_names[plane]), " ", \
3349 dispc_read_reg(DISPC_REG(plane, name, i)))
3351 /* Video pipeline coefficient registers */
3353 /* start from OMAP_DSS_VIDEO1 */
3354 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3355 for (j = 0; j < 8; j++)
3356 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
3358 for (j = 0; j < 8; j++)
3359 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
3361 for (j = 0; j < 5; j++)
3362 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
3364 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3365 for (j = 0; j < 8; j++)
3366 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3369 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3370 for (j = 0; j < 8; j++)
3371 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
3373 for (j = 0; j < 8; j++)
3374 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
3376 for (j = 0; j < 8; j++)
3377 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3381 dispc_runtime_put();
3387 /* with fck as input clock rate, find dispc dividers that produce req_pck */
3388 void dispc_find_clk_divs(unsigned long req_pck, unsigned long fck,
3389 struct dispc_clock_info *cinfo)
3391 u16 pcd_min, pcd_max;
3392 unsigned long best_pck;
3393 u16 best_ld, cur_ld;
3394 u16 best_pd, cur_pd;
3396 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3397 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3403 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
3404 unsigned long lck = fck / cur_ld;
3406 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
3407 unsigned long pck = lck / cur_pd;
3408 long old_delta = abs(best_pck - req_pck);
3409 long new_delta = abs(pck - req_pck);
3411 if (best_pck == 0 || new_delta < old_delta) {
3424 if (lck / pcd_min < req_pck)
3429 cinfo->lck_div = best_ld;
3430 cinfo->pck_div = best_pd;
3431 cinfo->lck = fck / cinfo->lck_div;
3432 cinfo->pck = cinfo->lck / cinfo->pck_div;
3435 /* calculate clock rates using dividers in cinfo */
3436 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3437 struct dispc_clock_info *cinfo)
3439 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3441 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3444 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3445 cinfo->pck = cinfo->lck / cinfo->pck_div;
3450 void dispc_mgr_set_clock_div(enum omap_channel channel,
3451 struct dispc_clock_info *cinfo)
3453 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3454 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3456 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
3459 int dispc_mgr_get_clock_div(enum omap_channel channel,
3460 struct dispc_clock_info *cinfo)
3464 fck = dispc_fclk_rate();
3466 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3467 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
3469 cinfo->lck = fck / cinfo->lck_div;
3470 cinfo->pck = cinfo->lck / cinfo->pck_div;
3475 /* dispc.irq_lock has to be locked by the caller */
3476 static void _omap_dispc_set_irqs(void)
3481 struct omap_dispc_isr_data *isr_data;
3483 mask = dispc.irq_error_mask;
3485 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3486 isr_data = &dispc.registered_isr[i];
3488 if (isr_data->isr == NULL)
3491 mask |= isr_data->mask;
3494 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3495 /* clear the irqstatus for newly enabled irqs */
3496 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
3498 dispc_write_reg(DISPC_IRQENABLE, mask);
3501 int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3505 unsigned long flags;
3506 struct omap_dispc_isr_data *isr_data;
3511 spin_lock_irqsave(&dispc.irq_lock, flags);
3513 /* check for duplicate entry */
3514 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3515 isr_data = &dispc.registered_isr[i];
3516 if (isr_data->isr == isr && isr_data->arg == arg &&
3517 isr_data->mask == mask) {
3526 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3527 isr_data = &dispc.registered_isr[i];
3529 if (isr_data->isr != NULL)
3532 isr_data->isr = isr;
3533 isr_data->arg = arg;
3534 isr_data->mask = mask;
3543 _omap_dispc_set_irqs();
3545 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3549 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3553 EXPORT_SYMBOL(omap_dispc_register_isr);
3555 int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3558 unsigned long flags;
3560 struct omap_dispc_isr_data *isr_data;
3562 spin_lock_irqsave(&dispc.irq_lock, flags);
3564 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3565 isr_data = &dispc.registered_isr[i];
3566 if (isr_data->isr != isr || isr_data->arg != arg ||
3567 isr_data->mask != mask)
3570 /* found the correct isr */
3572 isr_data->isr = NULL;
3573 isr_data->arg = NULL;
3581 _omap_dispc_set_irqs();
3583 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3587 EXPORT_SYMBOL(omap_dispc_unregister_isr);
3590 static void print_irq_status(u32 status)
3592 if ((status & dispc.irq_error_mask) == 0)
3595 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
3598 if (status & DISPC_IRQ_##x) \
3600 PIS(GFX_FIFO_UNDERFLOW);
3602 PIS(VID1_FIFO_UNDERFLOW);
3603 PIS(VID2_FIFO_UNDERFLOW);
3604 if (dss_feat_get_num_ovls() > 3)
3605 PIS(VID3_FIFO_UNDERFLOW);
3607 PIS(SYNC_LOST_DIGIT);
3608 if (dss_has_feature(FEAT_MGR_LCD2))
3610 if (dss_has_feature(FEAT_MGR_LCD3))
3618 /* Called from dss.c. Note that we don't touch clocks here,
3619 * but we presume they are on because we got an IRQ. However,
3620 * an irq handler may turn the clocks off, so we may not have
3621 * clock later in the function. */
3622 static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
3625 u32 irqstatus, irqenable;
3626 u32 handledirqs = 0;
3627 u32 unhandled_errors;
3628 struct omap_dispc_isr_data *isr_data;
3629 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3631 spin_lock(&dispc.irq_lock);
3633 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
3634 irqenable = dispc_read_reg(DISPC_IRQENABLE);
3636 /* IRQ is not for us */
3637 if (!(irqstatus & irqenable)) {
3638 spin_unlock(&dispc.irq_lock);
3642 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3643 spin_lock(&dispc.irq_stats_lock);
3644 dispc.irq_stats.irq_count++;
3645 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3646 spin_unlock(&dispc.irq_stats_lock);
3651 print_irq_status(irqstatus);
3653 /* Ack the interrupt. Do it here before clocks are possibly turned
3655 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
3656 /* flush posted write */
3657 dispc_read_reg(DISPC_IRQSTATUS);
3659 /* make a copy and unlock, so that isrs can unregister
3661 memcpy(registered_isr, dispc.registered_isr,
3662 sizeof(registered_isr));
3664 spin_unlock(&dispc.irq_lock);
3666 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3667 isr_data = ®istered_isr[i];
3672 if (isr_data->mask & irqstatus) {
3673 isr_data->isr(isr_data->arg, irqstatus);
3674 handledirqs |= isr_data->mask;
3678 spin_lock(&dispc.irq_lock);
3680 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3682 if (unhandled_errors) {
3683 dispc.error_irqs |= unhandled_errors;
3685 dispc.irq_error_mask &= ~unhandled_errors;
3686 _omap_dispc_set_irqs();
3688 schedule_work(&dispc.error_work);
3691 spin_unlock(&dispc.irq_lock);
3696 static void dispc_error_worker(struct work_struct *work)
3700 unsigned long flags;
3701 static const unsigned fifo_underflow_bits[] = {
3702 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3703 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3704 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
3705 DISPC_IRQ_VID3_FIFO_UNDERFLOW,
3708 spin_lock_irqsave(&dispc.irq_lock, flags);
3709 errors = dispc.error_irqs;
3710 dispc.error_irqs = 0;
3711 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3713 dispc_runtime_get();
3715 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3716 struct omap_overlay *ovl;
3719 ovl = omap_dss_get_overlay(i);
3720 bit = fifo_underflow_bits[i];
3723 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3725 dispc_ovl_enable(ovl->id, false);
3726 dispc_mgr_go(ovl->manager->id);
3731 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3732 struct omap_overlay_manager *mgr;
3735 mgr = omap_dss_get_overlay_manager(i);
3736 bit = mgr_desc[i].sync_lost_irq;
3739 struct omap_dss_device *dssdev = mgr->get_device(mgr);
3742 DSSERR("SYNC_LOST on channel %s, restarting the output "
3743 "with video overlays disabled\n",
3746 enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
3747 dssdev->driver->disable(dssdev);
3749 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3750 struct omap_overlay *ovl;
3751 ovl = omap_dss_get_overlay(i);
3753 if (ovl->id != OMAP_DSS_GFX &&
3754 ovl->manager == mgr)
3755 dispc_ovl_enable(ovl->id, false);
3758 dispc_mgr_go(mgr->id);
3762 dssdev->driver->enable(dssdev);
3766 if (errors & DISPC_IRQ_OCP_ERR) {
3767 DSSERR("OCP_ERR\n");
3768 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3769 struct omap_overlay_manager *mgr;
3770 struct omap_dss_device *dssdev;
3772 mgr = omap_dss_get_overlay_manager(i);
3773 dssdev = mgr->get_device(mgr);
3775 if (dssdev && dssdev->driver)
3776 dssdev->driver->disable(dssdev);
3780 spin_lock_irqsave(&dispc.irq_lock, flags);
3781 dispc.irq_error_mask |= errors;
3782 _omap_dispc_set_irqs();
3783 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3785 dispc_runtime_put();
3788 int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3790 void dispc_irq_wait_handler(void *data, u32 mask)
3792 complete((struct completion *)data);
3796 DECLARE_COMPLETION_ONSTACK(completion);
3798 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3804 timeout = wait_for_completion_timeout(&completion, timeout);
3806 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3811 if (timeout == -ERESTARTSYS)
3812 return -ERESTARTSYS;
3817 int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3818 unsigned long timeout)
3820 void dispc_irq_wait_handler(void *data, u32 mask)
3822 complete((struct completion *)data);
3826 DECLARE_COMPLETION_ONSTACK(completion);
3828 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3834 timeout = wait_for_completion_interruptible_timeout(&completion,
3837 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3842 if (timeout == -ERESTARTSYS)
3843 return -ERESTARTSYS;
3848 static void _omap_dispc_initialize_irq(void)
3850 unsigned long flags;
3852 spin_lock_irqsave(&dispc.irq_lock, flags);
3854 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3856 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
3857 if (dss_has_feature(FEAT_MGR_LCD2))
3858 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
3859 if (dss_has_feature(FEAT_MGR_LCD3))
3860 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST3;
3861 if (dss_feat_get_num_ovls() > 3)
3862 dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
3864 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3866 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3868 _omap_dispc_set_irqs();
3870 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3873 void dispc_enable_sidle(void)
3875 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3878 void dispc_disable_sidle(void)
3880 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3883 static void _omap_dispc_initial_config(void)
3887 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3888 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3889 l = dispc_read_reg(DISPC_DIVISOR);
3890 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3891 l = FLD_MOD(l, 1, 0, 0);
3892 l = FLD_MOD(l, 1, 23, 16);
3893 dispc_write_reg(DISPC_DIVISOR, l);
3897 if (dss_has_feature(FEAT_FUNCGATED))
3898 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3900 _dispc_setup_color_conv_coef();
3902 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3906 dispc_configure_burst_sizes();
3908 dispc_ovl_enable_zorder_planes();
3911 static const struct dispc_features omap24xx_dispc_feats __initconst = {
3918 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3919 .calc_core_clk = calc_core_clk_24xx,
3923 static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
3930 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3931 .calc_core_clk = calc_core_clk_34xx,
3935 static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
3942 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3943 .calc_core_clk = calc_core_clk_34xx,
3947 static const struct dispc_features omap44xx_dispc_feats __initconst = {
3954 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3955 .calc_core_clk = calc_core_clk_44xx,
3957 .gfx_fifo_workaround = true,
3960 static int __init dispc_init_features(struct device *dev)
3962 const struct dispc_features *src;
3963 struct dispc_features *dst;
3965 dst = devm_kzalloc(dev, sizeof(*dst), GFP_KERNEL);
3967 dev_err(dev, "Failed to allocate DISPC Features\n");
3971 if (cpu_is_omap24xx()) {
3972 src = &omap24xx_dispc_feats;
3973 } else if (cpu_is_omap34xx()) {
3974 if (omap_rev() < OMAP3430_REV_ES3_0)
3975 src = &omap34xx_rev1_0_dispc_feats;
3977 src = &omap34xx_rev3_0_dispc_feats;
3978 } else if (cpu_is_omap44xx()) {
3979 src = &omap44xx_dispc_feats;
3980 } else if (soc_is_omap54xx()) {
3981 src = &omap44xx_dispc_feats;
3986 memcpy(dst, src, sizeof(*dst));
3992 /* DISPC HW IP initialisation */
3993 static int __init omap_dispchw_probe(struct platform_device *pdev)
3997 struct resource *dispc_mem;
4002 r = dispc_init_features(&dispc.pdev->dev);
4006 spin_lock_init(&dispc.irq_lock);
4008 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
4009 spin_lock_init(&dispc.irq_stats_lock);
4010 dispc.irq_stats.last_reset = jiffies;
4013 INIT_WORK(&dispc.error_work, dispc_error_worker);
4015 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
4017 DSSERR("can't get IORESOURCE_MEM DISPC\n");
4021 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
4022 resource_size(dispc_mem));
4024 DSSERR("can't ioremap DISPC\n");
4028 dispc.irq = platform_get_irq(dispc.pdev, 0);
4029 if (dispc.irq < 0) {
4030 DSSERR("platform_get_irq failed\n");
4034 r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
4035 IRQF_SHARED, "OMAP DISPC", dispc.pdev);
4037 DSSERR("request_irq failed\n");
4041 clk = clk_get(&pdev->dev, "fck");
4043 DSSERR("can't get fck\n");
4048 dispc.dss_clk = clk;
4050 pm_runtime_enable(&pdev->dev);
4052 r = dispc_runtime_get();
4054 goto err_runtime_get;
4056 _omap_dispc_initial_config();
4058 _omap_dispc_initialize_irq();
4060 rev = dispc_read_reg(DISPC_REVISION);
4061 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
4062 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4064 dispc_runtime_put();
4066 dss_debugfs_create_file("dispc", dispc_dump_regs);
4068 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
4069 dss_debugfs_create_file("dispc_irq", dispc_dump_irqs);
4074 pm_runtime_disable(&pdev->dev);
4075 clk_put(dispc.dss_clk);
4079 static int __exit omap_dispchw_remove(struct platform_device *pdev)
4081 pm_runtime_disable(&pdev->dev);
4083 clk_put(dispc.dss_clk);
4088 static int dispc_runtime_suspend(struct device *dev)
4090 dispc_save_context();
4095 static int dispc_runtime_resume(struct device *dev)
4097 dispc_restore_context();
4102 static const struct dev_pm_ops dispc_pm_ops = {
4103 .runtime_suspend = dispc_runtime_suspend,
4104 .runtime_resume = dispc_runtime_resume,
4107 static struct platform_driver omap_dispchw_driver = {
4108 .remove = __exit_p(omap_dispchw_remove),
4110 .name = "omapdss_dispc",
4111 .owner = THIS_MODULE,
4112 .pm = &dispc_pm_ops,
4116 int __init dispc_init_platform_driver(void)
4118 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
4121 void __exit dispc_uninit_platform_driver(void)
4123 platform_driver_unregister(&omap_dispchw_driver);