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/omapfb_dss.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 struct omap_overlay_manager_info info
;
188 r
= sysfs_match_string(trans_key_type_str
, buf
);
192 mgr
->get_manager_info(mgr
, &info
);
194 info
.trans_key_type
= r
;
196 r
= mgr
->set_manager_info(mgr
, &info
);
207 static ssize_t
manager_trans_key_value_show(struct omap_overlay_manager
*mgr
,
210 struct omap_overlay_manager_info info
;
212 mgr
->get_manager_info(mgr
, &info
);
214 return snprintf(buf
, PAGE_SIZE
, "%#x\n", info
.trans_key
);
217 static ssize_t
manager_trans_key_value_store(struct omap_overlay_manager
*mgr
,
218 const char *buf
, size_t size
)
220 struct omap_overlay_manager_info info
;
224 r
= kstrtouint(buf
, 0, &key_value
);
228 mgr
->get_manager_info(mgr
, &info
);
230 info
.trans_key
= key_value
;
232 r
= mgr
->set_manager_info(mgr
, &info
);
243 static ssize_t
manager_trans_key_enabled_show(struct omap_overlay_manager
*mgr
,
246 struct omap_overlay_manager_info info
;
248 mgr
->get_manager_info(mgr
, &info
);
250 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.trans_enabled
);
253 static ssize_t
manager_trans_key_enabled_store(struct omap_overlay_manager
*mgr
,
254 const char *buf
, size_t size
)
256 struct omap_overlay_manager_info info
;
260 r
= strtobool(buf
, &enable
);
264 mgr
->get_manager_info(mgr
, &info
);
266 info
.trans_enabled
= enable
;
268 r
= mgr
->set_manager_info(mgr
, &info
);
279 static ssize_t
manager_alpha_blending_enabled_show(
280 struct omap_overlay_manager
*mgr
, char *buf
)
282 struct omap_overlay_manager_info info
;
284 if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
287 mgr
->get_manager_info(mgr
, &info
);
289 return snprintf(buf
, PAGE_SIZE
, "%d\n",
290 info
.partial_alpha_enabled
);
293 static ssize_t
manager_alpha_blending_enabled_store(
294 struct omap_overlay_manager
*mgr
,
295 const char *buf
, size_t size
)
297 struct omap_overlay_manager_info info
;
301 if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
304 r
= strtobool(buf
, &enable
);
308 mgr
->get_manager_info(mgr
, &info
);
310 info
.partial_alpha_enabled
= enable
;
312 r
= mgr
->set_manager_info(mgr
, &info
);
323 static ssize_t
manager_cpr_enable_show(struct omap_overlay_manager
*mgr
,
326 struct omap_overlay_manager_info info
;
328 mgr
->get_manager_info(mgr
, &info
);
330 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.cpr_enable
);
333 static ssize_t
manager_cpr_enable_store(struct omap_overlay_manager
*mgr
,
334 const char *buf
, size_t size
)
336 struct omap_overlay_manager_info info
;
340 if (!dss_has_feature(FEAT_CPR
))
343 r
= strtobool(buf
, &enable
);
347 mgr
->get_manager_info(mgr
, &info
);
349 if (info
.cpr_enable
== enable
)
352 info
.cpr_enable
= enable
;
354 r
= mgr
->set_manager_info(mgr
, &info
);
365 static ssize_t
manager_cpr_coef_show(struct omap_overlay_manager
*mgr
,
368 struct omap_overlay_manager_info info
;
370 mgr
->get_manager_info(mgr
, &info
);
372 return snprintf(buf
, PAGE_SIZE
,
373 "%d %d %d %d %d %d %d %d %d\n",
385 static ssize_t
manager_cpr_coef_store(struct omap_overlay_manager
*mgr
,
386 const char *buf
, size_t size
)
388 struct omap_overlay_manager_info info
;
389 struct omap_dss_cpr_coefs coefs
;
393 if (!dss_has_feature(FEAT_CPR
))
396 if (sscanf(buf
, "%hd %hd %hd %hd %hd %hd %hd %hd %hd",
397 &coefs
.rr
, &coefs
.rg
, &coefs
.rb
,
398 &coefs
.gr
, &coefs
.gg
, &coefs
.gb
,
399 &coefs
.br
, &coefs
.bg
, &coefs
.bb
) != 9)
402 arr
= (s16
[]){ coefs
.rr
, coefs
.rg
, coefs
.rb
,
403 coefs
.gr
, coefs
.gg
, coefs
.gb
,
404 coefs
.br
, coefs
.bg
, coefs
.bb
};
406 for (i
= 0; i
< 9; ++i
) {
407 if (arr
[i
] < -512 || arr
[i
] > 511)
411 mgr
->get_manager_info(mgr
, &info
);
413 info
.cpr_coefs
= coefs
;
415 r
= mgr
->set_manager_info(mgr
, &info
);
426 struct manager_attribute
{
427 struct attribute attr
;
428 ssize_t (*show
)(struct omap_overlay_manager
*, char *);
429 ssize_t (*store
)(struct omap_overlay_manager
*, const char *, size_t);
432 #define MANAGER_ATTR(_name, _mode, _show, _store) \
433 struct manager_attribute manager_attr_##_name = \
434 __ATTR(_name, _mode, _show, _store)
436 static MANAGER_ATTR(name
, S_IRUGO
, manager_name_show
, NULL
);
437 static MANAGER_ATTR(display
, S_IRUGO
|S_IWUSR
,
438 manager_display_show
, manager_display_store
);
439 static MANAGER_ATTR(default_color
, S_IRUGO
|S_IWUSR
,
440 manager_default_color_show
, manager_default_color_store
);
441 static MANAGER_ATTR(trans_key_type
, S_IRUGO
|S_IWUSR
,
442 manager_trans_key_type_show
, manager_trans_key_type_store
);
443 static MANAGER_ATTR(trans_key_value
, S_IRUGO
|S_IWUSR
,
444 manager_trans_key_value_show
, manager_trans_key_value_store
);
445 static MANAGER_ATTR(trans_key_enabled
, S_IRUGO
|S_IWUSR
,
446 manager_trans_key_enabled_show
,
447 manager_trans_key_enabled_store
);
448 static MANAGER_ATTR(alpha_blending_enabled
, S_IRUGO
|S_IWUSR
,
449 manager_alpha_blending_enabled_show
,
450 manager_alpha_blending_enabled_store
);
451 static MANAGER_ATTR(cpr_enable
, S_IRUGO
|S_IWUSR
,
452 manager_cpr_enable_show
,
453 manager_cpr_enable_store
);
454 static MANAGER_ATTR(cpr_coef
, S_IRUGO
|S_IWUSR
,
455 manager_cpr_coef_show
,
456 manager_cpr_coef_store
);
459 static struct attribute
*manager_sysfs_attrs
[] = {
460 &manager_attr_name
.attr
,
461 &manager_attr_display
.attr
,
462 &manager_attr_default_color
.attr
,
463 &manager_attr_trans_key_type
.attr
,
464 &manager_attr_trans_key_value
.attr
,
465 &manager_attr_trans_key_enabled
.attr
,
466 &manager_attr_alpha_blending_enabled
.attr
,
467 &manager_attr_cpr_enable
.attr
,
468 &manager_attr_cpr_coef
.attr
,
472 static ssize_t
manager_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
475 struct omap_overlay_manager
*manager
;
476 struct manager_attribute
*manager_attr
;
478 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
479 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
481 if (!manager_attr
->show
)
484 return manager_attr
->show(manager
, buf
);
487 static ssize_t
manager_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
488 const char *buf
, size_t size
)
490 struct omap_overlay_manager
*manager
;
491 struct manager_attribute
*manager_attr
;
493 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
494 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
496 if (!manager_attr
->store
)
499 return manager_attr
->store(manager
, buf
, size
);
502 static const struct sysfs_ops manager_sysfs_ops
= {
503 .show
= manager_attr_show
,
504 .store
= manager_attr_store
,
507 static struct kobj_type manager_ktype
= {
508 .sysfs_ops
= &manager_sysfs_ops
,
509 .default_attrs
= manager_sysfs_attrs
,
512 int dss_manager_kobj_init(struct omap_overlay_manager
*mgr
,
513 struct platform_device
*pdev
)
515 return kobject_init_and_add(&mgr
->kobj
, &manager_ktype
,
516 &pdev
->dev
.kobj
, "manager%d", mgr
->id
);
519 void dss_manager_kobj_uninit(struct omap_overlay_manager
*mgr
)
521 kobject_del(&mgr
->kobj
);
522 kobject_put(&mgr
->kobj
);
524 memset(&mgr
->kobj
, 0, sizeof(mgr
->kobj
));