Full support for Ginger Console
[linux-ginger.git] / drivers / video / omap2 / dss / manager.c
blob27d9c465c8518554cdcdb5f1ff046bd491bcdde6
1 /*
2 * linux/drivers/video/omap2/dss/manager.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
23 #define DSS_SUBSYS_NAME "MANAGER"
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/spinlock.h>
29 #include <linux/jiffies.h>
31 #include <plat/display.h>
32 #include <plat/cpu.h>
34 #include "dss.h"
36 static int num_managers;
37 static struct list_head manager_list;
39 static ssize_t manager_name_show(struct omap_overlay_manager *mgr, char *buf)
41 return snprintf(buf, PAGE_SIZE, "%s\n", mgr->name);
44 static ssize_t manager_display_show(struct omap_overlay_manager *mgr, char *buf)
46 return snprintf(buf, PAGE_SIZE, "%s\n",
47 mgr->device ? mgr->device->name : "<none>");
50 static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
51 const char *buf, size_t size)
53 int r = 0;
54 size_t len = size;
55 struct omap_dss_device *dssdev = NULL;
57 int match(struct omap_dss_device *dssdev, void *data)
59 const char *str = data;
60 return sysfs_streq(dssdev->name, str);
63 if (buf[size-1] == '\n')
64 --len;
66 if (len > 0)
67 dssdev = omap_dss_find_device((void *)buf, match);
69 if (len > 0 && dssdev == NULL)
70 return -EINVAL;
72 if (dssdev)
73 DSSDBG("display %s found\n", dssdev->name);
75 if (mgr->device) {
76 r = mgr->unset_device(mgr);
77 if (r) {
78 DSSERR("failed to unset display\n");
79 goto put_device;
83 if (dssdev) {
84 r = mgr->set_device(mgr, dssdev);
85 if (r) {
86 DSSERR("failed to set manager\n");
87 goto put_device;
90 r = mgr->apply(mgr);
91 if (r) {
92 DSSERR("failed to apply dispc config\n");
93 goto put_device;
97 put_device:
98 if (dssdev)
99 omap_dss_put_device(dssdev);
101 return r ? r : size;
104 static ssize_t manager_default_color_show(struct omap_overlay_manager *mgr,
105 char *buf)
107 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.default_color);
110 static ssize_t manager_default_color_store(struct omap_overlay_manager *mgr,
111 const char *buf, size_t size)
113 struct omap_overlay_manager_info info;
114 u32 color;
115 int r;
117 if (sscanf(buf, "%d", &color) != 1)
118 return -EINVAL;
120 mgr->get_manager_info(mgr, &info);
122 info.default_color = color;
124 r = mgr->set_manager_info(mgr, &info);
125 if (r)
126 return r;
128 r = mgr->apply(mgr);
129 if (r)
130 return r;
132 return size;
135 static const char *trans_key_type_str[] = {
136 "gfx-destination",
137 "video-source",
140 static ssize_t manager_trans_key_type_show(struct omap_overlay_manager *mgr,
141 char *buf)
143 enum omap_dss_trans_key_type key_type;
145 key_type = mgr->info.trans_key_type;
146 BUG_ON(key_type >= ARRAY_SIZE(trans_key_type_str));
148 return snprintf(buf, PAGE_SIZE, "%s\n", trans_key_type_str[key_type]);
151 static ssize_t manager_trans_key_type_store(struct omap_overlay_manager *mgr,
152 const char *buf, size_t size)
154 enum omap_dss_trans_key_type key_type;
155 struct omap_overlay_manager_info info;
156 int r;
158 for (key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
159 key_type < ARRAY_SIZE(trans_key_type_str); key_type++) {
160 if (sysfs_streq(buf, trans_key_type_str[key_type]))
161 break;
164 if (key_type == ARRAY_SIZE(trans_key_type_str))
165 return -EINVAL;
167 mgr->get_manager_info(mgr, &info);
169 info.trans_key_type = key_type;
171 r = mgr->set_manager_info(mgr, &info);
172 if (r)
173 return r;
175 r = mgr->apply(mgr);
176 if (r)
177 return r;
179 return size;
182 static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
183 char *buf)
185 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_key);
188 static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
189 const char *buf, size_t size)
191 struct omap_overlay_manager_info info;
192 u32 key_value;
193 int r;
195 if (sscanf(buf, "%d", &key_value) != 1)
196 return -EINVAL;
198 mgr->get_manager_info(mgr, &info);
200 info.trans_key = key_value;
202 r = mgr->set_manager_info(mgr, &info);
203 if (r)
204 return r;
206 r = mgr->apply(mgr);
207 if (r)
208 return r;
210 return size;
213 static ssize_t manager_trans_key_enabled_show(struct omap_overlay_manager *mgr,
214 char *buf)
216 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_enabled);
219 static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
220 const char *buf, size_t size)
222 struct omap_overlay_manager_info info;
223 int enable;
224 int r;
226 if (sscanf(buf, "%d", &enable) != 1)
227 return -EINVAL;
229 mgr->get_manager_info(mgr, &info);
231 info.trans_enabled = enable ? true : false;
233 r = mgr->set_manager_info(mgr, &info);
234 if (r)
235 return r;
237 r = mgr->apply(mgr);
238 if (r)
239 return r;
241 return size;
244 static ssize_t manager_alpha_blending_enabled_show(
245 struct omap_overlay_manager *mgr, char *buf)
247 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.alpha_enabled);
250 static ssize_t manager_alpha_blending_enabled_store(
251 struct omap_overlay_manager *mgr,
252 const char *buf, size_t size)
254 struct omap_overlay_manager_info info;
255 int enable;
256 int r;
258 if (sscanf(buf, "%d", &enable) != 1)
259 return -EINVAL;
261 mgr->get_manager_info(mgr, &info);
263 info.alpha_enabled = enable ? true : false;
265 r = mgr->set_manager_info(mgr, &info);
266 if (r)
267 return r;
269 r = mgr->apply(mgr);
270 if (r)
271 return r;
273 return size;
276 struct manager_attribute {
277 struct attribute attr;
278 ssize_t (*show)(struct omap_overlay_manager *, char *);
279 ssize_t (*store)(struct omap_overlay_manager *, const char *, size_t);
282 #define MANAGER_ATTR(_name, _mode, _show, _store) \
283 struct manager_attribute manager_attr_##_name = \
284 __ATTR(_name, _mode, _show, _store)
286 static MANAGER_ATTR(name, S_IRUGO, manager_name_show, NULL);
287 static MANAGER_ATTR(display, S_IRUGO|S_IWUSR,
288 manager_display_show, manager_display_store);
289 static MANAGER_ATTR(default_color, S_IRUGO|S_IWUSR,
290 manager_default_color_show, manager_default_color_store);
291 static MANAGER_ATTR(trans_key_type, S_IRUGO|S_IWUSR,
292 manager_trans_key_type_show, manager_trans_key_type_store);
293 static MANAGER_ATTR(trans_key_value, S_IRUGO|S_IWUSR,
294 manager_trans_key_value_show, manager_trans_key_value_store);
295 static MANAGER_ATTR(trans_key_enabled, S_IRUGO|S_IWUSR,
296 manager_trans_key_enabled_show,
297 manager_trans_key_enabled_store);
298 static MANAGER_ATTR(alpha_blending_enabled, S_IRUGO|S_IWUSR,
299 manager_alpha_blending_enabled_show,
300 manager_alpha_blending_enabled_store);
303 static struct attribute *manager_sysfs_attrs[] = {
304 &manager_attr_name.attr,
305 &manager_attr_display.attr,
306 &manager_attr_default_color.attr,
307 &manager_attr_trans_key_type.attr,
308 &manager_attr_trans_key_value.attr,
309 &manager_attr_trans_key_enabled.attr,
310 &manager_attr_alpha_blending_enabled.attr,
311 NULL
314 static ssize_t manager_attr_show(struct kobject *kobj, struct attribute *attr,
315 char *buf)
317 struct omap_overlay_manager *manager;
318 struct manager_attribute *manager_attr;
320 manager = container_of(kobj, struct omap_overlay_manager, kobj);
321 manager_attr = container_of(attr, struct manager_attribute, attr);
323 if (!manager_attr->show)
324 return -ENOENT;
326 return manager_attr->show(manager, buf);
329 static ssize_t manager_attr_store(struct kobject *kobj, struct attribute *attr,
330 const char *buf, size_t size)
332 struct omap_overlay_manager *manager;
333 struct manager_attribute *manager_attr;
335 manager = container_of(kobj, struct omap_overlay_manager, kobj);
336 manager_attr = container_of(attr, struct manager_attribute, attr);
338 if (!manager_attr->store)
339 return -ENOENT;
341 return manager_attr->store(manager, buf, size);
344 static struct sysfs_ops manager_sysfs_ops = {
345 .show = manager_attr_show,
346 .store = manager_attr_store,
349 static struct kobj_type manager_ktype = {
350 .sysfs_ops = &manager_sysfs_ops,
351 .default_attrs = manager_sysfs_attrs,
355 * We have 4 levels of cache for the dispc settings. First two are in SW and
356 * the latter two in HW.
358 * +--------------------+
359 * |overlay/manager_info|
360 * +--------------------+
362 * apply()
364 * +--------------------+
365 * | dss_cache |
366 * +--------------------+
368 * configure()
370 * +--------------------+
371 * | shadow registers |
372 * +--------------------+
374 * VFP or lcd/digit_enable
376 * +--------------------+
377 * | registers |
378 * +--------------------+
381 struct overlay_cache_data {
382 /* If true, cache changed, but not written to shadow registers. Set
383 * in apply(), cleared when registers written. */
384 bool dirty;
385 /* If true, shadow registers contain changed values not yet in real
386 * registers. Set when writing to shadow registers, cleared at
387 * VSYNC/EVSYNC */
388 bool shadow_dirty;
390 bool enabled;
392 u32 paddr;
393 void __iomem *vaddr;
394 u16 screen_width;
395 u16 width;
396 u16 height;
397 enum omap_color_mode color_mode;
398 u8 rotation;
399 enum omap_dss_rotation_type rotation_type;
400 bool mirror;
402 u16 pos_x;
403 u16 pos_y;
404 u16 out_width; /* if 0, out_width == width */
405 u16 out_height; /* if 0, out_height == height */
406 u8 global_alpha;
408 enum omap_channel channel;
409 bool replication;
410 bool ilace;
412 enum omap_burst_size burst_size;
413 u32 fifo_low;
414 u32 fifo_high;
416 bool manual_update;
419 struct manager_cache_data {
420 /* If true, cache changed, but not written to shadow registers. Set
421 * in apply(), cleared when registers written. */
422 bool dirty;
423 /* If true, shadow registers contain changed values not yet in real
424 * registers. Set when writing to shadow registers, cleared at
425 * VSYNC/EVSYNC */
426 bool shadow_dirty;
428 u32 default_color;
430 enum omap_dss_trans_key_type trans_key_type;
431 u32 trans_key;
432 bool trans_enabled;
434 bool alpha_enabled;
436 bool manual_upd_display;
437 bool manual_update;
438 bool do_manual_update;
440 /* manual update region */
441 u16 x, y, w, h;
444 static struct {
445 spinlock_t lock;
446 struct overlay_cache_data overlay_cache[3];
447 struct manager_cache_data manager_cache[2];
449 bool irq_enabled;
450 } dss_cache;
454 static int omap_dss_set_device(struct omap_overlay_manager *mgr,
455 struct omap_dss_device *dssdev)
457 int i;
458 int r;
460 if (dssdev->manager) {
461 DSSERR("display '%s' already has a manager '%s'\n",
462 dssdev->name, dssdev->manager->name);
463 return -EINVAL;
466 if ((mgr->supported_displays & dssdev->type) == 0) {
467 DSSERR("display '%s' does not support manager '%s'\n",
468 dssdev->name, mgr->name);
469 return -EINVAL;
472 for (i = 0; i < mgr->num_overlays; i++) {
473 struct omap_overlay *ovl = mgr->overlays[i];
475 if (ovl->manager != mgr || !ovl->info.enabled)
476 continue;
478 r = dss_check_overlay(ovl, dssdev);
479 if (r)
480 return r;
483 dssdev->manager = mgr;
484 mgr->device = dssdev;
485 mgr->device_changed = true;
487 return 0;
490 static int omap_dss_unset_device(struct omap_overlay_manager *mgr)
492 if (!mgr->device) {
493 DSSERR("failed to unset display, display not set.\n");
494 return -EINVAL;
497 mgr->device->manager = NULL;
498 mgr->device = NULL;
499 mgr->device_changed = true;
501 return 0;
504 static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
506 unsigned long timeout = msecs_to_jiffies(500);
507 struct manager_cache_data *mc;
508 enum omap_channel channel;
509 u32 irq;
510 int r;
511 int i;
513 if (!mgr->device)
514 return 0;
516 if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC) {
517 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
518 channel = OMAP_DSS_CHANNEL_DIGIT;
519 } else {
520 if (mgr->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
521 enum omap_dss_update_mode mode;
522 mode = mgr->device->get_update_mode(mgr->device);
523 if (mode != OMAP_DSS_UPDATE_AUTO)
524 return 0;
526 irq = DISPC_IRQ_FRAMEDONE;
527 } else {
528 irq = DISPC_IRQ_VSYNC;
530 channel = OMAP_DSS_CHANNEL_LCD;
533 mc = &dss_cache.manager_cache[mgr->id];
534 i = 0;
535 while (1) {
536 unsigned long flags;
537 bool shadow_dirty, dirty;
539 spin_lock_irqsave(&dss_cache.lock, flags);
540 dirty = mc->dirty;
541 shadow_dirty = mc->shadow_dirty;
542 spin_unlock_irqrestore(&dss_cache.lock, flags);
544 if (!dirty && !shadow_dirty) {
545 r = 0;
546 break;
549 /* 4 iterations is the worst case:
550 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
551 * 2 - first VSYNC, dirty = true
552 * 3 - dirty = false, shadow_dirty = true
553 * 4 - shadow_dirty = false */
554 if (i++ == 3) {
555 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
556 mgr->id);
557 r = 0;
558 break;
561 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
562 if (r == -ERESTARTSYS)
563 break;
565 if (r) {
566 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
567 break;
571 return r;
574 int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
576 unsigned long timeout = msecs_to_jiffies(500);
577 enum omap_channel channel;
578 struct overlay_cache_data *oc;
579 struct omap_dss_device *dssdev;
580 u32 irq;
581 int r;
582 int i;
584 if (!ovl->manager || !ovl->manager->device)
585 return 0;
587 dssdev = ovl->manager->device;
589 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) {
590 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
591 channel = OMAP_DSS_CHANNEL_DIGIT;
592 } else {
593 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
594 enum omap_dss_update_mode mode;
595 mode = dssdev->get_update_mode(dssdev);
596 if (mode != OMAP_DSS_UPDATE_AUTO)
597 return 0;
599 irq = DISPC_IRQ_FRAMEDONE;
600 } else {
601 irq = DISPC_IRQ_VSYNC;
603 channel = OMAP_DSS_CHANNEL_LCD;
606 oc = &dss_cache.overlay_cache[ovl->id];
607 i = 0;
608 while (1) {
609 unsigned long flags;
610 bool shadow_dirty, dirty;
612 spin_lock_irqsave(&dss_cache.lock, flags);
613 dirty = oc->dirty;
614 shadow_dirty = oc->shadow_dirty;
615 spin_unlock_irqrestore(&dss_cache.lock, flags);
617 if (!dirty && !shadow_dirty) {
618 r = 0;
619 break;
622 /* 4 iterations is the worst case:
623 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
624 * 2 - first VSYNC, dirty = true
625 * 3 - dirty = false, shadow_dirty = true
626 * 4 - shadow_dirty = false */
627 if (i++ == 3) {
628 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
629 ovl->id);
630 r = 0;
631 break;
634 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
635 if (r == -ERESTARTSYS)
636 break;
638 if (r) {
639 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
640 break;
644 return r;
647 static int overlay_enabled(struct omap_overlay *ovl)
649 return ovl->info.enabled && ovl->manager && ovl->manager->device;
652 /* Is rect1 a subset of rect2? */
653 static bool rectangle_subset(int x1, int y1, int w1, int h1,
654 int x2, int y2, int w2, int h2)
656 if (x1 < x2 || y1 < y2)
657 return false;
659 if (x1 + w1 > x2 + w2)
660 return false;
662 if (y1 + h1 > y2 + h2)
663 return false;
665 return true;
668 /* Do rect1 and rect2 overlap? */
669 static bool rectangle_intersects(int x1, int y1, int w1, int h1,
670 int x2, int y2, int w2, int h2)
672 if (x1 >= x2 + w2)
673 return false;
675 if (x2 >= x1 + w1)
676 return false;
678 if (y1 >= y2 + h2)
679 return false;
681 if (y2 >= y1 + h1)
682 return false;
684 return true;
687 static bool dispc_is_overlay_scaled(struct overlay_cache_data *oc)
689 if (oc->out_width != 0 && oc->width != oc->out_width)
690 return true;
692 if (oc->out_height != 0 && oc->height != oc->out_height)
693 return true;
695 return false;
698 static int configure_overlay(enum omap_plane plane)
700 struct overlay_cache_data *c;
701 struct manager_cache_data *mc;
702 u16 outw, outh;
703 u16 x, y, w, h;
704 u32 paddr;
705 int r;
707 DSSDBGF("%d", plane);
709 c = &dss_cache.overlay_cache[plane];
711 if (!c->enabled) {
712 dispc_enable_plane(plane, 0);
713 return 0;
716 mc = &dss_cache.manager_cache[c->channel];
718 x = c->pos_x;
719 y = c->pos_y;
720 w = c->width;
721 h = c->height;
722 outw = c->out_width == 0 ? c->width : c->out_width;
723 outh = c->out_height == 0 ? c->height : c->out_height;
724 paddr = c->paddr;
726 if (c->manual_update && mc->do_manual_update) {
727 unsigned bpp;
728 /* If the overlay is outside the update region, disable it */
729 if (!rectangle_intersects(mc->x, mc->y, mc->w, mc->h,
730 x, y, outw, outh)) {
731 dispc_enable_plane(plane, 0);
732 return 0;
735 switch (c->color_mode) {
736 case OMAP_DSS_COLOR_RGB16:
737 case OMAP_DSS_COLOR_ARGB16:
738 case OMAP_DSS_COLOR_YUV2:
739 case OMAP_DSS_COLOR_UYVY:
740 bpp = 16;
741 break;
743 case OMAP_DSS_COLOR_RGB24P:
744 bpp = 24;
745 break;
747 case OMAP_DSS_COLOR_RGB24U:
748 case OMAP_DSS_COLOR_ARGB32:
749 case OMAP_DSS_COLOR_RGBA32:
750 case OMAP_DSS_COLOR_RGBX32:
751 bpp = 32;
752 break;
754 default:
755 BUG();
758 if (dispc_is_overlay_scaled(c)) {
759 /* If the overlay is scaled, the update area has
760 * already been enlarged to cover the whole overlay. We
761 * only need to adjust x/y here */
762 x = c->pos_x - mc->x;
763 y = c->pos_y - mc->y;
764 } else {
765 if (mc->x > c->pos_x) {
766 x = 0;
767 w -= (mc->x - c->pos_x);
768 paddr += (mc->x - c->pos_x) * bpp / 8;
769 } else {
770 x = c->pos_x - mc->x;
773 if (mc->y > c->pos_y) {
774 y = 0;
775 h -= (mc->y - c->pos_y);
776 paddr += (mc->y - c->pos_y) * c->screen_width *
777 bpp / 8;
778 } else {
779 y = c->pos_y - mc->y;
782 if (mc->w < (x+w))
783 w -= (x+w) - (mc->w);
785 if (mc->h < (y+h))
786 h -= (y+h) - (mc->h);
788 outw = w;
789 outh = h;
793 r = dispc_setup_plane(plane,
794 paddr,
795 c->screen_width,
796 x, y,
797 w, h,
798 outw, outh,
799 c->color_mode,
800 c->ilace,
801 c->rotation_type,
802 c->rotation,
803 c->mirror,
804 c->global_alpha);
806 if (r) {
807 /* this shouldn't happen */
808 DSSERR("dispc_setup_plane failed for ovl %d\n", plane);
809 dispc_enable_plane(plane, 0);
810 return r;
813 dispc_enable_replication(plane, c->replication);
815 dispc_set_burst_size(plane, c->burst_size);
816 dispc_setup_plane_fifo(plane, c->fifo_low, c->fifo_high);
818 dispc_enable_plane(plane, 1);
820 return 0;
823 static void configure_manager(enum omap_channel channel)
825 struct manager_cache_data *c;
827 DSSDBGF("%d", channel);
829 c = &dss_cache.manager_cache[channel];
831 dispc_set_trans_key(channel, c->trans_key_type, c->trans_key);
832 dispc_enable_trans_key(channel, c->trans_enabled);
833 dispc_enable_alpha_blending(channel, c->alpha_enabled);
836 /* configure_dispc() tries to write values from cache to shadow registers.
837 * It writes only to those managers/overlays that are not busy.
838 * returns 0 if everything could be written to shadow registers.
839 * returns 1 if not everything could be written to shadow registers. */
840 static int configure_dispc(void)
842 struct overlay_cache_data *oc;
843 struct manager_cache_data *mc;
844 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
845 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
846 int i;
847 int r;
848 bool mgr_busy[2];
849 bool mgr_go[2];
850 bool busy;
852 r = 0;
853 busy = false;
855 mgr_busy[0] = dispc_go_busy(0);
856 mgr_busy[1] = dispc_go_busy(1);
857 mgr_go[0] = false;
858 mgr_go[1] = false;
860 /* Commit overlay settings */
861 for (i = 0; i < num_ovls; ++i) {
862 oc = &dss_cache.overlay_cache[i];
863 mc = &dss_cache.manager_cache[oc->channel];
865 if (!oc->dirty)
866 continue;
868 if (oc->manual_update && !mc->do_manual_update)
869 continue;
871 if (mgr_busy[oc->channel]) {
872 busy = true;
873 continue;
876 r = configure_overlay(i);
877 if (r)
878 DSSERR("configure_overlay %d failed\n", i);
880 oc->dirty = false;
881 oc->shadow_dirty = true;
882 mgr_go[oc->channel] = true;
885 /* Commit manager settings */
886 for (i = 0; i < num_mgrs; ++i) {
887 mc = &dss_cache.manager_cache[i];
889 if (!mc->dirty)
890 continue;
892 if (mc->manual_update && !mc->do_manual_update)
893 continue;
895 if (mgr_busy[i]) {
896 busy = true;
897 continue;
900 configure_manager(i);
901 mc->dirty = false;
902 mc->shadow_dirty = true;
903 mgr_go[i] = true;
906 /* set GO */
907 for (i = 0; i < num_mgrs; ++i) {
908 mc = &dss_cache.manager_cache[i];
910 if (!mgr_go[i])
911 continue;
913 /* We don't need GO with manual update display. LCD iface will
914 * always be turned off after frame, and new settings will be
915 * taken in to use at next update */
916 if (!mc->manual_upd_display)
917 dispc_go(i);
920 if (busy)
921 r = 1;
922 else
923 r = 0;
925 return r;
928 /* Configure dispc for partial update. Return possibly modified update
929 * area */
930 void dss_setup_partial_planes(struct omap_dss_device *dssdev,
931 u16 *xi, u16 *yi, u16 *wi, u16 *hi)
933 struct overlay_cache_data *oc;
934 struct manager_cache_data *mc;
935 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
936 struct omap_overlay_manager *mgr;
937 int i;
938 u16 x, y, w, h;
939 unsigned long flags;
941 x = *xi;
942 y = *yi;
943 w = *wi;
944 h = *hi;
946 DSSDBG("dispc_setup_partial_planes %d,%d %dx%d\n",
947 *xi, *yi, *wi, *hi);
949 mgr = dssdev->manager;
951 if (!mgr) {
952 DSSDBG("no manager\n");
953 return;
956 spin_lock_irqsave(&dss_cache.lock, flags);
958 /* We need to show the whole overlay if it is scaled. So look for
959 * those, and make the update area larger if found.
960 * Also mark the overlay cache dirty */
961 for (i = 0; i < num_ovls; ++i) {
962 unsigned x1, y1, x2, y2;
963 unsigned outw, outh;
965 oc = &dss_cache.overlay_cache[i];
967 if (oc->channel != mgr->id)
968 continue;
970 oc->dirty = true;
972 if (!oc->enabled)
973 continue;
975 if (!dispc_is_overlay_scaled(oc))
976 continue;
978 outw = oc->out_width == 0 ? oc->width : oc->out_width;
979 outh = oc->out_height == 0 ? oc->height : oc->out_height;
981 /* is the overlay outside the update region? */
982 if (!rectangle_intersects(x, y, w, h,
983 oc->pos_x, oc->pos_y,
984 outw, outh))
985 continue;
987 /* if the overlay totally inside the update region? */
988 if (rectangle_subset(oc->pos_x, oc->pos_y, outw, outh,
989 x, y, w, h))
990 continue;
992 if (x > oc->pos_x)
993 x1 = oc->pos_x;
994 else
995 x1 = x;
997 if (y > oc->pos_y)
998 y1 = oc->pos_y;
999 else
1000 y1 = y;
1002 if ((x + w) < (oc->pos_x + outw))
1003 x2 = oc->pos_x + outw;
1004 else
1005 x2 = x + w;
1007 if ((y + h) < (oc->pos_y + outh))
1008 y2 = oc->pos_y + outh;
1009 else
1010 y2 = y + h;
1012 x = x1;
1013 y = y1;
1014 w = x2 - x1;
1015 h = y2 - y1;
1017 DSSDBG("changing upd area due to ovl(%d) scaling %d,%d %dx%d\n",
1018 i, x, y, w, h);
1021 mc = &dss_cache.manager_cache[mgr->id];
1022 mc->do_manual_update = true;
1023 mc->x = x;
1024 mc->y = y;
1025 mc->w = w;
1026 mc->h = h;
1028 configure_dispc();
1030 mc->do_manual_update = false;
1032 spin_unlock_irqrestore(&dss_cache.lock, flags);
1034 *xi = x;
1035 *yi = y;
1036 *wi = w;
1037 *hi = h;
1040 void dss_start_update(struct omap_dss_device *dssdev)
1042 struct manager_cache_data *mc;
1043 struct overlay_cache_data *oc;
1044 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
1045 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
1046 struct omap_overlay_manager *mgr;
1047 int i;
1049 mgr = dssdev->manager;
1051 for (i = 0; i < num_ovls; ++i) {
1052 oc = &dss_cache.overlay_cache[i];
1053 if (oc->channel != mgr->id)
1054 continue;
1056 oc->shadow_dirty = false;
1059 for (i = 0; i < num_mgrs; ++i) {
1060 mc = &dss_cache.manager_cache[i];
1061 if (mgr->id != i)
1062 continue;
1064 mc->shadow_dirty = false;
1067 dispc_enable_lcd_out(1);
1070 static void dss_apply_irq_handler(void *data, u32 mask)
1072 struct manager_cache_data *mc;
1073 struct overlay_cache_data *oc;
1074 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
1075 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
1076 int i, r;
1077 bool mgr_busy[2];
1079 mgr_busy[0] = dispc_go_busy(0);
1080 mgr_busy[1] = dispc_go_busy(1);
1082 spin_lock(&dss_cache.lock);
1084 for (i = 0; i < num_ovls; ++i) {
1085 oc = &dss_cache.overlay_cache[i];
1086 if (!mgr_busy[oc->channel])
1087 oc->shadow_dirty = false;
1090 for (i = 0; i < num_mgrs; ++i) {
1091 mc = &dss_cache.manager_cache[i];
1092 if (!mgr_busy[i])
1093 mc->shadow_dirty = false;
1096 r = configure_dispc();
1097 if (r == 1)
1098 goto end;
1100 /* re-read busy flags */
1101 mgr_busy[0] = dispc_go_busy(0);
1102 mgr_busy[1] = dispc_go_busy(1);
1104 /* keep running as long as there are busy managers, so that
1105 * we can collect overlay-applied information */
1106 for (i = 0; i < num_mgrs; ++i) {
1107 if (mgr_busy[i])
1108 goto end;
1111 omap_dispc_unregister_isr(dss_apply_irq_handler, NULL,
1112 DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1113 DISPC_IRQ_EVSYNC_EVEN);
1114 dss_cache.irq_enabled = false;
1116 end:
1117 spin_unlock(&dss_cache.lock);
1120 static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
1122 struct overlay_cache_data *oc;
1123 struct manager_cache_data *mc;
1124 int i;
1125 struct omap_overlay *ovl;
1126 int num_planes_enabled = 0;
1127 bool use_fifomerge;
1128 unsigned long flags;
1129 int r;
1131 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
1133 spin_lock_irqsave(&dss_cache.lock, flags);
1135 /* Configure overlays */
1136 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1137 struct omap_dss_device *dssdev;
1139 ovl = omap_dss_get_overlay(i);
1141 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1142 continue;
1144 oc = &dss_cache.overlay_cache[ovl->id];
1146 if (!overlay_enabled(ovl)) {
1147 if (oc->enabled) {
1148 oc->enabled = false;
1149 oc->dirty = true;
1151 continue;
1154 if (!ovl->info_dirty) {
1155 if (oc->enabled)
1156 ++num_planes_enabled;
1157 continue;
1160 dssdev = ovl->manager->device;
1162 if (dss_check_overlay(ovl, dssdev)) {
1163 if (oc->enabled) {
1164 oc->enabled = false;
1165 oc->dirty = true;
1167 continue;
1170 ovl->info_dirty = false;
1171 oc->dirty = true;
1173 oc->paddr = ovl->info.paddr;
1174 oc->vaddr = ovl->info.vaddr;
1175 oc->screen_width = ovl->info.screen_width;
1176 oc->width = ovl->info.width;
1177 oc->height = ovl->info.height;
1178 oc->color_mode = ovl->info.color_mode;
1179 oc->rotation = ovl->info.rotation;
1180 oc->rotation_type = ovl->info.rotation_type;
1181 oc->mirror = ovl->info.mirror;
1182 oc->pos_x = ovl->info.pos_x;
1183 oc->pos_y = ovl->info.pos_y;
1184 oc->out_width = ovl->info.out_width;
1185 oc->out_height = ovl->info.out_height;
1186 oc->global_alpha = ovl->info.global_alpha;
1188 oc->replication =
1189 dss_use_replication(dssdev, ovl->info.color_mode);
1191 oc->ilace = dssdev->type == OMAP_DISPLAY_TYPE_VENC;
1193 oc->channel = ovl->manager->id;
1195 oc->enabled = true;
1197 oc->manual_update =
1198 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
1199 dssdev->get_update_mode(dssdev) != OMAP_DSS_UPDATE_AUTO;
1201 ++num_planes_enabled;
1204 /* Configure managers */
1205 list_for_each_entry(mgr, &manager_list, list) {
1206 struct omap_dss_device *dssdev;
1208 if (!(mgr->caps & OMAP_DSS_OVL_MGR_CAP_DISPC))
1209 continue;
1211 mc = &dss_cache.manager_cache[mgr->id];
1213 if (mgr->device_changed) {
1214 mgr->device_changed = false;
1215 mgr->info_dirty = true;
1218 if (!mgr->info_dirty)
1219 continue;
1221 if (!mgr->device)
1222 continue;
1224 dssdev = mgr->device;
1226 mgr->info_dirty = false;
1227 mc->dirty = true;
1229 mc->default_color = mgr->info.default_color;
1230 mc->trans_key_type = mgr->info.trans_key_type;
1231 mc->trans_key = mgr->info.trans_key;
1232 mc->trans_enabled = mgr->info.trans_enabled;
1233 mc->alpha_enabled = mgr->info.alpha_enabled;
1235 mc->manual_upd_display =
1236 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
1238 mc->manual_update =
1239 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
1240 dssdev->get_update_mode(dssdev) != OMAP_DSS_UPDATE_AUTO;
1243 /* XXX TODO: Try to get fifomerge working. The problem is that it
1244 * affects both managers, not individually but at the same time. This
1245 * means the change has to be well synchronized. I guess the proper way
1246 * is to have a two step process for fifo merge:
1247 * fifomerge enable:
1248 * 1. disable other planes, leaving one plane enabled
1249 * 2. wait until the planes are disabled on HW
1250 * 3. config merged fifo thresholds, enable fifomerge
1251 * fifomerge disable:
1252 * 1. config unmerged fifo thresholds, disable fifomerge
1253 * 2. wait until fifo changes are in HW
1254 * 3. enable planes
1256 use_fifomerge = false;
1258 /* Configure overlay fifos */
1259 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1260 struct omap_dss_device *dssdev;
1261 u32 size;
1263 ovl = omap_dss_get_overlay(i);
1265 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1266 continue;
1268 oc = &dss_cache.overlay_cache[ovl->id];
1270 if (!oc->enabled)
1271 continue;
1273 dssdev = ovl->manager->device;
1275 size = dispc_get_plane_fifo_size(ovl->id);
1276 if (use_fifomerge)
1277 size *= 3;
1279 switch (dssdev->type) {
1280 case OMAP_DISPLAY_TYPE_DPI:
1281 case OMAP_DISPLAY_TYPE_DBI:
1282 case OMAP_DISPLAY_TYPE_SDI:
1283 case OMAP_DISPLAY_TYPE_VENC:
1284 default_get_overlay_fifo_thresholds(ovl->id, size,
1285 &oc->burst_size, &oc->fifo_low,
1286 &oc->fifo_high);
1287 break;
1288 #ifdef CONFIG_OMAP2_DSS_DSI
1289 case OMAP_DISPLAY_TYPE_DSI:
1290 dsi_get_overlay_fifo_thresholds(ovl->id, size,
1291 &oc->burst_size, &oc->fifo_low,
1292 &oc->fifo_high);
1293 break;
1294 #endif
1295 default:
1296 BUG();
1300 r = 0;
1301 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
1302 if (!dss_cache.irq_enabled) {
1303 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL,
1304 DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1305 DISPC_IRQ_EVSYNC_EVEN);
1306 dss_cache.irq_enabled = true;
1308 configure_dispc();
1309 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
1311 spin_unlock_irqrestore(&dss_cache.lock, flags);
1313 return r;
1316 static int dss_check_manager(struct omap_overlay_manager *mgr)
1318 /* OMAP supports only graphics source transparency color key and alpha
1319 * blending simultaneously. See TRM 15.4.2.4.2.2 Alpha Mode */
1321 if (mgr->info.alpha_enabled && mgr->info.trans_enabled &&
1322 mgr->info.trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST)
1323 return -EINVAL;
1325 return 0;
1328 static int omap_dss_mgr_set_info(struct omap_overlay_manager *mgr,
1329 struct omap_overlay_manager_info *info)
1331 int r;
1332 struct omap_overlay_manager_info old_info;
1334 old_info = mgr->info;
1335 mgr->info = *info;
1337 r = dss_check_manager(mgr);
1338 if (r) {
1339 mgr->info = old_info;
1340 return r;
1343 mgr->info_dirty = true;
1345 return 0;
1348 static void omap_dss_mgr_get_info(struct omap_overlay_manager *mgr,
1349 struct omap_overlay_manager_info *info)
1351 *info = mgr->info;
1354 static void omap_dss_add_overlay_manager(struct omap_overlay_manager *manager)
1356 ++num_managers;
1357 list_add_tail(&manager->list, &manager_list);
1360 int dss_init_overlay_managers(struct platform_device *pdev)
1362 int i, r;
1364 spin_lock_init(&dss_cache.lock);
1366 INIT_LIST_HEAD(&manager_list);
1368 num_managers = 0;
1370 for (i = 0; i < 2; ++i) {
1371 struct omap_overlay_manager *mgr;
1372 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1374 BUG_ON(mgr == NULL);
1376 switch (i) {
1377 case 0:
1378 mgr->name = "lcd";
1379 mgr->id = OMAP_DSS_CHANNEL_LCD;
1380 mgr->supported_displays =
1381 OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
1382 OMAP_DISPLAY_TYPE_SDI | OMAP_DISPLAY_TYPE_DSI;
1383 break;
1384 case 1:
1385 mgr->name = "tv";
1386 mgr->id = OMAP_DSS_CHANNEL_DIGIT;
1387 mgr->supported_displays = OMAP_DISPLAY_TYPE_VENC;
1388 break;
1391 mgr->set_device = &omap_dss_set_device;
1392 mgr->unset_device = &omap_dss_unset_device;
1393 mgr->apply = &omap_dss_mgr_apply;
1394 mgr->set_manager_info = &omap_dss_mgr_set_info;
1395 mgr->get_manager_info = &omap_dss_mgr_get_info;
1396 mgr->wait_for_go = &dss_mgr_wait_for_go;
1398 mgr->caps = OMAP_DSS_OVL_MGR_CAP_DISPC;
1400 dss_overlay_setup_dispc_manager(mgr);
1402 omap_dss_add_overlay_manager(mgr);
1404 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1405 &pdev->dev.kobj, "manager%d", i);
1407 if (r) {
1408 DSSERR("failed to create sysfs file\n");
1409 continue;
1413 #ifdef L4_EXAMPLE
1415 int omap_dss_mgr_apply_l4(struct omap_overlay_manager *mgr)
1417 DSSDBG("omap_dss_mgr_apply_l4(%s)\n", mgr->name);
1419 return 0;
1422 struct omap_overlay_manager *mgr;
1423 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1425 BUG_ON(mgr == NULL);
1427 mgr->name = "l4";
1428 mgr->supported_displays =
1429 OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI;
1431 mgr->set_device = &omap_dss_set_device;
1432 mgr->unset_device = &omap_dss_unset_device;
1433 mgr->apply = &omap_dss_mgr_apply_l4;
1434 mgr->set_manager_info = &omap_dss_mgr_set_info;
1435 mgr->get_manager_info = &omap_dss_mgr_get_info;
1437 dss_overlay_setup_l4_manager(mgr);
1439 omap_dss_add_overlay_manager(mgr);
1441 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1442 &pdev->dev.kobj, "managerl4");
1444 if (r)
1445 DSSERR("failed to create sysfs file\n");
1447 #endif
1449 return 0;
1452 void dss_uninit_overlay_managers(struct platform_device *pdev)
1454 struct omap_overlay_manager *mgr;
1456 while (!list_empty(&manager_list)) {
1457 mgr = list_first_entry(&manager_list,
1458 struct omap_overlay_manager, list);
1459 list_del(&mgr->list);
1460 kobject_del(&mgr->kobj);
1461 kobject_put(&mgr->kobj);
1462 kfree(mgr);
1465 num_managers = 0;
1468 int omap_dss_get_num_overlay_managers(void)
1470 return num_managers;
1472 EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
1474 struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
1476 int i = 0;
1477 struct omap_overlay_manager *mgr;
1479 list_for_each_entry(mgr, &manager_list, list) {
1480 if (i++ == num)
1481 return mgr;
1484 return NULL;
1486 EXPORT_SYMBOL(omap_dss_get_overlay_manager);