xref: /openbmc/linux/drivers/gpu/drm/omapdrm/dss/dispc.c (revision 6e366c28)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2009 Nokia Corporation
4  * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
5  *
6  * Some code and ideas taken from drivers/video/omap/ driver
7  * by Imre Deak.
8  */
9 
10 #define DSS_SUBSYS_NAME "DISPC"
11 
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>
17 #include <linux/io.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>
28 #include <linux/of.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>
34 
35 #include "omapdss.h"
36 #include "dss.h"
37 #include "dispc.h"
38 
39 struct dispc_device;
40 
41 /* DISPC */
42 #define DISPC_SZ_REGS			SZ_4K
43 
44 enum omap_burst_size {
45 	BURST_SIZE_X2 = 0,
46 	BURST_SIZE_X4 = 1,
47 	BURST_SIZE_X8 = 2,
48 };
49 
50 #define REG_GET(dispc, idx, start, end) \
51 	FLD_GET(dispc_read_reg(dispc, idx), start, end)
52 
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))
56 
57 /* DISPC has feature id */
58 enum dispc_feature_id {
59 	FEAT_LCDENABLEPOL,
60 	FEAT_LCDENABLESIGNAL,
61 	FEAT_PCKFREEENABLE,
62 	FEAT_FUNCGATED,
63 	FEAT_MGR_LCD2,
64 	FEAT_MGR_LCD3,
65 	FEAT_LINEBUFFERSPLIT,
66 	FEAT_ROWREPEATENABLE,
67 	FEAT_RESIZECONF,
68 	/* Independent core clk divider */
69 	FEAT_CORE_CLK_DIV,
70 	FEAT_HANDLE_UV_SEPARATE,
71 	FEAT_ATTR2,
72 	FEAT_CPR,
73 	FEAT_PRELOAD,
74 	FEAT_FIR_COEF_V,
75 	FEAT_ALPHA_FIXED_ZORDER,
76 	FEAT_ALPHA_FREE_ZORDER,
77 	FEAT_FIFO_MERGE,
78 	/* An unknown HW bug causing the normal FIFO thresholds not to work */
79 	FEAT_OMAP3_DSI_FIFO_BUG,
80 	FEAT_BURST_2D,
81 	FEAT_MFLAG,
82 };
83 
84 struct dispc_features {
85 	u8 sw_start;
86 	u8 fp_start;
87 	u8 bp_start;
88 	u16 sw_max;
89 	u16 vp_max;
90 	u16 hp_max;
91 	u8 mgr_width_start;
92 	u8 mgr_height_start;
93 	u16 mgr_width_max;
94 	u16 mgr_height_max;
95 	unsigned long max_lcd_pclk;
96 	unsigned long max_tv_pclk;
97 	unsigned int max_downscale;
98 	unsigned int max_line_width;
99 	unsigned int min_pcd;
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,
109 		bool mem_to_mem);
110 	u8 num_fifos;
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 	unsigned int num_mgrs;
118 	unsigned int num_ovls;
119 	unsigned int buffer_size_unit;
120 	unsigned int burst_size_unit;
121 
122 	/* swap GFX & WB fifos */
123 	bool gfx_fifo_workaround:1;
124 
125 	/* no DISPC_IRQ_FRAMEDONETV on this SoC */
126 	bool no_framedone_tv:1;
127 
128 	/* revert to the OMAP4 mechanism of DISPC Smart Standby operation */
129 	bool mstandby_workaround:1;
130 
131 	bool set_max_preload:1;
132 
133 	/* PIXEL_INC is not added to the last pixel of a line */
134 	bool last_pixel_inc_missing:1;
135 
136 	/* POL_FREQ has ALIGN bit */
137 	bool supports_sync_align:1;
138 
139 	bool has_writeback:1;
140 
141 	bool supports_double_pixel:1;
142 
143 	/*
144 	 * Field order for VENC is different than HDMI. We should handle this in
145 	 * some intelligent manner, but as the SoCs have either HDMI or VENC,
146 	 * never both, we can just use this flag for now.
147 	 */
148 	bool reverse_ilace_field_order:1;
149 
150 	bool has_gamma_table:1;
151 
152 	bool has_gamma_i734_bug:1;
153 };
154 
155 #define DISPC_MAX_NR_FIFOS 5
156 #define DISPC_MAX_CHANNEL_GAMMA 4
157 
158 struct dispc_device {
159 	struct platform_device *pdev;
160 	void __iomem    *base;
161 	struct dss_device *dss;
162 
163 	struct dss_debugfs_entry *debugfs;
164 
165 	int irq;
166 	irq_handler_t user_handler;
167 	void *user_data;
168 
169 	unsigned long core_clk_rate;
170 	unsigned long tv_pclk_rate;
171 
172 	u32 fifo_size[DISPC_MAX_NR_FIFOS];
173 	/* maps which plane is using a fifo. fifo-id -> plane-id */
174 	int fifo_assignment[DISPC_MAX_NR_FIFOS];
175 
176 	bool		ctx_valid;
177 	u32		ctx[DISPC_SZ_REGS / sizeof(u32)];
178 
179 	u32 *gamma_table[DISPC_MAX_CHANNEL_GAMMA];
180 
181 	const struct dispc_features *feat;
182 
183 	bool is_enabled;
184 
185 	struct regmap *syscon_pol;
186 	u32 syscon_pol_offset;
187 };
188 
189 enum omap_color_component {
190 	/* used for all color formats for OMAP3 and earlier
191 	 * and for RGB and Y color component on OMAP4
192 	 */
193 	DISPC_COLOR_COMPONENT_RGB_Y		= 1 << 0,
194 	/* used for UV component for
195 	 * DRM_FORMAT_YUYV, DRM_FORMAT_UYVY, DRM_FORMAT_NV12
196 	 * color formats on OMAP4
197 	 */
198 	DISPC_COLOR_COMPONENT_UV		= 1 << 1,
199 };
200 
201 enum mgr_reg_fields {
202 	DISPC_MGR_FLD_ENABLE,
203 	DISPC_MGR_FLD_STNTFT,
204 	DISPC_MGR_FLD_GO,
205 	DISPC_MGR_FLD_TFTDATALINES,
206 	DISPC_MGR_FLD_STALLMODE,
207 	DISPC_MGR_FLD_TCKENABLE,
208 	DISPC_MGR_FLD_TCKSELECTION,
209 	DISPC_MGR_FLD_CPR,
210 	DISPC_MGR_FLD_FIFOHANDCHECK,
211 	/* used to maintain a count of the above fields */
212 	DISPC_MGR_FLD_NUM,
213 };
214 
215 /* DISPC register field id */
216 enum dispc_feat_reg_field {
217 	FEAT_REG_FIRHINC,
218 	FEAT_REG_FIRVINC,
219 	FEAT_REG_FIFOHIGHTHRESHOLD,
220 	FEAT_REG_FIFOLOWTHRESHOLD,
221 	FEAT_REG_FIFOSIZE,
222 	FEAT_REG_HORIZONTALACCU,
223 	FEAT_REG_VERTICALACCU,
224 };
225 
226 struct dispc_reg_field {
227 	u16 reg;
228 	u8 high;
229 	u8 low;
230 };
231 
232 struct dispc_gamma_desc {
233 	u32 len;
234 	u32 bits;
235 	u16 reg;
236 	bool has_index;
237 };
238 
239 static const struct {
240 	const char *name;
241 	u32 vsync_irq;
242 	u32 framedone_irq;
243 	u32 sync_lost_irq;
244 	struct dispc_gamma_desc gamma;
245 	struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM];
246 } mgr_desc[] = {
247 	[OMAP_DSS_CHANNEL_LCD] = {
248 		.name		= "LCD",
249 		.vsync_irq	= DISPC_IRQ_VSYNC,
250 		.framedone_irq	= DISPC_IRQ_FRAMEDONE,
251 		.sync_lost_irq	= DISPC_IRQ_SYNC_LOST,
252 		.gamma		= {
253 			.len	= 256,
254 			.bits	= 8,
255 			.reg	= DISPC_GAMMA_TABLE0,
256 			.has_index = true,
257 		},
258 		.reg_desc	= {
259 			[DISPC_MGR_FLD_ENABLE]		= { DISPC_CONTROL,  0,  0 },
260 			[DISPC_MGR_FLD_STNTFT]		= { DISPC_CONTROL,  3,  3 },
261 			[DISPC_MGR_FLD_GO]		= { DISPC_CONTROL,  5,  5 },
262 			[DISPC_MGR_FLD_TFTDATALINES]	= { DISPC_CONTROL,  9,  8 },
263 			[DISPC_MGR_FLD_STALLMODE]	= { DISPC_CONTROL, 11, 11 },
264 			[DISPC_MGR_FLD_TCKENABLE]	= { DISPC_CONFIG,  10, 10 },
265 			[DISPC_MGR_FLD_TCKSELECTION]	= { DISPC_CONFIG,  11, 11 },
266 			[DISPC_MGR_FLD_CPR]		= { DISPC_CONFIG,  15, 15 },
267 			[DISPC_MGR_FLD_FIFOHANDCHECK]	= { DISPC_CONFIG,  16, 16 },
268 		},
269 	},
270 	[OMAP_DSS_CHANNEL_DIGIT] = {
271 		.name		= "DIGIT",
272 		.vsync_irq	= DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN,
273 		.framedone_irq	= DISPC_IRQ_FRAMEDONETV,
274 		.sync_lost_irq	= DISPC_IRQ_SYNC_LOST_DIGIT,
275 		.gamma		= {
276 			.len	= 1024,
277 			.bits	= 10,
278 			.reg	= DISPC_GAMMA_TABLE2,
279 			.has_index = false,
280 		},
281 		.reg_desc	= {
282 			[DISPC_MGR_FLD_ENABLE]		= { DISPC_CONTROL,  1,  1 },
283 			[DISPC_MGR_FLD_STNTFT]		= { },
284 			[DISPC_MGR_FLD_GO]		= { DISPC_CONTROL,  6,  6 },
285 			[DISPC_MGR_FLD_TFTDATALINES]	= { },
286 			[DISPC_MGR_FLD_STALLMODE]	= { },
287 			[DISPC_MGR_FLD_TCKENABLE]	= { DISPC_CONFIG,  12, 12 },
288 			[DISPC_MGR_FLD_TCKSELECTION]	= { DISPC_CONFIG,  13, 13 },
289 			[DISPC_MGR_FLD_CPR]		= { },
290 			[DISPC_MGR_FLD_FIFOHANDCHECK]	= { DISPC_CONFIG,  16, 16 },
291 		},
292 	},
293 	[OMAP_DSS_CHANNEL_LCD2] = {
294 		.name		= "LCD2",
295 		.vsync_irq	= DISPC_IRQ_VSYNC2,
296 		.framedone_irq	= DISPC_IRQ_FRAMEDONE2,
297 		.sync_lost_irq	= DISPC_IRQ_SYNC_LOST2,
298 		.gamma		= {
299 			.len	= 256,
300 			.bits	= 8,
301 			.reg	= DISPC_GAMMA_TABLE1,
302 			.has_index = true,
303 		},
304 		.reg_desc	= {
305 			[DISPC_MGR_FLD_ENABLE]		= { DISPC_CONTROL2,  0,  0 },
306 			[DISPC_MGR_FLD_STNTFT]		= { DISPC_CONTROL2,  3,  3 },
307 			[DISPC_MGR_FLD_GO]		= { DISPC_CONTROL2,  5,  5 },
308 			[DISPC_MGR_FLD_TFTDATALINES]	= { DISPC_CONTROL2,  9,  8 },
309 			[DISPC_MGR_FLD_STALLMODE]	= { DISPC_CONTROL2, 11, 11 },
310 			[DISPC_MGR_FLD_TCKENABLE]	= { DISPC_CONFIG2,  10, 10 },
311 			[DISPC_MGR_FLD_TCKSELECTION]	= { DISPC_CONFIG2,  11, 11 },
312 			[DISPC_MGR_FLD_CPR]		= { DISPC_CONFIG2,  15, 15 },
313 			[DISPC_MGR_FLD_FIFOHANDCHECK]	= { DISPC_CONFIG2,  16, 16 },
314 		},
315 	},
316 	[OMAP_DSS_CHANNEL_LCD3] = {
317 		.name		= "LCD3",
318 		.vsync_irq	= DISPC_IRQ_VSYNC3,
319 		.framedone_irq	= DISPC_IRQ_FRAMEDONE3,
320 		.sync_lost_irq	= DISPC_IRQ_SYNC_LOST3,
321 		.gamma		= {
322 			.len	= 256,
323 			.bits	= 8,
324 			.reg	= DISPC_GAMMA_TABLE3,
325 			.has_index = true,
326 		},
327 		.reg_desc	= {
328 			[DISPC_MGR_FLD_ENABLE]		= { DISPC_CONTROL3,  0,  0 },
329 			[DISPC_MGR_FLD_STNTFT]		= { DISPC_CONTROL3,  3,  3 },
330 			[DISPC_MGR_FLD_GO]		= { DISPC_CONTROL3,  5,  5 },
331 			[DISPC_MGR_FLD_TFTDATALINES]	= { DISPC_CONTROL3,  9,  8 },
332 			[DISPC_MGR_FLD_STALLMODE]	= { DISPC_CONTROL3, 11, 11 },
333 			[DISPC_MGR_FLD_TCKENABLE]	= { DISPC_CONFIG3,  10, 10 },
334 			[DISPC_MGR_FLD_TCKSELECTION]	= { DISPC_CONFIG3,  11, 11 },
335 			[DISPC_MGR_FLD_CPR]		= { DISPC_CONFIG3,  15, 15 },
336 			[DISPC_MGR_FLD_FIFOHANDCHECK]	= { DISPC_CONFIG3,  16, 16 },
337 		},
338 	},
339 };
340 
341 static unsigned long dispc_fclk_rate(struct dispc_device *dispc);
342 static unsigned long dispc_core_clk_rate(struct dispc_device *dispc);
343 static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
344 					 enum omap_channel channel);
345 static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
346 					 enum omap_channel channel);
347 
348 static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
349 					   enum omap_plane_id plane);
350 static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
351 					   enum omap_plane_id plane);
352 
353 static void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask);
354 
355 static inline void dispc_write_reg(struct dispc_device *dispc, u16 idx, u32 val)
356 {
357 	__raw_writel(val, dispc->base + idx);
358 }
359 
360 static inline u32 dispc_read_reg(struct dispc_device *dispc, u16 idx)
361 {
362 	return __raw_readl(dispc->base + idx);
363 }
364 
365 static u32 mgr_fld_read(struct dispc_device *dispc, enum omap_channel channel,
366 			enum mgr_reg_fields regfld)
367 {
368 	const struct dispc_reg_field *rfld = &mgr_desc[channel].reg_desc[regfld];
369 
370 	return REG_GET(dispc, rfld->reg, rfld->high, rfld->low);
371 }
372 
373 static void mgr_fld_write(struct dispc_device *dispc, enum omap_channel channel,
374 			  enum mgr_reg_fields regfld, int val)
375 {
376 	const struct dispc_reg_field *rfld = &mgr_desc[channel].reg_desc[regfld];
377 
378 	REG_FLD_MOD(dispc, rfld->reg, val, rfld->high, rfld->low);
379 }
380 
381 static int dispc_get_num_ovls(struct dispc_device *dispc)
382 {
383 	return dispc->feat->num_ovls;
384 }
385 
386 static int dispc_get_num_mgrs(struct dispc_device *dispc)
387 {
388 	return dispc->feat->num_mgrs;
389 }
390 
391 static void dispc_get_reg_field(struct dispc_device *dispc,
392 				enum dispc_feat_reg_field id,
393 				u8 *start, u8 *end)
394 {
395 	if (id >= dispc->feat->num_reg_fields)
396 		BUG();
397 
398 	*start = dispc->feat->reg_fields[id].start;
399 	*end = dispc->feat->reg_fields[id].end;
400 }
401 
402 static bool dispc_has_feature(struct dispc_device *dispc,
403 			      enum dispc_feature_id id)
404 {
405 	unsigned int i;
406 
407 	for (i = 0; i < dispc->feat->num_features; i++) {
408 		if (dispc->feat->features[i] == id)
409 			return true;
410 	}
411 
412 	return false;
413 }
414 
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)])
419 
420 static void dispc_save_context(struct dispc_device *dispc)
421 {
422 	int i, j;
423 
424 	DSSDBG("dispc_save_context\n");
425 
426 	SR(dispc, IRQENABLE);
427 	SR(dispc, CONTROL);
428 	SR(dispc, CONFIG);
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)) {
434 		SR(dispc, CONTROL2);
435 		SR(dispc, CONFIG2);
436 	}
437 	if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
438 		SR(dispc, CONTROL3);
439 		SR(dispc, CONFIG3);
440 	}
441 
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)
447 			continue;
448 		SR(dispc, TIMING_H(i));
449 		SR(dispc, TIMING_V(i));
450 		SR(dispc, POL_FREQ(i));
451 		SR(dispc, DIVISORo(i));
452 
453 		SR(dispc, DATA_CYCLE1(i));
454 		SR(dispc, DATA_CYCLE2(i));
455 		SR(dispc, DATA_CYCLE3(i));
456 
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));
461 		}
462 	}
463 
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));
478 			continue;
479 		}
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));
484 
485 		for (j = 0; j < 8; j++)
486 			SR(dispc, OVL_FIR_COEF_H(i, j));
487 
488 		for (j = 0; j < 8; j++)
489 			SR(dispc, OVL_FIR_COEF_HV(i, j));
490 
491 		for (j = 0; j < 5; j++)
492 			SR(dispc, OVL_CONV_COEF(i, j));
493 
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));
497 		}
498 
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));
505 
506 			for (j = 0; j < 8; j++)
507 				SR(dispc, OVL_FIR_COEF_H2(i, j));
508 
509 			for (j = 0; j < 8; j++)
510 				SR(dispc, OVL_FIR_COEF_HV2(i, j));
511 
512 			for (j = 0; j < 8; j++)
513 				SR(dispc, OVL_FIR_COEF_V2(i, j));
514 		}
515 		if (dispc_has_feature(dispc, FEAT_ATTR2))
516 			SR(dispc, OVL_ATTRIBUTES2(i));
517 	}
518 
519 	if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
520 		SR(dispc, DIVISOR);
521 
522 	dispc->ctx_valid = true;
523 
524 	DSSDBG("context saved\n");
525 }
526 
527 static void dispc_restore_context(struct dispc_device *dispc)
528 {
529 	int i, j;
530 
531 	DSSDBG("dispc_restore_context\n");
532 
533 	if (!dispc->ctx_valid)
534 		return;
535 
536 	/*RR(dispc, IRQENABLE);*/
537 	/*RR(dispc, CONTROL);*/
538 	RR(dispc, CONFIG);
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))
544 		RR(dispc, CONFIG2);
545 	if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
546 		RR(dispc, CONFIG3);
547 
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)
553 			continue;
554 		RR(dispc, TIMING_H(i));
555 		RR(dispc, TIMING_V(i));
556 		RR(dispc, POL_FREQ(i));
557 		RR(dispc, DIVISORo(i));
558 
559 		RR(dispc, DATA_CYCLE1(i));
560 		RR(dispc, DATA_CYCLE2(i));
561 		RR(dispc, DATA_CYCLE3(i));
562 
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));
567 		}
568 	}
569 
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));
584 			continue;
585 		}
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));
590 
591 		for (j = 0; j < 8; j++)
592 			RR(dispc, OVL_FIR_COEF_H(i, j));
593 
594 		for (j = 0; j < 8; j++)
595 			RR(dispc, OVL_FIR_COEF_HV(i, j));
596 
597 		for (j = 0; j < 5; j++)
598 			RR(dispc, OVL_CONV_COEF(i, j));
599 
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));
603 		}
604 
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));
611 
612 			for (j = 0; j < 8; j++)
613 				RR(dispc, OVL_FIR_COEF_H2(i, j));
614 
615 			for (j = 0; j < 8; j++)
616 				RR(dispc, OVL_FIR_COEF_HV2(i, j));
617 
618 			for (j = 0; j < 8; j++)
619 				RR(dispc, OVL_FIR_COEF_V2(i, j));
620 		}
621 		if (dispc_has_feature(dispc, FEAT_ATTR2))
622 			RR(dispc, OVL_ATTRIBUTES2(i));
623 	}
624 
625 	if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
626 		RR(dispc, DIVISOR);
627 
628 	/* enable last, because LCD & DIGIT enable are here */
629 	RR(dispc, CONTROL);
630 	if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
631 		RR(dispc, CONTROL2);
632 	if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
633 		RR(dispc, CONTROL3);
634 	/* clear spurious SYNC_LOST_DIGIT interrupts */
635 	dispc_clear_irqstatus(dispc, DISPC_IRQ_SYNC_LOST_DIGIT);
636 
637 	/*
638 	 * enable last so IRQs won't trigger before
639 	 * the context is fully restored
640 	 */
641 	RR(dispc, IRQENABLE);
642 
643 	DSSDBG("context restored\n");
644 }
645 
646 #undef SR
647 #undef RR
648 
649 int dispc_runtime_get(struct dispc_device *dispc)
650 {
651 	int r;
652 
653 	DSSDBG("dispc_runtime_get\n");
654 
655 	r = pm_runtime_get_sync(&dispc->pdev->dev);
656 	WARN_ON(r < 0);
657 	return r < 0 ? r : 0;
658 }
659 
660 void dispc_runtime_put(struct dispc_device *dispc)
661 {
662 	int r;
663 
664 	DSSDBG("dispc_runtime_put\n");
665 
666 	r = pm_runtime_put_sync(&dispc->pdev->dev);
667 	WARN_ON(r < 0 && r != -ENOSYS);
668 }
669 
670 static u32 dispc_mgr_get_vsync_irq(struct dispc_device *dispc,
671 				   enum omap_channel channel)
672 {
673 	return mgr_desc[channel].vsync_irq;
674 }
675 
676 static u32 dispc_mgr_get_framedone_irq(struct dispc_device *dispc,
677 				       enum omap_channel channel)
678 {
679 	if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc->feat->no_framedone_tv)
680 		return 0;
681 
682 	return mgr_desc[channel].framedone_irq;
683 }
684 
685 static u32 dispc_mgr_get_sync_lost_irq(struct dispc_device *dispc,
686 				       enum omap_channel channel)
687 {
688 	return mgr_desc[channel].sync_lost_irq;
689 }
690 
691 static u32 dispc_wb_get_framedone_irq(struct dispc_device *dispc)
692 {
693 	return DISPC_IRQ_FRAMEDONEWB;
694 }
695 
696 static void dispc_mgr_enable(struct dispc_device *dispc,
697 			     enum omap_channel channel, bool enable)
698 {
699 	mgr_fld_write(dispc, channel, DISPC_MGR_FLD_ENABLE, enable);
700 	/* flush posted write */
701 	mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
702 }
703 
704 static bool dispc_mgr_is_enabled(struct dispc_device *dispc,
705 				 enum omap_channel channel)
706 {
707 	return !!mgr_fld_read(dispc, channel, DISPC_MGR_FLD_ENABLE);
708 }
709 
710 static bool dispc_mgr_go_busy(struct dispc_device *dispc,
711 			      enum omap_channel channel)
712 {
713 	return mgr_fld_read(dispc, channel, DISPC_MGR_FLD_GO) == 1;
714 }
715 
716 static void dispc_mgr_go(struct dispc_device *dispc, enum omap_channel channel)
717 {
718 	WARN_ON(!dispc_mgr_is_enabled(dispc, channel));
719 	WARN_ON(dispc_mgr_go_busy(dispc, channel));
720 
721 	DSSDBG("GO %s\n", mgr_desc[channel].name);
722 
723 	mgr_fld_write(dispc, channel, DISPC_MGR_FLD_GO, 1);
724 }
725 
726 static bool dispc_wb_go_busy(struct dispc_device *dispc)
727 {
728 	return REG_GET(dispc, DISPC_CONTROL2, 6, 6) == 1;
729 }
730 
731 static void dispc_wb_go(struct dispc_device *dispc)
732 {
733 	enum omap_plane_id plane = OMAP_DSS_WB;
734 	bool enable, go;
735 
736 	enable = REG_GET(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1;
737 
738 	if (!enable)
739 		return;
740 
741 	go = REG_GET(dispc, DISPC_CONTROL2, 6, 6) == 1;
742 	if (go) {
743 		DSSERR("GO bit not down for WB\n");
744 		return;
745 	}
746 
747 	REG_FLD_MOD(dispc, DISPC_CONTROL2, 1, 6, 6);
748 }
749 
750 static void dispc_ovl_write_firh_reg(struct dispc_device *dispc,
751 				     enum omap_plane_id plane, int reg,
752 				     u32 value)
753 {
754 	dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H(plane, reg), value);
755 }
756 
757 static void dispc_ovl_write_firhv_reg(struct dispc_device *dispc,
758 				      enum omap_plane_id plane, int reg,
759 				      u32 value)
760 {
761 	dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV(plane, reg), value);
762 }
763 
764 static void dispc_ovl_write_firv_reg(struct dispc_device *dispc,
765 				     enum omap_plane_id plane, int reg,
766 				     u32 value)
767 {
768 	dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V(plane, reg), value);
769 }
770 
771 static void dispc_ovl_write_firh2_reg(struct dispc_device *dispc,
772 				      enum omap_plane_id plane, int reg,
773 				      u32 value)
774 {
775 	BUG_ON(plane == OMAP_DSS_GFX);
776 
777 	dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_H2(plane, reg), value);
778 }
779 
780 static void dispc_ovl_write_firhv2_reg(struct dispc_device *dispc,
781 				       enum omap_plane_id plane, int reg,
782 				       u32 value)
783 {
784 	BUG_ON(plane == OMAP_DSS_GFX);
785 
786 	dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_HV2(plane, reg), value);
787 }
788 
789 static void dispc_ovl_write_firv2_reg(struct dispc_device *dispc,
790 				      enum omap_plane_id plane, int reg,
791 				      u32 value)
792 {
793 	BUG_ON(plane == OMAP_DSS_GFX);
794 
795 	dispc_write_reg(dispc, DISPC_OVL_FIR_COEF_V2(plane, reg), value);
796 }
797 
798 static void dispc_ovl_set_scale_coef(struct dispc_device *dispc,
799 				     enum omap_plane_id plane, int fir_hinc,
800 				     int fir_vinc, int five_taps,
801 				     enum omap_color_component color_comp)
802 {
803 	const struct dispc_coef *h_coef, *v_coef;
804 	int i;
805 
806 	h_coef = dispc_ovl_get_scale_coef(fir_hinc, true);
807 	v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps);
808 
809 	if (!h_coef || !v_coef) {
810 		dev_err(&dispc->pdev->dev, "%s: failed to find scale coefs\n",
811 			__func__);
812 		return;
813 	}
814 
815 	for (i = 0; i < 8; i++) {
816 		u32 h, hv;
817 
818 		h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0)
819 			| FLD_VAL(h_coef[i].hc1_vc0, 15, 8)
820 			| FLD_VAL(h_coef[i].hc2_vc1, 23, 16)
821 			| FLD_VAL(h_coef[i].hc3_vc2, 31, 24);
822 		hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0)
823 			| FLD_VAL(v_coef[i].hc1_vc0, 15, 8)
824 			| FLD_VAL(v_coef[i].hc2_vc1, 23, 16)
825 			| FLD_VAL(v_coef[i].hc3_vc2, 31, 24);
826 
827 		if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
828 			dispc_ovl_write_firh_reg(dispc, plane, i, h);
829 			dispc_ovl_write_firhv_reg(dispc, plane, i, hv);
830 		} else {
831 			dispc_ovl_write_firh2_reg(dispc, plane, i, h);
832 			dispc_ovl_write_firhv2_reg(dispc, plane, i, hv);
833 		}
834 
835 	}
836 
837 	if (five_taps) {
838 		for (i = 0; i < 8; i++) {
839 			u32 v;
840 			v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0)
841 				| FLD_VAL(v_coef[i].hc4_vc22, 15, 8);
842 			if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y)
843 				dispc_ovl_write_firv_reg(dispc, plane, i, v);
844 			else
845 				dispc_ovl_write_firv2_reg(dispc, plane, i, v);
846 		}
847 	}
848 }
849 
850 struct csc_coef_yuv2rgb {
851 	int ry, rcb, rcr, gy, gcb, gcr, by, bcb, bcr;
852 	bool full_range;
853 };
854 
855 struct csc_coef_rgb2yuv {
856 	int yr, yg, yb, cbr, cbg, cbb, crr, crg, crb;
857 	bool full_range;
858 };
859 
860 static void dispc_ovl_write_color_conv_coef(struct dispc_device *dispc,
861 					    enum omap_plane_id plane,
862 					    const struct csc_coef_yuv2rgb *ct)
863 {
864 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
865 
866 	dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry));
867 	dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy,  ct->rcb));
868 	dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr));
869 	dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by));
870 	dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb));
871 
872 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
873 
874 #undef CVAL
875 }
876 
877 static void dispc_wb_write_color_conv_coef(struct dispc_device *dispc,
878 					   const struct csc_coef_rgb2yuv *ct)
879 {
880 	const enum omap_plane_id plane = OMAP_DSS_WB;
881 
882 #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0))
883 
884 	dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->yg,  ct->yr));
885 	dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->crr, ct->yb));
886 	dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->crb, ct->crg));
887 	dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->cbg, ct->cbr));
888 	dispc_write_reg(dispc, DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->cbb));
889 
890 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11);
891 
892 #undef CVAL
893 }
894 
895 static void dispc_setup_color_conv_coef(struct dispc_device *dispc)
896 {
897 	int i;
898 	int num_ovl = dispc_get_num_ovls(dispc);
899 
900 	/* YUV -> RGB, ITU-R BT.601, limited range */
901 	const struct csc_coef_yuv2rgb coefs_yuv2rgb_bt601_lim = {
902 		298,    0,  409,	/* ry, rcb, rcr */
903 		298, -100, -208,	/* gy, gcb, gcr */
904 		298,  516,    0,	/* by, bcb, bcr */
905 		false,			/* limited range */
906 	};
907 
908 	/* RGB -> YUV, ITU-R BT.601, limited range */
909 	const struct csc_coef_rgb2yuv coefs_rgb2yuv_bt601_lim = {
910 		 66, 129,  25,		/* yr,   yg,  yb */
911 		-38, -74, 112,		/* cbr, cbg, cbb */
912 		112, -94, -18,		/* crr, crg, crb */
913 		false,			/* limited range */
914 	};
915 
916 	for (i = 1; i < num_ovl; i++)
917 		dispc_ovl_write_color_conv_coef(dispc, i, &coefs_yuv2rgb_bt601_lim);
918 
919 	if (dispc->feat->has_writeback)
920 		dispc_wb_write_color_conv_coef(dispc, &coefs_rgb2yuv_bt601_lim);
921 }
922 
923 static void dispc_ovl_set_ba0(struct dispc_device *dispc,
924 			      enum omap_plane_id plane, u32 paddr)
925 {
926 	dispc_write_reg(dispc, DISPC_OVL_BA0(plane), paddr);
927 }
928 
929 static void dispc_ovl_set_ba1(struct dispc_device *dispc,
930 			      enum omap_plane_id plane, u32 paddr)
931 {
932 	dispc_write_reg(dispc, DISPC_OVL_BA1(plane), paddr);
933 }
934 
935 static void dispc_ovl_set_ba0_uv(struct dispc_device *dispc,
936 				 enum omap_plane_id plane, u32 paddr)
937 {
938 	dispc_write_reg(dispc, DISPC_OVL_BA0_UV(plane), paddr);
939 }
940 
941 static void dispc_ovl_set_ba1_uv(struct dispc_device *dispc,
942 				 enum omap_plane_id plane, u32 paddr)
943 {
944 	dispc_write_reg(dispc, DISPC_OVL_BA1_UV(plane), paddr);
945 }
946 
947 static void dispc_ovl_set_pos(struct dispc_device *dispc,
948 			      enum omap_plane_id plane,
949 			      enum omap_overlay_caps caps, int x, int y)
950 {
951 	u32 val;
952 
953 	if ((caps & OMAP_DSS_OVL_CAP_POS) == 0)
954 		return;
955 
956 	val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0);
957 
958 	dispc_write_reg(dispc, DISPC_OVL_POSITION(plane), val);
959 }
960 
961 static void dispc_ovl_set_input_size(struct dispc_device *dispc,
962 				     enum omap_plane_id plane, int width,
963 				     int height)
964 {
965 	u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
966 
967 	if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB)
968 		dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
969 	else
970 		dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
971 }
972 
973 static void dispc_ovl_set_output_size(struct dispc_device *dispc,
974 				      enum omap_plane_id plane, int width,
975 				      int height)
976 {
977 	u32 val;
978 
979 	BUG_ON(plane == OMAP_DSS_GFX);
980 
981 	val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
982 
983 	if (plane == OMAP_DSS_WB)
984 		dispc_write_reg(dispc, DISPC_OVL_PICTURE_SIZE(plane), val);
985 	else
986 		dispc_write_reg(dispc, DISPC_OVL_SIZE(plane), val);
987 }
988 
989 static void dispc_ovl_set_zorder(struct dispc_device *dispc,
990 				 enum omap_plane_id plane,
991 				 enum omap_overlay_caps caps, u8 zorder)
992 {
993 	if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
994 		return;
995 
996 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26);
997 }
998 
999 static void dispc_ovl_enable_zorder_planes(struct dispc_device *dispc)
1000 {
1001 	int i;
1002 
1003 	if (!dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
1004 		return;
1005 
1006 	for (i = 0; i < dispc_get_num_ovls(dispc); i++)
1007 		REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(i), 1, 25, 25);
1008 }
1009 
1010 static void dispc_ovl_set_pre_mult_alpha(struct dispc_device *dispc,
1011 					 enum omap_plane_id plane,
1012 					 enum omap_overlay_caps caps,
1013 					 bool enable)
1014 {
1015 	if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
1016 		return;
1017 
1018 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28);
1019 }
1020 
1021 static void dispc_ovl_setup_global_alpha(struct dispc_device *dispc,
1022 					 enum omap_plane_id plane,
1023 					 enum omap_overlay_caps caps,
1024 					 u8 global_alpha)
1025 {
1026 	static const unsigned int shifts[] = { 0, 8, 16, 24, };
1027 	int shift;
1028 
1029 	if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
1030 		return;
1031 
1032 	shift = shifts[plane];
1033 	REG_FLD_MOD(dispc, DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift);
1034 }
1035 
1036 static void dispc_ovl_set_pix_inc(struct dispc_device *dispc,
1037 				  enum omap_plane_id plane, s32 inc)
1038 {
1039 	dispc_write_reg(dispc, DISPC_OVL_PIXEL_INC(plane), inc);
1040 }
1041 
1042 static void dispc_ovl_set_row_inc(struct dispc_device *dispc,
1043 				  enum omap_plane_id plane, s32 inc)
1044 {
1045 	dispc_write_reg(dispc, DISPC_OVL_ROW_INC(plane), inc);
1046 }
1047 
1048 static void dispc_ovl_set_color_mode(struct dispc_device *dispc,
1049 				     enum omap_plane_id plane, u32 fourcc)
1050 {
1051 	u32 m = 0;
1052 	if (plane != OMAP_DSS_GFX) {
1053 		switch (fourcc) {
1054 		case DRM_FORMAT_NV12:
1055 			m = 0x0; break;
1056 		case DRM_FORMAT_XRGB4444:
1057 			m = 0x1; break;
1058 		case DRM_FORMAT_RGBA4444:
1059 			m = 0x2; break;
1060 		case DRM_FORMAT_RGBX4444:
1061 			m = 0x4; break;
1062 		case DRM_FORMAT_ARGB4444:
1063 			m = 0x5; break;
1064 		case DRM_FORMAT_RGB565:
1065 			m = 0x6; break;
1066 		case DRM_FORMAT_ARGB1555:
1067 			m = 0x7; break;
1068 		case DRM_FORMAT_XRGB8888:
1069 			m = 0x8; break;
1070 		case DRM_FORMAT_RGB888:
1071 			m = 0x9; break;
1072 		case DRM_FORMAT_YUYV:
1073 			m = 0xa; break;
1074 		case DRM_FORMAT_UYVY:
1075 			m = 0xb; break;
1076 		case DRM_FORMAT_ARGB8888:
1077 			m = 0xc; break;
1078 		case DRM_FORMAT_RGBA8888:
1079 			m = 0xd; break;
1080 		case DRM_FORMAT_RGBX8888:
1081 			m = 0xe; break;
1082 		case DRM_FORMAT_XRGB1555:
1083 			m = 0xf; break;
1084 		default:
1085 			BUG(); return;
1086 		}
1087 	} else {
1088 		switch (fourcc) {
1089 		case DRM_FORMAT_RGBX4444:
1090 			m = 0x4; break;
1091 		case DRM_FORMAT_ARGB4444:
1092 			m = 0x5; break;
1093 		case DRM_FORMAT_RGB565:
1094 			m = 0x6; break;
1095 		case DRM_FORMAT_ARGB1555:
1096 			m = 0x7; break;
1097 		case DRM_FORMAT_XRGB8888:
1098 			m = 0x8; break;
1099 		case DRM_FORMAT_RGB888:
1100 			m = 0x9; break;
1101 		case DRM_FORMAT_XRGB4444:
1102 			m = 0xa; break;
1103 		case DRM_FORMAT_RGBA4444:
1104 			m = 0xb; break;
1105 		case DRM_FORMAT_ARGB8888:
1106 			m = 0xc; break;
1107 		case DRM_FORMAT_RGBA8888:
1108 			m = 0xd; break;
1109 		case DRM_FORMAT_RGBX8888:
1110 			m = 0xe; break;
1111 		case DRM_FORMAT_XRGB1555:
1112 			m = 0xf; break;
1113 		default:
1114 			BUG(); return;
1115 		}
1116 	}
1117 
1118 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
1119 }
1120 
1121 static void dispc_ovl_configure_burst_type(struct dispc_device *dispc,
1122 					   enum omap_plane_id plane,
1123 					   enum omap_dss_rotation_type rotation)
1124 {
1125 	if (dispc_has_feature(dispc, FEAT_BURST_2D) == 0)
1126 		return;
1127 
1128 	if (rotation == OMAP_DSS_ROT_TILER)
1129 		REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
1130 	else
1131 		REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
1132 }
1133 
1134 static void dispc_ovl_set_channel_out(struct dispc_device *dispc,
1135 				      enum omap_plane_id plane,
1136 				      enum omap_channel channel)
1137 {
1138 	int shift;
1139 	u32 val;
1140 	int chan = 0, chan2 = 0;
1141 
1142 	switch (plane) {
1143 	case OMAP_DSS_GFX:
1144 		shift = 8;
1145 		break;
1146 	case OMAP_DSS_VIDEO1:
1147 	case OMAP_DSS_VIDEO2:
1148 	case OMAP_DSS_VIDEO3:
1149 		shift = 16;
1150 		break;
1151 	default:
1152 		BUG();
1153 		return;
1154 	}
1155 
1156 	val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
1157 	if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
1158 		switch (channel) {
1159 		case OMAP_DSS_CHANNEL_LCD:
1160 			chan = 0;
1161 			chan2 = 0;
1162 			break;
1163 		case OMAP_DSS_CHANNEL_DIGIT:
1164 			chan = 1;
1165 			chan2 = 0;
1166 			break;
1167 		case OMAP_DSS_CHANNEL_LCD2:
1168 			chan = 0;
1169 			chan2 = 1;
1170 			break;
1171 		case OMAP_DSS_CHANNEL_LCD3:
1172 			if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
1173 				chan = 0;
1174 				chan2 = 2;
1175 			} else {
1176 				BUG();
1177 				return;
1178 			}
1179 			break;
1180 		case OMAP_DSS_CHANNEL_WB:
1181 			chan = 0;
1182 			chan2 = 3;
1183 			break;
1184 		default:
1185 			BUG();
1186 			return;
1187 		}
1188 
1189 		val = FLD_MOD(val, chan, shift, shift);
1190 		val = FLD_MOD(val, chan2, 31, 30);
1191 	} else {
1192 		val = FLD_MOD(val, channel, shift, shift);
1193 	}
1194 	dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
1195 }
1196 
1197 static enum omap_channel dispc_ovl_get_channel_out(struct dispc_device *dispc,
1198 						   enum omap_plane_id plane)
1199 {
1200 	int shift;
1201 	u32 val;
1202 
1203 	switch (plane) {
1204 	case OMAP_DSS_GFX:
1205 		shift = 8;
1206 		break;
1207 	case OMAP_DSS_VIDEO1:
1208 	case OMAP_DSS_VIDEO2:
1209 	case OMAP_DSS_VIDEO3:
1210 		shift = 16;
1211 		break;
1212 	default:
1213 		BUG();
1214 		return 0;
1215 	}
1216 
1217 	val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
1218 
1219 	if (FLD_GET(val, shift, shift) == 1)
1220 		return OMAP_DSS_CHANNEL_DIGIT;
1221 
1222 	if (!dispc_has_feature(dispc, FEAT_MGR_LCD2))
1223 		return OMAP_DSS_CHANNEL_LCD;
1224 
1225 	switch (FLD_GET(val, 31, 30)) {
1226 	case 0:
1227 	default:
1228 		return OMAP_DSS_CHANNEL_LCD;
1229 	case 1:
1230 		return OMAP_DSS_CHANNEL_LCD2;
1231 	case 2:
1232 		return OMAP_DSS_CHANNEL_LCD3;
1233 	case 3:
1234 		return OMAP_DSS_CHANNEL_WB;
1235 	}
1236 }
1237 
1238 static void dispc_ovl_set_burst_size(struct dispc_device *dispc,
1239 				     enum omap_plane_id plane,
1240 				     enum omap_burst_size burst_size)
1241 {
1242 	static const unsigned int shifts[] = { 6, 14, 14, 14, 14, };
1243 	int shift;
1244 
1245 	shift = shifts[plane];
1246 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), burst_size,
1247 		    shift + 1, shift);
1248 }
1249 
1250 static void dispc_configure_burst_sizes(struct dispc_device *dispc)
1251 {
1252 	int i;
1253 	const int burst_size = BURST_SIZE_X8;
1254 
1255 	/* Configure burst size always to maximum size */
1256 	for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
1257 		dispc_ovl_set_burst_size(dispc, i, burst_size);
1258 	if (dispc->feat->has_writeback)
1259 		dispc_ovl_set_burst_size(dispc, OMAP_DSS_WB, burst_size);
1260 }
1261 
1262 static u32 dispc_ovl_get_burst_size(struct dispc_device *dispc,
1263 				    enum omap_plane_id plane)
1264 {
1265 	/* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */
1266 	return dispc->feat->burst_size_unit * 8;
1267 }
1268 
1269 static bool dispc_ovl_color_mode_supported(struct dispc_device *dispc,
1270 					   enum omap_plane_id plane, u32 fourcc)
1271 {
1272 	const u32 *modes;
1273 	unsigned int i;
1274 
1275 	modes = dispc->feat->supported_color_modes[plane];
1276 
1277 	for (i = 0; modes[i]; ++i) {
1278 		if (modes[i] == fourcc)
1279 			return true;
1280 	}
1281 
1282 	return false;
1283 }
1284 
1285 static const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
1286 					    enum omap_plane_id plane)
1287 {
1288 	return dispc->feat->supported_color_modes[plane];
1289 }
1290 
1291 static void dispc_mgr_enable_cpr(struct dispc_device *dispc,
1292 				 enum omap_channel channel, bool enable)
1293 {
1294 	if (channel == OMAP_DSS_CHANNEL_DIGIT)
1295 		return;
1296 
1297 	mgr_fld_write(dispc, channel, DISPC_MGR_FLD_CPR, enable);
1298 }
1299 
1300 static void dispc_mgr_set_cpr_coef(struct dispc_device *dispc,
1301 				   enum omap_channel channel,
1302 				   const struct omap_dss_cpr_coefs *coefs)
1303 {
1304 	u32 coef_r, coef_g, coef_b;
1305 
1306 	if (!dss_mgr_is_lcd(channel))
1307 		return;
1308 
1309 	coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) |
1310 		FLD_VAL(coefs->rb, 9, 0);
1311 	coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) |
1312 		FLD_VAL(coefs->gb, 9, 0);
1313 	coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) |
1314 		FLD_VAL(coefs->bb, 9, 0);
1315 
1316 	dispc_write_reg(dispc, DISPC_CPR_COEF_R(channel), coef_r);
1317 	dispc_write_reg(dispc, DISPC_CPR_COEF_G(channel), coef_g);
1318 	dispc_write_reg(dispc, DISPC_CPR_COEF_B(channel), coef_b);
1319 }
1320 
1321 static void dispc_ovl_set_vid_color_conv(struct dispc_device *dispc,
1322 					 enum omap_plane_id plane, bool enable)
1323 {
1324 	u32 val;
1325 
1326 	BUG_ON(plane == OMAP_DSS_GFX);
1327 
1328 	val = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
1329 	val = FLD_MOD(val, enable, 9, 9);
1330 	dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), val);
1331 }
1332 
1333 static void dispc_ovl_enable_replication(struct dispc_device *dispc,
1334 					 enum omap_plane_id plane,
1335 					 enum omap_overlay_caps caps,
1336 					 bool enable)
1337 {
1338 	static const unsigned int shifts[] = { 5, 10, 10, 10 };
1339 	int shift;
1340 
1341 	if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0)
1342 		return;
1343 
1344 	shift = shifts[plane];
1345 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
1346 }
1347 
1348 static void dispc_mgr_set_size(struct dispc_device *dispc,
1349 			       enum omap_channel channel, u16 width, u16 height)
1350 {
1351 	u32 val;
1352 
1353 	val = FLD_VAL(height - 1, dispc->feat->mgr_height_start, 16) |
1354 		FLD_VAL(width - 1, dispc->feat->mgr_width_start, 0);
1355 
1356 	dispc_write_reg(dispc, DISPC_SIZE_MGR(channel), val);
1357 }
1358 
1359 static void dispc_init_fifos(struct dispc_device *dispc)
1360 {
1361 	u32 size;
1362 	int fifo;
1363 	u8 start, end;
1364 	u32 unit;
1365 	int i;
1366 
1367 	unit = dispc->feat->buffer_size_unit;
1368 
1369 	dispc_get_reg_field(dispc, FEAT_REG_FIFOSIZE, &start, &end);
1370 
1371 	for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
1372 		size = REG_GET(dispc, DISPC_OVL_FIFO_SIZE_STATUS(fifo),
1373 			       start, end);
1374 		size *= unit;
1375 		dispc->fifo_size[fifo] = size;
1376 
1377 		/*
1378 		 * By default fifos are mapped directly to overlays, fifo 0 to
1379 		 * ovl 0, fifo 1 to ovl 1, etc.
1380 		 */
1381 		dispc->fifo_assignment[fifo] = fifo;
1382 	}
1383 
1384 	/*
1385 	 * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo
1386 	 * causes problems with certain use cases, like using the tiler in 2D
1387 	 * mode. The below hack swaps the fifos of GFX and WB planes, thus
1388 	 * giving GFX plane a larger fifo. WB but should work fine with a
1389 	 * smaller fifo.
1390 	 */
1391 	if (dispc->feat->gfx_fifo_workaround) {
1392 		u32 v;
1393 
1394 		v = dispc_read_reg(dispc, DISPC_GLOBAL_BUFFER);
1395 
1396 		v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */
1397 		v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */
1398 		v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */
1399 		v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */
1400 
1401 		dispc_write_reg(dispc, DISPC_GLOBAL_BUFFER, v);
1402 
1403 		dispc->fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB;
1404 		dispc->fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX;
1405 	}
1406 
1407 	/*
1408 	 * Setup default fifo thresholds.
1409 	 */
1410 	for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
1411 		u32 low, high;
1412 		const bool use_fifomerge = false;
1413 		const bool manual_update = false;
1414 
1415 		dispc_ovl_compute_fifo_thresholds(dispc, i, &low, &high,
1416 						  use_fifomerge, manual_update);
1417 
1418 		dispc_ovl_set_fifo_threshold(dispc, i, low, high);
1419 	}
1420 
1421 	if (dispc->feat->has_writeback) {
1422 		u32 low, high;
1423 		const bool use_fifomerge = false;
1424 		const bool manual_update = false;
1425 
1426 		dispc_ovl_compute_fifo_thresholds(dispc, OMAP_DSS_WB,
1427 						  &low, &high, use_fifomerge,
1428 						  manual_update);
1429 
1430 		dispc_ovl_set_fifo_threshold(dispc, OMAP_DSS_WB, low, high);
1431 	}
1432 }
1433 
1434 static u32 dispc_ovl_get_fifo_size(struct dispc_device *dispc,
1435 				   enum omap_plane_id plane)
1436 {
1437 	int fifo;
1438 	u32 size = 0;
1439 
1440 	for (fifo = 0; fifo < dispc->feat->num_fifos; ++fifo) {
1441 		if (dispc->fifo_assignment[fifo] == plane)
1442 			size += dispc->fifo_size[fifo];
1443 	}
1444 
1445 	return size;
1446 }
1447 
1448 void dispc_ovl_set_fifo_threshold(struct dispc_device *dispc,
1449 				  enum omap_plane_id plane,
1450 				  u32 low, u32 high)
1451 {
1452 	u8 hi_start, hi_end, lo_start, lo_end;
1453 	u32 unit;
1454 
1455 	unit = dispc->feat->buffer_size_unit;
1456 
1457 	WARN_ON(low % unit != 0);
1458 	WARN_ON(high % unit != 0);
1459 
1460 	low /= unit;
1461 	high /= unit;
1462 
1463 	dispc_get_reg_field(dispc, FEAT_REG_FIFOHIGHTHRESHOLD,
1464 			    &hi_start, &hi_end);
1465 	dispc_get_reg_field(dispc, FEAT_REG_FIFOLOWTHRESHOLD,
1466 			    &lo_start, &lo_end);
1467 
1468 	DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n",
1469 			plane,
1470 			REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
1471 				lo_start, lo_end) * unit,
1472 			REG_GET(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
1473 				hi_start, hi_end) * unit,
1474 			low * unit, high * unit);
1475 
1476 	dispc_write_reg(dispc, DISPC_OVL_FIFO_THRESHOLD(plane),
1477 			FLD_VAL(high, hi_start, hi_end) |
1478 			FLD_VAL(low, lo_start, lo_end));
1479 
1480 	/*
1481 	 * configure the preload to the pipeline's high threhold, if HT it's too
1482 	 * large for the preload field, set the threshold to the maximum value
1483 	 * that can be held by the preload register
1484 	 */
1485 	if (dispc_has_feature(dispc, FEAT_PRELOAD) &&
1486 	    dispc->feat->set_max_preload && plane != OMAP_DSS_WB)
1487 		dispc_write_reg(dispc, DISPC_OVL_PRELOAD(plane),
1488 				min(high, 0xfffu));
1489 }
1490 
1491 void dispc_enable_fifomerge(struct dispc_device *dispc, bool enable)
1492 {
1493 	if (!dispc_has_feature(dispc, FEAT_FIFO_MERGE)) {
1494 		WARN_ON(enable);
1495 		return;
1496 	}
1497 
1498 	DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled");
1499 	REG_FLD_MOD(dispc, DISPC_CONFIG, enable ? 1 : 0, 14, 14);
1500 }
1501 
1502 void dispc_ovl_compute_fifo_thresholds(struct dispc_device *dispc,
1503 				       enum omap_plane_id plane,
1504 				       u32 *fifo_low, u32 *fifo_high,
1505 				       bool use_fifomerge, bool manual_update)
1506 {
1507 	/*
1508 	 * All sizes are in bytes. Both the buffer and burst are made of
1509 	 * buffer_units, and the fifo thresholds must be buffer_unit aligned.
1510 	 */
1511 	unsigned int buf_unit = dispc->feat->buffer_size_unit;
1512 	unsigned int ovl_fifo_size, total_fifo_size, burst_size;
1513 	int i;
1514 
1515 	burst_size = dispc_ovl_get_burst_size(dispc, plane);
1516 	ovl_fifo_size = dispc_ovl_get_fifo_size(dispc, plane);
1517 
1518 	if (use_fifomerge) {
1519 		total_fifo_size = 0;
1520 		for (i = 0; i < dispc_get_num_ovls(dispc); ++i)
1521 			total_fifo_size += dispc_ovl_get_fifo_size(dispc, i);
1522 	} else {
1523 		total_fifo_size = ovl_fifo_size;
1524 	}
1525 
1526 	/*
1527 	 * We use the same low threshold for both fifomerge and non-fifomerge
1528 	 * cases, but for fifomerge we calculate the high threshold using the
1529 	 * combined fifo size
1530 	 */
1531 
1532 	if (manual_update && dispc_has_feature(dispc, FEAT_OMAP3_DSI_FIFO_BUG)) {
1533 		*fifo_low = ovl_fifo_size - burst_size * 2;
1534 		*fifo_high = total_fifo_size - burst_size;
1535 	} else if (plane == OMAP_DSS_WB) {
1536 		/*
1537 		 * Most optimal configuration for writeback is to push out data
1538 		 * to the interconnect the moment writeback pushes enough pixels
1539 		 * in the FIFO to form a burst
1540 		 */
1541 		*fifo_low = 0;
1542 		*fifo_high = burst_size;
1543 	} else {
1544 		*fifo_low = ovl_fifo_size - burst_size;
1545 		*fifo_high = total_fifo_size - buf_unit;
1546 	}
1547 }
1548 
1549 static void dispc_ovl_set_mflag(struct dispc_device *dispc,
1550 				enum omap_plane_id plane, bool enable)
1551 {
1552 	int bit;
1553 
1554 	if (plane == OMAP_DSS_GFX)
1555 		bit = 14;
1556 	else
1557 		bit = 23;
1558 
1559 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit);
1560 }
1561 
1562 static void dispc_ovl_set_mflag_threshold(struct dispc_device *dispc,
1563 					  enum omap_plane_id plane,
1564 					  int low, int high)
1565 {
1566 	dispc_write_reg(dispc, DISPC_OVL_MFLAG_THRESHOLD(plane),
1567 		FLD_VAL(high, 31, 16) |	FLD_VAL(low, 15, 0));
1568 }
1569 
1570 static void dispc_init_mflag(struct dispc_device *dispc)
1571 {
1572 	int i;
1573 
1574 	/*
1575 	 * HACK: NV12 color format and MFLAG seem to have problems working
1576 	 * together: using two displays, and having an NV12 overlay on one of
1577 	 * the displays will cause underflows/synclosts when MFLAG_CTRL=2.
1578 	 * Changing MFLAG thresholds and PRELOAD to certain values seem to
1579 	 * remove the errors, but there doesn't seem to be a clear logic on
1580 	 * which values work and which not.
1581 	 *
1582 	 * As a work-around, set force MFLAG to always on.
1583 	 */
1584 	dispc_write_reg(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE,
1585 		(1 << 0) |	/* MFLAG_CTRL = force always on */
1586 		(0 << 2));	/* MFLAG_START = disable */
1587 
1588 	for (i = 0; i < dispc_get_num_ovls(dispc); ++i) {
1589 		u32 size = dispc_ovl_get_fifo_size(dispc, i);
1590 		u32 unit = dispc->feat->buffer_size_unit;
1591 		u32 low, high;
1592 
1593 		dispc_ovl_set_mflag(dispc, i, true);
1594 
1595 		/*
1596 		 * Simulation team suggests below thesholds:
1597 		 * HT = fifosize * 5 / 8;
1598 		 * LT = fifosize * 4 / 8;
1599 		 */
1600 
1601 		low = size * 4 / 8 / unit;
1602 		high = size * 5 / 8 / unit;
1603 
1604 		dispc_ovl_set_mflag_threshold(dispc, i, low, high);
1605 	}
1606 
1607 	if (dispc->feat->has_writeback) {
1608 		u32 size = dispc_ovl_get_fifo_size(dispc, OMAP_DSS_WB);
1609 		u32 unit = dispc->feat->buffer_size_unit;
1610 		u32 low, high;
1611 
1612 		dispc_ovl_set_mflag(dispc, OMAP_DSS_WB, true);
1613 
1614 		/*
1615 		 * Simulation team suggests below thesholds:
1616 		 * HT = fifosize * 5 / 8;
1617 		 * LT = fifosize * 4 / 8;
1618 		 */
1619 
1620 		low = size * 4 / 8 / unit;
1621 		high = size * 5 / 8 / unit;
1622 
1623 		dispc_ovl_set_mflag_threshold(dispc, OMAP_DSS_WB, low, high);
1624 	}
1625 }
1626 
1627 static void dispc_ovl_set_fir(struct dispc_device *dispc,
1628 			      enum omap_plane_id plane,
1629 			      int hinc, int vinc,
1630 			      enum omap_color_component color_comp)
1631 {
1632 	u32 val;
1633 
1634 	if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) {
1635 		u8 hinc_start, hinc_end, vinc_start, vinc_end;
1636 
1637 		dispc_get_reg_field(dispc, FEAT_REG_FIRHINC,
1638 				    &hinc_start, &hinc_end);
1639 		dispc_get_reg_field(dispc, FEAT_REG_FIRVINC,
1640 				    &vinc_start, &vinc_end);
1641 		val = FLD_VAL(vinc, vinc_start, vinc_end) |
1642 				FLD_VAL(hinc, hinc_start, hinc_end);
1643 
1644 		dispc_write_reg(dispc, DISPC_OVL_FIR(plane), val);
1645 	} else {
1646 		val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0);
1647 		dispc_write_reg(dispc, DISPC_OVL_FIR2(plane), val);
1648 	}
1649 }
1650 
1651 static void dispc_ovl_set_vid_accu0(struct dispc_device *dispc,
1652 				    enum omap_plane_id plane, int haccu,
1653 				    int vaccu)
1654 {
1655 	u32 val;
1656 	u8 hor_start, hor_end, vert_start, vert_end;
1657 
1658 	dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
1659 			    &hor_start, &hor_end);
1660 	dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
1661 			    &vert_start, &vert_end);
1662 
1663 	val = FLD_VAL(vaccu, vert_start, vert_end) |
1664 			FLD_VAL(haccu, hor_start, hor_end);
1665 
1666 	dispc_write_reg(dispc, DISPC_OVL_ACCU0(plane), val);
1667 }
1668 
1669 static void dispc_ovl_set_vid_accu1(struct dispc_device *dispc,
1670 				    enum omap_plane_id plane, int haccu,
1671 				    int vaccu)
1672 {
1673 	u32 val;
1674 	u8 hor_start, hor_end, vert_start, vert_end;
1675 
1676 	dispc_get_reg_field(dispc, FEAT_REG_HORIZONTALACCU,
1677 			    &hor_start, &hor_end);
1678 	dispc_get_reg_field(dispc, FEAT_REG_VERTICALACCU,
1679 			    &vert_start, &vert_end);
1680 
1681 	val = FLD_VAL(vaccu, vert_start, vert_end) |
1682 			FLD_VAL(haccu, hor_start, hor_end);
1683 
1684 	dispc_write_reg(dispc, DISPC_OVL_ACCU1(plane), val);
1685 }
1686 
1687 static void dispc_ovl_set_vid_accu2_0(struct dispc_device *dispc,
1688 				      enum omap_plane_id plane, int haccu,
1689 				      int vaccu)
1690 {
1691 	u32 val;
1692 
1693 	val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1694 	dispc_write_reg(dispc, DISPC_OVL_ACCU2_0(plane), val);
1695 }
1696 
1697 static void dispc_ovl_set_vid_accu2_1(struct dispc_device *dispc,
1698 				      enum omap_plane_id plane, int haccu,
1699 				      int vaccu)
1700 {
1701 	u32 val;
1702 
1703 	val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0);
1704 	dispc_write_reg(dispc, DISPC_OVL_ACCU2_1(plane), val);
1705 }
1706 
1707 static void dispc_ovl_set_scale_param(struct dispc_device *dispc,
1708 				      enum omap_plane_id plane,
1709 				      u16 orig_width, u16 orig_height,
1710 				      u16 out_width, u16 out_height,
1711 				      bool five_taps, u8 rotation,
1712 				      enum omap_color_component color_comp)
1713 {
1714 	int fir_hinc, fir_vinc;
1715 
1716 	fir_hinc = 1024 * orig_width / out_width;
1717 	fir_vinc = 1024 * orig_height / out_height;
1718 
1719 	dispc_ovl_set_scale_coef(dispc, plane, fir_hinc, fir_vinc, five_taps,
1720 				 color_comp);
1721 	dispc_ovl_set_fir(dispc, plane, fir_hinc, fir_vinc, color_comp);
1722 }
1723 
1724 static void dispc_ovl_set_accu_uv(struct dispc_device *dispc,
1725 				  enum omap_plane_id plane,
1726 				  u16 orig_width, u16 orig_height,
1727 				  u16 out_width, u16 out_height,
1728 				  bool ilace, u32 fourcc, u8 rotation)
1729 {
1730 	int h_accu2_0, h_accu2_1;
1731 	int v_accu2_0, v_accu2_1;
1732 	int chroma_hinc, chroma_vinc;
1733 	int idx;
1734 
1735 	struct accu {
1736 		s8 h0_m, h0_n;
1737 		s8 h1_m, h1_n;
1738 		s8 v0_m, v0_n;
1739 		s8 v1_m, v1_n;
1740 	};
1741 
1742 	const struct accu *accu_table;
1743 	const struct accu *accu_val;
1744 
1745 	static const struct accu accu_nv12[4] = {
1746 		{  0, 1,  0, 1 , -1, 2, 0, 1 },
1747 		{  1, 2, -3, 4 ,  0, 1, 0, 1 },
1748 		{ -1, 1,  0, 1 , -1, 2, 0, 1 },
1749 		{ -1, 2, -1, 2 , -1, 1, 0, 1 },
1750 	};
1751 
1752 	static const struct accu accu_nv12_ilace[4] = {
1753 		{  0, 1,  0, 1 , -3, 4, -1, 4 },
1754 		{ -1, 4, -3, 4 ,  0, 1,  0, 1 },
1755 		{ -1, 1,  0, 1 , -1, 4, -3, 4 },
1756 		{ -3, 4, -3, 4 , -1, 1,  0, 1 },
1757 	};
1758 
1759 	static const struct accu accu_yuv[4] = {
1760 		{  0, 1, 0, 1,  0, 1, 0, 1 },
1761 		{  0, 1, 0, 1,  0, 1, 0, 1 },
1762 		{ -1, 1, 0, 1,  0, 1, 0, 1 },
1763 		{  0, 1, 0, 1, -1, 1, 0, 1 },
1764 	};
1765 
1766 	/* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
1767 	switch (rotation & DRM_MODE_ROTATE_MASK) {
1768 	default:
1769 	case DRM_MODE_ROTATE_0:
1770 		idx = 0;
1771 		break;
1772 	case DRM_MODE_ROTATE_90:
1773 		idx = 3;
1774 		break;
1775 	case DRM_MODE_ROTATE_180:
1776 		idx = 2;
1777 		break;
1778 	case DRM_MODE_ROTATE_270:
1779 		idx = 1;
1780 		break;
1781 	}
1782 
1783 	switch (fourcc) {
1784 	case DRM_FORMAT_NV12:
1785 		if (ilace)
1786 			accu_table = accu_nv12_ilace;
1787 		else
1788 			accu_table = accu_nv12;
1789 		break;
1790 	case DRM_FORMAT_YUYV:
1791 	case DRM_FORMAT_UYVY:
1792 		accu_table = accu_yuv;
1793 		break;
1794 	default:
1795 		BUG();
1796 		return;
1797 	}
1798 
1799 	accu_val = &accu_table[idx];
1800 
1801 	chroma_hinc = 1024 * orig_width / out_width;
1802 	chroma_vinc = 1024 * orig_height / out_height;
1803 
1804 	h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1805 	h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1806 	v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1807 	v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1808 
1809 	dispc_ovl_set_vid_accu2_0(dispc, plane, h_accu2_0, v_accu2_0);
1810 	dispc_ovl_set_vid_accu2_1(dispc, plane, h_accu2_1, v_accu2_1);
1811 }
1812 
1813 static void dispc_ovl_set_scaling_common(struct dispc_device *dispc,
1814 					 enum omap_plane_id plane,
1815 					 u16 orig_width, u16 orig_height,
1816 					 u16 out_width, u16 out_height,
1817 					 bool ilace, bool five_taps,
1818 					 bool fieldmode, u32 fourcc,
1819 					 u8 rotation)
1820 {
1821 	int accu0 = 0;
1822 	int accu1 = 0;
1823 	u32 l;
1824 
1825 	dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
1826 				  out_width, out_height, five_taps,
1827 				  rotation, DISPC_COLOR_COMPONENT_RGB_Y);
1828 	l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
1829 
1830 	/* RESIZEENABLE and VERTICALTAPS */
1831 	l &= ~((0x3 << 5) | (0x1 << 21));
1832 	l |= (orig_width != out_width) ? (1 << 5) : 0;
1833 	l |= (orig_height != out_height) ? (1 << 6) : 0;
1834 	l |= five_taps ? (1 << 21) : 0;
1835 
1836 	/* VRESIZECONF and HRESIZECONF */
1837 	if (dispc_has_feature(dispc, FEAT_RESIZECONF)) {
1838 		l &= ~(0x3 << 7);
1839 		l |= (orig_width <= out_width) ? 0 : (1 << 7);
1840 		l |= (orig_height <= out_height) ? 0 : (1 << 8);
1841 	}
1842 
1843 	/* LINEBUFFERSPLIT */
1844 	if (dispc_has_feature(dispc, FEAT_LINEBUFFERSPLIT)) {
1845 		l &= ~(0x1 << 22);
1846 		l |= five_taps ? (1 << 22) : 0;
1847 	}
1848 
1849 	dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
1850 
1851 	/*
1852 	 * field 0 = even field = bottom field
1853 	 * field 1 = odd field = top field
1854 	 */
1855 	if (ilace && !fieldmode) {
1856 		accu1 = 0;
1857 		accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff;
1858 		if (accu0 >= 1024/2) {
1859 			accu1 = 1024/2;
1860 			accu0 -= accu1;
1861 		}
1862 	}
1863 
1864 	dispc_ovl_set_vid_accu0(dispc, plane, 0, accu0);
1865 	dispc_ovl_set_vid_accu1(dispc, plane, 0, accu1);
1866 }
1867 
1868 static void dispc_ovl_set_scaling_uv(struct dispc_device *dispc,
1869 				     enum omap_plane_id plane,
1870 				     u16 orig_width, u16 orig_height,
1871 				     u16 out_width, u16 out_height,
1872 				     bool ilace, bool five_taps,
1873 				     bool fieldmode, u32 fourcc,
1874 				     u8 rotation)
1875 {
1876 	int scale_x = out_width != orig_width;
1877 	int scale_y = out_height != orig_height;
1878 	bool chroma_upscale = plane != OMAP_DSS_WB;
1879 	const struct drm_format_info *info;
1880 
1881 	info = drm_format_info(fourcc);
1882 
1883 	if (!dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE))
1884 		return;
1885 
1886 	if (!info->is_yuv) {
1887 		/* reset chroma resampling for RGB formats  */
1888 		if (plane != OMAP_DSS_WB)
1889 			REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
1890 				    0, 8, 8);
1891 		return;
1892 	}
1893 
1894 	dispc_ovl_set_accu_uv(dispc, plane, orig_width, orig_height, out_width,
1895 			      out_height, ilace, fourcc, rotation);
1896 
1897 	switch (fourcc) {
1898 	case DRM_FORMAT_NV12:
1899 		if (chroma_upscale) {
1900 			/* UV is subsampled by 2 horizontally and vertically */
1901 			orig_height >>= 1;
1902 			orig_width >>= 1;
1903 		} else {
1904 			/* UV is downsampled by 2 horizontally and vertically */
1905 			orig_height <<= 1;
1906 			orig_width <<= 1;
1907 		}
1908 
1909 		break;
1910 	case DRM_FORMAT_YUYV:
1911 	case DRM_FORMAT_UYVY:
1912 		/* For YUV422 with 90/270 rotation, we don't upsample chroma */
1913 		if (!drm_rotation_90_or_270(rotation)) {
1914 			if (chroma_upscale)
1915 				/* UV is subsampled by 2 horizontally */
1916 				orig_width >>= 1;
1917 			else
1918 				/* UV is downsampled by 2 horizontally */
1919 				orig_width <<= 1;
1920 		}
1921 
1922 		/* must use FIR for YUV422 if rotated */
1923 		if ((rotation & DRM_MODE_ROTATE_MASK) != DRM_MODE_ROTATE_0)
1924 			scale_x = scale_y = true;
1925 
1926 		break;
1927 	default:
1928 		BUG();
1929 		return;
1930 	}
1931 
1932 	if (out_width != orig_width)
1933 		scale_x = true;
1934 	if (out_height != orig_height)
1935 		scale_y = true;
1936 
1937 	dispc_ovl_set_scale_param(dispc, plane, orig_width, orig_height,
1938 				  out_width, out_height, five_taps,
1939 				  rotation, DISPC_COLOR_COMPONENT_UV);
1940 
1941 	if (plane != OMAP_DSS_WB)
1942 		REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane),
1943 			(scale_x || scale_y) ? 1 : 0, 8, 8);
1944 
1945 	/* set H scaling */
1946 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1947 	/* set V scaling */
1948 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1949 }
1950 
1951 static void dispc_ovl_set_scaling(struct dispc_device *dispc,
1952 				  enum omap_plane_id plane,
1953 				  u16 orig_width, u16 orig_height,
1954 				  u16 out_width, u16 out_height,
1955 				  bool ilace, bool five_taps,
1956 				  bool fieldmode, u32 fourcc,
1957 				  u8 rotation)
1958 {
1959 	BUG_ON(plane == OMAP_DSS_GFX);
1960 
1961 	dispc_ovl_set_scaling_common(dispc, plane, orig_width, orig_height,
1962 				     out_width, out_height, ilace, five_taps,
1963 				     fieldmode, fourcc, rotation);
1964 
1965 	dispc_ovl_set_scaling_uv(dispc, plane, orig_width, orig_height,
1966 				 out_width, out_height, ilace, five_taps,
1967 				 fieldmode, fourcc, rotation);
1968 }
1969 
1970 static void dispc_ovl_set_rotation_attrs(struct dispc_device *dispc,
1971 					 enum omap_plane_id plane, u8 rotation,
1972 					 enum omap_dss_rotation_type rotation_type,
1973 					 u32 fourcc)
1974 {
1975 	bool row_repeat = false;
1976 	int vidrot = 0;
1977 
1978 	/* Note: DSS HW rotates clockwise, DRM_MODE_ROTATE_* counter-clockwise */
1979 	if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY) {
1980 
1981 		if (rotation & DRM_MODE_REFLECT_X) {
1982 			switch (rotation & DRM_MODE_ROTATE_MASK) {
1983 			case DRM_MODE_ROTATE_0:
1984 				vidrot = 2;
1985 				break;
1986 			case DRM_MODE_ROTATE_90:
1987 				vidrot = 1;
1988 				break;
1989 			case DRM_MODE_ROTATE_180:
1990 				vidrot = 0;
1991 				break;
1992 			case DRM_MODE_ROTATE_270:
1993 				vidrot = 3;
1994 				break;
1995 			}
1996 		} else {
1997 			switch (rotation & DRM_MODE_ROTATE_MASK) {
1998 			case DRM_MODE_ROTATE_0:
1999 				vidrot = 0;
2000 				break;
2001 			case DRM_MODE_ROTATE_90:
2002 				vidrot = 3;
2003 				break;
2004 			case DRM_MODE_ROTATE_180:
2005 				vidrot = 2;
2006 				break;
2007 			case DRM_MODE_ROTATE_270:
2008 				vidrot = 1;
2009 				break;
2010 			}
2011 		}
2012 
2013 		if (drm_rotation_90_or_270(rotation))
2014 			row_repeat = true;
2015 		else
2016 			row_repeat = false;
2017 	}
2018 
2019 	/*
2020 	 * OMAP4/5 Errata i631:
2021 	 * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra
2022 	 * rows beyond the framebuffer, which may cause OCP error.
2023 	 */
2024 	if (fourcc == DRM_FORMAT_NV12 && rotation_type != OMAP_DSS_ROT_TILER)
2025 		vidrot = 1;
2026 
2027 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12);
2028 	if (dispc_has_feature(dispc, FEAT_ROWREPEATENABLE))
2029 		REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
2030 			row_repeat ? 1 : 0, 18, 18);
2031 
2032 	if (dispc_ovl_color_mode_supported(dispc, plane, DRM_FORMAT_NV12)) {
2033 		bool doublestride =
2034 			fourcc == DRM_FORMAT_NV12 &&
2035 			rotation_type == OMAP_DSS_ROT_TILER &&
2036 			!drm_rotation_90_or_270(rotation);
2037 
2038 		/* DOUBLESTRIDE */
2039 		REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane),
2040 			    doublestride, 22, 22);
2041 	}
2042 }
2043 
2044 static int color_mode_to_bpp(u32 fourcc)
2045 {
2046 	switch (fourcc) {
2047 	case DRM_FORMAT_NV12:
2048 		return 8;
2049 	case DRM_FORMAT_RGBX4444:
2050 	case DRM_FORMAT_RGB565:
2051 	case DRM_FORMAT_ARGB4444:
2052 	case DRM_FORMAT_YUYV:
2053 	case DRM_FORMAT_UYVY:
2054 	case DRM_FORMAT_RGBA4444:
2055 	case DRM_FORMAT_XRGB4444:
2056 	case DRM_FORMAT_ARGB1555:
2057 	case DRM_FORMAT_XRGB1555:
2058 		return 16;
2059 	case DRM_FORMAT_RGB888:
2060 		return 24;
2061 	case DRM_FORMAT_XRGB8888:
2062 	case DRM_FORMAT_ARGB8888:
2063 	case DRM_FORMAT_RGBA8888:
2064 	case DRM_FORMAT_RGBX8888:
2065 		return 32;
2066 	default:
2067 		BUG();
2068 		return 0;
2069 	}
2070 }
2071 
2072 static s32 pixinc(int pixels, u8 ps)
2073 {
2074 	if (pixels == 1)
2075 		return 1;
2076 	else if (pixels > 1)
2077 		return 1 + (pixels - 1) * ps;
2078 	else if (pixels < 0)
2079 		return 1 - (-pixels + 1) * ps;
2080 	else
2081 		BUG();
2082 		return 0;
2083 }
2084 
2085 static void calc_offset(u16 screen_width, u16 width,
2086 		u32 fourcc, bool fieldmode, unsigned int field_offset,
2087 		unsigned int *offset0, unsigned int *offset1,
2088 		s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim,
2089 		enum omap_dss_rotation_type rotation_type, u8 rotation)
2090 {
2091 	u8 ps;
2092 
2093 	ps = color_mode_to_bpp(fourcc) / 8;
2094 
2095 	DSSDBG("scrw %d, width %d\n", screen_width, width);
2096 
2097 	if (rotation_type == OMAP_DSS_ROT_TILER &&
2098 	    (fourcc == DRM_FORMAT_UYVY || fourcc == DRM_FORMAT_YUYV) &&
2099 	    drm_rotation_90_or_270(rotation)) {
2100 		/*
2101 		 * HACK: ROW_INC needs to be calculated with TILER units.
2102 		 * We get such 'screen_width' that multiplying it with the
2103 		 * YUV422 pixel size gives the correct TILER container width.
2104 		 * However, 'width' is in pixels and multiplying it with YUV422
2105 		 * pixel size gives incorrect result. We thus multiply it here
2106 		 * with 2 to match the 32 bit TILER unit size.
2107 		 */
2108 		width *= 2;
2109 	}
2110 
2111 	/*
2112 	 * field 0 = even field = bottom field
2113 	 * field 1 = odd field = top field
2114 	 */
2115 	*offset0 = field_offset * screen_width * ps;
2116 	*offset1 = 0;
2117 
2118 	*row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
2119 			(fieldmode ? screen_width : 0), ps);
2120 	if (fourcc == DRM_FORMAT_YUYV || fourcc == DRM_FORMAT_UYVY)
2121 		*pix_inc = pixinc(x_predecim, 2 * ps);
2122 	else
2123 		*pix_inc = pixinc(x_predecim, ps);
2124 }
2125 
2126 /*
2127  * This function is used to avoid synclosts in OMAP3, because of some
2128  * undocumented horizontal position and timing related limitations.
2129  */
2130 static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk,
2131 		const struct videomode *vm, u16 pos_x,
2132 		u16 width, u16 height, u16 out_width, u16 out_height,
2133 		bool five_taps)
2134 {
2135 	const int ds = DIV_ROUND_UP(height, out_height);
2136 	unsigned long nonactive;
2137 	static const u8 limits[3] = { 8, 10, 20 };
2138 	u64 val, blank;
2139 	int i;
2140 
2141 	nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len +
2142 		    vm->hback_porch - out_width;
2143 
2144 	i = 0;
2145 	if (out_height < height)
2146 		i++;
2147 	if (out_width < width)
2148 		i++;
2149 	blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) *
2150 			lclk, pclk);
2151 	DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
2152 	if (blank <= limits[i])
2153 		return -EINVAL;
2154 
2155 	/* FIXME add checks for 3-tap filter once the limitations are known */
2156 	if (!five_taps)
2157 		return 0;
2158 
2159 	/*
2160 	 * Pixel data should be prepared before visible display point starts.
2161 	 * So, atleast DS-2 lines must have already been fetched by DISPC
2162 	 * during nonactive - pos_x period.
2163 	 */
2164 	val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
2165 	DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
2166 		val, max(0, ds - 2) * width);
2167 	if (val < max(0, ds - 2) * width)
2168 		return -EINVAL;
2169 
2170 	/*
2171 	 * All lines need to be refilled during the nonactive period of which
2172 	 * only one line can be loaded during the active period. So, atleast
2173 	 * DS - 1 lines should be loaded during nonactive period.
2174 	 */
2175 	val =  div_u64((u64)nonactive * lclk, pclk);
2176 	DSSDBG("nonactive * pcd  = %llu, max(0, DS - 1) * width = %d\n",
2177 		val, max(0, ds - 1) * width);
2178 	if (val < max(0, ds - 1) * width)
2179 		return -EINVAL;
2180 
2181 	return 0;
2182 }
2183 
2184 static unsigned long calc_core_clk_five_taps(unsigned long pclk,
2185 		const struct videomode *vm, u16 width,
2186 		u16 height, u16 out_width, u16 out_height,
2187 		u32 fourcc)
2188 {
2189 	u32 core_clk = 0;
2190 	u64 tmp;
2191 
2192 	if (height <= out_height && width <= out_width)
2193 		return (unsigned long) pclk;
2194 
2195 	if (height > out_height) {
2196 		unsigned int ppl = vm->hactive;
2197 
2198 		tmp = (u64)pclk * height * out_width;
2199 		do_div(tmp, 2 * out_height * ppl);
2200 		core_clk = tmp;
2201 
2202 		if (height > 2 * out_height) {
2203 			if (ppl == out_width)
2204 				return 0;
2205 
2206 			tmp = (u64)pclk * (height - 2 * out_height) * out_width;
2207 			do_div(tmp, 2 * out_height * (ppl - out_width));
2208 			core_clk = max_t(u32, core_clk, tmp);
2209 		}
2210 	}
2211 
2212 	if (width > out_width) {
2213 		tmp = (u64)pclk * width;
2214 		do_div(tmp, out_width);
2215 		core_clk = max_t(u32, core_clk, tmp);
2216 
2217 		if (fourcc == DRM_FORMAT_XRGB8888)
2218 			core_clk <<= 1;
2219 	}
2220 
2221 	return core_clk;
2222 }
2223 
2224 static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width,
2225 		u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2226 {
2227 	if (height > out_height && width > out_width)
2228 		return pclk * 4;
2229 	else
2230 		return pclk * 2;
2231 }
2232 
2233 static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width,
2234 		u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2235 {
2236 	unsigned int hf, vf;
2237 
2238 	/*
2239 	 * FIXME how to determine the 'A' factor
2240 	 * for the no downscaling case ?
2241 	 */
2242 
2243 	if (width > 3 * out_width)
2244 		hf = 4;
2245 	else if (width > 2 * out_width)
2246 		hf = 3;
2247 	else if (width > out_width)
2248 		hf = 2;
2249 	else
2250 		hf = 1;
2251 	if (height > out_height)
2252 		vf = 2;
2253 	else
2254 		vf = 1;
2255 
2256 	return pclk * vf * hf;
2257 }
2258 
2259 static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width,
2260 		u16 height, u16 out_width, u16 out_height, bool mem_to_mem)
2261 {
2262 	/*
2263 	 * If the overlay/writeback is in mem to mem mode, there are no
2264 	 * downscaling limitations with respect to pixel clock, return 1 as
2265 	 * required core clock to represent that we have sufficient enough
2266 	 * core clock to do maximum downscaling
2267 	 */
2268 	if (mem_to_mem)
2269 		return 1;
2270 
2271 	if (width > out_width)
2272 		return DIV_ROUND_UP(pclk, out_width) * width;
2273 	else
2274 		return pclk;
2275 }
2276 
2277 static int dispc_ovl_calc_scaling_24xx(struct dispc_device *dispc,
2278 				       unsigned long pclk, unsigned long lclk,
2279 				       const struct videomode *vm,
2280 				       u16 width, u16 height,
2281 				       u16 out_width, u16 out_height,
2282 				       u32 fourcc, bool *five_taps,
2283 				       int *x_predecim, int *y_predecim,
2284 				       int *decim_x, int *decim_y,
2285 				       u16 pos_x, unsigned long *core_clk,
2286 				       bool mem_to_mem)
2287 {
2288 	int error;
2289 	u16 in_width, in_height;
2290 	int min_factor = min(*decim_x, *decim_y);
2291 	const int maxsinglelinewidth = dispc->feat->max_line_width;
2292 
2293 	*five_taps = false;
2294 
2295 	do {
2296 		in_height = height / *decim_y;
2297 		in_width = width / *decim_x;
2298 		*core_clk = dispc->feat->calc_core_clk(pclk, in_width,
2299 				in_height, out_width, out_height, mem_to_mem);
2300 		error = (in_width > maxsinglelinewidth || !*core_clk ||
2301 			*core_clk > dispc_core_clk_rate(dispc));
2302 		if (error) {
2303 			if (*decim_x == *decim_y) {
2304 				*decim_x = min_factor;
2305 				++*decim_y;
2306 			} else {
2307 				swap(*decim_x, *decim_y);
2308 				if (*decim_x < *decim_y)
2309 					++*decim_x;
2310 			}
2311 		}
2312 	} while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2313 
2314 	if (error) {
2315 		DSSERR("failed to find scaling settings\n");
2316 		return -EINVAL;
2317 	}
2318 
2319 	if (in_width > maxsinglelinewidth) {
2320 		DSSERR("Cannot scale max input width exceeded\n");
2321 		return -EINVAL;
2322 	}
2323 	return 0;
2324 }
2325 
2326 static int dispc_ovl_calc_scaling_34xx(struct dispc_device *dispc,
2327 				       unsigned long pclk, unsigned long lclk,
2328 				       const struct videomode *vm,
2329 				       u16 width, u16 height,
2330 				       u16 out_width, u16 out_height,
2331 				       u32 fourcc, bool *five_taps,
2332 				       int *x_predecim, int *y_predecim,
2333 				       int *decim_x, int *decim_y,
2334 				       u16 pos_x, unsigned long *core_clk,
2335 				       bool mem_to_mem)
2336 {
2337 	int error;
2338 	u16 in_width, in_height;
2339 	const int maxsinglelinewidth = dispc->feat->max_line_width;
2340 
2341 	do {
2342 		in_height = height / *decim_y;
2343 		in_width = width / *decim_x;
2344 		*five_taps = in_height > out_height;
2345 
2346 		if (in_width > maxsinglelinewidth)
2347 			if (in_height > out_height &&
2348 						in_height < out_height * 2)
2349 				*five_taps = false;
2350 again:
2351 		if (*five_taps)
2352 			*core_clk = calc_core_clk_five_taps(pclk, vm,
2353 						in_width, in_height, out_width,
2354 						out_height, fourcc);
2355 		else
2356 			*core_clk = dispc->feat->calc_core_clk(pclk, in_width,
2357 					in_height, out_width, out_height,
2358 					mem_to_mem);
2359 
2360 		error = check_horiz_timing_omap3(pclk, lclk, vm,
2361 				pos_x, in_width, in_height, out_width,
2362 				out_height, *five_taps);
2363 		if (error && *five_taps) {
2364 			*five_taps = false;
2365 			goto again;
2366 		}
2367 
2368 		error = (error || in_width > maxsinglelinewidth * 2 ||
2369 			(in_width > maxsinglelinewidth && *five_taps) ||
2370 			!*core_clk || *core_clk > dispc_core_clk_rate(dispc));
2371 
2372 		if (!error) {
2373 			/* verify that we're inside the limits of scaler */
2374 			if (in_width / 4 > out_width)
2375 					error = 1;
2376 
2377 			if (*five_taps) {
2378 				if (in_height / 4 > out_height)
2379 					error = 1;
2380 			} else {
2381 				if (in_height / 2 > out_height)
2382 					error = 1;
2383 			}
2384 		}
2385 
2386 		if (error)
2387 			++*decim_y;
2388 	} while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error);
2389 
2390 	if (error) {
2391 		DSSERR("failed to find scaling settings\n");
2392 		return -EINVAL;
2393 	}
2394 
2395 	if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width,
2396 				in_height, out_width, out_height, *five_taps)) {
2397 			DSSERR("horizontal timing too tight\n");
2398 			return -EINVAL;
2399 	}
2400 
2401 	if (in_width > (maxsinglelinewidth * 2)) {
2402 		DSSERR("Cannot setup scaling\n");
2403 		DSSERR("width exceeds maximum width possible\n");
2404 		return -EINVAL;
2405 	}
2406 
2407 	if (in_width > maxsinglelinewidth && *five_taps) {
2408 		DSSERR("cannot setup scaling with five taps\n");
2409 		return -EINVAL;
2410 	}
2411 	return 0;
2412 }
2413 
2414 static int dispc_ovl_calc_scaling_44xx(struct dispc_device *dispc,
2415 				       unsigned long pclk, unsigned long lclk,
2416 				       const struct videomode *vm,
2417 				       u16 width, u16 height,
2418 				       u16 out_width, u16 out_height,
2419 				       u32 fourcc, bool *five_taps,
2420 				       int *x_predecim, int *y_predecim,
2421 				       int *decim_x, int *decim_y,
2422 				       u16 pos_x, unsigned long *core_clk,
2423 				       bool mem_to_mem)
2424 {
2425 	u16 in_width, in_width_max;
2426 	int decim_x_min = *decim_x;
2427 	u16 in_height = height / *decim_y;
2428 	const int maxsinglelinewidth = dispc->feat->max_line_width;
2429 	const int maxdownscale = dispc->feat->max_downscale;
2430 
2431 	if (mem_to_mem) {
2432 		in_width_max = out_width * maxdownscale;
2433 	} else {
2434 		in_width_max = dispc_core_clk_rate(dispc)
2435 			     / DIV_ROUND_UP(pclk, out_width);
2436 	}
2437 
2438 	*decim_x = DIV_ROUND_UP(width, in_width_max);
2439 
2440 	*decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min;
2441 	if (*decim_x > *x_predecim)
2442 		return -EINVAL;
2443 
2444 	do {
2445 		in_width = width / *decim_x;
2446 	} while (*decim_x <= *x_predecim &&
2447 			in_width > maxsinglelinewidth && ++*decim_x);
2448 
2449 	if (in_width > maxsinglelinewidth) {
2450 		DSSERR("Cannot scale width exceeds max line width\n");
2451 		return -EINVAL;
2452 	}
2453 
2454 	if (*decim_x > 4 && fourcc != DRM_FORMAT_NV12) {
2455 		/*
2456 		 * Let's disable all scaling that requires horizontal
2457 		 * decimation with higher factor than 4, until we have
2458 		 * better estimates of what we can and can not
2459 		 * do. However, NV12 color format appears to work Ok
2460 		 * with all decimation factors.
2461 		 *
2462 		 * When decimating horizontally by more that 4 the dss
2463 		 * is not able to fetch the data in burst mode. When
2464 		 * this happens it is hard to tell if there enough
2465 		 * bandwidth. Despite what theory says this appears to
2466 		 * be true also for 16-bit color formats.
2467 		 */
2468 		DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)\n", *decim_x);
2469 
2470 		return -EINVAL;
2471 	}
2472 
2473 	*core_clk = dispc->feat->calc_core_clk(pclk, in_width, in_height,
2474 				out_width, out_height, mem_to_mem);
2475 	return 0;
2476 }
2477 
2478 #define DIV_FRAC(dividend, divisor) \
2479 	((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
2480 
2481 static int dispc_ovl_calc_scaling(struct dispc_device *dispc,
2482 				  enum omap_plane_id plane,
2483 				  unsigned long pclk, unsigned long lclk,
2484 				  enum omap_overlay_caps caps,
2485 				  const struct videomode *vm,
2486 				  u16 width, u16 height,
2487 				  u16 out_width, u16 out_height,
2488 				  u32 fourcc, bool *five_taps,
2489 				  int *x_predecim, int *y_predecim, u16 pos_x,
2490 				  enum omap_dss_rotation_type rotation_type,
2491 				  bool mem_to_mem)
2492 {
2493 	int maxhdownscale = dispc->feat->max_downscale;
2494 	int maxvdownscale = dispc->feat->max_downscale;
2495 	const int max_decim_limit = 16;
2496 	unsigned long core_clk = 0;
2497 	int decim_x, decim_y, ret;
2498 
2499 	if (width == out_width && height == out_height)
2500 		return 0;
2501 
2502 	if (plane == OMAP_DSS_WB) {
2503 		switch (fourcc) {
2504 		case DRM_FORMAT_NV12:
2505 			maxhdownscale = maxvdownscale = 2;
2506 			break;
2507 		case DRM_FORMAT_YUYV:
2508 		case DRM_FORMAT_UYVY:
2509 			maxhdownscale = 2;
2510 			maxvdownscale = 4;
2511 			break;
2512 		default:
2513 			break;
2514 		}
2515 	}
2516 	if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) {
2517 		DSSERR("cannot calculate scaling settings: pclk is zero\n");
2518 		return -EINVAL;
2519 	}
2520 
2521 	if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
2522 		return -EINVAL;
2523 
2524 	if (mem_to_mem) {
2525 		*x_predecim = *y_predecim = 1;
2526 	} else {
2527 		*x_predecim = max_decim_limit;
2528 		*y_predecim = (rotation_type == OMAP_DSS_ROT_TILER &&
2529 				dispc_has_feature(dispc, FEAT_BURST_2D)) ?
2530 				2 : max_decim_limit;
2531 	}
2532 
2533 	decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxhdownscale);
2534 	decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxvdownscale);
2535 
2536 	if (decim_x > *x_predecim || out_width > width * 8)
2537 		return -EINVAL;
2538 
2539 	if (decim_y > *y_predecim || out_height > height * 8)
2540 		return -EINVAL;
2541 
2542 	ret = dispc->feat->calc_scaling(dispc, pclk, lclk, vm, width, height,
2543 					out_width, out_height, fourcc,
2544 					five_taps, x_predecim, y_predecim,
2545 					&decim_x, &decim_y, pos_x, &core_clk,
2546 					mem_to_mem);
2547 	if (ret)
2548 		return ret;
2549 
2550 	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",
2551 		width, height,
2552 		out_width, out_height,
2553 		out_width / width, DIV_FRAC(out_width, width),
2554 		out_height / height, DIV_FRAC(out_height, height),
2555 
2556 		decim_x, decim_y,
2557 		width / decim_x, height / decim_y,
2558 		out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x),
2559 		out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y),
2560 
2561 		*five_taps ? 5 : 3,
2562 		core_clk, dispc_core_clk_rate(dispc));
2563 
2564 	if (!core_clk || core_clk > dispc_core_clk_rate(dispc)) {
2565 		DSSERR("failed to set up scaling, "
2566 			"required core clk rate = %lu Hz, "
2567 			"current core clk rate = %lu Hz\n",
2568 			core_clk, dispc_core_clk_rate(dispc));
2569 		return -EINVAL;
2570 	}
2571 
2572 	*x_predecim = decim_x;
2573 	*y_predecim = decim_y;
2574 	return 0;
2575 }
2576 
2577 static int dispc_ovl_setup_common(struct dispc_device *dispc,
2578 				  enum omap_plane_id plane,
2579 				  enum omap_overlay_caps caps,
2580 				  u32 paddr, u32 p_uv_addr,
2581 				  u16 screen_width, int pos_x, int pos_y,
2582 				  u16 width, u16 height,
2583 				  u16 out_width, u16 out_height,
2584 				  u32 fourcc, u8 rotation, u8 zorder,
2585 				  u8 pre_mult_alpha, u8 global_alpha,
2586 				  enum omap_dss_rotation_type rotation_type,
2587 				  bool replication, const struct videomode *vm,
2588 				  bool mem_to_mem)
2589 {
2590 	bool five_taps = true;
2591 	bool fieldmode = false;
2592 	int r, cconv = 0;
2593 	unsigned int offset0, offset1;
2594 	s32 row_inc;
2595 	s32 pix_inc;
2596 	u16 frame_width;
2597 	unsigned int field_offset = 0;
2598 	u16 in_height = height;
2599 	u16 in_width = width;
2600 	int x_predecim = 1, y_predecim = 1;
2601 	bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED);
2602 	unsigned long pclk = dispc_plane_pclk_rate(dispc, plane);
2603 	unsigned long lclk = dispc_plane_lclk_rate(dispc, plane);
2604 	const struct drm_format_info *info;
2605 
2606 	info = drm_format_info(fourcc);
2607 
2608 	/* when setting up WB, dispc_plane_pclk_rate() returns 0 */
2609 	if (plane == OMAP_DSS_WB)
2610 		pclk = vm->pixelclock;
2611 
2612 	if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER)
2613 		return -EINVAL;
2614 
2615 	if (info->is_yuv && (in_width & 1)) {
2616 		DSSERR("input width %d is not even for YUV format\n", in_width);
2617 		return -EINVAL;
2618 	}
2619 
2620 	out_width = out_width == 0 ? width : out_width;
2621 	out_height = out_height == 0 ? height : out_height;
2622 
2623 	if (plane != OMAP_DSS_WB) {
2624 		if (ilace && height == out_height)
2625 			fieldmode = true;
2626 
2627 		if (ilace) {
2628 			if (fieldmode)
2629 				in_height /= 2;
2630 			pos_y /= 2;
2631 			out_height /= 2;
2632 
2633 			DSSDBG("adjusting for ilace: height %d, pos_y %d, out_height %d\n",
2634 				in_height, pos_y, out_height);
2635 		}
2636 	}
2637 
2638 	if (!dispc_ovl_color_mode_supported(dispc, plane, fourcc))
2639 		return -EINVAL;
2640 
2641 	r = dispc_ovl_calc_scaling(dispc, plane, pclk, lclk, caps, vm, in_width,
2642 				   in_height, out_width, out_height, fourcc,
2643 				   &five_taps, &x_predecim, &y_predecim, pos_x,
2644 				   rotation_type, mem_to_mem);
2645 	if (r)
2646 		return r;
2647 
2648 	in_width = in_width / x_predecim;
2649 	in_height = in_height / y_predecim;
2650 
2651 	if (x_predecim > 1 || y_predecim > 1)
2652 		DSSDBG("predecimation %d x %x, new input size %d x %d\n",
2653 			x_predecim, y_predecim, in_width, in_height);
2654 
2655 	if (info->is_yuv && (in_width & 1)) {
2656 		DSSDBG("predecimated input width is not even for YUV format\n");
2657 		DSSDBG("adjusting input width %d -> %d\n",
2658 			in_width, in_width & ~1);
2659 
2660 		in_width &= ~1;
2661 	}
2662 
2663 	if (info->is_yuv)
2664 		cconv = 1;
2665 
2666 	if (ilace && !fieldmode) {
2667 		/*
2668 		 * when downscaling the bottom field may have to start several
2669 		 * source lines below the top field. Unfortunately ACCUI
2670 		 * registers will only hold the fractional part of the offset
2671 		 * so the integer part must be added to the base address of the
2672 		 * bottom field.
2673 		 */
2674 		if (!in_height || in_height == out_height)
2675 			field_offset = 0;
2676 		else
2677 			field_offset = in_height / out_height / 2;
2678 	}
2679 
2680 	/* Fields are independent but interleaved in memory. */
2681 	if (fieldmode)
2682 		field_offset = 1;
2683 
2684 	offset0 = 0;
2685 	offset1 = 0;
2686 	row_inc = 0;
2687 	pix_inc = 0;
2688 
2689 	if (plane == OMAP_DSS_WB)
2690 		frame_width = out_width;
2691 	else
2692 		frame_width = in_width;
2693 
2694 	calc_offset(screen_width, frame_width,
2695 			fourcc, fieldmode, field_offset,
2696 			&offset0, &offset1, &row_inc, &pix_inc,
2697 			x_predecim, y_predecim,
2698 			rotation_type, rotation);
2699 
2700 	DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
2701 			offset0, offset1, row_inc, pix_inc);
2702 
2703 	dispc_ovl_set_color_mode(dispc, plane, fourcc);
2704 
2705 	dispc_ovl_configure_burst_type(dispc, plane, rotation_type);
2706 
2707 	if (dispc->feat->reverse_ilace_field_order)
2708 		swap(offset0, offset1);
2709 
2710 	dispc_ovl_set_ba0(dispc, plane, paddr + offset0);
2711 	dispc_ovl_set_ba1(dispc, plane, paddr + offset1);
2712 
2713 	if (fourcc == DRM_FORMAT_NV12) {
2714 		dispc_ovl_set_ba0_uv(dispc, plane, p_uv_addr + offset0);
2715 		dispc_ovl_set_ba1_uv(dispc, plane, p_uv_addr + offset1);
2716 	}
2717 
2718 	if (dispc->feat->last_pixel_inc_missing)
2719 		row_inc += pix_inc - 1;
2720 
2721 	dispc_ovl_set_row_inc(dispc, plane, row_inc);
2722 	dispc_ovl_set_pix_inc(dispc, plane, pix_inc);
2723 
2724 	DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width,
2725 			in_height, out_width, out_height);
2726 
2727 	dispc_ovl_set_pos(dispc, plane, caps, pos_x, pos_y);
2728 
2729 	dispc_ovl_set_input_size(dispc, plane, in_width, in_height);
2730 
2731 	if (caps & OMAP_DSS_OVL_CAP_SCALE) {
2732 		dispc_ovl_set_scaling(dispc, plane, in_width, in_height,
2733 				      out_width, out_height, ilace, five_taps,
2734 				      fieldmode, fourcc, rotation);
2735 		dispc_ovl_set_output_size(dispc, plane, out_width, out_height);
2736 		dispc_ovl_set_vid_color_conv(dispc, plane, cconv);
2737 	}
2738 
2739 	dispc_ovl_set_rotation_attrs(dispc, plane, rotation, rotation_type,
2740 				     fourcc);
2741 
2742 	dispc_ovl_set_zorder(dispc, plane, caps, zorder);
2743 	dispc_ovl_set_pre_mult_alpha(dispc, plane, caps, pre_mult_alpha);
2744 	dispc_ovl_setup_global_alpha(dispc, plane, caps, global_alpha);
2745 
2746 	dispc_ovl_enable_replication(dispc, plane, caps, replication);
2747 
2748 	return 0;
2749 }
2750 
2751 static int dispc_ovl_setup(struct dispc_device *dispc,
2752 			   enum omap_plane_id plane,
2753 			   const struct omap_overlay_info *oi,
2754 			   const struct videomode *vm, bool mem_to_mem,
2755 			   enum omap_channel channel)
2756 {
2757 	int r;
2758 	enum omap_overlay_caps caps = dispc->feat->overlay_caps[plane];
2759 	const bool replication = true;
2760 
2761 	DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->"
2762 		" %dx%d, cmode %x, rot %d, chan %d repl %d\n",
2763 		plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x,
2764 		oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height,
2765 		oi->fourcc, oi->rotation, channel, replication);
2766 
2767 	dispc_ovl_set_channel_out(dispc, plane, channel);
2768 
2769 	r = dispc_ovl_setup_common(dispc, plane, caps, oi->paddr, oi->p_uv_addr,
2770 		oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height,
2771 		oi->out_width, oi->out_height, oi->fourcc, oi->rotation,
2772 		oi->zorder, oi->pre_mult_alpha, oi->global_alpha,
2773 		oi->rotation_type, replication, vm, mem_to_mem);
2774 
2775 	return r;
2776 }
2777 
2778 static int dispc_wb_setup(struct dispc_device *dispc,
2779 		   const struct omap_dss_writeback_info *wi,
2780 		   bool mem_to_mem, const struct videomode *vm,
2781 		   enum dss_writeback_channel channel_in)
2782 {
2783 	int r;
2784 	u32 l;
2785 	enum omap_plane_id plane = OMAP_DSS_WB;
2786 	const int pos_x = 0, pos_y = 0;
2787 	const u8 zorder = 0, global_alpha = 0;
2788 	const bool replication = true;
2789 	bool truncation;
2790 	int in_width = vm->hactive;
2791 	int in_height = vm->vactive;
2792 	enum omap_overlay_caps caps =
2793 		OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA;
2794 
2795 	if (vm->flags & DISPLAY_FLAGS_INTERLACED)
2796 		in_height /= 2;
2797 
2798 	DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, "
2799 		"rot %d\n", wi->paddr, wi->p_uv_addr, in_width,
2800 		in_height, wi->width, wi->height, wi->fourcc, wi->rotation);
2801 
2802 	r = dispc_ovl_setup_common(dispc, plane, caps, wi->paddr, wi->p_uv_addr,
2803 		wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width,
2804 		wi->height, wi->fourcc, wi->rotation, zorder,
2805 		wi->pre_mult_alpha, global_alpha, wi->rotation_type,
2806 		replication, vm, mem_to_mem);
2807 	if (r)
2808 		return r;
2809 
2810 	switch (wi->fourcc) {
2811 	case DRM_FORMAT_RGB565:
2812 	case DRM_FORMAT_RGB888:
2813 	case DRM_FORMAT_ARGB4444:
2814 	case DRM_FORMAT_RGBA4444:
2815 	case DRM_FORMAT_RGBX4444:
2816 	case DRM_FORMAT_ARGB1555:
2817 	case DRM_FORMAT_XRGB1555:
2818 	case DRM_FORMAT_XRGB4444:
2819 		truncation = true;
2820 		break;
2821 	default:
2822 		truncation = false;
2823 		break;
2824 	}
2825 
2826 	/* setup extra DISPC_WB_ATTRIBUTES */
2827 	l = dispc_read_reg(dispc, DISPC_OVL_ATTRIBUTES(plane));
2828 	l = FLD_MOD(l, truncation, 10, 10);	/* TRUNCATIONENABLE */
2829 	l = FLD_MOD(l, channel_in, 18, 16);	/* CHANNELIN */
2830 	l = FLD_MOD(l, mem_to_mem, 19, 19);	/* WRITEBACKMODE */
2831 	if (mem_to_mem)
2832 		l = FLD_MOD(l, 1, 26, 24);	/* CAPTUREMODE */
2833 	else
2834 		l = FLD_MOD(l, 0, 26, 24);	/* CAPTUREMODE */
2835 	dispc_write_reg(dispc, DISPC_OVL_ATTRIBUTES(plane), l);
2836 
2837 	if (mem_to_mem) {
2838 		/* WBDELAYCOUNT */
2839 		REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0);
2840 	} else {
2841 		u32 wbdelay;
2842 
2843 		if (channel_in == DSS_WB_TV_MGR)
2844 			wbdelay = vm->vsync_len + vm->vback_porch;
2845 		else
2846 			wbdelay = vm->vfront_porch + vm->vsync_len +
2847 				vm->vback_porch;
2848 
2849 		if (vm->flags & DISPLAY_FLAGS_INTERLACED)
2850 			wbdelay /= 2;
2851 
2852 		wbdelay = min(wbdelay, 255u);
2853 
2854 		/* WBDELAYCOUNT */
2855 		REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0);
2856 	}
2857 
2858 	return 0;
2859 }
2860 
2861 static bool dispc_has_writeback(struct dispc_device *dispc)
2862 {
2863 	return dispc->feat->has_writeback;
2864 }
2865 
2866 static int dispc_ovl_enable(struct dispc_device *dispc,
2867 			    enum omap_plane_id plane, bool enable)
2868 {
2869 	DSSDBG("dispc_enable_plane %d, %d\n", plane, enable);
2870 
2871 	REG_FLD_MOD(dispc, DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0);
2872 
2873 	return 0;
2874 }
2875 
2876 static void dispc_lcd_enable_signal_polarity(struct dispc_device *dispc,
2877 					     bool act_high)
2878 {
2879 	if (!dispc_has_feature(dispc, FEAT_LCDENABLEPOL))
2880 		return;
2881 
2882 	REG_FLD_MOD(dispc, DISPC_CONTROL, act_high ? 1 : 0, 29, 29);
2883 }
2884 
2885 void dispc_lcd_enable_signal(struct dispc_device *dispc, bool enable)
2886 {
2887 	if (!dispc_has_feature(dispc, FEAT_LCDENABLESIGNAL))
2888 		return;
2889 
2890 	REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 28, 28);
2891 }
2892 
2893 void dispc_pck_free_enable(struct dispc_device *dispc, bool enable)
2894 {
2895 	if (!dispc_has_feature(dispc, FEAT_PCKFREEENABLE))
2896 		return;
2897 
2898 	REG_FLD_MOD(dispc, DISPC_CONTROL, enable ? 1 : 0, 27, 27);
2899 }
2900 
2901 static void dispc_mgr_enable_fifohandcheck(struct dispc_device *dispc,
2902 					   enum omap_channel channel,
2903 					   bool enable)
2904 {
2905 	mgr_fld_write(dispc, channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable);
2906 }
2907 
2908 
2909 static void dispc_mgr_set_lcd_type_tft(struct dispc_device *dispc,
2910 				       enum omap_channel channel)
2911 {
2912 	mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STNTFT, 1);
2913 }
2914 
2915 static void dispc_set_loadmode(struct dispc_device *dispc,
2916 			       enum omap_dss_load_mode mode)
2917 {
2918 	REG_FLD_MOD(dispc, DISPC_CONFIG, mode, 2, 1);
2919 }
2920 
2921 
2922 static void dispc_mgr_set_default_color(struct dispc_device *dispc,
2923 					enum omap_channel channel, u32 color)
2924 {
2925 	dispc_write_reg(dispc, DISPC_DEFAULT_COLOR(channel), color);
2926 }
2927 
2928 static void dispc_mgr_set_trans_key(struct dispc_device *dispc,
2929 				    enum omap_channel ch,
2930 				    enum omap_dss_trans_key_type type,
2931 				    u32 trans_key)
2932 {
2933 	mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKSELECTION, type);
2934 
2935 	dispc_write_reg(dispc, DISPC_TRANS_COLOR(ch), trans_key);
2936 }
2937 
2938 static void dispc_mgr_enable_trans_key(struct dispc_device *dispc,
2939 				       enum omap_channel ch, bool enable)
2940 {
2941 	mgr_fld_write(dispc, ch, DISPC_MGR_FLD_TCKENABLE, enable);
2942 }
2943 
2944 static void dispc_mgr_enable_alpha_fixed_zorder(struct dispc_device *dispc,
2945 						enum omap_channel ch,
2946 						bool enable)
2947 {
2948 	if (!dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER))
2949 		return;
2950 
2951 	if (ch == OMAP_DSS_CHANNEL_LCD)
2952 		REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 18, 18);
2953 	else if (ch == OMAP_DSS_CHANNEL_DIGIT)
2954 		REG_FLD_MOD(dispc, DISPC_CONFIG, enable, 19, 19);
2955 }
2956 
2957 static void dispc_mgr_setup(struct dispc_device *dispc,
2958 			    enum omap_channel channel,
2959 			    const struct omap_overlay_manager_info *info)
2960 {
2961 	dispc_mgr_set_default_color(dispc, channel, info->default_color);
2962 	dispc_mgr_set_trans_key(dispc, channel, info->trans_key_type,
2963 				info->trans_key);
2964 	dispc_mgr_enable_trans_key(dispc, channel, info->trans_enabled);
2965 	dispc_mgr_enable_alpha_fixed_zorder(dispc, channel,
2966 			info->partial_alpha_enabled);
2967 	if (dispc_has_feature(dispc, FEAT_CPR)) {
2968 		dispc_mgr_enable_cpr(dispc, channel, info->cpr_enable);
2969 		dispc_mgr_set_cpr_coef(dispc, channel, &info->cpr_coefs);
2970 	}
2971 }
2972 
2973 static void dispc_mgr_set_tft_data_lines(struct dispc_device *dispc,
2974 					 enum omap_channel channel,
2975 					 u8 data_lines)
2976 {
2977 	int code;
2978 
2979 	switch (data_lines) {
2980 	case 12:
2981 		code = 0;
2982 		break;
2983 	case 16:
2984 		code = 1;
2985 		break;
2986 	case 18:
2987 		code = 2;
2988 		break;
2989 	case 24:
2990 		code = 3;
2991 		break;
2992 	default:
2993 		BUG();
2994 		return;
2995 	}
2996 
2997 	mgr_fld_write(dispc, channel, DISPC_MGR_FLD_TFTDATALINES, code);
2998 }
2999 
3000 static void dispc_mgr_set_io_pad_mode(struct dispc_device *dispc,
3001 				      enum dss_io_pad_mode mode)
3002 {
3003 	u32 l;
3004 	int gpout0, gpout1;
3005 
3006 	switch (mode) {
3007 	case DSS_IO_PAD_MODE_RESET:
3008 		gpout0 = 0;
3009 		gpout1 = 0;
3010 		break;
3011 	case DSS_IO_PAD_MODE_RFBI:
3012 		gpout0 = 1;
3013 		gpout1 = 0;
3014 		break;
3015 	case DSS_IO_PAD_MODE_BYPASS:
3016 		gpout0 = 1;
3017 		gpout1 = 1;
3018 		break;
3019 	default:
3020 		BUG();
3021 		return;
3022 	}
3023 
3024 	l = dispc_read_reg(dispc, DISPC_CONTROL);
3025 	l = FLD_MOD(l, gpout0, 15, 15);
3026 	l = FLD_MOD(l, gpout1, 16, 16);
3027 	dispc_write_reg(dispc, DISPC_CONTROL, l);
3028 }
3029 
3030 static void dispc_mgr_enable_stallmode(struct dispc_device *dispc,
3031 				       enum omap_channel channel, bool enable)
3032 {
3033 	mgr_fld_write(dispc, channel, DISPC_MGR_FLD_STALLMODE, enable);
3034 }
3035 
3036 static void dispc_mgr_set_lcd_config(struct dispc_device *dispc,
3037 				     enum omap_channel channel,
3038 				     const struct dss_lcd_mgr_config *config)
3039 {
3040 	dispc_mgr_set_io_pad_mode(dispc, config->io_pad_mode);
3041 
3042 	dispc_mgr_enable_stallmode(dispc, channel, config->stallmode);
3043 	dispc_mgr_enable_fifohandcheck(dispc, channel, config->fifohandcheck);
3044 
3045 	dispc_mgr_set_clock_div(dispc, channel, &config->clock_info);
3046 
3047 	dispc_mgr_set_tft_data_lines(dispc, channel, config->video_port_width);
3048 
3049 	dispc_lcd_enable_signal_polarity(dispc, config->lcden_sig_polarity);
3050 
3051 	dispc_mgr_set_lcd_type_tft(dispc, channel);
3052 }
3053 
3054 static bool _dispc_mgr_size_ok(struct dispc_device *dispc,
3055 			       u16 width, u16 height)
3056 {
3057 	return width <= dispc->feat->mgr_width_max &&
3058 		height <= dispc->feat->mgr_height_max;
3059 }
3060 
3061 static bool _dispc_lcd_timings_ok(struct dispc_device *dispc,
3062 				  int hsync_len, int hfp, int hbp,
3063 				  int vsw, int vfp, int vbp)
3064 {
3065 	if (hsync_len < 1 || hsync_len > dispc->feat->sw_max ||
3066 	    hfp < 1 || hfp > dispc->feat->hp_max ||
3067 	    hbp < 1 || hbp > dispc->feat->hp_max ||
3068 	    vsw < 1 || vsw > dispc->feat->sw_max ||
3069 	    vfp < 0 || vfp > dispc->feat->vp_max ||
3070 	    vbp < 0 || vbp > dispc->feat->vp_max)
3071 		return false;
3072 	return true;
3073 }
3074 
3075 static bool _dispc_mgr_pclk_ok(struct dispc_device *dispc,
3076 			       enum omap_channel channel,
3077 			       unsigned long pclk)
3078 {
3079 	if (dss_mgr_is_lcd(channel))
3080 		return pclk <= dispc->feat->max_lcd_pclk;
3081 	else
3082 		return pclk <= dispc->feat->max_tv_pclk;
3083 }
3084 
3085 static int dispc_mgr_check_timings(struct dispc_device *dispc,
3086 				   enum omap_channel channel,
3087 				   const struct videomode *vm)
3088 {
3089 	if (!_dispc_mgr_size_ok(dispc, vm->hactive, vm->vactive))
3090 		return MODE_BAD;
3091 
3092 	if (!_dispc_mgr_pclk_ok(dispc, channel, vm->pixelclock))
3093 		return MODE_BAD;
3094 
3095 	if (dss_mgr_is_lcd(channel)) {
3096 		/* TODO: OMAP4+ supports interlace for LCD outputs */
3097 		if (vm->flags & DISPLAY_FLAGS_INTERLACED)
3098 			return MODE_BAD;
3099 
3100 		if (!_dispc_lcd_timings_ok(dispc, vm->hsync_len,
3101 				vm->hfront_porch, vm->hback_porch,
3102 				vm->vsync_len, vm->vfront_porch,
3103 				vm->vback_porch))
3104 			return MODE_BAD;
3105 	}
3106 
3107 	return MODE_OK;
3108 }
3109 
3110 static void _dispc_mgr_set_lcd_timings(struct dispc_device *dispc,
3111 				       enum omap_channel channel,
3112 				       const struct videomode *vm)
3113 {
3114 	u32 timing_h, timing_v, l;
3115 	bool onoff, rf, ipc, vs, hs, de;
3116 
3117 	timing_h = FLD_VAL(vm->hsync_len - 1, dispc->feat->sw_start, 0) |
3118 		   FLD_VAL(vm->hfront_porch - 1, dispc->feat->fp_start, 8) |
3119 		   FLD_VAL(vm->hback_porch - 1, dispc->feat->bp_start, 20);
3120 	timing_v = FLD_VAL(vm->vsync_len - 1, dispc->feat->sw_start, 0) |
3121 		   FLD_VAL(vm->vfront_porch, dispc->feat->fp_start, 8) |
3122 		   FLD_VAL(vm->vback_porch, dispc->feat->bp_start, 20);
3123 
3124 	dispc_write_reg(dispc, DISPC_TIMING_H(channel), timing_h);
3125 	dispc_write_reg(dispc, DISPC_TIMING_V(channel), timing_v);
3126 
3127 	if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH)
3128 		vs = false;
3129 	else
3130 		vs = true;
3131 
3132 	if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH)
3133 		hs = false;
3134 	else
3135 		hs = true;
3136 
3137 	if (vm->flags & DISPLAY_FLAGS_DE_HIGH)
3138 		de = false;
3139 	else
3140 		de = true;
3141 
3142 	if (vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
3143 		ipc = false;
3144 	else
3145 		ipc = true;
3146 
3147 	/* always use the 'rf' setting */
3148 	onoff = true;
3149 
3150 	if (vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE)
3151 		rf = true;
3152 	else
3153 		rf = false;
3154 
3155 	l = FLD_VAL(onoff, 17, 17) |
3156 		FLD_VAL(rf, 16, 16) |
3157 		FLD_VAL(de, 15, 15) |
3158 		FLD_VAL(ipc, 14, 14) |
3159 		FLD_VAL(hs, 13, 13) |
3160 		FLD_VAL(vs, 12, 12);
3161 
3162 	/* always set ALIGN bit when available */
3163 	if (dispc->feat->supports_sync_align)
3164 		l |= (1 << 18);
3165 
3166 	dispc_write_reg(dispc, DISPC_POL_FREQ(channel), l);
3167 
3168 	if (dispc->syscon_pol) {
3169 		const int shifts[] = {
3170 			[OMAP_DSS_CHANNEL_LCD] = 0,
3171 			[OMAP_DSS_CHANNEL_LCD2] = 1,
3172 			[OMAP_DSS_CHANNEL_LCD3] = 2,
3173 		};
3174 
3175 		u32 mask, val;
3176 
3177 		mask = (1 << 0) | (1 << 3) | (1 << 6);
3178 		val = (rf << 0) | (ipc << 3) | (onoff << 6);
3179 
3180 		mask <<= 16 + shifts[channel];
3181 		val <<= 16 + shifts[channel];
3182 
3183 		regmap_update_bits(dispc->syscon_pol, dispc->syscon_pol_offset,
3184 				   mask, val);
3185 	}
3186 }
3187 
3188 static int vm_flag_to_int(enum display_flags flags, enum display_flags high,
3189 	enum display_flags low)
3190 {
3191 	if (flags & high)
3192 		return 1;
3193 	if (flags & low)
3194 		return -1;
3195 	return 0;
3196 }
3197 
3198 /* change name to mode? */
3199 static void dispc_mgr_set_timings(struct dispc_device *dispc,
3200 				  enum omap_channel channel,
3201 				  const struct videomode *vm)
3202 {
3203 	unsigned int xtot, ytot;
3204 	unsigned long ht, vt;
3205 	struct videomode t = *vm;
3206 
3207 	DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
3208 
3209 	if (dispc_mgr_check_timings(dispc, channel, &t)) {
3210 		BUG();
3211 		return;
3212 	}
3213 
3214 	if (dss_mgr_is_lcd(channel)) {
3215 		_dispc_mgr_set_lcd_timings(dispc, channel, &t);
3216 
3217 		xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch;
3218 		ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch;
3219 
3220 		ht = vm->pixelclock / xtot;
3221 		vt = vm->pixelclock / xtot / ytot;
3222 
3223 		DSSDBG("pck %lu\n", vm->pixelclock);
3224 		DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
3225 			t.hsync_len, t.hfront_porch, t.hback_porch,
3226 			t.vsync_len, t.vfront_porch, t.vback_porch);
3227 		DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n",
3228 			vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW),
3229 			vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW),
3230 			vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE),
3231 			vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW),
3232 			vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE));
3233 
3234 		DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
3235 	} else {
3236 		if (t.flags & DISPLAY_FLAGS_INTERLACED)
3237 			t.vactive /= 2;
3238 
3239 		if (dispc->feat->supports_double_pixel)
3240 			REG_FLD_MOD(dispc, DISPC_CONTROL,
3241 				    !!(t.flags & DISPLAY_FLAGS_DOUBLECLK),
3242 				    19, 17);
3243 	}
3244 
3245 	dispc_mgr_set_size(dispc, channel, t.hactive, t.vactive);
3246 }
3247 
3248 static void dispc_mgr_set_lcd_divisor(struct dispc_device *dispc,
3249 				      enum omap_channel channel, u16 lck_div,
3250 				      u16 pck_div)
3251 {
3252 	BUG_ON(lck_div < 1);
3253 	BUG_ON(pck_div < 1);
3254 
3255 	dispc_write_reg(dispc, DISPC_DIVISORo(channel),
3256 			FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0));
3257 
3258 	if (!dispc_has_feature(dispc, FEAT_CORE_CLK_DIV) &&
3259 			channel == OMAP_DSS_CHANNEL_LCD)
3260 		dispc->core_clk_rate = dispc_fclk_rate(dispc) / lck_div;
3261 }
3262 
3263 static void dispc_mgr_get_lcd_divisor(struct dispc_device *dispc,
3264 				      enum omap_channel channel, int *lck_div,
3265 				      int *pck_div)
3266 {
3267 	u32 l;
3268 	l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
3269 	*lck_div = FLD_GET(l, 23, 16);
3270 	*pck_div = FLD_GET(l, 7, 0);
3271 }
3272 
3273 static unsigned long dispc_fclk_rate(struct dispc_device *dispc)
3274 {
3275 	unsigned long r;
3276 	enum dss_clk_source src;
3277 
3278 	src = dss_get_dispc_clk_source(dispc->dss);
3279 
3280 	if (src == DSS_CLK_SRC_FCK) {
3281 		r = dss_get_dispc_clk_rate(dispc->dss);
3282 	} else {
3283 		struct dss_pll *pll;
3284 		unsigned int clkout_idx;
3285 
3286 		pll = dss_pll_find_by_src(dispc->dss, src);
3287 		clkout_idx = dss_pll_get_clkout_idx_for_src(src);
3288 
3289 		r = pll->cinfo.clkout[clkout_idx];
3290 	}
3291 
3292 	return r;
3293 }
3294 
3295 static unsigned long dispc_mgr_lclk_rate(struct dispc_device *dispc,
3296 					 enum omap_channel channel)
3297 {
3298 	int lcd;
3299 	unsigned long r;
3300 	enum dss_clk_source src;
3301 
3302 	/* for TV, LCLK rate is the FCLK rate */
3303 	if (!dss_mgr_is_lcd(channel))
3304 		return dispc_fclk_rate(dispc);
3305 
3306 	src = dss_get_lcd_clk_source(dispc->dss, channel);
3307 
3308 	if (src == DSS_CLK_SRC_FCK) {
3309 		r = dss_get_dispc_clk_rate(dispc->dss);
3310 	} else {
3311 		struct dss_pll *pll;
3312 		unsigned int clkout_idx;
3313 
3314 		pll = dss_pll_find_by_src(dispc->dss, src);
3315 		clkout_idx = dss_pll_get_clkout_idx_for_src(src);
3316 
3317 		r = pll->cinfo.clkout[clkout_idx];
3318 	}
3319 
3320 	lcd = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
3321 
3322 	return r / lcd;
3323 }
3324 
3325 static unsigned long dispc_mgr_pclk_rate(struct dispc_device *dispc,
3326 					 enum omap_channel channel)
3327 {
3328 	unsigned long r;
3329 
3330 	if (dss_mgr_is_lcd(channel)) {
3331 		int pcd;
3332 		u32 l;
3333 
3334 		l = dispc_read_reg(dispc, DISPC_DIVISORo(channel));
3335 
3336 		pcd = FLD_GET(l, 7, 0);
3337 
3338 		r = dispc_mgr_lclk_rate(dispc, channel);
3339 
3340 		return r / pcd;
3341 	} else {
3342 		return dispc->tv_pclk_rate;
3343 	}
3344 }
3345 
3346 void dispc_set_tv_pclk(struct dispc_device *dispc, unsigned long pclk)
3347 {
3348 	dispc->tv_pclk_rate = pclk;
3349 }
3350 
3351 static unsigned long dispc_core_clk_rate(struct dispc_device *dispc)
3352 {
3353 	return dispc->core_clk_rate;
3354 }
3355 
3356 static unsigned long dispc_plane_pclk_rate(struct dispc_device *dispc,
3357 					   enum omap_plane_id plane)
3358 {
3359 	enum omap_channel channel;
3360 
3361 	if (plane == OMAP_DSS_WB)
3362 		return 0;
3363 
3364 	channel = dispc_ovl_get_channel_out(dispc, plane);
3365 
3366 	return dispc_mgr_pclk_rate(dispc, channel);
3367 }
3368 
3369 static unsigned long dispc_plane_lclk_rate(struct dispc_device *dispc,
3370 					   enum omap_plane_id plane)
3371 {
3372 	enum omap_channel channel;
3373 
3374 	if (plane == OMAP_DSS_WB)
3375 		return 0;
3376 
3377 	channel	= dispc_ovl_get_channel_out(dispc, plane);
3378 
3379 	return dispc_mgr_lclk_rate(dispc, channel);
3380 }
3381 
3382 static void dispc_dump_clocks_channel(struct dispc_device *dispc,
3383 				      struct seq_file *s,
3384 				      enum omap_channel channel)
3385 {
3386 	int lcd, pcd;
3387 	enum dss_clk_source lcd_clk_src;
3388 
3389 	seq_printf(s, "- %s -\n", mgr_desc[channel].name);
3390 
3391 	lcd_clk_src = dss_get_lcd_clk_source(dispc->dss, channel);
3392 
3393 	seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name,
3394 		dss_get_clk_source_name(lcd_clk_src));
3395 
3396 	dispc_mgr_get_lcd_divisor(dispc, channel, &lcd, &pcd);
3397 
3398 	seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3399 		dispc_mgr_lclk_rate(dispc, channel), lcd);
3400 	seq_printf(s, "pck\t\t%-16lupck div\t%u\n",
3401 		dispc_mgr_pclk_rate(dispc, channel), pcd);
3402 }
3403 
3404 void dispc_dump_clocks(struct dispc_device *dispc, struct seq_file *s)
3405 {
3406 	enum dss_clk_source dispc_clk_src;
3407 	int lcd;
3408 	u32 l;
3409 
3410 	if (dispc_runtime_get(dispc))
3411 		return;
3412 
3413 	seq_printf(s, "- DISPC -\n");
3414 
3415 	dispc_clk_src = dss_get_dispc_clk_source(dispc->dss);
3416 	seq_printf(s, "dispc fclk source = %s\n",
3417 			dss_get_clk_source_name(dispc_clk_src));
3418 
3419 	seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate(dispc));
3420 
3421 	if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
3422 		seq_printf(s, "- DISPC-CORE-CLK -\n");
3423 		l = dispc_read_reg(dispc, DISPC_DIVISOR);
3424 		lcd = FLD_GET(l, 23, 16);
3425 
3426 		seq_printf(s, "lck\t\t%-16lulck div\t%u\n",
3427 				(dispc_fclk_rate(dispc)/lcd), lcd);
3428 	}
3429 
3430 	dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD);
3431 
3432 	if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
3433 		dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD2);
3434 	if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
3435 		dispc_dump_clocks_channel(dispc, s, OMAP_DSS_CHANNEL_LCD3);
3436 
3437 	dispc_runtime_put(dispc);
3438 }
3439 
3440 static int dispc_dump_regs(struct seq_file *s, void *p)
3441 {
3442 	struct dispc_device *dispc = s->private;
3443 	int i, j;
3444 	const char *mgr_names[] = {
3445 		[OMAP_DSS_CHANNEL_LCD]		= "LCD",
3446 		[OMAP_DSS_CHANNEL_DIGIT]	= "TV",
3447 		[OMAP_DSS_CHANNEL_LCD2]		= "LCD2",
3448 		[OMAP_DSS_CHANNEL_LCD3]		= "LCD3",
3449 	};
3450 	const char *ovl_names[] = {
3451 		[OMAP_DSS_GFX]		= "GFX",
3452 		[OMAP_DSS_VIDEO1]	= "VID1",
3453 		[OMAP_DSS_VIDEO2]	= "VID2",
3454 		[OMAP_DSS_VIDEO3]	= "VID3",
3455 		[OMAP_DSS_WB]		= "WB",
3456 	};
3457 	const char **p_names;
3458 
3459 #define DUMPREG(dispc, r) \
3460 	seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(dispc, r))
3461 
3462 	if (dispc_runtime_get(dispc))
3463 		return 0;
3464 
3465 	/* DISPC common registers */
3466 	DUMPREG(dispc, DISPC_REVISION);
3467 	DUMPREG(dispc, DISPC_SYSCONFIG);
3468 	DUMPREG(dispc, DISPC_SYSSTATUS);
3469 	DUMPREG(dispc, DISPC_IRQSTATUS);
3470 	DUMPREG(dispc, DISPC_IRQENABLE);
3471 	DUMPREG(dispc, DISPC_CONTROL);
3472 	DUMPREG(dispc, DISPC_CONFIG);
3473 	DUMPREG(dispc, DISPC_CAPABLE);
3474 	DUMPREG(dispc, DISPC_LINE_STATUS);
3475 	DUMPREG(dispc, DISPC_LINE_NUMBER);
3476 	if (dispc_has_feature(dispc, FEAT_ALPHA_FIXED_ZORDER) ||
3477 			dispc_has_feature(dispc, FEAT_ALPHA_FREE_ZORDER))
3478 		DUMPREG(dispc, DISPC_GLOBAL_ALPHA);
3479 	if (dispc_has_feature(dispc, FEAT_MGR_LCD2)) {
3480 		DUMPREG(dispc, DISPC_CONTROL2);
3481 		DUMPREG(dispc, DISPC_CONFIG2);
3482 	}
3483 	if (dispc_has_feature(dispc, FEAT_MGR_LCD3)) {
3484 		DUMPREG(dispc, DISPC_CONTROL3);
3485 		DUMPREG(dispc, DISPC_CONFIG3);
3486 	}
3487 	if (dispc_has_feature(dispc, FEAT_MFLAG))
3488 		DUMPREG(dispc, DISPC_GLOBAL_MFLAG_ATTRIBUTE);
3489 
3490 #undef DUMPREG
3491 
3492 #define DISPC_REG(i, name) name(i)
3493 #define DUMPREG(dispc, i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \
3494 	(int)(48 - strlen(#r) - strlen(p_names[i])), " ", \
3495 	dispc_read_reg(dispc, DISPC_REG(i, r)))
3496 
3497 	p_names = mgr_names;
3498 
3499 	/* DISPC channel specific registers */
3500 	for (i = 0; i < dispc_get_num_mgrs(dispc); i++) {
3501 		DUMPREG(dispc, i, DISPC_DEFAULT_COLOR);
3502 		DUMPREG(dispc, i, DISPC_TRANS_COLOR);
3503 		DUMPREG(dispc, i, DISPC_SIZE_MGR);
3504 
3505 		if (i == OMAP_DSS_CHANNEL_DIGIT)
3506 			continue;
3507 
3508 		DUMPREG(dispc, i, DISPC_TIMING_H);
3509 		DUMPREG(dispc, i, DISPC_TIMING_V);
3510 		DUMPREG(dispc, i, DISPC_POL_FREQ);
3511 		DUMPREG(dispc, i, DISPC_DIVISORo);
3512 
3513 		DUMPREG(dispc, i, DISPC_DATA_CYCLE1);
3514 		DUMPREG(dispc, i, DISPC_DATA_CYCLE2);
3515 		DUMPREG(dispc, i, DISPC_DATA_CYCLE3);
3516 
3517 		if (dispc_has_feature(dispc, FEAT_CPR)) {
3518 			DUMPREG(dispc, i, DISPC_CPR_COEF_R);
3519 			DUMPREG(dispc, i, DISPC_CPR_COEF_G);
3520 			DUMPREG(dispc, i, DISPC_CPR_COEF_B);
3521 		}
3522 	}
3523 
3524 	p_names = ovl_names;
3525 
3526 	for (i = 0; i < dispc_get_num_ovls(dispc); i++) {
3527 		DUMPREG(dispc, i, DISPC_OVL_BA0);
3528 		DUMPREG(dispc, i, DISPC_OVL_BA1);
3529 		DUMPREG(dispc, i, DISPC_OVL_POSITION);
3530 		DUMPREG(dispc, i, DISPC_OVL_SIZE);
3531 		DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
3532 		DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
3533 		DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
3534 		DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
3535 		DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
3536 
3537 		if (dispc_has_feature(dispc, FEAT_PRELOAD))
3538 			DUMPREG(dispc, i, DISPC_OVL_PRELOAD);
3539 		if (dispc_has_feature(dispc, FEAT_MFLAG))
3540 			DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
3541 
3542 		if (i == OMAP_DSS_GFX) {
3543 			DUMPREG(dispc, i, DISPC_OVL_WINDOW_SKIP);
3544 			DUMPREG(dispc, i, DISPC_OVL_TABLE_BA);
3545 			continue;
3546 		}
3547 
3548 		DUMPREG(dispc, i, DISPC_OVL_FIR);
3549 		DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
3550 		DUMPREG(dispc, i, DISPC_OVL_ACCU0);
3551 		DUMPREG(dispc, i, DISPC_OVL_ACCU1);
3552 		if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
3553 			DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
3554 			DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
3555 			DUMPREG(dispc, i, DISPC_OVL_FIR2);
3556 			DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
3557 			DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
3558 		}
3559 		if (dispc_has_feature(dispc, FEAT_ATTR2))
3560 			DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
3561 	}
3562 
3563 	if (dispc->feat->has_writeback) {
3564 		i = OMAP_DSS_WB;
3565 		DUMPREG(dispc, i, DISPC_OVL_BA0);
3566 		DUMPREG(dispc, i, DISPC_OVL_BA1);
3567 		DUMPREG(dispc, i, DISPC_OVL_SIZE);
3568 		DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES);
3569 		DUMPREG(dispc, i, DISPC_OVL_FIFO_THRESHOLD);
3570 		DUMPREG(dispc, i, DISPC_OVL_FIFO_SIZE_STATUS);
3571 		DUMPREG(dispc, i, DISPC_OVL_ROW_INC);
3572 		DUMPREG(dispc, i, DISPC_OVL_PIXEL_INC);
3573 
3574 		if (dispc_has_feature(dispc, FEAT_MFLAG))
3575 			DUMPREG(dispc, i, DISPC_OVL_MFLAG_THRESHOLD);
3576 
3577 		DUMPREG(dispc, i, DISPC_OVL_FIR);
3578 		DUMPREG(dispc, i, DISPC_OVL_PICTURE_SIZE);
3579 		DUMPREG(dispc, i, DISPC_OVL_ACCU0);
3580 		DUMPREG(dispc, i, DISPC_OVL_ACCU1);
3581 		if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
3582 			DUMPREG(dispc, i, DISPC_OVL_BA0_UV);
3583 			DUMPREG(dispc, i, DISPC_OVL_BA1_UV);
3584 			DUMPREG(dispc, i, DISPC_OVL_FIR2);
3585 			DUMPREG(dispc, i, DISPC_OVL_ACCU2_0);
3586 			DUMPREG(dispc, i, DISPC_OVL_ACCU2_1);
3587 		}
3588 		if (dispc_has_feature(dispc, FEAT_ATTR2))
3589 			DUMPREG(dispc, i, DISPC_OVL_ATTRIBUTES2);
3590 	}
3591 
3592 #undef DISPC_REG
3593 #undef DUMPREG
3594 
3595 #define DISPC_REG(plane, name, i) name(plane, i)
3596 #define DUMPREG(dispc, plane, name, i) \
3597 	seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \
3598 	(int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \
3599 	dispc_read_reg(dispc, DISPC_REG(plane, name, i)))
3600 
3601 	/* Video pipeline coefficient registers */
3602 
3603 	/* start from OMAP_DSS_VIDEO1 */
3604 	for (i = 1; i < dispc_get_num_ovls(dispc); i++) {
3605 		for (j = 0; j < 8; j++)
3606 			DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H, j);
3607 
3608 		for (j = 0; j < 8; j++)
3609 			DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV, j);
3610 
3611 		for (j = 0; j < 5; j++)
3612 			DUMPREG(dispc, i, DISPC_OVL_CONV_COEF, j);
3613 
3614 		if (dispc_has_feature(dispc, FEAT_FIR_COEF_V)) {
3615 			for (j = 0; j < 8; j++)
3616 				DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V, j);
3617 		}
3618 
3619 		if (dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) {
3620 			for (j = 0; j < 8; j++)
3621 				DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_H2, j);
3622 
3623 			for (j = 0; j < 8; j++)
3624 				DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_HV2, j);
3625 
3626 			for (j = 0; j < 8; j++)
3627 				DUMPREG(dispc, i, DISPC_OVL_FIR_COEF_V2, j);
3628 		}
3629 	}
3630 
3631 	dispc_runtime_put(dispc);
3632 
3633 #undef DISPC_REG
3634 #undef DUMPREG
3635 
3636 	return 0;
3637 }
3638 
3639 /* calculate clock rates using dividers in cinfo */
3640 int dispc_calc_clock_rates(struct dispc_device *dispc,
3641 			   unsigned long dispc_fclk_rate,
3642 			   struct dispc_clock_info *cinfo)
3643 {
3644 	if (cinfo->lck_div > 255 || cinfo->lck_div == 0)
3645 		return -EINVAL;
3646 	if (cinfo->pck_div < 1 || cinfo->pck_div > 255)
3647 		return -EINVAL;
3648 
3649 	cinfo->lck = dispc_fclk_rate / cinfo->lck_div;
3650 	cinfo->pck = cinfo->lck / cinfo->pck_div;
3651 
3652 	return 0;
3653 }
3654 
3655 bool dispc_div_calc(struct dispc_device *dispc, unsigned long dispc_freq,
3656 		    unsigned long pck_min, unsigned long pck_max,
3657 		    dispc_div_calc_func func, void *data)
3658 {
3659 	int lckd, lckd_start, lckd_stop;
3660 	int pckd, pckd_start, pckd_stop;
3661 	unsigned long pck, lck;
3662 	unsigned long lck_max;
3663 	unsigned long pckd_hw_min, pckd_hw_max;
3664 	unsigned int min_fck_per_pck;
3665 	unsigned long fck;
3666 
3667 #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
3668 	min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
3669 #else
3670 	min_fck_per_pck = 0;
3671 #endif
3672 
3673 	pckd_hw_min = dispc->feat->min_pcd;
3674 	pckd_hw_max = 255;
3675 
3676 	lck_max = dss_get_max_fck_rate(dispc->dss);
3677 
3678 	pck_min = pck_min ? pck_min : 1;
3679 	pck_max = pck_max ? pck_max : ULONG_MAX;
3680 
3681 	lckd_start = max(DIV_ROUND_UP(dispc_freq, lck_max), 1ul);
3682 	lckd_stop = min(dispc_freq / pck_min, 255ul);
3683 
3684 	for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) {
3685 		lck = dispc_freq / lckd;
3686 
3687 		pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min);
3688 		pckd_stop = min(lck / pck_min, pckd_hw_max);
3689 
3690 		for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) {
3691 			pck = lck / pckd;
3692 
3693 			/*
3694 			 * For OMAP2/3 the DISPC fclk is the same as LCD's logic
3695 			 * clock, which means we're configuring DISPC fclk here
3696 			 * also. Thus we need to use the calculated lck. For
3697 			 * OMAP4+ the DISPC fclk is a separate clock.
3698 			 */
3699 			if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV))
3700 				fck = dispc_core_clk_rate(dispc);
3701 			else
3702 				fck = lck;
3703 
3704 			if (fck < pck * min_fck_per_pck)
3705 				continue;
3706 
3707 			if (func(lckd, pckd, lck, pck, data))
3708 				return true;
3709 		}
3710 	}
3711 
3712 	return false;
3713 }
3714 
3715 void dispc_mgr_set_clock_div(struct dispc_device *dispc,
3716 			     enum omap_channel channel,
3717 			     const struct dispc_clock_info *cinfo)
3718 {
3719 	DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div);
3720 	DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div);
3721 
3722 	dispc_mgr_set_lcd_divisor(dispc, channel, cinfo->lck_div,
3723 				  cinfo->pck_div);
3724 }
3725 
3726 int dispc_mgr_get_clock_div(struct dispc_device *dispc,
3727 			    enum omap_channel channel,
3728 			    struct dispc_clock_info *cinfo)
3729 {
3730 	unsigned long fck;
3731 
3732 	fck = dispc_fclk_rate(dispc);
3733 
3734 	cinfo->lck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 23, 16);
3735 	cinfo->pck_div = REG_GET(dispc, DISPC_DIVISORo(channel), 7, 0);
3736 
3737 	cinfo->lck = fck / cinfo->lck_div;
3738 	cinfo->pck = cinfo->lck / cinfo->pck_div;
3739 
3740 	return 0;
3741 }
3742 
3743 static u32 dispc_read_irqstatus(struct dispc_device *dispc)
3744 {
3745 	return dispc_read_reg(dispc, DISPC_IRQSTATUS);
3746 }
3747 
3748 static void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask)
3749 {
3750 	dispc_write_reg(dispc, DISPC_IRQSTATUS, mask);
3751 }
3752 
3753 static void dispc_write_irqenable(struct dispc_device *dispc, u32 mask)
3754 {
3755 	u32 old_mask = dispc_read_reg(dispc, DISPC_IRQENABLE);
3756 
3757 	/* clear the irqstatus for newly enabled irqs */
3758 	dispc_clear_irqstatus(dispc, (mask ^ old_mask) & mask);
3759 
3760 	dispc_write_reg(dispc, DISPC_IRQENABLE, mask);
3761 
3762 	/* flush posted write */
3763 	dispc_read_reg(dispc, DISPC_IRQENABLE);
3764 }
3765 
3766 void dispc_enable_sidle(struct dispc_device *dispc)
3767 {
3768 	/* SIDLEMODE: smart idle */
3769 	REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 2, 4, 3);
3770 }
3771 
3772 void dispc_disable_sidle(struct dispc_device *dispc)
3773 {
3774 	REG_FLD_MOD(dispc, DISPC_SYSCONFIG, 1, 4, 3);	/* SIDLEMODE: no idle */
3775 }
3776 
3777 static u32 dispc_mgr_gamma_size(struct dispc_device *dispc,
3778 				enum omap_channel channel)
3779 {
3780 	const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3781 
3782 	if (!dispc->feat->has_gamma_table)
3783 		return 0;
3784 
3785 	return gdesc->len;
3786 }
3787 
3788 static void dispc_mgr_write_gamma_table(struct dispc_device *dispc,
3789 					enum omap_channel channel)
3790 {
3791 	const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3792 	u32 *table = dispc->gamma_table[channel];
3793 	unsigned int i;
3794 
3795 	DSSDBG("%s: channel %d\n", __func__, channel);
3796 
3797 	for (i = 0; i < gdesc->len; ++i) {
3798 		u32 v = table[i];
3799 
3800 		if (gdesc->has_index)
3801 			v |= i << 24;
3802 		else if (i == 0)
3803 			v |= 1 << 31;
3804 
3805 		dispc_write_reg(dispc, gdesc->reg, v);
3806 	}
3807 }
3808 
3809 static void dispc_restore_gamma_tables(struct dispc_device *dispc)
3810 {
3811 	DSSDBG("%s()\n", __func__);
3812 
3813 	if (!dispc->feat->has_gamma_table)
3814 		return;
3815 
3816 	dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD);
3817 
3818 	dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_DIGIT);
3819 
3820 	if (dispc_has_feature(dispc, FEAT_MGR_LCD2))
3821 		dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD2);
3822 
3823 	if (dispc_has_feature(dispc, FEAT_MGR_LCD3))
3824 		dispc_mgr_write_gamma_table(dispc, OMAP_DSS_CHANNEL_LCD3);
3825 }
3826 
3827 static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = {
3828 	{ .red = 0, .green = 0, .blue = 0, },
3829 	{ .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, },
3830 };
3831 
3832 static void dispc_mgr_set_gamma(struct dispc_device *dispc,
3833 				enum omap_channel channel,
3834 				const struct drm_color_lut *lut,
3835 				unsigned int length)
3836 {
3837 	const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3838 	u32 *table = dispc->gamma_table[channel];
3839 	uint i;
3840 
3841 	DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__,
3842 	       channel, length, gdesc->len);
3843 
3844 	if (!dispc->feat->has_gamma_table)
3845 		return;
3846 
3847 	if (lut == NULL || length < 2) {
3848 		lut = dispc_mgr_gamma_default_lut;
3849 		length = ARRAY_SIZE(dispc_mgr_gamma_default_lut);
3850 	}
3851 
3852 	for (i = 0; i < length - 1; ++i) {
3853 		uint first = i * (gdesc->len - 1) / (length - 1);
3854 		uint last = (i + 1) * (gdesc->len - 1) / (length - 1);
3855 		uint w = last - first;
3856 		u16 r, g, b;
3857 		uint j;
3858 
3859 		if (w == 0)
3860 			continue;
3861 
3862 		for (j = 0; j <= w; j++) {
3863 			r = (lut[i].red * (w - j) + lut[i+1].red * j) / w;
3864 			g = (lut[i].green * (w - j) + lut[i+1].green * j) / w;
3865 			b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w;
3866 
3867 			r >>= 16 - gdesc->bits;
3868 			g >>= 16 - gdesc->bits;
3869 			b >>= 16 - gdesc->bits;
3870 
3871 			table[first + j] = (r << (gdesc->bits * 2)) |
3872 				(g << gdesc->bits) | b;
3873 		}
3874 	}
3875 
3876 	if (dispc->is_enabled)
3877 		dispc_mgr_write_gamma_table(dispc, channel);
3878 }
3879 
3880 static int dispc_init_gamma_tables(struct dispc_device *dispc)
3881 {
3882 	int channel;
3883 
3884 	if (!dispc->feat->has_gamma_table)
3885 		return 0;
3886 
3887 	for (channel = 0; channel < ARRAY_SIZE(dispc->gamma_table); channel++) {
3888 		const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma;
3889 		u32 *gt;
3890 
3891 		if (channel == OMAP_DSS_CHANNEL_LCD2 &&
3892 		    !dispc_has_feature(dispc, FEAT_MGR_LCD2))
3893 			continue;
3894 
3895 		if (channel == OMAP_DSS_CHANNEL_LCD3 &&
3896 		    !dispc_has_feature(dispc, FEAT_MGR_LCD3))
3897 			continue;
3898 
3899 		gt = devm_kmalloc_array(&dispc->pdev->dev, gdesc->len,
3900 					sizeof(u32), GFP_KERNEL);
3901 		if (!gt)
3902 			return -ENOMEM;
3903 
3904 		dispc->gamma_table[channel] = gt;
3905 
3906 		dispc_mgr_set_gamma(dispc, channel, NULL, 0);
3907 	}
3908 	return 0;
3909 }
3910 
3911 static void _omap_dispc_initial_config(struct dispc_device *dispc)
3912 {
3913 	u32 l;
3914 
3915 	/* Exclusively enable DISPC_CORE_CLK and set divider to 1 */
3916 	if (dispc_has_feature(dispc, FEAT_CORE_CLK_DIV)) {
3917 		l = dispc_read_reg(dispc, DISPC_DIVISOR);
3918 		/* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */
3919 		l = FLD_MOD(l, 1, 0, 0);
3920 		l = FLD_MOD(l, 1, 23, 16);
3921 		dispc_write_reg(dispc, DISPC_DIVISOR, l);
3922 
3923 		dispc->core_clk_rate = dispc_fclk_rate(dispc);
3924 	}
3925 
3926 	/* Use gamma table mode, instead of palette mode */
3927 	if (dispc->feat->has_gamma_table)
3928 		REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 3, 3);
3929 
3930 	/* For older DSS versions (FEAT_FUNCGATED) this enables
3931 	 * func-clock auto-gating. For newer versions
3932 	 * (dispc->feat->has_gamma_table) this enables tv-out gamma tables.
3933 	 */
3934 	if (dispc_has_feature(dispc, FEAT_FUNCGATED) ||
3935 	    dispc->feat->has_gamma_table)
3936 		REG_FLD_MOD(dispc, DISPC_CONFIG, 1, 9, 9);
3937 
3938 	dispc_setup_color_conv_coef(dispc);
3939 
3940 	dispc_set_loadmode(dispc, OMAP_DSS_LOAD_FRAME_ONLY);
3941 
3942 	dispc_init_fifos(dispc);
3943 
3944 	dispc_configure_burst_sizes(dispc);
3945 
3946 	dispc_ovl_enable_zorder_planes(dispc);
3947 
3948 	if (dispc->feat->mstandby_workaround)
3949 		REG_FLD_MOD(dispc, DISPC_MSTANDBY_CTRL, 1, 0, 0);
3950 
3951 	if (dispc_has_feature(dispc, FEAT_MFLAG))
3952 		dispc_init_mflag(dispc);
3953 }
3954 
3955 static const enum dispc_feature_id omap2_dispc_features_list[] = {
3956 	FEAT_LCDENABLEPOL,
3957 	FEAT_LCDENABLESIGNAL,
3958 	FEAT_PCKFREEENABLE,
3959 	FEAT_FUNCGATED,
3960 	FEAT_ROWREPEATENABLE,
3961 	FEAT_RESIZECONF,
3962 };
3963 
3964 static const enum dispc_feature_id omap3_dispc_features_list[] = {
3965 	FEAT_LCDENABLEPOL,
3966 	FEAT_LCDENABLESIGNAL,
3967 	FEAT_PCKFREEENABLE,
3968 	FEAT_FUNCGATED,
3969 	FEAT_LINEBUFFERSPLIT,
3970 	FEAT_ROWREPEATENABLE,
3971 	FEAT_RESIZECONF,
3972 	FEAT_CPR,
3973 	FEAT_PRELOAD,
3974 	FEAT_FIR_COEF_V,
3975 	FEAT_ALPHA_FIXED_ZORDER,
3976 	FEAT_FIFO_MERGE,
3977 	FEAT_OMAP3_DSI_FIFO_BUG,
3978 };
3979 
3980 static const enum dispc_feature_id am43xx_dispc_features_list[] = {
3981 	FEAT_LCDENABLEPOL,
3982 	FEAT_LCDENABLESIGNAL,
3983 	FEAT_PCKFREEENABLE,
3984 	FEAT_FUNCGATED,
3985 	FEAT_LINEBUFFERSPLIT,
3986 	FEAT_ROWREPEATENABLE,
3987 	FEAT_RESIZECONF,
3988 	FEAT_CPR,
3989 	FEAT_PRELOAD,
3990 	FEAT_FIR_COEF_V,
3991 	FEAT_ALPHA_FIXED_ZORDER,
3992 	FEAT_FIFO_MERGE,
3993 };
3994 
3995 static const enum dispc_feature_id omap4_dispc_features_list[] = {
3996 	FEAT_MGR_LCD2,
3997 	FEAT_CORE_CLK_DIV,
3998 	FEAT_HANDLE_UV_SEPARATE,
3999 	FEAT_ATTR2,
4000 	FEAT_CPR,
4001 	FEAT_PRELOAD,
4002 	FEAT_FIR_COEF_V,
4003 	FEAT_ALPHA_FREE_ZORDER,
4004 	FEAT_FIFO_MERGE,
4005 	FEAT_BURST_2D,
4006 };
4007 
4008 static const enum dispc_feature_id omap5_dispc_features_list[] = {
4009 	FEAT_MGR_LCD2,
4010 	FEAT_MGR_LCD3,
4011 	FEAT_CORE_CLK_DIV,
4012 	FEAT_HANDLE_UV_SEPARATE,
4013 	FEAT_ATTR2,
4014 	FEAT_CPR,
4015 	FEAT_PRELOAD,
4016 	FEAT_FIR_COEF_V,
4017 	FEAT_ALPHA_FREE_ZORDER,
4018 	FEAT_FIFO_MERGE,
4019 	FEAT_BURST_2D,
4020 	FEAT_MFLAG,
4021 };
4022 
4023 static const struct dss_reg_field omap2_dispc_reg_fields[] = {
4024 	[FEAT_REG_FIRHINC]			= { 11, 0 },
4025 	[FEAT_REG_FIRVINC]			= { 27, 16 },
4026 	[FEAT_REG_FIFOLOWTHRESHOLD]		= { 8, 0 },
4027 	[FEAT_REG_FIFOHIGHTHRESHOLD]		= { 24, 16 },
4028 	[FEAT_REG_FIFOSIZE]			= { 8, 0 },
4029 	[FEAT_REG_HORIZONTALACCU]		= { 9, 0 },
4030 	[FEAT_REG_VERTICALACCU]			= { 25, 16 },
4031 };
4032 
4033 static const struct dss_reg_field omap3_dispc_reg_fields[] = {
4034 	[FEAT_REG_FIRHINC]			= { 12, 0 },
4035 	[FEAT_REG_FIRVINC]			= { 28, 16 },
4036 	[FEAT_REG_FIFOLOWTHRESHOLD]		= { 11, 0 },
4037 	[FEAT_REG_FIFOHIGHTHRESHOLD]		= { 27, 16 },
4038 	[FEAT_REG_FIFOSIZE]			= { 10, 0 },
4039 	[FEAT_REG_HORIZONTALACCU]		= { 9, 0 },
4040 	[FEAT_REG_VERTICALACCU]			= { 25, 16 },
4041 };
4042 
4043 static const struct dss_reg_field omap4_dispc_reg_fields[] = {
4044 	[FEAT_REG_FIRHINC]			= { 12, 0 },
4045 	[FEAT_REG_FIRVINC]			= { 28, 16 },
4046 	[FEAT_REG_FIFOLOWTHRESHOLD]		= { 15, 0 },
4047 	[FEAT_REG_FIFOHIGHTHRESHOLD]		= { 31, 16 },
4048 	[FEAT_REG_FIFOSIZE]			= { 15, 0 },
4049 	[FEAT_REG_HORIZONTALACCU]		= { 10, 0 },
4050 	[FEAT_REG_VERTICALACCU]			= { 26, 16 },
4051 };
4052 
4053 static const enum omap_overlay_caps omap2_dispc_overlay_caps[] = {
4054 	/* OMAP_DSS_GFX */
4055 	OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4056 
4057 	/* OMAP_DSS_VIDEO1 */
4058 	OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4059 		OMAP_DSS_OVL_CAP_REPLICATION,
4060 
4061 	/* OMAP_DSS_VIDEO2 */
4062 	OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4063 		OMAP_DSS_OVL_CAP_REPLICATION,
4064 };
4065 
4066 static const enum omap_overlay_caps omap3430_dispc_overlay_caps[] = {
4067 	/* OMAP_DSS_GFX */
4068 	OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_POS |
4069 		OMAP_DSS_OVL_CAP_REPLICATION,
4070 
4071 	/* OMAP_DSS_VIDEO1 */
4072 	OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4073 		OMAP_DSS_OVL_CAP_REPLICATION,
4074 
4075 	/* OMAP_DSS_VIDEO2 */
4076 	OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4077 		OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4078 };
4079 
4080 static const enum omap_overlay_caps omap3630_dispc_overlay_caps[] = {
4081 	/* OMAP_DSS_GFX */
4082 	OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
4083 		OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4084 
4085 	/* OMAP_DSS_VIDEO1 */
4086 	OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_POS |
4087 		OMAP_DSS_OVL_CAP_REPLICATION,
4088 
4089 	/* OMAP_DSS_VIDEO2 */
4090 	OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4091 		OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_POS |
4092 		OMAP_DSS_OVL_CAP_REPLICATION,
4093 };
4094 
4095 static const enum omap_overlay_caps omap4_dispc_overlay_caps[] = {
4096 	/* OMAP_DSS_GFX */
4097 	OMAP_DSS_OVL_CAP_GLOBAL_ALPHA | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA |
4098 		OMAP_DSS_OVL_CAP_ZORDER | OMAP_DSS_OVL_CAP_POS |
4099 		OMAP_DSS_OVL_CAP_REPLICATION,
4100 
4101 	/* OMAP_DSS_VIDEO1 */
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,
4105 
4106 	/* OMAP_DSS_VIDEO2 */
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,
4110 
4111 	/* OMAP_DSS_VIDEO3 */
4112 	OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_GLOBAL_ALPHA |
4113 		OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA | OMAP_DSS_OVL_CAP_ZORDER |
4114 		OMAP_DSS_OVL_CAP_POS | OMAP_DSS_OVL_CAP_REPLICATION,
4115 };
4116 
4117 #define COLOR_ARRAY(arr...) (const u32[]) { arr, 0 }
4118 
4119 static const u32 *omap2_dispc_supported_color_modes[] = {
4120 
4121 	/* OMAP_DSS_GFX */
4122 	COLOR_ARRAY(
4123 	DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
4124 	DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888),
4125 
4126 	/* OMAP_DSS_VIDEO1 */
4127 	COLOR_ARRAY(
4128 	DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4129 	DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
4130 	DRM_FORMAT_UYVY),
4131 
4132 	/* OMAP_DSS_VIDEO2 */
4133 	COLOR_ARRAY(
4134 	DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4135 	DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
4136 	DRM_FORMAT_UYVY),
4137 };
4138 
4139 static const u32 *omap3_dispc_supported_color_modes[] = {
4140 	/* OMAP_DSS_GFX */
4141 	COLOR_ARRAY(
4142 	DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
4143 	DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4144 	DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
4145 	DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
4146 
4147 	/* OMAP_DSS_VIDEO1 */
4148 	COLOR_ARRAY(
4149 	DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB888,
4150 	DRM_FORMAT_RGBX4444, DRM_FORMAT_RGB565,
4151 	DRM_FORMAT_YUYV, DRM_FORMAT_UYVY),
4152 
4153 	/* OMAP_DSS_VIDEO2 */
4154 	COLOR_ARRAY(
4155 	DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
4156 	DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4157 	DRM_FORMAT_RGB888, DRM_FORMAT_YUYV,
4158 	DRM_FORMAT_UYVY, DRM_FORMAT_ARGB8888,
4159 	DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888),
4160 };
4161 
4162 static const u32 *omap4_dispc_supported_color_modes[] = {
4163 	/* OMAP_DSS_GFX */
4164 	COLOR_ARRAY(
4165 	DRM_FORMAT_RGBX4444, DRM_FORMAT_ARGB4444,
4166 	DRM_FORMAT_RGB565, DRM_FORMAT_XRGB8888,
4167 	DRM_FORMAT_RGB888, DRM_FORMAT_ARGB8888,
4168 	DRM_FORMAT_RGBA8888, DRM_FORMAT_RGBX8888,
4169 	DRM_FORMAT_ARGB1555, DRM_FORMAT_XRGB4444,
4170 	DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB1555),
4171 
4172 	/* OMAP_DSS_VIDEO1 */
4173 	COLOR_ARRAY(
4174 	DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4175 	DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4176 	DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4177 	DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4178 	DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4179 	DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4180 	DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4181 	DRM_FORMAT_RGBX8888),
4182 
4183        /* OMAP_DSS_VIDEO2 */
4184 	COLOR_ARRAY(
4185 	DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4186 	DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4187 	DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4188 	DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4189 	DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4190 	DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4191 	DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4192 	DRM_FORMAT_RGBX8888),
4193 
4194 	/* OMAP_DSS_VIDEO3 */
4195 	COLOR_ARRAY(
4196 	DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4197 	DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4198 	DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4199 	DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4200 	DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4201 	DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4202 	DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4203 	DRM_FORMAT_RGBX8888),
4204 
4205 	/* OMAP_DSS_WB */
4206 	COLOR_ARRAY(
4207 	DRM_FORMAT_RGB565, DRM_FORMAT_RGBX4444,
4208 	DRM_FORMAT_YUYV, DRM_FORMAT_ARGB1555,
4209 	DRM_FORMAT_RGBA8888, DRM_FORMAT_NV12,
4210 	DRM_FORMAT_RGBA4444, DRM_FORMAT_XRGB8888,
4211 	DRM_FORMAT_RGB888, DRM_FORMAT_UYVY,
4212 	DRM_FORMAT_ARGB4444, DRM_FORMAT_XRGB1555,
4213 	DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB4444,
4214 	DRM_FORMAT_RGBX8888),
4215 };
4216 
4217 static const struct dispc_features omap24xx_dispc_feats = {
4218 	.sw_start		=	5,
4219 	.fp_start		=	15,
4220 	.bp_start		=	27,
4221 	.sw_max			=	64,
4222 	.vp_max			=	255,
4223 	.hp_max			=	256,
4224 	.mgr_width_start	=	10,
4225 	.mgr_height_start	=	26,
4226 	.mgr_width_max		=	2048,
4227 	.mgr_height_max		=	2048,
4228 	.max_lcd_pclk		=	66500000,
4229 	.max_downscale		=	2,
4230 	/*
4231 	 * Assume the line width buffer to be 768 pixels as OMAP2 DISPC scaler
4232 	 * cannot scale an image width larger than 768.
4233 	 */
4234 	.max_line_width		=	768,
4235 	.min_pcd		=	2,
4236 	.calc_scaling		=	dispc_ovl_calc_scaling_24xx,
4237 	.calc_core_clk		=	calc_core_clk_24xx,
4238 	.num_fifos		=	3,
4239 	.features		=	omap2_dispc_features_list,
4240 	.num_features		=	ARRAY_SIZE(omap2_dispc_features_list),
4241 	.reg_fields		=	omap2_dispc_reg_fields,
4242 	.num_reg_fields		=	ARRAY_SIZE(omap2_dispc_reg_fields),
4243 	.overlay_caps		=	omap2_dispc_overlay_caps,
4244 	.supported_color_modes	=	omap2_dispc_supported_color_modes,
4245 	.num_mgrs		=	2,
4246 	.num_ovls		=	3,
4247 	.buffer_size_unit	=	1,
4248 	.burst_size_unit	=	8,
4249 	.no_framedone_tv	=	true,
4250 	.set_max_preload	=	false,
4251 	.last_pixel_inc_missing	=	true,
4252 };
4253 
4254 static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
4255 	.sw_start		=	5,
4256 	.fp_start		=	15,
4257 	.bp_start		=	27,
4258 	.sw_max			=	64,
4259 	.vp_max			=	255,
4260 	.hp_max			=	256,
4261 	.mgr_width_start	=	10,
4262 	.mgr_height_start	=	26,
4263 	.mgr_width_max		=	2048,
4264 	.mgr_height_max		=	2048,
4265 	.max_lcd_pclk		=	173000000,
4266 	.max_tv_pclk		=	59000000,
4267 	.max_downscale		=	4,
4268 	.max_line_width		=	1024,
4269 	.min_pcd		=	1,
4270 	.calc_scaling		=	dispc_ovl_calc_scaling_34xx,
4271 	.calc_core_clk		=	calc_core_clk_34xx,
4272 	.num_fifos		=	3,
4273 	.features		=	omap3_dispc_features_list,
4274 	.num_features		=	ARRAY_SIZE(omap3_dispc_features_list),
4275 	.reg_fields		=	omap3_dispc_reg_fields,
4276 	.num_reg_fields		=	ARRAY_SIZE(omap3_dispc_reg_fields),
4277 	.overlay_caps		=	omap3430_dispc_overlay_caps,
4278 	.supported_color_modes	=	omap3_dispc_supported_color_modes,
4279 	.num_mgrs		=	2,
4280 	.num_ovls		=	3,
4281 	.buffer_size_unit	=	1,
4282 	.burst_size_unit	=	8,
4283 	.no_framedone_tv	=	true,
4284 	.set_max_preload	=	false,
4285 	.last_pixel_inc_missing	=	true,
4286 };
4287 
4288 static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
4289 	.sw_start		=	7,
4290 	.fp_start		=	19,
4291 	.bp_start		=	31,
4292 	.sw_max			=	256,
4293 	.vp_max			=	4095,
4294 	.hp_max			=	4096,
4295 	.mgr_width_start	=	10,
4296 	.mgr_height_start	=	26,
4297 	.mgr_width_max		=	2048,
4298 	.mgr_height_max		=	2048,
4299 	.max_lcd_pclk		=	173000000,
4300 	.max_tv_pclk		=	59000000,
4301 	.max_downscale		=	4,
4302 	.max_line_width		=	1024,
4303 	.min_pcd		=	1,
4304 	.calc_scaling		=	dispc_ovl_calc_scaling_34xx,
4305 	.calc_core_clk		=	calc_core_clk_34xx,
4306 	.num_fifos		=	3,
4307 	.features		=	omap3_dispc_features_list,
4308 	.num_features		=	ARRAY_SIZE(omap3_dispc_features_list),
4309 	.reg_fields		=	omap3_dispc_reg_fields,
4310 	.num_reg_fields		=	ARRAY_SIZE(omap3_dispc_reg_fields),
4311 	.overlay_caps		=	omap3430_dispc_overlay_caps,
4312 	.supported_color_modes	=	omap3_dispc_supported_color_modes,
4313 	.num_mgrs		=	2,
4314 	.num_ovls		=	3,
4315 	.buffer_size_unit	=	1,
4316 	.burst_size_unit	=	8,
4317 	.no_framedone_tv	=	true,
4318 	.set_max_preload	=	false,
4319 	.last_pixel_inc_missing	=	true,
4320 };
4321 
4322 static const struct dispc_features omap36xx_dispc_feats = {
4323 	.sw_start		=	7,
4324 	.fp_start		=	19,
4325 	.bp_start		=	31,
4326 	.sw_max			=	256,
4327 	.vp_max			=	4095,
4328 	.hp_max			=	4096,
4329 	.mgr_width_start	=	10,
4330 	.mgr_height_start	=	26,
4331 	.mgr_width_max		=	2048,
4332 	.mgr_height_max		=	2048,
4333 	.max_lcd_pclk		=	173000000,
4334 	.max_tv_pclk		=	59000000,
4335 	.max_downscale		=	4,
4336 	.max_line_width		=	1024,
4337 	.min_pcd		=	1,
4338 	.calc_scaling		=	dispc_ovl_calc_scaling_34xx,
4339 	.calc_core_clk		=	calc_core_clk_34xx,
4340 	.num_fifos		=	3,
4341 	.features		=	omap3_dispc_features_list,
4342 	.num_features		=	ARRAY_SIZE(omap3_dispc_features_list),
4343 	.reg_fields		=	omap3_dispc_reg_fields,
4344 	.num_reg_fields		=	ARRAY_SIZE(omap3_dispc_reg_fields),
4345 	.overlay_caps		=	omap3630_dispc_overlay_caps,
4346 	.supported_color_modes	=	omap3_dispc_supported_color_modes,
4347 	.num_mgrs		=	2,
4348 	.num_ovls		=	3,
4349 	.buffer_size_unit	=	1,
4350 	.burst_size_unit	=	8,
4351 	.no_framedone_tv	=	true,
4352 	.set_max_preload	=	false,
4353 	.last_pixel_inc_missing	=	true,
4354 };
4355 
4356 static const struct dispc_features am43xx_dispc_feats = {
4357 	.sw_start		=	7,
4358 	.fp_start		=	19,
4359 	.bp_start		=	31,
4360 	.sw_max			=	256,
4361 	.vp_max			=	4095,
4362 	.hp_max			=	4096,
4363 	.mgr_width_start	=	10,
4364 	.mgr_height_start	=	26,
4365 	.mgr_width_max		=	2048,
4366 	.mgr_height_max		=	2048,
4367 	.max_lcd_pclk		=	173000000,
4368 	.max_tv_pclk		=	59000000,
4369 	.max_downscale		=	4,
4370 	.max_line_width		=	1024,
4371 	.min_pcd		=	1,
4372 	.calc_scaling		=	dispc_ovl_calc_scaling_34xx,
4373 	.calc_core_clk		=	calc_core_clk_34xx,
4374 	.num_fifos		=	3,
4375 	.features		=	am43xx_dispc_features_list,
4376 	.num_features		=	ARRAY_SIZE(am43xx_dispc_features_list),
4377 	.reg_fields		=	omap3_dispc_reg_fields,
4378 	.num_reg_fields		=	ARRAY_SIZE(omap3_dispc_reg_fields),
4379 	.overlay_caps		=	omap3430_dispc_overlay_caps,
4380 	.supported_color_modes	=	omap3_dispc_supported_color_modes,
4381 	.num_mgrs		=	1,
4382 	.num_ovls		=	3,
4383 	.buffer_size_unit	=	1,
4384 	.burst_size_unit	=	8,
4385 	.no_framedone_tv	=	true,
4386 	.set_max_preload	=	false,
4387 	.last_pixel_inc_missing	=	true,
4388 };
4389 
4390 static const struct dispc_features omap44xx_dispc_feats = {
4391 	.sw_start		=	7,
4392 	.fp_start		=	19,
4393 	.bp_start		=	31,
4394 	.sw_max			=	256,
4395 	.vp_max			=	4095,
4396 	.hp_max			=	4096,
4397 	.mgr_width_start	=	10,
4398 	.mgr_height_start	=	26,
4399 	.mgr_width_max		=	2048,
4400 	.mgr_height_max		=	2048,
4401 	.max_lcd_pclk		=	170000000,
4402 	.max_tv_pclk		=	185625000,
4403 	.max_downscale		=	4,
4404 	.max_line_width		=	2048,
4405 	.min_pcd		=	1,
4406 	.calc_scaling		=	dispc_ovl_calc_scaling_44xx,
4407 	.calc_core_clk		=	calc_core_clk_44xx,
4408 	.num_fifos		=	5,
4409 	.features		=	omap4_dispc_features_list,
4410 	.num_features		=	ARRAY_SIZE(omap4_dispc_features_list),
4411 	.reg_fields		=	omap4_dispc_reg_fields,
4412 	.num_reg_fields		=	ARRAY_SIZE(omap4_dispc_reg_fields),
4413 	.overlay_caps		=	omap4_dispc_overlay_caps,
4414 	.supported_color_modes	=	omap4_dispc_supported_color_modes,
4415 	.num_mgrs		=	3,
4416 	.num_ovls		=	4,
4417 	.buffer_size_unit	=	16,
4418 	.burst_size_unit	=	16,
4419 	.gfx_fifo_workaround	=	true,
4420 	.set_max_preload	=	true,
4421 	.supports_sync_align	=	true,
4422 	.has_writeback		=	true,
4423 	.supports_double_pixel	=	true,
4424 	.reverse_ilace_field_order =	true,
4425 	.has_gamma_table	=	true,
4426 	.has_gamma_i734_bug	=	true,
4427 };
4428 
4429 static const struct dispc_features omap54xx_dispc_feats = {
4430 	.sw_start		=	7,
4431 	.fp_start		=	19,
4432 	.bp_start		=	31,
4433 	.sw_max			=	256,
4434 	.vp_max			=	4095,
4435 	.hp_max			=	4096,
4436 	.mgr_width_start	=	11,
4437 	.mgr_height_start	=	27,
4438 	.mgr_width_max		=	4096,
4439 	.mgr_height_max		=	4096,
4440 	.max_lcd_pclk		=	170000000,
4441 	.max_tv_pclk		=	186000000,
4442 	.max_downscale		=	4,
4443 	.max_line_width		=	2048,
4444 	.min_pcd		=	1,
4445 	.calc_scaling		=	dispc_ovl_calc_scaling_44xx,
4446 	.calc_core_clk		=	calc_core_clk_44xx,
4447 	.num_fifos		=	5,
4448 	.features		=	omap5_dispc_features_list,
4449 	.num_features		=	ARRAY_SIZE(omap5_dispc_features_list),
4450 	.reg_fields		=	omap4_dispc_reg_fields,
4451 	.num_reg_fields		=	ARRAY_SIZE(omap4_dispc_reg_fields),
4452 	.overlay_caps		=	omap4_dispc_overlay_caps,
4453 	.supported_color_modes	=	omap4_dispc_supported_color_modes,
4454 	.num_mgrs		=	4,
4455 	.num_ovls		=	4,
4456 	.buffer_size_unit	=	16,
4457 	.burst_size_unit	=	16,
4458 	.gfx_fifo_workaround	=	true,
4459 	.mstandby_workaround	=	true,
4460 	.set_max_preload	=	true,
4461 	.supports_sync_align	=	true,
4462 	.has_writeback		=	true,
4463 	.supports_double_pixel	=	true,
4464 	.reverse_ilace_field_order =	true,
4465 	.has_gamma_table	=	true,
4466 	.has_gamma_i734_bug	=	true,
4467 };
4468 
4469 static irqreturn_t dispc_irq_handler(int irq, void *arg)
4470 {
4471 	struct dispc_device *dispc = arg;
4472 
4473 	if (!dispc->is_enabled)
4474 		return IRQ_NONE;
4475 
4476 	return dispc->user_handler(irq, dispc->user_data);
4477 }
4478 
4479 static int dispc_request_irq(struct dispc_device *dispc, irq_handler_t handler,
4480 			     void *dev_id)
4481 {
4482 	int r;
4483 
4484 	if (dispc->user_handler != NULL)
4485 		return -EBUSY;
4486 
4487 	dispc->user_handler = handler;
4488 	dispc->user_data = dev_id;
4489 
4490 	/* ensure the dispc_irq_handler sees the values above */
4491 	smp_wmb();
4492 
4493 	r = devm_request_irq(&dispc->pdev->dev, dispc->irq, dispc_irq_handler,
4494 			     IRQF_SHARED, "OMAP DISPC", dispc);
4495 	if (r) {
4496 		dispc->user_handler = NULL;
4497 		dispc->user_data = NULL;
4498 	}
4499 
4500 	return r;
4501 }
4502 
4503 static void dispc_free_irq(struct dispc_device *dispc, void *dev_id)
4504 {
4505 	devm_free_irq(&dispc->pdev->dev, dispc->irq, dispc);
4506 
4507 	dispc->user_handler = NULL;
4508 	dispc->user_data = NULL;
4509 }
4510 
4511 static u32 dispc_get_memory_bandwidth_limit(struct dispc_device *dispc)
4512 {
4513 	u32 limit = 0;
4514 
4515 	/* Optional maximum memory bandwidth */
4516 	of_property_read_u32(dispc->pdev->dev.of_node, "max-memory-bandwidth",
4517 			     &limit);
4518 
4519 	return limit;
4520 }
4521 
4522 /*
4523  * Workaround for errata i734 in DSS dispc
4524  *  - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled
4525  *
4526  * For gamma tables to work on LCD1 the GFX plane has to be used at
4527  * least once after DSS HW has come out of reset. The workaround
4528  * sets up a minimal LCD setup with GFX plane and waits for one
4529  * vertical sync irq before disabling the setup and continuing with
4530  * the context restore. The physical outputs are gated during the
4531  * operation. This workaround requires that gamma table's LOADMODE
4532  * is set to 0x2 in DISPC_CONTROL1 register.
4533  *
4534  * For details see:
4535  * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata
4536  * Literature Number: SWPZ037E
4537  * Or some other relevant errata document for the DSS IP version.
4538  */
4539 
4540 static const struct dispc_errata_i734_data {
4541 	struct videomode vm;
4542 	struct omap_overlay_info ovli;
4543 	struct omap_overlay_manager_info mgri;
4544 	struct dss_lcd_mgr_config lcd_conf;
4545 } i734 = {
4546 	.vm = {
4547 		.hactive = 8, .vactive = 1,
4548 		.pixelclock = 16000000,
4549 		.hsync_len = 8, .hfront_porch = 4, .hback_porch = 4,
4550 		.vsync_len = 1, .vfront_porch = 1, .vback_porch = 1,
4551 
4552 		.flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
4553 			 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
4554 			 DISPLAY_FLAGS_PIXDATA_POSEDGE,
4555 	},
4556 	.ovli = {
4557 		.screen_width = 1,
4558 		.width = 1, .height = 1,
4559 		.fourcc = DRM_FORMAT_XRGB8888,
4560 		.rotation = DRM_MODE_ROTATE_0,
4561 		.rotation_type = OMAP_DSS_ROT_NONE,
4562 		.pos_x = 0, .pos_y = 0,
4563 		.out_width = 0, .out_height = 0,
4564 		.global_alpha = 0xff,
4565 		.pre_mult_alpha = 0,
4566 		.zorder = 0,
4567 	},
4568 	.mgri = {
4569 		.default_color = 0,
4570 		.trans_enabled = false,
4571 		.partial_alpha_enabled = false,
4572 		.cpr_enable = false,
4573 	},
4574 	.lcd_conf = {
4575 		.io_pad_mode = DSS_IO_PAD_MODE_BYPASS,
4576 		.stallmode = false,
4577 		.fifohandcheck = false,
4578 		.clock_info = {
4579 			.lck_div = 1,
4580 			.pck_div = 2,
4581 		},
4582 		.video_port_width = 24,
4583 		.lcden_sig_polarity = 0,
4584 	},
4585 };
4586 
4587 static struct i734_buf {
4588 	size_t size;
4589 	dma_addr_t paddr;
4590 	void *vaddr;
4591 } i734_buf;
4592 
4593 static int dispc_errata_i734_wa_init(struct dispc_device *dispc)
4594 {
4595 	if (!dispc->feat->has_gamma_i734_bug)
4596 		return 0;
4597 
4598 	i734_buf.size = i734.ovli.width * i734.ovli.height *
4599 		color_mode_to_bpp(i734.ovli.fourcc) / 8;
4600 
4601 	i734_buf.vaddr = dma_alloc_wc(&dispc->pdev->dev, i734_buf.size,
4602 				      &i734_buf.paddr, GFP_KERNEL);
4603 	if (!i734_buf.vaddr) {
4604 		dev_err(&dispc->pdev->dev, "%s: dma_alloc_wc failed\n",
4605 			__func__);
4606 		return -ENOMEM;
4607 	}
4608 
4609 	return 0;
4610 }
4611 
4612 static void dispc_errata_i734_wa_fini(struct dispc_device *dispc)
4613 {
4614 	if (!dispc->feat->has_gamma_i734_bug)
4615 		return;
4616 
4617 	dma_free_wc(&dispc->pdev->dev, i734_buf.size, i734_buf.vaddr,
4618 		    i734_buf.paddr);
4619 }
4620 
4621 static void dispc_errata_i734_wa(struct dispc_device *dispc)
4622 {
4623 	u32 framedone_irq = dispc_mgr_get_framedone_irq(dispc,
4624 							OMAP_DSS_CHANNEL_LCD);
4625 	struct omap_overlay_info ovli;
4626 	struct dss_lcd_mgr_config lcd_conf;
4627 	u32 gatestate;
4628 	unsigned int count;
4629 
4630 	if (!dispc->feat->has_gamma_i734_bug)
4631 		return;
4632 
4633 	gatestate = REG_GET(dispc, DISPC_CONFIG, 8, 4);
4634 
4635 	ovli = i734.ovli;
4636 	ovli.paddr = i734_buf.paddr;
4637 	lcd_conf = i734.lcd_conf;
4638 
4639 	/* Gate all LCD1 outputs */
4640 	REG_FLD_MOD(dispc, DISPC_CONFIG, 0x1f, 8, 4);
4641 
4642 	/* Setup and enable GFX plane */
4643 	dispc_ovl_setup(dispc, OMAP_DSS_GFX, &ovli, &i734.vm, false,
4644 			OMAP_DSS_CHANNEL_LCD);
4645 	dispc_ovl_enable(dispc, OMAP_DSS_GFX, true);
4646 
4647 	/* Set up and enable display manager for LCD1 */
4648 	dispc_mgr_setup(dispc, OMAP_DSS_CHANNEL_LCD, &i734.mgri);
4649 	dispc_calc_clock_rates(dispc, dss_get_dispc_clk_rate(dispc->dss),
4650 			       &lcd_conf.clock_info);
4651 	dispc_mgr_set_lcd_config(dispc, OMAP_DSS_CHANNEL_LCD, &lcd_conf);
4652 	dispc_mgr_set_timings(dispc, OMAP_DSS_CHANNEL_LCD, &i734.vm);
4653 
4654 	dispc_clear_irqstatus(dispc, framedone_irq);
4655 
4656 	/* Enable and shut the channel to produce just one frame */
4657 	dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, true);
4658 	dispc_mgr_enable(dispc, OMAP_DSS_CHANNEL_LCD, false);
4659 
4660 	/* Busy wait for framedone. We can't fiddle with irq handlers
4661 	 * in PM resume. Typically the loop runs less than 5 times and
4662 	 * waits less than a micro second.
4663 	 */
4664 	count = 0;
4665 	while (!(dispc_read_irqstatus(dispc) & framedone_irq)) {
4666 		if (count++ > 10000) {
4667 			dev_err(&dispc->pdev->dev, "%s: framedone timeout\n",
4668 				__func__);
4669 			break;
4670 		}
4671 	}
4672 	dispc_ovl_enable(dispc, OMAP_DSS_GFX, false);
4673 
4674 	/* Clear all irq bits before continuing */
4675 	dispc_clear_irqstatus(dispc, 0xffffffff);
4676 
4677 	/* Restore the original state to LCD1 output gates */
4678 	REG_FLD_MOD(dispc, DISPC_CONFIG, gatestate, 8, 4);
4679 }
4680 
4681 static const struct dispc_ops dispc_ops = {
4682 	.read_irqstatus = dispc_read_irqstatus,
4683 	.clear_irqstatus = dispc_clear_irqstatus,
4684 	.write_irqenable = dispc_write_irqenable,
4685 
4686 	.request_irq = dispc_request_irq,
4687 	.free_irq = dispc_free_irq,
4688 
4689 	.runtime_get = dispc_runtime_get,
4690 	.runtime_put = dispc_runtime_put,
4691 
4692 	.get_num_ovls = dispc_get_num_ovls,
4693 	.get_num_mgrs = dispc_get_num_mgrs,
4694 
4695 	.get_memory_bandwidth_limit = dispc_get_memory_bandwidth_limit,
4696 
4697 	.mgr_enable = dispc_mgr_enable,
4698 	.mgr_is_enabled = dispc_mgr_is_enabled,
4699 	.mgr_get_vsync_irq = dispc_mgr_get_vsync_irq,
4700 	.mgr_get_framedone_irq = dispc_mgr_get_framedone_irq,
4701 	.mgr_get_sync_lost_irq = dispc_mgr_get_sync_lost_irq,
4702 	.mgr_go_busy = dispc_mgr_go_busy,
4703 	.mgr_go = dispc_mgr_go,
4704 	.mgr_set_lcd_config = dispc_mgr_set_lcd_config,
4705 	.mgr_check_timings = dispc_mgr_check_timings,
4706 	.mgr_set_timings = dispc_mgr_set_timings,
4707 	.mgr_setup = dispc_mgr_setup,
4708 	.mgr_gamma_size = dispc_mgr_gamma_size,
4709 	.mgr_set_gamma = dispc_mgr_set_gamma,
4710 
4711 	.ovl_enable = dispc_ovl_enable,
4712 	.ovl_setup = dispc_ovl_setup,
4713 	.ovl_get_color_modes = dispc_ovl_get_color_modes,
4714 
4715 	.wb_get_framedone_irq = dispc_wb_get_framedone_irq,
4716 	.wb_setup = dispc_wb_setup,
4717 	.has_writeback = dispc_has_writeback,
4718 	.wb_go_busy = dispc_wb_go_busy,
4719 	.wb_go = dispc_wb_go,
4720 };
4721 
4722 /* DISPC HW IP initialisation */
4723 static const struct of_device_id dispc_of_match[] = {
4724 	{ .compatible = "ti,omap2-dispc", .data = &omap24xx_dispc_feats },
4725 	{ .compatible = "ti,omap3-dispc", .data = &omap36xx_dispc_feats },
4726 	{ .compatible = "ti,omap4-dispc", .data = &omap44xx_dispc_feats },
4727 	{ .compatible = "ti,omap5-dispc", .data = &omap54xx_dispc_feats },
4728 	{ .compatible = "ti,dra7-dispc",  .data = &omap54xx_dispc_feats },
4729 	{},
4730 };
4731 
4732 static const struct soc_device_attribute dispc_soc_devices[] = {
4733 	{ .machine = "OMAP3[45]*",
4734 	  .revision = "ES[12].?",	.data = &omap34xx_rev1_0_dispc_feats },
4735 	{ .machine = "OMAP3[45]*",	.data = &omap34xx_rev3_0_dispc_feats },
4736 	{ .machine = "AM35*",		.data = &omap34xx_rev3_0_dispc_feats },
4737 	{ .machine = "AM43*",		.data = &am43xx_dispc_feats },
4738 	{ /* sentinel */ }
4739 };
4740 
4741 static int dispc_bind(struct device *dev, struct device *master, void *data)
4742 {
4743 	struct platform_device *pdev = to_platform_device(dev);
4744 	const struct soc_device_attribute *soc;
4745 	struct dss_device *dss = dss_get_device(master);
4746 	struct dispc_device *dispc;
4747 	u32 rev;
4748 	int r = 0;
4749 	struct resource *dispc_mem;
4750 	struct device_node *np = pdev->dev.of_node;
4751 
4752 	dispc = kzalloc(sizeof(*dispc), GFP_KERNEL);
4753 	if (!dispc)
4754 		return -ENOMEM;
4755 
4756 	dispc->pdev = pdev;
4757 	platform_set_drvdata(pdev, dispc);
4758 	dispc->dss = dss;
4759 
4760 	/*
4761 	 * The OMAP3-based models can't be told apart using the compatible
4762 	 * string, use SoC device matching.
4763 	 */
4764 	soc = soc_device_match(dispc_soc_devices);
4765 	if (soc)
4766 		dispc->feat = soc->data;
4767 	else
4768 		dispc->feat = of_match_device(dispc_of_match, &pdev->dev)->data;
4769 
4770 	r = dispc_errata_i734_wa_init(dispc);
4771 	if (r)
4772 		goto err_free;
4773 
4774 	dispc_mem = platform_get_resource(dispc->pdev, IORESOURCE_MEM, 0);
4775 	dispc->base = devm_ioremap_resource(&pdev->dev, dispc_mem);
4776 	if (IS_ERR(dispc->base)) {
4777 		r = PTR_ERR(dispc->base);
4778 		goto err_free;
4779 	}
4780 
4781 	dispc->irq = platform_get_irq(dispc->pdev, 0);
4782 	if (dispc->irq < 0) {
4783 		DSSERR("platform_get_irq failed\n");
4784 		r = -ENODEV;
4785 		goto err_free;
4786 	}
4787 
4788 	if (np && of_property_read_bool(np, "syscon-pol")) {
4789 		dispc->syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol");
4790 		if (IS_ERR(dispc->syscon_pol)) {
4791 			dev_err(&pdev->dev, "failed to get syscon-pol regmap\n");
4792 			r = PTR_ERR(dispc->syscon_pol);
4793 			goto err_free;
4794 		}
4795 
4796 		if (of_property_read_u32_index(np, "syscon-pol", 1,
4797 				&dispc->syscon_pol_offset)) {
4798 			dev_err(&pdev->dev, "failed to get syscon-pol offset\n");
4799 			r = -EINVAL;
4800 			goto err_free;
4801 		}
4802 	}
4803 
4804 	r = dispc_init_gamma_tables(dispc);
4805 	if (r)
4806 		goto err_free;
4807 
4808 	pm_runtime_enable(&pdev->dev);
4809 
4810 	r = dispc_runtime_get(dispc);
4811 	if (r)
4812 		goto err_runtime_get;
4813 
4814 	_omap_dispc_initial_config(dispc);
4815 
4816 	rev = dispc_read_reg(dispc, DISPC_REVISION);
4817 	dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n",
4818 	       FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4819 
4820 	dispc_runtime_put(dispc);
4821 
4822 	dss->dispc = dispc;
4823 	dss->dispc_ops = &dispc_ops;
4824 
4825 	dispc->debugfs = dss_debugfs_create_file(dss, "dispc", dispc_dump_regs,
4826 						 dispc);
4827 
4828 	return 0;
4829 
4830 err_runtime_get:
4831 	pm_runtime_disable(&pdev->dev);
4832 err_free:
4833 	kfree(dispc);
4834 	return r;
4835 }
4836 
4837 static void dispc_unbind(struct device *dev, struct device *master, void *data)
4838 {
4839 	struct dispc_device *dispc = dev_get_drvdata(dev);
4840 	struct dss_device *dss = dispc->dss;
4841 
4842 	dss_debugfs_remove_file(dispc->debugfs);
4843 
4844 	dss->dispc = NULL;
4845 	dss->dispc_ops = NULL;
4846 
4847 	pm_runtime_disable(dev);
4848 
4849 	dispc_errata_i734_wa_fini(dispc);
4850 
4851 	kfree(dispc);
4852 }
4853 
4854 static const struct component_ops dispc_component_ops = {
4855 	.bind	= dispc_bind,
4856 	.unbind	= dispc_unbind,
4857 };
4858 
4859 static int dispc_probe(struct platform_device *pdev)
4860 {
4861 	return component_add(&pdev->dev, &dispc_component_ops);
4862 }
4863 
4864 static int dispc_remove(struct platform_device *pdev)
4865 {
4866 	component_del(&pdev->dev, &dispc_component_ops);
4867 	return 0;
4868 }
4869 
4870 static int dispc_runtime_suspend(struct device *dev)
4871 {
4872 	struct dispc_device *dispc = dev_get_drvdata(dev);
4873 
4874 	dispc->is_enabled = false;
4875 	/* ensure the dispc_irq_handler sees the is_enabled value */
4876 	smp_wmb();
4877 	/* wait for current handler to finish before turning the DISPC off */
4878 	synchronize_irq(dispc->irq);
4879 
4880 	dispc_save_context(dispc);
4881 
4882 	return 0;
4883 }
4884 
4885 static int dispc_runtime_resume(struct device *dev)
4886 {
4887 	struct dispc_device *dispc = dev_get_drvdata(dev);
4888 
4889 	/*
4890 	 * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME)
4891 	 * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in
4892 	 * _omap_dispc_initial_config(). We can thus use it to detect if
4893 	 * we have lost register context.
4894 	 */
4895 	if (REG_GET(dispc, DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) {
4896 		_omap_dispc_initial_config(dispc);
4897 
4898 		dispc_errata_i734_wa(dispc);
4899 
4900 		dispc_restore_context(dispc);
4901 
4902 		dispc_restore_gamma_tables(dispc);
4903 	}
4904 
4905 	dispc->is_enabled = true;
4906 	/* ensure the dispc_irq_handler sees the is_enabled value */
4907 	smp_wmb();
4908 
4909 	return 0;
4910 }
4911 
4912 static const struct dev_pm_ops dispc_pm_ops = {
4913 	.runtime_suspend = dispc_runtime_suspend,
4914 	.runtime_resume = dispc_runtime_resume,
4915 };
4916 
4917 struct platform_driver omap_dispchw_driver = {
4918 	.probe		= dispc_probe,
4919 	.remove         = dispc_remove,
4920 	.driver         = {
4921 		.name   = "omapdss_dispc",
4922 		.pm	= &dispc_pm_ops,
4923 		.of_match_table = dispc_of_match,
4924 		.suppress_bind_attrs = true,
4925 	},
4926 };
4927