intel_dsi_pll.c 15.8 KB
Newer Older
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
/*
 * Copyright © 2013 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *	Shobhit Kumar <shobhit.kumar@intel.com>
 *	Yogesh Mohan Marimuthu <yogesh.mohan.marimuthu@intel.com>
 */

#include <linux/kernel.h>
#include "intel_drv.h"
#include "i915_drv.h"
#include "intel_dsi.h"

33
static const u16 lfsr_converts[] = {
34 35
	426, 469, 234, 373, 442, 221, 110, 311, 411,		/* 62 - 70 */
	461, 486, 243, 377, 188, 350, 175, 343, 427, 213,	/* 71 - 80 */
36 37
	106, 53, 282, 397, 454, 227, 113, 56, 284, 142,		/* 81 - 90 */
	71, 35, 273, 136, 324, 418, 465, 488, 500, 506		/* 91 - 100 */
38 39
};

40
/* Get DSI clock from pixel clock */
41 42
static u32 dsi_clk_from_pclk(u32 pclk, enum mipi_dsi_pixel_format fmt,
			     int lane_count)
43
{
44
	u32 dsi_clk_khz;
45
	u32 bpp = mipi_dsi_pixel_format_to_bpp(fmt);
46

47 48
	/* DSI data rate = pixel clock * bits per pixel / lane count
	   pixel clock is converted from KHz to Hz */
49
	dsi_clk_khz = DIV_ROUND_CLOSEST(pclk * bpp, lane_count);
50

51
	return dsi_clk_khz;
52 53
}

54
static int dsi_calc_mnp(struct drm_i915_private *dev_priv,
55 56
			struct intel_crtc_state *config,
			int target_dsi_clk)
57
{
58 59
	unsigned int m_min, m_max, p_min = 2, p_max = 6;
	unsigned int m, n, p;
60 61
	unsigned int calc_m, calc_p;
	int delta, ref_clk;
62

63 64
	/* target_dsi_clk is expected in kHz */
	if (target_dsi_clk < 300000 || target_dsi_clk > 1150000) {
65 66 67 68
		DRM_ERROR("DSI CLK Out of Range\n");
		return -ECHRNG;
	}

69 70 71 72 73 74 75 76 77 78 79 80
	if (IS_CHERRYVIEW(dev_priv)) {
		ref_clk = 100000;
		n = 4;
		m_min = 70;
		m_max = 96;
	} else {
		ref_clk = 25000;
		n = 1;
		m_min = 62;
		m_max = 92;
	}

81 82 83 84
	calc_p = p_min;
	calc_m = m_min;
	delta = abs(target_dsi_clk - (m_min * ref_clk) / (p_min * n));

85 86
	for (m = m_min; m <= m_max && delta; m++) {
		for (p = p_min; p <= p_max && delta; p++) {
87 88 89 90
			/*
			 * Find the optimal m and p divisors with minimal delta
			 * +/- the required clock
			 */
91
			int calc_dsi_clk = (m * ref_clk) / (p * n);
92 93 94
			int d = abs(target_dsi_clk - calc_dsi_clk);
			if (d < delta) {
				delta = d;
95 96
				calc_m = m;
				calc_p = p;
97 98 99 100
			}
		}
	}

101
	/* register has log2(N1), this works fine for powers of two */
102
	config->dsi_pll.ctrl = 1 << (DSI_PLL_P1_POST_DIV_SHIFT + calc_p - 2);
103 104 105
	config->dsi_pll.div =
		(ffs(n) - 1) << DSI_PLL_N1_DIV_SHIFT |
		(u32)lfsr_converts[calc_m - 62] << DSI_PLL_M1_DIV_SHIFT;
106 107 108 109 110 111 112 113

	return 0;
}

/*
 * XXX: The muxing and gating is hard coded for now. Need to add support for
 * sharing PLLs with two DSI outputs.
 */
114 115
static int vlv_compute_dsi_pll(struct intel_encoder *encoder,
			       struct intel_crtc_state *config)
116
{
117
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
118 119 120 121
	struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
	int ret;
	u32 dsi_clk;

122
	dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
123
				    intel_dsi->lane_count);
124

125
	ret = dsi_calc_mnp(dev_priv, config, dsi_clk);
126 127
	if (ret) {
		DRM_DEBUG_KMS("dsi_calc_mnp failed\n");
128
		return ret;
129 130
	}

131
	if (intel_dsi->ports & (1 << PORT_A))
132
		config->dsi_pll.ctrl |= DSI_PLL_CLK_GATE_DSI0_DSIPLL;
133

134
	if (intel_dsi->ports & (1 << PORT_C))
135 136 137
		config->dsi_pll.ctrl |= DSI_PLL_CLK_GATE_DSI1_DSIPLL;

	config->dsi_pll.ctrl |= DSI_PLL_VCO_EN;
138

139
	DRM_DEBUG_KMS("dsi pll div %08x, ctrl %08x\n",
140 141 142 143 144 145 146
		      config->dsi_pll.div, config->dsi_pll.ctrl);

	return 0;
}

static void vlv_enable_dsi_pll(struct intel_encoder *encoder,
			       const struct intel_crtc_state *config)
147
{
148
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
149 150 151

	DRM_DEBUG_KMS("\n");

V
Ville Syrjälä 已提交
152
	mutex_lock(&dev_priv->sb_lock);
153

154 155 156 157
	vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, 0);
	vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_DIVIDER, config->dsi_pll.div);
	vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL,
		      config->dsi_pll.ctrl & ~DSI_PLL_VCO_EN);
158

159 160 161 162
	/* wait at least 0.5 us after ungating before enabling VCO,
	 * allow hrtimer subsystem optimization by relaxing timing
	 */
	usleep_range(10, 50);
163

164
	vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, config->dsi_pll.ctrl);
165

166 167
	if (wait_for(vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL) &
						DSI_PLL_LOCK, 20)) {
168

V
Ville Syrjälä 已提交
169
		mutex_unlock(&dev_priv->sb_lock);
170 171 172
		DRM_ERROR("DSI PLL lock failed\n");
		return;
	}
V
Ville Syrjälä 已提交
173
	mutex_unlock(&dev_priv->sb_lock);
174 175 176 177

	DRM_DEBUG_KMS("DSI PLL locked\n");
}

178
static void vlv_disable_dsi_pll(struct intel_encoder *encoder)
179
{
180
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
181 182 183 184
	u32 tmp;

	DRM_DEBUG_KMS("\n");

V
Ville Syrjälä 已提交
185
	mutex_lock(&dev_priv->sb_lock);
186 187 188 189 190 191

	tmp = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
	tmp &= ~DSI_PLL_VCO_EN;
	tmp |= DSI_PLL_LDO_GATE;
	vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, tmp);

V
Ville Syrjälä 已提交
192
	mutex_unlock(&dev_priv->sb_lock);
193
}
194

195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
static bool bxt_dsi_pll_is_enabled(struct drm_i915_private *dev_priv)
{
	bool enabled;
	u32 val;
	u32 mask;

	mask = BXT_DSI_PLL_DO_ENABLE | BXT_DSI_PLL_LOCKED;
	val = I915_READ(BXT_DSI_PLL_ENABLE);
	enabled = (val & mask) == mask;

	if (!enabled)
		return false;

	/*
	 * Both dividers must be programmed with valid values even if only one
	 * of the PLL is used, see BSpec/Broxton Clocks. Check this here for
	 * paranoia, since BIOS is known to misconfigure PLLs in this way at
	 * times, and since accessing DSI registers with invalid dividers
	 * causes a system hang.
	 */
	val = I915_READ(BXT_DSI_PLL_CTL);
	if (!(val & BXT_DSIA_16X_MASK) || !(val & BXT_DSIC_16X_MASK)) {
		DRM_DEBUG_DRIVER("PLL is enabled with invalid divider settings (%08x)\n",
				 val);
		enabled = false;
	}

	return enabled;
}

225 226
static void bxt_disable_dsi_pll(struct intel_encoder *encoder)
{
227
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
228 229 230 231 232 233 234 235 236 237 238 239
	u32 val;

	DRM_DEBUG_KMS("\n");

	val = I915_READ(BXT_DSI_PLL_ENABLE);
	val &= ~BXT_DSI_PLL_DO_ENABLE;
	I915_WRITE(BXT_DSI_PLL_ENABLE, val);

	/*
	 * PLL lock should deassert within 200us.
	 * Wait up to 1ms before timing out.
	 */
240 241 242 243 244
	if (intel_wait_for_register(dev_priv,
				    BXT_DSI_PLL_ENABLE,
				    BXT_DSI_PLL_LOCKED,
				    0,
				    1))
245 246 247
		DRM_ERROR("Timeout waiting for PLL lock deassertion\n");
}

248
static void assert_bpp_mismatch(enum mipi_dsi_pixel_format fmt, int pipe_bpp)
249
{
250
	int bpp = mipi_dsi_pixel_format_to_bpp(fmt);
251 252

	WARN(bpp != pipe_bpp,
253 254
	     "bpp match assertion failure (expected %d, current %d)\n",
	     bpp, pipe_bpp);
255 256
}

257 258
static u32 vlv_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
			    struct intel_crtc_state *config)
259
{
260
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
261 262 263
	struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
	u32 dsi_clock, pclk;
	u32 pll_ctl, pll_div;
264
	u32 m = 0, p = 0, n;
265
	int refclk = IS_CHERRYVIEW(dev_priv) ? 100000 : 25000;
266 267 268 269
	int i;

	DRM_DEBUG_KMS("\n");

V
Ville Syrjälä 已提交
270
	mutex_lock(&dev_priv->sb_lock);
271 272
	pll_ctl = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
	pll_div = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_DIVIDER);
V
Ville Syrjälä 已提交
273
	mutex_unlock(&dev_priv->sb_lock);
274

275 276 277
	config->dsi_pll.ctrl = pll_ctl & ~DSI_PLL_LOCK;
	config->dsi_pll.div = pll_div;

278 279 280 281
	/* mask out other bits and extract the P1 divisor */
	pll_ctl &= DSI_PLL_P1_POST_DIV_MASK;
	pll_ctl = pll_ctl >> (DSI_PLL_P1_POST_DIV_SHIFT - 2);

282 283 284 285
	/* N1 divisor */
	n = (pll_div & DSI_PLL_N1_DIV_MASK) >> DSI_PLL_N1_DIV_SHIFT;
	n = 1 << n; /* register has log2(N1) */

286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
	/* mask out the other bits and extract the M1 divisor */
	pll_div &= DSI_PLL_M1_DIV_MASK;
	pll_div = pll_div >> DSI_PLL_M1_DIV_SHIFT;

	while (pll_ctl) {
		pll_ctl = pll_ctl >> 1;
		p++;
	}
	p--;

	if (!p) {
		DRM_ERROR("wrong P1 divisor\n");
		return 0;
	}

	for (i = 0; i < ARRAY_SIZE(lfsr_converts); i++) {
		if (lfsr_converts[i] == pll_div)
			break;
	}

	if (i == ARRAY_SIZE(lfsr_converts)) {
		DRM_ERROR("wrong m_seed programmed\n");
		return 0;
	}

	m = i + 62;

313
	dsi_clock = (m * refclk) / (p * n);
314 315 316 317 318 319 320 321

	/* pixel_format and pipe_bpp should agree */
	assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp);

	pclk = DIV_ROUND_CLOSEST(dsi_clock * intel_dsi->lane_count, pipe_bpp);

	return pclk;
}
322

323 324
static u32 bxt_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
			    struct intel_crtc_state *config)
S
Shashank Sharma 已提交
325 326 327 328 329
{
	u32 pclk;
	u32 dsi_clk;
	u32 dsi_ratio;
	struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
330
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
S
Shashank Sharma 已提交
331 332 333 334 335 336 337

	/* Divide by zero */
	if (!pipe_bpp) {
		DRM_ERROR("Invalid BPP(0)\n");
		return 0;
	}

338
	config->dsi_pll.ctrl = I915_READ(BXT_DSI_PLL_CTL);
S
Shashank Sharma 已提交
339

340
	dsi_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
S
Shashank Sharma 已提交
341 342 343 344 345 346 347 348 349 350 351 352

	dsi_clk = (dsi_ratio * BXT_REF_CLOCK_KHZ) / 2;

	/* pixel_format and pipe_bpp should agree */
	assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp);

	pclk = DIV_ROUND_CLOSEST(dsi_clk * intel_dsi->lane_count, pipe_bpp);

	DRM_DEBUG_DRIVER("Calculated pclk=%u\n", pclk);
	return pclk;
}

353 354
u32 intel_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
		       struct intel_crtc_state *config)
355
{
356
	if (IS_GEN9_LP(to_i915(encoder->base.dev)))
357
		return bxt_dsi_get_pclk(encoder, pipe_bpp, config);
358
	else
359
		return vlv_dsi_get_pclk(encoder, pipe_bpp, config);
360 361
}

362
static void vlv_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
363 364
{
	u32 temp;
365
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
366 367 368 369 370 371 372 373 374
	struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);

	temp = I915_READ(MIPI_CTRL(port));
	temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
	I915_WRITE(MIPI_CTRL(port), temp |
			intel_dsi->escape_clk_div <<
			ESCAPE_CLOCK_DIVIDER_SHIFT);
}

375
/* Program BXT Mipi clocks and dividers */
376 377
static void bxt_dsi_program_clocks(struct drm_device *dev, enum port port,
				   const struct intel_crtc_state *config)
378
{
379
	struct drm_i915_private *dev_priv = to_i915(dev);
380 381 382 383 384 385 386 387
	u32 tmp;
	u32 dsi_rate = 0;
	u32 pll_ratio = 0;
	u32 rx_div;
	u32 tx_div;
	u32 rx_div_upper;
	u32 rx_div_lower;
	u32 mipi_8by3_divider;
388 389 390 391

	/* Clear old configurations */
	tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
	tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
392 393 394
	tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port));
	tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port));
	tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port));
395 396

	/* Get the current DSI rate(actual) */
397
	pll_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
398 399
	dsi_rate = (BXT_REF_CLOCK_KHZ * pll_ratio) / 2;

400 401 402 403 404 405 406 407 408 409
	/*
	 * tx clock should be <= 20MHz and the div value must be
	 * subtracted by 1 as per bspec
	 */
	tx_div = DIV_ROUND_UP(dsi_rate, 20000) - 1;
	/*
	 * rx clock should be <= 150MHz and the div value must be
	 * subtracted by 1 as per bspec
	 */
	rx_div = DIV_ROUND_UP(dsi_rate, 150000) - 1;
410 411

	/*
412 413 414
	 * rx divider value needs to be updated in the
	 * two differnt bit fields in the register hence splitting the
	 * rx divider value accordingly
415
	 */
416 417 418
	rx_div_lower = rx_div & RX_DIVIDER_BIT_1_2;
	rx_div_upper = (rx_div & RX_DIVIDER_BIT_3_4) >> 2;

419
	mipi_8by3_divider = 0x2;
420

421 422 423 424
	tmp |= BXT_MIPI_8X_BY3_DIVIDER(port, mipi_8by3_divider);
	tmp |= BXT_MIPI_TX_ESCLK_DIVIDER(port, tx_div);
	tmp |= BXT_MIPI_RX_ESCLK_LOWER_DIVIDER(port, rx_div_lower);
	tmp |= BXT_MIPI_RX_ESCLK_UPPER_DIVIDER(port, rx_div_upper);
425 426 427 428

	I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
}

429 430
static int bxt_compute_dsi_pll(struct intel_encoder *encoder,
			       struct intel_crtc_state *config)
431 432 433 434 435 436
{
	struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
	u8 dsi_ratio;
	u32 dsi_clk;

	dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
437
				    intel_dsi->lane_count);
438 439 440 441 442 443 444 445

	/*
	 * From clock diagram, to get PLL ratio divider, divide double of DSI
	 * link rate (i.e., 2*8x=16x frequency value) by ref clock. Make sure to
	 * round 'up' the result
	 */
	dsi_ratio = DIV_ROUND_UP(dsi_clk * 2, BXT_REF_CLOCK_KHZ);
	if (dsi_ratio < BXT_DSI_PLL_RATIO_MIN ||
446
	    dsi_ratio > BXT_DSI_PLL_RATIO_MAX) {
447
		DRM_ERROR("Cant get a suitable ratio from DSI PLL ratios\n");
448
		return -ECHRNG;
449 450 451 452 453 454 455
	}

	/*
	 * Program DSI ratio and Select MIPIC and MIPIA PLL output as 8x
	 * Spec says both have to be programmed, even if one is not getting
	 * used. Configure MIPI_CLOCK_CTL dividers in modeset
	 */
456
	config->dsi_pll.ctrl = dsi_ratio | BXT_DSIA_16X_BY2 | BXT_DSIC_16X_BY2;
457 458 459 460

	/* As per recommendation from hardware team,
	 * Prog PVD ratio =1 if dsi ratio <= 50
	 */
461 462
	if (dsi_ratio <= 50)
		config->dsi_pll.ctrl |= BXT_DSI_PLL_PVD_RATIO_1;
463

464 465
	return 0;
}
466

467 468
static void bxt_enable_dsi_pll(struct intel_encoder *encoder,
			       const struct intel_crtc_state *config)
469
{
470
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
471 472
	struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
	enum port port;
473 474 475 476 477
	u32 val;

	DRM_DEBUG_KMS("\n");

	/* Configure PLL vales */
478 479
	I915_WRITE(BXT_DSI_PLL_CTL, config->dsi_pll.ctrl);
	POSTING_READ(BXT_DSI_PLL_CTL);
480

481 482
	/* Program TX, RX, Dphy clocks */
	for_each_dsi_port(port, intel_dsi->ports)
483
		bxt_dsi_program_clocks(encoder->base.dev, port, config);
484

485 486 487 488 489 490
	/* Enable DSI PLL */
	val = I915_READ(BXT_DSI_PLL_ENABLE);
	val |= BXT_DSI_PLL_DO_ENABLE;
	I915_WRITE(BXT_DSI_PLL_ENABLE, val);

	/* Timeout and fail if PLL not locked */
491 492 493 494 495
	if (intel_wait_for_register(dev_priv,
				    BXT_DSI_PLL_ENABLE,
				    BXT_DSI_PLL_LOCKED,
				    BXT_DSI_PLL_LOCKED,
				    1)) {
496 497 498 499 500 501 502
		DRM_ERROR("Timed out waiting for DSI PLL to lock\n");
		return;
	}

	DRM_DEBUG_KMS("DSI PLL locked\n");
}

503 504
bool intel_dsi_pll_is_enabled(struct drm_i915_private *dev_priv)
{
505
	if (IS_GEN9_LP(dev_priv))
506 507 508 509 510 511 512
		return bxt_dsi_pll_is_enabled(dev_priv);

	MISSING_CASE(INTEL_DEVID(dev_priv));

	return false;
}

513 514 515
int intel_compute_dsi_pll(struct intel_encoder *encoder,
			  struct intel_crtc_state *config)
{
516
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
517

518
	if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
519
		return vlv_compute_dsi_pll(encoder, config);
520
	else if (IS_GEN9_LP(dev_priv))
521 522 523 524 525 526 527
		return bxt_compute_dsi_pll(encoder, config);

	return -ENODEV;
}

void intel_enable_dsi_pll(struct intel_encoder *encoder,
			  const struct intel_crtc_state *config)
528
{
529
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
530

531
	if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
532
		vlv_enable_dsi_pll(encoder, config);
533
	else if (IS_GEN9_LP(dev_priv))
534
		bxt_enable_dsi_pll(encoder, config);
535
}
536 537 538

void intel_disable_dsi_pll(struct intel_encoder *encoder)
{
539
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
540

541
	if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
542
		vlv_disable_dsi_pll(encoder);
543
	else if (IS_GEN9_LP(dev_priv))
544 545
		bxt_disable_dsi_pll(encoder);
}
546

547
static void bxt_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
548 549 550
{
	u32 tmp;
	struct drm_device *dev = encoder->base.dev;
551
	struct drm_i915_private *dev_priv = to_i915(dev);
552 553 554 555

	/* Clear old configurations */
	tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
	tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
556 557 558
	tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port));
	tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port));
	tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port));
559 560 561 562 563 564
	I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
	I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
}

void intel_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
{
565
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
566

567
	if (IS_GEN9_LP(dev_priv))
568
		bxt_dsi_reset_clocks(encoder, port);
569
	else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
570 571
		vlv_dsi_reset_clocks(encoder, port);
}