xref: /dflybsd-src/sys/dev/drm/i915/intel_lvds.c (revision aee94f86171368465eaa15d649743f13cea3363a)
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  */
29e3adcf8fSFrançois Tigeot 
305d0b1887SFrançois Tigeot #include <linux/dmi.h>
31a2fdbec6SFrançois Tigeot #include <linux/i2c.h>
3218e26a6dSFrançois Tigeot #include <drm/drmP.h>
332c9916cdSFrançois Tigeot #include <drm/drm_atomic_helper.h>
3418e26a6dSFrançois Tigeot #include <drm/drm_crtc.h>
3518e26a6dSFrançois Tigeot #include <drm/drm_edid.h>
3618e26a6dSFrançois Tigeot #include "intel_drv.h"
375c6c6f23SFrançois Tigeot #include <drm/i915_drm.h>
38e3adcf8fSFrançois Tigeot #include "i915_drv.h"
39e3adcf8fSFrançois Tigeot 
40e3adcf8fSFrançois Tigeot /* Private structure for the integrated LVDS support */
4119df918dSFrançois Tigeot struct intel_lvds_connector {
4219df918dSFrançois Tigeot 	struct intel_connector base;
4319df918dSFrançois Tigeot 
4419df918dSFrançois Tigeot 	struct notifier_block lid_notifier;
4519df918dSFrançois Tigeot };
4619df918dSFrançois Tigeot 
4719df918dSFrançois Tigeot struct intel_lvds_encoder {
48e3adcf8fSFrançois Tigeot 	struct intel_encoder base;
49e3adcf8fSFrançois Tigeot 
50a2fdbec6SFrançois Tigeot 	bool is_dual_link;
51*aee94f86SFrançois Tigeot 	i915_reg_t reg;
5224edb884SFrançois Tigeot 	u32 a3_power;
53e3adcf8fSFrançois Tigeot 
5419df918dSFrançois Tigeot 	struct intel_lvds_connector *attached_connector;
55e3adcf8fSFrançois Tigeot };
56e3adcf8fSFrançois Tigeot 
5719df918dSFrançois Tigeot static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
58e3adcf8fSFrançois Tigeot {
5919df918dSFrançois Tigeot 	return container_of(encoder, struct intel_lvds_encoder, base.base);
60e3adcf8fSFrançois Tigeot }
61e3adcf8fSFrançois Tigeot 
6219df918dSFrançois Tigeot static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
63e3adcf8fSFrançois Tigeot {
6419df918dSFrançois Tigeot 	return container_of(connector, struct intel_lvds_connector, base.base);
6519df918dSFrançois Tigeot }
6619df918dSFrançois Tigeot 
6719df918dSFrançois Tigeot static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
6819df918dSFrançois Tigeot 				    enum i915_pipe *pipe)
6919df918dSFrançois Tigeot {
7019df918dSFrançois Tigeot 	struct drm_device *dev = encoder->base.dev;
7119df918dSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
72a2fdbec6SFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
7324edb884SFrançois Tigeot 	enum intel_display_power_domain power_domain;
74a2fdbec6SFrançois Tigeot 	u32 tmp;
75*aee94f86SFrançois Tigeot 	bool ret;
7619df918dSFrançois Tigeot 
7724edb884SFrançois Tigeot 	power_domain = intel_display_port_power_domain(encoder);
78*aee94f86SFrançois Tigeot 	if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
7924edb884SFrançois Tigeot 		return false;
8024edb884SFrançois Tigeot 
81*aee94f86SFrançois Tigeot 	ret = false;
82*aee94f86SFrançois Tigeot 
83a2fdbec6SFrançois Tigeot 	tmp = I915_READ(lvds_encoder->reg);
8419df918dSFrançois Tigeot 
8519df918dSFrançois Tigeot 	if (!(tmp & LVDS_PORT_EN))
86*aee94f86SFrançois Tigeot 		goto out;
8719df918dSFrançois Tigeot 
8819df918dSFrançois Tigeot 	if (HAS_PCH_CPT(dev))
8919df918dSFrançois Tigeot 		*pipe = PORT_TO_PIPE_CPT(tmp);
9019df918dSFrançois Tigeot 	else
9119df918dSFrançois Tigeot 		*pipe = PORT_TO_PIPE(tmp);
9219df918dSFrançois Tigeot 
93*aee94f86SFrançois Tigeot 	ret = true;
94*aee94f86SFrançois Tigeot 
95*aee94f86SFrançois Tigeot out:
96*aee94f86SFrançois Tigeot 	intel_display_power_put(dev_priv, power_domain);
97*aee94f86SFrançois Tigeot 
98*aee94f86SFrançois Tigeot 	return ret;
99e3adcf8fSFrançois Tigeot }
100e3adcf8fSFrançois Tigeot 
1015d0b1887SFrançois Tigeot static void intel_lvds_get_config(struct intel_encoder *encoder,
1022c9916cdSFrançois Tigeot 				  struct intel_crtc_state *pipe_config)
1035d0b1887SFrançois Tigeot {
1045d0b1887SFrançois Tigeot 	struct drm_device *dev = encoder->base.dev;
1055d0b1887SFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
106352ff8bdSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
107352ff8bdSFrançois Tigeot 	u32 tmp, flags = 0;
1089edbd4a0SFrançois Tigeot 	int dotclock;
1095d0b1887SFrançois Tigeot 
110352ff8bdSFrançois Tigeot 	tmp = I915_READ(lvds_encoder->reg);
1115d0b1887SFrançois Tigeot 	if (tmp & LVDS_HSYNC_POLARITY)
1125d0b1887SFrançois Tigeot 		flags |= DRM_MODE_FLAG_NHSYNC;
1135d0b1887SFrançois Tigeot 	else
1145d0b1887SFrançois Tigeot 		flags |= DRM_MODE_FLAG_PHSYNC;
1155d0b1887SFrançois Tigeot 	if (tmp & LVDS_VSYNC_POLARITY)
1165d0b1887SFrançois Tigeot 		flags |= DRM_MODE_FLAG_NVSYNC;
1175d0b1887SFrançois Tigeot 	else
1185d0b1887SFrançois Tigeot 		flags |= DRM_MODE_FLAG_PVSYNC;
1195d0b1887SFrançois Tigeot 
1202c9916cdSFrançois Tigeot 	pipe_config->base.adjusted_mode.flags |= flags;
1215d0b1887SFrançois Tigeot 
1225d0b1887SFrançois Tigeot 	/* gen2/3 store dither state in pfit control, needs to match */
1235d0b1887SFrançois Tigeot 	if (INTEL_INFO(dev)->gen < 4) {
1245d0b1887SFrançois Tigeot 		tmp = I915_READ(PFIT_CONTROL);
1255d0b1887SFrançois Tigeot 
1265d0b1887SFrançois Tigeot 		pipe_config->gmch_pfit.control |= tmp & PANEL_8TO6_DITHER_ENABLE;
1275d0b1887SFrançois Tigeot 	}
1289edbd4a0SFrançois Tigeot 
1299edbd4a0SFrançois Tigeot 	dotclock = pipe_config->port_clock;
1309edbd4a0SFrançois Tigeot 
1319edbd4a0SFrançois Tigeot 	if (HAS_PCH_SPLIT(dev_priv->dev))
1329edbd4a0SFrançois Tigeot 		ironlake_check_encoder_dotclock(pipe_config, dotclock);
1339edbd4a0SFrançois Tigeot 
1342c9916cdSFrançois Tigeot 	pipe_config->base.adjusted_mode.crtc_clock = dotclock;
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,
1509edbd4a0SFrançois Tigeot 					    intel_crtc_to_shared_dpll(crtc));
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;
218*aee94f86SFranç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;
243*aee94f86SFranç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 	 */
4789edbd4a0SFrançois Tigeot 	if (!HAS_PCH_SPLIT(dev)) {
479a2fdbec6SFrançois Tigeot 		drm_modeset_lock_all(dev);
480a05eeebfSFrançois Tigeot 		intel_display_resume(dev);
481a2fdbec6SFrançois Tigeot 		drm_modeset_unlock_all(dev);
4829edbd4a0SFrançois Tigeot 	}
483e3adcf8fSFrançois Tigeot 
484a2fdbec6SFrançois Tigeot 	dev_priv->modeset_restore = MODESET_DONE;
485a2fdbec6SFrançois Tigeot 
486a2fdbec6SFrançois Tigeot exit:
487a2fdbec6SFrançois Tigeot 	mutex_unlock(&dev_priv->modeset_restore_lock);
488e3adcf8fSFrançois Tigeot 	return NOTIFY_OK;
489e3adcf8fSFrançois Tigeot }
490e3adcf8fSFrançois Tigeot #endif
491e3adcf8fSFrançois Tigeot 
492e3adcf8fSFrançois Tigeot /**
493e3adcf8fSFrançois Tigeot  * intel_lvds_destroy - unregister and free LVDS structures
494e3adcf8fSFrançois Tigeot  * @connector: connector to free
495e3adcf8fSFrançois Tigeot  *
496e3adcf8fSFrançois Tigeot  * Unregister the DDC bus for this connector then free the driver private
497e3adcf8fSFrançois Tigeot  * structure.
498e3adcf8fSFrançois Tigeot  */
499e3adcf8fSFrançois Tigeot static void intel_lvds_destroy(struct drm_connector *connector)
500e3adcf8fSFrançois Tigeot {
50119df918dSFrançois Tigeot 	struct intel_lvds_connector *lvds_connector =
50219df918dSFrançois Tigeot 		to_lvds_connector(connector);
503e3adcf8fSFrançois Tigeot 
504e3adcf8fSFrançois Tigeot #if 0
50519df918dSFrançois Tigeot 	if (lvds_connector->lid_notifier.notifier_call)
50619df918dSFrançois Tigeot 		acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
507e3adcf8fSFrançois Tigeot #endif
50819df918dSFrançois Tigeot 
50919df918dSFrançois Tigeot 	if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
510158486a6SFrançois Tigeot 		kfree(lvds_connector->base.edid);
51119df918dSFrançois Tigeot 
51219df918dSFrançois Tigeot 	intel_panel_fini(&lvds_connector->base.panel);
51319df918dSFrançois Tigeot 
514e3adcf8fSFrançois Tigeot 	drm_connector_cleanup(connector);
515158486a6SFrançois Tigeot 	kfree(connector);
516e3adcf8fSFrançois Tigeot }
517e3adcf8fSFrançois Tigeot 
518e3adcf8fSFrançois Tigeot static int intel_lvds_set_property(struct drm_connector *connector,
519e3adcf8fSFrançois Tigeot 				   struct drm_property *property,
520e3adcf8fSFrançois Tigeot 				   uint64_t value)
521e3adcf8fSFrançois Tigeot {
52219df918dSFrançois Tigeot 	struct intel_connector *intel_connector = to_intel_connector(connector);
523e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
524e3adcf8fSFrançois Tigeot 
525e3adcf8fSFrançois Tigeot 	if (property == dev->mode_config.scaling_mode_property) {
52619df918dSFrançois Tigeot 		struct drm_crtc *crtc;
527e3adcf8fSFrançois Tigeot 
528e3adcf8fSFrançois Tigeot 		if (value == DRM_MODE_SCALE_NONE) {
529e3adcf8fSFrançois Tigeot 			DRM_DEBUG_KMS("no scaling not supported\n");
530e3adcf8fSFrançois Tigeot 			return -EINVAL;
531e3adcf8fSFrançois Tigeot 		}
532e3adcf8fSFrançois Tigeot 
53319df918dSFrançois Tigeot 		if (intel_connector->panel.fitting_mode == value) {
534e3adcf8fSFrançois Tigeot 			/* the LVDS scaling property is not changed */
535e3adcf8fSFrançois Tigeot 			return 0;
536e3adcf8fSFrançois Tigeot 		}
53719df918dSFrançois Tigeot 		intel_connector->panel.fitting_mode = value;
53819df918dSFrançois Tigeot 
53919df918dSFrançois Tigeot 		crtc = intel_attached_encoder(connector)->base.crtc;
540477eb7f9SFrançois Tigeot 		if (crtc && crtc->state->enable) {
541e3adcf8fSFrançois Tigeot 			/*
542e3adcf8fSFrançois Tigeot 			 * If the CRTC is enabled, the display will be changed
543e3adcf8fSFrançois Tigeot 			 * according to the new panel fitting mode.
544e3adcf8fSFrançois Tigeot 			 */
545a2fdbec6SFrançois Tigeot 			intel_crtc_restore_mode(crtc);
546e3adcf8fSFrançois Tigeot 		}
547e3adcf8fSFrançois Tigeot 	}
548e3adcf8fSFrançois Tigeot 
549e3adcf8fSFrançois Tigeot 	return 0;
550e3adcf8fSFrançois Tigeot }
551e3adcf8fSFrançois Tigeot 
552e3adcf8fSFrançois Tigeot static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
553e3adcf8fSFrançois Tigeot 	.get_modes = intel_lvds_get_modes,
554e3adcf8fSFrançois Tigeot 	.mode_valid = intel_lvds_mode_valid,
555e3adcf8fSFrançois Tigeot 	.best_encoder = intel_best_encoder,
556e3adcf8fSFrançois Tigeot };
557e3adcf8fSFrançois Tigeot 
558e3adcf8fSFrançois Tigeot static const struct drm_connector_funcs intel_lvds_connector_funcs = {
559a05eeebfSFrançois Tigeot 	.dpms = drm_atomic_helper_connector_dpms,
560e3adcf8fSFrançois Tigeot 	.detect = intel_lvds_detect,
561e3adcf8fSFrançois Tigeot 	.fill_modes = drm_helper_probe_single_connector_modes,
562e3adcf8fSFrançois Tigeot 	.set_property = intel_lvds_set_property,
5632c9916cdSFrançois Tigeot 	.atomic_get_property = intel_connector_atomic_get_property,
564e3adcf8fSFrançois Tigeot 	.destroy = intel_lvds_destroy,
5652c9916cdSFrançois Tigeot 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
566477eb7f9SFrançois Tigeot 	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
567e3adcf8fSFrançois Tigeot };
568e3adcf8fSFrançois Tigeot 
569e3adcf8fSFrançois Tigeot static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
570e3adcf8fSFrançois Tigeot 	.destroy = intel_encoder_destroy,
571e3adcf8fSFrançois Tigeot };
572e3adcf8fSFrançois Tigeot 
57324edb884SFrançois Tigeot static int intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
574e3adcf8fSFrançois Tigeot {
57519df918dSFrançois Tigeot 	DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
576e3adcf8fSFrançois Tigeot 	return 1;
577e3adcf8fSFrançois Tigeot }
578e3adcf8fSFrançois Tigeot 
579e3adcf8fSFrançois Tigeot /* These systems claim to have LVDS, but really don't */
580e3adcf8fSFrançois Tigeot static const struct dmi_system_id intel_no_lvds[] = {
581e3adcf8fSFrançois Tigeot 	{
582e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
583e3adcf8fSFrançois Tigeot 		.ident = "Apple Mac Mini (Core series)",
584e3adcf8fSFrançois Tigeot 		.matches = {
585e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
586e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
587e3adcf8fSFrançois Tigeot 		},
588e3adcf8fSFrançois Tigeot 	},
589e3adcf8fSFrançois Tigeot 	{
590e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
591e3adcf8fSFrançois Tigeot 		.ident = "Apple Mac Mini (Core 2 series)",
592e3adcf8fSFrançois Tigeot 		.matches = {
593e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
594e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
595e3adcf8fSFrançois Tigeot 		},
596e3adcf8fSFrançois Tigeot 	},
597e3adcf8fSFrançois Tigeot 	{
598e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
599e3adcf8fSFrançois Tigeot 		.ident = "MSI IM-945GSE-A",
600e3adcf8fSFrançois Tigeot 		.matches = {
601e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
602e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
603e3adcf8fSFrançois Tigeot 		},
604e3adcf8fSFrançois Tigeot 	},
605e3adcf8fSFrançois Tigeot 	{
606e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
607e3adcf8fSFrançois Tigeot 		.ident = "Dell Studio Hybrid",
608e3adcf8fSFrançois Tigeot 		.matches = {
609e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
610e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
611e3adcf8fSFrançois Tigeot 		},
612e3adcf8fSFrançois Tigeot 	},
613e3adcf8fSFrançois Tigeot 	{
614e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
615e3adcf8fSFrançois Tigeot 		.ident = "Dell OptiPlex FX170",
616e3adcf8fSFrançois Tigeot 		.matches = {
617e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
618e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
619e3adcf8fSFrançois Tigeot 		},
620e3adcf8fSFrançois Tigeot 	},
621e3adcf8fSFrançois Tigeot 	{
622e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
623e3adcf8fSFrançois Tigeot 		.ident = "AOpen Mini PC",
624e3adcf8fSFrançois Tigeot 		.matches = {
625e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
626e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
627e3adcf8fSFrançois Tigeot 		},
628e3adcf8fSFrançois Tigeot 	},
629e3adcf8fSFrançois Tigeot 	{
630e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
631e3adcf8fSFrançois Tigeot 		.ident = "AOpen Mini PC MP915",
632e3adcf8fSFrançois Tigeot 		.matches = {
633e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
634e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
635e3adcf8fSFrançois Tigeot 		},
636e3adcf8fSFrançois Tigeot 	},
637e3adcf8fSFrançois Tigeot 	{
638e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
639e3adcf8fSFrançois Tigeot 		.ident = "AOpen i915GMm-HFS",
640e3adcf8fSFrançois Tigeot 		.matches = {
641e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
642e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
643e3adcf8fSFrançois Tigeot 		},
644e3adcf8fSFrançois Tigeot 	},
645e3adcf8fSFrançois Tigeot 	{
646e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
647e3adcf8fSFrançois Tigeot                 .ident = "AOpen i45GMx-I",
648e3adcf8fSFrançois Tigeot                 .matches = {
649e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
650e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
651e3adcf8fSFrançois Tigeot                 },
652e3adcf8fSFrançois Tigeot         },
653e3adcf8fSFrançois Tigeot 	{
654e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
655e3adcf8fSFrançois Tigeot 		.ident = "Aopen i945GTt-VFA",
656e3adcf8fSFrançois Tigeot 		.matches = {
657e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
658e3adcf8fSFrançois Tigeot 		},
659e3adcf8fSFrançois Tigeot 	},
660e3adcf8fSFrançois Tigeot 	{
661e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
662e3adcf8fSFrançois Tigeot 		.ident = "Clientron U800",
663e3adcf8fSFrançois Tigeot 		.matches = {
664e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
665e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
666e3adcf8fSFrançois Tigeot 		},
667e3adcf8fSFrançois Tigeot 	},
668e3adcf8fSFrançois Tigeot 	{
669e3adcf8fSFrançois Tigeot                 .callback = intel_no_lvds_dmi_callback,
670e3adcf8fSFrançois Tigeot                 .ident = "Clientron E830",
671e3adcf8fSFrançois Tigeot                 .matches = {
672e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
673e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
674e3adcf8fSFrançois Tigeot                 },
675e3adcf8fSFrançois Tigeot         },
676e3adcf8fSFrançois Tigeot         {
677e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
678e3adcf8fSFrançois Tigeot 		.ident = "Asus EeeBox PC EB1007",
679e3adcf8fSFrançois Tigeot 		.matches = {
680e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
681e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
682e3adcf8fSFrançois Tigeot 		},
683e3adcf8fSFrançois Tigeot 	},
684e3adcf8fSFrançois Tigeot 	{
685e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
686e3adcf8fSFrançois Tigeot 		.ident = "Asus AT5NM10T-I",
687e3adcf8fSFrançois Tigeot 		.matches = {
688e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
689e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
690e3adcf8fSFrançois Tigeot 		},
691e3adcf8fSFrançois Tigeot 	},
692e3adcf8fSFrançois Tigeot 	{
693e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
694a2fdbec6SFrançois Tigeot 		.ident = "Hewlett-Packard HP t5740",
69519df918dSFrançois Tigeot 		.matches = {
69619df918dSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
697a2fdbec6SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
69819df918dSFrançois Tigeot 		},
69919df918dSFrançois Tigeot 	},
70019df918dSFrançois Tigeot 	{
70119df918dSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
702e3adcf8fSFrançois Tigeot 		.ident = "Hewlett-Packard t5745",
703e3adcf8fSFrançois Tigeot 		.matches = {
704e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
705e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
706e3adcf8fSFrançois Tigeot 		},
707e3adcf8fSFrançois Tigeot 	},
708e3adcf8fSFrançois Tigeot 	{
709e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
710e3adcf8fSFrançois Tigeot 		.ident = "Hewlett-Packard st5747",
711e3adcf8fSFrançois Tigeot 		.matches = {
712e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
713e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
714e3adcf8fSFrançois Tigeot 		},
715e3adcf8fSFrançois Tigeot 	},
716e3adcf8fSFrançois Tigeot 	{
717e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
718e3adcf8fSFrançois Tigeot 		.ident = "MSI Wind Box DC500",
719e3adcf8fSFrançois Tigeot 		.matches = {
720e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
721e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
722e3adcf8fSFrançois Tigeot 		},
723e3adcf8fSFrançois Tigeot 	},
724e3adcf8fSFrançois Tigeot 	{
725e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
72619df918dSFrançois Tigeot 		.ident = "Gigabyte GA-D525TUD",
72719df918dSFrançois Tigeot 		.matches = {
72819df918dSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
72919df918dSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
73019df918dSFrançois Tigeot 		},
73119df918dSFrançois Tigeot 	},
73219df918dSFrançois Tigeot 	{
73319df918dSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
734e3adcf8fSFrançois Tigeot 		.ident = "Supermicro X7SPA-H",
735e3adcf8fSFrançois Tigeot 		.matches = {
736e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
737e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
738e3adcf8fSFrançois Tigeot 		},
739e3adcf8fSFrançois Tigeot 	},
74019df918dSFrançois Tigeot 	{
74119df918dSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
74219df918dSFrançois Tigeot 		.ident = "Fujitsu Esprimo Q900",
74319df918dSFrançois Tigeot 		.matches = {
74419df918dSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
74519df918dSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
74619df918dSFrançois Tigeot 		},
74719df918dSFrançois Tigeot 	},
7485d0b1887SFrançois Tigeot 	{
7495d0b1887SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7509edbd4a0SFrançois Tigeot 		.ident = "Intel D410PT",
7519edbd4a0SFrançois Tigeot 		.matches = {
7529edbd4a0SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7539edbd4a0SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "D410PT"),
7549edbd4a0SFrançois Tigeot 		},
7559edbd4a0SFrançois Tigeot 	},
7569edbd4a0SFrançois Tigeot 	{
7579edbd4a0SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7589edbd4a0SFrançois Tigeot 		.ident = "Intel D425KT",
7599edbd4a0SFrançois Tigeot 		.matches = {
7609edbd4a0SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7619edbd4a0SFrançois Tigeot 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "D425KT"),
7629edbd4a0SFrançois Tigeot 		},
7639edbd4a0SFrançois Tigeot 	},
7649edbd4a0SFrançois Tigeot 	{
7659edbd4a0SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7665d0b1887SFrançois Tigeot 		.ident = "Intel D510MO",
7675d0b1887SFrançois Tigeot 		.matches = {
7685d0b1887SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7695d0b1887SFrançois Tigeot 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
7705d0b1887SFrançois Tigeot 		},
7715d0b1887SFrançois Tigeot 	},
7725d0b1887SFrançois Tigeot 	{
7735d0b1887SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7745d0b1887SFrançois Tigeot 		.ident = "Intel D525MW",
7755d0b1887SFrançois Tigeot 		.matches = {
7765d0b1887SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7775d0b1887SFrançois Tigeot 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
7785d0b1887SFrançois Tigeot 		},
7795d0b1887SFrançois Tigeot 	},
780e3adcf8fSFrançois Tigeot 
781e3adcf8fSFrançois Tigeot 	{ }	/* terminating entry */
782e3adcf8fSFrançois Tigeot };
783e3adcf8fSFrançois Tigeot 
784e3adcf8fSFrançois Tigeot /*
785e3adcf8fSFrançois Tigeot  * Enumerate the child dev array parsed from VBT to check whether
786e3adcf8fSFrançois Tigeot  * the LVDS is present.
787e3adcf8fSFrançois Tigeot  * If it is present, return 1.
788e3adcf8fSFrançois Tigeot  * If it is not present, return false.
789e3adcf8fSFrançois Tigeot  * If no child dev is parsed from VBT, it assumes that the LVDS is present.
790e3adcf8fSFrançois Tigeot  */
791e3adcf8fSFrançois Tigeot static bool lvds_is_present_in_vbt(struct drm_device *dev,
792e3adcf8fSFrançois Tigeot 				   u8 *i2c_pin)
793e3adcf8fSFrançois Tigeot {
794e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
795e3adcf8fSFrançois Tigeot 	int i;
796e3adcf8fSFrançois Tigeot 
7975d0b1887SFrançois Tigeot 	if (!dev_priv->vbt.child_dev_num)
798e3adcf8fSFrançois Tigeot 		return true;
799e3adcf8fSFrançois Tigeot 
8005d0b1887SFrançois Tigeot 	for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
8019edbd4a0SFrançois Tigeot 		union child_device_config *uchild = dev_priv->vbt.child_dev + i;
8029edbd4a0SFrançois Tigeot 		struct old_child_dev_config *child = &uchild->old;
803e3adcf8fSFrançois Tigeot 
804e3adcf8fSFrançois Tigeot 		/* If the device type is not LFP, continue.
805e3adcf8fSFrançois Tigeot 		 * We have to check both the new identifiers as well as the
806e3adcf8fSFrançois Tigeot 		 * old for compatibility with some BIOSes.
807e3adcf8fSFrançois Tigeot 		 */
808e3adcf8fSFrançois Tigeot 		if (child->device_type != DEVICE_TYPE_INT_LFP &&
809e3adcf8fSFrançois Tigeot 		    child->device_type != DEVICE_TYPE_LFP)
810e3adcf8fSFrançois Tigeot 			continue;
811e3adcf8fSFrançois Tigeot 
81219c468b4SFrançois Tigeot 		if (intel_gmbus_is_valid_pin(dev_priv, child->i2c_pin))
813e3adcf8fSFrançois Tigeot 			*i2c_pin = child->i2c_pin;
814e3adcf8fSFrançois Tigeot 
815e3adcf8fSFrançois Tigeot 		/* However, we cannot trust the BIOS writers to populate
816e3adcf8fSFrançois Tigeot 		 * the VBT correctly.  Since LVDS requires additional
817e3adcf8fSFrançois Tigeot 		 * information from AIM blocks, a non-zero addin offset is
818e3adcf8fSFrançois Tigeot 		 * a good indicator that the LVDS is actually present.
819e3adcf8fSFrançois Tigeot 		 */
820e3adcf8fSFrançois Tigeot 		if (child->addin_offset)
821e3adcf8fSFrançois Tigeot 			return true;
822e3adcf8fSFrançois Tigeot 
823e3adcf8fSFrançois Tigeot 		/* But even then some BIOS writers perform some black magic
824e3adcf8fSFrançois Tigeot 		 * and instantiate the device without reference to any
825e3adcf8fSFrançois Tigeot 		 * additional data.  Trust that if the VBT was written into
826e3adcf8fSFrançois Tigeot 		 * the OpRegion then they have validated the LVDS's existence.
827e3adcf8fSFrançois Tigeot 		 */
828e3adcf8fSFrançois Tigeot 		if (dev_priv->opregion.vbt)
829e3adcf8fSFrançois Tigeot 			return true;
830e3adcf8fSFrançois Tigeot 	}
831e3adcf8fSFrançois Tigeot 
832e3adcf8fSFrançois Tigeot 	return false;
833e3adcf8fSFrançois Tigeot }
834e3adcf8fSFrançois Tigeot 
835a2fdbec6SFrançois Tigeot static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
836a2fdbec6SFrançois Tigeot {
837a2fdbec6SFrançois Tigeot 	DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
838a2fdbec6SFrançois Tigeot 	return 1;
839a2fdbec6SFrançois Tigeot }
840a2fdbec6SFrançois Tigeot 
841a2fdbec6SFrançois Tigeot static const struct dmi_system_id intel_dual_link_lvds[] = {
842a2fdbec6SFrançois Tigeot 	{
843a2fdbec6SFrançois Tigeot 		.callback = intel_dual_link_lvds_callback,
844477eb7f9SFrançois Tigeot 		.ident = "Apple MacBook Pro 15\" (2010)",
845477eb7f9SFrançois Tigeot 		.matches = {
846477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
847477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6,2"),
848477eb7f9SFrançois Tigeot 		},
849477eb7f9SFrançois Tigeot 	},
850477eb7f9SFrançois Tigeot 	{
851477eb7f9SFrançois Tigeot 		.callback = intel_dual_link_lvds_callback,
852477eb7f9SFrançois Tigeot 		.ident = "Apple MacBook Pro 15\" (2011)",
853a2fdbec6SFrançois Tigeot 		.matches = {
854a2fdbec6SFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
855a2fdbec6SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
856a2fdbec6SFrançois Tigeot 		},
857a2fdbec6SFrançois Tigeot 	},
858477eb7f9SFrançois Tigeot 	{
859477eb7f9SFrançois Tigeot 		.callback = intel_dual_link_lvds_callback,
860477eb7f9SFrançois Tigeot 		.ident = "Apple MacBook Pro 15\" (2012)",
861477eb7f9SFrançois Tigeot 		.matches = {
862477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
863477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,1"),
864477eb7f9SFrançois Tigeot 		},
865477eb7f9SFrançois Tigeot 	},
866a2fdbec6SFrançois Tigeot 	{ }	/* terminating entry */
867a2fdbec6SFrançois Tigeot };
868a2fdbec6SFrançois Tigeot 
869a2fdbec6SFrançois Tigeot bool intel_is_dual_link_lvds(struct drm_device *dev)
870a2fdbec6SFrançois Tigeot {
871a2fdbec6SFrançois Tigeot 	struct intel_encoder *encoder;
872a2fdbec6SFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder;
873a2fdbec6SFrançois Tigeot 
8741b13d190SFrançois Tigeot 	for_each_intel_encoder(dev, encoder) {
875a2fdbec6SFrançois Tigeot 		if (encoder->type == INTEL_OUTPUT_LVDS) {
876a2fdbec6SFrançois Tigeot 			lvds_encoder = to_lvds_encoder(&encoder->base);
877a2fdbec6SFrançois Tigeot 
878a2fdbec6SFrançois Tigeot 			return lvds_encoder->is_dual_link;
879a2fdbec6SFrançois Tigeot 		}
880a2fdbec6SFrançois Tigeot 	}
881a2fdbec6SFrançois Tigeot 
882a2fdbec6SFrançois Tigeot 	return false;
883a2fdbec6SFrançois Tigeot }
884a2fdbec6SFrançois Tigeot 
885a2fdbec6SFrançois Tigeot static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
886a2fdbec6SFrançois Tigeot {
887a2fdbec6SFrançois Tigeot 	struct drm_device *dev = lvds_encoder->base.base.dev;
888a2fdbec6SFrançois Tigeot 	unsigned int val;
889a2fdbec6SFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
890a2fdbec6SFrançois Tigeot 
891a2fdbec6SFrançois Tigeot 	/* use the module option value if specified */
892ba55f2f5SFrançois Tigeot 	if (i915.lvds_channel_mode > 0)
893ba55f2f5SFrançois Tigeot 		return i915.lvds_channel_mode == 2;
894a2fdbec6SFrançois Tigeot 
895477eb7f9SFrançois Tigeot 	/* single channel LVDS is limited to 112 MHz */
896477eb7f9SFrançois Tigeot 	if (lvds_encoder->attached_connector->base.panel.fixed_mode->clock
897477eb7f9SFrançois Tigeot 	    > 112999)
898477eb7f9SFrançois Tigeot 		return true;
899477eb7f9SFrançois Tigeot 
900a2fdbec6SFrançois Tigeot 	if (dmi_check_system(intel_dual_link_lvds))
901a2fdbec6SFrançois Tigeot 		return true;
902a2fdbec6SFrançois Tigeot 
903a2fdbec6SFrançois Tigeot 	/* BIOS should set the proper LVDS register value at boot, but
904a2fdbec6SFrançois Tigeot 	 * in reality, it doesn't set the value when the lid is closed;
905a2fdbec6SFrançois Tigeot 	 * we need to check "the value to be set" in VBT when LVDS
906a2fdbec6SFrançois Tigeot 	 * register is uninitialized.
907a2fdbec6SFrançois Tigeot 	 */
908a2fdbec6SFrançois Tigeot 	val = I915_READ(lvds_encoder->reg);
909a2fdbec6SFrançois Tigeot 	if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
9105d0b1887SFrançois Tigeot 		val = dev_priv->vbt.bios_lvds_val;
911a2fdbec6SFrançois Tigeot 
912a2fdbec6SFrançois Tigeot 	return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
913a2fdbec6SFrançois Tigeot }
914a2fdbec6SFrançois Tigeot 
915e3adcf8fSFrançois Tigeot static bool intel_lvds_supported(struct drm_device *dev)
916e3adcf8fSFrançois Tigeot {
917e3adcf8fSFrançois Tigeot 	/* With the introduction of the PCH we gained a dedicated
918e3adcf8fSFrançois Tigeot 	 * LVDS presence pin, use it. */
9198e26cdf6SFrançois Tigeot 	if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
920e3adcf8fSFrançois Tigeot 		return true;
921e3adcf8fSFrançois Tigeot 
922e3adcf8fSFrançois Tigeot 	/* Otherwise LVDS was only attached to mobile products,
923e3adcf8fSFrançois Tigeot 	 * except for the inglorious 830gm */
9248e26cdf6SFrançois Tigeot 	if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
9258e26cdf6SFrançois Tigeot 		return true;
9268e26cdf6SFrançois Tigeot 
9278e26cdf6SFrançois Tigeot 	return false;
928e3adcf8fSFrançois Tigeot }
929e3adcf8fSFrançois Tigeot 
930e3adcf8fSFrançois Tigeot /**
931e3adcf8fSFrançois Tigeot  * intel_lvds_init - setup LVDS connectors on this device
932e3adcf8fSFrançois Tigeot  * @dev: drm device
933e3adcf8fSFrançois Tigeot  *
934e3adcf8fSFrançois Tigeot  * Create the connector, register the LVDS DDC bus, and try to figure out what
935e3adcf8fSFrançois Tigeot  * modes we can display on the LVDS panel (if present).
936e3adcf8fSFrançois Tigeot  */
9375d0b1887SFrançois Tigeot void intel_lvds_init(struct drm_device *dev)
938e3adcf8fSFrançois Tigeot {
939e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
94019df918dSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder;
941e3adcf8fSFrançois Tigeot 	struct intel_encoder *intel_encoder;
94219df918dSFrançois Tigeot 	struct intel_lvds_connector *lvds_connector;
943e3adcf8fSFrançois Tigeot 	struct intel_connector *intel_connector;
944e3adcf8fSFrançois Tigeot 	struct drm_connector *connector;
945e3adcf8fSFrançois Tigeot 	struct drm_encoder *encoder;
946e3adcf8fSFrançois Tigeot 	struct drm_display_mode *scan; /* *modes, *bios_mode; */
94719df918dSFrançois Tigeot 	struct drm_display_mode *fixed_mode = NULL;
948ba55f2f5SFrançois Tigeot 	struct drm_display_mode *downclock_mode = NULL;
94919df918dSFrançois Tigeot 	struct edid *edid;
950e3adcf8fSFrançois Tigeot 	struct drm_crtc *crtc;
951*aee94f86SFrançois Tigeot 	i915_reg_t lvds_reg;
952e3adcf8fSFrançois Tigeot 	u32 lvds;
953e3adcf8fSFrançois Tigeot 	int pipe;
954e3adcf8fSFrançois Tigeot 	u8 pin;
955e3adcf8fSFrançois Tigeot 
9561b13d190SFrançois Tigeot 	/*
9571b13d190SFrançois Tigeot 	 * Unlock registers and just leave them unlocked. Do this before
9581b13d190SFrançois Tigeot 	 * checking quirk lists to avoid bogus WARNINGs.
9591b13d190SFrançois Tigeot 	 */
9601b13d190SFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
9611b13d190SFrançois Tigeot 		I915_WRITE(PCH_PP_CONTROL,
9621b13d190SFrançois Tigeot 			   I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
963352ff8bdSFrançois Tigeot 	} else if (INTEL_INFO(dev_priv)->gen < 5) {
9641b13d190SFrançois Tigeot 		I915_WRITE(PP_CONTROL,
9651b13d190SFrançois Tigeot 			   I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
9661b13d190SFrançois Tigeot 	}
967e3adcf8fSFrançois Tigeot 	if (!intel_lvds_supported(dev))
9685d0b1887SFrançois Tigeot 		return;
969e3adcf8fSFrançois Tigeot 
970e3adcf8fSFrançois Tigeot 	/* Skip init on machines we know falsely report LVDS */
971e3adcf8fSFrançois Tigeot 	if (dmi_check_system(intel_no_lvds))
9725d0b1887SFrançois Tigeot 		return;
973e3adcf8fSFrançois Tigeot 
974352ff8bdSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev))
975352ff8bdSFrançois Tigeot 		lvds_reg = PCH_LVDS;
976352ff8bdSFrançois Tigeot 	else
977352ff8bdSFrançois Tigeot 		lvds_reg = LVDS;
978352ff8bdSFrançois Tigeot 
979352ff8bdSFrançois Tigeot 	lvds = I915_READ(lvds_reg);
980352ff8bdSFrançois Tigeot 
981e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
982352ff8bdSFrançois Tigeot 		if ((lvds & LVDS_DETECTED) == 0)
9835d0b1887SFrançois Tigeot 			return;
9845d0b1887SFrançois Tigeot 		if (dev_priv->vbt.edp_support) {
985e3adcf8fSFrançois Tigeot 			DRM_DEBUG_KMS("disable LVDS for eDP support\n");
9865d0b1887SFrançois Tigeot 			return;
987e3adcf8fSFrançois Tigeot 		}
988e3adcf8fSFrançois Tigeot 	}
989e3adcf8fSFrançois Tigeot 
990a05eeebfSFrançois Tigeot 	pin = GMBUS_PIN_PANEL;
991a05eeebfSFrançois Tigeot 	if (!lvds_is_present_in_vbt(dev, &pin)) {
992352ff8bdSFrançois Tigeot 		if ((lvds & LVDS_PORT_EN) == 0) {
993a05eeebfSFrançois Tigeot 			DRM_DEBUG_KMS("LVDS is not present in VBT\n");
994a05eeebfSFrançois Tigeot 			return;
995a05eeebfSFrançois Tigeot 		}
996a05eeebfSFrançois Tigeot 		DRM_DEBUG_KMS("LVDS is not present in VBT, but enabled anyway\n");
997a05eeebfSFrançois Tigeot 	}
998a05eeebfSFrançois Tigeot 
999352ff8bdSFrançois Tigeot 	 /* Set the Panel Power On/Off timings if uninitialized. */
1000352ff8bdSFrançois Tigeot 	if (INTEL_INFO(dev_priv)->gen < 5 &&
1001352ff8bdSFrançois Tigeot 	    I915_READ(PP_ON_DELAYS) == 0 && I915_READ(PP_OFF_DELAYS) == 0) {
1002352ff8bdSFrançois Tigeot 		/* Set T2 to 40ms and T5 to 200ms */
1003352ff8bdSFrançois Tigeot 		I915_WRITE(PP_ON_DELAYS, 0x019007d0);
1004352ff8bdSFrançois Tigeot 
1005352ff8bdSFrançois Tigeot 		/* Set T3 to 35ms and Tx to 200ms */
1006352ff8bdSFrançois Tigeot 		I915_WRITE(PP_OFF_DELAYS, 0x015e07d0);
1007352ff8bdSFrançois Tigeot 
1008352ff8bdSFrançois Tigeot 		DRM_DEBUG_KMS("Panel power timings uninitialized, setting defaults\n");
1009352ff8bdSFrançois Tigeot 	}
1010352ff8bdSFrançois Tigeot 
10119edbd4a0SFrançois Tigeot 	lvds_encoder = kzalloc(sizeof(*lvds_encoder), GFP_KERNEL);
101219df918dSFrançois Tigeot 	if (!lvds_encoder)
10135d0b1887SFrançois Tigeot 		return;
1014e3adcf8fSFrançois Tigeot 
10159edbd4a0SFrançois Tigeot 	lvds_connector = kzalloc(sizeof(*lvds_connector), GFP_KERNEL);
101619df918dSFrançois Tigeot 	if (!lvds_connector) {
1017158486a6SFrançois Tigeot 		kfree(lvds_encoder);
10185d0b1887SFrançois Tigeot 		return;
1019e3adcf8fSFrançois Tigeot 	}
1020e3adcf8fSFrançois Tigeot 
1021477eb7f9SFrançois Tigeot 	if (intel_connector_init(&lvds_connector->base) < 0) {
1022477eb7f9SFrançois Tigeot 		kfree(lvds_connector);
1023477eb7f9SFrançois Tigeot 		kfree(lvds_encoder);
1024477eb7f9SFrançois Tigeot 		return;
1025477eb7f9SFrançois Tigeot 	}
1026477eb7f9SFrançois Tigeot 
102719df918dSFrançois Tigeot 	lvds_encoder->attached_connector = lvds_connector;
102819df918dSFrançois Tigeot 
102919df918dSFrançois Tigeot 	intel_encoder = &lvds_encoder->base;
1030e3adcf8fSFrançois Tigeot 	encoder = &intel_encoder->base;
103119df918dSFrançois Tigeot 	intel_connector = &lvds_connector->base;
1032e3adcf8fSFrançois Tigeot 	connector = &intel_connector->base;
1033e3adcf8fSFrançois Tigeot 	drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
1034e3adcf8fSFrançois Tigeot 			   DRM_MODE_CONNECTOR_LVDS);
1035e3adcf8fSFrançois Tigeot 
1036e3adcf8fSFrançois Tigeot 	drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
1037*aee94f86SFrançois Tigeot 			 DRM_MODE_ENCODER_LVDS, NULL);
1038e3adcf8fSFrançois Tigeot 
103919df918dSFrançois Tigeot 	intel_encoder->enable = intel_enable_lvds;
10409edbd4a0SFrançois Tigeot 	intel_encoder->pre_enable = intel_pre_enable_lvds;
10418e26cdf6SFrançois Tigeot 	intel_encoder->compute_config = intel_lvds_compute_config;
1042a05eeebfSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev_priv)) {
1043a05eeebfSFrançois Tigeot 		intel_encoder->disable = pch_disable_lvds;
1044a05eeebfSFrançois Tigeot 		intel_encoder->post_disable = pch_post_disable_lvds;
1045a05eeebfSFrançois Tigeot 	} else {
1046a05eeebfSFrançois Tigeot 		intel_encoder->disable = gmch_disable_lvds;
1047a05eeebfSFrançois Tigeot 	}
104819df918dSFrançois Tigeot 	intel_encoder->get_hw_state = intel_lvds_get_hw_state;
10495d0b1887SFrançois Tigeot 	intel_encoder->get_config = intel_lvds_get_config;
105019df918dSFrançois Tigeot 	intel_connector->get_hw_state = intel_connector_get_hw_state;
1051ba55f2f5SFrançois Tigeot 	intel_connector->unregister = intel_connector_unregister;
105219df918dSFrançois Tigeot 
1053e3adcf8fSFrançois Tigeot 	intel_connector_attach_encoder(intel_connector, intel_encoder);
1054e3adcf8fSFrançois Tigeot 	intel_encoder->type = INTEL_OUTPUT_LVDS;
1055e3adcf8fSFrançois Tigeot 
1056ba55f2f5SFrançois Tigeot 	intel_encoder->cloneable = 0;
1057e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev))
1058e3adcf8fSFrançois Tigeot 		intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
105919df918dSFrançois Tigeot 	else if (IS_GEN4(dev))
106019df918dSFrançois Tigeot 		intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
1061e3adcf8fSFrançois Tigeot 	else
1062e3adcf8fSFrançois Tigeot 		intel_encoder->crtc_mask = (1 << 1);
1063e3adcf8fSFrançois Tigeot 
1064e3adcf8fSFrançois Tigeot 	drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
1065e3adcf8fSFrançois Tigeot 	connector->display_info.subpixel_order = SubPixelHorizontalRGB;
1066e3adcf8fSFrançois Tigeot 	connector->interlace_allowed = false;
1067e3adcf8fSFrançois Tigeot 	connector->doublescan_allowed = false;
1068e3adcf8fSFrançois Tigeot 
1069352ff8bdSFrançois Tigeot 	lvds_encoder->reg = lvds_reg;
1070a2fdbec6SFrançois Tigeot 
1071e3adcf8fSFrançois Tigeot 	/* create the scaling mode property */
1072e3adcf8fSFrançois Tigeot 	drm_mode_create_scaling_mode_property(dev);
1073b5162e19SFrançois Tigeot 	drm_object_attach_property(&connector->base,
1074e3adcf8fSFrançois Tigeot 				      dev->mode_config.scaling_mode_property,
1075e3adcf8fSFrançois Tigeot 				      DRM_MODE_SCALE_ASPECT);
107619df918dSFrançois Tigeot 	intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
1077e3adcf8fSFrançois Tigeot 	/*
1078e3adcf8fSFrançois Tigeot 	 * LVDS discovery:
1079e3adcf8fSFrançois Tigeot 	 * 1) check for EDID on DDC
1080e3adcf8fSFrançois Tigeot 	 * 2) check for VBT data
1081e3adcf8fSFrançois Tigeot 	 * 3) check to see if LVDS is already on
1082e3adcf8fSFrançois Tigeot 	 *    if none of the above, no panel
1083e3adcf8fSFrançois Tigeot 	 * 4) make sure lid is open
1084e3adcf8fSFrançois Tigeot 	 *    if closed, act like it's not there for now
1085e3adcf8fSFrançois Tigeot 	 */
1086e3adcf8fSFrançois Tigeot 
1087e3adcf8fSFrançois Tigeot 	/*
1088e3adcf8fSFrançois Tigeot 	 * Attempt to get the fixed panel mode from DDC.  Assume that the
1089e3adcf8fSFrançois Tigeot 	 * preferred mode is the right one.
1090e3adcf8fSFrançois Tigeot 	 */
1091ba55f2f5SFrançois Tigeot 	mutex_lock(&dev->mode_config.mutex);
109219df918dSFrançois Tigeot 	edid = drm_get_edid(connector, intel_gmbus_get_adapter(dev_priv, pin));
109319df918dSFrançois Tigeot 	if (edid) {
109419df918dSFrançois Tigeot 		if (drm_add_edid_modes(connector, edid)) {
1095e3adcf8fSFrançois Tigeot 			drm_mode_connector_update_edid_property(connector,
109619df918dSFrançois Tigeot 								edid);
1097e3adcf8fSFrançois Tigeot 		} else {
1098158486a6SFrançois Tigeot 			kfree(edid);
109919df918dSFrançois Tigeot 			edid = ERR_PTR(-EINVAL);
1100e3adcf8fSFrançois Tigeot 		}
110119df918dSFrançois Tigeot 	} else {
110219df918dSFrançois Tigeot 		edid = ERR_PTR(-ENOENT);
1103e3adcf8fSFrançois Tigeot 	}
110419df918dSFrançois Tigeot 	lvds_connector->base.edid = edid;
110519df918dSFrançois Tigeot 
110619df918dSFrançois Tigeot 	if (IS_ERR_OR_NULL(edid)) {
1107e3adcf8fSFrançois Tigeot 		/* Didn't get an EDID, so
1108e3adcf8fSFrançois Tigeot 		 * Set wide sync ranges so we get all modes
1109e3adcf8fSFrançois Tigeot 		 * handed to valid_mode for checking
1110e3adcf8fSFrançois Tigeot 		 */
1111e3adcf8fSFrançois Tigeot 		connector->display_info.min_vfreq = 0;
1112e3adcf8fSFrançois Tigeot 		connector->display_info.max_vfreq = 200;
1113e3adcf8fSFrançois Tigeot 		connector->display_info.min_hfreq = 0;
1114e3adcf8fSFrançois Tigeot 		connector->display_info.max_hfreq = 200;
1115e3adcf8fSFrançois Tigeot 	}
1116e3adcf8fSFrançois Tigeot 
1117e3adcf8fSFrançois Tigeot 	list_for_each_entry(scan, &connector->probed_modes, head) {
1118e3adcf8fSFrançois Tigeot 		if (scan->type & DRM_MODE_TYPE_PREFERRED) {
111919df918dSFrançois Tigeot 			DRM_DEBUG_KMS("using preferred mode from EDID: ");
112019df918dSFrançois Tigeot 			drm_mode_debug_printmodeline(scan);
112119df918dSFrançois Tigeot 
112219df918dSFrançois Tigeot 			fixed_mode = drm_mode_duplicate(dev, scan);
1123a05eeebfSFrançois Tigeot 			if (fixed_mode)
1124e3adcf8fSFrançois Tigeot 				goto out;
1125e3adcf8fSFrançois Tigeot 		}
1126e3adcf8fSFrançois Tigeot 	}
1127e3adcf8fSFrançois Tigeot 
1128e3adcf8fSFrançois Tigeot 	/* Failed to get EDID, what about VBT? */
11295d0b1887SFrançois Tigeot 	if (dev_priv->vbt.lfp_lvds_vbt_mode) {
113019df918dSFrançois Tigeot 		DRM_DEBUG_KMS("using mode from VBT: ");
11315d0b1887SFrançois Tigeot 		drm_mode_debug_printmodeline(dev_priv->vbt.lfp_lvds_vbt_mode);
113219df918dSFrançois Tigeot 
11335d0b1887SFrançois Tigeot 		fixed_mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
113419df918dSFrançois Tigeot 		if (fixed_mode) {
113519df918dSFrançois Tigeot 			fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1136e3adcf8fSFrançois Tigeot 			goto out;
1137e3adcf8fSFrançois Tigeot 		}
1138e3adcf8fSFrançois Tigeot 	}
1139e3adcf8fSFrançois Tigeot 
1140e3adcf8fSFrançois Tigeot 	/*
1141e3adcf8fSFrançois Tigeot 	 * If we didn't get EDID, try checking if the panel is already turned
1142e3adcf8fSFrançois Tigeot 	 * on.  If so, assume that whatever is currently programmed is the
1143e3adcf8fSFrançois Tigeot 	 * correct mode.
1144e3adcf8fSFrançois Tigeot 	 */
1145e3adcf8fSFrançois Tigeot 
1146e3adcf8fSFrançois Tigeot 	/* Ironlake: FIXME if still fail, not try pipe mode now */
1147e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev))
1148e3adcf8fSFrançois Tigeot 		goto failed;
1149e3adcf8fSFrançois Tigeot 
1150e3adcf8fSFrançois Tigeot 	pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
1151e3adcf8fSFrançois Tigeot 	crtc = intel_get_crtc_for_pipe(dev, pipe);
1152e3adcf8fSFrançois Tigeot 
1153e3adcf8fSFrançois Tigeot 	if (crtc && (lvds & LVDS_PORT_EN)) {
115419df918dSFrançois Tigeot 		fixed_mode = intel_crtc_mode_get(dev, crtc);
115519df918dSFrançois Tigeot 		if (fixed_mode) {
115619df918dSFrançois Tigeot 			DRM_DEBUG_KMS("using current (BIOS) mode: ");
115719df918dSFrançois Tigeot 			drm_mode_debug_printmodeline(fixed_mode);
115819df918dSFrançois Tigeot 			fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1159e3adcf8fSFrançois Tigeot 			goto out;
1160e3adcf8fSFrançois Tigeot 		}
1161e3adcf8fSFrançois Tigeot 	}
1162e3adcf8fSFrançois Tigeot 
1163e3adcf8fSFrançois Tigeot 	/* If we still don't have a mode after all that, give up. */
116419df918dSFrançois Tigeot 	if (!fixed_mode)
1165e3adcf8fSFrançois Tigeot 		goto failed;
1166e3adcf8fSFrançois Tigeot 
1167e3adcf8fSFrançois Tigeot out:
1168ba55f2f5SFrançois Tigeot 	mutex_unlock(&dev->mode_config.mutex);
1169ba55f2f5SFrançois Tigeot 
1170477eb7f9SFrançois Tigeot 	intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
1171477eb7f9SFrançois Tigeot 
1172a2fdbec6SFrançois Tigeot 	lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
1173a2fdbec6SFrançois Tigeot 	DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
1174a2fdbec6SFrançois Tigeot 		      lvds_encoder->is_dual_link ? "dual" : "single");
1175a2fdbec6SFrançois Tigeot 
1176*aee94f86SFrançois Tigeot 	lvds_encoder->a3_power = lvds & LVDS_A3_POWER_MASK;
117724edb884SFrançois Tigeot 
1178e3adcf8fSFrançois Tigeot #if 0
117919df918dSFrançois Tigeot 	lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
118019df918dSFrançois Tigeot 	if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
118119df918dSFrançois Tigeot 		DRM_DEBUG_KMS("lid notifier registration failed\n");
118219df918dSFrançois Tigeot 		lvds_connector->lid_notifier.notifier_call = NULL;
118319df918dSFrançois Tigeot 	}
1184c6f73aabSFrançois Tigeot 	drm_connector_register(connector);
1185e3adcf8fSFrançois Tigeot #endif
118619df918dSFrançois Tigeot 
11872c9916cdSFrançois Tigeot 	intel_panel_setup_backlight(connector, INVALID_PIPE);
118819df918dSFrançois Tigeot 
11895d0b1887SFrançois Tigeot 	return;
1190e3adcf8fSFrançois Tigeot 
1191e3adcf8fSFrançois Tigeot failed:
1192ba55f2f5SFrançois Tigeot 	mutex_unlock(&dev->mode_config.mutex);
1193ba55f2f5SFrançois Tigeot 
1194e3adcf8fSFrançois Tigeot 	DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
1195e3adcf8fSFrançois Tigeot 	drm_connector_cleanup(connector);
1196e3adcf8fSFrançois Tigeot 	drm_encoder_cleanup(encoder);
1197158486a6SFrançois Tigeot 	kfree(lvds_encoder);
1198158486a6SFrançois Tigeot 	kfree(lvds_connector);
11995d0b1887SFrançois Tigeot 	return;
1200e3adcf8fSFrançois Tigeot }
1201