blob: f54c17f849b7934f44df24e30090b39e43bae302 [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);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200718 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200719}
720
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +0200721static void dss_set_go_bits(void)
722{
723 const int num_mgrs = omap_dss_get_num_overlay_managers();
724 int i;
725
726 for (i = 0; i < num_mgrs; ++i) {
727 struct omap_overlay_manager *mgr;
728 struct mgr_priv_data *mp;
729
730 mgr = omap_dss_get_overlay_manager(i);
731 mp = get_mgr_priv(mgr);
732
733 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
734 continue;
735
736 if (!need_go(mgr))
737 continue;
738
739 mp->busy = true;
740
741 if (!dss_data.irq_enabled && need_isr())
742 dss_register_vsync_isr();
743
744 dispc_mgr_go(mgr->id);
745 }
746
747}
748
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200749void dss_mgr_start_update(struct omap_overlay_manager *mgr)
750{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200751 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200752 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200753 int r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200754
755 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200756
Tomi Valkeinen34861372011-11-18 15:43:29 +0200757 WARN_ON(mp->updating);
758
Tomi Valkeinen39518352011-11-17 17:35:28 +0200759 r = dss_check_settings(mgr, mgr->device);
760 if (r) {
761 DSSERR("cannot start manual update: illegal configuration\n");
762 spin_unlock_irqrestore(&data_lock, flags);
763 return;
764 }
765
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200766 dss_mgr_write_regs(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200767
Tomi Valkeinen34861372011-11-18 15:43:29 +0200768 mp->updating = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200769
Tomi Valkeinen34861372011-11-18 15:43:29 +0200770 if (!dss_data.irq_enabled && need_isr())
771 dss_register_vsync_isr();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200772
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200773 dispc_mgr_enable(mgr->id, true);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200774
775 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200776}
777
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200778static void dss_apply_irq_handler(void *data, u32 mask);
779
780static void dss_register_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_register_isr(dss_apply_irq_handler, NULL, mask);
794 WARN_ON(r);
795
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200796 dss_data.irq_enabled = true;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200797}
798
799static void dss_unregister_vsync_isr(void)
800{
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200801 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200802 u32 mask;
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200803 int r, i;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200804
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200805 mask = 0;
806 for (i = 0; i < num_mgrs; ++i)
807 mask |= dispc_mgr_get_vsync_irq(i);
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200808
Tomi Valkeinen34861372011-11-18 15:43:29 +0200809 for (i = 0; i < num_mgrs; ++i)
810 mask |= dispc_mgr_get_framedone_irq(i);
811
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200812 r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask);
813 WARN_ON(r);
814
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200815 dss_data.irq_enabled = false;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200816}
817
Tomi Valkeinen76098932011-11-16 12:03:22 +0200818static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200819{
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200820 struct omap_overlay *ovl;
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200821 struct mgr_priv_data *mp;
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200822 struct ovl_priv_data *op;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200823
824 mp = get_mgr_priv(mgr);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200825 mp->shadow_info_dirty = false;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200826
827 list_for_each_entry(ovl, &mgr->overlays, list) {
828 op = get_ovl_priv(ovl);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200829 op->shadow_info_dirty = false;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200830 op->shadow_extra_info_dirty = false;
831 }
832}
833
834static void dss_apply_irq_handler(void *data, u32 mask)
835{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200836 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200837 int i;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200838 bool extra_updating;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200839
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200840 spin_lock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200841
Tomi Valkeinen76098932011-11-16 12:03:22 +0200842 /* clear busy, updating flags, shadow_dirty flags */
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200843 for (i = 0; i < num_mgrs; i++) {
Tomi Valkeinen76098932011-11-16 12:03:22 +0200844 struct omap_overlay_manager *mgr;
845 struct mgr_priv_data *mp;
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200846 bool was_updating;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200847
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200848 mgr = omap_dss_get_overlay_manager(i);
849 mp = get_mgr_priv(mgr);
850
Tomi Valkeinen76098932011-11-16 12:03:22 +0200851 if (!mp->enabled)
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200852 continue;
853
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200854 was_updating = mp->updating;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200855 mp->updating = dispc_mgr_is_enabled(i);
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200856
Tomi Valkeinen76098932011-11-16 12:03:22 +0200857 if (!mgr_manual_update(mgr)) {
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200858 bool was_busy = mp->busy;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200859 mp->busy = dispc_mgr_go_busy(i);
860
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200861 if (was_busy && !mp->busy)
Tomi Valkeinen76098932011-11-16 12:03:22 +0200862 mgr_clear_shadow_dirty(mgr);
863 } else {
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200864 if (was_updating && !mp->updating)
Tomi Valkeinen76098932011-11-16 12:03:22 +0200865 mgr_clear_shadow_dirty(mgr);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200866 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200867 }
868
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200869 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +0200870 dss_set_go_bits();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200871
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200872 extra_updating = extra_info_update_ongoing();
873 if (!extra_updating)
874 complete_all(&extra_updated_completion);
875
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200876 if (!need_isr())
877 dss_unregister_vsync_isr();
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200878
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200879 spin_unlock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200880}
881
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200882static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200883{
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200884 struct ovl_priv_data *op;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200885
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200886 op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200887
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200888 if (!op->user_info_dirty)
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200889 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200890
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200891 op->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200892 op->info_dirty = true;
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200893 op->info = op->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200894}
895
896static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
897{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200898 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200899
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200900 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200901
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200902 if (!mp->user_info_dirty)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200903 return;
904
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200905 mp->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200906 mp->info_dirty = true;
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200907 mp->info = mp->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200908}
909
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200910int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
911{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200912 unsigned long flags;
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200913 struct omap_overlay *ovl;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200914 int r;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200915
916 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
917
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200918 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200919
Tomi Valkeinen39518352011-11-17 17:35:28 +0200920 r = dss_check_settings_apply(mgr, mgr->device);
921 if (r) {
922 spin_unlock_irqrestore(&data_lock, flags);
923 DSSERR("failed to apply settings: illegal configuration.\n");
924 return r;
925 }
926
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200927 /* Configure overlays */
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200928 list_for_each_entry(ovl, &mgr->overlays, list)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200929 omap_dss_mgr_apply_ovl(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200930
931 /* Configure manager */
932 omap_dss_mgr_apply_mgr(mgr);
933
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200934 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +0200935 dss_set_go_bits();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200936
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200937 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200938
Tomi Valkeinene70f98a2011-11-16 16:53:44 +0200939 return 0;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200940}
941
Tomi Valkeinen841c09c2011-11-16 15:25:53 +0200942static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
943{
944 struct ovl_priv_data *op;
945
946 op = get_ovl_priv(ovl);
947
948 if (op->enabled == enable)
949 return;
950
951 op->enabled = enable;
952 op->extra_info_dirty = true;
953}
954
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200955static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
956{
957 struct ovl_priv_data *op = get_ovl_priv(ovl);
958 struct omap_dss_device *dssdev;
959 u32 size, burst_size;
960 u32 fifo_low, fifo_high;
961
962 dssdev = ovl->manager->device;
963
964 size = dispc_ovl_get_fifo_size(ovl->id);
965
966 burst_size = dispc_ovl_get_burst_size(ovl->id);
967
968 switch (dssdev->type) {
969 case OMAP_DISPLAY_TYPE_DPI:
970 case OMAP_DISPLAY_TYPE_DBI:
971 case OMAP_DISPLAY_TYPE_SDI:
972 case OMAP_DISPLAY_TYPE_VENC:
973 case OMAP_DISPLAY_TYPE_HDMI:
974 default_get_overlay_fifo_thresholds(ovl->id, size,
975 burst_size, &fifo_low, &fifo_high);
976 break;
977#ifdef CONFIG_OMAP2_DSS_DSI
978 case OMAP_DISPLAY_TYPE_DSI:
979 dsi_get_overlay_fifo_thresholds(ovl->id, size,
980 burst_size, &fifo_low, &fifo_high);
981 break;
982#endif
983 default:
984 BUG();
985 }
986
987 op->fifo_low = fifo_low;
988 op->fifo_high = fifo_high;
989 op->extra_info_dirty = true;
990}
991
992static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
993{
994 struct omap_overlay *ovl;
995 struct ovl_priv_data *op;
996 struct mgr_priv_data *mp;
997
998 mp = get_mgr_priv(mgr);
999
1000 if (!mp->enabled)
1001 return;
1002
1003 list_for_each_entry(ovl, &mgr->overlays, list) {
1004 op = get_ovl_priv(ovl);
1005
1006 if (!op->enabled)
1007 continue;
1008
1009 dss_ovl_setup_fifo(ovl);
1010 }
1011}
1012
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001013int dss_mgr_enable(struct omap_overlay_manager *mgr)
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001014{
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001015 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1016 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001017 int r;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001018
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001019 mutex_lock(&apply_lock);
1020
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001021 if (mp->enabled)
1022 goto out;
1023
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001024 spin_lock_irqsave(&data_lock, flags);
1025
1026 mp->enabled = true;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001027 r = dss_check_settings(mgr, mgr->device);
1028 mp->enabled = false;
1029 if (r) {
1030 DSSERR("failed to enable manager %d: check_settings failed\n",
1031 mgr->id);
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001032 goto err;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001033 }
1034
1035 mp->enabled = true;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001036
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001037 dss_mgr_setup_fifos(mgr);
1038
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001039 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +02001040 dss_set_go_bits();
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001041
Tomi Valkeinen34861372011-11-18 15:43:29 +02001042 if (!mgr_manual_update(mgr))
1043 mp->updating = true;
1044
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001045 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001046
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001047 if (!mgr_manual_update(mgr))
1048 dispc_mgr_enable(mgr->id, true);
1049
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001050out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001051 mutex_unlock(&apply_lock);
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001052
1053 return 0;
1054
1055err:
1056 spin_unlock_irqrestore(&data_lock, flags);
1057 mutex_unlock(&apply_lock);
1058 return r;
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001059}
1060
1061void dss_mgr_disable(struct omap_overlay_manager *mgr)
1062{
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001063 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1064 unsigned long flags;
1065
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001066 mutex_lock(&apply_lock);
1067
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001068 if (!mp->enabled)
1069 goto out;
1070
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02001071 if (!mgr_manual_update(mgr))
1072 dispc_mgr_enable(mgr->id, false);
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001073
1074 spin_lock_irqsave(&data_lock, flags);
1075
Tomi Valkeinen34861372011-11-18 15:43:29 +02001076 mp->updating = false;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001077 mp->enabled = false;
1078
1079 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001080
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001081out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001082 mutex_unlock(&apply_lock);
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001083}
1084
Tomi Valkeinenf17d04f2011-11-17 14:31:09 +02001085static int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
1086 const struct omap_overlay_manager_info *info)
1087{
1088 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
1089 /*
1090 * OMAP3 supports only graphics source transparency color key
1091 * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
1092 * Alpha Mode.
1093 */
1094 if (info->partial_alpha_enabled && info->trans_enabled
1095 && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
1096 DSSERR("check_manager: illegal transparency key\n");
1097 return -EINVAL;
1098 }
1099 }
1100
1101 return 0;
1102}
1103
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001104int dss_mgr_set_info(struct omap_overlay_manager *mgr,
1105 struct omap_overlay_manager_info *info)
1106{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001107 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001108 unsigned long flags;
Tomi Valkeinenf17d04f2011-11-17 14:31:09 +02001109 int r;
1110
1111 r = dss_mgr_simple_check(mgr, info);
1112 if (r)
1113 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001114
1115 spin_lock_irqsave(&data_lock, flags);
1116
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001117 mp->user_info = *info;
1118 mp->user_info_dirty = true;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001119
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001120 spin_unlock_irqrestore(&data_lock, flags);
1121
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001122 return 0;
1123}
1124
1125void dss_mgr_get_info(struct omap_overlay_manager *mgr,
1126 struct omap_overlay_manager_info *info)
1127{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001128 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001129 unsigned long flags;
1130
1131 spin_lock_irqsave(&data_lock, flags);
1132
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001133 *info = mp->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001134
1135 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001136}
1137
1138int dss_mgr_set_device(struct omap_overlay_manager *mgr,
1139 struct omap_dss_device *dssdev)
1140{
1141 int r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001142
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001143 mutex_lock(&apply_lock);
1144
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001145 if (dssdev->manager) {
1146 DSSERR("display '%s' already has a manager '%s'\n",
1147 dssdev->name, dssdev->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001148 r = -EINVAL;
1149 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001150 }
1151
1152 if ((mgr->supported_displays & dssdev->type) == 0) {
1153 DSSERR("display '%s' does not support manager '%s'\n",
1154 dssdev->name, mgr->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001155 r = -EINVAL;
1156 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001157 }
1158
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001159 dssdev->manager = mgr;
1160 mgr->device = dssdev;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001161
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001162 mutex_unlock(&apply_lock);
1163
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001164 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001165err:
1166 mutex_unlock(&apply_lock);
1167 return r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001168}
1169
1170int dss_mgr_unset_device(struct omap_overlay_manager *mgr)
1171{
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001172 int r;
1173
1174 mutex_lock(&apply_lock);
1175
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001176 if (!mgr->device) {
1177 DSSERR("failed to unset display, display not set.\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001178 r = -EINVAL;
1179 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001180 }
1181
1182 /*
1183 * Don't allow currently enabled displays to have the overlay manager
1184 * pulled out from underneath them
1185 */
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001186 if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED) {
1187 r = -EINVAL;
1188 goto err;
1189 }
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001190
1191 mgr->device->manager = NULL;
1192 mgr->device = NULL;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001193
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001194 mutex_unlock(&apply_lock);
1195
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001196 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001197err:
1198 mutex_unlock(&apply_lock);
1199 return r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001200}
1201
1202
Tomi Valkeinenfcc764d2011-11-17 14:26:48 +02001203static int dss_ovl_simple_check(struct omap_overlay *ovl,
1204 const struct omap_overlay_info *info)
1205{
1206 if (info->paddr == 0) {
1207 DSSERR("check_overlay: paddr cannot be 0\n");
1208 return -EINVAL;
1209 }
1210
1211 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
1212 if (info->out_width != 0 && info->width != info->out_width) {
1213 DSSERR("check_overlay: overlay %d doesn't support "
1214 "scaling\n", ovl->id);
1215 return -EINVAL;
1216 }
1217
1218 if (info->out_height != 0 && info->height != info->out_height) {
1219 DSSERR("check_overlay: overlay %d doesn't support "
1220 "scaling\n", ovl->id);
1221 return -EINVAL;
1222 }
1223 }
1224
1225 if ((ovl->supported_modes & info->color_mode) == 0) {
1226 DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
1227 ovl->id, info->color_mode);
1228 return -EINVAL;
1229 }
1230
1231 if (info->zorder >= omap_dss_get_num_overlays()) {
1232 DSSERR("check_overlay: zorder %d too high\n", info->zorder);
1233 return -EINVAL;
1234 }
1235
1236 return 0;
1237}
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001238
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001239int dss_ovl_set_info(struct omap_overlay *ovl,
1240 struct omap_overlay_info *info)
1241{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001242 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001243 unsigned long flags;
Tomi Valkeinenfcc764d2011-11-17 14:26:48 +02001244 int r;
1245
1246 r = dss_ovl_simple_check(ovl, info);
1247 if (r)
1248 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001249
1250 spin_lock_irqsave(&data_lock, flags);
1251
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001252 op->user_info = *info;
1253 op->user_info_dirty = true;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001254
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001255 spin_unlock_irqrestore(&data_lock, flags);
1256
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001257 return 0;
1258}
1259
1260void dss_ovl_get_info(struct omap_overlay *ovl,
1261 struct omap_overlay_info *info)
1262{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001263 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001264 unsigned long flags;
1265
1266 spin_lock_irqsave(&data_lock, flags);
1267
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001268 *info = op->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001269
1270 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001271}
1272
1273int dss_ovl_set_manager(struct omap_overlay *ovl,
1274 struct omap_overlay_manager *mgr)
1275{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001276 struct ovl_priv_data *op = get_ovl_priv(ovl);
1277 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001278 int r;
1279
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001280 if (!mgr)
1281 return -EINVAL;
1282
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001283 mutex_lock(&apply_lock);
1284
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001285 if (ovl->manager) {
1286 DSSERR("overlay '%s' already has a manager '%s'\n",
1287 ovl->name, ovl->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001288 r = -EINVAL;
1289 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001290 }
1291
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001292 spin_lock_irqsave(&data_lock, flags);
1293
1294 if (op->enabled) {
1295 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001296 DSSERR("overlay has to be disabled to change the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001297 r = -EINVAL;
1298 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001299 }
1300
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001301 op->channel = mgr->id;
1302 op->extra_info_dirty = true;
1303
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001304 ovl->manager = mgr;
1305 list_add_tail(&ovl->list, &mgr->overlays);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001306
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001307 spin_unlock_irqrestore(&data_lock, flags);
1308
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001309 /* XXX: When there is an overlay on a DSI manual update display, and
1310 * the overlay is first disabled, then moved to tv, and enabled, we
1311 * seem to get SYNC_LOST_DIGIT error.
1312 *
1313 * Waiting doesn't seem to help, but updating the manual update display
1314 * after disabling the overlay seems to fix this. This hints that the
1315 * overlay is perhaps somehow tied to the LCD output until the output
1316 * is updated.
1317 *
1318 * Userspace workaround for this is to update the LCD after disabling
1319 * the overlay, but before moving the overlay to TV.
1320 */
1321
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001322 mutex_unlock(&apply_lock);
1323
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001324 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001325err:
1326 mutex_unlock(&apply_lock);
1327 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001328}
1329
1330int dss_ovl_unset_manager(struct omap_overlay *ovl)
1331{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001332 struct ovl_priv_data *op = get_ovl_priv(ovl);
1333 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001334 int r;
1335
1336 mutex_lock(&apply_lock);
1337
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001338 if (!ovl->manager) {
1339 DSSERR("failed to detach overlay: manager not set\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001340 r = -EINVAL;
1341 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001342 }
1343
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001344 spin_lock_irqsave(&data_lock, flags);
1345
1346 if (op->enabled) {
1347 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001348 DSSERR("overlay has to be disabled to unset the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001349 r = -EINVAL;
1350 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001351 }
1352
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001353 op->channel = -1;
1354
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001355 ovl->manager = NULL;
1356 list_del(&ovl->list);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001357
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001358 spin_unlock_irqrestore(&data_lock, flags);
1359
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001360 mutex_unlock(&apply_lock);
1361
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001362 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001363err:
1364 mutex_unlock(&apply_lock);
1365 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001366}
1367
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001368bool dss_ovl_is_enabled(struct omap_overlay *ovl)
1369{
1370 struct ovl_priv_data *op = get_ovl_priv(ovl);
1371 unsigned long flags;
1372 bool e;
1373
1374 spin_lock_irqsave(&data_lock, flags);
1375
1376 e = op->enabled;
1377
1378 spin_unlock_irqrestore(&data_lock, flags);
1379
1380 return e;
1381}
1382
1383int dss_ovl_enable(struct omap_overlay *ovl)
1384{
1385 struct ovl_priv_data *op = get_ovl_priv(ovl);
1386 unsigned long flags;
1387 int r;
1388
1389 mutex_lock(&apply_lock);
1390
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001391 if (op->enabled) {
1392 r = 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001393 goto err1;
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001394 }
1395
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001396 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1397 r = -EINVAL;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001398 goto err1;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001399 }
1400
1401 spin_lock_irqsave(&data_lock, flags);
1402
Tomi Valkeinen39518352011-11-17 17:35:28 +02001403 op->enabled = true;
1404 r = dss_check_settings(ovl->manager, ovl->manager->device);
1405 op->enabled = false;
1406 if (r) {
1407 DSSERR("failed to enable overlay %d: check_settings failed\n",
1408 ovl->id);
1409 goto err2;
1410 }
1411
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001412 dss_apply_ovl_enable(ovl, true);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001413
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001414 dss_ovl_setup_fifo(ovl);
1415
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001416 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +02001417 dss_set_go_bits();
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001418
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001419 spin_unlock_irqrestore(&data_lock, flags);
1420
1421 mutex_unlock(&apply_lock);
1422
1423 return 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001424err2:
1425 spin_unlock_irqrestore(&data_lock, flags);
1426err1:
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001427 mutex_unlock(&apply_lock);
1428 return r;
1429}
1430
1431int dss_ovl_disable(struct omap_overlay *ovl)
1432{
1433 struct ovl_priv_data *op = get_ovl_priv(ovl);
1434 unsigned long flags;
1435 int r;
1436
1437 mutex_lock(&apply_lock);
1438
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001439 if (!op->enabled) {
1440 r = 0;
1441 goto err;
1442 }
1443
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001444 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1445 r = -EINVAL;
1446 goto err;
1447 }
1448
1449 spin_lock_irqsave(&data_lock, flags);
1450
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001451 dss_apply_ovl_enable(ovl, false);
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001452 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +02001453 dss_set_go_bits();
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001454
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001455 spin_unlock_irqrestore(&data_lock, flags);
1456
1457 mutex_unlock(&apply_lock);
1458
1459 return 0;
1460
1461err:
1462 mutex_unlock(&apply_lock);
1463 return r;
1464}
1465