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/module.h>
22 #include <linux/slab.h>
23 #include <linux/spinlock.h>
24 #include <linux/jiffies.h>
25
26 #include <video/omapdss.h>
27
28 #include "dss.h"
29 #include "dss_features.h"
30 #include "dispc-compat.h"
31
32 /*
33 * We have 4 levels of cache for the dispc settings. First two are in SW and
34 * the latter two in HW.
35 *
36 * set_info()
37 * v
38 * +--------------------+
39 * | user_info |
40 * +--------------------+
41 * v
42 * apply()
43 * v
44 * +--------------------+
45 * | info |
46 * +--------------------+
47 * v
48 * write_regs()
49 * v
50 * +--------------------+
51 * | shadow registers |
52 * +--------------------+
53 * v
54 * VFP or lcd/digit_enable
55 * v
56 * +--------------------+
57 * | registers |
58 * +--------------------+
59 */
60
61 struct ovl_priv_data {
62
63 bool user_info_dirty;
64 struct omap_overlay_info user_info;
65
66 bool info_dirty;
67 struct omap_overlay_info info;
68
69 bool shadow_info_dirty;
70
71 bool extra_info_dirty;
72 bool shadow_extra_info_dirty;
73
74 bool enabled;
75 u32 fifo_low, fifo_high;
76
77 /*
78 * True if overlay is to be enabled. Used to check and calculate configs
79 * for the overlay before it is enabled in the HW.
80 */
81 bool enabling;
82 };
83
84 struct mgr_priv_data {
85
86 bool user_info_dirty;
87 struct omap_overlay_manager_info user_info;
88
89 bool info_dirty;
90 struct omap_overlay_manager_info info;
91
92 bool shadow_info_dirty;
93
94 /* If true, GO bit is up and shadow registers cannot be written.
95 * Never true for manual update displays */
96 bool busy;
97
98 /* If true, dispc output is enabled */
99 bool updating;
100
101 /* If true, a display is enabled using this manager */
102 bool enabled;
103
104 bool extra_info_dirty;
105 bool shadow_extra_info_dirty;
106
107 struct omap_video_timings timings;
108 struct dss_lcd_mgr_config lcd_config;
109
110 void (*framedone_handler)(void *);
111 void *framedone_handler_data;
112 };
113
114 static struct {
115 struct ovl_priv_data ovl_priv_data_array[MAX_DSS_OVERLAYS];
116 struct mgr_priv_data mgr_priv_data_array[MAX_DSS_MANAGERS];
117
118 bool irq_enabled;
119 } dss_data;
120
121 /* protects dss_data */
122 static spinlock_t data_lock;
123 /* lock for blocking functions */
124 static DEFINE_MUTEX(apply_lock);
125 static DECLARE_COMPLETION(extra_updated_completion);
126
127 static void dss_register_vsync_isr(void);
128
get_ovl_priv(struct omap_overlay * ovl)129 static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl)
130 {
131 return &dss_data.ovl_priv_data_array[ovl->id];
132 }
133
get_mgr_priv(struct omap_overlay_manager * mgr)134 static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr)
135 {
136 return &dss_data.mgr_priv_data_array[mgr->id];
137 }
138
apply_init_priv(void)139 static void apply_init_priv(void)
140 {
141 const int num_ovls = dss_feat_get_num_ovls();
142 struct mgr_priv_data *mp;
143 int i;
144
145 spin_lock_init(&data_lock);
146
147 for (i = 0; i < num_ovls; ++i) {
148 struct ovl_priv_data *op;
149
150 op = &dss_data.ovl_priv_data_array[i];
151
152 op->info.global_alpha = 255;
153
154 switch (i) {
155 case 0:
156 op->info.zorder = 0;
157 break;
158 case 1:
159 op->info.zorder =
160 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 3 : 0;
161 break;
162 case 2:
163 op->info.zorder =
164 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 2 : 0;
165 break;
166 case 3:
167 op->info.zorder =
168 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 1 : 0;
169 break;
170 }
171
172 op->user_info = op->info;
173 }
174
175 /*
176 * Initialize some of the lcd_config fields for TV manager, this lets
177 * us prevent checking if the manager is LCD or TV at some places
178 */
179 mp = &dss_data.mgr_priv_data_array[OMAP_DSS_CHANNEL_DIGIT];
180
181 mp->lcd_config.video_port_width = 24;
182 mp->lcd_config.clock_info.lck_div = 1;
183 mp->lcd_config.clock_info.pck_div = 1;
184 }
185
186 /*
187 * A LCD manager's stallmode decides whether it is in manual or auto update. TV
188 * manager is always auto update, stallmode field for TV manager is false by
189 * default
190 */
ovl_manual_update(struct omap_overlay * ovl)191 static bool ovl_manual_update(struct omap_overlay *ovl)
192 {
193 struct mgr_priv_data *mp = get_mgr_priv(ovl->manager);
194
195 return mp->lcd_config.stallmode;
196 }
197
mgr_manual_update(struct omap_overlay_manager * mgr)198 static bool mgr_manual_update(struct omap_overlay_manager *mgr)
199 {
200 struct mgr_priv_data *mp = get_mgr_priv(mgr);
201
202 return mp->lcd_config.stallmode;
203 }
204
dss_check_settings_low(struct omap_overlay_manager * mgr,bool applying)205 static int dss_check_settings_low(struct omap_overlay_manager *mgr,
206 bool applying)
207 {
208 struct omap_overlay_info *oi;
209 struct omap_overlay_manager_info *mi;
210 struct omap_overlay *ovl;
211 struct omap_overlay_info *ois[MAX_DSS_OVERLAYS];
212 struct ovl_priv_data *op;
213 struct mgr_priv_data *mp;
214
215 mp = get_mgr_priv(mgr);
216
217 if (!mp->enabled)
218 return 0;
219
220 if (applying && mp->user_info_dirty)
221 mi = &mp->user_info;
222 else
223 mi = &mp->info;
224
225 /* collect the infos to be tested into the array */
226 list_for_each_entry(ovl, &mgr->overlays, list) {
227 op = get_ovl_priv(ovl);
228
229 if (!op->enabled && !op->enabling)
230 oi = NULL;
231 else if (applying && op->user_info_dirty)
232 oi = &op->user_info;
233 else
234 oi = &op->info;
235
236 ois[ovl->id] = oi;
237 }
238
239 return dss_mgr_check(mgr, mi, &mp->timings, &mp->lcd_config, ois);
240 }
241
242 /*
243 * check manager and overlay settings using overlay_info from data->info
244 */
dss_check_settings(struct omap_overlay_manager * mgr)245 static int dss_check_settings(struct omap_overlay_manager *mgr)
246 {
247 return dss_check_settings_low(mgr, false);
248 }
249
250 /*
251 * check manager and overlay settings using overlay_info from ovl->info if
252 * dirty and from data->info otherwise
253 */
dss_check_settings_apply(struct omap_overlay_manager * mgr)254 static int dss_check_settings_apply(struct omap_overlay_manager *mgr)
255 {
256 return dss_check_settings_low(mgr, true);
257 }
258
need_isr(void)259 static bool need_isr(void)
260 {
261 const int num_mgrs = dss_feat_get_num_mgrs();
262 int i;
263
264 for (i = 0; i < num_mgrs; ++i) {
265 struct omap_overlay_manager *mgr;
266 struct mgr_priv_data *mp;
267 struct omap_overlay *ovl;
268
269 mgr = omap_dss_get_overlay_manager(i);
270 mp = get_mgr_priv(mgr);
271
272 if (!mp->enabled)
273 continue;
274
275 if (mgr_manual_update(mgr)) {
276 /* to catch FRAMEDONE */
277 if (mp->updating)
278 return true;
279 } else {
280 /* to catch GO bit going down */
281 if (mp->busy)
282 return true;
283
284 /* to write new values to registers */
285 if (mp->info_dirty)
286 return true;
287
288 /* to set GO bit */
289 if (mp->shadow_info_dirty)
290 return true;
291
292 /*
293 * NOTE: we don't check extra_info flags for disabled
294 * managers, once the manager is enabled, the extra_info
295 * related manager changes will be taken in by HW.
296 */
297
298 /* to write new values to registers */
299 if (mp->extra_info_dirty)
300 return true;
301
302 /* to set GO bit */
303 if (mp->shadow_extra_info_dirty)
304 return true;
305
306 list_for_each_entry(ovl, &mgr->overlays, list) {
307 struct ovl_priv_data *op;
308
309 op = get_ovl_priv(ovl);
310
311 /*
312 * NOTE: we check extra_info flags even for
313 * disabled overlays, as extra_infos need to be
314 * always written.
315 */
316
317 /* to write new values to registers */
318 if (op->extra_info_dirty)
319 return true;
320
321 /* to set GO bit */
322 if (op->shadow_extra_info_dirty)
323 return true;
324
325 if (!op->enabled)
326 continue;
327
328 /* to write new values to registers */
329 if (op->info_dirty)
330 return true;
331
332 /* to set GO bit */
333 if (op->shadow_info_dirty)
334 return true;
335 }
336 }
337 }
338
339 return false;
340 }
341
need_go(struct omap_overlay_manager * mgr)342 static bool need_go(struct omap_overlay_manager *mgr)
343 {
344 struct omap_overlay *ovl;
345 struct mgr_priv_data *mp;
346 struct ovl_priv_data *op;
347
348 mp = get_mgr_priv(mgr);
349
350 if (mp->shadow_info_dirty || mp->shadow_extra_info_dirty)
351 return true;
352
353 list_for_each_entry(ovl, &mgr->overlays, list) {
354 op = get_ovl_priv(ovl);
355 if (op->shadow_info_dirty || op->shadow_extra_info_dirty)
356 return true;
357 }
358
359 return false;
360 }
361
362 /* returns true if an extra_info field is currently being updated */
extra_info_update_ongoing(void)363 static bool extra_info_update_ongoing(void)
364 {
365 const int num_mgrs = dss_feat_get_num_mgrs();
366 int i;
367
368 for (i = 0; i < num_mgrs; ++i) {
369 struct omap_overlay_manager *mgr;
370 struct omap_overlay *ovl;
371 struct mgr_priv_data *mp;
372
373 mgr = omap_dss_get_overlay_manager(i);
374 mp = get_mgr_priv(mgr);
375
376 if (!mp->enabled)
377 continue;
378
379 if (!mp->updating)
380 continue;
381
382 if (mp->extra_info_dirty || mp->shadow_extra_info_dirty)
383 return true;
384
385 list_for_each_entry(ovl, &mgr->overlays, list) {
386 struct ovl_priv_data *op = get_ovl_priv(ovl);
387
388 if (op->extra_info_dirty || op->shadow_extra_info_dirty)
389 return true;
390 }
391 }
392
393 return false;
394 }
395
396 /* wait until no extra_info updates are pending */
wait_pending_extra_info_updates(void)397 static void wait_pending_extra_info_updates(void)
398 {
399 bool updating;
400 unsigned long flags;
401 unsigned long t;
402 int r;
403
404 spin_lock_irqsave(&data_lock, flags);
405
406 updating = extra_info_update_ongoing();
407
408 if (!updating) {
409 spin_unlock_irqrestore(&data_lock, flags);
410 return;
411 }
412
413 init_completion(&extra_updated_completion);
414
415 spin_unlock_irqrestore(&data_lock, flags);
416
417 t = msecs_to_jiffies(500);
418 r = wait_for_completion_timeout(&extra_updated_completion, t);
419 if (r == 0)
420 DSSWARN("timeout in wait_pending_extra_info_updates\n");
421 }
422
dss_ovl_get_device(struct omap_overlay * ovl)423 static inline struct omap_dss_device *dss_ovl_get_device(struct omap_overlay *ovl)
424 {
425 return ovl->manager ?
426 (ovl->manager->output ? ovl->manager->output->device : NULL) :
427 NULL;
428 }
429
dss_mgr_get_device(struct omap_overlay_manager * mgr)430 static inline struct omap_dss_device *dss_mgr_get_device(struct omap_overlay_manager *mgr)
431 {
432 return mgr->output ? mgr->output->device : NULL;
433 }
434
dss_mgr_wait_for_vsync(struct omap_overlay_manager * mgr)435 static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
436 {
437 unsigned long timeout = msecs_to_jiffies(500);
438 u32 irq;
439 int r;
440
441 if (mgr->output == NULL)
442 return -ENODEV;
443
444 r = dispc_runtime_get();
445 if (r)
446 return r;
447
448 switch (mgr->output->id) {
449 case OMAP_DSS_OUTPUT_VENC:
450 irq = DISPC_IRQ_EVSYNC_ODD;
451 break;
452 case OMAP_DSS_OUTPUT_HDMI:
453 irq = DISPC_IRQ_EVSYNC_EVEN;
454 break;
455 default:
456 irq = dispc_mgr_get_vsync_irq(mgr->id);
457 break;
458 }
459
460 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
461
462 dispc_runtime_put();
463
464 return r;
465 }
466
dss_mgr_wait_for_go(struct omap_overlay_manager * mgr)467 static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
468 {
469 unsigned long timeout = msecs_to_jiffies(500);
470 struct mgr_priv_data *mp = get_mgr_priv(mgr);
471 u32 irq;
472 unsigned long flags;
473 int r;
474 int i;
475
476 spin_lock_irqsave(&data_lock, flags);
477
478 if (mgr_manual_update(mgr)) {
479 spin_unlock_irqrestore(&data_lock, flags);
480 return 0;
481 }
482
483 if (!mp->enabled) {
484 spin_unlock_irqrestore(&data_lock, flags);
485 return 0;
486 }
487
488 spin_unlock_irqrestore(&data_lock, flags);
489
490 r = dispc_runtime_get();
491 if (r)
492 return r;
493
494 irq = dispc_mgr_get_vsync_irq(mgr->id);
495
496 i = 0;
497 while (1) {
498 bool shadow_dirty, dirty;
499
500 spin_lock_irqsave(&data_lock, flags);
501 dirty = mp->info_dirty;
502 shadow_dirty = mp->shadow_info_dirty;
503 spin_unlock_irqrestore(&data_lock, flags);
504
505 if (!dirty && !shadow_dirty) {
506 r = 0;
507 break;
508 }
509
510 /* 4 iterations is the worst case:
511 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
512 * 2 - first VSYNC, dirty = true
513 * 3 - dirty = false, shadow_dirty = true
514 * 4 - shadow_dirty = false */
515 if (i++ == 3) {
516 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
517 mgr->id);
518 r = 0;
519 break;
520 }
521
522 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
523 if (r == -ERESTARTSYS)
524 break;
525
526 if (r) {
527 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
528 break;
529 }
530 }
531
532 dispc_runtime_put();
533
534 return r;
535 }
536
dss_mgr_wait_for_go_ovl(struct omap_overlay * ovl)537 static int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
538 {
539 unsigned long timeout = msecs_to_jiffies(500);
540 struct ovl_priv_data *op;
541 struct mgr_priv_data *mp;
542 u32 irq;
543 unsigned long flags;
544 int r;
545 int i;
546
547 if (!ovl->manager)
548 return 0;
549
550 mp = get_mgr_priv(ovl->manager);
551
552 spin_lock_irqsave(&data_lock, flags);
553
554 if (ovl_manual_update(ovl)) {
555 spin_unlock_irqrestore(&data_lock, flags);
556 return 0;
557 }
558
559 if (!mp->enabled) {
560 spin_unlock_irqrestore(&data_lock, flags);
561 return 0;
562 }
563
564 spin_unlock_irqrestore(&data_lock, flags);
565
566 r = dispc_runtime_get();
567 if (r)
568 return r;
569
570 irq = dispc_mgr_get_vsync_irq(ovl->manager->id);
571
572 op = get_ovl_priv(ovl);
573 i = 0;
574 while (1) {
575 bool shadow_dirty, dirty;
576
577 spin_lock_irqsave(&data_lock, flags);
578 dirty = op->info_dirty;
579 shadow_dirty = op->shadow_info_dirty;
580 spin_unlock_irqrestore(&data_lock, flags);
581
582 if (!dirty && !shadow_dirty) {
583 r = 0;
584 break;
585 }
586
587 /* 4 iterations is the worst case:
588 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
589 * 2 - first VSYNC, dirty = true
590 * 3 - dirty = false, shadow_dirty = true
591 * 4 - shadow_dirty = false */
592 if (i++ == 3) {
593 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
594 ovl->id);
595 r = 0;
596 break;
597 }
598
599 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
600 if (r == -ERESTARTSYS)
601 break;
602
603 if (r) {
604 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
605 break;
606 }
607 }
608
609 dispc_runtime_put();
610
611 return r;
612 }
613
dss_ovl_write_regs(struct omap_overlay * ovl)614 static void dss_ovl_write_regs(struct omap_overlay *ovl)
615 {
616 struct ovl_priv_data *op = get_ovl_priv(ovl);
617 struct omap_overlay_info *oi;
618 bool replication;
619 struct mgr_priv_data *mp;
620 int r;
621
622 DSSDBG("writing ovl %d regs", ovl->id);
623
624 if (!op->enabled || !op->info_dirty)
625 return;
626
627 oi = &op->info;
628
629 mp = get_mgr_priv(ovl->manager);
630
631 replication = dss_ovl_use_replication(mp->lcd_config, oi->color_mode);
632
633 r = dispc_ovl_setup(ovl->id, oi, replication, &mp->timings, false);
634 if (r) {
635 /*
636 * We can't do much here, as this function can be called from
637 * vsync interrupt.
638 */
639 DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id);
640
641 /* This will leave fifo configurations in a nonoptimal state */
642 op->enabled = false;
643 dispc_ovl_enable(ovl->id, false);
644 return;
645 }
646
647 op->info_dirty = false;
648 if (mp->updating)
649 op->shadow_info_dirty = true;
650 }
651
dss_ovl_write_regs_extra(struct omap_overlay * ovl)652 static void dss_ovl_write_regs_extra(struct omap_overlay *ovl)
653 {
654 struct ovl_priv_data *op = get_ovl_priv(ovl);
655 struct mgr_priv_data *mp;
656
657 DSSDBG("writing ovl %d regs extra", ovl->id);
658
659 if (!op->extra_info_dirty)
660 return;
661
662 /* note: write also when op->enabled == false, so that the ovl gets
663 * disabled */
664
665 dispc_ovl_enable(ovl->id, op->enabled);
666 dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high);
667
668 mp = get_mgr_priv(ovl->manager);
669
670 op->extra_info_dirty = false;
671 if (mp->updating)
672 op->shadow_extra_info_dirty = true;
673 }
674
dss_mgr_write_regs(struct omap_overlay_manager * mgr)675 static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
676 {
677 struct mgr_priv_data *mp = get_mgr_priv(mgr);
678 struct omap_overlay *ovl;
679
680 DSSDBG("writing mgr %d regs", mgr->id);
681
682 if (!mp->enabled)
683 return;
684
685 WARN_ON(mp->busy);
686
687 /* Commit overlay settings */
688 list_for_each_entry(ovl, &mgr->overlays, list) {
689 dss_ovl_write_regs(ovl);
690 dss_ovl_write_regs_extra(ovl);
691 }
692
693 if (mp->info_dirty) {
694 dispc_mgr_setup(mgr->id, &mp->info);
695
696 mp->info_dirty = false;
697 if (mp->updating)
698 mp->shadow_info_dirty = true;
699 }
700 }
701
dss_mgr_write_regs_extra(struct omap_overlay_manager * mgr)702 static void dss_mgr_write_regs_extra(struct omap_overlay_manager *mgr)
703 {
704 struct mgr_priv_data *mp = get_mgr_priv(mgr);
705
706 DSSDBG("writing mgr %d regs extra", mgr->id);
707
708 if (!mp->extra_info_dirty)
709 return;
710
711 dispc_mgr_set_timings(mgr->id, &mp->timings);
712
713 /* lcd_config parameters */
714 if (dss_mgr_is_lcd(mgr->id))
715 dispc_mgr_set_lcd_config(mgr->id, &mp->lcd_config);
716
717 mp->extra_info_dirty = false;
718 if (mp->updating)
719 mp->shadow_extra_info_dirty = true;
720 }
721
dss_write_regs(void)722 static void dss_write_regs(void)
723 {
724 const int num_mgrs = omap_dss_get_num_overlay_managers();
725 int i;
726
727 for (i = 0; i < num_mgrs; ++i) {
728 struct omap_overlay_manager *mgr;
729 struct mgr_priv_data *mp;
730 int r;
731
732 mgr = omap_dss_get_overlay_manager(i);
733 mp = get_mgr_priv(mgr);
734
735 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
736 continue;
737
738 r = dss_check_settings(mgr);
739 if (r) {
740 DSSERR("cannot write registers for manager %s: "
741 "illegal configuration\n", mgr->name);
742 continue;
743 }
744
745 dss_mgr_write_regs(mgr);
746 dss_mgr_write_regs_extra(mgr);
747 }
748 }
749
dss_set_go_bits(void)750 static void dss_set_go_bits(void)
751 {
752 const int num_mgrs = omap_dss_get_num_overlay_managers();
753 int i;
754
755 for (i = 0; i < num_mgrs; ++i) {
756 struct omap_overlay_manager *mgr;
757 struct mgr_priv_data *mp;
758
759 mgr = omap_dss_get_overlay_manager(i);
760 mp = get_mgr_priv(mgr);
761
762 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
763 continue;
764
765 if (!need_go(mgr))
766 continue;
767
768 mp->busy = true;
769
770 if (!dss_data.irq_enabled && need_isr())
771 dss_register_vsync_isr();
772
773 dispc_mgr_go(mgr->id);
774 }
775
776 }
777
mgr_clear_shadow_dirty(struct omap_overlay_manager * mgr)778 static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
779 {
780 struct omap_overlay *ovl;
781 struct mgr_priv_data *mp;
782 struct ovl_priv_data *op;
783
784 mp = get_mgr_priv(mgr);
785 mp->shadow_info_dirty = false;
786 mp->shadow_extra_info_dirty = false;
787
788 list_for_each_entry(ovl, &mgr->overlays, list) {
789 op = get_ovl_priv(ovl);
790 op->shadow_info_dirty = false;
791 op->shadow_extra_info_dirty = false;
792 }
793 }
794
dss_mgr_start_update_compat(struct omap_overlay_manager * mgr)795 static void dss_mgr_start_update_compat(struct omap_overlay_manager *mgr)
796 {
797 struct mgr_priv_data *mp = get_mgr_priv(mgr);
798 unsigned long flags;
799 int r;
800
801 spin_lock_irqsave(&data_lock, flags);
802
803 WARN_ON(mp->updating);
804
805 r = dss_check_settings(mgr);
806 if (r) {
807 DSSERR("cannot start manual update: illegal configuration\n");
808 spin_unlock_irqrestore(&data_lock, flags);
809 return;
810 }
811
812 dss_mgr_write_regs(mgr);
813 dss_mgr_write_regs_extra(mgr);
814
815 mp->updating = true;
816
817 if (!dss_data.irq_enabled && need_isr())
818 dss_register_vsync_isr();
819
820 dispc_mgr_enable_sync(mgr->id);
821
822 spin_unlock_irqrestore(&data_lock, flags);
823 }
824
825 static void dss_apply_irq_handler(void *data, u32 mask);
826
dss_register_vsync_isr(void)827 static void dss_register_vsync_isr(void)
828 {
829 const int num_mgrs = dss_feat_get_num_mgrs();
830 u32 mask;
831 int r, i;
832
833 mask = 0;
834 for (i = 0; i < num_mgrs; ++i)
835 mask |= dispc_mgr_get_vsync_irq(i);
836
837 for (i = 0; i < num_mgrs; ++i)
838 mask |= dispc_mgr_get_framedone_irq(i);
839
840 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
841 WARN_ON(r);
842
843 dss_data.irq_enabled = true;
844 }
845
dss_unregister_vsync_isr(void)846 static void dss_unregister_vsync_isr(void)
847 {
848 const int num_mgrs = dss_feat_get_num_mgrs();
849 u32 mask;
850 int r, i;
851
852 mask = 0;
853 for (i = 0; i < num_mgrs; ++i)
854 mask |= dispc_mgr_get_vsync_irq(i);
855
856 for (i = 0; i < num_mgrs; ++i)
857 mask |= dispc_mgr_get_framedone_irq(i);
858
859 r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask);
860 WARN_ON(r);
861
862 dss_data.irq_enabled = false;
863 }
864
dss_apply_irq_handler(void * data,u32 mask)865 static void dss_apply_irq_handler(void *data, u32 mask)
866 {
867 const int num_mgrs = dss_feat_get_num_mgrs();
868 int i;
869 bool extra_updating;
870
871 spin_lock(&data_lock);
872
873 /* clear busy, updating flags, shadow_dirty flags */
874 for (i = 0; i < num_mgrs; i++) {
875 struct omap_overlay_manager *mgr;
876 struct mgr_priv_data *mp;
877
878 mgr = omap_dss_get_overlay_manager(i);
879 mp = get_mgr_priv(mgr);
880
881 if (!mp->enabled)
882 continue;
883
884 mp->updating = dispc_mgr_is_enabled(i);
885
886 if (!mgr_manual_update(mgr)) {
887 bool was_busy = mp->busy;
888 mp->busy = dispc_mgr_go_busy(i);
889
890 if (was_busy && !mp->busy)
891 mgr_clear_shadow_dirty(mgr);
892 }
893 }
894
895 dss_write_regs();
896 dss_set_go_bits();
897
898 extra_updating = extra_info_update_ongoing();
899 if (!extra_updating)
900 complete_all(&extra_updated_completion);
901
902 /* call framedone handlers for manual update displays */
903 for (i = 0; i < num_mgrs; i++) {
904 struct omap_overlay_manager *mgr;
905 struct mgr_priv_data *mp;
906
907 mgr = omap_dss_get_overlay_manager(i);
908 mp = get_mgr_priv(mgr);
909
910 if (!mgr_manual_update(mgr) || !mp->framedone_handler)
911 continue;
912
913 if (mask & dispc_mgr_get_framedone_irq(i))
914 mp->framedone_handler(mp->framedone_handler_data);
915 }
916
917 if (!need_isr())
918 dss_unregister_vsync_isr();
919
920 spin_unlock(&data_lock);
921 }
922
omap_dss_mgr_apply_ovl(struct omap_overlay * ovl)923 static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
924 {
925 struct ovl_priv_data *op;
926
927 op = get_ovl_priv(ovl);
928
929 if (!op->user_info_dirty)
930 return;
931
932 op->user_info_dirty = false;
933 op->info_dirty = true;
934 op->info = op->user_info;
935 }
936
omap_dss_mgr_apply_mgr(struct omap_overlay_manager * mgr)937 static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
938 {
939 struct mgr_priv_data *mp;
940
941 mp = get_mgr_priv(mgr);
942
943 if (!mp->user_info_dirty)
944 return;
945
946 mp->user_info_dirty = false;
947 mp->info_dirty = true;
948 mp->info = mp->user_info;
949 }
950
omap_dss_mgr_apply(struct omap_overlay_manager * mgr)951 static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
952 {
953 unsigned long flags;
954 struct omap_overlay *ovl;
955 int r;
956
957 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
958
959 spin_lock_irqsave(&data_lock, flags);
960
961 r = dss_check_settings_apply(mgr);
962 if (r) {
963 spin_unlock_irqrestore(&data_lock, flags);
964 DSSERR("failed to apply settings: illegal configuration.\n");
965 return r;
966 }
967
968 /* Configure overlays */
969 list_for_each_entry(ovl, &mgr->overlays, list)
970 omap_dss_mgr_apply_ovl(ovl);
971
972 /* Configure manager */
973 omap_dss_mgr_apply_mgr(mgr);
974
975 dss_write_regs();
976 dss_set_go_bits();
977
978 spin_unlock_irqrestore(&data_lock, flags);
979
980 return 0;
981 }
982
dss_apply_ovl_enable(struct omap_overlay * ovl,bool enable)983 static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
984 {
985 struct ovl_priv_data *op;
986
987 op = get_ovl_priv(ovl);
988
989 if (op->enabled == enable)
990 return;
991
992 op->enabled = enable;
993 op->extra_info_dirty = true;
994 }
995
dss_apply_ovl_fifo_thresholds(struct omap_overlay * ovl,u32 fifo_low,u32 fifo_high)996 static void dss_apply_ovl_fifo_thresholds(struct omap_overlay *ovl,
997 u32 fifo_low, u32 fifo_high)
998 {
999 struct ovl_priv_data *op = get_ovl_priv(ovl);
1000
1001 if (op->fifo_low == fifo_low && op->fifo_high == fifo_high)
1002 return;
1003
1004 op->fifo_low = fifo_low;
1005 op->fifo_high = fifo_high;
1006 op->extra_info_dirty = true;
1007 }
1008
dss_ovl_setup_fifo(struct omap_overlay * ovl)1009 static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
1010 {
1011 struct ovl_priv_data *op = get_ovl_priv(ovl);
1012 u32 fifo_low, fifo_high;
1013 bool use_fifo_merge = false;
1014
1015 if (!op->enabled && !op->enabling)
1016 return;
1017
1018 dispc_ovl_compute_fifo_thresholds(ovl->id, &fifo_low, &fifo_high,
1019 use_fifo_merge, ovl_manual_update(ovl));
1020
1021 dss_apply_ovl_fifo_thresholds(ovl, fifo_low, fifo_high);
1022 }
1023
dss_mgr_setup_fifos(struct omap_overlay_manager * mgr)1024 static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
1025 {
1026 struct omap_overlay *ovl;
1027 struct mgr_priv_data *mp;
1028
1029 mp = get_mgr_priv(mgr);
1030
1031 if (!mp->enabled)
1032 return;
1033
1034 list_for_each_entry(ovl, &mgr->overlays, list)
1035 dss_ovl_setup_fifo(ovl);
1036 }
1037
dss_setup_fifos(void)1038 static void dss_setup_fifos(void)
1039 {
1040 const int num_mgrs = omap_dss_get_num_overlay_managers();
1041 struct omap_overlay_manager *mgr;
1042 int i;
1043
1044 for (i = 0; i < num_mgrs; ++i) {
1045 mgr = omap_dss_get_overlay_manager(i);
1046 dss_mgr_setup_fifos(mgr);
1047 }
1048 }
1049
dss_mgr_enable_compat(struct omap_overlay_manager * mgr)1050 static int dss_mgr_enable_compat(struct omap_overlay_manager *mgr)
1051 {
1052 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1053 unsigned long flags;
1054 int r;
1055
1056 mutex_lock(&apply_lock);
1057
1058 if (mp->enabled)
1059 goto out;
1060
1061 spin_lock_irqsave(&data_lock, flags);
1062
1063 mp->enabled = true;
1064
1065 r = dss_check_settings(mgr);
1066 if (r) {
1067 DSSERR("failed to enable manager %d: check_settings failed\n",
1068 mgr->id);
1069 goto err;
1070 }
1071
1072 dss_setup_fifos();
1073
1074 dss_write_regs();
1075 dss_set_go_bits();
1076
1077 if (!mgr_manual_update(mgr))
1078 mp->updating = true;
1079
1080 if (!dss_data.irq_enabled && need_isr())
1081 dss_register_vsync_isr();
1082
1083 spin_unlock_irqrestore(&data_lock, flags);
1084
1085 if (!mgr_manual_update(mgr))
1086 dispc_mgr_enable_sync(mgr->id);
1087
1088 out:
1089 mutex_unlock(&apply_lock);
1090
1091 return 0;
1092
1093 err:
1094 mp->enabled = false;
1095 spin_unlock_irqrestore(&data_lock, flags);
1096 mutex_unlock(&apply_lock);
1097 return r;
1098 }
1099
dss_mgr_disable_compat(struct omap_overlay_manager * mgr)1100 static void dss_mgr_disable_compat(struct omap_overlay_manager *mgr)
1101 {
1102 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1103 unsigned long flags;
1104
1105 mutex_lock(&apply_lock);
1106
1107 if (!mp->enabled)
1108 goto out;
1109
1110 if (!mgr_manual_update(mgr))
1111 dispc_mgr_disable_sync(mgr->id);
1112
1113 spin_lock_irqsave(&data_lock, flags);
1114
1115 mp->updating = false;
1116 mp->enabled = false;
1117
1118 spin_unlock_irqrestore(&data_lock, flags);
1119
1120 out:
1121 mutex_unlock(&apply_lock);
1122 }
1123
dss_mgr_set_info(struct omap_overlay_manager * mgr,struct omap_overlay_manager_info * info)1124 static int dss_mgr_set_info(struct omap_overlay_manager *mgr,
1125 struct omap_overlay_manager_info *info)
1126 {
1127 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1128 unsigned long flags;
1129 int r;
1130
1131 r = dss_mgr_simple_check(mgr, info);
1132 if (r)
1133 return r;
1134
1135 spin_lock_irqsave(&data_lock, flags);
1136
1137 mp->user_info = *info;
1138 mp->user_info_dirty = true;
1139
1140 spin_unlock_irqrestore(&data_lock, flags);
1141
1142 return 0;
1143 }
1144
dss_mgr_get_info(struct omap_overlay_manager * mgr,struct omap_overlay_manager_info * info)1145 static void dss_mgr_get_info(struct omap_overlay_manager *mgr,
1146 struct omap_overlay_manager_info *info)
1147 {
1148 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1149 unsigned long flags;
1150
1151 spin_lock_irqsave(&data_lock, flags);
1152
1153 *info = mp->user_info;
1154
1155 spin_unlock_irqrestore(&data_lock, flags);
1156 }
1157
dss_mgr_set_output(struct omap_overlay_manager * mgr,struct omap_dss_output * output)1158 static int dss_mgr_set_output(struct omap_overlay_manager *mgr,
1159 struct omap_dss_output *output)
1160 {
1161 int r;
1162
1163 mutex_lock(&apply_lock);
1164
1165 if (mgr->output) {
1166 DSSERR("manager %s is already connected to an output\n",
1167 mgr->name);
1168 r = -EINVAL;
1169 goto err;
1170 }
1171
1172 if ((mgr->supported_outputs & output->id) == 0) {
1173 DSSERR("output does not support manager %s\n",
1174 mgr->name);
1175 r = -EINVAL;
1176 goto err;
1177 }
1178
1179 output->manager = mgr;
1180 mgr->output = output;
1181
1182 mutex_unlock(&apply_lock);
1183
1184 return 0;
1185 err:
1186 mutex_unlock(&apply_lock);
1187 return r;
1188 }
1189
dss_mgr_unset_output(struct omap_overlay_manager * mgr)1190 static int dss_mgr_unset_output(struct omap_overlay_manager *mgr)
1191 {
1192 int r;
1193 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1194 unsigned long flags;
1195
1196 mutex_lock(&apply_lock);
1197
1198 if (!mgr->output) {
1199 DSSERR("failed to unset output, output not set\n");
1200 r = -EINVAL;
1201 goto err;
1202 }
1203
1204 spin_lock_irqsave(&data_lock, flags);
1205
1206 if (mp->enabled) {
1207 DSSERR("output can't be unset when manager is enabled\n");
1208 r = -EINVAL;
1209 goto err1;
1210 }
1211
1212 spin_unlock_irqrestore(&data_lock, flags);
1213
1214 mgr->output->manager = NULL;
1215 mgr->output = NULL;
1216
1217 mutex_unlock(&apply_lock);
1218
1219 return 0;
1220 err1:
1221 spin_unlock_irqrestore(&data_lock, flags);
1222 err:
1223 mutex_unlock(&apply_lock);
1224
1225 return r;
1226 }
1227
dss_apply_mgr_timings(struct omap_overlay_manager * mgr,const struct omap_video_timings * timings)1228 static void dss_apply_mgr_timings(struct omap_overlay_manager *mgr,
1229 const struct omap_video_timings *timings)
1230 {
1231 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1232
1233 mp->timings = *timings;
1234 mp->extra_info_dirty = true;
1235 }
1236
dss_mgr_set_timings_compat(struct omap_overlay_manager * mgr,const struct omap_video_timings * timings)1237 static void dss_mgr_set_timings_compat(struct omap_overlay_manager *mgr,
1238 const struct omap_video_timings *timings)
1239 {
1240 unsigned long flags;
1241 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1242
1243 spin_lock_irqsave(&data_lock, flags);
1244
1245 if (mp->updating) {
1246 DSSERR("cannot set timings for %s: manager needs to be disabled\n",
1247 mgr->name);
1248 goto out;
1249 }
1250
1251 dss_apply_mgr_timings(mgr, timings);
1252 out:
1253 spin_unlock_irqrestore(&data_lock, flags);
1254 }
1255
dss_apply_mgr_lcd_config(struct omap_overlay_manager * mgr,const struct dss_lcd_mgr_config * config)1256 static void dss_apply_mgr_lcd_config(struct omap_overlay_manager *mgr,
1257 const struct dss_lcd_mgr_config *config)
1258 {
1259 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1260
1261 mp->lcd_config = *config;
1262 mp->extra_info_dirty = true;
1263 }
1264
dss_mgr_set_lcd_config_compat(struct omap_overlay_manager * mgr,const struct dss_lcd_mgr_config * config)1265 static void dss_mgr_set_lcd_config_compat(struct omap_overlay_manager *mgr,
1266 const struct dss_lcd_mgr_config *config)
1267 {
1268 unsigned long flags;
1269 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1270
1271 spin_lock_irqsave(&data_lock, flags);
1272
1273 if (mp->enabled) {
1274 DSSERR("cannot apply lcd config for %s: manager needs to be disabled\n",
1275 mgr->name);
1276 goto out;
1277 }
1278
1279 dss_apply_mgr_lcd_config(mgr, config);
1280 out:
1281 spin_unlock_irqrestore(&data_lock, flags);
1282 }
1283
dss_ovl_set_info(struct omap_overlay * ovl,struct omap_overlay_info * info)1284 static int dss_ovl_set_info(struct omap_overlay *ovl,
1285 struct omap_overlay_info *info)
1286 {
1287 struct ovl_priv_data *op = get_ovl_priv(ovl);
1288 unsigned long flags;
1289 int r;
1290
1291 r = dss_ovl_simple_check(ovl, info);
1292 if (r)
1293 return r;
1294
1295 spin_lock_irqsave(&data_lock, flags);
1296
1297 op->user_info = *info;
1298 op->user_info_dirty = true;
1299
1300 spin_unlock_irqrestore(&data_lock, flags);
1301
1302 return 0;
1303 }
1304
dss_ovl_get_info(struct omap_overlay * ovl,struct omap_overlay_info * info)1305 static void dss_ovl_get_info(struct omap_overlay *ovl,
1306 struct omap_overlay_info *info)
1307 {
1308 struct ovl_priv_data *op = get_ovl_priv(ovl);
1309 unsigned long flags;
1310
1311 spin_lock_irqsave(&data_lock, flags);
1312
1313 *info = op->user_info;
1314
1315 spin_unlock_irqrestore(&data_lock, flags);
1316 }
1317
dss_ovl_set_manager(struct omap_overlay * ovl,struct omap_overlay_manager * mgr)1318 static int dss_ovl_set_manager(struct omap_overlay *ovl,
1319 struct omap_overlay_manager *mgr)
1320 {
1321 struct ovl_priv_data *op = get_ovl_priv(ovl);
1322 unsigned long flags;
1323 int r;
1324
1325 if (!mgr)
1326 return -EINVAL;
1327
1328 mutex_lock(&apply_lock);
1329
1330 if (ovl->manager) {
1331 DSSERR("overlay '%s' already has a manager '%s'\n",
1332 ovl->name, ovl->manager->name);
1333 r = -EINVAL;
1334 goto err;
1335 }
1336
1337 r = dispc_runtime_get();
1338 if (r)
1339 goto err;
1340
1341 spin_lock_irqsave(&data_lock, flags);
1342
1343 if (op->enabled) {
1344 spin_unlock_irqrestore(&data_lock, flags);
1345 DSSERR("overlay has to be disabled to change the manager\n");
1346 r = -EINVAL;
1347 goto err1;
1348 }
1349
1350 dispc_ovl_set_channel_out(ovl->id, mgr->id);
1351
1352 ovl->manager = mgr;
1353 list_add_tail(&ovl->list, &mgr->overlays);
1354
1355 spin_unlock_irqrestore(&data_lock, flags);
1356
1357 dispc_runtime_put();
1358
1359 mutex_unlock(&apply_lock);
1360
1361 return 0;
1362
1363 err1:
1364 dispc_runtime_put();
1365 err:
1366 mutex_unlock(&apply_lock);
1367 return r;
1368 }
1369
dss_ovl_unset_manager(struct omap_overlay * ovl)1370 static int dss_ovl_unset_manager(struct omap_overlay *ovl)
1371 {
1372 struct ovl_priv_data *op = get_ovl_priv(ovl);
1373 unsigned long flags;
1374 int r;
1375
1376 mutex_lock(&apply_lock);
1377
1378 if (!ovl->manager) {
1379 DSSERR("failed to detach overlay: manager not set\n");
1380 r = -EINVAL;
1381 goto err;
1382 }
1383
1384 spin_lock_irqsave(&data_lock, flags);
1385
1386 if (op->enabled) {
1387 spin_unlock_irqrestore(&data_lock, flags);
1388 DSSERR("overlay has to be disabled to unset the manager\n");
1389 r = -EINVAL;
1390 goto err;
1391 }
1392
1393 spin_unlock_irqrestore(&data_lock, flags);
1394
1395 /* wait for pending extra_info updates to ensure the ovl is disabled */
1396 wait_pending_extra_info_updates();
1397
1398 /*
1399 * For a manual update display, there is no guarantee that the overlay
1400 * is really disabled in HW, we may need an extra update from this
1401 * manager before the configurations can go in. Return an error if the
1402 * overlay needed an update from the manager.
1403 *
1404 * TODO: Instead of returning an error, try to do a dummy manager update
1405 * here to disable the overlay in hardware. Use the *GATED fields in
1406 * the DISPC_CONFIG registers to do a dummy update.
1407 */
1408 spin_lock_irqsave(&data_lock, flags);
1409
1410 if (ovl_manual_update(ovl) && op->extra_info_dirty) {
1411 spin_unlock_irqrestore(&data_lock, flags);
1412 DSSERR("need an update to change the manager\n");
1413 r = -EINVAL;
1414 goto err;
1415 }
1416
1417 ovl->manager = NULL;
1418 list_del(&ovl->list);
1419
1420 spin_unlock_irqrestore(&data_lock, flags);
1421
1422 mutex_unlock(&apply_lock);
1423
1424 return 0;
1425 err:
1426 mutex_unlock(&apply_lock);
1427 return r;
1428 }
1429
dss_ovl_is_enabled(struct omap_overlay * ovl)1430 static bool dss_ovl_is_enabled(struct omap_overlay *ovl)
1431 {
1432 struct ovl_priv_data *op = get_ovl_priv(ovl);
1433 unsigned long flags;
1434 bool e;
1435
1436 spin_lock_irqsave(&data_lock, flags);
1437
1438 e = op->enabled;
1439
1440 spin_unlock_irqrestore(&data_lock, flags);
1441
1442 return e;
1443 }
1444
dss_ovl_enable(struct omap_overlay * ovl)1445 static int dss_ovl_enable(struct omap_overlay *ovl)
1446 {
1447 struct ovl_priv_data *op = get_ovl_priv(ovl);
1448 unsigned long flags;
1449 int r;
1450
1451 mutex_lock(&apply_lock);
1452
1453 if (op->enabled) {
1454 r = 0;
1455 goto err1;
1456 }
1457
1458 if (ovl->manager == NULL || ovl->manager->output == NULL) {
1459 r = -EINVAL;
1460 goto err1;
1461 }
1462
1463 spin_lock_irqsave(&data_lock, flags);
1464
1465 op->enabling = true;
1466
1467 r = dss_check_settings(ovl->manager);
1468 if (r) {
1469 DSSERR("failed to enable overlay %d: check_settings failed\n",
1470 ovl->id);
1471 goto err2;
1472 }
1473
1474 dss_setup_fifos();
1475
1476 op->enabling = false;
1477 dss_apply_ovl_enable(ovl, true);
1478
1479 dss_write_regs();
1480 dss_set_go_bits();
1481
1482 spin_unlock_irqrestore(&data_lock, flags);
1483
1484 mutex_unlock(&apply_lock);
1485
1486 return 0;
1487 err2:
1488 op->enabling = false;
1489 spin_unlock_irqrestore(&data_lock, flags);
1490 err1:
1491 mutex_unlock(&apply_lock);
1492 return r;
1493 }
1494
dss_ovl_disable(struct omap_overlay * ovl)1495 static int dss_ovl_disable(struct omap_overlay *ovl)
1496 {
1497 struct ovl_priv_data *op = get_ovl_priv(ovl);
1498 unsigned long flags;
1499 int r;
1500
1501 mutex_lock(&apply_lock);
1502
1503 if (!op->enabled) {
1504 r = 0;
1505 goto err;
1506 }
1507
1508 if (ovl->manager == NULL || ovl->manager->output == NULL) {
1509 r = -EINVAL;
1510 goto err;
1511 }
1512
1513 spin_lock_irqsave(&data_lock, flags);
1514
1515 dss_apply_ovl_enable(ovl, false);
1516 dss_write_regs();
1517 dss_set_go_bits();
1518
1519 spin_unlock_irqrestore(&data_lock, flags);
1520
1521 mutex_unlock(&apply_lock);
1522
1523 return 0;
1524
1525 err:
1526 mutex_unlock(&apply_lock);
1527 return r;
1528 }
1529
dss_mgr_register_framedone_handler_compat(struct omap_overlay_manager * mgr,void (* handler)(void *),void * data)1530 static int dss_mgr_register_framedone_handler_compat(struct omap_overlay_manager *mgr,
1531 void (*handler)(void *), void *data)
1532 {
1533 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1534
1535 if (mp->framedone_handler)
1536 return -EBUSY;
1537
1538 mp->framedone_handler = handler;
1539 mp->framedone_handler_data = data;
1540
1541 return 0;
1542 }
1543
dss_mgr_unregister_framedone_handler_compat(struct omap_overlay_manager * mgr,void (* handler)(void *),void * data)1544 static void dss_mgr_unregister_framedone_handler_compat(struct omap_overlay_manager *mgr,
1545 void (*handler)(void *), void *data)
1546 {
1547 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1548
1549 WARN_ON(mp->framedone_handler != handler ||
1550 mp->framedone_handler_data != data);
1551
1552 mp->framedone_handler = NULL;
1553 mp->framedone_handler_data = NULL;
1554 }
1555
1556 static const struct dss_mgr_ops apply_mgr_ops = {
1557 .start_update = dss_mgr_start_update_compat,
1558 .enable = dss_mgr_enable_compat,
1559 .disable = dss_mgr_disable_compat,
1560 .set_timings = dss_mgr_set_timings_compat,
1561 .set_lcd_config = dss_mgr_set_lcd_config_compat,
1562 .register_framedone_handler = dss_mgr_register_framedone_handler_compat,
1563 .unregister_framedone_handler = dss_mgr_unregister_framedone_handler_compat,
1564 };
1565
1566 static int compat_refcnt;
1567 static DEFINE_MUTEX(compat_init_lock);
1568
omapdss_compat_init(void)1569 int omapdss_compat_init(void)
1570 {
1571 struct platform_device *pdev = dss_get_core_pdev();
1572 struct omap_dss_device *dssdev = NULL;
1573 int i, r;
1574
1575 mutex_lock(&compat_init_lock);
1576
1577 if (compat_refcnt++ > 0)
1578 goto out;
1579
1580 apply_init_priv();
1581
1582 dss_init_overlay_managers(pdev);
1583 dss_init_overlays(pdev);
1584
1585 for (i = 0; i < omap_dss_get_num_overlay_managers(); i++) {
1586 struct omap_overlay_manager *mgr;
1587
1588 mgr = omap_dss_get_overlay_manager(i);
1589
1590 mgr->set_output = &dss_mgr_set_output;
1591 mgr->unset_output = &dss_mgr_unset_output;
1592 mgr->apply = &omap_dss_mgr_apply;
1593 mgr->set_manager_info = &dss_mgr_set_info;
1594 mgr->get_manager_info = &dss_mgr_get_info;
1595 mgr->wait_for_go = &dss_mgr_wait_for_go;
1596 mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
1597 mgr->get_device = &dss_mgr_get_device;
1598 }
1599
1600 for (i = 0; i < omap_dss_get_num_overlays(); i++) {
1601 struct omap_overlay *ovl = omap_dss_get_overlay(i);
1602
1603 ovl->is_enabled = &dss_ovl_is_enabled;
1604 ovl->enable = &dss_ovl_enable;
1605 ovl->disable = &dss_ovl_disable;
1606 ovl->set_manager = &dss_ovl_set_manager;
1607 ovl->unset_manager = &dss_ovl_unset_manager;
1608 ovl->set_overlay_info = &dss_ovl_set_info;
1609 ovl->get_overlay_info = &dss_ovl_get_info;
1610 ovl->wait_for_go = &dss_mgr_wait_for_go_ovl;
1611 ovl->get_device = &dss_ovl_get_device;
1612 }
1613
1614 r = dss_install_mgr_ops(&apply_mgr_ops);
1615 if (r)
1616 goto err_mgr_ops;
1617
1618 for_each_dss_dev(dssdev) {
1619 r = display_init_sysfs(pdev, dssdev);
1620 /* XXX uninit sysfs files on error */
1621 if (r)
1622 goto err_disp_sysfs;
1623 }
1624
1625 dispc_runtime_get();
1626
1627 r = dss_dispc_initialize_irq();
1628 if (r)
1629 goto err_init_irq;
1630
1631 dispc_runtime_put();
1632
1633 out:
1634 mutex_unlock(&compat_init_lock);
1635
1636 return 0;
1637
1638 err_init_irq:
1639 dispc_runtime_put();
1640
1641 err_disp_sysfs:
1642 dss_uninstall_mgr_ops();
1643
1644 err_mgr_ops:
1645 dss_uninit_overlay_managers(pdev);
1646 dss_uninit_overlays(pdev);
1647
1648 compat_refcnt--;
1649
1650 mutex_unlock(&compat_init_lock);
1651
1652 return r;
1653 }
1654 EXPORT_SYMBOL(omapdss_compat_init);
1655
omapdss_compat_uninit(void)1656 void omapdss_compat_uninit(void)
1657 {
1658 struct platform_device *pdev = dss_get_core_pdev();
1659 struct omap_dss_device *dssdev = NULL;
1660
1661 mutex_lock(&compat_init_lock);
1662
1663 if (--compat_refcnt > 0)
1664 goto out;
1665
1666 dss_dispc_uninitialize_irq();
1667
1668 for_each_dss_dev(dssdev)
1669 display_uninit_sysfs(pdev, dssdev);
1670
1671 dss_uninstall_mgr_ops();
1672
1673 dss_uninit_overlay_managers(pdev);
1674 dss_uninit_overlays(pdev);
1675 out:
1676 mutex_unlock(&compat_init_lock);
1677 }
1678 EXPORT_SYMBOL(omapdss_compat_uninit);
1679