blob: 98fef08da3baad16e026f4c0368ccefd1153fec9 [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;
827
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200828 mgr = omap_dss_get_overlay_manager(i);
829 mp = get_mgr_priv(mgr);
830
Tomi Valkeinen76098932011-11-16 12:03:22 +0200831 if (!mp->enabled)
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200832 continue;
833
Tomi Valkeinen76098932011-11-16 12:03:22 +0200834 mp->updating = dispc_mgr_is_enabled(i);
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200835
Tomi Valkeinen76098932011-11-16 12:03:22 +0200836 if (!mgr_manual_update(mgr)) {
837 mp->busy = dispc_mgr_go_busy(i);
838
839 if (!mp->busy)
840 mgr_clear_shadow_dirty(mgr);
841 } else {
842 if (!mp->updating)
843 mgr_clear_shadow_dirty(mgr);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200844 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200845 }
846
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200847 dss_write_regs();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200848
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200849 extra_updating = extra_info_update_ongoing();
850 if (!extra_updating)
851 complete_all(&extra_updated_completion);
852
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200853 if (!need_isr())
854 dss_unregister_vsync_isr();
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200855
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200856 spin_unlock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200857}
858
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200859static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200860{
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200861 struct ovl_priv_data *op;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200862
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200863 op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200864
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200865 if (!op->user_info_dirty)
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200866 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200867
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200868 op->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200869 op->info_dirty = true;
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200870 op->info = op->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200871}
872
873static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
874{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200875 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200876
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200877 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200878
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200879 if (!mp->user_info_dirty)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200880 return;
881
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200882 mp->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200883 mp->info_dirty = true;
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200884 mp->info = mp->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200885}
886
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200887int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
888{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200889 unsigned long flags;
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200890 struct omap_overlay *ovl;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200891 int r;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200892
893 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
894
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200895 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200896
Tomi Valkeinen39518352011-11-17 17:35:28 +0200897 r = dss_check_settings_apply(mgr, mgr->device);
898 if (r) {
899 spin_unlock_irqrestore(&data_lock, flags);
900 DSSERR("failed to apply settings: illegal configuration.\n");
901 return r;
902 }
903
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200904 /* Configure overlays */
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200905 list_for_each_entry(ovl, &mgr->overlays, list)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200906 omap_dss_mgr_apply_ovl(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200907
908 /* Configure manager */
909 omap_dss_mgr_apply_mgr(mgr);
910
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200911 dss_write_regs();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200912
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200913 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200914
Tomi Valkeinene70f98a2011-11-16 16:53:44 +0200915 return 0;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200916}
917
Tomi Valkeinen841c09c2011-11-16 15:25:53 +0200918static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
919{
920 struct ovl_priv_data *op;
921
922 op = get_ovl_priv(ovl);
923
924 if (op->enabled == enable)
925 return;
926
927 op->enabled = enable;
928 op->extra_info_dirty = true;
929}
930
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200931static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
932{
933 struct ovl_priv_data *op = get_ovl_priv(ovl);
934 struct omap_dss_device *dssdev;
935 u32 size, burst_size;
936 u32 fifo_low, fifo_high;
937
938 dssdev = ovl->manager->device;
939
940 size = dispc_ovl_get_fifo_size(ovl->id);
941
942 burst_size = dispc_ovl_get_burst_size(ovl->id);
943
944 switch (dssdev->type) {
945 case OMAP_DISPLAY_TYPE_DPI:
946 case OMAP_DISPLAY_TYPE_DBI:
947 case OMAP_DISPLAY_TYPE_SDI:
948 case OMAP_DISPLAY_TYPE_VENC:
949 case OMAP_DISPLAY_TYPE_HDMI:
950 default_get_overlay_fifo_thresholds(ovl->id, size,
951 burst_size, &fifo_low, &fifo_high);
952 break;
953#ifdef CONFIG_OMAP2_DSS_DSI
954 case OMAP_DISPLAY_TYPE_DSI:
955 dsi_get_overlay_fifo_thresholds(ovl->id, size,
956 burst_size, &fifo_low, &fifo_high);
957 break;
958#endif
959 default:
960 BUG();
961 }
962
963 op->fifo_low = fifo_low;
964 op->fifo_high = fifo_high;
965 op->extra_info_dirty = true;
966}
967
968static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
969{
970 struct omap_overlay *ovl;
971 struct ovl_priv_data *op;
972 struct mgr_priv_data *mp;
973
974 mp = get_mgr_priv(mgr);
975
976 if (!mp->enabled)
977 return;
978
979 list_for_each_entry(ovl, &mgr->overlays, list) {
980 op = get_ovl_priv(ovl);
981
982 if (!op->enabled)
983 continue;
984
985 dss_ovl_setup_fifo(ovl);
986 }
987}
988
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +0200989int dss_mgr_enable(struct omap_overlay_manager *mgr)
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200990{
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200991 struct mgr_priv_data *mp = get_mgr_priv(mgr);
992 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200993 int r;
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200994
Tomi Valkeinen5558db32011-11-15 14:28:48 +0200995 mutex_lock(&apply_lock);
996
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +0200997 if (mp->enabled)
998 goto out;
999
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001000 spin_lock_irqsave(&data_lock, flags);
1001
1002 mp->enabled = true;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001003 r = dss_check_settings(mgr, mgr->device);
1004 mp->enabled = false;
1005 if (r) {
1006 DSSERR("failed to enable manager %d: check_settings failed\n",
1007 mgr->id);
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001008 goto err;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001009 }
1010
1011 mp->enabled = true;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001012
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001013 dss_mgr_setup_fifos(mgr);
1014
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001015 dss_write_regs();
1016
Tomi Valkeinen34861372011-11-18 15:43:29 +02001017 if (!mgr_manual_update(mgr))
1018 mp->updating = true;
1019
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001020 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001021
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001022 if (!mgr_manual_update(mgr))
1023 dispc_mgr_enable(mgr->id, true);
1024
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001025out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001026 mutex_unlock(&apply_lock);
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001027
1028 return 0;
1029
1030err:
1031 spin_unlock_irqrestore(&data_lock, flags);
1032 mutex_unlock(&apply_lock);
1033 return r;
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001034}
1035
1036void dss_mgr_disable(struct omap_overlay_manager *mgr)
1037{
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001038 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1039 unsigned long flags;
1040
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001041 mutex_lock(&apply_lock);
1042
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001043 if (!mp->enabled)
1044 goto out;
1045
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02001046 if (!mgr_manual_update(mgr))
1047 dispc_mgr_enable(mgr->id, false);
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001048
1049 spin_lock_irqsave(&data_lock, flags);
1050
Tomi Valkeinen34861372011-11-18 15:43:29 +02001051 mp->updating = false;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001052 mp->enabled = false;
1053
1054 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001055
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001056out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001057 mutex_unlock(&apply_lock);
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001058}
1059
Tomi Valkeinenf17d04f2011-11-17 14:31:09 +02001060static int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
1061 const struct omap_overlay_manager_info *info)
1062{
1063 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
1064 /*
1065 * OMAP3 supports only graphics source transparency color key
1066 * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
1067 * Alpha Mode.
1068 */
1069 if (info->partial_alpha_enabled && info->trans_enabled
1070 && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
1071 DSSERR("check_manager: illegal transparency key\n");
1072 return -EINVAL;
1073 }
1074 }
1075
1076 return 0;
1077}
1078
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001079int dss_mgr_set_info(struct omap_overlay_manager *mgr,
1080 struct omap_overlay_manager_info *info)
1081{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001082 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001083 unsigned long flags;
Tomi Valkeinenf17d04f2011-11-17 14:31:09 +02001084 int r;
1085
1086 r = dss_mgr_simple_check(mgr, info);
1087 if (r)
1088 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001089
1090 spin_lock_irqsave(&data_lock, flags);
1091
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001092 mp->user_info = *info;
1093 mp->user_info_dirty = true;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001094
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001095 spin_unlock_irqrestore(&data_lock, flags);
1096
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001097 return 0;
1098}
1099
1100void dss_mgr_get_info(struct omap_overlay_manager *mgr,
1101 struct omap_overlay_manager_info *info)
1102{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001103 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001104 unsigned long flags;
1105
1106 spin_lock_irqsave(&data_lock, flags);
1107
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001108 *info = mp->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001109
1110 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001111}
1112
1113int dss_mgr_set_device(struct omap_overlay_manager *mgr,
1114 struct omap_dss_device *dssdev)
1115{
1116 int r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001117
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001118 mutex_lock(&apply_lock);
1119
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001120 if (dssdev->manager) {
1121 DSSERR("display '%s' already has a manager '%s'\n",
1122 dssdev->name, dssdev->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001123 r = -EINVAL;
1124 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001125 }
1126
1127 if ((mgr->supported_displays & dssdev->type) == 0) {
1128 DSSERR("display '%s' does not support manager '%s'\n",
1129 dssdev->name, mgr->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001130 r = -EINVAL;
1131 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001132 }
1133
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001134 dssdev->manager = mgr;
1135 mgr->device = dssdev;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001136
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001137 mutex_unlock(&apply_lock);
1138
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001139 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001140err:
1141 mutex_unlock(&apply_lock);
1142 return r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001143}
1144
1145int dss_mgr_unset_device(struct omap_overlay_manager *mgr)
1146{
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001147 int r;
1148
1149 mutex_lock(&apply_lock);
1150
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001151 if (!mgr->device) {
1152 DSSERR("failed to unset display, display not set.\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001153 r = -EINVAL;
1154 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001155 }
1156
1157 /*
1158 * Don't allow currently enabled displays to have the overlay manager
1159 * pulled out from underneath them
1160 */
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001161 if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED) {
1162 r = -EINVAL;
1163 goto err;
1164 }
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001165
1166 mgr->device->manager = NULL;
1167 mgr->device = NULL;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001168
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001169 mutex_unlock(&apply_lock);
1170
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001171 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001172err:
1173 mutex_unlock(&apply_lock);
1174 return r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001175}
1176
1177
Tomi Valkeinenfcc764d2011-11-17 14:26:48 +02001178static int dss_ovl_simple_check(struct omap_overlay *ovl,
1179 const struct omap_overlay_info *info)
1180{
1181 if (info->paddr == 0) {
1182 DSSERR("check_overlay: paddr cannot be 0\n");
1183 return -EINVAL;
1184 }
1185
1186 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
1187 if (info->out_width != 0 && info->width != info->out_width) {
1188 DSSERR("check_overlay: overlay %d doesn't support "
1189 "scaling\n", ovl->id);
1190 return -EINVAL;
1191 }
1192
1193 if (info->out_height != 0 && info->height != info->out_height) {
1194 DSSERR("check_overlay: overlay %d doesn't support "
1195 "scaling\n", ovl->id);
1196 return -EINVAL;
1197 }
1198 }
1199
1200 if ((ovl->supported_modes & info->color_mode) == 0) {
1201 DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
1202 ovl->id, info->color_mode);
1203 return -EINVAL;
1204 }
1205
1206 if (info->zorder >= omap_dss_get_num_overlays()) {
1207 DSSERR("check_overlay: zorder %d too high\n", info->zorder);
1208 return -EINVAL;
1209 }
1210
1211 return 0;
1212}
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001213
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001214int dss_ovl_set_info(struct omap_overlay *ovl,
1215 struct omap_overlay_info *info)
1216{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001217 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001218 unsigned long flags;
Tomi Valkeinenfcc764d2011-11-17 14:26:48 +02001219 int r;
1220
1221 r = dss_ovl_simple_check(ovl, info);
1222 if (r)
1223 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001224
1225 spin_lock_irqsave(&data_lock, flags);
1226
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001227 op->user_info = *info;
1228 op->user_info_dirty = true;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001229
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001230 spin_unlock_irqrestore(&data_lock, flags);
1231
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001232 return 0;
1233}
1234
1235void dss_ovl_get_info(struct omap_overlay *ovl,
1236 struct omap_overlay_info *info)
1237{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001238 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001239 unsigned long flags;
1240
1241 spin_lock_irqsave(&data_lock, flags);
1242
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001243 *info = op->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001244
1245 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001246}
1247
1248int dss_ovl_set_manager(struct omap_overlay *ovl,
1249 struct omap_overlay_manager *mgr)
1250{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001251 struct ovl_priv_data *op = get_ovl_priv(ovl);
1252 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001253 int r;
1254
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001255 if (!mgr)
1256 return -EINVAL;
1257
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001258 mutex_lock(&apply_lock);
1259
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001260 if (ovl->manager) {
1261 DSSERR("overlay '%s' already has a manager '%s'\n",
1262 ovl->name, ovl->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001263 r = -EINVAL;
1264 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001265 }
1266
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001267 spin_lock_irqsave(&data_lock, flags);
1268
1269 if (op->enabled) {
1270 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001271 DSSERR("overlay has to be disabled to change the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001272 r = -EINVAL;
1273 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001274 }
1275
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001276 op->channel = mgr->id;
1277 op->extra_info_dirty = true;
1278
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001279 ovl->manager = mgr;
1280 list_add_tail(&ovl->list, &mgr->overlays);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001281
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001282 spin_unlock_irqrestore(&data_lock, flags);
1283
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001284 /* XXX: When there is an overlay on a DSI manual update display, and
1285 * the overlay is first disabled, then moved to tv, and enabled, we
1286 * seem to get SYNC_LOST_DIGIT error.
1287 *
1288 * Waiting doesn't seem to help, but updating the manual update display
1289 * after disabling the overlay seems to fix this. This hints that the
1290 * overlay is perhaps somehow tied to the LCD output until the output
1291 * is updated.
1292 *
1293 * Userspace workaround for this is to update the LCD after disabling
1294 * the overlay, but before moving the overlay to TV.
1295 */
1296
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001297 mutex_unlock(&apply_lock);
1298
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001299 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001300err:
1301 mutex_unlock(&apply_lock);
1302 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001303}
1304
1305int dss_ovl_unset_manager(struct omap_overlay *ovl)
1306{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001307 struct ovl_priv_data *op = get_ovl_priv(ovl);
1308 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001309 int r;
1310
1311 mutex_lock(&apply_lock);
1312
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001313 if (!ovl->manager) {
1314 DSSERR("failed to detach overlay: manager not set\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001315 r = -EINVAL;
1316 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001317 }
1318
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001319 spin_lock_irqsave(&data_lock, flags);
1320
1321 if (op->enabled) {
1322 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001323 DSSERR("overlay has to be disabled to unset the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001324 r = -EINVAL;
1325 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001326 }
1327
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001328 op->channel = -1;
1329
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001330 ovl->manager = NULL;
1331 list_del(&ovl->list);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001332
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001333 spin_unlock_irqrestore(&data_lock, flags);
1334
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001335 mutex_unlock(&apply_lock);
1336
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001337 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001338err:
1339 mutex_unlock(&apply_lock);
1340 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001341}
1342
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001343bool dss_ovl_is_enabled(struct omap_overlay *ovl)
1344{
1345 struct ovl_priv_data *op = get_ovl_priv(ovl);
1346 unsigned long flags;
1347 bool e;
1348
1349 spin_lock_irqsave(&data_lock, flags);
1350
1351 e = op->enabled;
1352
1353 spin_unlock_irqrestore(&data_lock, flags);
1354
1355 return e;
1356}
1357
1358int dss_ovl_enable(struct omap_overlay *ovl)
1359{
1360 struct ovl_priv_data *op = get_ovl_priv(ovl);
1361 unsigned long flags;
1362 int r;
1363
1364 mutex_lock(&apply_lock);
1365
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001366 if (op->enabled) {
1367 r = 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001368 goto err1;
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001369 }
1370
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001371 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1372 r = -EINVAL;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001373 goto err1;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001374 }
1375
1376 spin_lock_irqsave(&data_lock, flags);
1377
Tomi Valkeinen39518352011-11-17 17:35:28 +02001378 op->enabled = true;
1379 r = dss_check_settings(ovl->manager, ovl->manager->device);
1380 op->enabled = false;
1381 if (r) {
1382 DSSERR("failed to enable overlay %d: check_settings failed\n",
1383 ovl->id);
1384 goto err2;
1385 }
1386
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001387 dss_apply_ovl_enable(ovl, true);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001388
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001389 dss_ovl_setup_fifo(ovl);
1390
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001391 dss_write_regs();
1392
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001393 spin_unlock_irqrestore(&data_lock, flags);
1394
1395 mutex_unlock(&apply_lock);
1396
1397 return 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001398err2:
1399 spin_unlock_irqrestore(&data_lock, flags);
1400err1:
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001401 mutex_unlock(&apply_lock);
1402 return r;
1403}
1404
1405int dss_ovl_disable(struct omap_overlay *ovl)
1406{
1407 struct ovl_priv_data *op = get_ovl_priv(ovl);
1408 unsigned long flags;
1409 int r;
1410
1411 mutex_lock(&apply_lock);
1412
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001413 if (!op->enabled) {
1414 r = 0;
1415 goto err;
1416 }
1417
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001418 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1419 r = -EINVAL;
1420 goto err;
1421 }
1422
1423 spin_lock_irqsave(&data_lock, flags);
1424
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001425 dss_apply_ovl_enable(ovl, false);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001426
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001427 dss_write_regs();
1428
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001429 spin_unlock_irqrestore(&data_lock, flags);
1430
1431 mutex_unlock(&apply_lock);
1432
1433 return 0;
1434
1435err:
1436 mutex_unlock(&apply_lock);
1437 return r;
1438}
1439