mdp4_kms.c 15.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2013 Red Hat
 * Author: Rob Clark <robdclark@gmail.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/>.
 */


#include "msm_drv.h"
20
#include "msm_gem.h"
21
#include "msm_mmu.h"
22 23 24 25 26 27
#include "mdp4_kms.h"

static struct mdp4_platform_config *mdp4_get_config(struct platform_device *dev);

static int mdp4_hw_init(struct msm_kms *kms)
{
R
Rob Clark 已提交
28
	struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms));
29 30 31 32 33 34 35
	struct drm_device *dev = mdp4_kms->dev;
	uint32_t version, major, minor, dmap_cfg, vg_cfg;
	unsigned long clk;
	int ret = 0;

	pm_runtime_get_sync(dev->dev);

36
	mdp4_enable(mdp4_kms);
37
	version = mdp4_read(mdp4_kms, REG_MDP4_VERSION);
38
	mdp4_disable(mdp4_kms);
39 40 41 42

	major = FIELD(version, MDP4_VERSION_MAJOR);
	minor = FIELD(version, MDP4_VERSION_MINOR);

43
	DBG("found MDP4 version v%d.%d", major, minor);
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

	if (major != 4) {
		dev_err(dev->dev, "unexpected MDP version: v%d.%d\n",
				major, minor);
		ret = -ENXIO;
		goto out;
	}

	mdp4_kms->rev = minor;

	if (mdp4_kms->rev > 1) {
		mdp4_write(mdp4_kms, REG_MDP4_CS_CONTROLLER0, 0x0707ffff);
		mdp4_write(mdp4_kms, REG_MDP4_CS_CONTROLLER1, 0x03073f3f);
	}

	mdp4_write(mdp4_kms, REG_MDP4_PORTMAP_MODE, 0x3);

	/* max read pending cmd config, 3 pending requests: */
	mdp4_write(mdp4_kms, REG_MDP4_READ_CNFG, 0x02222);

	clk = clk_get_rate(mdp4_kms->clk);

	if ((mdp4_kms->rev >= 1) || (clk >= 90000000)) {
		dmap_cfg = 0x47;     /* 16 bytes-burst x 8 req */
		vg_cfg = 0x47;       /* 16 bytes-burs x 8 req */
	} else {
		dmap_cfg = 0x27;     /* 8 bytes-burst x 8 req */
		vg_cfg = 0x43;       /* 16 bytes-burst x 4 req */
	}

	DBG("fetch config: dmap=%02x, vg=%02x", dmap_cfg, vg_cfg);

	mdp4_write(mdp4_kms, REG_MDP4_DMA_FETCH_CONFIG(DMA_P), dmap_cfg);
	mdp4_write(mdp4_kms, REG_MDP4_DMA_FETCH_CONFIG(DMA_E), dmap_cfg);

	mdp4_write(mdp4_kms, REG_MDP4_PIPE_FETCH_CONFIG(VG1), vg_cfg);
	mdp4_write(mdp4_kms, REG_MDP4_PIPE_FETCH_CONFIG(VG2), vg_cfg);
	mdp4_write(mdp4_kms, REG_MDP4_PIPE_FETCH_CONFIG(RGB1), vg_cfg);
	mdp4_write(mdp4_kms, REG_MDP4_PIPE_FETCH_CONFIG(RGB2), vg_cfg);

	if (mdp4_kms->rev >= 2)
		mdp4_write(mdp4_kms, REG_MDP4_LAYERMIXER_IN_CFG_UPDATE_METHOD, 1);
86
	mdp4_write(mdp4_kms, REG_MDP4_LAYERMIXER_IN_CFG, 0);
87 88 89 90 91 92 93 94 95 96 97 98

	/* disable CSC matrix / YUV by default: */
	mdp4_write(mdp4_kms, REG_MDP4_PIPE_OP_MODE(VG1), 0);
	mdp4_write(mdp4_kms, REG_MDP4_PIPE_OP_MODE(VG2), 0);
	mdp4_write(mdp4_kms, REG_MDP4_DMA_P_OP_MODE, 0);
	mdp4_write(mdp4_kms, REG_MDP4_DMA_S_OP_MODE, 0);
	mdp4_write(mdp4_kms, REG_MDP4_OVLP_CSC_CONFIG(1), 0);
	mdp4_write(mdp4_kms, REG_MDP4_OVLP_CSC_CONFIG(2), 0);

	if (mdp4_kms->rev > 1)
		mdp4_write(mdp4_kms, REG_MDP4_RESET_STATUS, 1);

99 100
	dev->mode_config.allow_fb_modifiers = true;

101 102 103 104 105 106
out:
	pm_runtime_put_sync(dev->dev);

	return ret;
}

107 108 109
static void mdp4_prepare_commit(struct msm_kms *kms, struct drm_atomic_state *state)
{
	struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms));
D
Daniel Vetter 已提交
110 111 112
	int i;
	struct drm_crtc *crtc;
	struct drm_crtc_state *crtc_state;
113 114 115 116

	mdp4_enable(mdp4_kms);

	/* see 119ecb7fd */
D
Daniel Vetter 已提交
117
	for_each_crtc_in_state(state, crtc, crtc_state, i)
118 119 120 121 122 123
		drm_crtc_vblank_get(crtc);
}

static void mdp4_complete_commit(struct msm_kms *kms, struct drm_atomic_state *state)
{
	struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms));
D
Daniel Vetter 已提交
124 125 126
	int i;
	struct drm_crtc *crtc;
	struct drm_crtc_state *crtc_state;
127 128

	/* see 119ecb7fd */
D
Daniel Vetter 已提交
129
	for_each_crtc_in_state(state, crtc, crtc_state, i)
130 131 132 133 134
		drm_crtc_vblank_put(crtc);

	mdp4_disable(mdp4_kms);
}

135 136 137 138 139 140
static void mdp4_wait_for_crtc_commit_done(struct msm_kms *kms,
						struct drm_crtc *crtc)
{
	mdp4_crtc_wait_for_commit_done(crtc);
}

141 142 143 144
static long mdp4_round_pixclk(struct msm_kms *kms, unsigned long rate,
		struct drm_encoder *encoder)
{
	/* if we had >1 encoder, we'd need something more clever: */
145 146 147 148 149 150 151 152
	switch (encoder->encoder_type) {
	case DRM_MODE_ENCODER_TMDS:
		return mdp4_dtv_round_pixclk(encoder, rate);
	case DRM_MODE_ENCODER_LVDS:
	case DRM_MODE_ENCODER_DSI:
	default:
		return rate;
	}
153 154
}

155 156 157 158
static const char * const iommu_ports[] = {
	"mdp_port0_cb0", "mdp_port1_cb0",
};

159 160
static void mdp4_destroy(struct msm_kms *kms)
{
R
Rob Clark 已提交
161
	struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms));
162
	struct device *dev = mdp4_kms->dev->dev;
163
	struct msm_gem_address_space *aspace = mdp4_kms->aspace;
164

165 166
	if (mdp4_kms->blank_cursor_iova)
		msm_gem_put_iova(mdp4_kms->blank_cursor_bo, mdp4_kms->id);
167
	drm_gem_object_unreference_unlocked(mdp4_kms->blank_cursor_bo);
168

169 170 171 172 173 174
	if (aspace) {
		aspace->mmu->funcs->detach(aspace->mmu,
				iommu_ports, ARRAY_SIZE(iommu_ports));
		msm_gem_address_space_destroy(aspace);
	}

175 176 177
	if (mdp4_kms->rpm_enabled)
		pm_runtime_disable(dev);

178 179 180
	kfree(mdp4_kms);
}

R
Rob Clark 已提交
181 182
static const struct mdp_kms_funcs kms_funcs = {
	.base = {
183 184 185 186 187 188 189
		.hw_init         = mdp4_hw_init,
		.irq_preinstall  = mdp4_irq_preinstall,
		.irq_postinstall = mdp4_irq_postinstall,
		.irq_uninstall   = mdp4_irq_uninstall,
		.irq             = mdp4_irq,
		.enable_vblank   = mdp4_enable_vblank,
		.disable_vblank  = mdp4_disable_vblank,
190 191
		.prepare_commit  = mdp4_prepare_commit,
		.complete_commit = mdp4_complete_commit,
192
		.wait_for_crtc_commit_done = mdp4_wait_for_crtc_commit_done,
R
Rob Clark 已提交
193
		.get_format      = mdp_get_format,
194 195
		.round_pixclk    = mdp4_round_pixclk,
		.destroy         = mdp4_destroy,
R
Rob Clark 已提交
196 197
	},
	.set_irqmask         = mdp4_set_irqmask,
198 199 200 201 202 203 204 205 206 207
};

int mdp4_disable(struct mdp4_kms *mdp4_kms)
{
	DBG("");

	clk_disable_unprepare(mdp4_kms->clk);
	if (mdp4_kms->pclk)
		clk_disable_unprepare(mdp4_kms->pclk);
	clk_disable_unprepare(mdp4_kms->lut_clk);
R
Rob Clark 已提交
208 209
	if (mdp4_kms->axi_clk)
		clk_disable_unprepare(mdp4_kms->axi_clk);
210 211 212 213 214 215 216 217 218 219 220 221

	return 0;
}

int mdp4_enable(struct mdp4_kms *mdp4_kms)
{
	DBG("");

	clk_prepare_enable(mdp4_kms->clk);
	if (mdp4_kms->pclk)
		clk_prepare_enable(mdp4_kms->pclk);
	clk_prepare_enable(mdp4_kms->lut_clk);
R
Rob Clark 已提交
222 223
	if (mdp4_kms->axi_clk)
		clk_prepare_enable(mdp4_kms->axi_clk);
224 225 226 227

	return 0;
}

228
static struct device_node *mdp4_detect_lcdc_panel(struct drm_device *dev)
R
Rob Clark 已提交
229
{
230 231
	struct device_node *endpoint, *panel_node;
	struct device_node *np = dev->dev->of_node;
R
Rob Clark 已提交
232

233 234 235 236 237
	/*
	 * LVDS/LCDC is the first port described in the list of ports in the
	 * MDP4 DT node.
	 */
	endpoint = of_graph_get_endpoint_by_regs(np, 0, -1);
238
	if (!endpoint) {
239
		DBG("no LVDS remote endpoint\n");
240
		return NULL;
241 242 243 244
	}

	panel_node = of_graph_get_remote_port_parent(endpoint);
	if (!panel_node) {
245
		DBG("no valid panel node in LVDS endpoint\n");
246
		of_node_put(endpoint);
247
		return NULL;
248 249 250 251
	}

	of_node_put(endpoint);

252
	return panel_node;
R
Rob Clark 已提交
253 254
}

255 256
static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms,
				  int intf_type)
257 258 259 260
{
	struct drm_device *dev = mdp4_kms->dev;
	struct msm_drm_private *priv = dev->dev_private;
	struct drm_encoder *encoder;
R
Rob Clark 已提交
261
	struct drm_connector *connector;
262
	struct device_node *panel_node;
263 264
	struct drm_encoder *dsi_encs[MSM_DSI_ENCODER_NUM];
	int i, dsi_id;
265 266
	int ret;

267 268
	switch (intf_type) {
	case DRM_MODE_ENCODER_LVDS:
269
		/*
270 271
		 * bail out early if there is no panel node (no need to
		 * initialize LCDC encoder and LVDS connector)
272 273
		 */
		panel_node = mdp4_detect_lcdc_panel(dev);
274 275
		if (!panel_node)
			return 0;
276 277

		encoder = mdp4_lcdc_encoder_init(dev, panel_node);
278 279 280 281
		if (IS_ERR(encoder)) {
			dev_err(dev->dev, "failed to construct LCDC encoder\n");
			return PTR_ERR(encoder);
		}
R
Rob Clark 已提交
282

283 284
		/* LCDC can be hooked to DMA_P (TODO: Add DMA_S later?) */
		encoder->possible_crtcs = 1 << DMA_P;
R
Rob Clark 已提交
285

286
		connector = mdp4_lvds_connector_init(dev, panel_node, encoder);
287 288 289 290
		if (IS_ERR(connector)) {
			dev_err(dev->dev, "failed to initialize LVDS connector\n");
			return PTR_ERR(connector);
		}
R
Rob Clark 已提交
291

292 293
		priv->encoders[priv->num_encoders++] = encoder;
		priv->connectors[priv->num_connectors++] = connector;
R
Rob Clark 已提交
294

295 296 297 298 299 300 301
		break;
	case DRM_MODE_ENCODER_TMDS:
		encoder = mdp4_dtv_encoder_init(dev);
		if (IS_ERR(encoder)) {
			dev_err(dev->dev, "failed to construct DTV encoder\n");
			return PTR_ERR(encoder);
		}
R
Rob Clark 已提交
302

303 304
		/* DTV can be hooked to DMA_E: */
		encoder->possible_crtcs = 1 << 1;
R
Rob Clark 已提交
305

306 307
		if (priv->hdmi) {
			/* Construct bridge/connector for HDMI: */
A
Arnd Bergmann 已提交
308
			ret = msm_hdmi_modeset_init(priv->hdmi, dev, encoder);
309 310 311 312 313
			if (ret) {
				dev_err(dev->dev, "failed to initialize HDMI: %d\n", ret);
				return ret;
			}
		}
R
Rob Clark 已提交
314

315
		priv->encoders[priv->num_encoders++] = encoder;
R
Rob Clark 已提交
316

317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
		break;
	case DRM_MODE_ENCODER_DSI:
		/* only DSI1 supported for now */
		dsi_id = 0;

		if (!priv->dsi[dsi_id])
			break;

		for (i = 0; i < MSM_DSI_ENCODER_NUM; i++) {
			dsi_encs[i] = mdp4_dsi_encoder_init(dev);
			if (IS_ERR(dsi_encs[i])) {
				ret = PTR_ERR(dsi_encs[i]);
				dev_err(dev->dev,
					"failed to construct DSI encoder: %d\n",
					ret);
				return ret;
			}

			/* TODO: Add DMA_S later? */
			dsi_encs[i]->possible_crtcs = 1 << DMA_P;
			priv->encoders[priv->num_encoders++] = dsi_encs[i];
		}

		ret = msm_dsi_modeset_init(priv->dsi[dsi_id], dev, dsi_encs);
		if (ret) {
			dev_err(dev->dev, "failed to initialize DSI: %d\n",
				ret);
			return ret;
		}

347 348 349 350
		break;
	default:
		dev_err(dev->dev, "Invalid or unsupported interface\n");
		return -EINVAL;
R
Rob Clark 已提交
351 352
	}

353 354
	return 0;
}
R
Rob Clark 已提交
355

356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
static int modeset_init(struct mdp4_kms *mdp4_kms)
{
	struct drm_device *dev = mdp4_kms->dev;
	struct msm_drm_private *priv = dev->dev_private;
	struct drm_plane *plane;
	struct drm_crtc *crtc;
	int i, ret;
	static const enum mdp4_pipe rgb_planes[] = {
		RGB1, RGB2,
	};
	static const enum mdp4_pipe vg_planes[] = {
		VG1, VG2,
	};
	static const enum mdp4_dma mdp4_crtcs[] = {
		DMA_P, DMA_E,
	};
	static const char * const mdp4_crtc_names[] = {
		"DMA_P", "DMA_E",
	};
	static const int mdp4_intfs[] = {
		DRM_MODE_ENCODER_LVDS,
377
		DRM_MODE_ENCODER_DSI,
378 379
		DRM_MODE_ENCODER_TMDS,
	};
380

381 382 383 384 385 386 387 388 389 390
	/* construct non-private planes: */
	for (i = 0; i < ARRAY_SIZE(vg_planes); i++) {
		plane = mdp4_plane_init(dev, vg_planes[i], false);
		if (IS_ERR(plane)) {
			dev_err(dev->dev,
				"failed to construct plane for VG%d\n", i + 1);
			ret = PTR_ERR(plane);
			goto fail;
		}
		priv->planes[priv->num_planes++] = plane;
391 392
	}

393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
	for (i = 0; i < ARRAY_SIZE(mdp4_crtcs); i++) {
		plane = mdp4_plane_init(dev, rgb_planes[i], true);
		if (IS_ERR(plane)) {
			dev_err(dev->dev,
				"failed to construct plane for RGB%d\n", i + 1);
			ret = PTR_ERR(plane);
			goto fail;
		}

		crtc  = mdp4_crtc_init(dev, plane, priv->num_crtcs, i,
				mdp4_crtcs[i]);
		if (IS_ERR(crtc)) {
			dev_err(dev->dev, "failed to construct crtc for %s\n",
				mdp4_crtc_names[i]);
			ret = PTR_ERR(crtc);
			goto fail;
		}
R
Rob Clark 已提交
410

411 412
		priv->crtcs[priv->num_crtcs++] = crtc;
	}
R
Rob Clark 已提交
413

414 415 416 417
	/*
	 * we currently set up two relatively fixed paths:
	 *
	 * LCDC/LVDS path: RGB1 -> DMA_P -> LCDC -> LVDS
418 419 420
	 *			or
	 * DSI path: RGB1 -> DMA_P -> DSI1 -> DSI Panel
	 *
421 422
	 * DTV/HDMI path: RGB2 -> DMA_E -> DTV -> HDMI
	 */
423

424 425
	for (i = 0; i < ARRAY_SIZE(mdp4_intfs); i++) {
		ret = mdp4_modeset_init_intf(mdp4_kms, mdp4_intfs[i]);
R
Rob Clark 已提交
426
		if (ret) {
427 428
			dev_err(dev->dev, "failed to initialize intf: %d, %d\n",
				i, ret);
R
Rob Clark 已提交
429 430
			goto fail;
		}
431 432 433 434 435 436 437 438 439 440 441 442 443 444
	}

	return 0;

fail:
	return ret;
}

struct msm_kms *mdp4_kms_init(struct drm_device *dev)
{
	struct platform_device *pdev = dev->platformdev;
	struct mdp4_platform_config *config = mdp4_get_config(pdev);
	struct mdp4_kms *mdp4_kms;
	struct msm_kms *kms = NULL;
445
	struct msm_gem_address_space *aspace;
446
	int irq, ret;
447 448 449 450 451 452 453 454

	mdp4_kms = kzalloc(sizeof(*mdp4_kms), GFP_KERNEL);
	if (!mdp4_kms) {
		dev_err(dev->dev, "failed to allocate kms\n");
		ret = -ENOMEM;
		goto fail;
	}

R
Rob Clark 已提交
455 456 457
	mdp_kms_init(&mdp4_kms->base, &kms_funcs);

	kms = &mdp4_kms->base.base;
458 459 460 461 462 463 464 465 466

	mdp4_kms->dev = dev;

	mdp4_kms->mmio = msm_ioremap(pdev, NULL, "MDP4");
	if (IS_ERR(mdp4_kms->mmio)) {
		ret = PTR_ERR(mdp4_kms->mmio);
		goto fail;
	}

467 468 469 470 471 472 473 474 475
	irq = platform_get_irq(pdev, 0);
	if (irq < 0) {
		ret = irq;
		dev_err(dev->dev, "failed to get irq: %d\n", ret);
		goto fail;
	}

	kms->irq = irq;

R
Rob Clark 已提交
476 477 478 479
	/* NOTE: driver for this regulator still missing upstream.. use
	 * _get_exclusive() and ignore the error if it does not exist
	 * (and hope that the bootloader left it on for us)
	 */
480
	mdp4_kms->vdd = devm_regulator_get_exclusive(&pdev->dev, "vdd");
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
	if (IS_ERR(mdp4_kms->vdd))
		mdp4_kms->vdd = NULL;

	if (mdp4_kms->vdd) {
		ret = regulator_enable(mdp4_kms->vdd);
		if (ret) {
			dev_err(dev->dev, "failed to enable regulator vdd: %d\n", ret);
			goto fail;
		}
	}

	mdp4_kms->clk = devm_clk_get(&pdev->dev, "core_clk");
	if (IS_ERR(mdp4_kms->clk)) {
		dev_err(dev->dev, "failed to get core_clk\n");
		ret = PTR_ERR(mdp4_kms->clk);
		goto fail;
	}

	mdp4_kms->pclk = devm_clk_get(&pdev->dev, "iface_clk");
	if (IS_ERR(mdp4_kms->pclk))
		mdp4_kms->pclk = NULL;

	// XXX if (rev >= MDP_REV_42) { ???
	mdp4_kms->lut_clk = devm_clk_get(&pdev->dev, "lut_clk");
	if (IS_ERR(mdp4_kms->lut_clk)) {
		dev_err(dev->dev, "failed to get lut_clk\n");
		ret = PTR_ERR(mdp4_kms->lut_clk);
		goto fail;
	}

511
	mdp4_kms->axi_clk = devm_clk_get(&pdev->dev, "bus_clk");
R
Rob Clark 已提交
512 513 514 515 516 517
	if (IS_ERR(mdp4_kms->axi_clk)) {
		dev_err(dev->dev, "failed to get axi_clk\n");
		ret = PTR_ERR(mdp4_kms->axi_clk);
		goto fail;
	}

518 519 520
	clk_set_rate(mdp4_kms->clk, config->max_clk);
	clk_set_rate(mdp4_kms->lut_clk, config->max_clk);

521 522 523
	pm_runtime_enable(dev->dev);
	mdp4_kms->rpm_enabled = true;

524 525 526 527
	/* make sure things are off before attaching iommu (bootloader could
	 * have left things on, in which case we'll start getting faults if
	 * we don't disable):
	 */
528
	mdp4_enable(mdp4_kms);
529 530 531
	mdp4_write(mdp4_kms, REG_MDP4_DTV_ENABLE, 0);
	mdp4_write(mdp4_kms, REG_MDP4_LCDC_ENABLE, 0);
	mdp4_write(mdp4_kms, REG_MDP4_DSI_ENABLE, 0);
532
	mdp4_disable(mdp4_kms);
533 534
	mdelay(16);

535
	if (config->iommu) {
536 537 538 539
		aspace = msm_gem_address_space_create(&pdev->dev,
				config->iommu, "mdp4");
		if (IS_ERR(aspace)) {
			ret = PTR_ERR(aspace);
540 541
			goto fail;
		}
542 543 544 545

		mdp4_kms->aspace = aspace;

		ret = aspace->mmu->funcs->attach(aspace->mmu, iommu_ports,
546 547 548 549 550 551
				ARRAY_SIZE(iommu_ports));
		if (ret)
			goto fail;
	} else {
		dev_info(dev->dev, "no iommu, fallback to phys "
				"contig buffers for scanout\n");
552
		aspace = NULL;
553
	}
554

555
	mdp4_kms->id = msm_register_address_space(dev, aspace);
556 557 558 559 560 561 562 563 564 565 566 567
	if (mdp4_kms->id < 0) {
		ret = mdp4_kms->id;
		dev_err(dev->dev, "failed to register mdp4 iommu: %d\n", ret);
		goto fail;
	}

	ret = modeset_init(mdp4_kms);
	if (ret) {
		dev_err(dev->dev, "modeset_init failed: %d\n", ret);
		goto fail;
	}

568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
	mutex_lock(&dev->struct_mutex);
	mdp4_kms->blank_cursor_bo = msm_gem_new(dev, SZ_16K, MSM_BO_WC);
	mutex_unlock(&dev->struct_mutex);
	if (IS_ERR(mdp4_kms->blank_cursor_bo)) {
		ret = PTR_ERR(mdp4_kms->blank_cursor_bo);
		dev_err(dev->dev, "could not allocate blank-cursor bo: %d\n", ret);
		mdp4_kms->blank_cursor_bo = NULL;
		goto fail;
	}

	ret = msm_gem_get_iova(mdp4_kms->blank_cursor_bo, mdp4_kms->id,
			&mdp4_kms->blank_cursor_iova);
	if (ret) {
		dev_err(dev->dev, "could not pin blank-cursor bo: %d\n", ret);
		goto fail;
	}

585 586 587 588 589
	dev->mode_config.min_width = 0;
	dev->mode_config.min_height = 0;
	dev->mode_config.max_width = 2048;
	dev->mode_config.max_height = 2048;

590 591 592 593 594 595 596 597 598 599 600
	return kms;

fail:
	if (kms)
		mdp4_destroy(kms);
	return ERR_PTR(ret);
}

static struct mdp4_platform_config *mdp4_get_config(struct platform_device *dev)
{
	static struct mdp4_platform_config config = {};
601 602

	/* TODO: Chips that aren't apq8064 have a 200 Mhz max_clk */
603 604
	config.max_clk = 266667000;
	config.iommu = iommu_domain_alloc(&platform_bus_type);
605 606 607 608
	if (config.iommu) {
		config.iommu->geometry.aperture_start = 0x1000;
		config.iommu->geometry.aperture_end = 0xffffffff;
	}
609

610 611
	return &config;
}