blob: 60758dbefd79fda6d64df8246479b4dd1407f6cd [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>
Tomi Valkeinen8dd24912012-10-10 10:26:45 +030021#include <linux/module.h>
Tomi Valkeinen58f255482011-11-04 09:48:54 +020022#include <linux/slab.h>
23#include <linux/spinlock.h>
24#include <linux/jiffies.h>
25
26#include <video/omapdss.h>
27
28#include "dss.h"
29#include "dss_features.h"
Tomi Valkeinenbb398132012-10-24 12:39:53 +030030#include "dispc-compat.h"
Tomi Valkeinen58f255482011-11-04 09:48:54 +020031
32/*
33 * We have 4 levels of cache for the dispc settings. First two are in SW and
34 * the latter two in HW.
35 *
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020036 * set_info()
37 * v
Tomi Valkeinen58f255482011-11-04 09:48:54 +020038 * +--------------------+
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020039 * | user_info |
Tomi Valkeinen58f255482011-11-04 09:48:54 +020040 * +--------------------+
41 * v
42 * apply()
43 * v
44 * +--------------------+
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +020045 * | info |
Tomi Valkeinen58f255482011-11-04 09:48:54 +020046 * +--------------------+
47 * v
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +020048 * write_regs()
Tomi Valkeinen58f255482011-11-04 09:48:54 +020049 * v
50 * +--------------------+
51 * | shadow registers |
52 * +--------------------+
53 * v
54 * VFP or lcd/digit_enable
55 * v
56 * +--------------------+
57 * | registers |
58 * +--------------------+
59 */
60
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +020061struct ovl_priv_data {
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +020062
63 bool user_info_dirty;
64 struct omap_overlay_info user_info;
65
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020066 bool info_dirty;
Tomi Valkeinen58f255482011-11-04 09:48:54 +020067 struct omap_overlay_info info;
68
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020069 bool shadow_info_dirty;
70
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +020071 bool extra_info_dirty;
72 bool shadow_extra_info_dirty;
73
74 bool enabled;
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +020075 u32 fifo_low, fifo_high;
Tomi Valkeinen82153ed2011-11-26 14:26:46 +020076
77 /*
78 * True if overlay is to be enabled. Used to check and calculate configs
79 * for the overlay before it is enabled in the HW.
80 */
81 bool enabling;
Tomi Valkeinen58f255482011-11-04 09:48:54 +020082};
83
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +020084struct mgr_priv_data {
Tomi Valkeinen388c4c62011-11-16 13:58:07 +020085
86 bool user_info_dirty;
87 struct omap_overlay_manager_info user_info;
88
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020089 bool info_dirty;
Tomi Valkeinen58f255482011-11-04 09:48:54 +020090 struct omap_overlay_manager_info info;
91
Tomi Valkeinen0b53f172011-11-16 14:31:58 +020092 bool shadow_info_dirty;
93
Tomi Valkeinen43a972d2011-11-15 15:04:25 +020094 /* If true, GO bit is up and shadow registers cannot be written.
95 * Never true for manual update displays */
96 bool busy;
97
Tomi Valkeinen34861372011-11-18 15:43:29 +020098 /* If true, dispc output is enabled */
99 bool updating;
100
Tomi Valkeinenbf213522011-11-15 14:43:53 +0200101 /* If true, a display is enabled using this manager */
102 bool enabled;
Archit Taneja45324a22012-04-26 19:31:22 +0530103
104 bool extra_info_dirty;
105 bool shadow_extra_info_dirty;
106
107 struct omap_video_timings timings;
Archit Tanejaf476ae92012-06-29 14:37:03 +0530108 struct dss_lcd_mgr_config lcd_config;
Tomi Valkeinen15502022012-10-10 13:59:07 +0300109
110 void (*framedone_handler)(void *);
111 void *framedone_handler_data;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200112};
113
114static struct {
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200115 struct ovl_priv_data ovl_priv_data_array[MAX_DSS_OVERLAYS];
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200116 struct mgr_priv_data mgr_priv_data_array[MAX_DSS_MANAGERS];
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200117
118 bool irq_enabled;
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200119} dss_data;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200120
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200121/* protects dss_data */
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200122static spinlock_t data_lock;
Tomi Valkeinen5558db32011-11-15 14:28:48 +0200123/* lock for blocking functions */
124static DEFINE_MUTEX(apply_lock);
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200125static DECLARE_COMPLETION(extra_updated_completion);
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200126
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200127static void dss_register_vsync_isr(void);
128
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200129static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl)
130{
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200131 return &dss_data.ovl_priv_data_array[ovl->id];
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200132}
133
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200134static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr)
135{
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200136 return &dss_data.mgr_priv_data_array[mgr->id];
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200137}
138
Tomi Valkeinen8dd24912012-10-10 10:26:45 +0300139static void apply_init_priv(void)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200140{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200141 const int num_ovls = dss_feat_get_num_ovls();
Archit Tanejaf476ae92012-06-29 14:37:03 +0530142 struct mgr_priv_data *mp;
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200143 int i;
144
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200145 spin_lock_init(&data_lock);
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200146
147 for (i = 0; i < num_ovls; ++i) {
148 struct ovl_priv_data *op;
149
150 op = &dss_data.ovl_priv_data_array[i];
151
152 op->info.global_alpha = 255;
153
154 switch (i) {
155 case 0:
156 op->info.zorder = 0;
157 break;
158 case 1:
159 op->info.zorder =
160 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 3 : 0;
161 break;
162 case 2:
163 op->info.zorder =
164 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 2 : 0;
165 break;
166 case 3:
167 op->info.zorder =
168 dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 1 : 0;
169 break;
170 }
171
172 op->user_info = op->info;
173 }
Archit Tanejaf476ae92012-06-29 14:37:03 +0530174
175 /*
176 * Initialize some of the lcd_config fields for TV manager, this lets
177 * us prevent checking if the manager is LCD or TV at some places
178 */
179 mp = &dss_data.mgr_priv_data_array[OMAP_DSS_CHANNEL_DIGIT];
180
181 mp->lcd_config.video_port_width = 24;
182 mp->lcd_config.clock_info.lck_div = 1;
183 mp->lcd_config.clock_info.pck_div = 1;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200184}
185
Archit Taneja75bac5d2012-05-24 15:08:54 +0530186/*
187 * A LCD manager's stallmode decides whether it is in manual or auto update. TV
188 * manager is always auto update, stallmode field for TV manager is false by
189 * default
190 */
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200191static bool ovl_manual_update(struct omap_overlay *ovl)
192{
Archit Taneja75bac5d2012-05-24 15:08:54 +0530193 struct mgr_priv_data *mp = get_mgr_priv(ovl->manager);
194
195 return mp->lcd_config.stallmode;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200196}
197
198static bool mgr_manual_update(struct omap_overlay_manager *mgr)
199{
Archit Taneja75bac5d2012-05-24 15:08:54 +0530200 struct mgr_priv_data *mp = get_mgr_priv(mgr);
201
202 return mp->lcd_config.stallmode;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200203}
204
Tomi Valkeinen39518352011-11-17 17:35:28 +0200205static int dss_check_settings_low(struct omap_overlay_manager *mgr,
Archit Taneja228b2132012-04-27 01:22:28 +0530206 bool applying)
Tomi Valkeinen39518352011-11-17 17:35:28 +0200207{
208 struct omap_overlay_info *oi;
209 struct omap_overlay_manager_info *mi;
210 struct omap_overlay *ovl;
211 struct omap_overlay_info *ois[MAX_DSS_OVERLAYS];
212 struct ovl_priv_data *op;
213 struct mgr_priv_data *mp;
214
215 mp = get_mgr_priv(mgr);
216
Archit Taneja5dd747e2012-05-08 18:19:15 +0530217 if (!mp->enabled)
218 return 0;
219
Tomi Valkeinen39518352011-11-17 17:35:28 +0200220 if (applying && mp->user_info_dirty)
221 mi = &mp->user_info;
222 else
223 mi = &mp->info;
224
225 /* collect the infos to be tested into the array */
226 list_for_each_entry(ovl, &mgr->overlays, list) {
227 op = get_ovl_priv(ovl);
228
Tomi Valkeinen82153ed2011-11-26 14:26:46 +0200229 if (!op->enabled && !op->enabling)
Tomi Valkeinen39518352011-11-17 17:35:28 +0200230 oi = NULL;
231 else if (applying && op->user_info_dirty)
232 oi = &op->user_info;
233 else
234 oi = &op->info;
235
236 ois[ovl->id] = oi;
237 }
238
Archit Taneja6e543592012-05-23 17:01:35 +0530239 return dss_mgr_check(mgr, mi, &mp->timings, &mp->lcd_config, ois);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200240}
241
242/*
243 * check manager and overlay settings using overlay_info from data->info
244 */
Archit Taneja228b2132012-04-27 01:22:28 +0530245static int dss_check_settings(struct omap_overlay_manager *mgr)
Tomi Valkeinen39518352011-11-17 17:35:28 +0200246{
Archit Taneja228b2132012-04-27 01:22:28 +0530247 return dss_check_settings_low(mgr, false);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200248}
249
250/*
251 * check manager and overlay settings using overlay_info from ovl->info if
252 * dirty and from data->info otherwise
253 */
Archit Taneja228b2132012-04-27 01:22:28 +0530254static int dss_check_settings_apply(struct omap_overlay_manager *mgr)
Tomi Valkeinen39518352011-11-17 17:35:28 +0200255{
Archit Taneja228b2132012-04-27 01:22:28 +0530256 return dss_check_settings_low(mgr, true);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200257}
258
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200259static bool need_isr(void)
260{
261 const int num_mgrs = dss_feat_get_num_mgrs();
262 int i;
263
264 for (i = 0; i < num_mgrs; ++i) {
265 struct omap_overlay_manager *mgr;
266 struct mgr_priv_data *mp;
267 struct omap_overlay *ovl;
268
269 mgr = omap_dss_get_overlay_manager(i);
270 mp = get_mgr_priv(mgr);
271
272 if (!mp->enabled)
273 continue;
274
Tomi Valkeinen34861372011-11-18 15:43:29 +0200275 if (mgr_manual_update(mgr)) {
276 /* to catch FRAMEDONE */
277 if (mp->updating)
278 return true;
279 } else {
280 /* to catch GO bit going down */
281 if (mp->busy)
282 return true;
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200283
284 /* to write new values to registers */
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200285 if (mp->info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200286 return true;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200287
Tomi Valkeinen9f808952011-11-25 17:26:13 +0200288 /* to set GO bit */
289 if (mp->shadow_info_dirty)
290 return true;
291
Archit Taneja45324a22012-04-26 19:31:22 +0530292 /*
293 * NOTE: we don't check extra_info flags for disabled
294 * managers, once the manager is enabled, the extra_info
295 * related manager changes will be taken in by HW.
296 */
297
298 /* to write new values to registers */
299 if (mp->extra_info_dirty)
300 return true;
301
302 /* to set GO bit */
303 if (mp->shadow_extra_info_dirty)
304 return true;
305
Tomi Valkeinen34861372011-11-18 15:43:29 +0200306 list_for_each_entry(ovl, &mgr->overlays, list) {
307 struct ovl_priv_data *op;
308
309 op = get_ovl_priv(ovl);
310
Tomi Valkeinen9f808952011-11-25 17:26:13 +0200311 /*
312 * NOTE: we check extra_info flags even for
313 * disabled overlays, as extra_infos need to be
314 * always written.
315 */
316
317 /* to write new values to registers */
318 if (op->extra_info_dirty)
319 return true;
320
321 /* to set GO bit */
322 if (op->shadow_extra_info_dirty)
323 return true;
324
Tomi Valkeinen34861372011-11-18 15:43:29 +0200325 if (!op->enabled)
326 continue;
327
328 /* to write new values to registers */
Tomi Valkeinen9f808952011-11-25 17:26:13 +0200329 if (op->info_dirty)
330 return true;
331
332 /* to set GO bit */
333 if (op->shadow_info_dirty)
Tomi Valkeinen34861372011-11-18 15:43:29 +0200334 return true;
335 }
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200336 }
337 }
338
339 return false;
340}
341
342static bool need_go(struct omap_overlay_manager *mgr)
343{
344 struct omap_overlay *ovl;
345 struct mgr_priv_data *mp;
346 struct ovl_priv_data *op;
347
348 mp = get_mgr_priv(mgr);
349
Archit Taneja45324a22012-04-26 19:31:22 +0530350 if (mp->shadow_info_dirty || mp->shadow_extra_info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200351 return true;
352
353 list_for_each_entry(ovl, &mgr->overlays, list) {
354 op = get_ovl_priv(ovl);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200355 if (op->shadow_info_dirty || op->shadow_extra_info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200356 return true;
357 }
358
359 return false;
360}
361
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200362/* returns true if an extra_info field is currently being updated */
363static bool extra_info_update_ongoing(void)
364{
Archit Taneja45324a22012-04-26 19:31:22 +0530365 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200366 int i;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200367
Archit Taneja45324a22012-04-26 19:31:22 +0530368 for (i = 0; i < num_mgrs; ++i) {
369 struct omap_overlay_manager *mgr;
370 struct omap_overlay *ovl;
371 struct mgr_priv_data *mp;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200372
Archit Taneja45324a22012-04-26 19:31:22 +0530373 mgr = omap_dss_get_overlay_manager(i);
374 mp = get_mgr_priv(mgr);
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200375
376 if (!mp->enabled)
377 continue;
378
Tomi Valkeinen153b6e72011-11-25 17:35:35 +0200379 if (!mp->updating)
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200380 continue;
381
Archit Taneja45324a22012-04-26 19:31:22 +0530382 if (mp->extra_info_dirty || mp->shadow_extra_info_dirty)
Tomi Valkeinen153b6e72011-11-25 17:35:35 +0200383 return true;
Archit Taneja45324a22012-04-26 19:31:22 +0530384
385 list_for_each_entry(ovl, &mgr->overlays, list) {
386 struct ovl_priv_data *op = get_ovl_priv(ovl);
387
388 if (op->extra_info_dirty || op->shadow_extra_info_dirty)
389 return true;
390 }
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200391 }
392
393 return false;
394}
395
396/* wait until no extra_info updates are pending */
397static void wait_pending_extra_info_updates(void)
398{
399 bool updating;
400 unsigned long flags;
401 unsigned long t;
Tomi Valkeinen46146792012-02-23 12:21:09 +0200402 int r;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200403
404 spin_lock_irqsave(&data_lock, flags);
405
406 updating = extra_info_update_ongoing();
407
408 if (!updating) {
409 spin_unlock_irqrestore(&data_lock, flags);
410 return;
411 }
412
413 init_completion(&extra_updated_completion);
414
415 spin_unlock_irqrestore(&data_lock, flags);
416
417 t = msecs_to_jiffies(500);
Tomi Valkeinen46146792012-02-23 12:21:09 +0200418 r = wait_for_completion_timeout(&extra_updated_completion, t);
419 if (r == 0)
420 DSSWARN("timeout in wait_pending_extra_info_updates\n");
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200421}
422
Tomi Valkeinene7243662013-04-23 15:23:42 +0300423static struct omap_dss_device *dss_mgr_get_device(struct omap_overlay_manager *mgr)
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +0300424{
Tomi Valkeinenefedce12013-04-23 14:35:40 +0300425 struct omap_dss_device *dssdev;
426
427 dssdev = mgr->output;
428 if (dssdev == NULL)
429 return NULL;
430
Tomi Valkeinen9560dc102013-07-24 13:06:54 +0300431 while (dssdev->dst)
432 dssdev = dssdev->dst;
Tomi Valkeinenefedce12013-04-23 14:35:40 +0300433
434 if (dssdev->driver)
435 return dssdev;
436 else
437 return NULL;
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +0300438}
439
Tomi Valkeinene7243662013-04-23 15:23:42 +0300440static struct omap_dss_device *dss_ovl_get_device(struct omap_overlay *ovl)
441{
442 return ovl->manager ? dss_mgr_get_device(ovl->manager) : NULL;
443}
444
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +0300445static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
446{
447 unsigned long timeout = msecs_to_jiffies(500);
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +0300448 u32 irq;
449 int r;
450
Tomi Valkeinen346f1e02013-02-15 14:24:38 +0200451 if (mgr->output == NULL)
452 return -ENODEV;
453
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +0300454 r = dispc_runtime_get();
455 if (r)
456 return r;
457
Tomi Valkeinen346f1e02013-02-15 14:24:38 +0200458 switch (mgr->output->id) {
459 case OMAP_DSS_OUTPUT_VENC:
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +0300460 irq = DISPC_IRQ_EVSYNC_ODD;
Tomi Valkeinen346f1e02013-02-15 14:24:38 +0200461 break;
462 case OMAP_DSS_OUTPUT_HDMI:
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +0300463 irq = DISPC_IRQ_EVSYNC_EVEN;
Tomi Valkeinen346f1e02013-02-15 14:24:38 +0200464 break;
465 default:
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +0300466 irq = dispc_mgr_get_vsync_irq(mgr->id);
Tomi Valkeinen346f1e02013-02-15 14:24:38 +0200467 break;
468 }
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +0300469
470 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
471
472 dispc_runtime_put();
473
474 return r;
475}
476
477static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200478{
479 unsigned long timeout = msecs_to_jiffies(500);
Archit Tanejafc22a842012-06-26 15:36:55 +0530480 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200481 u32 irq;
Archit Tanejafc22a842012-06-26 15:36:55 +0530482 unsigned long flags;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200483 int r;
484 int i;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200485
Archit Tanejafc22a842012-06-26 15:36:55 +0530486 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200487
Archit Tanejafc22a842012-06-26 15:36:55 +0530488 if (mgr_manual_update(mgr)) {
489 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200490 return 0;
Archit Tanejafc22a842012-06-26 15:36:55 +0530491 }
492
493 if (!mp->enabled) {
494 spin_unlock_irqrestore(&data_lock, flags);
495 return 0;
496 }
497
498 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200499
Lajos Molnar21e56f72012-02-22 12:23:16 +0530500 r = dispc_runtime_get();
501 if (r)
502 return r;
503
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200504 irq = dispc_mgr_get_vsync_irq(mgr->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200505
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200506 i = 0;
507 while (1) {
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200508 bool shadow_dirty, dirty;
509
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200510 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200511 dirty = mp->info_dirty;
512 shadow_dirty = mp->shadow_info_dirty;
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200513 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200514
515 if (!dirty && !shadow_dirty) {
516 r = 0;
517 break;
518 }
519
520 /* 4 iterations is the worst case:
521 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
522 * 2 - first VSYNC, dirty = true
523 * 3 - dirty = false, shadow_dirty = true
524 * 4 - shadow_dirty = false */
525 if (i++ == 3) {
526 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
527 mgr->id);
528 r = 0;
529 break;
530 }
531
532 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
533 if (r == -ERESTARTSYS)
534 break;
535
536 if (r) {
537 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
538 break;
539 }
540 }
541
Lajos Molnar21e56f72012-02-22 12:23:16 +0530542 dispc_runtime_put();
543
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200544 return r;
545}
546
Tomi Valkeinen6abae7a2012-10-23 13:45:07 +0300547static int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200548{
549 unsigned long timeout = msecs_to_jiffies(500);
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200550 struct ovl_priv_data *op;
Archit Tanejafc22a842012-06-26 15:36:55 +0530551 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200552 u32 irq;
Archit Tanejafc22a842012-06-26 15:36:55 +0530553 unsigned long flags;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200554 int r;
555 int i;
556
557 if (!ovl->manager)
558 return 0;
559
Archit Tanejafc22a842012-06-26 15:36:55 +0530560 mp = get_mgr_priv(ovl->manager);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200561
Archit Tanejafc22a842012-06-26 15:36:55 +0530562 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200563
Archit Tanejafc22a842012-06-26 15:36:55 +0530564 if (ovl_manual_update(ovl)) {
565 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200566 return 0;
Archit Tanejafc22a842012-06-26 15:36:55 +0530567 }
568
569 if (!mp->enabled) {
570 spin_unlock_irqrestore(&data_lock, flags);
571 return 0;
572 }
573
574 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200575
Lajos Molnar21e56f72012-02-22 12:23:16 +0530576 r = dispc_runtime_get();
577 if (r)
578 return r;
579
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200580 irq = dispc_mgr_get_vsync_irq(ovl->manager->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200581
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200582 op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200583 i = 0;
584 while (1) {
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200585 bool shadow_dirty, dirty;
586
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200587 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200588 dirty = op->info_dirty;
589 shadow_dirty = op->shadow_info_dirty;
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200590 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200591
592 if (!dirty && !shadow_dirty) {
593 r = 0;
594 break;
595 }
596
597 /* 4 iterations is the worst case:
598 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
599 * 2 - first VSYNC, dirty = true
600 * 3 - dirty = false, shadow_dirty = true
601 * 4 - shadow_dirty = false */
602 if (i++ == 3) {
603 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
604 ovl->id);
605 r = 0;
606 break;
607 }
608
609 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
610 if (r == -ERESTARTSYS)
611 break;
612
613 if (r) {
614 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
615 break;
616 }
617 }
618
Lajos Molnar21e56f72012-02-22 12:23:16 +0530619 dispc_runtime_put();
620
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200621 return r;
622}
623
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200624static void dss_ovl_write_regs(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200625{
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200626 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200627 struct omap_overlay_info *oi;
Archit Taneja8050cbe2012-06-06 16:25:52 +0530628 bool replication;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200629 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200630 int r;
631
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +0530632 DSSDBG("writing ovl %d regs", ovl->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200633
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200634 if (!op->enabled || !op->info_dirty)
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200635 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200636
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200637 oi = &op->info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200638
Archit Taneja81ab95b2012-05-08 15:53:20 +0530639 mp = get_mgr_priv(ovl->manager);
640
Archit Taneja6c6f5102012-06-25 14:58:48 +0530641 replication = dss_ovl_use_replication(mp->lcd_config, oi->color_mode);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200642
Archit Taneja8ba85302012-09-26 17:00:37 +0530643 r = dispc_ovl_setup(ovl->id, oi, replication, &mp->timings, false);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200644 if (r) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200645 /*
646 * We can't do much here, as this function can be called from
647 * vsync interrupt.
648 */
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200649 DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id);
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200650
651 /* This will leave fifo configurations in a nonoptimal state */
652 op->enabled = false;
653 dispc_ovl_enable(ovl->id, false);
654 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200655 }
656
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200657 op->info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200658 if (mp->updating)
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200659 op->shadow_info_dirty = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200660}
661
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200662static void dss_ovl_write_regs_extra(struct omap_overlay *ovl)
663{
664 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinen34861372011-11-18 15:43:29 +0200665 struct mgr_priv_data *mp;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200666
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +0530667 DSSDBG("writing ovl %d regs extra", ovl->id);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200668
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200669 if (!op->extra_info_dirty)
670 return;
671
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200672 /* note: write also when op->enabled == false, so that the ovl gets
673 * disabled */
674
675 dispc_ovl_enable(ovl->id, op->enabled);
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +0200676 dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high);
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200677
Tomi Valkeinen34861372011-11-18 15:43:29 +0200678 mp = get_mgr_priv(ovl->manager);
679
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200680 op->extra_info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200681 if (mp->updating)
682 op->shadow_extra_info_dirty = true;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200683}
684
Tomi Valkeinenf6a5e082011-11-15 11:47:39 +0200685static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200686{
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200687 struct mgr_priv_data *mp = get_mgr_priv(mgr);
688 struct omap_overlay *ovl;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200689
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +0530690 DSSDBG("writing mgr %d regs", mgr->id);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200691
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200692 if (!mp->enabled)
693 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200694
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200695 WARN_ON(mp->busy);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200696
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200697 /* Commit overlay settings */
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200698 list_for_each_entry(ovl, &mgr->overlays, list) {
699 dss_ovl_write_regs(ovl);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200700 dss_ovl_write_regs_extra(ovl);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200701 }
702
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200703 if (mp->info_dirty) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200704 dispc_mgr_setup(mgr->id, &mp->info);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200705
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200706 mp->info_dirty = false;
Tomi Valkeinen34861372011-11-18 15:43:29 +0200707 if (mp->updating)
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200708 mp->shadow_info_dirty = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200709 }
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200710}
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200711
Archit Taneja45324a22012-04-26 19:31:22 +0530712static void dss_mgr_write_regs_extra(struct omap_overlay_manager *mgr)
713{
714 struct mgr_priv_data *mp = get_mgr_priv(mgr);
715
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +0530716 DSSDBG("writing mgr %d regs extra", mgr->id);
Archit Taneja45324a22012-04-26 19:31:22 +0530717
718 if (!mp->extra_info_dirty)
719 return;
720
721 dispc_mgr_set_timings(mgr->id, &mp->timings);
722
Archit Tanejaf476ae92012-06-29 14:37:03 +0530723 /* lcd_config parameters */
Tomi Valkeinenfb2cec12012-09-12 13:30:39 +0300724 if (dss_mgr_is_lcd(mgr->id))
725 dispc_mgr_set_lcd_config(mgr->id, &mp->lcd_config);
Archit Tanejaf476ae92012-06-29 14:37:03 +0530726
Archit Taneja45324a22012-04-26 19:31:22 +0530727 mp->extra_info_dirty = false;
728 if (mp->updating)
729 mp->shadow_extra_info_dirty = true;
730}
731
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200732static void dss_write_regs(void)
733{
734 const int num_mgrs = omap_dss_get_num_overlay_managers();
735 int i;
736
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200737 for (i = 0; i < num_mgrs; ++i) {
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200738 struct omap_overlay_manager *mgr;
739 struct mgr_priv_data *mp;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200740 int r;
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200741
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200742 mgr = omap_dss_get_overlay_manager(i);
743 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200744
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200745 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200746 continue;
747
Archit Taneja228b2132012-04-27 01:22:28 +0530748 r = dss_check_settings(mgr);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200749 if (r) {
750 DSSERR("cannot write registers for manager %s: "
751 "illegal configuration\n", mgr->name);
752 continue;
753 }
754
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200755 dss_mgr_write_regs(mgr);
Archit Taneja45324a22012-04-26 19:31:22 +0530756 dss_mgr_write_regs_extra(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200757 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200758}
759
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +0200760static void dss_set_go_bits(void)
761{
762 const int num_mgrs = omap_dss_get_num_overlay_managers();
763 int i;
764
765 for (i = 0; i < num_mgrs; ++i) {
766 struct omap_overlay_manager *mgr;
767 struct mgr_priv_data *mp;
768
769 mgr = omap_dss_get_overlay_manager(i);
770 mp = get_mgr_priv(mgr);
771
772 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
773 continue;
774
775 if (!need_go(mgr))
776 continue;
777
778 mp->busy = true;
779
780 if (!dss_data.irq_enabled && need_isr())
781 dss_register_vsync_isr();
782
783 dispc_mgr_go(mgr->id);
784 }
785
786}
787
Tomi Valkeinendf01d532012-03-07 10:28:48 +0200788static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
789{
790 struct omap_overlay *ovl;
791 struct mgr_priv_data *mp;
792 struct ovl_priv_data *op;
793
794 mp = get_mgr_priv(mgr);
795 mp->shadow_info_dirty = false;
Archit Taneja45324a22012-04-26 19:31:22 +0530796 mp->shadow_extra_info_dirty = false;
Tomi Valkeinendf01d532012-03-07 10:28:48 +0200797
798 list_for_each_entry(ovl, &mgr->overlays, list) {
799 op = get_ovl_priv(ovl);
800 op->shadow_info_dirty = false;
801 op->shadow_extra_info_dirty = false;
802 }
803}
804
Tomi Valkeinena7e71e72013-05-08 16:23:32 +0300805static int dss_mgr_connect_compat(struct omap_overlay_manager *mgr,
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300806 struct omap_dss_device *dst)
Tomi Valkeinena7e71e72013-05-08 16:23:32 +0300807{
808 return mgr->set_output(mgr, dst);
809}
810
811static void dss_mgr_disconnect_compat(struct omap_overlay_manager *mgr,
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300812 struct omap_dss_device *dst)
Tomi Valkeinena7e71e72013-05-08 16:23:32 +0300813{
814 mgr->unset_output(mgr);
815}
816
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +0300817static void dss_mgr_start_update_compat(struct omap_overlay_manager *mgr)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200818{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200819 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200820 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200821 int r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200822
823 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200824
Tomi Valkeinen34861372011-11-18 15:43:29 +0200825 WARN_ON(mp->updating);
826
Archit Taneja228b2132012-04-27 01:22:28 +0530827 r = dss_check_settings(mgr);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200828 if (r) {
829 DSSERR("cannot start manual update: illegal configuration\n");
830 spin_unlock_irqrestore(&data_lock, flags);
831 return;
832 }
833
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200834 dss_mgr_write_regs(mgr);
Archit Taneja45324a22012-04-26 19:31:22 +0530835 dss_mgr_write_regs_extra(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200836
Tomi Valkeinen34861372011-11-18 15:43:29 +0200837 mp->updating = true;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200838
Tomi Valkeinen34861372011-11-18 15:43:29 +0200839 if (!dss_data.irq_enabled && need_isr())
840 dss_register_vsync_isr();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200841
Tomi Valkeinen3a979f82012-10-19 14:14:38 +0300842 dispc_mgr_enable_sync(mgr->id);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +0200843
844 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200845}
846
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200847static void dss_apply_irq_handler(void *data, u32 mask);
848
849static void dss_register_vsync_isr(void)
850{
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200851 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200852 u32 mask;
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200853 int r, i;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200854
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200855 mask = 0;
856 for (i = 0; i < num_mgrs; ++i)
857 mask |= dispc_mgr_get_vsync_irq(i);
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200858
Tomi Valkeinen34861372011-11-18 15:43:29 +0200859 for (i = 0; i < num_mgrs; ++i)
860 mask |= dispc_mgr_get_framedone_irq(i);
861
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200862 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
863 WARN_ON(r);
864
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200865 dss_data.irq_enabled = true;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200866}
867
868static void dss_unregister_vsync_isr(void)
869{
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200870 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200871 u32 mask;
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200872 int r, i;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200873
Tomi Valkeinenbc1a9512011-11-15 11:20:13 +0200874 mask = 0;
875 for (i = 0; i < num_mgrs; ++i)
876 mask |= dispc_mgr_get_vsync_irq(i);
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200877
Tomi Valkeinen34861372011-11-18 15:43:29 +0200878 for (i = 0; i < num_mgrs; ++i)
879 mask |= dispc_mgr_get_framedone_irq(i);
880
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200881 r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask);
882 WARN_ON(r);
883
Tomi Valkeinend09c7aa2011-11-15 12:04:43 +0200884 dss_data.irq_enabled = false;
Tomi Valkeinendbce0162011-11-15 11:18:12 +0200885}
886
Tomi Valkeinen76098932011-11-16 12:03:22 +0200887static void dss_apply_irq_handler(void *data, u32 mask)
888{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200889 const int num_mgrs = dss_feat_get_num_mgrs();
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200890 int i;
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200891 bool extra_updating;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200892
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200893 spin_lock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200894
Tomi Valkeinen76098932011-11-16 12:03:22 +0200895 /* clear busy, updating flags, shadow_dirty flags */
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200896 for (i = 0; i < num_mgrs; i++) {
Tomi Valkeinen76098932011-11-16 12:03:22 +0200897 struct omap_overlay_manager *mgr;
898 struct mgr_priv_data *mp;
899
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200900 mgr = omap_dss_get_overlay_manager(i);
901 mp = get_mgr_priv(mgr);
902
Tomi Valkeinen76098932011-11-16 12:03:22 +0200903 if (!mp->enabled)
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200904 continue;
905
Tomi Valkeinen76098932011-11-16 12:03:22 +0200906 mp->updating = dispc_mgr_is_enabled(i);
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200907
Tomi Valkeinen76098932011-11-16 12:03:22 +0200908 if (!mgr_manual_update(mgr)) {
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200909 bool was_busy = mp->busy;
Tomi Valkeinen76098932011-11-16 12:03:22 +0200910 mp->busy = dispc_mgr_go_busy(i);
911
Tomi Valkeinen5b214172011-11-25 17:27:45 +0200912 if (was_busy && !mp->busy)
Tomi Valkeinen76098932011-11-16 12:03:22 +0200913 mgr_clear_shadow_dirty(mgr);
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200914 }
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200915 }
916
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200917 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +0200918 dss_set_go_bits();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200919
Tomi Valkeinenf1577ce2011-11-16 14:37:48 +0200920 extra_updating = extra_info_update_ongoing();
921 if (!extra_updating)
922 complete_all(&extra_updated_completion);
923
Tomi Valkeinen15502022012-10-10 13:59:07 +0300924 /* call framedone handlers for manual update displays */
925 for (i = 0; i < num_mgrs; i++) {
926 struct omap_overlay_manager *mgr;
927 struct mgr_priv_data *mp;
928
929 mgr = omap_dss_get_overlay_manager(i);
930 mp = get_mgr_priv(mgr);
931
932 if (!mgr_manual_update(mgr) || !mp->framedone_handler)
933 continue;
934
935 if (mask & dispc_mgr_get_framedone_irq(i))
936 mp->framedone_handler(mp->framedone_handler_data);
937 }
938
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200939 if (!need_isr())
940 dss_unregister_vsync_isr();
Tomi Valkeinen43a972d2011-11-15 15:04:25 +0200941
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200942 spin_unlock(&data_lock);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200943}
944
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200945static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200946{
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200947 struct ovl_priv_data *op;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200948
Tomi Valkeinenc10c6f02011-11-15 11:56:57 +0200949 op = get_ovl_priv(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200950
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200951 if (!op->user_info_dirty)
Tomi Valkeinen5738b632011-11-15 13:37:33 +0200952 return;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200953
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200954 op->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200955 op->info_dirty = true;
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200956 op->info = op->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200957}
958
959static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
960{
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200961 struct mgr_priv_data *mp;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200962
Tomi Valkeinenaf3d64b2011-11-15 12:02:03 +0200963 mp = get_mgr_priv(mgr);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200964
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200965 if (!mp->user_info_dirty)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200966 return;
967
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200968 mp->user_info_dirty = false;
Tomi Valkeinen0b53f172011-11-16 14:31:58 +0200969 mp->info_dirty = true;
Tomi Valkeinen388c4c62011-11-16 13:58:07 +0200970 mp->info = mp->user_info;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200971}
972
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +0300973static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200974{
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200975 unsigned long flags;
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200976 struct omap_overlay *ovl;
Tomi Valkeinen39518352011-11-17 17:35:28 +0200977 int r;
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200978
979 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
980
Tomi Valkeinen063fd702011-11-15 12:04:10 +0200981 spin_lock_irqsave(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200982
Archit Taneja228b2132012-04-27 01:22:28 +0530983 r = dss_check_settings_apply(mgr);
Tomi Valkeinen39518352011-11-17 17:35:28 +0200984 if (r) {
985 spin_unlock_irqrestore(&data_lock, flags);
986 DSSERR("failed to apply settings: illegal configuration.\n");
987 return r;
988 }
989
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200990 /* Configure overlays */
Tomi Valkeinen07e327c2011-11-05 10:59:59 +0200991 list_for_each_entry(ovl, &mgr->overlays, list)
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200992 omap_dss_mgr_apply_ovl(ovl);
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200993
994 /* Configure manager */
995 omap_dss_mgr_apply_mgr(mgr);
996
Tomi Valkeinen75c94962011-11-15 18:25:23 +0200997 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +0200998 dss_set_go_bits();
Tomi Valkeinen58f255482011-11-04 09:48:54 +0200999
Tomi Valkeinen063fd702011-11-15 12:04:10 +02001000 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen58f255482011-11-04 09:48:54 +02001001
Tomi Valkeinene70f98a2011-11-16 16:53:44 +02001002 return 0;
Tomi Valkeinen58f255482011-11-04 09:48:54 +02001003}
1004
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001005static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
1006{
1007 struct ovl_priv_data *op;
1008
1009 op = get_ovl_priv(ovl);
1010
1011 if (op->enabled == enable)
1012 return;
1013
1014 op->enabled = enable;
1015 op->extra_info_dirty = true;
1016}
1017
Tomi Valkeinen04576d42011-11-26 14:39:16 +02001018static void dss_apply_ovl_fifo_thresholds(struct omap_overlay *ovl,
1019 u32 fifo_low, u32 fifo_high)
1020{
1021 struct ovl_priv_data *op = get_ovl_priv(ovl);
1022
1023 if (op->fifo_low == fifo_low && op->fifo_high == fifo_high)
1024 return;
1025
1026 op->fifo_low = fifo_low;
1027 op->fifo_high = fifo_high;
1028 op->extra_info_dirty = true;
1029}
1030
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +03001031static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001032{
1033 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001034 u32 fifo_low, fifo_high;
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +03001035 bool use_fifo_merge = false;
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001036
Tomi Valkeinen75ae1182011-11-26 14:36:19 +02001037 if (!op->enabled && !op->enabling)
1038 return;
1039
Tomi Valkeinen83fa2f22012-01-13 13:17:01 +02001040 dispc_ovl_compute_fifo_thresholds(ovl->id, &fifo_low, &fifo_high,
Tomi Valkeinen3568f2a2012-05-15 15:31:01 +03001041 use_fifo_merge, ovl_manual_update(ovl));
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001042
Tomi Valkeinen04576d42011-11-26 14:39:16 +02001043 dss_apply_ovl_fifo_thresholds(ovl, fifo_low, fifo_high);
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001044}
1045
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +03001046static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001047{
1048 struct omap_overlay *ovl;
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001049 struct mgr_priv_data *mp;
1050
1051 mp = get_mgr_priv(mgr);
1052
1053 if (!mp->enabled)
1054 return;
1055
Tomi Valkeinen75ae1182011-11-26 14:36:19 +02001056 list_for_each_entry(ovl, &mgr->overlays, list)
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +03001057 dss_ovl_setup_fifo(ovl);
Tomi Valkeinen75ae1182011-11-26 14:36:19 +02001058}
1059
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +03001060static void dss_setup_fifos(void)
Tomi Valkeinen75ae1182011-11-26 14:36:19 +02001061{
1062 const int num_mgrs = omap_dss_get_num_overlay_managers();
1063 struct omap_overlay_manager *mgr;
1064 int i;
1065
1066 for (i = 0; i < num_mgrs; ++i) {
1067 mgr = omap_dss_get_overlay_manager(i);
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +03001068 dss_mgr_setup_fifos(mgr);
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001069 }
1070}
1071
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001072static int dss_mgr_enable_compat(struct omap_overlay_manager *mgr)
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001073{
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001074 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1075 unsigned long flags;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001076 int r;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001077
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001078 mutex_lock(&apply_lock);
1079
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001080 if (mp->enabled)
1081 goto out;
1082
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001083 spin_lock_irqsave(&data_lock, flags);
1084
1085 mp->enabled = true;
Tomi Valkeinena6b24f82011-11-26 14:29:39 +02001086
Archit Taneja228b2132012-04-27 01:22:28 +05301087 r = dss_check_settings(mgr);
Tomi Valkeinen39518352011-11-17 17:35:28 +02001088 if (r) {
1089 DSSERR("failed to enable manager %d: check_settings failed\n",
1090 mgr->id);
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001091 goto err;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001092 }
1093
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +03001094 dss_setup_fifos();
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001095
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001096 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +02001097 dss_set_go_bits();
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001098
Tomi Valkeinen34861372011-11-18 15:43:29 +02001099 if (!mgr_manual_update(mgr))
1100 mp->updating = true;
1101
Tomi Valkeinend7b6b6b2012-08-10 14:17:47 +03001102 if (!dss_data.irq_enabled && need_isr())
1103 dss_register_vsync_isr();
1104
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001105 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001106
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001107 if (!mgr_manual_update(mgr))
Tomi Valkeinen3a979f82012-10-19 14:14:38 +03001108 dispc_mgr_enable_sync(mgr->id);
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001109
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001110out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001111 mutex_unlock(&apply_lock);
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001112
1113 return 0;
1114
1115err:
Tomi Valkeinena6b24f82011-11-26 14:29:39 +02001116 mp->enabled = false;
Tomi Valkeinen2a4ee7e2011-11-21 13:34:48 +02001117 spin_unlock_irqrestore(&data_lock, flags);
1118 mutex_unlock(&apply_lock);
1119 return r;
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001120}
1121
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001122static void dss_mgr_disable_compat(struct omap_overlay_manager *mgr)
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001123{
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001124 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1125 unsigned long flags;
1126
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001127 mutex_lock(&apply_lock);
1128
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001129 if (!mp->enabled)
1130 goto out;
1131
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02001132 if (!mgr_manual_update(mgr))
Tomi Valkeinen3a979f82012-10-19 14:14:38 +03001133 dispc_mgr_disable_sync(mgr->id);
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001134
1135 spin_lock_irqsave(&data_lock, flags);
1136
Tomi Valkeinen34861372011-11-18 15:43:29 +02001137 mp->updating = false;
Tomi Valkeinenbf213522011-11-15 14:43:53 +02001138 mp->enabled = false;
1139
1140 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001141
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001142out:
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001143 mutex_unlock(&apply_lock);
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02001144}
1145
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +03001146static int dss_mgr_set_info(struct omap_overlay_manager *mgr,
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001147 struct omap_overlay_manager_info *info)
1148{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001149 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001150 unsigned long flags;
Tomi Valkeinenf17d04f2011-11-17 14:31:09 +02001151 int r;
1152
1153 r = dss_mgr_simple_check(mgr, info);
1154 if (r)
1155 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001156
1157 spin_lock_irqsave(&data_lock, flags);
1158
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001159 mp->user_info = *info;
1160 mp->user_info_dirty = true;
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001161
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001162 spin_unlock_irqrestore(&data_lock, flags);
1163
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001164 return 0;
1165}
1166
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +03001167static void dss_mgr_get_info(struct omap_overlay_manager *mgr,
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001168 struct omap_overlay_manager_info *info)
1169{
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001170 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001171 unsigned long flags;
1172
1173 spin_lock_irqsave(&data_lock, flags);
1174
Tomi Valkeinen388c4c62011-11-16 13:58:07 +02001175 *info = mp->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001176
1177 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001178}
1179
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +03001180static int dss_mgr_set_output(struct omap_overlay_manager *mgr,
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03001181 struct omap_dss_device *output)
Archit Taneja97f01b32012-09-26 16:42:39 +05301182{
1183 int r;
1184
1185 mutex_lock(&apply_lock);
1186
1187 if (mgr->output) {
1188 DSSERR("manager %s is already connected to an output\n",
1189 mgr->name);
1190 r = -EINVAL;
1191 goto err;
1192 }
1193
1194 if ((mgr->supported_outputs & output->id) == 0) {
1195 DSSERR("output does not support manager %s\n",
1196 mgr->name);
1197 r = -EINVAL;
1198 goto err;
1199 }
1200
1201 output->manager = mgr;
1202 mgr->output = output;
1203
1204 mutex_unlock(&apply_lock);
1205
1206 return 0;
1207err:
1208 mutex_unlock(&apply_lock);
1209 return r;
1210}
1211
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +03001212static int dss_mgr_unset_output(struct omap_overlay_manager *mgr)
Archit Taneja97f01b32012-09-26 16:42:39 +05301213{
1214 int r;
1215 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1216 unsigned long flags;
1217
1218 mutex_lock(&apply_lock);
1219
1220 if (!mgr->output) {
1221 DSSERR("failed to unset output, output not set\n");
1222 r = -EINVAL;
1223 goto err;
1224 }
1225
1226 spin_lock_irqsave(&data_lock, flags);
1227
1228 if (mp->enabled) {
1229 DSSERR("output can't be unset when manager is enabled\n");
1230 r = -EINVAL;
1231 goto err1;
1232 }
1233
1234 spin_unlock_irqrestore(&data_lock, flags);
1235
1236 mgr->output->manager = NULL;
1237 mgr->output = NULL;
1238
1239 mutex_unlock(&apply_lock);
1240
1241 return 0;
1242err1:
1243 spin_unlock_irqrestore(&data_lock, flags);
1244err:
1245 mutex_unlock(&apply_lock);
1246
1247 return r;
1248}
1249
Archit Taneja45324a22012-04-26 19:31:22 +05301250static void dss_apply_mgr_timings(struct omap_overlay_manager *mgr,
Archit Taneja27dfddc2012-07-19 13:51:14 +05301251 const struct omap_video_timings *timings)
Archit Taneja45324a22012-04-26 19:31:22 +05301252{
1253 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1254
1255 mp->timings = *timings;
1256 mp->extra_info_dirty = true;
1257}
1258
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001259static void dss_mgr_set_timings_compat(struct omap_overlay_manager *mgr,
Archit Taneja27dfddc2012-07-19 13:51:14 +05301260 const struct omap_video_timings *timings)
Archit Taneja45324a22012-04-26 19:31:22 +05301261{
1262 unsigned long flags;
Tomi Valkeinenfed62e52012-08-09 18:13:13 +03001263 struct mgr_priv_data *mp = get_mgr_priv(mgr);
Archit Taneja45324a22012-04-26 19:31:22 +05301264
1265 spin_lock_irqsave(&data_lock, flags);
1266
Tomi Valkeinenfed62e52012-08-09 18:13:13 +03001267 if (mp->updating) {
1268 DSSERR("cannot set timings for %s: manager needs to be disabled\n",
1269 mgr->name);
1270 goto out;
1271 }
1272
Archit Taneja45324a22012-04-26 19:31:22 +05301273 dss_apply_mgr_timings(mgr, timings);
Tomi Valkeinenfed62e52012-08-09 18:13:13 +03001274out:
Archit Taneja45324a22012-04-26 19:31:22 +05301275 spin_unlock_irqrestore(&data_lock, flags);
Archit Taneja45324a22012-04-26 19:31:22 +05301276}
Tomi Valkeineneb70d732011-11-15 12:15:18 +02001277
Archit Tanejaf476ae92012-06-29 14:37:03 +05301278static void dss_apply_mgr_lcd_config(struct omap_overlay_manager *mgr,
1279 const struct dss_lcd_mgr_config *config)
1280{
1281 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1282
1283 mp->lcd_config = *config;
1284 mp->extra_info_dirty = true;
1285}
1286
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001287static void dss_mgr_set_lcd_config_compat(struct omap_overlay_manager *mgr,
Archit Tanejaf476ae92012-06-29 14:37:03 +05301288 const struct dss_lcd_mgr_config *config)
1289{
1290 unsigned long flags;
1291 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1292
Tomi Valkeinenaba96572012-08-09 18:07:45 +03001293 spin_lock_irqsave(&data_lock, flags);
Archit Tanejaf476ae92012-06-29 14:37:03 +05301294
1295 if (mp->enabled) {
1296 DSSERR("cannot apply lcd config for %s: manager needs to be disabled\n",
1297 mgr->name);
1298 goto out;
1299 }
1300
Archit Tanejaf476ae92012-06-29 14:37:03 +05301301 dss_apply_mgr_lcd_config(mgr, config);
Archit Tanejaf476ae92012-06-29 14:37:03 +05301302out:
Tomi Valkeinenaba96572012-08-09 18:07:45 +03001303 spin_unlock_irqrestore(&data_lock, flags);
Archit Tanejaf476ae92012-06-29 14:37:03 +05301304}
1305
Tomi Valkeinen6abae7a2012-10-23 13:45:07 +03001306static int dss_ovl_set_info(struct omap_overlay *ovl,
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001307 struct omap_overlay_info *info)
1308{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001309 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001310 unsigned long flags;
Tomi Valkeinenfcc764d2011-11-17 14:26:48 +02001311 int r;
1312
1313 r = dss_ovl_simple_check(ovl, info);
1314 if (r)
1315 return r;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001316
1317 spin_lock_irqsave(&data_lock, flags);
1318
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001319 op->user_info = *info;
1320 op->user_info_dirty = true;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001321
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001322 spin_unlock_irqrestore(&data_lock, flags);
1323
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001324 return 0;
1325}
1326
Tomi Valkeinen6abae7a2012-10-23 13:45:07 +03001327static void dss_ovl_get_info(struct omap_overlay *ovl,
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001328 struct omap_overlay_info *info)
1329{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001330 struct ovl_priv_data *op = get_ovl_priv(ovl);
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001331 unsigned long flags;
1332
1333 spin_lock_irqsave(&data_lock, flags);
1334
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +02001335 *info = op->user_info;
Tomi Valkeinene0a2aa5b2011-11-15 14:32:57 +02001336
1337 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001338}
1339
Tomi Valkeinen6abae7a2012-10-23 13:45:07 +03001340static int dss_ovl_set_manager(struct omap_overlay *ovl,
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001341 struct omap_overlay_manager *mgr)
1342{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001343 struct ovl_priv_data *op = get_ovl_priv(ovl);
1344 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001345 int r;
1346
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001347 if (!mgr)
1348 return -EINVAL;
1349
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001350 mutex_lock(&apply_lock);
1351
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001352 if (ovl->manager) {
1353 DSSERR("overlay '%s' already has a manager '%s'\n",
1354 ovl->name, ovl->manager->name);
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001355 r = -EINVAL;
1356 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001357 }
1358
Archit Taneja02b5ff12012-11-07 14:47:22 +05301359 r = dispc_runtime_get();
1360 if (r)
1361 goto err;
1362
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001363 spin_lock_irqsave(&data_lock, flags);
1364
1365 if (op->enabled) {
1366 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001367 DSSERR("overlay has to be disabled to change the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001368 r = -EINVAL;
Archit Taneja02b5ff12012-11-07 14:47:22 +05301369 goto err1;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001370 }
1371
Archit Taneja02b5ff12012-11-07 14:47:22 +05301372 dispc_ovl_set_channel_out(ovl->id, mgr->id);
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001373
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001374 ovl->manager = mgr;
1375 list_add_tail(&ovl->list, &mgr->overlays);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001376
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001377 spin_unlock_irqrestore(&data_lock, flags);
1378
Archit Taneja02b5ff12012-11-07 14:47:22 +05301379 dispc_runtime_put();
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001380
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001381 mutex_unlock(&apply_lock);
1382
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001383 return 0;
Archit Taneja02b5ff12012-11-07 14:47:22 +05301384
1385err1:
1386 dispc_runtime_put();
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001387err:
1388 mutex_unlock(&apply_lock);
1389 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001390}
1391
Tomi Valkeinen6abae7a2012-10-23 13:45:07 +03001392static int dss_ovl_unset_manager(struct omap_overlay *ovl)
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001393{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001394 struct ovl_priv_data *op = get_ovl_priv(ovl);
1395 unsigned long flags;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001396 int r;
1397
1398 mutex_lock(&apply_lock);
1399
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001400 if (!ovl->manager) {
1401 DSSERR("failed to detach overlay: manager not set\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001402 r = -EINVAL;
1403 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001404 }
1405
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001406 spin_lock_irqsave(&data_lock, flags);
1407
1408 if (op->enabled) {
1409 spin_unlock_irqrestore(&data_lock, flags);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001410 DSSERR("overlay has to be disabled to unset the manager\n");
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001411 r = -EINVAL;
1412 goto err;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001413 }
1414
Tomi Valkeinenb2f59762012-09-06 16:10:28 +03001415 spin_unlock_irqrestore(&data_lock, flags);
1416
1417 /* wait for pending extra_info updates to ensure the ovl is disabled */
1418 wait_pending_extra_info_updates();
1419
Archit Taneja02b5ff12012-11-07 14:47:22 +05301420 /*
1421 * For a manual update display, there is no guarantee that the overlay
1422 * is really disabled in HW, we may need an extra update from this
1423 * manager before the configurations can go in. Return an error if the
1424 * overlay needed an update from the manager.
1425 *
1426 * TODO: Instead of returning an error, try to do a dummy manager update
1427 * here to disable the overlay in hardware. Use the *GATED fields in
1428 * the DISPC_CONFIG registers to do a dummy update.
1429 */
Tomi Valkeinenb2f59762012-09-06 16:10:28 +03001430 spin_lock_irqsave(&data_lock, flags);
1431
Archit Taneja02b5ff12012-11-07 14:47:22 +05301432 if (ovl_manual_update(ovl) && op->extra_info_dirty) {
1433 spin_unlock_irqrestore(&data_lock, flags);
1434 DSSERR("need an update to change the manager\n");
1435 r = -EINVAL;
1436 goto err;
1437 }
Tomi Valkeinen5d5a97a2011-11-16 14:17:54 +02001438
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001439 ovl->manager = NULL;
1440 list_del(&ovl->list);
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001441
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001442 spin_unlock_irqrestore(&data_lock, flags);
1443
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001444 mutex_unlock(&apply_lock);
1445
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001446 return 0;
Tomi Valkeinen5558db32011-11-15 14:28:48 +02001447err:
1448 mutex_unlock(&apply_lock);
1449 return r;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +02001450}
1451
Tomi Valkeinen6abae7a2012-10-23 13:45:07 +03001452static bool dss_ovl_is_enabled(struct omap_overlay *ovl)
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001453{
1454 struct ovl_priv_data *op = get_ovl_priv(ovl);
1455 unsigned long flags;
1456 bool e;
1457
1458 spin_lock_irqsave(&data_lock, flags);
1459
1460 e = op->enabled;
1461
1462 spin_unlock_irqrestore(&data_lock, flags);
1463
1464 return e;
1465}
1466
Tomi Valkeinen6abae7a2012-10-23 13:45:07 +03001467static int dss_ovl_enable(struct omap_overlay *ovl)
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001468{
1469 struct ovl_priv_data *op = get_ovl_priv(ovl);
1470 unsigned long flags;
1471 int r;
1472
1473 mutex_lock(&apply_lock);
1474
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001475 if (op->enabled) {
1476 r = 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001477 goto err1;
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001478 }
1479
Archit Taneja0f0e4e32012-09-03 17:14:09 +05301480 if (ovl->manager == NULL || ovl->manager->output == NULL) {
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001481 r = -EINVAL;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001482 goto err1;
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001483 }
1484
1485 spin_lock_irqsave(&data_lock, flags);
1486
Tomi Valkeinen82153ed2011-11-26 14:26:46 +02001487 op->enabling = true;
1488
Archit Taneja228b2132012-04-27 01:22:28 +05301489 r = dss_check_settings(ovl->manager);
Tomi Valkeinen39518352011-11-17 17:35:28 +02001490 if (r) {
1491 DSSERR("failed to enable overlay %d: check_settings failed\n",
1492 ovl->id);
1493 goto err2;
1494 }
1495
Tomi Valkeinenb3e93cb2012-08-06 16:50:14 +03001496 dss_setup_fifos();
Tomi Valkeinen6dc802e2011-11-16 14:28:12 +02001497
Tomi Valkeinen82153ed2011-11-26 14:26:46 +02001498 op->enabling = false;
1499 dss_apply_ovl_enable(ovl, true);
1500
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001501 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +02001502 dss_set_go_bits();
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001503
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001504 spin_unlock_irqrestore(&data_lock, flags);
1505
1506 mutex_unlock(&apply_lock);
1507
1508 return 0;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001509err2:
Tomi Valkeinen82153ed2011-11-26 14:26:46 +02001510 op->enabling = false;
Tomi Valkeinen39518352011-11-17 17:35:28 +02001511 spin_unlock_irqrestore(&data_lock, flags);
1512err1:
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001513 mutex_unlock(&apply_lock);
1514 return r;
1515}
1516
Tomi Valkeinen6abae7a2012-10-23 13:45:07 +03001517static int dss_ovl_disable(struct omap_overlay *ovl)
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001518{
1519 struct ovl_priv_data *op = get_ovl_priv(ovl);
1520 unsigned long flags;
1521 int r;
1522
1523 mutex_lock(&apply_lock);
1524
Tomi Valkeinene4f7ad72011-11-16 16:01:33 +02001525 if (!op->enabled) {
1526 r = 0;
1527 goto err;
1528 }
1529
Archit Taneja0f0e4e32012-09-03 17:14:09 +05301530 if (ovl->manager == NULL || ovl->manager->output == NULL) {
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001531 r = -EINVAL;
1532 goto err;
1533 }
1534
1535 spin_lock_irqsave(&data_lock, flags);
1536
Tomi Valkeinen841c09c2011-11-16 15:25:53 +02001537 dss_apply_ovl_enable(ovl, false);
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001538 dss_write_regs();
Tomi Valkeinen3ab15b22011-11-25 17:32:20 +02001539 dss_set_go_bits();
Tomi Valkeinen75c94962011-11-15 18:25:23 +02001540
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +02001541 spin_unlock_irqrestore(&data_lock, flags);
1542
1543 mutex_unlock(&apply_lock);
1544
1545 return 0;
1546
1547err:
1548 mutex_unlock(&apply_lock);
1549 return r;
1550}
1551
Tomi Valkeinen15502022012-10-10 13:59:07 +03001552static int dss_mgr_register_framedone_handler_compat(struct omap_overlay_manager *mgr,
1553 void (*handler)(void *), void *data)
1554{
1555 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1556
1557 if (mp->framedone_handler)
1558 return -EBUSY;
1559
1560 mp->framedone_handler = handler;
1561 mp->framedone_handler_data = data;
1562
1563 return 0;
1564}
1565
1566static void dss_mgr_unregister_framedone_handler_compat(struct omap_overlay_manager *mgr,
1567 void (*handler)(void *), void *data)
1568{
1569 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1570
1571 WARN_ON(mp->framedone_handler != handler ||
1572 mp->framedone_handler_data != data);
1573
1574 mp->framedone_handler = NULL;
1575 mp->framedone_handler_data = NULL;
1576}
1577
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001578static const struct dss_mgr_ops apply_mgr_ops = {
Tomi Valkeinena7e71e72013-05-08 16:23:32 +03001579 .connect = dss_mgr_connect_compat,
1580 .disconnect = dss_mgr_disconnect_compat,
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001581 .start_update = dss_mgr_start_update_compat,
1582 .enable = dss_mgr_enable_compat,
1583 .disable = dss_mgr_disable_compat,
1584 .set_timings = dss_mgr_set_timings_compat,
1585 .set_lcd_config = dss_mgr_set_lcd_config_compat,
Tomi Valkeinen15502022012-10-10 13:59:07 +03001586 .register_framedone_handler = dss_mgr_register_framedone_handler_compat,
1587 .unregister_framedone_handler = dss_mgr_unregister_framedone_handler_compat,
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001588};
1589
Tomi Valkeinen8dd24912012-10-10 10:26:45 +03001590static int compat_refcnt;
1591static DEFINE_MUTEX(compat_init_lock);
1592
1593int omapdss_compat_init(void)
1594{
Tomi Valkeinen23dfd1a2012-10-23 13:46:12 +03001595 struct platform_device *pdev = dss_get_core_pdev();
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001596 int i, r;
Tomi Valkeinen23dfd1a2012-10-23 13:46:12 +03001597
Tomi Valkeinen8dd24912012-10-10 10:26:45 +03001598 mutex_lock(&compat_init_lock);
1599
1600 if (compat_refcnt++ > 0)
1601 goto out;
1602
1603 apply_init_priv();
1604
Tomi Valkeinen7f7cdbd2013-05-14 10:53:21 +03001605 dss_init_overlay_managers_sysfs(pdev);
Tomi Valkeinen23dfd1a2012-10-23 13:46:12 +03001606 dss_init_overlays(pdev);
1607
Tomi Valkeinen0c49ff72012-10-23 13:44:12 +03001608 for (i = 0; i < omap_dss_get_num_overlay_managers(); i++) {
1609 struct omap_overlay_manager *mgr;
1610
1611 mgr = omap_dss_get_overlay_manager(i);
1612
1613 mgr->set_output = &dss_mgr_set_output;
1614 mgr->unset_output = &dss_mgr_unset_output;
1615 mgr->apply = &omap_dss_mgr_apply;
1616 mgr->set_manager_info = &dss_mgr_set_info;
1617 mgr->get_manager_info = &dss_mgr_get_info;
1618 mgr->wait_for_go = &dss_mgr_wait_for_go;
1619 mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
1620 mgr->get_device = &dss_mgr_get_device;
1621 }
1622
Tomi Valkeinen6abae7a2012-10-23 13:45:07 +03001623 for (i = 0; i < omap_dss_get_num_overlays(); i++) {
1624 struct omap_overlay *ovl = omap_dss_get_overlay(i);
1625
1626 ovl->is_enabled = &dss_ovl_is_enabled;
1627 ovl->enable = &dss_ovl_enable;
1628 ovl->disable = &dss_ovl_disable;
1629 ovl->set_manager = &dss_ovl_set_manager;
1630 ovl->unset_manager = &dss_ovl_unset_manager;
1631 ovl->set_overlay_info = &dss_ovl_set_info;
1632 ovl->get_overlay_info = &dss_ovl_get_info;
1633 ovl->wait_for_go = &dss_mgr_wait_for_go_ovl;
1634 ovl->get_device = &dss_ovl_get_device;
1635 }
1636
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001637 r = dss_install_mgr_ops(&apply_mgr_ops);
1638 if (r)
1639 goto err_mgr_ops;
1640
Tomi Valkeinen94140f02013-02-13 13:40:19 +02001641 r = display_init_sysfs(pdev);
1642 if (r)
1643 goto err_disp_sysfs;
Tomi Valkeinen09e82ba2012-11-08 14:11:29 +02001644
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03001645 dispc_runtime_get();
1646
1647 r = dss_dispc_initialize_irq();
1648 if (r)
1649 goto err_init_irq;
1650
1651 dispc_runtime_put();
1652
Tomi Valkeinen8dd24912012-10-10 10:26:45 +03001653out:
1654 mutex_unlock(&compat_init_lock);
1655
1656 return 0;
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001657
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03001658err_init_irq:
1659 dispc_runtime_put();
Tomi Valkeinen94140f02013-02-13 13:40:19 +02001660 display_uninit_sysfs(pdev);
Tomi Valkeinen09e82ba2012-11-08 14:11:29 +02001661
1662err_disp_sysfs:
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03001663 dss_uninstall_mgr_ops();
1664
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001665err_mgr_ops:
Tomi Valkeinen7f7cdbd2013-05-14 10:53:21 +03001666 dss_uninit_overlay_managers_sysfs(pdev);
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001667 dss_uninit_overlays(pdev);
1668
1669 compat_refcnt--;
1670
1671 mutex_unlock(&compat_init_lock);
1672
1673 return r;
Tomi Valkeinen8dd24912012-10-10 10:26:45 +03001674}
1675EXPORT_SYMBOL(omapdss_compat_init);
1676
1677void omapdss_compat_uninit(void)
1678{
Tomi Valkeinen23dfd1a2012-10-23 13:46:12 +03001679 struct platform_device *pdev = dss_get_core_pdev();
1680
Tomi Valkeinen8dd24912012-10-10 10:26:45 +03001681 mutex_lock(&compat_init_lock);
1682
1683 if (--compat_refcnt > 0)
1684 goto out;
1685
Tomi Valkeinen96e2e632012-10-10 15:55:19 +03001686 dss_dispc_uninitialize_irq();
1687
Tomi Valkeinen94140f02013-02-13 13:40:19 +02001688 display_uninit_sysfs(pdev);
Tomi Valkeinen09e82ba2012-11-08 14:11:29 +02001689
Tomi Valkeinen74b65ec2012-10-10 10:56:05 +03001690 dss_uninstall_mgr_ops();
1691
Tomi Valkeinen7f7cdbd2013-05-14 10:53:21 +03001692 dss_uninit_overlay_managers_sysfs(pdev);
Tomi Valkeinen23dfd1a2012-10-23 13:46:12 +03001693 dss_uninit_overlays(pdev);
Tomi Valkeinen8dd24912012-10-10 10:26:45 +03001694out:
1695 mutex_unlock(&compat_init_lock);
1696}
1697EXPORT_SYMBOL(omapdss_compat_uninit);