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
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
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/slab.h>
27 #include <linux/module.h>
28 #include <linux/platform_device.h>
29 #include <linux/spinlock.h>
30 #include <linux/jiffies.h>
32 #include <plat/display.h>
37 static int num_managers;
38 static struct list_head manager_list;
40 static ssize_t manager_name_show(struct omap_overlay_manager *mgr, char *buf)
42 return snprintf(buf, PAGE_SIZE, "%s\n", mgr->name);
45 static ssize_t manager_display_show(struct omap_overlay_manager *mgr, char *buf)
47 return snprintf(buf, PAGE_SIZE, "%s\n",
48 mgr->device ? mgr->device->name : "<none>");
51 static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
52 const char *buf, size_t size)
56 struct omap_dss_device *dssdev = NULL;
58 int match(struct omap_dss_device *dssdev, void *data)
60 const char *str = data;
61 return sysfs_streq(dssdev->name, str);
64 if (buf[size-1] == '\n')
68 dssdev = omap_dss_find_device((void *)buf, match);
70 if (len > 0 && dssdev == NULL)
74 DSSDBG("display %s found\n", dssdev->name);
77 r = mgr->unset_device(mgr);
79 DSSERR("failed to unset display\n");
85 r = mgr->set_device(mgr, dssdev);
87 DSSERR("failed to set manager\n");
93 DSSERR("failed to apply dispc config\n");
100 omap_dss_put_device(dssdev);
105 static ssize_t manager_default_color_show(struct omap_overlay_manager *mgr,
108 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.default_color);
111 static ssize_t manager_default_color_store(struct omap_overlay_manager *mgr,
112 const char *buf, size_t size)
114 struct omap_overlay_manager_info info;
118 if (sscanf(buf, "%d", &color) != 1)
121 mgr->get_manager_info(mgr, &info);
123 info.default_color = color;
125 r = mgr->set_manager_info(mgr, &info);
136 static const char *trans_key_type_str[] = {
141 static ssize_t manager_trans_key_type_show(struct omap_overlay_manager *mgr,
144 enum omap_dss_trans_key_type key_type;
146 key_type = mgr->info.trans_key_type;
147 BUG_ON(key_type >= ARRAY_SIZE(trans_key_type_str));
149 return snprintf(buf, PAGE_SIZE, "%s\n", trans_key_type_str[key_type]);
152 static ssize_t manager_trans_key_type_store(struct omap_overlay_manager *mgr,
153 const char *buf, size_t size)
155 enum omap_dss_trans_key_type key_type;
156 struct omap_overlay_manager_info info;
159 for (key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
160 key_type < ARRAY_SIZE(trans_key_type_str); key_type++) {
161 if (sysfs_streq(buf, trans_key_type_str[key_type]))
165 if (key_type == ARRAY_SIZE(trans_key_type_str))
168 mgr->get_manager_info(mgr, &info);
170 info.trans_key_type = key_type;
172 r = mgr->set_manager_info(mgr, &info);
183 static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
186 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_key);
189 static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
190 const char *buf, size_t size)
192 struct omap_overlay_manager_info info;
196 if (sscanf(buf, "%d", &key_value) != 1)
199 mgr->get_manager_info(mgr, &info);
201 info.trans_key = key_value;
203 r = mgr->set_manager_info(mgr, &info);
214 static ssize_t manager_trans_key_enabled_show(struct omap_overlay_manager *mgr,
217 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_enabled);
220 static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
221 const char *buf, size_t size)
223 struct omap_overlay_manager_info info;
227 if (sscanf(buf, "%d", &enable) != 1)
230 mgr->get_manager_info(mgr, &info);
232 info.trans_enabled = enable ? true : false;
234 r = mgr->set_manager_info(mgr, &info);
245 static ssize_t manager_alpha_blending_enabled_show(
246 struct omap_overlay_manager *mgr, char *buf)
248 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.alpha_enabled);
251 static ssize_t manager_alpha_blending_enabled_store(
252 struct omap_overlay_manager *mgr,
253 const char *buf, size_t size)
255 struct omap_overlay_manager_info info;
259 if (sscanf(buf, "%d", &enable) != 1)
262 mgr->get_manager_info(mgr, &info);
264 info.alpha_enabled = enable ? true : false;
266 r = mgr->set_manager_info(mgr, &info);
277 struct manager_attribute {
278 struct attribute attr;
279 ssize_t (*show)(struct omap_overlay_manager *, char *);
280 ssize_t (*store)(struct omap_overlay_manager *, const char *, size_t);
283 #define MANAGER_ATTR(_name, _mode, _show, _store) \
284 struct manager_attribute manager_attr_##_name = \
285 __ATTR(_name, _mode, _show, _store)
287 static MANAGER_ATTR(name, S_IRUGO, manager_name_show, NULL);
288 static MANAGER_ATTR(display, S_IRUGO|S_IWUSR,
289 manager_display_show, manager_display_store);
290 static MANAGER_ATTR(default_color, S_IRUGO|S_IWUSR,
291 manager_default_color_show, manager_default_color_store);
292 static MANAGER_ATTR(trans_key_type, S_IRUGO|S_IWUSR,
293 manager_trans_key_type_show, manager_trans_key_type_store);
294 static MANAGER_ATTR(trans_key_value, S_IRUGO|S_IWUSR,
295 manager_trans_key_value_show, manager_trans_key_value_store);
296 static MANAGER_ATTR(trans_key_enabled, S_IRUGO|S_IWUSR,
297 manager_trans_key_enabled_show,
298 manager_trans_key_enabled_store);
299 static MANAGER_ATTR(alpha_blending_enabled, S_IRUGO|S_IWUSR,
300 manager_alpha_blending_enabled_show,
301 manager_alpha_blending_enabled_store);
304 static struct attribute *manager_sysfs_attrs[] = {
305 &manager_attr_name.attr,
306 &manager_attr_display.attr,
307 &manager_attr_default_color.attr,
308 &manager_attr_trans_key_type.attr,
309 &manager_attr_trans_key_value.attr,
310 &manager_attr_trans_key_enabled.attr,
311 &manager_attr_alpha_blending_enabled.attr,
315 static ssize_t manager_attr_show(struct kobject *kobj, struct attribute *attr,
318 struct omap_overlay_manager *manager;
319 struct manager_attribute *manager_attr;
321 manager = container_of(kobj, struct omap_overlay_manager, kobj);
322 manager_attr = container_of(attr, struct manager_attribute, attr);
324 if (!manager_attr->show)
327 return manager_attr->show(manager, buf);
330 static ssize_t manager_attr_store(struct kobject *kobj, struct attribute *attr,
331 const char *buf, size_t size)
333 struct omap_overlay_manager *manager;
334 struct manager_attribute *manager_attr;
336 manager = container_of(kobj, struct omap_overlay_manager, kobj);
337 manager_attr = container_of(attr, struct manager_attribute, attr);
339 if (!manager_attr->store)
342 return manager_attr->store(manager, buf, size);
345 static const struct sysfs_ops manager_sysfs_ops = {
346 .show = manager_attr_show,
347 .store = manager_attr_store,
350 static struct kobj_type manager_ktype = {
351 .sysfs_ops = &manager_sysfs_ops,
352 .default_attrs = manager_sysfs_attrs,
356 * We have 4 levels of cache for the dispc settings. First two are in SW and
357 * the latter two in HW.
359 * +--------------------+
360 * |overlay/manager_info|
361 * +--------------------+
365 * +--------------------+
367 * +--------------------+
371 * +--------------------+
372 * | shadow registers |
373 * +--------------------+
375 * VFP or lcd/digit_enable
377 * +--------------------+
379 * +--------------------+
382 struct overlay_cache_data {
383 /* If true, cache changed, but not written to shadow registers. Set
384 * in apply(), cleared when registers written. */
386 /* If true, shadow registers contain changed values not yet in real
387 * registers. Set when writing to shadow registers, cleared at
398 enum omap_color_mode color_mode;
400 enum omap_dss_rotation_type rotation_type;
405 u16 out_width; /* if 0, out_width == width */
406 u16 out_height; /* if 0, out_height == height */
409 enum omap_channel channel;
413 enum omap_burst_size burst_size;
420 struct manager_cache_data {
421 /* If true, cache changed, but not written to shadow registers. Set
422 * in apply(), cleared when registers written. */
424 /* If true, shadow registers contain changed values not yet in real
425 * registers. Set when writing to shadow registers, cleared at
431 enum omap_dss_trans_key_type trans_key_type;
437 bool manual_upd_display;
439 bool do_manual_update;
441 /* manual update region */
444 /* enlarge the update area if the update area contains scaled
446 bool enlarge_update_area;
451 struct overlay_cache_data overlay_cache[3];
452 struct manager_cache_data manager_cache[2];
459 static int omap_dss_set_device(struct omap_overlay_manager *mgr,
460 struct omap_dss_device *dssdev)
465 if (dssdev->manager) {
466 DSSERR("display '%s' already has a manager '%s'\n",
467 dssdev->name, dssdev->manager->name);
471 if ((mgr->supported_displays & dssdev->type) == 0) {
472 DSSERR("display '%s' does not support manager '%s'\n",
473 dssdev->name, mgr->name);
477 for (i = 0; i < mgr->num_overlays; i++) {
478 struct omap_overlay *ovl = mgr->overlays[i];
480 if (ovl->manager != mgr || !ovl->info.enabled)
483 r = dss_check_overlay(ovl, dssdev);
488 dssdev->manager = mgr;
489 mgr->device = dssdev;
490 mgr->device_changed = true;
495 static int omap_dss_unset_device(struct omap_overlay_manager *mgr)
498 DSSERR("failed to unset display, display not set.\n");
502 mgr->device->manager = NULL;
504 mgr->device_changed = true;
509 static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
511 unsigned long timeout = msecs_to_jiffies(500);
514 if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC)
515 irq = DISPC_IRQ_EVSYNC_ODD;
517 irq = DISPC_IRQ_VSYNC;
519 return omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
522 static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
524 unsigned long timeout = msecs_to_jiffies(500);
525 struct manager_cache_data *mc;
526 enum omap_channel channel;
530 struct omap_dss_device *dssdev = mgr->device;
532 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
535 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) {
536 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
537 channel = OMAP_DSS_CHANNEL_DIGIT;
539 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
540 enum omap_dss_update_mode mode;
541 mode = dssdev->driver->get_update_mode(dssdev);
542 if (mode != OMAP_DSS_UPDATE_AUTO)
545 irq = DISPC_IRQ_FRAMEDONE;
547 irq = DISPC_IRQ_VSYNC;
549 channel = OMAP_DSS_CHANNEL_LCD;
552 mc = &dss_cache.manager_cache[mgr->id];
556 bool shadow_dirty, dirty;
558 spin_lock_irqsave(&dss_cache.lock, flags);
560 shadow_dirty = mc->shadow_dirty;
561 spin_unlock_irqrestore(&dss_cache.lock, flags);
563 if (!dirty && !shadow_dirty) {
568 /* 4 iterations is the worst case:
569 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
570 * 2 - first VSYNC, dirty = true
571 * 3 - dirty = false, shadow_dirty = true
572 * 4 - shadow_dirty = false */
574 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
580 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
581 if (r == -ERESTARTSYS)
585 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
593 int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
595 unsigned long timeout = msecs_to_jiffies(500);
596 enum omap_channel channel;
597 struct overlay_cache_data *oc;
598 struct omap_dss_device *dssdev;
606 dssdev = ovl->manager->device;
608 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
611 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) {
612 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
613 channel = OMAP_DSS_CHANNEL_DIGIT;
615 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
616 enum omap_dss_update_mode mode;
617 mode = dssdev->driver->get_update_mode(dssdev);
618 if (mode != OMAP_DSS_UPDATE_AUTO)
621 irq = DISPC_IRQ_FRAMEDONE;
623 irq = DISPC_IRQ_VSYNC;
625 channel = OMAP_DSS_CHANNEL_LCD;
628 oc = &dss_cache.overlay_cache[ovl->id];
632 bool shadow_dirty, dirty;
634 spin_lock_irqsave(&dss_cache.lock, flags);
636 shadow_dirty = oc->shadow_dirty;
637 spin_unlock_irqrestore(&dss_cache.lock, flags);
639 if (!dirty && !shadow_dirty) {
644 /* 4 iterations is the worst case:
645 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
646 * 2 - first VSYNC, dirty = true
647 * 3 - dirty = false, shadow_dirty = true
648 * 4 - shadow_dirty = false */
650 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
656 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
657 if (r == -ERESTARTSYS)
661 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
669 static int overlay_enabled(struct omap_overlay *ovl)
671 return ovl->info.enabled && ovl->manager && ovl->manager->device;
674 /* Is rect1 a subset of rect2? */
675 static bool rectangle_subset(int x1, int y1, int w1, int h1,
676 int x2, int y2, int w2, int h2)
678 if (x1 < x2 || y1 < y2)
681 if (x1 + w1 > x2 + w2)
684 if (y1 + h1 > y2 + h2)
690 /* Do rect1 and rect2 overlap? */
691 static bool rectangle_intersects(int x1, int y1, int w1, int h1,
692 int x2, int y2, int w2, int h2)
709 static bool dispc_is_overlay_scaled(struct overlay_cache_data *oc)
711 if (oc->out_width != 0 && oc->width != oc->out_width)
714 if (oc->out_height != 0 && oc->height != oc->out_height)
720 static int configure_overlay(enum omap_plane plane)
722 struct overlay_cache_data *c;
723 struct manager_cache_data *mc;
728 u16 orig_w, orig_h, orig_outw, orig_outh;
730 DSSDBGF("%d", plane);
732 c = &dss_cache.overlay_cache[plane];
735 dispc_enable_plane(plane, 0);
739 mc = &dss_cache.manager_cache[c->channel];
745 outw = c->out_width == 0 ? c->width : c->out_width;
746 outh = c->out_height == 0 ? c->height : c->out_height;
754 if (c->manual_update && mc->do_manual_update) {
756 unsigned scale_x_m = w, scale_x_d = outw;
757 unsigned scale_y_m = h, scale_y_d = outh;
759 /* If the overlay is outside the update region, disable it */
760 if (!rectangle_intersects(mc->x, mc->y, mc->w, mc->h,
762 dispc_enable_plane(plane, 0);
766 switch (c->color_mode) {
767 case OMAP_DSS_COLOR_RGB16:
768 case OMAP_DSS_COLOR_ARGB16:
769 case OMAP_DSS_COLOR_YUV2:
770 case OMAP_DSS_COLOR_UYVY:
774 case OMAP_DSS_COLOR_RGB24P:
778 case OMAP_DSS_COLOR_RGB24U:
779 case OMAP_DSS_COLOR_ARGB32:
780 case OMAP_DSS_COLOR_RGBA32:
781 case OMAP_DSS_COLOR_RGBX32:
789 if (mc->x > c->pos_x) {
791 outw -= (mc->x - c->pos_x);
792 paddr += (mc->x - c->pos_x) *
793 scale_x_m / scale_x_d * bpp / 8;
795 x = c->pos_x - mc->x;
798 if (mc->y > c->pos_y) {
800 outh -= (mc->y - c->pos_y);
801 paddr += (mc->y - c->pos_y) *
802 scale_y_m / scale_y_d *
803 c->screen_width * bpp / 8;
805 y = c->pos_y - mc->y;
808 if (mc->w < (x + outw))
809 outw -= (x + outw) - (mc->w);
811 if (mc->h < (y + outh))
812 outh -= (y + outh) - (mc->h);
814 w = w * outw / orig_outw;
815 h = h * outh / orig_outh;
817 /* YUV mode overlay's input width has to be even and the
818 * algorithm above may adjust the width to be odd.
820 * Here we adjust the width if needed, preferring to increase
821 * the width if the original width was bigger.
824 (c->color_mode == OMAP_DSS_COLOR_YUV2 ||
825 c->color_mode == OMAP_DSS_COLOR_UYVY)) {
833 r = dispc_setup_plane(plane,
847 /* this shouldn't happen */
848 DSSERR("dispc_setup_plane failed for ovl %d\n", plane);
849 dispc_enable_plane(plane, 0);
853 dispc_enable_replication(plane, c->replication);
855 dispc_set_burst_size(plane, c->burst_size);
856 dispc_setup_plane_fifo(plane, c->fifo_low, c->fifo_high);
858 dispc_enable_plane(plane, 1);
863 static void configure_manager(enum omap_channel channel)
865 struct manager_cache_data *c;
867 DSSDBGF("%d", channel);
869 c = &dss_cache.manager_cache[channel];
871 dispc_set_default_color(channel, c->default_color);
872 dispc_set_trans_key(channel, c->trans_key_type, c->trans_key);
873 dispc_enable_trans_key(channel, c->trans_enabled);
874 dispc_enable_alpha_blending(channel, c->alpha_enabled);
877 /* configure_dispc() tries to write values from cache to shadow registers.
878 * It writes only to those managers/overlays that are not busy.
879 * returns 0 if everything could be written to shadow registers.
880 * returns 1 if not everything could be written to shadow registers. */
881 static int configure_dispc(void)
883 struct overlay_cache_data *oc;
884 struct manager_cache_data *mc;
885 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
886 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
896 mgr_busy[0] = dispc_go_busy(0);
897 mgr_busy[1] = dispc_go_busy(1);
901 /* Commit overlay settings */
902 for (i = 0; i < num_ovls; ++i) {
903 oc = &dss_cache.overlay_cache[i];
904 mc = &dss_cache.manager_cache[oc->channel];
909 if (oc->manual_update && !mc->do_manual_update)
912 if (mgr_busy[oc->channel]) {
917 r = configure_overlay(i);
919 DSSERR("configure_overlay %d failed\n", i);
922 oc->shadow_dirty = true;
923 mgr_go[oc->channel] = true;
926 /* Commit manager settings */
927 for (i = 0; i < num_mgrs; ++i) {
928 mc = &dss_cache.manager_cache[i];
933 if (mc->manual_update && !mc->do_manual_update)
941 configure_manager(i);
943 mc->shadow_dirty = true;
948 for (i = 0; i < num_mgrs; ++i) {
949 mc = &dss_cache.manager_cache[i];
954 /* We don't need GO with manual update display. LCD iface will
955 * always be turned off after frame, and new settings will be
956 * taken in to use at next update */
957 if (!mc->manual_upd_display)
969 /* Make the coordinates even. There are some strange problems with OMAP and
970 * partial DSI update when the update widths are odd. */
971 static void make_even(u16 *x, u16 *w)
985 /* Configure dispc for partial update. Return possibly modified update
987 void dss_setup_partial_planes(struct omap_dss_device *dssdev,
988 u16 *xi, u16 *yi, u16 *wi, u16 *hi, bool enlarge_update_area)
990 struct overlay_cache_data *oc;
991 struct manager_cache_data *mc;
992 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
993 struct omap_overlay_manager *mgr;
1004 DSSDBG("dispc_setup_partial_planes %d,%d %dx%d\n",
1005 *xi, *yi, *wi, *hi);
1007 mgr = dssdev->manager;
1010 DSSDBG("no manager\n");
1016 spin_lock_irqsave(&dss_cache.lock, flags);
1019 * Execute the outer loop until the inner loop has completed
1020 * once without increasing the update area. This will ensure that
1021 * all scaled overlays end up completely within the update area.
1024 area_changed = false;
1026 /* We need to show the whole overlay if it is scaled. So look
1027 * for those, and make the update area larger if found.
1028 * Also mark the overlay cache dirty */
1029 for (i = 0; i < num_ovls; ++i) {
1030 unsigned x1, y1, x2, y2;
1031 unsigned outw, outh;
1033 oc = &dss_cache.overlay_cache[i];
1035 if (oc->channel != mgr->id)
1040 if (!enlarge_update_area)
1046 if (!dispc_is_overlay_scaled(oc))
1049 outw = oc->out_width == 0 ?
1050 oc->width : oc->out_width;
1051 outh = oc->out_height == 0 ?
1052 oc->height : oc->out_height;
1054 /* is the overlay outside the update region? */
1055 if (!rectangle_intersects(x, y, w, h,
1056 oc->pos_x, oc->pos_y,
1060 /* if the overlay totally inside the update region? */
1061 if (rectangle_subset(oc->pos_x, oc->pos_y, outw, outh,
1075 if ((x + w) < (oc->pos_x + outw))
1076 x2 = oc->pos_x + outw;
1080 if ((y + h) < (oc->pos_y + outh))
1081 y2 = oc->pos_y + outh;
1092 DSSDBG("changing upd area due to ovl(%d) "
1093 "scaling %d,%d %dx%d\n",
1096 area_changed = true;
1098 } while (area_changed);
1100 mc = &dss_cache.manager_cache[mgr->id];
1101 mc->do_manual_update = true;
1102 mc->enlarge_update_area = enlarge_update_area;
1110 mc->do_manual_update = false;
1112 spin_unlock_irqrestore(&dss_cache.lock, flags);
1120 void dss_start_update(struct omap_dss_device *dssdev)
1122 struct manager_cache_data *mc;
1123 struct overlay_cache_data *oc;
1124 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
1125 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
1126 struct omap_overlay_manager *mgr;
1129 mgr = dssdev->manager;
1131 for (i = 0; i < num_ovls; ++i) {
1132 oc = &dss_cache.overlay_cache[i];
1133 if (oc->channel != mgr->id)
1136 oc->shadow_dirty = false;
1139 for (i = 0; i < num_mgrs; ++i) {
1140 mc = &dss_cache.manager_cache[i];
1144 mc->shadow_dirty = false;
1147 dssdev->manager->enable(dssdev->manager);
1150 static void dss_apply_irq_handler(void *data, u32 mask)
1152 struct manager_cache_data *mc;
1153 struct overlay_cache_data *oc;
1154 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
1155 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
1159 mgr_busy[0] = dispc_go_busy(0);
1160 mgr_busy[1] = dispc_go_busy(1);
1162 spin_lock(&dss_cache.lock);
1164 for (i = 0; i < num_ovls; ++i) {
1165 oc = &dss_cache.overlay_cache[i];
1166 if (!mgr_busy[oc->channel])
1167 oc->shadow_dirty = false;
1170 for (i = 0; i < num_mgrs; ++i) {
1171 mc = &dss_cache.manager_cache[i];
1173 mc->shadow_dirty = false;
1176 r = configure_dispc();
1180 /* re-read busy flags */
1181 mgr_busy[0] = dispc_go_busy(0);
1182 mgr_busy[1] = dispc_go_busy(1);
1184 /* keep running as long as there are busy managers, so that
1185 * we can collect overlay-applied information */
1186 for (i = 0; i < num_mgrs; ++i) {
1191 omap_dispc_unregister_isr(dss_apply_irq_handler, NULL,
1192 DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1193 DISPC_IRQ_EVSYNC_EVEN);
1194 dss_cache.irq_enabled = false;
1197 spin_unlock(&dss_cache.lock);
1200 static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
1202 struct overlay_cache_data *oc;
1203 struct manager_cache_data *mc;
1205 struct omap_overlay *ovl;
1206 int num_planes_enabled = 0;
1208 unsigned long flags;
1211 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
1213 spin_lock_irqsave(&dss_cache.lock, flags);
1215 /* Configure overlays */
1216 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1217 struct omap_dss_device *dssdev;
1219 ovl = omap_dss_get_overlay(i);
1221 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1224 oc = &dss_cache.overlay_cache[ovl->id];
1226 if (!overlay_enabled(ovl)) {
1228 oc->enabled = false;
1234 if (!ovl->info_dirty) {
1236 ++num_planes_enabled;
1240 dssdev = ovl->manager->device;
1242 if (dss_check_overlay(ovl, dssdev)) {
1244 oc->enabled = false;
1250 ovl->info_dirty = false;
1253 oc->paddr = ovl->info.paddr;
1254 oc->vaddr = ovl->info.vaddr;
1255 oc->screen_width = ovl->info.screen_width;
1256 oc->width = ovl->info.width;
1257 oc->height = ovl->info.height;
1258 oc->color_mode = ovl->info.color_mode;
1259 oc->rotation = ovl->info.rotation;
1260 oc->rotation_type = ovl->info.rotation_type;
1261 oc->mirror = ovl->info.mirror;
1262 oc->pos_x = ovl->info.pos_x;
1263 oc->pos_y = ovl->info.pos_y;
1264 oc->out_width = ovl->info.out_width;
1265 oc->out_height = ovl->info.out_height;
1266 oc->global_alpha = ovl->info.global_alpha;
1269 dss_use_replication(dssdev, ovl->info.color_mode);
1271 oc->ilace = dssdev->type == OMAP_DISPLAY_TYPE_VENC;
1273 oc->channel = ovl->manager->id;
1278 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
1279 dssdev->driver->get_update_mode(dssdev) !=
1280 OMAP_DSS_UPDATE_AUTO;
1282 ++num_planes_enabled;
1285 /* Configure managers */
1286 list_for_each_entry(mgr, &manager_list, list) {
1287 struct omap_dss_device *dssdev;
1289 if (!(mgr->caps & OMAP_DSS_OVL_MGR_CAP_DISPC))
1292 mc = &dss_cache.manager_cache[mgr->id];
1294 if (mgr->device_changed) {
1295 mgr->device_changed = false;
1296 mgr->info_dirty = true;
1299 if (!mgr->info_dirty)
1305 dssdev = mgr->device;
1307 mgr->info_dirty = false;
1310 mc->default_color = mgr->info.default_color;
1311 mc->trans_key_type = mgr->info.trans_key_type;
1312 mc->trans_key = mgr->info.trans_key;
1313 mc->trans_enabled = mgr->info.trans_enabled;
1314 mc->alpha_enabled = mgr->info.alpha_enabled;
1316 mc->manual_upd_display =
1317 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
1320 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
1321 dssdev->driver->get_update_mode(dssdev) !=
1322 OMAP_DSS_UPDATE_AUTO;
1325 /* XXX TODO: Try to get fifomerge working. The problem is that it
1326 * affects both managers, not individually but at the same time. This
1327 * means the change has to be well synchronized. I guess the proper way
1328 * is to have a two step process for fifo merge:
1330 * 1. disable other planes, leaving one plane enabled
1331 * 2. wait until the planes are disabled on HW
1332 * 3. config merged fifo thresholds, enable fifomerge
1333 * fifomerge disable:
1334 * 1. config unmerged fifo thresholds, disable fifomerge
1335 * 2. wait until fifo changes are in HW
1338 use_fifomerge = false;
1340 /* Configure overlay fifos */
1341 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1342 struct omap_dss_device *dssdev;
1345 ovl = omap_dss_get_overlay(i);
1347 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1350 oc = &dss_cache.overlay_cache[ovl->id];
1355 dssdev = ovl->manager->device;
1357 size = dispc_get_plane_fifo_size(ovl->id);
1361 switch (dssdev->type) {
1362 case OMAP_DISPLAY_TYPE_DPI:
1363 case OMAP_DISPLAY_TYPE_DBI:
1364 case OMAP_DISPLAY_TYPE_SDI:
1365 case OMAP_DISPLAY_TYPE_VENC:
1366 default_get_overlay_fifo_thresholds(ovl->id, size,
1367 &oc->burst_size, &oc->fifo_low,
1370 #ifdef CONFIG_OMAP2_DSS_DSI
1371 case OMAP_DISPLAY_TYPE_DSI:
1372 dsi_get_overlay_fifo_thresholds(ovl->id, size,
1373 &oc->burst_size, &oc->fifo_low,
1383 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
1384 if (!dss_cache.irq_enabled) {
1385 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL,
1386 DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1387 DISPC_IRQ_EVSYNC_EVEN);
1388 dss_cache.irq_enabled = true;
1391 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
1393 spin_unlock_irqrestore(&dss_cache.lock, flags);
1398 static int dss_check_manager(struct omap_overlay_manager *mgr)
1400 /* OMAP supports only graphics source transparency color key and alpha
1401 * blending simultaneously. See TRM 15.4.2.4.2.2 Alpha Mode */
1403 if (mgr->info.alpha_enabled && mgr->info.trans_enabled &&
1404 mgr->info.trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST)
1410 static int omap_dss_mgr_set_info(struct omap_overlay_manager *mgr,
1411 struct omap_overlay_manager_info *info)
1414 struct omap_overlay_manager_info old_info;
1416 old_info = mgr->info;
1419 r = dss_check_manager(mgr);
1421 mgr->info = old_info;
1425 mgr->info_dirty = true;
1430 static void omap_dss_mgr_get_info(struct omap_overlay_manager *mgr,
1431 struct omap_overlay_manager_info *info)
1436 static int dss_mgr_enable(struct omap_overlay_manager *mgr)
1438 dispc_enable_channel(mgr->id, 1);
1442 static int dss_mgr_disable(struct omap_overlay_manager *mgr)
1444 dispc_enable_channel(mgr->id, 0);
1448 static void omap_dss_add_overlay_manager(struct omap_overlay_manager *manager)
1451 list_add_tail(&manager->list, &manager_list);
1454 int dss_init_overlay_managers(struct platform_device *pdev)
1458 spin_lock_init(&dss_cache.lock);
1460 INIT_LIST_HEAD(&manager_list);
1464 for (i = 0; i < 2; ++i) {
1465 struct omap_overlay_manager *mgr;
1466 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1468 BUG_ON(mgr == NULL);
1473 mgr->id = OMAP_DSS_CHANNEL_LCD;
1474 mgr->supported_displays =
1475 OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
1476 OMAP_DISPLAY_TYPE_SDI | OMAP_DISPLAY_TYPE_DSI;
1480 mgr->id = OMAP_DSS_CHANNEL_DIGIT;
1481 mgr->supported_displays = OMAP_DISPLAY_TYPE_VENC;
1485 mgr->set_device = &omap_dss_set_device;
1486 mgr->unset_device = &omap_dss_unset_device;
1487 mgr->apply = &omap_dss_mgr_apply;
1488 mgr->set_manager_info = &omap_dss_mgr_set_info;
1489 mgr->get_manager_info = &omap_dss_mgr_get_info;
1490 mgr->wait_for_go = &dss_mgr_wait_for_go;
1491 mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
1493 mgr->enable = &dss_mgr_enable;
1494 mgr->disable = &dss_mgr_disable;
1496 mgr->caps = OMAP_DSS_OVL_MGR_CAP_DISPC;
1498 dss_overlay_setup_dispc_manager(mgr);
1500 omap_dss_add_overlay_manager(mgr);
1502 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1503 &pdev->dev.kobj, "manager%d", i);
1506 DSSERR("failed to create sysfs file\n");
1513 int omap_dss_mgr_apply_l4(struct omap_overlay_manager *mgr)
1515 DSSDBG("omap_dss_mgr_apply_l4(%s)\n", mgr->name);
1520 struct omap_overlay_manager *mgr;
1521 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1523 BUG_ON(mgr == NULL);
1526 mgr->supported_displays =
1527 OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI;
1529 mgr->set_device = &omap_dss_set_device;
1530 mgr->unset_device = &omap_dss_unset_device;
1531 mgr->apply = &omap_dss_mgr_apply_l4;
1532 mgr->set_manager_info = &omap_dss_mgr_set_info;
1533 mgr->get_manager_info = &omap_dss_mgr_get_info;
1535 dss_overlay_setup_l4_manager(mgr);
1537 omap_dss_add_overlay_manager(mgr);
1539 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1540 &pdev->dev.kobj, "managerl4");
1543 DSSERR("failed to create sysfs file\n");
1550 void dss_uninit_overlay_managers(struct platform_device *pdev)
1552 struct omap_overlay_manager *mgr;
1554 while (!list_empty(&manager_list)) {
1555 mgr = list_first_entry(&manager_list,
1556 struct omap_overlay_manager, list);
1557 list_del(&mgr->list);
1558 kobject_del(&mgr->kobj);
1559 kobject_put(&mgr->kobj);
1566 int omap_dss_get_num_overlay_managers(void)
1568 return num_managers;
1570 EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
1572 struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
1575 struct omap_overlay_manager *mgr;
1577 list_for_each_entry(mgr, &manager_list, list) {
1584 EXPORT_SYMBOL(omap_dss_get_overlay_manager);