2 * Copyright (C) 2009 Nokia Corporation
3 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
5 * Some code and ideas taken from drivers/video/omap/ driver
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
21 #define DSS_SUBSYS_NAME "MANAGER"
23 #include <linux/kernel.h>
24 #include <linux/slab.h>
25 #include <linux/module.h>
26 #include <linux/platform_device.h>
27 #include <linux/jiffies.h>
29 #include <video/omapdss.h>
32 #include "dss_features.h"
34 static ssize_t
manager_name_show(struct omap_overlay_manager
*mgr
, char *buf
)
36 return snprintf(buf
, PAGE_SIZE
, "%s\n", mgr
->name
);
39 static ssize_t
manager_display_show(struct omap_overlay_manager
*mgr
, char *buf
)
41 struct omap_dss_device
*dssdev
= mgr
->get_device(mgr
);
43 return snprintf(buf
, PAGE_SIZE
, "%s\n", dssdev
?
44 dssdev
->name
: "<none>");
47 static ssize_t
manager_display_store(struct omap_overlay_manager
*mgr
,
48 const char *buf
, size_t size
)
52 struct omap_dss_device
*dssdev
= NULL
;
53 struct omap_dss_device
*old_dssdev
;
55 int match(struct omap_dss_device
*dssdev
, void *data
)
57 const char *str
= data
;
58 return sysfs_streq(dssdev
->name
, str
);
61 if (buf
[size
-1] == '\n')
65 dssdev
= omap_dss_find_device((void *)buf
, match
);
67 if (len
> 0 && dssdev
== NULL
)
71 DSSDBG("display %s found\n", dssdev
->name
);
73 if (omapdss_device_is_connected(dssdev
)) {
74 DSSERR("new display is already connected\n");
79 if (omapdss_device_is_enabled(dssdev
)) {
80 DSSERR("new display is not disabled\n");
86 old_dssdev
= mgr
->get_device(mgr
);
88 if (omapdss_device_is_enabled(old_dssdev
)) {
89 DSSERR("old display is not disabled\n");
94 old_dssdev
->driver
->disconnect(old_dssdev
);
98 r
= dssdev
->driver
->connect(dssdev
);
100 DSSERR("failed to connect new device\n");
104 old_dssdev
= mgr
->get_device(mgr
);
105 if (old_dssdev
!= dssdev
) {
106 DSSERR("failed to connect device to this manager\n");
107 dssdev
->driver
->disconnect(dssdev
);
113 DSSERR("failed to apply dispc config\n");
120 omap_dss_put_device(dssdev
);
125 static ssize_t
manager_default_color_show(struct omap_overlay_manager
*mgr
,
128 struct omap_overlay_manager_info info
;
130 mgr
->get_manager_info(mgr
, &info
);
132 return snprintf(buf
, PAGE_SIZE
, "%#x\n", info
.default_color
);
135 static ssize_t
manager_default_color_store(struct omap_overlay_manager
*mgr
,
136 const char *buf
, size_t size
)
138 struct omap_overlay_manager_info info
;
142 r
= kstrtouint(buf
, 0, &color
);
146 mgr
->get_manager_info(mgr
, &info
);
148 info
.default_color
= color
;
150 r
= mgr
->set_manager_info(mgr
, &info
);
161 static const char *trans_key_type_str
[] = {
166 static ssize_t
manager_trans_key_type_show(struct omap_overlay_manager
*mgr
,
169 enum omap_dss_trans_key_type key_type
;
170 struct omap_overlay_manager_info info
;
172 mgr
->get_manager_info(mgr
, &info
);
174 key_type
= info
.trans_key_type
;
175 BUG_ON(key_type
>= ARRAY_SIZE(trans_key_type_str
));
177 return snprintf(buf
, PAGE_SIZE
, "%s\n", trans_key_type_str
[key_type
]);
180 static ssize_t
manager_trans_key_type_store(struct omap_overlay_manager
*mgr
,
181 const char *buf
, size_t size
)
183 enum omap_dss_trans_key_type key_type
;
184 struct omap_overlay_manager_info info
;
187 for (key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
188 key_type
< ARRAY_SIZE(trans_key_type_str
); key_type
++) {
189 if (sysfs_streq(buf
, trans_key_type_str
[key_type
]))
193 if (key_type
== ARRAY_SIZE(trans_key_type_str
))
196 mgr
->get_manager_info(mgr
, &info
);
198 info
.trans_key_type
= key_type
;
200 r
= mgr
->set_manager_info(mgr
, &info
);
211 static ssize_t
manager_trans_key_value_show(struct omap_overlay_manager
*mgr
,
214 struct omap_overlay_manager_info info
;
216 mgr
->get_manager_info(mgr
, &info
);
218 return snprintf(buf
, PAGE_SIZE
, "%#x\n", info
.trans_key
);
221 static ssize_t
manager_trans_key_value_store(struct omap_overlay_manager
*mgr
,
222 const char *buf
, size_t size
)
224 struct omap_overlay_manager_info info
;
228 r
= kstrtouint(buf
, 0, &key_value
);
232 mgr
->get_manager_info(mgr
, &info
);
234 info
.trans_key
= key_value
;
236 r
= mgr
->set_manager_info(mgr
, &info
);
247 static ssize_t
manager_trans_key_enabled_show(struct omap_overlay_manager
*mgr
,
250 struct omap_overlay_manager_info info
;
252 mgr
->get_manager_info(mgr
, &info
);
254 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.trans_enabled
);
257 static ssize_t
manager_trans_key_enabled_store(struct omap_overlay_manager
*mgr
,
258 const char *buf
, size_t size
)
260 struct omap_overlay_manager_info info
;
264 r
= strtobool(buf
, &enable
);
268 mgr
->get_manager_info(mgr
, &info
);
270 info
.trans_enabled
= enable
;
272 r
= mgr
->set_manager_info(mgr
, &info
);
283 static ssize_t
manager_alpha_blending_enabled_show(
284 struct omap_overlay_manager
*mgr
, char *buf
)
286 struct omap_overlay_manager_info info
;
288 if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
291 mgr
->get_manager_info(mgr
, &info
);
293 return snprintf(buf
, PAGE_SIZE
, "%d\n",
294 info
.partial_alpha_enabled
);
297 static ssize_t
manager_alpha_blending_enabled_store(
298 struct omap_overlay_manager
*mgr
,
299 const char *buf
, size_t size
)
301 struct omap_overlay_manager_info info
;
305 if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
308 r
= strtobool(buf
, &enable
);
312 mgr
->get_manager_info(mgr
, &info
);
314 info
.partial_alpha_enabled
= enable
;
316 r
= mgr
->set_manager_info(mgr
, &info
);
327 static ssize_t
manager_cpr_enable_show(struct omap_overlay_manager
*mgr
,
330 struct omap_overlay_manager_info info
;
332 mgr
->get_manager_info(mgr
, &info
);
334 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.cpr_enable
);
337 static ssize_t
manager_cpr_enable_store(struct omap_overlay_manager
*mgr
,
338 const char *buf
, size_t size
)
340 struct omap_overlay_manager_info info
;
344 if (!dss_has_feature(FEAT_CPR
))
347 r
= strtobool(buf
, &enable
);
351 mgr
->get_manager_info(mgr
, &info
);
353 if (info
.cpr_enable
== enable
)
356 info
.cpr_enable
= enable
;
358 r
= mgr
->set_manager_info(mgr
, &info
);
369 static ssize_t
manager_cpr_coef_show(struct omap_overlay_manager
*mgr
,
372 struct omap_overlay_manager_info info
;
374 mgr
->get_manager_info(mgr
, &info
);
376 return snprintf(buf
, PAGE_SIZE
,
377 "%d %d %d %d %d %d %d %d %d\n",
389 static ssize_t
manager_cpr_coef_store(struct omap_overlay_manager
*mgr
,
390 const char *buf
, size_t size
)
392 struct omap_overlay_manager_info info
;
393 struct omap_dss_cpr_coefs coefs
;
397 if (!dss_has_feature(FEAT_CPR
))
400 if (sscanf(buf
, "%hd %hd %hd %hd %hd %hd %hd %hd %hd",
401 &coefs
.rr
, &coefs
.rg
, &coefs
.rb
,
402 &coefs
.gr
, &coefs
.gg
, &coefs
.gb
,
403 &coefs
.br
, &coefs
.bg
, &coefs
.bb
) != 9)
406 arr
= (s16
[]){ coefs
.rr
, coefs
.rg
, coefs
.rb
,
407 coefs
.gr
, coefs
.gg
, coefs
.gb
,
408 coefs
.br
, coefs
.bg
, coefs
.bb
};
410 for (i
= 0; i
< 9; ++i
) {
411 if (arr
[i
] < -512 || arr
[i
] > 511)
415 mgr
->get_manager_info(mgr
, &info
);
417 info
.cpr_coefs
= coefs
;
419 r
= mgr
->set_manager_info(mgr
, &info
);
430 struct manager_attribute
{
431 struct attribute attr
;
432 ssize_t (*show
)(struct omap_overlay_manager
*, char *);
433 ssize_t (*store
)(struct omap_overlay_manager
*, const char *, size_t);
436 #define MANAGER_ATTR(_name, _mode, _show, _store) \
437 struct manager_attribute manager_attr_##_name = \
438 __ATTR(_name, _mode, _show, _store)
440 static MANAGER_ATTR(name
, S_IRUGO
, manager_name_show
, NULL
);
441 static MANAGER_ATTR(display
, S_IRUGO
|S_IWUSR
,
442 manager_display_show
, manager_display_store
);
443 static MANAGER_ATTR(default_color
, S_IRUGO
|S_IWUSR
,
444 manager_default_color_show
, manager_default_color_store
);
445 static MANAGER_ATTR(trans_key_type
, S_IRUGO
|S_IWUSR
,
446 manager_trans_key_type_show
, manager_trans_key_type_store
);
447 static MANAGER_ATTR(trans_key_value
, S_IRUGO
|S_IWUSR
,
448 manager_trans_key_value_show
, manager_trans_key_value_store
);
449 static MANAGER_ATTR(trans_key_enabled
, S_IRUGO
|S_IWUSR
,
450 manager_trans_key_enabled_show
,
451 manager_trans_key_enabled_store
);
452 static MANAGER_ATTR(alpha_blending_enabled
, S_IRUGO
|S_IWUSR
,
453 manager_alpha_blending_enabled_show
,
454 manager_alpha_blending_enabled_store
);
455 static MANAGER_ATTR(cpr_enable
, S_IRUGO
|S_IWUSR
,
456 manager_cpr_enable_show
,
457 manager_cpr_enable_store
);
458 static MANAGER_ATTR(cpr_coef
, S_IRUGO
|S_IWUSR
,
459 manager_cpr_coef_show
,
460 manager_cpr_coef_store
);
463 static struct attribute
*manager_sysfs_attrs
[] = {
464 &manager_attr_name
.attr
,
465 &manager_attr_display
.attr
,
466 &manager_attr_default_color
.attr
,
467 &manager_attr_trans_key_type
.attr
,
468 &manager_attr_trans_key_value
.attr
,
469 &manager_attr_trans_key_enabled
.attr
,
470 &manager_attr_alpha_blending_enabled
.attr
,
471 &manager_attr_cpr_enable
.attr
,
472 &manager_attr_cpr_coef
.attr
,
476 static ssize_t
manager_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
479 struct omap_overlay_manager
*manager
;
480 struct manager_attribute
*manager_attr
;
482 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
483 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
485 if (!manager_attr
->show
)
488 return manager_attr
->show(manager
, buf
);
491 static ssize_t
manager_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
492 const char *buf
, size_t size
)
494 struct omap_overlay_manager
*manager
;
495 struct manager_attribute
*manager_attr
;
497 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
498 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
500 if (!manager_attr
->store
)
503 return manager_attr
->store(manager
, buf
, size
);
506 static const struct sysfs_ops manager_sysfs_ops
= {
507 .show
= manager_attr_show
,
508 .store
= manager_attr_store
,
511 static struct kobj_type manager_ktype
= {
512 .sysfs_ops
= &manager_sysfs_ops
,
513 .default_attrs
= manager_sysfs_attrs
,
516 int dss_manager_kobj_init(struct omap_overlay_manager
*mgr
,
517 struct platform_device
*pdev
)
519 return kobject_init_and_add(&mgr
->kobj
, &manager_ktype
,
520 &pdev
->dev
.kobj
, "manager%d", mgr
->id
);
523 void dss_manager_kobj_uninit(struct omap_overlay_manager
*mgr
)
525 kobject_del(&mgr
->kobj
);
526 kobject_put(&mgr
->kobj
);
528 memset(&mgr
->kobj
, 0, sizeof(mgr
->kobj
));