mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / video / omap2 / dss / apply.c
blob60758dbefd79fda6d64df8246479b4dd1407f6cd
1 /*
2 * Copyright (C) 2011 Texas Instruments
3 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
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.
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.
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/>.
18 #define DSS_SUBSYS_NAME "APPLY"
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>
26 #include <video/omapdss.h>
28 #include "dss.h"
29 #include "dss_features.h"
30 #include "dispc-compat.h"
33 * We have 4 levels of cache for the dispc settings. First two are in SW and
34 * the latter two in HW.
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 * +--------------------+
61 struct ovl_priv_data {
63 bool user_info_dirty;
64 struct omap_overlay_info user_info;
66 bool info_dirty;
67 struct omap_overlay_info info;
69 bool shadow_info_dirty;
71 bool extra_info_dirty;
72 bool shadow_extra_info_dirty;
74 bool enabled;
75 u32 fifo_low, fifo_high;
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.
81 bool enabling;
84 struct mgr_priv_data {
86 bool user_info_dirty;
87 struct omap_overlay_manager_info user_info;
89 bool info_dirty;
90 struct omap_overlay_manager_info info;
92 bool shadow_info_dirty;
94 /* If true, GO bit is up and shadow registers cannot be written.
95 * Never true for manual update displays */
96 bool busy;
98 /* If true, dispc output is enabled */
99 bool updating;
101 /* If true, a display is enabled using this manager */
102 bool enabled;
104 bool extra_info_dirty;
105 bool shadow_extra_info_dirty;
107 struct omap_video_timings timings;
108 struct dss_lcd_mgr_config lcd_config;
110 void (*framedone_handler)(void *);
111 void *framedone_handler_data;
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];
118 bool irq_enabled;
119 } dss_data;
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);
127 static void dss_register_vsync_isr(void);
129 static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl)
131 return &dss_data.ovl_priv_data_array[ovl->id];
134 static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr)
136 return &dss_data.mgr_priv_data_array[mgr->id];
139 static void apply_init_priv(void)
141 const int num_ovls = dss_feat_get_num_ovls();
142 struct mgr_priv_data *mp;
143 int i;
145 spin_lock_init(&data_lock);
147 for (i = 0; i < num_ovls; ++i) {
148 struct ovl_priv_data *op;
150 op = &dss_data.ovl_priv_data_array[i];
152 op->info.global_alpha = 255;
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;
172 op->user_info = op->info;
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
179 mp = &dss_data.mgr_priv_data_array[OMAP_DSS_CHANNEL_DIGIT];
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;
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
191 static bool ovl_manual_update(struct omap_overlay *ovl)
193 struct mgr_priv_data *mp = get_mgr_priv(ovl->manager);
195 return mp->lcd_config.stallmode;
198 static bool mgr_manual_update(struct omap_overlay_manager *mgr)
200 struct mgr_priv_data *mp = get_mgr_priv(mgr);
202 return mp->lcd_config.stallmode;
205 static int dss_check_settings_low(struct omap_overlay_manager *mgr,
206 bool applying)
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;
215 mp = get_mgr_priv(mgr);
217 if (!mp->enabled)
218 return 0;
220 if (applying && mp->user_info_dirty)
221 mi = &mp->user_info;
222 else
223 mi = &mp->info;
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);
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;
236 ois[ovl->id] = oi;
239 return dss_mgr_check(mgr, mi, &mp->timings, &mp->lcd_config, ois);
243 * check manager and overlay settings using overlay_info from data->info
245 static int dss_check_settings(struct omap_overlay_manager *mgr)
247 return dss_check_settings_low(mgr, false);
251 * check manager and overlay settings using overlay_info from ovl->info if
252 * dirty and from data->info otherwise
254 static int dss_check_settings_apply(struct omap_overlay_manager *mgr)
256 return dss_check_settings_low(mgr, true);
259 static bool need_isr(void)
261 const int num_mgrs = dss_feat_get_num_mgrs();
262 int i;
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;
269 mgr = omap_dss_get_overlay_manager(i);
270 mp = get_mgr_priv(mgr);
272 if (!mp->enabled)
273 continue;
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;
284 /* to write new values to registers */
285 if (mp->info_dirty)
286 return true;
288 /* to set GO bit */
289 if (mp->shadow_info_dirty)
290 return true;
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.
298 /* to write new values to registers */
299 if (mp->extra_info_dirty)
300 return true;
302 /* to set GO bit */
303 if (mp->shadow_extra_info_dirty)
304 return true;
306 list_for_each_entry(ovl, &mgr->overlays, list) {
307 struct ovl_priv_data *op;
309 op = get_ovl_priv(ovl);
312 * NOTE: we check extra_info flags even for
313 * disabled overlays, as extra_infos need to be
314 * always written.
317 /* to write new values to registers */
318 if (op->extra_info_dirty)
319 return true;
321 /* to set GO bit */
322 if (op->shadow_extra_info_dirty)
323 return true;
325 if (!op->enabled)
326 continue;
328 /* to write new values to registers */
329 if (op->info_dirty)
330 return true;
332 /* to set GO bit */
333 if (op->shadow_info_dirty)
334 return true;
339 return false;
342 static bool need_go(struct omap_overlay_manager *mgr)
344 struct omap_overlay *ovl;
345 struct mgr_priv_data *mp;
346 struct ovl_priv_data *op;
348 mp = get_mgr_priv(mgr);
350 if (mp->shadow_info_dirty || mp->shadow_extra_info_dirty)
351 return true;
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;
359 return false;
362 /* returns true if an extra_info field is currently being updated */
363 static bool extra_info_update_ongoing(void)
365 const int num_mgrs = dss_feat_get_num_mgrs();
366 int i;
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;
373 mgr = omap_dss_get_overlay_manager(i);
374 mp = get_mgr_priv(mgr);
376 if (!mp->enabled)
377 continue;
379 if (!mp->updating)
380 continue;
382 if (mp->extra_info_dirty || mp->shadow_extra_info_dirty)
383 return true;
385 list_for_each_entry(ovl, &mgr->overlays, list) {
386 struct ovl_priv_data *op = get_ovl_priv(ovl);
388 if (op->extra_info_dirty || op->shadow_extra_info_dirty)
389 return true;
393 return false;
396 /* wait until no extra_info updates are pending */
397 static void wait_pending_extra_info_updates(void)
399 bool updating;
400 unsigned long flags;
401 unsigned long t;
402 int r;
404 spin_lock_irqsave(&data_lock, flags);
406 updating = extra_info_update_ongoing();
408 if (!updating) {
409 spin_unlock_irqrestore(&data_lock, flags);
410 return;
413 init_completion(&extra_updated_completion);
415 spin_unlock_irqrestore(&data_lock, flags);
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");
423 static struct omap_dss_device *dss_mgr_get_device(struct omap_overlay_manager *mgr)
425 struct omap_dss_device *dssdev;
427 dssdev = mgr->output;
428 if (dssdev == NULL)
429 return NULL;
431 while (dssdev->dst)
432 dssdev = dssdev->dst;
434 if (dssdev->driver)
435 return dssdev;
436 else
437 return NULL;
440 static struct omap_dss_device *dss_ovl_get_device(struct omap_overlay *ovl)
442 return ovl->manager ? dss_mgr_get_device(ovl->manager) : NULL;
445 static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
447 unsigned long timeout = msecs_to_jiffies(500);
448 u32 irq;
449 int r;
451 if (mgr->output == NULL)
452 return -ENODEV;
454 r = dispc_runtime_get();
455 if (r)
456 return r;
458 switch (mgr->output->id) {
459 case OMAP_DSS_OUTPUT_VENC:
460 irq = DISPC_IRQ_EVSYNC_ODD;
461 break;
462 case OMAP_DSS_OUTPUT_HDMI:
463 irq = DISPC_IRQ_EVSYNC_EVEN;
464 break;
465 default:
466 irq = dispc_mgr_get_vsync_irq(mgr->id);
467 break;
470 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
472 dispc_runtime_put();
474 return r;
477 static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
479 unsigned long timeout = msecs_to_jiffies(500);
480 struct mgr_priv_data *mp = get_mgr_priv(mgr);
481 u32 irq;
482 unsigned long flags;
483 int r;
484 int i;
486 spin_lock_irqsave(&data_lock, flags);
488 if (mgr_manual_update(mgr)) {
489 spin_unlock_irqrestore(&data_lock, flags);
490 return 0;
493 if (!mp->enabled) {
494 spin_unlock_irqrestore(&data_lock, flags);
495 return 0;
498 spin_unlock_irqrestore(&data_lock, flags);
500 r = dispc_runtime_get();
501 if (r)
502 return r;
504 irq = dispc_mgr_get_vsync_irq(mgr->id);
506 i = 0;
507 while (1) {
508 bool shadow_dirty, dirty;
510 spin_lock_irqsave(&data_lock, flags);
511 dirty = mp->info_dirty;
512 shadow_dirty = mp->shadow_info_dirty;
513 spin_unlock_irqrestore(&data_lock, flags);
515 if (!dirty && !shadow_dirty) {
516 r = 0;
517 break;
520 /* 4 iterations is the worst case:
521 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
522 * 2 - first VSYNC, dirty = true
523 * 3 - dirty = false, shadow_dirty = true
524 * 4 - shadow_dirty = false */
525 if (i++ == 3) {
526 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
527 mgr->id);
528 r = 0;
529 break;
532 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
533 if (r == -ERESTARTSYS)
534 break;
536 if (r) {
537 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
538 break;
542 dispc_runtime_put();
544 return r;
547 static int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
549 unsigned long timeout = msecs_to_jiffies(500);
550 struct ovl_priv_data *op;
551 struct mgr_priv_data *mp;
552 u32 irq;
553 unsigned long flags;
554 int r;
555 int i;
557 if (!ovl->manager)
558 return 0;
560 mp = get_mgr_priv(ovl->manager);
562 spin_lock_irqsave(&data_lock, flags);
564 if (ovl_manual_update(ovl)) {
565 spin_unlock_irqrestore(&data_lock, flags);
566 return 0;
569 if (!mp->enabled) {
570 spin_unlock_irqrestore(&data_lock, flags);
571 return 0;
574 spin_unlock_irqrestore(&data_lock, flags);
576 r = dispc_runtime_get();
577 if (r)
578 return r;
580 irq = dispc_mgr_get_vsync_irq(ovl->manager->id);
582 op = get_ovl_priv(ovl);
583 i = 0;
584 while (1) {
585 bool shadow_dirty, dirty;
587 spin_lock_irqsave(&data_lock, flags);
588 dirty = op->info_dirty;
589 shadow_dirty = op->shadow_info_dirty;
590 spin_unlock_irqrestore(&data_lock, flags);
592 if (!dirty && !shadow_dirty) {
593 r = 0;
594 break;
597 /* 4 iterations is the worst case:
598 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
599 * 2 - first VSYNC, dirty = true
600 * 3 - dirty = false, shadow_dirty = true
601 * 4 - shadow_dirty = false */
602 if (i++ == 3) {
603 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
604 ovl->id);
605 r = 0;
606 break;
609 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
610 if (r == -ERESTARTSYS)
611 break;
613 if (r) {
614 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
615 break;
619 dispc_runtime_put();
621 return r;
624 static void dss_ovl_write_regs(struct omap_overlay *ovl)
626 struct ovl_priv_data *op = get_ovl_priv(ovl);
627 struct omap_overlay_info *oi;
628 bool replication;
629 struct mgr_priv_data *mp;
630 int r;
632 DSSDBG("writing ovl %d regs", ovl->id);
634 if (!op->enabled || !op->info_dirty)
635 return;
637 oi = &op->info;
639 mp = get_mgr_priv(ovl->manager);
641 replication = dss_ovl_use_replication(mp->lcd_config, oi->color_mode);
643 r = dispc_ovl_setup(ovl->id, oi, replication, &mp->timings, false);
644 if (r) {
646 * We can't do much here, as this function can be called from
647 * vsync interrupt.
649 DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id);
651 /* This will leave fifo configurations in a nonoptimal state */
652 op->enabled = false;
653 dispc_ovl_enable(ovl->id, false);
654 return;
657 op->info_dirty = false;
658 if (mp->updating)
659 op->shadow_info_dirty = true;
662 static void dss_ovl_write_regs_extra(struct omap_overlay *ovl)
664 struct ovl_priv_data *op = get_ovl_priv(ovl);
665 struct mgr_priv_data *mp;
667 DSSDBG("writing ovl %d regs extra", ovl->id);
669 if (!op->extra_info_dirty)
670 return;
672 /* note: write also when op->enabled == false, so that the ovl gets
673 * disabled */
675 dispc_ovl_enable(ovl->id, op->enabled);
676 dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high);
678 mp = get_mgr_priv(ovl->manager);
680 op->extra_info_dirty = false;
681 if (mp->updating)
682 op->shadow_extra_info_dirty = true;
685 static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
687 struct mgr_priv_data *mp = get_mgr_priv(mgr);
688 struct omap_overlay *ovl;
690 DSSDBG("writing mgr %d regs", mgr->id);
692 if (!mp->enabled)
693 return;
695 WARN_ON(mp->busy);
697 /* Commit overlay settings */
698 list_for_each_entry(ovl, &mgr->overlays, list) {
699 dss_ovl_write_regs(ovl);
700 dss_ovl_write_regs_extra(ovl);
703 if (mp->info_dirty) {
704 dispc_mgr_setup(mgr->id, &mp->info);
706 mp->info_dirty = false;
707 if (mp->updating)
708 mp->shadow_info_dirty = true;
712 static void dss_mgr_write_regs_extra(struct omap_overlay_manager *mgr)
714 struct mgr_priv_data *mp = get_mgr_priv(mgr);
716 DSSDBG("writing mgr %d regs extra", mgr->id);
718 if (!mp->extra_info_dirty)
719 return;
721 dispc_mgr_set_timings(mgr->id, &mp->timings);
723 /* lcd_config parameters */
724 if (dss_mgr_is_lcd(mgr->id))
725 dispc_mgr_set_lcd_config(mgr->id, &mp->lcd_config);
727 mp->extra_info_dirty = false;
728 if (mp->updating)
729 mp->shadow_extra_info_dirty = true;
732 static void dss_write_regs(void)
734 const int num_mgrs = omap_dss_get_num_overlay_managers();
735 int i;
737 for (i = 0; i < num_mgrs; ++i) {
738 struct omap_overlay_manager *mgr;
739 struct mgr_priv_data *mp;
740 int r;
742 mgr = omap_dss_get_overlay_manager(i);
743 mp = get_mgr_priv(mgr);
745 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
746 continue;
748 r = dss_check_settings(mgr);
749 if (r) {
750 DSSERR("cannot write registers for manager %s: "
751 "illegal configuration\n", mgr->name);
752 continue;
755 dss_mgr_write_regs(mgr);
756 dss_mgr_write_regs_extra(mgr);
760 static void dss_set_go_bits(void)
762 const int num_mgrs = omap_dss_get_num_overlay_managers();
763 int i;
765 for (i = 0; i < num_mgrs; ++i) {
766 struct omap_overlay_manager *mgr;
767 struct mgr_priv_data *mp;
769 mgr = omap_dss_get_overlay_manager(i);
770 mp = get_mgr_priv(mgr);
772 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
773 continue;
775 if (!need_go(mgr))
776 continue;
778 mp->busy = true;
780 if (!dss_data.irq_enabled && need_isr())
781 dss_register_vsync_isr();
783 dispc_mgr_go(mgr->id);
788 static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
790 struct omap_overlay *ovl;
791 struct mgr_priv_data *mp;
792 struct ovl_priv_data *op;
794 mp = get_mgr_priv(mgr);
795 mp->shadow_info_dirty = false;
796 mp->shadow_extra_info_dirty = false;
798 list_for_each_entry(ovl, &mgr->overlays, list) {
799 op = get_ovl_priv(ovl);
800 op->shadow_info_dirty = false;
801 op->shadow_extra_info_dirty = false;
805 static int dss_mgr_connect_compat(struct omap_overlay_manager *mgr,
806 struct omap_dss_device *dst)
808 return mgr->set_output(mgr, dst);
811 static void dss_mgr_disconnect_compat(struct omap_overlay_manager *mgr,
812 struct omap_dss_device *dst)
814 mgr->unset_output(mgr);
817 static void dss_mgr_start_update_compat(struct omap_overlay_manager *mgr)
819 struct mgr_priv_data *mp = get_mgr_priv(mgr);
820 unsigned long flags;
821 int r;
823 spin_lock_irqsave(&data_lock, flags);
825 WARN_ON(mp->updating);
827 r = dss_check_settings(mgr);
828 if (r) {
829 DSSERR("cannot start manual update: illegal configuration\n");
830 spin_unlock_irqrestore(&data_lock, flags);
831 return;
834 dss_mgr_write_regs(mgr);
835 dss_mgr_write_regs_extra(mgr);
837 mp->updating = true;
839 if (!dss_data.irq_enabled && need_isr())
840 dss_register_vsync_isr();
842 dispc_mgr_enable_sync(mgr->id);
844 spin_unlock_irqrestore(&data_lock, flags);
847 static void dss_apply_irq_handler(void *data, u32 mask);
849 static void dss_register_vsync_isr(void)
851 const int num_mgrs = dss_feat_get_num_mgrs();
852 u32 mask;
853 int r, i;
855 mask = 0;
856 for (i = 0; i < num_mgrs; ++i)
857 mask |= dispc_mgr_get_vsync_irq(i);
859 for (i = 0; i < num_mgrs; ++i)
860 mask |= dispc_mgr_get_framedone_irq(i);
862 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
863 WARN_ON(r);
865 dss_data.irq_enabled = true;
868 static void dss_unregister_vsync_isr(void)
870 const int num_mgrs = dss_feat_get_num_mgrs();
871 u32 mask;
872 int r, i;
874 mask = 0;
875 for (i = 0; i < num_mgrs; ++i)
876 mask |= dispc_mgr_get_vsync_irq(i);
878 for (i = 0; i < num_mgrs; ++i)
879 mask |= dispc_mgr_get_framedone_irq(i);
881 r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask);
882 WARN_ON(r);
884 dss_data.irq_enabled = false;
887 static void dss_apply_irq_handler(void *data, u32 mask)
889 const int num_mgrs = dss_feat_get_num_mgrs();
890 int i;
891 bool extra_updating;
893 spin_lock(&data_lock);
895 /* clear busy, updating flags, shadow_dirty flags */
896 for (i = 0; i < num_mgrs; i++) {
897 struct omap_overlay_manager *mgr;
898 struct mgr_priv_data *mp;
900 mgr = omap_dss_get_overlay_manager(i);
901 mp = get_mgr_priv(mgr);
903 if (!mp->enabled)
904 continue;
906 mp->updating = dispc_mgr_is_enabled(i);
908 if (!mgr_manual_update(mgr)) {
909 bool was_busy = mp->busy;
910 mp->busy = dispc_mgr_go_busy(i);
912 if (was_busy && !mp->busy)
913 mgr_clear_shadow_dirty(mgr);
917 dss_write_regs();
918 dss_set_go_bits();
920 extra_updating = extra_info_update_ongoing();
921 if (!extra_updating)
922 complete_all(&extra_updated_completion);
924 /* call framedone handlers for manual update displays */
925 for (i = 0; i < num_mgrs; i++) {
926 struct omap_overlay_manager *mgr;
927 struct mgr_priv_data *mp;
929 mgr = omap_dss_get_overlay_manager(i);
930 mp = get_mgr_priv(mgr);
932 if (!mgr_manual_update(mgr) || !mp->framedone_handler)
933 continue;
935 if (mask & dispc_mgr_get_framedone_irq(i))
936 mp->framedone_handler(mp->framedone_handler_data);
939 if (!need_isr())
940 dss_unregister_vsync_isr();
942 spin_unlock(&data_lock);
945 static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
947 struct ovl_priv_data *op;
949 op = get_ovl_priv(ovl);
951 if (!op->user_info_dirty)
952 return;
954 op->user_info_dirty = false;
955 op->info_dirty = true;
956 op->info = op->user_info;
959 static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
961 struct mgr_priv_data *mp;
963 mp = get_mgr_priv(mgr);
965 if (!mp->user_info_dirty)
966 return;
968 mp->user_info_dirty = false;
969 mp->info_dirty = true;
970 mp->info = mp->user_info;
973 static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
975 unsigned long flags;
976 struct omap_overlay *ovl;
977 int r;
979 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
981 spin_lock_irqsave(&data_lock, flags);
983 r = dss_check_settings_apply(mgr);
984 if (r) {
985 spin_unlock_irqrestore(&data_lock, flags);
986 DSSERR("failed to apply settings: illegal configuration.\n");
987 return r;
990 /* Configure overlays */
991 list_for_each_entry(ovl, &mgr->overlays, list)
992 omap_dss_mgr_apply_ovl(ovl);
994 /* Configure manager */
995 omap_dss_mgr_apply_mgr(mgr);
997 dss_write_regs();
998 dss_set_go_bits();
1000 spin_unlock_irqrestore(&data_lock, flags);
1002 return 0;
1005 static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
1007 struct ovl_priv_data *op;
1009 op = get_ovl_priv(ovl);
1011 if (op->enabled == enable)
1012 return;
1014 op->enabled = enable;
1015 op->extra_info_dirty = true;
1018 static void dss_apply_ovl_fifo_thresholds(struct omap_overlay *ovl,
1019 u32 fifo_low, u32 fifo_high)
1021 struct ovl_priv_data *op = get_ovl_priv(ovl);
1023 if (op->fifo_low == fifo_low && op->fifo_high == fifo_high)
1024 return;
1026 op->fifo_low = fifo_low;
1027 op->fifo_high = fifo_high;
1028 op->extra_info_dirty = true;
1031 static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
1033 struct ovl_priv_data *op = get_ovl_priv(ovl);
1034 u32 fifo_low, fifo_high;
1035 bool use_fifo_merge = false;
1037 if (!op->enabled && !op->enabling)
1038 return;
1040 dispc_ovl_compute_fifo_thresholds(ovl->id, &fifo_low, &fifo_high,
1041 use_fifo_merge, ovl_manual_update(ovl));
1043 dss_apply_ovl_fifo_thresholds(ovl, fifo_low, fifo_high);
1046 static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
1048 struct omap_overlay *ovl;
1049 struct mgr_priv_data *mp;
1051 mp = get_mgr_priv(mgr);
1053 if (!mp->enabled)
1054 return;
1056 list_for_each_entry(ovl, &mgr->overlays, list)
1057 dss_ovl_setup_fifo(ovl);
1060 static void dss_setup_fifos(void)
1062 const int num_mgrs = omap_dss_get_num_overlay_managers();
1063 struct omap_overlay_manager *mgr;
1064 int i;
1066 for (i = 0; i < num_mgrs; ++i) {
1067 mgr = omap_dss_get_overlay_manager(i);
1068 dss_mgr_setup_fifos(mgr);
1072 static int dss_mgr_enable_compat(struct omap_overlay_manager *mgr)
1074 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1075 unsigned long flags;
1076 int r;
1078 mutex_lock(&apply_lock);
1080 if (mp->enabled)
1081 goto out;
1083 spin_lock_irqsave(&data_lock, flags);
1085 mp->enabled = true;
1087 r = dss_check_settings(mgr);
1088 if (r) {
1089 DSSERR("failed to enable manager %d: check_settings failed\n",
1090 mgr->id);
1091 goto err;
1094 dss_setup_fifos();
1096 dss_write_regs();
1097 dss_set_go_bits();
1099 if (!mgr_manual_update(mgr))
1100 mp->updating = true;
1102 if (!dss_data.irq_enabled && need_isr())
1103 dss_register_vsync_isr();
1105 spin_unlock_irqrestore(&data_lock, flags);
1107 if (!mgr_manual_update(mgr))
1108 dispc_mgr_enable_sync(mgr->id);
1110 out:
1111 mutex_unlock(&apply_lock);
1113 return 0;
1115 err:
1116 mp->enabled = false;
1117 spin_unlock_irqrestore(&data_lock, flags);
1118 mutex_unlock(&apply_lock);
1119 return r;
1122 static void dss_mgr_disable_compat(struct omap_overlay_manager *mgr)
1124 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1125 unsigned long flags;
1127 mutex_lock(&apply_lock);
1129 if (!mp->enabled)
1130 goto out;
1132 if (!mgr_manual_update(mgr))
1133 dispc_mgr_disable_sync(mgr->id);
1135 spin_lock_irqsave(&data_lock, flags);
1137 mp->updating = false;
1138 mp->enabled = false;
1140 spin_unlock_irqrestore(&data_lock, flags);
1142 out:
1143 mutex_unlock(&apply_lock);
1146 static int dss_mgr_set_info(struct omap_overlay_manager *mgr,
1147 struct omap_overlay_manager_info *info)
1149 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1150 unsigned long flags;
1151 int r;
1153 r = dss_mgr_simple_check(mgr, info);
1154 if (r)
1155 return r;
1157 spin_lock_irqsave(&data_lock, flags);
1159 mp->user_info = *info;
1160 mp->user_info_dirty = true;
1162 spin_unlock_irqrestore(&data_lock, flags);
1164 return 0;
1167 static void dss_mgr_get_info(struct omap_overlay_manager *mgr,
1168 struct omap_overlay_manager_info *info)
1170 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1171 unsigned long flags;
1173 spin_lock_irqsave(&data_lock, flags);
1175 *info = mp->user_info;
1177 spin_unlock_irqrestore(&data_lock, flags);
1180 static int dss_mgr_set_output(struct omap_overlay_manager *mgr,
1181 struct omap_dss_device *output)
1183 int r;
1185 mutex_lock(&apply_lock);
1187 if (mgr->output) {
1188 DSSERR("manager %s is already connected to an output\n",
1189 mgr->name);
1190 r = -EINVAL;
1191 goto err;
1194 if ((mgr->supported_outputs & output->id) == 0) {
1195 DSSERR("output does not support manager %s\n",
1196 mgr->name);
1197 r = -EINVAL;
1198 goto err;
1201 output->manager = mgr;
1202 mgr->output = output;
1204 mutex_unlock(&apply_lock);
1206 return 0;
1207 err:
1208 mutex_unlock(&apply_lock);
1209 return r;
1212 static int dss_mgr_unset_output(struct omap_overlay_manager *mgr)
1214 int r;
1215 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1216 unsigned long flags;
1218 mutex_lock(&apply_lock);
1220 if (!mgr->output) {
1221 DSSERR("failed to unset output, output not set\n");
1222 r = -EINVAL;
1223 goto err;
1226 spin_lock_irqsave(&data_lock, flags);
1228 if (mp->enabled) {
1229 DSSERR("output can't be unset when manager is enabled\n");
1230 r = -EINVAL;
1231 goto err1;
1234 spin_unlock_irqrestore(&data_lock, flags);
1236 mgr->output->manager = NULL;
1237 mgr->output = NULL;
1239 mutex_unlock(&apply_lock);
1241 return 0;
1242 err1:
1243 spin_unlock_irqrestore(&data_lock, flags);
1244 err:
1245 mutex_unlock(&apply_lock);
1247 return r;
1250 static void dss_apply_mgr_timings(struct omap_overlay_manager *mgr,
1251 const struct omap_video_timings *timings)
1253 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1255 mp->timings = *timings;
1256 mp->extra_info_dirty = true;
1259 static void dss_mgr_set_timings_compat(struct omap_overlay_manager *mgr,
1260 const struct omap_video_timings *timings)
1262 unsigned long flags;
1263 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1265 spin_lock_irqsave(&data_lock, flags);
1267 if (mp->updating) {
1268 DSSERR("cannot set timings for %s: manager needs to be disabled\n",
1269 mgr->name);
1270 goto out;
1273 dss_apply_mgr_timings(mgr, timings);
1274 out:
1275 spin_unlock_irqrestore(&data_lock, flags);
1278 static void dss_apply_mgr_lcd_config(struct omap_overlay_manager *mgr,
1279 const struct dss_lcd_mgr_config *config)
1281 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1283 mp->lcd_config = *config;
1284 mp->extra_info_dirty = true;
1287 static void dss_mgr_set_lcd_config_compat(struct omap_overlay_manager *mgr,
1288 const struct dss_lcd_mgr_config *config)
1290 unsigned long flags;
1291 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1293 spin_lock_irqsave(&data_lock, flags);
1295 if (mp->enabled) {
1296 DSSERR("cannot apply lcd config for %s: manager needs to be disabled\n",
1297 mgr->name);
1298 goto out;
1301 dss_apply_mgr_lcd_config(mgr, config);
1302 out:
1303 spin_unlock_irqrestore(&data_lock, flags);
1306 static int dss_ovl_set_info(struct omap_overlay *ovl,
1307 struct omap_overlay_info *info)
1309 struct ovl_priv_data *op = get_ovl_priv(ovl);
1310 unsigned long flags;
1311 int r;
1313 r = dss_ovl_simple_check(ovl, info);
1314 if (r)
1315 return r;
1317 spin_lock_irqsave(&data_lock, flags);
1319 op->user_info = *info;
1320 op->user_info_dirty = true;
1322 spin_unlock_irqrestore(&data_lock, flags);
1324 return 0;
1327 static void dss_ovl_get_info(struct omap_overlay *ovl,
1328 struct omap_overlay_info *info)
1330 struct ovl_priv_data *op = get_ovl_priv(ovl);
1331 unsigned long flags;
1333 spin_lock_irqsave(&data_lock, flags);
1335 *info = op->user_info;
1337 spin_unlock_irqrestore(&data_lock, flags);
1340 static int dss_ovl_set_manager(struct omap_overlay *ovl,
1341 struct omap_overlay_manager *mgr)
1343 struct ovl_priv_data *op = get_ovl_priv(ovl);
1344 unsigned long flags;
1345 int r;
1347 if (!mgr)
1348 return -EINVAL;
1350 mutex_lock(&apply_lock);
1352 if (ovl->manager) {
1353 DSSERR("overlay '%s' already has a manager '%s'\n",
1354 ovl->name, ovl->manager->name);
1355 r = -EINVAL;
1356 goto err;
1359 r = dispc_runtime_get();
1360 if (r)
1361 goto err;
1363 spin_lock_irqsave(&data_lock, flags);
1365 if (op->enabled) {
1366 spin_unlock_irqrestore(&data_lock, flags);
1367 DSSERR("overlay has to be disabled to change the manager\n");
1368 r = -EINVAL;
1369 goto err1;
1372 dispc_ovl_set_channel_out(ovl->id, mgr->id);
1374 ovl->manager = mgr;
1375 list_add_tail(&ovl->list, &mgr->overlays);
1377 spin_unlock_irqrestore(&data_lock, flags);
1379 dispc_runtime_put();
1381 mutex_unlock(&apply_lock);
1383 return 0;
1385 err1:
1386 dispc_runtime_put();
1387 err:
1388 mutex_unlock(&apply_lock);
1389 return r;
1392 static int dss_ovl_unset_manager(struct omap_overlay *ovl)
1394 struct ovl_priv_data *op = get_ovl_priv(ovl);
1395 unsigned long flags;
1396 int r;
1398 mutex_lock(&apply_lock);
1400 if (!ovl->manager) {
1401 DSSERR("failed to detach overlay: manager not set\n");
1402 r = -EINVAL;
1403 goto err;
1406 spin_lock_irqsave(&data_lock, flags);
1408 if (op->enabled) {
1409 spin_unlock_irqrestore(&data_lock, flags);
1410 DSSERR("overlay has to be disabled to unset the manager\n");
1411 r = -EINVAL;
1412 goto err;
1415 spin_unlock_irqrestore(&data_lock, flags);
1417 /* wait for pending extra_info updates to ensure the ovl is disabled */
1418 wait_pending_extra_info_updates();
1421 * For a manual update display, there is no guarantee that the overlay
1422 * is really disabled in HW, we may need an extra update from this
1423 * manager before the configurations can go in. Return an error if the
1424 * overlay needed an update from the manager.
1426 * TODO: Instead of returning an error, try to do a dummy manager update
1427 * here to disable the overlay in hardware. Use the *GATED fields in
1428 * the DISPC_CONFIG registers to do a dummy update.
1430 spin_lock_irqsave(&data_lock, flags);
1432 if (ovl_manual_update(ovl) && op->extra_info_dirty) {
1433 spin_unlock_irqrestore(&data_lock, flags);
1434 DSSERR("need an update to change the manager\n");
1435 r = -EINVAL;
1436 goto err;
1439 ovl->manager = NULL;
1440 list_del(&ovl->list);
1442 spin_unlock_irqrestore(&data_lock, flags);
1444 mutex_unlock(&apply_lock);
1446 return 0;
1447 err:
1448 mutex_unlock(&apply_lock);
1449 return r;
1452 static bool dss_ovl_is_enabled(struct omap_overlay *ovl)
1454 struct ovl_priv_data *op = get_ovl_priv(ovl);
1455 unsigned long flags;
1456 bool e;
1458 spin_lock_irqsave(&data_lock, flags);
1460 e = op->enabled;
1462 spin_unlock_irqrestore(&data_lock, flags);
1464 return e;
1467 static int dss_ovl_enable(struct omap_overlay *ovl)
1469 struct ovl_priv_data *op = get_ovl_priv(ovl);
1470 unsigned long flags;
1471 int r;
1473 mutex_lock(&apply_lock);
1475 if (op->enabled) {
1476 r = 0;
1477 goto err1;
1480 if (ovl->manager == NULL || ovl->manager->output == NULL) {
1481 r = -EINVAL;
1482 goto err1;
1485 spin_lock_irqsave(&data_lock, flags);
1487 op->enabling = true;
1489 r = dss_check_settings(ovl->manager);
1490 if (r) {
1491 DSSERR("failed to enable overlay %d: check_settings failed\n",
1492 ovl->id);
1493 goto err2;
1496 dss_setup_fifos();
1498 op->enabling = false;
1499 dss_apply_ovl_enable(ovl, true);
1501 dss_write_regs();
1502 dss_set_go_bits();
1504 spin_unlock_irqrestore(&data_lock, flags);
1506 mutex_unlock(&apply_lock);
1508 return 0;
1509 err2:
1510 op->enabling = false;
1511 spin_unlock_irqrestore(&data_lock, flags);
1512 err1:
1513 mutex_unlock(&apply_lock);
1514 return r;
1517 static int dss_ovl_disable(struct omap_overlay *ovl)
1519 struct ovl_priv_data *op = get_ovl_priv(ovl);
1520 unsigned long flags;
1521 int r;
1523 mutex_lock(&apply_lock);
1525 if (!op->enabled) {
1526 r = 0;
1527 goto err;
1530 if (ovl->manager == NULL || ovl->manager->output == NULL) {
1531 r = -EINVAL;
1532 goto err;
1535 spin_lock_irqsave(&data_lock, flags);
1537 dss_apply_ovl_enable(ovl, false);
1538 dss_write_regs();
1539 dss_set_go_bits();
1541 spin_unlock_irqrestore(&data_lock, flags);
1543 mutex_unlock(&apply_lock);
1545 return 0;
1547 err:
1548 mutex_unlock(&apply_lock);
1549 return r;
1552 static int dss_mgr_register_framedone_handler_compat(struct omap_overlay_manager *mgr,
1553 void (*handler)(void *), void *data)
1555 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1557 if (mp->framedone_handler)
1558 return -EBUSY;
1560 mp->framedone_handler = handler;
1561 mp->framedone_handler_data = data;
1563 return 0;
1566 static void dss_mgr_unregister_framedone_handler_compat(struct omap_overlay_manager *mgr,
1567 void (*handler)(void *), void *data)
1569 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1571 WARN_ON(mp->framedone_handler != handler ||
1572 mp->framedone_handler_data != data);
1574 mp->framedone_handler = NULL;
1575 mp->framedone_handler_data = NULL;
1578 static const struct dss_mgr_ops apply_mgr_ops = {
1579 .connect = dss_mgr_connect_compat,
1580 .disconnect = dss_mgr_disconnect_compat,
1581 .start_update = dss_mgr_start_update_compat,
1582 .enable = dss_mgr_enable_compat,
1583 .disable = dss_mgr_disable_compat,
1584 .set_timings = dss_mgr_set_timings_compat,
1585 .set_lcd_config = dss_mgr_set_lcd_config_compat,
1586 .register_framedone_handler = dss_mgr_register_framedone_handler_compat,
1587 .unregister_framedone_handler = dss_mgr_unregister_framedone_handler_compat,
1590 static int compat_refcnt;
1591 static DEFINE_MUTEX(compat_init_lock);
1593 int omapdss_compat_init(void)
1595 struct platform_device *pdev = dss_get_core_pdev();
1596 int i, r;
1598 mutex_lock(&compat_init_lock);
1600 if (compat_refcnt++ > 0)
1601 goto out;
1603 apply_init_priv();
1605 dss_init_overlay_managers_sysfs(pdev);
1606 dss_init_overlays(pdev);
1608 for (i = 0; i < omap_dss_get_num_overlay_managers(); i++) {
1609 struct omap_overlay_manager *mgr;
1611 mgr = omap_dss_get_overlay_manager(i);
1613 mgr->set_output = &dss_mgr_set_output;
1614 mgr->unset_output = &dss_mgr_unset_output;
1615 mgr->apply = &omap_dss_mgr_apply;
1616 mgr->set_manager_info = &dss_mgr_set_info;
1617 mgr->get_manager_info = &dss_mgr_get_info;
1618 mgr->wait_for_go = &dss_mgr_wait_for_go;
1619 mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
1620 mgr->get_device = &dss_mgr_get_device;
1623 for (i = 0; i < omap_dss_get_num_overlays(); i++) {
1624 struct omap_overlay *ovl = omap_dss_get_overlay(i);
1626 ovl->is_enabled = &dss_ovl_is_enabled;
1627 ovl->enable = &dss_ovl_enable;
1628 ovl->disable = &dss_ovl_disable;
1629 ovl->set_manager = &dss_ovl_set_manager;
1630 ovl->unset_manager = &dss_ovl_unset_manager;
1631 ovl->set_overlay_info = &dss_ovl_set_info;
1632 ovl->get_overlay_info = &dss_ovl_get_info;
1633 ovl->wait_for_go = &dss_mgr_wait_for_go_ovl;
1634 ovl->get_device = &dss_ovl_get_device;
1637 r = dss_install_mgr_ops(&apply_mgr_ops);
1638 if (r)
1639 goto err_mgr_ops;
1641 r = display_init_sysfs(pdev);
1642 if (r)
1643 goto err_disp_sysfs;
1645 dispc_runtime_get();
1647 r = dss_dispc_initialize_irq();
1648 if (r)
1649 goto err_init_irq;
1651 dispc_runtime_put();
1653 out:
1654 mutex_unlock(&compat_init_lock);
1656 return 0;
1658 err_init_irq:
1659 dispc_runtime_put();
1660 display_uninit_sysfs(pdev);
1662 err_disp_sysfs:
1663 dss_uninstall_mgr_ops();
1665 err_mgr_ops:
1666 dss_uninit_overlay_managers_sysfs(pdev);
1667 dss_uninit_overlays(pdev);
1669 compat_refcnt--;
1671 mutex_unlock(&compat_init_lock);
1673 return r;
1675 EXPORT_SYMBOL(omapdss_compat_init);
1677 void omapdss_compat_uninit(void)
1679 struct platform_device *pdev = dss_get_core_pdev();
1681 mutex_lock(&compat_init_lock);
1683 if (--compat_refcnt > 0)
1684 goto out;
1686 dss_dispc_uninitialize_irq();
1688 display_uninit_sysfs(pdev);
1690 dss_uninstall_mgr_ops();
1692 dss_uninit_overlay_managers_sysfs(pdev);
1693 dss_uninit_overlays(pdev);
1694 out:
1695 mutex_unlock(&compat_init_lock);
1697 EXPORT_SYMBOL(omapdss_compat_uninit);