intel_panel.c 19.5 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
/*
 * Copyright © 2006-2010 Intel Corporation
 * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
 *
 * 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:
 *	Eric Anholt <eric@anholt.net>
 *      Dave Airlie <airlied@linux.ie>
 *      Jesse Barnes <jesse.barnes@intel.com>
 *      Chris Wilson <chris@chris-wilson.co.uk>
 */

31
#include <linux/kernel.h>
32
#include <linux/pwm.h>
33

34
#include "intel_backlight.h"
35
#include "intel_connector.h"
36
#include "intel_de.h"
37
#include "intel_display_types.h"
38
#include "intel_drrs.h"
39
#include "intel_panel.h"
40

41 42 43 44 45 46 47 48
bool intel_panel_use_ssc(struct drm_i915_private *i915)
{
	if (i915->params.panel_use_ssc >= 0)
		return i915->params.panel_use_ssc != 0;
	return i915->vbt.lvds_use_ssc
		&& !(i915->quirks & QUIRK_LVDS_SSC_DISABLE);
}

49 50 51
const struct drm_display_mode *
intel_panel_preferred_fixed_mode(struct intel_connector *connector)
{
52 53
	return list_first_entry_or_null(&connector->panel.fixed_modes,
					struct drm_display_mode, head);
54 55
}

56 57 58 59
const struct drm_display_mode *
intel_panel_fixed_mode(struct intel_connector *connector,
		       const struct drm_display_mode *mode)
{
60 61 62 63 64 65 66 67 68 69 70 71
	const struct drm_display_mode *fixed_mode, *best_mode = NULL;
	int vrefresh = drm_mode_vrefresh(mode);

	/* pick the fixed_mode that is closest in terms of vrefresh */
	list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) {
		if (!best_mode ||
		    abs(drm_mode_vrefresh(fixed_mode) - vrefresh) <
		    abs(drm_mode_vrefresh(best_mode) - vrefresh))
			best_mode = fixed_mode;
	}

	return best_mode;
72 73 74 75 76 77
}

const struct drm_display_mode *
intel_panel_downclock_mode(struct intel_connector *connector,
			   const struct drm_display_mode *adjusted_mode)
{
78 79 80 81 82 83 84 85 86 87
	const struct drm_display_mode *fixed_mode, *best_mode = NULL;
	int vrefresh = drm_mode_vrefresh(adjusted_mode);

	/* pick the fixed_mode with the lowest refresh rate */
	list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) {
		if (drm_mode_vrefresh(fixed_mode) < vrefresh) {
			vrefresh = drm_mode_vrefresh(fixed_mode);
			best_mode = fixed_mode;
		}
	}
88

89
	return best_mode;
90 91
}

92 93
int intel_panel_get_modes(struct intel_connector *connector)
{
94
	const struct drm_display_mode *fixed_mode;
95 96
	int num_modes = 0;

97
	list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) {
98 99
		struct drm_display_mode *mode;

100
		mode = drm_mode_duplicate(connector->base.dev, fixed_mode);
101 102 103 104 105 106
		if (mode) {
			drm_mode_probed_add(&connector->base, mode);
			num_modes++;
		}
	}

107 108 109
	return num_modes;
}

110 111 112 113
enum drrs_type intel_panel_drrs_type(struct intel_connector *connector)
{
	struct drm_i915_private *i915 = to_i915(connector->base.dev);

114 115
	if (list_empty(&connector->panel.fixed_modes) ||
	    list_is_singular(&connector->panel.fixed_modes))
116 117 118 119 120
		return DRRS_TYPE_NONE;

	return i915->vbt.drrs_type;
}

121 122
int intel_panel_compute_config(struct intel_connector *connector,
			       struct drm_display_mode *adjusted_mode)
123
{
124 125
	const struct drm_display_mode *fixed_mode =
		intel_panel_fixed_mode(connector, adjusted_mode);
126 127 128 129

	if (!fixed_mode)
		return 0;

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
	/*
	 * We don't want to lie too much to the user about the refresh
	 * rate they're going to get. But we have to allow a bit of latitude
	 * for Xorg since it likes to automagically cook up modes with slightly
	 * off refresh rates.
	 */
	if (abs(drm_mode_vrefresh(adjusted_mode) - drm_mode_vrefresh(fixed_mode)) > 1) {
		drm_dbg_kms(connector->base.dev,
			    "[CONNECTOR:%d:%s] Requested mode vrefresh (%d Hz) does not match fixed mode vrefresh (%d Hz)\n",
			    connector->base.base.id, connector->base.name,
			    drm_mode_vrefresh(adjusted_mode), drm_mode_vrefresh(fixed_mode));

		return -EINVAL;
	}

145
	drm_mode_copy(adjusted_mode, fixed_mode);
146 147

	drm_mode_set_crtcinfo(adjusted_mode, 0);
148 149

	return 0;
150 151
}

152 153
static bool is_alt_fixed_mode(const struct drm_display_mode *mode,
			      const struct drm_display_mode *preferred_mode)
154
{
155
	return drm_mode_match(mode, preferred_mode,
156 157 158
			      DRM_MODE_MATCH_TIMINGS |
			      DRM_MODE_MATCH_FLAGS |
			      DRM_MODE_MATCH_3D_FLAGS) &&
159
		mode->clock != preferred_mode->clock;
160 161
}

162
static void intel_panel_add_edid_alt_fixed_modes(struct intel_connector *connector)
J
Jani Nikula 已提交
163
{
164
	struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
165
	const struct drm_display_mode *preferred_mode =
166
		intel_panel_preferred_fixed_mode(connector);
167
	struct drm_display_mode *mode, *next;
J
Jani Nikula 已提交
168

169
	list_for_each_entry_safe(mode, next, &connector->base.probed_modes, head) {
170
		if (!is_alt_fixed_mode(mode, preferred_mode))
171
			continue;
172

173
		drm_dbg_kms(&dev_priv->drm,
174
			    "[CONNECTOR:%d:%s] using alternate EDID fixed mode: " DRM_MODE_FMT "\n",
175 176
			    connector->base.base.id, connector->base.name,
			    DRM_MODE_ARG(mode));
177

178 179
		list_move_tail(&mode->head, &connector->panel.fixed_modes);
	}
J
Jani Nikula 已提交
180 181
}

182
static void intel_panel_add_edid_preferred_mode(struct intel_connector *connector)
183 184
{
	struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
185
	struct drm_display_mode *scan, *fixed_mode = NULL;
186 187

	if (list_empty(&connector->base.probed_modes))
188
		return;
189

190
	/* make sure the preferred mode is first */
191
	list_for_each_entry(scan, &connector->base.probed_modes, head) {
192 193 194 195
		if (scan->type & DRM_MODE_TYPE_PREFERRED) {
			fixed_mode = scan;
			break;
		}
196 197
	}

198
	if (!fixed_mode)
199 200
		fixed_mode = list_first_entry(&connector->base.probed_modes,
					      typeof(*fixed_mode), head);
201

202
	drm_dbg_kms(&dev_priv->drm,
203
		    "[CONNECTOR:%d:%s] using %s EDID fixed mode: " DRM_MODE_FMT "\n",
204
		    connector->base.base.id, connector->base.name,
205
		    fixed_mode->type & DRM_MODE_TYPE_PREFERRED ? "preferred" : "first",
206
		    DRM_MODE_ARG(fixed_mode));
207

208 209 210 211 212 213 214 215 216 217 218 219 220 221
	fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;

	list_move_tail(&fixed_mode->head, &connector->panel.fixed_modes);
}

static void intel_panel_destroy_probed_modes(struct intel_connector *connector)
{
	struct drm_i915_private *i915 = to_i915(connector->base.dev);
	struct drm_display_mode *mode, *next;

	list_for_each_entry_safe(mode, next, &connector->base.probed_modes, head) {
		list_del(&mode->head);
		drm_mode_destroy(&i915->drm, mode);
	}
222 223
}

224 225
void intel_panel_add_edid_fixed_modes(struct intel_connector *connector, bool has_drrs)
{
226
	intel_panel_add_edid_preferred_mode(connector);
227
	if (intel_panel_preferred_fixed_mode(connector) && has_drrs)
228
		intel_panel_add_edid_alt_fixed_modes(connector);
229
	intel_panel_destroy_probed_modes(connector);
230 231
}

232 233 234
static void intel_panel_add_fixed_mode(struct intel_connector *connector,
				       struct drm_display_mode *fixed_mode,
				       const char *type)
235
{
236
	struct drm_i915_private *i915 = to_i915(connector->base.dev);
237 238 239
	struct drm_display_info *info = &connector->base.display_info;

	if (!fixed_mode)
240
		return;
241

242
	fixed_mode->type |= DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
243 244 245 246

	info->width_mm = fixed_mode->width_mm;
	info->height_mm = fixed_mode->height_mm;

247 248 249 250
	drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] using %s fixed mode: " DRM_MODE_FMT "\n",
		    connector->base.base.id, connector->base.name, type,
		    DRM_MODE_ARG(fixed_mode));

251
	list_add_tail(&fixed_mode->head, &connector->panel.fixed_modes);
252 253
}

254
void intel_panel_add_vbt_lfp_fixed_mode(struct intel_connector *connector)
255 256
{
	struct drm_i915_private *i915 = to_i915(connector->base.dev);
257
	const struct drm_display_mode *mode;
258

259 260
	mode = i915->vbt.lfp_lvds_vbt_mode;
	if (!mode)
261
		return;
262

263 264 265
	intel_panel_add_fixed_mode(connector,
				   drm_mode_duplicate(&i915->drm, mode),
				   "VBT LFP");
266 267
}

268
void intel_panel_add_vbt_sdvo_fixed_mode(struct intel_connector *connector)
269 270
{
	struct drm_i915_private *i915 = to_i915(connector->base.dev);
271
	const struct drm_display_mode *mode;
272

273 274
	mode = i915->vbt.sdvo_lvds_vbt_mode;
	if (!mode)
275
		return;
276

277 278 279 280
	intel_panel_add_fixed_mode(connector,
				   drm_mode_duplicate(&i915->drm, mode),
				   "VBT SDVO");
}
281

282 283 284 285 286 287
void intel_panel_add_encoder_fixed_mode(struct intel_connector *connector,
					struct intel_encoder *encoder)
{
	intel_panel_add_fixed_mode(connector,
				   intel_encoder_current_mode(encoder),
				   "current (BIOS)");
288 289
}

290
/* adjusted_mode has been preset to be the panel's fixed mode */
291 292
static int pch_panel_fitting(struct intel_crtc_state *crtc_state,
			     const struct drm_connector_state *conn_state)
293
{
294 295
	const struct drm_display_mode *adjusted_mode =
		&crtc_state->hw.adjusted_mode;
296 297
	int pipe_src_w = drm_rect_width(&crtc_state->pipe_src);
	int pipe_src_h = drm_rect_height(&crtc_state->pipe_src);
298
	int x, y, width, height;
299 300

	/* Native modes don't need fitting */
301 302
	if (adjusted_mode->crtc_hdisplay == pipe_src_w &&
	    adjusted_mode->crtc_vdisplay == pipe_src_h &&
303
	    crtc_state->output_format != INTEL_OUTPUT_FORMAT_YCBCR420)
304
		return 0;
305

306
	switch (conn_state->scaling_mode) {
307
	case DRM_MODE_SCALE_CENTER:
308 309
		width = pipe_src_w;
		height = pipe_src_h;
310 311
		x = (adjusted_mode->crtc_hdisplay - width + 1)/2;
		y = (adjusted_mode->crtc_vdisplay - height + 1)/2;
312 313 314 315 316
		break;

	case DRM_MODE_SCALE_ASPECT:
		/* Scale but preserve the aspect ratio */
		{
317 318
			u32 scaled_width = adjusted_mode->crtc_hdisplay * pipe_src_h;
			u32 scaled_height = pipe_src_w * adjusted_mode->crtc_vdisplay;
319
			if (scaled_width > scaled_height) { /* pillar */
320
				width = scaled_height / pipe_src_h;
321
				if (width & 1)
322
					width++;
323
				x = (adjusted_mode->crtc_hdisplay - width + 1) / 2;
324
				y = 0;
325
				height = adjusted_mode->crtc_vdisplay;
326
			} else if (scaled_width < scaled_height) { /* letter */
327
				height = scaled_width / pipe_src_w;
328 329
				if (height & 1)
				    height++;
330
				y = (adjusted_mode->crtc_vdisplay - height + 1) / 2;
331
				x = 0;
332
				width = adjusted_mode->crtc_hdisplay;
333 334
			} else {
				x = y = 0;
335 336
				width = adjusted_mode->crtc_hdisplay;
				height = adjusted_mode->crtc_vdisplay;
337 338 339 340
			}
		}
		break;

341
	case DRM_MODE_SCALE_NONE:
342 343
		WARN_ON(adjusted_mode->crtc_hdisplay != pipe_src_w);
		WARN_ON(adjusted_mode->crtc_vdisplay != pipe_src_h);
344
		fallthrough;
345 346
	case DRM_MODE_SCALE_FULLSCREEN:
		x = y = 0;
347 348
		width = adjusted_mode->crtc_hdisplay;
		height = adjusted_mode->crtc_vdisplay;
349
		break;
350 351

	default:
352
		MISSING_CASE(conn_state->scaling_mode);
353
		return -EINVAL;
354 355
	}

356
	drm_rect_init(&crtc_state->pch_pfit.dst,
357
		      x, y, width, height);
358
	crtc_state->pch_pfit.enabled = true;
359 360

	return 0;
361
}
362

363
static void
364
centre_horizontally(struct drm_display_mode *adjusted_mode,
365 366 367 368 369
		    int width)
{
	u32 border, sync_pos, blank_width, sync_width;

	/* keep the hsync and hblank widths constant */
370 371
	sync_width = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
	blank_width = adjusted_mode->crtc_hblank_end - adjusted_mode->crtc_hblank_start;
372 373
	sync_pos = (blank_width - sync_width + 1) / 2;

374
	border = (adjusted_mode->crtc_hdisplay - width + 1) / 2;
375 376
	border += border & 1; /* make the border even */

377 378 379
	adjusted_mode->crtc_hdisplay = width;
	adjusted_mode->crtc_hblank_start = width + border;
	adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_hblank_start + blank_width;
380

381 382
	adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hblank_start + sync_pos;
	adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + sync_width;
383 384 385
}

static void
386
centre_vertically(struct drm_display_mode *adjusted_mode,
387 388 389 390 391
		  int height)
{
	u32 border, sync_pos, blank_width, sync_width;

	/* keep the vsync and vblank widths constant */
392 393
	sync_width = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
	blank_width = adjusted_mode->crtc_vblank_end - adjusted_mode->crtc_vblank_start;
394 395
	sync_pos = (blank_width - sync_width + 1) / 2;

396
	border = (adjusted_mode->crtc_vdisplay - height + 1) / 2;
397

398 399 400
	adjusted_mode->crtc_vdisplay = height;
	adjusted_mode->crtc_vblank_start = height + border;
	adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vblank_start + blank_width;
401

402 403
	adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vblank_start + sync_pos;
	adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + sync_width;
404 405
}

406
static u32 panel_fitter_scaling(u32 source, u32 target)
407 408 409 410 411 412 413 414 415 416 417 418
{
	/*
	 * Floating point operation is not supported. So the FACTOR
	 * is defined, which can avoid the floating point computation
	 * when calculating the panel ratio.
	 */
#define ACCURACY 12
#define FACTOR (1 << ACCURACY)
	u32 ratio = source * FACTOR / target;
	return (FACTOR * ratio + FACTOR/2) / FACTOR;
}

419
static void i965_scale_aspect(struct intel_crtc_state *crtc_state,
420 421
			      u32 *pfit_control)
{
422 423
	const struct drm_display_mode *adjusted_mode =
		&crtc_state->hw.adjusted_mode;
424 425 426 427
	int pipe_src_w = drm_rect_width(&crtc_state->pipe_src);
	int pipe_src_h = drm_rect_height(&crtc_state->pipe_src);
	u32 scaled_width = adjusted_mode->crtc_hdisplay * pipe_src_h;
	u32 scaled_height = pipe_src_w * adjusted_mode->crtc_vdisplay;
428 429 430 431 432 433 434 435

	/* 965+ is easy, it does everything in hw */
	if (scaled_width > scaled_height)
		*pfit_control |= PFIT_ENABLE |
			PFIT_SCALING_PILLAR;
	else if (scaled_width < scaled_height)
		*pfit_control |= PFIT_ENABLE |
			PFIT_SCALING_LETTER;
436
	else if (adjusted_mode->crtc_hdisplay != pipe_src_w)
437 438 439
		*pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
}

440
static void i9xx_scale_aspect(struct intel_crtc_state *crtc_state,
441 442 443
			      u32 *pfit_control, u32 *pfit_pgm_ratios,
			      u32 *border)
{
444
	struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
445 446 447 448
	int pipe_src_w = drm_rect_width(&crtc_state->pipe_src);
	int pipe_src_h = drm_rect_height(&crtc_state->pipe_src);
	u32 scaled_width = adjusted_mode->crtc_hdisplay * pipe_src_h;
	u32 scaled_height = pipe_src_w * adjusted_mode->crtc_vdisplay;
449 450 451 452 453 454 455 456 457
	u32 bits;

	/*
	 * For earlier chips we have to calculate the scaling
	 * ratio by hand and program it into the
	 * PFIT_PGM_RATIO register
	 */
	if (scaled_width > scaled_height) { /* pillar */
		centre_horizontally(adjusted_mode,
458
				    scaled_height / pipe_src_h);
459 460

		*border = LVDS_BORDER_ENABLE;
461 462
		if (pipe_src_h != adjusted_mode->crtc_vdisplay) {
			bits = panel_fitter_scaling(pipe_src_h,
463
						    adjusted_mode->crtc_vdisplay);
464 465 466 467 468 469 470 471 472

			*pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
					     bits << PFIT_VERT_SCALE_SHIFT);
			*pfit_control |= (PFIT_ENABLE |
					  VERT_INTERP_BILINEAR |
					  HORIZ_INTERP_BILINEAR);
		}
	} else if (scaled_width < scaled_height) { /* letter */
		centre_vertically(adjusted_mode,
473
				  scaled_width / pipe_src_w);
474 475

		*border = LVDS_BORDER_ENABLE;
476 477
		if (pipe_src_w != adjusted_mode->crtc_hdisplay) {
			bits = panel_fitter_scaling(pipe_src_w,
478
						    adjusted_mode->crtc_hdisplay);
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494

			*pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
					     bits << PFIT_VERT_SCALE_SHIFT);
			*pfit_control |= (PFIT_ENABLE |
					  VERT_INTERP_BILINEAR |
					  HORIZ_INTERP_BILINEAR);
		}
	} else {
		/* Aspects match, Let hw scale both directions */
		*pfit_control |= (PFIT_ENABLE |
				  VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
				  VERT_INTERP_BILINEAR |
				  HORIZ_INTERP_BILINEAR);
	}
}

495 496
static int gmch_panel_fitting(struct intel_crtc_state *crtc_state,
			      const struct drm_connector_state *conn_state)
497
{
498 499
	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
	struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
500
	u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
501
	struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
502 503
	int pipe_src_w = drm_rect_width(&crtc_state->pipe_src);
	int pipe_src_h = drm_rect_height(&crtc_state->pipe_src);
504 505

	/* Native modes don't need fitting */
506 507
	if (adjusted_mode->crtc_hdisplay == pipe_src_w &&
	    adjusted_mode->crtc_vdisplay == pipe_src_h)
508 509
		goto out;

510
	switch (conn_state->scaling_mode) {
511 512 513 514 515
	case DRM_MODE_SCALE_CENTER:
		/*
		 * For centered modes, we have to calculate border widths &
		 * heights and modify the values programmed into the CRTC.
		 */
516 517
		centre_horizontally(adjusted_mode, pipe_src_w);
		centre_vertically(adjusted_mode, pipe_src_h);
518 519 520 521
		border = LVDS_BORDER_ENABLE;
		break;
	case DRM_MODE_SCALE_ASPECT:
		/* Scale but preserve the aspect ratio */
522
		if (DISPLAY_VER(dev_priv) >= 4)
523
			i965_scale_aspect(crtc_state, &pfit_control);
524
		else
525
			i9xx_scale_aspect(crtc_state, &pfit_control,
526
					  &pfit_pgm_ratios, &border);
527 528 529 530 531 532
		break;
	case DRM_MODE_SCALE_FULLSCREEN:
		/*
		 * Full scaling, even if it changes the aspect ratio.
		 * Fortunately this is all done for us in hw.
		 */
533 534
		if (pipe_src_h != adjusted_mode->crtc_vdisplay ||
		    pipe_src_w != adjusted_mode->crtc_hdisplay) {
535
			pfit_control |= PFIT_ENABLE;
536
			if (DISPLAY_VER(dev_priv) >= 4)
537 538 539 540 541 542 543 544
				pfit_control |= PFIT_SCALING_AUTO;
			else
				pfit_control |= (VERT_AUTO_SCALE |
						 VERT_INTERP_BILINEAR |
						 HORIZ_AUTO_SCALE |
						 HORIZ_INTERP_BILINEAR);
		}
		break;
545
	default:
546
		MISSING_CASE(conn_state->scaling_mode);
547
		return -EINVAL;
548 549 550 551
	}

	/* 965+ wants fuzzy fitting */
	/* FIXME: handle multiple panels by failing gracefully */
552
	if (DISPLAY_VER(dev_priv) >= 4)
553
		pfit_control |= PFIT_PIPE(crtc->pipe) | PFIT_FILTER_FUZZY;
554 555 556 557 558 559 560

out:
	if ((pfit_control & PFIT_ENABLE) == 0) {
		pfit_control = 0;
		pfit_pgm_ratios = 0;
	}

561
	/* Make sure pre-965 set dither correctly for 18bpp panels. */
562
	if (DISPLAY_VER(dev_priv) < 4 && crtc_state->pipe_bpp == 18)
563 564
		pfit_control |= PANEL_8TO6_DITHER_ENABLE;

565 566 567
	crtc_state->gmch_pfit.control = pfit_control;
	crtc_state->gmch_pfit.pgm_ratios = pfit_pgm_ratios;
	crtc_state->gmch_pfit.lvds_border_bits = border;
568 569

	return 0;
570 571
}

572 573 574 575 576 577 578 579 580 581 582 583
int intel_panel_fitting(struct intel_crtc_state *crtc_state,
			const struct drm_connector_state *conn_state)
{
	struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
	struct drm_i915_private *i915 = to_i915(crtc->base.dev);

	if (HAS_GMCH(i915))
		return gmch_panel_fitting(crtc_state, conn_state);
	else
		return pch_panel_fitting(crtc_state, conn_state);
}

584 585 586 587 588 589 590 591 592 593 594
enum drm_connector_status
intel_panel_detect(struct drm_connector *connector, bool force)
{
	struct drm_i915_private *i915 = to_i915(connector->dev);

	if (!INTEL_DISPLAY_ENABLED(i915))
		return connector_status_disconnected;

	return connector_status_connected;
}

595 596 597 598
enum drm_mode_status
intel_panel_mode_valid(struct intel_connector *connector,
		       const struct drm_display_mode *mode)
{
599 600
	const struct drm_display_mode *fixed_mode =
		intel_panel_fixed_mode(connector, mode);
601 602 603 604 605 606 607 608 609 610

	if (!fixed_mode)
		return MODE_OK;

	if (mode->hdisplay != fixed_mode->hdisplay)
		return MODE_PANEL;

	if (mode->vdisplay != fixed_mode->vdisplay)
		return MODE_PANEL;

611 612 613
	if (drm_mode_vrefresh(mode) != drm_mode_vrefresh(fixed_mode))
		return MODE_PANEL;

614 615 616
	return MODE_OK;
}

617
int intel_panel_init(struct intel_connector *connector)
618
{
619 620
	struct intel_panel *panel = &connector->panel;

621
	intel_backlight_init_funcs(panel);
622

623 624 625 626 627
	drm_dbg_kms(connector->base.dev,
		    "[CONNECTOR:%d:%s] DRRS type: %s\n",
		    connector->base.base.id, connector->base.name,
		    intel_drrs_type_str(intel_panel_drrs_type(connector)));

628 629 630
	return 0;
}

631
void intel_panel_fini(struct intel_connector *connector)
632
{
633
	struct intel_panel *panel = &connector->panel;
634
	struct drm_display_mode *fixed_mode, *next;
635

636
	intel_backlight_destroy(panel);
637

638 639
	list_for_each_entry_safe(fixed_mode, next, &panel->fixed_modes, head) {
		list_del(&fixed_mode->head);
640
		drm_mode_destroy(connector->base.dev, fixed_mode);
641
	}
642
}