1 /*
2  * Copyright (C) 2011 Texas Instruments
3  * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #define DSS_SUBSYS_NAME "APPLY"
19 
20 #include <linux/kernel.h>
21 #include <linux/slab.h>
22 #include <linux/spinlock.h>
23 #include <linux/jiffies.h>
24 
25 #include <video/omapdss.h>
26 
27 #include "dss.h"
28 #include "dss_features.h"
29 
30 /*
31  * We have 4 levels of cache for the dispc settings. First two are in SW and
32  * the latter two in HW.
33  *
34  *       set_info()
35  *          v
36  * +--------------------+
37  * |     user_info      |
38  * +--------------------+
39  *          v
40  *        apply()
41  *          v
42  * +--------------------+
43  * |       info         |
44  * +--------------------+
45  *          v
46  *      write_regs()
47  *          v
48  * +--------------------+
49  * |  shadow registers  |
50  * +--------------------+
51  *          v
52  * VFP or lcd/digit_enable
53  *          v
54  * +--------------------+
55  * |      registers     |
56  * +--------------------+
57  */
58 
59 struct ovl_priv_data {
60 
61 	bool user_info_dirty;
62 	struct omap_overlay_info user_info;
63 
64 	bool info_dirty;
65 	struct omap_overlay_info info;
66 
67 	bool shadow_info_dirty;
68 
69 	bool extra_info_dirty;
70 	bool shadow_extra_info_dirty;
71 
72 	bool enabled;
73 	enum omap_channel channel;
74 	u32 fifo_low, fifo_high;
75 
76 	/*
77 	 * True if overlay is to be enabled. Used to check and calculate configs
78 	 * for the overlay before it is enabled in the HW.
79 	 */
80 	bool enabling;
81 };
82 
83 struct mgr_priv_data {
84 
85 	bool user_info_dirty;
86 	struct omap_overlay_manager_info user_info;
87 
88 	bool info_dirty;
89 	struct omap_overlay_manager_info info;
90 
91 	bool shadow_info_dirty;
92 
93 	/* If true, GO bit is up and shadow registers cannot be written.
94 	 * Never true for manual update displays */
95 	bool busy;
96 
97 	/* If true, dispc output is enabled */
98 	bool updating;
99 
100 	/* If true, a display is enabled using this manager */
101 	bool enabled;
102 };
103 
104 static struct {
105 	struct ovl_priv_data ovl_priv_data_array[MAX_DSS_OVERLAYS];
106 	struct mgr_priv_data mgr_priv_data_array[MAX_DSS_MANAGERS];
107 
108 	bool fifo_merge_dirty;
109 	bool fifo_merge;
110 
111 	bool irq_enabled;
112 } dss_data;
113 
114 /* protects dss_data */
115 static spinlock_t data_lock;
116 /* lock for blocking functions */
117 static DEFINE_MUTEX(apply_lock);
118 static DECLARE_COMPLETION(extra_updated_completion);
119 
120 static void dss_register_vsync_isr(void);
121 
get_ovl_priv(struct omap_overlay * ovl)122 static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl)
123 {
124 	return &dss_data.ovl_priv_data_array[ovl->id];
125 }
126 
get_mgr_priv(struct omap_overlay_manager * mgr)127 static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr)
128 {
129 	return &dss_data.mgr_priv_data_array[mgr->id];
130 }
131 
dss_apply_init(void)132 void dss_apply_init(void)
133 {
134 	const int num_ovls = dss_feat_get_num_ovls();
135 	int i;
136 
137 	spin_lock_init(&data_lock);
138 
139 	for (i = 0; i < num_ovls; ++i) {
140 		struct ovl_priv_data *op;
141 
142 		op = &dss_data.ovl_priv_data_array[i];
143 
144 		op->info.global_alpha = 255;
145 
146 		switch (i) {
147 		case 0:
148 			op->info.zorder = 0;
149 			break;
150 		case 1:
151 			op->info.zorder =
152 				dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 3 : 0;
153 			break;
154 		case 2:
155 			op->info.zorder =
156 				dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 2 : 0;
157 			break;
158 		case 3:
159 			op->info.zorder =
160 				dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 1 : 0;
161 			break;
162 		}
163 
164 		op->user_info = op->info;
165 	}
166 }
167 
ovl_manual_update(struct omap_overlay * ovl)168 static bool ovl_manual_update(struct omap_overlay *ovl)
169 {
170 	return ovl->manager->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
171 }
172 
mgr_manual_update(struct omap_overlay_manager * mgr)173 static bool mgr_manual_update(struct omap_overlay_manager *mgr)
174 {
175 	return mgr->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
176 }
177 
dss_check_settings_low(struct omap_overlay_manager * mgr,struct omap_dss_device * dssdev,bool applying)178 static int dss_check_settings_low(struct omap_overlay_manager *mgr,
179 		struct omap_dss_device *dssdev, bool applying)
180 {
181 	struct omap_overlay_info *oi;
182 	struct omap_overlay_manager_info *mi;
183 	struct omap_overlay *ovl;
184 	struct omap_overlay_info *ois[MAX_DSS_OVERLAYS];
185 	struct ovl_priv_data *op;
186 	struct mgr_priv_data *mp;
187 
188 	mp = get_mgr_priv(mgr);
189 
190 	if (applying && mp->user_info_dirty)
191 		mi = &mp->user_info;
192 	else
193 		mi = &mp->info;
194 
195 	/* collect the infos to be tested into the array */
196 	list_for_each_entry(ovl, &mgr->overlays, list) {
197 		op = get_ovl_priv(ovl);
198 
199 		if (!op->enabled && !op->enabling)
200 			oi = NULL;
201 		else if (applying && op->user_info_dirty)
202 			oi = &op->user_info;
203 		else
204 			oi = &op->info;
205 
206 		ois[ovl->id] = oi;
207 	}
208 
209 	return dss_mgr_check(mgr, dssdev, mi, ois);
210 }
211 
212 /*
213  * check manager and overlay settings using overlay_info from data->info
214  */
dss_check_settings(struct omap_overlay_manager * mgr,struct omap_dss_device * dssdev)215 static int dss_check_settings(struct omap_overlay_manager *mgr,
216 		struct omap_dss_device *dssdev)
217 {
218 	return dss_check_settings_low(mgr, dssdev, false);
219 }
220 
221 /*
222  * check manager and overlay settings using overlay_info from ovl->info if
223  * dirty and from data->info otherwise
224  */
dss_check_settings_apply(struct omap_overlay_manager * mgr,struct omap_dss_device * dssdev)225 static int dss_check_settings_apply(struct omap_overlay_manager *mgr,
226 		struct omap_dss_device *dssdev)
227 {
228 	return dss_check_settings_low(mgr, dssdev, true);
229 }
230 
need_isr(void)231 static bool need_isr(void)
232 {
233 	const int num_mgrs = dss_feat_get_num_mgrs();
234 	int i;
235 
236 	for (i = 0; i < num_mgrs; ++i) {
237 		struct omap_overlay_manager *mgr;
238 		struct mgr_priv_data *mp;
239 		struct omap_overlay *ovl;
240 
241 		mgr = omap_dss_get_overlay_manager(i);
242 		mp = get_mgr_priv(mgr);
243 
244 		if (!mp->enabled)
245 			continue;
246 
247 		if (mgr_manual_update(mgr)) {
248 			/* to catch FRAMEDONE */
249 			if (mp->updating)
250 				return true;
251 		} else {
252 			/* to catch GO bit going down */
253 			if (mp->busy)
254 				return true;
255 
256 			/* to write new values to registers */
257 			if (mp->info_dirty)
258 				return true;
259 
260 			/* to set GO bit */
261 			if (mp->shadow_info_dirty)
262 				return true;
263 
264 			list_for_each_entry(ovl, &mgr->overlays, list) {
265 				struct ovl_priv_data *op;
266 
267 				op = get_ovl_priv(ovl);
268 
269 				/*
270 				 * NOTE: we check extra_info flags even for
271 				 * disabled overlays, as extra_infos need to be
272 				 * always written.
273 				 */
274 
275 				/* to write new values to registers */
276 				if (op->extra_info_dirty)
277 					return true;
278 
279 				/* to set GO bit */
280 				if (op->shadow_extra_info_dirty)
281 					return true;
282 
283 				if (!op->enabled)
284 					continue;
285 
286 				/* to write new values to registers */
287 				if (op->info_dirty)
288 					return true;
289 
290 				/* to set GO bit */
291 				if (op->shadow_info_dirty)
292 					return true;
293 			}
294 		}
295 	}
296 
297 	return false;
298 }
299 
need_go(struct omap_overlay_manager * mgr)300 static bool need_go(struct omap_overlay_manager *mgr)
301 {
302 	struct omap_overlay *ovl;
303 	struct mgr_priv_data *mp;
304 	struct ovl_priv_data *op;
305 
306 	mp = get_mgr_priv(mgr);
307 
308 	if (mp->shadow_info_dirty)
309 		return true;
310 
311 	list_for_each_entry(ovl, &mgr->overlays, list) {
312 		op = get_ovl_priv(ovl);
313 		if (op->shadow_info_dirty || op->shadow_extra_info_dirty)
314 			return true;
315 	}
316 
317 	return false;
318 }
319 
320 /* returns true if an extra_info field is currently being updated */
extra_info_update_ongoing(void)321 static bool extra_info_update_ongoing(void)
322 {
323 	const int num_ovls = omap_dss_get_num_overlays();
324 	struct ovl_priv_data *op;
325 	struct omap_overlay *ovl;
326 	struct mgr_priv_data *mp;
327 	int i;
328 
329 	for (i = 0; i < num_ovls; ++i) {
330 		ovl = omap_dss_get_overlay(i);
331 		op = get_ovl_priv(ovl);
332 
333 		if (!ovl->manager)
334 			continue;
335 
336 		mp = get_mgr_priv(ovl->manager);
337 
338 		if (!mp->enabled)
339 			continue;
340 
341 		if (!mp->updating)
342 			continue;
343 
344 		if (op->extra_info_dirty || op->shadow_extra_info_dirty)
345 			return true;
346 	}
347 
348 	return false;
349 }
350 
351 /* wait until no extra_info updates are pending */
wait_pending_extra_info_updates(void)352 static void wait_pending_extra_info_updates(void)
353 {
354 	bool updating;
355 	unsigned long flags;
356 	unsigned long t;
357 	int r;
358 
359 	spin_lock_irqsave(&data_lock, flags);
360 
361 	updating = extra_info_update_ongoing();
362 
363 	if (!updating) {
364 		spin_unlock_irqrestore(&data_lock, flags);
365 		return;
366 	}
367 
368 	init_completion(&extra_updated_completion);
369 
370 	spin_unlock_irqrestore(&data_lock, flags);
371 
372 	t = msecs_to_jiffies(500);
373 	r = wait_for_completion_timeout(&extra_updated_completion, t);
374 	if (r == 0)
375 		DSSWARN("timeout in wait_pending_extra_info_updates\n");
376 	else if (r < 0)
377 		DSSERR("wait_pending_extra_info_updates failed: %d\n", r);
378 }
379 
dss_mgr_wait_for_go(struct omap_overlay_manager * mgr)380 int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
381 {
382 	unsigned long timeout = msecs_to_jiffies(500);
383 	struct mgr_priv_data *mp;
384 	u32 irq;
385 	int r;
386 	int i;
387 	struct omap_dss_device *dssdev = mgr->device;
388 
389 	if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
390 		return 0;
391 
392 	if (mgr_manual_update(mgr))
393 		return 0;
394 
395 	r = dispc_runtime_get();
396 	if (r)
397 		return r;
398 
399 	irq = dispc_mgr_get_vsync_irq(mgr->id);
400 
401 	mp = get_mgr_priv(mgr);
402 	i = 0;
403 	while (1) {
404 		unsigned long flags;
405 		bool shadow_dirty, dirty;
406 
407 		spin_lock_irqsave(&data_lock, flags);
408 		dirty = mp->info_dirty;
409 		shadow_dirty = mp->shadow_info_dirty;
410 		spin_unlock_irqrestore(&data_lock, flags);
411 
412 		if (!dirty && !shadow_dirty) {
413 			r = 0;
414 			break;
415 		}
416 
417 		/* 4 iterations is the worst case:
418 		 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
419 		 * 2 - first VSYNC, dirty = true
420 		 * 3 - dirty = false, shadow_dirty = true
421 		 * 4 - shadow_dirty = false */
422 		if (i++ == 3) {
423 			DSSERR("mgr(%d)->wait_for_go() not finishing\n",
424 					mgr->id);
425 			r = 0;
426 			break;
427 		}
428 
429 		r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
430 		if (r == -ERESTARTSYS)
431 			break;
432 
433 		if (r) {
434 			DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
435 			break;
436 		}
437 	}
438 
439 	dispc_runtime_put();
440 
441 	return r;
442 }
443 
dss_mgr_wait_for_go_ovl(struct omap_overlay * ovl)444 int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
445 {
446 	unsigned long timeout = msecs_to_jiffies(500);
447 	struct ovl_priv_data *op;
448 	struct omap_dss_device *dssdev;
449 	u32 irq;
450 	int r;
451 	int i;
452 
453 	if (!ovl->manager)
454 		return 0;
455 
456 	dssdev = ovl->manager->device;
457 
458 	if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
459 		return 0;
460 
461 	if (ovl_manual_update(ovl))
462 		return 0;
463 
464 	r = dispc_runtime_get();
465 	if (r)
466 		return r;
467 
468 	irq = dispc_mgr_get_vsync_irq(ovl->manager->id);
469 
470 	op = get_ovl_priv(ovl);
471 	i = 0;
472 	while (1) {
473 		unsigned long flags;
474 		bool shadow_dirty, dirty;
475 
476 		spin_lock_irqsave(&data_lock, flags);
477 		dirty = op->info_dirty;
478 		shadow_dirty = op->shadow_info_dirty;
479 		spin_unlock_irqrestore(&data_lock, flags);
480 
481 		if (!dirty && !shadow_dirty) {
482 			r = 0;
483 			break;
484 		}
485 
486 		/* 4 iterations is the worst case:
487 		 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
488 		 * 2 - first VSYNC, dirty = true
489 		 * 3 - dirty = false, shadow_dirty = true
490 		 * 4 - shadow_dirty = false */
491 		if (i++ == 3) {
492 			DSSERR("ovl(%d)->wait_for_go() not finishing\n",
493 					ovl->id);
494 			r = 0;
495 			break;
496 		}
497 
498 		r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
499 		if (r == -ERESTARTSYS)
500 			break;
501 
502 		if (r) {
503 			DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
504 			break;
505 		}
506 	}
507 
508 	dispc_runtime_put();
509 
510 	return r;
511 }
512 
dss_ovl_write_regs(struct omap_overlay * ovl)513 static void dss_ovl_write_regs(struct omap_overlay *ovl)
514 {
515 	struct ovl_priv_data *op = get_ovl_priv(ovl);
516 	struct omap_overlay_info *oi;
517 	bool ilace, replication;
518 	struct mgr_priv_data *mp;
519 	int r;
520 
521 	DSSDBGF("%d", ovl->id);
522 
523 	if (!op->enabled || !op->info_dirty)
524 		return;
525 
526 	oi = &op->info;
527 
528 	replication = dss_use_replication(ovl->manager->device, oi->color_mode);
529 
530 	ilace = ovl->manager->device->type == OMAP_DISPLAY_TYPE_VENC;
531 
532 	r = dispc_ovl_setup(ovl->id, oi, ilace, replication);
533 	if (r) {
534 		/*
535 		 * We can't do much here, as this function can be called from
536 		 * vsync interrupt.
537 		 */
538 		DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id);
539 
540 		/* This will leave fifo configurations in a nonoptimal state */
541 		op->enabled = false;
542 		dispc_ovl_enable(ovl->id, false);
543 		return;
544 	}
545 
546 	mp = get_mgr_priv(ovl->manager);
547 
548 	op->info_dirty = false;
549 	if (mp->updating)
550 		op->shadow_info_dirty = true;
551 }
552 
dss_ovl_write_regs_extra(struct omap_overlay * ovl)553 static void dss_ovl_write_regs_extra(struct omap_overlay *ovl)
554 {
555 	struct ovl_priv_data *op = get_ovl_priv(ovl);
556 	struct mgr_priv_data *mp;
557 
558 	DSSDBGF("%d", ovl->id);
559 
560 	if (!op->extra_info_dirty)
561 		return;
562 
563 	/* note: write also when op->enabled == false, so that the ovl gets
564 	 * disabled */
565 
566 	dispc_ovl_enable(ovl->id, op->enabled);
567 	dispc_ovl_set_channel_out(ovl->id, op->channel);
568 	dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high);
569 
570 	mp = get_mgr_priv(ovl->manager);
571 
572 	op->extra_info_dirty = false;
573 	if (mp->updating)
574 		op->shadow_extra_info_dirty = true;
575 }
576 
dss_mgr_write_regs(struct omap_overlay_manager * mgr)577 static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
578 {
579 	struct mgr_priv_data *mp = get_mgr_priv(mgr);
580 	struct omap_overlay *ovl;
581 
582 	DSSDBGF("%d", mgr->id);
583 
584 	if (!mp->enabled)
585 		return;
586 
587 	WARN_ON(mp->busy);
588 
589 	/* Commit overlay settings */
590 	list_for_each_entry(ovl, &mgr->overlays, list) {
591 		dss_ovl_write_regs(ovl);
592 		dss_ovl_write_regs_extra(ovl);
593 	}
594 
595 	if (mp->info_dirty) {
596 		dispc_mgr_setup(mgr->id, &mp->info);
597 
598 		mp->info_dirty = false;
599 		if (mp->updating)
600 			mp->shadow_info_dirty = true;
601 	}
602 }
603 
dss_write_regs_common(void)604 static void dss_write_regs_common(void)
605 {
606 	const int num_mgrs = omap_dss_get_num_overlay_managers();
607 	int i;
608 
609 	if (!dss_data.fifo_merge_dirty)
610 		return;
611 
612 	for (i = 0; i < num_mgrs; ++i) {
613 		struct omap_overlay_manager *mgr;
614 		struct mgr_priv_data *mp;
615 
616 		mgr = omap_dss_get_overlay_manager(i);
617 		mp = get_mgr_priv(mgr);
618 
619 		if (mp->enabled) {
620 			if (dss_data.fifo_merge_dirty) {
621 				dispc_enable_fifomerge(dss_data.fifo_merge);
622 				dss_data.fifo_merge_dirty = false;
623 			}
624 
625 			if (mp->updating)
626 				mp->shadow_info_dirty = true;
627 		}
628 	}
629 }
630 
dss_write_regs(void)631 static void dss_write_regs(void)
632 {
633 	const int num_mgrs = omap_dss_get_num_overlay_managers();
634 	int i;
635 
636 	dss_write_regs_common();
637 
638 	for (i = 0; i < num_mgrs; ++i) {
639 		struct omap_overlay_manager *mgr;
640 		struct mgr_priv_data *mp;
641 		int r;
642 
643 		mgr = omap_dss_get_overlay_manager(i);
644 		mp = get_mgr_priv(mgr);
645 
646 		if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
647 			continue;
648 
649 		r = dss_check_settings(mgr, mgr->device);
650 		if (r) {
651 			DSSERR("cannot write registers for manager %s: "
652 					"illegal configuration\n", mgr->name);
653 			continue;
654 		}
655 
656 		dss_mgr_write_regs(mgr);
657 	}
658 }
659 
dss_set_go_bits(void)660 static void dss_set_go_bits(void)
661 {
662 	const int num_mgrs = omap_dss_get_num_overlay_managers();
663 	int i;
664 
665 	for (i = 0; i < num_mgrs; ++i) {
666 		struct omap_overlay_manager *mgr;
667 		struct mgr_priv_data *mp;
668 
669 		mgr = omap_dss_get_overlay_manager(i);
670 		mp = get_mgr_priv(mgr);
671 
672 		if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
673 			continue;
674 
675 		if (!need_go(mgr))
676 			continue;
677 
678 		mp->busy = true;
679 
680 		if (!dss_data.irq_enabled && need_isr())
681 			dss_register_vsync_isr();
682 
683 		dispc_mgr_go(mgr->id);
684 	}
685 
686 }
687 
mgr_clear_shadow_dirty(struct omap_overlay_manager * mgr)688 static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
689 {
690 	struct omap_overlay *ovl;
691 	struct mgr_priv_data *mp;
692 	struct ovl_priv_data *op;
693 
694 	mp = get_mgr_priv(mgr);
695 	mp->shadow_info_dirty = false;
696 
697 	list_for_each_entry(ovl, &mgr->overlays, list) {
698 		op = get_ovl_priv(ovl);
699 		op->shadow_info_dirty = false;
700 		op->shadow_extra_info_dirty = false;
701 	}
702 }
703 
dss_mgr_start_update(struct omap_overlay_manager * mgr)704 void dss_mgr_start_update(struct omap_overlay_manager *mgr)
705 {
706 	struct mgr_priv_data *mp = get_mgr_priv(mgr);
707 	unsigned long flags;
708 	int r;
709 
710 	spin_lock_irqsave(&data_lock, flags);
711 
712 	WARN_ON(mp->updating);
713 
714 	r = dss_check_settings(mgr, mgr->device);
715 	if (r) {
716 		DSSERR("cannot start manual update: illegal configuration\n");
717 		spin_unlock_irqrestore(&data_lock, flags);
718 		return;
719 	}
720 
721 	dss_mgr_write_regs(mgr);
722 
723 	dss_write_regs_common();
724 
725 	mp->updating = true;
726 
727 	if (!dss_data.irq_enabled && need_isr())
728 		dss_register_vsync_isr();
729 
730 	dispc_mgr_enable(mgr->id, true);
731 
732 	mgr_clear_shadow_dirty(mgr);
733 
734 	spin_unlock_irqrestore(&data_lock, flags);
735 }
736 
737 static void dss_apply_irq_handler(void *data, u32 mask);
738 
dss_register_vsync_isr(void)739 static void dss_register_vsync_isr(void)
740 {
741 	const int num_mgrs = dss_feat_get_num_mgrs();
742 	u32 mask;
743 	int r, i;
744 
745 	mask = 0;
746 	for (i = 0; i < num_mgrs; ++i)
747 		mask |= dispc_mgr_get_vsync_irq(i);
748 
749 	for (i = 0; i < num_mgrs; ++i)
750 		mask |= dispc_mgr_get_framedone_irq(i);
751 
752 	r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
753 	WARN_ON(r);
754 
755 	dss_data.irq_enabled = true;
756 }
757 
dss_unregister_vsync_isr(void)758 static void dss_unregister_vsync_isr(void)
759 {
760 	const int num_mgrs = dss_feat_get_num_mgrs();
761 	u32 mask;
762 	int r, i;
763 
764 	mask = 0;
765 	for (i = 0; i < num_mgrs; ++i)
766 		mask |= dispc_mgr_get_vsync_irq(i);
767 
768 	for (i = 0; i < num_mgrs; ++i)
769 		mask |= dispc_mgr_get_framedone_irq(i);
770 
771 	r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask);
772 	WARN_ON(r);
773 
774 	dss_data.irq_enabled = false;
775 }
776 
dss_apply_irq_handler(void * data,u32 mask)777 static void dss_apply_irq_handler(void *data, u32 mask)
778 {
779 	const int num_mgrs = dss_feat_get_num_mgrs();
780 	int i;
781 	bool extra_updating;
782 
783 	spin_lock(&data_lock);
784 
785 	/* clear busy, updating flags, shadow_dirty flags */
786 	for (i = 0; i < num_mgrs; i++) {
787 		struct omap_overlay_manager *mgr;
788 		struct mgr_priv_data *mp;
789 		bool was_updating;
790 
791 		mgr = omap_dss_get_overlay_manager(i);
792 		mp = get_mgr_priv(mgr);
793 
794 		if (!mp->enabled)
795 			continue;
796 
797 		was_updating = mp->updating;
798 		mp->updating = dispc_mgr_is_enabled(i);
799 
800 		if (!mgr_manual_update(mgr)) {
801 			bool was_busy = mp->busy;
802 			mp->busy = dispc_mgr_go_busy(i);
803 
804 			if (was_busy && !mp->busy)
805 				mgr_clear_shadow_dirty(mgr);
806 		}
807 	}
808 
809 	dss_write_regs();
810 	dss_set_go_bits();
811 
812 	extra_updating = extra_info_update_ongoing();
813 	if (!extra_updating)
814 		complete_all(&extra_updated_completion);
815 
816 	if (!need_isr())
817 		dss_unregister_vsync_isr();
818 
819 	spin_unlock(&data_lock);
820 }
821 
omap_dss_mgr_apply_ovl(struct omap_overlay * ovl)822 static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
823 {
824 	struct ovl_priv_data *op;
825 
826 	op = get_ovl_priv(ovl);
827 
828 	if (!op->user_info_dirty)
829 		return;
830 
831 	op->user_info_dirty = false;
832 	op->info_dirty = true;
833 	op->info = op->user_info;
834 }
835 
omap_dss_mgr_apply_mgr(struct omap_overlay_manager * mgr)836 static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
837 {
838 	struct mgr_priv_data *mp;
839 
840 	mp = get_mgr_priv(mgr);
841 
842 	if (!mp->user_info_dirty)
843 		return;
844 
845 	mp->user_info_dirty = false;
846 	mp->info_dirty = true;
847 	mp->info = mp->user_info;
848 }
849 
omap_dss_mgr_apply(struct omap_overlay_manager * mgr)850 int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
851 {
852 	unsigned long flags;
853 	struct omap_overlay *ovl;
854 	int r;
855 
856 	DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
857 
858 	spin_lock_irqsave(&data_lock, flags);
859 
860 	r = dss_check_settings_apply(mgr, mgr->device);
861 	if (r) {
862 		spin_unlock_irqrestore(&data_lock, flags);
863 		DSSERR("failed to apply settings: illegal configuration.\n");
864 		return r;
865 	}
866 
867 	/* Configure overlays */
868 	list_for_each_entry(ovl, &mgr->overlays, list)
869 		omap_dss_mgr_apply_ovl(ovl);
870 
871 	/* Configure manager */
872 	omap_dss_mgr_apply_mgr(mgr);
873 
874 	dss_write_regs();
875 	dss_set_go_bits();
876 
877 	spin_unlock_irqrestore(&data_lock, flags);
878 
879 	return 0;
880 }
881 
dss_apply_ovl_enable(struct omap_overlay * ovl,bool enable)882 static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
883 {
884 	struct ovl_priv_data *op;
885 
886 	op = get_ovl_priv(ovl);
887 
888 	if (op->enabled == enable)
889 		return;
890 
891 	op->enabled = enable;
892 	op->extra_info_dirty = true;
893 }
894 
dss_apply_ovl_fifo_thresholds(struct omap_overlay * ovl,u32 fifo_low,u32 fifo_high)895 static void dss_apply_ovl_fifo_thresholds(struct omap_overlay *ovl,
896 		u32 fifo_low, u32 fifo_high)
897 {
898 	struct ovl_priv_data *op = get_ovl_priv(ovl);
899 
900 	if (op->fifo_low == fifo_low && op->fifo_high == fifo_high)
901 		return;
902 
903 	op->fifo_low = fifo_low;
904 	op->fifo_high = fifo_high;
905 	op->extra_info_dirty = true;
906 }
907 
dss_apply_fifo_merge(bool use_fifo_merge)908 static void dss_apply_fifo_merge(bool use_fifo_merge)
909 {
910 	if (dss_data.fifo_merge == use_fifo_merge)
911 		return;
912 
913 	dss_data.fifo_merge = use_fifo_merge;
914 	dss_data.fifo_merge_dirty = true;
915 }
916 
dss_ovl_setup_fifo(struct omap_overlay * ovl,bool use_fifo_merge)917 static void dss_ovl_setup_fifo(struct omap_overlay *ovl,
918 		bool use_fifo_merge)
919 {
920 	struct ovl_priv_data *op = get_ovl_priv(ovl);
921 	struct omap_dss_device *dssdev;
922 	u32 fifo_low, fifo_high;
923 
924 	if (!op->enabled && !op->enabling)
925 		return;
926 
927 	dssdev = ovl->manager->device;
928 
929 	dispc_ovl_compute_fifo_thresholds(ovl->id, &fifo_low, &fifo_high,
930 			use_fifo_merge, ovl_manual_update(ovl));
931 
932 	dss_apply_ovl_fifo_thresholds(ovl, fifo_low, fifo_high);
933 }
934 
dss_mgr_setup_fifos(struct omap_overlay_manager * mgr,bool use_fifo_merge)935 static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr,
936 		bool use_fifo_merge)
937 {
938 	struct omap_overlay *ovl;
939 	struct mgr_priv_data *mp;
940 
941 	mp = get_mgr_priv(mgr);
942 
943 	if (!mp->enabled)
944 		return;
945 
946 	list_for_each_entry(ovl, &mgr->overlays, list)
947 		dss_ovl_setup_fifo(ovl, use_fifo_merge);
948 }
949 
dss_setup_fifos(bool use_fifo_merge)950 static void dss_setup_fifos(bool use_fifo_merge)
951 {
952 	const int num_mgrs = omap_dss_get_num_overlay_managers();
953 	struct omap_overlay_manager *mgr;
954 	int i;
955 
956 	for (i = 0; i < num_mgrs; ++i) {
957 		mgr = omap_dss_get_overlay_manager(i);
958 		dss_mgr_setup_fifos(mgr, use_fifo_merge);
959 	}
960 }
961 
get_num_used_managers(void)962 static int get_num_used_managers(void)
963 {
964 	const int num_mgrs = omap_dss_get_num_overlay_managers();
965 	struct omap_overlay_manager *mgr;
966 	struct mgr_priv_data *mp;
967 	int i;
968 	int enabled_mgrs;
969 
970 	enabled_mgrs = 0;
971 
972 	for (i = 0; i < num_mgrs; ++i) {
973 		mgr = omap_dss_get_overlay_manager(i);
974 		mp = get_mgr_priv(mgr);
975 
976 		if (!mp->enabled)
977 			continue;
978 
979 		enabled_mgrs++;
980 	}
981 
982 	return enabled_mgrs;
983 }
984 
get_num_used_overlays(void)985 static int get_num_used_overlays(void)
986 {
987 	const int num_ovls = omap_dss_get_num_overlays();
988 	struct omap_overlay *ovl;
989 	struct ovl_priv_data *op;
990 	struct mgr_priv_data *mp;
991 	int i;
992 	int enabled_ovls;
993 
994 	enabled_ovls = 0;
995 
996 	for (i = 0; i < num_ovls; ++i) {
997 		ovl = omap_dss_get_overlay(i);
998 		op = get_ovl_priv(ovl);
999 
1000 		if (!op->enabled && !op->enabling)
1001 			continue;
1002 
1003 		mp = get_mgr_priv(ovl->manager);
1004 
1005 		if (!mp->enabled)
1006 			continue;
1007 
1008 		enabled_ovls++;
1009 	}
1010 
1011 	return enabled_ovls;
1012 }
1013 
get_use_fifo_merge(void)1014 static bool get_use_fifo_merge(void)
1015 {
1016 	int enabled_mgrs = get_num_used_managers();
1017 	int enabled_ovls = get_num_used_overlays();
1018 
1019 	if (!dss_has_feature(FEAT_FIFO_MERGE))
1020 		return false;
1021 
1022 	/*
1023 	 * In theory the only requirement for fifomerge is enabled_ovls <= 1.
1024 	 * However, if we have two managers enabled and set/unset the fifomerge,
1025 	 * we need to set the GO bits in particular sequence for the managers,
1026 	 * and wait in between.
1027 	 *
1028 	 * This is rather difficult as new apply calls can happen at any time,
1029 	 * so we simplify the problem by requiring also that enabled_mgrs <= 1.
1030 	 * In practice this shouldn't matter, because when only one overlay is
1031 	 * enabled, most likely only one output is enabled.
1032 	 */
1033 
1034 	return enabled_mgrs <= 1 && enabled_ovls <= 1;
1035 }
1036 
dss_mgr_enable(struct omap_overlay_manager * mgr)1037 int dss_mgr_enable(struct omap_overlay_manager *mgr)
1038 {
1039 	struct mgr_priv_data *mp = get_mgr_priv(mgr);
1040 	unsigned long flags;
1041 	int r;
1042 	bool fifo_merge;
1043 
1044 	mutex_lock(&apply_lock);
1045 
1046 	if (mp->enabled)
1047 		goto out;
1048 
1049 	spin_lock_irqsave(&data_lock, flags);
1050 
1051 	mp->enabled = true;
1052 
1053 	r = dss_check_settings(mgr, mgr->device);
1054 	if (r) {
1055 		DSSERR("failed to enable manager %d: check_settings failed\n",
1056 				mgr->id);
1057 		goto err;
1058 	}
1059 
1060 	/* step 1: setup fifos/fifomerge before enabling the manager */
1061 
1062 	fifo_merge = get_use_fifo_merge();
1063 	dss_setup_fifos(fifo_merge);
1064 	dss_apply_fifo_merge(fifo_merge);
1065 
1066 	dss_write_regs();
1067 	dss_set_go_bits();
1068 
1069 	spin_unlock_irqrestore(&data_lock, flags);
1070 
1071 	/* wait until fifo config is in */
1072 	wait_pending_extra_info_updates();
1073 
1074 	/* step 2: enable the manager */
1075 	spin_lock_irqsave(&data_lock, flags);
1076 
1077 	if (!mgr_manual_update(mgr))
1078 		mp->updating = true;
1079 
1080 	spin_unlock_irqrestore(&data_lock, flags);
1081 
1082 	if (!mgr_manual_update(mgr))
1083 		dispc_mgr_enable(mgr->id, true);
1084 
1085 out:
1086 	mutex_unlock(&apply_lock);
1087 
1088 	return 0;
1089 
1090 err:
1091 	mp->enabled = false;
1092 	spin_unlock_irqrestore(&data_lock, flags);
1093 	mutex_unlock(&apply_lock);
1094 	return r;
1095 }
1096 
dss_mgr_disable(struct omap_overlay_manager * mgr)1097 void dss_mgr_disable(struct omap_overlay_manager *mgr)
1098 {
1099 	struct mgr_priv_data *mp = get_mgr_priv(mgr);
1100 	unsigned long flags;
1101 	bool fifo_merge;
1102 
1103 	mutex_lock(&apply_lock);
1104 
1105 	if (!mp->enabled)
1106 		goto out;
1107 
1108 	if (!mgr_manual_update(mgr))
1109 		dispc_mgr_enable(mgr->id, false);
1110 
1111 	spin_lock_irqsave(&data_lock, flags);
1112 
1113 	mp->updating = false;
1114 	mp->enabled = false;
1115 
1116 	fifo_merge = get_use_fifo_merge();
1117 	dss_setup_fifos(fifo_merge);
1118 	dss_apply_fifo_merge(fifo_merge);
1119 
1120 	dss_write_regs();
1121 	dss_set_go_bits();
1122 
1123 	spin_unlock_irqrestore(&data_lock, flags);
1124 
1125 	wait_pending_extra_info_updates();
1126 out:
1127 	mutex_unlock(&apply_lock);
1128 }
1129 
dss_mgr_set_info(struct omap_overlay_manager * mgr,struct omap_overlay_manager_info * info)1130 int dss_mgr_set_info(struct omap_overlay_manager *mgr,
1131 		struct omap_overlay_manager_info *info)
1132 {
1133 	struct mgr_priv_data *mp = get_mgr_priv(mgr);
1134 	unsigned long flags;
1135 	int r;
1136 
1137 	r = dss_mgr_simple_check(mgr, info);
1138 	if (r)
1139 		return r;
1140 
1141 	spin_lock_irqsave(&data_lock, flags);
1142 
1143 	mp->user_info = *info;
1144 	mp->user_info_dirty = true;
1145 
1146 	spin_unlock_irqrestore(&data_lock, flags);
1147 
1148 	return 0;
1149 }
1150 
dss_mgr_get_info(struct omap_overlay_manager * mgr,struct omap_overlay_manager_info * info)1151 void dss_mgr_get_info(struct omap_overlay_manager *mgr,
1152 		struct omap_overlay_manager_info *info)
1153 {
1154 	struct mgr_priv_data *mp = get_mgr_priv(mgr);
1155 	unsigned long flags;
1156 
1157 	spin_lock_irqsave(&data_lock, flags);
1158 
1159 	*info = mp->user_info;
1160 
1161 	spin_unlock_irqrestore(&data_lock, flags);
1162 }
1163 
dss_mgr_set_device(struct omap_overlay_manager * mgr,struct omap_dss_device * dssdev)1164 int dss_mgr_set_device(struct omap_overlay_manager *mgr,
1165 		struct omap_dss_device *dssdev)
1166 {
1167 	int r;
1168 
1169 	mutex_lock(&apply_lock);
1170 
1171 	if (dssdev->manager) {
1172 		DSSERR("display '%s' already has a manager '%s'\n",
1173 			       dssdev->name, dssdev->manager->name);
1174 		r = -EINVAL;
1175 		goto err;
1176 	}
1177 
1178 	if ((mgr->supported_displays & dssdev->type) == 0) {
1179 		DSSERR("display '%s' does not support manager '%s'\n",
1180 			       dssdev->name, mgr->name);
1181 		r = -EINVAL;
1182 		goto err;
1183 	}
1184 
1185 	dssdev->manager = mgr;
1186 	mgr->device = dssdev;
1187 
1188 	mutex_unlock(&apply_lock);
1189 
1190 	return 0;
1191 err:
1192 	mutex_unlock(&apply_lock);
1193 	return r;
1194 }
1195 
dss_mgr_unset_device(struct omap_overlay_manager * mgr)1196 int dss_mgr_unset_device(struct omap_overlay_manager *mgr)
1197 {
1198 	int r;
1199 
1200 	mutex_lock(&apply_lock);
1201 
1202 	if (!mgr->device) {
1203 		DSSERR("failed to unset display, display not set.\n");
1204 		r = -EINVAL;
1205 		goto err;
1206 	}
1207 
1208 	/*
1209 	 * Don't allow currently enabled displays to have the overlay manager
1210 	 * pulled out from underneath them
1211 	 */
1212 	if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED) {
1213 		r = -EINVAL;
1214 		goto err;
1215 	}
1216 
1217 	mgr->device->manager = NULL;
1218 	mgr->device = NULL;
1219 
1220 	mutex_unlock(&apply_lock);
1221 
1222 	return 0;
1223 err:
1224 	mutex_unlock(&apply_lock);
1225 	return r;
1226 }
1227 
1228 
dss_ovl_set_info(struct omap_overlay * ovl,struct omap_overlay_info * info)1229 int dss_ovl_set_info(struct omap_overlay *ovl,
1230 		struct omap_overlay_info *info)
1231 {
1232 	struct ovl_priv_data *op = get_ovl_priv(ovl);
1233 	unsigned long flags;
1234 	int r;
1235 
1236 	r = dss_ovl_simple_check(ovl, info);
1237 	if (r)
1238 		return r;
1239 
1240 	spin_lock_irqsave(&data_lock, flags);
1241 
1242 	op->user_info = *info;
1243 	op->user_info_dirty = true;
1244 
1245 	spin_unlock_irqrestore(&data_lock, flags);
1246 
1247 	return 0;
1248 }
1249 
dss_ovl_get_info(struct omap_overlay * ovl,struct omap_overlay_info * info)1250 void dss_ovl_get_info(struct omap_overlay *ovl,
1251 		struct omap_overlay_info *info)
1252 {
1253 	struct ovl_priv_data *op = get_ovl_priv(ovl);
1254 	unsigned long flags;
1255 
1256 	spin_lock_irqsave(&data_lock, flags);
1257 
1258 	*info = op->user_info;
1259 
1260 	spin_unlock_irqrestore(&data_lock, flags);
1261 }
1262 
dss_ovl_set_manager(struct omap_overlay * ovl,struct omap_overlay_manager * mgr)1263 int dss_ovl_set_manager(struct omap_overlay *ovl,
1264 		struct omap_overlay_manager *mgr)
1265 {
1266 	struct ovl_priv_data *op = get_ovl_priv(ovl);
1267 	unsigned long flags;
1268 	int r;
1269 
1270 	if (!mgr)
1271 		return -EINVAL;
1272 
1273 	mutex_lock(&apply_lock);
1274 
1275 	if (ovl->manager) {
1276 		DSSERR("overlay '%s' already has a manager '%s'\n",
1277 				ovl->name, ovl->manager->name);
1278 		r = -EINVAL;
1279 		goto err;
1280 	}
1281 
1282 	spin_lock_irqsave(&data_lock, flags);
1283 
1284 	if (op->enabled) {
1285 		spin_unlock_irqrestore(&data_lock, flags);
1286 		DSSERR("overlay has to be disabled to change the manager\n");
1287 		r = -EINVAL;
1288 		goto err;
1289 	}
1290 
1291 	op->channel = mgr->id;
1292 	op->extra_info_dirty = true;
1293 
1294 	ovl->manager = mgr;
1295 	list_add_tail(&ovl->list, &mgr->overlays);
1296 
1297 	spin_unlock_irqrestore(&data_lock, flags);
1298 
1299 	/* XXX: When there is an overlay on a DSI manual update display, and
1300 	 * the overlay is first disabled, then moved to tv, and enabled, we
1301 	 * seem to get SYNC_LOST_DIGIT error.
1302 	 *
1303 	 * Waiting doesn't seem to help, but updating the manual update display
1304 	 * after disabling the overlay seems to fix this. This hints that the
1305 	 * overlay is perhaps somehow tied to the LCD output until the output
1306 	 * is updated.
1307 	 *
1308 	 * Userspace workaround for this is to update the LCD after disabling
1309 	 * the overlay, but before moving the overlay to TV.
1310 	 */
1311 
1312 	mutex_unlock(&apply_lock);
1313 
1314 	return 0;
1315 err:
1316 	mutex_unlock(&apply_lock);
1317 	return r;
1318 }
1319 
dss_ovl_unset_manager(struct omap_overlay * ovl)1320 int dss_ovl_unset_manager(struct omap_overlay *ovl)
1321 {
1322 	struct ovl_priv_data *op = get_ovl_priv(ovl);
1323 	unsigned long flags;
1324 	int r;
1325 
1326 	mutex_lock(&apply_lock);
1327 
1328 	if (!ovl->manager) {
1329 		DSSERR("failed to detach overlay: manager not set\n");
1330 		r = -EINVAL;
1331 		goto err;
1332 	}
1333 
1334 	spin_lock_irqsave(&data_lock, flags);
1335 
1336 	if (op->enabled) {
1337 		spin_unlock_irqrestore(&data_lock, flags);
1338 		DSSERR("overlay has to be disabled to unset the manager\n");
1339 		r = -EINVAL;
1340 		goto err;
1341 	}
1342 
1343 	op->channel = -1;
1344 
1345 	ovl->manager = NULL;
1346 	list_del(&ovl->list);
1347 
1348 	spin_unlock_irqrestore(&data_lock, flags);
1349 
1350 	mutex_unlock(&apply_lock);
1351 
1352 	return 0;
1353 err:
1354 	mutex_unlock(&apply_lock);
1355 	return r;
1356 }
1357 
dss_ovl_is_enabled(struct omap_overlay * ovl)1358 bool dss_ovl_is_enabled(struct omap_overlay *ovl)
1359 {
1360 	struct ovl_priv_data *op = get_ovl_priv(ovl);
1361 	unsigned long flags;
1362 	bool e;
1363 
1364 	spin_lock_irqsave(&data_lock, flags);
1365 
1366 	e = op->enabled;
1367 
1368 	spin_unlock_irqrestore(&data_lock, flags);
1369 
1370 	return e;
1371 }
1372 
dss_ovl_enable(struct omap_overlay * ovl)1373 int dss_ovl_enable(struct omap_overlay *ovl)
1374 {
1375 	struct ovl_priv_data *op = get_ovl_priv(ovl);
1376 	unsigned long flags;
1377 	bool fifo_merge;
1378 	int r;
1379 
1380 	mutex_lock(&apply_lock);
1381 
1382 	if (op->enabled) {
1383 		r = 0;
1384 		goto err1;
1385 	}
1386 
1387 	if (ovl->manager == NULL || ovl->manager->device == NULL) {
1388 		r = -EINVAL;
1389 		goto err1;
1390 	}
1391 
1392 	spin_lock_irqsave(&data_lock, flags);
1393 
1394 	op->enabling = true;
1395 
1396 	r = dss_check_settings(ovl->manager, ovl->manager->device);
1397 	if (r) {
1398 		DSSERR("failed to enable overlay %d: check_settings failed\n",
1399 				ovl->id);
1400 		goto err2;
1401 	}
1402 
1403 	/* step 1: configure fifos/fifomerge for currently enabled ovls */
1404 
1405 	fifo_merge = get_use_fifo_merge();
1406 	dss_setup_fifos(fifo_merge);
1407 	dss_apply_fifo_merge(fifo_merge);
1408 
1409 	dss_write_regs();
1410 	dss_set_go_bits();
1411 
1412 	spin_unlock_irqrestore(&data_lock, flags);
1413 
1414 	/* wait for fifo configs to go in */
1415 	wait_pending_extra_info_updates();
1416 
1417 	/* step 2: enable the overlay */
1418 	spin_lock_irqsave(&data_lock, flags);
1419 
1420 	op->enabling = false;
1421 	dss_apply_ovl_enable(ovl, true);
1422 
1423 	dss_write_regs();
1424 	dss_set_go_bits();
1425 
1426 	spin_unlock_irqrestore(&data_lock, flags);
1427 
1428 	/* wait for overlay to be enabled */
1429 	wait_pending_extra_info_updates();
1430 
1431 	mutex_unlock(&apply_lock);
1432 
1433 	return 0;
1434 err2:
1435 	op->enabling = false;
1436 	spin_unlock_irqrestore(&data_lock, flags);
1437 err1:
1438 	mutex_unlock(&apply_lock);
1439 	return r;
1440 }
1441 
dss_ovl_disable(struct omap_overlay * ovl)1442 int dss_ovl_disable(struct omap_overlay *ovl)
1443 {
1444 	struct ovl_priv_data *op = get_ovl_priv(ovl);
1445 	unsigned long flags;
1446 	bool fifo_merge;
1447 	int r;
1448 
1449 	mutex_lock(&apply_lock);
1450 
1451 	if (!op->enabled) {
1452 		r = 0;
1453 		goto err;
1454 	}
1455 
1456 	if (ovl->manager == NULL || ovl->manager->device == NULL) {
1457 		r = -EINVAL;
1458 		goto err;
1459 	}
1460 
1461 	/* step 1: disable the overlay */
1462 	spin_lock_irqsave(&data_lock, flags);
1463 
1464 	dss_apply_ovl_enable(ovl, false);
1465 
1466 	dss_write_regs();
1467 	dss_set_go_bits();
1468 
1469 	spin_unlock_irqrestore(&data_lock, flags);
1470 
1471 	/* wait for the overlay to be disabled */
1472 	wait_pending_extra_info_updates();
1473 
1474 	/* step 2: configure fifos/fifomerge */
1475 	spin_lock_irqsave(&data_lock, flags);
1476 
1477 	fifo_merge = get_use_fifo_merge();
1478 	dss_setup_fifos(fifo_merge);
1479 	dss_apply_fifo_merge(fifo_merge);
1480 
1481 	dss_write_regs();
1482 	dss_set_go_bits();
1483 
1484 	spin_unlock_irqrestore(&data_lock, flags);
1485 
1486 	/* wait for fifo config to go in */
1487 	wait_pending_extra_info_updates();
1488 
1489 	mutex_unlock(&apply_lock);
1490 
1491 	return 0;
1492 
1493 err:
1494 	mutex_unlock(&apply_lock);
1495 	return r;
1496 }
1497 
1498