2 * linux/drivers/video/omap2/dss/overlay.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 "OVERLAY"
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/err.h>
28 #include <linux/sysfs.h>
29 #include <linux/kobject.h>
30 #include <linux/platform_device.h>
31 #include <linux/delay.h>
32 #include <linux/slab.h>
34 #include <plat/display.h>
38 #include "dss_features.h"
40 static int num_overlays
;
41 static struct list_head overlay_list
;
43 static ssize_t
overlay_name_show(struct omap_overlay
*ovl
, char *buf
)
45 return snprintf(buf
, PAGE_SIZE
, "%s\n", ovl
->name
);
48 static ssize_t
overlay_manager_show(struct omap_overlay
*ovl
, char *buf
)
50 return snprintf(buf
, PAGE_SIZE
, "%s\n",
51 ovl
->manager
? ovl
->manager
->name
: "<none>");
54 static ssize_t
overlay_manager_store(struct omap_overlay
*ovl
, const char *buf
,
58 struct omap_overlay_manager
*mgr
= NULL
;
59 struct omap_overlay_manager
*old_mgr
;
62 if (buf
[size
-1] == '\n')
66 for (i
= 0; i
< omap_dss_get_num_overlay_managers(); ++i
) {
67 mgr
= omap_dss_get_overlay_manager(i
);
69 if (sysfs_streq(buf
, mgr
->name
))
76 if (len
> 0 && mgr
== NULL
)
80 DSSDBG("manager %s found\n", mgr
->name
);
82 if (mgr
== ovl
->manager
)
85 old_mgr
= ovl
->manager
;
87 /* detach old manager */
89 r
= ovl
->unset_manager(ovl
);
91 DSSERR("detach failed\n");
95 r
= old_mgr
->apply(old_mgr
);
101 r
= ovl
->set_manager(ovl
, mgr
);
103 DSSERR("Failed to attach overlay\n");
115 static ssize_t
overlay_input_size_show(struct omap_overlay
*ovl
, char *buf
)
117 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
118 ovl
->info
.width
, ovl
->info
.height
);
121 static ssize_t
overlay_screen_width_show(struct omap_overlay
*ovl
, char *buf
)
123 return snprintf(buf
, PAGE_SIZE
, "%d\n", ovl
->info
.screen_width
);
126 static ssize_t
overlay_position_show(struct omap_overlay
*ovl
, char *buf
)
128 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
129 ovl
->info
.pos_x
, ovl
->info
.pos_y
);
132 static ssize_t
overlay_position_store(struct omap_overlay
*ovl
,
133 const char *buf
, size_t size
)
137 struct omap_overlay_info info
;
139 ovl
->get_overlay_info(ovl
, &info
);
141 info
.pos_x
= simple_strtoul(buf
, &last
, 10);
143 if (last
- buf
>= size
)
146 info
.pos_y
= simple_strtoul(last
, &last
, 10);
148 r
= ovl
->set_overlay_info(ovl
, &info
);
153 r
= ovl
->manager
->apply(ovl
->manager
);
161 static ssize_t
overlay_output_size_show(struct omap_overlay
*ovl
, char *buf
)
163 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
164 ovl
->info
.out_width
, ovl
->info
.out_height
);
167 static ssize_t
overlay_output_size_store(struct omap_overlay
*ovl
,
168 const char *buf
, size_t size
)
172 struct omap_overlay_info info
;
174 ovl
->get_overlay_info(ovl
, &info
);
176 info
.out_width
= simple_strtoul(buf
, &last
, 10);
178 if (last
- buf
>= size
)
181 info
.out_height
= simple_strtoul(last
, &last
, 10);
183 r
= ovl
->set_overlay_info(ovl
, &info
);
188 r
= ovl
->manager
->apply(ovl
->manager
);
196 static ssize_t
overlay_enabled_show(struct omap_overlay
*ovl
, char *buf
)
198 return snprintf(buf
, PAGE_SIZE
, "%d\n", ovl
->info
.enabled
);
201 static ssize_t
overlay_enabled_store(struct omap_overlay
*ovl
, const char *buf
,
205 struct omap_overlay_info info
;
207 ovl
->get_overlay_info(ovl
, &info
);
209 info
.enabled
= simple_strtoul(buf
, NULL
, 10);
211 r
= ovl
->set_overlay_info(ovl
, &info
);
216 r
= ovl
->manager
->apply(ovl
->manager
);
224 static ssize_t
overlay_global_alpha_show(struct omap_overlay
*ovl
, char *buf
)
226 return snprintf(buf
, PAGE_SIZE
, "%d\n",
227 ovl
->info
.global_alpha
);
230 static ssize_t
overlay_global_alpha_store(struct omap_overlay
*ovl
,
231 const char *buf
, size_t size
)
234 struct omap_overlay_info info
;
236 ovl
->get_overlay_info(ovl
, &info
);
238 /* Video1 plane does not support global alpha
239 * to always make it 255 completely opaque
241 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1
) &&
242 ovl
->id
== OMAP_DSS_VIDEO1
)
243 info
.global_alpha
= 255;
245 info
.global_alpha
= simple_strtoul(buf
, NULL
, 10);
247 r
= ovl
->set_overlay_info(ovl
, &info
);
252 r
= ovl
->manager
->apply(ovl
->manager
);
260 static ssize_t
overlay_pre_mult_alpha_show(struct omap_overlay
*ovl
,
263 return snprintf(buf
, PAGE_SIZE
, "%d\n",
264 ovl
->info
.pre_mult_alpha
);
267 static ssize_t
overlay_pre_mult_alpha_store(struct omap_overlay
*ovl
,
268 const char *buf
, size_t size
)
271 struct omap_overlay_info info
;
273 ovl
->get_overlay_info(ovl
, &info
);
275 /* only GFX and Video2 plane support pre alpha multiplied
276 * set zero for Video1 plane
278 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1
) &&
279 ovl
->id
== OMAP_DSS_VIDEO1
)
280 info
.pre_mult_alpha
= 0;
282 info
.pre_mult_alpha
= simple_strtoul(buf
, NULL
, 10);
284 r
= ovl
->set_overlay_info(ovl
, &info
);
289 r
= ovl
->manager
->apply(ovl
->manager
);
297 struct overlay_attribute
{
298 struct attribute attr
;
299 ssize_t (*show
)(struct omap_overlay
*, char *);
300 ssize_t (*store
)(struct omap_overlay
*, const char *, size_t);
303 #define OVERLAY_ATTR(_name, _mode, _show, _store) \
304 struct overlay_attribute overlay_attr_##_name = \
305 __ATTR(_name, _mode, _show, _store)
307 static OVERLAY_ATTR(name
, S_IRUGO
, overlay_name_show
, NULL
);
308 static OVERLAY_ATTR(manager
, S_IRUGO
|S_IWUSR
,
309 overlay_manager_show
, overlay_manager_store
);
310 static OVERLAY_ATTR(input_size
, S_IRUGO
, overlay_input_size_show
, NULL
);
311 static OVERLAY_ATTR(screen_width
, S_IRUGO
, overlay_screen_width_show
, NULL
);
312 static OVERLAY_ATTR(position
, S_IRUGO
|S_IWUSR
,
313 overlay_position_show
, overlay_position_store
);
314 static OVERLAY_ATTR(output_size
, S_IRUGO
|S_IWUSR
,
315 overlay_output_size_show
, overlay_output_size_store
);
316 static OVERLAY_ATTR(enabled
, S_IRUGO
|S_IWUSR
,
317 overlay_enabled_show
, overlay_enabled_store
);
318 static OVERLAY_ATTR(global_alpha
, S_IRUGO
|S_IWUSR
,
319 overlay_global_alpha_show
, overlay_global_alpha_store
);
320 static OVERLAY_ATTR(pre_mult_alpha
, S_IRUGO
|S_IWUSR
,
321 overlay_pre_mult_alpha_show
,
322 overlay_pre_mult_alpha_store
);
324 static struct attribute
*overlay_sysfs_attrs
[] = {
325 &overlay_attr_name
.attr
,
326 &overlay_attr_manager
.attr
,
327 &overlay_attr_input_size
.attr
,
328 &overlay_attr_screen_width
.attr
,
329 &overlay_attr_position
.attr
,
330 &overlay_attr_output_size
.attr
,
331 &overlay_attr_enabled
.attr
,
332 &overlay_attr_global_alpha
.attr
,
333 &overlay_attr_pre_mult_alpha
.attr
,
337 static ssize_t
overlay_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
340 struct omap_overlay
*overlay
;
341 struct overlay_attribute
*overlay_attr
;
343 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
344 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
346 if (!overlay_attr
->show
)
349 return overlay_attr
->show(overlay
, buf
);
352 static ssize_t
overlay_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
353 const char *buf
, size_t size
)
355 struct omap_overlay
*overlay
;
356 struct overlay_attribute
*overlay_attr
;
358 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
359 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
361 if (!overlay_attr
->store
)
364 return overlay_attr
->store(overlay
, buf
, size
);
367 static const struct sysfs_ops overlay_sysfs_ops
= {
368 .show
= overlay_attr_show
,
369 .store
= overlay_attr_store
,
372 static struct kobj_type overlay_ktype
= {
373 .sysfs_ops
= &overlay_sysfs_ops
,
374 .default_attrs
= overlay_sysfs_attrs
,
377 /* Check if overlay parameters are compatible with display */
378 int dss_check_overlay(struct omap_overlay
*ovl
, struct omap_dss_device
*dssdev
)
380 struct omap_overlay_info
*info
;
387 if (!ovl
->info
.enabled
)
392 if (info
->paddr
== 0) {
393 DSSDBG("check_overlay failed: paddr 0\n");
397 dssdev
->driver
->get_resolution(dssdev
, &dw
, &dh
);
399 DSSDBG("check_overlay %d: (%d,%d %dx%d -> %dx%d) disp (%dx%d)\n",
401 info
->pos_x
, info
->pos_y
,
402 info
->width
, info
->height
,
403 info
->out_width
, info
->out_height
,
406 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0) {
410 if (info
->out_width
== 0)
413 outw
= info
->out_width
;
415 if (info
->out_height
== 0)
418 outh
= info
->out_height
;
421 if (dw
< info
->pos_x
+ outw
) {
422 DSSDBG("check_overlay failed 1: %d < %d + %d\n",
423 dw
, info
->pos_x
, outw
);
427 if (dh
< info
->pos_y
+ outh
) {
428 DSSDBG("check_overlay failed 2: %d < %d + %d\n",
429 dh
, info
->pos_y
, outh
);
433 if ((ovl
->supported_modes
& info
->color_mode
) == 0) {
434 DSSERR("overlay doesn't support mode %d\n", info
->color_mode
);
441 static int dss_ovl_set_overlay_info(struct omap_overlay
*ovl
,
442 struct omap_overlay_info
*info
)
445 struct omap_overlay_info old_info
;
447 old_info
= ovl
->info
;
451 r
= dss_check_overlay(ovl
, ovl
->manager
->device
);
453 ovl
->info
= old_info
;
458 ovl
->info_dirty
= true;
463 static void dss_ovl_get_overlay_info(struct omap_overlay
*ovl
,
464 struct omap_overlay_info
*info
)
469 static int dss_ovl_wait_for_go(struct omap_overlay
*ovl
)
471 return dss_mgr_wait_for_go_ovl(ovl
);
474 static int omap_dss_set_manager(struct omap_overlay
*ovl
,
475 struct omap_overlay_manager
*mgr
)
481 DSSERR("overlay '%s' already has a manager '%s'\n",
482 ovl
->name
, ovl
->manager
->name
);
486 if (ovl
->info
.enabled
) {
487 DSSERR("overlay has to be disabled to change the manager\n");
493 dss_clk_enable(DSS_CLK_ICK
| DSS_CLK_FCK
);
494 /* XXX: on manual update display, in auto update mode, a bug happens
495 * here. When an overlay is first enabled on LCD, then it's disabled,
496 * and the manager is changed to TV, we sometimes get SYNC_LOST_DIGIT
497 * errors. Waiting before changing the channel_out fixes it. I'm
498 * guessing that the overlay is still somehow being used for the LCD,
499 * but I don't understand how or why. */
501 dispc_set_channel_out(ovl
->id
, mgr
->id
);
502 dss_clk_disable(DSS_CLK_ICK
| DSS_CLK_FCK
);
507 static int omap_dss_unset_manager(struct omap_overlay
*ovl
)
512 DSSERR("failed to detach overlay: manager not set\n");
516 if (ovl
->info
.enabled
) {
517 DSSERR("overlay has to be disabled to unset the manager\n");
521 r
= ovl
->wait_for_go(ovl
);
530 int omap_dss_get_num_overlays(void)
534 EXPORT_SYMBOL(omap_dss_get_num_overlays
);
536 struct omap_overlay
*omap_dss_get_overlay(int num
)
539 struct omap_overlay
*ovl
;
541 list_for_each_entry(ovl
, &overlay_list
, list
) {
548 EXPORT_SYMBOL(omap_dss_get_overlay
);
550 static void omap_dss_add_overlay(struct omap_overlay
*overlay
)
553 list_add_tail(&overlay
->list
, &overlay_list
);
556 static struct omap_overlay
*dispc_overlays
[MAX_DSS_OVERLAYS
];
558 void dss_overlay_setup_dispc_manager(struct omap_overlay_manager
*mgr
)
560 mgr
->num_overlays
= dss_feat_get_num_ovls();
561 mgr
->overlays
= dispc_overlays
;
565 static struct omap_overlay
*l4_overlays
[1];
566 void dss_overlay_setup_l4_manager(struct omap_overlay_manager
*mgr
)
568 mgr
->num_overlays
= 1;
569 mgr
->overlays
= l4_overlays
;
573 void dss_init_overlays(struct platform_device
*pdev
)
577 INIT_LIST_HEAD(&overlay_list
);
581 for (i
= 0; i
< dss_feat_get_num_ovls(); ++i
) {
582 struct omap_overlay
*ovl
;
583 ovl
= kzalloc(sizeof(*ovl
), GFP_KERNEL
);
590 ovl
->id
= OMAP_DSS_GFX
;
591 ovl
->caps
= OMAP_DSS_OVL_CAP_DISPC
;
592 ovl
->info
.global_alpha
= 255;
596 ovl
->id
= OMAP_DSS_VIDEO1
;
597 ovl
->caps
= OMAP_DSS_OVL_CAP_SCALE
|
598 OMAP_DSS_OVL_CAP_DISPC
;
599 ovl
->info
.global_alpha
= 255;
603 ovl
->id
= OMAP_DSS_VIDEO2
;
604 ovl
->caps
= OMAP_DSS_OVL_CAP_SCALE
|
605 OMAP_DSS_OVL_CAP_DISPC
;
606 ovl
->info
.global_alpha
= 255;
610 ovl
->set_manager
= &omap_dss_set_manager
;
611 ovl
->unset_manager
= &omap_dss_unset_manager
;
612 ovl
->set_overlay_info
= &dss_ovl_set_overlay_info
;
613 ovl
->get_overlay_info
= &dss_ovl_get_overlay_info
;
614 ovl
->wait_for_go
= &dss_ovl_wait_for_go
;
616 ovl
->supported_modes
=
617 dss_feat_get_supported_color_modes(ovl
->id
);
619 omap_dss_add_overlay(ovl
);
621 r
= kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
622 &pdev
->dev
.kobj
, "overlay%d", i
);
625 DSSERR("failed to create sysfs file\n");
629 dispc_overlays
[i
] = ovl
;
634 struct omap_overlay
*ovl
;
635 ovl
= kzalloc(sizeof(*ovl
), GFP_KERNEL
);
640 ovl
->supported_modes
= OMAP_DSS_COLOR_RGB24U
;
642 ovl
->set_manager
= &omap_dss_set_manager
;
643 ovl
->unset_manager
= &omap_dss_unset_manager
;
644 ovl
->set_overlay_info
= &dss_ovl_set_overlay_info
;
645 ovl
->get_overlay_info
= &dss_ovl_get_overlay_info
;
647 omap_dss_add_overlay(ovl
);
649 r
= kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
650 &pdev
->dev
.kobj
, "overlayl4");
653 DSSERR("failed to create sysfs file\n");
655 l4_overlays
[0] = ovl
;
660 /* connect overlays to the new device, if not already connected. if force
661 * selected, connect always. */
662 void dss_recheck_connections(struct omap_dss_device
*dssdev
, bool force
)
665 struct omap_overlay_manager
*lcd_mgr
;
666 struct omap_overlay_manager
*tv_mgr
;
667 struct omap_overlay_manager
*lcd2_mgr
= NULL
;
668 struct omap_overlay_manager
*mgr
= NULL
;
670 lcd_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD
);
671 tv_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_TV
);
672 if (dss_has_feature(FEAT_MGR_LCD2
))
673 lcd2_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD2
);
675 if (dssdev
->channel
== OMAP_DSS_CHANNEL_LCD2
) {
676 if (!lcd2_mgr
->device
|| force
) {
677 if (lcd2_mgr
->device
)
678 lcd2_mgr
->unset_device(lcd2_mgr
);
679 lcd2_mgr
->set_device(lcd2_mgr
, dssdev
);
682 } else if (dssdev
->type
!= OMAP_DISPLAY_TYPE_VENC
683 && dssdev
->type
!= OMAP_DISPLAY_TYPE_HDMI
) {
684 if (!lcd_mgr
->device
|| force
) {
686 lcd_mgr
->unset_device(lcd_mgr
);
687 lcd_mgr
->set_device(lcd_mgr
, dssdev
);
692 if (dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
693 || dssdev
->type
== OMAP_DISPLAY_TYPE_HDMI
) {
694 if (!tv_mgr
->device
|| force
) {
696 tv_mgr
->unset_device(tv_mgr
);
697 tv_mgr
->set_device(tv_mgr
, dssdev
);
703 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
704 struct omap_overlay
*ovl
;
705 ovl
= omap_dss_get_overlay(i
);
706 if (!ovl
->manager
|| force
) {
708 omap_dss_unset_manager(ovl
);
709 omap_dss_set_manager(ovl
, mgr
);
715 void dss_uninit_overlays(struct platform_device
*pdev
)
717 struct omap_overlay
*ovl
;
719 while (!list_empty(&overlay_list
)) {
720 ovl
= list_first_entry(&overlay_list
,
721 struct omap_overlay
, list
);
722 list_del(&ovl
->list
);
723 kobject_del(&ovl
->kobj
);
724 kobject_put(&ovl
->kobj
);