apply.c 29.1 KB
Newer Older
T
Tomi Valkeinen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
 * Copyright (C) 2011 Texas Instruments
 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#define DSS_SUBSYS_NAME "APPLY"

#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/jiffies.h>

#include <video/omapdss.h>

#include "dss.h"
#include "dss_features.h"

/*
 * We have 4 levels of cache for the dispc settings. First two are in SW and
 * the latter two in HW.
 *
34 35
 *       set_info()
 *          v
T
Tomi Valkeinen 已提交
36
 * +--------------------+
37
 * |     user_info      |
T
Tomi Valkeinen 已提交
38 39 40 41 42
 * +--------------------+
 *          v
 *        apply()
 *          v
 * +--------------------+
43
 * |       info         |
T
Tomi Valkeinen 已提交
44 45
 * +--------------------+
 *          v
46
 *      write_regs()
T
Tomi Valkeinen 已提交
47 48 49 50 51 52 53 54 55 56 57 58
 *          v
 * +--------------------+
 * |  shadow registers  |
 * +--------------------+
 *          v
 * VFP or lcd/digit_enable
 *          v
 * +--------------------+
 * |      registers     |
 * +--------------------+
 */

59
struct ovl_priv_data {
60 61 62 63

	bool user_info_dirty;
	struct omap_overlay_info user_info;

64
	bool info_dirty;
T
Tomi Valkeinen 已提交
65 66
	struct omap_overlay_info info;

67 68
	bool shadow_info_dirty;

69 70 71 72
	bool extra_info_dirty;
	bool shadow_extra_info_dirty;

	bool enabled;
73
	u32 fifo_low, fifo_high;
T
Tomi Valkeinen 已提交
74 75 76 77 78 79

	/*
	 * True if overlay is to be enabled. Used to check and calculate configs
	 * for the overlay before it is enabled in the HW.
	 */
	bool enabling;
T
Tomi Valkeinen 已提交
80 81
};

82
struct mgr_priv_data {
83 84 85 86

	bool user_info_dirty;
	struct omap_overlay_manager_info user_info;

87
	bool info_dirty;
T
Tomi Valkeinen 已提交
88 89
	struct omap_overlay_manager_info info;

90 91
	bool shadow_info_dirty;

92 93 94 95
	/* If true, GO bit is up and shadow registers cannot be written.
	 * Never true for manual update displays */
	bool busy;

T
Tomi Valkeinen 已提交
96 97 98
	/* If true, dispc output is enabled */
	bool updating;

99 100
	/* If true, a display is enabled using this manager */
	bool enabled;
101 102 103 104 105

	bool extra_info_dirty;
	bool shadow_extra_info_dirty;

	struct omap_video_timings timings;
106
	struct dss_lcd_mgr_config lcd_config;
T
Tomi Valkeinen 已提交
107 108 109
};

static struct {
110
	struct ovl_priv_data ovl_priv_data_array[MAX_DSS_OVERLAYS];
111
	struct mgr_priv_data mgr_priv_data_array[MAX_DSS_MANAGERS];
T
Tomi Valkeinen 已提交
112 113

	bool irq_enabled;
114
} dss_data;
T
Tomi Valkeinen 已提交
115

116
/* protects dss_data */
117
static spinlock_t data_lock;
T
Tomi Valkeinen 已提交
118 119
/* lock for blocking functions */
static DEFINE_MUTEX(apply_lock);
120
static DECLARE_COMPLETION(extra_updated_completion);
121

122 123
static void dss_register_vsync_isr(void);

124 125
static struct ovl_priv_data *get_ovl_priv(struct omap_overlay *ovl)
{
126
	return &dss_data.ovl_priv_data_array[ovl->id];
127 128
}

129 130
static struct mgr_priv_data *get_mgr_priv(struct omap_overlay_manager *mgr)
{
131
	return &dss_data.mgr_priv_data_array[mgr->id];
132 133
}

T
Tomi Valkeinen 已提交
134 135
void dss_apply_init(void)
{
136
	const int num_ovls = dss_feat_get_num_ovls();
137
	struct mgr_priv_data *mp;
138 139
	int i;

140
	spin_lock_init(&data_lock);
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

	for (i = 0; i < num_ovls; ++i) {
		struct ovl_priv_data *op;

		op = &dss_data.ovl_priv_data_array[i];

		op->info.global_alpha = 255;

		switch (i) {
		case 0:
			op->info.zorder = 0;
			break;
		case 1:
			op->info.zorder =
				dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 3 : 0;
			break;
		case 2:
			op->info.zorder =
				dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 2 : 0;
			break;
		case 3:
			op->info.zorder =
				dss_has_feature(FEAT_ALPHA_FREE_ZORDER) ? 1 : 0;
			break;
		}

		op->user_info = op->info;
	}
169 170 171 172 173 174 175 176 177 178

	/*
	 * Initialize some of the lcd_config fields for TV manager, this lets
	 * us prevent checking if the manager is LCD or TV at some places
	 */
	mp = &dss_data.mgr_priv_data_array[OMAP_DSS_CHANNEL_DIGIT];

	mp->lcd_config.video_port_width = 24;
	mp->lcd_config.clock_info.lck_div = 1;
	mp->lcd_config.clock_info.pck_div = 1;
T
Tomi Valkeinen 已提交
179 180
}

181 182 183 184 185
/*
 * A LCD manager's stallmode decides whether it is in manual or auto update. TV
 * manager is always auto update, stallmode field for TV manager is false by
 * default
 */
T
Tomi Valkeinen 已提交
186 187
static bool ovl_manual_update(struct omap_overlay *ovl)
{
188 189 190
	struct mgr_priv_data *mp = get_mgr_priv(ovl->manager);

	return mp->lcd_config.stallmode;
T
Tomi Valkeinen 已提交
191 192 193 194
}

static bool mgr_manual_update(struct omap_overlay_manager *mgr)
{
195 196 197
	struct mgr_priv_data *mp = get_mgr_priv(mgr);

	return mp->lcd_config.stallmode;
T
Tomi Valkeinen 已提交
198 199
}

200
static int dss_check_settings_low(struct omap_overlay_manager *mgr,
201
		bool applying)
202 203 204 205 206 207 208 209 210 211
{
	struct omap_overlay_info *oi;
	struct omap_overlay_manager_info *mi;
	struct omap_overlay *ovl;
	struct omap_overlay_info *ois[MAX_DSS_OVERLAYS];
	struct ovl_priv_data *op;
	struct mgr_priv_data *mp;

	mp = get_mgr_priv(mgr);

212 213 214
	if (!mp->enabled)
		return 0;

215 216 217 218 219 220 221 222 223
	if (applying && mp->user_info_dirty)
		mi = &mp->user_info;
	else
		mi = &mp->info;

	/* collect the infos to be tested into the array */
	list_for_each_entry(ovl, &mgr->overlays, list) {
		op = get_ovl_priv(ovl);

T
Tomi Valkeinen 已提交
224
		if (!op->enabled && !op->enabling)
225 226 227 228 229 230 231 232 233
			oi = NULL;
		else if (applying && op->user_info_dirty)
			oi = &op->user_info;
		else
			oi = &op->info;

		ois[ovl->id] = oi;
	}

234
	return dss_mgr_check(mgr, mi, &mp->timings, &mp->lcd_config, ois);
235 236 237 238 239
}

/*
 * check manager and overlay settings using overlay_info from data->info
 */
240
static int dss_check_settings(struct omap_overlay_manager *mgr)
241
{
242
	return dss_check_settings_low(mgr, false);
243 244 245 246 247 248
}

/*
 * check manager and overlay settings using overlay_info from ovl->info if
 * dirty and from data->info otherwise
 */
249
static int dss_check_settings_apply(struct omap_overlay_manager *mgr)
250
{
251
	return dss_check_settings_low(mgr, true);
252 253
}

254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
static bool need_isr(void)
{
	const int num_mgrs = dss_feat_get_num_mgrs();
	int i;

	for (i = 0; i < num_mgrs; ++i) {
		struct omap_overlay_manager *mgr;
		struct mgr_priv_data *mp;
		struct omap_overlay *ovl;

		mgr = omap_dss_get_overlay_manager(i);
		mp = get_mgr_priv(mgr);

		if (!mp->enabled)
			continue;

T
Tomi Valkeinen 已提交
270 271 272 273 274 275 276 277
		if (mgr_manual_update(mgr)) {
			/* to catch FRAMEDONE */
			if (mp->updating)
				return true;
		} else {
			/* to catch GO bit going down */
			if (mp->busy)
				return true;
278

T
Tomi Valkeinen 已提交
279
			/* to write new values to registers */
280
			if (mp->info_dirty)
T
Tomi Valkeinen 已提交
281
				return true;
282

T
Tomi Valkeinen 已提交
283 284 285 286
			/* to set GO bit */
			if (mp->shadow_info_dirty)
				return true;

287 288 289 290 291 292 293 294 295 296 297 298 299 300
			/*
			 * NOTE: we don't check extra_info flags for disabled
			 * managers, once the manager is enabled, the extra_info
			 * related manager changes will be taken in by HW.
			 */

			/* to write new values to registers */
			if (mp->extra_info_dirty)
				return true;

			/* to set GO bit */
			if (mp->shadow_extra_info_dirty)
				return true;

T
Tomi Valkeinen 已提交
301 302
			list_for_each_entry(ovl, &mgr->overlays, list) {
				struct ovl_priv_data *op;
303

T
Tomi Valkeinen 已提交
304
				op = get_ovl_priv(ovl);
305

T
Tomi Valkeinen 已提交
306 307 308 309 310 311 312 313 314 315 316 317 318 319
				/*
				 * NOTE: we check extra_info flags even for
				 * disabled overlays, as extra_infos need to be
				 * always written.
				 */

				/* to write new values to registers */
				if (op->extra_info_dirty)
					return true;

				/* to set GO bit */
				if (op->shadow_extra_info_dirty)
					return true;

T
Tomi Valkeinen 已提交
320 321
				if (!op->enabled)
					continue;
322

T
Tomi Valkeinen 已提交
323
				/* to write new values to registers */
T
Tomi Valkeinen 已提交
324 325 326 327 328
				if (op->info_dirty)
					return true;

				/* to set GO bit */
				if (op->shadow_info_dirty)
T
Tomi Valkeinen 已提交
329 330
					return true;
			}
331 332 333 334 335 336 337 338 339 340 341 342 343 344
		}
	}

	return false;
}

static bool need_go(struct omap_overlay_manager *mgr)
{
	struct omap_overlay *ovl;
	struct mgr_priv_data *mp;
	struct ovl_priv_data *op;

	mp = get_mgr_priv(mgr);

345
	if (mp->shadow_info_dirty || mp->shadow_extra_info_dirty)
346 347 348 349
		return true;

	list_for_each_entry(ovl, &mgr->overlays, list) {
		op = get_ovl_priv(ovl);
350
		if (op->shadow_info_dirty || op->shadow_extra_info_dirty)
351 352 353 354 355 356
			return true;
	}

	return false;
}

357 358 359
/* returns true if an extra_info field is currently being updated */
static bool extra_info_update_ongoing(void)
{
360
	const int num_mgrs = dss_feat_get_num_mgrs();
361 362
	int i;

363 364 365 366
	for (i = 0; i < num_mgrs; ++i) {
		struct omap_overlay_manager *mgr;
		struct omap_overlay *ovl;
		struct mgr_priv_data *mp;
367

368 369
		mgr = omap_dss_get_overlay_manager(i);
		mp = get_mgr_priv(mgr);
370 371 372 373

		if (!mp->enabled)
			continue;

374
		if (!mp->updating)
375 376
			continue;

377
		if (mp->extra_info_dirty || mp->shadow_extra_info_dirty)
378
			return true;
379 380 381 382 383 384 385

		list_for_each_entry(ovl, &mgr->overlays, list) {
			struct ovl_priv_data *op = get_ovl_priv(ovl);

			if (op->extra_info_dirty || op->shadow_extra_info_dirty)
				return true;
		}
386 387 388 389 390 391 392 393 394 395 396
	}

	return false;
}

/* wait until no extra_info updates are pending */
static void wait_pending_extra_info_updates(void)
{
	bool updating;
	unsigned long flags;
	unsigned long t;
397
	int r;
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412

	spin_lock_irqsave(&data_lock, flags);

	updating = extra_info_update_ongoing();

	if (!updating) {
		spin_unlock_irqrestore(&data_lock, flags);
		return;
	}

	init_completion(&extra_updated_completion);

	spin_unlock_irqrestore(&data_lock, flags);

	t = msecs_to_jiffies(500);
413 414 415
	r = wait_for_completion_timeout(&extra_updated_completion, t);
	if (r == 0)
		DSSWARN("timeout in wait_pending_extra_info_updates\n");
416 417
}

T
Tomi Valkeinen 已提交
418 419 420
int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
{
	unsigned long timeout = msecs_to_jiffies(500);
421
	struct mgr_priv_data *mp = get_mgr_priv(mgr);
T
Tomi Valkeinen 已提交
422
	u32 irq;
423
	unsigned long flags;
T
Tomi Valkeinen 已提交
424 425 426
	int r;
	int i;

427 428 429 430
	spin_lock_irqsave(&data_lock, flags);

	if (mgr_manual_update(mgr)) {
		spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
431
		return 0;
432
	}
T
Tomi Valkeinen 已提交
433

434 435
	if (!mp->enabled) {
		spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
436
		return 0;
437 438 439
	}

	spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
440

441 442 443 444
	r = dispc_runtime_get();
	if (r)
		return r;

445
	irq = dispc_mgr_get_vsync_irq(mgr->id);
T
Tomi Valkeinen 已提交
446 447 448 449 450

	i = 0;
	while (1) {
		bool shadow_dirty, dirty;

451
		spin_lock_irqsave(&data_lock, flags);
452 453
		dirty = mp->info_dirty;
		shadow_dirty = mp->shadow_info_dirty;
454
		spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482

		if (!dirty && !shadow_dirty) {
			r = 0;
			break;
		}

		/* 4 iterations is the worst case:
		 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
		 * 2 - first VSYNC, dirty = true
		 * 3 - dirty = false, shadow_dirty = true
		 * 4 - shadow_dirty = false */
		if (i++ == 3) {
			DSSERR("mgr(%d)->wait_for_go() not finishing\n",
					mgr->id);
			r = 0;
			break;
		}

		r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
		if (r == -ERESTARTSYS)
			break;

		if (r) {
			DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
			break;
		}
	}

483 484
	dispc_runtime_put();

T
Tomi Valkeinen 已提交
485 486 487 488 489 490
	return r;
}

int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
{
	unsigned long timeout = msecs_to_jiffies(500);
491
	struct ovl_priv_data *op;
492
	struct mgr_priv_data *mp;
T
Tomi Valkeinen 已提交
493
	u32 irq;
494
	unsigned long flags;
T
Tomi Valkeinen 已提交
495 496 497 498 499 500
	int r;
	int i;

	if (!ovl->manager)
		return 0;

501
	mp = get_mgr_priv(ovl->manager);
T
Tomi Valkeinen 已提交
502

503 504 505 506
	spin_lock_irqsave(&data_lock, flags);

	if (ovl_manual_update(ovl)) {
		spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
507
		return 0;
508
	}
T
Tomi Valkeinen 已提交
509

510 511
	if (!mp->enabled) {
		spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
512
		return 0;
513 514 515
	}

	spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
516

517 518 519 520
	r = dispc_runtime_get();
	if (r)
		return r;

521
	irq = dispc_mgr_get_vsync_irq(ovl->manager->id);
T
Tomi Valkeinen 已提交
522

523
	op = get_ovl_priv(ovl);
T
Tomi Valkeinen 已提交
524 525 526 527
	i = 0;
	while (1) {
		bool shadow_dirty, dirty;

528
		spin_lock_irqsave(&data_lock, flags);
529 530
		dirty = op->info_dirty;
		shadow_dirty = op->shadow_info_dirty;
531
		spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559

		if (!dirty && !shadow_dirty) {
			r = 0;
			break;
		}

		/* 4 iterations is the worst case:
		 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
		 * 2 - first VSYNC, dirty = true
		 * 3 - dirty = false, shadow_dirty = true
		 * 4 - shadow_dirty = false */
		if (i++ == 3) {
			DSSERR("ovl(%d)->wait_for_go() not finishing\n",
					ovl->id);
			r = 0;
			break;
		}

		r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
		if (r == -ERESTARTSYS)
			break;

		if (r) {
			DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
			break;
		}
	}

560 561
	dispc_runtime_put();

T
Tomi Valkeinen 已提交
562 563 564
	return r;
}

565
static void dss_ovl_write_regs(struct omap_overlay *ovl)
T
Tomi Valkeinen 已提交
566
{
567
	struct ovl_priv_data *op = get_ovl_priv(ovl);
T
Tomi Valkeinen 已提交
568
	struct omap_overlay_info *oi;
569
	bool replication;
T
Tomi Valkeinen 已提交
570
	struct mgr_priv_data *mp;
T
Tomi Valkeinen 已提交
571 572
	int r;

573
	DSSDBG("writing ovl %d regs", ovl->id);
T
Tomi Valkeinen 已提交
574

575
	if (!op->enabled || !op->info_dirty)
576
		return;
T
Tomi Valkeinen 已提交
577

578
	oi = &op->info;
T
Tomi Valkeinen 已提交
579

580 581
	mp = get_mgr_priv(ovl->manager);

582
	replication = dss_ovl_use_replication(mp->lcd_config, oi->color_mode);
T
Tomi Valkeinen 已提交
583

584
	r = dispc_ovl_setup(ovl->id, oi, replication, &mp->timings, false);
T
Tomi Valkeinen 已提交
585
	if (r) {
586 587 588 589
		/*
		 * We can't do much here, as this function can be called from
		 * vsync interrupt.
		 */
590
		DSSERR("dispc_ovl_setup failed for ovl %d\n", ovl->id);
591 592 593 594 595

		/* This will leave fifo configurations in a nonoptimal state */
		op->enabled = false;
		dispc_ovl_enable(ovl->id, false);
		return;
T
Tomi Valkeinen 已提交
596 597
	}

598
	op->info_dirty = false;
T
Tomi Valkeinen 已提交
599
	if (mp->updating)
600
		op->shadow_info_dirty = true;
T
Tomi Valkeinen 已提交
601 602
}

603 604 605
static void dss_ovl_write_regs_extra(struct omap_overlay *ovl)
{
	struct ovl_priv_data *op = get_ovl_priv(ovl);
T
Tomi Valkeinen 已提交
606
	struct mgr_priv_data *mp;
607

608
	DSSDBG("writing ovl %d regs extra", ovl->id);
609

610 611 612
	if (!op->extra_info_dirty)
		return;

613 614 615 616
	/* note: write also when op->enabled == false, so that the ovl gets
	 * disabled */

	dispc_ovl_enable(ovl->id, op->enabled);
617
	dispc_ovl_set_fifo_threshold(ovl->id, op->fifo_low, op->fifo_high);
618

T
Tomi Valkeinen 已提交
619 620
	mp = get_mgr_priv(ovl->manager);

621
	op->extra_info_dirty = false;
T
Tomi Valkeinen 已提交
622 623
	if (mp->updating)
		op->shadow_extra_info_dirty = true;
624 625
}

626
static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
T
Tomi Valkeinen 已提交
627
{
628 629
	struct mgr_priv_data *mp = get_mgr_priv(mgr);
	struct omap_overlay *ovl;
T
Tomi Valkeinen 已提交
630

631
	DSSDBG("writing mgr %d regs", mgr->id);
T
Tomi Valkeinen 已提交
632

633 634
	if (!mp->enabled)
		return;
T
Tomi Valkeinen 已提交
635

636
	WARN_ON(mp->busy);
T
Tomi Valkeinen 已提交
637 638

	/* Commit overlay settings */
639 640
	list_for_each_entry(ovl, &mgr->overlays, list) {
		dss_ovl_write_regs(ovl);
641 642 643
		dss_ovl_write_regs_extra(ovl);
	}

644
	if (mp->info_dirty) {
645
		dispc_mgr_setup(mgr->id, &mp->info);
T
Tomi Valkeinen 已提交
646

647
		mp->info_dirty = false;
T
Tomi Valkeinen 已提交
648
		if (mp->updating)
649
			mp->shadow_info_dirty = true;
T
Tomi Valkeinen 已提交
650
	}
651 652
}

653 654 655 656
static void dss_mgr_write_regs_extra(struct omap_overlay_manager *mgr)
{
	struct mgr_priv_data *mp = get_mgr_priv(mgr);

657
	DSSDBG("writing mgr %d regs extra", mgr->id);
658 659 660 661 662 663

	if (!mp->extra_info_dirty)
		return;

	dispc_mgr_set_timings(mgr->id, &mp->timings);

664
	/* lcd_config parameters */
665 666
	if (dss_mgr_is_lcd(mgr->id))
		dispc_mgr_set_lcd_config(mgr->id, &mp->lcd_config);
667

668 669 670 671 672
	mp->extra_info_dirty = false;
	if (mp->updating)
		mp->shadow_extra_info_dirty = true;
}

673 674 675 676
static void dss_write_regs(void)
{
	const int num_mgrs = omap_dss_get_num_overlay_managers();
	int i;
T
Tomi Valkeinen 已提交
677 678

	for (i = 0; i < num_mgrs; ++i) {
679 680
		struct omap_overlay_manager *mgr;
		struct mgr_priv_data *mp;
681
		int r;
682

683 684
		mgr = omap_dss_get_overlay_manager(i);
		mp = get_mgr_priv(mgr);
T
Tomi Valkeinen 已提交
685

686
		if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
T
Tomi Valkeinen 已提交
687 688
			continue;

689
		r = dss_check_settings(mgr);
690 691 692 693 694 695
		if (r) {
			DSSERR("cannot write registers for manager %s: "
					"illegal configuration\n", mgr->name);
			continue;
		}

696
		dss_mgr_write_regs(mgr);
697
		dss_mgr_write_regs_extra(mgr);
698 699
	}
}
700

701 702 703 704
static void dss_set_go_bits(void)
{
	const int num_mgrs = omap_dss_get_num_overlay_managers();
	int i;
T
Tomi Valkeinen 已提交
705

706 707 708
	for (i = 0; i < num_mgrs; ++i) {
		struct omap_overlay_manager *mgr;
		struct mgr_priv_data *mp;
T
Tomi Valkeinen 已提交
709

710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
		mgr = omap_dss_get_overlay_manager(i);
		mp = get_mgr_priv(mgr);

		if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
			continue;

		if (!need_go(mgr))
			continue;

		mp->busy = true;

		if (!dss_data.irq_enabled && need_isr())
			dss_register_vsync_isr();

		dispc_mgr_go(mgr->id);
725
	}
726

T
Tomi Valkeinen 已提交
727 728
}

729 730 731 732 733 734 735 736
static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
{
	struct omap_overlay *ovl;
	struct mgr_priv_data *mp;
	struct ovl_priv_data *op;

	mp = get_mgr_priv(mgr);
	mp->shadow_info_dirty = false;
737
	mp->shadow_extra_info_dirty = false;
738 739 740 741 742 743 744 745

	list_for_each_entry(ovl, &mgr->overlays, list) {
		op = get_ovl_priv(ovl);
		op->shadow_info_dirty = false;
		op->shadow_extra_info_dirty = false;
	}
}

T
Tomi Valkeinen 已提交
746 747
void dss_mgr_start_update(struct omap_overlay_manager *mgr)
{
748
	struct mgr_priv_data *mp = get_mgr_priv(mgr);
749
	unsigned long flags;
750
	int r;
751 752

	spin_lock_irqsave(&data_lock, flags);
T
Tomi Valkeinen 已提交
753

T
Tomi Valkeinen 已提交
754 755
	WARN_ON(mp->updating);

756
	r = dss_check_settings(mgr);
757 758 759 760 761 762
	if (r) {
		DSSERR("cannot start manual update: illegal configuration\n");
		spin_unlock_irqrestore(&data_lock, flags);
		return;
	}

763
	dss_mgr_write_regs(mgr);
764
	dss_mgr_write_regs_extra(mgr);
T
Tomi Valkeinen 已提交
765

T
Tomi Valkeinen 已提交
766
	mp->updating = true;
T
Tomi Valkeinen 已提交
767

T
Tomi Valkeinen 已提交
768 769
	if (!dss_data.irq_enabled && need_isr())
		dss_register_vsync_isr();
T
Tomi Valkeinen 已提交
770

771
	dispc_mgr_enable_sync(mgr->id);
772 773

	spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
774 775
}

776 777 778 779
static void dss_apply_irq_handler(void *data, u32 mask);

static void dss_register_vsync_isr(void)
{
780
	const int num_mgrs = dss_feat_get_num_mgrs();
781
	u32 mask;
782
	int r, i;
783

784 785 786
	mask = 0;
	for (i = 0; i < num_mgrs; ++i)
		mask |= dispc_mgr_get_vsync_irq(i);
787

T
Tomi Valkeinen 已提交
788 789 790
	for (i = 0; i < num_mgrs; ++i)
		mask |= dispc_mgr_get_framedone_irq(i);

791 792 793
	r = omap_dispc_register_isr(dss_apply_irq_handler, NULL, mask);
	WARN_ON(r);

794
	dss_data.irq_enabled = true;
795 796 797 798
}

static void dss_unregister_vsync_isr(void)
{
799
	const int num_mgrs = dss_feat_get_num_mgrs();
800
	u32 mask;
801
	int r, i;
802

803 804 805
	mask = 0;
	for (i = 0; i < num_mgrs; ++i)
		mask |= dispc_mgr_get_vsync_irq(i);
806

T
Tomi Valkeinen 已提交
807 808 809
	for (i = 0; i < num_mgrs; ++i)
		mask |= dispc_mgr_get_framedone_irq(i);

810 811 812
	r = omap_dispc_unregister_isr(dss_apply_irq_handler, NULL, mask);
	WARN_ON(r);

813
	dss_data.irq_enabled = false;
814 815
}

816 817
static void dss_apply_irq_handler(void *data, u32 mask)
{
T
Tomi Valkeinen 已提交
818
	const int num_mgrs = dss_feat_get_num_mgrs();
819
	int i;
820
	bool extra_updating;
T
Tomi Valkeinen 已提交
821

822
	spin_lock(&data_lock);
T
Tomi Valkeinen 已提交
823

824
	/* clear busy, updating flags, shadow_dirty flags */
825
	for (i = 0; i < num_mgrs; i++) {
826 827 828
		struct omap_overlay_manager *mgr;
		struct mgr_priv_data *mp;

829 830 831
		mgr = omap_dss_get_overlay_manager(i);
		mp = get_mgr_priv(mgr);

832
		if (!mp->enabled)
833 834
			continue;

835
		mp->updating = dispc_mgr_is_enabled(i);
T
Tomi Valkeinen 已提交
836

837
		if (!mgr_manual_update(mgr)) {
838
			bool was_busy = mp->busy;
839
			mp->busy = dispc_mgr_go_busy(i);
840

841
			if (was_busy && !mp->busy)
842 843
				mgr_clear_shadow_dirty(mgr);
		}
T
Tomi Valkeinen 已提交
844 845
	}

846
	dss_write_regs();
847
	dss_set_go_bits();
T
Tomi Valkeinen 已提交
848

849 850 851 852
	extra_updating = extra_info_update_ongoing();
	if (!extra_updating)
		complete_all(&extra_updated_completion);

853 854
	if (!need_isr())
		dss_unregister_vsync_isr();
T
Tomi Valkeinen 已提交
855

856
	spin_unlock(&data_lock);
T
Tomi Valkeinen 已提交
857 858
}

859
static void omap_dss_mgr_apply_ovl(struct omap_overlay *ovl)
T
Tomi Valkeinen 已提交
860
{
861
	struct ovl_priv_data *op;
T
Tomi Valkeinen 已提交
862

863
	op = get_ovl_priv(ovl);
T
Tomi Valkeinen 已提交
864

865
	if (!op->user_info_dirty)
866
		return;
T
Tomi Valkeinen 已提交
867

868
	op->user_info_dirty = false;
869
	op->info_dirty = true;
870
	op->info = op->user_info;
T
Tomi Valkeinen 已提交
871 872 873 874
}

static void omap_dss_mgr_apply_mgr(struct omap_overlay_manager *mgr)
{
875
	struct mgr_priv_data *mp;
T
Tomi Valkeinen 已提交
876

877
	mp = get_mgr_priv(mgr);
T
Tomi Valkeinen 已提交
878

879
	if (!mp->user_info_dirty)
T
Tomi Valkeinen 已提交
880 881
		return;

882
	mp->user_info_dirty = false;
883
	mp->info_dirty = true;
884
	mp->info = mp->user_info;
T
Tomi Valkeinen 已提交
885 886
}

887
int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
T
Tomi Valkeinen 已提交
888
{
889 890
	unsigned long flags;
	struct omap_overlay *ovl;
891
	int r;
892 893 894 895 896

	DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);

	spin_lock_irqsave(&data_lock, flags);

897
	r = dss_check_settings_apply(mgr);
898 899 900 901 902 903
	if (r) {
		spin_unlock_irqrestore(&data_lock, flags);
		DSSERR("failed to apply settings: illegal configuration.\n");
		return r;
	}

904 905 906 907 908 909 910 911
	/* Configure overlays */
	list_for_each_entry(ovl, &mgr->overlays, list)
		omap_dss_mgr_apply_ovl(ovl);

	/* Configure manager */
	omap_dss_mgr_apply_mgr(mgr);

	dss_write_regs();
912
	dss_set_go_bits();
913 914 915

	spin_unlock_irqrestore(&data_lock, flags);

916
	return 0;
917 918
}

919 920 921 922 923 924 925 926 927 928 929 930 931
static void dss_apply_ovl_enable(struct omap_overlay *ovl, bool enable)
{
	struct ovl_priv_data *op;

	op = get_ovl_priv(ovl);

	if (op->enabled == enable)
		return;

	op->enabled = enable;
	op->extra_info_dirty = true;
}

932 933 934 935 936 937 938 939 940 941 942 943 944
static void dss_apply_ovl_fifo_thresholds(struct omap_overlay *ovl,
		u32 fifo_low, u32 fifo_high)
{
	struct ovl_priv_data *op = get_ovl_priv(ovl);

	if (op->fifo_low == fifo_low && op->fifo_high == fifo_high)
		return;

	op->fifo_low = fifo_low;
	op->fifo_high = fifo_high;
	op->extra_info_dirty = true;
}

945
static void dss_ovl_setup_fifo(struct omap_overlay *ovl)
946 947 948
{
	struct ovl_priv_data *op = get_ovl_priv(ovl);
	u32 fifo_low, fifo_high;
949
	bool use_fifo_merge = false;
T
Tomi Valkeinen 已提交
950

951 952 953
	if (!op->enabled && !op->enabling)
		return;

954
	dispc_ovl_compute_fifo_thresholds(ovl->id, &fifo_low, &fifo_high,
955
			use_fifo_merge, ovl_manual_update(ovl));
956

957
	dss_apply_ovl_fifo_thresholds(ovl, fifo_low, fifo_high);
T
Tomi Valkeinen 已提交
958 959
}

960
static void dss_mgr_setup_fifos(struct omap_overlay_manager *mgr)
T
Tomi Valkeinen 已提交
961
{
962
	struct omap_overlay *ovl;
963
	struct mgr_priv_data *mp;
T
Tomi Valkeinen 已提交
964

965
	mp = get_mgr_priv(mgr);
T
Tomi Valkeinen 已提交
966

967 968
	if (!mp->enabled)
		return;
T
Tomi Valkeinen 已提交
969

970
	list_for_each_entry(ovl, &mgr->overlays, list)
971
		dss_ovl_setup_fifo(ovl);
972
}
T
Tomi Valkeinen 已提交
973

974
static void dss_setup_fifos(void)
975 976 977 978
{
	const int num_mgrs = omap_dss_get_num_overlay_managers();
	struct omap_overlay_manager *mgr;
	int i;
T
Tomi Valkeinen 已提交
979

980 981
	for (i = 0; i < num_mgrs; ++i) {
		mgr = omap_dss_get_overlay_manager(i);
982
		dss_mgr_setup_fifos(mgr);
983
	}
T
Tomi Valkeinen 已提交
984 985
}

986
int dss_mgr_enable(struct omap_overlay_manager *mgr)
987
{
988 989
	struct mgr_priv_data *mp = get_mgr_priv(mgr);
	unsigned long flags;
990
	int r;
991

T
Tomi Valkeinen 已提交
992 993
	mutex_lock(&apply_lock);

994 995 996
	if (mp->enabled)
		goto out;

997 998
	spin_lock_irqsave(&data_lock, flags);

999
	mp->enabled = true;
1000

1001
	r = dss_check_settings(mgr);
1002 1003 1004
	if (r) {
		DSSERR("failed to enable manager %d: check_settings failed\n",
				mgr->id);
1005
		goto err;
1006 1007
	}

1008
	dss_setup_fifos();
1009

1010
	dss_write_regs();
1011
	dss_set_go_bits();
1012

T
Tomi Valkeinen 已提交
1013 1014 1015
	if (!mgr_manual_update(mgr))
		mp->updating = true;

1016 1017 1018
	if (!dss_data.irq_enabled && need_isr())
		dss_register_vsync_isr();

1019
	spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
1020

1021
	if (!mgr_manual_update(mgr))
1022
		dispc_mgr_enable_sync(mgr->id);
1023

1024
out:
T
Tomi Valkeinen 已提交
1025
	mutex_unlock(&apply_lock);
1026 1027 1028 1029

	return 0;

err:
1030
	mp->enabled = false;
1031 1032 1033
	spin_unlock_irqrestore(&data_lock, flags);
	mutex_unlock(&apply_lock);
	return r;
1034 1035 1036 1037
}

void dss_mgr_disable(struct omap_overlay_manager *mgr)
{
1038 1039 1040
	struct mgr_priv_data *mp = get_mgr_priv(mgr);
	unsigned long flags;

T
Tomi Valkeinen 已提交
1041 1042
	mutex_lock(&apply_lock);

1043 1044 1045
	if (!mp->enabled)
		goto out;

1046
	if (!mgr_manual_update(mgr))
1047
		dispc_mgr_disable_sync(mgr->id);
1048 1049 1050

	spin_lock_irqsave(&data_lock, flags);

T
Tomi Valkeinen 已提交
1051
	mp->updating = false;
1052 1053 1054
	mp->enabled = false;

	spin_unlock_irqrestore(&data_lock, flags);
T
Tomi Valkeinen 已提交
1055

1056
out:
T
Tomi Valkeinen 已提交
1057
	mutex_unlock(&apply_lock);
1058 1059
}

1060 1061 1062
int dss_mgr_set_info(struct omap_overlay_manager *mgr,
		struct omap_overlay_manager_info *info)
{
1063
	struct mgr_priv_data *mp = get_mgr_priv(mgr);
1064
	unsigned long flags;
1065 1066 1067 1068 1069
	int r;

	r = dss_mgr_simple_check(mgr, info);
	if (r)
		return r;
1070 1071 1072

	spin_lock_irqsave(&data_lock, flags);

1073 1074
	mp->user_info = *info;
	mp->user_info_dirty = true;
1075

1076 1077
	spin_unlock_irqrestore(&data_lock, flags);

1078 1079 1080 1081 1082 1083
	return 0;
}

void dss_mgr_get_info(struct omap_overlay_manager *mgr,
		struct omap_overlay_manager_info *info)
{
1084
	struct mgr_priv_data *mp = get_mgr_priv(mgr);
1085 1086 1087 1088
	unsigned long flags;

	spin_lock_irqsave(&data_lock, flags);

1089
	*info = mp->user_info;
1090 1091

	spin_unlock_irqrestore(&data_lock, flags);
1092 1093
}

1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
int dss_mgr_set_output(struct omap_overlay_manager *mgr,
		struct omap_dss_output *output)
{
	int r;

	mutex_lock(&apply_lock);

	if (mgr->output) {
		DSSERR("manager %s is already connected to an output\n",
			mgr->name);
		r = -EINVAL;
		goto err;
	}

	if ((mgr->supported_outputs & output->id) == 0) {
		DSSERR("output does not support manager %s\n",
			mgr->name);
		r = -EINVAL;
		goto err;
	}

	output->manager = mgr;
	mgr->output = output;

	mutex_unlock(&apply_lock);

	return 0;
err:
	mutex_unlock(&apply_lock);
	return r;
}

int dss_mgr_unset_output(struct omap_overlay_manager *mgr)
{
	int r;
	struct mgr_priv_data *mp = get_mgr_priv(mgr);
	unsigned long flags;

	mutex_lock(&apply_lock);

	if (!mgr->output) {
		DSSERR("failed to unset output, output not set\n");
		r = -EINVAL;
		goto err;
	}

	spin_lock_irqsave(&data_lock, flags);

	if (mp->enabled) {
		DSSERR("output can't be unset when manager is enabled\n");
		r = -EINVAL;
		goto err1;
	}

	spin_unlock_irqrestore(&data_lock, flags);

	mgr->output->manager = NULL;
	mgr->output = NULL;

	mutex_unlock(&apply_lock);

	return 0;
err1:
	spin_unlock_irqrestore(&data_lock, flags);
err:
	mutex_unlock(&apply_lock);

	return r;
}

1164
static void dss_apply_mgr_timings(struct omap_overlay_manager *mgr,
1165
		const struct omap_video_timings *timings)
1166 1167 1168 1169 1170 1171 1172 1173
{
	struct mgr_priv_data *mp = get_mgr_priv(mgr);

	mp->timings = *timings;
	mp->extra_info_dirty = true;
}

void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
1174
		const struct omap_video_timings *timings)
1175 1176
{
	unsigned long flags;
1177
	struct mgr_priv_data *mp = get_mgr_priv(mgr);
1178 1179 1180

	spin_lock_irqsave(&data_lock, flags);

1181 1182 1183 1184 1185
	if (mp->updating) {
		DSSERR("cannot set timings for %s: manager needs to be disabled\n",
			mgr->name);
		goto out;
	}
1186

1187 1188
	dss_apply_mgr_timings(mgr, timings);
out:
1189 1190
	spin_unlock_irqrestore(&data_lock, flags);
}
1191

1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
static void dss_apply_mgr_lcd_config(struct omap_overlay_manager *mgr,
		const struct dss_lcd_mgr_config *config)
{
	struct mgr_priv_data *mp = get_mgr_priv(mgr);

	mp->lcd_config = *config;
	mp->extra_info_dirty = true;
}

void dss_mgr_set_lcd_config(struct omap_overlay_manager *mgr,
		const struct dss_lcd_mgr_config *config)
{
	unsigned long flags;
	struct mgr_priv_data *mp = get_mgr_priv(mgr);

1207
	spin_lock_irqsave(&data_lock, flags);
1208 1209 1210 1211 1212 1213 1214 1215 1216

	if (mp->enabled) {
		DSSERR("cannot apply lcd config for %s: manager needs to be disabled\n",
			mgr->name);
		goto out;
	}

	dss_apply_mgr_lcd_config(mgr, config);
out:
1217
	spin_unlock_irqrestore(&data_lock, flags);
1218 1219
}

1220 1221 1222
int dss_ovl_set_info(struct omap_overlay *ovl,
		struct omap_overlay_info *info)
{
1223
	struct ovl_priv_data *op = get_ovl_priv(ovl);
1224
	unsigned long flags;
1225 1226 1227 1228 1229
	int r;

	r = dss_ovl_simple_check(ovl, info);
	if (r)
		return r;
1230 1231 1232

	spin_lock_irqsave(&data_lock, flags);

1233 1234
	op->user_info = *info;
	op->user_info_dirty = true;
1235

1236 1237
	spin_unlock_irqrestore(&data_lock, flags);

1238 1239 1240 1241 1242 1243
	return 0;
}

void dss_ovl_get_info(struct omap_overlay *ovl,
		struct omap_overlay_info *info)
{
1244
	struct ovl_priv_data *op = get_ovl_priv(ovl);
1245 1246 1247 1248
	unsigned long flags;

	spin_lock_irqsave(&data_lock, flags);

1249
	*info = op->user_info;
1250 1251

	spin_unlock_irqrestore(&data_lock, flags);
1252 1253 1254 1255 1256
}

int dss_ovl_set_manager(struct omap_overlay *ovl,
		struct omap_overlay_manager *mgr)
{
1257 1258
	struct ovl_priv_data *op = get_ovl_priv(ovl);
	unsigned long flags;
T
Tomi Valkeinen 已提交
1259 1260
	int r;

1261 1262 1263
	if (!mgr)
		return -EINVAL;

T
Tomi Valkeinen 已提交
1264 1265
	mutex_lock(&apply_lock);

1266 1267 1268
	if (ovl->manager) {
		DSSERR("overlay '%s' already has a manager '%s'\n",
				ovl->name, ovl->manager->name);
T
Tomi Valkeinen 已提交
1269 1270
		r = -EINVAL;
		goto err;
1271 1272
	}

1273 1274 1275 1276
	r = dispc_runtime_get();
	if (r)
		goto err;

1277 1278 1279 1280
	spin_lock_irqsave(&data_lock, flags);

	if (op->enabled) {
		spin_unlock_irqrestore(&data_lock, flags);
1281
		DSSERR("overlay has to be disabled to change the manager\n");
T
Tomi Valkeinen 已提交
1282
		r = -EINVAL;
1283
		goto err1;
1284 1285
	}

1286
	dispc_ovl_set_channel_out(ovl->id, mgr->id);
1287

1288 1289 1290
	ovl->manager = mgr;
	list_add_tail(&ovl->list, &mgr->overlays);

1291 1292
	spin_unlock_irqrestore(&data_lock, flags);

1293
	dispc_runtime_put();
1294

T
Tomi Valkeinen 已提交
1295 1296
	mutex_unlock(&apply_lock);

1297
	return 0;
1298 1299 1300

err1:
	dispc_runtime_put();
T
Tomi Valkeinen 已提交
1301 1302 1303
err:
	mutex_unlock(&apply_lock);
	return r;
1304 1305 1306 1307
}

int dss_ovl_unset_manager(struct omap_overlay *ovl)
{
1308 1309
	struct ovl_priv_data *op = get_ovl_priv(ovl);
	unsigned long flags;
T
Tomi Valkeinen 已提交
1310 1311 1312 1313
	int r;

	mutex_lock(&apply_lock);

1314 1315
	if (!ovl->manager) {
		DSSERR("failed to detach overlay: manager not set\n");
T
Tomi Valkeinen 已提交
1316 1317
		r = -EINVAL;
		goto err;
1318 1319
	}

1320 1321 1322 1323
	spin_lock_irqsave(&data_lock, flags);

	if (op->enabled) {
		spin_unlock_irqrestore(&data_lock, flags);
1324
		DSSERR("overlay has to be disabled to unset the manager\n");
T
Tomi Valkeinen 已提交
1325 1326
		r = -EINVAL;
		goto err;
1327 1328
	}

1329 1330 1331 1332 1333
	spin_unlock_irqrestore(&data_lock, flags);

	/* wait for pending extra_info updates to ensure the ovl is disabled */
	wait_pending_extra_info_updates();

1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
	/*
	 * For a manual update display, there is no guarantee that the overlay
	 * is really disabled in HW, we may need an extra update from this
	 * manager before the configurations can go in. Return an error if the
	 * overlay needed an update from the manager.
	 *
	 * TODO: Instead of returning an error, try to do a dummy manager update
	 * here to disable the overlay in hardware. Use the *GATED fields in
	 * the DISPC_CONFIG registers to do a dummy update.
	 */
1344 1345
	spin_lock_irqsave(&data_lock, flags);

1346 1347 1348 1349 1350 1351
	if (ovl_manual_update(ovl) && op->extra_info_dirty) {
		spin_unlock_irqrestore(&data_lock, flags);
		DSSERR("need an update to change the manager\n");
		r = -EINVAL;
		goto err;
	}
1352

1353 1354 1355
	ovl->manager = NULL;
	list_del(&ovl->list);

1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
	spin_unlock_irqrestore(&data_lock, flags);

	mutex_unlock(&apply_lock);

	return 0;
err:
	mutex_unlock(&apply_lock);
	return r;
}

bool dss_ovl_is_enabled(struct omap_overlay *ovl)
{
	struct ovl_priv_data *op = get_ovl_priv(ovl);
	unsigned long flags;
	bool e;

	spin_lock_irqsave(&data_lock, flags);

	e = op->enabled;

	spin_unlock_irqrestore(&data_lock, flags);

	return e;
}

int dss_ovl_enable(struct omap_overlay *ovl)
{
	struct ovl_priv_data *op = get_ovl_priv(ovl);
	unsigned long flags;
	int r;

	mutex_lock(&apply_lock);

1389 1390
	if (op->enabled) {
		r = 0;
1391
		goto err1;
1392 1393
	}

1394
	if (ovl->manager == NULL || ovl->manager->output == NULL) {
1395
		r = -EINVAL;
1396
		goto err1;
1397 1398 1399 1400
	}

	spin_lock_irqsave(&data_lock, flags);

T
Tomi Valkeinen 已提交
1401 1402
	op->enabling = true;

1403
	r = dss_check_settings(ovl->manager);
1404 1405 1406 1407 1408 1409
	if (r) {
		DSSERR("failed to enable overlay %d: check_settings failed\n",
				ovl->id);
		goto err2;
	}

1410
	dss_setup_fifos();
1411

T
Tomi Valkeinen 已提交
1412 1413 1414
	op->enabling = false;
	dss_apply_ovl_enable(ovl, true);

1415
	dss_write_regs();
1416
	dss_set_go_bits();
1417

1418 1419 1420 1421 1422
	spin_unlock_irqrestore(&data_lock, flags);

	mutex_unlock(&apply_lock);

	return 0;
1423
err2:
T
Tomi Valkeinen 已提交
1424
	op->enabling = false;
1425 1426
	spin_unlock_irqrestore(&data_lock, flags);
err1:
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438
	mutex_unlock(&apply_lock);
	return r;
}

int dss_ovl_disable(struct omap_overlay *ovl)
{
	struct ovl_priv_data *op = get_ovl_priv(ovl);
	unsigned long flags;
	int r;

	mutex_lock(&apply_lock);

1439 1440 1441 1442 1443
	if (!op->enabled) {
		r = 0;
		goto err;
	}

1444
	if (ovl->manager == NULL || ovl->manager->output == NULL) {
1445 1446 1447 1448 1449 1450
		r = -EINVAL;
		goto err;
	}

	spin_lock_irqsave(&data_lock, flags);

1451
	dss_apply_ovl_enable(ovl, false);
1452
	dss_write_regs();
1453
	dss_set_go_bits();
1454

1455 1456
	spin_unlock_irqrestore(&data_lock, flags);

T
Tomi Valkeinen 已提交
1457 1458
	mutex_unlock(&apply_lock);

1459
	return 0;
1460

T
Tomi Valkeinen 已提交
1461 1462 1463
err:
	mutex_unlock(&apply_lock);
	return r;
1464 1465
}