blob: f533169e5d8b636cf129a5325afb37a03f71a3f6 [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
2 * Copyright © 2006-2007 Intel Corporation
3 * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Eric Anholt <eric@anholt.net>
26 * Dave Airlie <airlied@linux.ie>
27 * Jesse Barnes <jesse.barnes@intel.com>
28 */
29
Jesse Barnesc1c7af62009-09-10 15:28:03 -070030#include <acpi/button.h>
Paul Collins565dcd42009-02-04 23:05:41 +130031#include <linux/dmi.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080032#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080034#include "drmP.h"
35#include "drm.h"
36#include "drm_crtc.h"
37#include "drm_edid.h"
38#include "intel_drv.h"
39#include "i915_drm.h"
40#include "i915_drv.h"
Zhao Yakuie99da352009-06-26 09:46:18 +080041#include <linux/acpi.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080042
Zhao Yakui3fbe18d2009-06-22 15:31:25 +080043/* Private structure for the integrated LVDS support */
Chris Wilsonea5b2132010-08-04 13:50:23 +010044struct intel_lvds {
45 struct intel_encoder base;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +080046 int fitting_mode;
47 u32 pfit_control;
48 u32 pfit_pgm_ratios;
49};
50
Chris Wilsonea5b2132010-08-04 13:50:23 +010051static struct intel_lvds *enc_to_intel_lvds(struct drm_encoder *encoder)
52{
Chris Wilson4ef69c72010-09-09 15:14:28 +010053 return container_of(encoder, struct intel_lvds, base.base);
Chris Wilsonea5b2132010-08-04 13:50:23 +010054}
55
Matthew Garrett309b1e32010-05-18 13:53:16 -040056static void intel_lvds_lock_panel(struct drm_device *dev, bool lock)
57{
58 struct drm_i915_private *dev_priv = dev->dev_private;
59
60 if (lock)
61 I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
62 else
63 I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
64}
65
Jesse Barnes79e53942008-11-07 14:24:08 -080066/**
Jesse Barnes79e53942008-11-07 14:24:08 -080067 * Sets the power state for the panel.
68 */
69static void intel_lvds_set_power(struct drm_device *dev, bool on)
70{
71 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson913d8d12010-08-07 11:01:35 +010072 u32 ctl_reg, status_reg, lvds_reg;
Zhenyu Wang541998a2009-06-05 15:38:44 +080073
Eric Anholtc619eed2010-01-28 16:45:52 -080074 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang541998a2009-06-05 15:38:44 +080075 ctl_reg = PCH_PP_CONTROL;
76 status_reg = PCH_PP_STATUS;
Jesse Barnes469d1292010-02-11 12:41:05 -080077 lvds_reg = PCH_LVDS;
Zhenyu Wang541998a2009-06-05 15:38:44 +080078 } else {
79 ctl_reg = PP_CONTROL;
80 status_reg = PP_STATUS;
Jesse Barnes469d1292010-02-11 12:41:05 -080081 lvds_reg = LVDS;
Zhenyu Wang541998a2009-06-05 15:38:44 +080082 }
Jesse Barnes79e53942008-11-07 14:24:08 -080083
84 if (on) {
Jesse Barnes469d1292010-02-11 12:41:05 -080085 I915_WRITE(lvds_reg, I915_READ(lvds_reg) | LVDS_PORT_EN);
Chris Wilson77d07fd2010-09-12 12:42:35 +010086 I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
Chris Wilson481b6af2010-08-23 17:43:35 +010087 if (wait_for(I915_READ(status_reg) & PP_ON, 1000))
Chris Wilson913d8d12010-08-07 11:01:35 +010088 DRM_ERROR("timed out waiting to enable LVDS pipe");
Jesse Barnes79e53942008-11-07 14:24:08 -080089
Chris Wilsona9573552010-08-22 13:18:16 +010090 intel_panel_set_backlight(dev, dev_priv->backlight_level);
Jesse Barnes79e53942008-11-07 14:24:08 -080091 } else {
Chris Wilsona9573552010-08-22 13:18:16 +010092 intel_panel_set_backlight(dev, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -080093
Chris Wilson77d07fd2010-09-12 12:42:35 +010094 I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
Jesse Barnes469d1292010-02-11 12:41:05 -080095 I915_WRITE(lvds_reg, I915_READ(lvds_reg) & ~LVDS_PORT_EN);
96 POSTING_READ(lvds_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -080097 }
98}
99
100static void intel_lvds_dpms(struct drm_encoder *encoder, int mode)
101{
102 struct drm_device *dev = encoder->dev;
103
104 if (mode == DRM_MODE_DPMS_ON)
105 intel_lvds_set_power(dev, true);
106 else
107 intel_lvds_set_power(dev, false);
108
109 /* XXX: We never power down the LVDS pairs. */
110}
111
Jesse Barnes79e53942008-11-07 14:24:08 -0800112static int intel_lvds_mode_valid(struct drm_connector *connector,
113 struct drm_display_mode *mode)
114{
115 struct drm_device *dev = connector->dev;
116 struct drm_i915_private *dev_priv = dev->dev_private;
117 struct drm_display_mode *fixed_mode = dev_priv->panel_fixed_mode;
118
119 if (fixed_mode) {
120 if (mode->hdisplay > fixed_mode->hdisplay)
121 return MODE_PANEL;
122 if (mode->vdisplay > fixed_mode->vdisplay)
123 return MODE_PANEL;
124 }
125
126 return MODE_OK;
127}
128
Chris Wilson49be6632010-07-18 12:05:54 +0100129static void
130centre_horizontally(struct drm_display_mode *mode,
131 int width)
132{
133 u32 border, sync_pos, blank_width, sync_width;
134
135 /* keep the hsync and hblank widths constant */
136 sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start;
137 blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start;
138 sync_pos = (blank_width - sync_width + 1) / 2;
139
140 border = (mode->hdisplay - width + 1) / 2;
141 border += border & 1; /* make the border even */
142
143 mode->crtc_hdisplay = width;
144 mode->crtc_hblank_start = width + border;
145 mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width;
146
147 mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;
148 mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;
149}
150
151static void
152centre_vertically(struct drm_display_mode *mode,
153 int height)
154{
155 u32 border, sync_pos, blank_width, sync_width;
156
157 /* keep the vsync and vblank widths constant */
158 sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start;
159 blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start;
160 sync_pos = (blank_width - sync_width + 1) / 2;
161
162 border = (mode->vdisplay - height + 1) / 2;
163
164 mode->crtc_vdisplay = height;
165 mode->crtc_vblank_start = height + border;
166 mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;
167
168 mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
169 mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
170}
171
172static inline u32 panel_fitter_scaling(u32 source, u32 target)
173{
174 /*
175 * Floating point operation is not supported. So the FACTOR
176 * is defined, which can avoid the floating point computation
177 * when calculating the panel ratio.
178 */
179#define ACCURACY 12
180#define FACTOR (1 << ACCURACY)
181 u32 ratio = source * FACTOR / target;
182 return (FACTOR * ratio + FACTOR/2) / FACTOR;
183}
184
Jesse Barnes79e53942008-11-07 14:24:08 -0800185static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
186 struct drm_display_mode *mode,
187 struct drm_display_mode *adjusted_mode)
188{
189 struct drm_device *dev = encoder->dev;
190 struct drm_i915_private *dev_priv = dev->dev_private;
191 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100192 struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -0800193 struct drm_encoder *tmp_encoder;
Chris Wilson49be6632010-07-18 12:05:54 +0100194 u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
Jesse Barnes79e53942008-11-07 14:24:08 -0800195
196 /* Should never happen!! */
197 if (!IS_I965G(dev) && intel_crtc->pipe == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700198 DRM_ERROR("Can't support LVDS on pipe A\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800199 return false;
200 }
201
202 /* Should never happen!! */
203 list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) {
204 if (tmp_encoder != encoder && tmp_encoder->crtc == encoder->crtc) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700205 DRM_ERROR("Can't enable LVDS and another "
Jesse Barnes79e53942008-11-07 14:24:08 -0800206 "encoder on the same pipe\n");
207 return false;
208 }
209 }
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800210 /* If we don't have a panel mode, there is nothing we can do */
211 if (dev_priv->panel_fixed_mode == NULL)
212 return true;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100213
Jesse Barnes79e53942008-11-07 14:24:08 -0800214 /*
Chris Wilson71677042010-07-17 13:38:43 +0100215 * We have timings from the BIOS for the panel, put them in
Jesse Barnes79e53942008-11-07 14:24:08 -0800216 * to the adjusted mode. The CRTC will be set up for this mode,
217 * with the panel scaling set up to source from the H/VDisplay
218 * of the original mode.
219 */
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100220 intel_fixed_panel_mode(dev_priv->panel_fixed_mode, adjusted_mode);
221
222 if (HAS_PCH_SPLIT(dev)) {
223 intel_pch_panel_fitting(dev, intel_lvds->fitting_mode,
224 mode, adjusted_mode);
225 return true;
226 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800227
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800228 /* Make sure pre-965s set dither correctly */
229 if (!IS_I965G(dev)) {
230 if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
231 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
232 }
233
234 /* Native modes don't need fitting */
235 if (adjusted_mode->hdisplay == mode->hdisplay &&
Chris Wilson49be6632010-07-18 12:05:54 +0100236 adjusted_mode->vdisplay == mode->vdisplay)
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800237 goto out;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800238
239 /* 965+ wants fuzzy fitting */
240 if (IS_I965G(dev))
Chris Wilson49be6632010-07-18 12:05:54 +0100241 pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) |
242 PFIT_FILTER_FUZZY);
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800243
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800244 /*
245 * Enable automatic panel scaling for non-native modes so that they fill
246 * the screen. Should be enabled before the pipe is enabled, according
247 * to register description and PRM.
248 * Change the value here to see the borders for debugging
249 */
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100250 I915_WRITE(BCLRPAT_A, 0);
251 I915_WRITE(BCLRPAT_B, 0);
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800252
Chris Wilsonea5b2132010-08-04 13:50:23 +0100253 switch (intel_lvds->fitting_mode) {
Jesse Barnes53bd8382009-07-01 10:04:40 -0700254 case DRM_MODE_SCALE_CENTER:
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800255 /*
256 * For centered modes, we have to calculate border widths &
257 * heights and modify the values programmed into the CRTC.
258 */
Chris Wilson49be6632010-07-18 12:05:54 +0100259 centre_horizontally(adjusted_mode, mode->hdisplay);
260 centre_vertically(adjusted_mode, mode->vdisplay);
261 border = LVDS_BORDER_ENABLE;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800262 break;
Chris Wilson49be6632010-07-18 12:05:54 +0100263
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800264 case DRM_MODE_SCALE_ASPECT:
Chris Wilson49be6632010-07-18 12:05:54 +0100265 /* Scale but preserve the aspect ratio */
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800266 if (IS_I965G(dev)) {
Chris Wilson49be6632010-07-18 12:05:54 +0100267 u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
268 u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
269
270 pfit_control |= PFIT_ENABLE;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800271 /* 965+ is easy, it does everything in hw */
Chris Wilson49be6632010-07-18 12:05:54 +0100272 if (scaled_width > scaled_height)
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800273 pfit_control |= PFIT_SCALING_PILLAR;
Chris Wilson49be6632010-07-18 12:05:54 +0100274 else if (scaled_width < scaled_height)
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800275 pfit_control |= PFIT_SCALING_LETTER;
276 else
277 pfit_control |= PFIT_SCALING_AUTO;
278 } else {
Chris Wilson49be6632010-07-18 12:05:54 +0100279 u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
280 u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800281 /*
282 * For earlier chips we have to calculate the scaling
283 * ratio by hand and program it into the
284 * PFIT_PGM_RATIO register
285 */
Chris Wilson49be6632010-07-18 12:05:54 +0100286 if (scaled_width > scaled_height) { /* pillar */
287 centre_horizontally(adjusted_mode, scaled_height / mode->vdisplay);
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800288
Chris Wilson49be6632010-07-18 12:05:54 +0100289 border = LVDS_BORDER_ENABLE;
290 if (mode->vdisplay != adjusted_mode->vdisplay) {
291 u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay);
292 pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
293 bits << PFIT_VERT_SCALE_SHIFT);
294 pfit_control |= (PFIT_ENABLE |
295 VERT_INTERP_BILINEAR |
296 HORIZ_INTERP_BILINEAR);
297 }
298 } else if (scaled_width < scaled_height) { /* letter */
299 centre_vertically(adjusted_mode, scaled_width / mode->hdisplay);
300
301 border = LVDS_BORDER_ENABLE;
302 if (mode->hdisplay != adjusted_mode->hdisplay) {
303 u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay);
304 pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
305 bits << PFIT_VERT_SCALE_SHIFT);
306 pfit_control |= (PFIT_ENABLE |
307 VERT_INTERP_BILINEAR |
308 HORIZ_INTERP_BILINEAR);
309 }
310 } else
311 /* Aspects match, Let hw scale both directions */
312 pfit_control |= (PFIT_ENABLE |
313 VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800314 VERT_INTERP_BILINEAR |
315 HORIZ_INTERP_BILINEAR);
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800316 }
317 break;
318
319 case DRM_MODE_SCALE_FULLSCREEN:
320 /*
321 * Full scaling, even if it changes the aspect ratio.
322 * Fortunately this is all done for us in hw.
323 */
324 pfit_control |= PFIT_ENABLE;
325 if (IS_I965G(dev))
326 pfit_control |= PFIT_SCALING_AUTO;
327 else
328 pfit_control |= (VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
329 VERT_INTERP_BILINEAR |
330 HORIZ_INTERP_BILINEAR);
331 break;
Chris Wilson49be6632010-07-18 12:05:54 +0100332
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800333 default:
334 break;
335 }
336
337out:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100338 intel_lvds->pfit_control = pfit_control;
339 intel_lvds->pfit_pgm_ratios = pfit_pgm_ratios;
Chris Wilson49be6632010-07-18 12:05:54 +0100340 dev_priv->lvds_border_bits = border;
341
Zhao Yakuia3e17eb2009-10-10 10:42:37 +0800342 /*
Jesse Barnes79e53942008-11-07 14:24:08 -0800343 * XXX: It would be nice to support lower refresh rates on the
344 * panels to reduce power consumption, and perhaps match the
345 * user's requested refresh rate.
346 */
347
348 return true;
349}
350
351static void intel_lvds_prepare(struct drm_encoder *encoder)
352{
353 struct drm_device *dev = encoder->dev;
354 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrett309b1e32010-05-18 13:53:16 -0400355 struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -0800356
Chris Wilsona9573552010-08-22 13:18:16 +0100357 dev_priv->backlight_level = intel_panel_get_backlight(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -0800358
Matthew Garrett309b1e32010-05-18 13:53:16 -0400359 if (intel_lvds->pfit_control == I915_READ(PFIT_CONTROL))
360 intel_lvds_lock_panel(dev, false);
361 else
362 intel_lvds_set_power(dev, false);
Jesse Barnes79e53942008-11-07 14:24:08 -0800363}
364
365static void intel_lvds_commit( struct drm_encoder *encoder)
366{
367 struct drm_device *dev = encoder->dev;
368 struct drm_i915_private *dev_priv = dev->dev_private;
369
Chris Wilsona9573552010-08-22 13:18:16 +0100370 if (dev_priv->backlight_level == 0)
371 dev_priv->backlight_level = intel_panel_get_max_backlight(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -0800372
Matthew Garrett309b1e32010-05-18 13:53:16 -0400373 if ((I915_READ(PP_CONTROL) & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS)
374 intel_lvds_lock_panel(dev, true);
375 else
376 intel_lvds_set_power(dev, true);
Jesse Barnes79e53942008-11-07 14:24:08 -0800377}
378
379static void intel_lvds_mode_set(struct drm_encoder *encoder,
380 struct drm_display_mode *mode,
381 struct drm_display_mode *adjusted_mode)
382{
383 struct drm_device *dev = encoder->dev;
384 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100385 struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -0800386
387 /*
388 * The LVDS pin pair will already have been turned on in the
389 * intel_crtc_mode_set since it has a large impact on the DPLL
390 * settings.
391 */
392
Eric Anholtc619eed2010-01-28 16:45:52 -0800393 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang541998a2009-06-05 15:38:44 +0800394 return;
395
Jesse Barnes79e53942008-11-07 14:24:08 -0800396 /*
397 * Enable automatic panel scaling so that non-native modes fill the
398 * screen. Should be enabled before the pipe is enabled, according to
399 * register description and PRM.
400 */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100401 I915_WRITE(PFIT_PGM_RATIOS, intel_lvds->pfit_pgm_ratios);
402 I915_WRITE(PFIT_CONTROL, intel_lvds->pfit_control);
Jesse Barnes79e53942008-11-07 14:24:08 -0800403}
404
405/**
406 * Detect the LVDS connection.
407 *
Jesse Barnesb42d4c52009-09-10 15:28:04 -0700408 * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
409 * connected and closed means disconnected. We also send hotplug events as
410 * needed, using lid status notification from the input layer.
Jesse Barnes79e53942008-11-07 14:24:08 -0800411 */
412static enum drm_connector_status intel_lvds_detect(struct drm_connector *connector)
413{
Jesse Barnes7b9c5ab2010-02-12 09:30:00 -0800414 struct drm_device *dev = connector->dev;
Jesse Barnesb42d4c52009-09-10 15:28:04 -0700415 enum drm_connector_status status = connector_status_connected;
416
Jesse Barnes7b9c5ab2010-02-12 09:30:00 -0800417 /* ACPI lid methods were generally unreliable in this generation, so
418 * don't even bother.
419 */
Eric Anholt6e6c8222010-03-17 13:48:06 -0700420 if (IS_GEN2(dev) || IS_GEN3(dev))
Jesse Barnes7b9c5ab2010-02-12 09:30:00 -0800421 return connector_status_connected;
422
Jesse Barnesb42d4c52009-09-10 15:28:04 -0700423 return status;
Jesse Barnes79e53942008-11-07 14:24:08 -0800424}
425
426/**
427 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
428 */
429static int intel_lvds_get_modes(struct drm_connector *connector)
430{
431 struct drm_device *dev = connector->dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800432 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes79e53942008-11-07 14:24:08 -0800433
Zhao Yakuibfac4d62010-04-07 17:11:22 +0800434 if (dev_priv->lvds_edid_good) {
Chris Wilsondf0e9242010-09-09 16:20:55 +0100435 struct intel_encoder *encoder = intel_attached_encoder(connector);
436 int ret = intel_ddc_get_modes(connector, encoder->ddc_bus);
Zhao Yakuibfac4d62010-04-07 17:11:22 +0800437 if (ret)
438 return ret;
439 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800440
441 /* Didn't get an EDID, so
442 * Set wide sync ranges so we get all modes
443 * handed to valid_mode for checking
444 */
445 connector->display_info.min_vfreq = 0;
446 connector->display_info.max_vfreq = 200;
447 connector->display_info.min_hfreq = 0;
448 connector->display_info.max_hfreq = 200;
449
450 if (dev_priv->panel_fixed_mode != NULL) {
451 struct drm_display_mode *mode;
452
Jesse Barnes79e53942008-11-07 14:24:08 -0800453 mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
454 drm_mode_probed_add(connector, mode);
Jesse Barnes79e53942008-11-07 14:24:08 -0800455
456 return 1;
457 }
458
459 return 0;
460}
461
Thomas Bächler0544edf2010-07-02 10:44:23 +0200462static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
463{
464 DRM_DEBUG_KMS("Skipping forced modeset for %s\n", id->ident);
465 return 1;
466}
467
468/* The GPU hangs up on these systems if modeset is performed on LID open */
469static const struct dmi_system_id intel_no_modeset_on_lid[] = {
470 {
471 .callback = intel_no_modeset_on_lid_dmi_callback,
472 .ident = "Toshiba Tecra A11",
473 .matches = {
474 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
475 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
476 },
477 },
478
479 { } /* terminating entry */
480};
481
Linus Torvaldsc9354c82009-11-02 09:29:55 -0800482/*
483 * Lid events. Note the use of 'modeset_on_lid':
484 * - we set it on lid close, and reset it on open
485 * - we use it as a "only once" bit (ie we ignore
486 * duplicate events where it was already properly
487 * set/reset)
488 * - the suspend/resume paths will also set it to
489 * zero, since they restore the mode ("lid open").
490 */
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700491static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
492 void *unused)
493{
494 struct drm_i915_private *dev_priv =
495 container_of(nb, struct drm_i915_private, lid_notifier);
496 struct drm_device *dev = dev_priv->dev;
Zhao Yakuia2565372009-12-11 09:26:11 +0800497 struct drm_connector *connector = dev_priv->int_lvds_connector;
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700498
Zhao Yakuia2565372009-12-11 09:26:11 +0800499 /*
500 * check and update the status of LVDS connector after receiving
501 * the LID nofication event.
502 */
503 if (connector)
504 connector->status = connector->funcs->detect(connector);
Thomas Bächler0544edf2010-07-02 10:44:23 +0200505 /* Don't force modeset on machines where it causes a GPU lockup */
506 if (dmi_check_system(intel_no_modeset_on_lid))
507 return NOTIFY_OK;
Linus Torvaldsc9354c82009-11-02 09:29:55 -0800508 if (!acpi_lid_open()) {
509 dev_priv->modeset_on_lid = 1;
510 return NOTIFY_OK;
Jesse Barnes06891e22009-09-14 10:58:48 -0700511 }
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700512
Linus Torvaldsc9354c82009-11-02 09:29:55 -0800513 if (!dev_priv->modeset_on_lid)
514 return NOTIFY_OK;
515
516 dev_priv->modeset_on_lid = 0;
517
518 mutex_lock(&dev->mode_config.mutex);
519 drm_helper_resume_force_mode(dev);
520 mutex_unlock(&dev->mode_config.mutex);
Jesse Barnes06324192009-09-10 15:28:05 -0700521
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700522 return NOTIFY_OK;
523}
524
Jesse Barnes79e53942008-11-07 14:24:08 -0800525/**
526 * intel_lvds_destroy - unregister and free LVDS structures
527 * @connector: connector to free
528 *
529 * Unregister the DDC bus for this connector then free the driver private
530 * structure.
531 */
532static void intel_lvds_destroy(struct drm_connector *connector)
533{
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700534 struct drm_device *dev = connector->dev;
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700535 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes79e53942008-11-07 14:24:08 -0800536
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700537 if (dev_priv->lid_notifier.notifier_call)
538 acpi_lid_notifier_unregister(&dev_priv->lid_notifier);
Jesse Barnes79e53942008-11-07 14:24:08 -0800539 drm_sysfs_connector_remove(connector);
540 drm_connector_cleanup(connector);
541 kfree(connector);
542}
543
Jesse Barnes335041e2009-01-22 22:22:06 +1000544static int intel_lvds_set_property(struct drm_connector *connector,
545 struct drm_property *property,
546 uint64_t value)
547{
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800548 struct drm_device *dev = connector->dev;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800549
550 if (property == dev->mode_config.scaling_mode_property &&
551 connector->encoder) {
552 struct drm_crtc *crtc = connector->encoder->crtc;
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800553 struct drm_encoder *encoder = connector->encoder;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100554 struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800555
Jesse Barnes53bd8382009-07-01 10:04:40 -0700556 if (value == DRM_MODE_SCALE_NONE) {
557 DRM_DEBUG_KMS("no scaling not supported\n");
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800558 return 0;
559 }
Chris Wilsonea5b2132010-08-04 13:50:23 +0100560 if (intel_lvds->fitting_mode == value) {
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800561 /* the LVDS scaling property is not changed */
562 return 0;
563 }
Chris Wilsonea5b2132010-08-04 13:50:23 +0100564 intel_lvds->fitting_mode = value;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800565 if (crtc && crtc->enabled) {
566 /*
567 * If the CRTC is enabled, the display will be changed
568 * according to the new panel fitting mode.
569 */
570 drm_crtc_helper_set_mode(crtc, &crtc->mode,
571 crtc->x, crtc->y, crtc->fb);
572 }
573 }
574
Jesse Barnes335041e2009-01-22 22:22:06 +1000575 return 0;
576}
577
Jesse Barnes79e53942008-11-07 14:24:08 -0800578static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
579 .dpms = intel_lvds_dpms,
580 .mode_fixup = intel_lvds_mode_fixup,
581 .prepare = intel_lvds_prepare,
582 .mode_set = intel_lvds_mode_set,
583 .commit = intel_lvds_commit,
584};
585
586static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
587 .get_modes = intel_lvds_get_modes,
588 .mode_valid = intel_lvds_mode_valid,
Chris Wilsondf0e9242010-09-09 16:20:55 +0100589 .best_encoder = intel_best_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800590};
591
592static const struct drm_connector_funcs intel_lvds_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700593 .dpms = drm_helper_connector_dpms,
Jesse Barnes79e53942008-11-07 14:24:08 -0800594 .detect = intel_lvds_detect,
595 .fill_modes = drm_helper_probe_single_connector_modes,
Jesse Barnes335041e2009-01-22 22:22:06 +1000596 .set_property = intel_lvds_set_property,
Jesse Barnes79e53942008-11-07 14:24:08 -0800597 .destroy = intel_lvds_destroy,
598};
599
Jesse Barnes79e53942008-11-07 14:24:08 -0800600static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100601 .destroy = intel_encoder_destroy,
Jesse Barnes79e53942008-11-07 14:24:08 -0800602};
603
Jarod Wilson425d2442009-05-05 10:00:25 -0400604static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
605{
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800606 DRM_DEBUG_KMS("Skipping LVDS initialization for %s\n", id->ident);
Jarod Wilson425d2442009-05-05 10:00:25 -0400607 return 1;
608}
Jesse Barnes79e53942008-11-07 14:24:08 -0800609
Jarod Wilson425d2442009-05-05 10:00:25 -0400610/* These systems claim to have LVDS, but really don't */
Jaswinder Singh Rajput93c05f22009-06-04 09:41:19 +1000611static const struct dmi_system_id intel_no_lvds[] = {
Jarod Wilson425d2442009-05-05 10:00:25 -0400612 {
613 .callback = intel_no_lvds_dmi_callback,
614 .ident = "Apple Mac Mini (Core series)",
615 .matches = {
Keith Packard98acd462009-06-14 12:31:58 -0700616 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
Jarod Wilson425d2442009-05-05 10:00:25 -0400617 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
618 },
619 },
620 {
621 .callback = intel_no_lvds_dmi_callback,
622 .ident = "Apple Mac Mini (Core 2 series)",
623 .matches = {
Keith Packard98acd462009-06-14 12:31:58 -0700624 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
Jarod Wilson425d2442009-05-05 10:00:25 -0400625 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
626 },
627 },
628 {
629 .callback = intel_no_lvds_dmi_callback,
630 .ident = "MSI IM-945GSE-A",
631 .matches = {
632 DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
633 DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
634 },
635 },
636 {
637 .callback = intel_no_lvds_dmi_callback,
638 .ident = "Dell Studio Hybrid",
639 .matches = {
640 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
641 DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
642 },
643 },
Jarod Wilson70aa96c2009-05-27 17:20:39 -0400644 {
645 .callback = intel_no_lvds_dmi_callback,
646 .ident = "AOpen Mini PC",
647 .matches = {
648 DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
649 DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
650 },
651 },
Michael Cousinfa0864b2009-06-05 21:16:22 +0200652 {
653 .callback = intel_no_lvds_dmi_callback,
Tormod Voldened8c7542009-07-13 22:26:48 +0200654 .ident = "AOpen Mini PC MP915",
655 .matches = {
656 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
657 DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
658 },
659 },
660 {
661 .callback = intel_no_lvds_dmi_callback,
Michael Cousinfa0864b2009-06-05 21:16:22 +0200662 .ident = "Aopen i945GTt-VFA",
663 .matches = {
664 DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
665 },
666 },
Stefan Bader98755572010-03-29 17:53:12 +0200667 {
668 .callback = intel_no_lvds_dmi_callback,
669 .ident = "Clientron U800",
670 .matches = {
671 DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
672 DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
673 },
674 },
Jarod Wilson425d2442009-05-05 10:00:25 -0400675
676 { } /* terminating entry */
677};
Jesse Barnes79e53942008-11-07 14:24:08 -0800678
679/**
Zhao Yakui18f9ed12009-11-20 03:24:16 +0000680 * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
681 * @dev: drm device
682 * @connector: LVDS connector
683 *
684 * Find the reduced downclock for LVDS in EDID.
685 */
686static void intel_find_lvds_downclock(struct drm_device *dev,
687 struct drm_connector *connector)
688{
689 struct drm_i915_private *dev_priv = dev->dev_private;
690 struct drm_display_mode *scan, *panel_fixed_mode;
691 int temp_downclock;
692
693 panel_fixed_mode = dev_priv->panel_fixed_mode;
694 temp_downclock = panel_fixed_mode->clock;
695
696 mutex_lock(&dev->mode_config.mutex);
697 list_for_each_entry(scan, &connector->probed_modes, head) {
698 /*
699 * If one mode has the same resolution with the fixed_panel
700 * mode while they have the different refresh rate, it means
701 * that the reduced downclock is found for the LVDS. In such
702 * case we can set the different FPx0/1 to dynamically select
703 * between low and high frequency.
704 */
705 if (scan->hdisplay == panel_fixed_mode->hdisplay &&
706 scan->hsync_start == panel_fixed_mode->hsync_start &&
707 scan->hsync_end == panel_fixed_mode->hsync_end &&
708 scan->htotal == panel_fixed_mode->htotal &&
709 scan->vdisplay == panel_fixed_mode->vdisplay &&
710 scan->vsync_start == panel_fixed_mode->vsync_start &&
711 scan->vsync_end == panel_fixed_mode->vsync_end &&
712 scan->vtotal == panel_fixed_mode->vtotal) {
713 if (scan->clock < temp_downclock) {
714 /*
715 * The downclock is already found. But we
716 * expect to find the lower downclock.
717 */
718 temp_downclock = scan->clock;
719 }
720 }
721 }
722 mutex_unlock(&dev->mode_config.mutex);
Jesse Barnes33814342010-01-14 20:48:02 +0000723 if (temp_downclock < panel_fixed_mode->clock &&
724 i915_lvds_downclock) {
Zhao Yakui18f9ed12009-11-20 03:24:16 +0000725 /* We found the downclock for LVDS. */
726 dev_priv->lvds_downclock_avail = 1;
727 dev_priv->lvds_downclock = temp_downclock;
728 DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
729 "Normal clock %dKhz, downclock %dKhz\n",
730 panel_fixed_mode->clock, temp_downclock);
731 }
732 return;
733}
734
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800735/*
736 * Enumerate the child dev array parsed from VBT to check whether
737 * the LVDS is present.
738 * If it is present, return 1.
739 * If it is not present, return false.
740 * If no child dev is parsed from VBT, it assumes that the LVDS is present.
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800741 */
Chris Wilson425904d2010-08-22 18:21:42 +0100742static bool lvds_is_present_in_vbt(struct drm_device *dev)
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800743{
744 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson425904d2010-08-22 18:21:42 +0100745 int i;
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800746
747 if (!dev_priv->child_dev_num)
Chris Wilson425904d2010-08-22 18:21:42 +0100748 return true;
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800749
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800750 for (i = 0; i < dev_priv->child_dev_num; i++) {
Chris Wilson425904d2010-08-22 18:21:42 +0100751 struct child_device_config *child = dev_priv->child_dev + i;
752
753 /* If the device type is not LFP, continue.
754 * We have to check both the new identifiers as well as the
755 * old for compatibility with some BIOSes.
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800756 */
Chris Wilson425904d2010-08-22 18:21:42 +0100757 if (child->device_type != DEVICE_TYPE_INT_LFP &&
758 child->device_type != DEVICE_TYPE_LFP)
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800759 continue;
760
Chris Wilson425904d2010-08-22 18:21:42 +0100761 /* However, we cannot trust the BIOS writers to populate
762 * the VBT correctly. Since LVDS requires additional
763 * information from AIM blocks, a non-zero addin offset is
764 * a good indicator that the LVDS is actually present.
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800765 */
Chris Wilson425904d2010-08-22 18:21:42 +0100766 if (child->addin_offset)
767 return true;
768
769 /* But even then some BIOS writers perform some black magic
770 * and instantiate the device without reference to any
771 * additional data. Trust that if the VBT was written into
772 * the OpRegion then they have validated the LVDS's existence.
773 */
774 if (dev_priv->opregion.vbt)
775 return true;
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800776 }
Chris Wilson425904d2010-08-22 18:21:42 +0100777
778 return false;
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800779}
780
Zhao Yakui18f9ed12009-11-20 03:24:16 +0000781/**
Jesse Barnes79e53942008-11-07 14:24:08 -0800782 * intel_lvds_init - setup LVDS connectors on this device
783 * @dev: drm device
784 *
785 * Create the connector, register the LVDS DDC bus, and try to figure out what
786 * modes we can display on the LVDS panel (if present).
787 */
788void intel_lvds_init(struct drm_device *dev)
789{
790 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100791 struct intel_lvds *intel_lvds;
Eric Anholt21d40d32010-03-25 11:11:14 -0700792 struct intel_encoder *intel_encoder;
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800793 struct intel_connector *intel_connector;
Jesse Barnes79e53942008-11-07 14:24:08 -0800794 struct drm_connector *connector;
795 struct drm_encoder *encoder;
796 struct drm_display_mode *scan; /* *modes, *bios_mode; */
797 struct drm_crtc *crtc;
798 u32 lvds;
Zhenyu Wang541998a2009-06-05 15:38:44 +0800799 int pipe, gpio = GPIOC;
Jesse Barnes79e53942008-11-07 14:24:08 -0800800
Jarod Wilson425d2442009-05-05 10:00:25 -0400801 /* Skip init on machines we know falsely report LVDS */
802 if (dmi_check_system(intel_no_lvds))
Paul Collins565dcd42009-02-04 23:05:41 +1300803 return;
Paul Collins565dcd42009-02-04 23:05:41 +1300804
Matthew Garrett11ba1592009-12-15 13:55:24 -0500805 if (!lvds_is_present_in_vbt(dev)) {
806 DRM_DEBUG_KMS("LVDS is not present in VBT\n");
Zhao Yakuie99da352009-06-26 09:46:18 +0800807 return;
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800808 }
Zhao Yakuie99da352009-06-26 09:46:18 +0800809
Eric Anholtc619eed2010-01-28 16:45:52 -0800810 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang541998a2009-06-05 15:38:44 +0800811 if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
812 return;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800813 if (dev_priv->edp_support) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800814 DRM_DEBUG_KMS("disable LVDS for eDP support\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800815 return;
816 }
Zhenyu Wang541998a2009-06-05 15:38:44 +0800817 gpio = PCH_GPIOC;
818 }
819
Chris Wilsonea5b2132010-08-04 13:50:23 +0100820 intel_lvds = kzalloc(sizeof(struct intel_lvds), GFP_KERNEL);
821 if (!intel_lvds) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800822 return;
823 }
824
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800825 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
826 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100827 kfree(intel_lvds);
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800828 return;
829 }
830
Chris Wilsonea5b2132010-08-04 13:50:23 +0100831 intel_encoder = &intel_lvds->base;
Chris Wilson4ef69c72010-09-09 15:14:28 +0100832 encoder = &intel_encoder->base;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100833 connector = &intel_connector->base;
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800834 drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800835 DRM_MODE_CONNECTOR_LVDS);
836
Chris Wilson4ef69c72010-09-09 15:14:28 +0100837 drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800838 DRM_MODE_ENCODER_LVDS);
839
Chris Wilsondf0e9242010-09-09 16:20:55 +0100840 intel_connector_attach_encoder(intel_connector, intel_encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -0700841 intel_encoder->type = INTEL_OUTPUT_LVDS;
Jesse Barnes79e53942008-11-07 14:24:08 -0800842
Eric Anholt21d40d32010-03-25 11:11:14 -0700843 intel_encoder->clone_mask = (1 << INTEL_LVDS_CLONE_BIT);
844 intel_encoder->crtc_mask = (1 << 1);
Jesse Barnes79e53942008-11-07 14:24:08 -0800845 drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
846 drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
847 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
848 connector->interlace_allowed = false;
849 connector->doublescan_allowed = false;
850
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800851 /* create the scaling mode property */
852 drm_mode_create_scaling_mode_property(dev);
853 /*
854 * the initial panel fitting mode will be FULL_SCREEN.
855 */
Jesse Barnes79e53942008-11-07 14:24:08 -0800856
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800857 drm_connector_attach_property(&intel_connector->base,
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800858 dev->mode_config.scaling_mode_property,
Jesse Barnesdd1ea372010-06-24 11:05:10 -0700859 DRM_MODE_SCALE_ASPECT);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100860 intel_lvds->fitting_mode = DRM_MODE_SCALE_ASPECT;
Jesse Barnes79e53942008-11-07 14:24:08 -0800861 /*
862 * LVDS discovery:
863 * 1) check for EDID on DDC
864 * 2) check for VBT data
865 * 3) check to see if LVDS is already on
866 * if none of the above, no panel
867 * 4) make sure lid is open
868 * if closed, act like it's not there for now
869 */
870
871 /* Set up the DDC bus. */
Eric Anholt21d40d32010-03-25 11:11:14 -0700872 intel_encoder->ddc_bus = intel_i2c_create(dev, gpio, "LVDSDDC_C");
873 if (!intel_encoder->ddc_bus) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800874 dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
875 "failed.\n");
876 goto failed;
877 }
878
879 /*
880 * Attempt to get the fixed panel mode from DDC. Assume that the
881 * preferred mode is the right one.
882 */
Zhao Yakuibfac4d62010-04-07 17:11:22 +0800883 dev_priv->lvds_edid_good = true;
884
Zhenyu Wang335af9a2010-03-30 14:39:31 +0800885 if (!intel_ddc_get_modes(connector, intel_encoder->ddc_bus))
Zhao Yakuibfac4d62010-04-07 17:11:22 +0800886 dev_priv->lvds_edid_good = false;
Jesse Barnes79e53942008-11-07 14:24:08 -0800887
888 list_for_each_entry(scan, &connector->probed_modes, head) {
889 mutex_lock(&dev->mode_config.mutex);
890 if (scan->type & DRM_MODE_TYPE_PREFERRED) {
891 dev_priv->panel_fixed_mode =
892 drm_mode_duplicate(dev, scan);
893 mutex_unlock(&dev->mode_config.mutex);
Zhao Yakui18f9ed12009-11-20 03:24:16 +0000894 intel_find_lvds_downclock(dev, connector);
Paul Collins565dcd42009-02-04 23:05:41 +1300895 goto out;
Jesse Barnes79e53942008-11-07 14:24:08 -0800896 }
897 mutex_unlock(&dev->mode_config.mutex);
898 }
899
900 /* Failed to get EDID, what about VBT? */
Ma Ling88631702009-05-13 11:19:55 +0800901 if (dev_priv->lfp_lvds_vbt_mode) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800902 mutex_lock(&dev->mode_config.mutex);
903 dev_priv->panel_fixed_mode =
Ma Ling88631702009-05-13 11:19:55 +0800904 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
Jesse Barnes79e53942008-11-07 14:24:08 -0800905 mutex_unlock(&dev->mode_config.mutex);
Jesse Barnese285f3c2009-01-14 10:53:36 -0800906 if (dev_priv->panel_fixed_mode) {
907 dev_priv->panel_fixed_mode->type |=
908 DRM_MODE_TYPE_PREFERRED;
Jesse Barnese285f3c2009-01-14 10:53:36 -0800909 goto out;
910 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800911 }
912
913 /*
914 * If we didn't get EDID, try checking if the panel is already turned
915 * on. If so, assume that whatever is currently programmed is the
916 * correct mode.
917 */
Zhenyu Wang541998a2009-06-05 15:38:44 +0800918
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500919 /* Ironlake: FIXME if still fail, not try pipe mode now */
Eric Anholtc619eed2010-01-28 16:45:52 -0800920 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang541998a2009-06-05 15:38:44 +0800921 goto failed;
922
Jesse Barnes79e53942008-11-07 14:24:08 -0800923 lvds = I915_READ(LVDS);
924 pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
Chris Wilsonf875c152010-09-09 15:44:14 +0100925 crtc = intel_get_crtc_for_pipe(dev, pipe);
Jesse Barnes79e53942008-11-07 14:24:08 -0800926
927 if (crtc && (lvds & LVDS_PORT_EN)) {
928 dev_priv->panel_fixed_mode = intel_crtc_mode_get(dev, crtc);
929 if (dev_priv->panel_fixed_mode) {
930 dev_priv->panel_fixed_mode->type |=
931 DRM_MODE_TYPE_PREFERRED;
Paul Collins565dcd42009-02-04 23:05:41 +1300932 goto out;
Jesse Barnes79e53942008-11-07 14:24:08 -0800933 }
934 }
935
936 /* If we still don't have a mode after all that, give up. */
937 if (!dev_priv->panel_fixed_mode)
938 goto failed;
939
Jesse Barnes79e53942008-11-07 14:24:08 -0800940out:
Eric Anholtc619eed2010-01-28 16:45:52 -0800941 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang541998a2009-06-05 15:38:44 +0800942 u32 pwm;
943 /* make sure PWM is enabled */
944 pwm = I915_READ(BLC_PWM_CPU_CTL2);
945 pwm |= (PWM_ENABLE | PWM_PIPE_B);
946 I915_WRITE(BLC_PWM_CPU_CTL2, pwm);
947
948 pwm = I915_READ(BLC_PWM_PCH_CTL1);
949 pwm |= PWM_PCH_ENABLE;
950 I915_WRITE(BLC_PWM_PCH_CTL1, pwm);
951 }
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700952 dev_priv->lid_notifier.notifier_call = intel_lid_notify;
953 if (acpi_lid_notifier_register(&dev_priv->lid_notifier)) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800954 DRM_DEBUG_KMS("lid notifier registration failed\n");
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700955 dev_priv->lid_notifier.notifier_call = NULL;
956 }
Zhao Yakuia2565372009-12-11 09:26:11 +0800957 /* keep the LVDS connector */
958 dev_priv->int_lvds_connector = connector;
Jesse Barnes79e53942008-11-07 14:24:08 -0800959 drm_sysfs_connector_add(connector);
960 return;
961
962failed:
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800963 DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
Eric Anholt21d40d32010-03-25 11:11:14 -0700964 if (intel_encoder->ddc_bus)
965 intel_i2c_destroy(intel_encoder->ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -0800966 drm_connector_cleanup(connector);
Shaohua Li1991bdf2009-11-17 17:19:23 +0800967 drm_encoder_cleanup(encoder);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100968 kfree(intel_lvds);
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800969 kfree(intel_connector);
Jesse Barnes79e53942008-11-07 14:24:08 -0800970}