blob: b40fe3dc9875c45f44c52e973ce47f8115004836 [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
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030032#include <video/omapdss.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030033#include <plat/cpu.h>
34
35#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053036#include "dss_features.h"
Tomi Valkeineneed07e02009-08-07 13:43:20 +030037
38static int num_managers;
39static struct list_head manager_list;
40
41static ssize_t manager_name_show(struct omap_overlay_manager *mgr, char *buf)
42{
43 return snprintf(buf, PAGE_SIZE, "%s\n", mgr->name);
44}
45
46static ssize_t manager_display_show(struct omap_overlay_manager *mgr, char *buf)
47{
48 return snprintf(buf, PAGE_SIZE, "%s\n",
49 mgr->device ? mgr->device->name : "<none>");
50}
51
52static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
53 const char *buf, size_t size)
54{
55 int r = 0;
56 size_t len = size;
57 struct omap_dss_device *dssdev = NULL;
58
59 int match(struct omap_dss_device *dssdev, void *data)
60 {
61 const char *str = data;
62 return sysfs_streq(dssdev->name, str);
63 }
64
65 if (buf[size-1] == '\n')
66 --len;
67
68 if (len > 0)
69 dssdev = omap_dss_find_device((void *)buf, match);
70
71 if (len > 0 && dssdev == NULL)
72 return -EINVAL;
73
74 if (dssdev)
75 DSSDBG("display %s found\n", dssdev->name);
76
77 if (mgr->device) {
78 r = mgr->unset_device(mgr);
79 if (r) {
80 DSSERR("failed to unset display\n");
81 goto put_device;
82 }
83 }
84
85 if (dssdev) {
86 r = mgr->set_device(mgr, dssdev);
87 if (r) {
88 DSSERR("failed to set manager\n");
89 goto put_device;
90 }
91
92 r = mgr->apply(mgr);
93 if (r) {
94 DSSERR("failed to apply dispc config\n");
95 goto put_device;
96 }
97 }
98
99put_device:
100 if (dssdev)
101 omap_dss_put_device(dssdev);
102
103 return r ? r : size;
104}
105
106static ssize_t manager_default_color_show(struct omap_overlay_manager *mgr,
107 char *buf)
108{
109 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.default_color);
110}
111
112static ssize_t manager_default_color_store(struct omap_overlay_manager *mgr,
113 const char *buf, size_t size)
114{
115 struct omap_overlay_manager_info info;
116 u32 color;
117 int r;
118
119 if (sscanf(buf, "%d", &color) != 1)
120 return -EINVAL;
121
122 mgr->get_manager_info(mgr, &info);
123
124 info.default_color = color;
125
126 r = mgr->set_manager_info(mgr, &info);
127 if (r)
128 return r;
129
130 r = mgr->apply(mgr);
131 if (r)
132 return r;
133
134 return size;
135}
136
137static const char *trans_key_type_str[] = {
138 "gfx-destination",
139 "video-source",
140};
141
142static ssize_t manager_trans_key_type_show(struct omap_overlay_manager *mgr,
143 char *buf)
144{
145 enum omap_dss_trans_key_type key_type;
146
147 key_type = mgr->info.trans_key_type;
148 BUG_ON(key_type >= ARRAY_SIZE(trans_key_type_str));
149
150 return snprintf(buf, PAGE_SIZE, "%s\n", trans_key_type_str[key_type]);
151}
152
153static ssize_t manager_trans_key_type_store(struct omap_overlay_manager *mgr,
154 const char *buf, size_t size)
155{
156 enum omap_dss_trans_key_type key_type;
157 struct omap_overlay_manager_info info;
158 int r;
159
160 for (key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
161 key_type < ARRAY_SIZE(trans_key_type_str); key_type++) {
162 if (sysfs_streq(buf, trans_key_type_str[key_type]))
163 break;
164 }
165
166 if (key_type == ARRAY_SIZE(trans_key_type_str))
167 return -EINVAL;
168
169 mgr->get_manager_info(mgr, &info);
170
171 info.trans_key_type = key_type;
172
173 r = mgr->set_manager_info(mgr, &info);
174 if (r)
175 return r;
176
177 r = mgr->apply(mgr);
178 if (r)
179 return r;
180
181 return size;
182}
183
184static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
185 char *buf)
186{
187 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_key);
188}
189
190static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
191 const char *buf, size_t size)
192{
193 struct omap_overlay_manager_info info;
194 u32 key_value;
195 int r;
196
197 if (sscanf(buf, "%d", &key_value) != 1)
198 return -EINVAL;
199
200 mgr->get_manager_info(mgr, &info);
201
202 info.trans_key = key_value;
203
204 r = mgr->set_manager_info(mgr, &info);
205 if (r)
206 return r;
207
208 r = mgr->apply(mgr);
209 if (r)
210 return r;
211
212 return size;
213}
214
215static ssize_t manager_trans_key_enabled_show(struct omap_overlay_manager *mgr,
216 char *buf)
217{
218 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_enabled);
219}
220
221static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
222 const char *buf, size_t size)
223{
224 struct omap_overlay_manager_info info;
225 int enable;
226 int r;
227
228 if (sscanf(buf, "%d", &enable) != 1)
229 return -EINVAL;
230
231 mgr->get_manager_info(mgr, &info);
232
233 info.trans_enabled = enable ? true : false;
234
235 r = mgr->set_manager_info(mgr, &info);
236 if (r)
237 return r;
238
239 r = mgr->apply(mgr);
240 if (r)
241 return r;
242
243 return size;
244}
245
246static ssize_t manager_alpha_blending_enabled_show(
247 struct omap_overlay_manager *mgr, char *buf)
248{
249 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.alpha_enabled);
250}
251
252static ssize_t manager_alpha_blending_enabled_store(
253 struct omap_overlay_manager *mgr,
254 const char *buf, size_t size)
255{
256 struct omap_overlay_manager_info info;
257 int enable;
258 int r;
259
260 if (sscanf(buf, "%d", &enable) != 1)
261 return -EINVAL;
262
263 mgr->get_manager_info(mgr, &info);
264
265 info.alpha_enabled = enable ? true : false;
266
267 r = mgr->set_manager_info(mgr, &info);
268 if (r)
269 return r;
270
271 r = mgr->apply(mgr);
272 if (r)
273 return r;
274
275 return size;
276}
277
278struct manager_attribute {
279 struct attribute attr;
280 ssize_t (*show)(struct omap_overlay_manager *, char *);
281 ssize_t (*store)(struct omap_overlay_manager *, const char *, size_t);
282};
283
284#define MANAGER_ATTR(_name, _mode, _show, _store) \
285 struct manager_attribute manager_attr_##_name = \
286 __ATTR(_name, _mode, _show, _store)
287
288static MANAGER_ATTR(name, S_IRUGO, manager_name_show, NULL);
289static MANAGER_ATTR(display, S_IRUGO|S_IWUSR,
290 manager_display_show, manager_display_store);
291static MANAGER_ATTR(default_color, S_IRUGO|S_IWUSR,
292 manager_default_color_show, manager_default_color_store);
293static MANAGER_ATTR(trans_key_type, S_IRUGO|S_IWUSR,
294 manager_trans_key_type_show, manager_trans_key_type_store);
295static MANAGER_ATTR(trans_key_value, S_IRUGO|S_IWUSR,
296 manager_trans_key_value_show, manager_trans_key_value_store);
297static MANAGER_ATTR(trans_key_enabled, S_IRUGO|S_IWUSR,
298 manager_trans_key_enabled_show,
299 manager_trans_key_enabled_store);
300static MANAGER_ATTR(alpha_blending_enabled, S_IRUGO|S_IWUSR,
301 manager_alpha_blending_enabled_show,
302 manager_alpha_blending_enabled_store);
303
304
305static struct attribute *manager_sysfs_attrs[] = {
306 &manager_attr_name.attr,
307 &manager_attr_display.attr,
308 &manager_attr_default_color.attr,
309 &manager_attr_trans_key_type.attr,
310 &manager_attr_trans_key_value.attr,
311 &manager_attr_trans_key_enabled.attr,
312 &manager_attr_alpha_blending_enabled.attr,
313 NULL
314};
315
316static ssize_t manager_attr_show(struct kobject *kobj, struct attribute *attr,
317 char *buf)
318{
319 struct omap_overlay_manager *manager;
320 struct manager_attribute *manager_attr;
321
322 manager = container_of(kobj, struct omap_overlay_manager, kobj);
323 manager_attr = container_of(attr, struct manager_attribute, attr);
324
325 if (!manager_attr->show)
326 return -ENOENT;
327
328 return manager_attr->show(manager, buf);
329}
330
331static ssize_t manager_attr_store(struct kobject *kobj, struct attribute *attr,
332 const char *buf, size_t size)
333{
334 struct omap_overlay_manager *manager;
335 struct manager_attribute *manager_attr;
336
337 manager = container_of(kobj, struct omap_overlay_manager, kobj);
338 manager_attr = container_of(attr, struct manager_attribute, attr);
339
340 if (!manager_attr->store)
341 return -ENOENT;
342
343 return manager_attr->store(manager, buf, size);
344}
345
Emese Revfy52cf25d2010-01-19 02:58:23 +0100346static const struct sysfs_ops manager_sysfs_ops = {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300347 .show = manager_attr_show,
348 .store = manager_attr_store,
349};
350
351static struct kobj_type manager_ktype = {
352 .sysfs_ops = &manager_sysfs_ops,
353 .default_attrs = manager_sysfs_attrs,
354};
355
356/*
357 * We have 4 levels of cache for the dispc settings. First two are in SW and
358 * the latter two in HW.
359 *
360 * +--------------------+
361 * |overlay/manager_info|
362 * +--------------------+
363 * v
364 * apply()
365 * v
366 * +--------------------+
367 * | dss_cache |
368 * +--------------------+
369 * v
370 * configure()
371 * v
372 * +--------------------+
373 * | shadow registers |
374 * +--------------------+
375 * v
376 * VFP or lcd/digit_enable
377 * v
378 * +--------------------+
379 * | registers |
380 * +--------------------+
381 */
382
383struct overlay_cache_data {
384 /* If true, cache changed, but not written to shadow registers. Set
385 * in apply(), cleared when registers written. */
386 bool dirty;
387 /* If true, shadow registers contain changed values not yet in real
388 * registers. Set when writing to shadow registers, cleared at
389 * VSYNC/EVSYNC */
390 bool shadow_dirty;
391
392 bool enabled;
393
394 u32 paddr;
395 void __iomem *vaddr;
396 u16 screen_width;
397 u16 width;
398 u16 height;
399 enum omap_color_mode color_mode;
400 u8 rotation;
401 enum omap_dss_rotation_type rotation_type;
402 bool mirror;
403
404 u16 pos_x;
405 u16 pos_y;
406 u16 out_width; /* if 0, out_width == width */
407 u16 out_height; /* if 0, out_height == height */
408 u8 global_alpha;
Rajkumar Nfd28a392010-11-04 12:28:42 +0100409 u8 pre_mult_alpha;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300410
411 enum omap_channel channel;
412 bool replication;
413 bool ilace;
414
415 enum omap_burst_size burst_size;
416 u32 fifo_low;
417 u32 fifo_high;
418
419 bool manual_update;
420};
421
422struct manager_cache_data {
423 /* If true, cache changed, but not written to shadow registers. Set
424 * in apply(), cleared when registers written. */
425 bool dirty;
426 /* If true, shadow registers contain changed values not yet in real
427 * registers. Set when writing to shadow registers, cleared at
428 * VSYNC/EVSYNC */
429 bool shadow_dirty;
430
431 u32 default_color;
432
433 enum omap_dss_trans_key_type trans_key_type;
434 u32 trans_key;
435 bool trans_enabled;
436
437 bool alpha_enabled;
438
439 bool manual_upd_display;
440 bool manual_update;
441 bool do_manual_update;
442
443 /* manual update region */
444 u16 x, y, w, h;
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300445
446 /* enlarge the update area if the update area contains scaled
447 * overlays */
448 bool enlarge_update_area;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300449};
450
451static struct {
452 spinlock_t lock;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530453 struct overlay_cache_data overlay_cache[MAX_DSS_OVERLAYS];
454 struct manager_cache_data manager_cache[MAX_DSS_MANAGERS];
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300455
456 bool irq_enabled;
457} dss_cache;
458
459
460
461static int omap_dss_set_device(struct omap_overlay_manager *mgr,
462 struct omap_dss_device *dssdev)
463{
464 int i;
465 int r;
466
467 if (dssdev->manager) {
468 DSSERR("display '%s' already has a manager '%s'\n",
469 dssdev->name, dssdev->manager->name);
470 return -EINVAL;
471 }
472
473 if ((mgr->supported_displays & dssdev->type) == 0) {
474 DSSERR("display '%s' does not support manager '%s'\n",
475 dssdev->name, mgr->name);
476 return -EINVAL;
477 }
478
479 for (i = 0; i < mgr->num_overlays; i++) {
480 struct omap_overlay *ovl = mgr->overlays[i];
481
482 if (ovl->manager != mgr || !ovl->info.enabled)
483 continue;
484
485 r = dss_check_overlay(ovl, dssdev);
486 if (r)
487 return r;
488 }
489
490 dssdev->manager = mgr;
491 mgr->device = dssdev;
492 mgr->device_changed = true;
493
494 return 0;
495}
496
497static int omap_dss_unset_device(struct omap_overlay_manager *mgr)
498{
499 if (!mgr->device) {
500 DSSERR("failed to unset display, display not set.\n");
501 return -EINVAL;
502 }
503
504 mgr->device->manager = NULL;
505 mgr->device = NULL;
506 mgr->device_changed = true;
507
508 return 0;
509}
510
Tomi Valkeinen3f71cbe2010-01-08 17:06:04 +0200511static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
512{
513 unsigned long timeout = msecs_to_jiffies(500);
514 u32 irq;
515
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000516 if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC) {
Tomi Valkeinen3f71cbe2010-01-08 17:06:04 +0200517 irq = DISPC_IRQ_EVSYNC_ODD;
Mythri P Kb1196012011-03-08 17:15:54 +0530518 } else if (mgr->device->type == OMAP_DISPLAY_TYPE_HDMI) {
519 irq = DISPC_IRQ_EVSYNC_EVEN;
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000520 } else {
521 if (mgr->id == OMAP_DSS_CHANNEL_LCD)
522 irq = DISPC_IRQ_VSYNC;
523 else
524 irq = DISPC_IRQ_VSYNC2;
525 }
Tomi Valkeinen3f71cbe2010-01-08 17:06:04 +0200526 return omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
527}
528
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300529static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
530{
531 unsigned long timeout = msecs_to_jiffies(500);
532 struct manager_cache_data *mc;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300533 u32 irq;
534 int r;
535 int i;
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200536 struct omap_dss_device *dssdev = mgr->device;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300537
Ville Syrjäläa74b2602010-03-04 16:03:56 +0200538 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300539 return 0;
540
Mythri P Kb1196012011-03-08 17:15:54 +0530541 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
542 || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300543 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300544 } else {
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200545 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300546 enum omap_dss_update_mode mode;
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200547 mode = dssdev->driver->get_update_mode(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300548 if (mode != OMAP_DSS_UPDATE_AUTO)
549 return 0;
550
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000551 irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
552 DISPC_IRQ_FRAMEDONE
553 : DISPC_IRQ_FRAMEDONE2;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300554 } else {
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000555 irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
556 DISPC_IRQ_VSYNC
557 : DISPC_IRQ_VSYNC2;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300558 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300559 }
560
561 mc = &dss_cache.manager_cache[mgr->id];
562 i = 0;
563 while (1) {
564 unsigned long flags;
565 bool shadow_dirty, dirty;
566
567 spin_lock_irqsave(&dss_cache.lock, flags);
568 dirty = mc->dirty;
569 shadow_dirty = mc->shadow_dirty;
570 spin_unlock_irqrestore(&dss_cache.lock, flags);
571
572 if (!dirty && !shadow_dirty) {
573 r = 0;
574 break;
575 }
576
577 /* 4 iterations is the worst case:
578 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
579 * 2 - first VSYNC, dirty = true
580 * 3 - dirty = false, shadow_dirty = true
581 * 4 - shadow_dirty = false */
582 if (i++ == 3) {
583 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
584 mgr->id);
585 r = 0;
586 break;
587 }
588
589 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
590 if (r == -ERESTARTSYS)
591 break;
592
593 if (r) {
594 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
595 break;
596 }
597 }
598
599 return r;
600}
601
602int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
603{
604 unsigned long timeout = msecs_to_jiffies(500);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300605 struct overlay_cache_data *oc;
606 struct omap_dss_device *dssdev;
607 u32 irq;
608 int r;
609 int i;
610
Ville Syrjäläa74b2602010-03-04 16:03:56 +0200611 if (!ovl->manager)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300612 return 0;
613
614 dssdev = ovl->manager->device;
615
Ville Syrjäläa74b2602010-03-04 16:03:56 +0200616 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
617 return 0;
618
Mythri P Kb1196012011-03-08 17:15:54 +0530619 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
620 || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300621 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300622 } else {
623 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
624 enum omap_dss_update_mode mode;
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200625 mode = dssdev->driver->get_update_mode(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300626 if (mode != OMAP_DSS_UPDATE_AUTO)
627 return 0;
628
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000629 irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
630 DISPC_IRQ_FRAMEDONE
631 : DISPC_IRQ_FRAMEDONE2;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300632 } else {
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000633 irq = (dssdev->manager->id == OMAP_DSS_CHANNEL_LCD) ?
634 DISPC_IRQ_VSYNC
635 : DISPC_IRQ_VSYNC2;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300636 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300637 }
638
639 oc = &dss_cache.overlay_cache[ovl->id];
640 i = 0;
641 while (1) {
642 unsigned long flags;
643 bool shadow_dirty, dirty;
644
645 spin_lock_irqsave(&dss_cache.lock, flags);
646 dirty = oc->dirty;
647 shadow_dirty = oc->shadow_dirty;
648 spin_unlock_irqrestore(&dss_cache.lock, flags);
649
650 if (!dirty && !shadow_dirty) {
651 r = 0;
652 break;
653 }
654
655 /* 4 iterations is the worst case:
656 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
657 * 2 - first VSYNC, dirty = true
658 * 3 - dirty = false, shadow_dirty = true
659 * 4 - shadow_dirty = false */
660 if (i++ == 3) {
661 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
662 ovl->id);
663 r = 0;
664 break;
665 }
666
667 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
668 if (r == -ERESTARTSYS)
669 break;
670
671 if (r) {
672 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
673 break;
674 }
675 }
676
677 return r;
678}
679
680static int overlay_enabled(struct omap_overlay *ovl)
681{
682 return ovl->info.enabled && ovl->manager && ovl->manager->device;
683}
684
685/* Is rect1 a subset of rect2? */
686static bool rectangle_subset(int x1, int y1, int w1, int h1,
687 int x2, int y2, int w2, int h2)
688{
689 if (x1 < x2 || y1 < y2)
690 return false;
691
692 if (x1 + w1 > x2 + w2)
693 return false;
694
695 if (y1 + h1 > y2 + h2)
696 return false;
697
698 return true;
699}
700
701/* Do rect1 and rect2 overlap? */
702static bool rectangle_intersects(int x1, int y1, int w1, int h1,
703 int x2, int y2, int w2, int h2)
704{
705 if (x1 >= x2 + w2)
706 return false;
707
708 if (x2 >= x1 + w1)
709 return false;
710
711 if (y1 >= y2 + h2)
712 return false;
713
714 if (y2 >= y1 + h1)
715 return false;
716
717 return true;
718}
719
720static bool dispc_is_overlay_scaled(struct overlay_cache_data *oc)
721{
722 if (oc->out_width != 0 && oc->width != oc->out_width)
723 return true;
724
725 if (oc->out_height != 0 && oc->height != oc->out_height)
726 return true;
727
728 return false;
729}
730
731static int configure_overlay(enum omap_plane plane)
732{
733 struct overlay_cache_data *c;
734 struct manager_cache_data *mc;
735 u16 outw, outh;
736 u16 x, y, w, h;
737 u32 paddr;
738 int r;
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300739 u16 orig_w, orig_h, orig_outw, orig_outh;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300740
741 DSSDBGF("%d", plane);
742
743 c = &dss_cache.overlay_cache[plane];
744
745 if (!c->enabled) {
746 dispc_enable_plane(plane, 0);
747 return 0;
748 }
749
750 mc = &dss_cache.manager_cache[c->channel];
751
752 x = c->pos_x;
753 y = c->pos_y;
754 w = c->width;
755 h = c->height;
756 outw = c->out_width == 0 ? c->width : c->out_width;
757 outh = c->out_height == 0 ? c->height : c->out_height;
758 paddr = c->paddr;
759
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300760 orig_w = w;
761 orig_h = h;
762 orig_outw = outw;
763 orig_outh = outh;
764
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300765 if (c->manual_update && mc->do_manual_update) {
766 unsigned bpp;
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300767 unsigned scale_x_m = w, scale_x_d = outw;
768 unsigned scale_y_m = h, scale_y_d = outh;
769
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300770 /* If the overlay is outside the update region, disable it */
771 if (!rectangle_intersects(mc->x, mc->y, mc->w, mc->h,
772 x, y, outw, outh)) {
773 dispc_enable_plane(plane, 0);
774 return 0;
775 }
776
777 switch (c->color_mode) {
Amber Jainf20e4222011-05-19 19:47:50 +0530778 case OMAP_DSS_COLOR_NV12:
779 bpp = 8;
780 break;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300781 case OMAP_DSS_COLOR_RGB16:
782 case OMAP_DSS_COLOR_ARGB16:
783 case OMAP_DSS_COLOR_YUV2:
784 case OMAP_DSS_COLOR_UYVY:
Amber Jainf20e4222011-05-19 19:47:50 +0530785 case OMAP_DSS_COLOR_RGBA16:
786 case OMAP_DSS_COLOR_RGBX16:
787 case OMAP_DSS_COLOR_ARGB16_1555:
788 case OMAP_DSS_COLOR_XRGB16_1555:
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300789 bpp = 16;
790 break;
791
792 case OMAP_DSS_COLOR_RGB24P:
793 bpp = 24;
794 break;
795
796 case OMAP_DSS_COLOR_RGB24U:
797 case OMAP_DSS_COLOR_ARGB32:
798 case OMAP_DSS_COLOR_RGBA32:
799 case OMAP_DSS_COLOR_RGBX32:
800 bpp = 32;
801 break;
802
803 default:
804 BUG();
805 }
806
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300807 if (mc->x > c->pos_x) {
808 x = 0;
809 outw -= (mc->x - c->pos_x);
810 paddr += (mc->x - c->pos_x) *
811 scale_x_m / scale_x_d * bpp / 8;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300812 } else {
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300813 x = c->pos_x - mc->x;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300814 }
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300815
816 if (mc->y > c->pos_y) {
817 y = 0;
818 outh -= (mc->y - c->pos_y);
819 paddr += (mc->y - c->pos_y) *
820 scale_y_m / scale_y_d *
821 c->screen_width * bpp / 8;
822 } else {
823 y = c->pos_y - mc->y;
824 }
825
826 if (mc->w < (x + outw))
827 outw -= (x + outw) - (mc->w);
828
829 if (mc->h < (y + outh))
830 outh -= (y + outh) - (mc->h);
831
832 w = w * outw / orig_outw;
833 h = h * outh / orig_outh;
Tomi Valkeinenf55fdcf2010-06-03 16:27:46 +0300834
835 /* YUV mode overlay's input width has to be even and the
836 * algorithm above may adjust the width to be odd.
837 *
838 * Here we adjust the width if needed, preferring to increase
839 * the width if the original width was bigger.
840 */
841 if ((w & 1) &&
842 (c->color_mode == OMAP_DSS_COLOR_YUV2 ||
843 c->color_mode == OMAP_DSS_COLOR_UYVY)) {
844 if (orig_w > w)
845 w += 1;
846 else
847 w -= 1;
848 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300849 }
850
851 r = dispc_setup_plane(plane,
852 paddr,
853 c->screen_width,
854 x, y,
855 w, h,
856 outw, outh,
857 c->color_mode,
858 c->ilace,
859 c->rotation_type,
860 c->rotation,
861 c->mirror,
Rajkumar Nfd28a392010-11-04 12:28:42 +0100862 c->global_alpha,
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000863 c->pre_mult_alpha,
864 c->channel);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300865
866 if (r) {
867 /* this shouldn't happen */
868 DSSERR("dispc_setup_plane failed for ovl %d\n", plane);
869 dispc_enable_plane(plane, 0);
870 return r;
871 }
872
873 dispc_enable_replication(plane, c->replication);
874
875 dispc_set_burst_size(plane, c->burst_size);
876 dispc_setup_plane_fifo(plane, c->fifo_low, c->fifo_high);
877
878 dispc_enable_plane(plane, 1);
879
880 return 0;
881}
882
883static void configure_manager(enum omap_channel channel)
884{
885 struct manager_cache_data *c;
886
887 DSSDBGF("%d", channel);
888
889 c = &dss_cache.manager_cache[channel];
890
Carlos Lopeza3bb67a2010-04-25 12:53:35 +0200891 dispc_set_default_color(channel, c->default_color);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300892 dispc_set_trans_key(channel, c->trans_key_type, c->trans_key);
893 dispc_enable_trans_key(channel, c->trans_enabled);
894 dispc_enable_alpha_blending(channel, c->alpha_enabled);
895}
896
897/* configure_dispc() tries to write values from cache to shadow registers.
898 * It writes only to those managers/overlays that are not busy.
899 * returns 0 if everything could be written to shadow registers.
900 * returns 1 if not everything could be written to shadow registers. */
901static int configure_dispc(void)
902{
903 struct overlay_cache_data *oc;
904 struct manager_cache_data *mc;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530905 const int num_ovls = dss_feat_get_num_ovls();
906 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300907 int i;
908 int r;
Archit Tanejaa0acb552010-09-15 19:20:00 +0530909 bool mgr_busy[MAX_DSS_MANAGERS];
910 bool mgr_go[MAX_DSS_MANAGERS];
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300911 bool busy;
912
913 r = 0;
914 busy = false;
915
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000916 for (i = 0; i < num_mgrs; i++) {
917 mgr_busy[i] = dispc_go_busy(i);
918 mgr_go[i] = false;
919 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300920
921 /* Commit overlay settings */
922 for (i = 0; i < num_ovls; ++i) {
923 oc = &dss_cache.overlay_cache[i];
924 mc = &dss_cache.manager_cache[oc->channel];
925
926 if (!oc->dirty)
927 continue;
928
929 if (oc->manual_update && !mc->do_manual_update)
930 continue;
931
932 if (mgr_busy[oc->channel]) {
933 busy = true;
934 continue;
935 }
936
937 r = configure_overlay(i);
938 if (r)
939 DSSERR("configure_overlay %d failed\n", i);
940
941 oc->dirty = false;
942 oc->shadow_dirty = true;
943 mgr_go[oc->channel] = true;
944 }
945
946 /* Commit manager settings */
947 for (i = 0; i < num_mgrs; ++i) {
948 mc = &dss_cache.manager_cache[i];
949
950 if (!mc->dirty)
951 continue;
952
953 if (mc->manual_update && !mc->do_manual_update)
954 continue;
955
956 if (mgr_busy[i]) {
957 busy = true;
958 continue;
959 }
960
961 configure_manager(i);
962 mc->dirty = false;
963 mc->shadow_dirty = true;
964 mgr_go[i] = true;
965 }
966
967 /* set GO */
968 for (i = 0; i < num_mgrs; ++i) {
969 mc = &dss_cache.manager_cache[i];
970
971 if (!mgr_go[i])
972 continue;
973
974 /* We don't need GO with manual update display. LCD iface will
975 * always be turned off after frame, and new settings will be
976 * taken in to use at next update */
977 if (!mc->manual_upd_display)
978 dispc_go(i);
979 }
980
981 if (busy)
982 r = 1;
983 else
984 r = 0;
985
986 return r;
987}
988
Tomi Valkeinenf49a9512010-03-26 16:26:37 +0200989/* Make the coordinates even. There are some strange problems with OMAP and
990 * partial DSI update when the update widths are odd. */
991static void make_even(u16 *x, u16 *w)
992{
993 u16 x1, x2;
994
995 x1 = *x;
996 x2 = *x + *w;
997
998 x1 &= ~1;
999 x2 = ALIGN(x2, 2);
1000
1001 *x = x1;
1002 *w = x2 - x1;
1003}
1004
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001005/* Configure dispc for partial update. Return possibly modified update
1006 * area */
1007void dss_setup_partial_planes(struct omap_dss_device *dssdev,
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03001008 u16 *xi, u16 *yi, u16 *wi, u16 *hi, bool enlarge_update_area)
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001009{
1010 struct overlay_cache_data *oc;
1011 struct manager_cache_data *mc;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301012 const int num_ovls = dss_feat_get_num_ovls();
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001013 struct omap_overlay_manager *mgr;
1014 int i;
1015 u16 x, y, w, h;
1016 unsigned long flags;
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001017 bool area_changed;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001018
1019 x = *xi;
1020 y = *yi;
1021 w = *wi;
1022 h = *hi;
1023
1024 DSSDBG("dispc_setup_partial_planes %d,%d %dx%d\n",
1025 *xi, *yi, *wi, *hi);
1026
1027 mgr = dssdev->manager;
1028
1029 if (!mgr) {
1030 DSSDBG("no manager\n");
1031 return;
1032 }
1033
Tomi Valkeinenf49a9512010-03-26 16:26:37 +02001034 make_even(&x, &w);
1035
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001036 spin_lock_irqsave(&dss_cache.lock, flags);
1037
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001038 /*
1039 * Execute the outer loop until the inner loop has completed
1040 * once without increasing the update area. This will ensure that
1041 * all scaled overlays end up completely within the update area.
1042 */
1043 do {
1044 area_changed = false;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001045
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001046 /* We need to show the whole overlay if it is scaled. So look
1047 * for those, and make the update area larger if found.
1048 * Also mark the overlay cache dirty */
1049 for (i = 0; i < num_ovls; ++i) {
1050 unsigned x1, y1, x2, y2;
1051 unsigned outw, outh;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001052
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001053 oc = &dss_cache.overlay_cache[i];
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001054
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001055 if (oc->channel != mgr->id)
1056 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001057
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001058 oc->dirty = true;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001059
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03001060 if (!enlarge_update_area)
1061 continue;
1062
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001063 if (!oc->enabled)
1064 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001065
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001066 if (!dispc_is_overlay_scaled(oc))
1067 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001068
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001069 outw = oc->out_width == 0 ?
1070 oc->width : oc->out_width;
1071 outh = oc->out_height == 0 ?
1072 oc->height : oc->out_height;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001073
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001074 /* is the overlay outside the update region? */
1075 if (!rectangle_intersects(x, y, w, h,
1076 oc->pos_x, oc->pos_y,
1077 outw, outh))
1078 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001079
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001080 /* if the overlay totally inside the update region? */
1081 if (rectangle_subset(oc->pos_x, oc->pos_y, outw, outh,
1082 x, y, w, h))
1083 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001084
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001085 if (x > oc->pos_x)
1086 x1 = oc->pos_x;
1087 else
1088 x1 = x;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001089
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001090 if (y > oc->pos_y)
1091 y1 = oc->pos_y;
1092 else
1093 y1 = y;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001094
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001095 if ((x + w) < (oc->pos_x + outw))
1096 x2 = oc->pos_x + outw;
1097 else
1098 x2 = x + w;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001099
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001100 if ((y + h) < (oc->pos_y + outh))
1101 y2 = oc->pos_y + outh;
1102 else
1103 y2 = y + h;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001104
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001105 x = x1;
1106 y = y1;
1107 w = x2 - x1;
1108 h = y2 - y1;
Tomi Valkeinenf49a9512010-03-26 16:26:37 +02001109
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001110 make_even(&x, &w);
1111
1112 DSSDBG("changing upd area due to ovl(%d) "
1113 "scaling %d,%d %dx%d\n",
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001114 i, x, y, w, h);
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001115
1116 area_changed = true;
1117 }
1118 } while (area_changed);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001119
1120 mc = &dss_cache.manager_cache[mgr->id];
1121 mc->do_manual_update = true;
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03001122 mc->enlarge_update_area = enlarge_update_area;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001123 mc->x = x;
1124 mc->y = y;
1125 mc->w = w;
1126 mc->h = h;
1127
1128 configure_dispc();
1129
1130 mc->do_manual_update = false;
1131
1132 spin_unlock_irqrestore(&dss_cache.lock, flags);
1133
1134 *xi = x;
1135 *yi = y;
1136 *wi = w;
1137 *hi = h;
1138}
1139
1140void dss_start_update(struct omap_dss_device *dssdev)
1141{
1142 struct manager_cache_data *mc;
1143 struct overlay_cache_data *oc;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301144 const int num_ovls = dss_feat_get_num_ovls();
1145 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001146 struct omap_overlay_manager *mgr;
1147 int i;
1148
1149 mgr = dssdev->manager;
1150
1151 for (i = 0; i < num_ovls; ++i) {
1152 oc = &dss_cache.overlay_cache[i];
1153 if (oc->channel != mgr->id)
1154 continue;
1155
1156 oc->shadow_dirty = false;
1157 }
1158
1159 for (i = 0; i < num_mgrs; ++i) {
1160 mc = &dss_cache.manager_cache[i];
1161 if (mgr->id != i)
1162 continue;
1163
1164 mc->shadow_dirty = false;
1165 }
1166
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001167 dssdev->manager->enable(dssdev->manager);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001168}
1169
1170static void dss_apply_irq_handler(void *data, u32 mask)
1171{
1172 struct manager_cache_data *mc;
1173 struct overlay_cache_data *oc;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301174 const int num_ovls = dss_feat_get_num_ovls();
1175 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001176 int i, r;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301177 bool mgr_busy[MAX_DSS_MANAGERS];
Sumit Semwal18faa1b2010-12-02 11:27:14 +00001178 u32 irq_mask;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001179
Sumit Semwal18faa1b2010-12-02 11:27:14 +00001180 for (i = 0; i < num_mgrs; i++)
1181 mgr_busy[i] = dispc_go_busy(i);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001182
1183 spin_lock(&dss_cache.lock);
1184
1185 for (i = 0; i < num_ovls; ++i) {
1186 oc = &dss_cache.overlay_cache[i];
1187 if (!mgr_busy[oc->channel])
1188 oc->shadow_dirty = false;
1189 }
1190
1191 for (i = 0; i < num_mgrs; ++i) {
1192 mc = &dss_cache.manager_cache[i];
1193 if (!mgr_busy[i])
1194 mc->shadow_dirty = false;
1195 }
1196
1197 r = configure_dispc();
1198 if (r == 1)
1199 goto end;
1200
1201 /* re-read busy flags */
Sumit Semwal18faa1b2010-12-02 11:27:14 +00001202 for (i = 0; i < num_mgrs; i++)
1203 mgr_busy[i] = dispc_go_busy(i);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001204
1205 /* keep running as long as there are busy managers, so that
1206 * we can collect overlay-applied information */
1207 for (i = 0; i < num_mgrs; ++i) {
1208 if (mgr_busy[i])
1209 goto end;
1210 }
1211
Sumit Semwal18faa1b2010-12-02 11:27:14 +00001212 irq_mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1213 DISPC_IRQ_EVSYNC_EVEN;
1214 if (dss_has_feature(FEAT_MGR_LCD2))
1215 irq_mask |= DISPC_IRQ_VSYNC2;
1216
1217 omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, irq_mask);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001218 dss_cache.irq_enabled = false;
1219
1220end:
1221 spin_unlock(&dss_cache.lock);
1222}
1223
1224static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
1225{
1226 struct overlay_cache_data *oc;
1227 struct manager_cache_data *mc;
1228 int i;
1229 struct omap_overlay *ovl;
1230 int num_planes_enabled = 0;
1231 bool use_fifomerge;
1232 unsigned long flags;
1233 int r;
1234
1235 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
1236
1237 spin_lock_irqsave(&dss_cache.lock, flags);
1238
1239 /* Configure overlays */
1240 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1241 struct omap_dss_device *dssdev;
1242
1243 ovl = omap_dss_get_overlay(i);
1244
1245 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1246 continue;
1247
1248 oc = &dss_cache.overlay_cache[ovl->id];
1249
1250 if (!overlay_enabled(ovl)) {
1251 if (oc->enabled) {
1252 oc->enabled = false;
1253 oc->dirty = true;
1254 }
1255 continue;
1256 }
1257
1258 if (!ovl->info_dirty) {
1259 if (oc->enabled)
1260 ++num_planes_enabled;
1261 continue;
1262 }
1263
1264 dssdev = ovl->manager->device;
1265
1266 if (dss_check_overlay(ovl, dssdev)) {
1267 if (oc->enabled) {
1268 oc->enabled = false;
1269 oc->dirty = true;
1270 }
1271 continue;
1272 }
1273
1274 ovl->info_dirty = false;
1275 oc->dirty = true;
1276
1277 oc->paddr = ovl->info.paddr;
1278 oc->vaddr = ovl->info.vaddr;
1279 oc->screen_width = ovl->info.screen_width;
1280 oc->width = ovl->info.width;
1281 oc->height = ovl->info.height;
1282 oc->color_mode = ovl->info.color_mode;
1283 oc->rotation = ovl->info.rotation;
1284 oc->rotation_type = ovl->info.rotation_type;
1285 oc->mirror = ovl->info.mirror;
1286 oc->pos_x = ovl->info.pos_x;
1287 oc->pos_y = ovl->info.pos_y;
1288 oc->out_width = ovl->info.out_width;
1289 oc->out_height = ovl->info.out_height;
1290 oc->global_alpha = ovl->info.global_alpha;
Rajkumar Nfd28a392010-11-04 12:28:42 +01001291 oc->pre_mult_alpha = ovl->info.pre_mult_alpha;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001292
1293 oc->replication =
1294 dss_use_replication(dssdev, ovl->info.color_mode);
1295
1296 oc->ilace = dssdev->type == OMAP_DISPLAY_TYPE_VENC;
1297
1298 oc->channel = ovl->manager->id;
1299
1300 oc->enabled = true;
1301
1302 oc->manual_update =
1303 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001304 dssdev->driver->get_update_mode(dssdev) !=
1305 OMAP_DSS_UPDATE_AUTO;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001306
1307 ++num_planes_enabled;
1308 }
1309
1310 /* Configure managers */
1311 list_for_each_entry(mgr, &manager_list, list) {
1312 struct omap_dss_device *dssdev;
1313
1314 if (!(mgr->caps & OMAP_DSS_OVL_MGR_CAP_DISPC))
1315 continue;
1316
1317 mc = &dss_cache.manager_cache[mgr->id];
1318
1319 if (mgr->device_changed) {
1320 mgr->device_changed = false;
1321 mgr->info_dirty = true;
1322 }
1323
1324 if (!mgr->info_dirty)
1325 continue;
1326
1327 if (!mgr->device)
1328 continue;
1329
1330 dssdev = mgr->device;
1331
1332 mgr->info_dirty = false;
1333 mc->dirty = true;
1334
1335 mc->default_color = mgr->info.default_color;
1336 mc->trans_key_type = mgr->info.trans_key_type;
1337 mc->trans_key = mgr->info.trans_key;
1338 mc->trans_enabled = mgr->info.trans_enabled;
1339 mc->alpha_enabled = mgr->info.alpha_enabled;
1340
1341 mc->manual_upd_display =
1342 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
1343
1344 mc->manual_update =
1345 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001346 dssdev->driver->get_update_mode(dssdev) !=
1347 OMAP_DSS_UPDATE_AUTO;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001348 }
1349
1350 /* XXX TODO: Try to get fifomerge working. The problem is that it
1351 * affects both managers, not individually but at the same time. This
1352 * means the change has to be well synchronized. I guess the proper way
1353 * is to have a two step process for fifo merge:
1354 * fifomerge enable:
1355 * 1. disable other planes, leaving one plane enabled
1356 * 2. wait until the planes are disabled on HW
1357 * 3. config merged fifo thresholds, enable fifomerge
1358 * fifomerge disable:
1359 * 1. config unmerged fifo thresholds, disable fifomerge
1360 * 2. wait until fifo changes are in HW
1361 * 3. enable planes
1362 */
1363 use_fifomerge = false;
1364
1365 /* Configure overlay fifos */
1366 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1367 struct omap_dss_device *dssdev;
1368 u32 size;
1369
1370 ovl = omap_dss_get_overlay(i);
1371
1372 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1373 continue;
1374
1375 oc = &dss_cache.overlay_cache[ovl->id];
1376
1377 if (!oc->enabled)
1378 continue;
1379
1380 dssdev = ovl->manager->device;
1381
1382 size = dispc_get_plane_fifo_size(ovl->id);
1383 if (use_fifomerge)
1384 size *= 3;
1385
1386 switch (dssdev->type) {
1387 case OMAP_DISPLAY_TYPE_DPI:
1388 case OMAP_DISPLAY_TYPE_DBI:
1389 case OMAP_DISPLAY_TYPE_SDI:
1390 case OMAP_DISPLAY_TYPE_VENC:
Mythri P Kb1196012011-03-08 17:15:54 +05301391 case OMAP_DISPLAY_TYPE_HDMI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001392 default_get_overlay_fifo_thresholds(ovl->id, size,
1393 &oc->burst_size, &oc->fifo_low,
1394 &oc->fifo_high);
1395 break;
1396#ifdef CONFIG_OMAP2_DSS_DSI
1397 case OMAP_DISPLAY_TYPE_DSI:
1398 dsi_get_overlay_fifo_thresholds(ovl->id, size,
1399 &oc->burst_size, &oc->fifo_low,
1400 &oc->fifo_high);
1401 break;
1402#endif
1403 default:
1404 BUG();
1405 }
1406 }
1407
1408 r = 0;
Archit Taneja6af9cd12011-01-31 16:27:44 +00001409 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001410 if (!dss_cache.irq_enabled) {
Sumit Semwal18faa1b2010-12-02 11:27:14 +00001411 u32 mask;
1412
1413 mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1414 DISPC_IRQ_EVSYNC_EVEN;
1415 if (dss_has_feature(FEAT_MGR_LCD2))
1416 mask |= DISPC_IRQ_VSYNC2;
1417
1418 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001419 dss_cache.irq_enabled = true;
1420 }
1421 configure_dispc();
Archit Taneja6af9cd12011-01-31 16:27:44 +00001422 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001423
1424 spin_unlock_irqrestore(&dss_cache.lock, flags);
1425
1426 return r;
1427}
1428
1429static int dss_check_manager(struct omap_overlay_manager *mgr)
1430{
1431 /* OMAP supports only graphics source transparency color key and alpha
1432 * blending simultaneously. See TRM 15.4.2.4.2.2 Alpha Mode */
1433
1434 if (mgr->info.alpha_enabled && mgr->info.trans_enabled &&
1435 mgr->info.trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST)
1436 return -EINVAL;
1437
1438 return 0;
1439}
1440
1441static int omap_dss_mgr_set_info(struct omap_overlay_manager *mgr,
1442 struct omap_overlay_manager_info *info)
1443{
1444 int r;
1445 struct omap_overlay_manager_info old_info;
1446
1447 old_info = mgr->info;
1448 mgr->info = *info;
1449
1450 r = dss_check_manager(mgr);
1451 if (r) {
1452 mgr->info = old_info;
1453 return r;
1454 }
1455
1456 mgr->info_dirty = true;
1457
1458 return 0;
1459}
1460
1461static void omap_dss_mgr_get_info(struct omap_overlay_manager *mgr,
1462 struct omap_overlay_manager_info *info)
1463{
1464 *info = mgr->info;
1465}
1466
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001467static int dss_mgr_enable(struct omap_overlay_manager *mgr)
1468{
1469 dispc_enable_channel(mgr->id, 1);
1470 return 0;
1471}
1472
1473static int dss_mgr_disable(struct omap_overlay_manager *mgr)
1474{
1475 dispc_enable_channel(mgr->id, 0);
1476 return 0;
1477}
1478
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001479static void omap_dss_add_overlay_manager(struct omap_overlay_manager *manager)
1480{
1481 ++num_managers;
1482 list_add_tail(&manager->list, &manager_list);
1483}
1484
1485int dss_init_overlay_managers(struct platform_device *pdev)
1486{
1487 int i, r;
1488
1489 spin_lock_init(&dss_cache.lock);
1490
1491 INIT_LIST_HEAD(&manager_list);
1492
1493 num_managers = 0;
1494
Archit Tanejaa0acb552010-09-15 19:20:00 +05301495 for (i = 0; i < dss_feat_get_num_mgrs(); ++i) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001496 struct omap_overlay_manager *mgr;
1497 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1498
1499 BUG_ON(mgr == NULL);
1500
1501 switch (i) {
1502 case 0:
1503 mgr->name = "lcd";
1504 mgr->id = OMAP_DSS_CHANNEL_LCD;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001505 break;
1506 case 1:
1507 mgr->name = "tv";
1508 mgr->id = OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001509 break;
Sumit Semwal18faa1b2010-12-02 11:27:14 +00001510 case 2:
1511 mgr->name = "lcd2";
1512 mgr->id = OMAP_DSS_CHANNEL_LCD2;
1513 break;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001514 }
1515
1516 mgr->set_device = &omap_dss_set_device;
1517 mgr->unset_device = &omap_dss_unset_device;
1518 mgr->apply = &omap_dss_mgr_apply;
1519 mgr->set_manager_info = &omap_dss_mgr_set_info;
1520 mgr->get_manager_info = &omap_dss_mgr_get_info;
1521 mgr->wait_for_go = &dss_mgr_wait_for_go;
Tomi Valkeinen3f71cbe2010-01-08 17:06:04 +02001522 mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001523
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001524 mgr->enable = &dss_mgr_enable;
1525 mgr->disable = &dss_mgr_disable;
1526
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001527 mgr->caps = OMAP_DSS_OVL_MGR_CAP_DISPC;
Archit Tanejaa0acb552010-09-15 19:20:00 +05301528 mgr->supported_displays =
1529 dss_feat_get_supported_displays(mgr->id);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001530
1531 dss_overlay_setup_dispc_manager(mgr);
1532
1533 omap_dss_add_overlay_manager(mgr);
1534
1535 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1536 &pdev->dev.kobj, "manager%d", i);
1537
1538 if (r) {
1539 DSSERR("failed to create sysfs file\n");
1540 continue;
1541 }
1542 }
1543
1544#ifdef L4_EXAMPLE
1545 {
1546 int omap_dss_mgr_apply_l4(struct omap_overlay_manager *mgr)
1547 {
1548 DSSDBG("omap_dss_mgr_apply_l4(%s)\n", mgr->name);
1549
1550 return 0;
1551 }
1552
1553 struct omap_overlay_manager *mgr;
1554 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1555
1556 BUG_ON(mgr == NULL);
1557
1558 mgr->name = "l4";
1559 mgr->supported_displays =
1560 OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI;
1561
1562 mgr->set_device = &omap_dss_set_device;
1563 mgr->unset_device = &omap_dss_unset_device;
1564 mgr->apply = &omap_dss_mgr_apply_l4;
1565 mgr->set_manager_info = &omap_dss_mgr_set_info;
1566 mgr->get_manager_info = &omap_dss_mgr_get_info;
1567
1568 dss_overlay_setup_l4_manager(mgr);
1569
1570 omap_dss_add_overlay_manager(mgr);
1571
1572 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1573 &pdev->dev.kobj, "managerl4");
1574
1575 if (r)
1576 DSSERR("failed to create sysfs file\n");
1577 }
1578#endif
1579
1580 return 0;
1581}
1582
1583void dss_uninit_overlay_managers(struct platform_device *pdev)
1584{
1585 struct omap_overlay_manager *mgr;
1586
1587 while (!list_empty(&manager_list)) {
1588 mgr = list_first_entry(&manager_list,
1589 struct omap_overlay_manager, list);
1590 list_del(&mgr->list);
1591 kobject_del(&mgr->kobj);
1592 kobject_put(&mgr->kobj);
1593 kfree(mgr);
1594 }
1595
1596 num_managers = 0;
1597}
1598
1599int omap_dss_get_num_overlay_managers(void)
1600{
1601 return num_managers;
1602}
1603EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
1604
1605struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
1606{
1607 int i = 0;
1608 struct omap_overlay_manager *mgr;
1609
1610 list_for_each_entry(mgr, &manager_list, list) {
1611 if (i++ == num)
1612 return mgr;
1613 }
1614
1615 return NULL;
1616}
1617EXPORT_SYMBOL(omap_dss_get_overlay_manager);
1618