xref: /dflybsd-src/sys/dev/drm/i915/intel_lvds.c (revision 31c068aaf635ad9fa72dbc4c65b32d890ff7544d)
1 /*
2  * Copyright © 2006-2007 Intel Corporation
3  * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *	Eric Anholt <eric@anholt.net>
26  *      Dave Airlie <airlied@linux.ie>
27  *      Jesse Barnes <jesse.barnes@intel.com>
28  */
29 
30 #include <linux/i2c.h>
31 #include <drm/drmP.h>
32 #include <drm/drm_crtc.h>
33 #include <drm/drm_edid.h>
34 #include "intel_drv.h"
35 #include <drm/i915_drm.h>
36 #include "i915_drv.h"
37 
38 /* Private structure for the integrated LVDS support */
39 struct intel_lvds_connector {
40 	struct intel_connector base;
41 
42 #if 0
43 	struct notifier_block lid_notifier;
44 #endif
45 };
46 
47 struct intel_lvds_encoder {
48 	struct intel_encoder base;
49 
50 	u32 pfit_control;
51 	u32 pfit_pgm_ratios;
52 	bool is_dual_link;
53 	u32 reg;
54 
55 	struct intel_lvds_connector *attached_connector;
56 };
57 
58 static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
59 {
60 	return container_of(encoder, struct intel_lvds_encoder, base.base);
61 }
62 
63 static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
64 {
65 	return container_of(connector, struct intel_lvds_connector, base.base);
66 }
67 
68 static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
69 				    enum i915_pipe *pipe)
70 {
71 	struct drm_device *dev = encoder->base.dev;
72 	struct drm_i915_private *dev_priv = dev->dev_private;
73 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
74 	u32 tmp;
75 
76 	tmp = I915_READ(lvds_encoder->reg);
77 
78 	if (!(tmp & LVDS_PORT_EN))
79 		return false;
80 
81 	if (HAS_PCH_CPT(dev))
82 		*pipe = PORT_TO_PIPE_CPT(tmp);
83 	else
84 		*pipe = PORT_TO_PIPE(tmp);
85 
86 	return true;
87 }
88 
89 /* The LVDS pin pair needs to be on before the DPLLs are enabled.
90  * This is an exception to the general rule that mode_set doesn't turn
91  * things on.
92  */
93 static void intel_pre_pll_enable_lvds(struct intel_encoder *encoder)
94 {
95 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
96 	struct drm_device *dev = encoder->base.dev;
97 	struct drm_i915_private *dev_priv = dev->dev_private;
98 	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
99 	struct drm_display_mode *fixed_mode =
100 		lvds_encoder->attached_connector->base.panel.fixed_mode;
101 	int pipe = intel_crtc->pipe;
102 	u32 temp;
103 
104 	temp = I915_READ(lvds_encoder->reg);
105 	temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
106 
107 	if (HAS_PCH_CPT(dev)) {
108 		temp &= ~PORT_TRANS_SEL_MASK;
109 		temp |= PORT_TRANS_SEL_CPT(pipe);
110 	} else {
111 		if (pipe == 1) {
112 			temp |= LVDS_PIPEB_SELECT;
113 		} else {
114 			temp &= ~LVDS_PIPEB_SELECT;
115 		}
116 	}
117 
118 	/* set the corresponsding LVDS_BORDER bit */
119 	temp |= dev_priv->lvds_border_bits;
120 	/* Set the B0-B3 data pairs corresponding to whether we're going to
121 	 * set the DPLLs for dual-channel mode or not.
122 	 */
123 	if (lvds_encoder->is_dual_link)
124 		temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
125 	else
126 		temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
127 
128 	/* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
129 	 * appropriately here, but we need to look more thoroughly into how
130 	 * panels behave in the two modes.
131 	 */
132 
133 	/* Set the dithering flag on LVDS as needed, note that there is no
134 	 * special lvds dither control bit on pch-split platforms, dithering is
135 	 * only controlled through the PIPECONF reg. */
136 	if (INTEL_INFO(dev)->gen == 4) {
137 		if (dev_priv->lvds_dither)
138 			temp |= LVDS_ENABLE_DITHER;
139 		else
140 			temp &= ~LVDS_ENABLE_DITHER;
141 	}
142 	temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
143 	if (fixed_mode->flags & DRM_MODE_FLAG_NHSYNC)
144 		temp |= LVDS_HSYNC_POLARITY;
145 	if (fixed_mode->flags & DRM_MODE_FLAG_NVSYNC)
146 		temp |= LVDS_VSYNC_POLARITY;
147 
148 	I915_WRITE(lvds_encoder->reg, temp);
149 }
150 
151 static void intel_pre_enable_lvds(struct intel_encoder *encoder)
152 {
153 	struct drm_device *dev = encoder->base.dev;
154 	struct intel_lvds_encoder *enc = to_lvds_encoder(&encoder->base);
155 	struct drm_i915_private *dev_priv = dev->dev_private;
156 
157 	if (HAS_PCH_SPLIT(dev) || !enc->pfit_control)
158 		return;
159 
160 	/*
161 	 * Enable automatic panel scaling so that non-native modes
162 	 * fill the screen.  The panel fitter should only be
163 	 * adjusted whilst the pipe is disabled, according to
164 	 * register description and PRM.
165 	 */
166 	DRM_DEBUG_KMS("applying panel-fitter: %x, %x\n",
167 		      enc->pfit_control,
168 		      enc->pfit_pgm_ratios);
169 
170 	I915_WRITE(PFIT_PGM_RATIOS, enc->pfit_pgm_ratios);
171 	I915_WRITE(PFIT_CONTROL, enc->pfit_control);
172 }
173 
174 /**
175  * Sets the power state for the panel.
176  */
177 static void intel_enable_lvds(struct intel_encoder *encoder)
178 {
179 	struct drm_device *dev = encoder->base.dev;
180 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
181 	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
182 	struct drm_i915_private *dev_priv = dev->dev_private;
183 	u32 ctl_reg, stat_reg;
184 
185 	if (HAS_PCH_SPLIT(dev)) {
186 		ctl_reg = PCH_PP_CONTROL;
187 		stat_reg = PCH_PP_STATUS;
188 	} else {
189 		ctl_reg = PP_CONTROL;
190 		stat_reg = PP_STATUS;
191 	}
192 
193 	I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
194 
195 	I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
196 	POSTING_READ(lvds_encoder->reg);
197 	if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
198 		DRM_ERROR("timed out waiting for panel to power on\n");
199 
200 	intel_panel_enable_backlight(dev, intel_crtc->pipe);
201 }
202 
203 static void intel_disable_lvds(struct intel_encoder *encoder)
204 {
205 	struct drm_device *dev = encoder->base.dev;
206 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
207 	struct drm_i915_private *dev_priv = dev->dev_private;
208 	u32 ctl_reg, stat_reg;
209 
210 	if (HAS_PCH_SPLIT(dev)) {
211 		ctl_reg = PCH_PP_CONTROL;
212 		stat_reg = PCH_PP_STATUS;
213 	} else {
214 		ctl_reg = PP_CONTROL;
215 		stat_reg = PP_STATUS;
216 	}
217 
218 	intel_panel_disable_backlight(dev);
219 
220 	I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
221 	if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
222 		DRM_ERROR("timed out waiting for panel to power off\n");
223 
224 	I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
225 	POSTING_READ(lvds_encoder->reg);
226 }
227 
228 static int intel_lvds_mode_valid(struct drm_connector *connector,
229 				 struct drm_display_mode *mode)
230 {
231 	struct intel_connector *intel_connector = to_intel_connector(connector);
232 	struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
233 
234 	if (mode->hdisplay > fixed_mode->hdisplay)
235 		return MODE_PANEL;
236 	if (mode->vdisplay > fixed_mode->vdisplay)
237 		return MODE_PANEL;
238 
239 	return MODE_OK;
240 }
241 
242 static void
243 centre_horizontally(struct drm_display_mode *mode,
244 		    int width)
245 {
246 	u32 border, sync_pos, blank_width, sync_width;
247 
248 	/* keep the hsync and hblank widths constant */
249 	sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start;
250 	blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start;
251 	sync_pos = (blank_width - sync_width + 1) / 2;
252 
253 	border = (mode->hdisplay - width + 1) / 2;
254 	border += border & 1; /* make the border even */
255 
256 	mode->crtc_hdisplay = width;
257 	mode->crtc_hblank_start = width + border;
258 	mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width;
259 
260 	mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;
261 	mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;
262 
263 	mode->private_flags |= INTEL_MODE_CRTC_TIMINGS_SET;
264 }
265 
266 static void
267 centre_vertically(struct drm_display_mode *mode,
268 		  int height)
269 {
270 	u32 border, sync_pos, blank_width, sync_width;
271 
272 	/* keep the vsync and vblank widths constant */
273 	sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start;
274 	blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start;
275 	sync_pos = (blank_width - sync_width + 1) / 2;
276 
277 	border = (mode->vdisplay - height + 1) / 2;
278 
279 	mode->crtc_vdisplay = height;
280 	mode->crtc_vblank_start = height + border;
281 	mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;
282 
283 	mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
284 	mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
285 
286 	mode->private_flags |= INTEL_MODE_CRTC_TIMINGS_SET;
287 }
288 
289 static inline u32 panel_fitter_scaling(u32 source, u32 target)
290 {
291 	/*
292 	 * Floating point operation is not supported. So the FACTOR
293 	 * is defined, which can avoid the floating point computation
294 	 * when calculating the panel ratio.
295 	 */
296 #define ACCURACY 12
297 #define FACTOR (1 << ACCURACY)
298 	u32 ratio = source * FACTOR / target;
299 	return (FACTOR * ratio + FACTOR/2) / FACTOR;
300 }
301 
302 static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
303 				  const struct drm_display_mode *mode,
304 				  struct drm_display_mode *adjusted_mode)
305 {
306 	struct drm_device *dev = encoder->dev;
307 	struct drm_i915_private *dev_priv = dev->dev_private;
308 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(encoder);
309 	struct intel_connector *intel_connector =
310 		&lvds_encoder->attached_connector->base;
311 	struct intel_crtc *intel_crtc = lvds_encoder->base.new_crtc;
312 	u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
313 	int pipe;
314 
315 	/* Should never happen!! */
316 	if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
317 		DRM_ERROR("Can't support LVDS on pipe A\n");
318 		return false;
319 	}
320 
321 	if (intel_encoder_check_is_cloned(&lvds_encoder->base))
322 		return false;
323 
324 	/*
325 	 * We have timings from the BIOS for the panel, put them in
326 	 * to the adjusted mode.  The CRTC will be set up for this mode,
327 	 * with the panel scaling set up to source from the H/VDisplay
328 	 * of the original mode.
329 	 */
330 	intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
331 			       adjusted_mode);
332 
333 	if (HAS_PCH_SPLIT(dev)) {
334 		intel_pch_panel_fitting(dev,
335 					intel_connector->panel.fitting_mode,
336 					mode, adjusted_mode);
337 		return true;
338 	}
339 
340 	/* Native modes don't need fitting */
341 	if (adjusted_mode->hdisplay == mode->hdisplay &&
342 	    adjusted_mode->vdisplay == mode->vdisplay)
343 		goto out;
344 
345 	/* 965+ wants fuzzy fitting */
346 	if (INTEL_INFO(dev)->gen >= 4)
347 		pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) |
348 				 PFIT_FILTER_FUZZY);
349 
350 	/*
351 	 * Enable automatic panel scaling for non-native modes so that they fill
352 	 * the screen.  Should be enabled before the pipe is enabled, according
353 	 * to register description and PRM.
354 	 * Change the value here to see the borders for debugging
355 	 */
356 	for_each_pipe(pipe)
357 		I915_WRITE(BCLRPAT(pipe), 0);
358 
359 	drm_mode_set_crtcinfo(adjusted_mode, 0);
360 
361 	switch (intel_connector->panel.fitting_mode) {
362 	case DRM_MODE_SCALE_CENTER:
363 		/*
364 		 * For centered modes, we have to calculate border widths &
365 		 * heights and modify the values programmed into the CRTC.
366 		 */
367 		centre_horizontally(adjusted_mode, mode->hdisplay);
368 		centre_vertically(adjusted_mode, mode->vdisplay);
369 		border = LVDS_BORDER_ENABLE;
370 		break;
371 
372 	case DRM_MODE_SCALE_ASPECT:
373 		/* Scale but preserve the aspect ratio */
374 		if (INTEL_INFO(dev)->gen >= 4) {
375 			u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
376 			u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
377 
378 			/* 965+ is easy, it does everything in hw */
379 			if (scaled_width > scaled_height)
380 				pfit_control |= PFIT_ENABLE | PFIT_SCALING_PILLAR;
381 			else if (scaled_width < scaled_height)
382 				pfit_control |= PFIT_ENABLE | PFIT_SCALING_LETTER;
383 			else if (adjusted_mode->hdisplay != mode->hdisplay)
384 				pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
385 		} else {
386 			u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
387 			u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
388 			/*
389 			 * For earlier chips we have to calculate the scaling
390 			 * ratio by hand and program it into the
391 			 * PFIT_PGM_RATIO register
392 			 */
393 			if (scaled_width > scaled_height) { /* pillar */
394 				centre_horizontally(adjusted_mode, scaled_height / mode->vdisplay);
395 
396 				border = LVDS_BORDER_ENABLE;
397 				if (mode->vdisplay != adjusted_mode->vdisplay) {
398 					u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay);
399 					pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
400 							    bits << PFIT_VERT_SCALE_SHIFT);
401 					pfit_control |= (PFIT_ENABLE |
402 							 VERT_INTERP_BILINEAR |
403 							 HORIZ_INTERP_BILINEAR);
404 				}
405 			} else if (scaled_width < scaled_height) { /* letter */
406 				centre_vertically(adjusted_mode, scaled_width / mode->hdisplay);
407 
408 				border = LVDS_BORDER_ENABLE;
409 				if (mode->hdisplay != adjusted_mode->hdisplay) {
410 					u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay);
411 					pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
412 							    bits << PFIT_VERT_SCALE_SHIFT);
413 					pfit_control |= (PFIT_ENABLE |
414 							 VERT_INTERP_BILINEAR |
415 							 HORIZ_INTERP_BILINEAR);
416 				}
417 			} else
418 				/* Aspects match, Let hw scale both directions */
419 				pfit_control |= (PFIT_ENABLE |
420 						 VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
421 						 VERT_INTERP_BILINEAR |
422 						 HORIZ_INTERP_BILINEAR);
423 		}
424 		break;
425 
426 	case DRM_MODE_SCALE_FULLSCREEN:
427 		/*
428 		 * Full scaling, even if it changes the aspect ratio.
429 		 * Fortunately this is all done for us in hw.
430 		 */
431 		if (mode->vdisplay != adjusted_mode->vdisplay ||
432 		    mode->hdisplay != adjusted_mode->hdisplay) {
433 			pfit_control |= PFIT_ENABLE;
434 			if (INTEL_INFO(dev)->gen >= 4)
435 				pfit_control |= PFIT_SCALING_AUTO;
436 			else
437 				pfit_control |= (VERT_AUTO_SCALE |
438 						 VERT_INTERP_BILINEAR |
439 						 HORIZ_AUTO_SCALE |
440 						 HORIZ_INTERP_BILINEAR);
441 		}
442 		break;
443 
444 	default:
445 		break;
446 	}
447 
448 out:
449 	/* If not enabling scaling, be consistent and always use 0. */
450 	if ((pfit_control & PFIT_ENABLE) == 0) {
451 		pfit_control = 0;
452 		pfit_pgm_ratios = 0;
453 	}
454 
455 	/* Make sure pre-965 set dither correctly */
456 	if (INTEL_INFO(dev)->gen < 4 && dev_priv->lvds_dither)
457 		pfit_control |= PANEL_8TO6_DITHER_ENABLE;
458 
459 	if (pfit_control != lvds_encoder->pfit_control ||
460 	    pfit_pgm_ratios != lvds_encoder->pfit_pgm_ratios) {
461 		lvds_encoder->pfit_control = pfit_control;
462 		lvds_encoder->pfit_pgm_ratios = pfit_pgm_ratios;
463 	}
464 	dev_priv->lvds_border_bits = border;
465 
466 	/*
467 	 * XXX: It would be nice to support lower refresh rates on the
468 	 * panels to reduce power consumption, and perhaps match the
469 	 * user's requested refresh rate.
470 	 */
471 
472 	return true;
473 }
474 
475 static void intel_lvds_mode_set(struct drm_encoder *encoder,
476 				struct drm_display_mode *mode,
477 				struct drm_display_mode *adjusted_mode)
478 {
479 	/*
480 	 * The LVDS pin pair will already have been turned on in the
481 	 * intel_crtc_mode_set since it has a large impact on the DPLL
482 	 * settings.
483 	 */
484 }
485 
486 /**
487  * Detect the LVDS connection.
488  *
489  * Since LVDS doesn't have hotlug, we use the lid as a proxy.  Open means
490  * connected and closed means disconnected.  We also send hotplug events as
491  * needed, using lid status notification from the input layer.
492  */
493 static enum drm_connector_status
494 intel_lvds_detect(struct drm_connector *connector, bool force)
495 {
496 	struct drm_device *dev = connector->dev;
497 	enum drm_connector_status status;
498 
499 	status = intel_panel_detect(dev);
500 	if (status != connector_status_unknown)
501 		return status;
502 
503 	return connector_status_connected;
504 }
505 
506 /**
507  * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
508  */
509 static int intel_lvds_get_modes(struct drm_connector *connector)
510 {
511 	struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
512 	struct drm_device *dev = connector->dev;
513 	struct drm_display_mode *mode;
514 
515 	/* use cached edid if we have one */
516 	if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
517 		return drm_add_edid_modes(connector, lvds_connector->base.edid);
518 
519 	mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
520 	if (mode == NULL)
521 		return 0;
522 
523 	drm_mode_probed_add(connector, mode);
524 	return 1;
525 }
526 
527 static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
528 {
529 	DRM_INFO("Skipping forced modeset for %s\n", id->ident);
530 	return 1;
531 }
532 
533 /* The GPU hangs up on these systems if modeset is performed on LID open */
534 static const struct dmi_system_id intel_no_modeset_on_lid[] = {
535 	{
536 		.callback = intel_no_modeset_on_lid_dmi_callback,
537 		.ident = "Toshiba Tecra A11",
538 		.matches = {
539 			DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
540 			DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
541 		},
542 	},
543 
544 	{ }	/* terminating entry */
545 };
546 
547 #if 0
548 /*
549  * Lid events. Note the use of 'modeset':
550  *  - we set it to MODESET_ON_LID_OPEN on lid close,
551  *    and set it to MODESET_DONE on open
552  *  - we use it as a "only once" bit (ie we ignore
553  *    duplicate events where it was already properly set)
554  *  - the suspend/resume paths will set it to
555  *    MODESET_SUSPENDED and ignore the lid open event,
556  *    because they restore the mode ("lid open").
557  */
558 static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
559 			    void *unused)
560 {
561 	struct intel_lvds_connector *lvds_connector =
562 		container_of(nb, struct intel_lvds_connector, lid_notifier);
563 	struct drm_connector *connector = &lvds_connector->base.base;
564 	struct drm_device *dev = connector->dev;
565 	struct drm_i915_private *dev_priv = dev->dev_private;
566 
567 	if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
568 		return NOTIFY_OK;
569 
570 	mutex_lock(&dev_priv->modeset_restore_lock);
571 	if (dev_priv->modeset_restore == MODESET_SUSPENDED)
572 		goto exit;
573 	/*
574 	 * check and update the status of LVDS connector after receiving
575 	 * the LID nofication event.
576 	 */
577 	connector->status = connector->funcs->detect(connector, false);
578 
579 	/* Don't force modeset on machines where it causes a GPU lockup */
580 	if (dmi_check_system(intel_no_modeset_on_lid))
581 		goto exit;
582 	if (!acpi_lid_open()) {
583 		/* do modeset on next lid open event */
584 		dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
585 		goto exit;
586 	}
587 
588 	if (dev_priv->modeset_restore == MODESET_DONE)
589 		goto exit;
590 
591 	drm_modeset_lock_all(dev);
592 	intel_modeset_setup_hw_state(dev, true);
593 	drm_modeset_unlock_all(dev);
594 
595 	dev_priv->modeset_restore = MODESET_DONE;
596 
597 exit:
598 	mutex_unlock(&dev_priv->modeset_restore_lock);
599 	return NOTIFY_OK;
600 }
601 #endif
602 
603 /**
604  * intel_lvds_destroy - unregister and free LVDS structures
605  * @connector: connector to free
606  *
607  * Unregister the DDC bus for this connector then free the driver private
608  * structure.
609  */
610 static void intel_lvds_destroy(struct drm_connector *connector)
611 {
612 	struct intel_lvds_connector *lvds_connector =
613 		to_lvds_connector(connector);
614 
615 #if 0
616 	if (lvds_connector->lid_notifier.notifier_call)
617 		acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
618 #endif
619 
620 	if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
621 		kfree(lvds_connector->base.edid, M_DRM);
622 
623 	intel_panel_fini(&lvds_connector->base.panel);
624 
625 #if 0
626 	drm_sysfs_connector_remove(connector);
627 #endif
628 	drm_connector_cleanup(connector);
629 	kfree(connector, M_DRM);
630 }
631 
632 static int intel_lvds_set_property(struct drm_connector *connector,
633 				   struct drm_property *property,
634 				   uint64_t value)
635 {
636 	struct intel_connector *intel_connector = to_intel_connector(connector);
637 	struct drm_device *dev = connector->dev;
638 
639 	if (property == dev->mode_config.scaling_mode_property) {
640 		struct drm_crtc *crtc;
641 
642 		if (value == DRM_MODE_SCALE_NONE) {
643 			DRM_DEBUG_KMS("no scaling not supported\n");
644 			return -EINVAL;
645 		}
646 
647 		if (intel_connector->panel.fitting_mode == value) {
648 			/* the LVDS scaling property is not changed */
649 			return 0;
650 		}
651 		intel_connector->panel.fitting_mode = value;
652 
653 		crtc = intel_attached_encoder(connector)->base.crtc;
654 		if (crtc && crtc->enabled) {
655 			/*
656 			 * If the CRTC is enabled, the display will be changed
657 			 * according to the new panel fitting mode.
658 			 */
659 			intel_crtc_restore_mode(crtc);
660 		}
661 	}
662 
663 	return 0;
664 }
665 
666 static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
667 	.mode_fixup = intel_lvds_mode_fixup,
668 	.mode_set = intel_lvds_mode_set,
669 };
670 
671 static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
672 	.get_modes = intel_lvds_get_modes,
673 	.mode_valid = intel_lvds_mode_valid,
674 	.best_encoder = intel_best_encoder,
675 };
676 
677 static const struct drm_connector_funcs intel_lvds_connector_funcs = {
678 	.dpms = intel_connector_dpms,
679 	.detect = intel_lvds_detect,
680 	.fill_modes = drm_helper_probe_single_connector_modes,
681 	.set_property = intel_lvds_set_property,
682 	.destroy = intel_lvds_destroy,
683 };
684 
685 static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
686 	.destroy = intel_encoder_destroy,
687 };
688 
689 static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
690 {
691 	DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
692 	return 1;
693 }
694 
695 /* These systems claim to have LVDS, but really don't */
696 static const struct dmi_system_id intel_no_lvds[] = {
697 	{
698 		.callback = intel_no_lvds_dmi_callback,
699 		.ident = "Apple Mac Mini (Core series)",
700 		.matches = {
701 			DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
702 			DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
703 		},
704 	},
705 	{
706 		.callback = intel_no_lvds_dmi_callback,
707 		.ident = "Apple Mac Mini (Core 2 series)",
708 		.matches = {
709 			DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
710 			DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
711 		},
712 	},
713 	{
714 		.callback = intel_no_lvds_dmi_callback,
715 		.ident = "MSI IM-945GSE-A",
716 		.matches = {
717 			DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
718 			DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
719 		},
720 	},
721 	{
722 		.callback = intel_no_lvds_dmi_callback,
723 		.ident = "Dell Studio Hybrid",
724 		.matches = {
725 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
726 			DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
727 		},
728 	},
729 	{
730 		.callback = intel_no_lvds_dmi_callback,
731 		.ident = "Dell OptiPlex FX170",
732 		.matches = {
733 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
734 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
735 		},
736 	},
737 	{
738 		.callback = intel_no_lvds_dmi_callback,
739 		.ident = "AOpen Mini PC",
740 		.matches = {
741 			DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
742 			DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
743 		},
744 	},
745 	{
746 		.callback = intel_no_lvds_dmi_callback,
747 		.ident = "AOpen Mini PC MP915",
748 		.matches = {
749 			DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
750 			DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
751 		},
752 	},
753 	{
754 		.callback = intel_no_lvds_dmi_callback,
755 		.ident = "AOpen i915GMm-HFS",
756 		.matches = {
757 			DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
758 			DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
759 		},
760 	},
761 	{
762 		.callback = intel_no_lvds_dmi_callback,
763                 .ident = "AOpen i45GMx-I",
764                 .matches = {
765                         DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
766                         DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
767                 },
768         },
769 	{
770 		.callback = intel_no_lvds_dmi_callback,
771 		.ident = "Aopen i945GTt-VFA",
772 		.matches = {
773 			DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
774 		},
775 	},
776 	{
777 		.callback = intel_no_lvds_dmi_callback,
778 		.ident = "Clientron U800",
779 		.matches = {
780 			DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
781 			DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
782 		},
783 	},
784 	{
785                 .callback = intel_no_lvds_dmi_callback,
786                 .ident = "Clientron E830",
787                 .matches = {
788                         DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
789                         DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
790                 },
791         },
792         {
793 		.callback = intel_no_lvds_dmi_callback,
794 		.ident = "Asus EeeBox PC EB1007",
795 		.matches = {
796 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
797 			DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
798 		},
799 	},
800 	{
801 		.callback = intel_no_lvds_dmi_callback,
802 		.ident = "Asus AT5NM10T-I",
803 		.matches = {
804 			DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
805 			DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
806 		},
807 	},
808 	{
809 		.callback = intel_no_lvds_dmi_callback,
810 		.ident = "Hewlett-Packard HP t5740",
811 		.matches = {
812 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
813 			DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
814 		},
815 	},
816 	{
817 		.callback = intel_no_lvds_dmi_callback,
818 		.ident = "Hewlett-Packard t5745",
819 		.matches = {
820 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
821 			DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
822 		},
823 	},
824 	{
825 		.callback = intel_no_lvds_dmi_callback,
826 		.ident = "Hewlett-Packard st5747",
827 		.matches = {
828 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
829 			DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
830 		},
831 	},
832 	{
833 		.callback = intel_no_lvds_dmi_callback,
834 		.ident = "MSI Wind Box DC500",
835 		.matches = {
836 			DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
837 			DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
838 		},
839 	},
840 	{
841 		.callback = intel_no_lvds_dmi_callback,
842 		.ident = "Gigabyte GA-D525TUD",
843 		.matches = {
844 			DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
845 			DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
846 		},
847 	},
848 	{
849 		.callback = intel_no_lvds_dmi_callback,
850 		.ident = "Supermicro X7SPA-H",
851 		.matches = {
852 			DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
853 			DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
854 		},
855 	},
856 	{
857 		.callback = intel_no_lvds_dmi_callback,
858 		.ident = "Fujitsu Esprimo Q900",
859 		.matches = {
860 			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
861 			DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
862 		},
863 	},
864 
865 	{ }	/* terminating entry */
866 };
867 
868 /**
869  * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
870  * @dev: drm device
871  * @connector: LVDS connector
872  *
873  * Find the reduced downclock for LVDS in EDID.
874  */
875 static void intel_find_lvds_downclock(struct drm_device *dev,
876 				      struct drm_display_mode *fixed_mode,
877 				      struct drm_connector *connector)
878 {
879 	struct drm_i915_private *dev_priv = dev->dev_private;
880 	struct drm_display_mode *scan;
881 	int temp_downclock;
882 
883 	temp_downclock = fixed_mode->clock;
884 	list_for_each_entry(scan, &connector->probed_modes, head) {
885 		/*
886 		 * If one mode has the same resolution with the fixed_panel
887 		 * mode while they have the different refresh rate, it means
888 		 * that the reduced downclock is found for the LVDS. In such
889 		 * case we can set the different FPx0/1 to dynamically select
890 		 * between low and high frequency.
891 		 */
892 		if (scan->hdisplay == fixed_mode->hdisplay &&
893 		    scan->hsync_start == fixed_mode->hsync_start &&
894 		    scan->hsync_end == fixed_mode->hsync_end &&
895 		    scan->htotal == fixed_mode->htotal &&
896 		    scan->vdisplay == fixed_mode->vdisplay &&
897 		    scan->vsync_start == fixed_mode->vsync_start &&
898 		    scan->vsync_end == fixed_mode->vsync_end &&
899 		    scan->vtotal == fixed_mode->vtotal) {
900 			if (scan->clock < temp_downclock) {
901 				/*
902 				 * The downclock is already found. But we
903 				 * expect to find the lower downclock.
904 				 */
905 				temp_downclock = scan->clock;
906 			}
907 		}
908 	}
909 	if (temp_downclock < fixed_mode->clock && i915_lvds_downclock) {
910 		/* We found the downclock for LVDS. */
911 		dev_priv->lvds_downclock_avail = 1;
912 		dev_priv->lvds_downclock = temp_downclock;
913 		DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
914 			      "Normal clock %dKhz, downclock %dKhz\n",
915 			      fixed_mode->clock, temp_downclock);
916 	}
917 }
918 
919 /*
920  * Enumerate the child dev array parsed from VBT to check whether
921  * the LVDS is present.
922  * If it is present, return 1.
923  * If it is not present, return false.
924  * If no child dev is parsed from VBT, it assumes that the LVDS is present.
925  */
926 static bool lvds_is_present_in_vbt(struct drm_device *dev,
927 				   u8 *i2c_pin)
928 {
929 	struct drm_i915_private *dev_priv = dev->dev_private;
930 	int i;
931 
932 	if (!dev_priv->child_dev_num)
933 		return true;
934 
935 	for (i = 0; i < dev_priv->child_dev_num; i++) {
936 		struct child_device_config *child = dev_priv->child_dev + i;
937 
938 		/* If the device type is not LFP, continue.
939 		 * We have to check both the new identifiers as well as the
940 		 * old for compatibility with some BIOSes.
941 		 */
942 		if (child->device_type != DEVICE_TYPE_INT_LFP &&
943 		    child->device_type != DEVICE_TYPE_LFP)
944 			continue;
945 
946 		if (intel_gmbus_is_port_valid(child->i2c_pin))
947 			*i2c_pin = child->i2c_pin;
948 
949 		/* However, we cannot trust the BIOS writers to populate
950 		 * the VBT correctly.  Since LVDS requires additional
951 		 * information from AIM blocks, a non-zero addin offset is
952 		 * a good indicator that the LVDS is actually present.
953 		 */
954 		if (child->addin_offset)
955 			return true;
956 
957 		/* But even then some BIOS writers perform some black magic
958 		 * and instantiate the device without reference to any
959 		 * additional data.  Trust that if the VBT was written into
960 		 * the OpRegion then they have validated the LVDS's existence.
961 		 */
962 		if (dev_priv->opregion.vbt)
963 			return true;
964 	}
965 
966 	return false;
967 }
968 
969 static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
970 {
971 	DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
972 	return 1;
973 }
974 
975 static const struct dmi_system_id intel_dual_link_lvds[] = {
976 	{
977 		.callback = intel_dual_link_lvds_callback,
978 		.ident = "Apple MacBook Pro (Core i5/i7 Series)",
979 		.matches = {
980 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
981 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
982 		},
983 	},
984 	{ }	/* terminating entry */
985 };
986 
987 bool intel_is_dual_link_lvds(struct drm_device *dev)
988 {
989 	struct intel_encoder *encoder;
990 	struct intel_lvds_encoder *lvds_encoder;
991 
992 	list_for_each_entry(encoder, &dev->mode_config.encoder_list,
993 			    base.head) {
994 		if (encoder->type == INTEL_OUTPUT_LVDS) {
995 			lvds_encoder = to_lvds_encoder(&encoder->base);
996 
997 			return lvds_encoder->is_dual_link;
998 		}
999 	}
1000 
1001 	return false;
1002 }
1003 
1004 static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
1005 {
1006 	struct drm_device *dev = lvds_encoder->base.base.dev;
1007 	unsigned int val;
1008 	struct drm_i915_private *dev_priv = dev->dev_private;
1009 
1010 	/* use the module option value if specified */
1011 	if (i915_lvds_channel_mode > 0)
1012 		return i915_lvds_channel_mode == 2;
1013 
1014 	if (dmi_check_system(intel_dual_link_lvds))
1015 		return true;
1016 
1017 	/* BIOS should set the proper LVDS register value at boot, but
1018 	 * in reality, it doesn't set the value when the lid is closed;
1019 	 * we need to check "the value to be set" in VBT when LVDS
1020 	 * register is uninitialized.
1021 	 */
1022 	val = I915_READ(lvds_encoder->reg);
1023 	if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
1024 		val = dev_priv->bios_lvds_val;
1025 
1026 	return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
1027 }
1028 
1029 static bool intel_lvds_supported(struct drm_device *dev)
1030 {
1031 	/* With the introduction of the PCH we gained a dedicated
1032 	 * LVDS presence pin, use it. */
1033 	if (HAS_PCH_SPLIT(dev))
1034 		return true;
1035 
1036 	/* Otherwise LVDS was only attached to mobile products,
1037 	 * except for the inglorious 830gm */
1038 	return IS_MOBILE(dev) && !IS_I830(dev);
1039 }
1040 
1041 /**
1042  * intel_lvds_init - setup LVDS connectors on this device
1043  * @dev: drm device
1044  *
1045  * Create the connector, register the LVDS DDC bus, and try to figure out what
1046  * modes we can display on the LVDS panel (if present).
1047  */
1048 bool intel_lvds_init(struct drm_device *dev)
1049 {
1050 	struct drm_i915_private *dev_priv = dev->dev_private;
1051 	struct intel_lvds_encoder *lvds_encoder;
1052 	struct intel_encoder *intel_encoder;
1053 	struct intel_lvds_connector *lvds_connector;
1054 	struct intel_connector *intel_connector;
1055 	struct drm_connector *connector;
1056 	struct drm_encoder *encoder;
1057 	struct drm_display_mode *scan; /* *modes, *bios_mode; */
1058 	struct drm_display_mode *fixed_mode = NULL;
1059 	struct edid *edid;
1060 	struct drm_crtc *crtc;
1061 	u32 lvds;
1062 	int pipe;
1063 	u8 pin;
1064 
1065 	if (!intel_lvds_supported(dev))
1066 		return false;
1067 
1068 	/* Skip init on machines we know falsely report LVDS */
1069 	if (dmi_check_system(intel_no_lvds))
1070 		return false;
1071 
1072 	pin = GMBUS_PORT_PANEL;
1073 	if (!lvds_is_present_in_vbt(dev, &pin)) {
1074 		DRM_DEBUG_KMS("LVDS is not present in VBT\n");
1075 		return false;
1076 	}
1077 
1078 	if (HAS_PCH_SPLIT(dev)) {
1079 		if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
1080 			return false;
1081 		if (dev_priv->edp.support) {
1082 			DRM_DEBUG_KMS("disable LVDS for eDP support\n");
1083 			return false;
1084 		}
1085 	}
1086 
1087 	lvds_encoder = kmalloc(sizeof(struct intel_lvds_encoder), M_DRM,
1088 	    M_WAITOK | M_ZERO);
1089 	if (!lvds_encoder)
1090 		return false;
1091 
1092 	lvds_connector = kmalloc(sizeof(struct intel_lvds_connector), M_DRM,
1093 	    M_WAITOK | M_ZERO);
1094 	if (!lvds_connector) {
1095 		kfree(lvds_encoder, M_DRM);
1096 		return false;
1097 	}
1098 
1099 	lvds_encoder->attached_connector = lvds_connector;
1100 
1101 	if (!HAS_PCH_SPLIT(dev)) {
1102 		lvds_encoder->pfit_control = I915_READ(PFIT_CONTROL);
1103 	}
1104 
1105 	intel_encoder = &lvds_encoder->base;
1106 	encoder = &intel_encoder->base;
1107 	intel_connector = &lvds_connector->base;
1108 	connector = &intel_connector->base;
1109 	drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
1110 			   DRM_MODE_CONNECTOR_LVDS);
1111 
1112 	drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
1113 			 DRM_MODE_ENCODER_LVDS);
1114 
1115 	intel_encoder->enable = intel_enable_lvds;
1116 	intel_encoder->pre_enable = intel_pre_enable_lvds;
1117 	intel_encoder->pre_pll_enable = intel_pre_pll_enable_lvds;
1118 	intel_encoder->disable = intel_disable_lvds;
1119 	intel_encoder->get_hw_state = intel_lvds_get_hw_state;
1120 	intel_connector->get_hw_state = intel_connector_get_hw_state;
1121 
1122 	intel_connector_attach_encoder(intel_connector, intel_encoder);
1123 	intel_encoder->type = INTEL_OUTPUT_LVDS;
1124 
1125 	intel_encoder->cloneable = false;
1126 	if (HAS_PCH_SPLIT(dev))
1127 		intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
1128 	else if (IS_GEN4(dev))
1129 		intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
1130 	else
1131 		intel_encoder->crtc_mask = (1 << 1);
1132 
1133 	drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
1134 	drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
1135 	connector->display_info.subpixel_order = SubPixelHorizontalRGB;
1136 	connector->interlace_allowed = false;
1137 	connector->doublescan_allowed = false;
1138 
1139 	if (HAS_PCH_SPLIT(dev)) {
1140 		lvds_encoder->reg = PCH_LVDS;
1141 	} else {
1142 		lvds_encoder->reg = LVDS;
1143 	}
1144 
1145 	/* create the scaling mode property */
1146 	drm_mode_create_scaling_mode_property(dev);
1147 	drm_object_attach_property(&connector->base,
1148 				      dev->mode_config.scaling_mode_property,
1149 				      DRM_MODE_SCALE_ASPECT);
1150 	intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
1151 	/*
1152 	 * LVDS discovery:
1153 	 * 1) check for EDID on DDC
1154 	 * 2) check for VBT data
1155 	 * 3) check to see if LVDS is already on
1156 	 *    if none of the above, no panel
1157 	 * 4) make sure lid is open
1158 	 *    if closed, act like it's not there for now
1159 	 */
1160 
1161 	/*
1162 	 * Attempt to get the fixed panel mode from DDC.  Assume that the
1163 	 * preferred mode is the right one.
1164 	 */
1165 	edid = drm_get_edid(connector, intel_gmbus_get_adapter(dev_priv, pin));
1166 	if (edid) {
1167 		if (drm_add_edid_modes(connector, edid)) {
1168 			drm_mode_connector_update_edid_property(connector,
1169 								edid);
1170 		} else {
1171 			kfree(edid, M_DRM);
1172 			edid = ERR_PTR(-EINVAL);
1173 		}
1174 	} else {
1175 		edid = ERR_PTR(-ENOENT);
1176 	}
1177 	lvds_connector->base.edid = edid;
1178 
1179 	if (IS_ERR_OR_NULL(edid)) {
1180 		/* Didn't get an EDID, so
1181 		 * Set wide sync ranges so we get all modes
1182 		 * handed to valid_mode for checking
1183 		 */
1184 		connector->display_info.min_vfreq = 0;
1185 		connector->display_info.max_vfreq = 200;
1186 		connector->display_info.min_hfreq = 0;
1187 		connector->display_info.max_hfreq = 200;
1188 	}
1189 
1190 	list_for_each_entry(scan, &connector->probed_modes, head) {
1191 		if (scan->type & DRM_MODE_TYPE_PREFERRED) {
1192 			DRM_DEBUG_KMS("using preferred mode from EDID: ");
1193 			drm_mode_debug_printmodeline(scan);
1194 
1195 			fixed_mode = drm_mode_duplicate(dev, scan);
1196 			if (fixed_mode) {
1197 				intel_find_lvds_downclock(dev, fixed_mode,
1198 							  connector);
1199 				goto out;
1200 			}
1201 		}
1202 	}
1203 
1204 	/* Failed to get EDID, what about VBT? */
1205 	if (dev_priv->lfp_lvds_vbt_mode) {
1206 		DRM_DEBUG_KMS("using mode from VBT: ");
1207 		drm_mode_debug_printmodeline(dev_priv->lfp_lvds_vbt_mode);
1208 
1209 		fixed_mode = drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
1210 		if (fixed_mode) {
1211 			fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1212 			goto out;
1213 		}
1214 	}
1215 
1216 	/*
1217 	 * If we didn't get EDID, try checking if the panel is already turned
1218 	 * on.  If so, assume that whatever is currently programmed is the
1219 	 * correct mode.
1220 	 */
1221 
1222 	/* Ironlake: FIXME if still fail, not try pipe mode now */
1223 	if (HAS_PCH_SPLIT(dev))
1224 		goto failed;
1225 
1226 	lvds = I915_READ(LVDS);
1227 	pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
1228 	crtc = intel_get_crtc_for_pipe(dev, pipe);
1229 
1230 	if (crtc && (lvds & LVDS_PORT_EN)) {
1231 		fixed_mode = intel_crtc_mode_get(dev, crtc);
1232 		if (fixed_mode) {
1233 			DRM_DEBUG_KMS("using current (BIOS) mode: ");
1234 			drm_mode_debug_printmodeline(fixed_mode);
1235 			fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1236 			goto out;
1237 		}
1238 	}
1239 
1240 	/* If we still don't have a mode after all that, give up. */
1241 	if (!fixed_mode)
1242 		goto failed;
1243 
1244 out:
1245 	lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
1246 	DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
1247 		      lvds_encoder->is_dual_link ? "dual" : "single");
1248 
1249 	/*
1250 	 * Unlock registers and just
1251 	 * leave them unlocked
1252 	 */
1253 	if (HAS_PCH_SPLIT(dev)) {
1254 		I915_WRITE(PCH_PP_CONTROL,
1255 			   I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
1256 	} else {
1257 		I915_WRITE(PP_CONTROL,
1258 			   I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
1259 	}
1260 #if 0
1261 	lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
1262 	if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
1263 		DRM_DEBUG_KMS("lid notifier registration failed\n");
1264 		lvds_connector->lid_notifier.notifier_call = NULL;
1265 	}
1266 	drm_sysfs_connector_add(connector);
1267 #endif
1268 
1269 	intel_panel_init(&intel_connector->panel, fixed_mode);
1270 	intel_panel_setup_backlight(connector);
1271 
1272 	return true;
1273 
1274 failed:
1275 	DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
1276 	drm_connector_cleanup(connector);
1277 	drm_encoder_cleanup(encoder);
1278 	if (fixed_mode)
1279 		drm_mode_destroy(dev, fixed_mode);
1280 	kfree(lvds_encoder, M_DRM);
1281 	kfree(lvds_connector, M_DRM);
1282 	return false;
1283 }
1284