Avoid beyond bounds copy while caching ACL
[zen-stable.git] / drivers / video / omap2 / dss / apply.c
blob87b3e25294cf506f7b70431b0a6fbc7df569a5f0
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/slab.h>
22 #include <linux/spinlock.h>
23 #include <linux/jiffies.h>
25 #include <video/omapdss.h>
27 #include "dss.h"
28 #include "dss_features.h"
31 * We have 4 levels of cache for the dispc settings. First two are in SW and
32 * the latter two in HW.
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 * +--------------------+
59 struct ovl_priv_data {
61 bool user_info_dirty;
62 struct omap_overlay_info user_info;
64 bool info_dirty;
65 struct omap_overlay_info info;
67 bool shadow_info_dirty;
69 bool extra_info_dirty;
70 bool shadow_extra_info_dirty;
72 bool enabled;
73 enum omap_channel channel;
74 u32 fifo_low, fifo_high;
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.
80 bool enabling;
83 struct mgr_priv_data {
85 bool user_info_dirty;
86 struct omap_overlay_manager_info user_info;
88 bool info_dirty;
89 struct omap_overlay_manager_info info;
91 bool shadow_info_dirty;
93 /* If true, GO bit is up and shadow registers cannot be written.
94 * Never true for manual update displays */
95 bool busy;
97 /* If true, dispc output is enabled */
98 bool updating;
100 /* If true, a display is enabled using this manager */
101 bool enabled;
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];
108 bool irq_enabled;
109 } dss_data;
111 /* protects dss_data */
112 static spinlock_t data_lock;
113 /* lock for blocking functions */
114 static DEFINE_MUTEX(apply_lock);
115 static DECLARE_COMPLETION(extra_updated_completion);
117 static void dss_register_vsync_isr(void);
119 static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl)
121 return &dss_data.ovl_priv_data_array[ovl->id];
124 static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr)
126 return &dss_data.mgr_priv_data_array[mgr->id];
129 void dss_apply_init(void)
131 const int num_ovls = dss_feat_get_num_ovls();
132 int i;
134 spin_lock_init(&data_lock);
136 for (i = 0; i < num_ovls; ++i) {
137 struct ovl_priv_data *op;
139 op = &dss_data.ovl_priv_data_array[i];
141 op->info.global_alpha = 255;
143 switch (i) {
144 case 0:
145 op->info.zorder = 0;
146 break;
147 case 1:
148 op->info.zorder =
149 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 3 : 0;
150 break;
151 case 2:
152 op->info.zorder =
153 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 2 : 0;
154 break;
155 case 3:
156 op->info.zorder =
157 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 1 : 0;
158 break;
161 op->user_info = op->info;
165 static bool ovl_manual_update(struct omap_overlay *ovl)
167 return ovl->manager->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
170 static bool mgr_manual_update(struct omap_overlay_manager *mgr)
172 return mgr->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
175 static int dss_check_settings_low(struct omap_overlay_manager *mgr,
176 struct omap_dss_device *dssdev, bool applying)
178 struct omap_overlay_info *oi;
179 struct omap_overlay_manager_info *mi;
180 struct omap_overlay *ovl;
181 struct omap_overlay_info *ois[MAX_DSS_OVERLAYS];
182 struct ovl_priv_data *op;
183 struct mgr_priv_data *mp;
185 mp = get_mgr_priv(mgr);
187 if (applying && mp->user_info_dirty)
188 mi = &mp->user_info;
189 else
190 mi = &mp->info;
192 /* collect the infos to be tested into the array */
193 list_for_each_entry(ovl, &mgr->overlays, list) {
194 op = get_ovl_priv(ovl);
196 if (!op->enabled && !op->enabling)
197 oi = NULL;
198 else if (applying && op->user_info_dirty)
199 oi = &op->user_info;
200 else
201 oi = &op->info;
203 ois[ovl->id] = oi;
206 return dss_mgr_check(mgr, dssdev, mi, ois);
210 * check manager and overlay settings using overlay_info from data->info
212 static int dss_check_settings(struct omap_overlay_manager *mgr,
213 struct omap_dss_device *dssdev)
215 return dss_check_settings_low(mgr, dssdev, false);
219 * check manager and overlay settings using overlay_info from ovl->info if
220 * dirty and from data->info otherwise
222 static int dss_check_settings_apply(struct omap_overlay_manager *mgr,
223 struct omap_dss_device *dssdev)
225 return dss_check_settings_low(mgr, dssdev, true);
228 static bool need_isr(void)
230 const int num_mgrs = dss_feat_get_num_mgrs();
231 int i;
233 for (i = 0; i < num_mgrs; ++i) {
234 struct omap_overlay_manager *mgr;
235 struct mgr_priv_data *mp;
236 struct omap_overlay *ovl;
238 mgr = omap_dss_get_overlay_manager(i);
239 mp = get_mgr_priv(mgr);
241 if (!mp->enabled)
242 continue;
244 if (mgr_manual_update(mgr)) {
245 /* to catch FRAMEDONE */
246 if (mp->updating)
247 return true;
248 } else {
249 /* to catch GO bit going down */
250 if (mp->busy)
251 return true;
253 /* to write new values to registers */
254 if (mp->info_dirty)
255 return true;
257 /* to set GO bit */
258 if (mp->shadow_info_dirty)
259 return true;
261 list_for_each_entry(ovl, &mgr->overlays, list) {
262 struct ovl_priv_data *op;
264 op = get_ovl_priv(ovl);
267 * NOTE: we check extra_info flags even for
268 * disabled overlays, as extra_infos need to be
269 * always written.
272 /* to write new values to registers */
273 if (op->extra_info_dirty)
274 return true;
276 /* to set GO bit */
277 if (op->shadow_extra_info_dirty)
278 return true;
280 if (!op->enabled)
281 continue;
283 /* to write new values to registers */
284 if (op->info_dirty)
285 return true;
287 /* to set GO bit */
288 if (op->shadow_info_dirty)
289 return true;
294 return false;
297 static bool need_go(struct omap_overlay_manager *mgr)
299 struct omap_overlay *ovl;
300 struct mgr_priv_data *mp;
301 struct ovl_priv_data *op;
303 mp = get_mgr_priv(mgr);
305 if (mp->shadow_info_dirty)
306 return true;
308 list_for_each_entry(ovl, &mgr->overlays, list) {
309 op = get_ovl_priv(ovl);
310 if (op->shadow_info_dirty || op->shadow_extra_info_dirty)
311 return true;
314 return false;
317 /* returns true if an extra_info field is currently being updated */
318 static bool extra_info_update_ongoing(void)
320 const int num_ovls = omap_dss_get_num_overlays();
321 struct ovl_priv_data *op;
322 struct omap_overlay *ovl;
323 struct mgr_priv_data *mp;
324 int i;
326 for (i = 0; i < num_ovls; ++i) {
327 ovl = omap_dss_get_overlay(i);
328 op = get_ovl_priv(ovl);
330 if (!ovl->manager)
331 continue;
333 mp = get_mgr_priv(ovl->manager);
335 if (!mp->enabled)
336 continue;
338 if (!mp->updating)
339 continue;
341 if (op->extra_info_dirty || op->shadow_extra_info_dirty)
342 return true;
345 return false;
348 /* wait until no extra_info updates are pending */
349 static void wait_pending_extra_info_updates(void)
351 bool updating;
352 unsigned long flags;
353 unsigned long t;
355 spin_lock_irqsave(&data_lock, flags);
357 updating = extra_info_update_ongoing();
359 if (!updating) {
360 spin_unlock_irqrestore(&data_lock, flags);
361 return;
364 init_completion(&extra_updated_completion);
366 spin_unlock_irqrestore(&data_lock, flags);
368 t = msecs_to_jiffies(500);
369 wait_for_completion_timeout(&extra_updated_completion, t);
371 updating = extra_info_update_ongoing();
373 WARN_ON(updating);
376 int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
378 unsigned long timeout = msecs_to_jiffies(500);
379 struct mgr_priv_data *mp;
380 u32 irq;
381 int r;
382 int i;
383 struct omap_dss_device *dssdev = mgr->device;
385 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
386 return 0;
388 if (mgr_manual_update(mgr))
389 return 0;
391 irq = dispc_mgr_get_vsync_irq(mgr->id);
393 mp = get_mgr_priv(mgr);
394 i = 0;
395 while (1) {
396 unsigned long flags;
397 bool shadow_dirty, dirty;
399 spin_lock_irqsave(&data_lock, flags);
400 dirty = mp->info_dirty;
401 shadow_dirty = mp->shadow_info_dirty;
402 spin_unlock_irqrestore(&data_lock, flags);
404 if (!dirty && !shadow_dirty) {
405 r = 0;
406 break;
409 /* 4 iterations is the worst case:
410 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
411 * 2 - first VSYNC, dirty = true
412 * 3 - dirty = false, shadow_dirty = true
413 * 4 - shadow_dirty = false */
414 if (i++ == 3) {
415 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
416 mgr->id);
417 r = 0;
418 break;
421 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
422 if (r == -ERESTARTSYS)
423 break;
425 if (r) {
426 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
427 break;
431 return r;
434 int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
436 unsigned long timeout = msecs_to_jiffies(500);
437 struct ovl_priv_data *op;
438 struct omap_dss_device *dssdev;
439 u32 irq;
440 int r;
441 int i;
443 if (!ovl->manager)
444 return 0;
446 dssdev = ovl->manager->device;
448 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
449 return 0;
451 if (ovl_manual_update(ovl))
452 return 0;
454 irq = dispc_mgr_get_vsync_irq(ovl->manager->id);
456 op = get_ovl_priv(ovl);
457 i = 0;
458 while (1) {
459 unsigned long flags;
460 bool shadow_dirty, dirty;
462 spin_lock_irqsave(&data_lock, flags);
463 dirty = op->info_dirty;
464 shadow_dirty = op->shadow_info_dirty;
465 spin_unlock_irqrestore(&data_lock, flags);
467 if (!dirty && !shadow_dirty) {
468 r = 0;
469 break;
472 /* 4 iterations is the worst case:
473 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
474 * 2 - first VSYNC, dirty = true
475 * 3 - dirty = false, shadow_dirty = true
476 * 4 - shadow_dirty = false */
477 if (i++ == 3) {
478 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
479 ovl->id);
480 r = 0;
481 break;
484 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
485 if (r == -ERESTARTSYS)
486 break;
488 if (r) {
489 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
490 break;
494 return r;
497 static void dss_ovl_write_regs(struct omap_overlay *ovl)
499 struct ovl_priv_data *op = get_ovl_priv(ovl);
500 struct omap_overlay_info *oi;
501 bool ilace, replication;
502 struct mgr_priv_data *mp;
503 int r;
505 DSSDBGF("%d", ovl->id);
507 if (!op->enabled || !op->info_dirty)
508 return;
510 oi = &op->info;
512 replication = dss_use_replication(ovl->manager->device, oi->color_mode);
514 ilace = ovl->manager->device->type == OMAP_DISPLAY_TYPE_VENC;
516 r = dispc_ovl_setup(ovl->id, oi, ilace, replication);
517 if (r) {
519 * We can't do much here, as this function can be called from
520 * vsync interrupt.
522 DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id);
524 /* This will leave fifo configurations in a nonoptimal state */
525 op->enabled = false;
526 dispc_ovl_enable(ovl->id, false);
527 return;
530 mp = get_mgr_priv(ovl->manager);
532 op->info_dirty = false;
533 if (mp->updating)
534 op->shadow_info_dirty = true;
537 static void dss_ovl_write_regs_extra(struct omap_overlay *ovl)
539 struct ovl_priv_data *op = get_ovl_priv(ovl);
540 struct mgr_priv_data *mp;
542 DSSDBGF("%d", ovl->id);
544 if (!op->extra_info_dirty)
545 return;
547 /* note: write also when op->enabled == false, so that the ovl gets
548 * disabled */
550 dispc_ovl_enable(ovl->id, op->enabled);
551 dispc_ovl_set_channel_out(ovl->id, op->channel);
552 dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high);
554 mp = get_mgr_priv(ovl->manager);
556 op->extra_info_dirty = false;
557 if (mp->updating)
558 op->shadow_extra_info_dirty = true;
561 static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
563 struct mgr_priv_data *mp = get_mgr_priv(mgr);
564 struct omap_overlay *ovl;
566 DSSDBGF("%d", mgr->id);
568 if (!mp->enabled)
569 return;
571 WARN_ON(mp->busy);
573 /* Commit overlay settings */
574 list_for_each_entry(ovl, &mgr->overlays, list) {
575 dss_ovl_write_regs(ovl);
576 dss_ovl_write_regs_extra(ovl);
579 if (mp->info_dirty) {
580 dispc_mgr_setup(mgr->id, &mp->info);
582 mp->info_dirty = false;
583 if (mp->updating)
584 mp->shadow_info_dirty = true;
588 static void dss_write_regs(void)
590 const int num_mgrs = omap_dss_get_num_overlay_managers();
591 int i;
593 for (i = 0; i < num_mgrs; ++i) {
594 struct omap_overlay_manager *mgr;
595 struct mgr_priv_data *mp;
596 int r;
598 mgr = omap_dss_get_overlay_manager(i);
599 mp = get_mgr_priv(mgr);
601 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
602 continue;
604 r = dss_check_settings(mgr, mgr->device);
605 if (r) {
606 DSSERR("cannot write registers for manager %s: "
607 "illegal configuration\n", mgr->name);
608 continue;
611 dss_mgr_write_regs(mgr);
615 static void dss_set_go_bits(void)
617 const int num_mgrs = omap_dss_get_num_overlay_managers();
618 int i;
620 for (i = 0; i < num_mgrs; ++i) {
621 struct omap_overlay_manager *mgr;
622 struct mgr_priv_data *mp;
624 mgr = omap_dss_get_overlay_manager(i);
625 mp = get_mgr_priv(mgr);
627 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
628 continue;
630 if (!need_go(mgr))
631 continue;
633 mp->busy = true;
635 if (!dss_data.irq_enabled && need_isr())
636 dss_register_vsync_isr();
638 dispc_mgr_go(mgr->id);
643 void dss_mgr_start_update(struct omap_overlay_manager *mgr)
645 struct mgr_priv_data *mp = get_mgr_priv(mgr);
646 unsigned long flags;
647 int r;
649 spin_lock_irqsave(&data_lock, flags);
651 WARN_ON(mp->updating);
653 r = dss_check_settings(mgr, mgr->device);
654 if (r) {
655 DSSERR("cannot start manual update: illegal configuration\n");
656 spin_unlock_irqrestore(&data_lock, flags);
657 return;
660 dss_mgr_write_regs(mgr);
662 mp->updating = true;
664 if (!dss_data.irq_enabled && need_isr())
665 dss_register_vsync_isr();
667 dispc_mgr_enable(mgr->id, true);
669 spin_unlock_irqrestore(&data_lock, flags);
672 static void dss_apply_irq_handler(void *data, u32 mask);
674 static void dss_register_vsync_isr(void)
676 const int num_mgrs = dss_feat_get_num_mgrs();
677 u32 mask;
678 int r, i;
680 mask = 0;
681 for (i = 0; i < num_mgrs; ++i)
682 mask |= dispc_mgr_get_vsync_irq(i);
684 for (i = 0; i < num_mgrs; ++i)
685 mask |= dispc_mgr_get_framedone_irq(i);
687 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
688 WARN_ON(r);
690 dss_data.irq_enabled = true;
693 static void dss_unregister_vsync_isr(void)
695 const int num_mgrs = dss_feat_get_num_mgrs();
696 u32 mask;
697 int r, i;
699 mask = 0;
700 for (i = 0; i < num_mgrs; ++i)
701 mask |= dispc_mgr_get_vsync_irq(i);
703 for (i = 0; i < num_mgrs; ++i)
704 mask |= dispc_mgr_get_framedone_irq(i);
706 r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask);
707 WARN_ON(r);
709 dss_data.irq_enabled = false;
712 static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
714 struct omap_overlay *ovl;
715 struct mgr_priv_data *mp;
716 struct ovl_priv_data *op;
718 mp = get_mgr_priv(mgr);
719 mp->shadow_info_dirty = false;
721 list_for_each_entry(ovl, &mgr->overlays, list) {
722 op = get_ovl_priv(ovl);
723 op->shadow_info_dirty = false;
724 op->shadow_extra_info_dirty = false;
728 static void dss_apply_irq_handler(void *data, u32 mask)
730 const int num_mgrs = dss_feat_get_num_mgrs();
731 int i;
732 bool extra_updating;
734 spin_lock(&data_lock);
736 /* clear busy, updating flags, shadow_dirty flags */
737 for (i = 0; i < num_mgrs; i++) {
738 struct omap_overlay_manager *mgr;
739 struct mgr_priv_data *mp;
740 bool was_updating;
742 mgr = omap_dss_get_overlay_manager(i);
743 mp = get_mgr_priv(mgr);
745 if (!mp->enabled)
746 continue;
748 was_updating = mp->updating;
749 mp->updating = dispc_mgr_is_enabled(i);
751 if (!mgr_manual_update(mgr)) {
752 bool was_busy = mp->busy;
753 mp->busy = dispc_mgr_go_busy(i);
755 if (was_busy && !mp->busy)
756 mgr_clear_shadow_dirty(mgr);
757 } else {
758 if (was_updating && !mp->updating)
759 mgr_clear_shadow_dirty(mgr);
763 dss_write_regs();
764 dss_set_go_bits();
766 extra_updating = extra_info_update_ongoing();
767 if (!extra_updating)
768 complete_all(&extra_updated_completion);
770 if (!need_isr())
771 dss_unregister_vsync_isr();
773 spin_unlock(&data_lock);
776 static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
778 struct ovl_priv_data *op;
780 op = get_ovl_priv(ovl);
782 if (!op->user_info_dirty)
783 return;
785 op->user_info_dirty = false;
786 op->info_dirty = true;
787 op->info = op->user_info;
790 static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
792 struct mgr_priv_data *mp;
794 mp = get_mgr_priv(mgr);
796 if (!mp->user_info_dirty)
797 return;
799 mp->user_info_dirty = false;
800 mp->info_dirty = true;
801 mp->info = mp->user_info;
804 int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
806 unsigned long flags;
807 struct omap_overlay *ovl;
808 int r;
810 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
812 spin_lock_irqsave(&data_lock, flags);
814 r = dss_check_settings_apply(mgr, mgr->device);
815 if (r) {
816 spin_unlock_irqrestore(&data_lock, flags);
817 DSSERR("failed to apply settings: illegal configuration.\n");
818 return r;
821 /* Configure overlays */
822 list_for_each_entry(ovl, &mgr->overlays, list)
823 omap_dss_mgr_apply_ovl(ovl);
825 /* Configure manager */
826 omap_dss_mgr_apply_mgr(mgr);
828 dss_write_regs();
829 dss_set_go_bits();
831 spin_unlock_irqrestore(&data_lock, flags);
833 return 0;
836 static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
838 struct ovl_priv_data *op;
840 op = get_ovl_priv(ovl);
842 if (op->enabled == enable)
843 return;
845 op->enabled = enable;
846 op->extra_info_dirty = true;
849 static void dss_apply_ovl_fifo_thresholds(struct omap_overlay *ovl,
850 u32 fifo_low, u32 fifo_high)
852 struct ovl_priv_data *op = get_ovl_priv(ovl);
854 if (op->fifo_low == fifo_low && op->fifo_high == fifo_high)
855 return;
857 op->fifo_low = fifo_low;
858 op->fifo_high = fifo_high;
859 op->extra_info_dirty = true;
862 static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
864 struct ovl_priv_data *op = get_ovl_priv(ovl);
865 struct omap_dss_device *dssdev;
866 u32 size, burst_size;
867 u32 fifo_low, fifo_high;
869 if (!op->enabled && !op->enabling)
870 return;
872 dssdev = ovl->manager->device;
874 size = dispc_ovl_get_fifo_size(ovl->id);
876 burst_size = dispc_ovl_get_burst_size(ovl->id);
878 switch (dssdev->type) {
879 case OMAP_DISPLAY_TYPE_DPI:
880 case OMAP_DISPLAY_TYPE_DBI:
881 case OMAP_DISPLAY_TYPE_SDI:
882 case OMAP_DISPLAY_TYPE_VENC:
883 case OMAP_DISPLAY_TYPE_HDMI:
884 default_get_overlay_fifo_thresholds(ovl->id, size,
885 burst_size, &fifo_low, &fifo_high);
886 break;
887 #ifdef CONFIG_OMAP2_DSS_DSI
888 case OMAP_DISPLAY_TYPE_DSI:
889 dsi_get_overlay_fifo_thresholds(ovl->id, size,
890 burst_size, &fifo_low, &fifo_high);
891 break;
892 #endif
893 default:
894 BUG();
897 dss_apply_ovl_fifo_thresholds(ovl, fifo_low, fifo_high);
900 static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
902 struct omap_overlay *ovl;
903 struct mgr_priv_data *mp;
905 mp = get_mgr_priv(mgr);
907 if (!mp->enabled)
908 return;
910 list_for_each_entry(ovl, &mgr->overlays, list)
911 dss_ovl_setup_fifo(ovl);
914 static void dss_setup_fifos(void)
916 const int num_mgrs = omap_dss_get_num_overlay_managers();
917 struct omap_overlay_manager *mgr;
918 int i;
920 for (i = 0; i < num_mgrs; ++i) {
921 mgr = omap_dss_get_overlay_manager(i);
922 dss_mgr_setup_fifos(mgr);
926 int dss_mgr_enable(struct omap_overlay_manager *mgr)
928 struct mgr_priv_data *mp = get_mgr_priv(mgr);
929 unsigned long flags;
930 int r;
932 mutex_lock(&apply_lock);
934 if (mp->enabled)
935 goto out;
937 spin_lock_irqsave(&data_lock, flags);
939 mp->enabled = true;
941 r = dss_check_settings(mgr, mgr->device);
942 if (r) {
943 DSSERR("failed to enable manager %d: check_settings failed\n",
944 mgr->id);
945 goto err;
948 dss_setup_fifos();
950 dss_write_regs();
951 dss_set_go_bits();
953 if (!mgr_manual_update(mgr))
954 mp->updating = true;
956 spin_unlock_irqrestore(&data_lock, flags);
958 if (!mgr_manual_update(mgr))
959 dispc_mgr_enable(mgr->id, true);
961 out:
962 mutex_unlock(&apply_lock);
964 return 0;
966 err:
967 mp->enabled = false;
968 spin_unlock_irqrestore(&data_lock, flags);
969 mutex_unlock(&apply_lock);
970 return r;
973 void dss_mgr_disable(struct omap_overlay_manager *mgr)
975 struct mgr_priv_data *mp = get_mgr_priv(mgr);
976 unsigned long flags;
978 mutex_lock(&apply_lock);
980 if (!mp->enabled)
981 goto out;
983 if (!mgr_manual_update(mgr))
984 dispc_mgr_enable(mgr->id, false);
986 spin_lock_irqsave(&data_lock, flags);
988 mp->updating = false;
989 mp->enabled = false;
991 spin_unlock_irqrestore(&data_lock, flags);
993 out:
994 mutex_unlock(&apply_lock);
997 int dss_mgr_set_info(struct omap_overlay_manager *mgr,
998 struct omap_overlay_manager_info *info)
1000 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1001 unsigned long flags;
1002 int r;
1004 r = dss_mgr_simple_check(mgr, info);
1005 if (r)
1006 return r;
1008 spin_lock_irqsave(&data_lock, flags);
1010 mp->user_info = *info;
1011 mp->user_info_dirty = true;
1013 spin_unlock_irqrestore(&data_lock, flags);
1015 return 0;
1018 void dss_mgr_get_info(struct omap_overlay_manager *mgr,
1019 struct omap_overlay_manager_info *info)
1021 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1022 unsigned long flags;
1024 spin_lock_irqsave(&data_lock, flags);
1026 *info = mp->user_info;
1028 spin_unlock_irqrestore(&data_lock, flags);
1031 int dss_mgr_set_device(struct omap_overlay_manager *mgr,
1032 struct omap_dss_device *dssdev)
1034 int r;
1036 mutex_lock(&apply_lock);
1038 if (dssdev->manager) {
1039 DSSERR("display '%s' already has a manager '%s'\n",
1040 dssdev->name, dssdev->manager->name);
1041 r = -EINVAL;
1042 goto err;
1045 if ((mgr->supported_displays & dssdev->type) == 0) {
1046 DSSERR("display '%s' does not support manager '%s'\n",
1047 dssdev->name, mgr->name);
1048 r = -EINVAL;
1049 goto err;
1052 dssdev->manager = mgr;
1053 mgr->device = dssdev;
1055 mutex_unlock(&apply_lock);
1057 return 0;
1058 err:
1059 mutex_unlock(&apply_lock);
1060 return r;
1063 int dss_mgr_unset_device(struct omap_overlay_manager *mgr)
1065 int r;
1067 mutex_lock(&apply_lock);
1069 if (!mgr->device) {
1070 DSSERR("failed to unset display, display not set.\n");
1071 r = -EINVAL;
1072 goto err;
1076 * Don't allow currently enabled displays to have the overlay manager
1077 * pulled out from underneath them
1079 if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED) {
1080 r = -EINVAL;
1081 goto err;
1084 mgr->device->manager = NULL;
1085 mgr->device = NULL;
1087 mutex_unlock(&apply_lock);
1089 return 0;
1090 err:
1091 mutex_unlock(&apply_lock);
1092 return r;
1096 int dss_ovl_set_info(struct omap_overlay *ovl,
1097 struct omap_overlay_info *info)
1099 struct ovl_priv_data *op = get_ovl_priv(ovl);
1100 unsigned long flags;
1101 int r;
1103 r = dss_ovl_simple_check(ovl, info);
1104 if (r)
1105 return r;
1107 spin_lock_irqsave(&data_lock, flags);
1109 op->user_info = *info;
1110 op->user_info_dirty = true;
1112 spin_unlock_irqrestore(&data_lock, flags);
1114 return 0;
1117 void dss_ovl_get_info(struct omap_overlay *ovl,
1118 struct omap_overlay_info *info)
1120 struct ovl_priv_data *op = get_ovl_priv(ovl);
1121 unsigned long flags;
1123 spin_lock_irqsave(&data_lock, flags);
1125 *info = op->user_info;
1127 spin_unlock_irqrestore(&data_lock, flags);
1130 int dss_ovl_set_manager(struct omap_overlay *ovl,
1131 struct omap_overlay_manager *mgr)
1133 struct ovl_priv_data *op = get_ovl_priv(ovl);
1134 unsigned long flags;
1135 int r;
1137 if (!mgr)
1138 return -EINVAL;
1140 mutex_lock(&apply_lock);
1142 if (ovl->manager) {
1143 DSSERR("overlay '%s' already has a manager '%s'\n",
1144 ovl->name, ovl->manager->name);
1145 r = -EINVAL;
1146 goto err;
1149 spin_lock_irqsave(&data_lock, flags);
1151 if (op->enabled) {
1152 spin_unlock_irqrestore(&data_lock, flags);
1153 DSSERR("overlay has to be disabled to change the manager\n");
1154 r = -EINVAL;
1155 goto err;
1158 op->channel = mgr->id;
1159 op->extra_info_dirty = true;
1161 ovl->manager = mgr;
1162 list_add_tail(&ovl->list, &mgr->overlays);
1164 spin_unlock_irqrestore(&data_lock, flags);
1166 /* XXX: When there is an overlay on a DSI manual update display, and
1167 * the overlay is first disabled, then moved to tv, and enabled, we
1168 * seem to get SYNC_LOST_DIGIT error.
1170 * Waiting doesn't seem to help, but updating the manual update display
1171 * after disabling the overlay seems to fix this. This hints that the
1172 * overlay is perhaps somehow tied to the LCD output until the output
1173 * is updated.
1175 * Userspace workaround for this is to update the LCD after disabling
1176 * the overlay, but before moving the overlay to TV.
1179 mutex_unlock(&apply_lock);
1181 return 0;
1182 err:
1183 mutex_unlock(&apply_lock);
1184 return r;
1187 int dss_ovl_unset_manager(struct omap_overlay *ovl)
1189 struct ovl_priv_data *op = get_ovl_priv(ovl);
1190 unsigned long flags;
1191 int r;
1193 mutex_lock(&apply_lock);
1195 if (!ovl->manager) {
1196 DSSERR("failed to detach overlay: manager not set\n");
1197 r = -EINVAL;
1198 goto err;
1201 spin_lock_irqsave(&data_lock, flags);
1203 if (op->enabled) {
1204 spin_unlock_irqrestore(&data_lock, flags);
1205 DSSERR("overlay has to be disabled to unset the manager\n");
1206 r = -EINVAL;
1207 goto err;
1210 op->channel = -1;
1212 ovl->manager = NULL;
1213 list_del(&ovl->list);
1215 spin_unlock_irqrestore(&data_lock, flags);
1217 mutex_unlock(&apply_lock);
1219 return 0;
1220 err:
1221 mutex_unlock(&apply_lock);
1222 return r;
1225 bool dss_ovl_is_enabled(struct omap_overlay *ovl)
1227 struct ovl_priv_data *op = get_ovl_priv(ovl);
1228 unsigned long flags;
1229 bool e;
1231 spin_lock_irqsave(&data_lock, flags);
1233 e = op->enabled;
1235 spin_unlock_irqrestore(&data_lock, flags);
1237 return e;
1240 int dss_ovl_enable(struct omap_overlay *ovl)
1242 struct ovl_priv_data *op = get_ovl_priv(ovl);
1243 unsigned long flags;
1244 int r;
1246 mutex_lock(&apply_lock);
1248 if (op->enabled) {
1249 r = 0;
1250 goto err1;
1253 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1254 r = -EINVAL;
1255 goto err1;
1258 spin_lock_irqsave(&data_lock, flags);
1260 op->enabling = true;
1262 r = dss_check_settings(ovl->manager, ovl->manager->device);
1263 if (r) {
1264 DSSERR("failed to enable overlay %d: check_settings failed\n",
1265 ovl->id);
1266 goto err2;
1269 dss_setup_fifos();
1271 op->enabling = false;
1272 dss_apply_ovl_enable(ovl, true);
1274 dss_write_regs();
1275 dss_set_go_bits();
1277 spin_unlock_irqrestore(&data_lock, flags);
1279 /* wait for overlay to be enabled */
1280 wait_pending_extra_info_updates();
1282 mutex_unlock(&apply_lock);
1284 return 0;
1285 err2:
1286 op->enabling = false;
1287 spin_unlock_irqrestore(&data_lock, flags);
1288 err1:
1289 mutex_unlock(&apply_lock);
1290 return r;
1293 int dss_ovl_disable(struct omap_overlay *ovl)
1295 struct ovl_priv_data *op = get_ovl_priv(ovl);
1296 unsigned long flags;
1297 int r;
1299 mutex_lock(&apply_lock);
1301 if (!op->enabled) {
1302 r = 0;
1303 goto err;
1306 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1307 r = -EINVAL;
1308 goto err;
1311 spin_lock_irqsave(&data_lock, flags);
1313 dss_apply_ovl_enable(ovl, false);
1314 dss_write_regs();
1315 dss_set_go_bits();
1317 spin_unlock_irqrestore(&data_lock, flags);
1319 /* wait for the overlay to be disabled */
1320 wait_pending_extra_info_updates();
1322 mutex_unlock(&apply_lock);
1324 return 0;
1326 err:
1327 mutex_unlock(&apply_lock);
1328 return r;