1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2009 Nokia Corporation
6 * Some code and ideas taken from drivers/video/omap/ driver
10 #define DSS_SUBSYS_NAME "DISPC"
12 #include <linux/kernel.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/vmalloc.h>
15 #include <linux/export.h>
16 #include <linux/clk.h>
18 #include <linux/jiffies.h>
19 #include <linux/seq_file.h>
20 #include <linux/delay.h>
21 #include <linux/workqueue.h>
22 #include <linux/hardirq.h>
23 #include <linux/platform_device.h>
24 #include <linux/pm_runtime.h>
25 #include <linux/sizes.h>
26 #include <linux/mfd/syscon.h>
27 #include <linux/regmap.h>
29 #include <linux/of_device.h>
30 #include <linux/component.h>
31 #include <linux/sys_soc.h>
32 #include <drm/drm_fourcc.h>
33 #include <drm/drm_blend.h>
42 #define DISPC_SZ_REGS SZ_4K
44 enum omap_burst_size {
50 #define REG_GET(dispc, idx, start, end) \
51 FLD_GET(dispc_read_reg(dispc, idx), start, end)
53 #define REG_FLD_MOD(dispc, idx, val, start, end) \
54 dispc_write_reg(dispc, idx, \
55 FLD_MOD(dispc_read_reg(dispc, idx), val, start, end))
57 /* DISPC has feature id */
58 enum dispc_feature_id {
68 /* Independent core clk divider */
70 FEAT_HANDLE_UV_SEPARATE,
75 FEAT_ALPHA_FIXED_ZORDER,
76 FEAT_ALPHA_FREE_ZORDER,
78 /* An unknown HW bug causing the normal FIFO thresholds not to work */
79 FEAT_OMAP3_DSI_FIFO_BUG,
84 struct dispc_features {
95 unsigned long max_lcd_pclk;
96 unsigned long max_tv_pclk;
97 unsigned int max_downscale;
98 unsigned int max_line_width;
100 int (*calc_scaling)(struct dispc_device *dispc,
101 unsigned long pclk, unsigned long lclk,
102 const struct videomode *vm,
103 u16 width, u16 height, u16 out_width, u16 out_height,
104 u32 fourcc, bool *five_taps,
105 int *x_predecim, int *y_predecim, int *decim_x, int *decim_y,
106 u16 pos_x, unsigned long *core_clk, bool mem_to_mem);
107 unsigned long (*calc_core_clk) (unsigned long pclk,
108 u16 width, u16 height, u16 out_width, u16 out_height,
111 const enum dispc_feature_id *features;
112 unsigned int num_features;
113 const struct dss_reg_field *reg_fields;
114 const unsigned int num_reg_fields;
115 const enum omap_overlay_caps *overlay_caps;
116 const u32 **supported_color_modes;
117 const u32 *supported_scaler_color_modes;
118 unsigned int num_mgrs;
119 unsigned int num_ovls;
120 unsigned int buffer_size_unit;
121 unsigned int burst_size_unit;
123 /* swap GFX & WB fifos */
124 bool gfx_fifo_workaround:1;
126 /* no DISPC_IRQ_FRAMEDONETV on this SoC */
127 bool no_framedone_tv:1;
129 /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
130 bool mstandby_workaround:1;
132 bool set_max_preload:1;
134 /* PIXEL_INC is not added to the last pixel of a line */
135 bool last_pixel_inc_missing:1;
137 /* POL_FREQ has ALIGN bit */
138 bool supports_sync_align:1;
140 bool has_writeback:1;
142 bool supports_double_pixel:1;
145 * Field order for VENC is different than HDMI. We should handle this in
146 * some intelligent manner, but as the SoCs have either HDMI or VENC,
147 * never both, we can just use this flag for now.
149 bool reverse_ilace_field_order:1;
151 bool has_gamma_table:1;
153 bool has_gamma_i734_bug:1;
156 #define DISPC_MAX_NR_FIFOS 5
157 #define DISPC_MAX_CHANNEL_GAMMA 4
159 struct dispc_device {
160 struct platform_device *pdev;
162 struct dss_device *dss;
164 struct dss_debugfs_entry *debugfs;
167 irq_handler_t user_handler;
170 unsigned long core_clk_rate;
171 unsigned long tv_pclk_rate;
173 u32 fifo_size[DISPC_MAX_NR_FIFOS];
174 /* maps which plane is using a fifo. fifo-id -> plane-id */
175 int fifo_assignment[DISPC_MAX_NR_FIFOS];
178 u32 ctx[DISPC_SZ_REGS / sizeof(u32)];
180 u32 *gamma_table[DISPC_MAX_CHANNEL_GAMMA];
182 const struct dispc_features *feat;
186 struct regmap *syscon_pol;
187 u32 syscon_pol_offset;
190 enum omap_color_component {
191 /* used for all color formats for OMAP3 and earlier
192 * and for RGB and Y color component on OMAP4
194 DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0,
195 /* used for UV component for
196 * DRM_FORMAT_YUYV, DRM_FORMAT_UYVY, DRM_FORMAT_NV12
197 * color formats on OMAP4
199 DISPC_COLOR_COMPONENT_UV = 1 << 1,
202 enum mgr_reg_fields {
203 DISPC_MGR_FLD_ENABLE,
204 DISPC_MGR_FLD_STNTFT,
206 DISPC_MGR_FLD_TFTDATALINES,
207 DISPC_MGR_FLD_STALLMODE,
208 DISPC_MGR_FLD_TCKENABLE,
209 DISPC_MGR_FLD_TCKSELECTION,
211 DISPC_MGR_FLD_FIFOHANDCHECK,
212 /* used to maintain a count of the above fields */
216 /* DISPC register field id */
217 enum dispc_feat_reg_field {
220 FEAT_REG_FIFOHIGHTHRESHOLD,
221 FEAT_REG_FIFOLOWTHRESHOLD,
223 FEAT_REG_HORIZONTALACCU,
224 FEAT_REG_VERTICALACCU,
227 struct dispc_reg_field {
233 struct dispc_gamma_desc {
240 static const struct {
245 struct dispc_gamma_desc gamma;
246 struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
248 [OMAP_DSS_CHANNEL_LCD] = {
250 .vsync_irq = DISPC_IRQ_VSYNC,
251 .framedone_irq = DISPC_IRQ_FRAMEDONE,
252 .sync_lost_irq = DISPC_IRQ_SYNC_LOST,
256 .reg = DISPC_GAMMA_TABLE0,
260 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 },
261 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 },
262 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 },
263 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 },
264 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 },
265 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 },
266 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 },
267 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 },
268 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
271 [OMAP_DSS_CHANNEL_DIGIT] = {
273 .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
274 .framedone_irq = DISPC_IRQ_FRAMEDONETV,
275 .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT,
279 .reg = DISPC_GAMMA_TABLE2,
283 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 },
284 [DISPC_MGR_FLD_STNTFT] = { },
285 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 },
286 [DISPC_MGR_FLD_TFTDATALINES] = { },
287 [DISPC_MGR_FLD_STALLMODE] = { },
288 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 },
289 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 },
290 [DISPC_MGR_FLD_CPR] = { },
291 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 },
294 [OMAP_DSS_CHANNEL_LCD2] = {
296 .vsync_irq = DISPC_IRQ_VSYNC2,
297 .framedone_irq = DISPC_IRQ_FRAMEDONE2,
298 .sync_lost_irq = DISPC_IRQ_SYNC_LOST2,
302 .reg = DISPC_GAMMA_TABLE1,
306 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 },
307 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 },
308 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 },
309 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 },
310 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 },
311 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 },
312 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 },
313 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 },
314 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 },
317 [OMAP_DSS_CHANNEL_LCD3] = {
319 .vsync_irq = DISPC_IRQ_VSYNC3,
320 .framedone_irq = DISPC_IRQ_FRAMEDONE3,
321 .sync_lost_irq = DISPC_IRQ_SYNC_LOST3,
325 .reg = DISPC_GAMMA_TABLE3,
329 [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 },
330 [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 },
331 [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 },
332 [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 },
333 [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 },
334 [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 },
335 [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 },
336 [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 },
337 [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 },
342 static unsigned long dispc_fclk_rate(struct dispc_device *dispc);
343 static unsigned long dispc_core_clk_rate(struct dispc_device *dispc);
344 static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
345 enum omap_channel channel);
346 static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
347 enum omap_channel channel);
349 static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
350 enum omap_plane_id plane);
351 static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
352 enum omap_plane_id plane);
354 static void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask);
356 static inline void dispc_write_reg(struct dispc_device *dispc, u16 idx, u32 val)
358 __raw_writel(val, dispc->base + idx);
361 static inline u32 dispc_read_reg(struct dispc_device *dispc, u16 idx)
363 return __raw_readl(dispc->base + idx);
366 static u32 mgr_fld_read(struct dispc_device *dispc, enum omap_channel channel,
367 enum mgr_reg_fields regfld)
369 const struct dispc_reg_field *rfld = &mgr_desc[channel].reg_desc[regfld];
371 return REG_GET(dispc, rfld->reg, rfld->high, rfld->low);
374 static void mgr_fld_write(struct dispc_device *dispc, enum omap_channel channel,
375 enum mgr_reg_fields regfld, int val)
377 const struct dispc_reg_field *rfld = &mgr_desc[channel].reg_desc[regfld];
379 REG_FLD_MOD(dispc, rfld->reg, val, rfld->high, rfld->low);
382 static int dispc_get_num_ovls(struct dispc_device *dispc)
384 return dispc->feat->num_ovls;
387 static int dispc_get_num_mgrs(struct dispc_device *dispc)
389 return dispc->feat->num_mgrs;
392 static void dispc_get_reg_field(struct dispc_device *dispc,
393 enum dispc_feat_reg_field id,
396 BUG_ON(id >= dispc->feat->num_reg_fields);
398 *start = dispc->feat->reg_fields[id].start;
399 *end = dispc->feat->reg_fields[id].end;
402 static bool dispc_has_feature(struct dispc_device *dispc,
403 enum dispc_feature_id id)
407 for (i = 0; i < dispc->feat->num_features; i++) {
408 if (dispc->feat->features[i] == id)
415 #define SR(dispc, reg) \
416 dispc->ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(dispc, DISPC_##reg)
417 #define RR(dispc, reg) \
418 dispc_write_reg(dispc, DISPC_##reg, dispc->ctx[DISPC_##reg / sizeof(u32)])
420 static void dispc_save_context(struct dispc_device *dispc)
424 DSSDBG("dispc_save_context\n");
426 SR(dispc, IRQENABLE);
429 SR(dispc, LINE_NUMBER);
430 if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
431 dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
432 SR(dispc, GLOBAL_ALPHA);
433 if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
437 if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
442 for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
443 SR(dispc, DEFAULT_COLOR(i));
444 SR(dispc, TRANS_COLOR(i));
445 SR(dispc, SIZE_MGR(i));
446 if (i == OMAP_DSS_CHANNEL_DIGIT)
448 SR(dispc, TIMING_H(i));
449 SR(dispc, TIMING_V(i));
450 SR(dispc, POL_FREQ(i));
451 SR(dispc, DIVISORo(i));
453 SR(dispc, DATA_CYCLE1(i));
454 SR(dispc, DATA_CYCLE2(i));
455 SR(dispc, DATA_CYCLE3(i));
457 if (dispc_has_feature(dispc, FEAT_CPR)) {
458 SR(dispc, CPR_COEF_R(i));
459 SR(dispc, CPR_COEF_G(i));
460 SR(dispc, CPR_COEF_B(i));
464 for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
465 SR(dispc, OVL_BA0(i));
466 SR(dispc, OVL_BA1(i));
467 SR(dispc, OVL_POSITION(i));
468 SR(dispc, OVL_SIZE(i));
469 SR(dispc, OVL_ATTRIBUTES(i));
470 SR(dispc, OVL_FIFO_THRESHOLD(i));
471 SR(dispc, OVL_ROW_INC(i));
472 SR(dispc, OVL_PIXEL_INC(i));
473 if (dispc_has_feature(dispc, FEAT_PRELOAD))
474 SR(dispc, OVL_PRELOAD(i));
475 if (i == OMAP_DSS_GFX) {
476 SR(dispc, OVL_WINDOW_SKIP(i));
477 SR(dispc, OVL_TABLE_BA(i));
480 SR(dispc, OVL_FIR(i));
481 SR(dispc, OVL_PICTURE_SIZE(i));
482 SR(dispc, OVL_ACCU0(i));
483 SR(dispc, OVL_ACCU1(i));
485 for (j = 0; j < 8; j++)
486 SR(dispc, OVL_FIR_COEF_H(i, j));
488 for (j = 0; j < 8; j++)
489 SR(dispc, OVL_FIR_COEF_HV(i, j));
491 for (j = 0; j < 5; j++)
492 SR(dispc, OVL_CONV_COEF(i, j));
494 if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
495 for (j = 0; j < 8; j++)
496 SR(dispc, OVL_FIR_COEF_V(i, j));
499 if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
500 SR(dispc, OVL_BA0_UV(i));
501 SR(dispc, OVL_BA1_UV(i));
502 SR(dispc, OVL_FIR2(i));
503 SR(dispc, OVL_ACCU2_0(i));
504 SR(dispc, OVL_ACCU2_1(i));
506 for (j = 0; j < 8; j++)
507 SR(dispc, OVL_FIR_COEF_H2(i, j));
509 for (j = 0; j < 8; j++)
510 SR(dispc, OVL_FIR_COEF_HV2(i, j));
512 for (j = 0; j < 8; j++)
513 SR(dispc, OVL_FIR_COEF_V2(i, j));
515 if (dispc_has_feature(dispc, FEAT_ATTR2))
516 SR(dispc, OVL_ATTRIBUTES2(i));
519 if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
522 dispc->ctx_valid = true;
524 DSSDBG("context saved\n");
527 static void dispc_restore_context(struct dispc_device *dispc)
531 DSSDBG("dispc_restore_context\n");
533 if (!dispc->ctx_valid)
536 /*RR(dispc, IRQENABLE);*/
537 /*RR(dispc, CONTROL);*/
539 RR(dispc, LINE_NUMBER);
540 if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
541 dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
542 RR(dispc, GLOBAL_ALPHA);
543 if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
545 if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
548 for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
549 RR(dispc, DEFAULT_COLOR(i));
550 RR(dispc, TRANS_COLOR(i));
551 RR(dispc, SIZE_MGR(i));
552 if (i == OMAP_DSS_CHANNEL_DIGIT)
554 RR(dispc, TIMING_H(i));
555 RR(dispc, TIMING_V(i));
556 RR(dispc, POL_FREQ(i));
557 RR(dispc, DIVISORo(i));
559 RR(dispc, DATA_CYCLE1(i));
560 RR(dispc, DATA_CYCLE2(i));
561 RR(dispc, DATA_CYCLE3(i));
563 if (dispc_has_feature(dispc, FEAT_CPR)) {
564 RR(dispc, CPR_COEF_R(i));
565 RR(dispc, CPR_COEF_G(i));
566 RR(dispc, CPR_COEF_B(i));
570 for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
571 RR(dispc, OVL_BA0(i));
572 RR(dispc, OVL_BA1(i));
573 RR(dispc, OVL_POSITION(i));
574 RR(dispc, OVL_SIZE(i));
575 RR(dispc, OVL_ATTRIBUTES(i));
576 RR(dispc, OVL_FIFO_THRESHOLD(i));
577 RR(dispc, OVL_ROW_INC(i));
578 RR(dispc, OVL_PIXEL_INC(i));
579 if (dispc_has_feature(dispc, FEAT_PRELOAD))
580 RR(dispc, OVL_PRELOAD(i));
581 if (i == OMAP_DSS_GFX) {
582 RR(dispc, OVL_WINDOW_SKIP(i));
583 RR(dispc, OVL_TABLE_BA(i));
586 RR(dispc, OVL_FIR(i));
587 RR(dispc, OVL_PICTURE_SIZE(i));
588 RR(dispc, OVL_ACCU0(i));
589 RR(dispc, OVL_ACCU1(i));
591 for (j = 0; j < 8; j++)
592 RR(dispc, OVL_FIR_COEF_H(i, j));
594 for (j = 0; j < 8; j++)
595 RR(dispc, OVL_FIR_COEF_HV(i, j));
597 for (j = 0; j < 5; j++)
598 RR(dispc, OVL_CONV_COEF(i, j));
600 if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
601 for (j = 0; j < 8; j++)
602 RR(dispc, OVL_FIR_COEF_V(i, j));
605 if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
606 RR(dispc, OVL_BA0_UV(i));
607 RR(dispc, OVL_BA1_UV(i));
608 RR(dispc, OVL_FIR2(i));
609 RR(dispc, OVL_ACCU2_0(i));
610 RR(dispc, OVL_ACCU2_1(i));
612 for (j = 0; j < 8; j++)
613 RR(dispc, OVL_FIR_COEF_H2(i, j));
615 for (j = 0; j < 8; j++)
616 RR(dispc, OVL_FIR_COEF_HV2(i, j));
618 for (j = 0; j < 8; j++)
619 RR(dispc, OVL_FIR_COEF_V2(i, j));
621 if (dispc_has_feature(dispc, FEAT_ATTR2))
622 RR(dispc, OVL_ATTRIBUTES2(i));
625 if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
628 /* enable last, because LCD & DIGIT enable are here */
630 if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
632 if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
634 /* clear spurious SYNC_LOST_DIGIT interrupts */
635 dispc_clear_irqstatus(dispc, DISPC_IRQ_SYNC_LOST_DIGIT);
638 * enable last so IRQs won't trigger before
639 * the context is fully restored
641 RR(dispc, IRQENABLE);
643 DSSDBG("context restored\n");
649 int dispc_runtime_get(struct dispc_device *dispc)
653 DSSDBG("dispc_runtime_get\n");
655 r = pm_runtime_get_sync(&dispc->pdev->dev);
656 if (WARN_ON(r < 0)) {
657 pm_runtime_put_noidle(&dispc->pdev->dev);
663 void dispc_runtime_put(struct dispc_device *dispc)
667 DSSDBG("dispc_runtime_put\n");
669 r = pm_runtime_put_sync(&dispc->pdev->dev);
670 WARN_ON(r < 0 && r != -ENOSYS);
673 static u32 dispc_mgr_get_vsync_irq(struct dispc_device *dispc,
674 enum omap_channel channel)
676 return mgr_desc[channel].vsync_irq;
679 static u32 dispc_mgr_get_framedone_irq(struct dispc_device *dispc,
680 enum omap_channel channel)
682 if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc->feat->no_framedone_tv)
685 return mgr_desc[channel].framedone_irq;
688 static u32 dispc_mgr_get_sync_lost_irq(struct dispc_device *dispc,
689 enum omap_channel channel)
691 return mgr_desc[channel].sync_lost_irq;
694 static u32 dispc_wb_get_framedone_irq(struct dispc_device *dispc)
696 return DISPC_IRQ_FRAMEDONEWB;
699 static void dispc_mgr_enable(struct dispc_device *dispc,
700 enum omap_channel channel, bool enable)
702 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_ENABLE, enable);
703 /* flush posted write */
704 mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
707 static bool dispc_mgr_is_enabled(struct dispc_device *dispc,
708 enum omap_channel channel)
710 return !!mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
713 static bool dispc_mgr_go_busy(struct dispc_device *dispc,
714 enum omap_channel channel)
716 return mgr_fld_read(dispc, channel, DISPC_MGR_FLD_GO) == 1;
719 static void dispc_mgr_go(struct dispc_device *dispc, enum omap_channel channel)
721 WARN_ON(!dispc_mgr_is_enabled(dispc, channel));
722 WARN_ON(dispc_mgr_go_busy(dispc, channel));
724 DSSDBG("GO %s\n", mgr_desc[channel].name);
726 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_GO, 1);
729 static bool dispc_wb_go_busy(struct dispc_device *dispc)
731 return REG_GET(dispc, DISPC_CONTROL2, 6, 6) == 1;
734 static void dispc_wb_go(struct dispc_device *dispc)
736 enum omap_plane_id plane = OMAP_DSS_WB;
739 enable = REG_GET(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
744 go = REG_GET(dispc, DISPC_CONTROL2, 6, 6) == 1;
746 DSSERR("GO bit not down for WB\n");
750 REG_FLD_MOD(dispc, DISPC_CONTROL2, 1, 6, 6);
753 static void dispc_ovl_write_firh_reg(struct dispc_device *dispc,
754 enum omap_plane_id plane, int reg,
757 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H(plane, reg), value);
760 static void dispc_ovl_write_firhv_reg(struct dispc_device *dispc,
761 enum omap_plane_id plane, int reg,
764 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV(plane, reg), value);
767 static void dispc_ovl_write_firv_reg(struct dispc_device *dispc,
768 enum omap_plane_id plane, int reg,
771 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V(plane, reg), value);
774 static void dispc_ovl_write_firh2_reg(struct dispc_device *dispc,
775 enum omap_plane_id plane, int reg,
778 BUG_ON(plane == OMAP_DSS_GFX);
780 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H2(plane, reg), value);
783 static void dispc_ovl_write_firhv2_reg(struct dispc_device *dispc,
784 enum omap_plane_id plane, int reg,
787 BUG_ON(plane == OMAP_DSS_GFX);
789 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
792 static void dispc_ovl_write_firv2_reg(struct dispc_device *dispc,
793 enum omap_plane_id plane, int reg,
796 BUG_ON(plane == OMAP_DSS_GFX);
798 dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V2(plane, reg), value);
801 static void dispc_ovl_set_scale_coef(struct dispc_device *dispc,
802 enum omap_plane_id plane, int fir_hinc,
803 int fir_vinc, int five_taps,
804 enum omap_color_component color_comp)
806 const struct dispc_coef *h_coef, *v_coef;
809 h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
810 v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
812 if (!h_coef || !v_coef) {
813 dev_err(&dispc->pdev->dev, "%s: failed to find scale coefs\n",
818 for (i = 0; i < 8; i++) {
821 h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
822 | FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
823 | FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
824 | FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
825 hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
826 | FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
827 | FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
828 | FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
830 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
831 dispc_ovl_write_firh_reg(dispc, plane, i, h);
832 dispc_ovl_write_firhv_reg(dispc, plane, i, hv);
834 dispc_ovl_write_firh2_reg(dispc, plane, i, h);
835 dispc_ovl_write_firhv2_reg(dispc, plane, i, hv);
841 for (i = 0; i < 8; i++) {
843 v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
844 | FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
845 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
846 dispc_ovl_write_firv_reg(dispc, plane, i, v);
848 dispc_ovl_write_firv2_reg(dispc, plane, i, v);
853 struct csc_coef_yuv2rgb {
854 int ry, rcb, rcr, gy, gcb, gcr, by, bcb, bcr;
858 struct csc_coef_rgb2yuv {
859 int yr, yg, yb, cbr, cbg, cbb, crr, crg, crb;
863 static void dispc_ovl_write_color_conv_coef(struct dispc_device *dispc,
864 enum omap_plane_id plane,
865 const struct csc_coef_yuv2rgb *ct)
867 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
869 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
870 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb));
871 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
872 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
873 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
875 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
880 static void dispc_wb_write_color_conv_coef(struct dispc_device *dispc,
881 const struct csc_coef_rgb2yuv *ct)
883 const enum omap_plane_id plane = OMAP_DSS_WB;
885 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
887 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->yg, ct->yr));
888 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->crr, ct->yb));
889 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->crb, ct->crg));
890 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->cbg, ct->cbr));
891 dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->cbb));
893 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
898 static void dispc_setup_color_conv_coef(struct dispc_device *dispc)
901 int num_ovl = dispc_get_num_ovls(dispc);
903 /* YUV -> RGB, ITU-R BT.601, limited range */
904 const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt601_lim = {
905 298, 0, 409, /* ry, rcb, rcr */
906 298, -100, -208, /* gy, gcb, gcr */
907 298, 516, 0, /* by, bcb, bcr */
908 false, /* limited range */
911 /* RGB -> YUV, ITU-R BT.601, limited range */
912 const struct csc_coef_rgb2yuv coefs_rgb2yuv_bt601_lim = {
913 66, 129, 25, /* yr, yg, yb */
914 -38, -74, 112, /* cbr, cbg, cbb */
915 112, -94, -18, /* crr, crg, crb */
916 false, /* limited range */
919 for (i = 1; i < num_ovl; i++)
920 dispc_ovl_write_color_conv_coef(dispc, i, &coefs_yuv2rgb_bt601_lim);
922 if (dispc->feat->has_writeback)
923 dispc_wb_write_color_conv_coef(dispc, &coefs_rgb2yuv_bt601_lim);
926 static void dispc_ovl_set_ba0(struct dispc_device *dispc,
927 enum omap_plane_id plane, u32 paddr)
929 dispc_write_reg(dispc, DISPC_OVL_BA0(plane), paddr);
932 static void dispc_ovl_set_ba1(struct dispc_device *dispc,
933 enum omap_plane_id plane, u32 paddr)
935 dispc_write_reg(dispc, DISPC_OVL_BA1(plane), paddr);
938 static void dispc_ovl_set_ba0_uv(struct dispc_device *dispc,
939 enum omap_plane_id plane, u32 paddr)
941 dispc_write_reg(dispc, DISPC_OVL_BA0_UV(plane), paddr);
944 static void dispc_ovl_set_ba1_uv(struct dispc_device *dispc,
945 enum omap_plane_id plane, u32 paddr)
947 dispc_write_reg(dispc, DISPC_OVL_BA1_UV(plane), paddr);
950 static void dispc_ovl_set_pos(struct dispc_device *dispc,
951 enum omap_plane_id plane,
952 enum omap_overlay_caps caps, int x, int y)
956 if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
959 val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
961 dispc_write_reg(dispc, DISPC_OVL_POSITION(plane), val);
964 static void dispc_ovl_set_input_size(struct dispc_device *dispc,
965 enum omap_plane_id plane, int width,
968 u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
970 if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
971 dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
973 dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
976 static void dispc_ovl_set_output_size(struct dispc_device *dispc,
977 enum omap_plane_id plane, int width,
982 BUG_ON(plane == OMAP_DSS_GFX);
984 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
986 if (plane == OMAP_DSS_WB)
987 dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
989 dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
992 static void dispc_ovl_set_zorder(struct dispc_device *dispc,
993 enum omap_plane_id plane,
994 enum omap_overlay_caps caps, u8 zorder)
996 if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
999 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
1002 static void dispc_ovl_enable_zorder_planes(struct dispc_device *dispc)
1006 if (!dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
1009 for (i = 0; i < dispc_get_num_ovls(dispc); i++)
1010 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
1013 static void dispc_ovl_set_pre_mult_alpha(struct dispc_device *dispc,
1014 enum omap_plane_id plane,
1015 enum omap_overlay_caps caps,
1018 if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
1021 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
1024 static void dispc_ovl_setup_global_alpha(struct dispc_device *dispc,
1025 enum omap_plane_id plane,
1026 enum omap_overlay_caps caps,
1029 static const unsigned int shifts[] = { 0, 8, 16, 24, };
1032 if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
1035 shift = shifts[plane];
1036 REG_FLD_MOD(dispc, DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
1039 static void dispc_ovl_set_pix_inc(struct dispc_device *dispc,
1040 enum omap_plane_id plane, s32 inc)
1042 dispc_write_reg(dispc, DISPC_OVL_PIXEL_INC(plane), inc);
1045 static void dispc_ovl_set_row_inc(struct dispc_device *dispc,
1046 enum omap_plane_id plane, s32 inc)
1048 dispc_write_reg(dispc, DISPC_OVL_ROW_INC(plane), inc);
1051 static void dispc_ovl_set_color_mode(struct dispc_device *dispc,
1052 enum omap_plane_id plane, u32 fourcc)
1055 if (plane != OMAP_DSS_GFX) {
1057 case DRM_FORMAT_NV12:
1059 case DRM_FORMAT_XRGB4444:
1061 case DRM_FORMAT_RGBA4444:
1063 case DRM_FORMAT_RGBX4444:
1065 case DRM_FORMAT_ARGB4444:
1067 case DRM_FORMAT_RGB565:
1069 case DRM_FORMAT_ARGB1555:
1071 case DRM_FORMAT_XRGB8888:
1073 case DRM_FORMAT_RGB888:
1075 case DRM_FORMAT_YUYV:
1077 case DRM_FORMAT_UYVY:
1079 case DRM_FORMAT_ARGB8888:
1081 case DRM_FORMAT_RGBA8888:
1083 case DRM_FORMAT_RGBX8888:
1085 case DRM_FORMAT_XRGB1555:
1092 case DRM_FORMAT_RGBX4444:
1094 case DRM_FORMAT_ARGB4444:
1096 case DRM_FORMAT_RGB565:
1098 case DRM_FORMAT_ARGB1555:
1100 case DRM_FORMAT_XRGB8888:
1102 case DRM_FORMAT_RGB888:
1104 case DRM_FORMAT_XRGB4444:
1106 case DRM_FORMAT_RGBA4444:
1108 case DRM_FORMAT_ARGB8888:
1110 case DRM_FORMAT_RGBA8888:
1112 case DRM_FORMAT_RGBX8888:
1114 case DRM_FORMAT_XRGB1555:
1121 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
1124 static void dispc_ovl_configure_burst_type(struct dispc_device *dispc,
1125 enum omap_plane_id plane,
1126 enum omap_dss_rotation_type rotation)
1128 if (dispc_has_feature(dispc, FEAT_BURST_2D) == 0)
1131 if (rotation == OMAP_DSS_ROT_TILER)
1132 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
1134 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
1137 static void dispc_ovl_set_channel_out(struct dispc_device *dispc,
1138 enum omap_plane_id plane,
1139 enum omap_channel channel)
1143 int chan = 0, chan2 = 0;
1149 case OMAP_DSS_VIDEO1:
1150 case OMAP_DSS_VIDEO2:
1151 case OMAP_DSS_VIDEO3:
1159 val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
1160 if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
1162 case OMAP_DSS_CHANNEL_LCD:
1166 case OMAP_DSS_CHANNEL_DIGIT:
1170 case OMAP_DSS_CHANNEL_LCD2:
1174 case OMAP_DSS_CHANNEL_LCD3:
1175 if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
1183 case OMAP_DSS_CHANNEL_WB:
1192 val = FLD_MOD(val, chan, shift, shift);
1193 val = FLD_MOD(val, chan2, 31, 30);
1195 val = FLD_MOD(val, channel, shift, shift);
1197 dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
1200 static enum omap_channel dispc_ovl_get_channel_out(struct dispc_device *dispc,
1201 enum omap_plane_id plane)
1210 case OMAP_DSS_VIDEO1:
1211 case OMAP_DSS_VIDEO2:
1212 case OMAP_DSS_VIDEO3:
1220 val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
1222 if (FLD_GET(val, shift, shift) == 1)
1223 return OMAP_DSS_CHANNEL_DIGIT;
1225 if (!dispc_has_feature(dispc, FEAT_MGR_LCD2))
1226 return OMAP_DSS_CHANNEL_LCD;
1228 switch (FLD_GET(val, 31, 30)) {
1231 return OMAP_DSS_CHANNEL_LCD;
1233 return OMAP_DSS_CHANNEL_LCD2;
1235 return OMAP_DSS_CHANNEL_LCD3;
1237 return OMAP_DSS_CHANNEL_WB;
1241 static void dispc_ovl_set_burst_size(struct dispc_device *dispc,
1242 enum omap_plane_id plane,
1243 enum omap_burst_size burst_size)
1245 static const unsigned int shifts[] = { 6, 14, 14, 14, 14, };
1248 shift = shifts[plane];
1249 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), burst_size,
1253 static void dispc_configure_burst_sizes(struct dispc_device *dispc)
1256 const int burst_size = BURST_SIZE_X8;
1258 /* Configure burst size always to maximum size */
1259 for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
1260 dispc_ovl_set_burst_size(dispc, i, burst_size);
1261 if (dispc->feat->has_writeback)
1262 dispc_ovl_set_burst_size(dispc, OMAP_DSS_WB, burst_size);
1265 static u32 dispc_ovl_get_burst_size(struct dispc_device *dispc,
1266 enum omap_plane_id plane)
1268 /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1269 return dispc->feat->burst_size_unit * 8;
1272 static bool dispc_ovl_color_mode_supported(struct dispc_device *dispc,
1273 enum omap_plane_id plane, u32 fourcc)
1278 modes = dispc->feat->supported_color_modes[plane];
1280 for (i = 0; modes[i]; ++i) {
1281 if (modes[i] == fourcc)
1288 static const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
1289 enum omap_plane_id plane)
1291 return dispc->feat->supported_color_modes[plane];
1294 static void dispc_mgr_enable_cpr(struct dispc_device *dispc,
1295 enum omap_channel channel, bool enable)
1297 if (channel == OMAP_DSS_CHANNEL_DIGIT)
1300 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_CPR, enable);
1303 static void dispc_mgr_set_cpr_coef(struct dispc_device *dispc,
1304 enum omap_channel channel,
1305 const struct omap_dss_cpr_coefs *coefs)
1307 u32 coef_r, coef_g, coef_b;
1309 if (!dss_mgr_is_lcd(channel))
1312 coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1313 FLD_VAL(coefs->rb, 9, 0);
1314 coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1315 FLD_VAL(coefs->gb, 9, 0);
1316 coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1317 FLD_VAL(coefs->bb, 9, 0);
1319 dispc_write_reg(dispc, DISPC_CPR_COEF_R(channel), coef_r);
1320 dispc_write_reg(dispc, DISPC_CPR_COEF_G(channel), coef_g);
1321 dispc_write_reg(dispc, DISPC_CPR_COEF_B(channel), coef_b);
1324 static void dispc_ovl_set_vid_color_conv(struct dispc_device *dispc,
1325 enum omap_plane_id plane, bool enable)
1329 BUG_ON(plane == OMAP_DSS_GFX);
1331 val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
1332 val = FLD_MOD(val, enable, 9, 9);
1333 dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
1336 static void dispc_ovl_enable_replication(struct dispc_device *dispc,
1337 enum omap_plane_id plane,
1338 enum omap_overlay_caps caps,
1341 static const unsigned int shifts[] = { 5, 10, 10, 10 };
1344 if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1347 shift = shifts[plane];
1348 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
1351 static void dispc_mgr_set_size(struct dispc_device *dispc,
1352 enum omap_channel channel, u16 width, u16 height)
1356 val = FLD_VAL(height - 1, dispc->feat->mgr_height_start, 16) |
1357 FLD_VAL(width - 1, dispc->feat->mgr_width_start, 0);
1359 dispc_write_reg(dispc, DISPC_SIZE_MGR(channel), val);
1362 static void dispc_init_fifos(struct dispc_device *dispc)
1370 unit = dispc->feat->buffer_size_unit;
1372 dispc_get_reg_field(dispc, FEAT_REG_FIFOSIZE, &start, &end);
1374 for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
1375 size = REG_GET(dispc, DISPC_OVL_FIFO_SIZE_STATUS(fifo),
1378 dispc->fifo_size[fifo] = size;
1381 * By default fifos are mapped directly to overlays, fifo 0 to
1382 * ovl 0, fifo 1 to ovl 1, etc.
1384 dispc->fifo_assignment[fifo] = fifo;
1388 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1389 * causes problems with certain use cases, like using the tiler in 2D
1390 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1391 * giving GFX plane a larger fifo. WB but should work fine with a
1394 if (dispc->feat->gfx_fifo_workaround) {
1397 v = dispc_read_reg(dispc, DISPC_GLOBAL_BUFFER);
1399 v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1400 v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1401 v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1402 v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1404 dispc_write_reg(dispc, DISPC_GLOBAL_BUFFER, v);
1406 dispc->fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1407 dispc->fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1411 * Setup default fifo thresholds.
1413 for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
1415 const bool use_fifomerge = false;
1416 const bool manual_update = false;
1418 dispc_ovl_compute_fifo_thresholds(dispc, i, &low, &high,
1419 use_fifomerge, manual_update);
1421 dispc_ovl_set_fifo_threshold(dispc, i, low, high);
1424 if (dispc->feat->has_writeback) {
1426 const bool use_fifomerge = false;
1427 const bool manual_update = false;
1429 dispc_ovl_compute_fifo_thresholds(dispc, OMAP_DSS_WB,
1430 &low, &high, use_fifomerge,
1433 dispc_ovl_set_fifo_threshold(dispc, OMAP_DSS_WB, low, high);
1437 static u32 dispc_ovl_get_fifo_size(struct dispc_device *dispc,
1438 enum omap_plane_id plane)
1443 for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
1444 if (dispc->fifo_assignment[fifo] == plane)
1445 size += dispc->fifo_size[fifo];
1451 void dispc_ovl_set_fifo_threshold(struct dispc_device *dispc,
1452 enum omap_plane_id plane,
1455 u8 hi_start, hi_end, lo_start, lo_end;
1458 unit = dispc->feat->buffer_size_unit;
1460 WARN_ON(low % unit != 0);
1461 WARN_ON(high % unit != 0);
1466 dispc_get_reg_field(dispc, FEAT_REG_FIFOHIGHTHRESHOLD,
1467 &hi_start, &hi_end);
1468 dispc_get_reg_field(dispc, FEAT_REG_FIFOLOWTHRESHOLD,
1469 &lo_start, &lo_end);
1471 DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1473 REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
1474 lo_start, lo_end) * unit,
1475 REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
1476 hi_start, hi_end) * unit,
1477 low * unit, high * unit);
1479 dispc_write_reg(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
1480 FLD_VAL(high, hi_start, hi_end) |
1481 FLD_VAL(low, lo_start, lo_end));
1484 * configure the preload to the pipeline's high threhold, if HT it's too
1485 * large for the preload field, set the threshold to the maximum value
1486 * that can be held by the preload register
1488 if (dispc_has_feature(dispc, FEAT_PRELOAD) &&
1489 dispc->feat->set_max_preload && plane != OMAP_DSS_WB)
1490 dispc_write_reg(dispc, DISPC_OVL_PRELOAD(plane),
1494 void dispc_enable_fifomerge(struct dispc_device *dispc, bool enable)
1496 if (!dispc_has_feature(dispc, FEAT_FIFO_MERGE)) {
1501 DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1502 REG_FLD_MOD(dispc, DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1505 void dispc_ovl_compute_fifo_thresholds(struct dispc_device *dispc,
1506 enum omap_plane_id plane,
1507 u32 *fifo_low, u32 *fifo_high,
1508 bool use_fifomerge, bool manual_update)
1511 * All sizes are in bytes. Both the buffer and burst are made of
1512 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1514 unsigned int buf_unit = dispc->feat->buffer_size_unit;
1515 unsigned int ovl_fifo_size, total_fifo_size, burst_size;
1518 burst_size = dispc_ovl_get_burst_size(dispc, plane);
1519 ovl_fifo_size = dispc_ovl_get_fifo_size(dispc, plane);
1521 if (use_fifomerge) {
1522 total_fifo_size = 0;
1523 for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
1524 total_fifo_size += dispc_ovl_get_fifo_size(dispc, i);
1526 total_fifo_size = ovl_fifo_size;
1530 * We use the same low threshold for both fifomerge and non-fifomerge
1531 * cases, but for fifomerge we calculate the high threshold using the
1532 * combined fifo size
1535 if (manual_update && dispc_has_feature(dispc, FEAT_OMAP3_DSI_FIFO_BUG)) {
1536 *fifo_low = ovl_fifo_size - burst_size * 2;
1537 *fifo_high = total_fifo_size - burst_size;
1538 } else if (plane == OMAP_DSS_WB) {
1540 * Most optimal configuration for writeback is to push out data
1541 * to the interconnect the moment writeback pushes enough pixels
1542 * in the FIFO to form a burst
1545 *fifo_high = burst_size;
1547 *fifo_low = ovl_fifo_size - burst_size;
1548 *fifo_high = total_fifo_size - buf_unit;
1552 static void dispc_ovl_set_mflag(struct dispc_device *dispc,
1553 enum omap_plane_id plane, bool enable)
1557 if (plane == OMAP_DSS_GFX)
1562 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1565 static void dispc_ovl_set_mflag_threshold(struct dispc_device *dispc,
1566 enum omap_plane_id plane,
1569 dispc_write_reg(dispc, DISPC_OVL_MFLAG_THRESHOLD(plane),
1570 FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0));
1573 static void dispc_init_mflag(struct dispc_device *dispc)
1578 * HACK: NV12 color format and MFLAG seem to have problems working
1579 * together: using two displays, and having an NV12 overlay on one of
1580 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1581 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1582 * remove the errors, but there doesn't seem to be a clear logic on
1583 * which values work and which not.
1585 * As a work-around, set force MFLAG to always on.
1587 dispc_write_reg(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE,
1588 (1 << 0) | /* MFLAG_CTRL = force always on */
1589 (0 << 2)); /* MFLAG_START = disable */
1591 for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
1592 u32 size = dispc_ovl_get_fifo_size(dispc, i);
1593 u32 unit = dispc->feat->buffer_size_unit;
1596 dispc_ovl_set_mflag(dispc, i, true);
1599 * Simulation team suggests below thesholds:
1600 * HT = fifosize * 5 / 8;
1601 * LT = fifosize * 4 / 8;
1604 low = size * 4 / 8 / unit;
1605 high = size * 5 / 8 / unit;
1607 dispc_ovl_set_mflag_threshold(dispc, i, low, high);
1610 if (dispc->feat->has_writeback) {
1611 u32 size = dispc_ovl_get_fifo_size(dispc, OMAP_DSS_WB);
1612 u32 unit = dispc->feat->buffer_size_unit;
1615 dispc_ovl_set_mflag(dispc, OMAP_DSS_WB, true);
1618 * Simulation team suggests below thesholds:
1619 * HT = fifosize * 5 / 8;
1620 * LT = fifosize * 4 / 8;
1623 low = size * 4 / 8 / unit;
1624 high = size * 5 / 8 / unit;
1626 dispc_ovl_set_mflag_threshold(dispc, OMAP_DSS_WB, low, high);
1630 static void dispc_ovl_set_fir(struct dispc_device *dispc,
1631 enum omap_plane_id plane,
1633 enum omap_color_component color_comp)
1637 if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1638 u8 hinc_start, hinc_end, vinc_start, vinc_end;
1640 dispc_get_reg_field(dispc, FEAT_REG_FIRHINC,
1641 &hinc_start, &hinc_end);
1642 dispc_get_reg_field(dispc, FEAT_REG_FIRVINC,
1643 &vinc_start, &vinc_end);
1644 val = FLD_VAL(vinc, vinc_start, vinc_end) |
1645 FLD_VAL(hinc, hinc_start, hinc_end);
1647 dispc_write_reg(dispc, DISPC_OVL_FIR(plane), val);
1649 val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1650 dispc_write_reg(dispc, DISPC_OVL_FIR2(plane), val);
1654 static void dispc_ovl_set_vid_accu0(struct dispc_device *dispc,
1655 enum omap_plane_id plane, int haccu,
1659 u8 hor_start, hor_end, vert_start, vert_end;
1661 dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
1662 &hor_start, &hor_end);
1663 dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
1664 &vert_start, &vert_end);
1666 val = FLD_VAL(vaccu, vert_start, vert_end) |
1667 FLD_VAL(haccu, hor_start, hor_end);
1669 dispc_write_reg(dispc, DISPC_OVL_ACCU0(plane), val);
1672 static void dispc_ovl_set_vid_accu1(struct dispc_device *dispc,
1673 enum omap_plane_id plane, int haccu,
1677 u8 hor_start, hor_end, vert_start, vert_end;
1679 dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
1680 &hor_start, &hor_end);
1681 dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
1682 &vert_start, &vert_end);
1684 val = FLD_VAL(vaccu, vert_start, vert_end) |
1685 FLD_VAL(haccu, hor_start, hor_end);
1687 dispc_write_reg(dispc, DISPC_OVL_ACCU1(plane), val);
1690 static void dispc_ovl_set_vid_accu2_0(struct dispc_device *dispc,
1691 enum omap_plane_id plane, int haccu,
1696 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1697 dispc_write_reg(dispc, DISPC_OVL_ACCU2_0(plane), val);
1700 static void dispc_ovl_set_vid_accu2_1(struct dispc_device *dispc,
1701 enum omap_plane_id plane, int haccu,
1706 val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1707 dispc_write_reg(dispc, DISPC_OVL_ACCU2_1(plane), val);
1710 static void dispc_ovl_set_scale_param(struct dispc_device *dispc,
1711 enum omap_plane_id plane,
1712 u16 orig_width, u16 orig_height,
1713 u16 out_width, u16 out_height,
1714 bool five_taps, u8 rotation,
1715 enum omap_color_component color_comp)
1717 int fir_hinc, fir_vinc;
1719 fir_hinc = 1024 * orig_width / out_width;
1720 fir_vinc = 1024 * orig_height / out_height;
1722 dispc_ovl_set_scale_coef(dispc, plane, fir_hinc, fir_vinc, five_taps,
1724 dispc_ovl_set_fir(dispc, plane, fir_hinc, fir_vinc, color_comp);
1727 static void dispc_ovl_set_accu_uv(struct dispc_device *dispc,
1728 enum omap_plane_id plane,
1729 u16 orig_width, u16 orig_height,
1730 u16 out_width, u16 out_height,
1731 bool ilace, u32 fourcc, u8 rotation)
1733 int h_accu2_0, h_accu2_1;
1734 int v_accu2_0, v_accu2_1;
1735 int chroma_hinc, chroma_vinc;
1745 const struct accu *accu_table;
1746 const struct accu *accu_val;
1748 static const struct accu accu_nv12[4] = {
1749 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1750 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1751 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1752 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1755 static const struct accu accu_nv12_ilace[4] = {
1756 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1757 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1758 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1759 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1762 static const struct accu accu_yuv[4] = {
1763 { 0, 1, 0, 1, 0, 1, 0, 1 },
1764 { 0, 1, 0, 1, 0, 1, 0, 1 },
1765 { -1, 1, 0, 1, 0, 1, 0, 1 },
1766 { 0, 1, 0, 1, -1, 1, 0, 1 },
1769 /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
1770 switch (rotation & DRM_MODE_ROTATE_MASK) {
1772 case DRM_MODE_ROTATE_0:
1775 case DRM_MODE_ROTATE_90:
1778 case DRM_MODE_ROTATE_180:
1781 case DRM_MODE_ROTATE_270:
1787 case DRM_FORMAT_NV12:
1789 accu_table = accu_nv12_ilace;
1791 accu_table = accu_nv12;
1793 case DRM_FORMAT_YUYV:
1794 case DRM_FORMAT_UYVY:
1795 accu_table = accu_yuv;
1802 accu_val = &accu_table[idx];
1804 chroma_hinc = 1024 * orig_width / out_width;
1805 chroma_vinc = 1024 * orig_height / out_height;
1807 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1808 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1809 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1810 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1812 dispc_ovl_set_vid_accu2_0(dispc, plane, h_accu2_0, v_accu2_0);
1813 dispc_ovl_set_vid_accu2_1(dispc, plane, h_accu2_1, v_accu2_1);
1816 static void dispc_ovl_set_scaling_common(struct dispc_device *dispc,
1817 enum omap_plane_id plane,
1818 u16 orig_width, u16 orig_height,
1819 u16 out_width, u16 out_height,
1820 bool ilace, bool five_taps,
1821 bool fieldmode, u32 fourcc,
1828 dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
1829 out_width, out_height, five_taps,
1830 rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1831 l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
1833 /* RESIZEENABLE and VERTICALTAPS */
1834 l &= ~((0x3 << 5) | (0x1 << 21));
1835 l |= (orig_width != out_width) ? (1 << 5) : 0;
1836 l |= (orig_height != out_height) ? (1 << 6) : 0;
1837 l |= five_taps ? (1 << 21) : 0;
1839 /* VRESIZECONF and HRESIZECONF */
1840 if (dispc_has_feature(dispc, FEAT_RESIZECONF)) {
1842 l |= (orig_width <= out_width) ? 0 : (1 << 7);
1843 l |= (orig_height <= out_height) ? 0 : (1 << 8);
1846 /* LINEBUFFERSPLIT */
1847 if (dispc_has_feature(dispc, FEAT_LINEBUFFERSPLIT)) {
1849 l |= five_taps ? (1 << 22) : 0;
1852 dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
1855 * field 0 = even field = bottom field
1856 * field 1 = odd field = top field
1858 if (ilace && !fieldmode) {
1860 accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1861 if (accu0 >= 1024/2) {
1867 dispc_ovl_set_vid_accu0(dispc, plane, 0, accu0);
1868 dispc_ovl_set_vid_accu1(dispc, plane, 0, accu1);
1871 static void dispc_ovl_set_scaling_uv(struct dispc_device *dispc,
1872 enum omap_plane_id plane,
1873 u16 orig_width, u16 orig_height,
1874 u16 out_width, u16 out_height,
1875 bool ilace, bool five_taps,
1876 bool fieldmode, u32 fourcc,
1879 int scale_x = out_width != orig_width;
1880 int scale_y = out_height != orig_height;
1881 bool chroma_upscale = plane != OMAP_DSS_WB;
1882 const struct drm_format_info *info;
1884 info = drm_format_info(fourcc);
1886 if (!dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE))
1889 if (!info->is_yuv) {
1890 /* reset chroma resampling for RGB formats */
1891 if (plane != OMAP_DSS_WB)
1892 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
1897 dispc_ovl_set_accu_uv(dispc, plane, orig_width, orig_height, out_width,
1898 out_height, ilace, fourcc, rotation);
1901 case DRM_FORMAT_NV12:
1902 if (chroma_upscale) {
1903 /* UV is subsampled by 2 horizontally and vertically */
1907 /* UV is downsampled by 2 horizontally and vertically */
1913 case DRM_FORMAT_YUYV:
1914 case DRM_FORMAT_UYVY:
1915 /* For YUV422 with 90/270 rotation, we don't upsample chroma */
1916 if (!drm_rotation_90_or_270(rotation)) {
1918 /* UV is subsampled by 2 horizontally */
1921 /* UV is downsampled by 2 horizontally */
1925 /* must use FIR for YUV422 if rotated */
1926 if ((rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0)
1927 scale_x = scale_y = true;
1935 if (out_width != orig_width)
1937 if (out_height != orig_height)
1940 dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
1941 out_width, out_height, five_taps,
1942 rotation, DISPC_COLOR_COMPONENT_UV);
1944 if (plane != OMAP_DSS_WB)
1945 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
1946 (scale_x || scale_y) ? 1 : 0, 8, 8);
1949 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1951 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1954 static void dispc_ovl_set_scaling(struct dispc_device *dispc,
1955 enum omap_plane_id plane,
1956 u16 orig_width, u16 orig_height,
1957 u16 out_width, u16 out_height,
1958 bool ilace, bool five_taps,
1959 bool fieldmode, u32 fourcc,
1962 BUG_ON(plane == OMAP_DSS_GFX);
1964 dispc_ovl_set_scaling_common(dispc, plane, orig_width, orig_height,
1965 out_width, out_height, ilace, five_taps,
1966 fieldmode, fourcc, rotation);
1968 dispc_ovl_set_scaling_uv(dispc, plane, orig_width, orig_height,
1969 out_width, out_height, ilace, five_taps,
1970 fieldmode, fourcc, rotation);
1973 static void dispc_ovl_set_rotation_attrs(struct dispc_device *dispc,
1974 enum omap_plane_id plane, u8 rotation,
1975 enum omap_dss_rotation_type rotation_type,
1978 bool row_repeat = false;
1981 /* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
1982 if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY) {
1984 if (rotation & DRM_MODE_REFLECT_X) {
1985 switch (rotation & DRM_MODE_ROTATE_MASK) {
1986 case DRM_MODE_ROTATE_0:
1989 case DRM_MODE_ROTATE_90:
1992 case DRM_MODE_ROTATE_180:
1995 case DRM_MODE_ROTATE_270:
2000 switch (rotation & DRM_MODE_ROTATE_MASK) {
2001 case DRM_MODE_ROTATE_0:
2004 case DRM_MODE_ROTATE_90:
2007 case DRM_MODE_ROTATE_180:
2010 case DRM_MODE_ROTATE_270:
2016 if (drm_rotation_90_or_270(rotation))
2023 * OMAP4/5 Errata i631:
2024 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
2025 * rows beyond the framebuffer, which may cause OCP error.
2027 if (fourcc == DRM_FORMAT_NV12 && rotation_type != OMAP_DSS_ROT_TILER)
2030 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
2031 if (dispc_has_feature(dispc, FEAT_ROWREPEATENABLE))
2032 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
2033 row_repeat ? 1 : 0, 18, 18);
2035 if (dispc_ovl_color_mode_supported(dispc, plane, DRM_FORMAT_NV12)) {
2037 fourcc == DRM_FORMAT_NV12 &&
2038 rotation_type == OMAP_DSS_ROT_TILER &&
2039 !drm_rotation_90_or_270(rotation);
2042 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
2043 doublestride, 22, 22);
2047 static int color_mode_to_bpp(u32 fourcc)
2050 case DRM_FORMAT_NV12:
2052 case DRM_FORMAT_RGBX4444:
2053 case DRM_FORMAT_RGB565:
2054 case DRM_FORMAT_ARGB4444:
2055 case DRM_FORMAT_YUYV:
2056 case DRM_FORMAT_UYVY:
2057 case DRM_FORMAT_RGBA4444:
2058 case DRM_FORMAT_XRGB4444:
2059 case DRM_FORMAT_ARGB1555:
2060 case DRM_FORMAT_XRGB1555:
2062 case DRM_FORMAT_RGB888:
2064 case DRM_FORMAT_XRGB8888:
2065 case DRM_FORMAT_ARGB8888:
2066 case DRM_FORMAT_RGBA8888:
2067 case DRM_FORMAT_RGBX8888:
2075 static s32 pixinc(int pixels, u8 ps)
2079 else if (pixels > 1)
2080 return 1 + (pixels - 1) * ps;
2081 else if (pixels < 0)
2082 return 1 - (-pixels + 1) * ps;
2088 static void calc_offset(u16 screen_width, u16 width,
2089 u32 fourcc, bool fieldmode, unsigned int field_offset,
2090 unsigned int *offset0, unsigned int *offset1,
2091 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim,
2092 enum omap_dss_rotation_type rotation_type, u8 rotation)
2096 ps = color_mode_to_bpp(fourcc) / 8;
2098 DSSDBG("scrw %d, width %d\n", screen_width, width);
2100 if (rotation_type == OMAP_DSS_ROT_TILER &&
2101 (fourcc == DRM_FORMAT_UYVY || fourcc == DRM_FORMAT_YUYV) &&
2102 drm_rotation_90_or_270(rotation)) {
2104 * HACK: ROW_INC needs to be calculated with TILER units.
2105 * We get such 'screen_width' that multiplying it with the
2106 * YUV422 pixel size gives the correct TILER container width.
2107 * However, 'width' is in pixels and multiplying it with YUV422
2108 * pixel size gives incorrect result. We thus multiply it here
2109 * with 2 to match the 32 bit TILER unit size.
2115 * field 0 = even field = bottom field
2116 * field 1 = odd field = top field
2118 *offset0 = field_offset * screen_width * ps;
2121 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2122 (fieldmode ? screen_width : 0), ps);
2123 if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY)
2124 *pix_inc = pixinc(x_predecim, 2 * ps);
2126 *pix_inc = pixinc(x_predecim, ps);
2130 * This function is used to avoid synclosts in OMAP3, because of some
2131 * undocumented horizontal position and timing related limitations.
2133 static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
2134 const struct videomode *vm, u16 pos_x,
2135 u16 width, u16 height, u16 out_width, u16 out_height,
2138 const int ds = DIV_ROUND_UP(height, out_height);
2139 unsigned long nonactive;
2140 static const u8 limits[3] = { 8, 10, 20 };
2144 nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len +
2145 vm->hback_porch - out_width;
2148 if (out_height < height)
2150 if (out_width < width)
2152 blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) *
2154 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2155 if (blank <= limits[i])
2158 /* FIXME add checks for 3-tap filter once the limitations are known */
2163 * Pixel data should be prepared before visible display point starts.
2164 * So, atleast DS-2 lines must have already been fetched by DISPC
2165 * during nonactive - pos_x period.
2167 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2168 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2169 val, max(0, ds - 2) * width);
2170 if (val < max(0, ds - 2) * width)
2174 * All lines need to be refilled during the nonactive period of which
2175 * only one line can be loaded during the active period. So, atleast
2176 * DS - 1 lines should be loaded during nonactive period.
2178 val = div_u64((u64)nonactive * lclk, pclk);
2179 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
2180 val, max(0, ds - 1) * width);
2181 if (val < max(0, ds - 1) * width)
2187 static unsigned long calc_core_clk_five_taps(unsigned long pclk,
2188 const struct videomode *vm, u16 width,
2189 u16 height, u16 out_width, u16 out_height,
2195 if (height <= out_height && width <= out_width)
2196 return (unsigned long) pclk;
2198 if (height > out_height) {
2199 unsigned int ppl = vm->hactive;
2201 tmp = (u64)pclk * height * out_width;
2202 do_div(tmp, 2 * out_height * ppl);
2205 if (height > 2 * out_height) {
2206 if (ppl == out_width)
2209 tmp = (u64)pclk * (height - 2 * out_height) * out_width;
2210 do_div(tmp, 2 * out_height * (ppl - out_width));
2211 core_clk = max_t(u32, core_clk, tmp);
2215 if (width > out_width) {
2216 tmp = (u64)pclk * width;
2217 do_div(tmp, out_width);
2218 core_clk = max_t(u32, core_clk, tmp);
2220 if (fourcc == DRM_FORMAT_XRGB8888)
2227 static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
2228 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2230 if (height > out_height && width > out_width)
2236 static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
2237 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2239 unsigned int hf, vf;
2242 * FIXME how to determine the 'A' factor
2243 * for the no downscaling case ?
2246 if (width > 3 * out_width)
2248 else if (width > 2 * out_width)
2250 else if (width > out_width)
2254 if (height > out_height)
2259 return pclk * vf * hf;
2262 static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
2263 u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2266 * If the overlay/writeback is in mem to mem mode, there are no
2267 * downscaling limitations with respect to pixel clock, return 1 as
2268 * required core clock to represent that we have sufficient enough
2269 * core clock to do maximum downscaling
2274 if (width > out_width)
2275 return DIV_ROUND_UP(pclk, out_width) * width;
2280 static int dispc_ovl_calc_scaling_24xx(struct dispc_device *dispc,
2281 unsigned long pclk, unsigned long lclk,
2282 const struct videomode *vm,
2283 u16 width, u16 height,
2284 u16 out_width, u16 out_height,
2285 u32 fourcc, bool *five_taps,
2286 int *x_predecim, int *y_predecim,
2287 int *decim_x, int *decim_y,
2288 u16 pos_x, unsigned long *core_clk,
2292 u16 in_width, in_height;
2293 int min_factor = min(*decim_x, *decim_y);
2294 const int maxsinglelinewidth = dispc->feat->max_line_width;
2299 in_height = height / *decim_y;
2300 in_width = width / *decim_x;
2301 *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
2302 in_height, out_width, out_height, mem_to_mem);
2303 error = (in_width > maxsinglelinewidth || !*core_clk ||
2304 *core_clk > dispc_core_clk_rate(dispc));
2306 if (*decim_x == *decim_y) {
2307 *decim_x = min_factor;
2310 swap(*decim_x, *decim_y);
2311 if (*decim_x < *decim_y)
2315 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2318 DSSERR("failed to find scaling settings\n");
2322 if (in_width > maxsinglelinewidth) {
2323 DSSERR("Cannot scale max input width exceeded\n");
2329 static int dispc_ovl_calc_scaling_34xx(struct dispc_device *dispc,
2330 unsigned long pclk, unsigned long lclk,
2331 const struct videomode *vm,
2332 u16 width, u16 height,
2333 u16 out_width, u16 out_height,
2334 u32 fourcc, bool *five_taps,
2335 int *x_predecim, int *y_predecim,
2336 int *decim_x, int *decim_y,
2337 u16 pos_x, unsigned long *core_clk,
2341 u16 in_width, in_height;
2342 const int maxsinglelinewidth = dispc->feat->max_line_width;
2345 in_height = height / *decim_y;
2346 in_width = width / *decim_x;
2347 *five_taps = in_height > out_height;
2349 if (in_width > maxsinglelinewidth)
2350 if (in_height > out_height &&
2351 in_height < out_height * 2)
2355 *core_clk = calc_core_clk_five_taps(pclk, vm,
2356 in_width, in_height, out_width,
2357 out_height, fourcc);
2359 *core_clk = dispc->feat->calc_core_clk(pclk, in_width,
2360 in_height, out_width, out_height,
2363 error = check_horiz_timing_omap3(pclk, lclk, vm,
2364 pos_x, in_width, in_height, out_width,
2365 out_height, *five_taps);
2366 if (error && *five_taps) {
2371 error = (error || in_width > maxsinglelinewidth * 2 ||
2372 (in_width > maxsinglelinewidth && *five_taps) ||
2373 !*core_clk || *core_clk > dispc_core_clk_rate(dispc));
2376 /* verify that we're inside the limits of scaler */
2377 if (in_width / 4 > out_width)
2381 if (in_height / 4 > out_height)
2384 if (in_height / 2 > out_height)
2391 } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2394 DSSERR("failed to find scaling settings\n");
2398 if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width,
2399 in_height, out_width, out_height, *five_taps)) {
2400 DSSERR("horizontal timing too tight\n");
2404 if (in_width > (maxsinglelinewidth * 2)) {
2405 DSSERR("Cannot setup scaling\n");
2406 DSSERR("width exceeds maximum width possible\n");
2410 if (in_width > maxsinglelinewidth && *five_taps) {
2411 DSSERR("cannot setup scaling with five taps\n");
2417 static int dispc_ovl_calc_scaling_44xx(struct dispc_device *dispc,
2418 unsigned long pclk, unsigned long lclk,
2419 const struct videomode *vm,
2420 u16 width, u16 height,
2421 u16 out_width, u16 out_height,
2422 u32 fourcc, bool *five_taps,
2423 int *x_predecim, int *y_predecim,
2424 int *decim_x, int *decim_y,
2425 u16 pos_x, unsigned long *core_clk,
2428 u16 in_width, in_width_max;
2429 int decim_x_min = *decim_x;
2430 u16 in_height = height / *decim_y;
2431 const int maxsinglelinewidth = dispc->feat->max_line_width;
2432 const int maxdownscale = dispc->feat->max_downscale;
2435 in_width_max = out_width * maxdownscale;
2437 in_width_max = dispc_core_clk_rate(dispc)
2438 / DIV_ROUND_UP(pclk, out_width);
2441 *decim_x = DIV_ROUND_UP(width, in_width_max);
2443 *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2444 if (*decim_x > *x_predecim)
2448 in_width = width / *decim_x;
2449 } while (*decim_x <= *x_predecim &&
2450 in_width > maxsinglelinewidth && ++*decim_x);
2452 if (in_width > maxsinglelinewidth) {
2453 DSSERR("Cannot scale width exceeds max line width\n");
2457 if (*decim_x > 4 && fourcc != DRM_FORMAT_NV12) {
2459 * Let's disable all scaling that requires horizontal
2460 * decimation with higher factor than 4, until we have
2461 * better estimates of what we can and can not
2462 * do. However, NV12 color format appears to work Ok
2463 * with all decimation factors.
2465 * When decimating horizontally by more that 4 the dss
2466 * is not able to fetch the data in burst mode. When
2467 * this happens it is hard to tell if there enough
2468 * bandwidth. Despite what theory says this appears to
2469 * be true also for 16-bit color formats.
2471 DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)\n", *decim_x);
2476 *core_clk = dispc->feat->calc_core_clk(pclk, in_width, in_height,
2477 out_width, out_height, mem_to_mem);
2481 #define DIV_FRAC(dividend, divisor) \
2482 ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2484 static int dispc_ovl_calc_scaling(struct dispc_device *dispc,
2485 enum omap_plane_id plane,
2486 unsigned long pclk, unsigned long lclk,
2487 enum omap_overlay_caps caps,
2488 const struct videomode *vm,
2489 u16 width, u16 height,
2490 u16 out_width, u16 out_height,
2491 u32 fourcc, bool *five_taps,
2492 int *x_predecim, int *y_predecim, u16 pos_x,
2493 enum omap_dss_rotation_type rotation_type,
2496 int maxhdownscale = dispc->feat->max_downscale;
2497 int maxvdownscale = dispc->feat->max_downscale;
2498 const int max_decim_limit = 16;
2499 unsigned long core_clk = 0;
2500 int decim_x, decim_y, ret;
2502 if (width == out_width && height == out_height)
2505 if (dispc->feat->supported_scaler_color_modes) {
2506 const u32 *modes = dispc->feat->supported_scaler_color_modes;
2509 for (i = 0; modes[i]; ++i) {
2510 if (modes[i] == fourcc)
2518 if (plane == OMAP_DSS_WB) {
2520 case DRM_FORMAT_NV12:
2521 maxhdownscale = maxvdownscale = 2;
2523 case DRM_FORMAT_YUYV:
2524 case DRM_FORMAT_UYVY:
2532 if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) {
2533 DSSERR("cannot calculate scaling settings: pclk is zero\n");
2537 if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
2541 *x_predecim = *y_predecim = 1;
2543 *x_predecim = max_decim_limit;
2544 *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2545 dispc_has_feature(dispc, FEAT_BURST_2D)) ?
2546 2 : max_decim_limit;
2549 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxhdownscale);
2550 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxvdownscale);
2552 if (decim_x > *x_predecim || out_width > width * 8)
2555 if (decim_y > *y_predecim || out_height > height * 8)
2558 ret = dispc->feat->calc_scaling(dispc, pclk, lclk, vm, width, height,
2559 out_width, out_height, fourcc,
2560 five_taps, x_predecim, y_predecim,
2561 &decim_x, &decim_y, pos_x, &core_clk,
2566 DSSDBG("%dx%d -> %dx%d (%d.%02d x %d.%02d), decim %dx%d %dx%d (%d.%02d x %d.%02d), taps %d, req clk %lu, cur clk %lu\n",
2568 out_width, out_height,
2569 out_width / width, DIV_FRAC(out_width, width),
2570 out_height / height, DIV_FRAC(out_height, height),
2573 width / decim_x, height / decim_y,
2574 out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
2575 out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
2578 core_clk, dispc_core_clk_rate(dispc));
2580 if (!core_clk || core_clk > dispc_core_clk_rate(dispc)) {
2581 DSSERR("failed to set up scaling, "
2582 "required core clk rate = %lu Hz, "
2583 "current core clk rate = %lu Hz\n",
2584 core_clk, dispc_core_clk_rate(dispc));
2588 *x_predecim = decim_x;
2589 *y_predecim = decim_y;
2593 static int dispc_ovl_setup_common(struct dispc_device *dispc,
2594 enum omap_plane_id plane,
2595 enum omap_overlay_caps caps,
2596 u32 paddr, u32 p_uv_addr,
2597 u16 screen_width, int pos_x, int pos_y,
2598 u16 width, u16 height,
2599 u16 out_width, u16 out_height,
2600 u32 fourcc, u8 rotation, u8 zorder,
2601 u8 pre_mult_alpha, u8 global_alpha,
2602 enum omap_dss_rotation_type rotation_type,
2603 bool replication, const struct videomode *vm,
2606 bool five_taps = true;
2607 bool fieldmode = false;
2609 unsigned int offset0, offset1;
2613 unsigned int field_offset = 0;
2614 u16 in_height = height;
2615 u16 in_width = width;
2616 int x_predecim = 1, y_predecim = 1;
2617 bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED);
2618 unsigned long pclk = dispc_plane_pclk_rate(dispc, plane);
2619 unsigned long lclk = dispc_plane_lclk_rate(dispc, plane);
2620 const struct drm_format_info *info;
2622 info = drm_format_info(fourcc);
2624 /* when setting up WB, dispc_plane_pclk_rate() returns 0 */
2625 if (plane == OMAP_DSS_WB)
2626 pclk = vm->pixelclock;
2628 if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
2631 if (info->is_yuv && (in_width & 1)) {
2632 DSSERR("input width %d is not even for YUV format\n", in_width);
2636 out_width = out_width == 0 ? width : out_width;
2637 out_height = out_height == 0 ? height : out_height;
2639 if (plane != OMAP_DSS_WB) {
2640 if (ilace && height == out_height)
2649 DSSDBG("adjusting for ilace: height %d, pos_y %d, out_height %d\n",
2650 in_height, pos_y, out_height);
2654 if (!dispc_ovl_color_mode_supported(dispc, plane, fourcc))
2657 r = dispc_ovl_calc_scaling(dispc, plane, pclk, lclk, caps, vm, in_width,
2658 in_height, out_width, out_height, fourcc,
2659 &five_taps, &x_predecim, &y_predecim, pos_x,
2660 rotation_type, mem_to_mem);
2664 in_width = in_width / x_predecim;
2665 in_height = in_height / y_predecim;
2667 if (x_predecim > 1 || y_predecim > 1)
2668 DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2669 x_predecim, y_predecim, in_width, in_height);
2671 if (info->is_yuv && (in_width & 1)) {
2672 DSSDBG("predecimated input width is not even for YUV format\n");
2673 DSSDBG("adjusting input width %d -> %d\n",
2674 in_width, in_width & ~1);
2682 if (ilace && !fieldmode) {
2684 * when downscaling the bottom field may have to start several
2685 * source lines below the top field. Unfortunately ACCUI
2686 * registers will only hold the fractional part of the offset
2687 * so the integer part must be added to the base address of the
2690 if (!in_height || in_height == out_height)
2693 field_offset = in_height / out_height / 2;
2696 /* Fields are independent but interleaved in memory. */
2705 if (plane == OMAP_DSS_WB)
2706 frame_width = out_width;
2708 frame_width = in_width;
2710 calc_offset(screen_width, frame_width,
2711 fourcc, fieldmode, field_offset,
2712 &offset0, &offset1, &row_inc, &pix_inc,
2713 x_predecim, y_predecim,
2714 rotation_type, rotation);
2716 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2717 offset0, offset1, row_inc, pix_inc);
2719 dispc_ovl_set_color_mode(dispc, plane, fourcc);
2721 dispc_ovl_configure_burst_type(dispc, plane, rotation_type);
2723 if (dispc->feat->reverse_ilace_field_order)
2724 swap(offset0, offset1);
2726 dispc_ovl_set_ba0(dispc, plane, paddr + offset0);
2727 dispc_ovl_set_ba1(dispc, plane, paddr + offset1);
2729 if (fourcc == DRM_FORMAT_NV12) {
2730 dispc_ovl_set_ba0_uv(dispc, plane, p_uv_addr + offset0);
2731 dispc_ovl_set_ba1_uv(dispc, plane, p_uv_addr + offset1);
2734 if (dispc->feat->last_pixel_inc_missing)
2735 row_inc += pix_inc - 1;
2737 dispc_ovl_set_row_inc(dispc, plane, row_inc);
2738 dispc_ovl_set_pix_inc(dispc, plane, pix_inc);
2740 DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
2741 in_height, out_width, out_height);
2743 dispc_ovl_set_pos(dispc, plane, caps, pos_x, pos_y);
2745 dispc_ovl_set_input_size(dispc, plane, in_width, in_height);
2747 if (caps & OMAP_DSS_OVL_CAP_SCALE) {
2748 dispc_ovl_set_scaling(dispc, plane, in_width, in_height,
2749 out_width, out_height, ilace, five_taps,
2750 fieldmode, fourcc, rotation);
2751 dispc_ovl_set_output_size(dispc, plane, out_width, out_height);
2752 dispc_ovl_set_vid_color_conv(dispc, plane, cconv);
2755 dispc_ovl_set_rotation_attrs(dispc, plane, rotation, rotation_type,
2758 dispc_ovl_set_zorder(dispc, plane, caps, zorder);
2759 dispc_ovl_set_pre_mult_alpha(dispc, plane, caps, pre_mult_alpha);
2760 dispc_ovl_setup_global_alpha(dispc, plane, caps, global_alpha);
2762 dispc_ovl_enable_replication(dispc, plane, caps, replication);
2767 static int dispc_ovl_setup(struct dispc_device *dispc,
2768 enum omap_plane_id plane,
2769 const struct omap_overlay_info *oi,
2770 const struct videomode *vm, bool mem_to_mem,
2771 enum omap_channel channel)
2774 enum omap_overlay_caps caps = dispc->feat->overlay_caps[plane];
2775 const bool replication = true;
2777 DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2778 " %dx%d, cmode %x, rot %d, chan %d repl %d\n",
2779 plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
2780 oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2781 oi->fourcc, oi->rotation, channel, replication);
2783 dispc_ovl_set_channel_out(dispc, plane, channel);
2785 r = dispc_ovl_setup_common(dispc, plane, caps, oi->paddr, oi->p_uv_addr,
2786 oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2787 oi->out_width, oi->out_height, oi->fourcc, oi->rotation,
2788 oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
2789 oi->rotation_type, replication, vm, mem_to_mem);
2794 static int dispc_wb_setup(struct dispc_device *dispc,
2795 const struct omap_dss_writeback_info *wi,
2796 bool mem_to_mem, const struct videomode *vm,
2797 enum dss_writeback_channel channel_in)
2801 enum omap_plane_id plane = OMAP_DSS_WB;
2802 const int pos_x = 0, pos_y = 0;
2803 const u8 zorder = 0, global_alpha = 0;
2804 const bool replication = true;
2806 int in_width = vm->hactive;
2807 int in_height = vm->vactive;
2808 enum omap_overlay_caps caps =
2809 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2811 if (vm->flags & DISPLAY_FLAGS_INTERLACED)
2814 DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2815 "rot %d\n", wi->paddr, wi->p_uv_addr, in_width,
2816 in_height, wi->width, wi->height, wi->fourcc, wi->rotation);
2818 r = dispc_ovl_setup_common(dispc, plane, caps, wi->paddr, wi->p_uv_addr,
2819 wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2820 wi->height, wi->fourcc, wi->rotation, zorder,
2821 wi->pre_mult_alpha, global_alpha, wi->rotation_type,
2822 replication, vm, mem_to_mem);
2826 switch (wi->fourcc) {
2827 case DRM_FORMAT_RGB565:
2828 case DRM_FORMAT_RGB888:
2829 case DRM_FORMAT_ARGB4444:
2830 case DRM_FORMAT_RGBA4444:
2831 case DRM_FORMAT_RGBX4444:
2832 case DRM_FORMAT_ARGB1555:
2833 case DRM_FORMAT_XRGB1555:
2834 case DRM_FORMAT_XRGB4444:
2842 /* setup extra DISPC_WB_ATTRIBUTES */
2843 l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
2844 l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */
2845 l = FLD_MOD(l, channel_in, 18, 16); /* CHANNELIN */
2846 l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */
2848 l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */
2850 l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */
2851 dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
2855 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
2859 if (channel_in == DSS_WB_TV_MGR)
2860 wbdelay = vm->vsync_len + vm->vback_porch;
2862 wbdelay = vm->vfront_porch + vm->vsync_len +
2865 if (vm->flags & DISPLAY_FLAGS_INTERLACED)
2868 wbdelay = min(wbdelay, 255u);
2871 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
2877 static bool dispc_has_writeback(struct dispc_device *dispc)
2879 return dispc->feat->has_writeback;
2882 static int dispc_ovl_enable(struct dispc_device *dispc,
2883 enum omap_plane_id plane, bool enable)
2885 DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2887 REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2892 static void dispc_lcd_enable_signal_polarity(struct dispc_device *dispc,
2895 if (!dispc_has_feature(dispc, FEAT_LCDENABLEPOL))
2898 REG_FLD_MOD(dispc, DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2901 void dispc_lcd_enable_signal(struct dispc_device *dispc, bool enable)
2903 if (!dispc_has_feature(dispc, FEAT_LCDENABLESIGNAL))
2906 REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2909 void dispc_pck_free_enable(struct dispc_device *dispc, bool enable)
2911 if (!dispc_has_feature(dispc, FEAT_PCKFREEENABLE))
2914 REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2917 static void dispc_mgr_enable_fifohandcheck(struct dispc_device *dispc,
2918 enum omap_channel channel,
2921 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
2925 static void dispc_mgr_set_lcd_type_tft(struct dispc_device *dispc,
2926 enum omap_channel channel)
2928 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STNTFT, 1);
2931 static void dispc_set_loadmode(struct dispc_device *dispc,
2932 enum omap_dss_load_mode mode)
2934 REG_FLD_MOD(dispc, DISPC_CONFIG, mode, 2, 1);
2938 static void dispc_mgr_set_default_color(struct dispc_device *dispc,
2939 enum omap_channel channel, u32 color)
2941 dispc_write_reg(dispc, DISPC_DEFAULT_COLOR(channel), color);
2944 static void dispc_mgr_set_trans_key(struct dispc_device *dispc,
2945 enum omap_channel ch,
2946 enum omap_dss_trans_key_type type,
2949 mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKSELECTION, type);
2951 dispc_write_reg(dispc, DISPC_TRANS_COLOR(ch), trans_key);
2954 static void dispc_mgr_enable_trans_key(struct dispc_device *dispc,
2955 enum omap_channel ch, bool enable)
2957 mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKENABLE, enable);
2960 static void dispc_mgr_enable_alpha_fixed_zorder(struct dispc_device *dispc,
2961 enum omap_channel ch,
2964 if (!dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER))
2967 if (ch == OMAP_DSS_CHANNEL_LCD)
2968 REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 18, 18);
2969 else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2970 REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 19, 19);
2973 static void dispc_mgr_setup(struct dispc_device *dispc,
2974 enum omap_channel channel,
2975 const struct omap_overlay_manager_info *info)
2977 dispc_mgr_set_default_color(dispc, channel, info->default_color);
2978 dispc_mgr_set_trans_key(dispc, channel, info->trans_key_type,
2980 dispc_mgr_enable_trans_key(dispc, channel, info->trans_enabled);
2981 dispc_mgr_enable_alpha_fixed_zorder(dispc, channel,
2982 info->partial_alpha_enabled);
2983 if (dispc_has_feature(dispc, FEAT_CPR)) {
2984 dispc_mgr_enable_cpr(dispc, channel, info->cpr_enable);
2985 dispc_mgr_set_cpr_coef(dispc, channel, &info->cpr_coefs);
2989 static void dispc_mgr_set_tft_data_lines(struct dispc_device *dispc,
2990 enum omap_channel channel,
2995 switch (data_lines) {
3013 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_TFTDATALINES, code);
3016 static void dispc_mgr_set_io_pad_mode(struct dispc_device *dispc,
3017 enum dss_io_pad_mode mode)
3023 case DSS_IO_PAD_MODE_RESET:
3027 case DSS_IO_PAD_MODE_RFBI:
3031 case DSS_IO_PAD_MODE_BYPASS:
3040 l = dispc_read_reg(dispc, DISPC_CONTROL);
3041 l = FLD_MOD(l, gpout0, 15, 15);
3042 l = FLD_MOD(l, gpout1, 16, 16);
3043 dispc_write_reg(dispc, DISPC_CONTROL, l);
3046 static void dispc_mgr_enable_stallmode(struct dispc_device *dispc,
3047 enum omap_channel channel, bool enable)
3049 mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STALLMODE, enable);
3052 static void dispc_mgr_set_lcd_config(struct dispc_device *dispc,
3053 enum omap_channel channel,
3054 const struct dss_lcd_mgr_config *config)
3056 dispc_mgr_set_io_pad_mode(dispc, config->io_pad_mode);
3058 dispc_mgr_enable_stallmode(dispc, channel, config->stallmode);
3059 dispc_mgr_enable_fifohandcheck(dispc, channel, config->fifohandcheck);
3061 dispc_mgr_set_clock_div(dispc, channel, &config->clock_info);
3063 dispc_mgr_set_tft_data_lines(dispc, channel, config->video_port_width);
3065 dispc_lcd_enable_signal_polarity(dispc, config->lcden_sig_polarity);
3067 dispc_mgr_set_lcd_type_tft(dispc, channel);
3070 static bool _dispc_mgr_size_ok(struct dispc_device *dispc,
3071 u16 width, u16 height)
3073 return width <= dispc->feat->mgr_width_max &&
3074 height <= dispc->feat->mgr_height_max;
3077 static bool _dispc_lcd_timings_ok(struct dispc_device *dispc,
3078 int hsync_len, int hfp, int hbp,
3079 int vsw, int vfp, int vbp)
3081 if (hsync_len < 1 || hsync_len > dispc->feat->sw_max ||
3082 hfp < 1 || hfp > dispc->feat->hp_max ||
3083 hbp < 1 || hbp > dispc->feat->hp_max ||
3084 vsw < 1 || vsw > dispc->feat->sw_max ||
3085 vfp < 0 || vfp > dispc->feat->vp_max ||
3086 vbp < 0 || vbp > dispc->feat->vp_max)
3091 static bool _dispc_mgr_pclk_ok(struct dispc_device *dispc,
3092 enum omap_channel channel,
3095 if (dss_mgr_is_lcd(channel))
3096 return pclk <= dispc->feat->max_lcd_pclk;
3098 return pclk <= dispc->feat->max_tv_pclk;
3101 static int dispc_mgr_check_timings(struct dispc_device *dispc,
3102 enum omap_channel channel,
3103 const struct videomode *vm)
3105 if (!_dispc_mgr_size_ok(dispc, vm->hactive, vm->vactive))
3108 if (!_dispc_mgr_pclk_ok(dispc, channel, vm->pixelclock))
3111 if (dss_mgr_is_lcd(channel)) {
3112 /* TODO: OMAP4+ supports interlace for LCD outputs */
3113 if (vm->flags & DISPLAY_FLAGS_INTERLACED)
3116 if (!_dispc_lcd_timings_ok(dispc, vm->hsync_len,
3117 vm->hfront_porch, vm->hback_porch,
3118 vm->vsync_len, vm->vfront_porch,
3126 static void _dispc_mgr_set_lcd_timings(struct dispc_device *dispc,
3127 enum omap_channel channel,
3128 const struct videomode *vm)
3130 u32 timing_h, timing_v, l;
3131 bool onoff, rf, ipc, vs, hs, de;
3133 timing_h = FLD_VAL(vm->hsync_len - 1, dispc->feat->sw_start, 0) |
3134 FLD_VAL(vm->hfront_porch - 1, dispc->feat->fp_start, 8) |
3135 FLD_VAL(vm->hback_porch - 1, dispc->feat->bp_start, 20);
3136 timing_v = FLD_VAL(vm->vsync_len - 1, dispc->feat->sw_start, 0) |
3137 FLD_VAL(vm->vfront_porch, dispc->feat->fp_start, 8) |
3138 FLD_VAL(vm->vback_porch, dispc->feat->bp_start, 20);
3140 dispc_write_reg(dispc, DISPC_TIMING_H(channel), timing_h);
3141 dispc_write_reg(dispc, DISPC_TIMING_V(channel), timing_v);
3143 vs = !!(vm->flags & DISPLAY_FLAGS_VSYNC_LOW);
3144 hs = !!(vm->flags & DISPLAY_FLAGS_HSYNC_LOW);
3145 de = !!(vm->flags & DISPLAY_FLAGS_DE_LOW);
3146 ipc = !!(vm->flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE);
3147 onoff = true; /* always use the 'rf' setting */
3148 rf = !!(vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE);
3150 l = FLD_VAL(onoff, 17, 17) |
3151 FLD_VAL(rf, 16, 16) |
3152 FLD_VAL(de, 15, 15) |
3153 FLD_VAL(ipc, 14, 14) |
3154 FLD_VAL(hs, 13, 13) |
3155 FLD_VAL(vs, 12, 12);
3157 /* always set ALIGN bit when available */
3158 if (dispc->feat->supports_sync_align)
3161 dispc_write_reg(dispc, DISPC_POL_FREQ(channel), l);
3163 if (dispc->syscon_pol) {
3164 const int shifts[] = {
3165 [OMAP_DSS_CHANNEL_LCD] = 0,
3166 [OMAP_DSS_CHANNEL_LCD2] = 1,
3167 [OMAP_DSS_CHANNEL_LCD3] = 2,
3172 mask = (1 << 0) | (1 << 3) | (1 << 6);
3173 val = (rf << 0) | (ipc << 3) | (onoff << 6);
3175 mask <<= 16 + shifts[channel];
3176 val <<= 16 + shifts[channel];
3178 regmap_update_bits(dispc->syscon_pol, dispc->syscon_pol_offset,
3183 static int vm_flag_to_int(enum display_flags flags, enum display_flags high,
3184 enum display_flags low)
3193 /* change name to mode? */
3194 static void dispc_mgr_set_timings(struct dispc_device *dispc,
3195 enum omap_channel channel,
3196 const struct videomode *vm)
3198 unsigned int xtot, ytot;
3199 unsigned long ht, vt;
3200 struct videomode t = *vm;
3202 DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
3204 if (dispc_mgr_check_timings(dispc, channel, &t)) {
3209 if (dss_mgr_is_lcd(channel)) {
3210 _dispc_mgr_set_lcd_timings(dispc, channel, &t);
3212 xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch;
3213 ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch;
3215 ht = vm->pixelclock / xtot;
3216 vt = vm->pixelclock / xtot / ytot;
3218 DSSDBG("pck %lu\n", vm->pixelclock);
3219 DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
3220 t.hsync_len, t.hfront_porch, t.hback_porch,
3221 t.vsync_len, t.vfront_porch, t.vback_porch);
3222 DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3223 vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW),
3224 vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW),
3225 vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE),
3226 vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW),
3227 vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE));
3229 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
3231 if (t.flags & DISPLAY_FLAGS_INTERLACED)
3234 if (dispc->feat->supports_double_pixel)
3235 REG_FLD_MOD(dispc, DISPC_CONTROL,
3236 !!(t.flags & DISPLAY_FLAGS_DOUBLECLK),
3240 dispc_mgr_set_size(dispc, channel, t.hactive, t.vactive);
3243 static void dispc_mgr_set_lcd_divisor(struct dispc_device *dispc,
3244 enum omap_channel channel, u16 lck_div,
3247 BUG_ON(lck_div < 1);
3248 BUG_ON(pck_div < 1);
3250 dispc_write_reg(dispc, DISPC_DIVISORo(channel),
3251 FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
3253 if (!dispc_has_feature(dispc, FEAT_CORE_CLK_DIV) &&
3254 channel == OMAP_DSS_CHANNEL_LCD)
3255 dispc->core_clk_rate = dispc_fclk_rate(dispc) / lck_div;
3258 static void dispc_mgr_get_lcd_divisor(struct dispc_device *dispc,
3259 enum omap_channel channel, int *lck_div,
3263 l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
3264 *lck_div = FLD_GET(l, 23, 16);
3265 *pck_div = FLD_GET(l, 7, 0);
3268 static unsigned long dispc_fclk_rate(struct dispc_device *dispc)
3271 enum dss_clk_source src;
3273 src = dss_get_dispc_clk_source(dispc->dss);
3275 if (src == DSS_CLK_SRC_FCK) {
3276 r = dss_get_dispc_clk_rate(dispc->dss);
3278 struct dss_pll *pll;
3279 unsigned int clkout_idx;
3281 pll = dss_pll_find_by_src(dispc->dss, src);
3282 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
3284 r = pll->cinfo.clkout[clkout_idx];
3290 static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
3291 enum omap_channel channel)
3295 enum dss_clk_source src;
3297 /* for TV, LCLK rate is the FCLK rate */
3298 if (!dss_mgr_is_lcd(channel))
3299 return dispc_fclk_rate(dispc);
3301 src = dss_get_lcd_clk_source(dispc->dss, channel);
3303 if (src == DSS_CLK_SRC_FCK) {
3304 r = dss_get_dispc_clk_rate(dispc->dss);
3306 struct dss_pll *pll;
3307 unsigned int clkout_idx;
3309 pll = dss_pll_find_by_src(dispc->dss, src);
3310 clkout_idx = dss_pll_get_clkout_idx_for_src(src);
3312 r = pll->cinfo.clkout[clkout_idx];
3315 lcd = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
3320 static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
3321 enum omap_channel channel)
3325 if (dss_mgr_is_lcd(channel)) {
3329 l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
3331 pcd = FLD_GET(l, 7, 0);
3333 r = dispc_mgr_lclk_rate(dispc, channel);
3337 return dispc->tv_pclk_rate;
3341 void dispc_set_tv_pclk(struct dispc_device *dispc, unsigned long pclk)
3343 dispc->tv_pclk_rate = pclk;
3346 static unsigned long dispc_core_clk_rate(struct dispc_device *dispc)
3348 return dispc->core_clk_rate;
3351 static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
3352 enum omap_plane_id plane)
3354 enum omap_channel channel;
3356 if (plane == OMAP_DSS_WB)
3359 channel = dispc_ovl_get_channel_out(dispc, plane);
3361 return dispc_mgr_pclk_rate(dispc, channel);
3364 static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
3365 enum omap_plane_id plane)
3367 enum omap_channel channel;
3369 if (plane == OMAP_DSS_WB)
3372 channel = dispc_ovl_get_channel_out(dispc, plane);
3374 return dispc_mgr_lclk_rate(dispc, channel);
3377 static void dispc_dump_clocks_channel(struct dispc_device *dispc,
3379 enum omap_channel channel)
3382 enum dss_clk_source lcd_clk_src;
3384 seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3386 lcd_clk_src = dss_get_lcd_clk_source(dispc->dss, channel);
3388 seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
3389 dss_get_clk_source_name(lcd_clk_src));
3391 dispc_mgr_get_lcd_divisor(dispc, channel, &lcd, &pcd);
3393 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3394 dispc_mgr_lclk_rate(dispc, channel), lcd);
3395 seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3396 dispc_mgr_pclk_rate(dispc, channel), pcd);
3399 void dispc_dump_clocks(struct dispc_device *dispc, struct seq_file *s)
3401 enum dss_clk_source dispc_clk_src;
3405 if (dispc_runtime_get(dispc))
3408 seq_printf(s, "- DISPC -\n");
3410 dispc_clk_src = dss_get_dispc_clk_source(dispc->dss);
3411 seq_printf(s, "dispc fclk source = %s\n",
3412 dss_get_clk_source_name(dispc_clk_src));
3414 seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate(dispc));
3416 if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
3417 seq_printf(s, "- DISPC-CORE-CLK -\n");
3418 l = dispc_read_reg(dispc, DISPC_DIVISOR);
3419 lcd = FLD_GET(l, 23, 16);
3421 seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3422 (dispc_fclk_rate(dispc)/lcd), lcd);
3425 dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD);
3427 if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
3428 dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD2);
3429 if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
3430 dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD3);
3432 dispc_runtime_put(dispc);
3435 static int dispc_dump_regs(struct seq_file *s, void *p)
3437 struct dispc_device *dispc = s->private;
3439 const char *mgr_names[] = {
3440 [OMAP_DSS_CHANNEL_LCD] = "LCD",
3441 [OMAP_DSS_CHANNEL_DIGIT] = "TV",
3442 [OMAP_DSS_CHANNEL_LCD2] = "LCD2",
3443 [OMAP_DSS_CHANNEL_LCD3] = "LCD3",
3445 const char *ovl_names[] = {
3446 [OMAP_DSS_GFX] = "GFX",
3447 [OMAP_DSS_VIDEO1] = "VID1",
3448 [OMAP_DSS_VIDEO2] = "VID2",
3449 [OMAP_DSS_VIDEO3] = "VID3",
3450 [OMAP_DSS_WB] = "WB",
3452 const char **p_names;
3454 #define DUMPREG(dispc, r) \
3455 seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(dispc, r))
3457 if (dispc_runtime_get(dispc))
3460 /* DISPC common registers */
3461 DUMPREG(dispc, DISPC_REVISION);
3462 DUMPREG(dispc, DISPC_SYSCONFIG);
3463 DUMPREG(dispc, DISPC_SYSSTATUS);
3464 DUMPREG(dispc, DISPC_IRQSTATUS);
3465 DUMPREG(dispc, DISPC_IRQENABLE);
3466 DUMPREG(dispc, DISPC_CONTROL);
3467 DUMPREG(dispc, DISPC_CONFIG);
3468 DUMPREG(dispc, DISPC_CAPABLE);
3469 DUMPREG(dispc, DISPC_LINE_STATUS);
3470 DUMPREG(dispc, DISPC_LINE_NUMBER);
3471 if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
3472 dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
3473 DUMPREG(dispc, DISPC_GLOBAL_ALPHA);
3474 if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
3475 DUMPREG(dispc, DISPC_CONTROL2);
3476 DUMPREG(dispc, DISPC_CONFIG2);
3478 if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
3479 DUMPREG(dispc, DISPC_CONTROL3);
3480 DUMPREG(dispc, DISPC_CONFIG3);
3482 if (dispc_has_feature(dispc, FEAT_MFLAG))
3483 DUMPREG(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE);
3487 #define DISPC_REG(i, name) name(i)
3488 #define DUMPREG(dispc, i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3489 (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
3490 dispc_read_reg(dispc, DISPC_REG(i, r)))
3492 p_names = mgr_names;
3494 /* DISPC channel specific registers */
3495 for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
3496 DUMPREG(dispc, i, DISPC_DEFAULT_COLOR);
3497 DUMPREG(dispc, i, DISPC_TRANS_COLOR);
3498 DUMPREG(dispc, i, DISPC_SIZE_MGR);
3500 if (i == OMAP_DSS_CHANNEL_DIGIT)
3503 DUMPREG(dispc, i, DISPC_TIMING_H);
3504 DUMPREG(dispc, i, DISPC_TIMING_V);
3505 DUMPREG(dispc, i, DISPC_POL_FREQ);
3506 DUMPREG(dispc, i, DISPC_DIVISORo);
3508 DUMPREG(dispc, i, DISPC_DATA_CYCLE1);
3509 DUMPREG(dispc, i, DISPC_DATA_CYCLE2);
3510 DUMPREG(dispc, i, DISPC_DATA_CYCLE3);
3512 if (dispc_has_feature(dispc, FEAT_CPR)) {
3513 DUMPREG(dispc, i, DISPC_CPR_COEF_R);
3514 DUMPREG(dispc, i, DISPC_CPR_COEF_G);
3515 DUMPREG(dispc, i, DISPC_CPR_COEF_B);
3519 p_names = ovl_names;
3521 for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
3522 DUMPREG(dispc, i, DISPC_OVL_BA0);
3523 DUMPREG(dispc, i, DISPC_OVL_BA1);
3524 DUMPREG(dispc, i, DISPC_OVL_POSITION);
3525 DUMPREG(dispc, i, DISPC_OVL_SIZE);
3526 DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
3527 DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
3528 DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
3529 DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
3530 DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
3532 if (dispc_has_feature(dispc, FEAT_PRELOAD))
3533 DUMPREG(dispc, i, DISPC_OVL_PRELOAD);
3534 if (dispc_has_feature(dispc, FEAT_MFLAG))
3535 DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
3537 if (i == OMAP_DSS_GFX) {
3538 DUMPREG(dispc, i, DISPC_OVL_WINDOW_SKIP);
3539 DUMPREG(dispc, i, DISPC_OVL_TABLE_BA);
3543 DUMPREG(dispc, i, DISPC_OVL_FIR);
3544 DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
3545 DUMPREG(dispc, i, DISPC_OVL_ACCU0);
3546 DUMPREG(dispc, i, DISPC_OVL_ACCU1);
3547 if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
3548 DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
3549 DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
3550 DUMPREG(dispc, i, DISPC_OVL_FIR2);
3551 DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
3552 DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
3554 if (dispc_has_feature(dispc, FEAT_ATTR2))
3555 DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
3558 if (dispc->feat->has_writeback) {
3560 DUMPREG(dispc, i, DISPC_OVL_BA0);
3561 DUMPREG(dispc, i, DISPC_OVL_BA1);
3562 DUMPREG(dispc, i, DISPC_OVL_SIZE);
3563 DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
3564 DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
3565 DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
3566 DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
3567 DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
3569 if (dispc_has_feature(dispc, FEAT_MFLAG))
3570 DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
3572 DUMPREG(dispc, i, DISPC_OVL_FIR);
3573 DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
3574 DUMPREG(dispc, i, DISPC_OVL_ACCU0);
3575 DUMPREG(dispc, i, DISPC_OVL_ACCU1);
3576 if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
3577 DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
3578 DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
3579 DUMPREG(dispc, i, DISPC_OVL_FIR2);
3580 DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
3581 DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
3583 if (dispc_has_feature(dispc, FEAT_ATTR2))
3584 DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
3590 #define DISPC_REG(plane, name, i) name(plane, i)
3591 #define DUMPREG(dispc, plane, name, i) \
3592 seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3593 (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
3594 dispc_read_reg(dispc, DISPC_REG(plane, name, i)))
3596 /* Video pipeline coefficient registers */
3598 /* start from OMAP_DSS_VIDEO1 */
3599 for (i = 1; i < dispc_get_num_ovls(dispc); i++) {
3600 for (j = 0; j < 8; j++)
3601 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H, j);
3603 for (j = 0; j < 8; j++)
3604 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV, j);
3606 for (j = 0; j < 5; j++)
3607 DUMPREG(dispc, i, DISPC_OVL_CONV_COEF, j);
3609 if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
3610 for (j = 0; j < 8; j++)
3611 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V, j);
3614 if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
3615 for (j = 0; j < 8; j++)
3616 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H2, j);
3618 for (j = 0; j < 8; j++)
3619 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV2, j);
3621 for (j = 0; j < 8; j++)
3622 DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V2, j);
3626 dispc_runtime_put(dispc);
3634 /* calculate clock rates using dividers in cinfo */
3635 int dispc_calc_clock_rates(struct dispc_device *dispc,
3636 unsigned long dispc_fclk_rate,
3637 struct dispc_clock_info *cinfo)
3639 if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3641 if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3644 cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3645 cinfo->pck = cinfo->lck / cinfo->pck_div;
3650 bool dispc_div_calc(struct dispc_device *dispc, unsigned long dispc_freq,
3651 unsigned long pck_min, unsigned long pck_max,
3652 dispc_div_calc_func func, void *data)
3654 int lckd, lckd_start, lckd_stop;
3655 int pckd, pckd_start, pckd_stop;
3656 unsigned long pck, lck;
3657 unsigned long lck_max;
3658 unsigned long pckd_hw_min, pckd_hw_max;
3659 unsigned int min_fck_per_pck;
3662 #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3663 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3665 min_fck_per_pck = 0;
3668 pckd_hw_min = dispc->feat->min_pcd;
3671 lck_max = dss_get_max_fck_rate(dispc->dss);
3673 pck_min = pck_min ? pck_min : 1;
3674 pck_max = pck_max ? pck_max : ULONG_MAX;
3676 lckd_start = max(DIV_ROUND_UP(dispc_freq, lck_max), 1ul);
3677 lckd_stop = min(dispc_freq / pck_min, 255ul);
3679 for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3680 lck = dispc_freq / lckd;
3682 pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3683 pckd_stop = min(lck / pck_min, pckd_hw_max);
3685 for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3689 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3690 * clock, which means we're configuring DISPC fclk here
3691 * also. Thus we need to use the calculated lck. For
3692 * OMAP4+ the DISPC fclk is a separate clock.
3694 if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
3695 fck = dispc_core_clk_rate(dispc);
3699 if (fck < pck * min_fck_per_pck)
3702 if (func(lckd, pckd, lck, pck, data))
3710 void dispc_mgr_set_clock_div(struct dispc_device *dispc,
3711 enum omap_channel channel,
3712 const struct dispc_clock_info *cinfo)
3714 DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3715 DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3717 dispc_mgr_set_lcd_divisor(dispc, channel, cinfo->lck_div,
3721 int dispc_mgr_get_clock_div(struct dispc_device *dispc,
3722 enum omap_channel channel,
3723 struct dispc_clock_info *cinfo)
3727 fck = dispc_fclk_rate(dispc);
3729 cinfo->lck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
3730 cinfo->pck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 7, 0);
3732 cinfo->lck = fck / cinfo->lck_div;
3733 cinfo->pck = cinfo->lck / cinfo->pck_div;
3738 static u32 dispc_read_irqstatus(struct dispc_device *dispc)
3740 return dispc_read_reg(dispc, DISPC_IRQSTATUS);
3743 static void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask)
3745 dispc_write_reg(dispc, DISPC_IRQSTATUS, mask);
3748 static void dispc_write_irqenable(struct dispc_device *dispc, u32 mask)
3750 u32 old_mask = dispc_read_reg(dispc, DISPC_IRQENABLE);
3752 /* clear the irqstatus for newly enabled irqs */
3753 dispc_clear_irqstatus(dispc, (mask ^ old_mask) & mask);
3755 dispc_write_reg(dispc, DISPC_IRQENABLE, mask);
3757 /* flush posted write */
3758 dispc_read_reg(dispc, DISPC_IRQENABLE);
3761 void dispc_enable_sidle(struct dispc_device *dispc)
3763 /* SIDLEMODE: smart idle */
3764 REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 2, 4, 3);
3767 void dispc_disable_sidle(struct dispc_device *dispc)
3769 REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */
3772 static u32 dispc_mgr_gamma_size(struct dispc_device *dispc,
3773 enum omap_channel channel)
3775 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3777 if (!dispc->feat->has_gamma_table)
3783 static void dispc_mgr_write_gamma_table(struct dispc_device *dispc,
3784 enum omap_channel channel)
3786 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3787 u32 *table = dispc->gamma_table[channel];
3790 DSSDBG("%s: channel %d\n", __func__, channel);
3792 for (i = 0; i < gdesc->len; ++i) {
3795 if (gdesc->has_index)
3800 dispc_write_reg(dispc, gdesc->reg, v);
3804 static void dispc_restore_gamma_tables(struct dispc_device *dispc)
3806 DSSDBG("%s()\n", __func__);
3808 if (!dispc->feat->has_gamma_table)
3811 dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD);
3813 dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_DIGIT);
3815 if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
3816 dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD2);
3818 if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
3819 dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD3);
3822 static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = {
3823 { .red = 0, .green = 0, .blue = 0, },
3824 { .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, },
3827 static void dispc_mgr_set_gamma(struct dispc_device *dispc,
3828 enum omap_channel channel,
3829 const struct drm_color_lut *lut,
3830 unsigned int length)
3832 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3833 u32 *table = dispc->gamma_table[channel];
3836 DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__,
3837 channel, length, gdesc->len);
3839 if (!dispc->feat->has_gamma_table)
3842 if (lut == NULL || length < 2) {
3843 lut = dispc_mgr_gamma_default_lut;
3844 length = ARRAY_SIZE(dispc_mgr_gamma_default_lut);
3847 for (i = 0; i < length - 1; ++i) {
3848 uint first = i * (gdesc->len - 1) / (length - 1);
3849 uint last = (i + 1) * (gdesc->len - 1) / (length - 1);
3850 uint w = last - first;
3857 for (j = 0; j <= w; j++) {
3858 r = (lut[i].red * (w - j) + lut[i+1].red * j) / w;
3859 g = (lut[i].green * (w - j) + lut[i+1].green * j) / w;
3860 b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w;
3862 r >>= 16 - gdesc->bits;
3863 g >>= 16 - gdesc->bits;
3864 b >>= 16 - gdesc->bits;
3866 table[first + j] = (r << (gdesc->bits * 2)) |
3867 (g << gdesc->bits) | b;
3871 if (dispc->is_enabled)
3872 dispc_mgr_write_gamma_table(dispc, channel);
3875 static int dispc_init_gamma_tables(struct dispc_device *dispc)
3879 if (!dispc->feat->has_gamma_table)
3882 for (channel = 0; channel < ARRAY_SIZE(dispc->gamma_table); channel++) {
3883 const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3886 if (channel == OMAP_DSS_CHANNEL_LCD2 &&
3887 !dispc_has_feature(dispc, FEAT_MGR_LCD2))
3890 if (channel == OMAP_DSS_CHANNEL_LCD3 &&
3891 !dispc_has_feature(dispc, FEAT_MGR_LCD3))
3894 gt = devm_kmalloc_array(&dispc->pdev->dev, gdesc->len,
3895 sizeof(u32), GFP_KERNEL);
3899 dispc->gamma_table[channel] = gt;
3901 dispc_mgr_set_gamma(dispc, channel, NULL, 0);
3906 static void _omap_dispc_initial_config(struct dispc_device *dispc)
3910 /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3911 if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
3912 l = dispc_read_reg(dispc, DISPC_DIVISOR);
3913 /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3914 l = FLD_MOD(l, 1, 0, 0);
3915 l = FLD_MOD(l, 1, 23, 16);
3916 dispc_write_reg(dispc, DISPC_DIVISOR, l);
3918 dispc->core_clk_rate = dispc_fclk_rate(dispc);
3921 /* Use gamma table mode, instead of palette mode */
3922 if (dispc->feat->has_gamma_table)
3923 REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 3, 3);
3925 /* For older DSS versions (FEAT_FUNCGATED) this enables
3926 * func-clock auto-gating. For newer versions
3927 * (dispc->feat->has_gamma_table) this enables tv-out gamma tables.
3929 if (dispc_has_feature(dispc, FEAT_FUNCGATED) ||
3930 dispc->feat->has_gamma_table)
3931 REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 9, 9);
3933 dispc_setup_color_conv_coef(dispc);
3935 dispc_set_loadmode(dispc, OMAP_DSS_LOAD_FRAME_ONLY);
3937 dispc_init_fifos(dispc);
3939 dispc_configure_burst_sizes(dispc);
3941 dispc_ovl_enable_zorder_planes(dispc);
3943 if (dispc->feat->mstandby_workaround)
3944 REG_FLD_MOD(dispc, DISPC_MSTANDBY_CTRL, 1, 0, 0);
3946 if (dispc_has_feature(dispc, FEAT_MFLAG))
3947 dispc_init_mflag(dispc);
3950 static const enum dispc_feature_id omap2_dispc_features_list[] = {
3952 FEAT_LCDENABLESIGNAL,
3955 FEAT_ROWREPEATENABLE,
3959 static const enum dispc_feature_id omap3_dispc_features_list[] = {
3961 FEAT_LCDENABLESIGNAL,
3964 FEAT_LINEBUFFERSPLIT,
3965 FEAT_ROWREPEATENABLE,
3970 FEAT_ALPHA_FIXED_ZORDER,
3972 FEAT_OMAP3_DSI_FIFO_BUG,
3975 static const enum dispc_feature_id am43xx_dispc_features_list[] = {
3977 FEAT_LCDENABLESIGNAL,
3980 FEAT_LINEBUFFERSPLIT,
3981 FEAT_ROWREPEATENABLE,
3986 FEAT_ALPHA_FIXED_ZORDER,
3990 static const enum dispc_feature_id omap4_dispc_features_list[] = {
3993 FEAT_HANDLE_UV_SEPARATE,
3998 FEAT_ALPHA_FREE_ZORDER,
4003 static const enum dispc_feature_id omap5_dispc_features_list[] = {
4007 FEAT_HANDLE_UV_SEPARATE,
4012 FEAT_ALPHA_FREE_ZORDER,
4018 static const struct dss_reg_field omap2_dispc_reg_fields[] = {
4019 [FEAT_REG_FIRHINC] = { 11, 0 },
4020 [FEAT_REG_FIRVINC] = { 27, 16 },
4021 [FEAT_REG_FIFOLOWTHRESHOLD] = { 8, 0 },
4022 [FEAT_REG_FIFOHIGHTHRESHOLD] = { 24, 16 },
4023 [FEAT_REG_FIFOSIZE] = { 8, 0 },
4024 [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
4025 [FEAT_REG_VERTICALACCU] = { 25, 16 },
4028 static const struct dss_reg_field omap3_dispc_reg_fields[] = {
4029 [FEAT_REG_FIRHINC] = { 12, 0 },
4030 [FEAT_REG_FIRVINC] = { 28, 16 },
4031 [FEAT_REG_FIFOLOWTHRESHOLD] = { 11, 0 },
4032 [FEAT_REG_FIFOHIGHTHRESHOLD] = { 27, 16 },
4033 [FEAT_REG_FIFOSIZE] = { 10, 0 },
4034 [FEAT_REG_HORIZONTALACCU] = { 9, 0 },
4035 [FEAT_REG_VERTICALACCU] = { 25, 16 },
4038 static const struct dss_reg_field omap4_dispc_reg_fields[] = {
4039 [FEAT_REG_FIRHINC] = { 12, 0 },
4040 [FEAT_REG_FIRVINC] = { 28, 16 },
4041 [FEAT_REG_FIFOLOWTHRESHOLD] = { 15, 0 },
4042 [FEAT_REG_FIFOHIGHTHRESHOLD] = { 31, 16 },
4043 [FEAT_REG_FIFOSIZE] = { 15, 0 },
4044 [FEAT_REG_HORIZONTALACCU] = { 10, 0 },
4045 [FEAT_REG_VERTICALACCU] = { 26, 16 },
4048 static const enum omap_overlay_caps omap2_dispc_overlay_caps[] = {
4050 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4052 /* OMAP_DSS_VIDEO1 */
4053 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4054 OMAP_DSS_OVL_CAP_REPLICATION,
4056 /* OMAP_DSS_VIDEO2 */
4057 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4058 OMAP_DSS_OVL_CAP_REPLICATION,
4061 static const enum omap_overlay_caps omap3430_dispc_overlay_caps[] = {
4063 OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_POS |
4064 OMAP_DSS_OVL_CAP_REPLICATION,
4066 /* OMAP_DSS_VIDEO1 */
4067 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4068 OMAP_DSS_OVL_CAP_REPLICATION,
4070 /* OMAP_DSS_VIDEO2 */
4071 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4072 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4075 static const enum omap_overlay_caps omap3630_dispc_overlay_caps[] = {
4077 OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
4078 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4080 /* OMAP_DSS_VIDEO1 */
4081 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4082 OMAP_DSS_OVL_CAP_REPLICATION,
4084 /* OMAP_DSS_VIDEO2 */
4085 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4086 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_POS |
4087 OMAP_DSS_OVL_CAP_REPLICATION,
4090 static const enum omap_overlay_caps omap4_dispc_overlay_caps[] = {
4092 OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
4093 OMAP_DSS_OVL_CAP_ZORDER | OMAP_DSS_OVL_CAP_POS |
4094 OMAP_DSS_OVL_CAP_REPLICATION,
4096 /* OMAP_DSS_VIDEO1 */
4097 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4098 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
4099 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4101 /* OMAP_DSS_VIDEO2 */
4102 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4103 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
4104 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4106 /* OMAP_DSS_VIDEO3 */
4107 OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4108 OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
4109 OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4112 #define COLOR_ARRAY(arr...) (const u32[]) { arr, 0 }
4114 static const u32 *omap2_dispc_supported_color_modes[] = {
4118 DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
4119 DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888),
4121 /* OMAP_DSS_VIDEO1 */
4123 DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4124 DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
4127 /* OMAP_DSS_VIDEO2 */
4129 DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4130 DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
4134 static const u32 *omap3_dispc_supported_color_modes[] = {
4137 DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
4138 DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4139 DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
4140 DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
4142 /* OMAP_DSS_VIDEO1 */
4144 DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888,
4145 DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
4146 DRM_FORMAT_YUYV, DRM_FORMAT_UYVY),
4148 /* OMAP_DSS_VIDEO2 */
4150 DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
4151 DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4152 DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
4153 DRM_FORMAT_UYVY, DRM_FORMAT_ARGB8888,
4154 DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
4157 static const u32 *omap4_dispc_supported_color_modes[] = {
4160 DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
4161 DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4162 DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
4163 DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888,
4164 DRM_FORMAT_ARGB1555, DRM_FORMAT_XRGB4444,
4165 DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB1555),
4167 /* OMAP_DSS_VIDEO1 */
4169 DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4170 DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4171 DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4172 DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4173 DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4174 DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4175 DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4176 DRM_FORMAT_RGBX8888),
4178 /* OMAP_DSS_VIDEO2 */
4180 DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4181 DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4182 DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4183 DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4184 DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4185 DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4186 DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4187 DRM_FORMAT_RGBX8888),
4189 /* OMAP_DSS_VIDEO3 */
4191 DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4192 DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4193 DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4194 DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4195 DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4196 DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4197 DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4198 DRM_FORMAT_RGBX8888),
4202 DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4203 DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4204 DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4205 DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4206 DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4207 DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4208 DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4209 DRM_FORMAT_RGBX8888),
4212 static const u32 omap3_dispc_supported_scaler_color_modes[] = {
4213 DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_YUYV,
4218 static const struct dispc_features omap24xx_dispc_feats = {
4225 .mgr_width_start = 10,
4226 .mgr_height_start = 26,
4227 .mgr_width_max = 2048,
4228 .mgr_height_max = 2048,
4229 .max_lcd_pclk = 66500000,
4232 * Assume the line width buffer to be 768 pixels as OMAP2 DISPC scaler
4233 * cannot scale an image width larger than 768.
4235 .max_line_width = 768,
4237 .calc_scaling = dispc_ovl_calc_scaling_24xx,
4238 .calc_core_clk = calc_core_clk_24xx,
4240 .features = omap2_dispc_features_list,
4241 .num_features = ARRAY_SIZE(omap2_dispc_features_list),
4242 .reg_fields = omap2_dispc_reg_fields,
4243 .num_reg_fields = ARRAY_SIZE(omap2_dispc_reg_fields),
4244 .overlay_caps = omap2_dispc_overlay_caps,
4245 .supported_color_modes = omap2_dispc_supported_color_modes,
4246 .supported_scaler_color_modes = COLOR_ARRAY(DRM_FORMAT_XRGB8888),
4249 .buffer_size_unit = 1,
4250 .burst_size_unit = 8,
4251 .no_framedone_tv = true,
4252 .set_max_preload = false,
4253 .last_pixel_inc_missing = true,
4256 static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
4263 .mgr_width_start = 10,
4264 .mgr_height_start = 26,
4265 .mgr_width_max = 2048,
4266 .mgr_height_max = 2048,
4267 .max_lcd_pclk = 173000000,
4268 .max_tv_pclk = 59000000,
4270 .max_line_width = 1024,
4272 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4273 .calc_core_clk = calc_core_clk_34xx,
4275 .features = omap3_dispc_features_list,
4276 .num_features = ARRAY_SIZE(omap3_dispc_features_list),
4277 .reg_fields = omap3_dispc_reg_fields,
4278 .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
4279 .overlay_caps = omap3430_dispc_overlay_caps,
4280 .supported_color_modes = omap3_dispc_supported_color_modes,
4281 .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
4284 .buffer_size_unit = 1,
4285 .burst_size_unit = 8,
4286 .no_framedone_tv = true,
4287 .set_max_preload = false,
4288 .last_pixel_inc_missing = true,
4291 static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
4298 .mgr_width_start = 10,
4299 .mgr_height_start = 26,
4300 .mgr_width_max = 2048,
4301 .mgr_height_max = 2048,
4302 .max_lcd_pclk = 173000000,
4303 .max_tv_pclk = 59000000,
4305 .max_line_width = 1024,
4307 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4308 .calc_core_clk = calc_core_clk_34xx,
4310 .features = omap3_dispc_features_list,
4311 .num_features = ARRAY_SIZE(omap3_dispc_features_list),
4312 .reg_fields = omap3_dispc_reg_fields,
4313 .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
4314 .overlay_caps = omap3430_dispc_overlay_caps,
4315 .supported_color_modes = omap3_dispc_supported_color_modes,
4316 .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
4319 .buffer_size_unit = 1,
4320 .burst_size_unit = 8,
4321 .no_framedone_tv = true,
4322 .set_max_preload = false,
4323 .last_pixel_inc_missing = true,
4326 static const struct dispc_features omap36xx_dispc_feats = {
4333 .mgr_width_start = 10,
4334 .mgr_height_start = 26,
4335 .mgr_width_max = 2048,
4336 .mgr_height_max = 2048,
4337 .max_lcd_pclk = 173000000,
4338 .max_tv_pclk = 59000000,
4340 .max_line_width = 1024,
4342 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4343 .calc_core_clk = calc_core_clk_34xx,
4345 .features = omap3_dispc_features_list,
4346 .num_features = ARRAY_SIZE(omap3_dispc_features_list),
4347 .reg_fields = omap3_dispc_reg_fields,
4348 .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
4349 .overlay_caps = omap3630_dispc_overlay_caps,
4350 .supported_color_modes = omap3_dispc_supported_color_modes,
4351 .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
4354 .buffer_size_unit = 1,
4355 .burst_size_unit = 8,
4356 .no_framedone_tv = true,
4357 .set_max_preload = false,
4358 .last_pixel_inc_missing = true,
4361 static const struct dispc_features am43xx_dispc_feats = {
4368 .mgr_width_start = 10,
4369 .mgr_height_start = 26,
4370 .mgr_width_max = 2048,
4371 .mgr_height_max = 2048,
4372 .max_lcd_pclk = 173000000,
4373 .max_tv_pclk = 59000000,
4375 .max_line_width = 1024,
4377 .calc_scaling = dispc_ovl_calc_scaling_34xx,
4378 .calc_core_clk = calc_core_clk_34xx,
4380 .features = am43xx_dispc_features_list,
4381 .num_features = ARRAY_SIZE(am43xx_dispc_features_list),
4382 .reg_fields = omap3_dispc_reg_fields,
4383 .num_reg_fields = ARRAY_SIZE(omap3_dispc_reg_fields),
4384 .overlay_caps = omap3430_dispc_overlay_caps,
4385 .supported_color_modes = omap3_dispc_supported_color_modes,
4386 .supported_scaler_color_modes = omap3_dispc_supported_scaler_color_modes,
4389 .buffer_size_unit = 1,
4390 .burst_size_unit = 8,
4391 .no_framedone_tv = true,
4392 .set_max_preload = false,
4393 .last_pixel_inc_missing = true,
4396 static const struct dispc_features omap44xx_dispc_feats = {
4403 .mgr_width_start = 10,
4404 .mgr_height_start = 26,
4405 .mgr_width_max = 2048,
4406 .mgr_height_max = 2048,
4407 .max_lcd_pclk = 170000000,
4408 .max_tv_pclk = 185625000,
4410 .max_line_width = 2048,
4412 .calc_scaling = dispc_ovl_calc_scaling_44xx,
4413 .calc_core_clk = calc_core_clk_44xx,
4415 .features = omap4_dispc_features_list,
4416 .num_features = ARRAY_SIZE(omap4_dispc_features_list),
4417 .reg_fields = omap4_dispc_reg_fields,
4418 .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
4419 .overlay_caps = omap4_dispc_overlay_caps,
4420 .supported_color_modes = omap4_dispc_supported_color_modes,
4423 .buffer_size_unit = 16,
4424 .burst_size_unit = 16,
4425 .gfx_fifo_workaround = true,
4426 .set_max_preload = true,
4427 .supports_sync_align = true,
4428 .has_writeback = true,
4429 .supports_double_pixel = true,
4430 .reverse_ilace_field_order = true,
4431 .has_gamma_table = true,
4432 .has_gamma_i734_bug = true,
4435 static const struct dispc_features omap54xx_dispc_feats = {
4442 .mgr_width_start = 11,
4443 .mgr_height_start = 27,
4444 .mgr_width_max = 4096,
4445 .mgr_height_max = 4096,
4446 .max_lcd_pclk = 170000000,
4447 .max_tv_pclk = 186000000,
4449 .max_line_width = 2048,
4451 .calc_scaling = dispc_ovl_calc_scaling_44xx,
4452 .calc_core_clk = calc_core_clk_44xx,
4454 .features = omap5_dispc_features_list,
4455 .num_features = ARRAY_SIZE(omap5_dispc_features_list),
4456 .reg_fields = omap4_dispc_reg_fields,
4457 .num_reg_fields = ARRAY_SIZE(omap4_dispc_reg_fields),
4458 .overlay_caps = omap4_dispc_overlay_caps,
4459 .supported_color_modes = omap4_dispc_supported_color_modes,
4462 .buffer_size_unit = 16,
4463 .burst_size_unit = 16,
4464 .gfx_fifo_workaround = true,
4465 .mstandby_workaround = true,
4466 .set_max_preload = true,
4467 .supports_sync_align = true,
4468 .has_writeback = true,
4469 .supports_double_pixel = true,
4470 .reverse_ilace_field_order = true,
4471 .has_gamma_table = true,
4472 .has_gamma_i734_bug = true,
4475 static irqreturn_t dispc_irq_handler(int irq, void *arg)
4477 struct dispc_device *dispc = arg;
4479 if (!dispc->is_enabled)
4482 return dispc->user_handler(irq, dispc->user_data);
4485 static int dispc_request_irq(struct dispc_device *dispc, irq_handler_t handler,
4490 if (dispc->user_handler != NULL)
4493 dispc->user_handler = handler;
4494 dispc->user_data = dev_id;
4496 /* ensure the dispc_irq_handler sees the values above */
4499 r = devm_request_irq(&dispc->pdev->dev, dispc->irq, dispc_irq_handler,
4500 IRQF_SHARED, "OMAP DISPC", dispc);
4502 dispc->user_handler = NULL;
4503 dispc->user_data = NULL;
4509 static void dispc_free_irq(struct dispc_device *dispc, void *dev_id)
4511 devm_free_irq(&dispc->pdev->dev, dispc->irq, dispc);
4513 dispc->user_handler = NULL;
4514 dispc->user_data = NULL;
4517 static u32 dispc_get_memory_bandwidth_limit(struct dispc_device *dispc)
4521 /* Optional maximum memory bandwidth */
4522 of_property_read_u32(dispc->pdev->dev.of_node, "max-memory-bandwidth",
4529 * Workaround for errata i734 in DSS dispc
4530 * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
4532 * For gamma tables to work on LCD1 the GFX plane has to be used at
4533 * least once after DSS HW has come out of reset. The workaround
4534 * sets up a minimal LCD setup with GFX plane and waits for one
4535 * vertical sync irq before disabling the setup and continuing with
4536 * the context restore. The physical outputs are gated during the
4537 * operation. This workaround requires that gamma table's LOADMODE
4538 * is set to 0x2 in DISPC_CONTROL1 register.
4541 * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
4542 * Literature Number: SWPZ037E
4543 * Or some other relevant errata document for the DSS IP version.
4546 static const struct dispc_errata_i734_data {
4547 struct videomode vm;
4548 struct omap_overlay_info ovli;
4549 struct omap_overlay_manager_info mgri;
4550 struct dss_lcd_mgr_config lcd_conf;
4553 .hactive = 8, .vactive = 1,
4554 .pixelclock = 16000000,
4555 .hsync_len = 8, .hfront_porch = 4, .hback_porch = 4,
4556 .vsync_len = 1, .vfront_porch = 1, .vback_porch = 1,
4558 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
4559 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
4560 DISPLAY_FLAGS_PIXDATA_POSEDGE,
4564 .width = 1, .height = 1,
4565 .fourcc = DRM_FORMAT_XRGB8888,
4566 .rotation = DRM_MODE_ROTATE_0,
4567 .rotation_type = OMAP_DSS_ROT_NONE,
4568 .pos_x = 0, .pos_y = 0,
4569 .out_width = 0, .out_height = 0,
4570 .global_alpha = 0xff,
4571 .pre_mult_alpha = 0,
4576 .trans_enabled = false,
4577 .partial_alpha_enabled = false,
4578 .cpr_enable = false,
4581 .io_pad_mode = DSS_IO_PAD_MODE_BYPASS,
4583 .fifohandcheck = false,
4588 .video_port_width = 24,
4589 .lcden_sig_polarity = 0,
4593 static struct i734_buf {
4599 static int dispc_errata_i734_wa_init(struct dispc_device *dispc)
4601 if (!dispc->feat->has_gamma_i734_bug)
4604 i734_buf.size = i734.ovli.width * i734.ovli.height *
4605 color_mode_to_bpp(i734.ovli.fourcc) / 8;
4607 i734_buf.vaddr = dma_alloc_wc(&dispc->pdev->dev, i734_buf.size,
4608 &i734_buf.paddr, GFP_KERNEL);
4609 if (!i734_buf.vaddr) {
4610 dev_err(&dispc->pdev->dev, "%s: dma_alloc_wc failed\n",
4618 static void dispc_errata_i734_wa_fini(struct dispc_device *dispc)
4620 if (!dispc->feat->has_gamma_i734_bug)
4623 dma_free_wc(&dispc->pdev->dev, i734_buf.size, i734_buf.vaddr,
4627 static void dispc_errata_i734_wa(struct dispc_device *dispc)
4629 u32 framedone_irq = dispc_mgr_get_framedone_irq(dispc,
4630 OMAP_DSS_CHANNEL_LCD);
4631 struct omap_overlay_info ovli;
4632 struct dss_lcd_mgr_config lcd_conf;
4636 if (!dispc->feat->has_gamma_i734_bug)
4639 gatestate = REG_GET(dispc, DISPC_CONFIG, 8, 4);
4642 ovli.paddr = i734_buf.paddr;
4643 lcd_conf = i734.lcd_conf;
4645 /* Gate all LCD1 outputs */
4646 REG_FLD_MOD(dispc, DISPC_CONFIG, 0x1f, 8, 4);
4648 /* Setup and enable GFX plane */
4649 dispc_ovl_setup(dispc, OMAP_DSS_GFX, &ovli, &i734.vm, false,
4650 OMAP_DSS_CHANNEL_LCD);
4651 dispc_ovl_enable(dispc, OMAP_DSS_GFX, true);
4653 /* Set up and enable display manager for LCD1 */
4654 dispc_mgr_setup(dispc, OMAP_DSS_CHANNEL_LCD, &i734.mgri);
4655 dispc_calc_clock_rates(dispc, dss_get_dispc_clk_rate(dispc->dss),
4656 &lcd_conf.clock_info);
4657 dispc_mgr_set_lcd_config(dispc, OMAP_DSS_CHANNEL_LCD, &lcd_conf);
4658 dispc_mgr_set_timings(dispc, OMAP_DSS_CHANNEL_LCD, &i734.vm);
4660 dispc_clear_irqstatus(dispc, framedone_irq);
4662 /* Enable and shut the channel to produce just one frame */
4663 dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, true);
4664 dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, false);
4666 /* Busy wait for framedone. We can't fiddle with irq handlers
4667 * in PM resume. Typically the loop runs less than 5 times and
4668 * waits less than a micro second.
4671 while (!(dispc_read_irqstatus(dispc) & framedone_irq)) {
4672 if (count++ > 10000) {
4673 dev_err(&dispc->pdev->dev, "%s: framedone timeout\n",
4678 dispc_ovl_enable(dispc, OMAP_DSS_GFX, false);
4680 /* Clear all irq bits before continuing */
4681 dispc_clear_irqstatus(dispc, 0xffffffff);
4683 /* Restore the original state to LCD1 output gates */
4684 REG_FLD_MOD(dispc, DISPC_CONFIG, gatestate, 8, 4);
4687 static const struct dispc_ops dispc_ops = {
4688 .read_irqstatus = dispc_read_irqstatus,
4689 .clear_irqstatus = dispc_clear_irqstatus,
4690 .write_irqenable = dispc_write_irqenable,
4692 .request_irq = dispc_request_irq,
4693 .free_irq = dispc_free_irq,
4695 .runtime_get = dispc_runtime_get,
4696 .runtime_put = dispc_runtime_put,
4698 .get_num_ovls = dispc_get_num_ovls,
4699 .get_num_mgrs = dispc_get_num_mgrs,
4701 .get_memory_bandwidth_limit = dispc_get_memory_bandwidth_limit,
4703 .mgr_enable = dispc_mgr_enable,
4704 .mgr_is_enabled = dispc_mgr_is_enabled,
4705 .mgr_get_vsync_irq = dispc_mgr_get_vsync_irq,
4706 .mgr_get_framedone_irq = dispc_mgr_get_framedone_irq,
4707 .mgr_get_sync_lost_irq = dispc_mgr_get_sync_lost_irq,
4708 .mgr_go_busy = dispc_mgr_go_busy,
4709 .mgr_go = dispc_mgr_go,
4710 .mgr_set_lcd_config = dispc_mgr_set_lcd_config,
4711 .mgr_check_timings = dispc_mgr_check_timings,
4712 .mgr_set_timings = dispc_mgr_set_timings,
4713 .mgr_setup = dispc_mgr_setup,
4714 .mgr_gamma_size = dispc_mgr_gamma_size,
4715 .mgr_set_gamma = dispc_mgr_set_gamma,
4717 .ovl_enable = dispc_ovl_enable,
4718 .ovl_setup = dispc_ovl_setup,
4719 .ovl_get_color_modes = dispc_ovl_get_color_modes,
4721 .wb_get_framedone_irq = dispc_wb_get_framedone_irq,
4722 .wb_setup = dispc_wb_setup,
4723 .has_writeback = dispc_has_writeback,
4724 .wb_go_busy = dispc_wb_go_busy,
4725 .wb_go = dispc_wb_go,
4728 /* DISPC HW IP initialisation */
4729 static const struct of_device_id dispc_of_match[] = {
4730 { .compatible = "ti,omap2-dispc", .data = &omap24xx_dispc_feats },
4731 { .compatible = "ti,omap3-dispc", .data = &omap36xx_dispc_feats },
4732 { .compatible = "ti,omap4-dispc", .data = &omap44xx_dispc_feats },
4733 { .compatible = "ti,omap5-dispc", .data = &omap54xx_dispc_feats },
4734 { .compatible = "ti,dra7-dispc", .data = &omap54xx_dispc_feats },
4738 static const struct soc_device_attribute dispc_soc_devices[] = {
4739 { .machine = "OMAP3[45]*",
4740 .revision = "ES[12].?", .data = &omap34xx_rev1_0_dispc_feats },
4741 { .machine = "OMAP3[45]*", .data = &omap34xx_rev3_0_dispc_feats },
4742 { .machine = "AM35*", .data = &omap34xx_rev3_0_dispc_feats },
4743 { .machine = "AM43*", .data = &am43xx_dispc_feats },
4747 static int dispc_bind(struct device *dev, struct device *master, void *data)
4749 struct platform_device *pdev = to_platform_device(dev);
4750 const struct soc_device_attribute *soc;
4751 struct dss_device *dss = dss_get_device(master);
4752 struct dispc_device *dispc;
4755 struct resource *dispc_mem;
4756 struct device_node *np = pdev->dev.of_node;
4758 dispc = kzalloc(sizeof(*dispc), GFP_KERNEL);
4763 platform_set_drvdata(pdev, dispc);
4767 * The OMAP3-based models can't be told apart using the compatible
4768 * string, use SoC device matching.
4770 soc = soc_device_match(dispc_soc_devices);
4772 dispc->feat = soc->data;
4774 dispc->feat = of_match_device(dispc_of_match, &pdev->dev)->data;
4776 r = dispc_errata_i734_wa_init(dispc);
4780 dispc_mem = platform_get_resource(dispc->pdev, IORESOURCE_MEM, 0);
4781 dispc->base = devm_ioremap_resource(&pdev->dev, dispc_mem);
4782 if (IS_ERR(dispc->base)) {
4783 r = PTR_ERR(dispc->base);
4787 dispc->irq = platform_get_irq(dispc->pdev, 0);
4788 if (dispc->irq < 0) {
4789 DSSERR("platform_get_irq failed\n");
4794 if (np && of_property_read_bool(np, "syscon-pol")) {
4795 dispc->syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
4796 if (IS_ERR(dispc->syscon_pol)) {
4797 dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
4798 r = PTR_ERR(dispc->syscon_pol);
4802 if (of_property_read_u32_index(np, "syscon-pol", 1,
4803 &dispc->syscon_pol_offset)) {
4804 dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
4810 r = dispc_init_gamma_tables(dispc);
4814 pm_runtime_enable(&pdev->dev);
4816 r = dispc_runtime_get(dispc);
4818 goto err_runtime_get;
4820 _omap_dispc_initial_config(dispc);
4822 rev = dispc_read_reg(dispc, DISPC_REVISION);
4823 dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
4824 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4826 dispc_runtime_put(dispc);
4829 dss->dispc_ops = &dispc_ops;
4831 dispc->debugfs = dss_debugfs_create_file(dss, "dispc", dispc_dump_regs,
4837 pm_runtime_disable(&pdev->dev);
4843 static void dispc_unbind(struct device *dev, struct device *master, void *data)
4845 struct dispc_device *dispc = dev_get_drvdata(dev);
4846 struct dss_device *dss = dispc->dss;
4848 dss_debugfs_remove_file(dispc->debugfs);
4851 dss->dispc_ops = NULL;
4853 pm_runtime_disable(dev);
4855 dispc_errata_i734_wa_fini(dispc);
4860 static const struct component_ops dispc_component_ops = {
4862 .unbind = dispc_unbind,
4865 static int dispc_probe(struct platform_device *pdev)
4867 return component_add(&pdev->dev, &dispc_component_ops);
4870 static int dispc_remove(struct platform_device *pdev)
4872 component_del(&pdev->dev, &dispc_component_ops);
4876 static int dispc_runtime_suspend(struct device *dev)
4878 struct dispc_device *dispc = dev_get_drvdata(dev);
4880 dispc->is_enabled = false;
4881 /* ensure the dispc_irq_handler sees the is_enabled value */
4883 /* wait for current handler to finish before turning the DISPC off */
4884 synchronize_irq(dispc->irq);
4886 dispc_save_context(dispc);
4891 static int dispc_runtime_resume(struct device *dev)
4893 struct dispc_device *dispc = dev_get_drvdata(dev);
4896 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4897 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4898 * _omap_dispc_initial_config(). We can thus use it to detect if
4899 * we have lost register context.
4901 if (REG_GET(dispc, DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4902 _omap_dispc_initial_config(dispc);
4904 dispc_errata_i734_wa(dispc);
4906 dispc_restore_context(dispc);
4908 dispc_restore_gamma_tables(dispc);
4911 dispc->is_enabled = true;
4912 /* ensure the dispc_irq_handler sees the is_enabled value */
4918 static const struct dev_pm_ops dispc_pm_ops = {
4919 .runtime_suspend = dispc_runtime_suspend,
4920 .runtime_resume = dispc_runtime_resume,
4921 SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
4924 struct platform_driver omap_dispchw_driver = {
4925 .probe = dispc_probe,
4926 .remove = dispc_remove,
4928 .name = "omapdss_dispc",
4929 .pm = &dispc_pm_ops,
4930 .of_match_table = dispc_of_match,
4931 .suppress_bind_attrs = true,