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/platform_device.h>
18 #include <video/omapfb_dss.h>
21 #include "dss_features.h"
23 static ssize_t
overlay_name_show(struct omap_overlay
*ovl
, char *buf
)
25 return snprintf(buf
, PAGE_SIZE
, "%s\n", ovl
->name
);
28 static ssize_t
overlay_manager_show(struct omap_overlay
*ovl
, char *buf
)
30 return snprintf(buf
, PAGE_SIZE
, "%s\n",
31 ovl
->manager
? ovl
->manager
->name
: "<none>");
34 static ssize_t
overlay_manager_store(struct omap_overlay
*ovl
, const char *buf
,
38 struct omap_overlay_manager
*mgr
= NULL
;
39 struct omap_overlay_manager
*old_mgr
;
42 if (buf
[size
-1] == '\n')
46 for (i
= 0; i
< omap_dss_get_num_overlay_managers(); ++i
) {
47 mgr
= omap_dss_get_overlay_manager(i
);
49 if (sysfs_streq(buf
, mgr
->name
))
56 if (len
> 0 && mgr
== NULL
)
60 DSSDBG("manager %s found\n", mgr
->name
);
62 if (mgr
== ovl
->manager
)
65 old_mgr
= ovl
->manager
;
67 r
= dispc_runtime_get();
71 /* detach old manager */
73 r
= ovl
->unset_manager(ovl
);
75 DSSERR("detach failed\n");
79 r
= old_mgr
->apply(old_mgr
);
85 r
= ovl
->set_manager(ovl
, mgr
);
87 DSSERR("Failed to attach overlay\n");
105 static ssize_t
overlay_input_size_show(struct omap_overlay
*ovl
, char *buf
)
107 struct omap_overlay_info info
;
109 ovl
->get_overlay_info(ovl
, &info
);
111 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
112 info
.width
, info
.height
);
115 static ssize_t
overlay_screen_width_show(struct omap_overlay
*ovl
, char *buf
)
117 struct omap_overlay_info info
;
119 ovl
->get_overlay_info(ovl
, &info
);
121 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.screen_width
);
124 static ssize_t
overlay_position_show(struct omap_overlay
*ovl
, char *buf
)
126 struct omap_overlay_info info
;
128 ovl
->get_overlay_info(ovl
, &info
);
130 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
131 info
.pos_x
, info
.pos_y
);
134 static ssize_t
overlay_position_store(struct omap_overlay
*ovl
,
135 const char *buf
, size_t size
)
139 struct omap_overlay_info info
;
141 ovl
->get_overlay_info(ovl
, &info
);
143 info
.pos_x
= simple_strtoul(buf
, &last
, 10);
145 if (last
- buf
>= size
)
148 info
.pos_y
= simple_strtoul(last
, &last
, 10);
150 r
= ovl
->set_overlay_info(ovl
, &info
);
155 r
= ovl
->manager
->apply(ovl
->manager
);
163 static ssize_t
overlay_output_size_show(struct omap_overlay
*ovl
, char *buf
)
165 struct omap_overlay_info info
;
167 ovl
->get_overlay_info(ovl
, &info
);
169 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
170 info
.out_width
, info
.out_height
);
173 static ssize_t
overlay_output_size_store(struct omap_overlay
*ovl
,
174 const char *buf
, size_t size
)
178 struct omap_overlay_info info
;
180 ovl
->get_overlay_info(ovl
, &info
);
182 info
.out_width
= simple_strtoul(buf
, &last
, 10);
184 if (last
- buf
>= size
)
187 info
.out_height
= simple_strtoul(last
, &last
, 10);
189 r
= ovl
->set_overlay_info(ovl
, &info
);
194 r
= ovl
->manager
->apply(ovl
->manager
);
202 static ssize_t
overlay_enabled_show(struct omap_overlay
*ovl
, char *buf
)
204 return snprintf(buf
, PAGE_SIZE
, "%d\n", ovl
->is_enabled(ovl
));
207 static ssize_t
overlay_enabled_store(struct omap_overlay
*ovl
, const char *buf
,
213 r
= strtobool(buf
, &enable
);
218 r
= ovl
->enable(ovl
);
220 r
= ovl
->disable(ovl
);
228 static ssize_t
overlay_global_alpha_show(struct omap_overlay
*ovl
, char *buf
)
230 struct omap_overlay_info info
;
232 ovl
->get_overlay_info(ovl
, &info
);
234 return snprintf(buf
, PAGE_SIZE
, "%d\n",
238 static ssize_t
overlay_global_alpha_store(struct omap_overlay
*ovl
,
239 const char *buf
, size_t size
)
243 struct omap_overlay_info info
;
245 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
248 r
= kstrtou8(buf
, 0, &alpha
);
252 ovl
->get_overlay_info(ovl
, &info
);
254 info
.global_alpha
= alpha
;
256 r
= ovl
->set_overlay_info(ovl
, &info
);
261 r
= ovl
->manager
->apply(ovl
->manager
);
269 static ssize_t
overlay_pre_mult_alpha_show(struct omap_overlay
*ovl
,
272 struct omap_overlay_info info
;
274 ovl
->get_overlay_info(ovl
, &info
);
276 return snprintf(buf
, PAGE_SIZE
, "%d\n",
277 info
.pre_mult_alpha
);
280 static ssize_t
overlay_pre_mult_alpha_store(struct omap_overlay
*ovl
,
281 const char *buf
, size_t size
)
285 struct omap_overlay_info info
;
287 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
) == 0)
290 r
= kstrtou8(buf
, 0, &alpha
);
294 ovl
->get_overlay_info(ovl
, &info
);
296 info
.pre_mult_alpha
= alpha
;
298 r
= ovl
->set_overlay_info(ovl
, &info
);
303 r
= ovl
->manager
->apply(ovl
->manager
);
311 static ssize_t
overlay_zorder_show(struct omap_overlay
*ovl
, char *buf
)
313 struct omap_overlay_info info
;
315 ovl
->get_overlay_info(ovl
, &info
);
317 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.zorder
);
320 static ssize_t
overlay_zorder_store(struct omap_overlay
*ovl
,
321 const char *buf
, size_t size
)
325 struct omap_overlay_info info
;
327 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_ZORDER
) == 0)
330 r
= kstrtou8(buf
, 0, &zorder
);
334 ovl
->get_overlay_info(ovl
, &info
);
336 info
.zorder
= zorder
;
338 r
= ovl
->set_overlay_info(ovl
, &info
);
343 r
= ovl
->manager
->apply(ovl
->manager
);
351 struct overlay_attribute
{
352 struct attribute attr
;
353 ssize_t (*show
)(struct omap_overlay
*, char *);
354 ssize_t (*store
)(struct omap_overlay
*, const char *, size_t);
357 #define OVERLAY_ATTR(_name, _mode, _show, _store) \
358 struct overlay_attribute overlay_attr_##_name = \
359 __ATTR(_name, _mode, _show, _store)
361 static OVERLAY_ATTR(name
, S_IRUGO
, overlay_name_show
, NULL
);
362 static OVERLAY_ATTR(manager
, S_IRUGO
|S_IWUSR
,
363 overlay_manager_show
, overlay_manager_store
);
364 static OVERLAY_ATTR(input_size
, S_IRUGO
, overlay_input_size_show
, NULL
);
365 static OVERLAY_ATTR(screen_width
, S_IRUGO
, overlay_screen_width_show
, NULL
);
366 static OVERLAY_ATTR(position
, S_IRUGO
|S_IWUSR
,
367 overlay_position_show
, overlay_position_store
);
368 static OVERLAY_ATTR(output_size
, S_IRUGO
|S_IWUSR
,
369 overlay_output_size_show
, overlay_output_size_store
);
370 static OVERLAY_ATTR(enabled
, S_IRUGO
|S_IWUSR
,
371 overlay_enabled_show
, overlay_enabled_store
);
372 static OVERLAY_ATTR(global_alpha
, S_IRUGO
|S_IWUSR
,
373 overlay_global_alpha_show
, overlay_global_alpha_store
);
374 static OVERLAY_ATTR(pre_mult_alpha
, S_IRUGO
|S_IWUSR
,
375 overlay_pre_mult_alpha_show
,
376 overlay_pre_mult_alpha_store
);
377 static OVERLAY_ATTR(zorder
, S_IRUGO
|S_IWUSR
,
378 overlay_zorder_show
, overlay_zorder_store
);
380 static struct attribute
*overlay_sysfs_attrs
[] = {
381 &overlay_attr_name
.attr
,
382 &overlay_attr_manager
.attr
,
383 &overlay_attr_input_size
.attr
,
384 &overlay_attr_screen_width
.attr
,
385 &overlay_attr_position
.attr
,
386 &overlay_attr_output_size
.attr
,
387 &overlay_attr_enabled
.attr
,
388 &overlay_attr_global_alpha
.attr
,
389 &overlay_attr_pre_mult_alpha
.attr
,
390 &overlay_attr_zorder
.attr
,
394 static ssize_t
overlay_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
397 struct omap_overlay
*overlay
;
398 struct overlay_attribute
*overlay_attr
;
400 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
401 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
403 if (!overlay_attr
->show
)
406 return overlay_attr
->show(overlay
, buf
);
409 static ssize_t
overlay_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
410 const char *buf
, size_t size
)
412 struct omap_overlay
*overlay
;
413 struct overlay_attribute
*overlay_attr
;
415 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
416 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
418 if (!overlay_attr
->store
)
421 return overlay_attr
->store(overlay
, buf
, size
);
424 static const struct sysfs_ops overlay_sysfs_ops
= {
425 .show
= overlay_attr_show
,
426 .store
= overlay_attr_store
,
429 static struct kobj_type overlay_ktype
= {
430 .sysfs_ops
= &overlay_sysfs_ops
,
431 .default_attrs
= overlay_sysfs_attrs
,
434 int dss_overlay_kobj_init(struct omap_overlay
*ovl
,
435 struct platform_device
*pdev
)
437 return kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
438 &pdev
->dev
.kobj
, "overlay%d", ovl
->id
);
441 void dss_overlay_kobj_uninit(struct omap_overlay
*ovl
)
443 kobject_del(&ovl
->kobj
);
444 kobject_put(&ovl
->kobj
);