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 <video/omapdss.h>
36 #include "dss_features.h"
38 static int num_managers;
39 static struct list_head manager_list;
41 static ssize_t manager_name_show(struct omap_overlay_manager *mgr, char *buf)
43 return snprintf(buf, PAGE_SIZE, "%s\n", mgr->name);
46 static ssize_t manager_display_show(struct omap_overlay_manager *mgr, char *buf)
48 return snprintf(buf, PAGE_SIZE, "%s\n",
49 mgr->device ? mgr->device->name : "<none>");
52 static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
53 const char *buf, size_t size)
57 struct omap_dss_device *dssdev = NULL;
59 int match(struct omap_dss_device *dssdev, void *data)
61 const char *str = data;
62 return sysfs_streq(dssdev->name, str);
65 if (buf[size-1] == '\n')
69 dssdev = omap_dss_find_device((void *)buf, match);
71 if (len > 0 && dssdev == NULL)
75 DSSDBG("display %s found\n", dssdev->name);
78 r = mgr->unset_device(mgr);
80 DSSERR("failed to unset display\n");
86 r = mgr->set_device(mgr, dssdev);
88 DSSERR("failed to set manager\n");
94 DSSERR("failed to apply dispc config\n");
101 omap_dss_put_device(dssdev);
106 static ssize_t manager_default_color_show(struct omap_overlay_manager *mgr,
109 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.default_color);
112 static ssize_t manager_default_color_store(struct omap_overlay_manager *mgr,
113 const char *buf, size_t size)
115 struct omap_overlay_manager_info info;
119 if (sscanf(buf, "%d", &color) != 1)
122 mgr->get_manager_info(mgr, &info);
124 info.default_color = color;
126 r = mgr->set_manager_info(mgr, &info);
137 static const char *trans_key_type_str[] = {
142 static ssize_t manager_trans_key_type_show(struct omap_overlay_manager *mgr,
145 enum omap_dss_trans_key_type key_type;
147 key_type = mgr->info.trans_key_type;
148 BUG_ON(key_type >= ARRAY_SIZE(trans_key_type_str));
150 return snprintf(buf, PAGE_SIZE, "%s\n", trans_key_type_str[key_type]);
153 static ssize_t manager_trans_key_type_store(struct omap_overlay_manager *mgr,
154 const char *buf, size_t size)
156 enum omap_dss_trans_key_type key_type;
157 struct omap_overlay_manager_info info;
160 for (key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
161 key_type < ARRAY_SIZE(trans_key_type_str); key_type++) {
162 if (sysfs_streq(buf, trans_key_type_str[key_type]))
166 if (key_type == ARRAY_SIZE(trans_key_type_str))
169 mgr->get_manager_info(mgr, &info);
171 info.trans_key_type = key_type;
173 r = mgr->set_manager_info(mgr, &info);
184 static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
187 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_key);
190 static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
191 const char *buf, size_t size)
193 struct omap_overlay_manager_info info;
197 if (sscanf(buf, "%d", &key_value) != 1)
200 mgr->get_manager_info(mgr, &info);
202 info.trans_key = key_value;
204 r = mgr->set_manager_info(mgr, &info);
215 static ssize_t manager_trans_key_enabled_show(struct omap_overlay_manager *mgr,
218 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_enabled);
221 static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
222 const char *buf, size_t size)
224 struct omap_overlay_manager_info info;
228 if (sscanf(buf, "%d", &enable) != 1)
231 mgr->get_manager_info(mgr, &info);
233 info.trans_enabled = enable ? true : false;
235 r = mgr->set_manager_info(mgr, &info);
246 static ssize_t manager_alpha_blending_enabled_show(
247 struct omap_overlay_manager *mgr, char *buf)
249 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.alpha_enabled);
252 static ssize_t manager_alpha_blending_enabled_store(
253 struct omap_overlay_manager *mgr,
254 const char *buf, size_t size)
256 struct omap_overlay_manager_info info;
260 if (sscanf(buf, "%d", &enable) != 1)
263 mgr->get_manager_info(mgr, &info);
265 info.alpha_enabled = enable ? true : false;
267 r = mgr->set_manager_info(mgr, &info);
278 struct manager_attribute {
279 struct attribute attr;
280 ssize_t (*show)(struct omap_overlay_manager *, char *);
281 ssize_t (*store)(struct omap_overlay_manager *, const char *, size_t);
284 #define MANAGER_ATTR(_name, _mode, _show, _store) \
285 struct manager_attribute manager_attr_##_name = \
286 __ATTR(_name, _mode, _show, _store)
288 static MANAGER_ATTR(name, S_IRUGO, manager_name_show, NULL);
289 static MANAGER_ATTR(display, S_IRUGO|S_IWUSR,
290 manager_display_show, manager_display_store);
291 static MANAGER_ATTR(default_color, S_IRUGO|S_IWUSR,
292 manager_default_color_show, manager_default_color_store);
293 static MANAGER_ATTR(trans_key_type, S_IRUGO|S_IWUSR,
294 manager_trans_key_type_show, manager_trans_key_type_store);
295 static MANAGER_ATTR(trans_key_value, S_IRUGO|S_IWUSR,
296 manager_trans_key_value_show, manager_trans_key_value_store);
297 static MANAGER_ATTR(trans_key_enabled, S_IRUGO|S_IWUSR,
298 manager_trans_key_enabled_show,
299 manager_trans_key_enabled_store);
300 static MANAGER_ATTR(alpha_blending_enabled, S_IRUGO|S_IWUSR,
301 manager_alpha_blending_enabled_show,
302 manager_alpha_blending_enabled_store);
305 static struct attribute *manager_sysfs_attrs[] = {
306 &manager_attr_name.attr,
307 &manager_attr_display.attr,
308 &manager_attr_default_color.attr,
309 &manager_attr_trans_key_type.attr,
310 &manager_attr_trans_key_value.attr,
311 &manager_attr_trans_key_enabled.attr,
312 &manager_attr_alpha_blending_enabled.attr,
316 static ssize_t manager_attr_show(struct kobject *kobj, struct attribute *attr,
319 struct omap_overlay_manager *manager;
320 struct manager_attribute *manager_attr;
322 manager = container_of(kobj, struct omap_overlay_manager, kobj);
323 manager_attr = container_of(attr, struct manager_attribute, attr);
325 if (!manager_attr->show)
328 return manager_attr->show(manager, buf);
331 static ssize_t manager_attr_store(struct kobject *kobj, struct attribute *attr,
332 const char *buf, size_t size)
334 struct omap_overlay_manager *manager;
335 struct manager_attribute *manager_attr;
337 manager = container_of(kobj, struct omap_overlay_manager, kobj);
338 manager_attr = container_of(attr, struct manager_attribute, attr);
340 if (!manager_attr->store)
343 return manager_attr->store(manager, buf, size);
346 static const struct sysfs_ops manager_sysfs_ops = {
347 .show = manager_attr_show,
348 .store = manager_attr_store,
351 static struct kobj_type manager_ktype = {
352 .sysfs_ops = &manager_sysfs_ops,
353 .default_attrs = manager_sysfs_attrs,
357 * We have 4 levels of cache for the dispc settings. First two are in SW and
358 * the latter two in HW.
360 * +--------------------+
361 * |overlay/manager_info|
362 * +--------------------+
366 * +--------------------+
368 * +--------------------+
372 * +--------------------+
373 * | shadow registers |
374 * +--------------------+
376 * VFP or lcd/digit_enable
378 * +--------------------+
380 * +--------------------+
383 struct overlay_cache_data {
384 /* If true, cache changed, but not written to shadow registers. Set
385 * in apply(), cleared when registers written. */
387 /* If true, shadow registers contain changed values not yet in real
388 * registers. Set when writing to shadow registers, cleared at
396 u32 p_uv_addr; /* relevant for NV12 format only */
400 enum omap_color_mode color_mode;
402 enum omap_dss_rotation_type rotation_type;
407 u16 out_width; /* if 0, out_width == width */
408 u16 out_height; /* if 0, out_height == height */
412 enum omap_channel channel;
416 enum omap_burst_size burst_size;
421 struct manager_cache_data {
422 /* If true, cache changed, but not written to shadow registers. Set
423 * in apply(), cleared when registers written. */
425 /* If true, shadow registers contain changed values not yet in real
426 * registers. Set when writing to shadow registers, cleared at
432 enum omap_dss_trans_key_type trans_key_type;
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[MAX_DSS_OVERLAYS];
452 struct manager_cache_data manager_cache[MAX_DSS_MANAGERS];
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;
516 } else if (mgr->device->type == OMAP_DISPLAY_TYPE_HDMI) {
517 irq = DISPC_IRQ_EVSYNC_EVEN;
519 if (mgr->id == OMAP_DSS_CHANNEL_LCD)
520 irq = DISPC_IRQ_VSYNC;
522 irq = DISPC_IRQ_VSYNC2;
524 return omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
527 static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
529 unsigned long timeout = msecs_to_jiffies(500);
530 struct manager_cache_data *mc;
534 struct omap_dss_device *dssdev = mgr->device;
536 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
539 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE)
542 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
543 || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
544 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
546 irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
547 DISPC_IRQ_VSYNC : DISPC_IRQ_VSYNC2;
550 mc = &dss_cache.manager_cache[mgr->id];
554 bool shadow_dirty, dirty;
556 spin_lock_irqsave(&dss_cache.lock, flags);
558 shadow_dirty = mc->shadow_dirty;
559 spin_unlock_irqrestore(&dss_cache.lock, flags);
561 if (!dirty && !shadow_dirty) {
566 /* 4 iterations is the worst case:
567 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
568 * 2 - first VSYNC, dirty = true
569 * 3 - dirty = false, shadow_dirty = true
570 * 4 - shadow_dirty = false */
572 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
578 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
579 if (r == -ERESTARTSYS)
583 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
591 int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
593 unsigned long timeout = msecs_to_jiffies(500);
594 struct overlay_cache_data *oc;
595 struct omap_dss_device *dssdev;
603 dssdev = ovl->manager->device;
605 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
608 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE)
611 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
612 || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
613 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
615 irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
616 DISPC_IRQ_VSYNC : DISPC_IRQ_VSYNC2;
619 oc = &dss_cache.overlay_cache[ovl->id];
623 bool shadow_dirty, dirty;
625 spin_lock_irqsave(&dss_cache.lock, flags);
627 shadow_dirty = oc->shadow_dirty;
628 spin_unlock_irqrestore(&dss_cache.lock, flags);
630 if (!dirty && !shadow_dirty) {
635 /* 4 iterations is the worst case:
636 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
637 * 2 - first VSYNC, dirty = true
638 * 3 - dirty = false, shadow_dirty = true
639 * 4 - shadow_dirty = false */
641 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
647 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
648 if (r == -ERESTARTSYS)
652 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
660 static int overlay_enabled(struct omap_overlay *ovl)
662 return ovl->info.enabled && ovl->manager && ovl->manager->device;
665 /* Is rect1 a subset of rect2? */
666 static bool rectangle_subset(int x1, int y1, int w1, int h1,
667 int x2, int y2, int w2, int h2)
669 if (x1 < x2 || y1 < y2)
672 if (x1 + w1 > x2 + w2)
675 if (y1 + h1 > y2 + h2)
681 /* Do rect1 and rect2 overlap? */
682 static bool rectangle_intersects(int x1, int y1, int w1, int h1,
683 int x2, int y2, int w2, int h2)
700 static bool dispc_is_overlay_scaled(struct overlay_cache_data *oc)
702 if (oc->out_width != 0 && oc->width != oc->out_width)
705 if (oc->out_height != 0 && oc->height != oc->out_height)
711 static int configure_overlay(enum omap_plane plane)
713 struct overlay_cache_data *c;
714 struct manager_cache_data *mc;
719 u16 orig_w, orig_h, orig_outw, orig_outh;
721 DSSDBGF("%d", plane);
723 c = &dss_cache.overlay_cache[plane];
726 dispc_enable_plane(plane, 0);
730 mc = &dss_cache.manager_cache[c->channel];
736 outw = c->out_width == 0 ? c->width : c->out_width;
737 outh = c->out_height == 0 ? c->height : c->out_height;
745 if (mc->manual_update && mc->do_manual_update) {
747 unsigned scale_x_m = w, scale_x_d = outw;
748 unsigned scale_y_m = h, scale_y_d = outh;
750 /* If the overlay is outside the update region, disable it */
751 if (!rectangle_intersects(mc->x, mc->y, mc->w, mc->h,
753 dispc_enable_plane(plane, 0);
757 switch (c->color_mode) {
758 case OMAP_DSS_COLOR_NV12:
761 case OMAP_DSS_COLOR_RGB16:
762 case OMAP_DSS_COLOR_ARGB16:
763 case OMAP_DSS_COLOR_YUV2:
764 case OMAP_DSS_COLOR_UYVY:
765 case OMAP_DSS_COLOR_RGBA16:
766 case OMAP_DSS_COLOR_RGBX16:
767 case OMAP_DSS_COLOR_ARGB16_1555:
768 case OMAP_DSS_COLOR_XRGB16_1555:
772 case OMAP_DSS_COLOR_RGB24P:
776 case OMAP_DSS_COLOR_RGB24U:
777 case OMAP_DSS_COLOR_ARGB32:
778 case OMAP_DSS_COLOR_RGBA32:
779 case OMAP_DSS_COLOR_RGBX32:
787 if (mc->x > c->pos_x) {
789 outw -= (mc->x - c->pos_x);
790 paddr += (mc->x - c->pos_x) *
791 scale_x_m / scale_x_d * bpp / 8;
793 x = c->pos_x - mc->x;
796 if (mc->y > c->pos_y) {
798 outh -= (mc->y - c->pos_y);
799 paddr += (mc->y - c->pos_y) *
800 scale_y_m / scale_y_d *
801 c->screen_width * bpp / 8;
803 y = c->pos_y - mc->y;
806 if (mc->w < (x + outw))
807 outw -= (x + outw) - (mc->w);
809 if (mc->h < (y + outh))
810 outh -= (y + outh) - (mc->h);
812 w = w * outw / orig_outw;
813 h = h * outh / orig_outh;
815 /* YUV mode overlay's input width has to be even and the
816 * algorithm above may adjust the width to be odd.
818 * Here we adjust the width if needed, preferring to increase
819 * the width if the original width was bigger.
822 (c->color_mode == OMAP_DSS_COLOR_YUV2 ||
823 c->color_mode == OMAP_DSS_COLOR_UYVY)) {
831 r = dispc_setup_plane(plane,
848 /* this shouldn't happen */
849 DSSERR("dispc_setup_plane failed for ovl %d\n", plane);
850 dispc_enable_plane(plane, 0);
854 dispc_enable_replication(plane, c->replication);
856 dispc_set_burst_size(plane, c->burst_size);
857 dispc_setup_plane_fifo(plane, c->fifo_low, c->fifo_high);
859 dispc_enable_plane(plane, 1);
864 static void configure_manager(enum omap_channel channel)
866 struct manager_cache_data *c;
868 DSSDBGF("%d", channel);
870 c = &dss_cache.manager_cache[channel];
872 dispc_set_default_color(channel, c->default_color);
873 dispc_set_trans_key(channel, c->trans_key_type, c->trans_key);
874 dispc_enable_trans_key(channel, c->trans_enabled);
875 dispc_enable_alpha_blending(channel, c->alpha_enabled);
878 /* configure_dispc() tries to write values from cache to shadow registers.
879 * It writes only to those managers/overlays that are not busy.
880 * returns 0 if everything could be written to shadow registers.
881 * returns 1 if not everything could be written to shadow registers. */
882 static int configure_dispc(void)
884 struct overlay_cache_data *oc;
885 struct manager_cache_data *mc;
886 const int num_ovls = dss_feat_get_num_ovls();
887 const int num_mgrs = dss_feat_get_num_mgrs();
890 bool mgr_busy[MAX_DSS_MANAGERS];
891 bool mgr_go[MAX_DSS_MANAGERS];
897 for (i = 0; i < num_mgrs; i++) {
898 mgr_busy[i] = dispc_go_busy(i);
902 /* Commit overlay settings */
903 for (i = 0; i < num_ovls; ++i) {
904 oc = &dss_cache.overlay_cache[i];
905 mc = &dss_cache.manager_cache[oc->channel];
910 if (mc->manual_update && !mc->do_manual_update)
913 if (mgr_busy[oc->channel]) {
918 r = configure_overlay(i);
920 DSSERR("configure_overlay %d failed\n", i);
923 oc->shadow_dirty = true;
924 mgr_go[oc->channel] = true;
927 /* Commit manager settings */
928 for (i = 0; i < num_mgrs; ++i) {
929 mc = &dss_cache.manager_cache[i];
934 if (mc->manual_update && !mc->do_manual_update)
942 configure_manager(i);
944 mc->shadow_dirty = true;
949 for (i = 0; i < num_mgrs; ++i) {
950 mc = &dss_cache.manager_cache[i];
955 /* We don't need GO with manual update display. LCD iface will
956 * always be turned off after frame, and new settings will be
957 * taken in to use at next update */
958 if (!mc->manual_update)
970 /* Make the coordinates even. There are some strange problems with OMAP and
971 * partial DSI update when the update widths are odd. */
972 static void make_even(u16 *x, u16 *w)
986 /* Configure dispc for partial update. Return possibly modified update
988 void dss_setup_partial_planes(struct omap_dss_device *dssdev,
989 u16 *xi, u16 *yi, u16 *wi, u16 *hi, bool enlarge_update_area)
991 struct overlay_cache_data *oc;
992 struct manager_cache_data *mc;
993 const int num_ovls = dss_feat_get_num_ovls();
994 struct omap_overlay_manager *mgr;
1005 DSSDBG("dispc_setup_partial_planes %d,%d %dx%d\n",
1006 *xi, *yi, *wi, *hi);
1008 mgr = dssdev->manager;
1011 DSSDBG("no manager\n");
1017 spin_lock_irqsave(&dss_cache.lock, flags);
1020 * Execute the outer loop until the inner loop has completed
1021 * once without increasing the update area. This will ensure that
1022 * all scaled overlays end up completely within the update area.
1025 area_changed = false;
1027 /* We need to show the whole overlay if it is scaled. So look
1028 * for those, and make the update area larger if found.
1029 * Also mark the overlay cache dirty */
1030 for (i = 0; i < num_ovls; ++i) {
1031 unsigned x1, y1, x2, y2;
1032 unsigned outw, outh;
1034 oc = &dss_cache.overlay_cache[i];
1036 if (oc->channel != mgr->id)
1041 if (!enlarge_update_area)
1047 if (!dispc_is_overlay_scaled(oc))
1050 outw = oc->out_width == 0 ?
1051 oc->width : oc->out_width;
1052 outh = oc->out_height == 0 ?
1053 oc->height : oc->out_height;
1055 /* is the overlay outside the update region? */
1056 if (!rectangle_intersects(x, y, w, h,
1057 oc->pos_x, oc->pos_y,
1061 /* if the overlay totally inside the update region? */
1062 if (rectangle_subset(oc->pos_x, oc->pos_y, outw, outh,
1076 if ((x + w) < (oc->pos_x + outw))
1077 x2 = oc->pos_x + outw;
1081 if ((y + h) < (oc->pos_y + outh))
1082 y2 = oc->pos_y + outh;
1093 DSSDBG("changing upd area due to ovl(%d) "
1094 "scaling %d,%d %dx%d\n",
1097 area_changed = true;
1099 } while (area_changed);
1101 mc = &dss_cache.manager_cache[mgr->id];
1102 mc->do_manual_update = true;
1103 mc->enlarge_update_area = enlarge_update_area;
1111 mc->do_manual_update = false;
1113 spin_unlock_irqrestore(&dss_cache.lock, flags);
1121 void dss_start_update(struct omap_dss_device *dssdev)
1123 struct manager_cache_data *mc;
1124 struct overlay_cache_data *oc;
1125 const int num_ovls = dss_feat_get_num_ovls();
1126 const int num_mgrs = dss_feat_get_num_mgrs();
1127 struct omap_overlay_manager *mgr;
1130 mgr = dssdev->manager;
1132 for (i = 0; i < num_ovls; ++i) {
1133 oc = &dss_cache.overlay_cache[i];
1134 if (oc->channel != mgr->id)
1137 oc->shadow_dirty = false;
1140 for (i = 0; i < num_mgrs; ++i) {
1141 mc = &dss_cache.manager_cache[i];
1145 mc->shadow_dirty = false;
1148 dssdev->manager->enable(dssdev->manager);
1151 static void dss_apply_irq_handler(void *data, u32 mask)
1153 struct manager_cache_data *mc;
1154 struct overlay_cache_data *oc;
1155 const int num_ovls = dss_feat_get_num_ovls();
1156 const int num_mgrs = dss_feat_get_num_mgrs();
1158 bool mgr_busy[MAX_DSS_MANAGERS];
1161 for (i = 0; i < num_mgrs; i++)
1162 mgr_busy[i] = dispc_go_busy(i);
1164 spin_lock(&dss_cache.lock);
1166 for (i = 0; i < num_ovls; ++i) {
1167 oc = &dss_cache.overlay_cache[i];
1168 if (!mgr_busy[oc->channel])
1169 oc->shadow_dirty = false;
1172 for (i = 0; i < num_mgrs; ++i) {
1173 mc = &dss_cache.manager_cache[i];
1175 mc->shadow_dirty = false;
1178 r = configure_dispc();
1182 /* re-read busy flags */
1183 for (i = 0; i < num_mgrs; i++)
1184 mgr_busy[i] = dispc_go_busy(i);
1186 /* keep running as long as there are busy managers, so that
1187 * we can collect overlay-applied information */
1188 for (i = 0; i < num_mgrs; ++i) {
1193 irq_mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1194 DISPC_IRQ_EVSYNC_EVEN;
1195 if (dss_has_feature(FEAT_MGR_LCD2))
1196 irq_mask |= DISPC_IRQ_VSYNC2;
1198 omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, irq_mask);
1199 dss_cache.irq_enabled = false;
1202 spin_unlock(&dss_cache.lock);
1205 static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
1207 struct overlay_cache_data *oc;
1208 struct manager_cache_data *mc;
1210 struct omap_overlay *ovl;
1211 int num_planes_enabled = 0;
1213 unsigned long flags;
1216 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
1218 spin_lock_irqsave(&dss_cache.lock, flags);
1220 /* Configure overlays */
1221 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1222 struct omap_dss_device *dssdev;
1224 ovl = omap_dss_get_overlay(i);
1226 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1229 oc = &dss_cache.overlay_cache[ovl->id];
1231 if (!overlay_enabled(ovl)) {
1233 oc->enabled = false;
1239 if (!ovl->info_dirty) {
1241 ++num_planes_enabled;
1245 dssdev = ovl->manager->device;
1247 if (dss_check_overlay(ovl, dssdev)) {
1249 oc->enabled = false;
1255 ovl->info_dirty = false;
1258 oc->paddr = ovl->info.paddr;
1259 oc->vaddr = ovl->info.vaddr;
1260 oc->p_uv_addr = ovl->info.p_uv_addr;
1261 oc->screen_width = ovl->info.screen_width;
1262 oc->width = ovl->info.width;
1263 oc->height = ovl->info.height;
1264 oc->color_mode = ovl->info.color_mode;
1265 oc->rotation = ovl->info.rotation;
1266 oc->rotation_type = ovl->info.rotation_type;
1267 oc->mirror = ovl->info.mirror;
1268 oc->pos_x = ovl->info.pos_x;
1269 oc->pos_y = ovl->info.pos_y;
1270 oc->out_width = ovl->info.out_width;
1271 oc->out_height = ovl->info.out_height;
1272 oc->global_alpha = ovl->info.global_alpha;
1273 oc->pre_mult_alpha = ovl->info.pre_mult_alpha;
1276 dss_use_replication(dssdev, ovl->info.color_mode);
1278 oc->ilace = dssdev->type == OMAP_DISPLAY_TYPE_VENC;
1280 oc->channel = ovl->manager->id;
1284 ++num_planes_enabled;
1287 /* Configure managers */
1288 list_for_each_entry(mgr, &manager_list, list) {
1289 struct omap_dss_device *dssdev;
1291 if (!(mgr->caps & OMAP_DSS_OVL_MGR_CAP_DISPC))
1294 mc = &dss_cache.manager_cache[mgr->id];
1296 if (mgr->device_changed) {
1297 mgr->device_changed = false;
1298 mgr->info_dirty = true;
1301 if (!mgr->info_dirty)
1307 dssdev = mgr->device;
1309 mgr->info_dirty = false;
1312 mc->default_color = mgr->info.default_color;
1313 mc->trans_key_type = mgr->info.trans_key_type;
1314 mc->trans_key = mgr->info.trans_key;
1315 mc->trans_enabled = mgr->info.trans_enabled;
1316 mc->alpha_enabled = mgr->info.alpha_enabled;
1319 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
1322 /* XXX TODO: Try to get fifomerge working. The problem is that it
1323 * affects both managers, not individually but at the same time. This
1324 * means the change has to be well synchronized. I guess the proper way
1325 * is to have a two step process for fifo merge:
1327 * 1. disable other planes, leaving one plane enabled
1328 * 2. wait until the planes are disabled on HW
1329 * 3. config merged fifo thresholds, enable fifomerge
1330 * fifomerge disable:
1331 * 1. config unmerged fifo thresholds, disable fifomerge
1332 * 2. wait until fifo changes are in HW
1335 use_fifomerge = false;
1337 /* Configure overlay fifos */
1338 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1339 struct omap_dss_device *dssdev;
1342 ovl = omap_dss_get_overlay(i);
1344 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1347 oc = &dss_cache.overlay_cache[ovl->id];
1352 dssdev = ovl->manager->device;
1354 size = dispc_get_plane_fifo_size(ovl->id);
1358 switch (dssdev->type) {
1359 case OMAP_DISPLAY_TYPE_DPI:
1360 case OMAP_DISPLAY_TYPE_DBI:
1361 case OMAP_DISPLAY_TYPE_SDI:
1362 case OMAP_DISPLAY_TYPE_VENC:
1363 case OMAP_DISPLAY_TYPE_HDMI:
1364 default_get_overlay_fifo_thresholds(ovl->id, size,
1365 &oc->burst_size, &oc->fifo_low,
1368 #ifdef CONFIG_OMAP2_DSS_DSI
1369 case OMAP_DISPLAY_TYPE_DSI:
1370 dsi_get_overlay_fifo_thresholds(ovl->id, size,
1371 &oc->burst_size, &oc->fifo_low,
1381 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
1382 if (!dss_cache.irq_enabled) {
1385 mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1386 DISPC_IRQ_EVSYNC_EVEN;
1387 if (dss_has_feature(FEAT_MGR_LCD2))
1388 mask |= DISPC_IRQ_VSYNC2;
1390 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
1391 dss_cache.irq_enabled = true;
1394 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
1396 spin_unlock_irqrestore(&dss_cache.lock, flags);
1401 static int dss_check_manager(struct omap_overlay_manager *mgr)
1403 /* OMAP supports only graphics source transparency color key and alpha
1404 * blending simultaneously. See TRM 15.4.2.4.2.2 Alpha Mode */
1406 if (mgr->info.alpha_enabled && mgr->info.trans_enabled &&
1407 mgr->info.trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST)
1413 static int omap_dss_mgr_set_info(struct omap_overlay_manager *mgr,
1414 struct omap_overlay_manager_info *info)
1417 struct omap_overlay_manager_info old_info;
1419 old_info = mgr->info;
1422 r = dss_check_manager(mgr);
1424 mgr->info = old_info;
1428 mgr->info_dirty = true;
1433 static void omap_dss_mgr_get_info(struct omap_overlay_manager *mgr,
1434 struct omap_overlay_manager_info *info)
1439 static int dss_mgr_enable(struct omap_overlay_manager *mgr)
1441 dispc_enable_channel(mgr->id, 1);
1445 static int dss_mgr_disable(struct omap_overlay_manager *mgr)
1447 dispc_enable_channel(mgr->id, 0);
1451 static void omap_dss_add_overlay_manager(struct omap_overlay_manager *manager)
1454 list_add_tail(&manager->list, &manager_list);
1457 int dss_init_overlay_managers(struct platform_device *pdev)
1461 spin_lock_init(&dss_cache.lock);
1463 INIT_LIST_HEAD(&manager_list);
1467 for (i = 0; i < dss_feat_get_num_mgrs(); ++i) {
1468 struct omap_overlay_manager *mgr;
1469 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1471 BUG_ON(mgr == NULL);
1476 mgr->id = OMAP_DSS_CHANNEL_LCD;
1480 mgr->id = OMAP_DSS_CHANNEL_DIGIT;
1484 mgr->id = OMAP_DSS_CHANNEL_LCD2;
1488 mgr->set_device = &omap_dss_set_device;
1489 mgr->unset_device = &omap_dss_unset_device;
1490 mgr->apply = &omap_dss_mgr_apply;
1491 mgr->set_manager_info = &omap_dss_mgr_set_info;
1492 mgr->get_manager_info = &omap_dss_mgr_get_info;
1493 mgr->wait_for_go = &dss_mgr_wait_for_go;
1494 mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
1496 mgr->enable = &dss_mgr_enable;
1497 mgr->disable = &dss_mgr_disable;
1499 mgr->caps = OMAP_DSS_OVL_MGR_CAP_DISPC;
1500 mgr->supported_displays =
1501 dss_feat_get_supported_displays(mgr->id);
1503 dss_overlay_setup_dispc_manager(mgr);
1505 omap_dss_add_overlay_manager(mgr);
1507 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1508 &pdev->dev.kobj, "manager%d", i);
1511 DSSERR("failed to create sysfs file\n");
1518 int omap_dss_mgr_apply_l4(struct omap_overlay_manager *mgr)
1520 DSSDBG("omap_dss_mgr_apply_l4(%s)\n", mgr->name);
1525 struct omap_overlay_manager *mgr;
1526 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1528 BUG_ON(mgr == NULL);
1531 mgr->supported_displays =
1532 OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI;
1534 mgr->set_device = &omap_dss_set_device;
1535 mgr->unset_device = &omap_dss_unset_device;
1536 mgr->apply = &omap_dss_mgr_apply_l4;
1537 mgr->set_manager_info = &omap_dss_mgr_set_info;
1538 mgr->get_manager_info = &omap_dss_mgr_get_info;
1540 dss_overlay_setup_l4_manager(mgr);
1542 omap_dss_add_overlay_manager(mgr);
1544 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1545 &pdev->dev.kobj, "managerl4");
1548 DSSERR("failed to create sysfs file\n");
1555 void dss_uninit_overlay_managers(struct platform_device *pdev)
1557 struct omap_overlay_manager *mgr;
1559 while (!list_empty(&manager_list)) {
1560 mgr = list_first_entry(&manager_list,
1561 struct omap_overlay_manager, list);
1562 list_del(&mgr->list);
1563 kobject_del(&mgr->kobj);
1564 kobject_put(&mgr->kobj);
1571 int omap_dss_get_num_overlay_managers(void)
1573 return num_managers;
1575 EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
1577 struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
1580 struct omap_overlay_manager *mgr;
1582 list_for_each_entry(mgr, &manager_list, list) {
1589 EXPORT_SYMBOL(omap_dss_get_overlay_manager);