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_channel channel,
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);
95 unsigned long (*calc_core_clk) (enum omap_channel channel,
96 u16 width, u16 height, u16 out_width, u16 out_height);
99 /* swap GFX & WB fifos */
100 bool gfx_fifo_workaround:1;
103 #define DISPC_MAX_NR_FIFOS 5
106 struct platform_device *pdev;
114 u32 fifo_size[DISPC_MAX_NR_FIFOS];
115 /* maps which plane is using a fifo. fifo-id -> plane-id */
116 int fifo_assignment[DISPC_MAX_NR_FIFOS];
120 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
122 struct work_struct error_work;
125 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
127 const struct dispc_features *feat;
129 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
130 spinlock_t irq_stats_lock;
131 struct dispc_irq_stats irq_stats;
135 enum omap_color_component {
136 /* used for all color formats for OMAP3 and earlier
137 * and for RGB and Y color component on OMAP4
139 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
140 /* used for UV component for
141 * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12
142 * color formats on OMAP4
144 DISPC_COLOR_COMPONENT_UV = 1 << 1,
147 enum mgr_reg_fields {
148 DISPC_MGR_FLD_ENABLE,
149 DISPC_MGR_FLD_STNTFT,
151 DISPC_MGR_FLD_TFTDATALINES,
152 DISPC_MGR_FLD_STALLMODE,
153 DISPC_MGR_FLD_TCKENABLE,
154 DISPC_MGR_FLD_TCKSELECTION,
156 DISPC_MGR_FLD_FIFOHANDCHECK,
157 /* used to maintain a count of the above fields */
161 static const struct {
166 struct reg_field reg_desc[DISPC_MGR_FLD_NUM];
168 [OMAP_DSS_CHANNEL_LCD] = {
170 .vsync_irq = DISPC_IRQ_VSYNC,
171 .framedone_irq = DISPC_IRQ_FRAMEDONE,
172 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
174 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
175 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
176 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
177 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
178 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
179 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
180 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
181 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
182 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
185 [OMAP_DSS_CHANNEL_DIGIT] = {
187 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
189 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
191 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
192 [DISPC_MGR_FLD_STNTFT] = { },
193 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
194 [DISPC_MGR_FLD_TFTDATALINES] = { },
195 [DISPC_MGR_FLD_STALLMODE] = { },
196 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
197 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
198 [DISPC_MGR_FLD_CPR] = { },
199 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
202 [OMAP_DSS_CHANNEL_LCD2] = {
204 .vsync_irq = DISPC_IRQ_VSYNC2,
205 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
206 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
208 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
209 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
210 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
211 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
212 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
213 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
214 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
215 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
216 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
219 [OMAP_DSS_CHANNEL_LCD3] = {
221 .vsync_irq = DISPC_IRQ_VSYNC3,
222 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
223 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
225 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
226 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
227 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
228 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
229 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
230 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
231 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
232 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
233 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
238 static void _omap_dispc_set_irqs(void);
240 static inline void dispc_write_reg(const u16 idx, u32 val)
242 __raw_writel(val, dispc.base + idx);
245 static inline u32 dispc_read_reg(const u16 idx)
247 return __raw_readl(dispc.base + idx);
250 static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld)
252 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
253 return REG_GET(rfld.reg, rfld.high, rfld.low);
256 static void mgr_fld_write(enum omap_channel channel,
257 enum mgr_reg_fields regfld, int val) {
258 const struct reg_field rfld = mgr_desc[channel].reg_desc[regfld];
259 REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low);
263 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
265 dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)])
267 static void dispc_save_context(void)
271 DSSDBG("dispc_save_context\n");
277 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
278 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
280 if (dss_has_feature(FEAT_MGR_LCD2)) {
284 if (dss_has_feature(FEAT_MGR_LCD3)) {
289 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
290 SR(DEFAULT_COLOR(i));
293 if (i == OMAP_DSS_CHANNEL_DIGIT)
304 if (dss_has_feature(FEAT_CPR)) {
311 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
316 SR(OVL_ATTRIBUTES(i));
317 SR(OVL_FIFO_THRESHOLD(i));
319 SR(OVL_PIXEL_INC(i));
320 if (dss_has_feature(FEAT_PRELOAD))
322 if (i == OMAP_DSS_GFX) {
323 SR(OVL_WINDOW_SKIP(i));
328 SR(OVL_PICTURE_SIZE(i));
332 for (j = 0; j < 8; j++)
333 SR(OVL_FIR_COEF_H(i, j));
335 for (j = 0; j < 8; j++)
336 SR(OVL_FIR_COEF_HV(i, j));
338 for (j = 0; j < 5; j++)
339 SR(OVL_CONV_COEF(i, j));
341 if (dss_has_feature(FEAT_FIR_COEF_V)) {
342 for (j = 0; j < 8; j++)
343 SR(OVL_FIR_COEF_V(i, j));
346 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
353 for (j = 0; j < 8; j++)
354 SR(OVL_FIR_COEF_H2(i, j));
356 for (j = 0; j < 8; j++)
357 SR(OVL_FIR_COEF_HV2(i, j));
359 for (j = 0; j < 8; j++)
360 SR(OVL_FIR_COEF_V2(i, j));
362 if (dss_has_feature(FEAT_ATTR2))
363 SR(OVL_ATTRIBUTES2(i));
366 if (dss_has_feature(FEAT_CORE_CLK_DIV))
369 dispc.ctx_loss_cnt = dss_get_ctx_loss_count(&dispc.pdev->dev);
370 dispc.ctx_valid = true;
372 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
375 static void dispc_restore_context(void)
379 DSSDBG("dispc_restore_context\n");
381 if (!dispc.ctx_valid)
384 ctx = dss_get_ctx_loss_count(&dispc.pdev->dev);
386 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
389 DSSDBG("ctx_loss_count: saved %d, current %d\n",
390 dispc.ctx_loss_cnt, ctx);
396 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
397 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
399 if (dss_has_feature(FEAT_MGR_LCD2))
401 if (dss_has_feature(FEAT_MGR_LCD3))
404 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
405 RR(DEFAULT_COLOR(i));
408 if (i == OMAP_DSS_CHANNEL_DIGIT)
419 if (dss_has_feature(FEAT_CPR)) {
426 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
431 RR(OVL_ATTRIBUTES(i));
432 RR(OVL_FIFO_THRESHOLD(i));
434 RR(OVL_PIXEL_INC(i));
435 if (dss_has_feature(FEAT_PRELOAD))
437 if (i == OMAP_DSS_GFX) {
438 RR(OVL_WINDOW_SKIP(i));
443 RR(OVL_PICTURE_SIZE(i));
447 for (j = 0; j < 8; j++)
448 RR(OVL_FIR_COEF_H(i, j));
450 for (j = 0; j < 8; j++)
451 RR(OVL_FIR_COEF_HV(i, j));
453 for (j = 0; j < 5; j++)
454 RR(OVL_CONV_COEF(i, j));
456 if (dss_has_feature(FEAT_FIR_COEF_V)) {
457 for (j = 0; j < 8; j++)
458 RR(OVL_FIR_COEF_V(i, j));
461 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
468 for (j = 0; j < 8; j++)
469 RR(OVL_FIR_COEF_H2(i, j));
471 for (j = 0; j < 8; j++)
472 RR(OVL_FIR_COEF_HV2(i, j));
474 for (j = 0; j < 8; j++)
475 RR(OVL_FIR_COEF_V2(i, j));
477 if (dss_has_feature(FEAT_ATTR2))
478 RR(OVL_ATTRIBUTES2(i));
481 if (dss_has_feature(FEAT_CORE_CLK_DIV))
484 /* enable last, because LCD & DIGIT enable are here */
486 if (dss_has_feature(FEAT_MGR_LCD2))
488 if (dss_has_feature(FEAT_MGR_LCD3))
490 /* clear spurious SYNC_LOST_DIGIT interrupts */
491 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
494 * enable last so IRQs won't trigger before
495 * the context is fully restored
499 DSSDBG("context restored\n");
505 int dispc_runtime_get(void)
509 DSSDBG("dispc_runtime_get\n");
511 r = pm_runtime_get_sync(&dispc.pdev->dev);
513 return r < 0 ? r : 0;
516 void dispc_runtime_put(void)
520 DSSDBG("dispc_runtime_put\n");
522 r = pm_runtime_put_sync(&dispc.pdev->dev);
523 WARN_ON(r < 0 && r != -ENOSYS);
526 u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
528 return mgr_desc[channel].vsync_irq;
531 u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
533 return mgr_desc[channel].framedone_irq;
536 bool dispc_mgr_go_busy(enum omap_channel channel)
538 return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
541 void dispc_mgr_go(enum omap_channel channel)
543 bool enable_bit, go_bit;
545 /* if the channel is not enabled, we don't need GO */
546 enable_bit = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE) == 1;
551 go_bit = mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1;
554 DSSERR("GO bit not down for channel %d\n", channel);
558 DSSDBG("GO %s\n", mgr_desc[channel].name);
560 mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1);
563 static void dispc_ovl_write_firh_reg(enum omap_plane plane, int reg, u32 value)
565 dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value);
568 static void dispc_ovl_write_firhv_reg(enum omap_plane plane, int reg, u32 value)
570 dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value);
573 static void dispc_ovl_write_firv_reg(enum omap_plane plane, int reg, u32 value)
575 dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value);
578 static void dispc_ovl_write_firh2_reg(enum omap_plane plane, int reg, u32 value)
580 BUG_ON(plane == OMAP_DSS_GFX);
582 dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value);
585 static void dispc_ovl_write_firhv2_reg(enum omap_plane plane, int reg,
588 BUG_ON(plane == OMAP_DSS_GFX);
590 dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
593 static void dispc_ovl_write_firv2_reg(enum omap_plane plane, int reg, u32 value)
595 BUG_ON(plane == OMAP_DSS_GFX);
597 dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value);
600 static void dispc_ovl_set_scale_coef(enum omap_plane plane, int fir_hinc,
601 int fir_vinc, int five_taps,
602 enum omap_color_component color_comp)
604 const struct dispc_coef *h_coef, *v_coef;
607 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
608 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
610 for (i = 0; i < 8; i++) {
613 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
614 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
615 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
616 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
617 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
618 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
619 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
620 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
622 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
623 dispc_ovl_write_firh_reg(plane, i, h);
624 dispc_ovl_write_firhv_reg(plane, i, hv);
626 dispc_ovl_write_firh2_reg(plane, i, h);
627 dispc_ovl_write_firhv2_reg(plane, i, hv);
633 for (i = 0; i < 8; i++) {
635 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
636 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
637 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
638 dispc_ovl_write_firv_reg(plane, i, v);
640 dispc_ovl_write_firv2_reg(plane, i, v);
645 static void _dispc_setup_color_conv_coef(void)
648 const struct color_conv_coef {
649 int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb;
652 298, 409, 0, 298, -208, -100, 298, 0, 517, 0,
655 const struct color_conv_coef *ct;
657 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
661 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
662 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 0),
663 CVAL(ct->rcr, ct->ry));
664 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 1),
665 CVAL(ct->gy, ct->rcb));
666 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 2),
667 CVAL(ct->gcb, ct->gcr));
668 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 3),
669 CVAL(ct->bcr, ct->by));
670 dispc_write_reg(DISPC_OVL_CONV_COEF(i, 4),
673 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), ct->full_range,
681 static void dispc_ovl_set_ba0(enum omap_plane plane, u32 paddr)
683 dispc_write_reg(DISPC_OVL_BA0(plane), paddr);
686 static void dispc_ovl_set_ba1(enum omap_plane plane, u32 paddr)
688 dispc_write_reg(DISPC_OVL_BA1(plane), paddr);
691 static void dispc_ovl_set_ba0_uv(enum omap_plane plane, u32 paddr)
693 dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr);
696 static void dispc_ovl_set_ba1_uv(enum omap_plane plane, u32 paddr)
698 dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr);
701 static void dispc_ovl_set_pos(enum omap_plane plane, int x, int y)
703 u32 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
705 dispc_write_reg(DISPC_OVL_POSITION(plane), val);
708 static void dispc_ovl_set_pic_size(enum omap_plane plane, int width, int height)
710 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
712 if (plane == OMAP_DSS_GFX)
713 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
715 dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val);
718 static void dispc_ovl_set_vid_size(enum omap_plane plane, int width, int height)
722 BUG_ON(plane == OMAP_DSS_GFX);
724 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
726 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
729 static void dispc_ovl_set_zorder(enum omap_plane plane, u8 zorder)
731 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
733 if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
736 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
739 static void dispc_ovl_enable_zorder_planes(void)
743 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
746 for (i = 0; i < dss_feat_get_num_ovls(); i++)
747 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
750 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane, bool enable)
752 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
754 if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
757 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
760 static void dispc_ovl_setup_global_alpha(enum omap_plane plane, u8 global_alpha)
762 static const unsigned shifts[] = { 0, 8, 16, 24, };
764 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
766 if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
769 shift = shifts[plane];
770 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
773 static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
775 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
778 static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
780 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
783 static void dispc_ovl_set_color_mode(enum omap_plane plane,
784 enum omap_color_mode color_mode)
787 if (plane != OMAP_DSS_GFX) {
788 switch (color_mode) {
789 case OMAP_DSS_COLOR_NV12:
791 case OMAP_DSS_COLOR_RGBX16:
793 case OMAP_DSS_COLOR_RGBA16:
795 case OMAP_DSS_COLOR_RGB12U:
797 case OMAP_DSS_COLOR_ARGB16:
799 case OMAP_DSS_COLOR_RGB16:
801 case OMAP_DSS_COLOR_ARGB16_1555:
803 case OMAP_DSS_COLOR_RGB24U:
805 case OMAP_DSS_COLOR_RGB24P:
807 case OMAP_DSS_COLOR_YUV2:
809 case OMAP_DSS_COLOR_UYVY:
811 case OMAP_DSS_COLOR_ARGB32:
813 case OMAP_DSS_COLOR_RGBA32:
815 case OMAP_DSS_COLOR_RGBX32:
817 case OMAP_DSS_COLOR_XRGB16_1555:
823 switch (color_mode) {
824 case OMAP_DSS_COLOR_CLUT1:
826 case OMAP_DSS_COLOR_CLUT2:
828 case OMAP_DSS_COLOR_CLUT4:
830 case OMAP_DSS_COLOR_CLUT8:
832 case OMAP_DSS_COLOR_RGB12U:
834 case OMAP_DSS_COLOR_ARGB16:
836 case OMAP_DSS_COLOR_RGB16:
838 case OMAP_DSS_COLOR_ARGB16_1555:
840 case OMAP_DSS_COLOR_RGB24U:
842 case OMAP_DSS_COLOR_RGB24P:
844 case OMAP_DSS_COLOR_RGBX16:
846 case OMAP_DSS_COLOR_RGBA16:
848 case OMAP_DSS_COLOR_ARGB32:
850 case OMAP_DSS_COLOR_RGBA32:
852 case OMAP_DSS_COLOR_RGBX32:
854 case OMAP_DSS_COLOR_XRGB16_1555:
861 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
864 static void dispc_ovl_configure_burst_type(enum omap_plane plane,
865 enum omap_dss_rotation_type rotation_type)
867 if (dss_has_feature(FEAT_BURST_2D) == 0)
870 if (rotation_type == OMAP_DSS_ROT_TILER)
871 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
873 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
876 void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
880 int chan = 0, chan2 = 0;
886 case OMAP_DSS_VIDEO1:
887 case OMAP_DSS_VIDEO2:
888 case OMAP_DSS_VIDEO3:
896 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
897 if (dss_has_feature(FEAT_MGR_LCD2)) {
899 case OMAP_DSS_CHANNEL_LCD:
903 case OMAP_DSS_CHANNEL_DIGIT:
907 case OMAP_DSS_CHANNEL_LCD2:
911 case OMAP_DSS_CHANNEL_LCD3:
912 if (dss_has_feature(FEAT_MGR_LCD3)) {
925 val = FLD_MOD(val, chan, shift, shift);
926 val = FLD_MOD(val, chan2, 31, 30);
928 val = FLD_MOD(val, channel, shift, shift);
930 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
933 static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
937 enum omap_channel channel;
943 case OMAP_DSS_VIDEO1:
944 case OMAP_DSS_VIDEO2:
945 case OMAP_DSS_VIDEO3:
953 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
955 if (dss_has_feature(FEAT_MGR_LCD3)) {
956 if (FLD_GET(val, 31, 30) == 0)
957 channel = FLD_GET(val, shift, shift);
958 else if (FLD_GET(val, 31, 30) == 1)
959 channel = OMAP_DSS_CHANNEL_LCD2;
961 channel = OMAP_DSS_CHANNEL_LCD3;
962 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
963 if (FLD_GET(val, 31, 30) == 0)
964 channel = FLD_GET(val, shift, shift);
966 channel = OMAP_DSS_CHANNEL_LCD2;
968 channel = FLD_GET(val, shift, shift);
974 static void dispc_ovl_set_burst_size(enum omap_plane plane,
975 enum omap_burst_size burst_size)
977 static const unsigned shifts[] = { 6, 14, 14, 14, };
980 shift = shifts[plane];
981 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
984 static void dispc_configure_burst_sizes(void)
987 const int burst_size = BURST_SIZE_X8;
989 /* Configure burst size always to maximum size */
990 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
991 dispc_ovl_set_burst_size(i, burst_size);
994 static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
996 unsigned unit = dss_feat_get_burst_size_unit();
997 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1001 void dispc_enable_gamma_table(bool enable)
1004 * This is partially implemented to support only disabling of
1008 DSSWARN("Gamma table enabling for TV not yet supported");
1012 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1015 static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
1017 if (channel == OMAP_DSS_CHANNEL_DIGIT)
1020 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
1023 static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
1024 struct omap_dss_cpr_coefs *coefs)
1026 u32 coef_r, coef_g, coef_b;
1028 if (!dss_mgr_is_lcd(channel))
1031 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1032 FLD_VAL(coefs->rb, 9, 0);
1033 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1034 FLD_VAL(coefs->gb, 9, 0);
1035 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1036 FLD_VAL(coefs->bb, 9, 0);
1038 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1039 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1040 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1043 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
1047 BUG_ON(plane == OMAP_DSS_GFX);
1049 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1050 val = FLD_MOD(val, enable, 9, 9);
1051 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
1054 static void dispc_ovl_enable_replication(enum omap_plane plane, bool enable)
1056 static const unsigned shifts[] = { 5, 10, 10, 10 };
1059 shift = shifts[plane];
1060 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
1063 static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
1068 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
1069 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
1072 static void dispc_init_fifos(void)
1079 unit = dss_feat_get_buffer_size_unit();
1081 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1083 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1084 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
1086 dispc.fifo_size[fifo] = size;
1089 * By default fifos are mapped directly to overlays, fifo 0 to
1090 * ovl 0, fifo 1 to ovl 1, etc.
1092 dispc.fifo_assignment[fifo] = fifo;
1096 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1097 * causes problems with certain use cases, like using the tiler in 2D
1098 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1099 * giving GFX plane a larger fifo. WB but should work fine with a
1102 if (dispc.feat->gfx_fifo_workaround) {
1105 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1107 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1108 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1109 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1110 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1112 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1114 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1115 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1119 static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1124 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1125 if (dispc.fifo_assignment[fifo] == plane)
1126 size += dispc.fifo_size[fifo];
1132 void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
1134 u8 hi_start, hi_end, lo_start, lo_end;
1137 unit = dss_feat_get_buffer_size_unit();
1139 WARN_ON(low % unit != 0);
1140 WARN_ON(high % unit != 0);
1145 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1146 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1148 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1150 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1151 lo_start, lo_end) * unit,
1152 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1153 hi_start, hi_end) * unit,
1154 low * unit, high * unit);
1156 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1157 FLD_VAL(high, hi_start, hi_end) |
1158 FLD_VAL(low, lo_start, lo_end));
1161 void dispc_enable_fifomerge(bool enable)
1163 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1168 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1169 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1172 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1173 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1177 * All sizes are in bytes. Both the buffer and burst are made of
1178 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1181 unsigned buf_unit = dss_feat_get_buffer_size_unit();
1182 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1185 burst_size = dispc_ovl_get_burst_size(plane);
1186 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
1188 if (use_fifomerge) {
1189 total_fifo_size = 0;
1190 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1191 total_fifo_size += dispc_ovl_get_fifo_size(i);
1193 total_fifo_size = ovl_fifo_size;
1197 * We use the same low threshold for both fifomerge and non-fifomerge
1198 * cases, but for fifomerge we calculate the high threshold using the
1199 * combined fifo size
1202 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1203 *fifo_low = ovl_fifo_size - burst_size * 2;
1204 *fifo_high = total_fifo_size - burst_size;
1206 *fifo_low = ovl_fifo_size - burst_size;
1207 *fifo_high = total_fifo_size - buf_unit;
1211 static void dispc_ovl_set_fir(enum omap_plane plane,
1213 enum omap_color_component color_comp)
1217 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1218 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1220 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1221 &hinc_start, &hinc_end);
1222 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1223 &vinc_start, &vinc_end);
1224 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1225 FLD_VAL(hinc, hinc_start, hinc_end);
1227 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1229 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1230 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1234 static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1237 u8 hor_start, hor_end, vert_start, vert_end;
1239 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1240 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1242 val = FLD_VAL(vaccu, vert_start, vert_end) |
1243 FLD_VAL(haccu, hor_start, hor_end);
1245 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1248 static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1251 u8 hor_start, hor_end, vert_start, vert_end;
1253 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1254 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1256 val = FLD_VAL(vaccu, vert_start, vert_end) |
1257 FLD_VAL(haccu, hor_start, hor_end);
1259 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1262 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1267 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1268 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1271 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1276 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1277 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1280 static void dispc_ovl_set_scale_param(enum omap_plane plane,
1281 u16 orig_width, u16 orig_height,
1282 u16 out_width, u16 out_height,
1283 bool five_taps, u8 rotation,
1284 enum omap_color_component color_comp)
1286 int fir_hinc, fir_vinc;
1288 fir_hinc = 1024 * orig_width / out_width;
1289 fir_vinc = 1024 * orig_height / out_height;
1291 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1293 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1296 static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1297 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1298 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1300 int h_accu2_0, h_accu2_1;
1301 int v_accu2_0, v_accu2_1;
1302 int chroma_hinc, chroma_vinc;
1312 const struct accu *accu_table;
1313 const struct accu *accu_val;
1315 static const struct accu accu_nv12[4] = {
1316 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1317 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1318 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1319 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1322 static const struct accu accu_nv12_ilace[4] = {
1323 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1324 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1325 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1326 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1329 static const struct accu accu_yuv[4] = {
1330 { 0, 1, 0, 1, 0, 1, 0, 1 },
1331 { 0, 1, 0, 1, 0, 1, 0, 1 },
1332 { -1, 1, 0, 1, 0, 1, 0, 1 },
1333 { 0, 1, 0, 1, -1, 1, 0, 1 },
1337 case OMAP_DSS_ROT_0:
1340 case OMAP_DSS_ROT_90:
1343 case OMAP_DSS_ROT_180:
1346 case OMAP_DSS_ROT_270:
1354 switch (color_mode) {
1355 case OMAP_DSS_COLOR_NV12:
1357 accu_table = accu_nv12_ilace;
1359 accu_table = accu_nv12;
1361 case OMAP_DSS_COLOR_YUV2:
1362 case OMAP_DSS_COLOR_UYVY:
1363 accu_table = accu_yuv;
1370 accu_val = &accu_table[idx];
1372 chroma_hinc = 1024 * orig_width / out_width;
1373 chroma_vinc = 1024 * orig_height / out_height;
1375 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1376 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1377 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1378 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1380 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1381 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1384 static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1385 u16 orig_width, u16 orig_height,
1386 u16 out_width, u16 out_height,
1387 bool ilace, bool five_taps,
1388 bool fieldmode, enum omap_color_mode color_mode,
1395 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1396 out_width, out_height, five_taps,
1397 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1398 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1400 /* RESIZEENABLE and VERTICALTAPS */
1401 l &= ~((0x3 << 5) | (0x1 << 21));
1402 l |= (orig_width != out_width) ? (1 << 5) : 0;
1403 l |= (orig_height != out_height) ? (1 << 6) : 0;
1404 l |= five_taps ? (1 << 21) : 0;
1406 /* VRESIZECONF and HRESIZECONF */
1407 if (dss_has_feature(FEAT_RESIZECONF)) {
1409 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1410 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1413 /* LINEBUFFERSPLIT */
1414 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1416 l |= five_taps ? (1 << 22) : 0;
1419 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1422 * field 0 = even field = bottom field
1423 * field 1 = odd field = top field
1425 if (ilace && !fieldmode) {
1427 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1428 if (accu0 >= 1024/2) {
1434 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1435 dispc_ovl_set_vid_accu1(plane, 0, accu1);
1438 static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1439 u16 orig_width, u16 orig_height,
1440 u16 out_width, u16 out_height,
1441 bool ilace, bool five_taps,
1442 bool fieldmode, enum omap_color_mode color_mode,
1445 int scale_x = out_width != orig_width;
1446 int scale_y = out_height != orig_height;
1448 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1450 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1451 color_mode != OMAP_DSS_COLOR_UYVY &&
1452 color_mode != OMAP_DSS_COLOR_NV12)) {
1453 /* reset chroma resampling for RGB formats */
1454 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1458 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1459 out_height, ilace, color_mode, rotation);
1461 switch (color_mode) {
1462 case OMAP_DSS_COLOR_NV12:
1463 /* UV is subsampled by 2 vertically*/
1465 /* UV is subsampled by 2 horz.*/
1468 case OMAP_DSS_COLOR_YUV2:
1469 case OMAP_DSS_COLOR_UYVY:
1470 /*For YUV422 with 90/270 rotation,
1471 *we don't upsample chroma
1473 if (rotation == OMAP_DSS_ROT_0 ||
1474 rotation == OMAP_DSS_ROT_180)
1475 /* UV is subsampled by 2 hrz*/
1477 /* must use FIR for YUV422 if rotated */
1478 if (rotation != OMAP_DSS_ROT_0)
1479 scale_x = scale_y = true;
1486 if (out_width != orig_width)
1488 if (out_height != orig_height)
1491 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1492 out_width, out_height, five_taps,
1493 rotation, DISPC_COLOR_COMPONENT_UV);
1495 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1496 (scale_x || scale_y) ? 1 : 0, 8, 8);
1498 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1500 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1503 static void dispc_ovl_set_scaling(enum omap_plane plane,
1504 u16 orig_width, u16 orig_height,
1505 u16 out_width, u16 out_height,
1506 bool ilace, bool five_taps,
1507 bool fieldmode, enum omap_color_mode color_mode,
1510 BUG_ON(plane == OMAP_DSS_GFX);
1512 dispc_ovl_set_scaling_common(plane,
1513 orig_width, orig_height,
1514 out_width, out_height,
1516 fieldmode, color_mode,
1519 dispc_ovl_set_scaling_uv(plane,
1520 orig_width, orig_height,
1521 out_width, out_height,
1523 fieldmode, color_mode,
1527 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1528 bool mirroring, enum omap_color_mode color_mode)
1530 bool row_repeat = false;
1533 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1534 color_mode == OMAP_DSS_COLOR_UYVY) {
1538 case OMAP_DSS_ROT_0:
1541 case OMAP_DSS_ROT_90:
1544 case OMAP_DSS_ROT_180:
1547 case OMAP_DSS_ROT_270:
1553 case OMAP_DSS_ROT_0:
1556 case OMAP_DSS_ROT_90:
1559 case OMAP_DSS_ROT_180:
1562 case OMAP_DSS_ROT_270:
1568 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1574 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1575 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1576 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1577 row_repeat ? 1 : 0, 18, 18);
1580 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1582 switch (color_mode) {
1583 case OMAP_DSS_COLOR_CLUT1:
1585 case OMAP_DSS_COLOR_CLUT2:
1587 case OMAP_DSS_COLOR_CLUT4:
1589 case OMAP_DSS_COLOR_CLUT8:
1590 case OMAP_DSS_COLOR_NV12:
1592 case OMAP_DSS_COLOR_RGB12U:
1593 case OMAP_DSS_COLOR_RGB16:
1594 case OMAP_DSS_COLOR_ARGB16:
1595 case OMAP_DSS_COLOR_YUV2:
1596 case OMAP_DSS_COLOR_UYVY:
1597 case OMAP_DSS_COLOR_RGBA16:
1598 case OMAP_DSS_COLOR_RGBX16:
1599 case OMAP_DSS_COLOR_ARGB16_1555:
1600 case OMAP_DSS_COLOR_XRGB16_1555:
1602 case OMAP_DSS_COLOR_RGB24P:
1604 case OMAP_DSS_COLOR_RGB24U:
1605 case OMAP_DSS_COLOR_ARGB32:
1606 case OMAP_DSS_COLOR_RGBA32:
1607 case OMAP_DSS_COLOR_RGBX32:
1615 static s32 pixinc(int pixels, u8 ps)
1619 else if (pixels > 1)
1620 return 1 + (pixels - 1) * ps;
1621 else if (pixels < 0)
1622 return 1 - (-pixels + 1) * ps;
1628 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1630 u16 width, u16 height,
1631 enum omap_color_mode color_mode, bool fieldmode,
1632 unsigned int field_offset,
1633 unsigned *offset0, unsigned *offset1,
1634 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1638 /* FIXME CLUT formats */
1639 switch (color_mode) {
1640 case OMAP_DSS_COLOR_CLUT1:
1641 case OMAP_DSS_COLOR_CLUT2:
1642 case OMAP_DSS_COLOR_CLUT4:
1643 case OMAP_DSS_COLOR_CLUT8:
1646 case OMAP_DSS_COLOR_YUV2:
1647 case OMAP_DSS_COLOR_UYVY:
1651 ps = color_mode_to_bpp(color_mode) / 8;
1655 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1659 * field 0 = even field = bottom field
1660 * field 1 = odd field = top field
1662 switch (rotation + mirror * 4) {
1663 case OMAP_DSS_ROT_0:
1664 case OMAP_DSS_ROT_180:
1666 * If the pixel format is YUV or UYVY divide the width
1667 * of the image by 2 for 0 and 180 degree rotation.
1669 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1670 color_mode == OMAP_DSS_COLOR_UYVY)
1672 case OMAP_DSS_ROT_90:
1673 case OMAP_DSS_ROT_270:
1676 *offset0 = field_offset * screen_width * ps;
1680 *row_inc = pixinc(1 +
1681 (y_predecim * screen_width - x_predecim * width) +
1682 (fieldmode ? screen_width : 0), ps);
1683 *pix_inc = pixinc(x_predecim, ps);
1686 case OMAP_DSS_ROT_0 + 4:
1687 case OMAP_DSS_ROT_180 + 4:
1688 /* If the pixel format is YUV or UYVY divide the width
1689 * of the image by 2 for 0 degree and 180 degree
1691 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1692 color_mode == OMAP_DSS_COLOR_UYVY)
1694 case OMAP_DSS_ROT_90 + 4:
1695 case OMAP_DSS_ROT_270 + 4:
1698 *offset0 = field_offset * screen_width * ps;
1701 *row_inc = pixinc(1 -
1702 (y_predecim * screen_width + x_predecim * width) -
1703 (fieldmode ? screen_width : 0), ps);
1704 *pix_inc = pixinc(x_predecim, ps);
1713 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1715 u16 width, u16 height,
1716 enum omap_color_mode color_mode, bool fieldmode,
1717 unsigned int field_offset,
1718 unsigned *offset0, unsigned *offset1,
1719 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1724 /* FIXME CLUT formats */
1725 switch (color_mode) {
1726 case OMAP_DSS_COLOR_CLUT1:
1727 case OMAP_DSS_COLOR_CLUT2:
1728 case OMAP_DSS_COLOR_CLUT4:
1729 case OMAP_DSS_COLOR_CLUT8:
1733 ps = color_mode_to_bpp(color_mode) / 8;
1737 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1740 /* width & height are overlay sizes, convert to fb sizes */
1742 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1751 * field 0 = even field = bottom field
1752 * field 1 = odd field = top field
1754 switch (rotation + mirror * 4) {
1755 case OMAP_DSS_ROT_0:
1758 *offset0 = *offset1 + field_offset * screen_width * ps;
1760 *offset0 = *offset1;
1761 *row_inc = pixinc(1 +
1762 (y_predecim * screen_width - fbw * x_predecim) +
1763 (fieldmode ? screen_width : 0), ps);
1764 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1765 color_mode == OMAP_DSS_COLOR_UYVY)
1766 *pix_inc = pixinc(x_predecim, 2 * ps);
1768 *pix_inc = pixinc(x_predecim, ps);
1770 case OMAP_DSS_ROT_90:
1771 *offset1 = screen_width * (fbh - 1) * ps;
1773 *offset0 = *offset1 + field_offset * ps;
1775 *offset0 = *offset1;
1776 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1777 y_predecim + (fieldmode ? 1 : 0), ps);
1778 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1780 case OMAP_DSS_ROT_180:
1781 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1783 *offset0 = *offset1 - field_offset * screen_width * ps;
1785 *offset0 = *offset1;
1786 *row_inc = pixinc(-1 -
1787 (y_predecim * screen_width - fbw * x_predecim) -
1788 (fieldmode ? screen_width : 0), ps);
1789 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1790 color_mode == OMAP_DSS_COLOR_UYVY)
1791 *pix_inc = pixinc(-x_predecim, 2 * ps);
1793 *pix_inc = pixinc(-x_predecim, ps);
1795 case OMAP_DSS_ROT_270:
1796 *offset1 = (fbw - 1) * ps;
1798 *offset0 = *offset1 - field_offset * ps;
1800 *offset0 = *offset1;
1801 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1802 y_predecim - (fieldmode ? 1 : 0), ps);
1803 *pix_inc = pixinc(x_predecim * screen_width, ps);
1807 case OMAP_DSS_ROT_0 + 4:
1808 *offset1 = (fbw - 1) * ps;
1810 *offset0 = *offset1 + field_offset * screen_width * ps;
1812 *offset0 = *offset1;
1813 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
1814 (fieldmode ? screen_width : 0),
1816 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1817 color_mode == OMAP_DSS_COLOR_UYVY)
1818 *pix_inc = pixinc(-x_predecim, 2 * ps);
1820 *pix_inc = pixinc(-x_predecim, ps);
1823 case OMAP_DSS_ROT_90 + 4:
1826 *offset0 = *offset1 + field_offset * ps;
1828 *offset0 = *offset1;
1829 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1830 y_predecim + (fieldmode ? 1 : 0),
1832 *pix_inc = pixinc(x_predecim * screen_width, ps);
1835 case OMAP_DSS_ROT_180 + 4:
1836 *offset1 = screen_width * (fbh - 1) * ps;
1838 *offset0 = *offset1 - field_offset * screen_width * ps;
1840 *offset0 = *offset1;
1841 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
1842 (fieldmode ? screen_width : 0),
1844 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1845 color_mode == OMAP_DSS_COLOR_UYVY)
1846 *pix_inc = pixinc(x_predecim, 2 * ps);
1848 *pix_inc = pixinc(x_predecim, ps);
1851 case OMAP_DSS_ROT_270 + 4:
1852 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1854 *offset0 = *offset1 - field_offset * ps;
1856 *offset0 = *offset1;
1857 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1858 y_predecim - (fieldmode ? 1 : 0),
1860 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1869 static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1870 enum omap_color_mode color_mode, bool fieldmode,
1871 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1872 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1876 switch (color_mode) {
1877 case OMAP_DSS_COLOR_CLUT1:
1878 case OMAP_DSS_COLOR_CLUT2:
1879 case OMAP_DSS_COLOR_CLUT4:
1880 case OMAP_DSS_COLOR_CLUT8:
1884 ps = color_mode_to_bpp(color_mode) / 8;
1888 DSSDBG("scrw %d, width %d\n", screen_width, width);
1891 * field 0 = even field = bottom field
1892 * field 1 = odd field = top field
1896 *offset0 = *offset1 + field_offset * screen_width * ps;
1898 *offset0 = *offset1;
1899 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1900 (fieldmode ? screen_width : 0), ps);
1901 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1902 color_mode == OMAP_DSS_COLOR_UYVY)
1903 *pix_inc = pixinc(x_predecim, 2 * ps);
1905 *pix_inc = pixinc(x_predecim, ps);
1909 * This function is used to avoid synclosts in OMAP3, because of some
1910 * undocumented horizontal position and timing related limitations.
1912 static int check_horiz_timing_omap3(enum omap_channel channel,
1913 const struct omap_video_timings *t, u16 pos_x,
1914 u16 width, u16 height, u16 out_width, u16 out_height)
1916 int DS = DIV_ROUND_UP(height, out_height);
1917 unsigned long nonactive, lclk, pclk;
1918 static const u8 limits[3] = { 8, 10, 20 };
1922 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
1923 pclk = dispc_mgr_pclk_rate(channel);
1924 if (dss_mgr_is_lcd(channel))
1925 lclk = dispc_mgr_lclk_rate(channel);
1927 lclk = dispc_fclk_rate();
1930 if (out_height < height)
1932 if (out_width < width)
1934 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
1935 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
1936 if (blank <= limits[i])
1940 * Pixel data should be prepared before visible display point starts.
1941 * So, atleast DS-2 lines must have already been fetched by DISPC
1942 * during nonactive - pos_x period.
1944 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
1945 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
1946 val, max(0, DS - 2) * width);
1947 if (val < max(0, DS - 2) * width)
1951 * All lines need to be refilled during the nonactive period of which
1952 * only one line can be loaded during the active period. So, atleast
1953 * DS - 1 lines should be loaded during nonactive period.
1955 val = div_u64((u64)nonactive * lclk, pclk);
1956 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
1957 val, max(0, DS - 1) * width);
1958 if (val < max(0, DS - 1) * width)
1964 static unsigned long calc_core_clk_five_taps(enum omap_channel channel,
1965 const struct omap_video_timings *mgr_timings, u16 width,
1966 u16 height, u16 out_width, u16 out_height,
1967 enum omap_color_mode color_mode)
1970 u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
1972 if (height <= out_height && width <= out_width)
1973 return (unsigned long) pclk;
1975 if (height > out_height) {
1976 unsigned int ppl = mgr_timings->x_res;
1978 tmp = pclk * height * out_width;
1979 do_div(tmp, 2 * out_height * ppl);
1982 if (height > 2 * out_height) {
1983 if (ppl == out_width)
1986 tmp = pclk * (height - 2 * out_height) * out_width;
1987 do_div(tmp, 2 * out_height * (ppl - out_width));
1988 core_clk = max_t(u32, core_clk, tmp);
1992 if (width > out_width) {
1994 do_div(tmp, out_width);
1995 core_clk = max_t(u32, core_clk, tmp);
1997 if (color_mode == OMAP_DSS_COLOR_RGB24U)
2004 static unsigned long calc_core_clk_24xx(enum omap_channel channel, u16 width,
2005 u16 height, u16 out_width, u16 out_height)
2007 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2009 if (height > out_height && width > out_width)
2015 static unsigned long calc_core_clk_34xx(enum omap_channel channel, u16 width,
2016 u16 height, u16 out_width, u16 out_height)
2018 unsigned int hf, vf;
2019 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2022 * FIXME how to determine the 'A' factor
2023 * for the no downscaling case ?
2026 if (width > 3 * out_width)
2028 else if (width > 2 * out_width)
2030 else if (width > out_width)
2034 if (height > out_height)
2039 return pclk * vf * hf;
2042 static unsigned long calc_core_clk_44xx(enum omap_channel channel, u16 width,
2043 u16 height, u16 out_width, u16 out_height)
2045 unsigned long pclk = dispc_mgr_pclk_rate(channel);
2047 if (width > out_width)
2048 return DIV_ROUND_UP(pclk, out_width) * width;
2053 static int dispc_ovl_calc_scaling_24xx(enum omap_channel channel,
2054 const struct omap_video_timings *mgr_timings,
2055 u16 width, u16 height, u16 out_width, u16 out_height,
2056 enum omap_color_mode color_mode, bool *five_taps,
2057 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2058 u16 pos_x, unsigned long *core_clk)
2061 u16 in_width, in_height;
2062 int min_factor = min(*decim_x, *decim_y);
2063 const int maxsinglelinewidth =
2064 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2068 in_height = DIV_ROUND_UP(height, *decim_y);
2069 in_width = DIV_ROUND_UP(width, *decim_x);
2070 *core_clk = dispc.feat->calc_core_clk(channel, in_width,
2071 in_height, out_width, out_height);
2072 error = (in_width > maxsinglelinewidth || !*core_clk ||
2073 *core_clk > dispc_core_clk_rate());
2075 if (*decim_x == *decim_y) {
2076 *decim_x = min_factor;
2079 swap(*decim_x, *decim_y);
2080 if (*decim_x < *decim_y)
2084 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2086 if (in_width > maxsinglelinewidth) {
2087 DSSERR("Cannot scale max input width exceeded");
2093 static int dispc_ovl_calc_scaling_34xx(enum omap_channel channel,
2094 const struct omap_video_timings *mgr_timings,
2095 u16 width, u16 height, u16 out_width, u16 out_height,
2096 enum omap_color_mode color_mode, bool *five_taps,
2097 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2098 u16 pos_x, unsigned long *core_clk)
2101 u16 in_width, in_height;
2102 int min_factor = min(*decim_x, *decim_y);
2103 const int maxsinglelinewidth =
2104 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2107 in_height = DIV_ROUND_UP(height, *decim_y);
2108 in_width = DIV_ROUND_UP(width, *decim_x);
2109 *core_clk = calc_core_clk_five_taps(channel, mgr_timings,
2110 in_width, in_height, out_width, out_height, color_mode);
2112 error = check_horiz_timing_omap3(channel, mgr_timings, pos_x,
2113 in_width, in_height, out_width, out_height);
2115 if (in_width > maxsinglelinewidth)
2116 if (in_height > out_height &&
2117 in_height < out_height * 2)
2120 *core_clk = dispc.feat->calc_core_clk(channel, in_width,
2121 in_height, out_width, out_height);
2123 error = (error || in_width > maxsinglelinewidth * 2 ||
2124 (in_width > maxsinglelinewidth && *five_taps) ||
2125 !*core_clk || *core_clk > dispc_core_clk_rate());
2127 if (*decim_x == *decim_y) {
2128 *decim_x = min_factor;
2131 swap(*decim_x, *decim_y);
2132 if (*decim_x < *decim_y)
2136 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2138 if (check_horiz_timing_omap3(channel, mgr_timings, pos_x, width, height,
2139 out_width, out_height)){
2140 DSSERR("horizontal timing too tight\n");
2144 if (in_width > (maxsinglelinewidth * 2)) {
2145 DSSERR("Cannot setup scaling");
2146 DSSERR("width exceeds maximum width possible");
2150 if (in_width > maxsinglelinewidth && *five_taps) {
2151 DSSERR("cannot setup scaling with five taps");
2157 static int dispc_ovl_calc_scaling_44xx(enum omap_channel channel,
2158 const struct omap_video_timings *mgr_timings,
2159 u16 width, u16 height, u16 out_width, u16 out_height,
2160 enum omap_color_mode color_mode, bool *five_taps,
2161 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2162 u16 pos_x, unsigned long *core_clk)
2164 u16 in_width, in_width_max;
2165 int decim_x_min = *decim_x;
2166 u16 in_height = DIV_ROUND_UP(height, *decim_y);
2167 const int maxsinglelinewidth =
2168 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2170 in_width_max = dispc_core_clk_rate() /
2171 DIV_ROUND_UP(dispc_mgr_pclk_rate(channel), out_width);
2172 *decim_x = DIV_ROUND_UP(width, in_width_max);
2174 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2175 if (*decim_x > *x_predecim)
2179 in_width = DIV_ROUND_UP(width, *decim_x);
2180 } while (*decim_x <= *x_predecim &&
2181 in_width > maxsinglelinewidth && ++*decim_x);
2183 if (in_width > maxsinglelinewidth) {
2184 DSSERR("Cannot scale width exceeds max line width");
2188 *core_clk = dispc.feat->calc_core_clk(channel, in_width, in_height,
2189 out_width, out_height);
2193 static int dispc_ovl_calc_scaling(enum omap_plane plane,
2194 enum omap_channel channel,
2195 const struct omap_video_timings *mgr_timings,
2196 u16 width, u16 height, u16 out_width, u16 out_height,
2197 enum omap_color_mode color_mode, bool *five_taps,
2198 int *x_predecim, int *y_predecim, u16 pos_x)
2200 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
2201 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2202 const int max_decim_limit = 16;
2203 unsigned long core_clk = 0;
2204 int decim_x, decim_y, ret;
2206 if (width == out_width && height == out_height)
2209 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
2212 *x_predecim = max_decim_limit;
2213 *y_predecim = max_decim_limit;
2215 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2216 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2217 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2218 color_mode == OMAP_DSS_COLOR_CLUT8) {
2225 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2226 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2228 if (decim_x > *x_predecim || out_width > width * 8)
2231 if (decim_y > *y_predecim || out_height > height * 8)
2234 ret = dispc.feat->calc_scaling(channel, mgr_timings, width, height,
2235 out_width, out_height, color_mode, five_taps, x_predecim,
2236 y_predecim, &decim_x, &decim_y, pos_x, &core_clk);
2240 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2241 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
2243 if (!core_clk || core_clk > dispc_core_clk_rate()) {
2244 DSSERR("failed to set up scaling, "
2245 "required core clk rate = %lu Hz, "
2246 "current core clk rate = %lu Hz\n",
2247 core_clk, dispc_core_clk_rate());
2251 *x_predecim = decim_x;
2252 *y_predecim = decim_y;
2256 int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
2257 bool replication, const struct omap_video_timings *mgr_timings)
2259 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
2260 bool five_taps = true;
2263 unsigned offset0, offset1;
2266 u16 frame_height = oi->height;
2267 unsigned int field_offset = 0;
2268 u16 in_height = oi->height;
2269 u16 in_width = oi->width;
2270 u16 out_width, out_height;
2271 enum omap_channel channel;
2272 int x_predecim = 1, y_predecim = 1;
2273 bool ilace = mgr_timings->interlace;
2275 channel = dispc_ovl_get_channel_out(plane);
2277 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
2278 "%dx%d, cmode %x, rot %d, mir %d, ilace %d chan %d repl %d\n",
2279 plane, oi->paddr, oi->p_uv_addr,
2280 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2281 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2282 oi->mirror, ilace, channel, replication);
2287 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
2288 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
2290 if (ilace && oi->height == out_height)
2299 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2301 in_height, oi->pos_y, out_height);
2304 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
2307 r = dispc_ovl_calc_scaling(plane, channel, mgr_timings, in_width,
2308 in_height, out_width, out_height, oi->color_mode,
2309 &five_taps, &x_predecim, &y_predecim, oi->pos_x);
2313 in_width = DIV_ROUND_UP(in_width, x_predecim);
2314 in_height = DIV_ROUND_UP(in_height, y_predecim);
2316 if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
2317 oi->color_mode == OMAP_DSS_COLOR_UYVY ||
2318 oi->color_mode == OMAP_DSS_COLOR_NV12)
2321 if (ilace && !fieldmode) {
2323 * when downscaling the bottom field may have to start several
2324 * source lines below the top field. Unfortunately ACCUI
2325 * registers will only hold the fractional part of the offset
2326 * so the integer part must be added to the base address of the
2329 if (!in_height || in_height == out_height)
2332 field_offset = in_height / out_height / 2;
2335 /* Fields are independent but interleaved in memory. */
2344 if (oi->rotation_type == OMAP_DSS_ROT_TILER)
2345 calc_tiler_rotation_offset(oi->screen_width, in_width,
2346 oi->color_mode, fieldmode, field_offset,
2347 &offset0, &offset1, &row_inc, &pix_inc,
2348 x_predecim, y_predecim);
2349 else if (oi->rotation_type == OMAP_DSS_ROT_DMA)
2350 calc_dma_rotation_offset(oi->rotation, oi->mirror,
2351 oi->screen_width, in_width, frame_height,
2352 oi->color_mode, fieldmode, field_offset,
2353 &offset0, &offset1, &row_inc, &pix_inc,
2354 x_predecim, y_predecim);
2356 calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
2357 oi->screen_width, in_width, frame_height,
2358 oi->color_mode, fieldmode, field_offset,
2359 &offset0, &offset1, &row_inc, &pix_inc,
2360 x_predecim, y_predecim);
2362 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2363 offset0, offset1, row_inc, pix_inc);
2365 dispc_ovl_set_color_mode(plane, oi->color_mode);
2367 dispc_ovl_configure_burst_type(plane, oi->rotation_type);
2369 dispc_ovl_set_ba0(plane, oi->paddr + offset0);
2370 dispc_ovl_set_ba1(plane, oi->paddr + offset1);
2372 if (OMAP_DSS_COLOR_NV12 == oi->color_mode) {
2373 dispc_ovl_set_ba0_uv(plane, oi->p_uv_addr + offset0);
2374 dispc_ovl_set_ba1_uv(plane, oi->p_uv_addr + offset1);
2378 dispc_ovl_set_row_inc(plane, row_inc);
2379 dispc_ovl_set_pix_inc(plane, pix_inc);
2381 DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, in_width,
2382 in_height, out_width, out_height);
2384 dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y);
2386 dispc_ovl_set_pic_size(plane, in_width, in_height);
2388 if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) {
2389 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2390 out_height, ilace, five_taps, fieldmode,
2391 oi->color_mode, oi->rotation);
2392 dispc_ovl_set_vid_size(plane, out_width, out_height);
2393 dispc_ovl_set_vid_color_conv(plane, cconv);
2396 dispc_ovl_set_rotation_attrs(plane, oi->rotation, oi->mirror,
2399 dispc_ovl_set_zorder(plane, oi->zorder);
2400 dispc_ovl_set_pre_mult_alpha(plane, oi->pre_mult_alpha);
2401 dispc_ovl_setup_global_alpha(plane, oi->global_alpha);
2403 dispc_ovl_enable_replication(plane, replication);
2408 int dispc_ovl_enable(enum omap_plane plane, bool enable)
2410 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2412 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2417 static void dispc_disable_isr(void *data, u32 mask)
2419 struct completion *compl = data;
2423 static void _enable_lcd_out(enum omap_channel channel, bool enable)
2425 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2426 /* flush posted write */
2427 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2430 static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
2432 struct completion frame_done_completion;
2437 /* When we disable LCD output, we need to wait until frame is done.
2438 * Otherwise the DSS is still working, and turning off the clocks
2439 * prevents DSS from going to OFF mode */
2440 is_on = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2442 irq = mgr_desc[channel].framedone_irq;
2444 if (!enable && is_on) {
2445 init_completion(&frame_done_completion);
2447 r = omap_dispc_register_isr(dispc_disable_isr,
2448 &frame_done_completion, irq);
2451 DSSERR("failed to register FRAMEDONE isr\n");
2454 _enable_lcd_out(channel, enable);
2456 if (!enable && is_on) {
2457 if (!wait_for_completion_timeout(&frame_done_completion,
2458 msecs_to_jiffies(100)))
2459 DSSERR("timeout waiting for FRAME DONE\n");
2461 r = omap_dispc_unregister_isr(dispc_disable_isr,
2462 &frame_done_completion, irq);
2465 DSSERR("failed to unregister FRAMEDONE isr\n");
2469 static void _enable_digit_out(bool enable)
2471 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
2472 /* flush posted write */
2473 dispc_read_reg(DISPC_CONTROL);
2476 static void dispc_mgr_enable_digit_out(bool enable)
2478 struct completion frame_done_completion;
2479 enum dss_hdmi_venc_clk_source_select src;
2484 if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
2487 src = dss_get_hdmi_venc_clk_source();
2490 unsigned long flags;
2491 /* When we enable digit output, we'll get an extra digit
2492 * sync lost interrupt, that we need to ignore */
2493 spin_lock_irqsave(&dispc.irq_lock, flags);
2494 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
2495 _omap_dispc_set_irqs();
2496 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2499 /* When we disable digit output, we need to wait until fields are done.
2500 * Otherwise the DSS is still working, and turning off the clocks
2501 * prevents DSS from going to OFF mode. And when enabling, we need to
2502 * wait for the extra sync losts */
2503 init_completion(&frame_done_completion);
2505 if (src == DSS_HDMI_M_PCLK && enable == false) {
2506 irq_mask = DISPC_IRQ_FRAMEDONETV;
2509 irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
2510 /* XXX I understand from TRM that we should only wait for the
2511 * current field to complete. But it seems we have to wait for
2516 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
2519 DSSERR("failed to register %x isr\n", irq_mask);
2521 _enable_digit_out(enable);
2523 for (i = 0; i < num_irqs; ++i) {
2524 if (!wait_for_completion_timeout(&frame_done_completion,
2525 msecs_to_jiffies(100)))
2526 DSSERR("timeout waiting for digit out to %s\n",
2527 enable ? "start" : "stop");
2530 r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
2533 DSSERR("failed to unregister %x isr\n", irq_mask);
2536 unsigned long flags;
2537 spin_lock_irqsave(&dispc.irq_lock, flags);
2538 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
2539 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
2540 _omap_dispc_set_irqs();
2541 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2545 bool dispc_mgr_is_enabled(enum omap_channel channel)
2547 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2550 void dispc_mgr_enable(enum omap_channel channel, bool enable)
2552 if (dss_mgr_is_lcd(channel))
2553 dispc_mgr_enable_lcd_out(channel, enable);
2554 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2555 dispc_mgr_enable_digit_out(enable);
2560 void dispc_lcd_enable_signal_polarity(bool act_high)
2562 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2565 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2568 void dispc_lcd_enable_signal(bool enable)
2570 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2573 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2576 void dispc_pck_free_enable(bool enable)
2578 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2581 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2584 void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2586 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
2590 void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
2592 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
2595 void dispc_set_loadmode(enum omap_dss_load_mode mode)
2597 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2601 static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2603 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2606 static void dispc_mgr_set_trans_key(enum omap_channel ch,
2607 enum omap_dss_trans_key_type type,
2610 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
2612 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2615 static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2617 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
2620 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2623 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
2626 if (ch == OMAP_DSS_CHANNEL_LCD)
2627 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2628 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2629 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2632 void dispc_mgr_setup(enum omap_channel channel,
2633 struct omap_overlay_manager_info *info)
2635 dispc_mgr_set_default_color(channel, info->default_color);
2636 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2637 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2638 dispc_mgr_enable_alpha_fixed_zorder(channel,
2639 info->partial_alpha_enabled);
2640 if (dss_has_feature(FEAT_CPR)) {
2641 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2642 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2646 void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2650 switch (data_lines) {
2668 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
2671 void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
2677 case DSS_IO_PAD_MODE_RESET:
2681 case DSS_IO_PAD_MODE_RFBI:
2685 case DSS_IO_PAD_MODE_BYPASS:
2694 l = dispc_read_reg(DISPC_CONTROL);
2695 l = FLD_MOD(l, gpout0, 15, 15);
2696 l = FLD_MOD(l, gpout1, 16, 16);
2697 dispc_write_reg(DISPC_CONTROL, l);
2700 void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2702 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
2705 static bool _dispc_mgr_size_ok(u16 width, u16 height)
2707 return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
2708 height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
2711 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2712 int vsw, int vfp, int vbp)
2714 if (hsw < 1 || hsw > dispc.feat->sw_max ||
2715 hfp < 1 || hfp > dispc.feat->hp_max ||
2716 hbp < 1 || hbp > dispc.feat->hp_max ||
2717 vsw < 1 || vsw > dispc.feat->sw_max ||
2718 vfp < 0 || vfp > dispc.feat->vp_max ||
2719 vbp < 0 || vbp > dispc.feat->vp_max)
2724 bool dispc_mgr_timings_ok(enum omap_channel channel,
2725 const struct omap_video_timings *timings)
2729 timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
2731 if (dss_mgr_is_lcd(channel))
2732 timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
2733 timings->hfp, timings->hbp,
2734 timings->vsw, timings->vfp,
2740 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
2741 int hfp, int hbp, int vsw, int vfp, int vbp,
2742 enum omap_dss_signal_level vsync_level,
2743 enum omap_dss_signal_level hsync_level,
2744 enum omap_dss_signal_edge data_pclk_edge,
2745 enum omap_dss_signal_level de_level,
2746 enum omap_dss_signal_edge sync_pclk_edge)
2749 u32 timing_h, timing_v, l;
2750 bool onoff, rf, ipc;
2752 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
2753 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
2754 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
2755 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
2756 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
2757 FLD_VAL(vbp, dispc.feat->bp_start, 20);
2759 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2760 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
2762 switch (data_pclk_edge) {
2763 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2766 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2769 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2774 switch (sync_pclk_edge) {
2775 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2779 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2783 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2791 l = dispc_read_reg(DISPC_POL_FREQ(channel));
2792 l |= FLD_VAL(onoff, 17, 17);
2793 l |= FLD_VAL(rf, 16, 16);
2794 l |= FLD_VAL(de_level, 15, 15);
2795 l |= FLD_VAL(ipc, 14, 14);
2796 l |= FLD_VAL(hsync_level, 13, 13);
2797 l |= FLD_VAL(vsync_level, 12, 12);
2798 dispc_write_reg(DISPC_POL_FREQ(channel), l);
2801 /* change name to mode? */
2802 void dispc_mgr_set_timings(enum omap_channel channel,
2803 struct omap_video_timings *timings)
2805 unsigned xtot, ytot;
2806 unsigned long ht, vt;
2807 struct omap_video_timings t = *timings;
2809 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
2811 if (!dispc_mgr_timings_ok(channel, &t)) {
2816 if (dss_mgr_is_lcd(channel)) {
2817 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
2818 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
2819 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
2821 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
2822 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
2824 ht = (timings->pixel_clock * 1000) / xtot;
2825 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2827 DSSDBG("pck %u\n", timings->pixel_clock);
2828 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2829 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
2830 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
2831 t.vsync_level, t.hsync_level, t.data_pclk_edge,
2832 t.de_level, t.sync_pclk_edge);
2834 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2836 if (t.interlace == true)
2840 dispc_mgr_set_size(channel, t.x_res, t.y_res);
2843 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
2846 BUG_ON(lck_div < 1);
2847 BUG_ON(pck_div < 1);
2849 dispc_write_reg(DISPC_DIVISORo(channel),
2850 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
2853 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
2857 l = dispc_read_reg(DISPC_DIVISORo(channel));
2858 *lck_div = FLD_GET(l, 23, 16);
2859 *pck_div = FLD_GET(l, 7, 0);
2862 unsigned long dispc_fclk_rate(void)
2864 struct platform_device *dsidev;
2865 unsigned long r = 0;
2867 switch (dss_get_dispc_clk_source()) {
2868 case OMAP_DSS_CLK_SRC_FCK:
2869 r = clk_get_rate(dispc.dss_clk);
2871 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2872 dsidev = dsi_get_dsidev_from_id(0);
2873 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2875 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2876 dsidev = dsi_get_dsidev_from_id(1);
2877 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2887 unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
2889 struct platform_device *dsidev;
2894 l = dispc_read_reg(DISPC_DIVISORo(channel));
2896 lcd = FLD_GET(l, 23, 16);
2898 switch (dss_get_lcd_clk_source(channel)) {
2899 case OMAP_DSS_CLK_SRC_FCK:
2900 r = clk_get_rate(dispc.dss_clk);
2902 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2903 dsidev = dsi_get_dsidev_from_id(0);
2904 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2906 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2907 dsidev = dsi_get_dsidev_from_id(1);
2908 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2918 unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
2922 if (dss_mgr_is_lcd(channel)) {
2926 l = dispc_read_reg(DISPC_DIVISORo(channel));
2928 pcd = FLD_GET(l, 7, 0);
2930 r = dispc_mgr_lclk_rate(channel);
2934 enum dss_hdmi_venc_clk_source_select source;
2936 source = dss_get_hdmi_venc_clk_source();
2939 case DSS_VENC_TV_CLK:
2940 return venc_get_pixel_clock();
2941 case DSS_HDMI_M_PCLK:
2942 return hdmi_get_pixel_clock();
2950 unsigned long dispc_core_clk_rate(void)
2953 unsigned long fclk = dispc_fclk_rate();
2955 if (dss_has_feature(FEAT_CORE_CLK_DIV))
2956 lcd = REG_GET(DISPC_DIVISOR, 23, 16);
2958 lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
2963 static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
2966 enum omap_dss_clk_source lcd_clk_src;
2968 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
2970 lcd_clk_src = dss_get_lcd_clk_source(channel);
2972 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
2973 dss_get_generic_clk_source_name(lcd_clk_src),
2974 dss_feat_get_clk_source_name(lcd_clk_src));
2976 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
2978 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
2979 dispc_mgr_lclk_rate(channel), lcd);
2980 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
2981 dispc_mgr_pclk_rate(channel), pcd);
2984 void dispc_dump_clocks(struct seq_file *s)
2988 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
2990 if (dispc_runtime_get())
2993 seq_printf(s, "- DISPC -\n");
2995 seq_printf(s, "dispc fclk source = %s (%s)\n",
2996 dss_get_generic_clk_source_name(dispc_clk_src),
2997 dss_feat_get_clk_source_name(dispc_clk_src));
2999 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
3001 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3002 seq_printf(s, "- DISPC-CORE-CLK -\n");
3003 l = dispc_read_reg(DISPC_DIVISOR);
3004 lcd = FLD_GET(l, 23, 16);
3006 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3007 (dispc_fclk_rate()/lcd), lcd);
3010 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
3012 if (dss_has_feature(FEAT_MGR_LCD2))
3013 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3014 if (dss_has_feature(FEAT_MGR_LCD3))
3015 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
3017 dispc_runtime_put();
3020 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3021 void dispc_dump_irqs(struct seq_file *s)
3023 unsigned long flags;
3024 struct dispc_irq_stats stats;
3026 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
3028 stats = dispc.irq_stats;
3029 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
3030 dispc.irq_stats.last_reset = jiffies;
3032 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
3034 seq_printf(s, "period %u ms\n",
3035 jiffies_to_msecs(jiffies - stats.last_reset));
3037 seq_printf(s, "irqs %d\n", stats.irq_count);
3039 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
3045 PIS(ACBIAS_COUNT_STAT);
3047 PIS(GFX_FIFO_UNDERFLOW);
3049 PIS(PAL_GAMMA_MASK);
3051 PIS(VID1_FIFO_UNDERFLOW);
3053 PIS(VID2_FIFO_UNDERFLOW);
3055 if (dss_feat_get_num_ovls() > 3) {
3056 PIS(VID3_FIFO_UNDERFLOW);
3060 PIS(SYNC_LOST_DIGIT);
3062 if (dss_has_feature(FEAT_MGR_LCD2)) {
3065 PIS(ACBIAS_COUNT_STAT2);
3068 if (dss_has_feature(FEAT_MGR_LCD3)) {
3071 PIS(ACBIAS_COUNT_STAT3);
3078 static void dispc_dump_regs(struct seq_file *s)
3081 const char *mgr_names[] = {
3082 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3083 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3084 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
3085 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
3087 const char *ovl_names[] = {
3088 [OMAP_DSS_GFX] = "GFX",
3089 [OMAP_DSS_VIDEO1] = "VID1",
3090 [OMAP_DSS_VIDEO2] = "VID2",
3091 [OMAP_DSS_VIDEO3] = "VID3",
3093 const char **p_names;
3095 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3097 if (dispc_runtime_get())
3100 /* DISPC common registers */
3101 DUMPREG(DISPC_REVISION);
3102 DUMPREG(DISPC_SYSCONFIG);
3103 DUMPREG(DISPC_SYSSTATUS);
3104 DUMPREG(DISPC_IRQSTATUS);
3105 DUMPREG(DISPC_IRQENABLE);
3106 DUMPREG(DISPC_CONTROL);
3107 DUMPREG(DISPC_CONFIG);
3108 DUMPREG(DISPC_CAPABLE);
3109 DUMPREG(DISPC_LINE_STATUS);
3110 DUMPREG(DISPC_LINE_NUMBER);
3111 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3112 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
3113 DUMPREG(DISPC_GLOBAL_ALPHA);
3114 if (dss_has_feature(FEAT_MGR_LCD2)) {
3115 DUMPREG(DISPC_CONTROL2);
3116 DUMPREG(DISPC_CONFIG2);
3118 if (dss_has_feature(FEAT_MGR_LCD3)) {
3119 DUMPREG(DISPC_CONTROL3);
3120 DUMPREG(DISPC_CONFIG3);
3125 #define DISPC_REG(i, name) name(i)
3126 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3127 48 - strlen(#r) - strlen(p_names[i]), " ", \
3128 dispc_read_reg(DISPC_REG(i, r)))
3130 p_names = mgr_names;
3132 /* DISPC channel specific registers */
3133 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3134 DUMPREG(i, DISPC_DEFAULT_COLOR);
3135 DUMPREG(i, DISPC_TRANS_COLOR);
3136 DUMPREG(i, DISPC_SIZE_MGR);
3138 if (i == OMAP_DSS_CHANNEL_DIGIT)
3141 DUMPREG(i, DISPC_DEFAULT_COLOR);
3142 DUMPREG(i, DISPC_TRANS_COLOR);
3143 DUMPREG(i, DISPC_TIMING_H);
3144 DUMPREG(i, DISPC_TIMING_V);
3145 DUMPREG(i, DISPC_POL_FREQ);
3146 DUMPREG(i, DISPC_DIVISORo);
3147 DUMPREG(i, DISPC_SIZE_MGR);
3149 DUMPREG(i, DISPC_DATA_CYCLE1);
3150 DUMPREG(i, DISPC_DATA_CYCLE2);
3151 DUMPREG(i, DISPC_DATA_CYCLE3);
3153 if (dss_has_feature(FEAT_CPR)) {
3154 DUMPREG(i, DISPC_CPR_COEF_R);
3155 DUMPREG(i, DISPC_CPR_COEF_G);
3156 DUMPREG(i, DISPC_CPR_COEF_B);
3160 p_names = ovl_names;
3162 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3163 DUMPREG(i, DISPC_OVL_BA0);
3164 DUMPREG(i, DISPC_OVL_BA1);
3165 DUMPREG(i, DISPC_OVL_POSITION);
3166 DUMPREG(i, DISPC_OVL_SIZE);
3167 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3168 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3169 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3170 DUMPREG(i, DISPC_OVL_ROW_INC);
3171 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3172 if (dss_has_feature(FEAT_PRELOAD))
3173 DUMPREG(i, DISPC_OVL_PRELOAD);
3175 if (i == OMAP_DSS_GFX) {
3176 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3177 DUMPREG(i, DISPC_OVL_TABLE_BA);
3181 DUMPREG(i, DISPC_OVL_FIR);
3182 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3183 DUMPREG(i, DISPC_OVL_ACCU0);
3184 DUMPREG(i, DISPC_OVL_ACCU1);
3185 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3186 DUMPREG(i, DISPC_OVL_BA0_UV);
3187 DUMPREG(i, DISPC_OVL_BA1_UV);
3188 DUMPREG(i, DISPC_OVL_FIR2);
3189 DUMPREG(i, DISPC_OVL_ACCU2_0);
3190 DUMPREG(i, DISPC_OVL_ACCU2_1);
3192 if (dss_has_feature(FEAT_ATTR2))
3193 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3194 if (dss_has_feature(FEAT_PRELOAD))
3195 DUMPREG(i, DISPC_OVL_PRELOAD);
3201 #define DISPC_REG(plane, name, i) name(plane, i)
3202 #define DUMPREG(plane, name, i) \
3203 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3204 46 - strlen(#name) - strlen(p_names[plane]), " ", \
3205 dispc_read_reg(DISPC_REG(plane, name, i)))
3207 /* Video pipeline coefficient registers */
3209 /* start from OMAP_DSS_VIDEO1 */
3210 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3211 for (j = 0; j < 8; j++)
3212 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
3214 for (j = 0; j < 8; j++)
3215 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
3217 for (j = 0; j < 5; j++)
3218 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
3220 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3221 for (j = 0; j < 8; j++)
3222 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3225 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3226 for (j = 0; j < 8; j++)
3227 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
3229 for (j = 0; j < 8; j++)
3230 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
3232 for (j = 0; j < 8; j++)
3233 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3237 dispc_runtime_put();
3243 /* with fck as input clock rate, find dispc dividers that produce req_pck */
3244 void dispc_find_clk_divs(unsigned long req_pck, unsigned long fck,
3245 struct dispc_clock_info *cinfo)
3247 u16 pcd_min, pcd_max;
3248 unsigned long best_pck;
3249 u16 best_ld, cur_ld;
3250 u16 best_pd, cur_pd;
3252 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3253 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3259 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
3260 unsigned long lck = fck / cur_ld;
3262 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
3263 unsigned long pck = lck / cur_pd;
3264 long old_delta = abs(best_pck - req_pck);
3265 long new_delta = abs(pck - req_pck);
3267 if (best_pck == 0 || new_delta < old_delta) {
3280 if (lck / pcd_min < req_pck)
3285 cinfo->lck_div = best_ld;
3286 cinfo->pck_div = best_pd;
3287 cinfo->lck = fck / cinfo->lck_div;
3288 cinfo->pck = cinfo->lck / cinfo->pck_div;
3291 /* calculate clock rates using dividers in cinfo */
3292 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3293 struct dispc_clock_info *cinfo)
3295 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3297 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3300 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3301 cinfo->pck = cinfo->lck / cinfo->pck_div;
3306 void dispc_mgr_set_clock_div(enum omap_channel channel,
3307 struct dispc_clock_info *cinfo)
3309 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3310 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3312 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
3315 int dispc_mgr_get_clock_div(enum omap_channel channel,
3316 struct dispc_clock_info *cinfo)
3320 fck = dispc_fclk_rate();
3322 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3323 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
3325 cinfo->lck = fck / cinfo->lck_div;
3326 cinfo->pck = cinfo->lck / cinfo->pck_div;
3331 /* dispc.irq_lock has to be locked by the caller */
3332 static void _omap_dispc_set_irqs(void)
3337 struct omap_dispc_isr_data *isr_data;
3339 mask = dispc.irq_error_mask;
3341 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3342 isr_data = &dispc.registered_isr[i];
3344 if (isr_data->isr == NULL)
3347 mask |= isr_data->mask;
3350 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3351 /* clear the irqstatus for newly enabled irqs */
3352 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
3354 dispc_write_reg(DISPC_IRQENABLE, mask);
3357 int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3361 unsigned long flags;
3362 struct omap_dispc_isr_data *isr_data;
3367 spin_lock_irqsave(&dispc.irq_lock, flags);
3369 /* check for duplicate entry */
3370 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3371 isr_data = &dispc.registered_isr[i];
3372 if (isr_data->isr == isr && isr_data->arg == arg &&
3373 isr_data->mask == mask) {
3382 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3383 isr_data = &dispc.registered_isr[i];
3385 if (isr_data->isr != NULL)
3388 isr_data->isr = isr;
3389 isr_data->arg = arg;
3390 isr_data->mask = mask;
3399 _omap_dispc_set_irqs();
3401 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3405 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3409 EXPORT_SYMBOL(omap_dispc_register_isr);
3411 int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3414 unsigned long flags;
3416 struct omap_dispc_isr_data *isr_data;
3418 spin_lock_irqsave(&dispc.irq_lock, flags);
3420 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3421 isr_data = &dispc.registered_isr[i];
3422 if (isr_data->isr != isr || isr_data->arg != arg ||
3423 isr_data->mask != mask)
3426 /* found the correct isr */
3428 isr_data->isr = NULL;
3429 isr_data->arg = NULL;
3437 _omap_dispc_set_irqs();
3439 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3443 EXPORT_SYMBOL(omap_dispc_unregister_isr);
3446 static void print_irq_status(u32 status)
3448 if ((status & dispc.irq_error_mask) == 0)
3451 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
3454 if (status & DISPC_IRQ_##x) \
3456 PIS(GFX_FIFO_UNDERFLOW);
3458 PIS(VID1_FIFO_UNDERFLOW);
3459 PIS(VID2_FIFO_UNDERFLOW);
3460 if (dss_feat_get_num_ovls() > 3)
3461 PIS(VID3_FIFO_UNDERFLOW);
3463 PIS(SYNC_LOST_DIGIT);
3464 if (dss_has_feature(FEAT_MGR_LCD2))
3466 if (dss_has_feature(FEAT_MGR_LCD3))
3474 /* Called from dss.c. Note that we don't touch clocks here,
3475 * but we presume they are on because we got an IRQ. However,
3476 * an irq handler may turn the clocks off, so we may not have
3477 * clock later in the function. */
3478 static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
3481 u32 irqstatus, irqenable;
3482 u32 handledirqs = 0;
3483 u32 unhandled_errors;
3484 struct omap_dispc_isr_data *isr_data;
3485 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3487 spin_lock(&dispc.irq_lock);
3489 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
3490 irqenable = dispc_read_reg(DISPC_IRQENABLE);
3492 /* IRQ is not for us */
3493 if (!(irqstatus & irqenable)) {
3494 spin_unlock(&dispc.irq_lock);
3498 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3499 spin_lock(&dispc.irq_stats_lock);
3500 dispc.irq_stats.irq_count++;
3501 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3502 spin_unlock(&dispc.irq_stats_lock);
3507 print_irq_status(irqstatus);
3509 /* Ack the interrupt. Do it here before clocks are possibly turned
3511 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
3512 /* flush posted write */
3513 dispc_read_reg(DISPC_IRQSTATUS);
3515 /* make a copy and unlock, so that isrs can unregister
3517 memcpy(registered_isr, dispc.registered_isr,
3518 sizeof(registered_isr));
3520 spin_unlock(&dispc.irq_lock);
3522 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3523 isr_data = ®istered_isr[i];
3528 if (isr_data->mask & irqstatus) {
3529 isr_data->isr(isr_data->arg, irqstatus);
3530 handledirqs |= isr_data->mask;
3534 spin_lock(&dispc.irq_lock);
3536 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3538 if (unhandled_errors) {
3539 dispc.error_irqs |= unhandled_errors;
3541 dispc.irq_error_mask &= ~unhandled_errors;
3542 _omap_dispc_set_irqs();
3544 schedule_work(&dispc.error_work);
3547 spin_unlock(&dispc.irq_lock);
3552 static void dispc_error_worker(struct work_struct *work)
3556 unsigned long flags;
3557 static const unsigned fifo_underflow_bits[] = {
3558 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3559 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3560 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
3561 DISPC_IRQ_VID3_FIFO_UNDERFLOW,
3564 spin_lock_irqsave(&dispc.irq_lock, flags);
3565 errors = dispc.error_irqs;
3566 dispc.error_irqs = 0;
3567 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3569 dispc_runtime_get();
3571 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3572 struct omap_overlay *ovl;
3575 ovl = omap_dss_get_overlay(i);
3576 bit = fifo_underflow_bits[i];
3579 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3581 dispc_ovl_enable(ovl->id, false);
3582 dispc_mgr_go(ovl->manager->id);
3587 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3588 struct omap_overlay_manager *mgr;
3591 mgr = omap_dss_get_overlay_manager(i);
3592 bit = mgr_desc[i].sync_lost_irq;
3595 struct omap_dss_device *dssdev = mgr->device;
3598 DSSERR("SYNC_LOST on channel %s, restarting the output "
3599 "with video overlays disabled\n",
3602 enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
3603 dssdev->driver->disable(dssdev);
3605 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3606 struct omap_overlay *ovl;
3607 ovl = omap_dss_get_overlay(i);
3609 if (ovl->id != OMAP_DSS_GFX &&
3610 ovl->manager == mgr)
3611 dispc_ovl_enable(ovl->id, false);
3614 dispc_mgr_go(mgr->id);
3618 dssdev->driver->enable(dssdev);
3622 if (errors & DISPC_IRQ_OCP_ERR) {
3623 DSSERR("OCP_ERR\n");
3624 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3625 struct omap_overlay_manager *mgr;
3626 mgr = omap_dss_get_overlay_manager(i);
3627 if (mgr->device && mgr->device->driver)
3628 mgr->device->driver->disable(mgr->device);
3632 spin_lock_irqsave(&dispc.irq_lock, flags);
3633 dispc.irq_error_mask |= errors;
3634 _omap_dispc_set_irqs();
3635 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3637 dispc_runtime_put();
3640 int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3642 void dispc_irq_wait_handler(void *data, u32 mask)
3644 complete((struct completion *)data);
3648 DECLARE_COMPLETION_ONSTACK(completion);
3650 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3656 timeout = wait_for_completion_timeout(&completion, timeout);
3658 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3663 if (timeout == -ERESTARTSYS)
3664 return -ERESTARTSYS;
3669 int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3670 unsigned long timeout)
3672 void dispc_irq_wait_handler(void *data, u32 mask)
3674 complete((struct completion *)data);
3678 DECLARE_COMPLETION_ONSTACK(completion);
3680 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3686 timeout = wait_for_completion_interruptible_timeout(&completion,
3689 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3694 if (timeout == -ERESTARTSYS)
3695 return -ERESTARTSYS;
3700 static void _omap_dispc_initialize_irq(void)
3702 unsigned long flags;
3704 spin_lock_irqsave(&dispc.irq_lock, flags);
3706 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3708 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
3709 if (dss_has_feature(FEAT_MGR_LCD2))
3710 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
3711 if (dss_has_feature(FEAT_MGR_LCD3))
3712 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST3;
3713 if (dss_feat_get_num_ovls() > 3)
3714 dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
3716 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3718 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3720 _omap_dispc_set_irqs();
3722 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3725 void dispc_enable_sidle(void)
3727 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3730 void dispc_disable_sidle(void)
3732 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3735 static void _omap_dispc_initial_config(void)
3739 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3740 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3741 l = dispc_read_reg(DISPC_DIVISOR);
3742 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3743 l = FLD_MOD(l, 1, 0, 0);
3744 l = FLD_MOD(l, 1, 23, 16);
3745 dispc_write_reg(DISPC_DIVISOR, l);
3749 if (dss_has_feature(FEAT_FUNCGATED))
3750 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3752 _dispc_setup_color_conv_coef();
3754 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3758 dispc_configure_burst_sizes();
3760 dispc_ovl_enable_zorder_planes();
3763 static const struct dispc_features omap24xx_dispc_feats __initconst = {
3770 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3771 .calc_core_clk = calc_core_clk_24xx,
3775 static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
3782 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3783 .calc_core_clk = calc_core_clk_34xx,
3787 static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
3794 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3795 .calc_core_clk = calc_core_clk_34xx,
3799 static const struct dispc_features omap44xx_dispc_feats __initconst = {
3806 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3807 .calc_core_clk = calc_core_clk_44xx,
3809 .gfx_fifo_workaround = true,
3812 static int __init dispc_init_features(struct device *dev)
3814 const struct dispc_features *src;
3815 struct dispc_features *dst;
3817 dst = devm_kzalloc(dev, sizeof(*dst), GFP_KERNEL);
3819 dev_err(dev, "Failed to allocate DISPC Features\n");
3823 if (cpu_is_omap24xx()) {
3824 src = &omap24xx_dispc_feats;
3825 } else if (cpu_is_omap34xx()) {
3826 if (omap_rev() < OMAP3430_REV_ES3_0)
3827 src = &omap34xx_rev1_0_dispc_feats;
3829 src = &omap34xx_rev3_0_dispc_feats;
3830 } else if (cpu_is_omap44xx()) {
3831 src = &omap44xx_dispc_feats;
3836 memcpy(dst, src, sizeof(*dst));
3842 /* DISPC HW IP initialisation */
3843 static int __init omap_dispchw_probe(struct platform_device *pdev)
3847 struct resource *dispc_mem;
3852 r = dispc_init_features(&dispc.pdev->dev);
3856 spin_lock_init(&dispc.irq_lock);
3858 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3859 spin_lock_init(&dispc.irq_stats_lock);
3860 dispc.irq_stats.last_reset = jiffies;
3863 INIT_WORK(&dispc.error_work, dispc_error_worker);
3865 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3867 DSSERR("can't get IORESOURCE_MEM DISPC\n");
3871 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3872 resource_size(dispc_mem));
3874 DSSERR("can't ioremap DISPC\n");
3878 dispc.irq = platform_get_irq(dispc.pdev, 0);
3879 if (dispc.irq < 0) {
3880 DSSERR("platform_get_irq failed\n");
3884 r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
3885 IRQF_SHARED, "OMAP DISPC", dispc.pdev);
3887 DSSERR("request_irq failed\n");
3891 clk = clk_get(&pdev->dev, "fck");
3893 DSSERR("can't get fck\n");
3898 dispc.dss_clk = clk;
3900 pm_runtime_enable(&pdev->dev);
3902 r = dispc_runtime_get();
3904 goto err_runtime_get;
3906 _omap_dispc_initial_config();
3908 _omap_dispc_initialize_irq();
3910 rev = dispc_read_reg(DISPC_REVISION);
3911 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
3912 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3914 dispc_runtime_put();
3916 dss_debugfs_create_file("dispc", dispc_dump_regs);
3918 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3919 dss_debugfs_create_file("dispc_irq", dispc_dump_irqs);
3924 pm_runtime_disable(&pdev->dev);
3925 clk_put(dispc.dss_clk);
3929 static int __exit omap_dispchw_remove(struct platform_device *pdev)
3931 pm_runtime_disable(&pdev->dev);
3933 clk_put(dispc.dss_clk);
3938 static int dispc_runtime_suspend(struct device *dev)
3940 dispc_save_context();
3945 static int dispc_runtime_resume(struct device *dev)
3947 dispc_restore_context();
3952 static const struct dev_pm_ops dispc_pm_ops = {
3953 .runtime_suspend = dispc_runtime_suspend,
3954 .runtime_resume = dispc_runtime_resume,
3957 static struct platform_driver omap_dispchw_driver = {
3958 .remove = __exit_p(omap_dispchw_remove),
3960 .name = "omapdss_dispc",
3961 .owner = THIS_MODULE,
3962 .pm = &dispc_pm_ops,
3966 int __init dispc_init_platform_driver(void)
3968 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
3971 void __exit dispc_uninit_platform_driver(void)
3973 platform_driver_unregister(&omap_dispchw_driver);