blob: 6eb48586501cdc5601b70b121c269a958b8864d3 [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
361 list_for_each_entry(ovl, &mgr->overlays, list) {
362 struct ovl_priv_data *op;
363
364 op = get_ovl_priv(ovl);
365
366 if (!op->enabled)
367 continue;
368
369 /* to write new values to registers */
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200370 if (op->info_dirty || op->extra_info_dirty)
Tomi Valkeinen34861372011-11-18 15:43:29 +0200371 return true;
372 }
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200373 }
374 }
375
376 return false;
377}
378
379static bool need_go(struct omap_overlay_manager *mgr)
380{
381 struct omap_overlay *ovl;
382 struct mgr_priv_data *mp;
383 struct ovl_priv_data *op;
384
385 mp = get_mgr_priv(mgr);
386
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200387 if (mp->shadow_info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200388 return true;
389
390 list_for_each_entry(ovl, &mgr->overlays, list) {
391 op = get_ovl_priv(ovl);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200392 if (op->shadow_info_dirty || op->shadow_extra_info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200393 return true;
394 }
395
396 return false;
397}
398
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200399/* returns true if an extra_info field is currently being updated */
400static bool extra_info_update_ongoing(void)
401{
402 const int num_ovls = omap_dss_get_num_overlays();
403 struct ovl_priv_data *op;
404 struct omap_overlay *ovl;
405 struct mgr_priv_data *mp;
406 int i;
407 bool eid;
408
409 for (i = 0; i < num_ovls; ++i) {
410 ovl = omap_dss_get_overlay(i);
411 op = get_ovl_priv(ovl);
412
413 if (!op->enabled)
414 continue;
415
416 mp = get_mgr_priv(ovl->manager);
417
418 if (!mp->enabled)
419 continue;
420
421 eid = op->extra_info_dirty || op->shadow_extra_info_dirty;
422
423 if (!eid)
424 continue;
425
426 if (ovl_manual_update(ovl) && !mp->updating)
427 continue;
428
429 return true;
430 }
431
432 return false;
433}
434
435/* wait until no extra_info updates are pending */
436static void wait_pending_extra_info_updates(void)
437{
438 bool updating;
439 unsigned long flags;
440 unsigned long t;
441
442 spin_lock_irqsave(&data_lock, flags);
443
444 updating = extra_info_update_ongoing();
445
446 if (!updating) {
447 spin_unlock_irqrestore(&data_lock, flags);
448 return;
449 }
450
451 init_completion(&extra_updated_completion);
452
453 spin_unlock_irqrestore(&data_lock, flags);
454
455 t = msecs_to_jiffies(500);
456 wait_for_completion_timeout(&extra_updated_completion, t);
457
458 updating = extra_info_update_ongoing();
459
460 WARN_ON(updating);
461}
462
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200463int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
464{
465 unsigned long timeout = msecs_to_jiffies(500);
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200466 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200467 u32 irq;
468 int r;
469 int i;
470 struct omap_dss_device *dssdev = mgr->device;
471
472 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
473 return 0;
474
475 if (mgr_manual_update(mgr))
476 return 0;
477
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200478 irq = dispc_mgr_get_vsync_irq(mgr->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200479
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200480 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200481 i = 0;
482 while (1) {
483 unsigned long flags;
484 bool shadow_dirty, dirty;
485
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200486 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200487 dirty = mp->info_dirty;
488 shadow_dirty = mp->shadow_info_dirty;
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200489 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200490
491 if (!dirty && !shadow_dirty) {
492 r = 0;
493 break;
494 }
495
496 /* 4 iterations is the worst case:
497 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
498 * 2 - first VSYNC, dirty = true
499 * 3 - dirty = false, shadow_dirty = true
500 * 4 - shadow_dirty = false */
501 if (i++ == 3) {
502 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
503 mgr->id);
504 r = 0;
505 break;
506 }
507
508 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
509 if (r == -ERESTARTSYS)
510 break;
511
512 if (r) {
513 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
514 break;
515 }
516 }
517
518 return r;
519}
520
521int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
522{
523 unsigned long timeout = msecs_to_jiffies(500);
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200524 struct ovl_priv_data *op;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200525 struct omap_dss_device *dssdev;
526 u32 irq;
527 int r;
528 int i;
529
530 if (!ovl->manager)
531 return 0;
532
533 dssdev = ovl->manager->device;
534
535 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
536 return 0;
537
538 if (ovl_manual_update(ovl))
539 return 0;
540
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200541 irq = dispc_mgr_get_vsync_irq(ovl->manager->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200542
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200543 op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200544 i = 0;
545 while (1) {
546 unsigned long flags;
547 bool shadow_dirty, dirty;
548
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200549 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200550 dirty = op->info_dirty;
551 shadow_dirty = op->shadow_info_dirty;
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200552 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200553
554 if (!dirty && !shadow_dirty) {
555 r = 0;
556 break;
557 }
558
559 /* 4 iterations is the worst case:
560 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
561 * 2 - first VSYNC, dirty = true
562 * 3 - dirty = false, shadow_dirty = true
563 * 4 - shadow_dirty = false */
564 if (i++ == 3) {
565 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
566 ovl->id);
567 r = 0;
568 break;
569 }
570
571 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
572 if (r == -ERESTARTSYS)
573 break;
574
575 if (r) {
576 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
577 break;
578 }
579 }
580
581 return r;
582}
583
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200584static void dss_ovl_write_regs(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200585{
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200586 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200587 struct omap_overlay_info *oi;
588 bool ilace, replication;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200589 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200590 int r;
591
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200592 DSSDBGF("%d", ovl->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200593
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200594 if (!op->enabled || !op->info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200595 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200596
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200597 oi = &op->info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200598
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200599 replication = dss_use_replication(ovl->manager->device, oi->color_mode);
600
601 ilace = ovl->manager->device->type == OMAP_DISPLAY_TYPE_VENC;
602
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200603 r = dispc_ovl_setup(ovl->id, oi, ilace, replication);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200604 if (r) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200605 /*
606 * We can't do much here, as this function can be called from
607 * vsync interrupt.
608 */
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200609 DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id);
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200610
611 /* This will leave fifo configurations in a nonoptimal state */
612 op->enabled = false;
613 dispc_ovl_enable(ovl->id, false);
614 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200615 }
616
Tomi Valkeinen34861372011-11-18 15:43:29 +0200617 mp = get_mgr_priv(ovl->manager);
618
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200619 op->info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200620 if (mp->updating)
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200621 op->shadow_info_dirty = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200622}
623
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200624static void dss_ovl_write_regs_extra(struct omap_overlay *ovl)
625{
626 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinen34861372011-11-18 15:43:29 +0200627 struct mgr_priv_data *mp;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200628
629 DSSDBGF("%d", ovl->id);
630
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200631 if (!op->extra_info_dirty)
632 return;
633
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200634 /* note: write also when op->enabled == false, so that the ovl gets
635 * disabled */
636
637 dispc_ovl_enable(ovl->id, op->enabled);
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +0200638 dispc_ovl_set_channel_out(ovl->id, op->channel);
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200639 dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high);
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200640
Tomi Valkeinen34861372011-11-18 15:43:29 +0200641 mp = get_mgr_priv(ovl->manager);
642
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200643 op->extra_info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200644 if (mp->updating)
645 op->shadow_extra_info_dirty = true;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200646}
647
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200648static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200649{
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200650 struct mgr_priv_data *mp = get_mgr_priv(mgr);
651 struct omap_overlay *ovl;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200652
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200653 DSSDBGF("%d", mgr->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200654
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200655 if (!mp->enabled)
656 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200657
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200658 WARN_ON(mp->busy);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200659
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200660 /* Commit overlay settings */
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200661 list_for_each_entry(ovl, &mgr->overlays, list) {
662 dss_ovl_write_regs(ovl);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200663 dss_ovl_write_regs_extra(ovl);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200664 }
665
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200666 if (mp->info_dirty) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200667 dispc_mgr_setup(mgr->id, &mp->info);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200668
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200669 mp->info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200670 if (mp->updating)
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200671 mp->shadow_info_dirty = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200672 }
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200673}
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200674
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200675static void dss_write_regs(void)
676{
677 const int num_mgrs = omap_dss_get_num_overlay_managers();
678 int i;
679
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200680 for (i = 0; i < num_mgrs; ++i) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200681 struct omap_overlay_manager *mgr;
682 struct mgr_priv_data *mp;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200683 int r;
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200684
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200685 mgr = omap_dss_get_overlay_manager(i);
686 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200687
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200688 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200689 continue;
690
Tomi Valkeinen39518352011-11-17 17:35:28 +0200691 r = dss_check_settings(mgr, mgr->device);
692 if (r) {
693 DSSERR("cannot write registers for manager %s: "
694 "illegal configuration\n", mgr->name);
695 continue;
696 }
697
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200698 dss_mgr_write_regs(mgr);
699
700 if (need_go(mgr)) {
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200701 mp->busy = true;
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200702
703 if (!dss_data.irq_enabled && need_isr())
704 dss_register_vsync_isr();
705
706 dispc_mgr_go(mgr->id);
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200707 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200708 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200709}
710
711void dss_mgr_start_update(struct omap_overlay_manager *mgr)
712{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200713 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200714 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200715 int r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200716
717 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200718
Tomi Valkeinen34861372011-11-18 15:43:29 +0200719 WARN_ON(mp->updating);
720
Tomi Valkeinen39518352011-11-17 17:35:28 +0200721 r = dss_check_settings(mgr, mgr->device);
722 if (r) {
723 DSSERR("cannot start manual update: illegal configuration\n");
724 spin_unlock_irqrestore(&data_lock, flags);
725 return;
726 }
727
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200728 dss_mgr_write_regs(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200729
Tomi Valkeinen34861372011-11-18 15:43:29 +0200730 mp->updating = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200731
Tomi Valkeinen34861372011-11-18 15:43:29 +0200732 if (!dss_data.irq_enabled && need_isr())
733 dss_register_vsync_isr();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200734
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200735 dispc_mgr_enable(mgr->id, true);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200736
737 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200738}
739
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200740static void dss_apply_irq_handler(void *data, u32 mask);
741
742static void dss_register_vsync_isr(void)
743{
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200744 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200745 u32 mask;
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200746 int r, i;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200747
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200748 mask = 0;
749 for (i = 0; i < num_mgrs; ++i)
750 mask |= dispc_mgr_get_vsync_irq(i);
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200751
Tomi Valkeinen34861372011-11-18 15:43:29 +0200752 for (i = 0; i < num_mgrs; ++i)
753 mask |= dispc_mgr_get_framedone_irq(i);
754
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200755 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
756 WARN_ON(r);
757
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200758 dss_data.irq_enabled = true;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200759}
760
761static void dss_unregister_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_unregister_isr(dss_apply_irq_handler, NULL, mask);
775 WARN_ON(r);
776
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200777 dss_data.irq_enabled = false;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200778}
779
Tomi Valkeinen76098932011-11-16 12:03:22 +0200780static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200781{
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200782 struct omap_overlay *ovl;
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200783 struct mgr_priv_data *mp;
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200784 struct ovl_priv_data *op;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200785
786 mp = get_mgr_priv(mgr);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200787 mp->shadow_info_dirty = false;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200788
789 list_for_each_entry(ovl, &mgr->overlays, list) {
790 op = get_ovl_priv(ovl);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200791 op->shadow_info_dirty = false;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200792 op->shadow_extra_info_dirty = false;
793 }
794}
795
796static void dss_apply_irq_handler(void *data, u32 mask)
797{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200798 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200799 int i;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200800 bool extra_updating;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200801
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200802 spin_lock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200803
Tomi Valkeinen76098932011-11-16 12:03:22 +0200804 /* clear busy, updating flags, shadow_dirty flags */
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200805 for (i = 0; i < num_mgrs; i++) {
Tomi Valkeinen76098932011-11-16 12:03:22 +0200806 struct omap_overlay_manager *mgr;
807 struct mgr_priv_data *mp;
808
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200809 mgr = omap_dss_get_overlay_manager(i);
810 mp = get_mgr_priv(mgr);
811
Tomi Valkeinen76098932011-11-16 12:03:22 +0200812 if (!mp->enabled)
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200813 continue;
814
Tomi Valkeinen76098932011-11-16 12:03:22 +0200815 mp->updating = dispc_mgr_is_enabled(i);
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200816
Tomi Valkeinen76098932011-11-16 12:03:22 +0200817 if (!mgr_manual_update(mgr)) {
818 mp->busy = dispc_mgr_go_busy(i);
819
820 if (!mp->busy)
821 mgr_clear_shadow_dirty(mgr);
822 } else {
823 if (!mp->updating)
824 mgr_clear_shadow_dirty(mgr);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200825 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200826 }
827
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200828 dss_write_regs();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200829
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200830 extra_updating = extra_info_update_ongoing();
831 if (!extra_updating)
832 complete_all(&extra_updated_completion);
833
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200834 if (!need_isr())
835 dss_unregister_vsync_isr();
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200836
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200837 spin_unlock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200838}
839
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200840static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200841{
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200842 struct ovl_priv_data *op;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200843
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200844 op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200845
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200846 if (!op->user_info_dirty)
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200847 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200848
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200849 op->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200850 op->info_dirty = true;
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200851 op->info = op->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200852}
853
854static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
855{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200856 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200857
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200858 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200859
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200860 if (!mp->user_info_dirty)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200861 return;
862
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200863 mp->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200864 mp->info_dirty = true;
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200865 mp->info = mp->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200866}
867
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200868int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
869{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200870 unsigned long flags;
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200871 struct omap_overlay *ovl;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200872 int r;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200873
874 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
875
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200876 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200877
Tomi Valkeinen39518352011-11-17 17:35:28 +0200878 r = dss_check_settings_apply(mgr, mgr->device);
879 if (r) {
880 spin_unlock_irqrestore(&data_lock, flags);
881 DSSERR("failed to apply settings: illegal configuration.\n");
882 return r;
883 }
884
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200885 /* Configure overlays */
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200886 list_for_each_entry(ovl, &mgr->overlays, list)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200887 omap_dss_mgr_apply_ovl(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200888
889 /* Configure manager */
890 omap_dss_mgr_apply_mgr(mgr);
891
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200892 dss_write_regs();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200893
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200894 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200895
Tomi Valkeinene70f98a2011-11-16 16:53:44 +0200896 return 0;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200897}
898
Tomi Valkeinen841c09c2011-11-16 15:25:53 +0200899static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
900{
901 struct ovl_priv_data *op;
902
903 op = get_ovl_priv(ovl);
904
905 if (op->enabled == enable)
906 return;
907
908 op->enabled = enable;
909 op->extra_info_dirty = true;
910}
911
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200912static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
913{
914 struct ovl_priv_data *op = get_ovl_priv(ovl);
915 struct omap_dss_device *dssdev;
916 u32 size, burst_size;
917 u32 fifo_low, fifo_high;
918
919 dssdev = ovl->manager->device;
920
921 size = dispc_ovl_get_fifo_size(ovl->id);
922
923 burst_size = dispc_ovl_get_burst_size(ovl->id);
924
925 switch (dssdev->type) {
926 case OMAP_DISPLAY_TYPE_DPI:
927 case OMAP_DISPLAY_TYPE_DBI:
928 case OMAP_DISPLAY_TYPE_SDI:
929 case OMAP_DISPLAY_TYPE_VENC:
930 case OMAP_DISPLAY_TYPE_HDMI:
931 default_get_overlay_fifo_thresholds(ovl->id, size,
932 burst_size, &fifo_low, &fifo_high);
933 break;
934#ifdef CONFIG_OMAP2_DSS_DSI
935 case OMAP_DISPLAY_TYPE_DSI:
936 dsi_get_overlay_fifo_thresholds(ovl->id, size,
937 burst_size, &fifo_low, &fifo_high);
938 break;
939#endif
940 default:
941 BUG();
942 }
943
944 op->fifo_low = fifo_low;
945 op->fifo_high = fifo_high;
946 op->extra_info_dirty = true;
947}
948
949static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
950{
951 struct omap_overlay *ovl;
952 struct ovl_priv_data *op;
953 struct mgr_priv_data *mp;
954
955 mp = get_mgr_priv(mgr);
956
957 if (!mp->enabled)
958 return;
959
960 list_for_each_entry(ovl, &mgr->overlays, list) {
961 op = get_ovl_priv(ovl);
962
963 if (!op->enabled)
964 continue;
965
966 dss_ovl_setup_fifo(ovl);
967 }
968}
969
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200970void dss_mgr_enable(struct omap_overlay_manager *mgr)
971{
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200972 struct mgr_priv_data *mp = get_mgr_priv(mgr);
973 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200974 int r;
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200975
Tomi Valkeinen5558db32011-11-15 14:28:48 +0200976 mutex_lock(&apply_lock);
977
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +0200978 if (mp->enabled)
979 goto out;
980
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200981 spin_lock_irqsave(&data_lock, flags);
982
983 mp->enabled = true;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200984 r = dss_check_settings(mgr, mgr->device);
985 mp->enabled = false;
986 if (r) {
987 DSSERR("failed to enable manager %d: check_settings failed\n",
988 mgr->id);
989 spin_unlock_irqrestore(&data_lock, flags);
990 goto out;
991 }
992
993 mp->enabled = true;
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200994
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200995 dss_mgr_setup_fifos(mgr);
996
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200997 dss_write_regs();
998
Tomi Valkeinen34861372011-11-18 15:43:29 +0200999 if (!mgr_manual_update(mgr))
1000 mp->updating = true;
1001
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001002 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001003
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001004 if (!mgr_manual_update(mgr))
1005 dispc_mgr_enable(mgr->id, true);
1006
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001007out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001008 mutex_unlock(&apply_lock);
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001009}
1010
1011void dss_mgr_disable(struct omap_overlay_manager *mgr)
1012{
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001013 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1014 unsigned long flags;
1015
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001016 mutex_lock(&apply_lock);
1017
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001018 if (!mp->enabled)
1019 goto out;
1020
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02001021 if (!mgr_manual_update(mgr))
1022 dispc_mgr_enable(mgr->id, false);
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001023
1024 spin_lock_irqsave(&data_lock, flags);
1025
Tomi Valkeinen34861372011-11-18 15:43:29 +02001026 mp->updating = false;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001027 mp->enabled = false;
1028
1029 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001030
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001031out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001032 mutex_unlock(&apply_lock);
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001033}
1034
Tomi Valkeinenf17d04f2011-11-17 14:31:09 +02001035static int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
1036 const struct omap_overlay_manager_info *info)
1037{
1038 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
1039 /*
1040 * OMAP3 supports only graphics source transparency color key
1041 * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
1042 * Alpha Mode.
1043 */
1044 if (info->partial_alpha_enabled && info->trans_enabled
1045 && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
1046 DSSERR("check_manager: illegal transparency key\n");
1047 return -EINVAL;
1048 }
1049 }
1050
1051 return 0;
1052}
1053
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001054int dss_mgr_set_info(struct omap_overlay_manager *mgr,
1055 struct omap_overlay_manager_info *info)
1056{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001057 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001058 unsigned long flags;
Tomi Valkeinenf17d04f2011-11-17 14:31:09 +02001059 int r;
1060
1061 r = dss_mgr_simple_check(mgr, info);
1062 if (r)
1063 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001064
1065 spin_lock_irqsave(&data_lock, flags);
1066
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001067 mp->user_info = *info;
1068 mp->user_info_dirty = true;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001069
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001070 spin_unlock_irqrestore(&data_lock, flags);
1071
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001072 return 0;
1073}
1074
1075void dss_mgr_get_info(struct omap_overlay_manager *mgr,
1076 struct omap_overlay_manager_info *info)
1077{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001078 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001079 unsigned long flags;
1080
1081 spin_lock_irqsave(&data_lock, flags);
1082
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001083 *info = mp->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001084
1085 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001086}
1087
1088int dss_mgr_set_device(struct omap_overlay_manager *mgr,
1089 struct omap_dss_device *dssdev)
1090{
1091 int r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001092
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001093 mutex_lock(&apply_lock);
1094
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001095 if (dssdev->manager) {
1096 DSSERR("display '%s' already has a manager '%s'\n",
1097 dssdev->name, dssdev->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001098 r = -EINVAL;
1099 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001100 }
1101
1102 if ((mgr->supported_displays & dssdev->type) == 0) {
1103 DSSERR("display '%s' does not support manager '%s'\n",
1104 dssdev->name, mgr->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001105 r = -EINVAL;
1106 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001107 }
1108
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001109 dssdev->manager = mgr;
1110 mgr->device = dssdev;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001111
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001112 mutex_unlock(&apply_lock);
1113
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001114 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001115err:
1116 mutex_unlock(&apply_lock);
1117 return r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001118}
1119
1120int dss_mgr_unset_device(struct omap_overlay_manager *mgr)
1121{
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001122 int r;
1123
1124 mutex_lock(&apply_lock);
1125
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001126 if (!mgr->device) {
1127 DSSERR("failed to unset display, display not set.\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001128 r = -EINVAL;
1129 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001130 }
1131
1132 /*
1133 * Don't allow currently enabled displays to have the overlay manager
1134 * pulled out from underneath them
1135 */
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001136 if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED) {
1137 r = -EINVAL;
1138 goto err;
1139 }
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001140
1141 mgr->device->manager = NULL;
1142 mgr->device = NULL;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001143
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001144 mutex_unlock(&apply_lock);
1145
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001146 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001147err:
1148 mutex_unlock(&apply_lock);
1149 return r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001150}
1151
1152
Tomi Valkeinenfcc764d2011-11-17 14:26:48 +02001153static int dss_ovl_simple_check(struct omap_overlay *ovl,
1154 const struct omap_overlay_info *info)
1155{
1156 if (info->paddr == 0) {
1157 DSSERR("check_overlay: paddr cannot be 0\n");
1158 return -EINVAL;
1159 }
1160
1161 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
1162 if (info->out_width != 0 && info->width != info->out_width) {
1163 DSSERR("check_overlay: overlay %d doesn't support "
1164 "scaling\n", ovl->id);
1165 return -EINVAL;
1166 }
1167
1168 if (info->out_height != 0 && info->height != info->out_height) {
1169 DSSERR("check_overlay: overlay %d doesn't support "
1170 "scaling\n", ovl->id);
1171 return -EINVAL;
1172 }
1173 }
1174
1175 if ((ovl->supported_modes & info->color_mode) == 0) {
1176 DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
1177 ovl->id, info->color_mode);
1178 return -EINVAL;
1179 }
1180
1181 if (info->zorder >= omap_dss_get_num_overlays()) {
1182 DSSERR("check_overlay: zorder %d too high\n", info->zorder);
1183 return -EINVAL;
1184 }
1185
1186 return 0;
1187}
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001188
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001189int dss_ovl_set_info(struct omap_overlay *ovl,
1190 struct omap_overlay_info *info)
1191{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001192 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001193 unsigned long flags;
Tomi Valkeinenfcc764d2011-11-17 14:26:48 +02001194 int r;
1195
1196 r = dss_ovl_simple_check(ovl, info);
1197 if (r)
1198 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001199
1200 spin_lock_irqsave(&data_lock, flags);
1201
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001202 op->user_info = *info;
1203 op->user_info_dirty = true;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001204
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001205 spin_unlock_irqrestore(&data_lock, flags);
1206
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001207 return 0;
1208}
1209
1210void dss_ovl_get_info(struct omap_overlay *ovl,
1211 struct omap_overlay_info *info)
1212{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001213 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001214 unsigned long flags;
1215
1216 spin_lock_irqsave(&data_lock, flags);
1217
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001218 *info = op->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001219
1220 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001221}
1222
1223int dss_ovl_set_manager(struct omap_overlay *ovl,
1224 struct omap_overlay_manager *mgr)
1225{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001226 struct ovl_priv_data *op = get_ovl_priv(ovl);
1227 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001228 int r;
1229
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001230 if (!mgr)
1231 return -EINVAL;
1232
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001233 mutex_lock(&apply_lock);
1234
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001235 if (ovl->manager) {
1236 DSSERR("overlay '%s' already has a manager '%s'\n",
1237 ovl->name, ovl->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001238 r = -EINVAL;
1239 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001240 }
1241
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001242 spin_lock_irqsave(&data_lock, flags);
1243
1244 if (op->enabled) {
1245 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001246 DSSERR("overlay has to be disabled to change the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001247 r = -EINVAL;
1248 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001249 }
1250
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001251 op->channel = mgr->id;
1252 op->extra_info_dirty = true;
1253
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001254 ovl->manager = mgr;
1255 list_add_tail(&ovl->list, &mgr->overlays);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001256
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001257 spin_unlock_irqrestore(&data_lock, flags);
1258
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001259 /* XXX: When there is an overlay on a DSI manual update display, and
1260 * the overlay is first disabled, then moved to tv, and enabled, we
1261 * seem to get SYNC_LOST_DIGIT error.
1262 *
1263 * Waiting doesn't seem to help, but updating the manual update display
1264 * after disabling the overlay seems to fix this. This hints that the
1265 * overlay is perhaps somehow tied to the LCD output until the output
1266 * is updated.
1267 *
1268 * Userspace workaround for this is to update the LCD after disabling
1269 * the overlay, but before moving the overlay to TV.
1270 */
1271
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001272 mutex_unlock(&apply_lock);
1273
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001274 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001275err:
1276 mutex_unlock(&apply_lock);
1277 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001278}
1279
1280int dss_ovl_unset_manager(struct omap_overlay *ovl)
1281{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001282 struct ovl_priv_data *op = get_ovl_priv(ovl);
1283 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001284 int r;
1285
1286 mutex_lock(&apply_lock);
1287
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001288 if (!ovl->manager) {
1289 DSSERR("failed to detach overlay: manager not set\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001290 r = -EINVAL;
1291 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001292 }
1293
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001294 spin_lock_irqsave(&data_lock, flags);
1295
1296 if (op->enabled) {
1297 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001298 DSSERR("overlay has to be disabled to unset the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001299 r = -EINVAL;
1300 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001301 }
1302
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001303 op->channel = -1;
1304
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001305 ovl->manager = NULL;
1306 list_del(&ovl->list);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001307
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001308 spin_unlock_irqrestore(&data_lock, flags);
1309
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001310 mutex_unlock(&apply_lock);
1311
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001312 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001313err:
1314 mutex_unlock(&apply_lock);
1315 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001316}
1317
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001318bool dss_ovl_is_enabled(struct omap_overlay *ovl)
1319{
1320 struct ovl_priv_data *op = get_ovl_priv(ovl);
1321 unsigned long flags;
1322 bool e;
1323
1324 spin_lock_irqsave(&data_lock, flags);
1325
1326 e = op->enabled;
1327
1328 spin_unlock_irqrestore(&data_lock, flags);
1329
1330 return e;
1331}
1332
1333int dss_ovl_enable(struct omap_overlay *ovl)
1334{
1335 struct ovl_priv_data *op = get_ovl_priv(ovl);
1336 unsigned long flags;
1337 int r;
1338
1339 mutex_lock(&apply_lock);
1340
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001341 if (op->enabled) {
1342 r = 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001343 goto err1;
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001344 }
1345
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001346 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1347 r = -EINVAL;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001348 goto err1;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001349 }
1350
1351 spin_lock_irqsave(&data_lock, flags);
1352
Tomi Valkeinen39518352011-11-17 17:35:28 +02001353 op->enabled = true;
1354 r = dss_check_settings(ovl->manager, ovl->manager->device);
1355 op->enabled = false;
1356 if (r) {
1357 DSSERR("failed to enable overlay %d: check_settings failed\n",
1358 ovl->id);
1359 goto err2;
1360 }
1361
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001362 dss_apply_ovl_enable(ovl, true);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001363
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001364 dss_ovl_setup_fifo(ovl);
1365
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001366 dss_write_regs();
1367
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001368 spin_unlock_irqrestore(&data_lock, flags);
1369
1370 mutex_unlock(&apply_lock);
1371
1372 return 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001373err2:
1374 spin_unlock_irqrestore(&data_lock, flags);
1375err1:
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001376 mutex_unlock(&apply_lock);
1377 return r;
1378}
1379
1380int dss_ovl_disable(struct omap_overlay *ovl)
1381{
1382 struct ovl_priv_data *op = get_ovl_priv(ovl);
1383 unsigned long flags;
1384 int r;
1385
1386 mutex_lock(&apply_lock);
1387
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001388 if (!op->enabled) {
1389 r = 0;
1390 goto err;
1391 }
1392
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001393 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1394 r = -EINVAL;
1395 goto err;
1396 }
1397
1398 spin_lock_irqsave(&data_lock, flags);
1399
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001400 dss_apply_ovl_enable(ovl, false);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001401
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001402 dss_write_regs();
1403
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001404 spin_unlock_irqrestore(&data_lock, flags);
1405
1406 mutex_unlock(&apply_lock);
1407
1408 return 0;
1409
1410err:
1411 mutex_unlock(&apply_lock);
1412 return r;
1413}
1414