xref: /dflybsd-src/sys/dev/drm/i915/intel_lvds.c (revision c0e85e96994c944a12cb708e4676eac8a306d23a)
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;
51aee94f86SFranç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;
75aee94f86SFrançois Tigeot 	bool ret;
7619df918dSFrançois Tigeot 
7724edb884SFrançois Tigeot 	power_domain = intel_display_port_power_domain(encoder);
78aee94f86SFrançois Tigeot 	if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
7924edb884SFrançois Tigeot 		return false;
8024edb884SFrançois Tigeot 
81aee94f86SFrançois Tigeot 	ret = false;
82aee94f86SFrançois Tigeot 
83a2fdbec6SFrançois Tigeot 	tmp = I915_READ(lvds_encoder->reg);
8419df918dSFrançois Tigeot 
8519df918dSFrançois Tigeot 	if (!(tmp & LVDS_PORT_EN))
86aee94f86SFranç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 
93aee94f86SFrançois Tigeot 	ret = true;
94aee94f86SFrançois Tigeot 
95aee94f86SFrançois Tigeot out:
96aee94f86SFrançois Tigeot 	intel_display_power_put(dev_priv, power_domain);
97aee94f86SFrançois Tigeot 
98aee94f86SFranç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 
122*c0e85e96SFrançois Tigeot 	if (INTEL_INFO(dev)->gen < 5)
123*c0e85e96SFrançois Tigeot 		pipe_config->gmch_pfit.lvds_border_bits =
124*c0e85e96SFrançois Tigeot 			tmp & LVDS_BORDER_ENABLE;
125*c0e85e96SFrançois Tigeot 
1265d0b1887SFrançois Tigeot 	/* gen2/3 store dither state in pfit control, needs to match */
1275d0b1887SFrançois Tigeot 	if (INTEL_INFO(dev)->gen < 4) {
1285d0b1887SFrançois Tigeot 		tmp = I915_READ(PFIT_CONTROL);
1295d0b1887SFrançois Tigeot 
1305d0b1887SFrançois Tigeot 		pipe_config->gmch_pfit.control |= tmp & PANEL_8TO6_DITHER_ENABLE;
1315d0b1887SFrançois Tigeot 	}
1329edbd4a0SFrançois Tigeot 
1339edbd4a0SFrançois Tigeot 	dotclock = pipe_config->port_clock;
1349edbd4a0SFrançois Tigeot 
1359edbd4a0SFrançois Tigeot 	if (HAS_PCH_SPLIT(dev_priv->dev))
1369edbd4a0SFrançois Tigeot 		ironlake_check_encoder_dotclock(pipe_config, dotclock);
1379edbd4a0SFrançois Tigeot 
1382c9916cdSFrançois Tigeot 	pipe_config->base.adjusted_mode.crtc_clock = dotclock;
1395d0b1887SFrançois Tigeot }
1405d0b1887SFrançois Tigeot 
1419edbd4a0SFrançois Tigeot static void intel_pre_enable_lvds(struct intel_encoder *encoder)
142a2fdbec6SFrançois Tigeot {
143a2fdbec6SFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
144a2fdbec6SFrançois Tigeot 	struct drm_device *dev = encoder->base.dev;
145a2fdbec6SFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
1469edbd4a0SFrançois Tigeot 	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
147352ff8bdSFrançois Tigeot 	const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
1489edbd4a0SFrançois Tigeot 	int pipe = crtc->pipe;
149a2fdbec6SFrançois Tigeot 	u32 temp;
150a2fdbec6SFrançois Tigeot 
1519edbd4a0SFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
1529edbd4a0SFrançois Tigeot 		assert_fdi_rx_pll_disabled(dev_priv, pipe);
1539edbd4a0SFrançois Tigeot 		assert_shared_dpll_disabled(dev_priv,
1549edbd4a0SFrançois Tigeot 					    intel_crtc_to_shared_dpll(crtc));
1559edbd4a0SFrançois Tigeot 	} else {
1569edbd4a0SFrançois Tigeot 		assert_pll_disabled(dev_priv, pipe);
1579edbd4a0SFrançois Tigeot 	}
1589edbd4a0SFrançois Tigeot 
159a2fdbec6SFrançois Tigeot 	temp = I915_READ(lvds_encoder->reg);
160a2fdbec6SFrançois Tigeot 	temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
161a2fdbec6SFrançois Tigeot 
162a2fdbec6SFrançois Tigeot 	if (HAS_PCH_CPT(dev)) {
163a2fdbec6SFrançois Tigeot 		temp &= ~PORT_TRANS_SEL_MASK;
164a2fdbec6SFrançois Tigeot 		temp |= PORT_TRANS_SEL_CPT(pipe);
165a2fdbec6SFrançois Tigeot 	} else {
166a2fdbec6SFrançois Tigeot 		if (pipe == 1) {
167a2fdbec6SFrançois Tigeot 			temp |= LVDS_PIPEB_SELECT;
168a2fdbec6SFrançois Tigeot 		} else {
169a2fdbec6SFrançois Tigeot 			temp &= ~LVDS_PIPEB_SELECT;
170a2fdbec6SFrançois Tigeot 		}
171a2fdbec6SFrançois Tigeot 	}
172a2fdbec6SFrançois Tigeot 
173a2fdbec6SFrançois Tigeot 	/* set the corresponsding LVDS_BORDER bit */
1745d0b1887SFrançois Tigeot 	temp &= ~LVDS_BORDER_ENABLE;
1752c9916cdSFrançois Tigeot 	temp |= crtc->config->gmch_pfit.lvds_border_bits;
176a2fdbec6SFrançois Tigeot 	/* Set the B0-B3 data pairs corresponding to whether we're going to
177a2fdbec6SFrançois Tigeot 	 * set the DPLLs for dual-channel mode or not.
178a2fdbec6SFrançois Tigeot 	 */
179a2fdbec6SFrançois Tigeot 	if (lvds_encoder->is_dual_link)
180a2fdbec6SFrançois Tigeot 		temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
181a2fdbec6SFrançois Tigeot 	else
182a2fdbec6SFrançois Tigeot 		temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
183a2fdbec6SFrançois Tigeot 
184a2fdbec6SFrançois Tigeot 	/* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
185a2fdbec6SFrançois Tigeot 	 * appropriately here, but we need to look more thoroughly into how
18624edb884SFrançois Tigeot 	 * panels behave in the two modes. For now, let's just maintain the
18724edb884SFrançois Tigeot 	 * value we got from the BIOS.
188a2fdbec6SFrançois Tigeot 	 */
18924edb884SFrançois Tigeot 	 temp &= ~LVDS_A3_POWER_MASK;
19024edb884SFrançois Tigeot 	 temp |= lvds_encoder->a3_power;
191a2fdbec6SFrançois Tigeot 
192a2fdbec6SFrançois Tigeot 	/* Set the dithering flag on LVDS as needed, note that there is no
193a2fdbec6SFrançois Tigeot 	 * special lvds dither control bit on pch-split platforms, dithering is
194a2fdbec6SFrançois Tigeot 	 * only controlled through the PIPECONF reg. */
195a2fdbec6SFrançois Tigeot 	if (INTEL_INFO(dev)->gen == 4) {
1965d0b1887SFrançois Tigeot 		/* Bspec wording suggests that LVDS port dithering only exists
1975d0b1887SFrançois Tigeot 		 * for 18bpp panels. */
1982c9916cdSFrançois Tigeot 		if (crtc->config->dither && crtc->config->pipe_bpp == 18)
199a2fdbec6SFrançois Tigeot 			temp |= LVDS_ENABLE_DITHER;
200a2fdbec6SFrançois Tigeot 		else
201a2fdbec6SFrançois Tigeot 			temp &= ~LVDS_ENABLE_DITHER;
202a2fdbec6SFrançois Tigeot 	}
203a2fdbec6SFrançois Tigeot 	temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
2049edbd4a0SFrançois Tigeot 	if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
205a2fdbec6SFrançois Tigeot 		temp |= LVDS_HSYNC_POLARITY;
2069edbd4a0SFrançois Tigeot 	if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
207a2fdbec6SFrançois Tigeot 		temp |= LVDS_VSYNC_POLARITY;
208a2fdbec6SFrançois Tigeot 
209a2fdbec6SFrançois Tigeot 	I915_WRITE(lvds_encoder->reg, temp);
210a2fdbec6SFrançois Tigeot }
211a2fdbec6SFrançois Tigeot 
212e3adcf8fSFrançois Tigeot /**
213e3adcf8fSFrançois Tigeot  * Sets the power state for the panel.
214e3adcf8fSFrançois Tigeot  */
21519df918dSFrançois Tigeot static void intel_enable_lvds(struct intel_encoder *encoder)
216e3adcf8fSFrançois Tigeot {
21719df918dSFrançois Tigeot 	struct drm_device *dev = encoder->base.dev;
21819df918dSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
2199edbd4a0SFrançois Tigeot 	struct intel_connector *intel_connector =
2209edbd4a0SFrançois Tigeot 		&lvds_encoder->attached_connector->base;
221e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
222aee94f86SFrançois Tigeot 	i915_reg_t ctl_reg, stat_reg;
223e3adcf8fSFrançois Tigeot 
224e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
225e3adcf8fSFrançois Tigeot 		ctl_reg = PCH_PP_CONTROL;
226e3adcf8fSFrançois Tigeot 		stat_reg = PCH_PP_STATUS;
227e3adcf8fSFrançois Tigeot 	} else {
228e3adcf8fSFrançois Tigeot 		ctl_reg = PP_CONTROL;
229e3adcf8fSFrançois Tigeot 		stat_reg = PP_STATUS;
230e3adcf8fSFrançois Tigeot 	}
231e3adcf8fSFrançois Tigeot 
232a2fdbec6SFrançois Tigeot 	I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
233e3adcf8fSFrançois Tigeot 
234e3adcf8fSFrançois Tigeot 	I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
235a2fdbec6SFrançois Tigeot 	POSTING_READ(lvds_encoder->reg);
23619df918dSFrançois Tigeot 	if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
23719df918dSFrançois Tigeot 		DRM_ERROR("timed out waiting for panel to power on\n");
238e3adcf8fSFrançois Tigeot 
2399edbd4a0SFrançois Tigeot 	intel_panel_enable_backlight(intel_connector);
240e3adcf8fSFrançois Tigeot }
241e3adcf8fSFrançois Tigeot 
24219df918dSFrançois Tigeot static void intel_disable_lvds(struct intel_encoder *encoder)
243e3adcf8fSFrançois Tigeot {
24419df918dSFrançois Tigeot 	struct drm_device *dev = encoder->base.dev;
24519df918dSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
246e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
247aee94f86SFrançois Tigeot 	i915_reg_t ctl_reg, stat_reg;
248e3adcf8fSFrançois Tigeot 
249e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
250e3adcf8fSFrançois Tigeot 		ctl_reg = PCH_PP_CONTROL;
251e3adcf8fSFrançois Tigeot 		stat_reg = PCH_PP_STATUS;
252e3adcf8fSFrançois Tigeot 	} else {
253e3adcf8fSFrançois Tigeot 		ctl_reg = PP_CONTROL;
254e3adcf8fSFrançois Tigeot 		stat_reg = PP_STATUS;
255e3adcf8fSFrançois Tigeot 	}
256e3adcf8fSFrançois Tigeot 
257e3adcf8fSFrançois Tigeot 	I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
25819df918dSFrançois Tigeot 	if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
259e3adcf8fSFrançois Tigeot 		DRM_ERROR("timed out waiting for panel to power off\n");
260e3adcf8fSFrançois Tigeot 
261a2fdbec6SFrançois Tigeot 	I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
262a2fdbec6SFrançois Tigeot 	POSTING_READ(lvds_encoder->reg);
263e3adcf8fSFrançois Tigeot }
264e3adcf8fSFrançois Tigeot 
265a05eeebfSFrançois Tigeot static void gmch_disable_lvds(struct intel_encoder *encoder)
266a05eeebfSFrançois Tigeot {
267a05eeebfSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
268a05eeebfSFrançois Tigeot 	struct intel_connector *intel_connector =
269a05eeebfSFrançois Tigeot 		&lvds_encoder->attached_connector->base;
270a05eeebfSFrançois Tigeot 
271a05eeebfSFrançois Tigeot 	intel_panel_disable_backlight(intel_connector);
272a05eeebfSFrançois Tigeot 
273a05eeebfSFrançois Tigeot 	intel_disable_lvds(encoder);
274a05eeebfSFrançois Tigeot }
275a05eeebfSFrançois Tigeot 
276a05eeebfSFrançois Tigeot static void pch_disable_lvds(struct intel_encoder *encoder)
277a05eeebfSFrançois Tigeot {
278a05eeebfSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
279a05eeebfSFrançois Tigeot 	struct intel_connector *intel_connector =
280a05eeebfSFrançois Tigeot 		&lvds_encoder->attached_connector->base;
281a05eeebfSFrançois Tigeot 
282a05eeebfSFrançois Tigeot 	intel_panel_disable_backlight(intel_connector);
283a05eeebfSFrançois Tigeot }
284a05eeebfSFrançois Tigeot 
285a05eeebfSFrançois Tigeot static void pch_post_disable_lvds(struct intel_encoder *encoder)
286a05eeebfSFrançois Tigeot {
287a05eeebfSFrançois Tigeot 	intel_disable_lvds(encoder);
288a05eeebfSFrançois Tigeot }
289a05eeebfSFrançois Tigeot 
2909edbd4a0SFrançois Tigeot static enum drm_mode_status
2919edbd4a0SFrançois Tigeot intel_lvds_mode_valid(struct drm_connector *connector,
292e3adcf8fSFrançois Tigeot 		      struct drm_display_mode *mode)
293e3adcf8fSFrançois Tigeot {
29419df918dSFrançois Tigeot 	struct intel_connector *intel_connector = to_intel_connector(connector);
29519df918dSFrançois Tigeot 	struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
296352ff8bdSFrançois Tigeot 	int max_pixclk = to_i915(connector->dev)->max_dotclk_freq;
297e3adcf8fSFrançois Tigeot 
298e3adcf8fSFrançois Tigeot 	if (mode->hdisplay > fixed_mode->hdisplay)
299e3adcf8fSFrançois Tigeot 		return MODE_PANEL;
300e3adcf8fSFrançois Tigeot 	if (mode->vdisplay > fixed_mode->vdisplay)
301e3adcf8fSFrançois Tigeot 		return MODE_PANEL;
302352ff8bdSFrançois Tigeot 	if (fixed_mode->clock > max_pixclk)
303352ff8bdSFrançois Tigeot 		return MODE_CLOCK_HIGH;
304e3adcf8fSFrançois Tigeot 
305e3adcf8fSFrançois Tigeot 	return MODE_OK;
306e3adcf8fSFrançois Tigeot }
307e3adcf8fSFrançois Tigeot 
3088e26cdf6SFrançois Tigeot static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
3092c9916cdSFrançois Tigeot 				      struct intel_crtc_state *pipe_config)
310e3adcf8fSFrançois Tigeot {
3118e26cdf6SFrançois Tigeot 	struct drm_device *dev = intel_encoder->base.dev;
3128e26cdf6SFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder =
3138e26cdf6SFrançois Tigeot 		to_lvds_encoder(&intel_encoder->base);
31419df918dSFrançois Tigeot 	struct intel_connector *intel_connector =
31519df918dSFrançois Tigeot 		&lvds_encoder->attached_connector->base;
3162c9916cdSFrançois Tigeot 	struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
317477eb7f9SFrançois Tigeot 	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
3188e26cdf6SFrançois Tigeot 	unsigned int lvds_bpp;
319e3adcf8fSFrançois Tigeot 
320e3adcf8fSFrançois Tigeot 	/* Should never happen!! */
321e3adcf8fSFrançois Tigeot 	if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
322e3adcf8fSFrançois Tigeot 		DRM_ERROR("Can't support LVDS on pipe A\n");
323e3adcf8fSFrançois Tigeot 		return false;
324e3adcf8fSFrançois Tigeot 	}
325e3adcf8fSFrançois Tigeot 
32624edb884SFrançois Tigeot 	if (lvds_encoder->a3_power == LVDS_A3_POWER_UP)
3278e26cdf6SFrançois Tigeot 		lvds_bpp = 8*3;
3288e26cdf6SFrançois Tigeot 	else
3298e26cdf6SFrançois Tigeot 		lvds_bpp = 6*3;
3308e26cdf6SFrançois Tigeot 
3315d0b1887SFrançois Tigeot 	if (lvds_bpp != pipe_config->pipe_bpp && !pipe_config->bw_constrained) {
3328e26cdf6SFrançois Tigeot 		DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n",
3338e26cdf6SFrançois Tigeot 			      pipe_config->pipe_bpp, lvds_bpp);
3348e26cdf6SFrançois Tigeot 		pipe_config->pipe_bpp = lvds_bpp;
3358e26cdf6SFrançois Tigeot 	}
3365d0b1887SFrançois Tigeot 
337e3adcf8fSFrançois Tigeot 	/*
338e3adcf8fSFrançois Tigeot 	 * We have timings from the BIOS for the panel, put them in
339e3adcf8fSFrançois Tigeot 	 * to the adjusted mode.  The CRTC will be set up for this mode,
340e3adcf8fSFrançois Tigeot 	 * with the panel scaling set up to source from the H/VDisplay
341e3adcf8fSFrançois Tigeot 	 * of the original mode.
342e3adcf8fSFrançois Tigeot 	 */
34319df918dSFrançois Tigeot 	intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
34419df918dSFrançois Tigeot 			       adjusted_mode);
345e3adcf8fSFrançois Tigeot 
346e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
3478e26cdf6SFrançois Tigeot 		pipe_config->has_pch_encoder = true;
3488e26cdf6SFrançois Tigeot 
3495d0b1887SFrançois Tigeot 		intel_pch_panel_fitting(intel_crtc, pipe_config,
3505d0b1887SFrançois Tigeot 					intel_connector->panel.fitting_mode);
351e3adcf8fSFrançois Tigeot 	} else {
3525d0b1887SFrançois Tigeot 		intel_gmch_panel_fitting(intel_crtc, pipe_config,
3535d0b1887SFrançois Tigeot 					 intel_connector->panel.fitting_mode);
354e3adcf8fSFrançois Tigeot 
355e3adcf8fSFrançois Tigeot 	}
356e3adcf8fSFrançois Tigeot 
357e3adcf8fSFrançois Tigeot 	/*
358e3adcf8fSFrançois Tigeot 	 * XXX: It would be nice to support lower refresh rates on the
359e3adcf8fSFrançois Tigeot 	 * panels to reduce power consumption, and perhaps match the
360e3adcf8fSFrançois Tigeot 	 * user's requested refresh rate.
361e3adcf8fSFrançois Tigeot 	 */
362e3adcf8fSFrançois Tigeot 
363e3adcf8fSFrançois Tigeot 	return true;
364e3adcf8fSFrançois Tigeot }
365e3adcf8fSFrançois Tigeot 
366e3adcf8fSFrançois Tigeot /**
367e3adcf8fSFrançois Tigeot  * Detect the LVDS connection.
368e3adcf8fSFrançois Tigeot  *
369e3adcf8fSFrançois Tigeot  * Since LVDS doesn't have hotlug, we use the lid as a proxy.  Open means
370e3adcf8fSFrançois Tigeot  * connected and closed means disconnected.  We also send hotplug events as
371e3adcf8fSFrançois Tigeot  * needed, using lid status notification from the input layer.
372e3adcf8fSFrançois Tigeot  */
373e3adcf8fSFrançois Tigeot static enum drm_connector_status
374e3adcf8fSFrançois Tigeot intel_lvds_detect(struct drm_connector *connector, bool force)
375e3adcf8fSFrançois Tigeot {
376e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
377e3adcf8fSFrançois Tigeot 	enum drm_connector_status status;
378e3adcf8fSFrançois Tigeot 
3799edbd4a0SFrançois Tigeot 	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
380b4efbf42Szrj 		      connector->base.id, connector->name);
3819edbd4a0SFrançois Tigeot 
382e3adcf8fSFrançois Tigeot 	status = intel_panel_detect(dev);
383e3adcf8fSFrançois Tigeot 	if (status != connector_status_unknown)
384e3adcf8fSFrançois Tigeot 		return status;
385e3adcf8fSFrançois Tigeot 
386e3adcf8fSFrançois Tigeot 	return connector_status_connected;
387e3adcf8fSFrançois Tigeot }
388e3adcf8fSFrançois Tigeot 
389e3adcf8fSFrançois Tigeot /**
390e3adcf8fSFrançois Tigeot  * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
391e3adcf8fSFrançois Tigeot  */
392e3adcf8fSFrançois Tigeot static int intel_lvds_get_modes(struct drm_connector *connector)
393e3adcf8fSFrançois Tigeot {
39419df918dSFrançois Tigeot 	struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
395e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
396e3adcf8fSFrançois Tigeot 	struct drm_display_mode *mode;
397e3adcf8fSFrançois Tigeot 
39819df918dSFrançois Tigeot 	/* use cached edid if we have one */
39919df918dSFrançois Tigeot 	if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
40019df918dSFrançois Tigeot 		return drm_add_edid_modes(connector, lvds_connector->base.edid);
401e3adcf8fSFrançois Tigeot 
40219df918dSFrançois Tigeot 	mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
403e3adcf8fSFrançois Tigeot 	if (mode == NULL)
404e3adcf8fSFrançois Tigeot 		return 0;
405e3adcf8fSFrançois Tigeot 
406e3adcf8fSFrançois Tigeot 	drm_mode_probed_add(connector, mode);
407e3adcf8fSFrançois Tigeot 	return 1;
408e3adcf8fSFrançois Tigeot }
409e3adcf8fSFrançois Tigeot 
410e3adcf8fSFrançois Tigeot static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
411e3adcf8fSFrançois Tigeot {
41219df918dSFrançois Tigeot 	DRM_INFO("Skipping forced modeset for %s\n", id->ident);
413e3adcf8fSFrançois Tigeot 	return 1;
414e3adcf8fSFrançois Tigeot }
415e3adcf8fSFrançois Tigeot 
416e3adcf8fSFrançois Tigeot /* The GPU hangs up on these systems if modeset is performed on LID open */
417e3adcf8fSFrançois Tigeot static const struct dmi_system_id intel_no_modeset_on_lid[] = {
418e3adcf8fSFrançois Tigeot 	{
419e3adcf8fSFrançois Tigeot 		.callback = intel_no_modeset_on_lid_dmi_callback,
420e3adcf8fSFrançois Tigeot 		.ident = "Toshiba Tecra A11",
421e3adcf8fSFrançois Tigeot 		.matches = {
422e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
423e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
424e3adcf8fSFrançois Tigeot 		},
425e3adcf8fSFrançois Tigeot 	},
426e3adcf8fSFrançois Tigeot 
427e3adcf8fSFrançois Tigeot 	{ }	/* terminating entry */
428e3adcf8fSFrançois Tigeot };
429e3adcf8fSFrançois Tigeot 
43019df918dSFrançois Tigeot #if 0
431e3adcf8fSFrançois Tigeot /*
432a2fdbec6SFrançois Tigeot  * Lid events. Note the use of 'modeset':
433a2fdbec6SFrançois Tigeot  *  - we set it to MODESET_ON_LID_OPEN on lid close,
434a2fdbec6SFrançois Tigeot  *    and set it to MODESET_DONE on open
435e3adcf8fSFrançois Tigeot  *  - we use it as a "only once" bit (ie we ignore
436a2fdbec6SFrançois Tigeot  *    duplicate events where it was already properly set)
437a2fdbec6SFrançois Tigeot  *  - the suspend/resume paths will set it to
438a2fdbec6SFrançois Tigeot  *    MODESET_SUSPENDED and ignore the lid open event,
439a2fdbec6SFrançois Tigeot  *    because they restore the mode ("lid open").
440e3adcf8fSFrançois Tigeot  */
441e3adcf8fSFrançois Tigeot static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
442e3adcf8fSFrançois Tigeot 			    void *unused)
443e3adcf8fSFrançois Tigeot {
44419df918dSFrançois Tigeot 	struct intel_lvds_connector *lvds_connector =
44519df918dSFrançois Tigeot 		container_of(nb, struct intel_lvds_connector, lid_notifier);
44619df918dSFrançois Tigeot 	struct drm_connector *connector = &lvds_connector->base.base;
44719df918dSFrançois Tigeot 	struct drm_device *dev = connector->dev;
44819df918dSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
449e3adcf8fSFrançois Tigeot 
450e3adcf8fSFrançois Tigeot 	if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
451e3adcf8fSFrançois Tigeot 		return NOTIFY_OK;
452e3adcf8fSFrançois Tigeot 
453a2fdbec6SFrançois Tigeot 	mutex_lock(&dev_priv->modeset_restore_lock);
454a2fdbec6SFrançois Tigeot 	if (dev_priv->modeset_restore == MODESET_SUSPENDED)
455a2fdbec6SFrançois Tigeot 		goto exit;
456e3adcf8fSFrançois Tigeot 	/*
457e3adcf8fSFrançois Tigeot 	 * check and update the status of LVDS connector after receiving
458e3adcf8fSFrançois Tigeot 	 * the LID nofication event.
459e3adcf8fSFrançois Tigeot 	 */
46019df918dSFrançois Tigeot 	connector->status = connector->funcs->detect(connector, false);
461e3adcf8fSFrançois Tigeot 
462e3adcf8fSFrançois Tigeot 	/* Don't force modeset on machines where it causes a GPU lockup */
463e3adcf8fSFrançois Tigeot 	if (dmi_check_system(intel_no_modeset_on_lid))
464a2fdbec6SFrançois Tigeot 		goto exit;
465e3adcf8fSFrançois Tigeot 	if (!acpi_lid_open()) {
466a2fdbec6SFrançois Tigeot 		/* do modeset on next lid open event */
467a2fdbec6SFrançois Tigeot 		dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
468a2fdbec6SFrançois Tigeot 		goto exit;
469e3adcf8fSFrançois Tigeot 	}
470e3adcf8fSFrançois Tigeot 
471a2fdbec6SFrançois Tigeot 	if (dev_priv->modeset_restore == MODESET_DONE)
472a2fdbec6SFrançois Tigeot 		goto exit;
473e3adcf8fSFrançois Tigeot 
4749edbd4a0SFrançois Tigeot 	/*
4759edbd4a0SFrançois Tigeot 	 * Some old platform's BIOS love to wreak havoc while the lid is closed.
4769edbd4a0SFrançois Tigeot 	 * We try to detect this here and undo any damage. The split for PCH
4779edbd4a0SFrançois Tigeot 	 * platforms is rather conservative and a bit arbitrary expect that on
4789edbd4a0SFrançois Tigeot 	 * those platforms VGA disabling requires actual legacy VGA I/O access,
4799edbd4a0SFrançois Tigeot 	 * and as part of the cleanup in the hw state restore we also redisable
4809edbd4a0SFrançois Tigeot 	 * the vga plane.
4819edbd4a0SFrançois Tigeot 	 */
482*c0e85e96SFrançois Tigeot 	if (!HAS_PCH_SPLIT(dev))
483a05eeebfSFrançois Tigeot 		intel_display_resume(dev);
484e3adcf8fSFrançois Tigeot 
485a2fdbec6SFrançois Tigeot 	dev_priv->modeset_restore = MODESET_DONE;
486a2fdbec6SFrançois Tigeot 
487a2fdbec6SFrançois Tigeot exit:
488a2fdbec6SFrançois Tigeot 	mutex_unlock(&dev_priv->modeset_restore_lock);
489e3adcf8fSFrançois Tigeot 	return NOTIFY_OK;
490e3adcf8fSFrançois Tigeot }
491e3adcf8fSFrançois Tigeot #endif
492e3adcf8fSFrançois Tigeot 
493e3adcf8fSFrançois Tigeot /**
494e3adcf8fSFrançois Tigeot  * intel_lvds_destroy - unregister and free LVDS structures
495e3adcf8fSFrançois Tigeot  * @connector: connector to free
496e3adcf8fSFrançois Tigeot  *
497e3adcf8fSFrançois Tigeot  * Unregister the DDC bus for this connector then free the driver private
498e3adcf8fSFrançois Tigeot  * structure.
499e3adcf8fSFrançois Tigeot  */
500e3adcf8fSFrançois Tigeot static void intel_lvds_destroy(struct drm_connector *connector)
501e3adcf8fSFrançois Tigeot {
50219df918dSFrançois Tigeot 	struct intel_lvds_connector *lvds_connector =
50319df918dSFrançois Tigeot 		to_lvds_connector(connector);
504e3adcf8fSFrançois Tigeot 
505e3adcf8fSFrançois Tigeot #if 0
50619df918dSFrançois Tigeot 	if (lvds_connector->lid_notifier.notifier_call)
50719df918dSFrançois Tigeot 		acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
508e3adcf8fSFrançois Tigeot #endif
50919df918dSFrançois Tigeot 
51019df918dSFrançois Tigeot 	if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
511158486a6SFrançois Tigeot 		kfree(lvds_connector->base.edid);
51219df918dSFrançois Tigeot 
51319df918dSFrançois Tigeot 	intel_panel_fini(&lvds_connector->base.panel);
51419df918dSFrançois Tigeot 
515e3adcf8fSFrançois Tigeot 	drm_connector_cleanup(connector);
516158486a6SFrançois Tigeot 	kfree(connector);
517e3adcf8fSFrançois Tigeot }
518e3adcf8fSFrançois Tigeot 
519e3adcf8fSFrançois Tigeot static int intel_lvds_set_property(struct drm_connector *connector,
520e3adcf8fSFrançois Tigeot 				   struct drm_property *property,
521e3adcf8fSFrançois Tigeot 				   uint64_t value)
522e3adcf8fSFrançois Tigeot {
52319df918dSFrançois Tigeot 	struct intel_connector *intel_connector = to_intel_connector(connector);
524e3adcf8fSFrançois Tigeot 	struct drm_device *dev = connector->dev;
525e3adcf8fSFrançois Tigeot 
526e3adcf8fSFrançois Tigeot 	if (property == dev->mode_config.scaling_mode_property) {
52719df918dSFrançois Tigeot 		struct drm_crtc *crtc;
528e3adcf8fSFrançois Tigeot 
529e3adcf8fSFrançois Tigeot 		if (value == DRM_MODE_SCALE_NONE) {
530e3adcf8fSFrançois Tigeot 			DRM_DEBUG_KMS("no scaling not supported\n");
531e3adcf8fSFrançois Tigeot 			return -EINVAL;
532e3adcf8fSFrançois Tigeot 		}
533e3adcf8fSFrançois Tigeot 
53419df918dSFrançois Tigeot 		if (intel_connector->panel.fitting_mode == value) {
535e3adcf8fSFrançois Tigeot 			/* the LVDS scaling property is not changed */
536e3adcf8fSFrançois Tigeot 			return 0;
537e3adcf8fSFrançois Tigeot 		}
53819df918dSFrançois Tigeot 		intel_connector->panel.fitting_mode = value;
53919df918dSFrançois Tigeot 
54019df918dSFrançois Tigeot 		crtc = intel_attached_encoder(connector)->base.crtc;
541477eb7f9SFrançois Tigeot 		if (crtc && crtc->state->enable) {
542e3adcf8fSFrançois Tigeot 			/*
543e3adcf8fSFrançois Tigeot 			 * If the CRTC is enabled, the display will be changed
544e3adcf8fSFrançois Tigeot 			 * according to the new panel fitting mode.
545e3adcf8fSFrançois Tigeot 			 */
546a2fdbec6SFrançois Tigeot 			intel_crtc_restore_mode(crtc);
547e3adcf8fSFrançois Tigeot 		}
548e3adcf8fSFrançois Tigeot 	}
549e3adcf8fSFrançois Tigeot 
550e3adcf8fSFrançois Tigeot 	return 0;
551e3adcf8fSFrançois Tigeot }
552e3adcf8fSFrançois Tigeot 
553e3adcf8fSFrançois Tigeot static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
554e3adcf8fSFrançois Tigeot 	.get_modes = intel_lvds_get_modes,
555e3adcf8fSFrançois Tigeot 	.mode_valid = intel_lvds_mode_valid,
556e3adcf8fSFrançois Tigeot 	.best_encoder = intel_best_encoder,
557e3adcf8fSFrançois Tigeot };
558e3adcf8fSFrançois Tigeot 
559e3adcf8fSFrançois Tigeot static const struct drm_connector_funcs intel_lvds_connector_funcs = {
560a05eeebfSFrançois Tigeot 	.dpms = drm_atomic_helper_connector_dpms,
561e3adcf8fSFrançois Tigeot 	.detect = intel_lvds_detect,
562e3adcf8fSFrançois Tigeot 	.fill_modes = drm_helper_probe_single_connector_modes,
563e3adcf8fSFrançois Tigeot 	.set_property = intel_lvds_set_property,
5642c9916cdSFrançois Tigeot 	.atomic_get_property = intel_connector_atomic_get_property,
565e3adcf8fSFrançois Tigeot 	.destroy = intel_lvds_destroy,
5662c9916cdSFrançois Tigeot 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
567477eb7f9SFrançois Tigeot 	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
568e3adcf8fSFrançois Tigeot };
569e3adcf8fSFrançois Tigeot 
570e3adcf8fSFrançois Tigeot static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
571e3adcf8fSFrançois Tigeot 	.destroy = intel_encoder_destroy,
572e3adcf8fSFrançois Tigeot };
573e3adcf8fSFrançois Tigeot 
57424edb884SFrançois Tigeot static int intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
575e3adcf8fSFrançois Tigeot {
57619df918dSFrançois Tigeot 	DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
577e3adcf8fSFrançois Tigeot 	return 1;
578e3adcf8fSFrançois Tigeot }
579e3adcf8fSFrançois Tigeot 
580e3adcf8fSFrançois Tigeot /* These systems claim to have LVDS, but really don't */
581e3adcf8fSFrançois Tigeot static const struct dmi_system_id intel_no_lvds[] = {
582e3adcf8fSFrançois Tigeot 	{
583e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
584e3adcf8fSFrançois Tigeot 		.ident = "Apple Mac Mini (Core series)",
585e3adcf8fSFrançois Tigeot 		.matches = {
586e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
587e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
588e3adcf8fSFrançois Tigeot 		},
589e3adcf8fSFrançois Tigeot 	},
590e3adcf8fSFrançois Tigeot 	{
591e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
592e3adcf8fSFrançois Tigeot 		.ident = "Apple Mac Mini (Core 2 series)",
593e3adcf8fSFrançois Tigeot 		.matches = {
594e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
595e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
596e3adcf8fSFrançois Tigeot 		},
597e3adcf8fSFrançois Tigeot 	},
598e3adcf8fSFrançois Tigeot 	{
599e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
600e3adcf8fSFrançois Tigeot 		.ident = "MSI IM-945GSE-A",
601e3adcf8fSFrançois Tigeot 		.matches = {
602e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
603e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
604e3adcf8fSFrançois Tigeot 		},
605e3adcf8fSFrançois Tigeot 	},
606e3adcf8fSFrançois Tigeot 	{
607e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
608e3adcf8fSFrançois Tigeot 		.ident = "Dell Studio Hybrid",
609e3adcf8fSFrançois Tigeot 		.matches = {
610e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
611e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
612e3adcf8fSFrançois Tigeot 		},
613e3adcf8fSFrançois Tigeot 	},
614e3adcf8fSFrançois Tigeot 	{
615e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
616e3adcf8fSFrançois Tigeot 		.ident = "Dell OptiPlex FX170",
617e3adcf8fSFrançois Tigeot 		.matches = {
618e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
619e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
620e3adcf8fSFrançois Tigeot 		},
621e3adcf8fSFrançois Tigeot 	},
622e3adcf8fSFrançois Tigeot 	{
623e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
624e3adcf8fSFrançois Tigeot 		.ident = "AOpen Mini PC",
625e3adcf8fSFrançois Tigeot 		.matches = {
626e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
627e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
628e3adcf8fSFrançois Tigeot 		},
629e3adcf8fSFrançois Tigeot 	},
630e3adcf8fSFrançois Tigeot 	{
631e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
632e3adcf8fSFrançois Tigeot 		.ident = "AOpen Mini PC MP915",
633e3adcf8fSFrançois Tigeot 		.matches = {
634e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
635e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
636e3adcf8fSFrançois Tigeot 		},
637e3adcf8fSFrançois Tigeot 	},
638e3adcf8fSFrançois Tigeot 	{
639e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
640e3adcf8fSFrançois Tigeot 		.ident = "AOpen i915GMm-HFS",
641e3adcf8fSFrançois Tigeot 		.matches = {
642e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
643e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
644e3adcf8fSFrançois Tigeot 		},
645e3adcf8fSFrançois Tigeot 	},
646e3adcf8fSFrançois Tigeot 	{
647e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
648e3adcf8fSFrançois Tigeot                 .ident = "AOpen i45GMx-I",
649e3adcf8fSFrançois Tigeot                 .matches = {
650e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
651e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
652e3adcf8fSFrançois Tigeot                 },
653e3adcf8fSFrançois Tigeot         },
654e3adcf8fSFrançois Tigeot 	{
655e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
656e3adcf8fSFrançois Tigeot 		.ident = "Aopen i945GTt-VFA",
657e3adcf8fSFrançois Tigeot 		.matches = {
658e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
659e3adcf8fSFrançois Tigeot 		},
660e3adcf8fSFrançois Tigeot 	},
661e3adcf8fSFrançois Tigeot 	{
662e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
663e3adcf8fSFrançois Tigeot 		.ident = "Clientron U800",
664e3adcf8fSFrançois Tigeot 		.matches = {
665e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
666e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
667e3adcf8fSFrançois Tigeot 		},
668e3adcf8fSFrançois Tigeot 	},
669e3adcf8fSFrançois Tigeot 	{
670e3adcf8fSFrançois Tigeot                 .callback = intel_no_lvds_dmi_callback,
671e3adcf8fSFrançois Tigeot                 .ident = "Clientron E830",
672e3adcf8fSFrançois Tigeot                 .matches = {
673e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
674e3adcf8fSFrançois Tigeot                         DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
675e3adcf8fSFrançois Tigeot                 },
676e3adcf8fSFrançois Tigeot         },
677e3adcf8fSFrançois Tigeot         {
678e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
679e3adcf8fSFrançois Tigeot 		.ident = "Asus EeeBox PC EB1007",
680e3adcf8fSFrançois Tigeot 		.matches = {
681e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
682e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
683e3adcf8fSFrançois Tigeot 		},
684e3adcf8fSFrançois Tigeot 	},
685e3adcf8fSFrançois Tigeot 	{
686e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
687e3adcf8fSFrançois Tigeot 		.ident = "Asus AT5NM10T-I",
688e3adcf8fSFrançois Tigeot 		.matches = {
689e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
690e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
691e3adcf8fSFrançois Tigeot 		},
692e3adcf8fSFrançois Tigeot 	},
693e3adcf8fSFrançois Tigeot 	{
694e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
695a2fdbec6SFrançois Tigeot 		.ident = "Hewlett-Packard HP t5740",
69619df918dSFrançois Tigeot 		.matches = {
69719df918dSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
698a2fdbec6SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
69919df918dSFrançois Tigeot 		},
70019df918dSFrançois Tigeot 	},
70119df918dSFrançois Tigeot 	{
70219df918dSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
703e3adcf8fSFrançois Tigeot 		.ident = "Hewlett-Packard t5745",
704e3adcf8fSFrançois Tigeot 		.matches = {
705e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
706e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
707e3adcf8fSFrançois Tigeot 		},
708e3adcf8fSFrançois Tigeot 	},
709e3adcf8fSFrançois Tigeot 	{
710e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
711e3adcf8fSFrançois Tigeot 		.ident = "Hewlett-Packard st5747",
712e3adcf8fSFrançois Tigeot 		.matches = {
713e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
714e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
715e3adcf8fSFrançois Tigeot 		},
716e3adcf8fSFrançois Tigeot 	},
717e3adcf8fSFrançois Tigeot 	{
718e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
719e3adcf8fSFrançois Tigeot 		.ident = "MSI Wind Box DC500",
720e3adcf8fSFrançois Tigeot 		.matches = {
721e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
722e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
723e3adcf8fSFrançois Tigeot 		},
724e3adcf8fSFrançois Tigeot 	},
725e3adcf8fSFrançois Tigeot 	{
726e3adcf8fSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
72719df918dSFrançois Tigeot 		.ident = "Gigabyte GA-D525TUD",
72819df918dSFrançois Tigeot 		.matches = {
72919df918dSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
73019df918dSFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
73119df918dSFrançois Tigeot 		},
73219df918dSFrançois Tigeot 	},
73319df918dSFrançois Tigeot 	{
73419df918dSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
735e3adcf8fSFrançois Tigeot 		.ident = "Supermicro X7SPA-H",
736e3adcf8fSFrançois Tigeot 		.matches = {
737e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
738e3adcf8fSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
739e3adcf8fSFrançois Tigeot 		},
740e3adcf8fSFrançois Tigeot 	},
74119df918dSFrançois Tigeot 	{
74219df918dSFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
74319df918dSFrançois Tigeot 		.ident = "Fujitsu Esprimo Q900",
74419df918dSFrançois Tigeot 		.matches = {
74519df918dSFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
74619df918dSFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
74719df918dSFrançois Tigeot 		},
74819df918dSFrançois Tigeot 	},
7495d0b1887SFrançois Tigeot 	{
7505d0b1887SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7519edbd4a0SFrançois Tigeot 		.ident = "Intel D410PT",
7529edbd4a0SFrançois Tigeot 		.matches = {
7539edbd4a0SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7549edbd4a0SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_NAME, "D410PT"),
7559edbd4a0SFrançois Tigeot 		},
7569edbd4a0SFrançois Tigeot 	},
7579edbd4a0SFrançois Tigeot 	{
7589edbd4a0SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7599edbd4a0SFrançois Tigeot 		.ident = "Intel D425KT",
7609edbd4a0SFrançois Tigeot 		.matches = {
7619edbd4a0SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7629edbd4a0SFrançois Tigeot 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "D425KT"),
7639edbd4a0SFrançois Tigeot 		},
7649edbd4a0SFrançois Tigeot 	},
7659edbd4a0SFrançois Tigeot 	{
7669edbd4a0SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7675d0b1887SFrançois Tigeot 		.ident = "Intel D510MO",
7685d0b1887SFrançois Tigeot 		.matches = {
7695d0b1887SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7705d0b1887SFrançois Tigeot 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
7715d0b1887SFrançois Tigeot 		},
7725d0b1887SFrançois Tigeot 	},
7735d0b1887SFrançois Tigeot 	{
7745d0b1887SFrançois Tigeot 		.callback = intel_no_lvds_dmi_callback,
7755d0b1887SFrançois Tigeot 		.ident = "Intel D525MW",
7765d0b1887SFrançois Tigeot 		.matches = {
7775d0b1887SFrançois Tigeot 			DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
7785d0b1887SFrançois Tigeot 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
7795d0b1887SFrançois Tigeot 		},
7805d0b1887SFrançois Tigeot 	},
781e3adcf8fSFrançois Tigeot 
782e3adcf8fSFrançois Tigeot 	{ }	/* terminating entry */
783e3adcf8fSFrançois Tigeot };
784e3adcf8fSFrançois Tigeot 
785e3adcf8fSFrançois Tigeot /*
786e3adcf8fSFrançois Tigeot  * Enumerate the child dev array parsed from VBT to check whether
787e3adcf8fSFrançois Tigeot  * the LVDS is present.
788e3adcf8fSFrançois Tigeot  * If it is present, return 1.
789e3adcf8fSFrançois Tigeot  * If it is not present, return false.
790e3adcf8fSFrançois Tigeot  * If no child dev is parsed from VBT, it assumes that the LVDS is present.
791e3adcf8fSFrançois Tigeot  */
792e3adcf8fSFrançois Tigeot static bool lvds_is_present_in_vbt(struct drm_device *dev,
793e3adcf8fSFrançois Tigeot 				   u8 *i2c_pin)
794e3adcf8fSFrançois Tigeot {
795e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
796e3adcf8fSFrançois Tigeot 	int i;
797e3adcf8fSFrançois Tigeot 
7985d0b1887SFrançois Tigeot 	if (!dev_priv->vbt.child_dev_num)
799e3adcf8fSFrançois Tigeot 		return true;
800e3adcf8fSFrançois Tigeot 
8015d0b1887SFrançois Tigeot 	for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
8029edbd4a0SFrançois Tigeot 		union child_device_config *uchild = dev_priv->vbt.child_dev + i;
8039edbd4a0SFrançois Tigeot 		struct old_child_dev_config *child = &uchild->old;
804e3adcf8fSFrançois Tigeot 
805e3adcf8fSFrançois Tigeot 		/* If the device type is not LFP, continue.
806e3adcf8fSFrançois Tigeot 		 * We have to check both the new identifiers as well as the
807e3adcf8fSFrançois Tigeot 		 * old for compatibility with some BIOSes.
808e3adcf8fSFrançois Tigeot 		 */
809e3adcf8fSFrançois Tigeot 		if (child->device_type != DEVICE_TYPE_INT_LFP &&
810e3adcf8fSFrançois Tigeot 		    child->device_type != DEVICE_TYPE_LFP)
811e3adcf8fSFrançois Tigeot 			continue;
812e3adcf8fSFrançois Tigeot 
81319c468b4SFrançois Tigeot 		if (intel_gmbus_is_valid_pin(dev_priv, child->i2c_pin))
814e3adcf8fSFrançois Tigeot 			*i2c_pin = child->i2c_pin;
815e3adcf8fSFrançois Tigeot 
816e3adcf8fSFrançois Tigeot 		/* However, we cannot trust the BIOS writers to populate
817e3adcf8fSFrançois Tigeot 		 * the VBT correctly.  Since LVDS requires additional
818e3adcf8fSFrançois Tigeot 		 * information from AIM blocks, a non-zero addin offset is
819e3adcf8fSFrançois Tigeot 		 * a good indicator that the LVDS is actually present.
820e3adcf8fSFrançois Tigeot 		 */
821e3adcf8fSFrançois Tigeot 		if (child->addin_offset)
822e3adcf8fSFrançois Tigeot 			return true;
823e3adcf8fSFrançois Tigeot 
824e3adcf8fSFrançois Tigeot 		/* But even then some BIOS writers perform some black magic
825e3adcf8fSFrançois Tigeot 		 * and instantiate the device without reference to any
826e3adcf8fSFrançois Tigeot 		 * additional data.  Trust that if the VBT was written into
827e3adcf8fSFrançois Tigeot 		 * the OpRegion then they have validated the LVDS's existence.
828e3adcf8fSFrançois Tigeot 		 */
829e3adcf8fSFrançois Tigeot 		if (dev_priv->opregion.vbt)
830e3adcf8fSFrançois Tigeot 			return true;
831e3adcf8fSFrançois Tigeot 	}
832e3adcf8fSFrançois Tigeot 
833e3adcf8fSFrançois Tigeot 	return false;
834e3adcf8fSFrançois Tigeot }
835e3adcf8fSFrançois Tigeot 
836a2fdbec6SFrançois Tigeot static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
837a2fdbec6SFrançois Tigeot {
838a2fdbec6SFrançois Tigeot 	DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
839a2fdbec6SFrançois Tigeot 	return 1;
840a2fdbec6SFrançois Tigeot }
841a2fdbec6SFrançois Tigeot 
842a2fdbec6SFrançois Tigeot static const struct dmi_system_id intel_dual_link_lvds[] = {
843a2fdbec6SFrançois Tigeot 	{
844a2fdbec6SFrançois Tigeot 		.callback = intel_dual_link_lvds_callback,
845477eb7f9SFrançois Tigeot 		.ident = "Apple MacBook Pro 15\" (2010)",
846477eb7f9SFrançois Tigeot 		.matches = {
847477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
848477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6,2"),
849477eb7f9SFrançois Tigeot 		},
850477eb7f9SFrançois Tigeot 	},
851477eb7f9SFrançois Tigeot 	{
852477eb7f9SFrançois Tigeot 		.callback = intel_dual_link_lvds_callback,
853477eb7f9SFrançois Tigeot 		.ident = "Apple MacBook Pro 15\" (2011)",
854a2fdbec6SFrançois Tigeot 		.matches = {
855a2fdbec6SFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
856a2fdbec6SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
857a2fdbec6SFrançois Tigeot 		},
858a2fdbec6SFrançois Tigeot 	},
859477eb7f9SFrançois Tigeot 	{
860477eb7f9SFrançois Tigeot 		.callback = intel_dual_link_lvds_callback,
861477eb7f9SFrançois Tigeot 		.ident = "Apple MacBook Pro 15\" (2012)",
862477eb7f9SFrançois Tigeot 		.matches = {
863477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
864477eb7f9SFrançois Tigeot 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,1"),
865477eb7f9SFrançois Tigeot 		},
866477eb7f9SFrançois Tigeot 	},
867a2fdbec6SFrançois Tigeot 	{ }	/* terminating entry */
868a2fdbec6SFrançois Tigeot };
869a2fdbec6SFrançois Tigeot 
870a2fdbec6SFrançois Tigeot bool intel_is_dual_link_lvds(struct drm_device *dev)
871a2fdbec6SFrançois Tigeot {
872a2fdbec6SFrançois Tigeot 	struct intel_encoder *encoder;
873a2fdbec6SFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder;
874a2fdbec6SFrançois Tigeot 
8751b13d190SFrançois Tigeot 	for_each_intel_encoder(dev, encoder) {
876a2fdbec6SFrançois Tigeot 		if (encoder->type == INTEL_OUTPUT_LVDS) {
877a2fdbec6SFrançois Tigeot 			lvds_encoder = to_lvds_encoder(&encoder->base);
878a2fdbec6SFrançois Tigeot 
879a2fdbec6SFrançois Tigeot 			return lvds_encoder->is_dual_link;
880a2fdbec6SFrançois Tigeot 		}
881a2fdbec6SFrançois Tigeot 	}
882a2fdbec6SFrançois Tigeot 
883a2fdbec6SFrançois Tigeot 	return false;
884a2fdbec6SFrançois Tigeot }
885a2fdbec6SFrançois Tigeot 
886a2fdbec6SFrançois Tigeot static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
887a2fdbec6SFrançois Tigeot {
888a2fdbec6SFrançois Tigeot 	struct drm_device *dev = lvds_encoder->base.base.dev;
889a2fdbec6SFrançois Tigeot 	unsigned int val;
890a2fdbec6SFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
891a2fdbec6SFrançois Tigeot 
892a2fdbec6SFrançois Tigeot 	/* use the module option value if specified */
893ba55f2f5SFrançois Tigeot 	if (i915.lvds_channel_mode > 0)
894ba55f2f5SFrançois Tigeot 		return i915.lvds_channel_mode == 2;
895a2fdbec6SFrançois Tigeot 
896477eb7f9SFrançois Tigeot 	/* single channel LVDS is limited to 112 MHz */
897477eb7f9SFrançois Tigeot 	if (lvds_encoder->attached_connector->base.panel.fixed_mode->clock
898477eb7f9SFrançois Tigeot 	    > 112999)
899477eb7f9SFrançois Tigeot 		return true;
900477eb7f9SFrançois Tigeot 
901a2fdbec6SFrançois Tigeot 	if (dmi_check_system(intel_dual_link_lvds))
902a2fdbec6SFrançois Tigeot 		return true;
903a2fdbec6SFrançois Tigeot 
904a2fdbec6SFrançois Tigeot 	/* BIOS should set the proper LVDS register value at boot, but
905a2fdbec6SFrançois Tigeot 	 * in reality, it doesn't set the value when the lid is closed;
906a2fdbec6SFrançois Tigeot 	 * we need to check "the value to be set" in VBT when LVDS
907a2fdbec6SFrançois Tigeot 	 * register is uninitialized.
908a2fdbec6SFrançois Tigeot 	 */
909a2fdbec6SFrançois Tigeot 	val = I915_READ(lvds_encoder->reg);
910a2fdbec6SFrançois Tigeot 	if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
9115d0b1887SFrançois Tigeot 		val = dev_priv->vbt.bios_lvds_val;
912a2fdbec6SFrançois Tigeot 
913a2fdbec6SFrançois Tigeot 	return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
914a2fdbec6SFrançois Tigeot }
915a2fdbec6SFrançois Tigeot 
916e3adcf8fSFrançois Tigeot static bool intel_lvds_supported(struct drm_device *dev)
917e3adcf8fSFrançois Tigeot {
918e3adcf8fSFrançois Tigeot 	/* With the introduction of the PCH we gained a dedicated
919e3adcf8fSFrançois Tigeot 	 * LVDS presence pin, use it. */
9208e26cdf6SFrançois Tigeot 	if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
921e3adcf8fSFrançois Tigeot 		return true;
922e3adcf8fSFrançois Tigeot 
923e3adcf8fSFrançois Tigeot 	/* Otherwise LVDS was only attached to mobile products,
924e3adcf8fSFrançois Tigeot 	 * except for the inglorious 830gm */
9258e26cdf6SFrançois Tigeot 	if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
9268e26cdf6SFrançois Tigeot 		return true;
9278e26cdf6SFrançois Tigeot 
9288e26cdf6SFrançois Tigeot 	return false;
929e3adcf8fSFrançois Tigeot }
930e3adcf8fSFrançois Tigeot 
931e3adcf8fSFrançois Tigeot /**
932e3adcf8fSFrançois Tigeot  * intel_lvds_init - setup LVDS connectors on this device
933e3adcf8fSFrançois Tigeot  * @dev: drm device
934e3adcf8fSFrançois Tigeot  *
935e3adcf8fSFrançois Tigeot  * Create the connector, register the LVDS DDC bus, and try to figure out what
936e3adcf8fSFrançois Tigeot  * modes we can display on the LVDS panel (if present).
937e3adcf8fSFrançois Tigeot  */
9385d0b1887SFrançois Tigeot void intel_lvds_init(struct drm_device *dev)
939e3adcf8fSFrançois Tigeot {
940e3adcf8fSFrançois Tigeot 	struct drm_i915_private *dev_priv = dev->dev_private;
94119df918dSFrançois Tigeot 	struct intel_lvds_encoder *lvds_encoder;
942e3adcf8fSFrançois Tigeot 	struct intel_encoder *intel_encoder;
94319df918dSFrançois Tigeot 	struct intel_lvds_connector *lvds_connector;
944e3adcf8fSFrançois Tigeot 	struct intel_connector *intel_connector;
945e3adcf8fSFrançois Tigeot 	struct drm_connector *connector;
946e3adcf8fSFrançois Tigeot 	struct drm_encoder *encoder;
947e3adcf8fSFrançois Tigeot 	struct drm_display_mode *scan; /* *modes, *bios_mode; */
94819df918dSFrançois Tigeot 	struct drm_display_mode *fixed_mode = NULL;
949ba55f2f5SFrançois Tigeot 	struct drm_display_mode *downclock_mode = NULL;
95019df918dSFrançois Tigeot 	struct edid *edid;
951e3adcf8fSFrançois Tigeot 	struct drm_crtc *crtc;
952aee94f86SFrançois Tigeot 	i915_reg_t lvds_reg;
953e3adcf8fSFrançois Tigeot 	u32 lvds;
954e3adcf8fSFrançois Tigeot 	int pipe;
955e3adcf8fSFrançois Tigeot 	u8 pin;
956e3adcf8fSFrançois Tigeot 
9571b13d190SFrançois Tigeot 	/*
9581b13d190SFrançois Tigeot 	 * Unlock registers and just leave them unlocked. Do this before
9591b13d190SFrançois Tigeot 	 * checking quirk lists to avoid bogus WARNINGs.
9601b13d190SFrançois Tigeot 	 */
9611b13d190SFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
9621b13d190SFrançois Tigeot 		I915_WRITE(PCH_PP_CONTROL,
9631b13d190SFrançois Tigeot 			   I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
964352ff8bdSFrançois Tigeot 	} else if (INTEL_INFO(dev_priv)->gen < 5) {
9651b13d190SFrançois Tigeot 		I915_WRITE(PP_CONTROL,
9661b13d190SFrançois Tigeot 			   I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
9671b13d190SFrançois Tigeot 	}
968e3adcf8fSFrançois Tigeot 	if (!intel_lvds_supported(dev))
9695d0b1887SFrançois Tigeot 		return;
970e3adcf8fSFrançois Tigeot 
971e3adcf8fSFrançois Tigeot 	/* Skip init on machines we know falsely report LVDS */
972e3adcf8fSFrançois Tigeot 	if (dmi_check_system(intel_no_lvds))
9735d0b1887SFrançois Tigeot 		return;
974e3adcf8fSFrançois Tigeot 
975352ff8bdSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev))
976352ff8bdSFrançois Tigeot 		lvds_reg = PCH_LVDS;
977352ff8bdSFrançois Tigeot 	else
978352ff8bdSFrançois Tigeot 		lvds_reg = LVDS;
979352ff8bdSFrançois Tigeot 
980352ff8bdSFrançois Tigeot 	lvds = I915_READ(lvds_reg);
981352ff8bdSFrançois Tigeot 
982e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev)) {
983352ff8bdSFrançois Tigeot 		if ((lvds & LVDS_DETECTED) == 0)
9845d0b1887SFrançois Tigeot 			return;
9855d0b1887SFrançois Tigeot 		if (dev_priv->vbt.edp_support) {
986e3adcf8fSFrançois Tigeot 			DRM_DEBUG_KMS("disable LVDS for eDP support\n");
9875d0b1887SFrançois Tigeot 			return;
988e3adcf8fSFrançois Tigeot 		}
989e3adcf8fSFrançois Tigeot 	}
990e3adcf8fSFrançois Tigeot 
991a05eeebfSFrançois Tigeot 	pin = GMBUS_PIN_PANEL;
992a05eeebfSFrançois Tigeot 	if (!lvds_is_present_in_vbt(dev, &pin)) {
993352ff8bdSFrançois Tigeot 		if ((lvds & LVDS_PORT_EN) == 0) {
994a05eeebfSFrançois Tigeot 			DRM_DEBUG_KMS("LVDS is not present in VBT\n");
995a05eeebfSFrançois Tigeot 			return;
996a05eeebfSFrançois Tigeot 		}
997a05eeebfSFrançois Tigeot 		DRM_DEBUG_KMS("LVDS is not present in VBT, but enabled anyway\n");
998a05eeebfSFrançois Tigeot 	}
999a05eeebfSFrançois Tigeot 
1000352ff8bdSFrançois Tigeot 	 /* Set the Panel Power On/Off timings if uninitialized. */
1001352ff8bdSFrançois Tigeot 	if (INTEL_INFO(dev_priv)->gen < 5 &&
1002352ff8bdSFrançois Tigeot 	    I915_READ(PP_ON_DELAYS) == 0 && I915_READ(PP_OFF_DELAYS) == 0) {
1003352ff8bdSFrançois Tigeot 		/* Set T2 to 40ms and T5 to 200ms */
1004352ff8bdSFrançois Tigeot 		I915_WRITE(PP_ON_DELAYS, 0x019007d0);
1005352ff8bdSFrançois Tigeot 
1006352ff8bdSFrançois Tigeot 		/* Set T3 to 35ms and Tx to 200ms */
1007352ff8bdSFrançois Tigeot 		I915_WRITE(PP_OFF_DELAYS, 0x015e07d0);
1008352ff8bdSFrançois Tigeot 
1009352ff8bdSFrançois Tigeot 		DRM_DEBUG_KMS("Panel power timings uninitialized, setting defaults\n");
1010352ff8bdSFrançois Tigeot 	}
1011352ff8bdSFrançois Tigeot 
10129edbd4a0SFrançois Tigeot 	lvds_encoder = kzalloc(sizeof(*lvds_encoder), GFP_KERNEL);
101319df918dSFrançois Tigeot 	if (!lvds_encoder)
10145d0b1887SFrançois Tigeot 		return;
1015e3adcf8fSFrançois Tigeot 
10169edbd4a0SFrançois Tigeot 	lvds_connector = kzalloc(sizeof(*lvds_connector), GFP_KERNEL);
101719df918dSFrançois Tigeot 	if (!lvds_connector) {
1018158486a6SFrançois Tigeot 		kfree(lvds_encoder);
10195d0b1887SFrançois Tigeot 		return;
1020e3adcf8fSFrançois Tigeot 	}
1021e3adcf8fSFrançois Tigeot 
1022477eb7f9SFrançois Tigeot 	if (intel_connector_init(&lvds_connector->base) < 0) {
1023477eb7f9SFrançois Tigeot 		kfree(lvds_connector);
1024477eb7f9SFrançois Tigeot 		kfree(lvds_encoder);
1025477eb7f9SFrançois Tigeot 		return;
1026477eb7f9SFrançois Tigeot 	}
1027477eb7f9SFrançois Tigeot 
102819df918dSFrançois Tigeot 	lvds_encoder->attached_connector = lvds_connector;
102919df918dSFrançois Tigeot 
103019df918dSFrançois Tigeot 	intel_encoder = &lvds_encoder->base;
1031e3adcf8fSFrançois Tigeot 	encoder = &intel_encoder->base;
103219df918dSFrançois Tigeot 	intel_connector = &lvds_connector->base;
1033e3adcf8fSFrançois Tigeot 	connector = &intel_connector->base;
1034e3adcf8fSFrançois Tigeot 	drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
1035e3adcf8fSFrançois Tigeot 			   DRM_MODE_CONNECTOR_LVDS);
1036e3adcf8fSFrançois Tigeot 
1037e3adcf8fSFrançois Tigeot 	drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
1038aee94f86SFrançois Tigeot 			 DRM_MODE_ENCODER_LVDS, NULL);
1039e3adcf8fSFrançois Tigeot 
104019df918dSFrançois Tigeot 	intel_encoder->enable = intel_enable_lvds;
10419edbd4a0SFrançois Tigeot 	intel_encoder->pre_enable = intel_pre_enable_lvds;
10428e26cdf6SFrançois Tigeot 	intel_encoder->compute_config = intel_lvds_compute_config;
1043a05eeebfSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev_priv)) {
1044a05eeebfSFrançois Tigeot 		intel_encoder->disable = pch_disable_lvds;
1045a05eeebfSFrançois Tigeot 		intel_encoder->post_disable = pch_post_disable_lvds;
1046a05eeebfSFrançois Tigeot 	} else {
1047a05eeebfSFrançois Tigeot 		intel_encoder->disable = gmch_disable_lvds;
1048a05eeebfSFrançois Tigeot 	}
104919df918dSFrançois Tigeot 	intel_encoder->get_hw_state = intel_lvds_get_hw_state;
10505d0b1887SFrançois Tigeot 	intel_encoder->get_config = intel_lvds_get_config;
105119df918dSFrançois Tigeot 	intel_connector->get_hw_state = intel_connector_get_hw_state;
1052ba55f2f5SFrançois Tigeot 	intel_connector->unregister = intel_connector_unregister;
105319df918dSFrançois Tigeot 
1054e3adcf8fSFrançois Tigeot 	intel_connector_attach_encoder(intel_connector, intel_encoder);
1055e3adcf8fSFrançois Tigeot 	intel_encoder->type = INTEL_OUTPUT_LVDS;
1056e3adcf8fSFrançois Tigeot 
1057ba55f2f5SFrançois Tigeot 	intel_encoder->cloneable = 0;
1058e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev))
1059e3adcf8fSFrançois Tigeot 		intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
106019df918dSFrançois Tigeot 	else if (IS_GEN4(dev))
106119df918dSFrançois Tigeot 		intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
1062e3adcf8fSFrançois Tigeot 	else
1063e3adcf8fSFrançois Tigeot 		intel_encoder->crtc_mask = (1 << 1);
1064e3adcf8fSFrançois Tigeot 
1065e3adcf8fSFrançois Tigeot 	drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
1066e3adcf8fSFrançois Tigeot 	connector->display_info.subpixel_order = SubPixelHorizontalRGB;
1067e3adcf8fSFrançois Tigeot 	connector->interlace_allowed = false;
1068e3adcf8fSFrançois Tigeot 	connector->doublescan_allowed = false;
1069e3adcf8fSFrançois Tigeot 
1070352ff8bdSFrançois Tigeot 	lvds_encoder->reg = lvds_reg;
1071a2fdbec6SFrançois Tigeot 
1072e3adcf8fSFrançois Tigeot 	/* create the scaling mode property */
1073e3adcf8fSFrançois Tigeot 	drm_mode_create_scaling_mode_property(dev);
1074b5162e19SFrançois Tigeot 	drm_object_attach_property(&connector->base,
1075e3adcf8fSFrançois Tigeot 				      dev->mode_config.scaling_mode_property,
1076e3adcf8fSFrançois Tigeot 				      DRM_MODE_SCALE_ASPECT);
107719df918dSFrançois Tigeot 	intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
1078e3adcf8fSFrançois Tigeot 	/*
1079e3adcf8fSFrançois Tigeot 	 * LVDS discovery:
1080e3adcf8fSFrançois Tigeot 	 * 1) check for EDID on DDC
1081e3adcf8fSFrançois Tigeot 	 * 2) check for VBT data
1082e3adcf8fSFrançois Tigeot 	 * 3) check to see if LVDS is already on
1083e3adcf8fSFrançois Tigeot 	 *    if none of the above, no panel
1084e3adcf8fSFrançois Tigeot 	 * 4) make sure lid is open
1085e3adcf8fSFrançois Tigeot 	 *    if closed, act like it's not there for now
1086e3adcf8fSFrançois Tigeot 	 */
1087e3adcf8fSFrançois Tigeot 
1088e3adcf8fSFrançois Tigeot 	/*
1089e3adcf8fSFrançois Tigeot 	 * Attempt to get the fixed panel mode from DDC.  Assume that the
1090e3adcf8fSFrançois Tigeot 	 * preferred mode is the right one.
1091e3adcf8fSFrançois Tigeot 	 */
1092ba55f2f5SFrançois Tigeot 	mutex_lock(&dev->mode_config.mutex);
1093*c0e85e96SFrançois Tigeot #if 0
1094*c0e85e96SFrançois Tigeot 	if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC)
1095*c0e85e96SFrançois Tigeot 		edid = drm_get_edid_switcheroo(connector,
1096*c0e85e96SFrançois Tigeot 				    intel_gmbus_get_adapter(dev_priv, pin));
1097*c0e85e96SFrançois Tigeot 	else
1098*c0e85e96SFrançois Tigeot #endif
1099*c0e85e96SFrançois Tigeot 		edid = drm_get_edid(connector,
1100*c0e85e96SFrançois Tigeot 				    intel_gmbus_get_adapter(dev_priv, pin));
110119df918dSFrançois Tigeot 	if (edid) {
110219df918dSFrançois Tigeot 		if (drm_add_edid_modes(connector, edid)) {
1103e3adcf8fSFrançois Tigeot 			drm_mode_connector_update_edid_property(connector,
110419df918dSFrançois Tigeot 								edid);
1105e3adcf8fSFrançois Tigeot 		} else {
1106158486a6SFrançois Tigeot 			kfree(edid);
110719df918dSFrançois Tigeot 			edid = ERR_PTR(-EINVAL);
1108e3adcf8fSFrançois Tigeot 		}
110919df918dSFrançois Tigeot 	} else {
111019df918dSFrançois Tigeot 		edid = ERR_PTR(-ENOENT);
1111e3adcf8fSFrançois Tigeot 	}
111219df918dSFrançois Tigeot 	lvds_connector->base.edid = edid;
111319df918dSFrançois Tigeot 
111419df918dSFrançois Tigeot 	if (IS_ERR_OR_NULL(edid)) {
1115e3adcf8fSFrançois Tigeot 		/* Didn't get an EDID, so
1116e3adcf8fSFrançois Tigeot 		 * Set wide sync ranges so we get all modes
1117e3adcf8fSFrançois Tigeot 		 * handed to valid_mode for checking
1118e3adcf8fSFrançois Tigeot 		 */
1119e3adcf8fSFrançois Tigeot 		connector->display_info.min_vfreq = 0;
1120e3adcf8fSFrançois Tigeot 		connector->display_info.max_vfreq = 200;
1121e3adcf8fSFrançois Tigeot 		connector->display_info.min_hfreq = 0;
1122e3adcf8fSFrançois Tigeot 		connector->display_info.max_hfreq = 200;
1123e3adcf8fSFrançois Tigeot 	}
1124e3adcf8fSFrançois Tigeot 
1125e3adcf8fSFrançois Tigeot 	list_for_each_entry(scan, &connector->probed_modes, head) {
1126e3adcf8fSFrançois Tigeot 		if (scan->type & DRM_MODE_TYPE_PREFERRED) {
112719df918dSFrançois Tigeot 			DRM_DEBUG_KMS("using preferred mode from EDID: ");
112819df918dSFrançois Tigeot 			drm_mode_debug_printmodeline(scan);
112919df918dSFrançois Tigeot 
113019df918dSFrançois Tigeot 			fixed_mode = drm_mode_duplicate(dev, scan);
1131a05eeebfSFrançois Tigeot 			if (fixed_mode)
1132e3adcf8fSFrançois Tigeot 				goto out;
1133e3adcf8fSFrançois Tigeot 		}
1134e3adcf8fSFrançois Tigeot 	}
1135e3adcf8fSFrançois Tigeot 
1136e3adcf8fSFrançois Tigeot 	/* Failed to get EDID, what about VBT? */
11375d0b1887SFrançois Tigeot 	if (dev_priv->vbt.lfp_lvds_vbt_mode) {
113819df918dSFrançois Tigeot 		DRM_DEBUG_KMS("using mode from VBT: ");
11395d0b1887SFrançois Tigeot 		drm_mode_debug_printmodeline(dev_priv->vbt.lfp_lvds_vbt_mode);
114019df918dSFrançois Tigeot 
11415d0b1887SFrançois Tigeot 		fixed_mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
114219df918dSFrançois Tigeot 		if (fixed_mode) {
114319df918dSFrançois Tigeot 			fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1144e3adcf8fSFrançois Tigeot 			goto out;
1145e3adcf8fSFrançois Tigeot 		}
1146e3adcf8fSFrançois Tigeot 	}
1147e3adcf8fSFrançois Tigeot 
1148e3adcf8fSFrançois Tigeot 	/*
1149e3adcf8fSFrançois Tigeot 	 * If we didn't get EDID, try checking if the panel is already turned
1150e3adcf8fSFrançois Tigeot 	 * on.  If so, assume that whatever is currently programmed is the
1151e3adcf8fSFrançois Tigeot 	 * correct mode.
1152e3adcf8fSFrançois Tigeot 	 */
1153e3adcf8fSFrançois Tigeot 
1154e3adcf8fSFrançois Tigeot 	/* Ironlake: FIXME if still fail, not try pipe mode now */
1155e3adcf8fSFrançois Tigeot 	if (HAS_PCH_SPLIT(dev))
1156e3adcf8fSFrançois Tigeot 		goto failed;
1157e3adcf8fSFrançois Tigeot 
1158e3adcf8fSFrançois Tigeot 	pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
1159e3adcf8fSFrançois Tigeot 	crtc = intel_get_crtc_for_pipe(dev, pipe);
1160e3adcf8fSFrançois Tigeot 
1161e3adcf8fSFrançois Tigeot 	if (crtc && (lvds & LVDS_PORT_EN)) {
116219df918dSFrançois Tigeot 		fixed_mode = intel_crtc_mode_get(dev, crtc);
116319df918dSFrançois Tigeot 		if (fixed_mode) {
116419df918dSFrançois Tigeot 			DRM_DEBUG_KMS("using current (BIOS) mode: ");
116519df918dSFrançois Tigeot 			drm_mode_debug_printmodeline(fixed_mode);
116619df918dSFrançois Tigeot 			fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1167e3adcf8fSFrançois Tigeot 			goto out;
1168e3adcf8fSFrançois Tigeot 		}
1169e3adcf8fSFrançois Tigeot 	}
1170e3adcf8fSFrançois Tigeot 
1171e3adcf8fSFrançois Tigeot 	/* If we still don't have a mode after all that, give up. */
117219df918dSFrançois Tigeot 	if (!fixed_mode)
1173e3adcf8fSFrançois Tigeot 		goto failed;
1174e3adcf8fSFrançois Tigeot 
1175e3adcf8fSFrançois Tigeot out:
1176ba55f2f5SFrançois Tigeot 	mutex_unlock(&dev->mode_config.mutex);
1177ba55f2f5SFrançois Tigeot 
1178477eb7f9SFrançois Tigeot 	intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
1179477eb7f9SFrançois Tigeot 
1180a2fdbec6SFrançois Tigeot 	lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
1181a2fdbec6SFrançois Tigeot 	DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
1182a2fdbec6SFrançois Tigeot 		      lvds_encoder->is_dual_link ? "dual" : "single");
1183a2fdbec6SFrançois Tigeot 
1184aee94f86SFrançois Tigeot 	lvds_encoder->a3_power = lvds & LVDS_A3_POWER_MASK;
118524edb884SFrançois Tigeot 
1186e3adcf8fSFrançois Tigeot #if 0
118719df918dSFrançois Tigeot 	lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
118819df918dSFrançois Tigeot 	if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
118919df918dSFrançois Tigeot 		DRM_DEBUG_KMS("lid notifier registration failed\n");
119019df918dSFrançois Tigeot 		lvds_connector->lid_notifier.notifier_call = NULL;
119119df918dSFrançois Tigeot 	}
1192c6f73aabSFrançois Tigeot 	drm_connector_register(connector);
1193e3adcf8fSFrançois Tigeot #endif
119419df918dSFrançois Tigeot 
11952c9916cdSFrançois Tigeot 	intel_panel_setup_backlight(connector, INVALID_PIPE);
119619df918dSFrançois Tigeot 
11975d0b1887SFrançois Tigeot 	return;
1198e3adcf8fSFrançois Tigeot 
1199e3adcf8fSFrançois Tigeot failed:
1200ba55f2f5SFrançois Tigeot 	mutex_unlock(&dev->mode_config.mutex);
1201ba55f2f5SFrançois Tigeot 
1202e3adcf8fSFrançois Tigeot 	DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
1203e3adcf8fSFrançois Tigeot 	drm_connector_cleanup(connector);
1204e3adcf8fSFrançois Tigeot 	drm_encoder_cleanup(encoder);
1205158486a6SFrançois Tigeot 	kfree(lvds_encoder);
1206158486a6SFrançois Tigeot 	kfree(lvds_connector);
12075d0b1887SFrançois Tigeot 	return;
1208e3adcf8fSFrançois Tigeot }
1209