blob: 6354bb842856ce7197bd2dec82f4310484e01c67 [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 Valkeinen82153ed2011-11-26 14:26:46 +020075
76 /*
77 * True if overlay is to be enabled. Used to check and calculate configs
78 * for the overlay before it is enabled in the HW.
79 */
80 bool enabling;
Tomi Valkeinen58f255482011-11-04 09:48:54 +020081};
82
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +020083struct mgr_priv_data {
Tomi Valkeinen388c4c62011-11-16 13:58:07 +020084
85 bool user_info_dirty;
86 struct omap_overlay_manager_info user_info;
87
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020088 bool info_dirty;
Tomi Valkeinen58f255482011-11-04 09:48:54 +020089 struct omap_overlay_manager_info info;
90
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020091 bool shadow_info_dirty;
92
Tomi Valkeinen43a972d2011-11-15 15:04:25 +020093 /* If true, GO bit is up and shadow registers cannot be written.
94 * Never true for manual update displays */
95 bool busy;
96
Tomi Valkeinen34861372011-11-18 15:43:29 +020097 /* If true, dispc output is enabled */
98 bool updating;
99
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200100 /* If true, a display is enabled using this manager */
101 bool enabled;
Archit Taneja45324a22012-04-26 19:31:22 +0530102
103 bool extra_info_dirty;
104 bool shadow_extra_info_dirty;
105
106 struct omap_video_timings timings;
Archit Tanejaf476ae92012-06-29 14:37:03 +0530107 struct dss_lcd_mgr_config lcd_config;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200108};
109
110static struct {
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200111 struct ovl_priv_data ovl_priv_data_array[MAX_DSS_OVERLAYS];
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200112 struct mgr_priv_data mgr_priv_data_array[MAX_DSS_MANAGERS];
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200113
114 bool irq_enabled;
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200115} dss_data;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200116
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200117/* protects dss_data */
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200118static spinlock_t data_lock;
Tomi Valkeinen5558db32011-11-15 14:28:48 +0200119/* lock for blocking functions */
120static DEFINE_MUTEX(apply_lock);
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200121static DECLARE_COMPLETION(extra_updated_completion);
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200122
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200123static void dss_register_vsync_isr(void);
124
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200125static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl)
126{
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200127 return &dss_data.ovl_priv_data_array[ovl->id];
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200128}
129
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200130static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr)
131{
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200132 return &dss_data.mgr_priv_data_array[mgr->id];
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200133}
134
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200135void dss_apply_init(void)
136{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200137 const int num_ovls = dss_feat_get_num_ovls();
Archit Tanejaf476ae92012-06-29 14:37:03 +0530138 struct mgr_priv_data *mp;
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200139 int i;
140
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200141 spin_lock_init(&data_lock);
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200142
143 for (i = 0; i < num_ovls; ++i) {
144 struct ovl_priv_data *op;
145
146 op = &dss_data.ovl_priv_data_array[i];
147
148 op->info.global_alpha = 255;
149
150 switch (i) {
151 case 0:
152 op->info.zorder = 0;
153 break;
154 case 1:
155 op->info.zorder =
156 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 3 : 0;
157 break;
158 case 2:
159 op->info.zorder =
160 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 2 : 0;
161 break;
162 case 3:
163 op->info.zorder =
164 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 1 : 0;
165 break;
166 }
167
168 op->user_info = op->info;
169 }
Archit Tanejaf476ae92012-06-29 14:37:03 +0530170
171 /*
172 * Initialize some of the lcd_config fields for TV manager, this lets
173 * us prevent checking if the manager is LCD or TV at some places
174 */
175 mp = &dss_data.mgr_priv_data_array[OMAP_DSS_CHANNEL_DIGIT];
176
177 mp->lcd_config.video_port_width = 24;
178 mp->lcd_config.clock_info.lck_div = 1;
179 mp->lcd_config.clock_info.pck_div = 1;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200180}
181
Archit Taneja75bac5d2012-05-24 15:08:54 +0530182/*
183 * A LCD manager's stallmode decides whether it is in manual or auto update. TV
184 * manager is always auto update, stallmode field for TV manager is false by
185 * default
186 */
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200187static bool ovl_manual_update(struct omap_overlay *ovl)
188{
Archit Taneja75bac5d2012-05-24 15:08:54 +0530189 struct mgr_priv_data *mp = get_mgr_priv(ovl->manager);
190
191 return mp->lcd_config.stallmode;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200192}
193
194static bool mgr_manual_update(struct omap_overlay_manager *mgr)
195{
Archit Taneja75bac5d2012-05-24 15:08:54 +0530196 struct mgr_priv_data *mp = get_mgr_priv(mgr);
197
198 return mp->lcd_config.stallmode;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200199}
200
Tomi Valkeinen39518352011-11-17 17:35:28 +0200201static int dss_check_settings_low(struct omap_overlay_manager *mgr,
Archit Taneja228b2132012-04-27 01:22:28 +0530202 bool applying)
Tomi Valkeinen39518352011-11-17 17:35:28 +0200203{
204 struct omap_overlay_info *oi;
205 struct omap_overlay_manager_info *mi;
206 struct omap_overlay *ovl;
207 struct omap_overlay_info *ois[MAX_DSS_OVERLAYS];
208 struct ovl_priv_data *op;
209 struct mgr_priv_data *mp;
210
211 mp = get_mgr_priv(mgr);
212
Archit Taneja5dd747e2012-05-08 18:19:15 +0530213 if (!mp->enabled)
214 return 0;
215
Tomi Valkeinen39518352011-11-17 17:35:28 +0200216 if (applying && mp->user_info_dirty)
217 mi = &mp->user_info;
218 else
219 mi = &mp->info;
220
221 /* collect the infos to be tested into the array */
222 list_for_each_entry(ovl, &mgr->overlays, list) {
223 op = get_ovl_priv(ovl);
224
Tomi Valkeinen82153ed2011-11-26 14:26:46 +0200225 if (!op->enabled && !op->enabling)
Tomi Valkeinen39518352011-11-17 17:35:28 +0200226 oi = NULL;
227 else if (applying && op->user_info_dirty)
228 oi = &op->user_info;
229 else
230 oi = &op->info;
231
232 ois[ovl->id] = oi;
233 }
234
Archit Taneja6e543592012-05-23 17:01:35 +0530235 return dss_mgr_check(mgr, mi, &mp->timings, &mp->lcd_config, ois);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200236}
237
238/*
239 * check manager and overlay settings using overlay_info from data->info
240 */
Archit Taneja228b2132012-04-27 01:22:28 +0530241static int dss_check_settings(struct omap_overlay_manager *mgr)
Tomi Valkeinen39518352011-11-17 17:35:28 +0200242{
Archit Taneja228b2132012-04-27 01:22:28 +0530243 return dss_check_settings_low(mgr, false);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200244}
245
246/*
247 * check manager and overlay settings using overlay_info from ovl->info if
248 * dirty and from data->info otherwise
249 */
Archit Taneja228b2132012-04-27 01:22:28 +0530250static int dss_check_settings_apply(struct omap_overlay_manager *mgr)
Tomi Valkeinen39518352011-11-17 17:35:28 +0200251{
Archit Taneja228b2132012-04-27 01:22:28 +0530252 return dss_check_settings_low(mgr, true);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200253}
254
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200255static bool need_isr(void)
256{
257 const int num_mgrs = dss_feat_get_num_mgrs();
258 int i;
259
260 for (i = 0; i < num_mgrs; ++i) {
261 struct omap_overlay_manager *mgr;
262 struct mgr_priv_data *mp;
263 struct omap_overlay *ovl;
264
265 mgr = omap_dss_get_overlay_manager(i);
266 mp = get_mgr_priv(mgr);
267
268 if (!mp->enabled)
269 continue;
270
Tomi Valkeinen34861372011-11-18 15:43:29 +0200271 if (mgr_manual_update(mgr)) {
272 /* to catch FRAMEDONE */
273 if (mp->updating)
274 return true;
275 } else {
276 /* to catch GO bit going down */
277 if (mp->busy)
278 return true;
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200279
280 /* to write new values to registers */
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200281 if (mp->info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200282 return true;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200283
Tomi Valkeinen9f808952011-11-25 17:26:13 +0200284 /* to set GO bit */
285 if (mp->shadow_info_dirty)
286 return true;
287
Archit Taneja45324a22012-04-26 19:31:22 +0530288 /*
289 * NOTE: we don't check extra_info flags for disabled
290 * managers, once the manager is enabled, the extra_info
291 * related manager changes will be taken in by HW.
292 */
293
294 /* to write new values to registers */
295 if (mp->extra_info_dirty)
296 return true;
297
298 /* to set GO bit */
299 if (mp->shadow_extra_info_dirty)
300 return true;
301
Tomi Valkeinen34861372011-11-18 15:43:29 +0200302 list_for_each_entry(ovl, &mgr->overlays, list) {
303 struct ovl_priv_data *op;
304
305 op = get_ovl_priv(ovl);
306
Tomi Valkeinen9f808952011-11-25 17:26:13 +0200307 /*
308 * NOTE: we check extra_info flags even for
309 * disabled overlays, as extra_infos need to be
310 * always written.
311 */
312
313 /* to write new values to registers */
314 if (op->extra_info_dirty)
315 return true;
316
317 /* to set GO bit */
318 if (op->shadow_extra_info_dirty)
319 return true;
320
Tomi Valkeinen34861372011-11-18 15:43:29 +0200321 if (!op->enabled)
322 continue;
323
324 /* to write new values to registers */
Tomi Valkeinen9f808952011-11-25 17:26:13 +0200325 if (op->info_dirty)
326 return true;
327
328 /* to set GO bit */
329 if (op->shadow_info_dirty)
Tomi Valkeinen34861372011-11-18 15:43:29 +0200330 return true;
331 }
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200332 }
333 }
334
335 return false;
336}
337
338static bool need_go(struct omap_overlay_manager *mgr)
339{
340 struct omap_overlay *ovl;
341 struct mgr_priv_data *mp;
342 struct ovl_priv_data *op;
343
344 mp = get_mgr_priv(mgr);
345
Archit Taneja45324a22012-04-26 19:31:22 +0530346 if (mp->shadow_info_dirty || mp->shadow_extra_info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200347 return true;
348
349 list_for_each_entry(ovl, &mgr->overlays, list) {
350 op = get_ovl_priv(ovl);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200351 if (op->shadow_info_dirty || op->shadow_extra_info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200352 return true;
353 }
354
355 return false;
356}
357
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200358/* returns true if an extra_info field is currently being updated */
359static bool extra_info_update_ongoing(void)
360{
Archit Taneja45324a22012-04-26 19:31:22 +0530361 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200362 int i;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200363
Archit Taneja45324a22012-04-26 19:31:22 +0530364 for (i = 0; i < num_mgrs; ++i) {
365 struct omap_overlay_manager *mgr;
366 struct omap_overlay *ovl;
367 struct mgr_priv_data *mp;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200368
Archit Taneja45324a22012-04-26 19:31:22 +0530369 mgr = omap_dss_get_overlay_manager(i);
370 mp = get_mgr_priv(mgr);
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200371
372 if (!mp->enabled)
373 continue;
374
Tomi Valkeinen153b6e72011-11-25 17:35:35 +0200375 if (!mp->updating)
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200376 continue;
377
Archit Taneja45324a22012-04-26 19:31:22 +0530378 if (mp->extra_info_dirty || mp->shadow_extra_info_dirty)
Tomi Valkeinen153b6e72011-11-25 17:35:35 +0200379 return true;
Archit Taneja45324a22012-04-26 19:31:22 +0530380
381 list_for_each_entry(ovl, &mgr->overlays, list) {
382 struct ovl_priv_data *op = get_ovl_priv(ovl);
383
384 if (op->extra_info_dirty || op->shadow_extra_info_dirty)
385 return true;
386 }
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200387 }
388
389 return false;
390}
391
392/* wait until no extra_info updates are pending */
393static void wait_pending_extra_info_updates(void)
394{
395 bool updating;
396 unsigned long flags;
397 unsigned long t;
Tomi Valkeinen46146792012-02-23 12:21:09 +0200398 int r;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200399
400 spin_lock_irqsave(&data_lock, flags);
401
402 updating = extra_info_update_ongoing();
403
404 if (!updating) {
405 spin_unlock_irqrestore(&data_lock, flags);
406 return;
407 }
408
409 init_completion(&extra_updated_completion);
410
411 spin_unlock_irqrestore(&data_lock, flags);
412
413 t = msecs_to_jiffies(500);
Tomi Valkeinen46146792012-02-23 12:21:09 +0200414 r = wait_for_completion_timeout(&extra_updated_completion, t);
415 if (r == 0)
416 DSSWARN("timeout in wait_pending_extra_info_updates\n");
417 else if (r < 0)
418 DSSERR("wait_pending_extra_info_updates failed: %d\n", r);
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200419}
420
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200421int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
422{
423 unsigned long timeout = msecs_to_jiffies(500);
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200424 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200425 u32 irq;
426 int r;
427 int i;
428 struct omap_dss_device *dssdev = mgr->device;
429
430 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
431 return 0;
432
433 if (mgr_manual_update(mgr))
434 return 0;
435
Lajos Molnar21e56f72012-02-22 12:23:16 +0530436 r = dispc_runtime_get();
437 if (r)
438 return r;
439
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200440 irq = dispc_mgr_get_vsync_irq(mgr->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200441
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200442 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200443 i = 0;
444 while (1) {
445 unsigned long flags;
446 bool shadow_dirty, dirty;
447
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200448 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200449 dirty = mp->info_dirty;
450 shadow_dirty = mp->shadow_info_dirty;
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200451 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200452
453 if (!dirty && !shadow_dirty) {
454 r = 0;
455 break;
456 }
457
458 /* 4 iterations is the worst case:
459 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
460 * 2 - first VSYNC, dirty = true
461 * 3 - dirty = false, shadow_dirty = true
462 * 4 - shadow_dirty = false */
463 if (i++ == 3) {
464 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
465 mgr->id);
466 r = 0;
467 break;
468 }
469
470 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
471 if (r == -ERESTARTSYS)
472 break;
473
474 if (r) {
475 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
476 break;
477 }
478 }
479
Lajos Molnar21e56f72012-02-22 12:23:16 +0530480 dispc_runtime_put();
481
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200482 return r;
483}
484
485int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
486{
487 unsigned long timeout = msecs_to_jiffies(500);
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200488 struct ovl_priv_data *op;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200489 struct omap_dss_device *dssdev;
490 u32 irq;
491 int r;
492 int i;
493
494 if (!ovl->manager)
495 return 0;
496
497 dssdev = ovl->manager->device;
498
499 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
500 return 0;
501
502 if (ovl_manual_update(ovl))
503 return 0;
504
Lajos Molnar21e56f72012-02-22 12:23:16 +0530505 r = dispc_runtime_get();
506 if (r)
507 return r;
508
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200509 irq = dispc_mgr_get_vsync_irq(ovl->manager->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200510
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200511 op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200512 i = 0;
513 while (1) {
514 unsigned long flags;
515 bool shadow_dirty, dirty;
516
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200517 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200518 dirty = op->info_dirty;
519 shadow_dirty = op->shadow_info_dirty;
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200520 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200521
522 if (!dirty && !shadow_dirty) {
523 r = 0;
524 break;
525 }
526
527 /* 4 iterations is the worst case:
528 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
529 * 2 - first VSYNC, dirty = true
530 * 3 - dirty = false, shadow_dirty = true
531 * 4 - shadow_dirty = false */
532 if (i++ == 3) {
533 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
534 ovl->id);
535 r = 0;
536 break;
537 }
538
539 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
540 if (r == -ERESTARTSYS)
541 break;
542
543 if (r) {
544 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
545 break;
546 }
547 }
548
Lajos Molnar21e56f72012-02-22 12:23:16 +0530549 dispc_runtime_put();
550
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200551 return r;
552}
553
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200554static void dss_ovl_write_regs(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200555{
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200556 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200557 struct omap_overlay_info *oi;
Archit Taneja8050cbe2012-06-06 16:25:52 +0530558 bool replication;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200559 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200560 int r;
561
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200562 DSSDBGF("%d", ovl->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200563
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200564 if (!op->enabled || !op->info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200565 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200566
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200567 oi = &op->info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200568
Archit Taneja81ab95b2012-05-08 15:53:20 +0530569 mp = get_mgr_priv(ovl->manager);
570
Archit Taneja6c6f5102012-06-25 14:58:48 +0530571 replication = dss_ovl_use_replication(mp->lcd_config, oi->color_mode);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200572
Archit Taneja8050cbe2012-06-06 16:25:52 +0530573 r = dispc_ovl_setup(ovl->id, oi, replication, &mp->timings);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200574 if (r) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200575 /*
576 * We can't do much here, as this function can be called from
577 * vsync interrupt.
578 */
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200579 DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id);
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200580
581 /* This will leave fifo configurations in a nonoptimal state */
582 op->enabled = false;
583 dispc_ovl_enable(ovl->id, false);
584 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200585 }
586
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200587 op->info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200588 if (mp->updating)
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200589 op->shadow_info_dirty = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200590}
591
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200592static void dss_ovl_write_regs_extra(struct omap_overlay *ovl)
593{
594 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinen34861372011-11-18 15:43:29 +0200595 struct mgr_priv_data *mp;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200596
597 DSSDBGF("%d", ovl->id);
598
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200599 if (!op->extra_info_dirty)
600 return;
601
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200602 /* note: write also when op->enabled == false, so that the ovl gets
603 * disabled */
604
605 dispc_ovl_enable(ovl->id, op->enabled);
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +0200606 dispc_ovl_set_channel_out(ovl->id, op->channel);
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200607 dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high);
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200608
Tomi Valkeinen34861372011-11-18 15:43:29 +0200609 mp = get_mgr_priv(ovl->manager);
610
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200611 op->extra_info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200612 if (mp->updating)
613 op->shadow_extra_info_dirty = true;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200614}
615
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200616static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200617{
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200618 struct mgr_priv_data *mp = get_mgr_priv(mgr);
619 struct omap_overlay *ovl;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200620
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200621 DSSDBGF("%d", mgr->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200622
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200623 if (!mp->enabled)
624 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200625
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200626 WARN_ON(mp->busy);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200627
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200628 /* Commit overlay settings */
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200629 list_for_each_entry(ovl, &mgr->overlays, list) {
630 dss_ovl_write_regs(ovl);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200631 dss_ovl_write_regs_extra(ovl);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200632 }
633
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200634 if (mp->info_dirty) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200635 dispc_mgr_setup(mgr->id, &mp->info);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200636
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200637 mp->info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200638 if (mp->updating)
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200639 mp->shadow_info_dirty = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200640 }
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200641}
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200642
Archit Taneja45324a22012-04-26 19:31:22 +0530643static void dss_mgr_write_regs_extra(struct omap_overlay_manager *mgr)
644{
645 struct mgr_priv_data *mp = get_mgr_priv(mgr);
646
647 DSSDBGF("%d", mgr->id);
648
649 if (!mp->extra_info_dirty)
650 return;
651
652 dispc_mgr_set_timings(mgr->id, &mp->timings);
653
Archit Tanejaf476ae92012-06-29 14:37:03 +0530654 /* lcd_config parameters */
655 if (dss_mgr_is_lcd(mgr->id)) {
656 dispc_mgr_set_io_pad_mode(mp->lcd_config.io_pad_mode);
657
658 dispc_mgr_enable_stallmode(mgr->id, mp->lcd_config.stallmode);
659 dispc_mgr_enable_fifohandcheck(mgr->id,
660 mp->lcd_config.fifohandcheck);
661
662 dispc_mgr_set_clock_div(mgr->id, &mp->lcd_config.clock_info);
663
664 dispc_mgr_set_tft_data_lines(mgr->id,
665 mp->lcd_config.video_port_width);
666
667 dispc_lcd_enable_signal_polarity(mp->lcd_config.lcden_sig_polarity);
668
669 dispc_mgr_set_lcd_type_tft(mgr->id);
670 }
671
Archit Taneja45324a22012-04-26 19:31:22 +0530672 mp->extra_info_dirty = false;
673 if (mp->updating)
674 mp->shadow_extra_info_dirty = true;
675}
676
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200677static void dss_write_regs(void)
678{
679 const int num_mgrs = omap_dss_get_num_overlay_managers();
680 int i;
681
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200682 for (i = 0; i < num_mgrs; ++i) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200683 struct omap_overlay_manager *mgr;
684 struct mgr_priv_data *mp;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200685 int r;
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200686
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200687 mgr = omap_dss_get_overlay_manager(i);
688 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200689
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200690 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200691 continue;
692
Archit Taneja228b2132012-04-27 01:22:28 +0530693 r = dss_check_settings(mgr);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200694 if (r) {
695 DSSERR("cannot write registers for manager %s: "
696 "illegal configuration\n", mgr->name);
697 continue;
698 }
699
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200700 dss_mgr_write_regs(mgr);
Archit Taneja45324a22012-04-26 19:31:22 +0530701 dss_mgr_write_regs_extra(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200702 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200703}
704
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +0200705static void dss_set_go_bits(void)
706{
707 const int num_mgrs = omap_dss_get_num_overlay_managers();
708 int i;
709
710 for (i = 0; i < num_mgrs; ++i) {
711 struct omap_overlay_manager *mgr;
712 struct mgr_priv_data *mp;
713
714 mgr = omap_dss_get_overlay_manager(i);
715 mp = get_mgr_priv(mgr);
716
717 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
718 continue;
719
720 if (!need_go(mgr))
721 continue;
722
723 mp->busy = true;
724
725 if (!dss_data.irq_enabled && need_isr())
726 dss_register_vsync_isr();
727
728 dispc_mgr_go(mgr->id);
729 }
730
731}
732
Tomi Valkeinendf01d532012-03-07 10:28:48 +0200733static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
734{
735 struct omap_overlay *ovl;
736 struct mgr_priv_data *mp;
737 struct ovl_priv_data *op;
738
739 mp = get_mgr_priv(mgr);
740 mp->shadow_info_dirty = false;
Archit Taneja45324a22012-04-26 19:31:22 +0530741 mp->shadow_extra_info_dirty = false;
Tomi Valkeinendf01d532012-03-07 10:28:48 +0200742
743 list_for_each_entry(ovl, &mgr->overlays, list) {
744 op = get_ovl_priv(ovl);
745 op->shadow_info_dirty = false;
746 op->shadow_extra_info_dirty = false;
747 }
748}
749
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200750void dss_mgr_start_update(struct omap_overlay_manager *mgr)
751{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200752 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200753 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200754 int r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200755
756 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200757
Tomi Valkeinen34861372011-11-18 15:43:29 +0200758 WARN_ON(mp->updating);
759
Archit Taneja228b2132012-04-27 01:22:28 +0530760 r = dss_check_settings(mgr);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200761 if (r) {
762 DSSERR("cannot start manual update: illegal configuration\n");
763 spin_unlock_irqrestore(&data_lock, flags);
764 return;
765 }
766
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200767 dss_mgr_write_regs(mgr);
Archit Taneja45324a22012-04-26 19:31:22 +0530768 dss_mgr_write_regs_extra(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200769
Tomi Valkeinen34861372011-11-18 15:43:29 +0200770 mp->updating = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200771
Tomi Valkeinen34861372011-11-18 15:43:29 +0200772 if (!dss_data.irq_enabled && need_isr())
773 dss_register_vsync_isr();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200774
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200775 dispc_mgr_enable(mgr->id, true);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200776
Tomi Valkeinendf01d532012-03-07 10:28:48 +0200777 mgr_clear_shadow_dirty(mgr);
778
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200779 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200780}
781
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200782static void dss_apply_irq_handler(void *data, u32 mask);
783
784static void dss_register_vsync_isr(void)
785{
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200786 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200787 u32 mask;
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200788 int r, i;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200789
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200790 mask = 0;
791 for (i = 0; i < num_mgrs; ++i)
792 mask |= dispc_mgr_get_vsync_irq(i);
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200793
Tomi Valkeinen34861372011-11-18 15:43:29 +0200794 for (i = 0; i < num_mgrs; ++i)
795 mask |= dispc_mgr_get_framedone_irq(i);
796
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200797 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
798 WARN_ON(r);
799
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200800 dss_data.irq_enabled = true;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200801}
802
803static void dss_unregister_vsync_isr(void)
804{
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200805 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200806 u32 mask;
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200807 int r, i;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200808
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200809 mask = 0;
810 for (i = 0; i < num_mgrs; ++i)
811 mask |= dispc_mgr_get_vsync_irq(i);
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200812
Tomi Valkeinen34861372011-11-18 15:43:29 +0200813 for (i = 0; i < num_mgrs; ++i)
814 mask |= dispc_mgr_get_framedone_irq(i);
815
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200816 r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask);
817 WARN_ON(r);
818
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200819 dss_data.irq_enabled = false;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200820}
821
Tomi Valkeinen76098932011-11-16 12:03:22 +0200822static void dss_apply_irq_handler(void *data, u32 mask)
823{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200824 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200825 int i;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200826 bool extra_updating;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200827
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200828 spin_lock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200829
Tomi Valkeinen76098932011-11-16 12:03:22 +0200830 /* clear busy, updating flags, shadow_dirty flags */
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200831 for (i = 0; i < num_mgrs; i++) {
Tomi Valkeinen76098932011-11-16 12:03:22 +0200832 struct omap_overlay_manager *mgr;
833 struct mgr_priv_data *mp;
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200834 bool was_updating;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200835
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200836 mgr = omap_dss_get_overlay_manager(i);
837 mp = get_mgr_priv(mgr);
838
Tomi Valkeinen76098932011-11-16 12:03:22 +0200839 if (!mp->enabled)
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200840 continue;
841
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200842 was_updating = mp->updating;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200843 mp->updating = dispc_mgr_is_enabled(i);
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200844
Tomi Valkeinen76098932011-11-16 12:03:22 +0200845 if (!mgr_manual_update(mgr)) {
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200846 bool was_busy = mp->busy;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200847 mp->busy = dispc_mgr_go_busy(i);
848
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200849 if (was_busy && !mp->busy)
Tomi Valkeinen76098932011-11-16 12:03:22 +0200850 mgr_clear_shadow_dirty(mgr);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200851 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200852 }
853
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200854 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +0200855 dss_set_go_bits();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200856
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200857 extra_updating = extra_info_update_ongoing();
858 if (!extra_updating)
859 complete_all(&extra_updated_completion);
860
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200861 if (!need_isr())
862 dss_unregister_vsync_isr();
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200863
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200864 spin_unlock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200865}
866
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200867static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200868{
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200869 struct ovl_priv_data *op;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200870
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200871 op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200872
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200873 if (!op->user_info_dirty)
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200874 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200875
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200876 op->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200877 op->info_dirty = true;
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200878 op->info = op->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200879}
880
881static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
882{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200883 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200884
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200885 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200886
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200887 if (!mp->user_info_dirty)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200888 return;
889
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200890 mp->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200891 mp->info_dirty = true;
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200892 mp->info = mp->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200893}
894
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200895int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
896{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200897 unsigned long flags;
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200898 struct omap_overlay *ovl;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200899 int r;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200900
901 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
902
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200903 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200904
Archit Taneja228b2132012-04-27 01:22:28 +0530905 r = dss_check_settings_apply(mgr);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200906 if (r) {
907 spin_unlock_irqrestore(&data_lock, flags);
908 DSSERR("failed to apply settings: illegal configuration.\n");
909 return r;
910 }
911
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200912 /* Configure overlays */
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200913 list_for_each_entry(ovl, &mgr->overlays, list)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200914 omap_dss_mgr_apply_ovl(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200915
916 /* Configure manager */
917 omap_dss_mgr_apply_mgr(mgr);
918
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200919 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +0200920 dss_set_go_bits();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200921
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200922 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200923
Tomi Valkeinene70f98a2011-11-16 16:53:44 +0200924 return 0;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200925}
926
Tomi Valkeinen841c09c2011-11-16 15:25:53 +0200927static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
928{
929 struct ovl_priv_data *op;
930
931 op = get_ovl_priv(ovl);
932
933 if (op->enabled == enable)
934 return;
935
936 op->enabled = enable;
937 op->extra_info_dirty = true;
938}
939
Tomi Valkeinen04576d42011-11-26 14:39:16 +0200940static void dss_apply_ovl_fifo_thresholds(struct omap_overlay *ovl,
941 u32 fifo_low, u32 fifo_high)
942{
943 struct ovl_priv_data *op = get_ovl_priv(ovl);
944
945 if (op->fifo_low == fifo_low && op->fifo_high == fifo_high)
946 return;
947
948 op->fifo_low = fifo_low;
949 op->fifo_high = fifo_high;
950 op->extra_info_dirty = true;
951}
952
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +0300953static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200954{
955 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200956 u32 fifo_low, fifo_high;
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +0300957 bool use_fifo_merge = false;
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200958
Tomi Valkeinen75ae1182011-11-26 14:36:19 +0200959 if (!op->enabled && !op->enabling)
960 return;
961
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +0200962 dispc_ovl_compute_fifo_thresholds(ovl->id, &fifo_low, &fifo_high,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +0300963 use_fifo_merge, ovl_manual_update(ovl));
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200964
Tomi Valkeinen04576d42011-11-26 14:39:16 +0200965 dss_apply_ovl_fifo_thresholds(ovl, fifo_low, fifo_high);
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200966}
967
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +0300968static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200969{
970 struct omap_overlay *ovl;
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200971 struct mgr_priv_data *mp;
972
973 mp = get_mgr_priv(mgr);
974
975 if (!mp->enabled)
976 return;
977
Tomi Valkeinen75ae1182011-11-26 14:36:19 +0200978 list_for_each_entry(ovl, &mgr->overlays, list)
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +0300979 dss_ovl_setup_fifo(ovl);
Tomi Valkeinen75ae1182011-11-26 14:36:19 +0200980}
981
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +0300982static void dss_setup_fifos(void)
Tomi Valkeinen75ae1182011-11-26 14:36:19 +0200983{
984 const int num_mgrs = omap_dss_get_num_overlay_managers();
985 struct omap_overlay_manager *mgr;
986 int i;
987
988 for (i = 0; i < num_mgrs; ++i) {
989 mgr = omap_dss_get_overlay_manager(i);
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +0300990 dss_mgr_setup_fifos(mgr);
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200991 }
992}
993
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +0200994int dss_mgr_enable(struct omap_overlay_manager *mgr)
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +0200995{
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200996 struct mgr_priv_data *mp = get_mgr_priv(mgr);
997 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200998 int r;
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200999
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001000 mutex_lock(&apply_lock);
1001
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001002 if (mp->enabled)
1003 goto out;
1004
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001005 spin_lock_irqsave(&data_lock, flags);
1006
1007 mp->enabled = true;
Tomi Valkeinena6b24f82011-11-26 14:29:39 +02001008
Archit Taneja228b2132012-04-27 01:22:28 +05301009 r = dss_check_settings(mgr);
Tomi Valkeinen39518352011-11-17 17:35:28 +02001010 if (r) {
1011 DSSERR("failed to enable manager %d: check_settings failed\n",
1012 mgr->id);
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001013 goto err;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001014 }
1015
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +03001016 dss_setup_fifos();
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001017
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001018 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +02001019 dss_set_go_bits();
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001020
Tomi Valkeinen34861372011-11-18 15:43:29 +02001021 if (!mgr_manual_update(mgr))
1022 mp->updating = true;
1023
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001024 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001025
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001026 if (!mgr_manual_update(mgr))
1027 dispc_mgr_enable(mgr->id, true);
1028
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001029out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001030 mutex_unlock(&apply_lock);
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001031
1032 return 0;
1033
1034err:
Tomi Valkeinena6b24f82011-11-26 14:29:39 +02001035 mp->enabled = false;
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001036 spin_unlock_irqrestore(&data_lock, flags);
1037 mutex_unlock(&apply_lock);
1038 return r;
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001039}
1040
1041void dss_mgr_disable(struct omap_overlay_manager *mgr)
1042{
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001043 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1044 unsigned long flags;
1045
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001046 mutex_lock(&apply_lock);
1047
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001048 if (!mp->enabled)
1049 goto out;
1050
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02001051 if (!mgr_manual_update(mgr))
1052 dispc_mgr_enable(mgr->id, false);
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001053
1054 spin_lock_irqsave(&data_lock, flags);
1055
Tomi Valkeinen34861372011-11-18 15:43:29 +02001056 mp->updating = false;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001057 mp->enabled = false;
1058
1059 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001060
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001061out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001062 mutex_unlock(&apply_lock);
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001063}
1064
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001065int dss_mgr_set_info(struct omap_overlay_manager *mgr,
1066 struct omap_overlay_manager_info *info)
1067{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001068 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001069 unsigned long flags;
Tomi Valkeinenf17d04f2011-11-17 14:31:09 +02001070 int r;
1071
1072 r = dss_mgr_simple_check(mgr, info);
1073 if (r)
1074 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001075
1076 spin_lock_irqsave(&data_lock, flags);
1077
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001078 mp->user_info = *info;
1079 mp->user_info_dirty = true;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001080
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001081 spin_unlock_irqrestore(&data_lock, flags);
1082
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001083 return 0;
1084}
1085
1086void dss_mgr_get_info(struct omap_overlay_manager *mgr,
1087 struct omap_overlay_manager_info *info)
1088{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001089 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001090 unsigned long flags;
1091
1092 spin_lock_irqsave(&data_lock, flags);
1093
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001094 *info = mp->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001095
1096 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001097}
1098
1099int dss_mgr_set_device(struct omap_overlay_manager *mgr,
1100 struct omap_dss_device *dssdev)
1101{
1102 int r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001103
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001104 mutex_lock(&apply_lock);
1105
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001106 if (dssdev->manager) {
1107 DSSERR("display '%s' already has a manager '%s'\n",
1108 dssdev->name, dssdev->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001109 r = -EINVAL;
1110 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001111 }
1112
1113 if ((mgr->supported_displays & dssdev->type) == 0) {
1114 DSSERR("display '%s' does not support manager '%s'\n",
1115 dssdev->name, mgr->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001116 r = -EINVAL;
1117 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001118 }
1119
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001120 dssdev->manager = mgr;
1121 mgr->device = dssdev;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001122
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001123 mutex_unlock(&apply_lock);
1124
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001125 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001126err:
1127 mutex_unlock(&apply_lock);
1128 return r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001129}
1130
1131int dss_mgr_unset_device(struct omap_overlay_manager *mgr)
1132{
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001133 int r;
1134
1135 mutex_lock(&apply_lock);
1136
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001137 if (!mgr->device) {
1138 DSSERR("failed to unset display, display not set.\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001139 r = -EINVAL;
1140 goto err;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001141 }
1142
1143 /*
1144 * Don't allow currently enabled displays to have the overlay manager
1145 * pulled out from underneath them
1146 */
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001147 if (mgr->device->state != OMAP_DSS_DISPLAY_DISABLED) {
1148 r = -EINVAL;
1149 goto err;
1150 }
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001151
1152 mgr->device->manager = NULL;
1153 mgr->device = NULL;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001154
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001155 mutex_unlock(&apply_lock);
1156
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001157 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001158err:
1159 mutex_unlock(&apply_lock);
1160 return r;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001161}
1162
Archit Taneja45324a22012-04-26 19:31:22 +05301163static void dss_apply_mgr_timings(struct omap_overlay_manager *mgr,
Archit Taneja27dfddc2012-07-19 13:51:14 +05301164 const struct omap_video_timings *timings)
Archit Taneja45324a22012-04-26 19:31:22 +05301165{
1166 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1167
1168 mp->timings = *timings;
1169 mp->extra_info_dirty = true;
1170}
1171
1172void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
Archit Taneja27dfddc2012-07-19 13:51:14 +05301173 const struct omap_video_timings *timings)
Archit Taneja45324a22012-04-26 19:31:22 +05301174{
1175 unsigned long flags;
Tomi Valkeinenfed62e52012-08-09 18:13:13 +03001176 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Archit Taneja45324a22012-04-26 19:31:22 +05301177
1178 spin_lock_irqsave(&data_lock, flags);
1179
Tomi Valkeinenfed62e52012-08-09 18:13:13 +03001180 if (mp->updating) {
1181 DSSERR("cannot set timings for %s: manager needs to be disabled\n",
1182 mgr->name);
1183 goto out;
1184 }
1185
Archit Taneja45324a22012-04-26 19:31:22 +05301186 dss_apply_mgr_timings(mgr, timings);
Tomi Valkeinenfed62e52012-08-09 18:13:13 +03001187out:
Archit Taneja45324a22012-04-26 19:31:22 +05301188 spin_unlock_irqrestore(&data_lock, flags);
Archit Taneja45324a22012-04-26 19:31:22 +05301189}
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001190
Archit Tanejaf476ae92012-06-29 14:37:03 +05301191static void dss_apply_mgr_lcd_config(struct omap_overlay_manager *mgr,
1192 const struct dss_lcd_mgr_config *config)
1193{
1194 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1195
1196 mp->lcd_config = *config;
1197 mp->extra_info_dirty = true;
1198}
1199
1200void dss_mgr_set_lcd_config(struct omap_overlay_manager *mgr,
1201 const struct dss_lcd_mgr_config *config)
1202{
1203 unsigned long flags;
1204 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1205
Tomi Valkeinenaba96572012-08-09 18:07:45 +03001206 spin_lock_irqsave(&data_lock, flags);
Archit Tanejaf476ae92012-06-29 14:37:03 +05301207
1208 if (mp->enabled) {
1209 DSSERR("cannot apply lcd config for %s: manager needs to be disabled\n",
1210 mgr->name);
1211 goto out;
1212 }
1213
Archit Tanejaf476ae92012-06-29 14:37:03 +05301214 dss_apply_mgr_lcd_config(mgr, config);
Archit Tanejaf476ae92012-06-29 14:37:03 +05301215out:
Tomi Valkeinenaba96572012-08-09 18:07:45 +03001216 spin_unlock_irqrestore(&data_lock, flags);
Archit Tanejaf476ae92012-06-29 14:37:03 +05301217}
1218
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001219int dss_ovl_set_info(struct omap_overlay *ovl,
1220 struct omap_overlay_info *info)
1221{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001222 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001223 unsigned long flags;
Tomi Valkeinenfcc764d2011-11-17 14:26:48 +02001224 int r;
1225
1226 r = dss_ovl_simple_check(ovl, info);
1227 if (r)
1228 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001229
1230 spin_lock_irqsave(&data_lock, flags);
1231
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001232 op->user_info = *info;
1233 op->user_info_dirty = true;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001234
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001235 spin_unlock_irqrestore(&data_lock, flags);
1236
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001237 return 0;
1238}
1239
1240void dss_ovl_get_info(struct omap_overlay *ovl,
1241 struct omap_overlay_info *info)
1242{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001243 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001244 unsigned long flags;
1245
1246 spin_lock_irqsave(&data_lock, flags);
1247
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001248 *info = op->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001249
1250 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001251}
1252
1253int dss_ovl_set_manager(struct omap_overlay *ovl,
1254 struct omap_overlay_manager *mgr)
1255{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001256 struct ovl_priv_data *op = get_ovl_priv(ovl);
1257 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001258 int r;
1259
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001260 if (!mgr)
1261 return -EINVAL;
1262
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001263 mutex_lock(&apply_lock);
1264
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001265 if (ovl->manager) {
1266 DSSERR("overlay '%s' already has a manager '%s'\n",
1267 ovl->name, ovl->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001268 r = -EINVAL;
1269 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001270 }
1271
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001272 spin_lock_irqsave(&data_lock, flags);
1273
1274 if (op->enabled) {
1275 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001276 DSSERR("overlay has to be disabled to change the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001277 r = -EINVAL;
1278 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001279 }
1280
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001281 op->channel = mgr->id;
1282 op->extra_info_dirty = true;
1283
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001284 ovl->manager = mgr;
1285 list_add_tail(&ovl->list, &mgr->overlays);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001286
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001287 spin_unlock_irqrestore(&data_lock, flags);
1288
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001289 /* XXX: When there is an overlay on a DSI manual update display, and
1290 * the overlay is first disabled, then moved to tv, and enabled, we
1291 * seem to get SYNC_LOST_DIGIT error.
1292 *
1293 * Waiting doesn't seem to help, but updating the manual update display
1294 * after disabling the overlay seems to fix this. This hints that the
1295 * overlay is perhaps somehow tied to the LCD output until the output
1296 * is updated.
1297 *
1298 * Userspace workaround for this is to update the LCD after disabling
1299 * the overlay, but before moving the overlay to TV.
1300 */
1301
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001302 mutex_unlock(&apply_lock);
1303
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001304 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001305err:
1306 mutex_unlock(&apply_lock);
1307 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001308}
1309
1310int dss_ovl_unset_manager(struct omap_overlay *ovl)
1311{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001312 struct ovl_priv_data *op = get_ovl_priv(ovl);
1313 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001314 int r;
1315
1316 mutex_lock(&apply_lock);
1317
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001318 if (!ovl->manager) {
1319 DSSERR("failed to detach overlay: manager not set\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001320 r = -EINVAL;
1321 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001322 }
1323
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001324 spin_lock_irqsave(&data_lock, flags);
1325
1326 if (op->enabled) {
1327 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001328 DSSERR("overlay has to be disabled to unset the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001329 r = -EINVAL;
1330 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001331 }
1332
Tomi Valkeinenb2f59762012-09-06 16:10:28 +03001333 spin_unlock_irqrestore(&data_lock, flags);
1334
1335 /* wait for pending extra_info updates to ensure the ovl is disabled */
1336 wait_pending_extra_info_updates();
1337
1338 spin_lock_irqsave(&data_lock, flags);
1339
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001340 op->channel = -1;
1341
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001342 ovl->manager = NULL;
1343 list_del(&ovl->list);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001344
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001345 spin_unlock_irqrestore(&data_lock, flags);
1346
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001347 mutex_unlock(&apply_lock);
1348
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001349 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001350err:
1351 mutex_unlock(&apply_lock);
1352 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001353}
1354
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001355bool dss_ovl_is_enabled(struct omap_overlay *ovl)
1356{
1357 struct ovl_priv_data *op = get_ovl_priv(ovl);
1358 unsigned long flags;
1359 bool e;
1360
1361 spin_lock_irqsave(&data_lock, flags);
1362
1363 e = op->enabled;
1364
1365 spin_unlock_irqrestore(&data_lock, flags);
1366
1367 return e;
1368}
1369
1370int dss_ovl_enable(struct omap_overlay *ovl)
1371{
1372 struct ovl_priv_data *op = get_ovl_priv(ovl);
1373 unsigned long flags;
1374 int r;
1375
1376 mutex_lock(&apply_lock);
1377
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001378 if (op->enabled) {
1379 r = 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001380 goto err1;
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001381 }
1382
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001383 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1384 r = -EINVAL;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001385 goto err1;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001386 }
1387
1388 spin_lock_irqsave(&data_lock, flags);
1389
Tomi Valkeinen82153ed2011-11-26 14:26:46 +02001390 op->enabling = true;
1391
Archit Taneja228b2132012-04-27 01:22:28 +05301392 r = dss_check_settings(ovl->manager);
Tomi Valkeinen39518352011-11-17 17:35:28 +02001393 if (r) {
1394 DSSERR("failed to enable overlay %d: check_settings failed\n",
1395 ovl->id);
1396 goto err2;
1397 }
1398
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +03001399 dss_setup_fifos();
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001400
Tomi Valkeinen82153ed2011-11-26 14:26:46 +02001401 op->enabling = false;
1402 dss_apply_ovl_enable(ovl, true);
1403
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001404 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +02001405 dss_set_go_bits();
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001406
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001407 spin_unlock_irqrestore(&data_lock, flags);
1408
1409 mutex_unlock(&apply_lock);
1410
1411 return 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001412err2:
Tomi Valkeinen82153ed2011-11-26 14:26:46 +02001413 op->enabling = false;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001414 spin_unlock_irqrestore(&data_lock, flags);
1415err1:
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001416 mutex_unlock(&apply_lock);
1417 return r;
1418}
1419
1420int dss_ovl_disable(struct omap_overlay *ovl)
1421{
1422 struct ovl_priv_data *op = get_ovl_priv(ovl);
1423 unsigned long flags;
1424 int r;
1425
1426 mutex_lock(&apply_lock);
1427
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001428 if (!op->enabled) {
1429 r = 0;
1430 goto err;
1431 }
1432
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001433 if (ovl->manager == NULL || ovl->manager->device == NULL) {
1434 r = -EINVAL;
1435 goto err;
1436 }
1437
1438 spin_lock_irqsave(&data_lock, flags);
1439
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001440 dss_apply_ovl_enable(ovl, false);
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001441 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +02001442 dss_set_go_bits();
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001443
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001444 spin_unlock_irqrestore(&data_lock, flags);
1445
1446 mutex_unlock(&apply_lock);
1447
1448 return 0;
1449
1450err:
1451 mutex_unlock(&apply_lock);
1452 return r;
1453}
1454