Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / video / fbdev / omap2 / omapfb / dss / manager-sysfs.c
blobb52cc1af095938eea283cfbf7fc70e3dd12fd3a4
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
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
7 * by Imre Deak.
8 */
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>
20 #include "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)
46 int r = 0;
47 size_t len = size;
48 struct omap_dss_device *dssdev = NULL;
49 struct omap_dss_device *old_dssdev;
51 if (buf[size-1] == '\n')
52 --len;
54 if (len > 0)
55 dssdev = omap_dss_find_device((void *)buf,
56 manager_display_match);
58 if (len > 0 && dssdev == NULL)
59 return -EINVAL;
61 if (dssdev) {
62 DSSDBG("display %s found\n", dssdev->name);
64 if (omapdss_device_is_connected(dssdev)) {
65 DSSERR("new display is already connected\n");
66 r = -EINVAL;
67 goto put_device;
70 if (omapdss_device_is_enabled(dssdev)) {
71 DSSERR("new display is not disabled\n");
72 r = -EINVAL;
73 goto put_device;
77 old_dssdev = mgr->get_device(mgr);
78 if (old_dssdev) {
79 if (omapdss_device_is_enabled(old_dssdev)) {
80 DSSERR("old display is not disabled\n");
81 r = -EINVAL;
82 goto put_device;
85 old_dssdev->driver->disconnect(old_dssdev);
88 if (dssdev) {
89 r = dssdev->driver->connect(dssdev);
90 if (r) {
91 DSSERR("failed to connect new device\n");
92 goto put_device;
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);
99 goto put_device;
102 r = mgr->apply(mgr);
103 if (r) {
104 DSSERR("failed to apply dispc config\n");
105 goto put_device;
109 put_device:
110 if (dssdev)
111 omap_dss_put_device(dssdev);
113 return r ? r : size;
116 static ssize_t manager_default_color_show(struct omap_overlay_manager *mgr,
117 char *buf)
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;
130 u32 color;
131 int r;
133 r = kstrtouint(buf, 0, &color);
134 if (r)
135 return r;
137 mgr->get_manager_info(mgr, &info);
139 info.default_color = color;
141 r = mgr->set_manager_info(mgr, &info);
142 if (r)
143 return r;
145 r = mgr->apply(mgr);
146 if (r)
147 return r;
149 return size;
152 static const char *trans_key_type_str[] = {
153 "gfx-destination",
154 "video-source",
157 static ssize_t manager_trans_key_type_show(struct omap_overlay_manager *mgr,
158 char *buf)
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;
175 int r;
177 r = sysfs_match_string(trans_key_type_str, buf);
178 if (r < 0)
179 return r;
181 mgr->get_manager_info(mgr, &info);
183 info.trans_key_type = r;
185 r = mgr->set_manager_info(mgr, &info);
186 if (r)
187 return r;
189 r = mgr->apply(mgr);
190 if (r)
191 return r;
193 return size;
196 static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
197 char *buf)
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;
210 u32 key_value;
211 int r;
213 r = kstrtouint(buf, 0, &key_value);
214 if (r)
215 return r;
217 mgr->get_manager_info(mgr, &info);
219 info.trans_key = key_value;
221 r = mgr->set_manager_info(mgr, &info);
222 if (r)
223 return r;
225 r = mgr->apply(mgr);
226 if (r)
227 return r;
229 return size;
232 static ssize_t manager_trans_key_enabled_show(struct omap_overlay_manager *mgr,
233 char *buf)
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;
246 bool enable;
247 int r;
249 r = strtobool(buf, &enable);
250 if (r)
251 return r;
253 mgr->get_manager_info(mgr, &info);
255 info.trans_enabled = enable;
257 r = mgr->set_manager_info(mgr, &info);
258 if (r)
259 return r;
261 r = mgr->apply(mgr);
262 if (r)
263 return r;
265 return size;
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))
274 return -ENODEV;
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;
287 bool enable;
288 int r;
290 if(!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER))
291 return -ENODEV;
293 r = strtobool(buf, &enable);
294 if (r)
295 return r;
297 mgr->get_manager_info(mgr, &info);
299 info.partial_alpha_enabled = enable;
301 r = mgr->set_manager_info(mgr, &info);
302 if (r)
303 return r;
305 r = mgr->apply(mgr);
306 if (r)
307 return r;
309 return size;
312 static ssize_t manager_cpr_enable_show(struct omap_overlay_manager *mgr,
313 char *buf)
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;
326 int r;
327 bool enable;
329 if (!dss_has_feature(FEAT_CPR))
330 return -ENODEV;
332 r = strtobool(buf, &enable);
333 if (r)
334 return r;
336 mgr->get_manager_info(mgr, &info);
338 if (info.cpr_enable == enable)
339 return size;
341 info.cpr_enable = enable;
343 r = mgr->set_manager_info(mgr, &info);
344 if (r)
345 return r;
347 r = mgr->apply(mgr);
348 if (r)
349 return r;
351 return size;
354 static ssize_t manager_cpr_coef_show(struct omap_overlay_manager *mgr,
355 char *buf)
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",
363 info.cpr_coefs.rr,
364 info.cpr_coefs.rg,
365 info.cpr_coefs.rb,
366 info.cpr_coefs.gr,
367 info.cpr_coefs.gg,
368 info.cpr_coefs.gb,
369 info.cpr_coefs.br,
370 info.cpr_coefs.bg,
371 info.cpr_coefs.bb);
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;
379 int r, i;
380 s16 *arr;
382 if (!dss_has_feature(FEAT_CPR))
383 return -ENODEV;
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)
389 return -EINVAL;
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)
397 return -EINVAL;
400 mgr->get_manager_info(mgr, &info);
402 info.cpr_coefs = coefs;
404 r = mgr->set_manager_info(mgr, &info);
405 if (r)
406 return r;
408 r = mgr->apply(mgr);
409 if (r)
410 return r;
412 return size;
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,
458 NULL
461 static ssize_t manager_attr_show(struct kobject *kobj, struct attribute *attr,
462 char *buf)
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)
471 return -ENOENT;
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)
486 return -ENOENT;
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));