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/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/spinlock.h>
29 #include <linux/jiffies.h>
31 #include <plat/display.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
)
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')
67 dssdev
= omap_dss_find_device((void *)buf
, match
);
69 if (len
> 0 && dssdev
== NULL
)
73 DSSDBG("display %s found\n", dssdev
->name
);
76 r
= mgr
->unset_device(mgr
);
78 DSSERR("failed to unset display\n");
84 r
= mgr
->set_device(mgr
, dssdev
);
86 DSSERR("failed to set manager\n");
92 DSSERR("failed to apply dispc config\n");
99 omap_dss_put_device(dssdev
);
104 static ssize_t
manager_default_color_show(struct omap_overlay_manager
*mgr
,
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
;
117 if (sscanf(buf
, "%d", &color
) != 1)
120 mgr
->get_manager_info(mgr
, &info
);
122 info
.default_color
= color
;
124 r
= mgr
->set_manager_info(mgr
, &info
);
135 static const char *trans_key_type_str
[] = {
140 static ssize_t
manager_trans_key_type_show(struct omap_overlay_manager
*mgr
,
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
;
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
]))
164 if (key_type
== ARRAY_SIZE(trans_key_type_str
))
167 mgr
->get_manager_info(mgr
, &info
);
169 info
.trans_key_type
= key_type
;
171 r
= mgr
->set_manager_info(mgr
, &info
);
182 static ssize_t
manager_trans_key_value_show(struct omap_overlay_manager
*mgr
,
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
;
195 if (sscanf(buf
, "%d", &key_value
) != 1)
198 mgr
->get_manager_info(mgr
, &info
);
200 info
.trans_key
= key_value
;
202 r
= mgr
->set_manager_info(mgr
, &info
);
213 static ssize_t
manager_trans_key_enabled_show(struct omap_overlay_manager
*mgr
,
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
;
226 if (sscanf(buf
, "%d", &enable
) != 1)
229 mgr
->get_manager_info(mgr
, &info
);
231 info
.trans_enabled
= enable
? true : false;
233 r
= mgr
->set_manager_info(mgr
, &info
);
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
;
258 if (sscanf(buf
, "%d", &enable
) != 1)
261 mgr
->get_manager_info(mgr
, &info
);
263 info
.alpha_enabled
= enable
? true : false;
265 r
= mgr
->set_manager_info(mgr
, &info
);
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
,
314 static ssize_t
manager_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
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
)
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
)
341 return manager_attr
->store(manager
, buf
, size
);
344 static const 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 * +--------------------+
364 * +--------------------+
366 * +--------------------+
370 * +--------------------+
371 * | shadow registers |
372 * +--------------------+
374 * VFP or lcd/digit_enable
376 * +--------------------+
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. */
385 /* If true, shadow registers contain changed values not yet in real
386 * registers. Set when writing to shadow registers, cleared at
397 enum omap_color_mode color_mode
;
399 enum omap_dss_rotation_type rotation_type
;
404 u16 out_width
; /* if 0, out_width == width */
405 u16 out_height
; /* if 0, out_height == height */
408 enum omap_channel channel
;
412 enum omap_burst_size burst_size
;
419 struct manager_cache_data
{
420 /* If true, cache changed, but not written to shadow registers. Set
421 * in apply(), cleared when registers written. */
423 /* If true, shadow registers contain changed values not yet in real
424 * registers. Set when writing to shadow registers, cleared at
430 enum omap_dss_trans_key_type trans_key_type
;
436 bool manual_upd_display
;
438 bool do_manual_update
;
440 /* manual update region */
446 struct overlay_cache_data overlay_cache
[3];
447 struct manager_cache_data manager_cache
[2];
454 static int omap_dss_set_device(struct omap_overlay_manager
*mgr
,
455 struct omap_dss_device
*dssdev
)
460 if (dssdev
->manager
) {
461 DSSERR("display '%s' already has a manager '%s'\n",
462 dssdev
->name
, dssdev
->manager
->name
);
466 if ((mgr
->supported_displays
& dssdev
->type
) == 0) {
467 DSSERR("display '%s' does not support manager '%s'\n",
468 dssdev
->name
, mgr
->name
);
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
)
478 r
= dss_check_overlay(ovl
, dssdev
);
483 dssdev
->manager
= mgr
;
484 mgr
->device
= dssdev
;
485 mgr
->device_changed
= true;
490 static int omap_dss_unset_device(struct omap_overlay_manager
*mgr
)
493 DSSERR("failed to unset display, display not set.\n");
497 mgr
->device
->manager
= NULL
;
499 mgr
->device_changed
= true;
504 static int dss_mgr_wait_for_vsync(struct omap_overlay_manager
*mgr
)
506 unsigned long timeout
= msecs_to_jiffies(500);
509 if (mgr
->device
->type
== OMAP_DISPLAY_TYPE_VENC
)
510 irq
= DISPC_IRQ_EVSYNC_ODD
;
512 irq
= DISPC_IRQ_VSYNC
;
514 return omap_dispc_wait_for_irq_interruptible_timeout(irq
, timeout
);
517 static int dss_mgr_wait_for_go(struct omap_overlay_manager
*mgr
)
519 unsigned long timeout
= msecs_to_jiffies(500);
520 struct manager_cache_data
*mc
;
521 enum omap_channel channel
;
525 struct omap_dss_device
*dssdev
= mgr
->device
;
530 if (dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
) {
531 irq
= DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_EVSYNC_EVEN
;
532 channel
= OMAP_DSS_CHANNEL_DIGIT
;
534 if (dssdev
->caps
& OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
) {
535 enum omap_dss_update_mode mode
;
536 mode
= dssdev
->driver
->get_update_mode(dssdev
);
537 if (mode
!= OMAP_DSS_UPDATE_AUTO
)
540 irq
= DISPC_IRQ_FRAMEDONE
;
542 irq
= DISPC_IRQ_VSYNC
;
544 channel
= OMAP_DSS_CHANNEL_LCD
;
547 mc
= &dss_cache
.manager_cache
[mgr
->id
];
551 bool shadow_dirty
, dirty
;
553 spin_lock_irqsave(&dss_cache
.lock
, flags
);
555 shadow_dirty
= mc
->shadow_dirty
;
556 spin_unlock_irqrestore(&dss_cache
.lock
, flags
);
558 if (!dirty
&& !shadow_dirty
) {
563 /* 4 iterations is the worst case:
564 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
565 * 2 - first VSYNC, dirty = true
566 * 3 - dirty = false, shadow_dirty = true
567 * 4 - shadow_dirty = false */
569 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
575 r
= omap_dispc_wait_for_irq_interruptible_timeout(irq
, timeout
);
576 if (r
== -ERESTARTSYS
)
580 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr
->id
);
588 int dss_mgr_wait_for_go_ovl(struct omap_overlay
*ovl
)
590 unsigned long timeout
= msecs_to_jiffies(500);
591 enum omap_channel channel
;
592 struct overlay_cache_data
*oc
;
593 struct omap_dss_device
*dssdev
;
598 if (!ovl
->manager
|| !ovl
->manager
->device
)
601 dssdev
= ovl
->manager
->device
;
603 if (dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
) {
604 irq
= DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_EVSYNC_EVEN
;
605 channel
= OMAP_DSS_CHANNEL_DIGIT
;
607 if (dssdev
->caps
& OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
) {
608 enum omap_dss_update_mode mode
;
609 mode
= dssdev
->driver
->get_update_mode(dssdev
);
610 if (mode
!= OMAP_DSS_UPDATE_AUTO
)
613 irq
= DISPC_IRQ_FRAMEDONE
;
615 irq
= DISPC_IRQ_VSYNC
;
617 channel
= OMAP_DSS_CHANNEL_LCD
;
620 oc
= &dss_cache
.overlay_cache
[ovl
->id
];
624 bool shadow_dirty
, dirty
;
626 spin_lock_irqsave(&dss_cache
.lock
, flags
);
628 shadow_dirty
= oc
->shadow_dirty
;
629 spin_unlock_irqrestore(&dss_cache
.lock
, flags
);
631 if (!dirty
&& !shadow_dirty
) {
636 /* 4 iterations is the worst case:
637 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
638 * 2 - first VSYNC, dirty = true
639 * 3 - dirty = false, shadow_dirty = true
640 * 4 - shadow_dirty = false */
642 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
648 r
= omap_dispc_wait_for_irq_interruptible_timeout(irq
, timeout
);
649 if (r
== -ERESTARTSYS
)
653 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl
->id
);
661 static int overlay_enabled(struct omap_overlay
*ovl
)
663 return ovl
->info
.enabled
&& ovl
->manager
&& ovl
->manager
->device
;
666 /* Is rect1 a subset of rect2? */
667 static bool rectangle_subset(int x1
, int y1
, int w1
, int h1
,
668 int x2
, int y2
, int w2
, int h2
)
670 if (x1
< x2
|| y1
< y2
)
673 if (x1
+ w1
> x2
+ w2
)
676 if (y1
+ h1
> y2
+ h2
)
682 /* Do rect1 and rect2 overlap? */
683 static bool rectangle_intersects(int x1
, int y1
, int w1
, int h1
,
684 int x2
, int y2
, int w2
, int h2
)
701 static bool dispc_is_overlay_scaled(struct overlay_cache_data
*oc
)
703 if (oc
->out_width
!= 0 && oc
->width
!= oc
->out_width
)
706 if (oc
->out_height
!= 0 && oc
->height
!= oc
->out_height
)
712 static int configure_overlay(enum omap_plane plane
)
714 struct overlay_cache_data
*c
;
715 struct manager_cache_data
*mc
;
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
;
740 if (c
->manual_update
&& mc
->do_manual_update
) {
742 /* If the overlay is outside the update region, disable it */
743 if (!rectangle_intersects(mc
->x
, mc
->y
, mc
->w
, mc
->h
,
745 dispc_enable_plane(plane
, 0);
749 switch (c
->color_mode
) {
750 case OMAP_DSS_COLOR_RGB16
:
751 case OMAP_DSS_COLOR_ARGB16
:
752 case OMAP_DSS_COLOR_YUV2
:
753 case OMAP_DSS_COLOR_UYVY
:
757 case OMAP_DSS_COLOR_RGB24P
:
761 case OMAP_DSS_COLOR_RGB24U
:
762 case OMAP_DSS_COLOR_ARGB32
:
763 case OMAP_DSS_COLOR_RGBA32
:
764 case OMAP_DSS_COLOR_RGBX32
:
772 if (dispc_is_overlay_scaled(c
)) {
773 /* If the overlay is scaled, the update area has
774 * already been enlarged to cover the whole overlay. We
775 * only need to adjust x/y here */
776 x
= c
->pos_x
- mc
->x
;
777 y
= c
->pos_y
- mc
->y
;
779 if (mc
->x
> c
->pos_x
) {
781 w
-= (mc
->x
- c
->pos_x
);
782 paddr
+= (mc
->x
- c
->pos_x
) * bpp
/ 8;
784 x
= c
->pos_x
- mc
->x
;
787 if (mc
->y
> c
->pos_y
) {
789 h
-= (mc
->y
- c
->pos_y
);
790 paddr
+= (mc
->y
- c
->pos_y
) * c
->screen_width
*
793 y
= c
->pos_y
- mc
->y
;
797 w
-= (x
+w
) - (mc
->w
);
800 h
-= (y
+h
) - (mc
->h
);
807 r
= dispc_setup_plane(plane
,
821 /* this shouldn't happen */
822 DSSERR("dispc_setup_plane failed for ovl %d\n", plane
);
823 dispc_enable_plane(plane
, 0);
827 dispc_enable_replication(plane
, c
->replication
);
829 dispc_set_burst_size(plane
, c
->burst_size
);
830 dispc_setup_plane_fifo(plane
, c
->fifo_low
, c
->fifo_high
);
832 dispc_enable_plane(plane
, 1);
837 static void configure_manager(enum omap_channel channel
)
839 struct manager_cache_data
*c
;
841 DSSDBGF("%d", channel
);
843 c
= &dss_cache
.manager_cache
[channel
];
845 dispc_set_trans_key(channel
, c
->trans_key_type
, c
->trans_key
);
846 dispc_enable_trans_key(channel
, c
->trans_enabled
);
847 dispc_enable_alpha_blending(channel
, c
->alpha_enabled
);
850 /* configure_dispc() tries to write values from cache to shadow registers.
851 * It writes only to those managers/overlays that are not busy.
852 * returns 0 if everything could be written to shadow registers.
853 * returns 1 if not everything could be written to shadow registers. */
854 static int configure_dispc(void)
856 struct overlay_cache_data
*oc
;
857 struct manager_cache_data
*mc
;
858 const int num_ovls
= ARRAY_SIZE(dss_cache
.overlay_cache
);
859 const int num_mgrs
= ARRAY_SIZE(dss_cache
.manager_cache
);
869 mgr_busy
[0] = dispc_go_busy(0);
870 mgr_busy
[1] = dispc_go_busy(1);
874 /* Commit overlay settings */
875 for (i
= 0; i
< num_ovls
; ++i
) {
876 oc
= &dss_cache
.overlay_cache
[i
];
877 mc
= &dss_cache
.manager_cache
[oc
->channel
];
882 if (oc
->manual_update
&& !mc
->do_manual_update
)
885 if (mgr_busy
[oc
->channel
]) {
890 r
= configure_overlay(i
);
892 DSSERR("configure_overlay %d failed\n", i
);
895 oc
->shadow_dirty
= true;
896 mgr_go
[oc
->channel
] = true;
899 /* Commit manager settings */
900 for (i
= 0; i
< num_mgrs
; ++i
) {
901 mc
= &dss_cache
.manager_cache
[i
];
906 if (mc
->manual_update
&& !mc
->do_manual_update
)
914 configure_manager(i
);
916 mc
->shadow_dirty
= true;
921 for (i
= 0; i
< num_mgrs
; ++i
) {
922 mc
= &dss_cache
.manager_cache
[i
];
927 /* We don't need GO with manual update display. LCD iface will
928 * always be turned off after frame, and new settings will be
929 * taken in to use at next update */
930 if (!mc
->manual_upd_display
)
942 /* Configure dispc for partial update. Return possibly modified update
944 void dss_setup_partial_planes(struct omap_dss_device
*dssdev
,
945 u16
*xi
, u16
*yi
, u16
*wi
, u16
*hi
)
947 struct overlay_cache_data
*oc
;
948 struct manager_cache_data
*mc
;
949 const int num_ovls
= ARRAY_SIZE(dss_cache
.overlay_cache
);
950 struct omap_overlay_manager
*mgr
;
960 DSSDBG("dispc_setup_partial_planes %d,%d %dx%d\n",
963 mgr
= dssdev
->manager
;
966 DSSDBG("no manager\n");
970 spin_lock_irqsave(&dss_cache
.lock
, flags
);
972 /* We need to show the whole overlay if it is scaled. So look for
973 * those, and make the update area larger if found.
974 * Also mark the overlay cache dirty */
975 for (i
= 0; i
< num_ovls
; ++i
) {
976 unsigned x1
, y1
, x2
, y2
;
979 oc
= &dss_cache
.overlay_cache
[i
];
981 if (oc
->channel
!= mgr
->id
)
989 if (!dispc_is_overlay_scaled(oc
))
992 outw
= oc
->out_width
== 0 ? oc
->width
: oc
->out_width
;
993 outh
= oc
->out_height
== 0 ? oc
->height
: oc
->out_height
;
995 /* is the overlay outside the update region? */
996 if (!rectangle_intersects(x
, y
, w
, h
,
997 oc
->pos_x
, oc
->pos_y
,
1001 /* if the overlay totally inside the update region? */
1002 if (rectangle_subset(oc
->pos_x
, oc
->pos_y
, outw
, outh
,
1016 if ((x
+ w
) < (oc
->pos_x
+ outw
))
1017 x2
= oc
->pos_x
+ outw
;
1021 if ((y
+ h
) < (oc
->pos_y
+ outh
))
1022 y2
= oc
->pos_y
+ outh
;
1031 DSSDBG("changing upd area due to ovl(%d) scaling %d,%d %dx%d\n",
1035 mc
= &dss_cache
.manager_cache
[mgr
->id
];
1036 mc
->do_manual_update
= true;
1044 mc
->do_manual_update
= false;
1046 spin_unlock_irqrestore(&dss_cache
.lock
, flags
);
1054 void dss_start_update(struct omap_dss_device
*dssdev
)
1056 struct manager_cache_data
*mc
;
1057 struct overlay_cache_data
*oc
;
1058 const int num_ovls
= ARRAY_SIZE(dss_cache
.overlay_cache
);
1059 const int num_mgrs
= ARRAY_SIZE(dss_cache
.manager_cache
);
1060 struct omap_overlay_manager
*mgr
;
1063 mgr
= dssdev
->manager
;
1065 for (i
= 0; i
< num_ovls
; ++i
) {
1066 oc
= &dss_cache
.overlay_cache
[i
];
1067 if (oc
->channel
!= mgr
->id
)
1070 oc
->shadow_dirty
= false;
1073 for (i
= 0; i
< num_mgrs
; ++i
) {
1074 mc
= &dss_cache
.manager_cache
[i
];
1078 mc
->shadow_dirty
= false;
1081 dssdev
->manager
->enable(dssdev
->manager
);
1084 static void dss_apply_irq_handler(void *data
, u32 mask
)
1086 struct manager_cache_data
*mc
;
1087 struct overlay_cache_data
*oc
;
1088 const int num_ovls
= ARRAY_SIZE(dss_cache
.overlay_cache
);
1089 const int num_mgrs
= ARRAY_SIZE(dss_cache
.manager_cache
);
1093 mgr_busy
[0] = dispc_go_busy(0);
1094 mgr_busy
[1] = dispc_go_busy(1);
1096 spin_lock(&dss_cache
.lock
);
1098 for (i
= 0; i
< num_ovls
; ++i
) {
1099 oc
= &dss_cache
.overlay_cache
[i
];
1100 if (!mgr_busy
[oc
->channel
])
1101 oc
->shadow_dirty
= false;
1104 for (i
= 0; i
< num_mgrs
; ++i
) {
1105 mc
= &dss_cache
.manager_cache
[i
];
1107 mc
->shadow_dirty
= false;
1110 r
= configure_dispc();
1114 /* re-read busy flags */
1115 mgr_busy
[0] = dispc_go_busy(0);
1116 mgr_busy
[1] = dispc_go_busy(1);
1118 /* keep running as long as there are busy managers, so that
1119 * we can collect overlay-applied information */
1120 for (i
= 0; i
< num_mgrs
; ++i
) {
1125 omap_dispc_unregister_isr(dss_apply_irq_handler
, NULL
,
1126 DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_ODD
|
1127 DISPC_IRQ_EVSYNC_EVEN
);
1128 dss_cache
.irq_enabled
= false;
1131 spin_unlock(&dss_cache
.lock
);
1134 static int omap_dss_mgr_apply(struct omap_overlay_manager
*mgr
)
1136 struct overlay_cache_data
*oc
;
1137 struct manager_cache_data
*mc
;
1139 struct omap_overlay
*ovl
;
1140 int num_planes_enabled
= 0;
1142 unsigned long flags
;
1145 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr
->name
);
1147 spin_lock_irqsave(&dss_cache
.lock
, flags
);
1149 /* Configure overlays */
1150 for (i
= 0; i
< omap_dss_get_num_overlays(); ++i
) {
1151 struct omap_dss_device
*dssdev
;
1153 ovl
= omap_dss_get_overlay(i
);
1155 if (!(ovl
->caps
& OMAP_DSS_OVL_CAP_DISPC
))
1158 oc
= &dss_cache
.overlay_cache
[ovl
->id
];
1160 if (!overlay_enabled(ovl
)) {
1162 oc
->enabled
= false;
1168 if (!ovl
->info_dirty
) {
1170 ++num_planes_enabled
;
1174 dssdev
= ovl
->manager
->device
;
1176 if (dss_check_overlay(ovl
, dssdev
)) {
1178 oc
->enabled
= false;
1184 ovl
->info_dirty
= false;
1187 oc
->paddr
= ovl
->info
.paddr
;
1188 oc
->vaddr
= ovl
->info
.vaddr
;
1189 oc
->screen_width
= ovl
->info
.screen_width
;
1190 oc
->width
= ovl
->info
.width
;
1191 oc
->height
= ovl
->info
.height
;
1192 oc
->color_mode
= ovl
->info
.color_mode
;
1193 oc
->rotation
= ovl
->info
.rotation
;
1194 oc
->rotation_type
= ovl
->info
.rotation_type
;
1195 oc
->mirror
= ovl
->info
.mirror
;
1196 oc
->pos_x
= ovl
->info
.pos_x
;
1197 oc
->pos_y
= ovl
->info
.pos_y
;
1198 oc
->out_width
= ovl
->info
.out_width
;
1199 oc
->out_height
= ovl
->info
.out_height
;
1200 oc
->global_alpha
= ovl
->info
.global_alpha
;
1203 dss_use_replication(dssdev
, ovl
->info
.color_mode
);
1205 oc
->ilace
= dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
;
1207 oc
->channel
= ovl
->manager
->id
;
1212 dssdev
->caps
& OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
&&
1213 dssdev
->driver
->get_update_mode(dssdev
) !=
1214 OMAP_DSS_UPDATE_AUTO
;
1216 ++num_planes_enabled
;
1219 /* Configure managers */
1220 list_for_each_entry(mgr
, &manager_list
, list
) {
1221 struct omap_dss_device
*dssdev
;
1223 if (!(mgr
->caps
& OMAP_DSS_OVL_MGR_CAP_DISPC
))
1226 mc
= &dss_cache
.manager_cache
[mgr
->id
];
1228 if (mgr
->device_changed
) {
1229 mgr
->device_changed
= false;
1230 mgr
->info_dirty
= true;
1233 if (!mgr
->info_dirty
)
1239 dssdev
= mgr
->device
;
1241 mgr
->info_dirty
= false;
1244 mc
->default_color
= mgr
->info
.default_color
;
1245 mc
->trans_key_type
= mgr
->info
.trans_key_type
;
1246 mc
->trans_key
= mgr
->info
.trans_key
;
1247 mc
->trans_enabled
= mgr
->info
.trans_enabled
;
1248 mc
->alpha_enabled
= mgr
->info
.alpha_enabled
;
1250 mc
->manual_upd_display
=
1251 dssdev
->caps
& OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
;
1254 dssdev
->caps
& OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
&&
1255 dssdev
->driver
->get_update_mode(dssdev
) !=
1256 OMAP_DSS_UPDATE_AUTO
;
1259 /* XXX TODO: Try to get fifomerge working. The problem is that it
1260 * affects both managers, not individually but at the same time. This
1261 * means the change has to be well synchronized. I guess the proper way
1262 * is to have a two step process for fifo merge:
1264 * 1. disable other planes, leaving one plane enabled
1265 * 2. wait until the planes are disabled on HW
1266 * 3. config merged fifo thresholds, enable fifomerge
1267 * fifomerge disable:
1268 * 1. config unmerged fifo thresholds, disable fifomerge
1269 * 2. wait until fifo changes are in HW
1272 use_fifomerge
= false;
1274 /* Configure overlay fifos */
1275 for (i
= 0; i
< omap_dss_get_num_overlays(); ++i
) {
1276 struct omap_dss_device
*dssdev
;
1279 ovl
= omap_dss_get_overlay(i
);
1281 if (!(ovl
->caps
& OMAP_DSS_OVL_CAP_DISPC
))
1284 oc
= &dss_cache
.overlay_cache
[ovl
->id
];
1289 dssdev
= ovl
->manager
->device
;
1291 size
= dispc_get_plane_fifo_size(ovl
->id
);
1295 switch (dssdev
->type
) {
1296 case OMAP_DISPLAY_TYPE_DPI
:
1297 case OMAP_DISPLAY_TYPE_DBI
:
1298 case OMAP_DISPLAY_TYPE_SDI
:
1299 case OMAP_DISPLAY_TYPE_VENC
:
1300 default_get_overlay_fifo_thresholds(ovl
->id
, size
,
1301 &oc
->burst_size
, &oc
->fifo_low
,
1304 #ifdef CONFIG_OMAP2_DSS_DSI
1305 case OMAP_DISPLAY_TYPE_DSI
:
1306 dsi_get_overlay_fifo_thresholds(ovl
->id
, size
,
1307 &oc
->burst_size
, &oc
->fifo_low
,
1317 dss_clk_enable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
1318 if (!dss_cache
.irq_enabled
) {
1319 r
= omap_dispc_register_isr(dss_apply_irq_handler
, NULL
,
1320 DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_ODD
|
1321 DISPC_IRQ_EVSYNC_EVEN
);
1322 dss_cache
.irq_enabled
= true;
1325 dss_clk_disable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
1327 spin_unlock_irqrestore(&dss_cache
.lock
, flags
);
1332 static int dss_check_manager(struct omap_overlay_manager
*mgr
)
1334 /* OMAP supports only graphics source transparency color key and alpha
1335 * blending simultaneously. See TRM 15.4.2.4.2.2 Alpha Mode */
1337 if (mgr
->info
.alpha_enabled
&& mgr
->info
.trans_enabled
&&
1338 mgr
->info
.trans_key_type
!= OMAP_DSS_COLOR_KEY_GFX_DST
)
1344 static int omap_dss_mgr_set_info(struct omap_overlay_manager
*mgr
,
1345 struct omap_overlay_manager_info
*info
)
1348 struct omap_overlay_manager_info old_info
;
1350 old_info
= mgr
->info
;
1353 r
= dss_check_manager(mgr
);
1355 mgr
->info
= old_info
;
1359 mgr
->info_dirty
= true;
1364 static void omap_dss_mgr_get_info(struct omap_overlay_manager
*mgr
,
1365 struct omap_overlay_manager_info
*info
)
1370 static int dss_mgr_enable(struct omap_overlay_manager
*mgr
)
1372 dispc_enable_channel(mgr
->id
, 1);
1376 static int dss_mgr_disable(struct omap_overlay_manager
*mgr
)
1378 dispc_enable_channel(mgr
->id
, 0);
1382 static void omap_dss_add_overlay_manager(struct omap_overlay_manager
*manager
)
1385 list_add_tail(&manager
->list
, &manager_list
);
1388 int dss_init_overlay_managers(struct platform_device
*pdev
)
1392 spin_lock_init(&dss_cache
.lock
);
1394 INIT_LIST_HEAD(&manager_list
);
1398 for (i
= 0; i
< 2; ++i
) {
1399 struct omap_overlay_manager
*mgr
;
1400 mgr
= kzalloc(sizeof(*mgr
), GFP_KERNEL
);
1402 BUG_ON(mgr
== NULL
);
1407 mgr
->id
= OMAP_DSS_CHANNEL_LCD
;
1408 mgr
->supported_displays
=
1409 OMAP_DISPLAY_TYPE_DPI
| OMAP_DISPLAY_TYPE_DBI
|
1410 OMAP_DISPLAY_TYPE_SDI
| OMAP_DISPLAY_TYPE_DSI
;
1414 mgr
->id
= OMAP_DSS_CHANNEL_DIGIT
;
1415 mgr
->supported_displays
= OMAP_DISPLAY_TYPE_VENC
;
1419 mgr
->set_device
= &omap_dss_set_device
;
1420 mgr
->unset_device
= &omap_dss_unset_device
;
1421 mgr
->apply
= &omap_dss_mgr_apply
;
1422 mgr
->set_manager_info
= &omap_dss_mgr_set_info
;
1423 mgr
->get_manager_info
= &omap_dss_mgr_get_info
;
1424 mgr
->wait_for_go
= &dss_mgr_wait_for_go
;
1425 mgr
->wait_for_vsync
= &dss_mgr_wait_for_vsync
;
1427 mgr
->enable
= &dss_mgr_enable
;
1428 mgr
->disable
= &dss_mgr_disable
;
1430 mgr
->caps
= OMAP_DSS_OVL_MGR_CAP_DISPC
;
1432 dss_overlay_setup_dispc_manager(mgr
);
1434 omap_dss_add_overlay_manager(mgr
);
1436 r
= kobject_init_and_add(&mgr
->kobj
, &manager_ktype
,
1437 &pdev
->dev
.kobj
, "manager%d", i
);
1440 DSSERR("failed to create sysfs file\n");
1447 int omap_dss_mgr_apply_l4(struct omap_overlay_manager
*mgr
)
1449 DSSDBG("omap_dss_mgr_apply_l4(%s)\n", mgr
->name
);
1454 struct omap_overlay_manager
*mgr
;
1455 mgr
= kzalloc(sizeof(*mgr
), GFP_KERNEL
);
1457 BUG_ON(mgr
== NULL
);
1460 mgr
->supported_displays
=
1461 OMAP_DISPLAY_TYPE_DBI
| OMAP_DISPLAY_TYPE_DSI
;
1463 mgr
->set_device
= &omap_dss_set_device
;
1464 mgr
->unset_device
= &omap_dss_unset_device
;
1465 mgr
->apply
= &omap_dss_mgr_apply_l4
;
1466 mgr
->set_manager_info
= &omap_dss_mgr_set_info
;
1467 mgr
->get_manager_info
= &omap_dss_mgr_get_info
;
1469 dss_overlay_setup_l4_manager(mgr
);
1471 omap_dss_add_overlay_manager(mgr
);
1473 r
= kobject_init_and_add(&mgr
->kobj
, &manager_ktype
,
1474 &pdev
->dev
.kobj
, "managerl4");
1477 DSSERR("failed to create sysfs file\n");
1484 void dss_uninit_overlay_managers(struct platform_device
*pdev
)
1486 struct omap_overlay_manager
*mgr
;
1488 while (!list_empty(&manager_list
)) {
1489 mgr
= list_first_entry(&manager_list
,
1490 struct omap_overlay_manager
, list
);
1491 list_del(&mgr
->list
);
1492 kobject_del(&mgr
->kobj
);
1493 kobject_put(&mgr
->kobj
);
1500 int omap_dss_get_num_overlay_managers(void)
1502 return num_managers
;
1504 EXPORT_SYMBOL(omap_dss_get_num_overlay_managers
);
1506 struct omap_overlay_manager
*omap_dss_get_overlay_manager(int num
)
1509 struct omap_overlay_manager
*mgr
;
1511 list_for_each_entry(mgr
, &manager_list
, list
) {
1518 EXPORT_SYMBOL(omap_dss_get_overlay_manager
);