blob: cb5821eb59b635593103e896f4ac11abc20ba969 [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{
53 return container_of(enc_to_intel_encoder(encoder), struct intel_lvds, base);
54}
55
Jesse Barnes79e53942008-11-07 14:24:08 -080056/**
57 * Sets the backlight level.
58 *
59 * \param level backlight level, from 0 to intel_lvds_get_max_backlight().
60 */
61static void intel_lvds_set_backlight(struct drm_device *dev, int level)
62{
63 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang541998a2009-06-05 15:38:44 +080064 u32 blc_pwm_ctl, reg;
Jesse Barnes79e53942008-11-07 14:24:08 -080065
Eric Anholtc619eed2010-01-28 16:45:52 -080066 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang541998a2009-06-05 15:38:44 +080067 reg = BLC_PWM_CPU_CTL;
68 else
69 reg = BLC_PWM_CTL;
70
71 blc_pwm_ctl = I915_READ(reg) & ~BACKLIGHT_DUTY_CYCLE_MASK;
72 I915_WRITE(reg, (blc_pwm_ctl |
Jesse Barnes79e53942008-11-07 14:24:08 -080073 (level << BACKLIGHT_DUTY_CYCLE_SHIFT)));
74}
75
76/**
77 * Returns the maximum level of the backlight duty cycle field.
78 */
79static u32 intel_lvds_get_max_backlight(struct drm_device *dev)
80{
81 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang541998a2009-06-05 15:38:44 +080082 u32 reg;
Jesse Barnes79e53942008-11-07 14:24:08 -080083
Eric Anholtc619eed2010-01-28 16:45:52 -080084 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang541998a2009-06-05 15:38:44 +080085 reg = BLC_PWM_PCH_CTL2;
86 else
87 reg = BLC_PWM_CTL;
88
89 return ((I915_READ(reg) & BACKLIGHT_MODULATION_FREQ_MASK) >>
Jesse Barnes79e53942008-11-07 14:24:08 -080090 BACKLIGHT_MODULATION_FREQ_SHIFT) * 2;
91}
92
93/**
94 * Sets the power state for the panel.
95 */
96static void intel_lvds_set_power(struct drm_device *dev, bool on)
97{
98 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes469d1292010-02-11 12:41:05 -080099 u32 pp_status, ctl_reg, status_reg, lvds_reg;
Zhenyu Wang541998a2009-06-05 15:38:44 +0800100
Eric Anholtc619eed2010-01-28 16:45:52 -0800101 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang541998a2009-06-05 15:38:44 +0800102 ctl_reg = PCH_PP_CONTROL;
103 status_reg = PCH_PP_STATUS;
Jesse Barnes469d1292010-02-11 12:41:05 -0800104 lvds_reg = PCH_LVDS;
Zhenyu Wang541998a2009-06-05 15:38:44 +0800105 } else {
106 ctl_reg = PP_CONTROL;
107 status_reg = PP_STATUS;
Jesse Barnes469d1292010-02-11 12:41:05 -0800108 lvds_reg = LVDS;
Zhenyu Wang541998a2009-06-05 15:38:44 +0800109 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800110
111 if (on) {
Jesse Barnes469d1292010-02-11 12:41:05 -0800112 I915_WRITE(lvds_reg, I915_READ(lvds_reg) | LVDS_PORT_EN);
113 POSTING_READ(lvds_reg);
114
Zhenyu Wang541998a2009-06-05 15:38:44 +0800115 I915_WRITE(ctl_reg, I915_READ(ctl_reg) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800116 POWER_TARGET_ON);
117 do {
Zhenyu Wang541998a2009-06-05 15:38:44 +0800118 pp_status = I915_READ(status_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -0800119 } while ((pp_status & PP_ON) == 0);
120
121 intel_lvds_set_backlight(dev, dev_priv->backlight_duty_cycle);
122 } else {
123 intel_lvds_set_backlight(dev, 0);
124
Zhenyu Wang541998a2009-06-05 15:38:44 +0800125 I915_WRITE(ctl_reg, I915_READ(ctl_reg) &
Jesse Barnes79e53942008-11-07 14:24:08 -0800126 ~POWER_TARGET_ON);
127 do {
Zhenyu Wang541998a2009-06-05 15:38:44 +0800128 pp_status = I915_READ(status_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -0800129 } while (pp_status & PP_ON);
Jesse Barnes469d1292010-02-11 12:41:05 -0800130
131 I915_WRITE(lvds_reg, I915_READ(lvds_reg) & ~LVDS_PORT_EN);
132 POSTING_READ(lvds_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -0800133 }
134}
135
136static void intel_lvds_dpms(struct drm_encoder *encoder, int mode)
137{
138 struct drm_device *dev = encoder->dev;
139
140 if (mode == DRM_MODE_DPMS_ON)
141 intel_lvds_set_power(dev, true);
142 else
143 intel_lvds_set_power(dev, false);
144
145 /* XXX: We never power down the LVDS pairs. */
146}
147
Jesse Barnes79e53942008-11-07 14:24:08 -0800148static int intel_lvds_mode_valid(struct drm_connector *connector,
149 struct drm_display_mode *mode)
150{
151 struct drm_device *dev = connector->dev;
152 struct drm_i915_private *dev_priv = dev->dev_private;
153 struct drm_display_mode *fixed_mode = dev_priv->panel_fixed_mode;
154
155 if (fixed_mode) {
156 if (mode->hdisplay > fixed_mode->hdisplay)
157 return MODE_PANEL;
158 if (mode->vdisplay > fixed_mode->vdisplay)
159 return MODE_PANEL;
160 }
161
162 return MODE_OK;
163}
164
Chris Wilson49be6632010-07-18 12:05:54 +0100165static void
166centre_horizontally(struct drm_display_mode *mode,
167 int width)
168{
169 u32 border, sync_pos, blank_width, sync_width;
170
171 /* keep the hsync and hblank widths constant */
172 sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start;
173 blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start;
174 sync_pos = (blank_width - sync_width + 1) / 2;
175
176 border = (mode->hdisplay - width + 1) / 2;
177 border += border & 1; /* make the border even */
178
179 mode->crtc_hdisplay = width;
180 mode->crtc_hblank_start = width + border;
181 mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width;
182
183 mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;
184 mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;
185}
186
187static void
188centre_vertically(struct drm_display_mode *mode,
189 int height)
190{
191 u32 border, sync_pos, blank_width, sync_width;
192
193 /* keep the vsync and vblank widths constant */
194 sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start;
195 blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start;
196 sync_pos = (blank_width - sync_width + 1) / 2;
197
198 border = (mode->vdisplay - height + 1) / 2;
199
200 mode->crtc_vdisplay = height;
201 mode->crtc_vblank_start = height + border;
202 mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;
203
204 mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
205 mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
206}
207
208static inline u32 panel_fitter_scaling(u32 source, u32 target)
209{
210 /*
211 * Floating point operation is not supported. So the FACTOR
212 * is defined, which can avoid the floating point computation
213 * when calculating the panel ratio.
214 */
215#define ACCURACY 12
216#define FACTOR (1 << ACCURACY)
217 u32 ratio = source * FACTOR / target;
218 return (FACTOR * ratio + FACTOR/2) / FACTOR;
219}
220
Jesse Barnes79e53942008-11-07 14:24:08 -0800221static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
222 struct drm_display_mode *mode,
223 struct drm_display_mode *adjusted_mode)
224{
225 struct drm_device *dev = encoder->dev;
226 struct drm_i915_private *dev_priv = dev->dev_private;
227 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100228 struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -0800229 struct drm_encoder *tmp_encoder;
Chris Wilson49be6632010-07-18 12:05:54 +0100230 u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
Jesse Barnes79e53942008-11-07 14:24:08 -0800231
232 /* Should never happen!! */
233 if (!IS_I965G(dev) && intel_crtc->pipe == 0) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700234 DRM_ERROR("Can't support LVDS on pipe A\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800235 return false;
236 }
237
238 /* Should never happen!! */
239 list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) {
240 if (tmp_encoder != encoder && tmp_encoder->crtc == encoder->crtc) {
Keith Packard1ae8c0a2009-06-28 15:42:17 -0700241 DRM_ERROR("Can't enable LVDS and another "
Jesse Barnes79e53942008-11-07 14:24:08 -0800242 "encoder on the same pipe\n");
243 return false;
244 }
245 }
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800246 /* If we don't have a panel mode, there is nothing we can do */
247 if (dev_priv->panel_fixed_mode == NULL)
248 return true;
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100249
Jesse Barnes79e53942008-11-07 14:24:08 -0800250 /*
Chris Wilson71677042010-07-17 13:38:43 +0100251 * We have timings from the BIOS for the panel, put them in
Jesse Barnes79e53942008-11-07 14:24:08 -0800252 * to the adjusted mode. The CRTC will be set up for this mode,
253 * with the panel scaling set up to source from the H/VDisplay
254 * of the original mode.
255 */
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100256 intel_fixed_panel_mode(dev_priv->panel_fixed_mode, adjusted_mode);
257
258 if (HAS_PCH_SPLIT(dev)) {
259 intel_pch_panel_fitting(dev, intel_lvds->fitting_mode,
260 mode, adjusted_mode);
261 return true;
262 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800263
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800264 /* Make sure pre-965s set dither correctly */
265 if (!IS_I965G(dev)) {
266 if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
267 pfit_control |= PANEL_8TO6_DITHER_ENABLE;
268 }
269
270 /* Native modes don't need fitting */
271 if (adjusted_mode->hdisplay == mode->hdisplay &&
Chris Wilson49be6632010-07-18 12:05:54 +0100272 adjusted_mode->vdisplay == mode->vdisplay)
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800273 goto out;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800274
275 /* 965+ wants fuzzy fitting */
276 if (IS_I965G(dev))
Chris Wilson49be6632010-07-18 12:05:54 +0100277 pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) |
278 PFIT_FILTER_FUZZY);
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800279
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800280 /*
281 * Enable automatic panel scaling for non-native modes so that they fill
282 * the screen. Should be enabled before the pipe is enabled, according
283 * to register description and PRM.
284 * Change the value here to see the borders for debugging
285 */
Chris Wilson1d8e1c72010-08-07 11:01:28 +0100286 I915_WRITE(BCLRPAT_A, 0);
287 I915_WRITE(BCLRPAT_B, 0);
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800288
Chris Wilsonea5b2132010-08-04 13:50:23 +0100289 switch (intel_lvds->fitting_mode) {
Jesse Barnes53bd8382009-07-01 10:04:40 -0700290 case DRM_MODE_SCALE_CENTER:
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800291 /*
292 * For centered modes, we have to calculate border widths &
293 * heights and modify the values programmed into the CRTC.
294 */
Chris Wilson49be6632010-07-18 12:05:54 +0100295 centre_horizontally(adjusted_mode, mode->hdisplay);
296 centre_vertically(adjusted_mode, mode->vdisplay);
297 border = LVDS_BORDER_ENABLE;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800298 break;
Chris Wilson49be6632010-07-18 12:05:54 +0100299
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800300 case DRM_MODE_SCALE_ASPECT:
Chris Wilson49be6632010-07-18 12:05:54 +0100301 /* Scale but preserve the aspect ratio */
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800302 if (IS_I965G(dev)) {
Chris Wilson49be6632010-07-18 12:05:54 +0100303 u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
304 u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
305
306 pfit_control |= PFIT_ENABLE;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800307 /* 965+ is easy, it does everything in hw */
Chris Wilson49be6632010-07-18 12:05:54 +0100308 if (scaled_width > scaled_height)
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800309 pfit_control |= PFIT_SCALING_PILLAR;
Chris Wilson49be6632010-07-18 12:05:54 +0100310 else if (scaled_width < scaled_height)
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800311 pfit_control |= PFIT_SCALING_LETTER;
312 else
313 pfit_control |= PFIT_SCALING_AUTO;
314 } else {
Chris Wilson49be6632010-07-18 12:05:54 +0100315 u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
316 u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800317 /*
318 * For earlier chips we have to calculate the scaling
319 * ratio by hand and program it into the
320 * PFIT_PGM_RATIO register
321 */
Chris Wilson49be6632010-07-18 12:05:54 +0100322 if (scaled_width > scaled_height) { /* pillar */
323 centre_horizontally(adjusted_mode, scaled_height / mode->vdisplay);
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800324
Chris Wilson49be6632010-07-18 12:05:54 +0100325 border = LVDS_BORDER_ENABLE;
326 if (mode->vdisplay != adjusted_mode->vdisplay) {
327 u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay);
328 pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
329 bits << PFIT_VERT_SCALE_SHIFT);
330 pfit_control |= (PFIT_ENABLE |
331 VERT_INTERP_BILINEAR |
332 HORIZ_INTERP_BILINEAR);
333 }
334 } else if (scaled_width < scaled_height) { /* letter */
335 centre_vertically(adjusted_mode, scaled_width / mode->hdisplay);
336
337 border = LVDS_BORDER_ENABLE;
338 if (mode->hdisplay != adjusted_mode->hdisplay) {
339 u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay);
340 pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
341 bits << PFIT_VERT_SCALE_SHIFT);
342 pfit_control |= (PFIT_ENABLE |
343 VERT_INTERP_BILINEAR |
344 HORIZ_INTERP_BILINEAR);
345 }
346 } else
347 /* Aspects match, Let hw scale both directions */
348 pfit_control |= (PFIT_ENABLE |
349 VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800350 VERT_INTERP_BILINEAR |
351 HORIZ_INTERP_BILINEAR);
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800352 }
353 break;
354
355 case DRM_MODE_SCALE_FULLSCREEN:
356 /*
357 * Full scaling, even if it changes the aspect ratio.
358 * Fortunately this is all done for us in hw.
359 */
360 pfit_control |= PFIT_ENABLE;
361 if (IS_I965G(dev))
362 pfit_control |= PFIT_SCALING_AUTO;
363 else
364 pfit_control |= (VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
365 VERT_INTERP_BILINEAR |
366 HORIZ_INTERP_BILINEAR);
367 break;
Chris Wilson49be6632010-07-18 12:05:54 +0100368
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800369 default:
370 break;
371 }
372
373out:
Chris Wilsonea5b2132010-08-04 13:50:23 +0100374 intel_lvds->pfit_control = pfit_control;
375 intel_lvds->pfit_pgm_ratios = pfit_pgm_ratios;
Chris Wilson49be6632010-07-18 12:05:54 +0100376 dev_priv->lvds_border_bits = border;
377
Zhao Yakuia3e17eb2009-10-10 10:42:37 +0800378 /*
Jesse Barnes79e53942008-11-07 14:24:08 -0800379 * XXX: It would be nice to support lower refresh rates on the
380 * panels to reduce power consumption, and perhaps match the
381 * user's requested refresh rate.
382 */
383
384 return true;
385}
386
387static void intel_lvds_prepare(struct drm_encoder *encoder)
388{
389 struct drm_device *dev = encoder->dev;
390 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang541998a2009-06-05 15:38:44 +0800391 u32 reg;
Jesse Barnes79e53942008-11-07 14:24:08 -0800392
Eric Anholtc619eed2010-01-28 16:45:52 -0800393 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang541998a2009-06-05 15:38:44 +0800394 reg = BLC_PWM_CPU_CTL;
395 else
396 reg = BLC_PWM_CTL;
397
398 dev_priv->saveBLC_PWM_CTL = I915_READ(reg);
Jesse Barnes79e53942008-11-07 14:24:08 -0800399 dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL &
400 BACKLIGHT_DUTY_CYCLE_MASK);
401
402 intel_lvds_set_power(dev, false);
403}
404
405static void intel_lvds_commit( struct drm_encoder *encoder)
406{
407 struct drm_device *dev = encoder->dev;
408 struct drm_i915_private *dev_priv = dev->dev_private;
409
410 if (dev_priv->backlight_duty_cycle == 0)
411 dev_priv->backlight_duty_cycle =
412 intel_lvds_get_max_backlight(dev);
413
414 intel_lvds_set_power(dev, true);
415}
416
417static void intel_lvds_mode_set(struct drm_encoder *encoder,
418 struct drm_display_mode *mode,
419 struct drm_display_mode *adjusted_mode)
420{
421 struct drm_device *dev = encoder->dev;
422 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100423 struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -0800424
425 /*
426 * The LVDS pin pair will already have been turned on in the
427 * intel_crtc_mode_set since it has a large impact on the DPLL
428 * settings.
429 */
430
Eric Anholtc619eed2010-01-28 16:45:52 -0800431 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang541998a2009-06-05 15:38:44 +0800432 return;
433
Jesse Barnes79e53942008-11-07 14:24:08 -0800434 /*
435 * Enable automatic panel scaling so that non-native modes fill the
436 * screen. Should be enabled before the pipe is enabled, according to
437 * register description and PRM.
438 */
Chris Wilsonea5b2132010-08-04 13:50:23 +0100439 I915_WRITE(PFIT_PGM_RATIOS, intel_lvds->pfit_pgm_ratios);
440 I915_WRITE(PFIT_CONTROL, intel_lvds->pfit_control);
Jesse Barnes79e53942008-11-07 14:24:08 -0800441}
442
443/**
444 * Detect the LVDS connection.
445 *
Jesse Barnesb42d4c52009-09-10 15:28:04 -0700446 * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
447 * connected and closed means disconnected. We also send hotplug events as
448 * needed, using lid status notification from the input layer.
Jesse Barnes79e53942008-11-07 14:24:08 -0800449 */
450static enum drm_connector_status intel_lvds_detect(struct drm_connector *connector)
451{
Jesse Barnes7b9c5ab2010-02-12 09:30:00 -0800452 struct drm_device *dev = connector->dev;
Jesse Barnesb42d4c52009-09-10 15:28:04 -0700453 enum drm_connector_status status = connector_status_connected;
454
Jesse Barnes7b9c5ab2010-02-12 09:30:00 -0800455 /* ACPI lid methods were generally unreliable in this generation, so
456 * don't even bother.
457 */
Eric Anholt6e6c8222010-03-17 13:48:06 -0700458 if (IS_GEN2(dev) || IS_GEN3(dev))
Jesse Barnes7b9c5ab2010-02-12 09:30:00 -0800459 return connector_status_connected;
460
Jesse Barnesb42d4c52009-09-10 15:28:04 -0700461 return status;
Jesse Barnes79e53942008-11-07 14:24:08 -0800462}
463
464/**
465 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
466 */
467static int intel_lvds_get_modes(struct drm_connector *connector)
468{
469 struct drm_device *dev = connector->dev;
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800470 struct drm_encoder *encoder = intel_attached_encoder(connector);
471 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -0800472 struct drm_i915_private *dev_priv = dev->dev_private;
473 int ret = 0;
474
Zhao Yakuibfac4d62010-04-07 17:11:22 +0800475 if (dev_priv->lvds_edid_good) {
Zhenyu Wang335af9a2010-03-30 14:39:31 +0800476 ret = intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -0800477
Zhao Yakuibfac4d62010-04-07 17:11:22 +0800478 if (ret)
479 return ret;
480 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800481
482 /* Didn't get an EDID, so
483 * Set wide sync ranges so we get all modes
484 * handed to valid_mode for checking
485 */
486 connector->display_info.min_vfreq = 0;
487 connector->display_info.max_vfreq = 200;
488 connector->display_info.min_hfreq = 0;
489 connector->display_info.max_hfreq = 200;
490
491 if (dev_priv->panel_fixed_mode != NULL) {
492 struct drm_display_mode *mode;
493
Jesse Barnes79e53942008-11-07 14:24:08 -0800494 mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
495 drm_mode_probed_add(connector, mode);
Jesse Barnes79e53942008-11-07 14:24:08 -0800496
497 return 1;
498 }
499
500 return 0;
501}
502
Thomas Bächler0544edf2010-07-02 10:44:23 +0200503static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
504{
505 DRM_DEBUG_KMS("Skipping forced modeset for %s\n", id->ident);
506 return 1;
507}
508
509/* The GPU hangs up on these systems if modeset is performed on LID open */
510static const struct dmi_system_id intel_no_modeset_on_lid[] = {
511 {
512 .callback = intel_no_modeset_on_lid_dmi_callback,
513 .ident = "Toshiba Tecra A11",
514 .matches = {
515 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
516 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
517 },
518 },
519
520 { } /* terminating entry */
521};
522
Linus Torvaldsc9354c82009-11-02 09:29:55 -0800523/*
524 * Lid events. Note the use of 'modeset_on_lid':
525 * - we set it on lid close, and reset it on open
526 * - we use it as a "only once" bit (ie we ignore
527 * duplicate events where it was already properly
528 * set/reset)
529 * - the suspend/resume paths will also set it to
530 * zero, since they restore the mode ("lid open").
531 */
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700532static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
533 void *unused)
534{
535 struct drm_i915_private *dev_priv =
536 container_of(nb, struct drm_i915_private, lid_notifier);
537 struct drm_device *dev = dev_priv->dev;
Zhao Yakuia2565372009-12-11 09:26:11 +0800538 struct drm_connector *connector = dev_priv->int_lvds_connector;
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700539
Zhao Yakuia2565372009-12-11 09:26:11 +0800540 /*
541 * check and update the status of LVDS connector after receiving
542 * the LID nofication event.
543 */
544 if (connector)
545 connector->status = connector->funcs->detect(connector);
Thomas Bächler0544edf2010-07-02 10:44:23 +0200546 /* Don't force modeset on machines where it causes a GPU lockup */
547 if (dmi_check_system(intel_no_modeset_on_lid))
548 return NOTIFY_OK;
Linus Torvaldsc9354c82009-11-02 09:29:55 -0800549 if (!acpi_lid_open()) {
550 dev_priv->modeset_on_lid = 1;
551 return NOTIFY_OK;
Jesse Barnes06891e22009-09-14 10:58:48 -0700552 }
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700553
Linus Torvaldsc9354c82009-11-02 09:29:55 -0800554 if (!dev_priv->modeset_on_lid)
555 return NOTIFY_OK;
556
557 dev_priv->modeset_on_lid = 0;
558
559 mutex_lock(&dev->mode_config.mutex);
560 drm_helper_resume_force_mode(dev);
561 mutex_unlock(&dev->mode_config.mutex);
Jesse Barnes06324192009-09-10 15:28:05 -0700562
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700563 return NOTIFY_OK;
564}
565
Jesse Barnes79e53942008-11-07 14:24:08 -0800566/**
567 * intel_lvds_destroy - unregister and free LVDS structures
568 * @connector: connector to free
569 *
570 * Unregister the DDC bus for this connector then free the driver private
571 * structure.
572 */
573static void intel_lvds_destroy(struct drm_connector *connector)
574{
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700575 struct drm_device *dev = connector->dev;
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700576 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes79e53942008-11-07 14:24:08 -0800577
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700578 if (dev_priv->lid_notifier.notifier_call)
579 acpi_lid_notifier_unregister(&dev_priv->lid_notifier);
Jesse Barnes79e53942008-11-07 14:24:08 -0800580 drm_sysfs_connector_remove(connector);
581 drm_connector_cleanup(connector);
582 kfree(connector);
583}
584
Jesse Barnes335041e2009-01-22 22:22:06 +1000585static int intel_lvds_set_property(struct drm_connector *connector,
586 struct drm_property *property,
587 uint64_t value)
588{
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800589 struct drm_device *dev = connector->dev;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800590
591 if (property == dev->mode_config.scaling_mode_property &&
592 connector->encoder) {
593 struct drm_crtc *crtc = connector->encoder->crtc;
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800594 struct drm_encoder *encoder = connector->encoder;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100595 struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800596
Jesse Barnes53bd8382009-07-01 10:04:40 -0700597 if (value == DRM_MODE_SCALE_NONE) {
598 DRM_DEBUG_KMS("no scaling not supported\n");
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800599 return 0;
600 }
Chris Wilsonea5b2132010-08-04 13:50:23 +0100601 if (intel_lvds->fitting_mode == value) {
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800602 /* the LVDS scaling property is not changed */
603 return 0;
604 }
Chris Wilsonea5b2132010-08-04 13:50:23 +0100605 intel_lvds->fitting_mode = value;
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800606 if (crtc && crtc->enabled) {
607 /*
608 * If the CRTC is enabled, the display will be changed
609 * according to the new panel fitting mode.
610 */
611 drm_crtc_helper_set_mode(crtc, &crtc->mode,
612 crtc->x, crtc->y, crtc->fb);
613 }
614 }
615
Jesse Barnes335041e2009-01-22 22:22:06 +1000616 return 0;
617}
618
Jesse Barnes79e53942008-11-07 14:24:08 -0800619static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
620 .dpms = intel_lvds_dpms,
621 .mode_fixup = intel_lvds_mode_fixup,
622 .prepare = intel_lvds_prepare,
623 .mode_set = intel_lvds_mode_set,
624 .commit = intel_lvds_commit,
625};
626
627static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
628 .get_modes = intel_lvds_get_modes,
629 .mode_valid = intel_lvds_mode_valid,
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800630 .best_encoder = intel_attached_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800631};
632
633static const struct drm_connector_funcs intel_lvds_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -0700634 .dpms = drm_helper_connector_dpms,
Jesse Barnes79e53942008-11-07 14:24:08 -0800635 .detect = intel_lvds_detect,
636 .fill_modes = drm_helper_probe_single_connector_modes,
Jesse Barnes335041e2009-01-22 22:22:06 +1000637 .set_property = intel_lvds_set_property,
Jesse Barnes79e53942008-11-07 14:24:08 -0800638 .destroy = intel_lvds_destroy,
639};
640
Jesse Barnes79e53942008-11-07 14:24:08 -0800641static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100642 .destroy = intel_encoder_destroy,
Jesse Barnes79e53942008-11-07 14:24:08 -0800643};
644
Jarod Wilson425d2442009-05-05 10:00:25 -0400645static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
646{
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800647 DRM_DEBUG_KMS("Skipping LVDS initialization for %s\n", id->ident);
Jarod Wilson425d2442009-05-05 10:00:25 -0400648 return 1;
649}
Jesse Barnes79e53942008-11-07 14:24:08 -0800650
Jarod Wilson425d2442009-05-05 10:00:25 -0400651/* These systems claim to have LVDS, but really don't */
Jaswinder Singh Rajput93c05f22009-06-04 09:41:19 +1000652static const struct dmi_system_id intel_no_lvds[] = {
Jarod Wilson425d2442009-05-05 10:00:25 -0400653 {
654 .callback = intel_no_lvds_dmi_callback,
655 .ident = "Apple Mac Mini (Core series)",
656 .matches = {
Keith Packard98acd462009-06-14 12:31:58 -0700657 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
Jarod Wilson425d2442009-05-05 10:00:25 -0400658 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
659 },
660 },
661 {
662 .callback = intel_no_lvds_dmi_callback,
663 .ident = "Apple Mac Mini (Core 2 series)",
664 .matches = {
Keith Packard98acd462009-06-14 12:31:58 -0700665 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
Jarod Wilson425d2442009-05-05 10:00:25 -0400666 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
667 },
668 },
669 {
670 .callback = intel_no_lvds_dmi_callback,
671 .ident = "MSI IM-945GSE-A",
672 .matches = {
673 DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
674 DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
675 },
676 },
677 {
678 .callback = intel_no_lvds_dmi_callback,
679 .ident = "Dell Studio Hybrid",
680 .matches = {
681 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
682 DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
683 },
684 },
Jarod Wilson70aa96c2009-05-27 17:20:39 -0400685 {
686 .callback = intel_no_lvds_dmi_callback,
687 .ident = "AOpen Mini PC",
688 .matches = {
689 DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
690 DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
691 },
692 },
Michael Cousinfa0864b2009-06-05 21:16:22 +0200693 {
694 .callback = intel_no_lvds_dmi_callback,
Tormod Voldened8c7542009-07-13 22:26:48 +0200695 .ident = "AOpen Mini PC MP915",
696 .matches = {
697 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
698 DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
699 },
700 },
701 {
702 .callback = intel_no_lvds_dmi_callback,
Michael Cousinfa0864b2009-06-05 21:16:22 +0200703 .ident = "Aopen i945GTt-VFA",
704 .matches = {
705 DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
706 },
707 },
Stefan Bader9875557ee82010-03-29 17:53:12 +0200708 {
709 .callback = intel_no_lvds_dmi_callback,
710 .ident = "Clientron U800",
711 .matches = {
712 DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
713 DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
714 },
715 },
Jarod Wilson425d2442009-05-05 10:00:25 -0400716
717 { } /* terminating entry */
718};
Jesse Barnes79e53942008-11-07 14:24:08 -0800719
720/**
Zhao Yakui18f9ed12009-11-20 03:24:16 +0000721 * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
722 * @dev: drm device
723 * @connector: LVDS connector
724 *
725 * Find the reduced downclock for LVDS in EDID.
726 */
727static void intel_find_lvds_downclock(struct drm_device *dev,
728 struct drm_connector *connector)
729{
730 struct drm_i915_private *dev_priv = dev->dev_private;
731 struct drm_display_mode *scan, *panel_fixed_mode;
732 int temp_downclock;
733
734 panel_fixed_mode = dev_priv->panel_fixed_mode;
735 temp_downclock = panel_fixed_mode->clock;
736
737 mutex_lock(&dev->mode_config.mutex);
738 list_for_each_entry(scan, &connector->probed_modes, head) {
739 /*
740 * If one mode has the same resolution with the fixed_panel
741 * mode while they have the different refresh rate, it means
742 * that the reduced downclock is found for the LVDS. In such
743 * case we can set the different FPx0/1 to dynamically select
744 * between low and high frequency.
745 */
746 if (scan->hdisplay == panel_fixed_mode->hdisplay &&
747 scan->hsync_start == panel_fixed_mode->hsync_start &&
748 scan->hsync_end == panel_fixed_mode->hsync_end &&
749 scan->htotal == panel_fixed_mode->htotal &&
750 scan->vdisplay == panel_fixed_mode->vdisplay &&
751 scan->vsync_start == panel_fixed_mode->vsync_start &&
752 scan->vsync_end == panel_fixed_mode->vsync_end &&
753 scan->vtotal == panel_fixed_mode->vtotal) {
754 if (scan->clock < temp_downclock) {
755 /*
756 * The downclock is already found. But we
757 * expect to find the lower downclock.
758 */
759 temp_downclock = scan->clock;
760 }
761 }
762 }
763 mutex_unlock(&dev->mode_config.mutex);
Jesse Barnes33814342010-01-14 20:48:02 +0000764 if (temp_downclock < panel_fixed_mode->clock &&
765 i915_lvds_downclock) {
Zhao Yakui18f9ed12009-11-20 03:24:16 +0000766 /* We found the downclock for LVDS. */
767 dev_priv->lvds_downclock_avail = 1;
768 dev_priv->lvds_downclock = temp_downclock;
769 DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
770 "Normal clock %dKhz, downclock %dKhz\n",
771 panel_fixed_mode->clock, temp_downclock);
772 }
773 return;
774}
775
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800776/*
777 * Enumerate the child dev array parsed from VBT to check whether
778 * the LVDS is present.
779 * If it is present, return 1.
780 * If it is not present, return false.
781 * If no child dev is parsed from VBT, it assumes that the LVDS is present.
782 * Note: The addin_offset should also be checked for LVDS panel.
783 * Only when it is non-zero, it is assumed that it is present.
784 */
Zhao Yakui6e365952009-12-02 10:03:34 +0800785static int lvds_is_present_in_vbt(struct drm_device *dev)
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800786{
787 struct drm_i915_private *dev_priv = dev->dev_private;
788 struct child_device_config *p_child;
789 int i, ret;
790
791 if (!dev_priv->child_dev_num)
792 return 1;
793
794 ret = 0;
795 for (i = 0; i < dev_priv->child_dev_num; i++) {
796 p_child = dev_priv->child_dev + i;
797 /*
798 * If the device type is not LFP, continue.
799 * If the device type is 0x22, it is also regarded as LFP.
800 */
801 if (p_child->device_type != DEVICE_TYPE_INT_LFP &&
802 p_child->device_type != DEVICE_TYPE_LFP)
803 continue;
804
805 /* The addin_offset should be checked. Only when it is
806 * non-zero, it is regarded as present.
807 */
808 if (p_child->addin_offset) {
809 ret = 1;
810 break;
811 }
812 }
813 return ret;
814}
815
Zhao Yakui18f9ed12009-11-20 03:24:16 +0000816/**
Jesse Barnes79e53942008-11-07 14:24:08 -0800817 * intel_lvds_init - setup LVDS connectors on this device
818 * @dev: drm device
819 *
820 * Create the connector, register the LVDS DDC bus, and try to figure out what
821 * modes we can display on the LVDS panel (if present).
822 */
823void intel_lvds_init(struct drm_device *dev)
824{
825 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100826 struct intel_lvds *intel_lvds;
Eric Anholt21d40d32010-03-25 11:11:14 -0700827 struct intel_encoder *intel_encoder;
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800828 struct intel_connector *intel_connector;
Jesse Barnes79e53942008-11-07 14:24:08 -0800829 struct drm_connector *connector;
830 struct drm_encoder *encoder;
831 struct drm_display_mode *scan; /* *modes, *bios_mode; */
832 struct drm_crtc *crtc;
833 u32 lvds;
Zhenyu Wang541998a2009-06-05 15:38:44 +0800834 int pipe, gpio = GPIOC;
Jesse Barnes79e53942008-11-07 14:24:08 -0800835
Jarod Wilson425d2442009-05-05 10:00:25 -0400836 /* Skip init on machines we know falsely report LVDS */
837 if (dmi_check_system(intel_no_lvds))
Paul Collins565dcd42009-02-04 23:05:41 +1300838 return;
Paul Collins565dcd42009-02-04 23:05:41 +1300839
Matthew Garrett11ba1592009-12-15 13:55:24 -0500840 if (!lvds_is_present_in_vbt(dev)) {
841 DRM_DEBUG_KMS("LVDS is not present in VBT\n");
Zhao Yakuie99da352009-06-26 09:46:18 +0800842 return;
Zhao Yakui7cf4f692009-11-24 09:48:47 +0800843 }
Zhao Yakuie99da352009-06-26 09:46:18 +0800844
Eric Anholtc619eed2010-01-28 16:45:52 -0800845 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang541998a2009-06-05 15:38:44 +0800846 if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
847 return;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800848 if (dev_priv->edp_support) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800849 DRM_DEBUG_KMS("disable LVDS for eDP support\n");
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800850 return;
851 }
Zhenyu Wang541998a2009-06-05 15:38:44 +0800852 gpio = PCH_GPIOC;
853 }
854
Chris Wilsonea5b2132010-08-04 13:50:23 +0100855 intel_lvds = kzalloc(sizeof(struct intel_lvds), GFP_KERNEL);
856 if (!intel_lvds) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800857 return;
858 }
859
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800860 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
861 if (!intel_connector) {
Chris Wilsonea5b2132010-08-04 13:50:23 +0100862 kfree(intel_lvds);
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800863 return;
864 }
865
Chris Wilsonea5b2132010-08-04 13:50:23 +0100866 intel_encoder = &intel_lvds->base;
Eric Anholt21d40d32010-03-25 11:11:14 -0700867 encoder = &intel_encoder->enc;
Chris Wilsonea5b2132010-08-04 13:50:23 +0100868 connector = &intel_connector->base;
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800869 drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800870 DRM_MODE_CONNECTOR_LVDS);
871
Eric Anholt21d40d32010-03-25 11:11:14 -0700872 drm_encoder_init(dev, &intel_encoder->enc, &intel_lvds_enc_funcs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800873 DRM_MODE_ENCODER_LVDS);
874
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800875 drm_mode_connector_attach_encoder(&intel_connector->base, &intel_encoder->enc);
Eric Anholt21d40d32010-03-25 11:11:14 -0700876 intel_encoder->type = INTEL_OUTPUT_LVDS;
Jesse Barnes79e53942008-11-07 14:24:08 -0800877
Eric Anholt21d40d32010-03-25 11:11:14 -0700878 intel_encoder->clone_mask = (1 << INTEL_LVDS_CLONE_BIT);
879 intel_encoder->crtc_mask = (1 << 1);
Adam Jackson0f3ee802010-03-31 11:41:51 -0400880 if (IS_I965G(dev))
881 intel_encoder->crtc_mask |= (1 << 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800882 drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
883 drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
884 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
885 connector->interlace_allowed = false;
886 connector->doublescan_allowed = false;
887
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800888 /* create the scaling mode property */
889 drm_mode_create_scaling_mode_property(dev);
890 /*
891 * the initial panel fitting mode will be FULL_SCREEN.
892 */
Jesse Barnes79e53942008-11-07 14:24:08 -0800893
Zhenyu Wangbb8a3562010-03-29 16:40:50 +0800894 drm_connector_attach_property(&intel_connector->base,
Zhao Yakui3fbe18d2009-06-22 15:31:25 +0800895 dev->mode_config.scaling_mode_property,
Jesse Barnesdd1ea372010-06-24 11:05:10 -0700896 DRM_MODE_SCALE_ASPECT);
Chris Wilsonea5b2132010-08-04 13:50:23 +0100897 intel_lvds->fitting_mode = DRM_MODE_SCALE_ASPECT;
Jesse Barnes79e53942008-11-07 14:24:08 -0800898 /*
899 * LVDS discovery:
900 * 1) check for EDID on DDC
901 * 2) check for VBT data
902 * 3) check to see if LVDS is already on
903 * if none of the above, no panel
904 * 4) make sure lid is open
905 * if closed, act like it's not there for now
906 */
907
908 /* Set up the DDC bus. */
Eric Anholt21d40d32010-03-25 11:11:14 -0700909 intel_encoder->ddc_bus = intel_i2c_create(dev, gpio, "LVDSDDC_C");
910 if (!intel_encoder->ddc_bus) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800911 dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
912 "failed.\n");
913 goto failed;
914 }
915
916 /*
917 * Attempt to get the fixed panel mode from DDC. Assume that the
918 * preferred mode is the right one.
919 */
Zhao Yakuibfac4d62010-04-07 17:11:22 +0800920 dev_priv->lvds_edid_good = true;
921
Zhenyu Wang335af9a2010-03-30 14:39:31 +0800922 if (!intel_ddc_get_modes(connector, intel_encoder->ddc_bus))
Zhao Yakuibfac4d62010-04-07 17:11:22 +0800923 dev_priv->lvds_edid_good = false;
Jesse Barnes79e53942008-11-07 14:24:08 -0800924
925 list_for_each_entry(scan, &connector->probed_modes, head) {
926 mutex_lock(&dev->mode_config.mutex);
927 if (scan->type & DRM_MODE_TYPE_PREFERRED) {
928 dev_priv->panel_fixed_mode =
929 drm_mode_duplicate(dev, scan);
930 mutex_unlock(&dev->mode_config.mutex);
Zhao Yakui18f9ed12009-11-20 03:24:16 +0000931 intel_find_lvds_downclock(dev, connector);
Paul Collins565dcd42009-02-04 23:05:41 +1300932 goto out;
Jesse Barnes79e53942008-11-07 14:24:08 -0800933 }
934 mutex_unlock(&dev->mode_config.mutex);
935 }
936
937 /* Failed to get EDID, what about VBT? */
Ma Ling88631702009-05-13 11:19:55 +0800938 if (dev_priv->lfp_lvds_vbt_mode) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800939 mutex_lock(&dev->mode_config.mutex);
940 dev_priv->panel_fixed_mode =
Ma Ling88631702009-05-13 11:19:55 +0800941 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
Jesse Barnes79e53942008-11-07 14:24:08 -0800942 mutex_unlock(&dev->mode_config.mutex);
Jesse Barnese285f3cd2009-01-14 10:53:36 -0800943 if (dev_priv->panel_fixed_mode) {
944 dev_priv->panel_fixed_mode->type |=
945 DRM_MODE_TYPE_PREFERRED;
Jesse Barnese285f3cd2009-01-14 10:53:36 -0800946 goto out;
947 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800948 }
949
950 /*
951 * If we didn't get EDID, try checking if the panel is already turned
952 * on. If so, assume that whatever is currently programmed is the
953 * correct mode.
954 */
Zhenyu Wang541998a2009-06-05 15:38:44 +0800955
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500956 /* Ironlake: FIXME if still fail, not try pipe mode now */
Eric Anholtc619eed2010-01-28 16:45:52 -0800957 if (HAS_PCH_SPLIT(dev))
Zhenyu Wang541998a2009-06-05 15:38:44 +0800958 goto failed;
959
Jesse Barnes79e53942008-11-07 14:24:08 -0800960 lvds = I915_READ(LVDS);
961 pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
962 crtc = intel_get_crtc_from_pipe(dev, pipe);
963
964 if (crtc && (lvds & LVDS_PORT_EN)) {
965 dev_priv->panel_fixed_mode = intel_crtc_mode_get(dev, crtc);
966 if (dev_priv->panel_fixed_mode) {
967 dev_priv->panel_fixed_mode->type |=
968 DRM_MODE_TYPE_PREFERRED;
Paul Collins565dcd42009-02-04 23:05:41 +1300969 goto out;
Jesse Barnes79e53942008-11-07 14:24:08 -0800970 }
971 }
972
973 /* If we still don't have a mode after all that, give up. */
974 if (!dev_priv->panel_fixed_mode)
975 goto failed;
976
Jesse Barnes79e53942008-11-07 14:24:08 -0800977out:
Eric Anholtc619eed2010-01-28 16:45:52 -0800978 if (HAS_PCH_SPLIT(dev)) {
Zhenyu Wang541998a2009-06-05 15:38:44 +0800979 u32 pwm;
980 /* make sure PWM is enabled */
981 pwm = I915_READ(BLC_PWM_CPU_CTL2);
982 pwm |= (PWM_ENABLE | PWM_PIPE_B);
983 I915_WRITE(BLC_PWM_CPU_CTL2, pwm);
984
985 pwm = I915_READ(BLC_PWM_PCH_CTL1);
986 pwm |= PWM_PCH_ENABLE;
987 I915_WRITE(BLC_PWM_PCH_CTL1, pwm);
988 }
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700989 dev_priv->lid_notifier.notifier_call = intel_lid_notify;
990 if (acpi_lid_notifier_register(&dev_priv->lid_notifier)) {
Zhao Yakui28c97732009-10-09 11:39:41 +0800991 DRM_DEBUG_KMS("lid notifier registration failed\n");
Jesse Barnesc1c7af62009-09-10 15:28:03 -0700992 dev_priv->lid_notifier.notifier_call = NULL;
993 }
Zhao Yakuia2565372009-12-11 09:26:11 +0800994 /* keep the LVDS connector */
995 dev_priv->int_lvds_connector = connector;
Jesse Barnes79e53942008-11-07 14:24:08 -0800996 drm_sysfs_connector_add(connector);
997 return;
998
999failed:
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001000 DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
Eric Anholt21d40d32010-03-25 11:11:14 -07001001 if (intel_encoder->ddc_bus)
1002 intel_i2c_destroy(intel_encoder->ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -08001003 drm_connector_cleanup(connector);
Shaohua Li1991bdf2009-11-17 17:19:23 +08001004 drm_encoder_cleanup(encoder);
Chris Wilsonea5b2132010-08-04 13:50:23 +01001005 kfree(intel_lvds);
Zhenyu Wangbb8a3562010-03-29 16:40:50 +08001006 kfree(intel_connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001007}