blob: 4ede519c0a31b6031c9781415207b082565bfb90 [file] [log] [blame]
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001/*
2 * linux/drivers/video/omap2/dss/manager.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
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.
13 *
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.
18 *
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/>.
21 */
22
23#define DSS_SUBSYS_NAME "MANAGER"
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/spinlock.h>
29#include <linux/jiffies.h>
30
31#include <plat/display.h>
32#include <plat/cpu.h>
33
34#include "dss.h"
35
36static int num_managers;
37static struct list_head manager_list;
38
39static ssize_t manager_name_show(struct omap_overlay_manager *mgr, char *buf)
40{
41 return snprintf(buf, PAGE_SIZE, "%s\n", mgr->name);
42}
43
44static ssize_t manager_display_show(struct omap_overlay_manager *mgr, char *buf)
45{
46 return snprintf(buf, PAGE_SIZE, "%s\n",
47 mgr->device ? mgr->device->name : "<none>");
48}
49
50static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
51 const char *buf, size_t size)
52{
53 int r = 0;
54 size_t len = size;
55 struct omap_dss_device *dssdev = NULL;
56
57 int match(struct omap_dss_device *dssdev, void *data)
58 {
59 const char *str = data;
60 return sysfs_streq(dssdev->name, str);
61 }
62
63 if (buf[size-1] == '\n')
64 --len;
65
66 if (len > 0)
67 dssdev = omap_dss_find_device((void *)buf, match);
68
69 if (len > 0 && dssdev == NULL)
70 return -EINVAL;
71
72 if (dssdev)
73 DSSDBG("display %s found\n", dssdev->name);
74
75 if (mgr->device) {
76 r = mgr->unset_device(mgr);
77 if (r) {
78 DSSERR("failed to unset display\n");
79 goto put_device;
80 }
81 }
82
83 if (dssdev) {
84 r = mgr->set_device(mgr, dssdev);
85 if (r) {
86 DSSERR("failed to set manager\n");
87 goto put_device;
88 }
89
90 r = mgr->apply(mgr);
91 if (r) {
92 DSSERR("failed to apply dispc config\n");
93 goto put_device;
94 }
95 }
96
97put_device:
98 if (dssdev)
99 omap_dss_put_device(dssdev);
100
101 return r ? r : size;
102}
103
104static ssize_t manager_default_color_show(struct omap_overlay_manager *mgr,
105 char *buf)
106{
107 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.default_color);
108}
109
110static ssize_t manager_default_color_store(struct omap_overlay_manager *mgr,
111 const char *buf, size_t size)
112{
113 struct omap_overlay_manager_info info;
114 u32 color;
115 int r;
116
117 if (sscanf(buf, "%d", &color) != 1)
118 return -EINVAL;
119
120 mgr->get_manager_info(mgr, &info);
121
122 info.default_color = color;
123
124 r = mgr->set_manager_info(mgr, &info);
125 if (r)
126 return r;
127
128 r = mgr->apply(mgr);
129 if (r)
130 return r;
131
132 return size;
133}
134
135static const char *trans_key_type_str[] = {
136 "gfx-destination",
137 "video-source",
138};
139
140static ssize_t manager_trans_key_type_show(struct omap_overlay_manager *mgr,
141 char *buf)
142{
143 enum omap_dss_trans_key_type key_type;
144
145 key_type = mgr->info.trans_key_type;
146 BUG_ON(key_type >= ARRAY_SIZE(trans_key_type_str));
147
148 return snprintf(buf, PAGE_SIZE, "%s\n", trans_key_type_str[key_type]);
149}
150
151static ssize_t manager_trans_key_type_store(struct omap_overlay_manager *mgr,
152 const char *buf, size_t size)
153{
154 enum omap_dss_trans_key_type key_type;
155 struct omap_overlay_manager_info info;
156 int r;
157
158 for (key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
159 key_type < ARRAY_SIZE(trans_key_type_str); key_type++) {
160 if (sysfs_streq(buf, trans_key_type_str[key_type]))
161 break;
162 }
163
164 if (key_type == ARRAY_SIZE(trans_key_type_str))
165 return -EINVAL;
166
167 mgr->get_manager_info(mgr, &info);
168
169 info.trans_key_type = key_type;
170
171 r = mgr->set_manager_info(mgr, &info);
172 if (r)
173 return r;
174
175 r = mgr->apply(mgr);
176 if (r)
177 return r;
178
179 return size;
180}
181
182static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
183 char *buf)
184{
185 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_key);
186}
187
188static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
189 const char *buf, size_t size)
190{
191 struct omap_overlay_manager_info info;
192 u32 key_value;
193 int r;
194
195 if (sscanf(buf, "%d", &key_value) != 1)
196 return -EINVAL;
197
198 mgr->get_manager_info(mgr, &info);
199
200 info.trans_key = key_value;
201
202 r = mgr->set_manager_info(mgr, &info);
203 if (r)
204 return r;
205
206 r = mgr->apply(mgr);
207 if (r)
208 return r;
209
210 return size;
211}
212
213static ssize_t manager_trans_key_enabled_show(struct omap_overlay_manager *mgr,
214 char *buf)
215{
216 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_enabled);
217}
218
219static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
220 const char *buf, size_t size)
221{
222 struct omap_overlay_manager_info info;
223 int enable;
224 int r;
225
226 if (sscanf(buf, "%d", &enable) != 1)
227 return -EINVAL;
228
229 mgr->get_manager_info(mgr, &info);
230
231 info.trans_enabled = enable ? true : false;
232
233 r = mgr->set_manager_info(mgr, &info);
234 if (r)
235 return r;
236
237 r = mgr->apply(mgr);
238 if (r)
239 return r;
240
241 return size;
242}
243
244static ssize_t manager_alpha_blending_enabled_show(
245 struct omap_overlay_manager *mgr, char *buf)
246{
247 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.alpha_enabled);
248}
249
250static ssize_t manager_alpha_blending_enabled_store(
251 struct omap_overlay_manager *mgr,
252 const char *buf, size_t size)
253{
254 struct omap_overlay_manager_info info;
255 int enable;
256 int r;
257
258 if (sscanf(buf, "%d", &enable) != 1)
259 return -EINVAL;
260
261 mgr->get_manager_info(mgr, &info);
262
263 info.alpha_enabled = enable ? true : false;
264
265 r = mgr->set_manager_info(mgr, &info);
266 if (r)
267 return r;
268
269 r = mgr->apply(mgr);
270 if (r)
271 return r;
272
273 return size;
274}
275
276struct manager_attribute {
277 struct attribute attr;
278 ssize_t (*show)(struct omap_overlay_manager *, char *);
279 ssize_t (*store)(struct omap_overlay_manager *, const char *, size_t);
280};
281
282#define MANAGER_ATTR(_name, _mode, _show, _store) \
283 struct manager_attribute manager_attr_##_name = \
284 __ATTR(_name, _mode, _show, _store)
285
286static MANAGER_ATTR(name, S_IRUGO, manager_name_show, NULL);
287static MANAGER_ATTR(display, S_IRUGO|S_IWUSR,
288 manager_display_show, manager_display_store);
289static MANAGER_ATTR(default_color, S_IRUGO|S_IWUSR,
290 manager_default_color_show, manager_default_color_store);
291static MANAGER_ATTR(trans_key_type, S_IRUGO|S_IWUSR,
292 manager_trans_key_type_show, manager_trans_key_type_store);
293static MANAGER_ATTR(trans_key_value, S_IRUGO|S_IWUSR,
294 manager_trans_key_value_show, manager_trans_key_value_store);
295static MANAGER_ATTR(trans_key_enabled, S_IRUGO|S_IWUSR,
296 manager_trans_key_enabled_show,
297 manager_trans_key_enabled_store);
298static MANAGER_ATTR(alpha_blending_enabled, S_IRUGO|S_IWUSR,
299 manager_alpha_blending_enabled_show,
300 manager_alpha_blending_enabled_store);
301
302
303static struct attribute *manager_sysfs_attrs[] = {
304 &manager_attr_name.attr,
305 &manager_attr_display.attr,
306 &manager_attr_default_color.attr,
307 &manager_attr_trans_key_type.attr,
308 &manager_attr_trans_key_value.attr,
309 &manager_attr_trans_key_enabled.attr,
310 &manager_attr_alpha_blending_enabled.attr,
311 NULL
312};
313
314static ssize_t manager_attr_show(struct kobject *kobj, struct attribute *attr,
315 char *buf)
316{
317 struct omap_overlay_manager *manager;
318 struct manager_attribute *manager_attr;
319
320 manager = container_of(kobj, struct omap_overlay_manager, kobj);
321 manager_attr = container_of(attr, struct manager_attribute, attr);
322
323 if (!manager_attr->show)
324 return -ENOENT;
325
326 return manager_attr->show(manager, buf);
327}
328
329static ssize_t manager_attr_store(struct kobject *kobj, struct attribute *attr,
330 const char *buf, size_t size)
331{
332 struct omap_overlay_manager *manager;
333 struct manager_attribute *manager_attr;
334
335 manager = container_of(kobj, struct omap_overlay_manager, kobj);
336 manager_attr = container_of(attr, struct manager_attribute, attr);
337
338 if (!manager_attr->store)
339 return -ENOENT;
340
341 return manager_attr->store(manager, buf, size);
342}
343
344static struct sysfs_ops manager_sysfs_ops = {
345 .show = manager_attr_show,
346 .store = manager_attr_store,
347};
348
349static struct kobj_type manager_ktype = {
350 .sysfs_ops = &manager_sysfs_ops,
351 .default_attrs = manager_sysfs_attrs,
352};
353
354/*
355 * We have 4 levels of cache for the dispc settings. First two are in SW and
356 * the latter two in HW.
357 *
358 * +--------------------+
359 * |overlay/manager_info|
360 * +--------------------+
361 * v
362 * apply()
363 * v
364 * +--------------------+
365 * | dss_cache |
366 * +--------------------+
367 * v
368 * configure()
369 * v
370 * +--------------------+
371 * | shadow registers |
372 * +--------------------+
373 * v
374 * VFP or lcd/digit_enable
375 * v
376 * +--------------------+
377 * | registers |
378 * +--------------------+
379 */
380
381struct overlay_cache_data {
382 /* If true, cache changed, but not written to shadow registers. Set
383 * in apply(), cleared when registers written. */
384 bool dirty;
385 /* If true, shadow registers contain changed values not yet in real
386 * registers. Set when writing to shadow registers, cleared at
387 * VSYNC/EVSYNC */
388 bool shadow_dirty;
389
390 bool enabled;
391
392 u32 paddr;
393 void __iomem *vaddr;
394 u16 screen_width;
395 u16 width;
396 u16 height;
397 enum omap_color_mode color_mode;
398 u8 rotation;
399 enum omap_dss_rotation_type rotation_type;
400 bool mirror;
401
402 u16 pos_x;
403 u16 pos_y;
404 u16 out_width; /* if 0, out_width == width */
405 u16 out_height; /* if 0, out_height == height */
406 u8 global_alpha;
407
408 enum omap_channel channel;
409 bool replication;
410 bool ilace;
411
412 enum omap_burst_size burst_size;
413 u32 fifo_low;
414 u32 fifo_high;
415
416 bool manual_update;
417};
418
419struct manager_cache_data {
420 /* If true, cache changed, but not written to shadow registers. Set
421 * in apply(), cleared when registers written. */
422 bool dirty;
423 /* If true, shadow registers contain changed values not yet in real
424 * registers. Set when writing to shadow registers, cleared at
425 * VSYNC/EVSYNC */
426 bool shadow_dirty;
427
428 u32 default_color;
429
430 enum omap_dss_trans_key_type trans_key_type;
431 u32 trans_key;
432 bool trans_enabled;
433
434 bool alpha_enabled;
435
436 bool manual_upd_display;
437 bool manual_update;
438 bool do_manual_update;
439
440 /* manual update region */
441 u16 x, y, w, h;
442};
443
444static struct {
445 spinlock_t lock;
446 struct overlay_cache_data overlay_cache[3];
447 struct manager_cache_data manager_cache[2];
448
449 bool irq_enabled;
450} dss_cache;
451
452
453
454static int omap_dss_set_device(struct omap_overlay_manager *mgr,
455 struct omap_dss_device *dssdev)
456{
457 int i;
458 int r;
459
460 if (dssdev->manager) {
461 DSSERR("display '%s' already has a manager '%s'\n",
462 dssdev->name, dssdev->manager->name);
463 return -EINVAL;
464 }
465
466 if ((mgr->supported_displays & dssdev->type) == 0) {
467 DSSERR("display '%s' does not support manager '%s'\n",
468 dssdev->name, mgr->name);
469 return -EINVAL;
470 }
471
472 for (i = 0; i < mgr->num_overlays; i++) {
473 struct omap_overlay *ovl = mgr->overlays[i];
474
475 if (ovl->manager != mgr || !ovl->info.enabled)
476 continue;
477
478 r = dss_check_overlay(ovl, dssdev);
479 if (r)
480 return r;
481 }
482
483 dssdev->manager = mgr;
484 mgr->device = dssdev;
485 mgr->device_changed = true;
486
487 return 0;
488}
489
490static int omap_dss_unset_device(struct omap_overlay_manager *mgr)
491{
492 if (!mgr->device) {
493 DSSERR("failed to unset display, display not set.\n");
494 return -EINVAL;
495 }
496
497 mgr->device->manager = NULL;
498 mgr->device = NULL;
499 mgr->device_changed = true;
500
501 return 0;
502}
503
Tomi Valkeinen3f71cbe2010-01-08 17:06:04 +0200504static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
505{
506 unsigned long timeout = msecs_to_jiffies(500);
507 u32 irq;
508
509 if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC)
510 irq = DISPC_IRQ_EVSYNC_ODD;
511 else
512 irq = DISPC_IRQ_VSYNC;
513
514 return omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
515}
516
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300517static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
518{
519 unsigned long timeout = msecs_to_jiffies(500);
520 struct manager_cache_data *mc;
521 enum omap_channel channel;
522 u32 irq;
523 int r;
524 int i;
525
526 if (!mgr->device)
527 return 0;
528
529 if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC) {
530 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
531 channel = OMAP_DSS_CHANNEL_DIGIT;
532 } else {
533 if (mgr->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
534 enum omap_dss_update_mode mode;
535 mode = mgr->device->get_update_mode(mgr->device);
536 if (mode != OMAP_DSS_UPDATE_AUTO)
537 return 0;
538
539 irq = DISPC_IRQ_FRAMEDONE;
540 } else {
541 irq = DISPC_IRQ_VSYNC;
542 }
543 channel = OMAP_DSS_CHANNEL_LCD;
544 }
545
546 mc = &dss_cache.manager_cache[mgr->id];
547 i = 0;
548 while (1) {
549 unsigned long flags;
550 bool shadow_dirty, dirty;
551
552 spin_lock_irqsave(&dss_cache.lock, flags);
553 dirty = mc->dirty;
554 shadow_dirty = mc->shadow_dirty;
555 spin_unlock_irqrestore(&dss_cache.lock, flags);
556
557 if (!dirty && !shadow_dirty) {
558 r = 0;
559 break;
560 }
561
562 /* 4 iterations is the worst case:
563 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
564 * 2 - first VSYNC, dirty = true
565 * 3 - dirty = false, shadow_dirty = true
566 * 4 - shadow_dirty = false */
567 if (i++ == 3) {
568 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
569 mgr->id);
570 r = 0;
571 break;
572 }
573
574 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
575 if (r == -ERESTARTSYS)
576 break;
577
578 if (r) {
579 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
580 break;
581 }
582 }
583
584 return r;
585}
586
587int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
588{
589 unsigned long timeout = msecs_to_jiffies(500);
590 enum omap_channel channel;
591 struct overlay_cache_data *oc;
592 struct omap_dss_device *dssdev;
593 u32 irq;
594 int r;
595 int i;
596
597 if (!ovl->manager || !ovl->manager->device)
598 return 0;
599
600 dssdev = ovl->manager->device;
601
602 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) {
603 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
604 channel = OMAP_DSS_CHANNEL_DIGIT;
605 } else {
606 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
607 enum omap_dss_update_mode mode;
608 mode = dssdev->get_update_mode(dssdev);
609 if (mode != OMAP_DSS_UPDATE_AUTO)
610 return 0;
611
612 irq = DISPC_IRQ_FRAMEDONE;
613 } else {
614 irq = DISPC_IRQ_VSYNC;
615 }
616 channel = OMAP_DSS_CHANNEL_LCD;
617 }
618
619 oc = &dss_cache.overlay_cache[ovl->id];
620 i = 0;
621 while (1) {
622 unsigned long flags;
623 bool shadow_dirty, dirty;
624
625 spin_lock_irqsave(&dss_cache.lock, flags);
626 dirty = oc->dirty;
627 shadow_dirty = oc->shadow_dirty;
628 spin_unlock_irqrestore(&dss_cache.lock, flags);
629
630 if (!dirty && !shadow_dirty) {
631 r = 0;
632 break;
633 }
634
635 /* 4 iterations is the worst case:
636 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
637 * 2 - first VSYNC, dirty = true
638 * 3 - dirty = false, shadow_dirty = true
639 * 4 - shadow_dirty = false */
640 if (i++ == 3) {
641 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
642 ovl->id);
643 r = 0;
644 break;
645 }
646
647 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
648 if (r == -ERESTARTSYS)
649 break;
650
651 if (r) {
652 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
653 break;
654 }
655 }
656
657 return r;
658}
659
660static int overlay_enabled(struct omap_overlay *ovl)
661{
662 return ovl->info.enabled && ovl->manager && ovl->manager->device;
663}
664
665/* Is rect1 a subset of rect2? */
666static bool rectangle_subset(int x1, int y1, int w1, int h1,
667 int x2, int y2, int w2, int h2)
668{
669 if (x1 < x2 || y1 < y2)
670 return false;
671
672 if (x1 + w1 > x2 + w2)
673 return false;
674
675 if (y1 + h1 > y2 + h2)
676 return false;
677
678 return true;
679}
680
681/* Do rect1 and rect2 overlap? */
682static bool rectangle_intersects(int x1, int y1, int w1, int h1,
683 int x2, int y2, int w2, int h2)
684{
685 if (x1 >= x2 + w2)
686 return false;
687
688 if (x2 >= x1 + w1)
689 return false;
690
691 if (y1 >= y2 + h2)
692 return false;
693
694 if (y2 >= y1 + h1)
695 return false;
696
697 return true;
698}
699
700static bool dispc_is_overlay_scaled(struct overlay_cache_data *oc)
701{
702 if (oc->out_width != 0 && oc->width != oc->out_width)
703 return true;
704
705 if (oc->out_height != 0 && oc->height != oc->out_height)
706 return true;
707
708 return false;
709}
710
711static int configure_overlay(enum omap_plane plane)
712{
713 struct overlay_cache_data *c;
714 struct manager_cache_data *mc;
715 u16 outw, outh;
716 u16 x, y, w, h;
717 u32 paddr;
718 int r;
719
720 DSSDBGF("%d", plane);
721
722 c = &dss_cache.overlay_cache[plane];
723
724 if (!c->enabled) {
725 dispc_enable_plane(plane, 0);
726 return 0;
727 }
728
729 mc = &dss_cache.manager_cache[c->channel];
730
731 x = c->pos_x;
732 y = c->pos_y;
733 w = c->width;
734 h = c->height;
735 outw = c->out_width == 0 ? c->width : c->out_width;
736 outh = c->out_height == 0 ? c->height : c->out_height;
737 paddr = c->paddr;
738
739 if (c->manual_update && mc->do_manual_update) {
740 unsigned bpp;
741 /* If the overlay is outside the update region, disable it */
742 if (!rectangle_intersects(mc->x, mc->y, mc->w, mc->h,
743 x, y, outw, outh)) {
744 dispc_enable_plane(plane, 0);
745 return 0;
746 }
747
748 switch (c->color_mode) {
749 case OMAP_DSS_COLOR_RGB16:
750 case OMAP_DSS_COLOR_ARGB16:
751 case OMAP_DSS_COLOR_YUV2:
752 case OMAP_DSS_COLOR_UYVY:
753 bpp = 16;
754 break;
755
756 case OMAP_DSS_COLOR_RGB24P:
757 bpp = 24;
758 break;
759
760 case OMAP_DSS_COLOR_RGB24U:
761 case OMAP_DSS_COLOR_ARGB32:
762 case OMAP_DSS_COLOR_RGBA32:
763 case OMAP_DSS_COLOR_RGBX32:
764 bpp = 32;
765 break;
766
767 default:
768 BUG();
769 }
770
771 if (dispc_is_overlay_scaled(c)) {
772 /* If the overlay is scaled, the update area has
773 * already been enlarged to cover the whole overlay. We
774 * only need to adjust x/y here */
775 x = c->pos_x - mc->x;
776 y = c->pos_y - mc->y;
777 } else {
778 if (mc->x > c->pos_x) {
779 x = 0;
780 w -= (mc->x - c->pos_x);
781 paddr += (mc->x - c->pos_x) * bpp / 8;
782 } else {
783 x = c->pos_x - mc->x;
784 }
785
786 if (mc->y > c->pos_y) {
787 y = 0;
788 h -= (mc->y - c->pos_y);
789 paddr += (mc->y - c->pos_y) * c->screen_width *
790 bpp / 8;
791 } else {
792 y = c->pos_y - mc->y;
793 }
794
795 if (mc->w < (x+w))
796 w -= (x+w) - (mc->w);
797
798 if (mc->h < (y+h))
799 h -= (y+h) - (mc->h);
800
801 outw = w;
802 outh = h;
803 }
804 }
805
806 r = dispc_setup_plane(plane,
807 paddr,
808 c->screen_width,
809 x, y,
810 w, h,
811 outw, outh,
812 c->color_mode,
813 c->ilace,
814 c->rotation_type,
815 c->rotation,
816 c->mirror,
817 c->global_alpha);
818
819 if (r) {
820 /* this shouldn't happen */
821 DSSERR("dispc_setup_plane failed for ovl %d\n", plane);
822 dispc_enable_plane(plane, 0);
823 return r;
824 }
825
826 dispc_enable_replication(plane, c->replication);
827
828 dispc_set_burst_size(plane, c->burst_size);
829 dispc_setup_plane_fifo(plane, c->fifo_low, c->fifo_high);
830
831 dispc_enable_plane(plane, 1);
832
833 return 0;
834}
835
836static void configure_manager(enum omap_channel channel)
837{
838 struct manager_cache_data *c;
839
840 DSSDBGF("%d", channel);
841
842 c = &dss_cache.manager_cache[channel];
843
844 dispc_set_trans_key(channel, c->trans_key_type, c->trans_key);
845 dispc_enable_trans_key(channel, c->trans_enabled);
846 dispc_enable_alpha_blending(channel, c->alpha_enabled);
847}
848
849/* configure_dispc() tries to write values from cache to shadow registers.
850 * It writes only to those managers/overlays that are not busy.
851 * returns 0 if everything could be written to shadow registers.
852 * returns 1 if not everything could be written to shadow registers. */
853static int configure_dispc(void)
854{
855 struct overlay_cache_data *oc;
856 struct manager_cache_data *mc;
857 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
858 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
859 int i;
860 int r;
861 bool mgr_busy[2];
862 bool mgr_go[2];
863 bool busy;
864
865 r = 0;
866 busy = false;
867
868 mgr_busy[0] = dispc_go_busy(0);
869 mgr_busy[1] = dispc_go_busy(1);
870 mgr_go[0] = false;
871 mgr_go[1] = false;
872
873 /* Commit overlay settings */
874 for (i = 0; i < num_ovls; ++i) {
875 oc = &dss_cache.overlay_cache[i];
876 mc = &dss_cache.manager_cache[oc->channel];
877
878 if (!oc->dirty)
879 continue;
880
881 if (oc->manual_update && !mc->do_manual_update)
882 continue;
883
884 if (mgr_busy[oc->channel]) {
885 busy = true;
886 continue;
887 }
888
889 r = configure_overlay(i);
890 if (r)
891 DSSERR("configure_overlay %d failed\n", i);
892
893 oc->dirty = false;
894 oc->shadow_dirty = true;
895 mgr_go[oc->channel] = true;
896 }
897
898 /* Commit manager settings */
899 for (i = 0; i < num_mgrs; ++i) {
900 mc = &dss_cache.manager_cache[i];
901
902 if (!mc->dirty)
903 continue;
904
905 if (mc->manual_update && !mc->do_manual_update)
906 continue;
907
908 if (mgr_busy[i]) {
909 busy = true;
910 continue;
911 }
912
913 configure_manager(i);
914 mc->dirty = false;
915 mc->shadow_dirty = true;
916 mgr_go[i] = true;
917 }
918
919 /* set GO */
920 for (i = 0; i < num_mgrs; ++i) {
921 mc = &dss_cache.manager_cache[i];
922
923 if (!mgr_go[i])
924 continue;
925
926 /* We don't need GO with manual update display. LCD iface will
927 * always be turned off after frame, and new settings will be
928 * taken in to use at next update */
929 if (!mc->manual_upd_display)
930 dispc_go(i);
931 }
932
933 if (busy)
934 r = 1;
935 else
936 r = 0;
937
938 return r;
939}
940
941/* Configure dispc for partial update. Return possibly modified update
942 * area */
943void dss_setup_partial_planes(struct omap_dss_device *dssdev,
944 u16 *xi, u16 *yi, u16 *wi, u16 *hi)
945{
946 struct overlay_cache_data *oc;
947 struct manager_cache_data *mc;
948 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
949 struct omap_overlay_manager *mgr;
950 int i;
951 u16 x, y, w, h;
952 unsigned long flags;
953
954 x = *xi;
955 y = *yi;
956 w = *wi;
957 h = *hi;
958
959 DSSDBG("dispc_setup_partial_planes %d,%d %dx%d\n",
960 *xi, *yi, *wi, *hi);
961
962 mgr = dssdev->manager;
963
964 if (!mgr) {
965 DSSDBG("no manager\n");
966 return;
967 }
968
969 spin_lock_irqsave(&dss_cache.lock, flags);
970
971 /* We need to show the whole overlay if it is scaled. So look for
972 * those, and make the update area larger if found.
973 * Also mark the overlay cache dirty */
974 for (i = 0; i < num_ovls; ++i) {
975 unsigned x1, y1, x2, y2;
976 unsigned outw, outh;
977
978 oc = &dss_cache.overlay_cache[i];
979
980 if (oc->channel != mgr->id)
981 continue;
982
983 oc->dirty = true;
984
985 if (!oc->enabled)
986 continue;
987
988 if (!dispc_is_overlay_scaled(oc))
989 continue;
990
991 outw = oc->out_width == 0 ? oc->width : oc->out_width;
992 outh = oc->out_height == 0 ? oc->height : oc->out_height;
993
994 /* is the overlay outside the update region? */
995 if (!rectangle_intersects(x, y, w, h,
996 oc->pos_x, oc->pos_y,
997 outw, outh))
998 continue;
999
1000 /* if the overlay totally inside the update region? */
1001 if (rectangle_subset(oc->pos_x, oc->pos_y, outw, outh,
1002 x, y, w, h))
1003 continue;
1004
1005 if (x > oc->pos_x)
1006 x1 = oc->pos_x;
1007 else
1008 x1 = x;
1009
1010 if (y > oc->pos_y)
1011 y1 = oc->pos_y;
1012 else
1013 y1 = y;
1014
1015 if ((x + w) < (oc->pos_x + outw))
1016 x2 = oc->pos_x + outw;
1017 else
1018 x2 = x + w;
1019
1020 if ((y + h) < (oc->pos_y + outh))
1021 y2 = oc->pos_y + outh;
1022 else
1023 y2 = y + h;
1024
1025 x = x1;
1026 y = y1;
1027 w = x2 - x1;
1028 h = y2 - y1;
1029
1030 DSSDBG("changing upd area due to ovl(%d) scaling %d,%d %dx%d\n",
1031 i, x, y, w, h);
1032 }
1033
1034 mc = &dss_cache.manager_cache[mgr->id];
1035 mc->do_manual_update = true;
1036 mc->x = x;
1037 mc->y = y;
1038 mc->w = w;
1039 mc->h = h;
1040
1041 configure_dispc();
1042
1043 mc->do_manual_update = false;
1044
1045 spin_unlock_irqrestore(&dss_cache.lock, flags);
1046
1047 *xi = x;
1048 *yi = y;
1049 *wi = w;
1050 *hi = h;
1051}
1052
1053void dss_start_update(struct omap_dss_device *dssdev)
1054{
1055 struct manager_cache_data *mc;
1056 struct overlay_cache_data *oc;
1057 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
1058 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
1059 struct omap_overlay_manager *mgr;
1060 int i;
1061
1062 mgr = dssdev->manager;
1063
1064 for (i = 0; i < num_ovls; ++i) {
1065 oc = &dss_cache.overlay_cache[i];
1066 if (oc->channel != mgr->id)
1067 continue;
1068
1069 oc->shadow_dirty = false;
1070 }
1071
1072 for (i = 0; i < num_mgrs; ++i) {
1073 mc = &dss_cache.manager_cache[i];
1074 if (mgr->id != i)
1075 continue;
1076
1077 mc->shadow_dirty = false;
1078 }
1079
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001080 dssdev->manager->enable(dssdev->manager);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001081}
1082
1083static void dss_apply_irq_handler(void *data, u32 mask)
1084{
1085 struct manager_cache_data *mc;
1086 struct overlay_cache_data *oc;
1087 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
1088 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
1089 int i, r;
1090 bool mgr_busy[2];
1091
1092 mgr_busy[0] = dispc_go_busy(0);
1093 mgr_busy[1] = dispc_go_busy(1);
1094
1095 spin_lock(&dss_cache.lock);
1096
1097 for (i = 0; i < num_ovls; ++i) {
1098 oc = &dss_cache.overlay_cache[i];
1099 if (!mgr_busy[oc->channel])
1100 oc->shadow_dirty = false;
1101 }
1102
1103 for (i = 0; i < num_mgrs; ++i) {
1104 mc = &dss_cache.manager_cache[i];
1105 if (!mgr_busy[i])
1106 mc->shadow_dirty = false;
1107 }
1108
1109 r = configure_dispc();
1110 if (r == 1)
1111 goto end;
1112
1113 /* re-read busy flags */
1114 mgr_busy[0] = dispc_go_busy(0);
1115 mgr_busy[1] = dispc_go_busy(1);
1116
1117 /* keep running as long as there are busy managers, so that
1118 * we can collect overlay-applied information */
1119 for (i = 0; i < num_mgrs; ++i) {
1120 if (mgr_busy[i])
1121 goto end;
1122 }
1123
1124 omap_dispc_unregister_isr(dss_apply_irq_handler, NULL,
1125 DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1126 DISPC_IRQ_EVSYNC_EVEN);
1127 dss_cache.irq_enabled = false;
1128
1129end:
1130 spin_unlock(&dss_cache.lock);
1131}
1132
1133static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
1134{
1135 struct overlay_cache_data *oc;
1136 struct manager_cache_data *mc;
1137 int i;
1138 struct omap_overlay *ovl;
1139 int num_planes_enabled = 0;
1140 bool use_fifomerge;
1141 unsigned long flags;
1142 int r;
1143
1144 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
1145
1146 spin_lock_irqsave(&dss_cache.lock, flags);
1147
1148 /* Configure overlays */
1149 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1150 struct omap_dss_device *dssdev;
1151
1152 ovl = omap_dss_get_overlay(i);
1153
1154 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1155 continue;
1156
1157 oc = &dss_cache.overlay_cache[ovl->id];
1158
1159 if (!overlay_enabled(ovl)) {
1160 if (oc->enabled) {
1161 oc->enabled = false;
1162 oc->dirty = true;
1163 }
1164 continue;
1165 }
1166
1167 if (!ovl->info_dirty) {
1168 if (oc->enabled)
1169 ++num_planes_enabled;
1170 continue;
1171 }
1172
1173 dssdev = ovl->manager->device;
1174
1175 if (dss_check_overlay(ovl, dssdev)) {
1176 if (oc->enabled) {
1177 oc->enabled = false;
1178 oc->dirty = true;
1179 }
1180 continue;
1181 }
1182
1183 ovl->info_dirty = false;
1184 oc->dirty = true;
1185
1186 oc->paddr = ovl->info.paddr;
1187 oc->vaddr = ovl->info.vaddr;
1188 oc->screen_width = ovl->info.screen_width;
1189 oc->width = ovl->info.width;
1190 oc->height = ovl->info.height;
1191 oc->color_mode = ovl->info.color_mode;
1192 oc->rotation = ovl->info.rotation;
1193 oc->rotation_type = ovl->info.rotation_type;
1194 oc->mirror = ovl->info.mirror;
1195 oc->pos_x = ovl->info.pos_x;
1196 oc->pos_y = ovl->info.pos_y;
1197 oc->out_width = ovl->info.out_width;
1198 oc->out_height = ovl->info.out_height;
1199 oc->global_alpha = ovl->info.global_alpha;
1200
1201 oc->replication =
1202 dss_use_replication(dssdev, ovl->info.color_mode);
1203
1204 oc->ilace = dssdev->type == OMAP_DISPLAY_TYPE_VENC;
1205
1206 oc->channel = ovl->manager->id;
1207
1208 oc->enabled = true;
1209
1210 oc->manual_update =
1211 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
1212 dssdev->get_update_mode(dssdev) != OMAP_DSS_UPDATE_AUTO;
1213
1214 ++num_planes_enabled;
1215 }
1216
1217 /* Configure managers */
1218 list_for_each_entry(mgr, &manager_list, list) {
1219 struct omap_dss_device *dssdev;
1220
1221 if (!(mgr->caps & OMAP_DSS_OVL_MGR_CAP_DISPC))
1222 continue;
1223
1224 mc = &dss_cache.manager_cache[mgr->id];
1225
1226 if (mgr->device_changed) {
1227 mgr->device_changed = false;
1228 mgr->info_dirty = true;
1229 }
1230
1231 if (!mgr->info_dirty)
1232 continue;
1233
1234 if (!mgr->device)
1235 continue;
1236
1237 dssdev = mgr->device;
1238
1239 mgr->info_dirty = false;
1240 mc->dirty = true;
1241
1242 mc->default_color = mgr->info.default_color;
1243 mc->trans_key_type = mgr->info.trans_key_type;
1244 mc->trans_key = mgr->info.trans_key;
1245 mc->trans_enabled = mgr->info.trans_enabled;
1246 mc->alpha_enabled = mgr->info.alpha_enabled;
1247
1248 mc->manual_upd_display =
1249 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
1250
1251 mc->manual_update =
1252 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
1253 dssdev->get_update_mode(dssdev) != OMAP_DSS_UPDATE_AUTO;
1254 }
1255
1256 /* XXX TODO: Try to get fifomerge working. The problem is that it
1257 * affects both managers, not individually but at the same time. This
1258 * means the change has to be well synchronized. I guess the proper way
1259 * is to have a two step process for fifo merge:
1260 * fifomerge enable:
1261 * 1. disable other planes, leaving one plane enabled
1262 * 2. wait until the planes are disabled on HW
1263 * 3. config merged fifo thresholds, enable fifomerge
1264 * fifomerge disable:
1265 * 1. config unmerged fifo thresholds, disable fifomerge
1266 * 2. wait until fifo changes are in HW
1267 * 3. enable planes
1268 */
1269 use_fifomerge = false;
1270
1271 /* Configure overlay fifos */
1272 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1273 struct omap_dss_device *dssdev;
1274 u32 size;
1275
1276 ovl = omap_dss_get_overlay(i);
1277
1278 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1279 continue;
1280
1281 oc = &dss_cache.overlay_cache[ovl->id];
1282
1283 if (!oc->enabled)
1284 continue;
1285
1286 dssdev = ovl->manager->device;
1287
1288 size = dispc_get_plane_fifo_size(ovl->id);
1289 if (use_fifomerge)
1290 size *= 3;
1291
1292 switch (dssdev->type) {
1293 case OMAP_DISPLAY_TYPE_DPI:
1294 case OMAP_DISPLAY_TYPE_DBI:
1295 case OMAP_DISPLAY_TYPE_SDI:
1296 case OMAP_DISPLAY_TYPE_VENC:
1297 default_get_overlay_fifo_thresholds(ovl->id, size,
1298 &oc->burst_size, &oc->fifo_low,
1299 &oc->fifo_high);
1300 break;
1301#ifdef CONFIG_OMAP2_DSS_DSI
1302 case OMAP_DISPLAY_TYPE_DSI:
1303 dsi_get_overlay_fifo_thresholds(ovl->id, size,
1304 &oc->burst_size, &oc->fifo_low,
1305 &oc->fifo_high);
1306 break;
1307#endif
1308 default:
1309 BUG();
1310 }
1311 }
1312
1313 r = 0;
1314 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
1315 if (!dss_cache.irq_enabled) {
1316 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL,
1317 DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1318 DISPC_IRQ_EVSYNC_EVEN);
1319 dss_cache.irq_enabled = true;
1320 }
1321 configure_dispc();
1322 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
1323
1324 spin_unlock_irqrestore(&dss_cache.lock, flags);
1325
1326 return r;
1327}
1328
1329static int dss_check_manager(struct omap_overlay_manager *mgr)
1330{
1331 /* OMAP supports only graphics source transparency color key and alpha
1332 * blending simultaneously. See TRM 15.4.2.4.2.2 Alpha Mode */
1333
1334 if (mgr->info.alpha_enabled && mgr->info.trans_enabled &&
1335 mgr->info.trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST)
1336 return -EINVAL;
1337
1338 return 0;
1339}
1340
1341static int omap_dss_mgr_set_info(struct omap_overlay_manager *mgr,
1342 struct omap_overlay_manager_info *info)
1343{
1344 int r;
1345 struct omap_overlay_manager_info old_info;
1346
1347 old_info = mgr->info;
1348 mgr->info = *info;
1349
1350 r = dss_check_manager(mgr);
1351 if (r) {
1352 mgr->info = old_info;
1353 return r;
1354 }
1355
1356 mgr->info_dirty = true;
1357
1358 return 0;
1359}
1360
1361static void omap_dss_mgr_get_info(struct omap_overlay_manager *mgr,
1362 struct omap_overlay_manager_info *info)
1363{
1364 *info = mgr->info;
1365}
1366
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001367static int dss_mgr_enable(struct omap_overlay_manager *mgr)
1368{
1369 dispc_enable_channel(mgr->id, 1);
1370 return 0;
1371}
1372
1373static int dss_mgr_disable(struct omap_overlay_manager *mgr)
1374{
1375 dispc_enable_channel(mgr->id, 0);
1376 return 0;
1377}
1378
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001379static void omap_dss_add_overlay_manager(struct omap_overlay_manager *manager)
1380{
1381 ++num_managers;
1382 list_add_tail(&manager->list, &manager_list);
1383}
1384
1385int dss_init_overlay_managers(struct platform_device *pdev)
1386{
1387 int i, r;
1388
1389 spin_lock_init(&dss_cache.lock);
1390
1391 INIT_LIST_HEAD(&manager_list);
1392
1393 num_managers = 0;
1394
1395 for (i = 0; i < 2; ++i) {
1396 struct omap_overlay_manager *mgr;
1397 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1398
1399 BUG_ON(mgr == NULL);
1400
1401 switch (i) {
1402 case 0:
1403 mgr->name = "lcd";
1404 mgr->id = OMAP_DSS_CHANNEL_LCD;
1405 mgr->supported_displays =
1406 OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
1407 OMAP_DISPLAY_TYPE_SDI | OMAP_DISPLAY_TYPE_DSI;
1408 break;
1409 case 1:
1410 mgr->name = "tv";
1411 mgr->id = OMAP_DSS_CHANNEL_DIGIT;
1412 mgr->supported_displays = OMAP_DISPLAY_TYPE_VENC;
1413 break;
1414 }
1415
1416 mgr->set_device = &omap_dss_set_device;
1417 mgr->unset_device = &omap_dss_unset_device;
1418 mgr->apply = &omap_dss_mgr_apply;
1419 mgr->set_manager_info = &omap_dss_mgr_set_info;
1420 mgr->get_manager_info = &omap_dss_mgr_get_info;
1421 mgr->wait_for_go = &dss_mgr_wait_for_go;
Tomi Valkeinen3f71cbe2010-01-08 17:06:04 +02001422 mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001423
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001424 mgr->enable = &dss_mgr_enable;
1425 mgr->disable = &dss_mgr_disable;
1426
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001427 mgr->caps = OMAP_DSS_OVL_MGR_CAP_DISPC;
1428
1429 dss_overlay_setup_dispc_manager(mgr);
1430
1431 omap_dss_add_overlay_manager(mgr);
1432
1433 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1434 &pdev->dev.kobj, "manager%d", i);
1435
1436 if (r) {
1437 DSSERR("failed to create sysfs file\n");
1438 continue;
1439 }
1440 }
1441
1442#ifdef L4_EXAMPLE
1443 {
1444 int omap_dss_mgr_apply_l4(struct omap_overlay_manager *mgr)
1445 {
1446 DSSDBG("omap_dss_mgr_apply_l4(%s)\n", mgr->name);
1447
1448 return 0;
1449 }
1450
1451 struct omap_overlay_manager *mgr;
1452 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1453
1454 BUG_ON(mgr == NULL);
1455
1456 mgr->name = "l4";
1457 mgr->supported_displays =
1458 OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI;
1459
1460 mgr->set_device = &omap_dss_set_device;
1461 mgr->unset_device = &omap_dss_unset_device;
1462 mgr->apply = &omap_dss_mgr_apply_l4;
1463 mgr->set_manager_info = &omap_dss_mgr_set_info;
1464 mgr->get_manager_info = &omap_dss_mgr_get_info;
1465
1466 dss_overlay_setup_l4_manager(mgr);
1467
1468 omap_dss_add_overlay_manager(mgr);
1469
1470 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1471 &pdev->dev.kobj, "managerl4");
1472
1473 if (r)
1474 DSSERR("failed to create sysfs file\n");
1475 }
1476#endif
1477
1478 return 0;
1479}
1480
1481void dss_uninit_overlay_managers(struct platform_device *pdev)
1482{
1483 struct omap_overlay_manager *mgr;
1484
1485 while (!list_empty(&manager_list)) {
1486 mgr = list_first_entry(&manager_list,
1487 struct omap_overlay_manager, list);
1488 list_del(&mgr->list);
1489 kobject_del(&mgr->kobj);
1490 kobject_put(&mgr->kobj);
1491 kfree(mgr);
1492 }
1493
1494 num_managers = 0;
1495}
1496
1497int omap_dss_get_num_overlay_managers(void)
1498{
1499 return num_managers;
1500}
1501EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
1502
1503struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
1504{
1505 int i = 0;
1506 struct omap_overlay_manager *mgr;
1507
1508 list_for_each_entry(mgr, &manager_list, list) {
1509 if (i++ == num)
1510 return mgr;
1511 }
1512
1513 return NULL;
1514}
1515EXPORT_SYMBOL(omap_dss_get_overlay_manager);
1516