diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2012-08-06 07:40:00 -0400 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2012-09-07 13:02:10 -0400 |
commit | 916915161d6a6995275dd41c580b3c9e16a859df (patch) | |
tree | 4d5d80e19645c664b50c84e0c45c67b302bf91b8 /drivers/video/omap2/dss | |
parent | a6df3fd963e3a0065418621edb30737d11c6662b (diff) |
OMAPDSS: split overlay sysfs code
Separate sysfs code for overlays to a separate file. This is a bit
cleaner, and will allow us later to easily switch off the sysfs support
via Kconfig option.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Diffstat (limited to 'drivers/video/omap2/dss')
-rw-r--r-- | drivers/video/omap2/dss/Makefile | 2 | ||||
-rw-r--r-- | drivers/video/omap2/dss/dss.h | 3 | ||||
-rw-r--r-- | drivers/video/omap2/dss/overlay-sysfs.c | 456 | ||||
-rw-r--r-- | drivers/video/omap2/dss/overlay.c | 420 |
4 files changed, 462 insertions, 419 deletions
diff --git a/drivers/video/omap2/dss/Makefile b/drivers/video/omap2/dss/Makefile index 30a48fba75b0..927d5ce48e75 100644 --- a/drivers/video/omap2/dss/Makefile +++ b/drivers/video/omap2/dss/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | obj-$(CONFIG_OMAP2_DSS) += omapdss.o | 1 | obj-$(CONFIG_OMAP2_DSS) += omapdss.o |
2 | omapdss-y := core.o dss.o dss_features.o dispc.o dispc_coefs.o display.o \ | 2 | omapdss-y := core.o dss.o dss_features.o dispc.o dispc_coefs.o display.o \ |
3 | manager.o overlay.o apply.o | 3 | manager.o overlay.o overlay-sysfs.o apply.o |
4 | omapdss-$(CONFIG_OMAP2_DSS_DPI) += dpi.o | 4 | omapdss-$(CONFIG_OMAP2_DSS_DPI) += dpi.o |
5 | omapdss-$(CONFIG_OMAP2_DSS_RFBI) += rfbi.o | 5 | omapdss-$(CONFIG_OMAP2_DSS_RFBI) += rfbi.o |
6 | omapdss-$(CONFIG_OMAP2_DSS_VENC) += venc.o venc_panel.o | 6 | omapdss-$(CONFIG_OMAP2_DSS_VENC) += venc.o venc_panel.o |
diff --git a/drivers/video/omap2/dss/dss.h b/drivers/video/omap2/dss/dss.h index d6cca820723c..11b053e53867 100644 --- a/drivers/video/omap2/dss/dss.h +++ b/drivers/video/omap2/dss/dss.h | |||
@@ -265,6 +265,9 @@ int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info, | |||
265 | const struct omap_video_timings *mgr_timings); | 265 | const struct omap_video_timings *mgr_timings); |
266 | bool dss_ovl_use_replication(struct dss_lcd_mgr_config config, | 266 | bool dss_ovl_use_replication(struct dss_lcd_mgr_config config, |
267 | enum omap_color_mode mode); | 267 | enum omap_color_mode mode); |
268 | int dss_overlay_kobj_init(struct omap_overlay *ovl, | ||
269 | struct platform_device *pdev); | ||
270 | void dss_overlay_kobj_uninit(struct omap_overlay *ovl); | ||
268 | 271 | ||
269 | /* DSS */ | 272 | /* DSS */ |
270 | int dss_init_platform_driver(void) __init; | 273 | int dss_init_platform_driver(void) __init; |
diff --git a/drivers/video/omap2/dss/overlay-sysfs.c b/drivers/video/omap2/dss/overlay-sysfs.c new file mode 100644 index 000000000000..4cc5ddebfb34 --- /dev/null +++ b/drivers/video/omap2/dss/overlay-sysfs.c | |||
@@ -0,0 +1,456 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009 Nokia Corporation | ||
3 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> | ||
4 | * | ||
5 | * Some code and ideas taken from drivers/video/omap/ driver | ||
6 | * by Imre Deak. | ||
7 | * | ||
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. | ||
11 | * | ||
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 | ||
15 | * more details. | ||
16 | * | ||
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/>. | ||
19 | */ | ||
20 | |||
21 | #define DSS_SUBSYS_NAME "OVERLAY" | ||
22 | |||
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> | ||
28 | |||
29 | #include <video/omapdss.h> | ||
30 | |||
31 | #include "dss.h" | ||
32 | #include "dss_features.h" | ||
33 | |||
34 | static ssize_t overlay_name_show(struct omap_overlay *ovl, char *buf) | ||
35 | { | ||
36 | return snprintf(buf, PAGE_SIZE, "%s\n", ovl->name); | ||
37 | } | ||
38 | |||
39 | static ssize_t overlay_manager_show(struct omap_overlay *ovl, char *buf) | ||
40 | { | ||
41 | return snprintf(buf, PAGE_SIZE, "%s\n", | ||
42 | ovl->manager ? ovl->manager->name : "<none>"); | ||
43 | } | ||
44 | |||
45 | static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, | ||
46 | size_t size) | ||
47 | { | ||
48 | int i, r; | ||
49 | struct omap_overlay_manager *mgr = NULL; | ||
50 | struct omap_overlay_manager *old_mgr; | ||
51 | int len = size; | ||
52 | |||
53 | if (buf[size-1] == '\n') | ||
54 | --len; | ||
55 | |||
56 | if (len > 0) { | ||
57 | for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { | ||
58 | mgr = omap_dss_get_overlay_manager(i); | ||
59 | |||
60 | if (sysfs_streq(buf, mgr->name)) | ||
61 | break; | ||
62 | |||
63 | mgr = NULL; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | if (len > 0 && mgr == NULL) | ||
68 | return -EINVAL; | ||
69 | |||
70 | if (mgr) | ||
71 | DSSDBG("manager %s found\n", mgr->name); | ||
72 | |||
73 | if (mgr == ovl->manager) | ||
74 | return size; | ||
75 | |||
76 | old_mgr = ovl->manager; | ||
77 | |||
78 | r = dispc_runtime_get(); | ||
79 | if (r) | ||
80 | return r; | ||
81 | |||
82 | /* detach old manager */ | ||
83 | if (old_mgr) { | ||
84 | r = ovl->unset_manager(ovl); | ||
85 | if (r) { | ||
86 | DSSERR("detach failed\n"); | ||
87 | goto err; | ||
88 | } | ||
89 | |||
90 | r = old_mgr->apply(old_mgr); | ||
91 | if (r) | ||
92 | goto err; | ||
93 | } | ||
94 | |||
95 | if (mgr) { | ||
96 | r = ovl->set_manager(ovl, mgr); | ||
97 | if (r) { | ||
98 | DSSERR("Failed to attach overlay\n"); | ||
99 | goto err; | ||
100 | } | ||
101 | |||
102 | r = mgr->apply(mgr); | ||
103 | if (r) | ||
104 | goto err; | ||
105 | } | ||
106 | |||
107 | dispc_runtime_put(); | ||
108 | |||
109 | return size; | ||
110 | |||
111 | err: | ||
112 | dispc_runtime_put(); | ||
113 | return r; | ||
114 | } | ||
115 | |||
116 | static ssize_t overlay_input_size_show(struct omap_overlay *ovl, char *buf) | ||
117 | { | ||
118 | struct omap_overlay_info info; | ||
119 | |||
120 | ovl->get_overlay_info(ovl, &info); | ||
121 | |||
122 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", | ||
123 | info.width, info.height); | ||
124 | } | ||
125 | |||
126 | static ssize_t overlay_screen_width_show(struct omap_overlay *ovl, char *buf) | ||
127 | { | ||
128 | struct omap_overlay_info info; | ||
129 | |||
130 | ovl->get_overlay_info(ovl, &info); | ||
131 | |||
132 | return snprintf(buf, PAGE_SIZE, "%d\n", info.screen_width); | ||
133 | } | ||
134 | |||
135 | static ssize_t overlay_position_show(struct omap_overlay *ovl, char *buf) | ||
136 | { | ||
137 | struct omap_overlay_info info; | ||
138 | |||
139 | ovl->get_overlay_info(ovl, &info); | ||
140 | |||
141 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", | ||
142 | info.pos_x, info.pos_y); | ||
143 | } | ||
144 | |||
145 | static ssize_t overlay_position_store(struct omap_overlay *ovl, | ||
146 | const char *buf, size_t size) | ||
147 | { | ||
148 | int r; | ||
149 | char *last; | ||
150 | struct omap_overlay_info info; | ||
151 | |||
152 | ovl->get_overlay_info(ovl, &info); | ||
153 | |||
154 | info.pos_x = simple_strtoul(buf, &last, 10); | ||
155 | ++last; | ||
156 | if (last - buf >= size) | ||
157 | return -EINVAL; | ||
158 | |||
159 | info.pos_y = simple_strtoul(last, &last, 10); | ||
160 | |||
161 | r = ovl->set_overlay_info(ovl, &info); | ||
162 | if (r) | ||
163 | return r; | ||
164 | |||
165 | if (ovl->manager) { | ||
166 | r = ovl->manager->apply(ovl->manager); | ||
167 | if (r) | ||
168 | return r; | ||
169 | } | ||
170 | |||
171 | return size; | ||
172 | } | ||
173 | |||
174 | static ssize_t overlay_output_size_show(struct omap_overlay *ovl, char *buf) | ||
175 | { | ||
176 | struct omap_overlay_info info; | ||
177 | |||
178 | ovl->get_overlay_info(ovl, &info); | ||
179 | |||
180 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", | ||
181 | info.out_width, info.out_height); | ||
182 | } | ||
183 | |||
184 | static ssize_t overlay_output_size_store(struct omap_overlay *ovl, | ||
185 | const char *buf, size_t size) | ||
186 | { | ||
187 | int r; | ||
188 | char *last; | ||
189 | struct omap_overlay_info info; | ||
190 | |||
191 | ovl->get_overlay_info(ovl, &info); | ||
192 | |||
193 | info.out_width = simple_strtoul(buf, &last, 10); | ||
194 | ++last; | ||
195 | if (last - buf >= size) | ||
196 | return -EINVAL; | ||
197 | |||
198 | info.out_height = simple_strtoul(last, &last, 10); | ||
199 | |||
200 | r = ovl->set_overlay_info(ovl, &info); | ||
201 | if (r) | ||
202 | return r; | ||
203 | |||
204 | if (ovl->manager) { | ||
205 | r = ovl->manager->apply(ovl->manager); | ||
206 | if (r) | ||
207 | return r; | ||
208 | } | ||
209 | |||
210 | return size; | ||
211 | } | ||
212 | |||
213 | static ssize_t overlay_enabled_show(struct omap_overlay *ovl, char *buf) | ||
214 | { | ||
215 | return snprintf(buf, PAGE_SIZE, "%d\n", ovl->is_enabled(ovl)); | ||
216 | } | ||
217 | |||
218 | static ssize_t overlay_enabled_store(struct omap_overlay *ovl, const char *buf, | ||
219 | size_t size) | ||
220 | { | ||
221 | int r; | ||
222 | bool enable; | ||
223 | |||
224 | r = strtobool(buf, &enable); | ||
225 | if (r) | ||
226 | return r; | ||
227 | |||
228 | if (enable) | ||
229 | r = ovl->enable(ovl); | ||
230 | else | ||
231 | r = ovl->disable(ovl); | ||
232 | |||
233 | if (r) | ||
234 | return r; | ||
235 | |||
236 | return size; | ||
237 | } | ||
238 | |||
239 | static ssize_t overlay_global_alpha_show(struct omap_overlay *ovl, char *buf) | ||
240 | { | ||
241 | struct omap_overlay_info info; | ||
242 | |||
243 | ovl->get_overlay_info(ovl, &info); | ||
244 | |||
245 | return snprintf(buf, PAGE_SIZE, "%d\n", | ||
246 | info.global_alpha); | ||
247 | } | ||
248 | |||
249 | static ssize_t overlay_global_alpha_store(struct omap_overlay *ovl, | ||
250 | const char *buf, size_t size) | ||
251 | { | ||
252 | int r; | ||
253 | u8 alpha; | ||
254 | struct omap_overlay_info info; | ||
255 | |||
256 | if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0) | ||
257 | return -ENODEV; | ||
258 | |||
259 | r = kstrtou8(buf, 0, &alpha); | ||
260 | if (r) | ||
261 | return r; | ||
262 | |||
263 | ovl->get_overlay_info(ovl, &info); | ||
264 | |||
265 | info.global_alpha = alpha; | ||
266 | |||
267 | r = ovl->set_overlay_info(ovl, &info); | ||
268 | if (r) | ||
269 | return r; | ||
270 | |||
271 | if (ovl->manager) { | ||
272 | r = ovl->manager->apply(ovl->manager); | ||
273 | if (r) | ||
274 | return r; | ||
275 | } | ||
276 | |||
277 | return size; | ||
278 | } | ||
279 | |||
280 | static ssize_t overlay_pre_mult_alpha_show(struct omap_overlay *ovl, | ||
281 | char *buf) | ||
282 | { | ||
283 | struct omap_overlay_info info; | ||
284 | |||
285 | ovl->get_overlay_info(ovl, &info); | ||
286 | |||
287 | return snprintf(buf, PAGE_SIZE, "%d\n", | ||
288 | info.pre_mult_alpha); | ||
289 | } | ||
290 | |||
291 | static ssize_t overlay_pre_mult_alpha_store(struct omap_overlay *ovl, | ||
292 | const char *buf, size_t size) | ||
293 | { | ||
294 | int r; | ||
295 | u8 alpha; | ||
296 | struct omap_overlay_info info; | ||
297 | |||
298 | if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0) | ||
299 | return -ENODEV; | ||
300 | |||
301 | r = kstrtou8(buf, 0, &alpha); | ||
302 | if (r) | ||
303 | return r; | ||
304 | |||
305 | ovl->get_overlay_info(ovl, &info); | ||
306 | |||
307 | info.pre_mult_alpha = alpha; | ||
308 | |||
309 | r = ovl->set_overlay_info(ovl, &info); | ||
310 | if (r) | ||
311 | return r; | ||
312 | |||
313 | if (ovl->manager) { | ||
314 | r = ovl->manager->apply(ovl->manager); | ||
315 | if (r) | ||
316 | return r; | ||
317 | } | ||
318 | |||
319 | return size; | ||
320 | } | ||
321 | |||
322 | static ssize_t overlay_zorder_show(struct omap_overlay *ovl, char *buf) | ||
323 | { | ||
324 | struct omap_overlay_info info; | ||
325 | |||
326 | ovl->get_overlay_info(ovl, &info); | ||
327 | |||
328 | return snprintf(buf, PAGE_SIZE, "%d\n", info.zorder); | ||
329 | } | ||
330 | |||
331 | static ssize_t overlay_zorder_store(struct omap_overlay *ovl, | ||
332 | const char *buf, size_t size) | ||
333 | { | ||
334 | int r; | ||
335 | u8 zorder; | ||
336 | struct omap_overlay_info info; | ||
337 | |||
338 | if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0) | ||
339 | return -ENODEV; | ||
340 | |||
341 | r = kstrtou8(buf, 0, &zorder); | ||
342 | if (r) | ||
343 | return r; | ||
344 | |||
345 | ovl->get_overlay_info(ovl, &info); | ||
346 | |||
347 | info.zorder = zorder; | ||
348 | |||
349 | r = ovl->set_overlay_info(ovl, &info); | ||
350 | if (r) | ||
351 | return r; | ||
352 | |||
353 | if (ovl->manager) { | ||
354 | r = ovl->manager->apply(ovl->manager); | ||
355 | if (r) | ||
356 | return r; | ||
357 | } | ||
358 | |||
359 | return size; | ||
360 | } | ||
361 | |||
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); | ||
366 | }; | ||
367 | |||
368 | #define OVERLAY_ATTR(_name, _mode, _show, _store) \ | ||
369 | struct overlay_attribute overlay_attr_##_name = \ | ||
370 | __ATTR(_name, _mode, _show, _store) | ||
371 | |||
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); | ||
390 | |||
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, | ||
402 | NULL | ||
403 | }; | ||
404 | |||
405 | static ssize_t overlay_attr_show(struct kobject *kobj, struct attribute *attr, | ||
406 | char *buf) | ||
407 | { | ||
408 | struct omap_overlay *overlay; | ||
409 | struct overlay_attribute *overlay_attr; | ||
410 | |||
411 | overlay = container_of(kobj, struct omap_overlay, kobj); | ||
412 | overlay_attr = container_of(attr, struct overlay_attribute, attr); | ||
413 | |||
414 | if (!overlay_attr->show) | ||
415 | return -ENOENT; | ||
416 | |||
417 | return overlay_attr->show(overlay, buf); | ||
418 | } | ||
419 | |||
420 | static ssize_t overlay_attr_store(struct kobject *kobj, struct attribute *attr, | ||
421 | const char *buf, size_t size) | ||
422 | { | ||
423 | struct omap_overlay *overlay; | ||
424 | struct overlay_attribute *overlay_attr; | ||
425 | |||
426 | overlay = container_of(kobj, struct omap_overlay, kobj); | ||
427 | overlay_attr = container_of(attr, struct overlay_attribute, attr); | ||
428 | |||
429 | if (!overlay_attr->store) | ||
430 | return -ENOENT; | ||
431 | |||
432 | return overlay_attr->store(overlay, buf, size); | ||
433 | } | ||
434 | |||
435 | static const struct sysfs_ops overlay_sysfs_ops = { | ||
436 | .show = overlay_attr_show, | ||
437 | .store = overlay_attr_store, | ||
438 | }; | ||
439 | |||
440 | static struct kobj_type overlay_ktype = { | ||
441 | .sysfs_ops = &overlay_sysfs_ops, | ||
442 | .default_attrs = overlay_sysfs_attrs, | ||
443 | }; | ||
444 | |||
445 | int dss_overlay_kobj_init(struct omap_overlay *ovl, | ||
446 | struct platform_device *pdev) | ||
447 | { | ||
448 | return kobject_init_and_add(&ovl->kobj, &overlay_ktype, | ||
449 | &pdev->dev.kobj, "overlay%d", ovl->id); | ||
450 | } | ||
451 | |||
452 | void dss_overlay_kobj_uninit(struct omap_overlay *ovl) | ||
453 | { | ||
454 | kobject_del(&ovl->kobj); | ||
455 | kobject_put(&ovl->kobj); | ||
456 | } | ||
diff --git a/drivers/video/omap2/dss/overlay.c b/drivers/video/omap2/dss/overlay.c index 94e74be0788d..e3d406875afd 100644 --- a/drivers/video/omap2/dss/overlay.c +++ b/drivers/video/omap2/dss/overlay.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/err.h> | 27 | #include <linux/err.h> |
28 | #include <linux/sysfs.h> | 28 | #include <linux/sysfs.h> |
29 | #include <linux/kobject.h> | ||
30 | #include <linux/platform_device.h> | 29 | #include <linux/platform_device.h> |
31 | #include <linux/delay.h> | 30 | #include <linux/delay.h> |
32 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
@@ -39,417 +38,6 @@ | |||
39 | static int num_overlays; | 38 | static int num_overlays; |
40 | static struct omap_overlay *overlays; | 39 | static struct omap_overlay *overlays; |
41 | 40 | ||
42 | static ssize_t overlay_name_show(struct omap_overlay *ovl, char *buf) | ||
43 | { | ||
44 | return snprintf(buf, PAGE_SIZE, "%s\n", ovl->name); | ||
45 | } | ||
46 | |||
47 | static ssize_t overlay_manager_show(struct omap_overlay *ovl, char *buf) | ||
48 | { | ||
49 | return snprintf(buf, PAGE_SIZE, "%s\n", | ||
50 | ovl->manager ? ovl->manager->name : "<none>"); | ||
51 | } | ||
52 | |||
53 | static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf, | ||
54 | size_t size) | ||
55 | { | ||
56 | int i, r; | ||
57 | struct omap_overlay_manager *mgr = NULL; | ||
58 | struct omap_overlay_manager *old_mgr; | ||
59 | int len = size; | ||
60 | |||
61 | if (buf[size-1] == '\n') | ||
62 | --len; | ||
63 | |||
64 | if (len > 0) { | ||
65 | for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { | ||
66 | mgr = omap_dss_get_overlay_manager(i); | ||
67 | |||
68 | if (sysfs_streq(buf, mgr->name)) | ||
69 | break; | ||
70 | |||
71 | mgr = NULL; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | if (len > 0 && mgr == NULL) | ||
76 | return -EINVAL; | ||
77 | |||
78 | if (mgr) | ||
79 | DSSDBG("manager %s found\n", mgr->name); | ||
80 | |||
81 | if (mgr == ovl->manager) | ||
82 | return size; | ||
83 | |||
84 | old_mgr = ovl->manager; | ||
85 | |||
86 | r = dispc_runtime_get(); | ||
87 | if (r) | ||
88 | return r; | ||
89 | |||
90 | /* detach old manager */ | ||
91 | if (old_mgr) { | ||
92 | r = ovl->unset_manager(ovl); | ||
93 | if (r) { | ||
94 | DSSERR("detach failed\n"); | ||
95 | goto err; | ||
96 | } | ||
97 | |||
98 | r = old_mgr->apply(old_mgr); | ||
99 | if (r) | ||
100 | goto err; | ||
101 | } | ||
102 | |||
103 | if (mgr) { | ||
104 | r = ovl->set_manager(ovl, mgr); | ||
105 | if (r) { | ||
106 | DSSERR("Failed to attach overlay\n"); | ||
107 | goto err; | ||
108 | } | ||
109 | |||
110 | r = mgr->apply(mgr); | ||
111 | if (r) | ||
112 | goto err; | ||
113 | } | ||
114 | |||
115 | dispc_runtime_put(); | ||
116 | |||
117 | return size; | ||
118 | |||
119 | err: | ||
120 | dispc_runtime_put(); | ||
121 | return r; | ||
122 | } | ||
123 | |||
124 | static ssize_t overlay_input_size_show(struct omap_overlay *ovl, char *buf) | ||
125 | { | ||
126 | struct omap_overlay_info info; | ||
127 | |||
128 | ovl->get_overlay_info(ovl, &info); | ||
129 | |||
130 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", | ||
131 | info.width, info.height); | ||
132 | } | ||
133 | |||
134 | static ssize_t overlay_screen_width_show(struct omap_overlay *ovl, char *buf) | ||
135 | { | ||
136 | struct omap_overlay_info info; | ||
137 | |||
138 | ovl->get_overlay_info(ovl, &info); | ||
139 | |||
140 | return snprintf(buf, PAGE_SIZE, "%d\n", info.screen_width); | ||
141 | } | ||
142 | |||
143 | static ssize_t overlay_position_show(struct omap_overlay *ovl, char *buf) | ||
144 | { | ||
145 | struct omap_overlay_info info; | ||
146 | |||
147 | ovl->get_overlay_info(ovl, &info); | ||
148 | |||
149 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", | ||
150 | info.pos_x, info.pos_y); | ||
151 | } | ||
152 | |||
153 | static ssize_t overlay_position_store(struct omap_overlay *ovl, | ||
154 | const char *buf, size_t size) | ||
155 | { | ||
156 | int r; | ||
157 | char *last; | ||
158 | struct omap_overlay_info info; | ||
159 | |||
160 | ovl->get_overlay_info(ovl, &info); | ||
161 | |||
162 | info.pos_x = simple_strtoul(buf, &last, 10); | ||
163 | ++last; | ||
164 | if (last - buf >= size) | ||
165 | return -EINVAL; | ||
166 | |||
167 | info.pos_y = simple_strtoul(last, &last, 10); | ||
168 | |||
169 | r = ovl->set_overlay_info(ovl, &info); | ||
170 | if (r) | ||
171 | return r; | ||
172 | |||
173 | if (ovl->manager) { | ||
174 | r = ovl->manager->apply(ovl->manager); | ||
175 | if (r) | ||
176 | return r; | ||
177 | } | ||
178 | |||
179 | return size; | ||
180 | } | ||
181 | |||
182 | static ssize_t overlay_output_size_show(struct omap_overlay *ovl, char *buf) | ||
183 | { | ||
184 | struct omap_overlay_info info; | ||
185 | |||
186 | ovl->get_overlay_info(ovl, &info); | ||
187 | |||
188 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", | ||
189 | info.out_width, info.out_height); | ||
190 | } | ||
191 | |||
192 | static ssize_t overlay_output_size_store(struct omap_overlay *ovl, | ||
193 | const char *buf, size_t size) | ||
194 | { | ||
195 | int r; | ||
196 | char *last; | ||
197 | struct omap_overlay_info info; | ||
198 | |||
199 | ovl->get_overlay_info(ovl, &info); | ||
200 | |||
201 | info.out_width = simple_strtoul(buf, &last, 10); | ||
202 | ++last; | ||
203 | if (last - buf >= size) | ||
204 | return -EINVAL; | ||
205 | |||
206 | info.out_height = simple_strtoul(last, &last, 10); | ||
207 | |||
208 | r = ovl->set_overlay_info(ovl, &info); | ||
209 | if (r) | ||
210 | return r; | ||
211 | |||
212 | if (ovl->manager) { | ||
213 | r = ovl->manager->apply(ovl->manager); | ||
214 | if (r) | ||
215 | return r; | ||
216 | } | ||
217 | |||
218 | return size; | ||
219 | } | ||
220 | |||
221 | static ssize_t overlay_enabled_show(struct omap_overlay *ovl, char *buf) | ||
222 | { | ||
223 | return snprintf(buf, PAGE_SIZE, "%d\n", ovl->is_enabled(ovl)); | ||
224 | } | ||
225 | |||
226 | static ssize_t overlay_enabled_store(struct omap_overlay *ovl, const char *buf, | ||
227 | size_t size) | ||
228 | { | ||
229 | int r; | ||
230 | bool enable; | ||
231 | |||
232 | r = strtobool(buf, &enable); | ||
233 | if (r) | ||
234 | return r; | ||
235 | |||
236 | if (enable) | ||
237 | r = ovl->enable(ovl); | ||
238 | else | ||
239 | r = ovl->disable(ovl); | ||
240 | |||
241 | if (r) | ||
242 | return r; | ||
243 | |||
244 | return size; | ||
245 | } | ||
246 | |||
247 | static ssize_t overlay_global_alpha_show(struct omap_overlay *ovl, char *buf) | ||
248 | { | ||
249 | struct omap_overlay_info info; | ||
250 | |||
251 | ovl->get_overlay_info(ovl, &info); | ||
252 | |||
253 | return snprintf(buf, PAGE_SIZE, "%d\n", | ||
254 | info.global_alpha); | ||
255 | } | ||
256 | |||
257 | static ssize_t overlay_global_alpha_store(struct omap_overlay *ovl, | ||
258 | const char *buf, size_t size) | ||
259 | { | ||
260 | int r; | ||
261 | u8 alpha; | ||
262 | struct omap_overlay_info info; | ||
263 | |||
264 | if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0) | ||
265 | return -ENODEV; | ||
266 | |||
267 | r = kstrtou8(buf, 0, &alpha); | ||
268 | if (r) | ||
269 | return r; | ||
270 | |||
271 | ovl->get_overlay_info(ovl, &info); | ||
272 | |||
273 | info.global_alpha = alpha; | ||
274 | |||
275 | r = ovl->set_overlay_info(ovl, &info); | ||
276 | if (r) | ||
277 | return r; | ||
278 | |||
279 | if (ovl->manager) { | ||
280 | r = ovl->manager->apply(ovl->manager); | ||
281 | if (r) | ||
282 | return r; | ||
283 | } | ||
284 | |||
285 | return size; | ||
286 | } | ||
287 | |||
288 | static ssize_t overlay_pre_mult_alpha_show(struct omap_overlay *ovl, | ||
289 | char *buf) | ||
290 | { | ||
291 | struct omap_overlay_info info; | ||
292 | |||
293 | ovl->get_overlay_info(ovl, &info); | ||
294 | |||
295 | return snprintf(buf, PAGE_SIZE, "%d\n", | ||
296 | info.pre_mult_alpha); | ||
297 | } | ||
298 | |||
299 | static ssize_t overlay_pre_mult_alpha_store(struct omap_overlay *ovl, | ||
300 | const char *buf, size_t size) | ||
301 | { | ||
302 | int r; | ||
303 | u8 alpha; | ||
304 | struct omap_overlay_info info; | ||
305 | |||
306 | if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0) | ||
307 | return -ENODEV; | ||
308 | |||
309 | r = kstrtou8(buf, 0, &alpha); | ||
310 | if (r) | ||
311 | return r; | ||
312 | |||
313 | ovl->get_overlay_info(ovl, &info); | ||
314 | |||
315 | info.pre_mult_alpha = alpha; | ||
316 | |||
317 | r = ovl->set_overlay_info(ovl, &info); | ||
318 | if (r) | ||
319 | return r; | ||
320 | |||
321 | if (ovl->manager) { | ||
322 | r = ovl->manager->apply(ovl->manager); | ||
323 | if (r) | ||
324 | return r; | ||
325 | } | ||
326 | |||
327 | return size; | ||
328 | } | ||
329 | |||
330 | static ssize_t overlay_zorder_show(struct omap_overlay *ovl, char *buf) | ||
331 | { | ||
332 | struct omap_overlay_info info; | ||
333 | |||
334 | ovl->get_overlay_info(ovl, &info); | ||
335 | |||
336 | return snprintf(buf, PAGE_SIZE, "%d\n", info.zorder); | ||
337 | } | ||
338 | |||
339 | static ssize_t overlay_zorder_store(struct omap_overlay *ovl, | ||
340 | const char *buf, size_t size) | ||
341 | { | ||
342 | int r; | ||
343 | u8 zorder; | ||
344 | struct omap_overlay_info info; | ||
345 | |||
346 | if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0) | ||
347 | return -ENODEV; | ||
348 | |||
349 | r = kstrtou8(buf, 0, &zorder); | ||
350 | if (r) | ||
351 | return r; | ||
352 | |||
353 | ovl->get_overlay_info(ovl, &info); | ||
354 | |||
355 | info.zorder = zorder; | ||
356 | |||
357 | r = ovl->set_overlay_info(ovl, &info); | ||
358 | if (r) | ||
359 | return r; | ||
360 | |||
361 | if (ovl->manager) { | ||
362 | r = ovl->manager->apply(ovl->manager); | ||
363 | if (r) | ||
364 | return r; | ||
365 | } | ||
366 | |||
367 | return size; | ||
368 | } | ||
369 | |||
370 | struct overlay_attribute { | ||
371 | struct attribute attr; | ||
372 | ssize_t (*show)(struct omap_overlay *, char *); | ||
373 | ssize_t (*store)(struct omap_overlay *, const char *, size_t); | ||
374 | }; | ||
375 | |||
376 | #define OVERLAY_ATTR(_name, _mode, _show, _store) \ | ||
377 | struct overlay_attribute overlay_attr_##_name = \ | ||
378 | __ATTR(_name, _mode, _show, _store) | ||
379 | |||
380 | static OVERLAY_ATTR(name, S_IRUGO, overlay_name_show, NULL); | ||
381 | static OVERLAY_ATTR(manager, S_IRUGO|S_IWUSR, | ||
382 | overlay_manager_show, overlay_manager_store); | ||
383 | static OVERLAY_ATTR(input_size, S_IRUGO, overlay_input_size_show, NULL); | ||
384 | static OVERLAY_ATTR(screen_width, S_IRUGO, overlay_screen_width_show, NULL); | ||
385 | static OVERLAY_ATTR(position, S_IRUGO|S_IWUSR, | ||
386 | overlay_position_show, overlay_position_store); | ||
387 | static OVERLAY_ATTR(output_size, S_IRUGO|S_IWUSR, | ||
388 | overlay_output_size_show, overlay_output_size_store); | ||
389 | static OVERLAY_ATTR(enabled, S_IRUGO|S_IWUSR, | ||
390 | overlay_enabled_show, overlay_enabled_store); | ||
391 | static OVERLAY_ATTR(global_alpha, S_IRUGO|S_IWUSR, | ||
392 | overlay_global_alpha_show, overlay_global_alpha_store); | ||
393 | static OVERLAY_ATTR(pre_mult_alpha, S_IRUGO|S_IWUSR, | ||
394 | overlay_pre_mult_alpha_show, | ||
395 | overlay_pre_mult_alpha_store); | ||
396 | static OVERLAY_ATTR(zorder, S_IRUGO|S_IWUSR, | ||
397 | overlay_zorder_show, overlay_zorder_store); | ||
398 | |||
399 | static struct attribute *overlay_sysfs_attrs[] = { | ||
400 | &overlay_attr_name.attr, | ||
401 | &overlay_attr_manager.attr, | ||
402 | &overlay_attr_input_size.attr, | ||
403 | &overlay_attr_screen_width.attr, | ||
404 | &overlay_attr_position.attr, | ||
405 | &overlay_attr_output_size.attr, | ||
406 | &overlay_attr_enabled.attr, | ||
407 | &overlay_attr_global_alpha.attr, | ||
408 | &overlay_attr_pre_mult_alpha.attr, | ||
409 | &overlay_attr_zorder.attr, | ||
410 | NULL | ||
411 | }; | ||
412 | |||
413 | static ssize_t overlay_attr_show(struct kobject *kobj, struct attribute *attr, | ||
414 | char *buf) | ||
415 | { | ||
416 | struct omap_overlay *overlay; | ||
417 | struct overlay_attribute *overlay_attr; | ||
418 | |||
419 | overlay = container_of(kobj, struct omap_overlay, kobj); | ||
420 | overlay_attr = container_of(attr, struct overlay_attribute, attr); | ||
421 | |||
422 | if (!overlay_attr->show) | ||
423 | return -ENOENT; | ||
424 | |||
425 | return overlay_attr->show(overlay, buf); | ||
426 | } | ||
427 | |||
428 | static ssize_t overlay_attr_store(struct kobject *kobj, struct attribute *attr, | ||
429 | const char *buf, size_t size) | ||
430 | { | ||
431 | struct omap_overlay *overlay; | ||
432 | struct overlay_attribute *overlay_attr; | ||
433 | |||
434 | overlay = container_of(kobj, struct omap_overlay, kobj); | ||
435 | overlay_attr = container_of(attr, struct overlay_attribute, attr); | ||
436 | |||
437 | if (!overlay_attr->store) | ||
438 | return -ENOENT; | ||
439 | |||
440 | return overlay_attr->store(overlay, buf, size); | ||
441 | } | ||
442 | |||
443 | static const struct sysfs_ops overlay_sysfs_ops = { | ||
444 | .show = overlay_attr_show, | ||
445 | .store = overlay_attr_store, | ||
446 | }; | ||
447 | |||
448 | static struct kobj_type overlay_ktype = { | ||
449 | .sysfs_ops = &overlay_sysfs_ops, | ||
450 | .default_attrs = overlay_sysfs_attrs, | ||
451 | }; | ||
452 | |||
453 | int omap_dss_get_num_overlays(void) | 41 | int omap_dss_get_num_overlays(void) |
454 | { | 42 | { |
455 | return num_overlays; | 43 | return num_overlays; |
@@ -511,9 +99,7 @@ void dss_init_overlays(struct platform_device *pdev) | |||
511 | ovl->supported_modes = | 99 | ovl->supported_modes = |
512 | dss_feat_get_supported_color_modes(ovl->id); | 100 | dss_feat_get_supported_color_modes(ovl->id); |
513 | 101 | ||
514 | r = kobject_init_and_add(&ovl->kobj, &overlay_ktype, | 102 | r = dss_overlay_kobj_init(ovl, pdev); |
515 | &pdev->dev.kobj, "overlay%d", i); | ||
516 | |||
517 | if (r) | 103 | if (r) |
518 | DSSERR("failed to create sysfs file\n"); | 104 | DSSERR("failed to create sysfs file\n"); |
519 | } | 105 | } |
@@ -594,9 +180,7 @@ void dss_uninit_overlays(struct platform_device *pdev) | |||
594 | 180 | ||
595 | for (i = 0; i < num_overlays; ++i) { | 181 | for (i = 0; i < num_overlays; ++i) { |
596 | struct omap_overlay *ovl = &overlays[i]; | 182 | struct omap_overlay *ovl = &overlays[i]; |
597 | 183 | dss_overlay_kobj_uninit(ovl); | |
598 | kobject_del(&ovl->kobj); | ||
599 | kobject_put(&ovl->kobj); | ||
600 | } | 184 | } |
601 | 185 | ||
602 | kfree(overlays); | 186 | kfree(overlays); |