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