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 "OVERLAY"
23 #include <linux/module.h>
24 #include <linux/err.h>
25 #include <linux/sysfs.h>
26 #include <linux/kobject.h>
27 #include <linux/platform_device.h>
29 #include <video/omapdss.h>
32 #include "dss_features.h"
34 static ssize_t
overlay_name_show(struct omap_overlay
*ovl
, char *buf
)
36 return snprintf(buf
, PAGE_SIZE
, "%s\n", ovl
->name
);
39 static ssize_t
overlay_manager_show(struct omap_overlay
*ovl
, char *buf
)
41 return snprintf(buf
, PAGE_SIZE
, "%s\n",
42 ovl
->manager
? ovl
->manager
->name
: "<none>");
45 static ssize_t
overlay_manager_store(struct omap_overlay
*ovl
, const char *buf
,
49 struct omap_overlay_manager
*mgr
= NULL
;
50 struct omap_overlay_manager
*old_mgr
;
53 if (buf
[size
-1] == '\n')
57 for (i
= 0; i
< omap_dss_get_num_overlay_managers(); ++i
) {
58 mgr
= omap_dss_get_overlay_manager(i
);
60 if (sysfs_streq(buf
, mgr
->name
))
67 if (len
> 0 && mgr
== NULL
)
71 DSSDBG("manager %s found\n", mgr
->name
);
73 if (mgr
== ovl
->manager
)
76 old_mgr
= ovl
->manager
;
78 r
= dispc_runtime_get();
82 /* detach old manager */
84 r
= ovl
->unset_manager(ovl
);
86 DSSERR("detach failed\n");
90 r
= old_mgr
->apply(old_mgr
);
96 r
= ovl
->set_manager(ovl
, mgr
);
98 DSSERR("Failed to attach overlay\n");
116 static ssize_t
overlay_input_size_show(struct omap_overlay
*ovl
, char *buf
)
118 struct omap_overlay_info info
;
120 ovl
->get_overlay_info(ovl
, &info
);
122 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
123 info
.width
, info
.height
);
126 static ssize_t
overlay_screen_width_show(struct omap_overlay
*ovl
, char *buf
)
128 struct omap_overlay_info info
;
130 ovl
->get_overlay_info(ovl
, &info
);
132 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.screen_width
);
135 static ssize_t
overlay_position_show(struct omap_overlay
*ovl
, char *buf
)
137 struct omap_overlay_info info
;
139 ovl
->get_overlay_info(ovl
, &info
);
141 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
142 info
.pos_x
, info
.pos_y
);
145 static ssize_t
overlay_position_store(struct omap_overlay
*ovl
,
146 const char *buf
, size_t size
)
150 struct omap_overlay_info info
;
152 ovl
->get_overlay_info(ovl
, &info
);
154 info
.pos_x
= simple_strtoul(buf
, &last
, 10);
156 if (last
- buf
>= size
)
159 info
.pos_y
= simple_strtoul(last
, &last
, 10);
161 r
= ovl
->set_overlay_info(ovl
, &info
);
166 r
= ovl
->manager
->apply(ovl
->manager
);
174 static ssize_t
overlay_output_size_show(struct omap_overlay
*ovl
, char *buf
)
176 struct omap_overlay_info info
;
178 ovl
->get_overlay_info(ovl
, &info
);
180 return snprintf(buf
, PAGE_SIZE
, "%d,%d\n",
181 info
.out_width
, info
.out_height
);
184 static ssize_t
overlay_output_size_store(struct omap_overlay
*ovl
,
185 const char *buf
, size_t size
)
189 struct omap_overlay_info info
;
191 ovl
->get_overlay_info(ovl
, &info
);
193 info
.out_width
= simple_strtoul(buf
, &last
, 10);
195 if (last
- buf
>= size
)
198 info
.out_height
= simple_strtoul(last
, &last
, 10);
200 r
= ovl
->set_overlay_info(ovl
, &info
);
205 r
= ovl
->manager
->apply(ovl
->manager
);
213 static ssize_t
overlay_enabled_show(struct omap_overlay
*ovl
, char *buf
)
215 return snprintf(buf
, PAGE_SIZE
, "%d\n", ovl
->is_enabled(ovl
));
218 static ssize_t
overlay_enabled_store(struct omap_overlay
*ovl
, const char *buf
,
224 r
= strtobool(buf
, &enable
);
229 r
= ovl
->enable(ovl
);
231 r
= ovl
->disable(ovl
);
239 static ssize_t
overlay_global_alpha_show(struct omap_overlay
*ovl
, char *buf
)
241 struct omap_overlay_info info
;
243 ovl
->get_overlay_info(ovl
, &info
);
245 return snprintf(buf
, PAGE_SIZE
, "%d\n",
249 static ssize_t
overlay_global_alpha_store(struct omap_overlay
*ovl
,
250 const char *buf
, size_t size
)
254 struct omap_overlay_info info
;
256 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_GLOBAL_ALPHA
) == 0)
259 r
= kstrtou8(buf
, 0, &alpha
);
263 ovl
->get_overlay_info(ovl
, &info
);
265 info
.global_alpha
= alpha
;
267 r
= ovl
->set_overlay_info(ovl
, &info
);
272 r
= ovl
->manager
->apply(ovl
->manager
);
280 static ssize_t
overlay_pre_mult_alpha_show(struct omap_overlay
*ovl
,
283 struct omap_overlay_info info
;
285 ovl
->get_overlay_info(ovl
, &info
);
287 return snprintf(buf
, PAGE_SIZE
, "%d\n",
288 info
.pre_mult_alpha
);
291 static ssize_t
overlay_pre_mult_alpha_store(struct omap_overlay
*ovl
,
292 const char *buf
, size_t size
)
296 struct omap_overlay_info info
;
298 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA
) == 0)
301 r
= kstrtou8(buf
, 0, &alpha
);
305 ovl
->get_overlay_info(ovl
, &info
);
307 info
.pre_mult_alpha
= alpha
;
309 r
= ovl
->set_overlay_info(ovl
, &info
);
314 r
= ovl
->manager
->apply(ovl
->manager
);
322 static ssize_t
overlay_zorder_show(struct omap_overlay
*ovl
, char *buf
)
324 struct omap_overlay_info info
;
326 ovl
->get_overlay_info(ovl
, &info
);
328 return snprintf(buf
, PAGE_SIZE
, "%d\n", info
.zorder
);
331 static ssize_t
overlay_zorder_store(struct omap_overlay
*ovl
,
332 const char *buf
, size_t size
)
336 struct omap_overlay_info info
;
338 if ((ovl
->caps
& OMAP_DSS_OVL_CAP_ZORDER
) == 0)
341 r
= kstrtou8(buf
, 0, &zorder
);
345 ovl
->get_overlay_info(ovl
, &info
);
347 info
.zorder
= zorder
;
349 r
= ovl
->set_overlay_info(ovl
, &info
);
354 r
= ovl
->manager
->apply(ovl
->manager
);
362 struct overlay_attribute
{
363 struct attribute attr
;
364 ssize_t (*show
)(struct omap_overlay
*, char *);
365 ssize_t (*store
)(struct omap_overlay
*, const char *, size_t);
368 #define OVERLAY_ATTR(_name, _mode, _show, _store) \
369 struct overlay_attribute overlay_attr_##_name = \
370 __ATTR(_name, _mode, _show, _store)
372 static OVERLAY_ATTR(name
, S_IRUGO
, overlay_name_show
, NULL
);
373 static OVERLAY_ATTR(manager
, S_IRUGO
|S_IWUSR
,
374 overlay_manager_show
, overlay_manager_store
);
375 static OVERLAY_ATTR(input_size
, S_IRUGO
, overlay_input_size_show
, NULL
);
376 static OVERLAY_ATTR(screen_width
, S_IRUGO
, overlay_screen_width_show
, NULL
);
377 static OVERLAY_ATTR(position
, S_IRUGO
|S_IWUSR
,
378 overlay_position_show
, overlay_position_store
);
379 static OVERLAY_ATTR(output_size
, S_IRUGO
|S_IWUSR
,
380 overlay_output_size_show
, overlay_output_size_store
);
381 static OVERLAY_ATTR(enabled
, S_IRUGO
|S_IWUSR
,
382 overlay_enabled_show
, overlay_enabled_store
);
383 static OVERLAY_ATTR(global_alpha
, S_IRUGO
|S_IWUSR
,
384 overlay_global_alpha_show
, overlay_global_alpha_store
);
385 static OVERLAY_ATTR(pre_mult_alpha
, S_IRUGO
|S_IWUSR
,
386 overlay_pre_mult_alpha_show
,
387 overlay_pre_mult_alpha_store
);
388 static OVERLAY_ATTR(zorder
, S_IRUGO
|S_IWUSR
,
389 overlay_zorder_show
, overlay_zorder_store
);
391 static struct attribute
*overlay_sysfs_attrs
[] = {
392 &overlay_attr_name
.attr
,
393 &overlay_attr_manager
.attr
,
394 &overlay_attr_input_size
.attr
,
395 &overlay_attr_screen_width
.attr
,
396 &overlay_attr_position
.attr
,
397 &overlay_attr_output_size
.attr
,
398 &overlay_attr_enabled
.attr
,
399 &overlay_attr_global_alpha
.attr
,
400 &overlay_attr_pre_mult_alpha
.attr
,
401 &overlay_attr_zorder
.attr
,
405 static ssize_t
overlay_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
408 struct omap_overlay
*overlay
;
409 struct overlay_attribute
*overlay_attr
;
411 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
412 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
414 if (!overlay_attr
->show
)
417 return overlay_attr
->show(overlay
, buf
);
420 static ssize_t
overlay_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
421 const char *buf
, size_t size
)
423 struct omap_overlay
*overlay
;
424 struct overlay_attribute
*overlay_attr
;
426 overlay
= container_of(kobj
, struct omap_overlay
, kobj
);
427 overlay_attr
= container_of(attr
, struct overlay_attribute
, attr
);
429 if (!overlay_attr
->store
)
432 return overlay_attr
->store(overlay
, buf
, size
);
435 static const struct sysfs_ops overlay_sysfs_ops
= {
436 .show
= overlay_attr_show
,
437 .store
= overlay_attr_store
,
440 static struct kobj_type overlay_ktype
= {
441 .sysfs_ops
= &overlay_sysfs_ops
,
442 .default_attrs
= overlay_sysfs_attrs
,
445 int dss_overlay_kobj_init(struct omap_overlay
*ovl
,
446 struct platform_device
*pdev
)
448 return kobject_init_and_add(&ovl
->kobj
, &overlay_ktype
,
449 &pdev
->dev
.kobj
, "overlay%d", ovl
->id
);
452 void dss_overlay_kobj_uninit(struct omap_overlay
*ovl
)
454 kobject_del(&ovl
->kobj
);
455 kobject_put(&ovl
->kobj
);