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>
33 #include <plat/display.h>
38 static int num_overlays
;
39 static struct list_head overlay_list
;
41 static ssize_t
overlay_name_show(struct omap_overlay
*ovl
, char *buf
)
43 return snprintf(buf
, PAGE_SIZE
, "%s\n", ovl
->name
);
46 static ssize_t
overlay_manager_show(struct omap_overlay
*ovl
, char *buf
)
48 return snprintf(buf
, PAGE_SIZE
, "%s\n",
49 ovl
->manager
? ovl
->manager
->name
: "<none>");
52 static ssize_t
overlay_manager_store(struct omap_overlay
*ovl
, const char *buf
,
56 struct omap_overlay_manager
*mgr
= NULL
;
57 struct omap_overlay_manager
*old_mgr
;
60 if (buf
[size
-1] == '\n')
64 for (i
= 0; i
< omap_dss_get_num_overlay_managers(); ++i
) {
65 mgr
= omap_dss_get_overlay_manager(i
);
67 if (strncmp(buf
, mgr
->name
, len
) == 0)
74 if (len
> 0 && mgr
== NULL
)
78 DSSDBG("manager %s found\n", mgr
->name
);
80 if (mgr
== ovl
->manager
)
83 old_mgr
= ovl
->manager
;
85 /* detach old manager */
87 r
= ovl
->unset_manager(ovl
);
89 DSSERR("detach failed\n");
93 r
= old_mgr
->apply(old_mgr
);
99 r
= ovl
->set_manager(ovl
, mgr
);
101 DSSERR("Failed to attach overlay\n");
113 static ssize_t
overlay_input_size_show(struct omap_overlay
*ovl
, char *buf
)
115 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
116 ovl
->info
.width
, ovl
->info
.height
);
119 static ssize_t
overlay_screen_width_show(struct omap_overlay
*ovl
, char *buf
)
121 return snprintf(buf
, PAGE_SIZE
, "%d\n", ovl
->info
.screen_width
);
124 static ssize_t
overlay_position_show(struct omap_overlay
*ovl
, char *buf
)
126 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
127 ovl
->info
.pos_x
, ovl
->info
.pos_y
);
130 static ssize_t
overlay_position_store(struct omap_overlay
*ovl
,
131 const char *buf
, size_t size
)
135 struct omap_overlay_info info
;
137 ovl
->get_overlay_info(ovl
, &info
);
139 info
.pos_x
= simple_strtoul(buf
, &last
, 10);
141 if (last
- buf
>= size
)
144 info
.pos_y
= simple_strtoul(last
, &last
, 10);
146 r
= ovl
->set_overlay_info(ovl
, &info
);
151 r
= ovl
->manager
->apply(ovl
->manager
);
159 static ssize_t
overlay_output_size_show(struct omap_overlay
*ovl
, char *buf
)
161 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
162 ovl
->info
.out_width
, ovl
->info
.out_height
);
165 static ssize_t
overlay_output_size_store(struct omap_overlay
*ovl
,
166 const char *buf
, size_t size
)
170 struct omap_overlay_info info
;
172 ovl
->get_overlay_info(ovl
, &info
);
174 info
.out_width
= simple_strtoul(buf
, &last
, 10);
176 if (last
- buf
>= size
)
179 info
.out_height
= simple_strtoul(last
, &last
, 10);
181 r
= ovl
->set_overlay_info(ovl
, &info
);
186 r
= ovl
->manager
->apply(ovl
->manager
);
194 static ssize_t
overlay_enabled_show(struct omap_overlay
*ovl
, char *buf
)
196 return snprintf(buf
, PAGE_SIZE
, "%d\n", ovl
->info
.enabled
);
199 static ssize_t
overlay_enabled_store(struct omap_overlay
*ovl
, const char *buf
,
203 struct omap_overlay_info info
;
205 ovl
->get_overlay_info(ovl
, &info
);
207 info
.enabled
= simple_strtoul(buf
, NULL
, 10);
209 r
= ovl
->set_overlay_info(ovl
, &info
);
214 r
= ovl
->manager
->apply(ovl
->manager
);
222 static ssize_t
overlay_global_alpha_show(struct omap_overlay
*ovl
, char *buf
)
224 return snprintf(buf
, PAGE_SIZE
, "%d\n",
225 ovl
->info
.global_alpha
);
228 static ssize_t
overlay_global_alpha_store(struct omap_overlay
*ovl
,
229 const char *buf
, size_t size
)
232 struct omap_overlay_info info
;
234 ovl
->get_overlay_info(ovl
, &info
);
236 /* Video1 plane does not support global alpha
237 * to always make it 255 completely opaque
239 if (ovl
->id
== OMAP_DSS_VIDEO1
)
240 info
.global_alpha
= 255;
242 info
.global_alpha
= simple_strtoul(buf
, NULL
, 10);
244 r
= ovl
->set_overlay_info(ovl
, &info
);
249 r
= ovl
->manager
->apply(ovl
->manager
);
257 struct overlay_attribute
{
258 struct attribute attr
;
259 ssize_t (*show
)(struct omap_overlay
*, char *);
260 ssize_t (*store
)(struct omap_overlay
*, const char *, size_t);
263 #define OVERLAY_ATTR(_name, _mode, _show, _store) \
264 struct overlay_attribute overlay_attr_##_name = \
265 __ATTR(_name, _mode, _show, _store)
267 static OVERLAY_ATTR(name
, S_IRUGO
, overlay_name_show
, NULL
);
268 static OVERLAY_ATTR(manager
, S_IRUGO
|S_IWUSR
,
269 overlay_manager_show
, overlay_manager_store
);
270 static OVERLAY_ATTR(input_size
, S_IRUGO
, overlay_input_size_show
, NULL
);
271 static OVERLAY_ATTR(screen_width
, S_IRUGO
, overlay_screen_width_show
, NULL
);
272 static OVERLAY_ATTR(position
, S_IRUGO
|S_IWUSR
,
273 overlay_position_show
, overlay_position_store
);
274 static OVERLAY_ATTR(output_size
, S_IRUGO
|S_IWUSR
,
275 overlay_output_size_show
, overlay_output_size_store
);
276 static OVERLAY_ATTR(enabled
, S_IRUGO
|S_IWUSR
,
277 overlay_enabled_show
, overlay_enabled_store
);
278 static OVERLAY_ATTR(global_alpha
, S_IRUGO
|S_IWUSR
,
279 overlay_global_alpha_show
, overlay_global_alpha_store
);
281 static struct attribute
*overlay_sysfs_attrs
[] = {
282 &overlay_attr_name
.attr
,
283 &overlay_attr_manager
.attr
,
284 &overlay_attr_input_size
.attr
,
285 &overlay_attr_screen_width
.attr
,
286 &overlay_attr_position
.attr
,
287 &overlay_attr_output_size
.attr
,
288 &overlay_attr_enabled
.attr
,
289 &overlay_attr_global_alpha
.attr
,
293 static ssize_t
overlay_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
296 struct omap_overlay
*overlay
;
297 struct overlay_attribute
*overlay_attr
;
299 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
300 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
302 if (!overlay_attr
->show
)
305 return overlay_attr
->show(overlay
, buf
);
308 static ssize_t
overlay_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
309 const char *buf
, size_t size
)
311 struct omap_overlay
*overlay
;
312 struct overlay_attribute
*overlay_attr
;
314 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
315 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
317 if (!overlay_attr
->store
)
320 return overlay_attr
->store(overlay
, buf
, size
);
323 static struct sysfs_ops overlay_sysfs_ops
= {
324 .show
= overlay_attr_show
,
325 .store
= overlay_attr_store
,
328 static struct kobj_type overlay_ktype
= {
329 .sysfs_ops
= &overlay_sysfs_ops
,
330 .default_attrs
= overlay_sysfs_attrs
,
333 /* Check if overlay parameters are compatible with display */
334 int dss_check_overlay(struct omap_overlay
*ovl
, struct omap_dss_device
*dssdev
)
336 struct omap_overlay_info
*info
;
343 if (!ovl
->info
.enabled
)
348 if (info
->paddr
== 0) {
349 DSSDBG("check_overlay failed: paddr 0\n");
353 dssdev
->get_resolution(dssdev
, &dw
, &dh
);
355 DSSDBG("check_overlay %d: (%d,%d %dx%d -> %dx%d) disp (%dx%d)\n",
357 info
->pos_x
, info
->pos_y
,
358 info
->width
, info
->height
,
359 info
->out_width
, info
->out_height
,
362 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_SCALE
) == 0) {
366 if (info
->out_width
== 0)
369 outw
= info
->out_width
;
371 if (info
->out_height
== 0)
374 outh
= info
->out_height
;
377 if (dw
< info
->pos_x
+ outw
) {
378 DSSDBG("check_overlay failed 1: %d < %d + %d\n",
379 dw
, info
->pos_x
, outw
);
383 if (dh
< info
->pos_y
+ outh
) {
384 DSSDBG("check_overlay failed 2: %d < %d + %d\n",
385 dh
, info
->pos_y
, outh
);
389 if ((ovl
->supported_modes
& info
->color_mode
) == 0) {
390 DSSERR("overlay doesn't support mode %d\n", info
->color_mode
);
397 static int dss_ovl_set_overlay_info(struct omap_overlay
*ovl
,
398 struct omap_overlay_info
*info
)
401 struct omap_overlay_info old_info
;
403 old_info
= ovl
->info
;
407 r
= dss_check_overlay(ovl
, ovl
->manager
->device
);
409 ovl
->info
= old_info
;
414 ovl
->info_dirty
= true;
419 static void dss_ovl_get_overlay_info(struct omap_overlay
*ovl
,
420 struct omap_overlay_info
*info
)
425 static int dss_ovl_wait_for_go(struct omap_overlay
*ovl
)
427 return dss_mgr_wait_for_go_ovl(ovl
);
430 static int omap_dss_set_manager(struct omap_overlay
*ovl
,
431 struct omap_overlay_manager
*mgr
)
437 DSSERR("overlay '%s' already has a manager '%s'\n",
438 ovl
->name
, ovl
->manager
->name
);
442 if (ovl
->info
.enabled
) {
443 DSSERR("overlay has to be disabled to change the manager\n");
449 dss_clk_enable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
450 /* XXX: on manual update display, in auto update mode, a bug happens
451 * here. When an overlay is first enabled on LCD, then it's disabled,
452 * and the manager is changed to TV, we sometimes get SYNC_LOST_DIGIT
453 * errors. Waiting before changing the channel_out fixes it. I'm
454 * guessing that the overlay is still somehow being used for the LCD,
455 * but I don't understand how or why. */
457 dispc_set_channel_out(ovl
->id
, mgr
->id
);
458 dss_clk_disable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
463 static int omap_dss_unset_manager(struct omap_overlay
*ovl
)
468 DSSERR("failed to detach overlay: manager not set\n");
472 if (ovl
->info
.enabled
) {
473 DSSERR("overlay has to be disabled to unset the manager\n");
477 r
= ovl
->wait_for_go(ovl
);
486 int omap_dss_get_num_overlays(void)
490 EXPORT_SYMBOL(omap_dss_get_num_overlays
);
492 struct omap_overlay
*omap_dss_get_overlay(int num
)
495 struct omap_overlay
*ovl
;
497 list_for_each_entry(ovl
, &overlay_list
, list
) {
504 EXPORT_SYMBOL(omap_dss_get_overlay
);
506 static void omap_dss_add_overlay(struct omap_overlay
*overlay
)
509 list_add_tail(&overlay
->list
, &overlay_list
);
512 static struct omap_overlay
*dispc_overlays
[3];
514 void dss_overlay_setup_dispc_manager(struct omap_overlay_manager
*mgr
)
516 mgr
->num_overlays
= 3;
517 mgr
->overlays
= dispc_overlays
;
521 static struct omap_overlay
*l4_overlays
[1];
522 void dss_overlay_setup_l4_manager(struct omap_overlay_manager
*mgr
)
524 mgr
->num_overlays
= 1;
525 mgr
->overlays
= l4_overlays
;
529 void dss_init_overlays(struct platform_device
*pdev
)
533 INIT_LIST_HEAD(&overlay_list
);
537 for (i
= 0; i
< 3; ++i
) {
538 struct omap_overlay
*ovl
;
539 ovl
= kzalloc(sizeof(*ovl
), GFP_KERNEL
);
546 ovl
->id
= OMAP_DSS_GFX
;
547 ovl
->supported_modes
= cpu_is_omap34xx() ?
548 OMAP_DSS_COLOR_GFX_OMAP3
:
549 OMAP_DSS_COLOR_GFX_OMAP2
;
550 ovl
->caps
= OMAP_DSS_OVL_CAP_DISPC
;
551 ovl
->info
.global_alpha
= 255;
555 ovl
->id
= OMAP_DSS_VIDEO1
;
556 ovl
->supported_modes
= cpu_is_omap34xx() ?
557 OMAP_DSS_COLOR_VID1_OMAP3
:
558 OMAP_DSS_COLOR_VID_OMAP2
;
559 ovl
->caps
= OMAP_DSS_OVL_CAP_SCALE
|
560 OMAP_DSS_OVL_CAP_DISPC
;
561 ovl
->info
.global_alpha
= 255;
565 ovl
->id
= OMAP_DSS_VIDEO2
;
566 ovl
->supported_modes
= cpu_is_omap34xx() ?
567 OMAP_DSS_COLOR_VID2_OMAP3
:
568 OMAP_DSS_COLOR_VID_OMAP2
;
569 ovl
->caps
= OMAP_DSS_OVL_CAP_SCALE
|
570 OMAP_DSS_OVL_CAP_DISPC
;
571 ovl
->info
.global_alpha
= 255;
575 ovl
->set_manager
= &omap_dss_set_manager
;
576 ovl
->unset_manager
= &omap_dss_unset_manager
;
577 ovl
->set_overlay_info
= &dss_ovl_set_overlay_info
;
578 ovl
->get_overlay_info
= &dss_ovl_get_overlay_info
;
579 ovl
->wait_for_go
= &dss_ovl_wait_for_go
;
581 omap_dss_add_overlay(ovl
);
583 r
= kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
584 &pdev
->dev
.kobj
, "overlay%d", i
);
587 DSSERR("failed to create sysfs file\n");
591 dispc_overlays
[i
] = ovl
;
596 struct omap_overlay
*ovl
;
597 ovl
= kzalloc(sizeof(*ovl
), GFP_KERNEL
);
602 ovl
->supported_modes
= OMAP_DSS_COLOR_RGB24U
;
604 ovl
->set_manager
= &omap_dss_set_manager
;
605 ovl
->unset_manager
= &omap_dss_unset_manager
;
606 ovl
->set_overlay_info
= &dss_ovl_set_overlay_info
;
607 ovl
->get_overlay_info
= &dss_ovl_get_overlay_info
;
609 omap_dss_add_overlay(ovl
);
611 r
= kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
612 &pdev
->dev
.kobj
, "overlayl4");
615 DSSERR("failed to create sysfs file\n");
617 l4_overlays
[0] = ovl
;
622 /* connect overlays to the new device, if not already connected. if force
623 * selected, connect always. */
624 void dss_recheck_connections(struct omap_dss_device
*dssdev
, bool force
)
627 struct omap_overlay_manager
*lcd_mgr
;
628 struct omap_overlay_manager
*tv_mgr
;
629 struct omap_overlay_manager
*mgr
= NULL
;
631 lcd_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD
);
632 tv_mgr
= omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_TV
);
634 if (dssdev
->type
!= OMAP_DISPLAY_TYPE_VENC
) {
635 if (!lcd_mgr
->device
|| force
) {
637 lcd_mgr
->unset_device(lcd_mgr
);
638 lcd_mgr
->set_device(lcd_mgr
, dssdev
);
643 if (dssdev
->type
== OMAP_DISPLAY_TYPE_VENC
) {
644 if (!tv_mgr
->device
|| force
) {
646 tv_mgr
->unset_device(tv_mgr
);
647 tv_mgr
->set_device(tv_mgr
, dssdev
);
653 for (i
= 0; i
< 3; i
++) {
654 struct omap_overlay
*ovl
;
655 ovl
= omap_dss_get_overlay(i
);
656 if (!ovl
->manager
|| force
) {
658 omap_dss_unset_manager(ovl
);
659 omap_dss_set_manager(ovl
, mgr
);
665 void dss_uninit_overlays(struct platform_device
*pdev
)
667 struct omap_overlay
*ovl
;
669 while (!list_empty(&overlay_list
)) {
670 ovl
= list_first_entry(&overlay_list
,
671 struct omap_overlay
, list
);
672 list_del(&ovl
->list
);
673 kobject_del(&ovl
->kobj
);
674 kobject_put(&ovl
->kobj
);