xref: /dflybsd-src/sys/dev/drm/i915/intel_lvds.c (revision 610e3300d4a708548c98ec7e66f6dd62d04bc2f2)
1e3adcf8fSFrançois Tigeot /*
2e3adcf8fSFrançois Tigeot  * Copyright © 2006-2007 Intel Corporation
3e3adcf8fSFrançois Tigeot  * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
4e3adcf8fSFrançois Tigeot  *
5e3adcf8fSFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
6e3adcf8fSFrançois Tigeot  * copy of this software and associated documentation files (the "Software"),
7e3adcf8fSFrançois Tigeot  * to deal in the Software without restriction, including without limitation
8e3adcf8fSFrançois Tigeot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9e3adcf8fSFrançois Tigeot  * and/or sell copies of the Software, and to permit persons to whom the
10e3adcf8fSFrançois Tigeot  * Software is furnished to do so, subject to the following conditions:
11e3adcf8fSFrançois Tigeot  *
12e3adcf8fSFrançois Tigeot  * The above copyright notice and this permission notice (including the next
13e3adcf8fSFrançois Tigeot  * paragraph) shall be included in all copies or substantial portions of the
14e3adcf8fSFrançois Tigeot  * Software.
15e3adcf8fSFrançois Tigeot  *
16e3adcf8fSFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17e3adcf8fSFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18e3adcf8fSFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19e3adcf8fSFrançois Tigeot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20e3adcf8fSFrançois Tigeot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21e3adcf8fSFrançois Tigeot  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22e3adcf8fSFrançois Tigeot  * DEALINGS IN THE SOFTWARE.
23e3adcf8fSFrançois Tigeot  *
24e3adcf8fSFrançois Tigeot  * Authors:
25e3adcf8fSFrançois Tigeot  *	Eric Anholt <eric@anholt.net>
26e3adcf8fSFrançois Tigeot  *      Dave Airlie <airlied@linux.ie>
27e3adcf8fSFrançois Tigeot  *      Jesse Barnes <jesse.barnes@intel.com>
28e3adcf8fSFrançois Tigeot  */
29*610e3300SPeeter Must #include "opt_drm.h"
30e3adcf8fSFrançois Tigeot 
315d0b1887SFrançois Tigeot #include <linux/dmi.h>
32a2fdbec6SFrançois Tigeot #include <linux/i2c.h>
338621f407SFrançois Tigeot #include <linux/vga_switcheroo.h>
3418e26a6dSFrançois Tigeot #include <drm/drmP.h>
352c9916cdSFrançois Tigeot #include <drm/drm_atomic_helper.h>
3618e26a6dSFrançois Tigeot #include <drm/drm_crtc.h>
3718e26a6dSFrançois Tigeot #include <drm/drm_edid.h>
3818e26a6dSFrançois Tigeot #include "intel_drv.h"
395c6c6f23SFrançois Tigeot #include <drm/i915_drm.h>
40e3adcf8fSFrançois Tigeot #include "i915_drv.h"
41e3adcf8fSFrançois Tigeot 
42e3adcf8fSFrançois Tigeot /* Private structure for the integrated LVDS support */
4319df918dSFrançois Tigeot struct intel_lvds_connector {
4419df918dSFrançois Tigeot 	struct intel_connector base;
4519df918dSFrançois Tigeot 
4619df918dSFrançois Tigeot 	struct notifier_block lid_notifier;
4719df918dSFrançois Tigeot };
4819df918dSFrançois Tigeot 
4919df918dSFrançois Tigeot struct intel_lvds_encoder {
50e3adcf8fSFrançois Tigeot 	struct intel_encoder base;
51e3adcf8fSFrançois Tigeot 
52a2fdbec6SFrançois Tigeot 	bool is_dual_link;
53aee94f86SFrançois Tigeot 	i915_reg_t reg;
5424edb884SFrançois Tigeot 	u32 a3_power;
55e3adcf8fSFrançois Tigeot 
5619df918dSFrançois Tigeot 	struct intel_lvds_connector *attached_connector;
57e3adcf8fSFrançois Tigeot };
58e3adcf8fSFrançois Tigeot 
5919df918dSFrançois Tigeot static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
60e3adcf8fSFrançois Tigeot {
6119df918dSFrançois Tigeot 	return container_of(encoder, struct intel_lvds_encoder, base.base);
62e3adcf8fSFrançois Tigeot }
63e3adcf8fSFrançois Tigeot 
6419df918dSFrançois Tigeot static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
65e3adcf8fSFrançois Tigeot {
6619df918dSFrançois Tigeot 	return container_of(connector, struct intel_lvds_connector, base.base);
6719df918dSFrançois Tigeot }
6819df918dSFrançois Tigeot 
6919df918dSFrançois Tigeot static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
7019df918dSFrançois Tigeot 				    enum i915_pipe *pipe)
7119df918dSFrançois Tigeot {
7219df918dSFrançois Tigeot 	struct drm_device *dev = encoder->base.dev;
7319df918dSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
74a2fdbec6SFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
7524edb884SFrançois Tigeot 	enum intel_display_power_domain power_domain;
76a2fdbec6SFrançois Tigeot 	u32 tmp;
77aee94f86SFrançois Tigeot 	bool ret;
7819df918dSFrançois Tigeot 
7924edb884SFrançois Tigeot 	power_domain = intel_display_port_power_domain(encoder);
80aee94f86SFrançois Tigeot 	if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
8124edb884SFrançois Tigeot 		return false;
8224edb884SFrançois Tigeot 
83aee94f86SFrançois Tigeot 	ret = false;
84aee94f86SFrançois Tigeot 
85a2fdbec6SFrançois Tigeot 	tmp = I915_READ(lvds_encoder->reg);
8619df918dSFrançois Tigeot 
8719df918dSFrançois Tigeot 	if (!(tmp & LVDS_PORT_EN))
88aee94f86SFrançois Tigeot 		goto out;
8919df918dSFrançois Tigeot 
9019df918dSFrançois Tigeot 	if (HAS_PCH_CPT(dev))
9119df918dSFrançois Tigeot 		*pipe = PORT_TO_PIPE_CPT(tmp);
9219df918dSFrançois Tigeot 	else
9319df918dSFrançois Tigeot 		*pipe = PORT_TO_PIPE(tmp);
9419df918dSFrançois Tigeot 
95aee94f86SFrançois Tigeot 	ret = true;
96aee94f86SFrançois Tigeot 
97aee94f86SFrançois Tigeot out:
98aee94f86SFrançois Tigeot 	intel_display_power_put(dev_priv, power_domain);
99aee94f86SFrançois Tigeot 
100aee94f86SFrançois Tigeot 	return ret;
101e3adcf8fSFrançois Tigeot }
102e3adcf8fSFrançois Tigeot 
1035d0b1887SFrançois Tigeot static void intel_lvds_get_config(struct intel_encoder *encoder,
1042c9916cdSFrançois Tigeot 				  struct intel_crtc_state *pipe_config)
1055d0b1887SFrançois Tigeot {
1065d0b1887SFrançois Tigeot 	struct drm_device *dev = encoder->base.dev;
1075d0b1887SFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
108352ff8bdSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
109352ff8bdSFrançois Tigeot 	u32 tmp, flags = 0;
1105d0b1887SFrançois Tigeot 
111352ff8bdSFrançois Tigeot 	tmp = I915_READ(lvds_encoder->reg);
1125d0b1887SFrançois Tigeot 	if (tmp & LVDS_HSYNC_POLARITY)
1135d0b1887SFrançois Tigeot 		flags |= DRM_MODE_FLAG_NHSYNC;
1145d0b1887SFrançois Tigeot 	else
1155d0b1887SFrançois Tigeot 		flags |= DRM_MODE_FLAG_PHSYNC;
1165d0b1887SFrançois Tigeot 	if (tmp & LVDS_VSYNC_POLARITY)
1175d0b1887SFrançois Tigeot 		flags |= DRM_MODE_FLAG_NVSYNC;
1185d0b1887SFrançois Tigeot 	else
1195d0b1887SFrançois Tigeot 		flags |= DRM_MODE_FLAG_PVSYNC;
1205d0b1887SFrançois Tigeot 
1212c9916cdSFrançois Tigeot 	pipe_config->base.adjusted_mode.flags |= flags;
1225d0b1887SFrançois Tigeot 
123c0e85e96SFrançois Tigeot 	if (INTEL_INFO(dev)->gen < 5)
124c0e85e96SFrançois Tigeot 		pipe_config->gmch_pfit.lvds_border_bits =
125c0e85e96SFrançois Tigeot 			tmp & LVDS_BORDER_ENABLE;
126c0e85e96SFrançois Tigeot 
1275d0b1887SFrançois Tigeot 	/* gen2/3 store dither state in pfit control, needs to match */
1285d0b1887SFrançois Tigeot 	if (INTEL_INFO(dev)->gen < 4) {
1295d0b1887SFrançois Tigeot 		tmp = I915_READ(PFIT_CONTROL);
1305d0b1887SFrançois Tigeot 
1315d0b1887SFrançois Tigeot 		pipe_config->gmch_pfit.control |= tmp & PANEL_8TO6_DITHER_ENABLE;
1325d0b1887SFrançois Tigeot 	}
1339edbd4a0SFrançois Tigeot 
1348621f407SFrançois Tigeot 	pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock;
1355d0b1887SFrançois Tigeot }
1365d0b1887SFrançois Tigeot 
1379edbd4a0SFrançois Tigeot static void intel_pre_enable_lvds(struct intel_encoder *encoder)
138a2fdbec6SFrançois Tigeot {
139a2fdbec6SFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
140a2fdbec6SFrançois Tigeot 	struct drm_device *dev = encoder->base.dev;
141a2fdbec6SFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
1429edbd4a0SFrançois Tigeot 	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
143352ff8bdSFrançois Tigeot 	const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
1449edbd4a0SFrançois Tigeot 	int pipe = crtc->pipe;
145a2fdbec6SFrançois Tigeot 	u32 temp;
146a2fdbec6SFrançois Tigeot 
1479edbd4a0SFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
1489edbd4a0SFrançois Tigeot 		assert_fdi_rx_pll_disabled(dev_priv, pipe);
1499edbd4a0SFrançois Tigeot 		assert_shared_dpll_disabled(dev_priv,
1508621f407SFrançois Tigeot 					    crtc->config->shared_dpll);
1519edbd4a0SFrançois Tigeot 	} else {
1529edbd4a0SFrançois Tigeot 		assert_pll_disabled(dev_priv, pipe);
1539edbd4a0SFrançois Tigeot 	}
1549edbd4a0SFrançois Tigeot 
155a2fdbec6SFrançois Tigeot 	temp = I915_READ(lvds_encoder->reg);
156a2fdbec6SFrançois Tigeot 	temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
157a2fdbec6SFrançois Tigeot 
158a2fdbec6SFrançois Tigeot 	if (HAS_PCH_CPT(dev)) {
159a2fdbec6SFrançois Tigeot 		temp &= ~PORT_TRANS_SEL_MASK;
160a2fdbec6SFrançois Tigeot 		temp |= PORT_TRANS_SEL_CPT(pipe);
161a2fdbec6SFrançois Tigeot 	} else {
162a2fdbec6SFrançois Tigeot 		if (pipe == 1) {
163a2fdbec6SFrançois Tigeot 			temp |= LVDS_PIPEB_SELECT;
164a2fdbec6SFrançois Tigeot 		} else {
165a2fdbec6SFrançois Tigeot 			temp &= ~LVDS_PIPEB_SELECT;
166a2fdbec6SFrançois Tigeot 		}
167a2fdbec6SFrançois Tigeot 	}
168a2fdbec6SFrançois Tigeot 
169a2fdbec6SFrançois Tigeot 	/* set the corresponsding LVDS_BORDER bit */
1705d0b1887SFrançois Tigeot 	temp &= ~LVDS_BORDER_ENABLE;
1712c9916cdSFrançois Tigeot 	temp |= crtc->config->gmch_pfit.lvds_border_bits;
172a2fdbec6SFrançois Tigeot 	/* Set the B0-B3 data pairs corresponding to whether we're going to
173a2fdbec6SFrançois Tigeot 	 * set the DPLLs for dual-channel mode or not.
174a2fdbec6SFrançois Tigeot 	 */
175a2fdbec6SFrançois Tigeot 	if (lvds_encoder->is_dual_link)
176a2fdbec6SFrançois Tigeot 		temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
177a2fdbec6SFrançois Tigeot 	else
178a2fdbec6SFrançois Tigeot 		temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
179a2fdbec6SFrançois Tigeot 
180a2fdbec6SFrançois Tigeot 	/* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
181a2fdbec6SFrançois Tigeot 	 * appropriately here, but we need to look more thoroughly into how
18224edb884SFrançois Tigeot 	 * panels behave in the two modes. For now, let's just maintain the
18324edb884SFrançois Tigeot 	 * value we got from the BIOS.
184a2fdbec6SFrançois Tigeot 	 */
18524edb884SFrançois Tigeot 	 temp &= ~LVDS_A3_POWER_MASK;
18624edb884SFrançois Tigeot 	 temp |= lvds_encoder->a3_power;
187a2fdbec6SFrançois Tigeot 
188a2fdbec6SFrançois Tigeot 	/* Set the dithering flag on LVDS as needed, note that there is no
189a2fdbec6SFrançois Tigeot 	 * special lvds dither control bit on pch-split platforms, dithering is
190a2fdbec6SFrançois Tigeot 	 * only controlled through the PIPECONF reg. */
191a2fdbec6SFrançois Tigeot 	if (INTEL_INFO(dev)->gen == 4) {
1925d0b1887SFrançois Tigeot 		/* Bspec wording suggests that LVDS port dithering only exists
1935d0b1887SFrançois Tigeot 		 * for 18bpp panels. */
1942c9916cdSFrançois Tigeot 		if (crtc->config->dither && crtc->config->pipe_bpp == 18)
195a2fdbec6SFrançois Tigeot 			temp |= LVDS_ENABLE_DITHER;
196a2fdbec6SFrançois Tigeot 		else
197a2fdbec6SFrançois Tigeot 			temp &= ~LVDS_ENABLE_DITHER;
198a2fdbec6SFrançois Tigeot 	}
199a2fdbec6SFrançois Tigeot 	temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
2009edbd4a0SFrançois Tigeot 	if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
201a2fdbec6SFrançois Tigeot 		temp |= LVDS_HSYNC_POLARITY;
2029edbd4a0SFrançois Tigeot 	if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
203a2fdbec6SFrançois Tigeot 		temp |= LVDS_VSYNC_POLARITY;
204a2fdbec6SFrançois Tigeot 
205a2fdbec6SFrançois Tigeot 	I915_WRITE(lvds_encoder->reg, temp);
206a2fdbec6SFrançois Tigeot }
207a2fdbec6SFrançois Tigeot 
208e3adcf8fSFrançois Tigeot /**
209e3adcf8fSFrançois Tigeot  * Sets the power state for the panel.
210e3adcf8fSFrançois Tigeot  */
21119df918dSFrançois Tigeot static void intel_enable_lvds(struct intel_encoder *encoder)
212e3adcf8fSFrançois Tigeot {
21319df918dSFrançois Tigeot 	struct drm_device *dev = encoder->base.dev;
21419df918dSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
2159edbd4a0SFrançois Tigeot 	struct intel_connector *intel_connector =
2169edbd4a0SFrançois Tigeot 		&lvds_encoder->attached_connector->base;
217e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
218aee94f86SFrançois Tigeot 	i915_reg_t ctl_reg, stat_reg;
219e3adcf8fSFrançois Tigeot 
220e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
221e3adcf8fSFrançois Tigeot 		ctl_reg = PCH_PP_CONTROL;
222e3adcf8fSFrançois Tigeot 		stat_reg = PCH_PP_STATUS;
223e3adcf8fSFrançois Tigeot 	} else {
224e3adcf8fSFrançois Tigeot 		ctl_reg = PP_CONTROL;
225e3adcf8fSFrançois Tigeot 		stat_reg = PP_STATUS;
226e3adcf8fSFrançois Tigeot 	}
227e3adcf8fSFrançois Tigeot 
228a2fdbec6SFrançois Tigeot 	I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
229e3adcf8fSFrançois Tigeot 
230e3adcf8fSFrançois Tigeot 	I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
231a2fdbec6SFrançois Tigeot 	POSTING_READ(lvds_encoder->reg);
23219df918dSFrançois Tigeot 	if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
23319df918dSFrançois Tigeot 		DRM_ERROR("timed out waiting for panel to power on\n");
234e3adcf8fSFrançois Tigeot 
2359edbd4a0SFrançois Tigeot 	intel_panel_enable_backlight(intel_connector);
236e3adcf8fSFrançois Tigeot }
237e3adcf8fSFrançois Tigeot 
23819df918dSFrançois Tigeot static void intel_disable_lvds(struct intel_encoder *encoder)
239e3adcf8fSFrançois Tigeot {
24019df918dSFrançois Tigeot 	struct drm_device *dev = encoder->base.dev;
24119df918dSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
242e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
243aee94f86SFrançois Tigeot 	i915_reg_t ctl_reg, stat_reg;
244e3adcf8fSFrançois Tigeot 
245e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
246e3adcf8fSFrançois Tigeot 		ctl_reg = PCH_PP_CONTROL;
247e3adcf8fSFrançois Tigeot 		stat_reg = PCH_PP_STATUS;
248e3adcf8fSFrançois Tigeot 	} else {
249e3adcf8fSFrançois Tigeot 		ctl_reg = PP_CONTROL;
250e3adcf8fSFrançois Tigeot 		stat_reg = PP_STATUS;
251e3adcf8fSFrançois Tigeot 	}
252e3adcf8fSFrançois Tigeot 
253e3adcf8fSFrançois Tigeot 	I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
25419df918dSFrançois Tigeot 	if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
255e3adcf8fSFrançois Tigeot 		DRM_ERROR("timed out waiting for panel to power off\n");
256e3adcf8fSFrançois Tigeot 
257a2fdbec6SFrançois Tigeot 	I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
258a2fdbec6SFrançois Tigeot 	POSTING_READ(lvds_encoder->reg);
259e3adcf8fSFrançois Tigeot }
260e3adcf8fSFrançois Tigeot 
261a05eeebfSFrançois Tigeot static void gmch_disable_lvds(struct intel_encoder *encoder)
262a05eeebfSFrançois Tigeot {
263a05eeebfSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
264a05eeebfSFrançois Tigeot 	struct intel_connector *intel_connector =
265a05eeebfSFrançois Tigeot 		&lvds_encoder->attached_connector->base;
266a05eeebfSFrançois Tigeot 
267a05eeebfSFrançois Tigeot 	intel_panel_disable_backlight(intel_connector);
268a05eeebfSFrançois Tigeot 
269a05eeebfSFrançois Tigeot 	intel_disable_lvds(encoder);
270a05eeebfSFrançois Tigeot }
271a05eeebfSFrançois Tigeot 
272a05eeebfSFrançois Tigeot static void pch_disable_lvds(struct intel_encoder *encoder)
273a05eeebfSFrançois Tigeot {
274a05eeebfSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
275a05eeebfSFrançois Tigeot 	struct intel_connector *intel_connector =
276a05eeebfSFrançois Tigeot 		&lvds_encoder->attached_connector->base;
277a05eeebfSFrançois Tigeot 
278a05eeebfSFrançois Tigeot 	intel_panel_disable_backlight(intel_connector);
279a05eeebfSFrançois Tigeot }
280a05eeebfSFrançois Tigeot 
281a05eeebfSFrançois Tigeot static void pch_post_disable_lvds(struct intel_encoder *encoder)
282a05eeebfSFrançois Tigeot {
283a05eeebfSFrançois Tigeot 	intel_disable_lvds(encoder);
284a05eeebfSFrançois Tigeot }
285a05eeebfSFrançois Tigeot 
2869edbd4a0SFrançois Tigeot static enum drm_mode_status
2879edbd4a0SFrançois Tigeot intel_lvds_mode_valid(struct drm_connector *connector,
288e3adcf8fSFrançois Tigeot 		      struct drm_display_mode *mode)
289e3adcf8fSFrançois Tigeot {
29019df918dSFrançois Tigeot 	struct intel_connector *intel_connector = to_intel_connector(connector);
29119df918dSFrançois Tigeot 	struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
292352ff8bdSFrançois Tigeot 	int max_pixclk = to_i915(connector->dev)->max_dotclk_freq;
293e3adcf8fSFrançois Tigeot 
294e3adcf8fSFrançois Tigeot 	if (mode->hdisplay > fixed_mode->hdisplay)
295e3adcf8fSFrançois Tigeot 		return MODE_PANEL;
296e3adcf8fSFrançois Tigeot 	if (mode->vdisplay > fixed_mode->vdisplay)
297e3adcf8fSFrançois Tigeot 		return MODE_PANEL;
298352ff8bdSFrançois Tigeot 	if (fixed_mode->clock > max_pixclk)
299352ff8bdSFrançois Tigeot 		return MODE_CLOCK_HIGH;
300e3adcf8fSFrançois Tigeot 
301e3adcf8fSFrançois Tigeot 	return MODE_OK;
302e3adcf8fSFrançois Tigeot }
303e3adcf8fSFrançois Tigeot 
3048e26cdf6SFrançois Tigeot static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
3052c9916cdSFrançois Tigeot 				      struct intel_crtc_state *pipe_config)
306e3adcf8fSFrançois Tigeot {
3078e26cdf6SFrançois Tigeot 	struct drm_device *dev = intel_encoder->base.dev;
3088e26cdf6SFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder =
3098e26cdf6SFrançois Tigeot 		to_lvds_encoder(&intel_encoder->base);
31019df918dSFrançois Tigeot 	struct intel_connector *intel_connector =
31119df918dSFrançois Tigeot 		&lvds_encoder->attached_connector->base;
3122c9916cdSFrançois Tigeot 	struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
313477eb7f9SFrançois Tigeot 	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
3148e26cdf6SFrançois Tigeot 	unsigned int lvds_bpp;
315e3adcf8fSFrançois Tigeot 
316e3adcf8fSFrançois Tigeot 	/* Should never happen!! */
317e3adcf8fSFrançois Tigeot 	if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
318e3adcf8fSFrançois Tigeot 		DRM_ERROR("Can't support LVDS on pipe A\n");
319e3adcf8fSFrançois Tigeot 		return false;
320e3adcf8fSFrançois Tigeot 	}
321e3adcf8fSFrançois Tigeot 
32224edb884SFrançois Tigeot 	if (lvds_encoder->a3_power == LVDS_A3_POWER_UP)
3238e26cdf6SFrançois Tigeot 		lvds_bpp = 8*3;
3248e26cdf6SFrançois Tigeot 	else
3258e26cdf6SFrançois Tigeot 		lvds_bpp = 6*3;
3268e26cdf6SFrançois Tigeot 
3275d0b1887SFrançois Tigeot 	if (lvds_bpp != pipe_config->pipe_bpp && !pipe_config->bw_constrained) {
3288e26cdf6SFrançois Tigeot 		DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n",
3298e26cdf6SFrançois Tigeot 			      pipe_config->pipe_bpp, lvds_bpp);
3308e26cdf6SFrançois Tigeot 		pipe_config->pipe_bpp = lvds_bpp;
3318e26cdf6SFrançois Tigeot 	}
3325d0b1887SFrançois Tigeot 
333e3adcf8fSFrançois Tigeot 	/*
334e3adcf8fSFrançois Tigeot 	 * We have timings from the BIOS for the panel, put them in
335e3adcf8fSFrançois Tigeot 	 * to the adjusted mode.  The CRTC will be set up for this mode,
336e3adcf8fSFrançois Tigeot 	 * with the panel scaling set up to source from the H/VDisplay
337e3adcf8fSFrançois Tigeot 	 * of the original mode.
338e3adcf8fSFrançois Tigeot 	 */
33919df918dSFrançois Tigeot 	intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
34019df918dSFrançois Tigeot 			       adjusted_mode);
341e3adcf8fSFrançois Tigeot 
342e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
3438e26cdf6SFrançois Tigeot 		pipe_config->has_pch_encoder = true;
3448e26cdf6SFrançois Tigeot 
3455d0b1887SFrançois Tigeot 		intel_pch_panel_fitting(intel_crtc, pipe_config,
3465d0b1887SFrançois Tigeot 					intel_connector->panel.fitting_mode);
347e3adcf8fSFrançois Tigeot 	} else {
3485d0b1887SFrançois Tigeot 		intel_gmch_panel_fitting(intel_crtc, pipe_config,
3495d0b1887SFrançois Tigeot 					 intel_connector->panel.fitting_mode);
350e3adcf8fSFrançois Tigeot 
351e3adcf8fSFrançois Tigeot 	}
352e3adcf8fSFrançois Tigeot 
353e3adcf8fSFrançois Tigeot 	/*
354e3adcf8fSFrançois Tigeot 	 * XXX: It would be nice to support lower refresh rates on the
355e3adcf8fSFrançois Tigeot 	 * panels to reduce power consumption, and perhaps match the
356e3adcf8fSFrançois Tigeot 	 * user's requested refresh rate.
357e3adcf8fSFrançois Tigeot 	 */
358e3adcf8fSFrançois Tigeot 
359e3adcf8fSFrançois Tigeot 	return true;
360e3adcf8fSFrançois Tigeot }
361e3adcf8fSFrançois Tigeot 
362e3adcf8fSFrançois Tigeot /**
363e3adcf8fSFrançois Tigeot  * Detect the LVDS connection.
364e3adcf8fSFrançois Tigeot  *
365e3adcf8fSFrançois Tigeot  * Since LVDS doesn't have hotlug, we use the lid as a proxy.  Open means
366e3adcf8fSFrançois Tigeot  * connected and closed means disconnected.  We also send hotplug events as
367e3adcf8fSFrançois Tigeot  * needed, using lid status notification from the input layer.
368e3adcf8fSFrançois Tigeot  */
369e3adcf8fSFrançois Tigeot static enum drm_connector_status
370e3adcf8fSFrançois Tigeot intel_lvds_detect(struct drm_connector *connector, bool force)
371e3adcf8fSFrançois Tigeot {
372e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
373e3adcf8fSFrançois Tigeot 	enum drm_connector_status status;
374e3adcf8fSFrançois Tigeot 
3759edbd4a0SFrançois Tigeot 	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
376b4efbf42Szrj 		      connector->base.id, connector->name);
3779edbd4a0SFrançois Tigeot 
378e3adcf8fSFrançois Tigeot 	status = intel_panel_detect(dev);
379e3adcf8fSFrançois Tigeot 	if (status != connector_status_unknown)
380e3adcf8fSFrançois Tigeot 		return status;
381e3adcf8fSFrançois Tigeot 
382e3adcf8fSFrançois Tigeot 	return connector_status_connected;
383e3adcf8fSFrançois Tigeot }
384e3adcf8fSFrançois Tigeot 
385e3adcf8fSFrançois Tigeot /**
386e3adcf8fSFrançois Tigeot  * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
387e3adcf8fSFrançois Tigeot  */
388e3adcf8fSFrançois Tigeot static int intel_lvds_get_modes(struct drm_connector *connector)
389e3adcf8fSFrançois Tigeot {
39019df918dSFrançois Tigeot 	struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
391e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
392e3adcf8fSFrançois Tigeot 	struct drm_display_mode *mode;
393e3adcf8fSFrançois Tigeot 
39419df918dSFrançois Tigeot 	/* use cached edid if we have one */
39519df918dSFrançois Tigeot 	if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
39619df918dSFrançois Tigeot 		return drm_add_edid_modes(connector, lvds_connector->base.edid);
397e3adcf8fSFrançois Tigeot 
39819df918dSFrançois Tigeot 	mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
399e3adcf8fSFrançois Tigeot 	if (mode == NULL)
400e3adcf8fSFrançois Tigeot 		return 0;
401e3adcf8fSFrançois Tigeot 
402e3adcf8fSFrançois Tigeot 	drm_mode_probed_add(connector, mode);
403e3adcf8fSFrançois Tigeot 	return 1;
404e3adcf8fSFrançois Tigeot }
405e3adcf8fSFrançois Tigeot 
406e3adcf8fSFrançois Tigeot static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
407e3adcf8fSFrançois Tigeot {
40819df918dSFrançois Tigeot 	DRM_INFO("Skipping forced modeset for %s\n", id->ident);
409e3adcf8fSFrançois Tigeot 	return 1;
410e3adcf8fSFrançois Tigeot }
411e3adcf8fSFrançois Tigeot 
412e3adcf8fSFrançois Tigeot /* The GPU hangs up on these systems if modeset is performed on LID open */
413e3adcf8fSFrançois Tigeot static const struct dmi_system_id intel_no_modeset_on_lid[] = {
414e3adcf8fSFrançois Tigeot 	{
415e3adcf8fSFrançois Tigeot 		.callback = intel_no_modeset_on_lid_dmi_callback,
416e3adcf8fSFrançois Tigeot 		.ident = "Toshiba Tecra A11",
417e3adcf8fSFrançois Tigeot 		.matches = {
418e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
419e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
420e3adcf8fSFrançois Tigeot 		},
421e3adcf8fSFrançois Tigeot 	},
422e3adcf8fSFrançois Tigeot 
423e3adcf8fSFrançois Tigeot 	{ }	/* terminating entry */
424e3adcf8fSFrançois Tigeot };
425e3adcf8fSFrançois Tigeot 
42619df918dSFrançois Tigeot #if 0
427e3adcf8fSFrançois Tigeot /*
428a2fdbec6SFrançois Tigeot  * Lid events. Note the use of 'modeset':
429a2fdbec6SFrançois Tigeot  *  - we set it to MODESET_ON_LID_OPEN on lid close,
430a2fdbec6SFrançois Tigeot  *    and set it to MODESET_DONE on open
431e3adcf8fSFrançois Tigeot  *  - we use it as a "only once" bit (ie we ignore
432a2fdbec6SFrançois Tigeot  *    duplicate events where it was already properly set)
433a2fdbec6SFrançois Tigeot  *  - the suspend/resume paths will set it to
434a2fdbec6SFrançois Tigeot  *    MODESET_SUSPENDED and ignore the lid open event,
435a2fdbec6SFrançois Tigeot  *    because they restore the mode ("lid open").
436e3adcf8fSFrançois Tigeot  */
437e3adcf8fSFrançois Tigeot static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
438e3adcf8fSFrançois Tigeot 			    void *unused)
439e3adcf8fSFrançois Tigeot {
44019df918dSFrançois Tigeot 	struct intel_lvds_connector *lvds_connector =
44119df918dSFrançois Tigeot 		container_of(nb, struct intel_lvds_connector, lid_notifier);
44219df918dSFrançois Tigeot 	struct drm_connector *connector = &lvds_connector->base.base;
44319df918dSFrançois Tigeot 	struct drm_device *dev = connector->dev;
44419df918dSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
445e3adcf8fSFrançois Tigeot 
446e3adcf8fSFrançois Tigeot 	if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
447e3adcf8fSFrançois Tigeot 		return NOTIFY_OK;
448e3adcf8fSFrançois Tigeot 
449a2fdbec6SFrançois Tigeot 	mutex_lock(&dev_priv->modeset_restore_lock);
450a2fdbec6SFrançois Tigeot 	if (dev_priv->modeset_restore == MODESET_SUSPENDED)
451a2fdbec6SFrançois Tigeot 		goto exit;
452e3adcf8fSFrançois Tigeot 	/*
453e3adcf8fSFrançois Tigeot 	 * check and update the status of LVDS connector after receiving
454e3adcf8fSFrançois Tigeot 	 * the LID nofication event.
455e3adcf8fSFrançois Tigeot 	 */
45619df918dSFrançois Tigeot 	connector->status = connector->funcs->detect(connector, false);
457e3adcf8fSFrançois Tigeot 
458e3adcf8fSFrançois Tigeot 	/* Don't force modeset on machines where it causes a GPU lockup */
459e3adcf8fSFrançois Tigeot 	if (dmi_check_system(intel_no_modeset_on_lid))
460a2fdbec6SFrançois Tigeot 		goto exit;
461e3adcf8fSFrançois Tigeot 	if (!acpi_lid_open()) {
462a2fdbec6SFrançois Tigeot 		/* do modeset on next lid open event */
463a2fdbec6SFrançois Tigeot 		dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
464a2fdbec6SFrançois Tigeot 		goto exit;
465e3adcf8fSFrançois Tigeot 	}
466e3adcf8fSFrançois Tigeot 
467a2fdbec6SFrançois Tigeot 	if (dev_priv->modeset_restore == MODESET_DONE)
468a2fdbec6SFrançois Tigeot 		goto exit;
469e3adcf8fSFrançois Tigeot 
4709edbd4a0SFrançois Tigeot 	/*
4719edbd4a0SFrançois Tigeot 	 * Some old platform's BIOS love to wreak havoc while the lid is closed.
4729edbd4a0SFrançois Tigeot 	 * We try to detect this here and undo any damage. The split for PCH
4739edbd4a0SFrançois Tigeot 	 * platforms is rather conservative and a bit arbitrary expect that on
4749edbd4a0SFrançois Tigeot 	 * those platforms VGA disabling requires actual legacy VGA I/O access,
4759edbd4a0SFrançois Tigeot 	 * and as part of the cleanup in the hw state restore we also redisable
4769edbd4a0SFrançois Tigeot 	 * the vga plane.
4779edbd4a0SFrançois Tigeot 	 */
478c0e85e96SFrançois Tigeot 	if (!HAS_PCH_SPLIT(dev))
479a05eeebfSFrançois Tigeot 		intel_display_resume(dev);
480e3adcf8fSFrançois Tigeot 
481a2fdbec6SFrançois Tigeot 	dev_priv->modeset_restore = MODESET_DONE;
482a2fdbec6SFrançois Tigeot 
483a2fdbec6SFrançois Tigeot exit:
484a2fdbec6SFrançois Tigeot 	mutex_unlock(&dev_priv->modeset_restore_lock);
485e3adcf8fSFrançois Tigeot 	return NOTIFY_OK;
486e3adcf8fSFrançois Tigeot }
487e3adcf8fSFrançois Tigeot #endif
488e3adcf8fSFrançois Tigeot 
489e3adcf8fSFrançois Tigeot /**
490e3adcf8fSFrançois Tigeot  * intel_lvds_destroy - unregister and free LVDS structures
491e3adcf8fSFrançois Tigeot  * @connector: connector to free
492e3adcf8fSFrançois Tigeot  *
493e3adcf8fSFrançois Tigeot  * Unregister the DDC bus for this connector then free the driver private
494e3adcf8fSFrançois Tigeot  * structure.
495e3adcf8fSFrançois Tigeot  */
496e3adcf8fSFrançois Tigeot static void intel_lvds_destroy(struct drm_connector *connector)
497e3adcf8fSFrançois Tigeot {
49819df918dSFrançois Tigeot 	struct intel_lvds_connector *lvds_connector =
49919df918dSFrançois Tigeot 		to_lvds_connector(connector);
500e3adcf8fSFrançois Tigeot 
501e3adcf8fSFrançois Tigeot #if 0
50219df918dSFrançois Tigeot 	if (lvds_connector->lid_notifier.notifier_call)
50319df918dSFrançois Tigeot 		acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
504e3adcf8fSFrançois Tigeot #endif
50519df918dSFrançois Tigeot 
50619df918dSFrançois Tigeot 	if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
507158486a6SFrançois Tigeot 		kfree(lvds_connector->base.edid);
50819df918dSFrançois Tigeot 
50919df918dSFrançois Tigeot 	intel_panel_fini(&lvds_connector->base.panel);
51019df918dSFrançois Tigeot 
511e3adcf8fSFrançois Tigeot 	drm_connector_cleanup(connector);
512158486a6SFrançois Tigeot 	kfree(connector);
513e3adcf8fSFrançois Tigeot }
514e3adcf8fSFrançois Tigeot 
515e3adcf8fSFrançois Tigeot static int intel_lvds_set_property(struct drm_connector *connector,
516e3adcf8fSFrançois Tigeot 				   struct drm_property *property,
517e3adcf8fSFrançois Tigeot 				   uint64_t value)
518e3adcf8fSFrançois Tigeot {
51919df918dSFrançois Tigeot 	struct intel_connector *intel_connector = to_intel_connector(connector);
520e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
521e3adcf8fSFrançois Tigeot 
522e3adcf8fSFrançois Tigeot 	if (property == dev->mode_config.scaling_mode_property) {
52319df918dSFrançois Tigeot 		struct drm_crtc *crtc;
524e3adcf8fSFrançois Tigeot 
525e3adcf8fSFrançois Tigeot 		if (value == DRM_MODE_SCALE_NONE) {
526e3adcf8fSFrançois Tigeot 			DRM_DEBUG_KMS("no scaling not supported\n");
527e3adcf8fSFrançois Tigeot 			return -EINVAL;
528e3adcf8fSFrançois Tigeot 		}
529e3adcf8fSFrançois Tigeot 
53019df918dSFrançois Tigeot 		if (intel_connector->panel.fitting_mode == value) {
531e3adcf8fSFrançois Tigeot 			/* the LVDS scaling property is not changed */
532e3adcf8fSFrançois Tigeot 			return 0;
533e3adcf8fSFrançois Tigeot 		}
53419df918dSFrançois Tigeot 		intel_connector->panel.fitting_mode = value;
53519df918dSFrançois Tigeot 
53619df918dSFrançois Tigeot 		crtc = intel_attached_encoder(connector)->base.crtc;
537477eb7f9SFrançois Tigeot 		if (crtc && crtc->state->enable) {
538e3adcf8fSFrançois Tigeot 			/*
539e3adcf8fSFrançois Tigeot 			 * If the CRTC is enabled, the display will be changed
540e3adcf8fSFrançois Tigeot 			 * according to the new panel fitting mode.
541e3adcf8fSFrançois Tigeot 			 */
542a2fdbec6SFrançois Tigeot 			intel_crtc_restore_mode(crtc);
543e3adcf8fSFrançois Tigeot 		}
544e3adcf8fSFrançois Tigeot 	}
545e3adcf8fSFrançois Tigeot 
546e3adcf8fSFrançois Tigeot 	return 0;
547e3adcf8fSFrançois Tigeot }
548e3adcf8fSFrançois Tigeot 
549e3adcf8fSFrançois Tigeot static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
550e3adcf8fSFrançois Tigeot 	.get_modes = intel_lvds_get_modes,
551e3adcf8fSFrançois Tigeot 	.mode_valid = intel_lvds_mode_valid,
552e3adcf8fSFrançois Tigeot 	.best_encoder = intel_best_encoder,
553e3adcf8fSFrançois Tigeot };
554e3adcf8fSFrançois Tigeot 
555e3adcf8fSFrançois Tigeot static const struct drm_connector_funcs intel_lvds_connector_funcs = {
556a05eeebfSFrançois Tigeot 	.dpms = drm_atomic_helper_connector_dpms,
557e3adcf8fSFrançois Tigeot 	.detect = intel_lvds_detect,
558e3adcf8fSFrançois Tigeot 	.fill_modes = drm_helper_probe_single_connector_modes,
559e3adcf8fSFrançois Tigeot 	.set_property = intel_lvds_set_property,
5602c9916cdSFrançois Tigeot 	.atomic_get_property = intel_connector_atomic_get_property,
561e3adcf8fSFrançois Tigeot 	.destroy = intel_lvds_destroy,
5622c9916cdSFrançois Tigeot 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
563477eb7f9SFrançois Tigeot 	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
564e3adcf8fSFrançois Tigeot };
565e3adcf8fSFrançois Tigeot 
566e3adcf8fSFrançois Tigeot static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
567e3adcf8fSFrançois Tigeot 	.destroy = intel_encoder_destroy,
568e3adcf8fSFrançois Tigeot };
569e3adcf8fSFrançois Tigeot 
57024edb884SFrançois Tigeot static int intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
571e3adcf8fSFrançois Tigeot {
57219df918dSFrançois Tigeot 	DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
573e3adcf8fSFrançois Tigeot 	return 1;
574e3adcf8fSFrançois Tigeot }
575e3adcf8fSFrançois Tigeot 
576e3adcf8fSFrançois Tigeot /* These systems claim to have LVDS, but really don't */
577e3adcf8fSFrançois Tigeot static const struct dmi_system_id intel_no_lvds[] = {
578e3adcf8fSFrançois Tigeot 	{
579e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
580e3adcf8fSFrançois Tigeot 		.ident = "Apple Mac Mini (Core series)",
581e3adcf8fSFrançois Tigeot 		.matches = {
582e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
583e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
584e3adcf8fSFrançois Tigeot 		},
585e3adcf8fSFrançois Tigeot 	},
586e3adcf8fSFrançois Tigeot 	{
587e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
588e3adcf8fSFrançois Tigeot 		.ident = "Apple Mac Mini (Core 2 series)",
589e3adcf8fSFrançois Tigeot 		.matches = {
590e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
591e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
592e3adcf8fSFrançois Tigeot 		},
593e3adcf8fSFrançois Tigeot 	},
594e3adcf8fSFrançois Tigeot 	{
595e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
596e3adcf8fSFrançois Tigeot 		.ident = "MSI IM-945GSE-A",
597e3adcf8fSFrançois Tigeot 		.matches = {
598e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
599e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
600e3adcf8fSFrançois Tigeot 		},
601e3adcf8fSFrançois Tigeot 	},
602e3adcf8fSFrançois Tigeot 	{
603e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
604e3adcf8fSFrançois Tigeot 		.ident = "Dell Studio Hybrid",
605e3adcf8fSFrançois Tigeot 		.matches = {
606e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
607e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
608e3adcf8fSFrançois Tigeot 		},
609e3adcf8fSFrançois Tigeot 	},
610e3adcf8fSFrançois Tigeot 	{
611e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
612e3adcf8fSFrançois Tigeot 		.ident = "Dell OptiPlex FX170",
613e3adcf8fSFrançois Tigeot 		.matches = {
614e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
615e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
616e3adcf8fSFrançois Tigeot 		},
617e3adcf8fSFrançois Tigeot 	},
618e3adcf8fSFrançois Tigeot 	{
619e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
620e3adcf8fSFrançois Tigeot 		.ident = "AOpen Mini PC",
621e3adcf8fSFrançois Tigeot 		.matches = {
622e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
623e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
624e3adcf8fSFrançois Tigeot 		},
625e3adcf8fSFrançois Tigeot 	},
626e3adcf8fSFrançois Tigeot 	{
627e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
628e3adcf8fSFrançois Tigeot 		.ident = "AOpen Mini PC MP915",
629e3adcf8fSFrançois Tigeot 		.matches = {
630e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
631e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
632e3adcf8fSFrançois Tigeot 		},
633e3adcf8fSFrançois Tigeot 	},
634e3adcf8fSFrançois Tigeot 	{
635e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
636e3adcf8fSFrançois Tigeot 		.ident = "AOpen i915GMm-HFS",
637e3adcf8fSFrançois Tigeot 		.matches = {
638e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
639e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
640e3adcf8fSFrançois Tigeot 		},
641e3adcf8fSFrançois Tigeot 	},
642e3adcf8fSFrançois Tigeot 	{
643e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
644e3adcf8fSFrançois Tigeot                 .ident = "AOpen i45GMx-I",
645e3adcf8fSFrançois Tigeot                 .matches = {
646e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
647e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
648e3adcf8fSFrançois Tigeot                 },
649e3adcf8fSFrançois Tigeot         },
650e3adcf8fSFrançois Tigeot 	{
651e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
652e3adcf8fSFrançois Tigeot 		.ident = "Aopen i945GTt-VFA",
653e3adcf8fSFrançois Tigeot 		.matches = {
654e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
655e3adcf8fSFrançois Tigeot 		},
656e3adcf8fSFrançois Tigeot 	},
657e3adcf8fSFrançois Tigeot 	{
658e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
659e3adcf8fSFrançois Tigeot 		.ident = "Clientron U800",
660e3adcf8fSFrançois Tigeot 		.matches = {
661e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
662e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
663e3adcf8fSFrançois Tigeot 		},
664e3adcf8fSFrançois Tigeot 	},
665e3adcf8fSFrançois Tigeot 	{
666e3adcf8fSFrançois Tigeot                 .callback = intel_no_lvds_dmi_callback,
667e3adcf8fSFrançois Tigeot                 .ident = "Clientron E830",
668e3adcf8fSFrançois Tigeot                 .matches = {
669e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
670e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
671e3adcf8fSFrançois Tigeot                 },
672e3adcf8fSFrançois Tigeot         },
673e3adcf8fSFrançois Tigeot         {
674e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
675e3adcf8fSFrançois Tigeot 		.ident = "Asus EeeBox PC EB1007",
676e3adcf8fSFrançois Tigeot 		.matches = {
677e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
678e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
679e3adcf8fSFrançois Tigeot 		},
680e3adcf8fSFrançois Tigeot 	},
681e3adcf8fSFrançois Tigeot 	{
682e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
683e3adcf8fSFrançois Tigeot 		.ident = "Asus AT5NM10T-I",
684e3adcf8fSFrançois Tigeot 		.matches = {
685e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
686e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
687e3adcf8fSFrançois Tigeot 		},
688e3adcf8fSFrançois Tigeot 	},
689e3adcf8fSFrançois Tigeot 	{
690e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
691a2fdbec6SFrançois Tigeot 		.ident = "Hewlett-Packard HP t5740",
69219df918dSFrançois Tigeot 		.matches = {
69319df918dSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
694a2fdbec6SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
69519df918dSFrançois Tigeot 		},
69619df918dSFrançois Tigeot 	},
69719df918dSFrançois Tigeot 	{
69819df918dSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
699e3adcf8fSFrançois Tigeot 		.ident = "Hewlett-Packard t5745",
700e3adcf8fSFrançois Tigeot 		.matches = {
701e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
702e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
703e3adcf8fSFrançois Tigeot 		},
704e3adcf8fSFrançois Tigeot 	},
705e3adcf8fSFrançois Tigeot 	{
706e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
707e3adcf8fSFrançois Tigeot 		.ident = "Hewlett-Packard st5747",
708e3adcf8fSFrançois Tigeot 		.matches = {
709e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
710e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
711e3adcf8fSFrançois Tigeot 		},
712e3adcf8fSFrançois Tigeot 	},
713e3adcf8fSFrançois Tigeot 	{
714e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
715e3adcf8fSFrançois Tigeot 		.ident = "MSI Wind Box DC500",
716e3adcf8fSFrançois Tigeot 		.matches = {
717e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
718e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
719e3adcf8fSFrançois Tigeot 		},
720e3adcf8fSFrançois Tigeot 	},
721e3adcf8fSFrançois Tigeot 	{
722e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
72319df918dSFrançois Tigeot 		.ident = "Gigabyte GA-D525TUD",
72419df918dSFrançois Tigeot 		.matches = {
72519df918dSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
72619df918dSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
72719df918dSFrançois Tigeot 		},
72819df918dSFrançois Tigeot 	},
72919df918dSFrançois Tigeot 	{
73019df918dSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
731e3adcf8fSFrançois Tigeot 		.ident = "Supermicro X7SPA-H",
732e3adcf8fSFrançois Tigeot 		.matches = {
733e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
734e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
735e3adcf8fSFrançois Tigeot 		},
736e3adcf8fSFrançois Tigeot 	},
73719df918dSFrançois Tigeot 	{
73819df918dSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
73919df918dSFrançois Tigeot 		.ident = "Fujitsu Esprimo Q900",
74019df918dSFrançois Tigeot 		.matches = {
74119df918dSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
74219df918dSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
74319df918dSFrançois Tigeot 		},
74419df918dSFrançois Tigeot 	},
7455d0b1887SFrançois Tigeot 	{
7465d0b1887SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7479edbd4a0SFrançois Tigeot 		.ident = "Intel D410PT",
7489edbd4a0SFrançois Tigeot 		.matches = {
7499edbd4a0SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7509edbd4a0SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "D410PT"),
7519edbd4a0SFrançois Tigeot 		},
7529edbd4a0SFrançois Tigeot 	},
7539edbd4a0SFrançois Tigeot 	{
7549edbd4a0SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7559edbd4a0SFrançois Tigeot 		.ident = "Intel D425KT",
7569edbd4a0SFrançois Tigeot 		.matches = {
7579edbd4a0SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7589edbd4a0SFrançois Tigeot 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "D425KT"),
7599edbd4a0SFrançois Tigeot 		},
7609edbd4a0SFrançois Tigeot 	},
7619edbd4a0SFrançois Tigeot 	{
7629edbd4a0SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7635d0b1887SFrançois Tigeot 		.ident = "Intel D510MO",
7645d0b1887SFrançois Tigeot 		.matches = {
7655d0b1887SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7665d0b1887SFrançois Tigeot 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
7675d0b1887SFrançois Tigeot 		},
7685d0b1887SFrançois Tigeot 	},
7695d0b1887SFrançois Tigeot 	{
7705d0b1887SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7715d0b1887SFrançois Tigeot 		.ident = "Intel D525MW",
7725d0b1887SFrançois Tigeot 		.matches = {
7735d0b1887SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7745d0b1887SFrançois Tigeot 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
7755d0b1887SFrançois Tigeot 		},
7765d0b1887SFrançois Tigeot 	},
777e3adcf8fSFrançois Tigeot 
778e3adcf8fSFrançois Tigeot 	{ }	/* terminating entry */
779e3adcf8fSFrançois Tigeot };
780e3adcf8fSFrançois Tigeot 
781a2fdbec6SFrançois Tigeot static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
782a2fdbec6SFrançois Tigeot {
783a2fdbec6SFrançois Tigeot 	DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
784a2fdbec6SFrançois Tigeot 	return 1;
785a2fdbec6SFrançois Tigeot }
786a2fdbec6SFrançois Tigeot 
787a2fdbec6SFrançois Tigeot static const struct dmi_system_id intel_dual_link_lvds[] = {
788a2fdbec6SFrançois Tigeot 	{
789a2fdbec6SFrançois Tigeot 		.callback = intel_dual_link_lvds_callback,
790477eb7f9SFrançois Tigeot 		.ident = "Apple MacBook Pro 15\" (2010)",
791477eb7f9SFrançois Tigeot 		.matches = {
792477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
793477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6,2"),
794477eb7f9SFrançois Tigeot 		},
795477eb7f9SFrançois Tigeot 	},
796477eb7f9SFrançois Tigeot 	{
797477eb7f9SFrançois Tigeot 		.callback = intel_dual_link_lvds_callback,
798477eb7f9SFrançois Tigeot 		.ident = "Apple MacBook Pro 15\" (2011)",
799a2fdbec6SFrançois Tigeot 		.matches = {
800a2fdbec6SFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
801a2fdbec6SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
802a2fdbec6SFrançois Tigeot 		},
803a2fdbec6SFrançois Tigeot 	},
804477eb7f9SFrançois Tigeot 	{
805477eb7f9SFrançois Tigeot 		.callback = intel_dual_link_lvds_callback,
806477eb7f9SFrançois Tigeot 		.ident = "Apple MacBook Pro 15\" (2012)",
807477eb7f9SFrançois Tigeot 		.matches = {
808477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
809477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,1"),
810477eb7f9SFrançois Tigeot 		},
811477eb7f9SFrançois Tigeot 	},
812a2fdbec6SFrançois Tigeot 	{ }	/* terminating entry */
813a2fdbec6SFrançois Tigeot };
814a2fdbec6SFrançois Tigeot 
815a2fdbec6SFrançois Tigeot bool intel_is_dual_link_lvds(struct drm_device *dev)
816a2fdbec6SFrançois Tigeot {
817a2fdbec6SFrançois Tigeot 	struct intel_encoder *encoder;
818a2fdbec6SFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder;
819a2fdbec6SFrançois Tigeot 
8201b13d190SFrançois Tigeot 	for_each_intel_encoder(dev, encoder) {
821a2fdbec6SFrançois Tigeot 		if (encoder->type == INTEL_OUTPUT_LVDS) {
822a2fdbec6SFrançois Tigeot 			lvds_encoder = to_lvds_encoder(&encoder->base);
823a2fdbec6SFrançois Tigeot 
824a2fdbec6SFrançois Tigeot 			return lvds_encoder->is_dual_link;
825a2fdbec6SFrançois Tigeot 		}
826a2fdbec6SFrançois Tigeot 	}
827a2fdbec6SFrançois Tigeot 
828a2fdbec6SFrançois Tigeot 	return false;
829a2fdbec6SFrançois Tigeot }
830a2fdbec6SFrançois Tigeot 
831a2fdbec6SFrançois Tigeot static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
832a2fdbec6SFrançois Tigeot {
833a2fdbec6SFrançois Tigeot 	struct drm_device *dev = lvds_encoder->base.base.dev;
834a2fdbec6SFrançois Tigeot 	unsigned int val;
835a2fdbec6SFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
836a2fdbec6SFrançois Tigeot 
837a2fdbec6SFrançois Tigeot 	/* use the module option value if specified */
838ba55f2f5SFrançois Tigeot 	if (i915.lvds_channel_mode > 0)
839ba55f2f5SFrançois Tigeot 		return i915.lvds_channel_mode == 2;
840a2fdbec6SFrançois Tigeot 
841477eb7f9SFrançois Tigeot 	/* single channel LVDS is limited to 112 MHz */
842477eb7f9SFrançois Tigeot 	if (lvds_encoder->attached_connector->base.panel.fixed_mode->clock
843477eb7f9SFrançois Tigeot 	    > 112999)
844477eb7f9SFrançois Tigeot 		return true;
845477eb7f9SFrançois Tigeot 
846a2fdbec6SFrançois Tigeot 	if (dmi_check_system(intel_dual_link_lvds))
847a2fdbec6SFrançois Tigeot 		return true;
848a2fdbec6SFrançois Tigeot 
849a2fdbec6SFrançois Tigeot 	/* BIOS should set the proper LVDS register value at boot, but
850a2fdbec6SFrançois Tigeot 	 * in reality, it doesn't set the value when the lid is closed;
851a2fdbec6SFrançois Tigeot 	 * we need to check "the value to be set" in VBT when LVDS
852a2fdbec6SFrançois Tigeot 	 * register is uninitialized.
853a2fdbec6SFrançois Tigeot 	 */
854a2fdbec6SFrançois Tigeot 	val = I915_READ(lvds_encoder->reg);
855a2fdbec6SFrançois Tigeot 	if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
8565d0b1887SFrançois Tigeot 		val = dev_priv->vbt.bios_lvds_val;
857a2fdbec6SFrançois Tigeot 
858a2fdbec6SFrançois Tigeot 	return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
859a2fdbec6SFrançois Tigeot }
860a2fdbec6SFrançois Tigeot 
861e3adcf8fSFrançois Tigeot static bool intel_lvds_supported(struct drm_device *dev)
862e3adcf8fSFrançois Tigeot {
863e3adcf8fSFrançois Tigeot 	/* With the introduction of the PCH we gained a dedicated
864e3adcf8fSFrançois Tigeot 	 * LVDS presence pin, use it. */
8658e26cdf6SFrançois Tigeot 	if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
866e3adcf8fSFrançois Tigeot 		return true;
867e3adcf8fSFrançois Tigeot 
868e3adcf8fSFrançois Tigeot 	/* Otherwise LVDS was only attached to mobile products,
869e3adcf8fSFrançois Tigeot 	 * except for the inglorious 830gm */
8708e26cdf6SFrançois Tigeot 	if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
8718e26cdf6SFrançois Tigeot 		return true;
8728e26cdf6SFrançois Tigeot 
8738e26cdf6SFrançois Tigeot 	return false;
874e3adcf8fSFrançois Tigeot }
875e3adcf8fSFrançois Tigeot 
876e3adcf8fSFrançois Tigeot /**
877e3adcf8fSFrançois Tigeot  * intel_lvds_init - setup LVDS connectors on this device
878e3adcf8fSFrançois Tigeot  * @dev: drm device
879e3adcf8fSFrançois Tigeot  *
880e3adcf8fSFrançois Tigeot  * Create the connector, register the LVDS DDC bus, and try to figure out what
881e3adcf8fSFrançois Tigeot  * modes we can display on the LVDS panel (if present).
882e3adcf8fSFrançois Tigeot  */
8835d0b1887SFrançois Tigeot void intel_lvds_init(struct drm_device *dev)
884e3adcf8fSFrançois Tigeot {
885e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
88619df918dSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder;
887e3adcf8fSFrançois Tigeot 	struct intel_encoder *intel_encoder;
88819df918dSFrançois Tigeot 	struct intel_lvds_connector *lvds_connector;
889e3adcf8fSFrançois Tigeot 	struct intel_connector *intel_connector;
890e3adcf8fSFrançois Tigeot 	struct drm_connector *connector;
891e3adcf8fSFrançois Tigeot 	struct drm_encoder *encoder;
892e3adcf8fSFrançois Tigeot 	struct drm_display_mode *scan; /* *modes, *bios_mode; */
89319df918dSFrançois Tigeot 	struct drm_display_mode *fixed_mode = NULL;
894ba55f2f5SFrançois Tigeot 	struct drm_display_mode *downclock_mode = NULL;
89519df918dSFrançois Tigeot 	struct edid *edid;
896e3adcf8fSFrançois Tigeot 	struct drm_crtc *crtc;
897aee94f86SFrançois Tigeot 	i915_reg_t lvds_reg;
898e3adcf8fSFrançois Tigeot 	u32 lvds;
899e3adcf8fSFrançois Tigeot 	int pipe;
900e3adcf8fSFrançois Tigeot 	u8 pin;
901e3adcf8fSFrançois Tigeot 
9021b13d190SFrançois Tigeot 	/*
9031b13d190SFrançois Tigeot 	 * Unlock registers and just leave them unlocked. Do this before
9041b13d190SFrançois Tigeot 	 * checking quirk lists to avoid bogus WARNINGs.
9051b13d190SFrançois Tigeot 	 */
9061b13d190SFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
9071b13d190SFrançois Tigeot 		I915_WRITE(PCH_PP_CONTROL,
9081b13d190SFrançois Tigeot 			   I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
909352ff8bdSFrançois Tigeot 	} else if (INTEL_INFO(dev_priv)->gen < 5) {
9101b13d190SFrançois Tigeot 		I915_WRITE(PP_CONTROL,
9111b13d190SFrançois Tigeot 			   I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
9121b13d190SFrançois Tigeot 	}
913e3adcf8fSFrançois Tigeot 	if (!intel_lvds_supported(dev))
9145d0b1887SFrançois Tigeot 		return;
915e3adcf8fSFrançois Tigeot 
916e3adcf8fSFrançois Tigeot 	/* Skip init on machines we know falsely report LVDS */
917e3adcf8fSFrançois Tigeot 	if (dmi_check_system(intel_no_lvds))
9185d0b1887SFrançois Tigeot 		return;
919e3adcf8fSFrançois Tigeot 
920352ff8bdSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev))
921352ff8bdSFrançois Tigeot 		lvds_reg = PCH_LVDS;
922352ff8bdSFrançois Tigeot 	else
923352ff8bdSFrançois Tigeot 		lvds_reg = LVDS;
924352ff8bdSFrançois Tigeot 
925352ff8bdSFrançois Tigeot 	lvds = I915_READ(lvds_reg);
926352ff8bdSFrançois Tigeot 
927e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
928352ff8bdSFrançois Tigeot 		if ((lvds & LVDS_DETECTED) == 0)
9295d0b1887SFrançois Tigeot 			return;
9308621f407SFrançois Tigeot 		if (dev_priv->vbt.edp.support) {
931e3adcf8fSFrançois Tigeot 			DRM_DEBUG_KMS("disable LVDS for eDP support\n");
9325d0b1887SFrançois Tigeot 			return;
933e3adcf8fSFrançois Tigeot 		}
934e3adcf8fSFrançois Tigeot 	}
935e3adcf8fSFrançois Tigeot 
936a05eeebfSFrançois Tigeot 	pin = GMBUS_PIN_PANEL;
9378621f407SFrançois Tigeot 	if (!intel_bios_is_lvds_present(dev_priv, &pin)) {
938352ff8bdSFrançois Tigeot 		if ((lvds & LVDS_PORT_EN) == 0) {
939a05eeebfSFrançois Tigeot 			DRM_DEBUG_KMS("LVDS is not present in VBT\n");
940a05eeebfSFrançois Tigeot 			return;
941a05eeebfSFrançois Tigeot 		}
942a05eeebfSFrançois Tigeot 		DRM_DEBUG_KMS("LVDS is not present in VBT, but enabled anyway\n");
943a05eeebfSFrançois Tigeot 	}
944a05eeebfSFrançois Tigeot 
945352ff8bdSFrançois Tigeot 	 /* Set the Panel Power On/Off timings if uninitialized. */
946352ff8bdSFrançois Tigeot 	if (INTEL_INFO(dev_priv)->gen < 5 &&
947352ff8bdSFrançois Tigeot 	    I915_READ(PP_ON_DELAYS) == 0 && I915_READ(PP_OFF_DELAYS) == 0) {
948352ff8bdSFrançois Tigeot 		/* Set T2 to 40ms and T5 to 200ms */
949352ff8bdSFrançois Tigeot 		I915_WRITE(PP_ON_DELAYS, 0x019007d0);
950352ff8bdSFrançois Tigeot 
951352ff8bdSFrançois Tigeot 		/* Set T3 to 35ms and Tx to 200ms */
952352ff8bdSFrançois Tigeot 		I915_WRITE(PP_OFF_DELAYS, 0x015e07d0);
953352ff8bdSFrançois Tigeot 
954352ff8bdSFrançois Tigeot 		DRM_DEBUG_KMS("Panel power timings uninitialized, setting defaults\n");
955352ff8bdSFrançois Tigeot 	}
956352ff8bdSFrançois Tigeot 
9579edbd4a0SFrançois Tigeot 	lvds_encoder = kzalloc(sizeof(*lvds_encoder), GFP_KERNEL);
95819df918dSFrançois Tigeot 	if (!lvds_encoder)
9595d0b1887SFrançois Tigeot 		return;
960e3adcf8fSFrançois Tigeot 
9619edbd4a0SFrançois Tigeot 	lvds_connector = kzalloc(sizeof(*lvds_connector), GFP_KERNEL);
96219df918dSFrançois Tigeot 	if (!lvds_connector) {
963158486a6SFrançois Tigeot 		kfree(lvds_encoder);
9645d0b1887SFrançois Tigeot 		return;
965e3adcf8fSFrançois Tigeot 	}
966e3adcf8fSFrançois Tigeot 
967477eb7f9SFrançois Tigeot 	if (intel_connector_init(&lvds_connector->base) < 0) {
968477eb7f9SFrançois Tigeot 		kfree(lvds_connector);
969477eb7f9SFrançois Tigeot 		kfree(lvds_encoder);
970477eb7f9SFrançois Tigeot 		return;
971477eb7f9SFrançois Tigeot 	}
972477eb7f9SFrançois Tigeot 
97319df918dSFrançois Tigeot 	lvds_encoder->attached_connector = lvds_connector;
97419df918dSFrançois Tigeot 
97519df918dSFrançois Tigeot 	intel_encoder = &lvds_encoder->base;
976e3adcf8fSFrançois Tigeot 	encoder = &intel_encoder->base;
97719df918dSFrançois Tigeot 	intel_connector = &lvds_connector->base;
978e3adcf8fSFrançois Tigeot 	connector = &intel_connector->base;
979e3adcf8fSFrançois Tigeot 	drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
980e3adcf8fSFrançois Tigeot 			   DRM_MODE_CONNECTOR_LVDS);
981e3adcf8fSFrançois Tigeot 
982e3adcf8fSFrançois Tigeot 	drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
983aee94f86SFrançois Tigeot 			 DRM_MODE_ENCODER_LVDS, NULL);
984e3adcf8fSFrançois Tigeot 
98519df918dSFrançois Tigeot 	intel_encoder->enable = intel_enable_lvds;
9869edbd4a0SFrançois Tigeot 	intel_encoder->pre_enable = intel_pre_enable_lvds;
9878e26cdf6SFrançois Tigeot 	intel_encoder->compute_config = intel_lvds_compute_config;
988a05eeebfSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev_priv)) {
989a05eeebfSFrançois Tigeot 		intel_encoder->disable = pch_disable_lvds;
990a05eeebfSFrançois Tigeot 		intel_encoder->post_disable = pch_post_disable_lvds;
991a05eeebfSFrançois Tigeot 	} else {
992a05eeebfSFrançois Tigeot 		intel_encoder->disable = gmch_disable_lvds;
993a05eeebfSFrançois Tigeot 	}
99419df918dSFrançois Tigeot 	intel_encoder->get_hw_state = intel_lvds_get_hw_state;
9955d0b1887SFrançois Tigeot 	intel_encoder->get_config = intel_lvds_get_config;
99619df918dSFrançois Tigeot 	intel_connector->get_hw_state = intel_connector_get_hw_state;
997ba55f2f5SFrançois Tigeot 	intel_connector->unregister = intel_connector_unregister;
99819df918dSFrançois Tigeot 
999e3adcf8fSFrançois Tigeot 	intel_connector_attach_encoder(intel_connector, intel_encoder);
1000e3adcf8fSFrançois Tigeot 	intel_encoder->type = INTEL_OUTPUT_LVDS;
1001e3adcf8fSFrançois Tigeot 
1002ba55f2f5SFrançois Tigeot 	intel_encoder->cloneable = 0;
1003e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev))
1004e3adcf8fSFrançois Tigeot 		intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
100519df918dSFrançois Tigeot 	else if (IS_GEN4(dev))
100619df918dSFrançois Tigeot 		intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
1007e3adcf8fSFrançois Tigeot 	else
1008e3adcf8fSFrançois Tigeot 		intel_encoder->crtc_mask = (1 << 1);
1009e3adcf8fSFrançois Tigeot 
1010e3adcf8fSFrançois Tigeot 	drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
1011e3adcf8fSFrançois Tigeot 	connector->display_info.subpixel_order = SubPixelHorizontalRGB;
1012e3adcf8fSFrançois Tigeot 	connector->interlace_allowed = false;
1013e3adcf8fSFrançois Tigeot 	connector->doublescan_allowed = false;
1014e3adcf8fSFrançois Tigeot 
1015352ff8bdSFrançois Tigeot 	lvds_encoder->reg = lvds_reg;
1016a2fdbec6SFrançois Tigeot 
1017e3adcf8fSFrançois Tigeot 	/* create the scaling mode property */
1018e3adcf8fSFrançois Tigeot 	drm_mode_create_scaling_mode_property(dev);
1019b5162e19SFrançois Tigeot 	drm_object_attach_property(&connector->base,
1020e3adcf8fSFrançois Tigeot 				      dev->mode_config.scaling_mode_property,
1021e3adcf8fSFrançois Tigeot 				      DRM_MODE_SCALE_ASPECT);
102219df918dSFrançois Tigeot 	intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
1023e3adcf8fSFrançois Tigeot 	/*
1024e3adcf8fSFrançois Tigeot 	 * LVDS discovery:
1025e3adcf8fSFrançois Tigeot 	 * 1) check for EDID on DDC
1026e3adcf8fSFrançois Tigeot 	 * 2) check for VBT data
1027e3adcf8fSFrançois Tigeot 	 * 3) check to see if LVDS is already on
1028e3adcf8fSFrançois Tigeot 	 *    if none of the above, no panel
1029e3adcf8fSFrançois Tigeot 	 * 4) make sure lid is open
1030e3adcf8fSFrançois Tigeot 	 *    if closed, act like it's not there for now
1031e3adcf8fSFrançois Tigeot 	 */
1032e3adcf8fSFrançois Tigeot 
1033e3adcf8fSFrançois Tigeot 	/*
1034e3adcf8fSFrançois Tigeot 	 * Attempt to get the fixed panel mode from DDC.  Assume that the
1035e3adcf8fSFrançois Tigeot 	 * preferred mode is the right one.
1036e3adcf8fSFrançois Tigeot 	 */
1037ba55f2f5SFrançois Tigeot 	mutex_lock(&dev->mode_config.mutex);
1038c0e85e96SFrançois Tigeot 	if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC)
1039c0e85e96SFrançois Tigeot 		edid = drm_get_edid_switcheroo(connector,
1040c0e85e96SFrançois Tigeot 				    intel_gmbus_get_adapter(dev_priv, pin));
1041c0e85e96SFrançois Tigeot 	else
1042c0e85e96SFrançois Tigeot 		edid = drm_get_edid(connector,
1043c0e85e96SFrançois Tigeot 				    intel_gmbus_get_adapter(dev_priv, pin));
104419df918dSFrançois Tigeot 	if (edid) {
104519df918dSFrançois Tigeot 		if (drm_add_edid_modes(connector, edid)) {
1046e3adcf8fSFrançois Tigeot 			drm_mode_connector_update_edid_property(connector,
104719df918dSFrançois Tigeot 								edid);
1048e3adcf8fSFrançois Tigeot 		} else {
1049158486a6SFrançois Tigeot 			kfree(edid);
105019df918dSFrançois Tigeot 			edid = ERR_PTR(-EINVAL);
1051e3adcf8fSFrançois Tigeot 		}
105219df918dSFrançois Tigeot 	} else {
105319df918dSFrançois Tigeot 		edid = ERR_PTR(-ENOENT);
1054e3adcf8fSFrançois Tigeot 	}
105519df918dSFrançois Tigeot 	lvds_connector->base.edid = edid;
105619df918dSFrançois Tigeot 
105719df918dSFrançois Tigeot 	if (IS_ERR_OR_NULL(edid)) {
1058e3adcf8fSFrançois Tigeot 		/* Didn't get an EDID, so
1059e3adcf8fSFrançois Tigeot 		 * Set wide sync ranges so we get all modes
1060e3adcf8fSFrançois Tigeot 		 * handed to valid_mode for checking
1061e3adcf8fSFrançois Tigeot 		 */
1062e3adcf8fSFrançois Tigeot 		connector->display_info.min_vfreq = 0;
1063e3adcf8fSFrançois Tigeot 		connector->display_info.max_vfreq = 200;
1064e3adcf8fSFrançois Tigeot 		connector->display_info.min_hfreq = 0;
1065e3adcf8fSFrançois Tigeot 		connector->display_info.max_hfreq = 200;
1066e3adcf8fSFrançois Tigeot 	}
1067e3adcf8fSFrançois Tigeot 
1068e3adcf8fSFrançois Tigeot 	list_for_each_entry(scan, &connector->probed_modes, head) {
1069e3adcf8fSFrançois Tigeot 		if (scan->type & DRM_MODE_TYPE_PREFERRED) {
107019df918dSFrançois Tigeot 			DRM_DEBUG_KMS("using preferred mode from EDID: ");
107119df918dSFrançois Tigeot 			drm_mode_debug_printmodeline(scan);
107219df918dSFrançois Tigeot 
107319df918dSFrançois Tigeot 			fixed_mode = drm_mode_duplicate(dev, scan);
1074a05eeebfSFrançois Tigeot 			if (fixed_mode)
1075e3adcf8fSFrançois Tigeot 				goto out;
1076e3adcf8fSFrançois Tigeot 		}
1077e3adcf8fSFrançois Tigeot 	}
1078e3adcf8fSFrançois Tigeot 
1079e3adcf8fSFrançois Tigeot 	/* Failed to get EDID, what about VBT? */
10805d0b1887SFrançois Tigeot 	if (dev_priv->vbt.lfp_lvds_vbt_mode) {
108119df918dSFrançois Tigeot 		DRM_DEBUG_KMS("using mode from VBT: ");
10825d0b1887SFrançois Tigeot 		drm_mode_debug_printmodeline(dev_priv->vbt.lfp_lvds_vbt_mode);
108319df918dSFrançois Tigeot 
10845d0b1887SFrançois Tigeot 		fixed_mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
108519df918dSFrançois Tigeot 		if (fixed_mode) {
108619df918dSFrançois Tigeot 			fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
10878621f407SFrançois Tigeot 			connector->display_info.width_mm = fixed_mode->width_mm;
10888621f407SFrançois Tigeot 			connector->display_info.height_mm = fixed_mode->height_mm;
1089e3adcf8fSFrançois Tigeot 			goto out;
1090e3adcf8fSFrançois Tigeot 		}
1091e3adcf8fSFrançois Tigeot 	}
1092e3adcf8fSFrançois Tigeot 
1093e3adcf8fSFrançois Tigeot 	/*
1094e3adcf8fSFrançois Tigeot 	 * If we didn't get EDID, try checking if the panel is already turned
1095e3adcf8fSFrançois Tigeot 	 * on.  If so, assume that whatever is currently programmed is the
1096e3adcf8fSFrançois Tigeot 	 * correct mode.
1097e3adcf8fSFrançois Tigeot 	 */
1098e3adcf8fSFrançois Tigeot 
1099e3adcf8fSFrançois Tigeot 	/* Ironlake: FIXME if still fail, not try pipe mode now */
1100e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev))
1101e3adcf8fSFrançois Tigeot 		goto failed;
1102e3adcf8fSFrançois Tigeot 
1103e3adcf8fSFrançois Tigeot 	pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
1104e3adcf8fSFrançois Tigeot 	crtc = intel_get_crtc_for_pipe(dev, pipe);
1105e3adcf8fSFrançois Tigeot 
1106e3adcf8fSFrançois Tigeot 	if (crtc && (lvds & LVDS_PORT_EN)) {
110719df918dSFrançois Tigeot 		fixed_mode = intel_crtc_mode_get(dev, crtc);
110819df918dSFrançois Tigeot 		if (fixed_mode) {
110919df918dSFrançois Tigeot 			DRM_DEBUG_KMS("using current (BIOS) mode: ");
111019df918dSFrançois Tigeot 			drm_mode_debug_printmodeline(fixed_mode);
111119df918dSFrançois Tigeot 			fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1112e3adcf8fSFrançois Tigeot 			goto out;
1113e3adcf8fSFrançois Tigeot 		}
1114e3adcf8fSFrançois Tigeot 	}
1115e3adcf8fSFrançois Tigeot 
1116e3adcf8fSFrançois Tigeot 	/* If we still don't have a mode after all that, give up. */
111719df918dSFrançois Tigeot 	if (!fixed_mode)
1118e3adcf8fSFrançois Tigeot 		goto failed;
1119e3adcf8fSFrançois Tigeot 
1120e3adcf8fSFrançois Tigeot out:
1121ba55f2f5SFrançois Tigeot 	mutex_unlock(&dev->mode_config.mutex);
1122ba55f2f5SFrançois Tigeot 
1123477eb7f9SFrançois Tigeot 	intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
1124477eb7f9SFrançois Tigeot 
1125a2fdbec6SFrançois Tigeot 	lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
1126a2fdbec6SFrançois Tigeot 	DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
1127a2fdbec6SFrançois Tigeot 		      lvds_encoder->is_dual_link ? "dual" : "single");
1128a2fdbec6SFrançois Tigeot 
1129aee94f86SFrançois Tigeot 	lvds_encoder->a3_power = lvds & LVDS_A3_POWER_MASK;
113024edb884SFrançois Tigeot 
1131e3adcf8fSFrançois Tigeot #if 0
113219df918dSFrançois Tigeot 	lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
113319df918dSFrançois Tigeot 	if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
113419df918dSFrançois Tigeot 		DRM_DEBUG_KMS("lid notifier registration failed\n");
113519df918dSFrançois Tigeot 		lvds_connector->lid_notifier.notifier_call = NULL;
113619df918dSFrançois Tigeot 	}
1137c6f73aabSFrançois Tigeot 	drm_connector_register(connector);
1138e3adcf8fSFrançois Tigeot #endif
113919df918dSFrançois Tigeot 
11402c9916cdSFrançois Tigeot 	intel_panel_setup_backlight(connector, INVALID_PIPE);
114119df918dSFrançois Tigeot 
11425d0b1887SFrançois Tigeot 	return;
1143e3adcf8fSFrançois Tigeot 
1144e3adcf8fSFrançois Tigeot failed:
1145ba55f2f5SFrançois Tigeot 	mutex_unlock(&dev->mode_config.mutex);
1146ba55f2f5SFrançois Tigeot 
1147e3adcf8fSFrançois Tigeot 	DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
1148e3adcf8fSFrançois Tigeot 	drm_connector_cleanup(connector);
1149e3adcf8fSFrançois Tigeot 	drm_encoder_cleanup(encoder);
1150158486a6SFrançois Tigeot 	kfree(lvds_encoder);
1151158486a6SFrançois Tigeot 	kfree(lvds_connector);
11525d0b1887SFrançois Tigeot 	return;
1153e3adcf8fSFrançois Tigeot }
1154