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 <video/omapdss.h>
38 #include "dss_features.h"
40 static int num_overlays
;
41 static struct omap_overlay
*overlays
;
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 r
= dispc_runtime_get();
91 /* detach old manager */
93 r
= ovl
->unset_manager(ovl
);
95 DSSERR("detach failed\n");
99 r
= old_mgr
->apply(old_mgr
);
105 r
= ovl
->set_manager(ovl
, mgr
);
107 DSSERR("Failed to attach overlay\n");
125 static ssize_t
overlay_input_size_show(struct omap_overlay
*ovl
, char *buf
)
127 struct omap_overlay_info info
;
129 ovl
->get_overlay_info(ovl
, &info
);
131 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
132 info
.width
, info
.height
);
135 static ssize_t
overlay_screen_width_show(struct omap_overlay
*ovl
, char *buf
)
137 struct omap_overlay_info info
;
139 ovl
->get_overlay_info(ovl
, &info
);
141 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.screen_width
);
144 static ssize_t
overlay_position_show(struct omap_overlay
*ovl
, char *buf
)
146 struct omap_overlay_info info
;
148 ovl
->get_overlay_info(ovl
, &info
);
150 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
151 info
.pos_x
, info
.pos_y
);
154 static ssize_t
overlay_position_store(struct omap_overlay
*ovl
,
155 const char *buf
, size_t size
)
159 struct omap_overlay_info info
;
161 ovl
->get_overlay_info(ovl
, &info
);
163 info
.pos_x
= simple_strtoul(buf
, &last
, 10);
165 if (last
- buf
>= size
)
168 info
.pos_y
= simple_strtoul(last
, &last
, 10);
170 r
= ovl
->set_overlay_info(ovl
, &info
);
175 r
= ovl
->manager
->apply(ovl
->manager
);
183 static ssize_t
overlay_output_size_show(struct omap_overlay
*ovl
, char *buf
)
185 struct omap_overlay_info info
;
187 ovl
->get_overlay_info(ovl
, &info
);
189 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
190 info
.out_width
, info
.out_height
);
193 static ssize_t
overlay_output_size_store(struct omap_overlay
*ovl
,
194 const char *buf
, size_t size
)
198 struct omap_overlay_info info
;
200 ovl
->get_overlay_info(ovl
, &info
);
202 info
.out_width
= simple_strtoul(buf
, &last
, 10);
204 if (last
- buf
>= size
)
207 info
.out_height
= simple_strtoul(last
, &last
, 10);
209 r
= ovl
->set_overlay_info(ovl
, &info
);
214 r
= ovl
->manager
->apply(ovl
->manager
);
222 static ssize_t
overlay_enabled_show(struct omap_overlay
*ovl
, char *buf
)
224 return snprintf(buf
, PAGE_SIZE
, "%d\n", ovl
->is_enabled(ovl
));
227 static ssize_t
overlay_enabled_store(struct omap_overlay
*ovl
, const char *buf
,
233 r
= strtobool(buf
, &enable
);
238 r
= ovl
->enable(ovl
);
240 r
= ovl
->disable(ovl
);
248 static ssize_t
overlay_global_alpha_show(struct omap_overlay
*ovl
, char *buf
)
250 struct omap_overlay_info info
;
252 ovl
->get_overlay_info(ovl
, &info
);
254 return snprintf(buf
, PAGE_SIZE
, "%d\n",
258 static ssize_t
overlay_global_alpha_store(struct omap_overlay
*ovl
,
259 const char *buf
, size_t size
)
263 struct omap_overlay_info info
;
265 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
268 r
= kstrtou8(buf
, 0, &alpha
);
272 ovl
->get_overlay_info(ovl
, &info
);
274 info
.global_alpha
= alpha
;
276 r
= ovl
->set_overlay_info(ovl
, &info
);
281 r
= ovl
->manager
->apply(ovl
->manager
);
289 static ssize_t
overlay_pre_mult_alpha_show(struct omap_overlay
*ovl
,
292 struct omap_overlay_info info
;
294 ovl
->get_overlay_info(ovl
, &info
);
296 return snprintf(buf
, PAGE_SIZE
, "%d\n",
297 info
.pre_mult_alpha
);
300 static ssize_t
overlay_pre_mult_alpha_store(struct omap_overlay
*ovl
,
301 const char *buf
, size_t size
)
305 struct omap_overlay_info info
;
307 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
) == 0)
310 r
= kstrtou8(buf
, 0, &alpha
);
314 ovl
->get_overlay_info(ovl
, &info
);
316 info
.pre_mult_alpha
= alpha
;
318 r
= ovl
->set_overlay_info(ovl
, &info
);
323 r
= ovl
->manager
->apply(ovl
->manager
);
331 static ssize_t
overlay_zorder_show(struct omap_overlay
*ovl
, char *buf
)
333 struct omap_overlay_info info
;
335 ovl
->get_overlay_info(ovl
, &info
);
337 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.zorder
);
340 static ssize_t
overlay_zorder_store(struct omap_overlay
*ovl
,
341 const char *buf
, size_t size
)
345 struct omap_overlay_info info
;
347 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_ZORDER
) == 0)
350 r
= kstrtou8(buf
, 0, &zorder
);
354 ovl
->get_overlay_info(ovl
, &info
);
356 info
.zorder
= zorder
;
358 r
= ovl
->set_overlay_info(ovl
, &info
);
363 r
= ovl
->manager
->apply(ovl
->manager
);
371 struct overlay_attribute
{
372 struct attribute attr
;
373 ssize_t (*show
)(struct omap_overlay
*, char *);
374 ssize_t (*store
)(struct omap_overlay
*, const char *, size_t);
377 #define OVERLAY_ATTR(_name, _mode, _show, _store) \
378 struct overlay_attribute overlay_attr_##_name = \
379 __ATTR(_name, _mode, _show, _store)
381 static OVERLAY_ATTR(name
, S_IRUGO
, overlay_name_show
, NULL
);
382 static OVERLAY_ATTR(manager
, S_IRUGO
|S_IWUSR
,
383 overlay_manager_show
, overlay_manager_store
);
384 static OVERLAY_ATTR(input_size
, S_IRUGO
, overlay_input_size_show
, NULL
);
385 static OVERLAY_ATTR(screen_width
, S_IRUGO
, overlay_screen_width_show
, NULL
);
386 static OVERLAY_ATTR(position
, S_IRUGO
|S_IWUSR
,
387 overlay_position_show
, overlay_position_store
);
388 static OVERLAY_ATTR(output_size
, S_IRUGO
|S_IWUSR
,
389 overlay_output_size_show
, overlay_output_size_store
);
390 static OVERLAY_ATTR(enabled
, S_IRUGO
|S_IWUSR
,
391 overlay_enabled_show
, overlay_enabled_store
);
392 static OVERLAY_ATTR(global_alpha
, S_IRUGO
|S_IWUSR
,
393 overlay_global_alpha_show
, overlay_global_alpha_store
);
394 static OVERLAY_ATTR(pre_mult_alpha
, S_IRUGO
|S_IWUSR
,
395 overlay_pre_mult_alpha_show
,
396 overlay_pre_mult_alpha_store
);
397 static OVERLAY_ATTR(zorder
, S_IRUGO
|S_IWUSR
,
398 overlay_zorder_show
, overlay_zorder_store
);
400 static struct attribute
*overlay_sysfs_attrs
[] = {
401 &overlay_attr_name
.attr
,
402 &overlay_attr_manager
.attr
,
403 &overlay_attr_input_size
.attr
,
404 &overlay_attr_screen_width
.attr
,
405 &overlay_attr_position
.attr
,
406 &overlay_attr_output_size
.attr
,
407 &overlay_attr_enabled
.attr
,
408 &overlay_attr_global_alpha
.attr
,
409 &overlay_attr_pre_mult_alpha
.attr
,
410 &overlay_attr_zorder
.attr
,
414 static ssize_t
overlay_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
417 struct omap_overlay
*overlay
;
418 struct overlay_attribute
*overlay_attr
;
420 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
421 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
423 if (!overlay_attr
->show
)
426 return overlay_attr
->show(overlay
, buf
);
429 static ssize_t
overlay_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
430 const char *buf
, size_t size
)
432 struct omap_overlay
*overlay
;
433 struct overlay_attribute
*overlay_attr
;
435 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
436 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
438 if (!overlay_attr
->store
)
441 return overlay_attr
->store(overlay
, buf
, size
);
444 static const struct sysfs_ops overlay_sysfs_ops
= {
445 .show
= overlay_attr_show
,
446 .store
= overlay_attr_store
,
449 static struct kobj_type overlay_ktype
= {
450 .sysfs_ops
= &overlay_sysfs_ops
,
451 .default_attrs
= overlay_sysfs_attrs
,
454 int omap_dss_get_num_overlays(void)
458 EXPORT_SYMBOL(omap_dss_get_num_overlays
);
460 struct omap_overlay
*omap_dss_get_overlay(int num
)
462 if (num
>= num_overlays
)
465 return &overlays
[num
];
467 EXPORT_SYMBOL(omap_dss_get_overlay
);
469 void dss_init_overlays(struct platform_device
*pdev
)
473 num_overlays
= dss_feat_get_num_ovls();
475 overlays
= kzalloc(sizeof(struct omap_overlay
) * num_overlays
,
478 BUG_ON(overlays
== NULL
);
480 for (i
= 0; i
< num_overlays
; ++i
) {
481 struct omap_overlay
*ovl
= &overlays
[i
];
486 ovl
->id
= OMAP_DSS_GFX
;
490 ovl
->id
= OMAP_DSS_VIDEO1
;
494 ovl
->id
= OMAP_DSS_VIDEO2
;
498 ovl
->id
= OMAP_DSS_VIDEO3
;
502 ovl
->is_enabled
= &dss_ovl_is_enabled
;
503 ovl
->enable
= &dss_ovl_enable
;
504 ovl
->disable
= &dss_ovl_disable
;
505 ovl
->set_manager
= &dss_ovl_set_manager
;
506 ovl
->unset_manager
= &dss_ovl_unset_manager
;
507 ovl
->set_overlay_info
= &dss_ovl_set_info
;
508 ovl
->get_overlay_info
= &dss_ovl_get_info
;
509 ovl
->wait_for_go
= &dss_mgr_wait_for_go_ovl
;
511 ovl
->caps
= dss_feat_get_overlay_caps(ovl
->id
);
512 ovl
->supported_modes
=
513 dss_feat_get_supported_color_modes(ovl
->id
);
515 r
= kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
516 &pdev
->dev
.kobj
, "overlay%d", i
);
519 DSSERR("failed to create sysfs file\n");
523 /* connect overlays to the new device, if not already connected. if force
524 * selected, connect always. */
525 void dss_recheck_connections(struct omap_dss_device
*dssdev
, bool force
)
528 struct omap_overlay_manager
*lcd_mgr
;
529 struct omap_overlay_manager
*tv_mgr
;
530 struct omap_overlay_manager
*lcd2_mgr
= NULL
;
531 struct omap_overlay_manager
*lcd3_mgr
= NULL
;
532 struct omap_overlay_manager
*mgr
= NULL
;
534 lcd_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_LCD
);
535 tv_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_DIGIT
);
536 if (dss_has_feature(FEAT_MGR_LCD3
))
537 lcd3_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_LCD3
);
538 if (dss_has_feature(FEAT_MGR_LCD2
))
539 lcd2_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_CHANNEL_LCD2
);
541 if (dssdev
->channel
== OMAP_DSS_CHANNEL_LCD3
) {
542 if (!lcd3_mgr
->device
|| force
) {
543 if (lcd3_mgr
->device
)
544 lcd3_mgr
->unset_device(lcd3_mgr
);
545 lcd3_mgr
->set_device(lcd3_mgr
, dssdev
);
548 } else if (dssdev
->channel
== OMAP_DSS_CHANNEL_LCD2
) {
549 if (!lcd2_mgr
->device
|| force
) {
550 if (lcd2_mgr
->device
)
551 lcd2_mgr
->unset_device(lcd2_mgr
);
552 lcd2_mgr
->set_device(lcd2_mgr
, dssdev
);
555 } else if (dssdev
->type
!= OMAP_DISPLAY_TYPE_VENC
556 && dssdev
->type
!= OMAP_DISPLAY_TYPE_HDMI
) {
557 if (!lcd_mgr
->device
|| force
) {
559 lcd_mgr
->unset_device(lcd_mgr
);
560 lcd_mgr
->set_device(lcd_mgr
, dssdev
);
565 if (dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
566 || dssdev
->type
== OMAP_DISPLAY_TYPE_HDMI
) {
567 if (!tv_mgr
->device
|| force
) {
569 tv_mgr
->unset_device(tv_mgr
);
570 tv_mgr
->set_device(tv_mgr
, dssdev
);
578 for (i
= 0; i
< dss_feat_get_num_ovls(); i
++) {
579 struct omap_overlay
*ovl
;
580 ovl
= omap_dss_get_overlay(i
);
581 if (!ovl
->manager
|| force
) {
583 ovl
->unset_manager(ovl
);
584 ovl
->set_manager(ovl
, mgr
);
592 void dss_uninit_overlays(struct platform_device
*pdev
)
596 for (i
= 0; i
< num_overlays
; ++i
) {
597 struct omap_overlay
*ovl
= &overlays
[i
];
599 kobject_del(&ovl
->kobj
);
600 kobject_put(&ovl
->kobj
);
608 int dss_ovl_simple_check(struct omap_overlay
*ovl
,
609 const struct omap_overlay_info
*info
)
611 if (info
->paddr
== 0) {
612 DSSERR("check_overlay: paddr cannot be 0\n");
616 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0) {
617 if (info
->out_width
!= 0 && info
->width
!= info
->out_width
) {
618 DSSERR("check_overlay: overlay %d doesn't support "
619 "scaling\n", ovl
->id
);
623 if (info
->out_height
!= 0 && info
->height
!= info
->out_height
) {
624 DSSERR("check_overlay: overlay %d doesn't support "
625 "scaling\n", ovl
->id
);
630 if ((ovl
->supported_modes
& info
->color_mode
) == 0) {
631 DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
632 ovl
->id
, info
->color_mode
);
636 if (info
->zorder
>= omap_dss_get_num_overlays()) {
637 DSSERR("check_overlay: zorder %d too high\n", info
->zorder
);
641 if (dss_feat_rotation_type_supported(info
->rotation_type
) == 0) {
642 DSSERR("check_overlay: rotation type %d not supported\n",
643 info
->rotation_type
);
650 int dss_ovl_check(struct omap_overlay
*ovl
, struct omap_overlay_info
*info
,
651 const struct omap_video_timings
*mgr_timings
)
656 dw
= mgr_timings
->x_res
;
657 dh
= mgr_timings
->y_res
;
659 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0) {
663 if (info
->out_width
== 0)
666 outw
= info
->out_width
;
668 if (info
->out_height
== 0)
671 outh
= info
->out_height
;
674 if (dw
< info
->pos_x
+ outw
) {
675 DSSERR("overlay %d horizontally not inside the display area "
677 ovl
->id
, info
->pos_x
, outw
, dw
);
681 if (dh
< info
->pos_y
+ outh
) {
682 DSSERR("overlay %d vertically not inside the display area "
684 ovl
->id
, info
->pos_y
, outh
, dh
);
692 * Checks if replication logic should be used. Only use when overlay is in
693 * RGB12U or RGB16 mode, and video port width interface is 18bpp or 24bpp
695 bool dss_ovl_use_replication(struct dss_lcd_mgr_config config
,
696 enum omap_color_mode mode
)
698 if (mode
!= OMAP_DSS_COLOR_RGB12U
&& mode
!= OMAP_DSS_COLOR_RGB16
)
701 return config
.video_port_width
> 16;