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 int manager_display_match(struct omap_dss_device
*dssdev
, void *data
)
49 const char *str
= data
;
51 return sysfs_streq(dssdev
->name
, str
);
54 static ssize_t
manager_display_store(struct omap_overlay_manager
*mgr
,
55 const char *buf
, size_t size
)
59 struct omap_dss_device
*dssdev
= NULL
;
60 struct omap_dss_device
*old_dssdev
;
62 if (buf
[size
-1] == '\n')
66 dssdev
= omap_dss_find_device((void *)buf
,
67 manager_display_match
);
69 if (len
> 0 && dssdev
== NULL
)
73 DSSDBG("display %s found\n", dssdev
->name
);
75 if (omapdss_device_is_connected(dssdev
)) {
76 DSSERR("new display is already connected\n");
81 if (omapdss_device_is_enabled(dssdev
)) {
82 DSSERR("new display is not disabled\n");
88 old_dssdev
= mgr
->get_device(mgr
);
90 if (omapdss_device_is_enabled(old_dssdev
)) {
91 DSSERR("old display is not disabled\n");
96 old_dssdev
->driver
->disconnect(old_dssdev
);
100 r
= dssdev
->driver
->connect(dssdev
);
102 DSSERR("failed to connect new device\n");
106 old_dssdev
= mgr
->get_device(mgr
);
107 if (old_dssdev
!= dssdev
) {
108 DSSERR("failed to connect device to this manager\n");
109 dssdev
->driver
->disconnect(dssdev
);
115 DSSERR("failed to apply dispc config\n");
122 omap_dss_put_device(dssdev
);
127 static ssize_t
manager_default_color_show(struct omap_overlay_manager
*mgr
,
130 struct omap_overlay_manager_info info
;
132 mgr
->get_manager_info(mgr
, &info
);
134 return snprintf(buf
, PAGE_SIZE
, "%#x\n", info
.default_color
);
137 static ssize_t
manager_default_color_store(struct omap_overlay_manager
*mgr
,
138 const char *buf
, size_t size
)
140 struct omap_overlay_manager_info info
;
144 r
= kstrtouint(buf
, 0, &color
);
148 mgr
->get_manager_info(mgr
, &info
);
150 info
.default_color
= color
;
152 r
= mgr
->set_manager_info(mgr
, &info
);
163 static const char *trans_key_type_str
[] = {
168 static ssize_t
manager_trans_key_type_show(struct omap_overlay_manager
*mgr
,
171 enum omap_dss_trans_key_type key_type
;
172 struct omap_overlay_manager_info info
;
174 mgr
->get_manager_info(mgr
, &info
);
176 key_type
= info
.trans_key_type
;
177 BUG_ON(key_type
>= ARRAY_SIZE(trans_key_type_str
));
179 return snprintf(buf
, PAGE_SIZE
, "%s\n", trans_key_type_str
[key_type
]);
182 static ssize_t
manager_trans_key_type_store(struct omap_overlay_manager
*mgr
,
183 const char *buf
, size_t size
)
185 enum omap_dss_trans_key_type key_type
;
186 struct omap_overlay_manager_info info
;
189 for (key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
190 key_type
< ARRAY_SIZE(trans_key_type_str
); key_type
++) {
191 if (sysfs_streq(buf
, trans_key_type_str
[key_type
]))
195 if (key_type
== ARRAY_SIZE(trans_key_type_str
))
198 mgr
->get_manager_info(mgr
, &info
);
200 info
.trans_key_type
= key_type
;
202 r
= mgr
->set_manager_info(mgr
, &info
);
213 static ssize_t
manager_trans_key_value_show(struct omap_overlay_manager
*mgr
,
216 struct omap_overlay_manager_info info
;
218 mgr
->get_manager_info(mgr
, &info
);
220 return snprintf(buf
, PAGE_SIZE
, "%#x\n", info
.trans_key
);
223 static ssize_t
manager_trans_key_value_store(struct omap_overlay_manager
*mgr
,
224 const char *buf
, size_t size
)
226 struct omap_overlay_manager_info info
;
230 r
= kstrtouint(buf
, 0, &key_value
);
234 mgr
->get_manager_info(mgr
, &info
);
236 info
.trans_key
= key_value
;
238 r
= mgr
->set_manager_info(mgr
, &info
);
249 static ssize_t
manager_trans_key_enabled_show(struct omap_overlay_manager
*mgr
,
252 struct omap_overlay_manager_info info
;
254 mgr
->get_manager_info(mgr
, &info
);
256 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.trans_enabled
);
259 static ssize_t
manager_trans_key_enabled_store(struct omap_overlay_manager
*mgr
,
260 const char *buf
, size_t size
)
262 struct omap_overlay_manager_info info
;
266 r
= strtobool(buf
, &enable
);
270 mgr
->get_manager_info(mgr
, &info
);
272 info
.trans_enabled
= enable
;
274 r
= mgr
->set_manager_info(mgr
, &info
);
285 static ssize_t
manager_alpha_blending_enabled_show(
286 struct omap_overlay_manager
*mgr
, char *buf
)
288 struct omap_overlay_manager_info info
;
290 if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
293 mgr
->get_manager_info(mgr
, &info
);
295 return snprintf(buf
, PAGE_SIZE
, "%d\n",
296 info
.partial_alpha_enabled
);
299 static ssize_t
manager_alpha_blending_enabled_store(
300 struct omap_overlay_manager
*mgr
,
301 const char *buf
, size_t size
)
303 struct omap_overlay_manager_info info
;
307 if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
310 r
= strtobool(buf
, &enable
);
314 mgr
->get_manager_info(mgr
, &info
);
316 info
.partial_alpha_enabled
= enable
;
318 r
= mgr
->set_manager_info(mgr
, &info
);
329 static ssize_t
manager_cpr_enable_show(struct omap_overlay_manager
*mgr
,
332 struct omap_overlay_manager_info info
;
334 mgr
->get_manager_info(mgr
, &info
);
336 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.cpr_enable
);
339 static ssize_t
manager_cpr_enable_store(struct omap_overlay_manager
*mgr
,
340 const char *buf
, size_t size
)
342 struct omap_overlay_manager_info info
;
346 if (!dss_has_feature(FEAT_CPR
))
349 r
= strtobool(buf
, &enable
);
353 mgr
->get_manager_info(mgr
, &info
);
355 if (info
.cpr_enable
== enable
)
358 info
.cpr_enable
= enable
;
360 r
= mgr
->set_manager_info(mgr
, &info
);
371 static ssize_t
manager_cpr_coef_show(struct omap_overlay_manager
*mgr
,
374 struct omap_overlay_manager_info info
;
376 mgr
->get_manager_info(mgr
, &info
);
378 return snprintf(buf
, PAGE_SIZE
,
379 "%d %d %d %d %d %d %d %d %d\n",
391 static ssize_t
manager_cpr_coef_store(struct omap_overlay_manager
*mgr
,
392 const char *buf
, size_t size
)
394 struct omap_overlay_manager_info info
;
395 struct omap_dss_cpr_coefs coefs
;
399 if (!dss_has_feature(FEAT_CPR
))
402 if (sscanf(buf
, "%hd %hd %hd %hd %hd %hd %hd %hd %hd",
403 &coefs
.rr
, &coefs
.rg
, &coefs
.rb
,
404 &coefs
.gr
, &coefs
.gg
, &coefs
.gb
,
405 &coefs
.br
, &coefs
.bg
, &coefs
.bb
) != 9)
408 arr
= (s16
[]){ coefs
.rr
, coefs
.rg
, coefs
.rb
,
409 coefs
.gr
, coefs
.gg
, coefs
.gb
,
410 coefs
.br
, coefs
.bg
, coefs
.bb
};
412 for (i
= 0; i
< 9; ++i
) {
413 if (arr
[i
] < -512 || arr
[i
] > 511)
417 mgr
->get_manager_info(mgr
, &info
);
419 info
.cpr_coefs
= coefs
;
421 r
= mgr
->set_manager_info(mgr
, &info
);
432 struct manager_attribute
{
433 struct attribute attr
;
434 ssize_t (*show
)(struct omap_overlay_manager
*, char *);
435 ssize_t (*store
)(struct omap_overlay_manager
*, const char *, size_t);
438 #define MANAGER_ATTR(_name, _mode, _show, _store) \
439 struct manager_attribute manager_attr_##_name = \
440 __ATTR(_name, _mode, _show, _store)
442 static MANAGER_ATTR(name
, S_IRUGO
, manager_name_show
, NULL
);
443 static MANAGER_ATTR(display
, S_IRUGO
|S_IWUSR
,
444 manager_display_show
, manager_display_store
);
445 static MANAGER_ATTR(default_color
, S_IRUGO
|S_IWUSR
,
446 manager_default_color_show
, manager_default_color_store
);
447 static MANAGER_ATTR(trans_key_type
, S_IRUGO
|S_IWUSR
,
448 manager_trans_key_type_show
, manager_trans_key_type_store
);
449 static MANAGER_ATTR(trans_key_value
, S_IRUGO
|S_IWUSR
,
450 manager_trans_key_value_show
, manager_trans_key_value_store
);
451 static MANAGER_ATTR(trans_key_enabled
, S_IRUGO
|S_IWUSR
,
452 manager_trans_key_enabled_show
,
453 manager_trans_key_enabled_store
);
454 static MANAGER_ATTR(alpha_blending_enabled
, S_IRUGO
|S_IWUSR
,
455 manager_alpha_blending_enabled_show
,
456 manager_alpha_blending_enabled_store
);
457 static MANAGER_ATTR(cpr_enable
, S_IRUGO
|S_IWUSR
,
458 manager_cpr_enable_show
,
459 manager_cpr_enable_store
);
460 static MANAGER_ATTR(cpr_coef
, S_IRUGO
|S_IWUSR
,
461 manager_cpr_coef_show
,
462 manager_cpr_coef_store
);
465 static struct attribute
*manager_sysfs_attrs
[] = {
466 &manager_attr_name
.attr
,
467 &manager_attr_display
.attr
,
468 &manager_attr_default_color
.attr
,
469 &manager_attr_trans_key_type
.attr
,
470 &manager_attr_trans_key_value
.attr
,
471 &manager_attr_trans_key_enabled
.attr
,
472 &manager_attr_alpha_blending_enabled
.attr
,
473 &manager_attr_cpr_enable
.attr
,
474 &manager_attr_cpr_coef
.attr
,
478 static ssize_t
manager_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
481 struct omap_overlay_manager
*manager
;
482 struct manager_attribute
*manager_attr
;
484 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
485 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
487 if (!manager_attr
->show
)
490 return manager_attr
->show(manager
, buf
);
493 static ssize_t
manager_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
494 const char *buf
, size_t size
)
496 struct omap_overlay_manager
*manager
;
497 struct manager_attribute
*manager_attr
;
499 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
500 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
502 if (!manager_attr
->store
)
505 return manager_attr
->store(manager
, buf
, size
);
508 static const struct sysfs_ops manager_sysfs_ops
= {
509 .show
= manager_attr_show
,
510 .store
= manager_attr_store
,
513 static struct kobj_type manager_ktype
= {
514 .sysfs_ops
= &manager_sysfs_ops
,
515 .default_attrs
= manager_sysfs_attrs
,
518 int dss_manager_kobj_init(struct omap_overlay_manager
*mgr
,
519 struct platform_device
*pdev
)
521 return kobject_init_and_add(&mgr
->kobj
, &manager_ktype
,
522 &pdev
->dev
.kobj
, "manager%d", mgr
->id
);
525 void dss_manager_kobj_uninit(struct omap_overlay_manager
*mgr
)
527 kobject_del(&mgr
->kobj
);
528 kobject_put(&mgr
->kobj
);
530 memset(&mgr
->kobj
, 0, sizeof(mgr
->kobj
));