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 (strncmp(buf
, mgr
->name
, len
) == 0)
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
);
451 /* XXX: on manual update display, in auto update mode, a bug happens
452 * here. When an overlay is first enabled on LCD, then it's disabled,
453 * and the manager is changed to TV, we sometimes get SYNC_LOST_DIGIT
454 * errors. Waiting before changing the channel_out fixes it. I'm
455 * guessing that the overlay is still somehow being used for the LCD,
456 * but I don't understand how or why. */
458 dispc_set_channel_out(ovl
->id
, mgr
->id
);
459 dss_clk_disable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
464 static int omap_dss_unset_manager(struct omap_overlay
*ovl
)
469 DSSERR("failed to detach overlay: manager not set\n");
473 if (ovl
->info
.enabled
) {
474 DSSERR("overlay has to be disabled to unset the manager\n");
478 r
= ovl
->wait_for_go(ovl
);
487 int omap_dss_get_num_overlays(void)
491 EXPORT_SYMBOL(omap_dss_get_num_overlays
);
493 struct omap_overlay
*omap_dss_get_overlay(int num
)
496 struct omap_overlay
*ovl
;
498 list_for_each_entry(ovl
, &overlay_list
, list
) {
505 EXPORT_SYMBOL(omap_dss_get_overlay
);
507 static void omap_dss_add_overlay(struct omap_overlay
*overlay
)
510 list_add_tail(&overlay
->list
, &overlay_list
);
513 static struct omap_overlay
*dispc_overlays
[3];
515 void dss_overlay_setup_dispc_manager(struct omap_overlay_manager
*mgr
)
517 mgr
->num_overlays
= 3;
518 mgr
->overlays
= dispc_overlays
;
522 static struct omap_overlay
*l4_overlays
[1];
523 void dss_overlay_setup_l4_manager(struct omap_overlay_manager
*mgr
)
525 mgr
->num_overlays
= 1;
526 mgr
->overlays
= l4_overlays
;
530 void dss_init_overlays(struct platform_device
*pdev
)
534 INIT_LIST_HEAD(&overlay_list
);
538 for (i
= 0; i
< 3; ++i
) {
539 struct omap_overlay
*ovl
;
540 ovl
= kzalloc(sizeof(*ovl
), GFP_KERNEL
);
547 ovl
->id
= OMAP_DSS_GFX
;
548 ovl
->supported_modes
= cpu_is_omap34xx() ?
549 OMAP_DSS_COLOR_GFX_OMAP3
:
550 OMAP_DSS_COLOR_GFX_OMAP2
;
551 ovl
->caps
= OMAP_DSS_OVL_CAP_DISPC
;
552 ovl
->info
.global_alpha
= 255;
556 ovl
->id
= OMAP_DSS_VIDEO1
;
557 ovl
->supported_modes
= cpu_is_omap34xx() ?
558 OMAP_DSS_COLOR_VID1_OMAP3
:
559 OMAP_DSS_COLOR_VID_OMAP2
;
560 ovl
->caps
= OMAP_DSS_OVL_CAP_SCALE
|
561 OMAP_DSS_OVL_CAP_DISPC
;
562 ovl
->info
.global_alpha
= 255;
566 ovl
->id
= OMAP_DSS_VIDEO2
;
567 ovl
->supported_modes
= cpu_is_omap34xx() ?
568 OMAP_DSS_COLOR_VID2_OMAP3
:
569 OMAP_DSS_COLOR_VID_OMAP2
;
570 ovl
->caps
= OMAP_DSS_OVL_CAP_SCALE
|
571 OMAP_DSS_OVL_CAP_DISPC
;
572 ovl
->info
.global_alpha
= 255;
576 ovl
->set_manager
= &omap_dss_set_manager
;
577 ovl
->unset_manager
= &omap_dss_unset_manager
;
578 ovl
->set_overlay_info
= &dss_ovl_set_overlay_info
;
579 ovl
->get_overlay_info
= &dss_ovl_get_overlay_info
;
580 ovl
->wait_for_go
= &dss_ovl_wait_for_go
;
582 omap_dss_add_overlay(ovl
);
584 r
= kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
585 &pdev
->dev
.kobj
, "overlay%d", i
);
588 DSSERR("failed to create sysfs file\n");
592 dispc_overlays
[i
] = ovl
;
597 struct omap_overlay
*ovl
;
598 ovl
= kzalloc(sizeof(*ovl
), GFP_KERNEL
);
603 ovl
->supported_modes
= OMAP_DSS_COLOR_RGB24U
;
605 ovl
->set_manager
= &omap_dss_set_manager
;
606 ovl
->unset_manager
= &omap_dss_unset_manager
;
607 ovl
->set_overlay_info
= &dss_ovl_set_overlay_info
;
608 ovl
->get_overlay_info
= &dss_ovl_get_overlay_info
;
610 omap_dss_add_overlay(ovl
);
612 r
= kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
613 &pdev
->dev
.kobj
, "overlayl4");
616 DSSERR("failed to create sysfs file\n");
618 l4_overlays
[0] = ovl
;
623 /* connect overlays to the new device, if not already connected. if force
624 * selected, connect always. */
625 void dss_recheck_connections(struct omap_dss_device
*dssdev
, bool force
)
628 struct omap_overlay_manager
*lcd_mgr
;
629 struct omap_overlay_manager
*tv_mgr
;
630 struct omap_overlay_manager
*mgr
= NULL
;
632 lcd_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD
);
633 tv_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_TV
);
635 if (dssdev
->type
!= OMAP_DISPLAY_TYPE_VENC
) {
636 if (!lcd_mgr
->device
|| force
) {
638 lcd_mgr
->unset_device(lcd_mgr
);
639 lcd_mgr
->set_device(lcd_mgr
, dssdev
);
644 if (dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
) {
645 if (!tv_mgr
->device
|| force
) {
647 tv_mgr
->unset_device(tv_mgr
);
648 tv_mgr
->set_device(tv_mgr
, dssdev
);
654 for (i
= 0; i
< 3; i
++) {
655 struct omap_overlay
*ovl
;
656 ovl
= omap_dss_get_overlay(i
);
657 if (!ovl
->manager
|| force
) {
659 omap_dss_unset_manager(ovl
);
660 omap_dss_set_manager(ovl
, mgr
);
666 void dss_uninit_overlays(struct platform_device
*pdev
)
668 struct omap_overlay
*ovl
;
670 while (!list_empty(&overlay_list
)) {
671 ovl
= list_first_entry(&overlay_list
,
672 struct omap_overlay
, list
);
673 list_del(&ovl
->list
);
674 kobject_del(&ovl
->kobj
);
675 kobject_put(&ovl
->kobj
);