intel_panel.c 19.7 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
	struct drm_i915_private *i915 = to_i915(connector->base.dev);
79
	const struct drm_display_mode *fixed_mode, *best_mode = NULL;
80 81
	int min_vrefresh = i915->vbt.seamless_drrs_min_refresh_rate;
	int max_vrefresh = drm_mode_vrefresh(adjusted_mode);
82 83 84

	/* pick the fixed_mode with the lowest refresh rate */
	list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) {
85 86 87 88
		int vrefresh = drm_mode_vrefresh(fixed_mode);

		if (vrefresh >= min_vrefresh && vrefresh < max_vrefresh) {
			max_vrefresh = vrefresh;
89 90 91
			best_mode = fixed_mode;
		}
	}
92

93
	return best_mode;
94 95
}

96 97
int intel_panel_get_modes(struct intel_connector *connector)
{
98
	const struct drm_display_mode *fixed_mode;
99 100
	int num_modes = 0;

101
	list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) {
102 103
		struct drm_display_mode *mode;

104
		mode = drm_mode_duplicate(connector->base.dev, fixed_mode);
105 106 107 108 109 110
		if (mode) {
			drm_mode_probed_add(&connector->base, mode);
			num_modes++;
		}
	}

111 112 113
	return num_modes;
}

114 115 116 117
enum drrs_type intel_panel_drrs_type(struct intel_connector *connector)
{
	struct drm_i915_private *i915 = to_i915(connector->base.dev);

118 119
	if (list_empty(&connector->panel.fixed_modes) ||
	    list_is_singular(&connector->panel.fixed_modes))
120 121 122 123 124
		return DRRS_TYPE_NONE;

	return i915->vbt.drrs_type;
}

125 126
int intel_panel_compute_config(struct intel_connector *connector,
			       struct drm_display_mode *adjusted_mode)
127
{
128 129
	const struct drm_display_mode *fixed_mode =
		intel_panel_fixed_mode(connector, adjusted_mode);
130 131 132 133

	if (!fixed_mode)
		return 0;

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
	/*
	 * 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;
	}

149
	drm_mode_copy(adjusted_mode, fixed_mode);
150 151

	drm_mode_set_crtcinfo(adjusted_mode, 0);
152 153

	return 0;
154 155
}

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

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

173
	list_for_each_entry_safe(mode, next, &connector->base.probed_modes, head) {
174
		if (!is_alt_fixed_mode(mode, preferred_mode))
175
			continue;
176

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

182 183
		list_move_tail(&mode->head, &connector->panel.fixed_modes);
	}
J
Jani Nikula 已提交
184 185
}

186
static void intel_panel_add_edid_preferred_mode(struct intel_connector *connector)
187 188
{
	struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
189
	struct drm_display_mode *scan, *fixed_mode = NULL;
190 191

	if (list_empty(&connector->base.probed_modes))
192
		return;
193

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

202
	if (!fixed_mode)
203 204
		fixed_mode = list_first_entry(&connector->base.probed_modes,
					      typeof(*fixed_mode), head);
205

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

212 213 214 215 216 217 218 219 220 221 222 223 224 225
	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);
	}
226 227
}

228 229
void intel_panel_add_edid_fixed_modes(struct intel_connector *connector, bool has_drrs)
{
230
	intel_panel_add_edid_preferred_mode(connector);
231
	if (intel_panel_preferred_fixed_mode(connector) && has_drrs)
232
		intel_panel_add_edid_alt_fixed_modes(connector);
233
	intel_panel_destroy_probed_modes(connector);
234 235
}

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

	if (!fixed_mode)
244
		return;
245

246
	fixed_mode->type |= DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
247 248 249 250

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

251 252 253 254
	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));

255
	list_add_tail(&fixed_mode->head, &connector->panel.fixed_modes);
256 257
}

258
void intel_panel_add_vbt_lfp_fixed_mode(struct intel_connector *connector)
259 260
{
	struct drm_i915_private *i915 = to_i915(connector->base.dev);
261
	const struct drm_display_mode *mode;
262

263 264
	mode = i915->vbt.lfp_lvds_vbt_mode;
	if (!mode)
265
		return;
266

267 268 269
	intel_panel_add_fixed_mode(connector,
				   drm_mode_duplicate(&i915->drm, mode),
				   "VBT LFP");
270 271
}

272
void intel_panel_add_vbt_sdvo_fixed_mode(struct intel_connector *connector)
273 274
{
	struct drm_i915_private *i915 = to_i915(connector->base.dev);
275
	const struct drm_display_mode *mode;
276

277 278
	mode = i915->vbt.sdvo_lvds_vbt_mode;
	if (!mode)
279
		return;
280

281 282 283 284
	intel_panel_add_fixed_mode(connector,
				   drm_mode_duplicate(&i915->drm, mode),
				   "VBT SDVO");
}
285

286 287 288 289 290 291
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)");
292 293
}

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

	/* Native modes don't need fitting */
305 306
	if (adjusted_mode->crtc_hdisplay == pipe_src_w &&
	    adjusted_mode->crtc_vdisplay == pipe_src_h &&
307
	    crtc_state->output_format != INTEL_OUTPUT_FORMAT_YCBCR420)
308
		return 0;
309

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

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

345
	case DRM_MODE_SCALE_NONE:
346 347
		WARN_ON(adjusted_mode->crtc_hdisplay != pipe_src_w);
		WARN_ON(adjusted_mode->crtc_vdisplay != pipe_src_h);
348
		fallthrough;
349 350
	case DRM_MODE_SCALE_FULLSCREEN:
		x = y = 0;
351 352
		width = adjusted_mode->crtc_hdisplay;
		height = adjusted_mode->crtc_vdisplay;
353
		break;
354 355

	default:
356
		MISSING_CASE(conn_state->scaling_mode);
357
		return -EINVAL;
358 359
	}

360
	drm_rect_init(&crtc_state->pch_pfit.dst,
361
		      x, y, width, height);
362
	crtc_state->pch_pfit.enabled = true;
363 364

	return 0;
365
}
366

367
static void
368
centre_horizontally(struct drm_display_mode *adjusted_mode,
369 370 371 372 373
		    int width)
{
	u32 border, sync_pos, blank_width, sync_width;

	/* keep the hsync and hblank widths constant */
374 375
	sync_width = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
	blank_width = adjusted_mode->crtc_hblank_end - adjusted_mode->crtc_hblank_start;
376 377
	sync_pos = (blank_width - sync_width + 1) / 2;

378
	border = (adjusted_mode->crtc_hdisplay - width + 1) / 2;
379 380
	border += border & 1; /* make the border even */

381 382 383
	adjusted_mode->crtc_hdisplay = width;
	adjusted_mode->crtc_hblank_start = width + border;
	adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_hblank_start + blank_width;
384

385 386
	adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hblank_start + sync_pos;
	adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + sync_width;
387 388 389
}

static void
390
centre_vertically(struct drm_display_mode *adjusted_mode,
391 392 393 394 395
		  int height)
{
	u32 border, sync_pos, blank_width, sync_width;

	/* keep the vsync and vblank widths constant */
396 397
	sync_width = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
	blank_width = adjusted_mode->crtc_vblank_end - adjusted_mode->crtc_vblank_start;
398 399
	sync_pos = (blank_width - sync_width + 1) / 2;

400
	border = (adjusted_mode->crtc_vdisplay - height + 1) / 2;
401

402 403 404
	adjusted_mode->crtc_vdisplay = height;
	adjusted_mode->crtc_vblank_start = height + border;
	adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vblank_start + blank_width;
405

406 407
	adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vblank_start + sync_pos;
	adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + sync_width;
408 409
}

410
static u32 panel_fitter_scaling(u32 source, u32 target)
411 412 413 414 415 416 417 418 419 420 421 422
{
	/*
	 * 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;
}

423
static void i965_scale_aspect(struct intel_crtc_state *crtc_state,
424 425
			      u32 *pfit_control)
{
426 427
	const struct drm_display_mode *adjusted_mode =
		&crtc_state->hw.adjusted_mode;
428 429 430 431
	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;
432 433 434 435 436 437 438 439

	/* 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;
440
	else if (adjusted_mode->crtc_hdisplay != pipe_src_w)
441 442 443
		*pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
}

444
static void i9xx_scale_aspect(struct intel_crtc_state *crtc_state,
445 446 447
			      u32 *pfit_control, u32 *pfit_pgm_ratios,
			      u32 *border)
{
448
	struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
449 450 451 452
	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;
453 454 455 456 457 458 459 460 461
	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,
462
				    scaled_height / pipe_src_h);
463 464

		*border = LVDS_BORDER_ENABLE;
465 466
		if (pipe_src_h != adjusted_mode->crtc_vdisplay) {
			bits = panel_fitter_scaling(pipe_src_h,
467
						    adjusted_mode->crtc_vdisplay);
468 469 470 471 472 473 474 475 476

			*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,
477
				  scaled_width / pipe_src_w);
478 479

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

			*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);
	}
}

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

	/* Native modes don't need fitting */
510 511
	if (adjusted_mode->crtc_hdisplay == pipe_src_w &&
	    adjusted_mode->crtc_vdisplay == pipe_src_h)
512 513
		goto out;

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

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

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

565
	/* Make sure pre-965 set dither correctly for 18bpp panels. */
566
	if (DISPLAY_VER(dev_priv) < 4 && crtc_state->pipe_bpp == 18)
567 568
		pfit_control |= PANEL_8TO6_DITHER_ENABLE;

569 570 571
	crtc_state->gmch_pfit.control = pfit_control;
	crtc_state->gmch_pfit.pgm_ratios = pfit_pgm_ratios;
	crtc_state->gmch_pfit.lvds_border_bits = border;
572 573

	return 0;
574 575
}

576 577 578 579 580 581 582 583 584 585 586 587
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);
}

588 589 590 591 592 593 594 595 596 597 598
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;
}

599 600 601 602
enum drm_mode_status
intel_panel_mode_valid(struct intel_connector *connector,
		       const struct drm_display_mode *mode)
{
603 604
	const struct drm_display_mode *fixed_mode =
		intel_panel_fixed_mode(connector, mode);
605 606 607 608 609 610 611 612 613 614

	if (!fixed_mode)
		return MODE_OK;

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

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

615 616 617
	if (drm_mode_vrefresh(mode) != drm_mode_vrefresh(fixed_mode))
		return MODE_PANEL;

618 619 620
	return MODE_OK;
}

621
int intel_panel_init(struct intel_connector *connector)
622
{
623 624
	struct intel_panel *panel = &connector->panel;

625
	intel_backlight_init_funcs(panel);
626

627 628 629 630 631
	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)));

632 633 634
	return 0;
}

635
void intel_panel_fini(struct intel_connector *connector)
636
{
637
	struct intel_panel *panel = &connector->panel;
638
	struct drm_display_mode *fixed_mode, *next;
639

640
	intel_backlight_destroy(panel);
641

642 643
	list_for_each_entry_safe(fixed_mode, next, &panel->fixed_modes, head) {
		list_del(&fixed_mode->head);
644
		drm_mode_destroy(connector->base.dev, fixed_mode);
645
	}
646
}