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>
39 static int num_overlays
;
40 static struct list_head overlay_list
;
42 static ssize_t
overlay_name_show(struct omap_overlay
*ovl
, char *buf
)
44 return snprintf(buf
, PAGE_SIZE
, "%s\n", ovl
->name
);
47 static ssize_t
overlay_manager_show(struct omap_overlay
*ovl
, char *buf
)
49 return snprintf(buf
, PAGE_SIZE
, "%s\n",
50 ovl
->manager
? ovl
->manager
->name
: "<none>");
53 static ssize_t
overlay_manager_store(struct omap_overlay
*ovl
, const char *buf
,
57 struct omap_overlay_manager
*mgr
= NULL
;
58 struct omap_overlay_manager
*old_mgr
;
61 if (buf
[size
-1] == '\n')
65 for (i
= 0; i
< omap_dss_get_num_overlay_managers(); ++i
) {
66 mgr
= omap_dss_get_overlay_manager(i
);
68 if (sysfs_streq(buf
, mgr
->name
))
75 if (len
> 0 && mgr
== NULL
)
79 DSSDBG("manager %s found\n", mgr
->name
);
81 if (mgr
== ovl
->manager
)
84 old_mgr
= ovl
->manager
;
86 /* detach old manager */
88 r
= ovl
->unset_manager(ovl
);
90 DSSERR("detach failed\n");
94 r
= old_mgr
->apply(old_mgr
);
100 r
= ovl
->set_manager(ovl
, mgr
);
102 DSSERR("Failed to attach overlay\n");
114 static ssize_t
overlay_input_size_show(struct omap_overlay
*ovl
, char *buf
)
116 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
117 ovl
->info
.width
, ovl
->info
.height
);
120 static ssize_t
overlay_screen_width_show(struct omap_overlay
*ovl
, char *buf
)
122 return snprintf(buf
, PAGE_SIZE
, "%d\n", ovl
->info
.screen_width
);
125 static ssize_t
overlay_position_show(struct omap_overlay
*ovl
, char *buf
)
127 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
128 ovl
->info
.pos_x
, ovl
->info
.pos_y
);
131 static ssize_t
overlay_position_store(struct omap_overlay
*ovl
,
132 const char *buf
, size_t size
)
136 struct omap_overlay_info info
;
138 ovl
->get_overlay_info(ovl
, &info
);
140 info
.pos_x
= simple_strtoul(buf
, &last
, 10);
142 if (last
- buf
>= size
)
145 info
.pos_y
= simple_strtoul(last
, &last
, 10);
147 r
= ovl
->set_overlay_info(ovl
, &info
);
152 r
= ovl
->manager
->apply(ovl
->manager
);
160 static ssize_t
overlay_output_size_show(struct omap_overlay
*ovl
, char *buf
)
162 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
163 ovl
->info
.out_width
, ovl
->info
.out_height
);
166 static ssize_t
overlay_output_size_store(struct omap_overlay
*ovl
,
167 const char *buf
, size_t size
)
171 struct omap_overlay_info info
;
173 ovl
->get_overlay_info(ovl
, &info
);
175 info
.out_width
= simple_strtoul(buf
, &last
, 10);
177 if (last
- buf
>= size
)
180 info
.out_height
= simple_strtoul(last
, &last
, 10);
182 r
= ovl
->set_overlay_info(ovl
, &info
);
187 r
= ovl
->manager
->apply(ovl
->manager
);
195 static ssize_t
overlay_enabled_show(struct omap_overlay
*ovl
, char *buf
)
197 return snprintf(buf
, PAGE_SIZE
, "%d\n", ovl
->info
.enabled
);
200 static ssize_t
overlay_enabled_store(struct omap_overlay
*ovl
, const char *buf
,
204 struct omap_overlay_info info
;
206 ovl
->get_overlay_info(ovl
, &info
);
208 info
.enabled
= simple_strtoul(buf
, NULL
, 10);
210 r
= ovl
->set_overlay_info(ovl
, &info
);
215 r
= ovl
->manager
->apply(ovl
->manager
);
223 static ssize_t
overlay_global_alpha_show(struct omap_overlay
*ovl
, char *buf
)
225 return snprintf(buf
, PAGE_SIZE
, "%d\n",
226 ovl
->info
.global_alpha
);
229 static ssize_t
overlay_global_alpha_store(struct omap_overlay
*ovl
,
230 const char *buf
, size_t size
)
233 struct omap_overlay_info info
;
235 ovl
->get_overlay_info(ovl
, &info
);
237 /* Video1 plane does not support global alpha
238 * to always make it 255 completely opaque
240 if (ovl
->id
== OMAP_DSS_VIDEO1
)
241 info
.global_alpha
= 255;
243 info
.global_alpha
= simple_strtoul(buf
, NULL
, 10);
245 r
= ovl
->set_overlay_info(ovl
, &info
);
250 r
= ovl
->manager
->apply(ovl
->manager
);
258 struct overlay_attribute
{
259 struct attribute attr
;
260 ssize_t (*show
)(struct omap_overlay
*, char *);
261 ssize_t (*store
)(struct omap_overlay
*, const char *, size_t);
264 #define OVERLAY_ATTR(_name, _mode, _show, _store) \
265 struct overlay_attribute overlay_attr_##_name = \
266 __ATTR(_name, _mode, _show, _store)
268 static OVERLAY_ATTR(name
, S_IRUGO
, overlay_name_show
, NULL
);
269 static OVERLAY_ATTR(manager
, S_IRUGO
|S_IWUSR
,
270 overlay_manager_show
, overlay_manager_store
);
271 static OVERLAY_ATTR(input_size
, S_IRUGO
, overlay_input_size_show
, NULL
);
272 static OVERLAY_ATTR(screen_width
, S_IRUGO
, overlay_screen_width_show
, NULL
);
273 static OVERLAY_ATTR(position
, S_IRUGO
|S_IWUSR
,
274 overlay_position_show
, overlay_position_store
);
275 static OVERLAY_ATTR(output_size
, S_IRUGO
|S_IWUSR
,
276 overlay_output_size_show
, overlay_output_size_store
);
277 static OVERLAY_ATTR(enabled
, S_IRUGO
|S_IWUSR
,
278 overlay_enabled_show
, overlay_enabled_store
);
279 static OVERLAY_ATTR(global_alpha
, S_IRUGO
|S_IWUSR
,
280 overlay_global_alpha_show
, overlay_global_alpha_store
);
282 static struct attribute
*overlay_sysfs_attrs
[] = {
283 &overlay_attr_name
.attr
,
284 &overlay_attr_manager
.attr
,
285 &overlay_attr_input_size
.attr
,
286 &overlay_attr_screen_width
.attr
,
287 &overlay_attr_position
.attr
,
288 &overlay_attr_output_size
.attr
,
289 &overlay_attr_enabled
.attr
,
290 &overlay_attr_global_alpha
.attr
,
294 static ssize_t
overlay_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
297 struct omap_overlay
*overlay
;
298 struct overlay_attribute
*overlay_attr
;
300 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
301 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
303 if (!overlay_attr
->show
)
306 return overlay_attr
->show(overlay
, buf
);
309 static ssize_t
overlay_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
310 const char *buf
, size_t size
)
312 struct omap_overlay
*overlay
;
313 struct overlay_attribute
*overlay_attr
;
315 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
316 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
318 if (!overlay_attr
->store
)
321 return overlay_attr
->store(overlay
, buf
, size
);
324 static const struct sysfs_ops overlay_sysfs_ops
= {
325 .show
= overlay_attr_show
,
326 .store
= overlay_attr_store
,
329 static struct kobj_type overlay_ktype
= {
330 .sysfs_ops
= &overlay_sysfs_ops
,
331 .default_attrs
= overlay_sysfs_attrs
,
334 /* Check if overlay parameters are compatible with display */
335 int dss_check_overlay(struct omap_overlay
*ovl
, struct omap_dss_device
*dssdev
)
337 struct omap_overlay_info
*info
;
344 if (!ovl
->info
.enabled
)
349 if (info
->paddr
== 0) {
350 DSSDBG("check_overlay failed: paddr 0\n");
354 dssdev
->driver
->get_resolution(dssdev
, &dw
, &dh
);
356 DSSDBG("check_overlay %d: (%d,%d %dx%d -> %dx%d) disp (%dx%d)\n",
358 info
->pos_x
, info
->pos_y
,
359 info
->width
, info
->height
,
360 info
->out_width
, info
->out_height
,
363 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0) {
367 if (info
->out_width
== 0)
370 outw
= info
->out_width
;
372 if (info
->out_height
== 0)
375 outh
= info
->out_height
;
378 if (dw
< info
->pos_x
+ outw
) {
379 DSSDBG("check_overlay failed 1: %d < %d + %d\n",
380 dw
, info
->pos_x
, outw
);
384 if (dh
< info
->pos_y
+ outh
) {
385 DSSDBG("check_overlay failed 2: %d < %d + %d\n",
386 dh
, info
->pos_y
, outh
);
390 if ((ovl
->supported_modes
& info
->color_mode
) == 0) {
391 DSSERR("overlay doesn't support mode %d\n", info
->color_mode
);
398 static int dss_ovl_set_overlay_info(struct omap_overlay
*ovl
,
399 struct omap_overlay_info
*info
)
402 struct omap_overlay_info old_info
;
404 old_info
= ovl
->info
;
408 r
= dss_check_overlay(ovl
, ovl
->manager
->device
);
410 ovl
->info
= old_info
;
415 ovl
->info_dirty
= true;
420 static void dss_ovl_get_overlay_info(struct omap_overlay
*ovl
,
421 struct omap_overlay_info
*info
)
426 static int dss_ovl_wait_for_go(struct omap_overlay
*ovl
)
428 return dss_mgr_wait_for_go_ovl(ovl
);
431 static int omap_dss_set_manager(struct omap_overlay
*ovl
,
432 struct omap_overlay_manager
*mgr
)
438 DSSERR("overlay '%s' already has a manager '%s'\n",
439 ovl
->name
, ovl
->manager
->name
);
443 if (ovl
->info
.enabled
) {
444 DSSERR("overlay has to be disabled to change the manager\n");
450 dss_clk_enable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
452 dispc_set_channel_out(ovl
->id
, mgr
->id
);
453 dss_clk_disable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
458 static int omap_dss_unset_manager(struct omap_overlay
*ovl
)
463 DSSERR("failed to detach overlay: manager not set\n");
467 if (ovl
->info
.enabled
) {
468 DSSERR("overlay has to be disabled to unset the manager\n");
472 r
= ovl
->wait_for_go(ovl
);
481 int omap_dss_get_num_overlays(void)
485 EXPORT_SYMBOL(omap_dss_get_num_overlays
);
487 struct omap_overlay
*omap_dss_get_overlay(int num
)
490 struct omap_overlay
*ovl
;
492 list_for_each_entry(ovl
, &overlay_list
, list
) {
499 EXPORT_SYMBOL(omap_dss_get_overlay
);
501 static void omap_dss_add_overlay(struct omap_overlay
*overlay
)
504 list_add_tail(&overlay
->list
, &overlay_list
);
507 static struct omap_overlay
*dispc_overlays
[3];
509 void dss_overlay_setup_dispc_manager(struct omap_overlay_manager
*mgr
)
511 mgr
->num_overlays
= 3;
512 mgr
->overlays
= dispc_overlays
;
516 static struct omap_overlay
*l4_overlays
[1];
517 void dss_overlay_setup_l4_manager(struct omap_overlay_manager
*mgr
)
519 mgr
->num_overlays
= 1;
520 mgr
->overlays
= l4_overlays
;
524 void dss_init_overlays(struct platform_device
*pdev
)
528 INIT_LIST_HEAD(&overlay_list
);
532 for (i
= 0; i
< 3; ++i
) {
533 struct omap_overlay
*ovl
;
534 ovl
= kzalloc(sizeof(*ovl
), GFP_KERNEL
);
541 ovl
->id
= OMAP_DSS_GFX
;
542 ovl
->supported_modes
= cpu_is_omap34xx() ?
543 OMAP_DSS_COLOR_GFX_OMAP3
:
544 OMAP_DSS_COLOR_GFX_OMAP2
;
545 ovl
->caps
= OMAP_DSS_OVL_CAP_DISPC
;
546 ovl
->info
.global_alpha
= 255;
550 ovl
->id
= OMAP_DSS_VIDEO1
;
551 ovl
->supported_modes
= cpu_is_omap34xx() ?
552 OMAP_DSS_COLOR_VID1_OMAP3
:
553 OMAP_DSS_COLOR_VID_OMAP2
;
554 ovl
->caps
= OMAP_DSS_OVL_CAP_SCALE
|
555 OMAP_DSS_OVL_CAP_DISPC
;
556 ovl
->info
.global_alpha
= 255;
560 ovl
->id
= OMAP_DSS_VIDEO2
;
561 ovl
->supported_modes
= cpu_is_omap34xx() ?
562 OMAP_DSS_COLOR_VID2_OMAP3
:
563 OMAP_DSS_COLOR_VID_OMAP2
;
564 ovl
->caps
= OMAP_DSS_OVL_CAP_SCALE
|
565 OMAP_DSS_OVL_CAP_DISPC
;
566 ovl
->info
.global_alpha
= 255;
570 ovl
->set_manager
= &omap_dss_set_manager
;
571 ovl
->unset_manager
= &omap_dss_unset_manager
;
572 ovl
->set_overlay_info
= &dss_ovl_set_overlay_info
;
573 ovl
->get_overlay_info
= &dss_ovl_get_overlay_info
;
574 ovl
->wait_for_go
= &dss_ovl_wait_for_go
;
576 omap_dss_add_overlay(ovl
);
578 r
= kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
579 &pdev
->dev
.kobj
, "overlay%d", i
);
582 DSSERR("failed to create sysfs file\n");
586 dispc_overlays
[i
] = ovl
;
591 struct omap_overlay
*ovl
;
592 ovl
= kzalloc(sizeof(*ovl
), GFP_KERNEL
);
597 ovl
->supported_modes
= OMAP_DSS_COLOR_RGB24U
;
599 ovl
->set_manager
= &omap_dss_set_manager
;
600 ovl
->unset_manager
= &omap_dss_unset_manager
;
601 ovl
->set_overlay_info
= &dss_ovl_set_overlay_info
;
602 ovl
->get_overlay_info
= &dss_ovl_get_overlay_info
;
604 omap_dss_add_overlay(ovl
);
606 r
= kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
607 &pdev
->dev
.kobj
, "overlayl4");
610 DSSERR("failed to create sysfs file\n");
612 l4_overlays
[0] = ovl
;
617 /* connect overlays to the new device, if not already connected. if force
618 * selected, connect always. */
619 void dss_recheck_connections(struct omap_dss_device
*dssdev
, bool force
)
622 struct omap_overlay_manager
*lcd_mgr
;
623 struct omap_overlay_manager
*tv_mgr
;
624 struct omap_overlay_manager
*mgr
= NULL
;
626 lcd_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD
);
627 tv_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_TV
);
629 if (dssdev
->type
!= OMAP_DISPLAY_TYPE_VENC
) {
630 if (!lcd_mgr
->device
|| force
) {
632 lcd_mgr
->unset_device(lcd_mgr
);
633 lcd_mgr
->set_device(lcd_mgr
, dssdev
);
638 if (dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
) {
639 if (!tv_mgr
->device
|| force
) {
641 tv_mgr
->unset_device(tv_mgr
);
642 tv_mgr
->set_device(tv_mgr
, dssdev
);
648 for (i
= 0; i
< 3; i
++) {
649 struct omap_overlay
*ovl
;
650 ovl
= omap_dss_get_overlay(i
);
651 if (!ovl
->manager
|| force
) {
653 omap_dss_unset_manager(ovl
);
654 omap_dss_set_manager(ovl
, mgr
);
660 void dss_uninit_overlays(struct platform_device
*pdev
)
662 struct omap_overlay
*ovl
;
664 while (!list_empty(&overlay_list
)) {
665 ovl
= list_first_entry(&overlay_list
,
666 struct omap_overlay
, list
);
667 list_del(&ovl
->list
);
668 kobject_del(&ovl
->kobj
);
669 kobject_put(&ovl
->kobj
);