blob: e2eaed2e9172a37004c385ec51868345cbccea0a [file] [log] [blame]
Tomi Valkeinen58f255482011-11-04 09:48:54 +02001/*
2 * Copyright (C) 2011 Texas Instruments
3 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#define DSS_SUBSYS_NAME "APPLY"
19
20#include <linux/kernel.h>
21#include <linux/slab.h>
22#include <linux/spinlock.h>
23#include <linux/jiffies.h>
24
25#include <video/omapdss.h>
26
27#include "dss.h"
28#include "dss_features.h"
29
30/*
31 * We have 4 levels of cache for the dispc settings. First two are in SW and
32 * the latter two in HW.
33 *
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020034 * set_info()
35 * v
Tomi Valkeinen58f255482011-11-04 09:48:54 +020036 * +--------------------+
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020037 * | user_info |
Tomi Valkeinen58f255482011-11-04 09:48:54 +020038 * +--------------------+
39 * v
40 * apply()
41 * v
42 * +--------------------+
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +020043 * | info |
Tomi Valkeinen58f255482011-11-04 09:48:54 +020044 * +--------------------+
45 * v
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +020046 * write_regs()
Tomi Valkeinen58f255482011-11-04 09:48:54 +020047 * v
48 * +--------------------+
49 * | shadow registers |
50 * +--------------------+
51 * v
52 * VFP or lcd/digit_enable
53 * v
54 * +--------------------+
55 * | registers |
56 * +--------------------+
57 */
58
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +020059struct ovl_priv_data {
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +020060
61 bool user_info_dirty;
62 struct omap_overlay_info user_info;
63
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020064 bool info_dirty;
Tomi Valkeinen58f255482011-11-04 09:48:54 +020065 struct omap_overlay_info info;
66
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020067 bool shadow_info_dirty;
68
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +020069 bool extra_info_dirty;
70 bool shadow_extra_info_dirty;
71
72 bool enabled;
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +020073 enum omap_channel channel;
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +020074 u32 fifo_low, fifo_high;
Tomi Valkeinen58f255482011-11-04 09:48:54 +020075};
76
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +020077struct mgr_priv_data {
Tomi Valkeinen388c4c62011-11-16 13:58:07 +020078
79 bool user_info_dirty;
80 struct omap_overlay_manager_info user_info;
81
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020082 bool info_dirty;
Tomi Valkeinen58f255482011-11-04 09:48:54 +020083 struct omap_overlay_manager_info info;
84
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020085 bool shadow_info_dirty;
86
Tomi Valkeinen43a972d2011-11-15 15:04:25 +020087 /* If true, GO bit is up and shadow registers cannot be written.
88 * Never true for manual update displays */
89 bool busy;
90
Tomi Valkeinen34861372011-11-18 15:43:29 +020091 /* If true, dispc output is enabled */
92 bool updating;
93
Tomi Valkeinenbf213522011-11-15 14:43:53 +020094 /* If true, a display is enabled using this manager */
95 bool enabled;
Tomi Valkeinen58f255482011-11-04 09:48:54 +020096};
97
98static struct {
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +020099 struct ovl_priv_data ovl_priv_data_array[MAX_DSS_OVERLAYS];
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200100 struct mgr_priv_data mgr_priv_data_array[MAX_DSS_MANAGERS];
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200101
102 bool irq_enabled;
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200103} dss_data;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200104
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200105/* protects dss_data */
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200106static spinlock_t data_lock;
Tomi Valkeinen5558db32011-11-15 14:28:48 +0200107/* lock for blocking functions */
108static DEFINE_MUTEX(apply_lock);
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200109static DECLARE_COMPLETION(extra_updated_completion);
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200110
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200111static void dss_register_vsync_isr(void);
112
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200113static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl)
114{
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200115 return &dss_data.ovl_priv_data_array[ovl->id];
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200116}
117
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200118static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr)
119{
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200120 return &dss_data.mgr_priv_data_array[mgr->id];
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200121}
122
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200123void dss_apply_init(void)
124{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200125 const int num_ovls = dss_feat_get_num_ovls();
126 int i;
127
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200128 spin_lock_init(&data_lock);
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200129
130 for (i = 0; i < num_ovls; ++i) {
131 struct ovl_priv_data *op;
132
133 op = &dss_data.ovl_priv_data_array[i];
134
135 op->info.global_alpha = 255;
136
137 switch (i) {
138 case 0:
139 op->info.zorder = 0;
140 break;
141 case 1:
142 op->info.zorder =
143 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 3 : 0;
144 break;
145 case 2:
146 op->info.zorder =
147 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 2 : 0;
148 break;
149 case 3:
150 op->info.zorder =
151 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 1 : 0;
152 break;
153 }
154
155 op->user_info = op->info;
156 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200157}
158
159static bool ovl_manual_update(struct omap_overlay *ovl)
160{
161 return ovl->manager->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
162}
163
164static bool mgr_manual_update(struct omap_overlay_manager *mgr)
165{
166 return mgr->device->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
167}
168
Tomi Valkeinen39518352011-11-17 17:35:28 +0200169/* Check if overlay parameters are compatible with display */
170static int dss_ovl_check(struct omap_overlay *ovl,
171 struct omap_overlay_info *info, struct omap_dss_device *dssdev)
172{
173 u16 outw, outh;
174 u16 dw, dh;
175
176 if (dssdev == NULL)
177 return 0;
178
179 dssdev->driver->get_resolution(dssdev, &dw, &dh);
180
181 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
182 outw = info->width;
183 outh = info->height;
184 } else {
185 if (info->out_width == 0)
186 outw = info->width;
187 else
188 outw = info->out_width;
189
190 if (info->out_height == 0)
191 outh = info->height;
192 else
193 outh = info->out_height;
194 }
195
196 if (dw < info->pos_x + outw) {
197 DSSERR("overlay %d horizontally not inside the display area "
198 "(%d + %d >= %d)\n",
199 ovl->id, info->pos_x, outw, dw);
200 return -EINVAL;
201 }
202
203 if (dh < info->pos_y + outh) {
204 DSSERR("overlay %d vertically not inside the display area "
205 "(%d + %d >= %d)\n",
206 ovl->id, info->pos_y, outh, dh);
207 return -EINVAL;
208 }
209
210 return 0;
211}
212
213static int dss_mgr_check_zorder(struct omap_overlay_manager *mgr,
214 struct omap_overlay_info **overlay_infos)
215{
216 struct omap_overlay *ovl1, *ovl2;
217 struct ovl_priv_data *op1, *op2;
218 struct omap_overlay_info *info1, *info2;
219
220 list_for_each_entry(ovl1, &mgr->overlays, list) {
221 op1 = get_ovl_priv(ovl1);
222 info1 = overlay_infos[ovl1->id];
223
224 if (info1 == NULL)
225 continue;
226
227 list_for_each_entry(ovl2, &mgr->overlays, list) {
228 if (ovl1 == ovl2)
229 continue;
230
231 op2 = get_ovl_priv(ovl2);
232 info2 = overlay_infos[ovl2->id];
233
234 if (info2 == NULL)
235 continue;
236
237 if (info1->zorder == info2->zorder) {
238 DSSERR("overlays %d and %d have the same "
239 "zorder %d\n",
240 ovl1->id, ovl2->id, info1->zorder);
241 return -EINVAL;
242 }
243 }
244 }
245
246 return 0;
247}
248
249static int dss_mgr_check(struct omap_overlay_manager *mgr,
250 struct omap_dss_device *dssdev,
251 struct omap_overlay_manager_info *info,
252 struct omap_overlay_info **overlay_infos)
253{
254 struct omap_overlay *ovl;
255 int r;
256
257 if (dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) {
258 r = dss_mgr_check_zorder(mgr, overlay_infos);
259 if (r)
260 return r;
261 }
262
263 list_for_each_entry(ovl, &mgr->overlays, list) {
264 struct omap_overlay_info *oi;
265 int r;
266
267 oi = overlay_infos[ovl->id];
268
269 if (oi == NULL)
270 continue;
271
272 r = dss_ovl_check(ovl, oi, dssdev);
273 if (r)
274 return r;
275 }
276
277 return 0;
278}
279static int dss_check_settings_low(struct omap_overlay_manager *mgr,
280 struct omap_dss_device *dssdev, bool applying)
281{
282 struct omap_overlay_info *oi;
283 struct omap_overlay_manager_info *mi;
284 struct omap_overlay *ovl;
285 struct omap_overlay_info *ois[MAX_DSS_OVERLAYS];
286 struct ovl_priv_data *op;
287 struct mgr_priv_data *mp;
288
289 mp = get_mgr_priv(mgr);
290
291 if (applying && mp->user_info_dirty)
292 mi = &mp->user_info;
293 else
294 mi = &mp->info;
295
296 /* collect the infos to be tested into the array */
297 list_for_each_entry(ovl, &mgr->overlays, list) {
298 op = get_ovl_priv(ovl);
299
300 if (!op->enabled)
301 oi = NULL;
302 else if (applying && op->user_info_dirty)
303 oi = &op->user_info;
304 else
305 oi = &op->info;
306
307 ois[ovl->id] = oi;
308 }
309
310 return dss_mgr_check(mgr, dssdev, mi, ois);
311}
312
313/*
314 * check manager and overlay settings using overlay_info from data->info
315 */
316static int dss_check_settings(struct omap_overlay_manager *mgr,
317 struct omap_dss_device *dssdev)
318{
319 return dss_check_settings_low(mgr, dssdev, false);
320}
321
322/*
323 * check manager and overlay settings using overlay_info from ovl->info if
324 * dirty and from data->info otherwise
325 */
326static int dss_check_settings_apply(struct omap_overlay_manager *mgr,
327 struct omap_dss_device *dssdev)
328{
329 return dss_check_settings_low(mgr, dssdev, true);
330}
331
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200332static bool need_isr(void)
333{
334 const int num_mgrs = dss_feat_get_num_mgrs();
335 int i;
336
337 for (i = 0; i < num_mgrs; ++i) {
338 struct omap_overlay_manager *mgr;
339 struct mgr_priv_data *mp;
340 struct omap_overlay *ovl;
341
342 mgr = omap_dss_get_overlay_manager(i);
343 mp = get_mgr_priv(mgr);
344
345 if (!mp->enabled)
346 continue;
347
Tomi Valkeinen34861372011-11-18 15:43:29 +0200348 if (mgr_manual_update(mgr)) {
349 /* to catch FRAMEDONE */
350 if (mp->updating)
351 return true;
352 } else {
353 /* to catch GO bit going down */
354 if (mp->busy)
355 return true;
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200356
357 /* to write new values to registers */
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200358 if (mp->info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200359 return true;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200360
Tomi Valkeinen9f808952011-11-25 17:26:13 +0200361 /* to set GO bit */
362 if (mp->shadow_info_dirty)
363 return true;
364
Tomi Valkeinen34861372011-11-18 15:43:29 +0200365 list_for_each_entry(ovl, &mgr->overlays, list) {
366 struct ovl_priv_data *op;
367
368 op = get_ovl_priv(ovl);
369
Tomi Valkeinen9f808952011-11-25 17:26:13 +0200370 /*
371 * NOTE: we check extra_info flags even for
372 * disabled overlays, as extra_infos need to be
373 * always written.
374 */
375
376 /* to write new values to registers */
377 if (op->extra_info_dirty)
378 return true;
379
380 /* to set GO bit */
381 if (op->shadow_extra_info_dirty)
382 return true;
383
Tomi Valkeinen34861372011-11-18 15:43:29 +0200384 if (!op->enabled)
385 continue;
386
387 /* to write new values to registers */
Tomi Valkeinen9f808952011-11-25 17:26:13 +0200388 if (op->info_dirty)
389 return true;
390
391 /* to set GO bit */
392 if (op->shadow_info_dirty)
Tomi Valkeinen34861372011-11-18 15:43:29 +0200393 return true;
394 }
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200395 }
396 }
397
398 return false;
399}
400
401static bool need_go(struct omap_overlay_manager *mgr)
402{
403 struct omap_overlay *ovl;
404 struct mgr_priv_data *mp;
405 struct ovl_priv_data *op;
406
407 mp = get_mgr_priv(mgr);
408
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200409 if (mp->shadow_info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200410 return true;
411
412 list_for_each_entry(ovl, &mgr->overlays, list) {
413 op = get_ovl_priv(ovl);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200414 if (op->shadow_info_dirty || op->shadow_extra_info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200415 return true;
416 }
417
418 return false;
419}
420
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200421/* returns true if an extra_info field is currently being updated */
422static bool extra_info_update_ongoing(void)
423{
424 const int num_ovls = omap_dss_get_num_overlays();
425 struct ovl_priv_data *op;
426 struct omap_overlay *ovl;
427 struct mgr_priv_data *mp;
428 int i;
429 bool eid;
430
431 for (i = 0; i < num_ovls; ++i) {
432 ovl = omap_dss_get_overlay(i);
433 op = get_ovl_priv(ovl);
434
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200435 mp = get_mgr_priv(ovl->manager);
436
437 if (!mp->enabled)
438 continue;
439
440 eid = op->extra_info_dirty || op->shadow_extra_info_dirty;
441
442 if (!eid)
443 continue;
444
445 if (ovl_manual_update(ovl) && !mp->updating)
446 continue;
447
448 return true;
449 }
450
451 return false;
452}
453
454/* wait until no extra_info updates are pending */
455static void wait_pending_extra_info_updates(void)
456{
457 bool updating;
458 unsigned long flags;
459 unsigned long t;
460
461 spin_lock_irqsave(&data_lock, flags);
462
463 updating = extra_info_update_ongoing();
464
465 if (!updating) {
466 spin_unlock_irqrestore(&data_lock, flags);
467 return;
468 }
469
470 init_completion(&extra_updated_completion);
471
472 spin_unlock_irqrestore(&data_lock, flags);
473
474 t = msecs_to_jiffies(500);
475 wait_for_completion_timeout(&extra_updated_completion, t);
476
477 updating = extra_info_update_ongoing();
478
479 WARN_ON(updating);
480}
481
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200482int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
483{
484 unsigned long timeout = msecs_to_jiffies(500);
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200485 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200486 u32 irq;
487 int r;
488 int i;
489 struct omap_dss_device *dssdev = mgr->device;
490
491 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
492 return 0;
493
494 if (mgr_manual_update(mgr))
495 return 0;
496
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200497 irq = dispc_mgr_get_vsync_irq(mgr->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200498
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200499 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200500 i = 0;
501 while (1) {
502 unsigned long flags;
503 bool shadow_dirty, dirty;
504
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200505 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200506 dirty = mp->info_dirty;
507 shadow_dirty = mp->shadow_info_dirty;
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200508 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200509
510 if (!dirty && !shadow_dirty) {
511 r = 0;
512 break;
513 }
514
515 /* 4 iterations is the worst case:
516 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
517 * 2 - first VSYNC, dirty = true
518 * 3 - dirty = false, shadow_dirty = true
519 * 4 - shadow_dirty = false */
520 if (i++ == 3) {
521 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
522 mgr->id);
523 r = 0;
524 break;
525 }
526
527 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
528 if (r == -ERESTARTSYS)
529 break;
530
531 if (r) {
532 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
533 break;
534 }
535 }
536
537 return r;
538}
539
540int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
541{
542 unsigned long timeout = msecs_to_jiffies(500);
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200543 struct ovl_priv_data *op;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200544 struct omap_dss_device *dssdev;
545 u32 irq;
546 int r;
547 int i;
548
549 if (!ovl->manager)
550 return 0;
551
552 dssdev = ovl->manager->device;
553
554 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
555 return 0;
556
557 if (ovl_manual_update(ovl))
558 return 0;
559
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200560 irq = dispc_mgr_get_vsync_irq(ovl->manager->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200561
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200562 op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200563 i = 0;
564 while (1) {
565 unsigned long flags;
566 bool shadow_dirty, dirty;
567
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200568 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200569 dirty = op->info_dirty;
570 shadow_dirty = op->shadow_info_dirty;
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200571 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200572
573 if (!dirty && !shadow_dirty) {
574 r = 0;
575 break;
576 }
577
578 /* 4 iterations is the worst case:
579 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
580 * 2 - first VSYNC, dirty = true
581 * 3 - dirty = false, shadow_dirty = true
582 * 4 - shadow_dirty = false */
583 if (i++ == 3) {
584 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
585 ovl->id);
586 r = 0;
587 break;
588 }
589
590 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
591 if (r == -ERESTARTSYS)
592 break;
593
594 if (r) {
595 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
596 break;
597 }
598 }
599
600 return r;
601}
602
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200603static void dss_ovl_write_regs(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200604{
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200605 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200606 struct omap_overlay_info *oi;
607 bool ilace, replication;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200608 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200609 int r;
610
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200611 DSSDBGF("%d", ovl->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200612
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200613 if (!op->enabled || !op->info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200614 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200615
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200616 oi = &op->info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200617
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200618 replication = dss_use_replication(ovl->manager->device, oi->color_mode);
619
620 ilace = ovl->manager->device->type == OMAP_DISPLAY_TYPE_VENC;
621
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200622 r = dispc_ovl_setup(ovl->id, oi, ilace, replication);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200623 if (r) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200624 /*
625 * We can't do much here, as this function can be called from
626 * vsync interrupt.
627 */
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200628 DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id);
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200629
630 /* This will leave fifo configurations in a nonoptimal state */
631 op->enabled = false;
632 dispc_ovl_enable(ovl->id, false);
633 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200634 }
635
Tomi Valkeinen34861372011-11-18 15:43:29 +0200636 mp = get_mgr_priv(ovl->manager);
637
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200638 op->info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200639 if (mp->updating)
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200640 op->shadow_info_dirty = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200641}
642
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200643static void dss_ovl_write_regs_extra(struct omap_overlay *ovl)
644{
645 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinen34861372011-11-18 15:43:29 +0200646 struct mgr_priv_data *mp;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200647
648 DSSDBGF("%d", ovl->id);
649
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200650 if (!op->extra_info_dirty)
651 return;
652
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200653 /* note: write also when op->enabled == false, so that the ovl gets
654 * disabled */
655
656 dispc_ovl_enable(ovl->id, op->enabled);
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +0200657 dispc_ovl_set_channel_out(ovl->id, op->channel);
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200658 dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high);
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200659
Tomi Valkeinen34861372011-11-18 15:43:29 +0200660 mp = get_mgr_priv(ovl->manager);
661
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200662 op->extra_info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200663 if (mp->updating)
664 op->shadow_extra_info_dirty = true;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200665}
666
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200667static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200668{
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200669 struct mgr_priv_data *mp = get_mgr_priv(mgr);
670 struct omap_overlay *ovl;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200671
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200672 DSSDBGF("%d", mgr->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200673
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200674 if (!mp->enabled)
675 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200676
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200677 WARN_ON(mp->busy);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200678
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200679 /* Commit overlay settings */
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200680 list_for_each_entry(ovl, &mgr->overlays, list) {
681 dss_ovl_write_regs(ovl);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200682 dss_ovl_write_regs_extra(ovl);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200683 }
684
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200685 if (mp->info_dirty) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200686 dispc_mgr_setup(mgr->id, &mp->info);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200687
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200688 mp->info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200689 if (mp->updating)
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200690 mp->shadow_info_dirty = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200691 }
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200692}
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200693
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200694static void dss_write_regs(void)
695{
696 const int num_mgrs = omap_dss_get_num_overlay_managers();
697 int i;
698
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200699 for (i = 0; i < num_mgrs; ++i) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200700 struct omap_overlay_manager *mgr;
701 struct mgr_priv_data *mp;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200702 int r;
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200703
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200704 mgr = omap_dss_get_overlay_manager(i);
705 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200706
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200707 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200708 continue;
709
Tomi Valkeinen39518352011-11-17 17:35:28 +0200710 r = dss_check_settings(mgr, mgr->device);
711 if (r) {
712 DSSERR("cannot write registers for manager %s: "
713 "illegal configuration\n", mgr->name);
714 continue;
715 }
716
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200717 dss_mgr_write_regs(mgr);
718
719 if (need_go(mgr)) {
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200720 mp->busy = true;
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200721
722 if (!dss_data.irq_enabled && need_isr())
723 dss_register_vsync_isr();
724
725 dispc_mgr_go(mgr->id);
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200726 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200727 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200728}
729
730void dss_mgr_start_update(struct omap_overlay_manager *mgr)
731{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200732 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200733 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200734 int r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200735
736 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200737
Tomi Valkeinen34861372011-11-18 15:43:29 +0200738 WARN_ON(mp->updating);
739
Tomi Valkeinen39518352011-11-17 17:35:28 +0200740 r = dss_check_settings(mgr, mgr->device);
741 if (r) {
742 DSSERR("cannot start manual update: illegal configuration\n");
743 spin_unlock_irqrestore(&data_lock, flags);
744 return;
745 }
746
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200747 dss_mgr_write_regs(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200748
Tomi Valkeinen34861372011-11-18 15:43:29 +0200749 mp->updating = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200750
Tomi Valkeinen34861372011-11-18 15:43:29 +0200751 if (!dss_data.irq_enabled && need_isr())
752 dss_register_vsync_isr();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200753
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200754 dispc_mgr_enable(mgr->id, true);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200755
756 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200757}
758
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200759static void dss_apply_irq_handler(void *data, u32 mask);
760
761static void dss_register_vsync_isr(void)
762{
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200763 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200764 u32 mask;
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200765 int r, i;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200766
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200767 mask = 0;
768 for (i = 0; i < num_mgrs; ++i)
769 mask |= dispc_mgr_get_vsync_irq(i);
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200770
Tomi Valkeinen34861372011-11-18 15:43:29 +0200771 for (i = 0; i < num_mgrs; ++i)
772 mask |= dispc_mgr_get_framedone_irq(i);
773
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200774 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
775 WARN_ON(r);
776
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200777 dss_data.irq_enabled = true;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200778}
779
780static void dss_unregister_vsync_isr(void)
781{
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200782 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200783 u32 mask;
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200784 int r, i;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200785
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200786 mask = 0;
787 for (i = 0; i < num_mgrs; ++i)
788 mask |= dispc_mgr_get_vsync_irq(i);
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200789
Tomi Valkeinen34861372011-11-18 15:43:29 +0200790 for (i = 0; i < num_mgrs; ++i)
791 mask |= dispc_mgr_get_framedone_irq(i);
792
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200793 r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask);
794 WARN_ON(r);
795
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200796 dss_data.irq_enabled = false;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200797}
798
Tomi Valkeinen76098932011-11-16 12:03:22 +0200799static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200800{
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200801 struct omap_overlay *ovl;
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200802 struct mgr_priv_data *mp;
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200803 struct ovl_priv_data *op;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200804
805 mp = get_mgr_priv(mgr);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200806 mp->shadow_info_dirty = false;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200807
808 list_for_each_entry(ovl, &mgr->overlays, list) {
809 op = get_ovl_priv(ovl);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200810 op->shadow_info_dirty = false;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200811 op->shadow_extra_info_dirty = false;
812 }
813}
814
815static void dss_apply_irq_handler(void *data, u32 mask)
816{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200817 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200818 int i;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200819 bool extra_updating;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200820
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200821 spin_lock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200822
Tomi Valkeinen76098932011-11-16 12:03:22 +0200823 /* clear busy, updating flags, shadow_dirty flags */
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200824 for (i = 0; i < num_mgrs; i++) {
Tomi Valkeinen76098932011-11-16 12:03:22 +0200825 struct omap_overlay_manager *mgr;
826 struct mgr_priv_data *mp;
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200827 bool was_updating;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200828
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200829 mgr = omap_dss_get_overlay_manager(i);
830 mp = get_mgr_priv(mgr);
831
Tomi Valkeinen76098932011-11-16 12:03:22 +0200832 if (!mp->enabled)
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200833 continue;
834
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200835 was_updating = mp->updating;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200836 mp->updating = dispc_mgr_is_enabled(i);
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200837
Tomi Valkeinen76098932011-11-16 12:03:22 +0200838 if (!mgr_manual_update(mgr)) {
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200839 bool was_busy = mp->busy;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200840 mp->busy = dispc_mgr_go_busy(i);
841
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200842 if (was_busy && !mp->busy)
Tomi Valkeinen76098932011-11-16 12:03:22 +0200843 mgr_clear_shadow_dirty(mgr);
844 } else {
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200845 if (was_updating && !mp->updating)
Tomi Valkeinen76098932011-11-16 12:03:22 +0200846 mgr_clear_shadow_dirty(mgr);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200847 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200848 }
849
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200850 dss_write_regs();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200851
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200852 extra_updating = extra_info_update_ongoing();
853 if (!extra_updating)
854 complete_all(&extra_updated_completion);
855
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200856 if (!need_isr())
857 dss_unregister_vsync_isr();
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200858
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200859 spin_unlock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200860}
861
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200862static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200863{
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200864 struct ovl_priv_data *op;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200865
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200866 op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200867
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200868 if (!op->user_info_dirty)
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200869 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200870
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200871 op->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200872 op->info_dirty = true;
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200873 op->info = op->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200874}
875
876static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
877{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200878 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200879
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200880 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200881
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200882 if (!mp->user_info_dirty)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200883 return;
884
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200885 mp->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200886 mp->info_dirty = true;
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200887 mp->info = mp->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200888}
889
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200890int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
891{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200892 unsigned long flags;
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200893 struct omap_overlay *ovl;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200894 int r;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200895
896 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
897
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200898 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200899
Tomi Valkeinen39518352011-11-17 17:35:28 +0200900 r = dss_check_settings_apply(mgr, mgr->device);
901 if (r) {
902 spin_unlock_irqrestore(&data_lock, flags);
903 DSSERR("failed to apply settings: illegal configuration.\n");
904 return r;
905 }
906
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200907 /* Configure overlays */
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200908 list_for_each_entry(ovl, &mgr->overlays, list)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200909 omap_dss_mgr_apply_ovl(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200910
911 /* Configure manager */
912 omap_dss_mgr_apply_mgr(mgr);
913
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200914 dss_write_regs();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200915
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200916 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200917
Tomi Valkeinene70f98a2011-11-16 16:53:44 +0200918 return 0;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200919}
920
Tomi Valkeinen841c09c2011-11-16 15:25:53 +0200921static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
922{
923 struct ovl_priv_data *op;
924
925 op = get_ovl_priv(ovl);
926
927 if (op->enabled == enable)
928 return;
929
930 op->enabled = enable;
931 op->extra_info_dirty = true;
932}
933
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200934static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
935{
936 struct ovl_priv_data *op = get_ovl_priv(ovl);
937 struct omap_dss_device *dssdev;
938 u32 size, burst_size;
939 u32 fifo_low, fifo_high;
940
941 dssdev = ovl->manager->device;
942
943 size = dispc_ovl_get_fifo_size(ovl->id);
944
945 burst_size = dispc_ovl_get_burst_size(ovl->id);
946
947 switch (dssdev->type) {
948 case OMAP_DISPLAY_TYPE_DPI:
949 case OMAP_DISPLAY_TYPE_DBI:
950 case OMAP_DISPLAY_TYPE_SDI:
951 case OMAP_DISPLAY_TYPE_VENC:
952 case OMAP_DISPLAY_TYPE_HDMI:
953 default_get_overlay_fifo_thresholds(ovl->id, size,
954 burst_size, &fifo_low, &fifo_high);
955 break;
956#ifdef CONFIG_OMAP2_DSS_DSI
957 case OMAP_DISPLAY_TYPE_DSI:
958 dsi_get_overlay_fifo_thresholds(ovl->id, size,
959 burst_size, &fifo_low, &fifo_high);
960 break;
961#endif
962 default:
963 BUG();
964 }
965
966 op->fifo_low = fifo_low;
967 op->fifo_high = fifo_high;
968 op->extra_info_dirty = true;
969}
970
971static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
972{
973 struct omap_overlay *ovl;
974 struct ovl_priv_data *op;
975 struct mgr_priv_data *mp;
976
977 mp = get_mgr_priv(mgr);
978
979 if (!mp->enabled)
980 return;
981
982 list_for_each_entry(ovl, &mgr->overlays, list) {
983 op = get_ovl_priv(ovl);
984
985 if (!op->enabled)
986 continue;
987
988 dss_ovl_setup_fifo(ovl);
989 }
990}
991
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +0200992int dss_mgr_enable(struct omap_overlay_manager *mgr)
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200993{
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200994 struct mgr_priv_data *mp = get_mgr_priv(mgr);
995 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200996 int r;
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200997
Tomi Valkeinen5558db32011-11-15 14:28:48 +0200998 mutex_lock(&apply_lock);
999
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001000 if (mp->enabled)
1001 goto out;
1002
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001003 spin_lock_irqsave(&data_lock, flags);
1004
1005 mp->enabled = true;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001006 r = dss_check_settings(mgr, mgr->device);
1007 mp->enabled = false;
1008 if (r) {
1009 DSSERR("failed to enable manager %d: check_settings failed\n",
1010 mgr->id);
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001011 goto err;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001012 }
1013
1014 mp->enabled = true;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001015
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001016 dss_mgr_setup_fifos(mgr);
1017
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001018 dss_write_regs();
1019
Tomi Valkeinen34861372011-11-18 15:43:29 +02001020 if (!mgr_manual_update(mgr))
1021 mp->updating = true;
1022
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001023 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001024
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001025 if (!mgr_manual_update(mgr))
1026 dispc_mgr_enable(mgr->id, true);
1027
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001028out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001029 mutex_unlock(&apply_lock);
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001030
1031 return 0;
1032
1033err:
1034 spin_unlock_irqrestore(&data_lock, flags);
1035 mutex_unlock(&apply_lock);
1036 return r;
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001037}
1038
1039void dss_mgr_disable(struct omap_overlay_manager *mgr)
1040{
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001041 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1042 unsigned long flags;
1043
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001044 mutex_lock(&apply_lock);
1045
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001046 if (!mp->enabled)
1047 goto out;
1048
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02001049 if (!mgr_manual_update(mgr))
1050 dispc_mgr_enable(mgr->id, false);
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001051
1052 spin_lock_irqsave(&data_lock, flags);
1053
Tomi Valkeinen34861372011-11-18 15:43:29 +02001054 mp->updating = false;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001055 mp->enabled = false;
1056
1057 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001058
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001059out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001060 mutex_unlock(&apply_lock);
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001061}
1062
Tomi Valkeinenf17d04f2011-11-17 14:31:09 +02001063static int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
1064 const struct omap_overlay_manager_info *info)
1065{
1066 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
1067 /*
1068 * OMAP3 supports only graphics source transparency color key
1069 * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
1070 * Alpha Mode.
1071 */
1072 if (info->partial_alpha_enabled && info->trans_enabled
1073 && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
1074 DSSERR("check_manager: illegal transparency key\n");
1075 return -EINVAL;
1076 }
1077 }
1078
1079 return 0;
1080}
1081
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001082int dss_mgr_set_info(struct omap_overlay_manager *mgr,
1083 struct omap_overlay_manager_info *info)
1084{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001085 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001086 unsigned long flags;
Tomi Valkeinenf17d04f2011-11-17 14:31:09 +02001087 int r;
1088
1089 r = dss_mgr_simple_check(mgr, info);
1090 if (r)
1091 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001092
1093 spin_lock_irqsave(&data_lock, flags);
1094
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001095 mp->user_info = *info;
1096 mp->user_info_dirty = true;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001097
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001098 spin_unlock_irqrestore(&data_lock, flags);
1099
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001100 return 0;
1101}
1102
1103void dss_mgr_get_info(struct omap_overlay_manager *mgr,
1104 struct omap_overlay_manager_info *info)
1105{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001106 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001107 unsigned long flags;
1108
1109 spin_lock_irqsave(&data_lock, flags);
1110
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001111 *info = mp->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001112
1113 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001114}
1115
1116int dss_mgr_set_device(struct omap_overlay_manager *mgr,
1117 struct omap_dss_device *dssdev)
1118{
1119 int r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001120
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001121 mutex_lock(&apply_lock);
1122
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001123 if (dssdev->manager) {
1124 DSSERR("display '%s' already has a manager '%s'\n",
1125 dssdev->name, dssdev->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001126 r = -EINVAL;
1127 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001128 }
1129
1130 if ((mgr->supported_displays & dssdev->type) == 0) {
1131 DSSERR("display '%s' does not support manager '%s'\n",
1132 dssdev->name, mgr->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001133 r = -EINVAL;
1134 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001135 }
1136
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001137 dssdev->manager = mgr;
1138 mgr->device = dssdev;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001139
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001140 mutex_unlock(&apply_lock);
1141
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001142 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001143err:
1144 mutex_unlock(&apply_lock);
1145 return r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001146}
1147
1148int dss_mgr_unset_device(struct omap_overlay_manager *mgr)
1149{
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001150 int r;
1151
1152 mutex_lock(&apply_lock);
1153
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001154 if (!mgr->device) {
1155 DSSERR("failed to unset display, display not set.\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001156 r = -EINVAL;
1157 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001158 }
1159
1160 /*
1161 * Don't allow currently enabled displays to have the overlay manager
1162 * pulled out from underneath them
1163 */
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001164 if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED) {
1165 r = -EINVAL;
1166 goto err;
1167 }
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001168
1169 mgr->device->manager = NULL;
1170 mgr->device = NULL;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001171
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001172 mutex_unlock(&apply_lock);
1173
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001174 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001175err:
1176 mutex_unlock(&apply_lock);
1177 return r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001178}
1179
1180
Tomi Valkeinenfcc764d2011-11-17 14:26:48 +02001181static int dss_ovl_simple_check(struct omap_overlay *ovl,
1182 const struct omap_overlay_info *info)
1183{
1184 if (info->paddr == 0) {
1185 DSSERR("check_overlay: paddr cannot be 0\n");
1186 return -EINVAL;
1187 }
1188
1189 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
1190 if (info->out_width != 0 && info->width != info->out_width) {
1191 DSSERR("check_overlay: overlay %d doesn't support "
1192 "scaling\n", ovl->id);
1193 return -EINVAL;
1194 }
1195
1196 if (info->out_height != 0 && info->height != info->out_height) {
1197 DSSERR("check_overlay: overlay %d doesn't support "
1198 "scaling\n", ovl->id);
1199 return -EINVAL;
1200 }
1201 }
1202
1203 if ((ovl->supported_modes & info->color_mode) == 0) {
1204 DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
1205 ovl->id, info->color_mode);
1206 return -EINVAL;
1207 }
1208
1209 if (info->zorder >= omap_dss_get_num_overlays()) {
1210 DSSERR("check_overlay: zorder %d too high\n", info->zorder);
1211 return -EINVAL;
1212 }
1213
1214 return 0;
1215}
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001216
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001217int dss_ovl_set_info(struct omap_overlay *ovl,
1218 struct omap_overlay_info *info)
1219{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001220 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001221 unsigned long flags;
Tomi Valkeinenfcc764d2011-11-17 14:26:48 +02001222 int r;
1223
1224 r = dss_ovl_simple_check(ovl, info);
1225 if (r)
1226 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001227
1228 spin_lock_irqsave(&data_lock, flags);
1229
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001230 op->user_info = *info;
1231 op->user_info_dirty = true;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001232
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001233 spin_unlock_irqrestore(&data_lock, flags);
1234
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001235 return 0;
1236}
1237
1238void dss_ovl_get_info(struct omap_overlay *ovl,
1239 struct omap_overlay_info *info)
1240{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001241 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001242 unsigned long flags;
1243
1244 spin_lock_irqsave(&data_lock, flags);
1245
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001246 *info = op->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001247
1248 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001249}
1250
1251int dss_ovl_set_manager(struct omap_overlay *ovl,
1252 struct omap_overlay_manager *mgr)
1253{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001254 struct ovl_priv_data *op = get_ovl_priv(ovl);
1255 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001256 int r;
1257
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001258 if (!mgr)
1259 return -EINVAL;
1260
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001261 mutex_lock(&apply_lock);
1262
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001263 if (ovl->manager) {
1264 DSSERR("overlay '%s' already has a manager '%s'\n",
1265 ovl->name, ovl->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001266 r = -EINVAL;
1267 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001268 }
1269
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001270 spin_lock_irqsave(&data_lock, flags);
1271
1272 if (op->enabled) {
1273 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001274 DSSERR("overlay has to be disabled to change the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001275 r = -EINVAL;
1276 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001277 }
1278
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001279 op->channel = mgr->id;
1280 op->extra_info_dirty = true;
1281
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001282 ovl->manager = mgr;
1283 list_add_tail(&ovl->list, &mgr->overlays);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001284
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001285 spin_unlock_irqrestore(&data_lock, flags);
1286
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001287 /* XXX: When there is an overlay on a DSI manual update display, and
1288 * the overlay is first disabled, then moved to tv, and enabled, we
1289 * seem to get SYNC_LOST_DIGIT error.
1290 *
1291 * Waiting doesn't seem to help, but updating the manual update display
1292 * after disabling the overlay seems to fix this. This hints that the
1293 * overlay is perhaps somehow tied to the LCD output until the output
1294 * is updated.
1295 *
1296 * Userspace workaround for this is to update the LCD after disabling
1297 * the overlay, but before moving the overlay to TV.
1298 */
1299
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001300 mutex_unlock(&apply_lock);
1301
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001302 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001303err:
1304 mutex_unlock(&apply_lock);
1305 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001306}
1307
1308int dss_ovl_unset_manager(struct omap_overlay *ovl)
1309{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001310 struct ovl_priv_data *op = get_ovl_priv(ovl);
1311 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001312 int r;
1313
1314 mutex_lock(&apply_lock);
1315
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001316 if (!ovl->manager) {
1317 DSSERR("failed to detach overlay: manager not set\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001318 r = -EINVAL;
1319 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001320 }
1321
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001322 spin_lock_irqsave(&data_lock, flags);
1323
1324 if (op->enabled) {
1325 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001326 DSSERR("overlay has to be disabled to unset the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001327 r = -EINVAL;
1328 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001329 }
1330
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001331 op->channel = -1;
1332
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001333 ovl->manager = NULL;
1334 list_del(&ovl->list);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001335
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001336 spin_unlock_irqrestore(&data_lock, flags);
1337
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001338 mutex_unlock(&apply_lock);
1339
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001340 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001341err:
1342 mutex_unlock(&apply_lock);
1343 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001344}
1345
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001346bool dss_ovl_is_enabled(struct omap_overlay *ovl)
1347{
1348 struct ovl_priv_data *op = get_ovl_priv(ovl);
1349 unsigned long flags;
1350 bool e;
1351
1352 spin_lock_irqsave(&data_lock, flags);
1353
1354 e = op->enabled;
1355
1356 spin_unlock_irqrestore(&data_lock, flags);
1357
1358 return e;
1359}
1360
1361int dss_ovl_enable(struct omap_overlay *ovl)
1362{
1363 struct ovl_priv_data *op = get_ovl_priv(ovl);
1364 unsigned long flags;
1365 int r;
1366
1367 mutex_lock(&apply_lock);
1368
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001369 if (op->enabled) {
1370 r = 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001371 goto err1;
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001372 }
1373
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001374 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1375 r = -EINVAL;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001376 goto err1;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001377 }
1378
1379 spin_lock_irqsave(&data_lock, flags);
1380
Tomi Valkeinen39518352011-11-17 17:35:28 +02001381 op->enabled = true;
1382 r = dss_check_settings(ovl->manager, ovl->manager->device);
1383 op->enabled = false;
1384 if (r) {
1385 DSSERR("failed to enable overlay %d: check_settings failed\n",
1386 ovl->id);
1387 goto err2;
1388 }
1389
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001390 dss_apply_ovl_enable(ovl, true);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001391
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001392 dss_ovl_setup_fifo(ovl);
1393
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001394 dss_write_regs();
1395
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001396 spin_unlock_irqrestore(&data_lock, flags);
1397
1398 mutex_unlock(&apply_lock);
1399
1400 return 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001401err2:
1402 spin_unlock_irqrestore(&data_lock, flags);
1403err1:
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001404 mutex_unlock(&apply_lock);
1405 return r;
1406}
1407
1408int dss_ovl_disable(struct omap_overlay *ovl)
1409{
1410 struct ovl_priv_data *op = get_ovl_priv(ovl);
1411 unsigned long flags;
1412 int r;
1413
1414 mutex_lock(&apply_lock);
1415
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001416 if (!op->enabled) {
1417 r = 0;
1418 goto err;
1419 }
1420
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001421 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1422 r = -EINVAL;
1423 goto err;
1424 }
1425
1426 spin_lock_irqsave(&data_lock, flags);
1427
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001428 dss_apply_ovl_enable(ovl, false);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001429
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001430 dss_write_regs();
1431
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001432 spin_unlock_irqrestore(&data_lock, flags);
1433
1434 mutex_unlock(&apply_lock);
1435
1436 return 0;
1437
1438err:
1439 mutex_unlock(&apply_lock);
1440 return r;
1441}
1442