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)
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 dispc_write_reg(DISPC_OVL_SIZE(plane), val);
740 static void dispc_ovl_set_zorder(enum omap_plane plane,
741 enum omap_overlay_caps caps, u8 zorder)
743 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
746 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
749 static void dispc_ovl_enable_zorder_planes(void)
753 if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
756 for (i = 0; i < dss_feat_get_num_ovls(); i++)
757 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
760 static void dispc_ovl_set_pre_mult_alpha(enum omap_plane plane,
761 enum omap_overlay_caps caps, bool enable)
763 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
766 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
769 static void dispc_ovl_setup_global_alpha(enum omap_plane plane,
770 enum omap_overlay_caps caps, u8 global_alpha)
772 static const unsigned shifts[] = { 0, 8, 16, 24, };
775 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
778 shift = shifts[plane];
779 REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
782 static void dispc_ovl_set_pix_inc(enum omap_plane plane, s32 inc)
784 dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc);
787 static void dispc_ovl_set_row_inc(enum omap_plane plane, s32 inc)
789 dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc);
792 static void dispc_ovl_set_color_mode(enum omap_plane plane,
793 enum omap_color_mode color_mode)
796 if (plane != OMAP_DSS_GFX) {
797 switch (color_mode) {
798 case OMAP_DSS_COLOR_NV12:
800 case OMAP_DSS_COLOR_RGBX16:
802 case OMAP_DSS_COLOR_RGBA16:
804 case OMAP_DSS_COLOR_RGB12U:
806 case OMAP_DSS_COLOR_ARGB16:
808 case OMAP_DSS_COLOR_RGB16:
810 case OMAP_DSS_COLOR_ARGB16_1555:
812 case OMAP_DSS_COLOR_RGB24U:
814 case OMAP_DSS_COLOR_RGB24P:
816 case OMAP_DSS_COLOR_YUV2:
818 case OMAP_DSS_COLOR_UYVY:
820 case OMAP_DSS_COLOR_ARGB32:
822 case OMAP_DSS_COLOR_RGBA32:
824 case OMAP_DSS_COLOR_RGBX32:
826 case OMAP_DSS_COLOR_XRGB16_1555:
832 switch (color_mode) {
833 case OMAP_DSS_COLOR_CLUT1:
835 case OMAP_DSS_COLOR_CLUT2:
837 case OMAP_DSS_COLOR_CLUT4:
839 case OMAP_DSS_COLOR_CLUT8:
841 case OMAP_DSS_COLOR_RGB12U:
843 case OMAP_DSS_COLOR_ARGB16:
845 case OMAP_DSS_COLOR_RGB16:
847 case OMAP_DSS_COLOR_ARGB16_1555:
849 case OMAP_DSS_COLOR_RGB24U:
851 case OMAP_DSS_COLOR_RGB24P:
853 case OMAP_DSS_COLOR_RGBX16:
855 case OMAP_DSS_COLOR_RGBA16:
857 case OMAP_DSS_COLOR_ARGB32:
859 case OMAP_DSS_COLOR_RGBA32:
861 case OMAP_DSS_COLOR_RGBX32:
863 case OMAP_DSS_COLOR_XRGB16_1555:
870 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
873 static void dispc_ovl_configure_burst_type(enum omap_plane plane,
874 enum omap_dss_rotation_type rotation_type)
876 if (dss_has_feature(FEAT_BURST_2D) == 0)
879 if (rotation_type == OMAP_DSS_ROT_TILER)
880 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
882 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
885 void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
889 int chan = 0, chan2 = 0;
895 case OMAP_DSS_VIDEO1:
896 case OMAP_DSS_VIDEO2:
897 case OMAP_DSS_VIDEO3:
905 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
906 if (dss_has_feature(FEAT_MGR_LCD2)) {
908 case OMAP_DSS_CHANNEL_LCD:
912 case OMAP_DSS_CHANNEL_DIGIT:
916 case OMAP_DSS_CHANNEL_LCD2:
920 case OMAP_DSS_CHANNEL_LCD3:
921 if (dss_has_feature(FEAT_MGR_LCD3)) {
934 val = FLD_MOD(val, chan, shift, shift);
935 val = FLD_MOD(val, chan2, 31, 30);
937 val = FLD_MOD(val, channel, shift, shift);
939 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
942 static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
946 enum omap_channel channel;
952 case OMAP_DSS_VIDEO1:
953 case OMAP_DSS_VIDEO2:
954 case OMAP_DSS_VIDEO3:
962 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
964 if (dss_has_feature(FEAT_MGR_LCD3)) {
965 if (FLD_GET(val, 31, 30) == 0)
966 channel = FLD_GET(val, shift, shift);
967 else if (FLD_GET(val, 31, 30) == 1)
968 channel = OMAP_DSS_CHANNEL_LCD2;
970 channel = OMAP_DSS_CHANNEL_LCD3;
971 } else if (dss_has_feature(FEAT_MGR_LCD2)) {
972 if (FLD_GET(val, 31, 30) == 0)
973 channel = FLD_GET(val, shift, shift);
975 channel = OMAP_DSS_CHANNEL_LCD2;
977 channel = FLD_GET(val, shift, shift);
983 static void dispc_ovl_set_burst_size(enum omap_plane plane,
984 enum omap_burst_size burst_size)
986 static const unsigned shifts[] = { 6, 14, 14, 14, };
989 shift = shifts[plane];
990 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift);
993 static void dispc_configure_burst_sizes(void)
996 const int burst_size = BURST_SIZE_X8;
998 /* Configure burst size always to maximum size */
999 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1000 dispc_ovl_set_burst_size(i, burst_size);
1003 static u32 dispc_ovl_get_burst_size(enum omap_plane plane)
1005 unsigned unit = dss_feat_get_burst_size_unit();
1006 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1010 void dispc_enable_gamma_table(bool enable)
1013 * This is partially implemented to support only disabling of
1017 DSSWARN("Gamma table enabling for TV not yet supported");
1021 REG_FLD_MOD(DISPC_CONFIG, enable, 9, 9);
1024 static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable)
1026 if (channel == OMAP_DSS_CHANNEL_DIGIT)
1029 mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable);
1032 static void dispc_mgr_set_cpr_coef(enum omap_channel channel,
1033 struct omap_dss_cpr_coefs *coefs)
1035 u32 coef_r, coef_g, coef_b;
1037 if (!dss_mgr_is_lcd(channel))
1040 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1041 FLD_VAL(coefs->rb, 9, 0);
1042 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1043 FLD_VAL(coefs->gb, 9, 0);
1044 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1045 FLD_VAL(coefs->bb, 9, 0);
1047 dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r);
1048 dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g);
1049 dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b);
1052 static void dispc_ovl_set_vid_color_conv(enum omap_plane plane, bool enable)
1056 BUG_ON(plane == OMAP_DSS_GFX);
1058 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1059 val = FLD_MOD(val, enable, 9, 9);
1060 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val);
1063 static void dispc_ovl_enable_replication(enum omap_plane plane,
1064 enum omap_overlay_caps caps, bool enable)
1066 static const unsigned shifts[] = { 5, 10, 10, 10 };
1069 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1072 shift = shifts[plane];
1073 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
1076 static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
1081 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
1082 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
1085 static void dispc_init_fifos(void)
1092 unit = dss_feat_get_buffer_size_unit();
1094 dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end);
1096 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1097 size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end);
1099 dispc.fifo_size[fifo] = size;
1102 * By default fifos are mapped directly to overlays, fifo 0 to
1103 * ovl 0, fifo 1 to ovl 1, etc.
1105 dispc.fifo_assignment[fifo] = fifo;
1109 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1110 * causes problems with certain use cases, like using the tiler in 2D
1111 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1112 * giving GFX plane a larger fifo. WB but should work fine with a
1115 if (dispc.feat->gfx_fifo_workaround) {
1118 v = dispc_read_reg(DISPC_GLOBAL_BUFFER);
1120 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1121 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1122 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1123 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1125 dispc_write_reg(DISPC_GLOBAL_BUFFER, v);
1127 dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1128 dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1132 static u32 dispc_ovl_get_fifo_size(enum omap_plane plane)
1137 for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) {
1138 if (dispc.fifo_assignment[fifo] == plane)
1139 size += dispc.fifo_size[fifo];
1145 void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high)
1147 u8 hi_start, hi_end, lo_start, lo_end;
1150 unit = dss_feat_get_buffer_size_unit();
1152 WARN_ON(low % unit != 0);
1153 WARN_ON(high % unit != 0);
1158 dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end);
1159 dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end);
1161 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1163 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1164 lo_start, lo_end) * unit,
1165 REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane),
1166 hi_start, hi_end) * unit,
1167 low * unit, high * unit);
1169 dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane),
1170 FLD_VAL(high, hi_start, hi_end) |
1171 FLD_VAL(low, lo_start, lo_end));
1174 void dispc_enable_fifomerge(bool enable)
1176 if (!dss_has_feature(FEAT_FIFO_MERGE)) {
1181 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1182 REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1185 void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1186 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1190 * All sizes are in bytes. Both the buffer and burst are made of
1191 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1194 unsigned buf_unit = dss_feat_get_buffer_size_unit();
1195 unsigned ovl_fifo_size, total_fifo_size, burst_size;
1198 burst_size = dispc_ovl_get_burst_size(plane);
1199 ovl_fifo_size = dispc_ovl_get_fifo_size(plane);
1201 if (use_fifomerge) {
1202 total_fifo_size = 0;
1203 for (i = 0; i < omap_dss_get_num_overlays(); ++i)
1204 total_fifo_size += dispc_ovl_get_fifo_size(i);
1206 total_fifo_size = ovl_fifo_size;
1210 * We use the same low threshold for both fifomerge and non-fifomerge
1211 * cases, but for fifomerge we calculate the high threshold using the
1212 * combined fifo size
1215 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1216 *fifo_low = ovl_fifo_size - burst_size * 2;
1217 *fifo_high = total_fifo_size - burst_size;
1219 *fifo_low = ovl_fifo_size - burst_size;
1220 *fifo_high = total_fifo_size - buf_unit;
1224 static void dispc_ovl_set_fir(enum omap_plane plane,
1226 enum omap_color_component color_comp)
1230 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1231 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1233 dss_feat_get_reg_field(FEAT_REG_FIRHINC,
1234 &hinc_start, &hinc_end);
1235 dss_feat_get_reg_field(FEAT_REG_FIRVINC,
1236 &vinc_start, &vinc_end);
1237 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1238 FLD_VAL(hinc, hinc_start, hinc_end);
1240 dispc_write_reg(DISPC_OVL_FIR(plane), val);
1242 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1243 dispc_write_reg(DISPC_OVL_FIR2(plane), val);
1247 static void dispc_ovl_set_vid_accu0(enum omap_plane plane, int haccu, int vaccu)
1250 u8 hor_start, hor_end, vert_start, vert_end;
1252 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1253 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1255 val = FLD_VAL(vaccu, vert_start, vert_end) |
1256 FLD_VAL(haccu, hor_start, hor_end);
1258 dispc_write_reg(DISPC_OVL_ACCU0(plane), val);
1261 static void dispc_ovl_set_vid_accu1(enum omap_plane plane, int haccu, int vaccu)
1264 u8 hor_start, hor_end, vert_start, vert_end;
1266 dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end);
1267 dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end);
1269 val = FLD_VAL(vaccu, vert_start, vert_end) |
1270 FLD_VAL(haccu, hor_start, hor_end);
1272 dispc_write_reg(DISPC_OVL_ACCU1(plane), val);
1275 static void dispc_ovl_set_vid_accu2_0(enum omap_plane plane, int haccu,
1280 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1281 dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val);
1284 static void dispc_ovl_set_vid_accu2_1(enum omap_plane plane, int haccu,
1289 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1290 dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val);
1293 static void dispc_ovl_set_scale_param(enum omap_plane plane,
1294 u16 orig_width, u16 orig_height,
1295 u16 out_width, u16 out_height,
1296 bool five_taps, u8 rotation,
1297 enum omap_color_component color_comp)
1299 int fir_hinc, fir_vinc;
1301 fir_hinc = 1024 * orig_width / out_width;
1302 fir_vinc = 1024 * orig_height / out_height;
1304 dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps,
1306 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1309 static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1310 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1311 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1313 int h_accu2_0, h_accu2_1;
1314 int v_accu2_0, v_accu2_1;
1315 int chroma_hinc, chroma_vinc;
1325 const struct accu *accu_table;
1326 const struct accu *accu_val;
1328 static const struct accu accu_nv12[4] = {
1329 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1330 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1331 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1332 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1335 static const struct accu accu_nv12_ilace[4] = {
1336 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1337 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1338 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1339 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1342 static const struct accu accu_yuv[4] = {
1343 { 0, 1, 0, 1, 0, 1, 0, 1 },
1344 { 0, 1, 0, 1, 0, 1, 0, 1 },
1345 { -1, 1, 0, 1, 0, 1, 0, 1 },
1346 { 0, 1, 0, 1, -1, 1, 0, 1 },
1350 case OMAP_DSS_ROT_0:
1353 case OMAP_DSS_ROT_90:
1356 case OMAP_DSS_ROT_180:
1359 case OMAP_DSS_ROT_270:
1367 switch (color_mode) {
1368 case OMAP_DSS_COLOR_NV12:
1370 accu_table = accu_nv12_ilace;
1372 accu_table = accu_nv12;
1374 case OMAP_DSS_COLOR_YUV2:
1375 case OMAP_DSS_COLOR_UYVY:
1376 accu_table = accu_yuv;
1383 accu_val = &accu_table[idx];
1385 chroma_hinc = 1024 * orig_width / out_width;
1386 chroma_vinc = 1024 * orig_height / out_height;
1388 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1389 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1390 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1391 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1393 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1394 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1397 static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1398 u16 orig_width, u16 orig_height,
1399 u16 out_width, u16 out_height,
1400 bool ilace, bool five_taps,
1401 bool fieldmode, enum omap_color_mode color_mode,
1408 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1409 out_width, out_height, five_taps,
1410 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1411 l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
1413 /* RESIZEENABLE and VERTICALTAPS */
1414 l &= ~((0x3 << 5) | (0x1 << 21));
1415 l |= (orig_width != out_width) ? (1 << 5) : 0;
1416 l |= (orig_height != out_height) ? (1 << 6) : 0;
1417 l |= five_taps ? (1 << 21) : 0;
1419 /* VRESIZECONF and HRESIZECONF */
1420 if (dss_has_feature(FEAT_RESIZECONF)) {
1422 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1423 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1426 /* LINEBUFFERSPLIT */
1427 if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) {
1429 l |= five_taps ? (1 << 22) : 0;
1432 dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l);
1435 * field 0 = even field = bottom field
1436 * field 1 = odd field = top field
1438 if (ilace && !fieldmode) {
1440 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1441 if (accu0 >= 1024/2) {
1447 dispc_ovl_set_vid_accu0(plane, 0, accu0);
1448 dispc_ovl_set_vid_accu1(plane, 0, accu1);
1451 static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1452 u16 orig_width, u16 orig_height,
1453 u16 out_width, u16 out_height,
1454 bool ilace, bool five_taps,
1455 bool fieldmode, enum omap_color_mode color_mode,
1458 int scale_x = out_width != orig_width;
1459 int scale_y = out_height != orig_height;
1461 if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE))
1463 if ((color_mode != OMAP_DSS_COLOR_YUV2 &&
1464 color_mode != OMAP_DSS_COLOR_UYVY &&
1465 color_mode != OMAP_DSS_COLOR_NV12)) {
1466 /* reset chroma resampling for RGB formats */
1467 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1471 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1472 out_height, ilace, color_mode, rotation);
1474 switch (color_mode) {
1475 case OMAP_DSS_COLOR_NV12:
1476 /* UV is subsampled by 2 vertically*/
1478 /* UV is subsampled by 2 horz.*/
1481 case OMAP_DSS_COLOR_YUV2:
1482 case OMAP_DSS_COLOR_UYVY:
1483 /*For YUV422 with 90/270 rotation,
1484 *we don't upsample chroma
1486 if (rotation == OMAP_DSS_ROT_0 ||
1487 rotation == OMAP_DSS_ROT_180)
1488 /* UV is subsampled by 2 hrz*/
1490 /* must use FIR for YUV422 if rotated */
1491 if (rotation != OMAP_DSS_ROT_0)
1492 scale_x = scale_y = true;
1499 if (out_width != orig_width)
1501 if (out_height != orig_height)
1504 dispc_ovl_set_scale_param(plane, orig_width, orig_height,
1505 out_width, out_height, five_taps,
1506 rotation, DISPC_COLOR_COMPONENT_UV);
1508 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane),
1509 (scale_x || scale_y) ? 1 : 0, 8, 8);
1511 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1513 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1516 static void dispc_ovl_set_scaling(enum omap_plane plane,
1517 u16 orig_width, u16 orig_height,
1518 u16 out_width, u16 out_height,
1519 bool ilace, bool five_taps,
1520 bool fieldmode, enum omap_color_mode color_mode,
1523 BUG_ON(plane == OMAP_DSS_GFX);
1525 dispc_ovl_set_scaling_common(plane,
1526 orig_width, orig_height,
1527 out_width, out_height,
1529 fieldmode, color_mode,
1532 dispc_ovl_set_scaling_uv(plane,
1533 orig_width, orig_height,
1534 out_width, out_height,
1536 fieldmode, color_mode,
1540 static void dispc_ovl_set_rotation_attrs(enum omap_plane plane, u8 rotation,
1541 bool mirroring, enum omap_color_mode color_mode)
1543 bool row_repeat = false;
1546 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1547 color_mode == OMAP_DSS_COLOR_UYVY) {
1551 case OMAP_DSS_ROT_0:
1554 case OMAP_DSS_ROT_90:
1557 case OMAP_DSS_ROT_180:
1560 case OMAP_DSS_ROT_270:
1566 case OMAP_DSS_ROT_0:
1569 case OMAP_DSS_ROT_90:
1572 case OMAP_DSS_ROT_180:
1575 case OMAP_DSS_ROT_270:
1581 if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270)
1587 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
1588 if (dss_has_feature(FEAT_ROWREPEATENABLE))
1589 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane),
1590 row_repeat ? 1 : 0, 18, 18);
1593 static int color_mode_to_bpp(enum omap_color_mode color_mode)
1595 switch (color_mode) {
1596 case OMAP_DSS_COLOR_CLUT1:
1598 case OMAP_DSS_COLOR_CLUT2:
1600 case OMAP_DSS_COLOR_CLUT4:
1602 case OMAP_DSS_COLOR_CLUT8:
1603 case OMAP_DSS_COLOR_NV12:
1605 case OMAP_DSS_COLOR_RGB12U:
1606 case OMAP_DSS_COLOR_RGB16:
1607 case OMAP_DSS_COLOR_ARGB16:
1608 case OMAP_DSS_COLOR_YUV2:
1609 case OMAP_DSS_COLOR_UYVY:
1610 case OMAP_DSS_COLOR_RGBA16:
1611 case OMAP_DSS_COLOR_RGBX16:
1612 case OMAP_DSS_COLOR_ARGB16_1555:
1613 case OMAP_DSS_COLOR_XRGB16_1555:
1615 case OMAP_DSS_COLOR_RGB24P:
1617 case OMAP_DSS_COLOR_RGB24U:
1618 case OMAP_DSS_COLOR_ARGB32:
1619 case OMAP_DSS_COLOR_RGBA32:
1620 case OMAP_DSS_COLOR_RGBX32:
1628 static s32 pixinc(int pixels, u8 ps)
1632 else if (pixels > 1)
1633 return 1 + (pixels - 1) * ps;
1634 else if (pixels < 0)
1635 return 1 - (-pixels + 1) * ps;
1641 static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1643 u16 width, u16 height,
1644 enum omap_color_mode color_mode, bool fieldmode,
1645 unsigned int field_offset,
1646 unsigned *offset0, unsigned *offset1,
1647 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1651 /* FIXME CLUT formats */
1652 switch (color_mode) {
1653 case OMAP_DSS_COLOR_CLUT1:
1654 case OMAP_DSS_COLOR_CLUT2:
1655 case OMAP_DSS_COLOR_CLUT4:
1656 case OMAP_DSS_COLOR_CLUT8:
1659 case OMAP_DSS_COLOR_YUV2:
1660 case OMAP_DSS_COLOR_UYVY:
1664 ps = color_mode_to_bpp(color_mode) / 8;
1668 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1672 * field 0 = even field = bottom field
1673 * field 1 = odd field = top field
1675 switch (rotation + mirror * 4) {
1676 case OMAP_DSS_ROT_0:
1677 case OMAP_DSS_ROT_180:
1679 * If the pixel format is YUV or UYVY divide the width
1680 * of the image by 2 for 0 and 180 degree rotation.
1682 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1683 color_mode == OMAP_DSS_COLOR_UYVY)
1685 case OMAP_DSS_ROT_90:
1686 case OMAP_DSS_ROT_270:
1689 *offset0 = field_offset * screen_width * ps;
1693 *row_inc = pixinc(1 +
1694 (y_predecim * screen_width - x_predecim * width) +
1695 (fieldmode ? screen_width : 0), ps);
1696 *pix_inc = pixinc(x_predecim, ps);
1699 case OMAP_DSS_ROT_0 + 4:
1700 case OMAP_DSS_ROT_180 + 4:
1701 /* If the pixel format is YUV or UYVY divide the width
1702 * of the image by 2 for 0 degree and 180 degree
1704 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1705 color_mode == OMAP_DSS_COLOR_UYVY)
1707 case OMAP_DSS_ROT_90 + 4:
1708 case OMAP_DSS_ROT_270 + 4:
1711 *offset0 = field_offset * screen_width * ps;
1714 *row_inc = pixinc(1 -
1715 (y_predecim * screen_width + x_predecim * width) -
1716 (fieldmode ? screen_width : 0), ps);
1717 *pix_inc = pixinc(x_predecim, ps);
1726 static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1728 u16 width, u16 height,
1729 enum omap_color_mode color_mode, bool fieldmode,
1730 unsigned int field_offset,
1731 unsigned *offset0, unsigned *offset1,
1732 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1737 /* FIXME CLUT formats */
1738 switch (color_mode) {
1739 case OMAP_DSS_COLOR_CLUT1:
1740 case OMAP_DSS_COLOR_CLUT2:
1741 case OMAP_DSS_COLOR_CLUT4:
1742 case OMAP_DSS_COLOR_CLUT8:
1746 ps = color_mode_to_bpp(color_mode) / 8;
1750 DSSDBG("calc_rot(%d): scrw %d, %dx%d\n", rotation, screen_width,
1753 /* width & height are overlay sizes, convert to fb sizes */
1755 if (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180) {
1764 * field 0 = even field = bottom field
1765 * field 1 = odd field = top field
1767 switch (rotation + mirror * 4) {
1768 case OMAP_DSS_ROT_0:
1771 *offset0 = *offset1 + field_offset * screen_width * ps;
1773 *offset0 = *offset1;
1774 *row_inc = pixinc(1 +
1775 (y_predecim * screen_width - fbw * x_predecim) +
1776 (fieldmode ? screen_width : 0), ps);
1777 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1778 color_mode == OMAP_DSS_COLOR_UYVY)
1779 *pix_inc = pixinc(x_predecim, 2 * ps);
1781 *pix_inc = pixinc(x_predecim, ps);
1783 case OMAP_DSS_ROT_90:
1784 *offset1 = screen_width * (fbh - 1) * ps;
1786 *offset0 = *offset1 + field_offset * ps;
1788 *offset0 = *offset1;
1789 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1790 y_predecim + (fieldmode ? 1 : 0), ps);
1791 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1793 case OMAP_DSS_ROT_180:
1794 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
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_270:
1809 *offset1 = (fbw - 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);
1820 case OMAP_DSS_ROT_0 + 4:
1821 *offset1 = (fbw - 1) * ps;
1823 *offset0 = *offset1 + field_offset * screen_width * ps;
1825 *offset0 = *offset1;
1826 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
1827 (fieldmode ? screen_width : 0),
1829 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1830 color_mode == OMAP_DSS_COLOR_UYVY)
1831 *pix_inc = pixinc(-x_predecim, 2 * ps);
1833 *pix_inc = pixinc(-x_predecim, ps);
1836 case OMAP_DSS_ROT_90 + 4:
1839 *offset0 = *offset1 + field_offset * ps;
1841 *offset0 = *offset1;
1842 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1843 y_predecim + (fieldmode ? 1 : 0),
1845 *pix_inc = pixinc(x_predecim * screen_width, ps);
1848 case OMAP_DSS_ROT_180 + 4:
1849 *offset1 = screen_width * (fbh - 1) * ps;
1851 *offset0 = *offset1 - field_offset * screen_width * ps;
1853 *offset0 = *offset1;
1854 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
1855 (fieldmode ? screen_width : 0),
1857 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1858 color_mode == OMAP_DSS_COLOR_UYVY)
1859 *pix_inc = pixinc(x_predecim, 2 * ps);
1861 *pix_inc = pixinc(x_predecim, ps);
1864 case OMAP_DSS_ROT_270 + 4:
1865 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
1867 *offset0 = *offset1 - field_offset * ps;
1869 *offset0 = *offset1;
1870 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1871 y_predecim - (fieldmode ? 1 : 0),
1873 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1882 static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1883 enum omap_color_mode color_mode, bool fieldmode,
1884 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1885 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1889 switch (color_mode) {
1890 case OMAP_DSS_COLOR_CLUT1:
1891 case OMAP_DSS_COLOR_CLUT2:
1892 case OMAP_DSS_COLOR_CLUT4:
1893 case OMAP_DSS_COLOR_CLUT8:
1897 ps = color_mode_to_bpp(color_mode) / 8;
1901 DSSDBG("scrw %d, width %d\n", screen_width, width);
1904 * field 0 = even field = bottom field
1905 * field 1 = odd field = top field
1909 *offset0 = *offset1 + field_offset * screen_width * ps;
1911 *offset0 = *offset1;
1912 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1913 (fieldmode ? screen_width : 0), ps);
1914 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1915 color_mode == OMAP_DSS_COLOR_UYVY)
1916 *pix_inc = pixinc(x_predecim, 2 * ps);
1918 *pix_inc = pixinc(x_predecim, ps);
1922 * This function is used to avoid synclosts in OMAP3, because of some
1923 * undocumented horizontal position and timing related limitations.
1925 static int check_horiz_timing_omap3(enum omap_plane plane,
1926 const struct omap_video_timings *t, u16 pos_x,
1927 u16 width, u16 height, u16 out_width, u16 out_height)
1929 int DS = DIV_ROUND_UP(height, out_height);
1930 unsigned long nonactive;
1931 static const u8 limits[3] = { 8, 10, 20 };
1933 unsigned long pclk = dispc_plane_pclk_rate(plane);
1934 unsigned long lclk = dispc_plane_lclk_rate(plane);
1937 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
1940 if (out_height < height)
1942 if (out_width < width)
1944 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
1945 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
1946 if (blank <= limits[i])
1950 * Pixel data should be prepared before visible display point starts.
1951 * So, atleast DS-2 lines must have already been fetched by DISPC
1952 * during nonactive - pos_x period.
1954 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
1955 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
1956 val, max(0, DS - 2) * width);
1957 if (val < max(0, DS - 2) * width)
1961 * All lines need to be refilled during the nonactive period of which
1962 * only one line can be loaded during the active period. So, atleast
1963 * DS - 1 lines should be loaded during nonactive period.
1965 val = div_u64((u64)nonactive * lclk, pclk);
1966 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
1967 val, max(0, DS - 1) * width);
1968 if (val < max(0, DS - 1) * width)
1974 static unsigned long calc_core_clk_five_taps(enum omap_plane plane,
1975 const struct omap_video_timings *mgr_timings, u16 width,
1976 u16 height, u16 out_width, u16 out_height,
1977 enum omap_color_mode color_mode)
1981 unsigned long pclk = dispc_plane_pclk_rate(plane);
1983 if (height <= out_height && width <= out_width)
1984 return (unsigned long) pclk;
1986 if (height > out_height) {
1987 unsigned int ppl = mgr_timings->x_res;
1989 tmp = pclk * height * out_width;
1990 do_div(tmp, 2 * out_height * ppl);
1993 if (height > 2 * out_height) {
1994 if (ppl == out_width)
1997 tmp = pclk * (height - 2 * out_height) * out_width;
1998 do_div(tmp, 2 * out_height * (ppl - out_width));
1999 core_clk = max_t(u32, core_clk, tmp);
2003 if (width > out_width) {
2005 do_div(tmp, out_width);
2006 core_clk = max_t(u32, core_clk, tmp);
2008 if (color_mode == OMAP_DSS_COLOR_RGB24U)
2015 static unsigned long calc_core_clk_24xx(enum omap_plane plane, u16 width,
2016 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2018 unsigned long pclk = dispc_plane_pclk_rate(plane);
2020 if (height > out_height && width > out_width)
2026 static unsigned long calc_core_clk_34xx(enum omap_plane plane, u16 width,
2027 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2029 unsigned int hf, vf;
2030 unsigned long pclk = dispc_plane_pclk_rate(plane);
2033 * FIXME how to determine the 'A' factor
2034 * for the no downscaling case ?
2037 if (width > 3 * out_width)
2039 else if (width > 2 * out_width)
2041 else if (width > out_width)
2045 if (height > out_height)
2050 return pclk * vf * hf;
2053 static unsigned long calc_core_clk_44xx(enum omap_plane plane, u16 width,
2054 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2059 * If the overlay/writeback is in mem to mem mode, there are no
2060 * downscaling limitations with respect to pixel clock, return 1 as
2061 * required core clock to represent that we have sufficient enough
2062 * core clock to do maximum downscaling
2067 pclk = dispc_plane_pclk_rate(plane);
2069 if (width > out_width)
2070 return DIV_ROUND_UP(pclk, out_width) * width;
2075 static int dispc_ovl_calc_scaling_24xx(enum omap_plane plane,
2076 const struct omap_video_timings *mgr_timings,
2077 u16 width, u16 height, u16 out_width, u16 out_height,
2078 enum omap_color_mode color_mode, bool *five_taps,
2079 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2080 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2083 u16 in_width, in_height;
2084 int min_factor = min(*decim_x, *decim_y);
2085 const int maxsinglelinewidth =
2086 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2091 in_height = DIV_ROUND_UP(height, *decim_y);
2092 in_width = DIV_ROUND_UP(width, *decim_x);
2093 *core_clk = dispc.feat->calc_core_clk(plane, in_width,
2094 in_height, out_width, out_height, mem_to_mem);
2095 error = (in_width > maxsinglelinewidth || !*core_clk ||
2096 *core_clk > dispc_core_clk_rate());
2098 if (*decim_x == *decim_y) {
2099 *decim_x = min_factor;
2102 swap(*decim_x, *decim_y);
2103 if (*decim_x < *decim_y)
2107 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2109 if (in_width > maxsinglelinewidth) {
2110 DSSERR("Cannot scale max input width exceeded");
2116 static int dispc_ovl_calc_scaling_34xx(enum omap_plane plane,
2117 const struct omap_video_timings *mgr_timings,
2118 u16 width, u16 height, u16 out_width, u16 out_height,
2119 enum omap_color_mode color_mode, bool *five_taps,
2120 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2121 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2124 u16 in_width, in_height;
2125 int min_factor = min(*decim_x, *decim_y);
2126 const int maxsinglelinewidth =
2127 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2130 in_height = DIV_ROUND_UP(height, *decim_y);
2131 in_width = DIV_ROUND_UP(width, *decim_x);
2132 *core_clk = calc_core_clk_five_taps(plane, mgr_timings,
2133 in_width, in_height, out_width, out_height, color_mode);
2135 error = check_horiz_timing_omap3(plane, mgr_timings,
2136 pos_x, in_width, in_height, out_width,
2139 if (in_width > maxsinglelinewidth)
2140 if (in_height > out_height &&
2141 in_height < out_height * 2)
2144 *core_clk = dispc.feat->calc_core_clk(plane, in_width,
2145 in_height, out_width, out_height,
2148 error = (error || in_width > maxsinglelinewidth * 2 ||
2149 (in_width > maxsinglelinewidth && *five_taps) ||
2150 !*core_clk || *core_clk > dispc_core_clk_rate());
2152 if (*decim_x == *decim_y) {
2153 *decim_x = min_factor;
2156 swap(*decim_x, *decim_y);
2157 if (*decim_x < *decim_y)
2161 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2163 if (check_horiz_timing_omap3(plane, mgr_timings, pos_x, width, height,
2164 out_width, out_height)){
2165 DSSERR("horizontal timing too tight\n");
2169 if (in_width > (maxsinglelinewidth * 2)) {
2170 DSSERR("Cannot setup scaling");
2171 DSSERR("width exceeds maximum width possible");
2175 if (in_width > maxsinglelinewidth && *five_taps) {
2176 DSSERR("cannot setup scaling with five taps");
2182 static int dispc_ovl_calc_scaling_44xx(enum omap_plane plane,
2183 const struct omap_video_timings *mgr_timings,
2184 u16 width, u16 height, u16 out_width, u16 out_height,
2185 enum omap_color_mode color_mode, bool *five_taps,
2186 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
2187 u16 pos_x, unsigned long *core_clk, bool mem_to_mem)
2189 u16 in_width, in_width_max;
2190 int decim_x_min = *decim_x;
2191 u16 in_height = DIV_ROUND_UP(height, *decim_y);
2192 const int maxsinglelinewidth =
2193 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
2194 unsigned long pclk = dispc_plane_pclk_rate(plane);
2195 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2198 in_width_max = DIV_ROUND_UP(out_width, maxdownscale);
2200 in_width_max = dispc_core_clk_rate() /
2201 DIV_ROUND_UP(pclk, out_width);
2203 *decim_x = DIV_ROUND_UP(width, in_width_max);
2205 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2206 if (*decim_x > *x_predecim)
2210 in_width = DIV_ROUND_UP(width, *decim_x);
2211 } while (*decim_x <= *x_predecim &&
2212 in_width > maxsinglelinewidth && ++*decim_x);
2214 if (in_width > maxsinglelinewidth) {
2215 DSSERR("Cannot scale width exceeds max line width");
2219 *core_clk = dispc.feat->calc_core_clk(plane, in_width, in_height,
2220 out_width, out_height, mem_to_mem);
2224 static int dispc_ovl_calc_scaling(enum omap_plane plane,
2225 enum omap_overlay_caps caps,
2226 const struct omap_video_timings *mgr_timings,
2227 u16 width, u16 height, u16 out_width, u16 out_height,
2228 enum omap_color_mode color_mode, bool *five_taps,
2229 int *x_predecim, int *y_predecim, u16 pos_x,
2230 enum omap_dss_rotation_type rotation_type, bool mem_to_mem)
2232 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
2233 const int max_decim_limit = 16;
2234 unsigned long core_clk = 0;
2235 int decim_x, decim_y, ret;
2237 if (width == out_width && height == out_height)
2240 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
2243 *x_predecim = max_decim_limit;
2244 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2245 dss_has_feature(FEAT_BURST_2D)) ? 2 : max_decim_limit;
2247 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
2248 color_mode == OMAP_DSS_COLOR_CLUT2 ||
2249 color_mode == OMAP_DSS_COLOR_CLUT4 ||
2250 color_mode == OMAP_DSS_COLOR_CLUT8) {
2257 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
2258 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
2260 if (decim_x > *x_predecim || out_width > width * 8)
2263 if (decim_y > *y_predecim || out_height > height * 8)
2266 ret = dispc.feat->calc_scaling(plane, mgr_timings, width, height,
2267 out_width, out_height, color_mode, five_taps,
2268 x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk,
2273 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
2274 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
2276 if (!core_clk || core_clk > dispc_core_clk_rate()) {
2277 DSSERR("failed to set up scaling, "
2278 "required core clk rate = %lu Hz, "
2279 "current core clk rate = %lu Hz\n",
2280 core_clk, dispc_core_clk_rate());
2284 *x_predecim = decim_x;
2285 *y_predecim = decim_y;
2289 static int dispc_ovl_setup_common(enum omap_plane plane,
2290 enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr,
2291 u16 screen_width, int pos_x, int pos_y, u16 width, u16 height,
2292 u16 out_width, u16 out_height, enum omap_color_mode color_mode,
2293 u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha,
2294 u8 global_alpha, enum omap_dss_rotation_type rotation_type,
2295 bool replication, const struct omap_video_timings *mgr_timings,
2298 bool five_taps = true;
2301 unsigned offset0, offset1;
2304 u16 frame_height = height;
2305 unsigned int field_offset = 0;
2306 u16 in_height = height;
2307 u16 in_width = width;
2308 int x_predecim = 1, y_predecim = 1;
2309 bool ilace = mgr_timings->interlace;
2314 out_width = out_width == 0 ? width : out_width;
2315 out_height = out_height == 0 ? height : out_height;
2317 if (ilace && height == out_height)
2326 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
2327 "out_height %d\n", in_height, pos_y,
2331 if (!dss_feat_color_mode_supported(plane, color_mode))
2334 r = dispc_ovl_calc_scaling(plane, caps, mgr_timings, in_width,
2335 in_height, out_width, out_height, color_mode,
2336 &five_taps, &x_predecim, &y_predecim, pos_x,
2337 rotation_type, mem_to_mem);
2341 in_width = DIV_ROUND_UP(in_width, x_predecim);
2342 in_height = DIV_ROUND_UP(in_height, y_predecim);
2344 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
2345 color_mode == OMAP_DSS_COLOR_UYVY ||
2346 color_mode == OMAP_DSS_COLOR_NV12)
2349 if (ilace && !fieldmode) {
2351 * when downscaling the bottom field may have to start several
2352 * source lines below the top field. Unfortunately ACCUI
2353 * registers will only hold the fractional part of the offset
2354 * so the integer part must be added to the base address of the
2357 if (!in_height || in_height == out_height)
2360 field_offset = in_height / out_height / 2;
2363 /* Fields are independent but interleaved in memory. */
2372 if (rotation_type == OMAP_DSS_ROT_TILER)
2373 calc_tiler_rotation_offset(screen_width, in_width,
2374 color_mode, fieldmode, field_offset,
2375 &offset0, &offset1, &row_inc, &pix_inc,
2376 x_predecim, y_predecim);
2377 else if (rotation_type == OMAP_DSS_ROT_DMA)
2378 calc_dma_rotation_offset(rotation, mirror,
2379 screen_width, in_width, frame_height,
2380 color_mode, fieldmode, field_offset,
2381 &offset0, &offset1, &row_inc, &pix_inc,
2382 x_predecim, y_predecim);
2384 calc_vrfb_rotation_offset(rotation, mirror,
2385 screen_width, in_width, frame_height,
2386 color_mode, fieldmode, field_offset,
2387 &offset0, &offset1, &row_inc, &pix_inc,
2388 x_predecim, y_predecim);
2390 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2391 offset0, offset1, row_inc, pix_inc);
2393 dispc_ovl_set_color_mode(plane, color_mode);
2395 dispc_ovl_configure_burst_type(plane, rotation_type);
2397 dispc_ovl_set_ba0(plane, paddr + offset0);
2398 dispc_ovl_set_ba1(plane, paddr + offset1);
2400 if (OMAP_DSS_COLOR_NV12 == color_mode) {
2401 dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0);
2402 dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1);
2405 dispc_ovl_set_row_inc(plane, row_inc);
2406 dispc_ovl_set_pix_inc(plane, pix_inc);
2408 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
2409 in_height, out_width, out_height);
2411 dispc_ovl_set_pos(plane, caps, pos_x, pos_y);
2413 dispc_ovl_set_input_size(plane, in_width, in_height);
2415 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
2416 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
2417 out_height, ilace, five_taps, fieldmode,
2418 color_mode, rotation);
2419 dispc_ovl_set_output_size(plane, out_width, out_height);
2420 dispc_ovl_set_vid_color_conv(plane, cconv);
2423 dispc_ovl_set_rotation_attrs(plane, rotation, mirror, color_mode);
2425 dispc_ovl_set_zorder(plane, caps, zorder);
2426 dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha);
2427 dispc_ovl_setup_global_alpha(plane, caps, global_alpha);
2429 dispc_ovl_enable_replication(plane, caps, replication);
2434 int dispc_ovl_setup(enum omap_plane plane, const struct omap_overlay_info *oi,
2435 bool replication, const struct omap_video_timings *mgr_timings,
2439 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
2440 enum omap_channel channel;
2442 channel = dispc_ovl_get_channel_out(plane);
2444 DSSDBG("dispc_ovl_setup %d, pa %x, pa_uv %x, sw %d, %d,%d, %dx%d -> "
2445 "%dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n",
2446 plane, oi->paddr, oi->p_uv_addr, oi->screen_width, oi->pos_x,
2447 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2448 oi->color_mode, oi->rotation, oi->mirror, channel, replication);
2450 r = dispc_ovl_setup_common(plane, ovl->caps, oi->paddr, oi->p_uv_addr,
2451 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2452 oi->out_width, oi->out_height, oi->color_mode, oi->rotation,
2453 oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
2454 oi->rotation_type, replication, mgr_timings, mem_to_mem);
2459 int dispc_ovl_enable(enum omap_plane plane, bool enable)
2461 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2463 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2468 static void dispc_disable_isr(void *data, u32 mask)
2470 struct completion *compl = data;
2474 static void _enable_lcd_out(enum omap_channel channel, bool enable)
2476 mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable);
2477 /* flush posted write */
2478 mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2481 static void dispc_mgr_enable_lcd_out(enum omap_channel channel, bool enable)
2483 struct completion frame_done_completion;
2488 /* When we disable LCD output, we need to wait until frame is done.
2489 * Otherwise the DSS is still working, and turning off the clocks
2490 * prevents DSS from going to OFF mode */
2491 is_on = mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2493 irq = mgr_desc[channel].framedone_irq;
2495 if (!enable && is_on) {
2496 init_completion(&frame_done_completion);
2498 r = omap_dispc_register_isr(dispc_disable_isr,
2499 &frame_done_completion, irq);
2502 DSSERR("failed to register FRAMEDONE isr\n");
2505 _enable_lcd_out(channel, enable);
2507 if (!enable && is_on) {
2508 if (!wait_for_completion_timeout(&frame_done_completion,
2509 msecs_to_jiffies(100)))
2510 DSSERR("timeout waiting for FRAME DONE\n");
2512 r = omap_dispc_unregister_isr(dispc_disable_isr,
2513 &frame_done_completion, irq);
2516 DSSERR("failed to unregister FRAMEDONE isr\n");
2520 static void _enable_digit_out(bool enable)
2522 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 1, 1);
2523 /* flush posted write */
2524 dispc_read_reg(DISPC_CONTROL);
2527 static void dispc_mgr_enable_digit_out(bool enable)
2529 struct completion frame_done_completion;
2530 enum dss_hdmi_venc_clk_source_select src;
2535 if (REG_GET(DISPC_CONTROL, 1, 1) == enable)
2538 src = dss_get_hdmi_venc_clk_source();
2541 unsigned long flags;
2542 /* When we enable digit output, we'll get an extra digit
2543 * sync lost interrupt, that we need to ignore */
2544 spin_lock_irqsave(&dispc.irq_lock, flags);
2545 dispc.irq_error_mask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
2546 _omap_dispc_set_irqs();
2547 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2550 /* When we disable digit output, we need to wait until fields are done.
2551 * Otherwise the DSS is still working, and turning off the clocks
2552 * prevents DSS from going to OFF mode. And when enabling, we need to
2553 * wait for the extra sync losts */
2554 init_completion(&frame_done_completion);
2556 if (src == DSS_HDMI_M_PCLK && enable == false) {
2557 irq_mask = DISPC_IRQ_FRAMEDONETV;
2560 irq_mask = DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
2561 /* XXX I understand from TRM that we should only wait for the
2562 * current field to complete. But it seems we have to wait for
2567 r = omap_dispc_register_isr(dispc_disable_isr, &frame_done_completion,
2570 DSSERR("failed to register %x isr\n", irq_mask);
2572 _enable_digit_out(enable);
2574 for (i = 0; i < num_irqs; ++i) {
2575 if (!wait_for_completion_timeout(&frame_done_completion,
2576 msecs_to_jiffies(100)))
2577 DSSERR("timeout waiting for digit out to %s\n",
2578 enable ? "start" : "stop");
2581 r = omap_dispc_unregister_isr(dispc_disable_isr, &frame_done_completion,
2584 DSSERR("failed to unregister %x isr\n", irq_mask);
2587 unsigned long flags;
2588 spin_lock_irqsave(&dispc.irq_lock, flags);
2589 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST_DIGIT;
2590 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
2591 _omap_dispc_set_irqs();
2592 spin_unlock_irqrestore(&dispc.irq_lock, flags);
2596 bool dispc_mgr_is_enabled(enum omap_channel channel)
2598 return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE);
2601 void dispc_mgr_enable(enum omap_channel channel, bool enable)
2603 if (dss_mgr_is_lcd(channel))
2604 dispc_mgr_enable_lcd_out(channel, enable);
2605 else if (channel == OMAP_DSS_CHANNEL_DIGIT)
2606 dispc_mgr_enable_digit_out(enable);
2611 void dispc_lcd_enable_signal_polarity(bool act_high)
2613 if (!dss_has_feature(FEAT_LCDENABLEPOL))
2616 REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2619 void dispc_lcd_enable_signal(bool enable)
2621 if (!dss_has_feature(FEAT_LCDENABLESIGNAL))
2624 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2627 void dispc_pck_free_enable(bool enable)
2629 if (!dss_has_feature(FEAT_PCKFREEENABLE))
2632 REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2635 void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable)
2637 mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
2641 void dispc_mgr_set_lcd_type_tft(enum omap_channel channel)
2643 mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1);
2646 void dispc_set_loadmode(enum omap_dss_load_mode mode)
2648 REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1);
2652 static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color)
2654 dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color);
2657 static void dispc_mgr_set_trans_key(enum omap_channel ch,
2658 enum omap_dss_trans_key_type type,
2661 mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type);
2663 dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key);
2666 static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable)
2668 mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable);
2671 static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch,
2674 if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
2677 if (ch == OMAP_DSS_CHANNEL_LCD)
2678 REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18);
2679 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2680 REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19);
2683 void dispc_mgr_setup(enum omap_channel channel,
2684 struct omap_overlay_manager_info *info)
2686 dispc_mgr_set_default_color(channel, info->default_color);
2687 dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key);
2688 dispc_mgr_enable_trans_key(channel, info->trans_enabled);
2689 dispc_mgr_enable_alpha_fixed_zorder(channel,
2690 info->partial_alpha_enabled);
2691 if (dss_has_feature(FEAT_CPR)) {
2692 dispc_mgr_enable_cpr(channel, info->cpr_enable);
2693 dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs);
2697 void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines)
2701 switch (data_lines) {
2719 mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code);
2722 void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode)
2728 case DSS_IO_PAD_MODE_RESET:
2732 case DSS_IO_PAD_MODE_RFBI:
2736 case DSS_IO_PAD_MODE_BYPASS:
2745 l = dispc_read_reg(DISPC_CONTROL);
2746 l = FLD_MOD(l, gpout0, 15, 15);
2747 l = FLD_MOD(l, gpout1, 16, 16);
2748 dispc_write_reg(DISPC_CONTROL, l);
2751 void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2753 mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable);
2756 static bool _dispc_mgr_size_ok(u16 width, u16 height)
2758 return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
2759 height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
2762 static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2763 int vsw, int vfp, int vbp)
2765 if (hsw < 1 || hsw > dispc.feat->sw_max ||
2766 hfp < 1 || hfp > dispc.feat->hp_max ||
2767 hbp < 1 || hbp > dispc.feat->hp_max ||
2768 vsw < 1 || vsw > dispc.feat->sw_max ||
2769 vfp < 0 || vfp > dispc.feat->vp_max ||
2770 vbp < 0 || vbp > dispc.feat->vp_max)
2775 bool dispc_mgr_timings_ok(enum omap_channel channel,
2776 const struct omap_video_timings *timings)
2780 timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
2782 if (dss_mgr_is_lcd(channel))
2783 timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
2784 timings->hfp, timings->hbp,
2785 timings->vsw, timings->vfp,
2791 static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
2792 int hfp, int hbp, int vsw, int vfp, int vbp,
2793 enum omap_dss_signal_level vsync_level,
2794 enum omap_dss_signal_level hsync_level,
2795 enum omap_dss_signal_edge data_pclk_edge,
2796 enum omap_dss_signal_level de_level,
2797 enum omap_dss_signal_edge sync_pclk_edge)
2800 u32 timing_h, timing_v, l;
2801 bool onoff, rf, ipc;
2803 timing_h = FLD_VAL(hsw-1, dispc.feat->sw_start, 0) |
2804 FLD_VAL(hfp-1, dispc.feat->fp_start, 8) |
2805 FLD_VAL(hbp-1, dispc.feat->bp_start, 20);
2806 timing_v = FLD_VAL(vsw-1, dispc.feat->sw_start, 0) |
2807 FLD_VAL(vfp, dispc.feat->fp_start, 8) |
2808 FLD_VAL(vbp, dispc.feat->bp_start, 20);
2810 dispc_write_reg(DISPC_TIMING_H(channel), timing_h);
2811 dispc_write_reg(DISPC_TIMING_V(channel), timing_v);
2813 switch (data_pclk_edge) {
2814 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2817 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2820 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2825 switch (sync_pclk_edge) {
2826 case OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES:
2830 case OMAPDSS_DRIVE_SIG_FALLING_EDGE:
2834 case OMAPDSS_DRIVE_SIG_RISING_EDGE:
2842 l = dispc_read_reg(DISPC_POL_FREQ(channel));
2843 l |= FLD_VAL(onoff, 17, 17);
2844 l |= FLD_VAL(rf, 16, 16);
2845 l |= FLD_VAL(de_level, 15, 15);
2846 l |= FLD_VAL(ipc, 14, 14);
2847 l |= FLD_VAL(hsync_level, 13, 13);
2848 l |= FLD_VAL(vsync_level, 12, 12);
2849 dispc_write_reg(DISPC_POL_FREQ(channel), l);
2852 /* change name to mode? */
2853 void dispc_mgr_set_timings(enum omap_channel channel,
2854 struct omap_video_timings *timings)
2856 unsigned xtot, ytot;
2857 unsigned long ht, vt;
2858 struct omap_video_timings t = *timings;
2860 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
2862 if (!dispc_mgr_timings_ok(channel, &t)) {
2867 if (dss_mgr_is_lcd(channel)) {
2868 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
2869 t.vfp, t.vbp, t.vsync_level, t.hsync_level,
2870 t.data_pclk_edge, t.de_level, t.sync_pclk_edge);
2872 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
2873 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
2875 ht = (timings->pixel_clock * 1000) / xtot;
2876 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2878 DSSDBG("pck %u\n", timings->pixel_clock);
2879 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2880 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
2881 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
2882 t.vsync_level, t.hsync_level, t.data_pclk_edge,
2883 t.de_level, t.sync_pclk_edge);
2885 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2887 if (t.interlace == true)
2891 dispc_mgr_set_size(channel, t.x_res, t.y_res);
2894 static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
2897 BUG_ON(lck_div < 1);
2898 BUG_ON(pck_div < 1);
2900 dispc_write_reg(DISPC_DIVISORo(channel),
2901 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
2904 static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div,
2908 l = dispc_read_reg(DISPC_DIVISORo(channel));
2909 *lck_div = FLD_GET(l, 23, 16);
2910 *pck_div = FLD_GET(l, 7, 0);
2913 unsigned long dispc_fclk_rate(void)
2915 struct platform_device *dsidev;
2916 unsigned long r = 0;
2918 switch (dss_get_dispc_clk_source()) {
2919 case OMAP_DSS_CLK_SRC_FCK:
2920 r = clk_get_rate(dispc.dss_clk);
2922 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2923 dsidev = dsi_get_dsidev_from_id(0);
2924 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2926 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2927 dsidev = dsi_get_dsidev_from_id(1);
2928 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2938 unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
2940 struct platform_device *dsidev;
2945 l = dispc_read_reg(DISPC_DIVISORo(channel));
2947 lcd = FLD_GET(l, 23, 16);
2949 switch (dss_get_lcd_clk_source(channel)) {
2950 case OMAP_DSS_CLK_SRC_FCK:
2951 r = clk_get_rate(dispc.dss_clk);
2953 case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC:
2954 dsidev = dsi_get_dsidev_from_id(0);
2955 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2957 case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC:
2958 dsidev = dsi_get_dsidev_from_id(1);
2959 r = dsi_get_pll_hsdiv_dispc_rate(dsidev);
2969 unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
2973 if (dss_mgr_is_lcd(channel)) {
2977 l = dispc_read_reg(DISPC_DIVISORo(channel));
2979 pcd = FLD_GET(l, 7, 0);
2981 r = dispc_mgr_lclk_rate(channel);
2985 enum dss_hdmi_venc_clk_source_select source;
2987 source = dss_get_hdmi_venc_clk_source();
2990 case DSS_VENC_TV_CLK:
2991 return venc_get_pixel_clock();
2992 case DSS_HDMI_M_PCLK:
2993 return hdmi_get_pixel_clock();
3001 unsigned long dispc_core_clk_rate(void)
3004 unsigned long fclk = dispc_fclk_rate();
3006 if (dss_has_feature(FEAT_CORE_CLK_DIV))
3007 lcd = REG_GET(DISPC_DIVISOR, 23, 16);
3009 lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
3014 static unsigned long dispc_plane_pclk_rate(enum omap_plane plane)
3016 enum omap_channel channel = dispc_ovl_get_channel_out(plane);
3018 return dispc_mgr_pclk_rate(channel);
3021 static unsigned long dispc_plane_lclk_rate(enum omap_plane plane)
3023 enum omap_channel channel = dispc_ovl_get_channel_out(plane);
3025 if (dss_mgr_is_lcd(channel))
3026 return dispc_mgr_lclk_rate(channel);
3028 return dispc_fclk_rate();
3031 static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel)
3034 enum omap_dss_clk_source lcd_clk_src;
3036 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3038 lcd_clk_src = dss_get_lcd_clk_source(channel);
3040 seq_printf(s, "%s clk source = %s (%s)\n", mgr_desc[channel].name,
3041 dss_get_generic_clk_source_name(lcd_clk_src),
3042 dss_feat_get_clk_source_name(lcd_clk_src));
3044 dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd);
3046 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3047 dispc_mgr_lclk_rate(channel), lcd);
3048 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3049 dispc_mgr_pclk_rate(channel), pcd);
3052 void dispc_dump_clocks(struct seq_file *s)
3056 enum omap_dss_clk_source dispc_clk_src = dss_get_dispc_clk_source();
3058 if (dispc_runtime_get())
3061 seq_printf(s, "- DISPC -\n");
3063 seq_printf(s, "dispc fclk source = %s (%s)\n",
3064 dss_get_generic_clk_source_name(dispc_clk_src),
3065 dss_feat_get_clk_source_name(dispc_clk_src));
3067 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate());
3069 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3070 seq_printf(s, "- DISPC-CORE-CLK -\n");
3071 l = dispc_read_reg(DISPC_DIVISOR);
3072 lcd = FLD_GET(l, 23, 16);
3074 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3075 (dispc_fclk_rate()/lcd), lcd);
3078 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD);
3080 if (dss_has_feature(FEAT_MGR_LCD2))
3081 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2);
3082 if (dss_has_feature(FEAT_MGR_LCD3))
3083 dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3);
3085 dispc_runtime_put();
3088 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3089 void dispc_dump_irqs(struct seq_file *s)
3091 unsigned long flags;
3092 struct dispc_irq_stats stats;
3094 spin_lock_irqsave(&dispc.irq_stats_lock, flags);
3096 stats = dispc.irq_stats;
3097 memset(&dispc.irq_stats, 0, sizeof(dispc.irq_stats));
3098 dispc.irq_stats.last_reset = jiffies;
3100 spin_unlock_irqrestore(&dispc.irq_stats_lock, flags);
3102 seq_printf(s, "period %u ms\n",
3103 jiffies_to_msecs(jiffies - stats.last_reset));
3105 seq_printf(s, "irqs %d\n", stats.irq_count);
3107 seq_printf(s, "%-20s %10d\n", #x, stats.irqs[ffs(DISPC_IRQ_##x)-1]);
3113 PIS(ACBIAS_COUNT_STAT);
3115 PIS(GFX_FIFO_UNDERFLOW);
3117 PIS(PAL_GAMMA_MASK);
3119 PIS(VID1_FIFO_UNDERFLOW);
3121 PIS(VID2_FIFO_UNDERFLOW);
3123 if (dss_feat_get_num_ovls() > 3) {
3124 PIS(VID3_FIFO_UNDERFLOW);
3128 PIS(SYNC_LOST_DIGIT);
3130 if (dss_has_feature(FEAT_MGR_LCD2)) {
3133 PIS(ACBIAS_COUNT_STAT2);
3136 if (dss_has_feature(FEAT_MGR_LCD3)) {
3139 PIS(ACBIAS_COUNT_STAT3);
3146 static void dispc_dump_regs(struct seq_file *s)
3149 const char *mgr_names[] = {
3150 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3151 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3152 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
3153 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
3155 const char *ovl_names[] = {
3156 [OMAP_DSS_GFX] = "GFX",
3157 [OMAP_DSS_VIDEO1] = "VID1",
3158 [OMAP_DSS_VIDEO2] = "VID2",
3159 [OMAP_DSS_VIDEO3] = "VID3",
3161 const char **p_names;
3163 #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r))
3165 if (dispc_runtime_get())
3168 /* DISPC common registers */
3169 DUMPREG(DISPC_REVISION);
3170 DUMPREG(DISPC_SYSCONFIG);
3171 DUMPREG(DISPC_SYSSTATUS);
3172 DUMPREG(DISPC_IRQSTATUS);
3173 DUMPREG(DISPC_IRQENABLE);
3174 DUMPREG(DISPC_CONTROL);
3175 DUMPREG(DISPC_CONFIG);
3176 DUMPREG(DISPC_CAPABLE);
3177 DUMPREG(DISPC_LINE_STATUS);
3178 DUMPREG(DISPC_LINE_NUMBER);
3179 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) ||
3180 dss_has_feature(FEAT_ALPHA_FREE_ZORDER))
3181 DUMPREG(DISPC_GLOBAL_ALPHA);
3182 if (dss_has_feature(FEAT_MGR_LCD2)) {
3183 DUMPREG(DISPC_CONTROL2);
3184 DUMPREG(DISPC_CONFIG2);
3186 if (dss_has_feature(FEAT_MGR_LCD3)) {
3187 DUMPREG(DISPC_CONTROL3);
3188 DUMPREG(DISPC_CONFIG3);
3193 #define DISPC_REG(i, name) name(i)
3194 #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3195 48 - strlen(#r) - strlen(p_names[i]), " ", \
3196 dispc_read_reg(DISPC_REG(i, r)))
3198 p_names = mgr_names;
3200 /* DISPC channel specific registers */
3201 for (i = 0; i < dss_feat_get_num_mgrs(); i++) {
3202 DUMPREG(i, DISPC_DEFAULT_COLOR);
3203 DUMPREG(i, DISPC_TRANS_COLOR);
3204 DUMPREG(i, DISPC_SIZE_MGR);
3206 if (i == OMAP_DSS_CHANNEL_DIGIT)
3209 DUMPREG(i, DISPC_DEFAULT_COLOR);
3210 DUMPREG(i, DISPC_TRANS_COLOR);
3211 DUMPREG(i, DISPC_TIMING_H);
3212 DUMPREG(i, DISPC_TIMING_V);
3213 DUMPREG(i, DISPC_POL_FREQ);
3214 DUMPREG(i, DISPC_DIVISORo);
3215 DUMPREG(i, DISPC_SIZE_MGR);
3217 DUMPREG(i, DISPC_DATA_CYCLE1);
3218 DUMPREG(i, DISPC_DATA_CYCLE2);
3219 DUMPREG(i, DISPC_DATA_CYCLE3);
3221 if (dss_has_feature(FEAT_CPR)) {
3222 DUMPREG(i, DISPC_CPR_COEF_R);
3223 DUMPREG(i, DISPC_CPR_COEF_G);
3224 DUMPREG(i, DISPC_CPR_COEF_B);
3228 p_names = ovl_names;
3230 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
3231 DUMPREG(i, DISPC_OVL_BA0);
3232 DUMPREG(i, DISPC_OVL_BA1);
3233 DUMPREG(i, DISPC_OVL_POSITION);
3234 DUMPREG(i, DISPC_OVL_SIZE);
3235 DUMPREG(i, DISPC_OVL_ATTRIBUTES);
3236 DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD);
3237 DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS);
3238 DUMPREG(i, DISPC_OVL_ROW_INC);
3239 DUMPREG(i, DISPC_OVL_PIXEL_INC);
3240 if (dss_has_feature(FEAT_PRELOAD))
3241 DUMPREG(i, DISPC_OVL_PRELOAD);
3243 if (i == OMAP_DSS_GFX) {
3244 DUMPREG(i, DISPC_OVL_WINDOW_SKIP);
3245 DUMPREG(i, DISPC_OVL_TABLE_BA);
3249 DUMPREG(i, DISPC_OVL_FIR);
3250 DUMPREG(i, DISPC_OVL_PICTURE_SIZE);
3251 DUMPREG(i, DISPC_OVL_ACCU0);
3252 DUMPREG(i, DISPC_OVL_ACCU1);
3253 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3254 DUMPREG(i, DISPC_OVL_BA0_UV);
3255 DUMPREG(i, DISPC_OVL_BA1_UV);
3256 DUMPREG(i, DISPC_OVL_FIR2);
3257 DUMPREG(i, DISPC_OVL_ACCU2_0);
3258 DUMPREG(i, DISPC_OVL_ACCU2_1);
3260 if (dss_has_feature(FEAT_ATTR2))
3261 DUMPREG(i, DISPC_OVL_ATTRIBUTES2);
3262 if (dss_has_feature(FEAT_PRELOAD))
3263 DUMPREG(i, DISPC_OVL_PRELOAD);
3269 #define DISPC_REG(plane, name, i) name(plane, i)
3270 #define DUMPREG(plane, name, i) \
3271 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3272 46 - strlen(#name) - strlen(p_names[plane]), " ", \
3273 dispc_read_reg(DISPC_REG(plane, name, i)))
3275 /* Video pipeline coefficient registers */
3277 /* start from OMAP_DSS_VIDEO1 */
3278 for (i = 1; i < dss_feat_get_num_ovls(); i++) {
3279 for (j = 0; j < 8; j++)
3280 DUMPREG(i, DISPC_OVL_FIR_COEF_H, j);
3282 for (j = 0; j < 8; j++)
3283 DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j);
3285 for (j = 0; j < 5; j++)
3286 DUMPREG(i, DISPC_OVL_CONV_COEF, j);
3288 if (dss_has_feature(FEAT_FIR_COEF_V)) {
3289 for (j = 0; j < 8; j++)
3290 DUMPREG(i, DISPC_OVL_FIR_COEF_V, j);
3293 if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) {
3294 for (j = 0; j < 8; j++)
3295 DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j);
3297 for (j = 0; j < 8; j++)
3298 DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j);
3300 for (j = 0; j < 8; j++)
3301 DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j);
3305 dispc_runtime_put();
3311 /* with fck as input clock rate, find dispc dividers that produce req_pck */
3312 void dispc_find_clk_divs(unsigned long req_pck, unsigned long fck,
3313 struct dispc_clock_info *cinfo)
3315 u16 pcd_min, pcd_max;
3316 unsigned long best_pck;
3317 u16 best_ld, cur_ld;
3318 u16 best_pd, cur_pd;
3320 pcd_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD);
3321 pcd_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD);
3327 for (cur_ld = 1; cur_ld <= 255; ++cur_ld) {
3328 unsigned long lck = fck / cur_ld;
3330 for (cur_pd = pcd_min; cur_pd <= pcd_max; ++cur_pd) {
3331 unsigned long pck = lck / cur_pd;
3332 long old_delta = abs(best_pck - req_pck);
3333 long new_delta = abs(pck - req_pck);
3335 if (best_pck == 0 || new_delta < old_delta) {
3348 if (lck / pcd_min < req_pck)
3353 cinfo->lck_div = best_ld;
3354 cinfo->pck_div = best_pd;
3355 cinfo->lck = fck / cinfo->lck_div;
3356 cinfo->pck = cinfo->lck / cinfo->pck_div;
3359 /* calculate clock rates using dividers in cinfo */
3360 int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
3361 struct dispc_clock_info *cinfo)
3363 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3365 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3368 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3369 cinfo->pck = cinfo->lck / cinfo->pck_div;
3374 void dispc_mgr_set_clock_div(enum omap_channel channel,
3375 struct dispc_clock_info *cinfo)
3377 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3378 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3380 dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div);
3383 int dispc_mgr_get_clock_div(enum omap_channel channel,
3384 struct dispc_clock_info *cinfo)
3388 fck = dispc_fclk_rate();
3390 cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16);
3391 cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0);
3393 cinfo->lck = fck / cinfo->lck_div;
3394 cinfo->pck = cinfo->lck / cinfo->pck_div;
3399 /* dispc.irq_lock has to be locked by the caller */
3400 static void _omap_dispc_set_irqs(void)
3405 struct omap_dispc_isr_data *isr_data;
3407 mask = dispc.irq_error_mask;
3409 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3410 isr_data = &dispc.registered_isr[i];
3412 if (isr_data->isr == NULL)
3415 mask |= isr_data->mask;
3418 old_mask = dispc_read_reg(DISPC_IRQENABLE);
3419 /* clear the irqstatus for newly enabled irqs */
3420 dispc_write_reg(DISPC_IRQSTATUS, (mask ^ old_mask) & mask);
3422 dispc_write_reg(DISPC_IRQENABLE, mask);
3425 int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3429 unsigned long flags;
3430 struct omap_dispc_isr_data *isr_data;
3435 spin_lock_irqsave(&dispc.irq_lock, flags);
3437 /* check for duplicate entry */
3438 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3439 isr_data = &dispc.registered_isr[i];
3440 if (isr_data->isr == isr && isr_data->arg == arg &&
3441 isr_data->mask == mask) {
3450 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3451 isr_data = &dispc.registered_isr[i];
3453 if (isr_data->isr != NULL)
3456 isr_data->isr = isr;
3457 isr_data->arg = arg;
3458 isr_data->mask = mask;
3467 _omap_dispc_set_irqs();
3469 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3473 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3477 EXPORT_SYMBOL(omap_dispc_register_isr);
3479 int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask)
3482 unsigned long flags;
3484 struct omap_dispc_isr_data *isr_data;
3486 spin_lock_irqsave(&dispc.irq_lock, flags);
3488 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3489 isr_data = &dispc.registered_isr[i];
3490 if (isr_data->isr != isr || isr_data->arg != arg ||
3491 isr_data->mask != mask)
3494 /* found the correct isr */
3496 isr_data->isr = NULL;
3497 isr_data->arg = NULL;
3505 _omap_dispc_set_irqs();
3507 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3511 EXPORT_SYMBOL(omap_dispc_unregister_isr);
3514 static void print_irq_status(u32 status)
3516 if ((status & dispc.irq_error_mask) == 0)
3519 printk(KERN_DEBUG "DISPC IRQ: 0x%x: ", status);
3522 if (status & DISPC_IRQ_##x) \
3524 PIS(GFX_FIFO_UNDERFLOW);
3526 PIS(VID1_FIFO_UNDERFLOW);
3527 PIS(VID2_FIFO_UNDERFLOW);
3528 if (dss_feat_get_num_ovls() > 3)
3529 PIS(VID3_FIFO_UNDERFLOW);
3531 PIS(SYNC_LOST_DIGIT);
3532 if (dss_has_feature(FEAT_MGR_LCD2))
3534 if (dss_has_feature(FEAT_MGR_LCD3))
3542 /* Called from dss.c. Note that we don't touch clocks here,
3543 * but we presume they are on because we got an IRQ. However,
3544 * an irq handler may turn the clocks off, so we may not have
3545 * clock later in the function. */
3546 static irqreturn_t omap_dispc_irq_handler(int irq, void *arg)
3549 u32 irqstatus, irqenable;
3550 u32 handledirqs = 0;
3551 u32 unhandled_errors;
3552 struct omap_dispc_isr_data *isr_data;
3553 struct omap_dispc_isr_data registered_isr[DISPC_MAX_NR_ISRS];
3555 spin_lock(&dispc.irq_lock);
3557 irqstatus = dispc_read_reg(DISPC_IRQSTATUS);
3558 irqenable = dispc_read_reg(DISPC_IRQENABLE);
3560 /* IRQ is not for us */
3561 if (!(irqstatus & irqenable)) {
3562 spin_unlock(&dispc.irq_lock);
3566 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3567 spin_lock(&dispc.irq_stats_lock);
3568 dispc.irq_stats.irq_count++;
3569 dss_collect_irq_stats(irqstatus, dispc.irq_stats.irqs);
3570 spin_unlock(&dispc.irq_stats_lock);
3575 print_irq_status(irqstatus);
3577 /* Ack the interrupt. Do it here before clocks are possibly turned
3579 dispc_write_reg(DISPC_IRQSTATUS, irqstatus);
3580 /* flush posted write */
3581 dispc_read_reg(DISPC_IRQSTATUS);
3583 /* make a copy and unlock, so that isrs can unregister
3585 memcpy(registered_isr, dispc.registered_isr,
3586 sizeof(registered_isr));
3588 spin_unlock(&dispc.irq_lock);
3590 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3591 isr_data = ®istered_isr[i];
3596 if (isr_data->mask & irqstatus) {
3597 isr_data->isr(isr_data->arg, irqstatus);
3598 handledirqs |= isr_data->mask;
3602 spin_lock(&dispc.irq_lock);
3604 unhandled_errors = irqstatus & ~handledirqs & dispc.irq_error_mask;
3606 if (unhandled_errors) {
3607 dispc.error_irqs |= unhandled_errors;
3609 dispc.irq_error_mask &= ~unhandled_errors;
3610 _omap_dispc_set_irqs();
3612 schedule_work(&dispc.error_work);
3615 spin_unlock(&dispc.irq_lock);
3620 static void dispc_error_worker(struct work_struct *work)
3624 unsigned long flags;
3625 static const unsigned fifo_underflow_bits[] = {
3626 DISPC_IRQ_GFX_FIFO_UNDERFLOW,
3627 DISPC_IRQ_VID1_FIFO_UNDERFLOW,
3628 DISPC_IRQ_VID2_FIFO_UNDERFLOW,
3629 DISPC_IRQ_VID3_FIFO_UNDERFLOW,
3632 spin_lock_irqsave(&dispc.irq_lock, flags);
3633 errors = dispc.error_irqs;
3634 dispc.error_irqs = 0;
3635 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3637 dispc_runtime_get();
3639 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3640 struct omap_overlay *ovl;
3643 ovl = omap_dss_get_overlay(i);
3644 bit = fifo_underflow_bits[i];
3647 DSSERR("FIFO UNDERFLOW on %s, disabling the overlay\n",
3649 dispc_ovl_enable(ovl->id, false);
3650 dispc_mgr_go(ovl->manager->id);
3655 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3656 struct omap_overlay_manager *mgr;
3659 mgr = omap_dss_get_overlay_manager(i);
3660 bit = mgr_desc[i].sync_lost_irq;
3663 struct omap_dss_device *dssdev = mgr->get_device(mgr);
3666 DSSERR("SYNC_LOST on channel %s, restarting the output "
3667 "with video overlays disabled\n",
3670 enable = dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
3671 dssdev->driver->disable(dssdev);
3673 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
3674 struct omap_overlay *ovl;
3675 ovl = omap_dss_get_overlay(i);
3677 if (ovl->id != OMAP_DSS_GFX &&
3678 ovl->manager == mgr)
3679 dispc_ovl_enable(ovl->id, false);
3682 dispc_mgr_go(mgr->id);
3686 dssdev->driver->enable(dssdev);
3690 if (errors & DISPC_IRQ_OCP_ERR) {
3691 DSSERR("OCP_ERR\n");
3692 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
3693 struct omap_overlay_manager *mgr;
3694 struct omap_dss_device *dssdev;
3696 mgr = omap_dss_get_overlay_manager(i);
3697 dssdev = mgr->get_device(mgr);
3699 if (dssdev && dssdev->driver)
3700 dssdev->driver->disable(dssdev);
3704 spin_lock_irqsave(&dispc.irq_lock, flags);
3705 dispc.irq_error_mask |= errors;
3706 _omap_dispc_set_irqs();
3707 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3709 dispc_runtime_put();
3712 int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout)
3714 void dispc_irq_wait_handler(void *data, u32 mask)
3716 complete((struct completion *)data);
3720 DECLARE_COMPLETION_ONSTACK(completion);
3722 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3728 timeout = wait_for_completion_timeout(&completion, timeout);
3730 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3735 if (timeout == -ERESTARTSYS)
3736 return -ERESTARTSYS;
3741 int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3742 unsigned long timeout)
3744 void dispc_irq_wait_handler(void *data, u32 mask)
3746 complete((struct completion *)data);
3750 DECLARE_COMPLETION_ONSTACK(completion);
3752 r = omap_dispc_register_isr(dispc_irq_wait_handler, &completion,
3758 timeout = wait_for_completion_interruptible_timeout(&completion,
3761 omap_dispc_unregister_isr(dispc_irq_wait_handler, &completion, irqmask);
3766 if (timeout == -ERESTARTSYS)
3767 return -ERESTARTSYS;
3772 static void _omap_dispc_initialize_irq(void)
3774 unsigned long flags;
3776 spin_lock_irqsave(&dispc.irq_lock, flags);
3778 memset(dispc.registered_isr, 0, sizeof(dispc.registered_isr));
3780 dispc.irq_error_mask = DISPC_IRQ_MASK_ERROR;
3781 if (dss_has_feature(FEAT_MGR_LCD2))
3782 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST2;
3783 if (dss_has_feature(FEAT_MGR_LCD3))
3784 dispc.irq_error_mask |= DISPC_IRQ_SYNC_LOST3;
3785 if (dss_feat_get_num_ovls() > 3)
3786 dispc.irq_error_mask |= DISPC_IRQ_VID3_FIFO_UNDERFLOW;
3788 /* there's SYNC_LOST_DIGIT waiting after enabling the DSS,
3790 dispc_write_reg(DISPC_IRQSTATUS, dispc_read_reg(DISPC_IRQSTATUS));
3792 _omap_dispc_set_irqs();
3794 spin_unlock_irqrestore(&dispc.irq_lock, flags);
3797 void dispc_enable_sidle(void)
3799 REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */
3802 void dispc_disable_sidle(void)
3804 REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3807 static void _omap_dispc_initial_config(void)
3811 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3812 if (dss_has_feature(FEAT_CORE_CLK_DIV)) {
3813 l = dispc_read_reg(DISPC_DIVISOR);
3814 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3815 l = FLD_MOD(l, 1, 0, 0);
3816 l = FLD_MOD(l, 1, 23, 16);
3817 dispc_write_reg(DISPC_DIVISOR, l);
3821 if (dss_has_feature(FEAT_FUNCGATED))
3822 REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9);
3824 _dispc_setup_color_conv_coef();
3826 dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY);
3830 dispc_configure_burst_sizes();
3832 dispc_ovl_enable_zorder_planes();
3835 static const struct dispc_features omap24xx_dispc_feats __initconst = {
3842 .calc_scaling = dispc_ovl_calc_scaling_24xx,
3843 .calc_core_clk = calc_core_clk_24xx,
3847 static const struct dispc_features omap34xx_rev1_0_dispc_feats __initconst = {
3854 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3855 .calc_core_clk = calc_core_clk_34xx,
3859 static const struct dispc_features omap34xx_rev3_0_dispc_feats __initconst = {
3866 .calc_scaling = dispc_ovl_calc_scaling_34xx,
3867 .calc_core_clk = calc_core_clk_34xx,
3871 static const struct dispc_features omap44xx_dispc_feats __initconst = {
3878 .calc_scaling = dispc_ovl_calc_scaling_44xx,
3879 .calc_core_clk = calc_core_clk_44xx,
3881 .gfx_fifo_workaround = true,
3884 static int __init dispc_init_features(struct device *dev)
3886 const struct dispc_features *src;
3887 struct dispc_features *dst;
3889 dst = devm_kzalloc(dev, sizeof(*dst), GFP_KERNEL);
3891 dev_err(dev, "Failed to allocate DISPC Features\n");
3895 if (cpu_is_omap24xx()) {
3896 src = &omap24xx_dispc_feats;
3897 } else if (cpu_is_omap34xx()) {
3898 if (omap_rev() < OMAP3430_REV_ES3_0)
3899 src = &omap34xx_rev1_0_dispc_feats;
3901 src = &omap34xx_rev3_0_dispc_feats;
3902 } else if (cpu_is_omap44xx()) {
3903 src = &omap44xx_dispc_feats;
3904 } else if (soc_is_omap54xx()) {
3905 src = &omap44xx_dispc_feats;
3910 memcpy(dst, src, sizeof(*dst));
3916 /* DISPC HW IP initialisation */
3917 static int __init omap_dispchw_probe(struct platform_device *pdev)
3921 struct resource *dispc_mem;
3926 r = dispc_init_features(&dispc.pdev->dev);
3930 spin_lock_init(&dispc.irq_lock);
3932 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3933 spin_lock_init(&dispc.irq_stats_lock);
3934 dispc.irq_stats.last_reset = jiffies;
3937 INIT_WORK(&dispc.error_work, dispc_error_worker);
3939 dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0);
3941 DSSERR("can't get IORESOURCE_MEM DISPC\n");
3945 dispc.base = devm_ioremap(&pdev->dev, dispc_mem->start,
3946 resource_size(dispc_mem));
3948 DSSERR("can't ioremap DISPC\n");
3952 dispc.irq = platform_get_irq(dispc.pdev, 0);
3953 if (dispc.irq < 0) {
3954 DSSERR("platform_get_irq failed\n");
3958 r = devm_request_irq(&pdev->dev, dispc.irq, omap_dispc_irq_handler,
3959 IRQF_SHARED, "OMAP DISPC", dispc.pdev);
3961 DSSERR("request_irq failed\n");
3965 clk = clk_get(&pdev->dev, "fck");
3967 DSSERR("can't get fck\n");
3972 dispc.dss_clk = clk;
3974 pm_runtime_enable(&pdev->dev);
3976 r = dispc_runtime_get();
3978 goto err_runtime_get;
3980 _omap_dispc_initial_config();
3982 _omap_dispc_initialize_irq();
3984 rev = dispc_read_reg(DISPC_REVISION);
3985 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
3986 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3988 dispc_runtime_put();
3990 dss_debugfs_create_file("dispc", dispc_dump_regs);
3992 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3993 dss_debugfs_create_file("dispc_irq", dispc_dump_irqs);
3998 pm_runtime_disable(&pdev->dev);
3999 clk_put(dispc.dss_clk);
4003 static int __exit omap_dispchw_remove(struct platform_device *pdev)
4005 pm_runtime_disable(&pdev->dev);
4007 clk_put(dispc.dss_clk);
4012 static int dispc_runtime_suspend(struct device *dev)
4014 dispc_save_context();
4019 static int dispc_runtime_resume(struct device *dev)
4021 dispc_restore_context();
4026 static const struct dev_pm_ops dispc_pm_ops = {
4027 .runtime_suspend = dispc_runtime_suspend,
4028 .runtime_resume = dispc_runtime_resume,
4031 static struct platform_driver omap_dispchw_driver = {
4032 .remove = __exit_p(omap_dispchw_remove),
4034 .name = "omapdss_dispc",
4035 .owner = THIS_MODULE,
4036 .pm = &dispc_pm_ops,
4040 int __init dispc_init_platform_driver(void)
4042 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
4045 void __exit dispc_uninit_platform_driver(void)
4047 platform_driver_unregister(&omap_dispchw_driver);