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 static ssize_t
manager_cpr_enable_show(struct omap_overlay_manager
*mgr
,
281 return snprintf(buf
, PAGE_SIZE
, "%d\n", mgr
->info
.cpr_enable
);
284 static ssize_t
manager_cpr_enable_store(struct omap_overlay_manager
*mgr
,
285 const char *buf
, size_t size
)
287 struct omap_overlay_manager_info info
;
292 if (!dss_has_feature(FEAT_CPR
))
295 r
= kstrtoint(buf
, 0, &v
);
301 mgr
->get_manager_info(mgr
, &info
);
303 if (info
.cpr_enable
== enable
)
306 info
.cpr_enable
= enable
;
308 r
= mgr
->set_manager_info(mgr
, &info
);
319 static ssize_t
manager_cpr_coef_show(struct omap_overlay_manager
*mgr
,
322 struct omap_overlay_manager_info info
;
324 mgr
->get_manager_info(mgr
, &info
);
326 return snprintf(buf
, PAGE_SIZE
,
327 "%d %d %d %d %d %d %d %d %d\n",
339 static ssize_t
manager_cpr_coef_store(struct omap_overlay_manager
*mgr
,
340 const char *buf
, size_t size
)
342 struct omap_overlay_manager_info info
;
343 struct omap_dss_cpr_coefs coefs
;
347 if (!dss_has_feature(FEAT_CPR
))
350 if (sscanf(buf
, "%hd %hd %hd %hd %hd %hd %hd %hd %hd",
351 &coefs
.rr
, &coefs
.rg
, &coefs
.rb
,
352 &coefs
.gr
, &coefs
.gg
, &coefs
.gb
,
353 &coefs
.br
, &coefs
.bg
, &coefs
.bb
) != 9)
356 arr
= (s16
[]){ coefs
.rr
, coefs
.rg
, coefs
.rb
,
357 coefs
.gr
, coefs
.gg
, coefs
.gb
,
358 coefs
.br
, coefs
.bg
, coefs
.bb
};
360 for (i
= 0; i
< 9; ++i
) {
361 if (arr
[i
] < -512 || arr
[i
] > 511)
365 mgr
->get_manager_info(mgr
, &info
);
367 info
.cpr_coefs
= coefs
;
369 r
= mgr
->set_manager_info(mgr
, &info
);
380 struct manager_attribute
{
381 struct attribute attr
;
382 ssize_t (*show
)(struct omap_overlay_manager
*, char *);
383 ssize_t (*store
)(struct omap_overlay_manager
*, const char *, size_t);
386 #define MANAGER_ATTR(_name, _mode, _show, _store) \
387 struct manager_attribute manager_attr_##_name = \
388 __ATTR(_name, _mode, _show, _store)
390 static MANAGER_ATTR(name
, S_IRUGO
, manager_name_show
, NULL
);
391 static MANAGER_ATTR(display
, S_IRUGO
|S_IWUSR
,
392 manager_display_show
, manager_display_store
);
393 static MANAGER_ATTR(default_color
, S_IRUGO
|S_IWUSR
,
394 manager_default_color_show
, manager_default_color_store
);
395 static MANAGER_ATTR(trans_key_type
, S_IRUGO
|S_IWUSR
,
396 manager_trans_key_type_show
, manager_trans_key_type_store
);
397 static MANAGER_ATTR(trans_key_value
, S_IRUGO
|S_IWUSR
,
398 manager_trans_key_value_show
, manager_trans_key_value_store
);
399 static MANAGER_ATTR(trans_key_enabled
, S_IRUGO
|S_IWUSR
,
400 manager_trans_key_enabled_show
,
401 manager_trans_key_enabled_store
);
402 static MANAGER_ATTR(alpha_blending_enabled
, S_IRUGO
|S_IWUSR
,
403 manager_alpha_blending_enabled_show
,
404 manager_alpha_blending_enabled_store
);
405 static MANAGER_ATTR(cpr_enable
, S_IRUGO
|S_IWUSR
,
406 manager_cpr_enable_show
,
407 manager_cpr_enable_store
);
408 static MANAGER_ATTR(cpr_coef
, S_IRUGO
|S_IWUSR
,
409 manager_cpr_coef_show
,
410 manager_cpr_coef_store
);
413 static struct attribute
*manager_sysfs_attrs
[] = {
414 &manager_attr_name
.attr
,
415 &manager_attr_display
.attr
,
416 &manager_attr_default_color
.attr
,
417 &manager_attr_trans_key_type
.attr
,
418 &manager_attr_trans_key_value
.attr
,
419 &manager_attr_trans_key_enabled
.attr
,
420 &manager_attr_alpha_blending_enabled
.attr
,
421 &manager_attr_cpr_enable
.attr
,
422 &manager_attr_cpr_coef
.attr
,
426 static ssize_t
manager_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
429 struct omap_overlay_manager
*manager
;
430 struct manager_attribute
*manager_attr
;
432 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
433 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
435 if (!manager_attr
->show
)
438 return manager_attr
->show(manager
, buf
);
441 static ssize_t
manager_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
442 const char *buf
, size_t size
)
444 struct omap_overlay_manager
*manager
;
445 struct manager_attribute
*manager_attr
;
447 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
448 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
450 if (!manager_attr
->store
)
453 return manager_attr
->store(manager
, buf
, size
);
456 static const struct sysfs_ops manager_sysfs_ops
= {
457 .show
= manager_attr_show
,
458 .store
= manager_attr_store
,
461 static struct kobj_type manager_ktype
= {
462 .sysfs_ops
= &manager_sysfs_ops
,
463 .default_attrs
= manager_sysfs_attrs
,
467 * We have 4 levels of cache for the dispc settings. First two are in SW and
468 * the latter two in HW.
470 * +--------------------+
471 * |overlay/manager_info|
472 * +--------------------+
476 * +--------------------+
478 * +--------------------+
482 * +--------------------+
483 * | shadow registers |
484 * +--------------------+
486 * VFP or lcd/digit_enable
488 * +--------------------+
490 * +--------------------+
493 struct overlay_cache_data
{
494 /* If true, cache changed, but not written to shadow registers. Set
495 * in apply(), cleared when registers written. */
497 /* If true, shadow registers contain changed values not yet in real
498 * registers. Set when writing to shadow registers, cleared at
504 struct omap_overlay_info info
;
506 enum omap_channel channel
;
514 struct manager_cache_data
{
515 /* If true, cache changed, but not written to shadow registers. Set
516 * in apply(), cleared when registers written. */
518 /* If true, shadow registers contain changed values not yet in real
519 * registers. Set when writing to shadow registers, cleared at
523 struct omap_overlay_manager_info info
;
526 bool do_manual_update
;
528 /* manual update region */
531 /* enlarge the update area if the update area contains scaled
533 bool enlarge_update_area
;
538 struct overlay_cache_data overlay_cache
[MAX_DSS_OVERLAYS
];
539 struct manager_cache_data manager_cache
[MAX_DSS_MANAGERS
];
546 static int omap_dss_set_device(struct omap_overlay_manager
*mgr
,
547 struct omap_dss_device
*dssdev
)
552 if (dssdev
->manager
) {
553 DSSERR("display '%s' already has a manager '%s'\n",
554 dssdev
->name
, dssdev
->manager
->name
);
558 if ((mgr
->supported_displays
& dssdev
->type
) == 0) {
559 DSSERR("display '%s' does not support manager '%s'\n",
560 dssdev
->name
, mgr
->name
);
564 for (i
= 0; i
< mgr
->num_overlays
; i
++) {
565 struct omap_overlay
*ovl
= mgr
->overlays
[i
];
567 if (ovl
->manager
!= mgr
|| !ovl
->info
.enabled
)
570 r
= dss_check_overlay(ovl
, dssdev
);
575 dssdev
->manager
= mgr
;
576 mgr
->device
= dssdev
;
577 mgr
->device_changed
= true;
582 static int omap_dss_unset_device(struct omap_overlay_manager
*mgr
)
585 DSSERR("failed to unset display, display not set.\n");
589 mgr
->device
->manager
= NULL
;
591 mgr
->device_changed
= true;
596 static int dss_mgr_wait_for_vsync(struct omap_overlay_manager
*mgr
)
598 unsigned long timeout
= msecs_to_jiffies(500);
601 if (mgr
->device
->type
== OMAP_DISPLAY_TYPE_VENC
) {
602 irq
= DISPC_IRQ_EVSYNC_ODD
;
603 } else if (mgr
->device
->type
== OMAP_DISPLAY_TYPE_HDMI
) {
604 irq
= DISPC_IRQ_EVSYNC_EVEN
;
606 if (mgr
->id
== OMAP_DSS_CHANNEL_LCD
)
607 irq
= DISPC_IRQ_VSYNC
;
609 irq
= DISPC_IRQ_VSYNC2
;
611 return omap_dispc_wait_for_irq_interruptible_timeout(irq
, timeout
);
614 static int dss_mgr_wait_for_go(struct omap_overlay_manager
*mgr
)
616 unsigned long timeout
= msecs_to_jiffies(500);
617 struct manager_cache_data
*mc
;
621 struct omap_dss_device
*dssdev
= mgr
->device
;
623 if (!dssdev
|| dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
626 if (dssdev
->caps
& OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
)
629 if (dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
630 || dssdev
->type
== OMAP_DISPLAY_TYPE_HDMI
) {
631 irq
= DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_EVSYNC_EVEN
;
633 irq
= (dssdev
->manager
->id
== OMAP_DSS_CHANNEL_LCD
) ?
634 DISPC_IRQ_VSYNC
: DISPC_IRQ_VSYNC2
;
637 mc
= &dss_cache
.manager_cache
[mgr
->id
];
641 bool shadow_dirty
, dirty
;
643 spin_lock_irqsave(&dss_cache
.lock
, flags
);
645 shadow_dirty
= mc
->shadow_dirty
;
646 spin_unlock_irqrestore(&dss_cache
.lock
, flags
);
648 if (!dirty
&& !shadow_dirty
) {
653 /* 4 iterations is the worst case:
654 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
655 * 2 - first VSYNC, dirty = true
656 * 3 - dirty = false, shadow_dirty = true
657 * 4 - shadow_dirty = false */
659 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
665 r
= omap_dispc_wait_for_irq_interruptible_timeout(irq
, timeout
);
666 if (r
== -ERESTARTSYS
)
670 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr
->id
);
678 int dss_mgr_wait_for_go_ovl(struct omap_overlay
*ovl
)
680 unsigned long timeout
= msecs_to_jiffies(500);
681 struct overlay_cache_data
*oc
;
682 struct omap_dss_device
*dssdev
;
690 dssdev
= ovl
->manager
->device
;
692 if (!dssdev
|| dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
695 if (dssdev
->caps
& OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
)
698 if (dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
699 || dssdev
->type
== OMAP_DISPLAY_TYPE_HDMI
) {
700 irq
= DISPC_IRQ_EVSYNC_ODD
| DISPC_IRQ_EVSYNC_EVEN
;
702 irq
= (dssdev
->manager
->id
== OMAP_DSS_CHANNEL_LCD
) ?
703 DISPC_IRQ_VSYNC
: DISPC_IRQ_VSYNC2
;
706 oc
= &dss_cache
.overlay_cache
[ovl
->id
];
710 bool shadow_dirty
, dirty
;
712 spin_lock_irqsave(&dss_cache
.lock
, flags
);
714 shadow_dirty
= oc
->shadow_dirty
;
715 spin_unlock_irqrestore(&dss_cache
.lock
, flags
);
717 if (!dirty
&& !shadow_dirty
) {
722 /* 4 iterations is the worst case:
723 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
724 * 2 - first VSYNC, dirty = true
725 * 3 - dirty = false, shadow_dirty = true
726 * 4 - shadow_dirty = false */
728 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
734 r
= omap_dispc_wait_for_irq_interruptible_timeout(irq
, timeout
);
735 if (r
== -ERESTARTSYS
)
739 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl
->id
);
747 static int overlay_enabled(struct omap_overlay
*ovl
)
749 return ovl
->info
.enabled
&& ovl
->manager
&& ovl
->manager
->device
;
752 /* Is rect1 a subset of rect2? */
753 static bool rectangle_subset(int x1
, int y1
, int w1
, int h1
,
754 int x2
, int y2
, int w2
, int h2
)
756 if (x1
< x2
|| y1
< y2
)
759 if (x1
+ w1
> x2
+ w2
)
762 if (y1
+ h1
> y2
+ h2
)
768 /* Do rect1 and rect2 overlap? */
769 static bool rectangle_intersects(int x1
, int y1
, int w1
, int h1
,
770 int x2
, int y2
, int w2
, int h2
)
787 static bool dispc_is_overlay_scaled(struct overlay_cache_data
*oc
)
789 struct omap_overlay_info
*oi
= &oc
->info
;
791 if (oi
->out_width
!= 0 && oi
->width
!= oi
->out_width
)
794 if (oi
->out_height
!= 0 && oi
->height
!= oi
->out_height
)
800 static int configure_overlay(enum omap_plane plane
)
802 struct overlay_cache_data
*c
;
803 struct manager_cache_data
*mc
;
804 struct omap_overlay_info
*oi
;
805 struct omap_overlay_manager_info
*mi
;
810 u16 orig_w
, orig_h
, orig_outw
, orig_outh
;
812 DSSDBGF("%d", plane
);
814 c
= &dss_cache
.overlay_cache
[plane
];
818 dispc_enable_plane(plane
, 0);
822 mc
= &dss_cache
.manager_cache
[c
->channel
];
829 outw
= oi
->out_width
== 0 ? oi
->width
: oi
->out_width
;
830 outh
= oi
->out_height
== 0 ? oi
->height
: oi
->out_height
;
838 if (mc
->manual_update
&& mc
->do_manual_update
) {
840 unsigned scale_x_m
= w
, scale_x_d
= outw
;
841 unsigned scale_y_m
= h
, scale_y_d
= outh
;
843 /* If the overlay is outside the update region, disable it */
844 if (!rectangle_intersects(mc
->x
, mc
->y
, mc
->w
, mc
->h
,
846 dispc_enable_plane(plane
, 0);
850 switch (oi
->color_mode
) {
851 case OMAP_DSS_COLOR_NV12
:
854 case OMAP_DSS_COLOR_RGB16
:
855 case OMAP_DSS_COLOR_ARGB16
:
856 case OMAP_DSS_COLOR_YUV2
:
857 case OMAP_DSS_COLOR_UYVY
:
858 case OMAP_DSS_COLOR_RGBA16
:
859 case OMAP_DSS_COLOR_RGBX16
:
860 case OMAP_DSS_COLOR_ARGB16_1555
:
861 case OMAP_DSS_COLOR_XRGB16_1555
:
865 case OMAP_DSS_COLOR_RGB24P
:
869 case OMAP_DSS_COLOR_RGB24U
:
870 case OMAP_DSS_COLOR_ARGB32
:
871 case OMAP_DSS_COLOR_RGBA32
:
872 case OMAP_DSS_COLOR_RGBX32
:
880 if (mc
->x
> oi
->pos_x
) {
882 outw
-= (mc
->x
- oi
->pos_x
);
883 paddr
+= (mc
->x
- oi
->pos_x
) *
884 scale_x_m
/ scale_x_d
* bpp
/ 8;
886 x
= oi
->pos_x
- mc
->x
;
889 if (mc
->y
> oi
->pos_y
) {
891 outh
-= (mc
->y
- oi
->pos_y
);
892 paddr
+= (mc
->y
- oi
->pos_y
) *
893 scale_y_m
/ scale_y_d
*
894 oi
->screen_width
* bpp
/ 8;
896 y
= oi
->pos_y
- mc
->y
;
899 if (mc
->w
< (x
+ outw
))
900 outw
-= (x
+ outw
) - (mc
->w
);
902 if (mc
->h
< (y
+ outh
))
903 outh
-= (y
+ outh
) - (mc
->h
);
905 w
= w
* outw
/ orig_outw
;
906 h
= h
* outh
/ orig_outh
;
908 /* YUV mode overlay's input width has to be even and the
909 * algorithm above may adjust the width to be odd.
911 * Here we adjust the width if needed, preferring to increase
912 * the width if the original width was bigger.
915 (oi
->color_mode
== OMAP_DSS_COLOR_YUV2
||
916 oi
->color_mode
== OMAP_DSS_COLOR_UYVY
)) {
924 r
= dispc_setup_plane(plane
,
941 /* this shouldn't happen */
942 DSSERR("dispc_setup_plane failed for ovl %d\n", plane
);
943 dispc_enable_plane(plane
, 0);
947 dispc_enable_replication(plane
, c
->replication
);
949 dispc_set_fifo_threshold(plane
, c
->fifo_low
, c
->fifo_high
);
951 dispc_enable_plane(plane
, 1);
956 static void configure_manager(enum omap_channel channel
)
958 struct omap_overlay_manager_info
*mi
;
960 DSSDBGF("%d", channel
);
962 /* picking info from the cache */
963 mi
= &dss_cache
.manager_cache
[channel
].info
;
965 dispc_set_default_color(channel
, mi
->default_color
);
966 dispc_set_trans_key(channel
, mi
->trans_key_type
, mi
->trans_key
);
967 dispc_enable_trans_key(channel
, mi
->trans_enabled
);
968 dispc_enable_alpha_blending(channel
, mi
->alpha_enabled
);
969 if (dss_has_feature(FEAT_CPR
)) {
970 dispc_enable_cpr(channel
, mi
->cpr_enable
);
971 dispc_set_cpr_coef(channel
, &mi
->cpr_coefs
);
975 /* configure_dispc() tries to write values from cache to shadow registers.
976 * It writes only to those managers/overlays that are not busy.
977 * returns 0 if everything could be written to shadow registers.
978 * returns 1 if not everything could be written to shadow registers. */
979 static int configure_dispc(void)
981 struct overlay_cache_data
*oc
;
982 struct manager_cache_data
*mc
;
983 const int num_ovls
= dss_feat_get_num_ovls();
984 const int num_mgrs
= dss_feat_get_num_mgrs();
987 bool mgr_busy
[MAX_DSS_MANAGERS
];
988 bool mgr_go
[MAX_DSS_MANAGERS
];
994 for (i
= 0; i
< num_mgrs
; i
++) {
995 mgr_busy
[i
] = dispc_go_busy(i
);
999 /* Commit overlay settings */
1000 for (i
= 0; i
< num_ovls
; ++i
) {
1001 oc
= &dss_cache
.overlay_cache
[i
];
1002 mc
= &dss_cache
.manager_cache
[oc
->channel
];
1007 if (mc
->manual_update
&& !mc
->do_manual_update
)
1010 if (mgr_busy
[oc
->channel
]) {
1015 r
= configure_overlay(i
);
1017 DSSERR("configure_overlay %d failed\n", i
);
1020 oc
->shadow_dirty
= true;
1021 mgr_go
[oc
->channel
] = true;
1024 /* Commit manager settings */
1025 for (i
= 0; i
< num_mgrs
; ++i
) {
1026 mc
= &dss_cache
.manager_cache
[i
];
1031 if (mc
->manual_update
&& !mc
->do_manual_update
)
1039 configure_manager(i
);
1041 mc
->shadow_dirty
= true;
1046 for (i
= 0; i
< num_mgrs
; ++i
) {
1047 mc
= &dss_cache
.manager_cache
[i
];
1052 /* We don't need GO with manual update display. LCD iface will
1053 * always be turned off after frame, and new settings will be
1054 * taken in to use at next update */
1055 if (!mc
->manual_update
)
1067 /* Make the coordinates even. There are some strange problems with OMAP and
1068 * partial DSI update when the update widths are odd. */
1069 static void make_even(u16
*x
, u16
*w
)
1083 /* Configure dispc for partial update. Return possibly modified update
1085 void dss_setup_partial_planes(struct omap_dss_device
*dssdev
,
1086 u16
*xi
, u16
*yi
, u16
*wi
, u16
*hi
, bool enlarge_update_area
)
1088 struct overlay_cache_data
*oc
;
1089 struct manager_cache_data
*mc
;
1090 struct omap_overlay_info
*oi
;
1091 const int num_ovls
= dss_feat_get_num_ovls();
1092 struct omap_overlay_manager
*mgr
;
1095 unsigned long flags
;
1103 DSSDBG("dispc_setup_partial_planes %d,%d %dx%d\n",
1104 *xi
, *yi
, *wi
, *hi
);
1106 mgr
= dssdev
->manager
;
1109 DSSDBG("no manager\n");
1115 spin_lock_irqsave(&dss_cache
.lock
, flags
);
1118 * Execute the outer loop until the inner loop has completed
1119 * once without increasing the update area. This will ensure that
1120 * all scaled overlays end up completely within the update area.
1123 area_changed
= false;
1125 /* We need to show the whole overlay if it is scaled. So look
1126 * for those, and make the update area larger if found.
1127 * Also mark the overlay cache dirty */
1128 for (i
= 0; i
< num_ovls
; ++i
) {
1129 unsigned x1
, y1
, x2
, y2
;
1130 unsigned outw
, outh
;
1132 oc
= &dss_cache
.overlay_cache
[i
];
1135 if (oc
->channel
!= mgr
->id
)
1140 if (!enlarge_update_area
)
1146 if (!dispc_is_overlay_scaled(oc
))
1149 outw
= oi
->out_width
== 0 ?
1150 oi
->width
: oi
->out_width
;
1151 outh
= oi
->out_height
== 0 ?
1152 oi
->height
: oi
->out_height
;
1154 /* is the overlay outside the update region? */
1155 if (!rectangle_intersects(x
, y
, w
, h
,
1156 oi
->pos_x
, oi
->pos_y
,
1160 /* if the overlay totally inside the update region? */
1161 if (rectangle_subset(oi
->pos_x
, oi
->pos_y
, outw
, outh
,
1175 if ((x
+ w
) < (oi
->pos_x
+ outw
))
1176 x2
= oi
->pos_x
+ outw
;
1180 if ((y
+ h
) < (oi
->pos_y
+ outh
))
1181 y2
= oi
->pos_y
+ outh
;
1192 DSSDBG("changing upd area due to ovl(%d) "
1193 "scaling %d,%d %dx%d\n",
1196 area_changed
= true;
1198 } while (area_changed
);
1200 mc
= &dss_cache
.manager_cache
[mgr
->id
];
1201 mc
->do_manual_update
= true;
1202 mc
->enlarge_update_area
= enlarge_update_area
;
1210 mc
->do_manual_update
= false;
1212 spin_unlock_irqrestore(&dss_cache
.lock
, flags
);
1220 void dss_start_update(struct omap_dss_device
*dssdev
)
1222 struct manager_cache_data
*mc
;
1223 struct overlay_cache_data
*oc
;
1224 const int num_ovls
= dss_feat_get_num_ovls();
1225 const int num_mgrs
= dss_feat_get_num_mgrs();
1226 struct omap_overlay_manager
*mgr
;
1229 mgr
= dssdev
->manager
;
1231 for (i
= 0; i
< num_ovls
; ++i
) {
1232 oc
= &dss_cache
.overlay_cache
[i
];
1233 if (oc
->channel
!= mgr
->id
)
1236 oc
->shadow_dirty
= false;
1239 for (i
= 0; i
< num_mgrs
; ++i
) {
1240 mc
= &dss_cache
.manager_cache
[i
];
1244 mc
->shadow_dirty
= false;
1247 dssdev
->manager
->enable(dssdev
->manager
);
1250 static void dss_apply_irq_handler(void *data
, u32 mask
)
1252 struct manager_cache_data
*mc
;
1253 struct overlay_cache_data
*oc
;
1254 const int num_ovls
= dss_feat_get_num_ovls();
1255 const int num_mgrs
= dss_feat_get_num_mgrs();
1257 bool mgr_busy
[MAX_DSS_MANAGERS
];
1260 for (i
= 0; i
< num_mgrs
; i
++)
1261 mgr_busy
[i
] = dispc_go_busy(i
);
1263 spin_lock(&dss_cache
.lock
);
1265 for (i
= 0; i
< num_ovls
; ++i
) {
1266 oc
= &dss_cache
.overlay_cache
[i
];
1267 if (!mgr_busy
[oc
->channel
])
1268 oc
->shadow_dirty
= false;
1271 for (i
= 0; i
< num_mgrs
; ++i
) {
1272 mc
= &dss_cache
.manager_cache
[i
];
1274 mc
->shadow_dirty
= false;
1277 r
= configure_dispc();
1281 /* re-read busy flags */
1282 for (i
= 0; i
< num_mgrs
; i
++)
1283 mgr_busy
[i
] = dispc_go_busy(i
);
1285 /* keep running as long as there are busy managers, so that
1286 * we can collect overlay-applied information */
1287 for (i
= 0; i
< num_mgrs
; ++i
) {
1292 irq_mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_ODD
|
1293 DISPC_IRQ_EVSYNC_EVEN
;
1294 if (dss_has_feature(FEAT_MGR_LCD2
))
1295 irq_mask
|= DISPC_IRQ_VSYNC2
;
1297 omap_dispc_unregister_isr(dss_apply_irq_handler
, NULL
, irq_mask
);
1298 dss_cache
.irq_enabled
= false;
1301 spin_unlock(&dss_cache
.lock
);
1304 static int omap_dss_mgr_apply(struct omap_overlay_manager
*mgr
)
1306 struct overlay_cache_data
*oc
;
1307 struct manager_cache_data
*mc
;
1309 struct omap_overlay
*ovl
;
1310 int num_planes_enabled
= 0;
1312 unsigned long flags
;
1315 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr
->name
);
1317 r
= dispc_runtime_get();
1321 spin_lock_irqsave(&dss_cache
.lock
, flags
);
1323 /* Configure overlays */
1324 for (i
= 0; i
< omap_dss_get_num_overlays(); ++i
) {
1325 struct omap_dss_device
*dssdev
;
1327 ovl
= omap_dss_get_overlay(i
);
1329 if (!(ovl
->caps
& OMAP_DSS_OVL_CAP_DISPC
))
1332 oc
= &dss_cache
.overlay_cache
[ovl
->id
];
1334 if (!overlay_enabled(ovl
)) {
1336 oc
->enabled
= false;
1342 if (!ovl
->info_dirty
) {
1344 ++num_planes_enabled
;
1348 dssdev
= ovl
->manager
->device
;
1350 if (dss_check_overlay(ovl
, dssdev
)) {
1352 oc
->enabled
= false;
1358 ovl
->info_dirty
= false;
1360 oc
->info
= ovl
->info
;
1363 dss_use_replication(dssdev
, ovl
->info
.color_mode
);
1365 oc
->ilace
= dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
;
1367 oc
->channel
= ovl
->manager
->id
;
1371 ++num_planes_enabled
;
1374 /* Configure managers */
1375 list_for_each_entry(mgr
, &manager_list
, list
) {
1376 struct omap_dss_device
*dssdev
;
1378 if (!(mgr
->caps
& OMAP_DSS_OVL_MGR_CAP_DISPC
))
1381 mc
= &dss_cache
.manager_cache
[mgr
->id
];
1383 if (mgr
->device_changed
) {
1384 mgr
->device_changed
= false;
1385 mgr
->info_dirty
= true;
1388 if (!mgr
->info_dirty
)
1394 dssdev
= mgr
->device
;
1396 mgr
->info_dirty
= false;
1398 mc
->info
= mgr
->info
;
1401 dssdev
->caps
& OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
;
1404 /* XXX TODO: Try to get fifomerge working. The problem is that it
1405 * affects both managers, not individually but at the same time. This
1406 * means the change has to be well synchronized. I guess the proper way
1407 * is to have a two step process for fifo merge:
1409 * 1. disable other planes, leaving one plane enabled
1410 * 2. wait until the planes are disabled on HW
1411 * 3. config merged fifo thresholds, enable fifomerge
1412 * fifomerge disable:
1413 * 1. config unmerged fifo thresholds, disable fifomerge
1414 * 2. wait until fifo changes are in HW
1417 use_fifomerge
= false;
1419 /* Configure overlay fifos */
1420 for (i
= 0; i
< omap_dss_get_num_overlays(); ++i
) {
1421 struct omap_dss_device
*dssdev
;
1422 u32 size
, burst_size
;
1424 ovl
= omap_dss_get_overlay(i
);
1426 if (!(ovl
->caps
& OMAP_DSS_OVL_CAP_DISPC
))
1429 oc
= &dss_cache
.overlay_cache
[ovl
->id
];
1434 dssdev
= ovl
->manager
->device
;
1436 size
= dispc_get_plane_fifo_size(ovl
->id
);
1440 burst_size
= dispc_get_burst_size(ovl
->id
);
1442 switch (dssdev
->type
) {
1443 case OMAP_DISPLAY_TYPE_DPI
:
1444 case OMAP_DISPLAY_TYPE_DBI
:
1445 case OMAP_DISPLAY_TYPE_SDI
:
1446 case OMAP_DISPLAY_TYPE_VENC
:
1447 case OMAP_DISPLAY_TYPE_HDMI
:
1448 default_get_overlay_fifo_thresholds(ovl
->id
, size
,
1449 burst_size
, &oc
->fifo_low
,
1452 #ifdef CONFIG_OMAP2_DSS_DSI
1453 case OMAP_DISPLAY_TYPE_DSI
:
1454 dsi_get_overlay_fifo_thresholds(ovl
->id
, size
,
1455 burst_size
, &oc
->fifo_low
,
1465 if (!dss_cache
.irq_enabled
) {
1468 mask
= DISPC_IRQ_VSYNC
| DISPC_IRQ_EVSYNC_ODD
|
1469 DISPC_IRQ_EVSYNC_EVEN
;
1470 if (dss_has_feature(FEAT_MGR_LCD2
))
1471 mask
|= DISPC_IRQ_VSYNC2
;
1473 r
= omap_dispc_register_isr(dss_apply_irq_handler
, NULL
, mask
);
1474 dss_cache
.irq_enabled
= true;
1478 spin_unlock_irqrestore(&dss_cache
.lock
, flags
);
1480 dispc_runtime_put();
1485 static int dss_check_manager(struct omap_overlay_manager
*mgr
)
1487 /* OMAP supports only graphics source transparency color key and alpha
1488 * blending simultaneously. See TRM 15.4.2.4.2.2 Alpha Mode */
1490 if (mgr
->info
.alpha_enabled
&& mgr
->info
.trans_enabled
&&
1491 mgr
->info
.trans_key_type
!= OMAP_DSS_COLOR_KEY_GFX_DST
)
1497 static int omap_dss_mgr_set_info(struct omap_overlay_manager
*mgr
,
1498 struct omap_overlay_manager_info
*info
)
1501 struct omap_overlay_manager_info old_info
;
1503 old_info
= mgr
->info
;
1506 r
= dss_check_manager(mgr
);
1508 mgr
->info
= old_info
;
1512 mgr
->info_dirty
= true;
1517 static void omap_dss_mgr_get_info(struct omap_overlay_manager
*mgr
,
1518 struct omap_overlay_manager_info
*info
)
1523 static int dss_mgr_enable(struct omap_overlay_manager
*mgr
)
1525 dispc_enable_channel(mgr
->id
, 1);
1529 static int dss_mgr_disable(struct omap_overlay_manager
*mgr
)
1531 dispc_enable_channel(mgr
->id
, 0);
1535 static void omap_dss_add_overlay_manager(struct omap_overlay_manager
*manager
)
1538 list_add_tail(&manager
->list
, &manager_list
);
1541 int dss_init_overlay_managers(struct platform_device
*pdev
)
1545 spin_lock_init(&dss_cache
.lock
);
1547 INIT_LIST_HEAD(&manager_list
);
1551 for (i
= 0; i
< dss_feat_get_num_mgrs(); ++i
) {
1552 struct omap_overlay_manager
*mgr
;
1553 mgr
= kzalloc(sizeof(*mgr
), GFP_KERNEL
);
1555 BUG_ON(mgr
== NULL
);
1560 mgr
->id
= OMAP_DSS_CHANNEL_LCD
;
1564 mgr
->id
= OMAP_DSS_CHANNEL_DIGIT
;
1568 mgr
->id
= OMAP_DSS_CHANNEL_LCD2
;
1572 mgr
->set_device
= &omap_dss_set_device
;
1573 mgr
->unset_device
= &omap_dss_unset_device
;
1574 mgr
->apply
= &omap_dss_mgr_apply
;
1575 mgr
->set_manager_info
= &omap_dss_mgr_set_info
;
1576 mgr
->get_manager_info
= &omap_dss_mgr_get_info
;
1577 mgr
->wait_for_go
= &dss_mgr_wait_for_go
;
1578 mgr
->wait_for_vsync
= &dss_mgr_wait_for_vsync
;
1580 mgr
->enable
= &dss_mgr_enable
;
1581 mgr
->disable
= &dss_mgr_disable
;
1583 mgr
->caps
= OMAP_DSS_OVL_MGR_CAP_DISPC
;
1584 mgr
->supported_displays
=
1585 dss_feat_get_supported_displays(mgr
->id
);
1587 dss_overlay_setup_dispc_manager(mgr
);
1589 omap_dss_add_overlay_manager(mgr
);
1591 r
= kobject_init_and_add(&mgr
->kobj
, &manager_ktype
,
1592 &pdev
->dev
.kobj
, "manager%d", i
);
1595 DSSERR("failed to create sysfs file\n");
1602 int omap_dss_mgr_apply_l4(struct omap_overlay_manager
*mgr
)
1604 DSSDBG("omap_dss_mgr_apply_l4(%s)\n", mgr
->name
);
1609 struct omap_overlay_manager
*mgr
;
1610 mgr
= kzalloc(sizeof(*mgr
), GFP_KERNEL
);
1612 BUG_ON(mgr
== NULL
);
1615 mgr
->supported_displays
=
1616 OMAP_DISPLAY_TYPE_DBI
| OMAP_DISPLAY_TYPE_DSI
;
1618 mgr
->set_device
= &omap_dss_set_device
;
1619 mgr
->unset_device
= &omap_dss_unset_device
;
1620 mgr
->apply
= &omap_dss_mgr_apply_l4
;
1621 mgr
->set_manager_info
= &omap_dss_mgr_set_info
;
1622 mgr
->get_manager_info
= &omap_dss_mgr_get_info
;
1624 dss_overlay_setup_l4_manager(mgr
);
1626 omap_dss_add_overlay_manager(mgr
);
1628 r
= kobject_init_and_add(&mgr
->kobj
, &manager_ktype
,
1629 &pdev
->dev
.kobj
, "managerl4");
1632 DSSERR("failed to create sysfs file\n");
1639 void dss_uninit_overlay_managers(struct platform_device
*pdev
)
1641 struct omap_overlay_manager
*mgr
;
1643 while (!list_empty(&manager_list
)) {
1644 mgr
= list_first_entry(&manager_list
,
1645 struct omap_overlay_manager
, list
);
1646 list_del(&mgr
->list
);
1647 kobject_del(&mgr
->kobj
);
1648 kobject_put(&mgr
->kobj
);
1655 int omap_dss_get_num_overlay_managers(void)
1657 return num_managers
;
1659 EXPORT_SYMBOL(omap_dss_get_num_overlay_managers
);
1661 struct omap_overlay_manager
*omap_dss_get_overlay_manager(int num
)
1664 struct omap_overlay_manager
*mgr
;
1666 list_for_each_entry(mgr
, &manager_list
, list
) {
1673 EXPORT_SYMBOL(omap_dss_get_overlay_manager
);