IPVS: fix netns if reading ip_vs_* procfs entries
[linux-2.6/linux-mips.git] / drivers / video / omap2 / dss / overlay.c
blobf1aca6d0401117c9858a4300b5dfe0748a7863e4
1 /*
2 * linux/drivers/video/omap2/dss/overlay.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
23 #define DSS_SUBSYS_NAME "OVERLAY"
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/err.h>
28 #include <linux/sysfs.h>
29 #include <linux/kobject.h>
30 #include <linux/platform_device.h>
31 #include <linux/delay.h>
32 #include <linux/slab.h>
34 #include <plat/display.h>
35 #include <plat/cpu.h>
37 #include "dss.h"
38 #include "dss_features.h"
40 static int num_overlays;
41 static struct list_head overlay_list;
43 static ssize_t overlay_name_show(struct omap_overlay *ovl, char *buf)
45 return snprintf(buf, PAGE_SIZE, "%s\n", ovl->name);
48 static ssize_t overlay_manager_show(struct omap_overlay *ovl, char *buf)
50 return snprintf(buf, PAGE_SIZE, "%s\n",
51 ovl->manager ? ovl->manager->name : "<none>");
54 static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf,
55 size_t size)
57 int i, r;
58 struct omap_overlay_manager *mgr = NULL;
59 struct omap_overlay_manager *old_mgr;
60 int len = size;
62 if (buf[size-1] == '\n')
63 --len;
65 if (len > 0) {
66 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
67 mgr = omap_dss_get_overlay_manager(i);
69 if (sysfs_streq(buf, mgr->name))
70 break;
72 mgr = NULL;
76 if (len > 0 && mgr == NULL)
77 return -EINVAL;
79 if (mgr)
80 DSSDBG("manager %s found\n", mgr->name);
82 if (mgr == ovl->manager)
83 return size;
85 old_mgr = ovl->manager;
87 /* detach old manager */
88 if (old_mgr) {
89 r = ovl->unset_manager(ovl);
90 if (r) {
91 DSSERR("detach failed\n");
92 return r;
95 r = old_mgr->apply(old_mgr);
96 if (r)
97 return r;
100 if (mgr) {
101 r = ovl->set_manager(ovl, mgr);
102 if (r) {
103 DSSERR("Failed to attach overlay\n");
104 return r;
107 r = mgr->apply(mgr);
108 if (r)
109 return r;
112 return size;
115 static ssize_t overlay_input_size_show(struct omap_overlay *ovl, char *buf)
117 return snprintf(buf, PAGE_SIZE, "%d,%d\n",
118 ovl->info.width, ovl->info.height);
121 static ssize_t overlay_screen_width_show(struct omap_overlay *ovl, char *buf)
123 return snprintf(buf, PAGE_SIZE, "%d\n", ovl->info.screen_width);
126 static ssize_t overlay_position_show(struct omap_overlay *ovl, char *buf)
128 return snprintf(buf, PAGE_SIZE, "%d,%d\n",
129 ovl->info.pos_x, ovl->info.pos_y);
132 static ssize_t overlay_position_store(struct omap_overlay *ovl,
133 const char *buf, size_t size)
135 int r;
136 char *last;
137 struct omap_overlay_info info;
139 ovl->get_overlay_info(ovl, &info);
141 info.pos_x = simple_strtoul(buf, &last, 10);
142 ++last;
143 if (last - buf >= size)
144 return -EINVAL;
146 info.pos_y = simple_strtoul(last, &last, 10);
148 r = ovl->set_overlay_info(ovl, &info);
149 if (r)
150 return r;
152 if (ovl->manager) {
153 r = ovl->manager->apply(ovl->manager);
154 if (r)
155 return r;
158 return size;
161 static ssize_t overlay_output_size_show(struct omap_overlay *ovl, char *buf)
163 return snprintf(buf, PAGE_SIZE, "%d,%d\n",
164 ovl->info.out_width, ovl->info.out_height);
167 static ssize_t overlay_output_size_store(struct omap_overlay *ovl,
168 const char *buf, size_t size)
170 int r;
171 char *last;
172 struct omap_overlay_info info;
174 ovl->get_overlay_info(ovl, &info);
176 info.out_width = simple_strtoul(buf, &last, 10);
177 ++last;
178 if (last - buf >= size)
179 return -EINVAL;
181 info.out_height = simple_strtoul(last, &last, 10);
183 r = ovl->set_overlay_info(ovl, &info);
184 if (r)
185 return r;
187 if (ovl->manager) {
188 r = ovl->manager->apply(ovl->manager);
189 if (r)
190 return r;
193 return size;
196 static ssize_t overlay_enabled_show(struct omap_overlay *ovl, char *buf)
198 return snprintf(buf, PAGE_SIZE, "%d\n", ovl->info.enabled);
201 static ssize_t overlay_enabled_store(struct omap_overlay *ovl, const char *buf,
202 size_t size)
204 int r;
205 struct omap_overlay_info info;
207 ovl->get_overlay_info(ovl, &info);
209 info.enabled = simple_strtoul(buf, NULL, 10);
211 r = ovl->set_overlay_info(ovl, &info);
212 if (r)
213 return r;
215 if (ovl->manager) {
216 r = ovl->manager->apply(ovl->manager);
217 if (r)
218 return r;
221 return size;
224 static ssize_t overlay_global_alpha_show(struct omap_overlay *ovl, char *buf)
226 return snprintf(buf, PAGE_SIZE, "%d\n",
227 ovl->info.global_alpha);
230 static ssize_t overlay_global_alpha_store(struct omap_overlay *ovl,
231 const char *buf, size_t size)
233 int r;
234 struct omap_overlay_info info;
236 ovl->get_overlay_info(ovl, &info);
238 /* Video1 plane does not support global alpha
239 * to always make it 255 completely opaque
241 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
242 ovl->id == OMAP_DSS_VIDEO1)
243 info.global_alpha = 255;
244 else
245 info.global_alpha = simple_strtoul(buf, NULL, 10);
247 r = ovl->set_overlay_info(ovl, &info);
248 if (r)
249 return r;
251 if (ovl->manager) {
252 r = ovl->manager->apply(ovl->manager);
253 if (r)
254 return r;
257 return size;
260 static ssize_t overlay_pre_mult_alpha_show(struct omap_overlay *ovl,
261 char *buf)
263 return snprintf(buf, PAGE_SIZE, "%d\n",
264 ovl->info.pre_mult_alpha);
267 static ssize_t overlay_pre_mult_alpha_store(struct omap_overlay *ovl,
268 const char *buf, size_t size)
270 int r;
271 struct omap_overlay_info info;
273 ovl->get_overlay_info(ovl, &info);
275 /* only GFX and Video2 plane support pre alpha multiplied
276 * set zero for Video1 plane
278 if (!dss_has_feature(FEAT_GLOBAL_ALPHA_VID1) &&
279 ovl->id == OMAP_DSS_VIDEO1)
280 info.pre_mult_alpha = 0;
281 else
282 info.pre_mult_alpha = simple_strtoul(buf, NULL, 10);
284 r = ovl->set_overlay_info(ovl, &info);
285 if (r)
286 return r;
288 if (ovl->manager) {
289 r = ovl->manager->apply(ovl->manager);
290 if (r)
291 return r;
294 return size;
297 struct overlay_attribute {
298 struct attribute attr;
299 ssize_t (*show)(struct omap_overlay *, char *);
300 ssize_t (*store)(struct omap_overlay *, const char *, size_t);
303 #define OVERLAY_ATTR(_name, _mode, _show, _store) \
304 struct overlay_attribute overlay_attr_##_name = \
305 __ATTR(_name, _mode, _show, _store)
307 static OVERLAY_ATTR(name, S_IRUGO, overlay_name_show, NULL);
308 static OVERLAY_ATTR(manager, S_IRUGO|S_IWUSR,
309 overlay_manager_show, overlay_manager_store);
310 static OVERLAY_ATTR(input_size, S_IRUGO, overlay_input_size_show, NULL);
311 static OVERLAY_ATTR(screen_width, S_IRUGO, overlay_screen_width_show, NULL);
312 static OVERLAY_ATTR(position, S_IRUGO|S_IWUSR,
313 overlay_position_show, overlay_position_store);
314 static OVERLAY_ATTR(output_size, S_IRUGO|S_IWUSR,
315 overlay_output_size_show, overlay_output_size_store);
316 static OVERLAY_ATTR(enabled, S_IRUGO|S_IWUSR,
317 overlay_enabled_show, overlay_enabled_store);
318 static OVERLAY_ATTR(global_alpha, S_IRUGO|S_IWUSR,
319 overlay_global_alpha_show, overlay_global_alpha_store);
320 static OVERLAY_ATTR(pre_mult_alpha, S_IRUGO|S_IWUSR,
321 overlay_pre_mult_alpha_show,
322 overlay_pre_mult_alpha_store);
324 static struct attribute *overlay_sysfs_attrs[] = {
325 &overlay_attr_name.attr,
326 &overlay_attr_manager.attr,
327 &overlay_attr_input_size.attr,
328 &overlay_attr_screen_width.attr,
329 &overlay_attr_position.attr,
330 &overlay_attr_output_size.attr,
331 &overlay_attr_enabled.attr,
332 &overlay_attr_global_alpha.attr,
333 &overlay_attr_pre_mult_alpha.attr,
334 NULL
337 static ssize_t overlay_attr_show(struct kobject *kobj, struct attribute *attr,
338 char *buf)
340 struct omap_overlay *overlay;
341 struct overlay_attribute *overlay_attr;
343 overlay = container_of(kobj, struct omap_overlay, kobj);
344 overlay_attr = container_of(attr, struct overlay_attribute, attr);
346 if (!overlay_attr->show)
347 return -ENOENT;
349 return overlay_attr->show(overlay, buf);
352 static ssize_t overlay_attr_store(struct kobject *kobj, struct attribute *attr,
353 const char *buf, size_t size)
355 struct omap_overlay *overlay;
356 struct overlay_attribute *overlay_attr;
358 overlay = container_of(kobj, struct omap_overlay, kobj);
359 overlay_attr = container_of(attr, struct overlay_attribute, attr);
361 if (!overlay_attr->store)
362 return -ENOENT;
364 return overlay_attr->store(overlay, buf, size);
367 static const struct sysfs_ops overlay_sysfs_ops = {
368 .show = overlay_attr_show,
369 .store = overlay_attr_store,
372 static struct kobj_type overlay_ktype = {
373 .sysfs_ops = &overlay_sysfs_ops,
374 .default_attrs = overlay_sysfs_attrs,
377 /* Check if overlay parameters are compatible with display */
378 int dss_check_overlay(struct omap_overlay *ovl, struct omap_dss_device *dssdev)
380 struct omap_overlay_info *info;
381 u16 outw, outh;
382 u16 dw, dh;
384 if (!dssdev)
385 return 0;
387 if (!ovl->info.enabled)
388 return 0;
390 info = &ovl->info;
392 if (info->paddr == 0) {
393 DSSDBG("check_overlay failed: paddr 0\n");
394 return -EINVAL;
397 dssdev->driver->get_resolution(dssdev, &dw, &dh);
399 DSSDBG("check_overlay %d: (%d,%d %dx%d -> %dx%d) disp (%dx%d)\n",
400 ovl->id,
401 info->pos_x, info->pos_y,
402 info->width, info->height,
403 info->out_width, info->out_height,
404 dw, dh);
406 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
407 outw = info->width;
408 outh = info->height;
409 } else {
410 if (info->out_width == 0)
411 outw = info->width;
412 else
413 outw = info->out_width;
415 if (info->out_height == 0)
416 outh = info->height;
417 else
418 outh = info->out_height;
421 if (dw < info->pos_x + outw) {
422 DSSDBG("check_overlay failed 1: %d < %d + %d\n",
423 dw, info->pos_x, outw);
424 return -EINVAL;
427 if (dh < info->pos_y + outh) {
428 DSSDBG("check_overlay failed 2: %d < %d + %d\n",
429 dh, info->pos_y, outh);
430 return -EINVAL;
433 if ((ovl->supported_modes & info->color_mode) == 0) {
434 DSSERR("overlay doesn't support mode %d\n", info->color_mode);
435 return -EINVAL;
438 return 0;
441 static int dss_ovl_set_overlay_info(struct omap_overlay *ovl,
442 struct omap_overlay_info *info)
444 int r;
445 struct omap_overlay_info old_info;
447 old_info = ovl->info;
448 ovl->info = *info;
450 if (ovl->manager) {
451 r = dss_check_overlay(ovl, ovl->manager->device);
452 if (r) {
453 ovl->info = old_info;
454 return r;
458 ovl->info_dirty = true;
460 return 0;
463 static void dss_ovl_get_overlay_info(struct omap_overlay *ovl,
464 struct omap_overlay_info *info)
466 *info = ovl->info;
469 static int dss_ovl_wait_for_go(struct omap_overlay *ovl)
471 return dss_mgr_wait_for_go_ovl(ovl);
474 static int omap_dss_set_manager(struct omap_overlay *ovl,
475 struct omap_overlay_manager *mgr)
477 if (!mgr)
478 return -EINVAL;
480 if (ovl->manager) {
481 DSSERR("overlay '%s' already has a manager '%s'\n",
482 ovl->name, ovl->manager->name);
483 return -EINVAL;
486 if (ovl->info.enabled) {
487 DSSERR("overlay has to be disabled to change the manager\n");
488 return -EINVAL;
491 ovl->manager = mgr;
493 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
494 /* XXX: on manual update display, in auto update mode, a bug happens
495 * here. When an overlay is first enabled on LCD, then it's disabled,
496 * and the manager is changed to TV, we sometimes get SYNC_LOST_DIGIT
497 * errors. Waiting before changing the channel_out fixes it. I'm
498 * guessing that the overlay is still somehow being used for the LCD,
499 * but I don't understand how or why. */
500 msleep(40);
501 dispc_set_channel_out(ovl->id, mgr->id);
502 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
504 return 0;
507 static int omap_dss_unset_manager(struct omap_overlay *ovl)
509 int r;
511 if (!ovl->manager) {
512 DSSERR("failed to detach overlay: manager not set\n");
513 return -EINVAL;
516 if (ovl->info.enabled) {
517 DSSERR("overlay has to be disabled to unset the manager\n");
518 return -EINVAL;
521 r = ovl->wait_for_go(ovl);
522 if (r)
523 return r;
525 ovl->manager = NULL;
527 return 0;
530 int omap_dss_get_num_overlays(void)
532 return num_overlays;
534 EXPORT_SYMBOL(omap_dss_get_num_overlays);
536 struct omap_overlay *omap_dss_get_overlay(int num)
538 int i = 0;
539 struct omap_overlay *ovl;
541 list_for_each_entry(ovl, &overlay_list, list) {
542 if (i++ == num)
543 return ovl;
546 return NULL;
548 EXPORT_SYMBOL(omap_dss_get_overlay);
550 static void omap_dss_add_overlay(struct omap_overlay *overlay)
552 ++num_overlays;
553 list_add_tail(&overlay->list, &overlay_list);
556 static struct omap_overlay *dispc_overlays[MAX_DSS_OVERLAYS];
558 void dss_overlay_setup_dispc_manager(struct omap_overlay_manager *mgr)
560 mgr->num_overlays = dss_feat_get_num_ovls();
561 mgr->overlays = dispc_overlays;
564 #ifdef L4_EXAMPLE
565 static struct omap_overlay *l4_overlays[1];
566 void dss_overlay_setup_l4_manager(struct omap_overlay_manager *mgr)
568 mgr->num_overlays = 1;
569 mgr->overlays = l4_overlays;
571 #endif
573 void dss_init_overlays(struct platform_device *pdev)
575 int i, r;
577 INIT_LIST_HEAD(&overlay_list);
579 num_overlays = 0;
581 for (i = 0; i < dss_feat_get_num_ovls(); ++i) {
582 struct omap_overlay *ovl;
583 ovl = kzalloc(sizeof(*ovl), GFP_KERNEL);
585 BUG_ON(ovl == NULL);
587 switch (i) {
588 case 0:
589 ovl->name = "gfx";
590 ovl->id = OMAP_DSS_GFX;
591 ovl->caps = OMAP_DSS_OVL_CAP_DISPC;
592 ovl->info.global_alpha = 255;
593 break;
594 case 1:
595 ovl->name = "vid1";
596 ovl->id = OMAP_DSS_VIDEO1;
597 ovl->caps = OMAP_DSS_OVL_CAP_SCALE |
598 OMAP_DSS_OVL_CAP_DISPC;
599 ovl->info.global_alpha = 255;
600 break;
601 case 2:
602 ovl->name = "vid2";
603 ovl->id = OMAP_DSS_VIDEO2;
604 ovl->caps = OMAP_DSS_OVL_CAP_SCALE |
605 OMAP_DSS_OVL_CAP_DISPC;
606 ovl->info.global_alpha = 255;
607 break;
610 ovl->set_manager = &omap_dss_set_manager;
611 ovl->unset_manager = &omap_dss_unset_manager;
612 ovl->set_overlay_info = &dss_ovl_set_overlay_info;
613 ovl->get_overlay_info = &dss_ovl_get_overlay_info;
614 ovl->wait_for_go = &dss_ovl_wait_for_go;
616 ovl->supported_modes =
617 dss_feat_get_supported_color_modes(ovl->id);
619 omap_dss_add_overlay(ovl);
621 r = kobject_init_and_add(&ovl->kobj, &overlay_ktype,
622 &pdev->dev.kobj, "overlay%d", i);
624 if (r) {
625 DSSERR("failed to create sysfs file\n");
626 continue;
629 dispc_overlays[i] = ovl;
632 #ifdef L4_EXAMPLE
634 struct omap_overlay *ovl;
635 ovl = kzalloc(sizeof(*ovl), GFP_KERNEL);
637 BUG_ON(ovl == NULL);
639 ovl->name = "l4";
640 ovl->supported_modes = OMAP_DSS_COLOR_RGB24U;
642 ovl->set_manager = &omap_dss_set_manager;
643 ovl->unset_manager = &omap_dss_unset_manager;
644 ovl->set_overlay_info = &dss_ovl_set_overlay_info;
645 ovl->get_overlay_info = &dss_ovl_get_overlay_info;
647 omap_dss_add_overlay(ovl);
649 r = kobject_init_and_add(&ovl->kobj, &overlay_ktype,
650 &pdev->dev.kobj, "overlayl4");
652 if (r)
653 DSSERR("failed to create sysfs file\n");
655 l4_overlays[0] = ovl;
657 #endif
660 /* connect overlays to the new device, if not already connected. if force
661 * selected, connect always. */
662 void dss_recheck_connections(struct omap_dss_device *dssdev, bool force)
664 int i;
665 struct omap_overlay_manager *lcd_mgr;
666 struct omap_overlay_manager *tv_mgr;
667 struct omap_overlay_manager *lcd2_mgr = NULL;
668 struct omap_overlay_manager *mgr = NULL;
670 lcd_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD);
671 tv_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_TV);
672 if (dss_has_feature(FEAT_MGR_LCD2))
673 lcd2_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD2);
675 if (dssdev->channel == OMAP_DSS_CHANNEL_LCD2) {
676 if (!lcd2_mgr->device || force) {
677 if (lcd2_mgr->device)
678 lcd2_mgr->unset_device(lcd2_mgr);
679 lcd2_mgr->set_device(lcd2_mgr, dssdev);
680 mgr = lcd2_mgr;
682 } else if (dssdev->type != OMAP_DISPLAY_TYPE_VENC
683 && dssdev->type != OMAP_DISPLAY_TYPE_HDMI) {
684 if (!lcd_mgr->device || force) {
685 if (lcd_mgr->device)
686 lcd_mgr->unset_device(lcd_mgr);
687 lcd_mgr->set_device(lcd_mgr, dssdev);
688 mgr = lcd_mgr;
692 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
693 || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
694 if (!tv_mgr->device || force) {
695 if (tv_mgr->device)
696 tv_mgr->unset_device(tv_mgr);
697 tv_mgr->set_device(tv_mgr, dssdev);
698 mgr = tv_mgr;
702 if (mgr) {
703 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
704 struct omap_overlay *ovl;
705 ovl = omap_dss_get_overlay(i);
706 if (!ovl->manager || force) {
707 if (ovl->manager)
708 omap_dss_unset_manager(ovl);
709 omap_dss_set_manager(ovl, mgr);
715 void dss_uninit_overlays(struct platform_device *pdev)
717 struct omap_overlay *ovl;
719 while (!list_empty(&overlay_list)) {
720 ovl = list_first_entry(&overlay_list,
721 struct omap_overlay, list);
722 list_del(&ovl->list);
723 kobject_del(&ovl->kobj);
724 kobject_put(&ovl->kobj);
725 kfree(ovl);
728 num_overlays = 0;