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 "OVERLAY"
12 #include <linux/module.h>
13 #include <linux/err.h>
14 #include <linux/sysfs.h>
15 #include <linux/kobject.h>
16 #include <linux/kstrtox.h>
17 #include <linux/platform_device.h>
19 #include <video/omapfb_dss.h>
22 #include "dss_features.h"
24 static ssize_t
overlay_name_show(struct omap_overlay
*ovl
, char *buf
)
26 return sysfs_emit(buf
, "%s\n", ovl
->name
);
29 static ssize_t
overlay_manager_show(struct omap_overlay
*ovl
, char *buf
)
31 return sysfs_emit(buf
, "%s\n",
32 ovl
->manager
? ovl
->manager
->name
: "<none>");
35 static ssize_t
overlay_manager_store(struct omap_overlay
*ovl
, const char *buf
,
39 struct omap_overlay_manager
*mgr
= NULL
;
40 struct omap_overlay_manager
*old_mgr
;
43 if (buf
[size
-1] == '\n')
47 for (i
= 0; i
< omap_dss_get_num_overlay_managers(); ++i
) {
48 mgr
= omap_dss_get_overlay_manager(i
);
50 if (sysfs_streq(buf
, mgr
->name
))
57 if (len
> 0 && mgr
== NULL
)
61 DSSDBG("manager %s found\n", mgr
->name
);
63 if (mgr
== ovl
->manager
)
66 old_mgr
= ovl
->manager
;
68 r
= dispc_runtime_get();
72 /* detach old manager */
74 r
= ovl
->unset_manager(ovl
);
76 DSSERR("detach failed\n");
80 r
= old_mgr
->apply(old_mgr
);
86 r
= ovl
->set_manager(ovl
, mgr
);
88 DSSERR("Failed to attach overlay\n");
106 static ssize_t
overlay_input_size_show(struct omap_overlay
*ovl
, char *buf
)
108 struct omap_overlay_info info
;
110 ovl
->get_overlay_info(ovl
, &info
);
112 return sysfs_emit(buf
, "%d,%d\n",
113 info
.width
, info
.height
);
116 static ssize_t
overlay_screen_width_show(struct omap_overlay
*ovl
, char *buf
)
118 struct omap_overlay_info info
;
120 ovl
->get_overlay_info(ovl
, &info
);
122 return sysfs_emit(buf
, "%d\n", info
.screen_width
);
125 static ssize_t
overlay_position_show(struct omap_overlay
*ovl
, char *buf
)
127 struct omap_overlay_info info
;
129 ovl
->get_overlay_info(ovl
, &info
);
131 return sysfs_emit(buf
, "%d,%d\n",
132 info
.pos_x
, info
.pos_y
);
135 static ssize_t
overlay_position_store(struct omap_overlay
*ovl
,
136 const char *buf
, size_t size
)
140 struct omap_overlay_info info
;
142 ovl
->get_overlay_info(ovl
, &info
);
144 info
.pos_x
= simple_strtoul(buf
, &last
, 10);
146 if (last
- buf
>= size
)
149 info
.pos_y
= simple_strtoul(last
, &last
, 10);
151 r
= ovl
->set_overlay_info(ovl
, &info
);
156 r
= ovl
->manager
->apply(ovl
->manager
);
164 static ssize_t
overlay_output_size_show(struct omap_overlay
*ovl
, char *buf
)
166 struct omap_overlay_info info
;
168 ovl
->get_overlay_info(ovl
, &info
);
170 return sysfs_emit(buf
, "%d,%d\n",
171 info
.out_width
, info
.out_height
);
174 static ssize_t
overlay_output_size_store(struct omap_overlay
*ovl
,
175 const char *buf
, size_t size
)
179 struct omap_overlay_info info
;
181 ovl
->get_overlay_info(ovl
, &info
);
183 info
.out_width
= simple_strtoul(buf
, &last
, 10);
185 if (last
- buf
>= size
)
188 info
.out_height
= simple_strtoul(last
, &last
, 10);
190 r
= ovl
->set_overlay_info(ovl
, &info
);
195 r
= ovl
->manager
->apply(ovl
->manager
);
203 static ssize_t
overlay_enabled_show(struct omap_overlay
*ovl
, char *buf
)
205 return sysfs_emit(buf
, "%d\n", ovl
->is_enabled(ovl
));
208 static ssize_t
overlay_enabled_store(struct omap_overlay
*ovl
, const char *buf
,
214 r
= kstrtobool(buf
, &enable
);
219 r
= ovl
->enable(ovl
);
221 r
= ovl
->disable(ovl
);
229 static ssize_t
overlay_global_alpha_show(struct omap_overlay
*ovl
, char *buf
)
231 struct omap_overlay_info info
;
233 ovl
->get_overlay_info(ovl
, &info
);
235 return sysfs_emit(buf
, "%d\n",
239 static ssize_t
overlay_global_alpha_store(struct omap_overlay
*ovl
,
240 const char *buf
, size_t size
)
244 struct omap_overlay_info info
;
246 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
249 r
= kstrtou8(buf
, 0, &alpha
);
253 ovl
->get_overlay_info(ovl
, &info
);
255 info
.global_alpha
= alpha
;
257 r
= ovl
->set_overlay_info(ovl
, &info
);
262 r
= ovl
->manager
->apply(ovl
->manager
);
270 static ssize_t
overlay_pre_mult_alpha_show(struct omap_overlay
*ovl
,
273 struct omap_overlay_info info
;
275 ovl
->get_overlay_info(ovl
, &info
);
277 return sysfs_emit(buf
, "%d\n",
278 info
.pre_mult_alpha
);
281 static ssize_t
overlay_pre_mult_alpha_store(struct omap_overlay
*ovl
,
282 const char *buf
, size_t size
)
286 struct omap_overlay_info info
;
288 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
) == 0)
291 r
= kstrtou8(buf
, 0, &alpha
);
295 ovl
->get_overlay_info(ovl
, &info
);
297 info
.pre_mult_alpha
= alpha
;
299 r
= ovl
->set_overlay_info(ovl
, &info
);
304 r
= ovl
->manager
->apply(ovl
->manager
);
312 static ssize_t
overlay_zorder_show(struct omap_overlay
*ovl
, char *buf
)
314 struct omap_overlay_info info
;
316 ovl
->get_overlay_info(ovl
, &info
);
318 return sysfs_emit(buf
, "%d\n", info
.zorder
);
321 static ssize_t
overlay_zorder_store(struct omap_overlay
*ovl
,
322 const char *buf
, size_t size
)
326 struct omap_overlay_info info
;
328 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_ZORDER
) == 0)
331 r
= kstrtou8(buf
, 0, &zorder
);
335 ovl
->get_overlay_info(ovl
, &info
);
337 info
.zorder
= zorder
;
339 r
= ovl
->set_overlay_info(ovl
, &info
);
344 r
= ovl
->manager
->apply(ovl
->manager
);
352 struct overlay_attribute
{
353 struct attribute attr
;
354 ssize_t (*show
)(struct omap_overlay
*, char *);
355 ssize_t (*store
)(struct omap_overlay
*, const char *, size_t);
358 #define OVERLAY_ATTR(_name, _mode, _show, _store) \
359 struct overlay_attribute overlay_attr_##_name = \
360 __ATTR(_name, _mode, _show, _store)
362 static OVERLAY_ATTR(name
, S_IRUGO
, overlay_name_show
, NULL
);
363 static OVERLAY_ATTR(manager
, S_IRUGO
|S_IWUSR
,
364 overlay_manager_show
, overlay_manager_store
);
365 static OVERLAY_ATTR(input_size
, S_IRUGO
, overlay_input_size_show
, NULL
);
366 static OVERLAY_ATTR(screen_width
, S_IRUGO
, overlay_screen_width_show
, NULL
);
367 static OVERLAY_ATTR(position
, S_IRUGO
|S_IWUSR
,
368 overlay_position_show
, overlay_position_store
);
369 static OVERLAY_ATTR(output_size
, S_IRUGO
|S_IWUSR
,
370 overlay_output_size_show
, overlay_output_size_store
);
371 static OVERLAY_ATTR(enabled
, S_IRUGO
|S_IWUSR
,
372 overlay_enabled_show
, overlay_enabled_store
);
373 static OVERLAY_ATTR(global_alpha
, S_IRUGO
|S_IWUSR
,
374 overlay_global_alpha_show
, overlay_global_alpha_store
);
375 static OVERLAY_ATTR(pre_mult_alpha
, S_IRUGO
|S_IWUSR
,
376 overlay_pre_mult_alpha_show
,
377 overlay_pre_mult_alpha_store
);
378 static OVERLAY_ATTR(zorder
, S_IRUGO
|S_IWUSR
,
379 overlay_zorder_show
, overlay_zorder_store
);
381 static struct attribute
*overlay_sysfs_attrs
[] = {
382 &overlay_attr_name
.attr
,
383 &overlay_attr_manager
.attr
,
384 &overlay_attr_input_size
.attr
,
385 &overlay_attr_screen_width
.attr
,
386 &overlay_attr_position
.attr
,
387 &overlay_attr_output_size
.attr
,
388 &overlay_attr_enabled
.attr
,
389 &overlay_attr_global_alpha
.attr
,
390 &overlay_attr_pre_mult_alpha
.attr
,
391 &overlay_attr_zorder
.attr
,
394 ATTRIBUTE_GROUPS(overlay_sysfs
);
396 static ssize_t
overlay_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
399 struct omap_overlay
*overlay
;
400 struct overlay_attribute
*overlay_attr
;
402 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
403 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
405 if (!overlay_attr
->show
)
408 return overlay_attr
->show(overlay
, buf
);
411 static ssize_t
overlay_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
412 const char *buf
, size_t size
)
414 struct omap_overlay
*overlay
;
415 struct overlay_attribute
*overlay_attr
;
417 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
418 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
420 if (!overlay_attr
->store
)
423 return overlay_attr
->store(overlay
, buf
, size
);
426 static const struct sysfs_ops overlay_sysfs_ops
= {
427 .show
= overlay_attr_show
,
428 .store
= overlay_attr_store
,
431 static struct kobj_type overlay_ktype
= {
432 .sysfs_ops
= &overlay_sysfs_ops
,
433 .default_groups
= overlay_sysfs_groups
,
436 int dss_overlay_kobj_init(struct omap_overlay
*ovl
,
437 struct platform_device
*pdev
)
439 return kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
440 &pdev
->dev
.kobj
, "overlay%d", ovl
->id
);
443 void dss_overlay_kobj_uninit(struct omap_overlay
*ovl
)
445 kobject_del(&ovl
->kobj
);
446 kobject_put(&ovl
->kobj
);