2 * linux/drivers/video/omap2/dss/manager.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 "MANAGER"
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/module.h>
28 #include <linux/platform_device.h>
29 #include <linux/jiffies.h>
31 #include <video/omapdss.h>
34 #include "dss_features.h"
36 static int num_managers
;
37 static struct omap_overlay_manager
*managers
;
39 static ssize_t
manager_name_show(struct omap_overlay_manager
*mgr
, char *buf
)
41 return snprintf(buf
, PAGE_SIZE
, "%s\n", mgr
->name
);
44 static ssize_t
manager_display_show(struct omap_overlay_manager
*mgr
, char *buf
)
46 return snprintf(buf
, PAGE_SIZE
, "%s\n",
47 mgr
->device
? mgr
->device
->name
: "<none>");
50 static ssize_t
manager_display_store(struct omap_overlay_manager
*mgr
,
51 const char *buf
, size_t size
)
55 struct omap_dss_device
*dssdev
= NULL
;
57 int match(struct omap_dss_device
*dssdev
, void *data
)
59 const char *str
= data
;
60 return sysfs_streq(dssdev
->name
, str
);
63 if (buf
[size
-1] == '\n')
67 dssdev
= omap_dss_find_device((void *)buf
, match
);
69 if (len
> 0 && dssdev
== NULL
)
73 DSSDBG("display %s found\n", dssdev
->name
);
76 r
= mgr
->unset_device(mgr
);
78 DSSERR("failed to unset display\n");
84 r
= mgr
->set_device(mgr
, dssdev
);
86 DSSERR("failed to set manager\n");
92 DSSERR("failed to apply dispc config\n");
99 omap_dss_put_device(dssdev
);
104 static ssize_t
manager_default_color_show(struct omap_overlay_manager
*mgr
,
107 struct omap_overlay_manager_info info
;
109 mgr
->get_manager_info(mgr
, &info
);
111 return snprintf(buf
, PAGE_SIZE
, "%#x\n", info
.default_color
);
114 static ssize_t
manager_default_color_store(struct omap_overlay_manager
*mgr
,
115 const char *buf
, size_t size
)
117 struct omap_overlay_manager_info info
;
121 r
= kstrtouint(buf
, 0, &color
);
125 mgr
->get_manager_info(mgr
, &info
);
127 info
.default_color
= color
;
129 r
= mgr
->set_manager_info(mgr
, &info
);
140 static const char *trans_key_type_str
[] = {
145 static ssize_t
manager_trans_key_type_show(struct omap_overlay_manager
*mgr
,
148 enum omap_dss_trans_key_type key_type
;
149 struct omap_overlay_manager_info info
;
151 mgr
->get_manager_info(mgr
, &info
);
153 key_type
= info
.trans_key_type
;
154 BUG_ON(key_type
>= ARRAY_SIZE(trans_key_type_str
));
156 return snprintf(buf
, PAGE_SIZE
, "%s\n", trans_key_type_str
[key_type
]);
159 static ssize_t
manager_trans_key_type_store(struct omap_overlay_manager
*mgr
,
160 const char *buf
, size_t size
)
162 enum omap_dss_trans_key_type key_type
;
163 struct omap_overlay_manager_info info
;
166 for (key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
167 key_type
< ARRAY_SIZE(trans_key_type_str
); key_type
++) {
168 if (sysfs_streq(buf
, trans_key_type_str
[key_type
]))
172 if (key_type
== ARRAY_SIZE(trans_key_type_str
))
175 mgr
->get_manager_info(mgr
, &info
);
177 info
.trans_key_type
= key_type
;
179 r
= mgr
->set_manager_info(mgr
, &info
);
190 static ssize_t
manager_trans_key_value_show(struct omap_overlay_manager
*mgr
,
193 struct omap_overlay_manager_info info
;
195 mgr
->get_manager_info(mgr
, &info
);
197 return snprintf(buf
, PAGE_SIZE
, "%#x\n", info
.trans_key
);
200 static ssize_t
manager_trans_key_value_store(struct omap_overlay_manager
*mgr
,
201 const char *buf
, size_t size
)
203 struct omap_overlay_manager_info info
;
207 r
= kstrtouint(buf
, 0, &key_value
);
211 mgr
->get_manager_info(mgr
, &info
);
213 info
.trans_key
= key_value
;
215 r
= mgr
->set_manager_info(mgr
, &info
);
226 static ssize_t
manager_trans_key_enabled_show(struct omap_overlay_manager
*mgr
,
229 struct omap_overlay_manager_info info
;
231 mgr
->get_manager_info(mgr
, &info
);
233 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.trans_enabled
);
236 static ssize_t
manager_trans_key_enabled_store(struct omap_overlay_manager
*mgr
,
237 const char *buf
, size_t size
)
239 struct omap_overlay_manager_info info
;
243 r
= strtobool(buf
, &enable
);
247 mgr
->get_manager_info(mgr
, &info
);
249 info
.trans_enabled
= enable
;
251 r
= mgr
->set_manager_info(mgr
, &info
);
262 static ssize_t
manager_alpha_blending_enabled_show(
263 struct omap_overlay_manager
*mgr
, char *buf
)
265 struct omap_overlay_manager_info info
;
267 mgr
->get_manager_info(mgr
, &info
);
269 WARN_ON(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
));
271 return snprintf(buf
, PAGE_SIZE
, "%d\n",
272 info
.partial_alpha_enabled
);
275 static ssize_t
manager_alpha_blending_enabled_store(
276 struct omap_overlay_manager
*mgr
,
277 const char *buf
, size_t size
)
279 struct omap_overlay_manager_info info
;
283 WARN_ON(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
));
285 r
= strtobool(buf
, &enable
);
289 mgr
->get_manager_info(mgr
, &info
);
291 info
.partial_alpha_enabled
= enable
;
293 r
= mgr
->set_manager_info(mgr
, &info
);
304 static ssize_t
manager_cpr_enable_show(struct omap_overlay_manager
*mgr
,
307 struct omap_overlay_manager_info info
;
309 mgr
->get_manager_info(mgr
, &info
);
311 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.cpr_enable
);
314 static ssize_t
manager_cpr_enable_store(struct omap_overlay_manager
*mgr
,
315 const char *buf
, size_t size
)
317 struct omap_overlay_manager_info info
;
321 if (!dss_has_feature(FEAT_CPR
))
324 r
= strtobool(buf
, &enable
);
328 mgr
->get_manager_info(mgr
, &info
);
330 if (info
.cpr_enable
== enable
)
333 info
.cpr_enable
= enable
;
335 r
= mgr
->set_manager_info(mgr
, &info
);
346 static ssize_t
manager_cpr_coef_show(struct omap_overlay_manager
*mgr
,
349 struct omap_overlay_manager_info info
;
351 mgr
->get_manager_info(mgr
, &info
);
353 return snprintf(buf
, PAGE_SIZE
,
354 "%d %d %d %d %d %d %d %d %d\n",
366 static ssize_t
manager_cpr_coef_store(struct omap_overlay_manager
*mgr
,
367 const char *buf
, size_t size
)
369 struct omap_overlay_manager_info info
;
370 struct omap_dss_cpr_coefs coefs
;
374 if (!dss_has_feature(FEAT_CPR
))
377 if (sscanf(buf
, "%hd %hd %hd %hd %hd %hd %hd %hd %hd",
378 &coefs
.rr
, &coefs
.rg
, &coefs
.rb
,
379 &coefs
.gr
, &coefs
.gg
, &coefs
.gb
,
380 &coefs
.br
, &coefs
.bg
, &coefs
.bb
) != 9)
383 arr
= (s16
[]){ coefs
.rr
, coefs
.rg
, coefs
.rb
,
384 coefs
.gr
, coefs
.gg
, coefs
.gb
,
385 coefs
.br
, coefs
.bg
, coefs
.bb
};
387 for (i
= 0; i
< 9; ++i
) {
388 if (arr
[i
] < -512 || arr
[i
] > 511)
392 mgr
->get_manager_info(mgr
, &info
);
394 info
.cpr_coefs
= coefs
;
396 r
= mgr
->set_manager_info(mgr
, &info
);
407 struct manager_attribute
{
408 struct attribute attr
;
409 ssize_t (*show
)(struct omap_overlay_manager
*, char *);
410 ssize_t (*store
)(struct omap_overlay_manager
*, const char *, size_t);
413 #define MANAGER_ATTR(_name, _mode, _show, _store) \
414 struct manager_attribute manager_attr_##_name = \
415 __ATTR(_name, _mode, _show, _store)
417 static MANAGER_ATTR(name
, S_IRUGO
, manager_name_show
, NULL
);
418 static MANAGER_ATTR(display
, S_IRUGO
|S_IWUSR
,
419 manager_display_show
, manager_display_store
);
420 static MANAGER_ATTR(default_color
, S_IRUGO
|S_IWUSR
,
421 manager_default_color_show
, manager_default_color_store
);
422 static MANAGER_ATTR(trans_key_type
, S_IRUGO
|S_IWUSR
,
423 manager_trans_key_type_show
, manager_trans_key_type_store
);
424 static MANAGER_ATTR(trans_key_value
, S_IRUGO
|S_IWUSR
,
425 manager_trans_key_value_show
, manager_trans_key_value_store
);
426 static MANAGER_ATTR(trans_key_enabled
, S_IRUGO
|S_IWUSR
,
427 manager_trans_key_enabled_show
,
428 manager_trans_key_enabled_store
);
429 static MANAGER_ATTR(alpha_blending_enabled
, S_IRUGO
|S_IWUSR
,
430 manager_alpha_blending_enabled_show
,
431 manager_alpha_blending_enabled_store
);
432 static MANAGER_ATTR(cpr_enable
, S_IRUGO
|S_IWUSR
,
433 manager_cpr_enable_show
,
434 manager_cpr_enable_store
);
435 static MANAGER_ATTR(cpr_coef
, S_IRUGO
|S_IWUSR
,
436 manager_cpr_coef_show
,
437 manager_cpr_coef_store
);
440 static struct attribute
*manager_sysfs_attrs
[] = {
441 &manager_attr_name
.attr
,
442 &manager_attr_display
.attr
,
443 &manager_attr_default_color
.attr
,
444 &manager_attr_trans_key_type
.attr
,
445 &manager_attr_trans_key_value
.attr
,
446 &manager_attr_trans_key_enabled
.attr
,
447 &manager_attr_alpha_blending_enabled
.attr
,
448 &manager_attr_cpr_enable
.attr
,
449 &manager_attr_cpr_coef
.attr
,
453 static ssize_t
manager_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
456 struct omap_overlay_manager
*manager
;
457 struct manager_attribute
*manager_attr
;
459 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
460 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
462 if (!manager_attr
->show
)
465 return manager_attr
->show(manager
, buf
);
468 static ssize_t
manager_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
469 const char *buf
, size_t size
)
471 struct omap_overlay_manager
*manager
;
472 struct manager_attribute
*manager_attr
;
474 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
475 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
477 if (!manager_attr
->store
)
480 return manager_attr
->store(manager
, buf
, size
);
483 static const struct sysfs_ops manager_sysfs_ops
= {
484 .show
= manager_attr_show
,
485 .store
= manager_attr_store
,
488 static struct kobj_type manager_ktype
= {
489 .sysfs_ops
= &manager_sysfs_ops
,
490 .default_attrs
= manager_sysfs_attrs
,
493 static int dss_mgr_wait_for_vsync(struct omap_overlay_manager
*mgr
)
495 unsigned long timeout
= msecs_to_jiffies(500);
499 r
= dispc_runtime_get();
503 if (mgr
->device
->type
== OMAP_DISPLAY_TYPE_VENC
)
504 irq
= DISPC_IRQ_EVSYNC_ODD
;
505 else if (mgr
->device
->type
== OMAP_DISPLAY_TYPE_HDMI
)
506 irq
= DISPC_IRQ_EVSYNC_EVEN
;
508 irq
= dispc_mgr_get_vsync_irq(mgr
->id
);
510 r
= omap_dispc_wait_for_irq_interruptible_timeout(irq
, timeout
);
517 int dss_init_overlay_managers(struct platform_device
*pdev
)
521 num_managers
= dss_feat_get_num_mgrs();
523 managers
= kzalloc(sizeof(struct omap_overlay_manager
) * num_managers
,
526 BUG_ON(managers
== NULL
);
528 for (i
= 0; i
< num_managers
; ++i
) {
529 struct omap_overlay_manager
*mgr
= &managers
[i
];
534 mgr
->id
= OMAP_DSS_CHANNEL_LCD
;
538 mgr
->id
= OMAP_DSS_CHANNEL_DIGIT
;
542 mgr
->id
= OMAP_DSS_CHANNEL_LCD2
;
546 mgr
->id
= OMAP_DSS_CHANNEL_LCD3
;
550 mgr
->set_device
= &dss_mgr_set_device
;
551 mgr
->unset_device
= &dss_mgr_unset_device
;
552 mgr
->apply
= &omap_dss_mgr_apply
;
553 mgr
->set_manager_info
= &dss_mgr_set_info
;
554 mgr
->get_manager_info
= &dss_mgr_get_info
;
555 mgr
->wait_for_go
= &dss_mgr_wait_for_go
;
556 mgr
->wait_for_vsync
= &dss_mgr_wait_for_vsync
;
559 mgr
->supported_displays
=
560 dss_feat_get_supported_displays(mgr
->id
);
562 INIT_LIST_HEAD(&mgr
->overlays
);
564 r
= kobject_init_and_add(&mgr
->kobj
, &manager_ktype
,
565 &pdev
->dev
.kobj
, "manager%d", i
);
568 DSSERR("failed to create sysfs file\n");
574 void dss_uninit_overlay_managers(struct platform_device
*pdev
)
578 for (i
= 0; i
< num_managers
; ++i
) {
579 struct omap_overlay_manager
*mgr
= &managers
[i
];
581 kobject_del(&mgr
->kobj
);
582 kobject_put(&mgr
->kobj
);
590 int omap_dss_get_num_overlay_managers(void)
594 EXPORT_SYMBOL(omap_dss_get_num_overlay_managers
);
596 struct omap_overlay_manager
*omap_dss_get_overlay_manager(int num
)
598 if (num
>= num_managers
)
601 return &managers
[num
];
603 EXPORT_SYMBOL(omap_dss_get_overlay_manager
);
605 int dss_mgr_simple_check(struct omap_overlay_manager
*mgr
,
606 const struct omap_overlay_manager_info
*info
)
608 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
)) {
610 * OMAP3 supports only graphics source transparency color key
611 * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
614 if (info
->partial_alpha_enabled
&& info
->trans_enabled
615 && info
->trans_key_type
!= OMAP_DSS_COLOR_KEY_GFX_DST
) {
616 DSSERR("check_manager: illegal transparency key\n");
624 static int dss_mgr_check_zorder(struct omap_overlay_manager
*mgr
,
625 struct omap_overlay_info
**overlay_infos
)
627 struct omap_overlay
*ovl1
, *ovl2
;
628 struct omap_overlay_info
*info1
, *info2
;
630 list_for_each_entry(ovl1
, &mgr
->overlays
, list
) {
631 info1
= overlay_infos
[ovl1
->id
];
636 list_for_each_entry(ovl2
, &mgr
->overlays
, list
) {
640 info2
= overlay_infos
[ovl2
->id
];
645 if (info1
->zorder
== info2
->zorder
) {
646 DSSERR("overlays %d and %d have the same "
648 ovl1
->id
, ovl2
->id
, info1
->zorder
);
657 int dss_mgr_check_timings(struct omap_overlay_manager
*mgr
,
658 const struct omap_video_timings
*timings
)
660 if (!dispc_mgr_timings_ok(mgr
->id
, timings
)) {
661 DSSERR("check_manager: invalid timings\n");
668 static int dss_mgr_check_lcd_config(struct omap_overlay_manager
*mgr
,
669 const struct dss_lcd_mgr_config
*config
)
671 struct dispc_clock_info cinfo
= config
->clock_info
;
672 int dl
= config
->video_port_width
;
673 bool stallmode
= config
->stallmode
;
674 bool fifohandcheck
= config
->fifohandcheck
;
676 if (cinfo
.lck_div
< 1 || cinfo
.lck_div
> 255)
679 if (cinfo
.pck_div
< 1 || cinfo
.pck_div
> 255)
682 if (dl
!= 12 && dl
!= 16 && dl
!= 18 && dl
!= 24)
685 /* fifohandcheck should be used only with stallmode */
686 if (stallmode
== false && fifohandcheck
== true)
690 * io pad mode can be only checked by using dssdev connected to the
691 * manager. Ignore checking these for now, add checks when manager
692 * is capable of holding information related to the connected interface
698 int dss_mgr_check(struct omap_overlay_manager
*mgr
,
699 struct omap_overlay_manager_info
*info
,
700 const struct omap_video_timings
*mgr_timings
,
701 const struct dss_lcd_mgr_config
*lcd_config
,
702 struct omap_overlay_info
**overlay_infos
)
704 struct omap_overlay
*ovl
;
707 if (dss_has_feature(FEAT_ALPHA_FREE_ZORDER
)) {
708 r
= dss_mgr_check_zorder(mgr
, overlay_infos
);
713 r
= dss_mgr_check_timings(mgr
, mgr_timings
);
717 r
= dss_mgr_check_lcd_config(mgr
, lcd_config
);
721 list_for_each_entry(ovl
, &mgr
->overlays
, list
) {
722 struct omap_overlay_info
*oi
;
725 oi
= overlay_infos
[ovl
->id
];
730 r
= dss_ovl_check(ovl
, oi
, mgr_timings
);