1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2009 Nokia Corporation
4 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 * Some code and ideas taken from drivers/video/omap/ driver
10 #define DSS_SUBSYS_NAME "MANAGER"
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/jiffies.h>
18 #include <video/omapfb_dss.h>
21 #include "dss_features.h"
23 static ssize_t
manager_name_show(struct omap_overlay_manager
*mgr
, char *buf
)
25 return snprintf(buf
, PAGE_SIZE
, "%s\n", mgr
->name
);
28 static ssize_t
manager_display_show(struct omap_overlay_manager
*mgr
, char *buf
)
30 struct omap_dss_device
*dssdev
= mgr
->get_device(mgr
);
32 return snprintf(buf
, PAGE_SIZE
, "%s\n", dssdev
?
33 dssdev
->name
: "<none>");
36 static int manager_display_match(struct omap_dss_device
*dssdev
, void *data
)
38 const char *str
= data
;
40 return sysfs_streq(dssdev
->name
, str
);
43 static ssize_t
manager_display_store(struct omap_overlay_manager
*mgr
,
44 const char *buf
, size_t size
)
48 struct omap_dss_device
*dssdev
= NULL
;
49 struct omap_dss_device
*old_dssdev
;
51 if (buf
[size
-1] == '\n')
55 dssdev
= omap_dss_find_device((void *)buf
,
56 manager_display_match
);
58 if (len
> 0 && dssdev
== NULL
)
62 DSSDBG("display %s found\n", dssdev
->name
);
64 if (omapdss_device_is_connected(dssdev
)) {
65 DSSERR("new display is already connected\n");
70 if (omapdss_device_is_enabled(dssdev
)) {
71 DSSERR("new display is not disabled\n");
77 old_dssdev
= mgr
->get_device(mgr
);
79 if (omapdss_device_is_enabled(old_dssdev
)) {
80 DSSERR("old display is not disabled\n");
85 old_dssdev
->driver
->disconnect(old_dssdev
);
89 r
= dssdev
->driver
->connect(dssdev
);
91 DSSERR("failed to connect new device\n");
95 old_dssdev
= mgr
->get_device(mgr
);
96 if (old_dssdev
!= dssdev
) {
97 DSSERR("failed to connect device to this manager\n");
98 dssdev
->driver
->disconnect(dssdev
);
104 DSSERR("failed to apply dispc config\n");
111 omap_dss_put_device(dssdev
);
116 static ssize_t
manager_default_color_show(struct omap_overlay_manager
*mgr
,
119 struct omap_overlay_manager_info info
;
121 mgr
->get_manager_info(mgr
, &info
);
123 return snprintf(buf
, PAGE_SIZE
, "%#x\n", info
.default_color
);
126 static ssize_t
manager_default_color_store(struct omap_overlay_manager
*mgr
,
127 const char *buf
, size_t size
)
129 struct omap_overlay_manager_info info
;
133 r
= kstrtouint(buf
, 0, &color
);
137 mgr
->get_manager_info(mgr
, &info
);
139 info
.default_color
= color
;
141 r
= mgr
->set_manager_info(mgr
, &info
);
152 static const char *trans_key_type_str
[] = {
157 static ssize_t
manager_trans_key_type_show(struct omap_overlay_manager
*mgr
,
160 enum omap_dss_trans_key_type key_type
;
161 struct omap_overlay_manager_info info
;
163 mgr
->get_manager_info(mgr
, &info
);
165 key_type
= info
.trans_key_type
;
166 BUG_ON(key_type
>= ARRAY_SIZE(trans_key_type_str
));
168 return snprintf(buf
, PAGE_SIZE
, "%s\n", trans_key_type_str
[key_type
]);
171 static ssize_t
manager_trans_key_type_store(struct omap_overlay_manager
*mgr
,
172 const char *buf
, size_t size
)
174 struct omap_overlay_manager_info info
;
177 r
= sysfs_match_string(trans_key_type_str
, buf
);
181 mgr
->get_manager_info(mgr
, &info
);
183 info
.trans_key_type
= r
;
185 r
= mgr
->set_manager_info(mgr
, &info
);
196 static ssize_t
manager_trans_key_value_show(struct omap_overlay_manager
*mgr
,
199 struct omap_overlay_manager_info info
;
201 mgr
->get_manager_info(mgr
, &info
);
203 return snprintf(buf
, PAGE_SIZE
, "%#x\n", info
.trans_key
);
206 static ssize_t
manager_trans_key_value_store(struct omap_overlay_manager
*mgr
,
207 const char *buf
, size_t size
)
209 struct omap_overlay_manager_info info
;
213 r
= kstrtouint(buf
, 0, &key_value
);
217 mgr
->get_manager_info(mgr
, &info
);
219 info
.trans_key
= key_value
;
221 r
= mgr
->set_manager_info(mgr
, &info
);
232 static ssize_t
manager_trans_key_enabled_show(struct omap_overlay_manager
*mgr
,
235 struct omap_overlay_manager_info info
;
237 mgr
->get_manager_info(mgr
, &info
);
239 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.trans_enabled
);
242 static ssize_t
manager_trans_key_enabled_store(struct omap_overlay_manager
*mgr
,
243 const char *buf
, size_t size
)
245 struct omap_overlay_manager_info info
;
249 r
= strtobool(buf
, &enable
);
253 mgr
->get_manager_info(mgr
, &info
);
255 info
.trans_enabled
= enable
;
257 r
= mgr
->set_manager_info(mgr
, &info
);
268 static ssize_t
manager_alpha_blending_enabled_show(
269 struct omap_overlay_manager
*mgr
, char *buf
)
271 struct omap_overlay_manager_info info
;
273 if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
276 mgr
->get_manager_info(mgr
, &info
);
278 return snprintf(buf
, PAGE_SIZE
, "%d\n",
279 info
.partial_alpha_enabled
);
282 static ssize_t
manager_alpha_blending_enabled_store(
283 struct omap_overlay_manager
*mgr
,
284 const char *buf
, size_t size
)
286 struct omap_overlay_manager_info info
;
290 if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER
))
293 r
= strtobool(buf
, &enable
);
297 mgr
->get_manager_info(mgr
, &info
);
299 info
.partial_alpha_enabled
= enable
;
301 r
= mgr
->set_manager_info(mgr
, &info
);
312 static ssize_t
manager_cpr_enable_show(struct omap_overlay_manager
*mgr
,
315 struct omap_overlay_manager_info info
;
317 mgr
->get_manager_info(mgr
, &info
);
319 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.cpr_enable
);
322 static ssize_t
manager_cpr_enable_store(struct omap_overlay_manager
*mgr
,
323 const char *buf
, size_t size
)
325 struct omap_overlay_manager_info info
;
329 if (!dss_has_feature(FEAT_CPR
))
332 r
= strtobool(buf
, &enable
);
336 mgr
->get_manager_info(mgr
, &info
);
338 if (info
.cpr_enable
== enable
)
341 info
.cpr_enable
= enable
;
343 r
= mgr
->set_manager_info(mgr
, &info
);
354 static ssize_t
manager_cpr_coef_show(struct omap_overlay_manager
*mgr
,
357 struct omap_overlay_manager_info info
;
359 mgr
->get_manager_info(mgr
, &info
);
361 return snprintf(buf
, PAGE_SIZE
,
362 "%d %d %d %d %d %d %d %d %d\n",
374 static ssize_t
manager_cpr_coef_store(struct omap_overlay_manager
*mgr
,
375 const char *buf
, size_t size
)
377 struct omap_overlay_manager_info info
;
378 struct omap_dss_cpr_coefs coefs
;
382 if (!dss_has_feature(FEAT_CPR
))
385 if (sscanf(buf
, "%hd %hd %hd %hd %hd %hd %hd %hd %hd",
386 &coefs
.rr
, &coefs
.rg
, &coefs
.rb
,
387 &coefs
.gr
, &coefs
.gg
, &coefs
.gb
,
388 &coefs
.br
, &coefs
.bg
, &coefs
.bb
) != 9)
391 arr
= (s16
[]){ coefs
.rr
, coefs
.rg
, coefs
.rb
,
392 coefs
.gr
, coefs
.gg
, coefs
.gb
,
393 coefs
.br
, coefs
.bg
, coefs
.bb
};
395 for (i
= 0; i
< 9; ++i
) {
396 if (arr
[i
] < -512 || arr
[i
] > 511)
400 mgr
->get_manager_info(mgr
, &info
);
402 info
.cpr_coefs
= coefs
;
404 r
= mgr
->set_manager_info(mgr
, &info
);
415 struct manager_attribute
{
416 struct attribute attr
;
417 ssize_t (*show
)(struct omap_overlay_manager
*, char *);
418 ssize_t (*store
)(struct omap_overlay_manager
*, const char *, size_t);
421 #define MANAGER_ATTR(_name, _mode, _show, _store) \
422 struct manager_attribute manager_attr_##_name = \
423 __ATTR(_name, _mode, _show, _store)
425 static MANAGER_ATTR(name
, S_IRUGO
, manager_name_show
, NULL
);
426 static MANAGER_ATTR(display
, S_IRUGO
|S_IWUSR
,
427 manager_display_show
, manager_display_store
);
428 static MANAGER_ATTR(default_color
, S_IRUGO
|S_IWUSR
,
429 manager_default_color_show
, manager_default_color_store
);
430 static MANAGER_ATTR(trans_key_type
, S_IRUGO
|S_IWUSR
,
431 manager_trans_key_type_show
, manager_trans_key_type_store
);
432 static MANAGER_ATTR(trans_key_value
, S_IRUGO
|S_IWUSR
,
433 manager_trans_key_value_show
, manager_trans_key_value_store
);
434 static MANAGER_ATTR(trans_key_enabled
, S_IRUGO
|S_IWUSR
,
435 manager_trans_key_enabled_show
,
436 manager_trans_key_enabled_store
);
437 static MANAGER_ATTR(alpha_blending_enabled
, S_IRUGO
|S_IWUSR
,
438 manager_alpha_blending_enabled_show
,
439 manager_alpha_blending_enabled_store
);
440 static MANAGER_ATTR(cpr_enable
, S_IRUGO
|S_IWUSR
,
441 manager_cpr_enable_show
,
442 manager_cpr_enable_store
);
443 static MANAGER_ATTR(cpr_coef
, S_IRUGO
|S_IWUSR
,
444 manager_cpr_coef_show
,
445 manager_cpr_coef_store
);
448 static struct attribute
*manager_sysfs_attrs
[] = {
449 &manager_attr_name
.attr
,
450 &manager_attr_display
.attr
,
451 &manager_attr_default_color
.attr
,
452 &manager_attr_trans_key_type
.attr
,
453 &manager_attr_trans_key_value
.attr
,
454 &manager_attr_trans_key_enabled
.attr
,
455 &manager_attr_alpha_blending_enabled
.attr
,
456 &manager_attr_cpr_enable
.attr
,
457 &manager_attr_cpr_coef
.attr
,
461 static ssize_t
manager_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
464 struct omap_overlay_manager
*manager
;
465 struct manager_attribute
*manager_attr
;
467 manager
= container_of(kobj
, struct omap_overlay_manager
, kobj
);
468 manager_attr
= container_of(attr
, struct manager_attribute
, attr
);
470 if (!manager_attr
->show
)
473 return manager_attr
->show(manager
, buf
);
476 static ssize_t
manager_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
477 const char *buf
, size_t size
)
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
->store
)
488 return manager_attr
->store(manager
, buf
, size
);
491 static const struct sysfs_ops manager_sysfs_ops
= {
492 .show
= manager_attr_show
,
493 .store
= manager_attr_store
,
496 static struct kobj_type manager_ktype
= {
497 .sysfs_ops
= &manager_sysfs_ops
,
498 .default_attrs
= manager_sysfs_attrs
,
501 int dss_manager_kobj_init(struct omap_overlay_manager
*mgr
,
502 struct platform_device
*pdev
)
504 return kobject_init_and_add(&mgr
->kobj
, &manager_ktype
,
505 &pdev
->dev
.kobj
, "manager%d", mgr
->id
);
508 void dss_manager_kobj_uninit(struct omap_overlay_manager
*mgr
)
510 kobject_del(&mgr
->kobj
);
511 kobject_put(&mgr
->kobj
);
513 memset(&mgr
->kobj
, 0, sizeof(mgr
->kobj
));