Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 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 Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 30 | #include <acpi/button.h> |
Paul Collins | 565dcd4 | 2009-02-04 23:05:41 +1300 | [diff] [blame] | 31 | #include <linux/dmi.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 32 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 34 | #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 Yakui | e99da35 | 2009-06-26 09:46:18 +0800 | [diff] [blame] | 41 | #include <linux/acpi.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 42 | |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 43 | /* Private structure for the integrated LVDS support */ |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 44 | struct intel_lvds { |
| 45 | struct intel_encoder base; |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 46 | int fitting_mode; |
| 47 | u32 pfit_control; |
| 48 | u32 pfit_pgm_ratios; |
| 49 | }; |
| 50 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 51 | static 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 Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 56 | /** |
| 57 | * Sets the backlight level. |
| 58 | * |
| 59 | * \param level backlight level, from 0 to intel_lvds_get_max_backlight(). |
| 60 | */ |
| 61 | static void intel_lvds_set_backlight(struct drm_device *dev, int level) |
| 62 | { |
| 63 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 64 | u32 blc_pwm_ctl, reg; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 65 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 66 | if (HAS_PCH_SPLIT(dev)) |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 67 | 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 Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 73 | (level << BACKLIGHT_DUTY_CYCLE_SHIFT))); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the maximum level of the backlight duty cycle field. |
| 78 | */ |
| 79 | static u32 intel_lvds_get_max_backlight(struct drm_device *dev) |
| 80 | { |
| 81 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 82 | u32 reg; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 83 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 84 | if (HAS_PCH_SPLIT(dev)) |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 85 | reg = BLC_PWM_PCH_CTL2; |
| 86 | else |
| 87 | reg = BLC_PWM_CTL; |
| 88 | |
| 89 | return ((I915_READ(reg) & BACKLIGHT_MODULATION_FREQ_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 90 | BACKLIGHT_MODULATION_FREQ_SHIFT) * 2; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Sets the power state for the panel. |
| 95 | */ |
| 96 | static void intel_lvds_set_power(struct drm_device *dev, bool on) |
| 97 | { |
| 98 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 469d129 | 2010-02-11 12:41:05 -0800 | [diff] [blame] | 99 | u32 pp_status, ctl_reg, status_reg, lvds_reg; |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 100 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 101 | if (HAS_PCH_SPLIT(dev)) { |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 102 | ctl_reg = PCH_PP_CONTROL; |
| 103 | status_reg = PCH_PP_STATUS; |
Jesse Barnes | 469d129 | 2010-02-11 12:41:05 -0800 | [diff] [blame] | 104 | lvds_reg = PCH_LVDS; |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 105 | } else { |
| 106 | ctl_reg = PP_CONTROL; |
| 107 | status_reg = PP_STATUS; |
Jesse Barnes | 469d129 | 2010-02-11 12:41:05 -0800 | [diff] [blame] | 108 | lvds_reg = LVDS; |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 109 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 110 | |
| 111 | if (on) { |
Jesse Barnes | 469d129 | 2010-02-11 12:41:05 -0800 | [diff] [blame] | 112 | I915_WRITE(lvds_reg, I915_READ(lvds_reg) | LVDS_PORT_EN); |
| 113 | POSTING_READ(lvds_reg); |
| 114 | |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 115 | I915_WRITE(ctl_reg, I915_READ(ctl_reg) | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 116 | POWER_TARGET_ON); |
| 117 | do { |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 118 | pp_status = I915_READ(status_reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 119 | } 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 Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 125 | I915_WRITE(ctl_reg, I915_READ(ctl_reg) & |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 126 | ~POWER_TARGET_ON); |
| 127 | do { |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 128 | pp_status = I915_READ(status_reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 129 | } while (pp_status & PP_ON); |
Jesse Barnes | 469d129 | 2010-02-11 12:41:05 -0800 | [diff] [blame] | 130 | |
| 131 | I915_WRITE(lvds_reg, I915_READ(lvds_reg) & ~LVDS_PORT_EN); |
| 132 | POSTING_READ(lvds_reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
| 136 | static 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 Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 148 | static 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 Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 165 | static void |
| 166 | centre_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 | |
| 187 | static void |
| 188 | centre_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 | |
| 208 | static 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 Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 221 | static 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 Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 228 | struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 229 | struct drm_encoder *tmp_encoder; |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 230 | u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 231 | |
| 232 | /* Should never happen!! */ |
| 233 | if (!IS_I965G(dev) && intel_crtc->pipe == 0) { |
Keith Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 234 | DRM_ERROR("Can't support LVDS on pipe A\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 235 | 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 Packard | 1ae8c0a | 2009-06-28 15:42:17 -0700 | [diff] [blame] | 241 | DRM_ERROR("Can't enable LVDS and another " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 242 | "encoder on the same pipe\n"); |
| 243 | return false; |
| 244 | } |
| 245 | } |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 246 | /* 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; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 249 | /* |
Chris Wilson | 7167704 | 2010-07-17 13:38:43 +0100 | [diff] [blame] | 250 | * We have timings from the BIOS for the panel, put them in |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 251 | * to the adjusted mode. The CRTC will be set up for this mode, |
| 252 | * with the panel scaling set up to source from the H/VDisplay |
| 253 | * of the original mode. |
| 254 | */ |
Chris Wilson | 7167704 | 2010-07-17 13:38:43 +0100 | [diff] [blame] | 255 | adjusted_mode->hdisplay = dev_priv->panel_fixed_mode->hdisplay; |
| 256 | adjusted_mode->hsync_start = |
| 257 | dev_priv->panel_fixed_mode->hsync_start; |
| 258 | adjusted_mode->hsync_end = |
| 259 | dev_priv->panel_fixed_mode->hsync_end; |
| 260 | adjusted_mode->htotal = dev_priv->panel_fixed_mode->htotal; |
| 261 | adjusted_mode->vdisplay = dev_priv->panel_fixed_mode->vdisplay; |
| 262 | adjusted_mode->vsync_start = |
| 263 | dev_priv->panel_fixed_mode->vsync_start; |
| 264 | adjusted_mode->vsync_end = |
| 265 | dev_priv->panel_fixed_mode->vsync_end; |
| 266 | adjusted_mode->vtotal = dev_priv->panel_fixed_mode->vtotal; |
| 267 | adjusted_mode->clock = dev_priv->panel_fixed_mode->clock; |
| 268 | drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 269 | |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 270 | /* Make sure pre-965s set dither correctly */ |
| 271 | if (!IS_I965G(dev)) { |
| 272 | if (dev_priv->panel_wants_dither || dev_priv->lvds_dither) |
| 273 | pfit_control |= PANEL_8TO6_DITHER_ENABLE; |
| 274 | } |
| 275 | |
| 276 | /* Native modes don't need fitting */ |
| 277 | if (adjusted_mode->hdisplay == mode->hdisplay && |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 278 | adjusted_mode->vdisplay == mode->vdisplay) |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 279 | goto out; |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 280 | |
Zhenyu Wang | 8dd81a3 | 2009-09-19 14:54:09 +0800 | [diff] [blame] | 281 | /* full screen scale for now */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 282 | if (HAS_PCH_SPLIT(dev)) |
Zhenyu Wang | 8dd81a3 | 2009-09-19 14:54:09 +0800 | [diff] [blame] | 283 | goto out; |
| 284 | |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 285 | /* 965+ wants fuzzy fitting */ |
| 286 | if (IS_I965G(dev)) |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 287 | pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) | |
| 288 | PFIT_FILTER_FUZZY); |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 289 | |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 290 | /* |
| 291 | * Enable automatic panel scaling for non-native modes so that they fill |
| 292 | * the screen. Should be enabled before the pipe is enabled, according |
| 293 | * to register description and PRM. |
| 294 | * Change the value here to see the borders for debugging |
| 295 | */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 296 | if (!HAS_PCH_SPLIT(dev)) { |
Zhenyu Wang | 8dd81a3 | 2009-09-19 14:54:09 +0800 | [diff] [blame] | 297 | I915_WRITE(BCLRPAT_A, 0); |
| 298 | I915_WRITE(BCLRPAT_B, 0); |
| 299 | } |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 300 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 301 | switch (intel_lvds->fitting_mode) { |
Jesse Barnes | 53bd838 | 2009-07-01 10:04:40 -0700 | [diff] [blame] | 302 | case DRM_MODE_SCALE_CENTER: |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 303 | /* |
| 304 | * For centered modes, we have to calculate border widths & |
| 305 | * heights and modify the values programmed into the CRTC. |
| 306 | */ |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 307 | centre_horizontally(adjusted_mode, mode->hdisplay); |
| 308 | centre_vertically(adjusted_mode, mode->vdisplay); |
| 309 | border = LVDS_BORDER_ENABLE; |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 310 | break; |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 311 | |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 312 | case DRM_MODE_SCALE_ASPECT: |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 313 | /* Scale but preserve the aspect ratio */ |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 314 | if (IS_I965G(dev)) { |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 315 | u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay; |
| 316 | u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay; |
| 317 | |
| 318 | pfit_control |= PFIT_ENABLE; |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 319 | /* 965+ is easy, it does everything in hw */ |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 320 | if (scaled_width > scaled_height) |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 321 | pfit_control |= PFIT_SCALING_PILLAR; |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 322 | else if (scaled_width < scaled_height) |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 323 | pfit_control |= PFIT_SCALING_LETTER; |
| 324 | else |
| 325 | pfit_control |= PFIT_SCALING_AUTO; |
| 326 | } else { |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 327 | u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay; |
| 328 | u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay; |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 329 | /* |
| 330 | * For earlier chips we have to calculate the scaling |
| 331 | * ratio by hand and program it into the |
| 332 | * PFIT_PGM_RATIO register |
| 333 | */ |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 334 | if (scaled_width > scaled_height) { /* pillar */ |
| 335 | centre_horizontally(adjusted_mode, scaled_height / mode->vdisplay); |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 336 | |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 337 | border = LVDS_BORDER_ENABLE; |
| 338 | if (mode->vdisplay != adjusted_mode->vdisplay) { |
| 339 | u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay); |
| 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 if (scaled_width < scaled_height) { /* letter */ |
| 347 | centre_vertically(adjusted_mode, scaled_width / mode->hdisplay); |
| 348 | |
| 349 | border = LVDS_BORDER_ENABLE; |
| 350 | if (mode->hdisplay != adjusted_mode->hdisplay) { |
| 351 | u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay); |
| 352 | pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT | |
| 353 | bits << PFIT_VERT_SCALE_SHIFT); |
| 354 | pfit_control |= (PFIT_ENABLE | |
| 355 | VERT_INTERP_BILINEAR | |
| 356 | HORIZ_INTERP_BILINEAR); |
| 357 | } |
| 358 | } else |
| 359 | /* Aspects match, Let hw scale both directions */ |
| 360 | pfit_control |= (PFIT_ENABLE | |
| 361 | VERT_AUTO_SCALE | HORIZ_AUTO_SCALE | |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 362 | VERT_INTERP_BILINEAR | |
| 363 | HORIZ_INTERP_BILINEAR); |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 364 | } |
| 365 | break; |
| 366 | |
| 367 | case DRM_MODE_SCALE_FULLSCREEN: |
| 368 | /* |
| 369 | * Full scaling, even if it changes the aspect ratio. |
| 370 | * Fortunately this is all done for us in hw. |
| 371 | */ |
| 372 | pfit_control |= PFIT_ENABLE; |
| 373 | if (IS_I965G(dev)) |
| 374 | pfit_control |= PFIT_SCALING_AUTO; |
| 375 | else |
| 376 | pfit_control |= (VERT_AUTO_SCALE | HORIZ_AUTO_SCALE | |
| 377 | VERT_INTERP_BILINEAR | |
| 378 | HORIZ_INTERP_BILINEAR); |
| 379 | break; |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 380 | |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 381 | default: |
| 382 | break; |
| 383 | } |
| 384 | |
| 385 | out: |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 386 | intel_lvds->pfit_control = pfit_control; |
| 387 | intel_lvds->pfit_pgm_ratios = pfit_pgm_ratios; |
Chris Wilson | 49be663 | 2010-07-18 12:05:54 +0100 | [diff] [blame] | 388 | dev_priv->lvds_border_bits = border; |
| 389 | |
Zhao Yakui | a3e17eb | 2009-10-10 10:42:37 +0800 | [diff] [blame] | 390 | /* |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 391 | * XXX: It would be nice to support lower refresh rates on the |
| 392 | * panels to reduce power consumption, and perhaps match the |
| 393 | * user's requested refresh rate. |
| 394 | */ |
| 395 | |
| 396 | return true; |
| 397 | } |
| 398 | |
| 399 | static void intel_lvds_prepare(struct drm_encoder *encoder) |
| 400 | { |
| 401 | struct drm_device *dev = encoder->dev; |
| 402 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 403 | u32 reg; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 404 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 405 | if (HAS_PCH_SPLIT(dev)) |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 406 | reg = BLC_PWM_CPU_CTL; |
| 407 | else |
| 408 | reg = BLC_PWM_CTL; |
| 409 | |
| 410 | dev_priv->saveBLC_PWM_CTL = I915_READ(reg); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 411 | dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL & |
| 412 | BACKLIGHT_DUTY_CYCLE_MASK); |
| 413 | |
| 414 | intel_lvds_set_power(dev, false); |
| 415 | } |
| 416 | |
| 417 | static void intel_lvds_commit( struct drm_encoder *encoder) |
| 418 | { |
| 419 | struct drm_device *dev = encoder->dev; |
| 420 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 421 | |
| 422 | if (dev_priv->backlight_duty_cycle == 0) |
| 423 | dev_priv->backlight_duty_cycle = |
| 424 | intel_lvds_get_max_backlight(dev); |
| 425 | |
| 426 | intel_lvds_set_power(dev, true); |
| 427 | } |
| 428 | |
| 429 | static void intel_lvds_mode_set(struct drm_encoder *encoder, |
| 430 | struct drm_display_mode *mode, |
| 431 | struct drm_display_mode *adjusted_mode) |
| 432 | { |
| 433 | struct drm_device *dev = encoder->dev; |
| 434 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 435 | struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 436 | |
| 437 | /* |
| 438 | * The LVDS pin pair will already have been turned on in the |
| 439 | * intel_crtc_mode_set since it has a large impact on the DPLL |
| 440 | * settings. |
| 441 | */ |
| 442 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 443 | if (HAS_PCH_SPLIT(dev)) |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 444 | return; |
| 445 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 446 | /* |
| 447 | * Enable automatic panel scaling so that non-native modes fill the |
| 448 | * screen. Should be enabled before the pipe is enabled, according to |
| 449 | * register description and PRM. |
| 450 | */ |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 451 | I915_WRITE(PFIT_PGM_RATIOS, intel_lvds->pfit_pgm_ratios); |
| 452 | I915_WRITE(PFIT_CONTROL, intel_lvds->pfit_control); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Detect the LVDS connection. |
| 457 | * |
Jesse Barnes | b42d4c5 | 2009-09-10 15:28:04 -0700 | [diff] [blame] | 458 | * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means |
| 459 | * connected and closed means disconnected. We also send hotplug events as |
| 460 | * needed, using lid status notification from the input layer. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 461 | */ |
| 462 | static enum drm_connector_status intel_lvds_detect(struct drm_connector *connector) |
| 463 | { |
Jesse Barnes | 7b9c5ab | 2010-02-12 09:30:00 -0800 | [diff] [blame] | 464 | struct drm_device *dev = connector->dev; |
Jesse Barnes | b42d4c5 | 2009-09-10 15:28:04 -0700 | [diff] [blame] | 465 | enum drm_connector_status status = connector_status_connected; |
| 466 | |
Jesse Barnes | 7b9c5ab | 2010-02-12 09:30:00 -0800 | [diff] [blame] | 467 | /* ACPI lid methods were generally unreliable in this generation, so |
| 468 | * don't even bother. |
| 469 | */ |
Eric Anholt | 6e6c822 | 2010-03-17 13:48:06 -0700 | [diff] [blame] | 470 | if (IS_GEN2(dev) || IS_GEN3(dev)) |
Jesse Barnes | 7b9c5ab | 2010-02-12 09:30:00 -0800 | [diff] [blame] | 471 | return connector_status_connected; |
| 472 | |
Jesse Barnes | b42d4c5 | 2009-09-10 15:28:04 -0700 | [diff] [blame] | 473 | return status; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Return the list of DDC modes if available, or the BIOS fixed mode otherwise. |
| 478 | */ |
| 479 | static int intel_lvds_get_modes(struct drm_connector *connector) |
| 480 | { |
| 481 | struct drm_device *dev = connector->dev; |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 482 | struct drm_encoder *encoder = intel_attached_encoder(connector); |
| 483 | struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 484 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 485 | int ret = 0; |
| 486 | |
Zhao Yakui | bfac4d6 | 2010-04-07 17:11:22 +0800 | [diff] [blame] | 487 | if (dev_priv->lvds_edid_good) { |
Zhenyu Wang | 335af9a | 2010-03-30 14:39:31 +0800 | [diff] [blame] | 488 | ret = intel_ddc_get_modes(connector, intel_encoder->ddc_bus); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 489 | |
Zhao Yakui | bfac4d6 | 2010-04-07 17:11:22 +0800 | [diff] [blame] | 490 | if (ret) |
| 491 | return ret; |
| 492 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 493 | |
| 494 | /* Didn't get an EDID, so |
| 495 | * Set wide sync ranges so we get all modes |
| 496 | * handed to valid_mode for checking |
| 497 | */ |
| 498 | connector->display_info.min_vfreq = 0; |
| 499 | connector->display_info.max_vfreq = 200; |
| 500 | connector->display_info.min_hfreq = 0; |
| 501 | connector->display_info.max_hfreq = 200; |
| 502 | |
| 503 | if (dev_priv->panel_fixed_mode != NULL) { |
| 504 | struct drm_display_mode *mode; |
| 505 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 506 | mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode); |
| 507 | drm_mode_probed_add(connector, mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 508 | |
| 509 | return 1; |
| 510 | } |
| 511 | |
| 512 | return 0; |
| 513 | } |
| 514 | |
Thomas Bächler | 0544edf | 2010-07-02 10:44:23 +0200 | [diff] [blame] | 515 | static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id) |
| 516 | { |
| 517 | DRM_DEBUG_KMS("Skipping forced modeset for %s\n", id->ident); |
| 518 | return 1; |
| 519 | } |
| 520 | |
| 521 | /* The GPU hangs up on these systems if modeset is performed on LID open */ |
| 522 | static const struct dmi_system_id intel_no_modeset_on_lid[] = { |
| 523 | { |
| 524 | .callback = intel_no_modeset_on_lid_dmi_callback, |
| 525 | .ident = "Toshiba Tecra A11", |
| 526 | .matches = { |
| 527 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 528 | DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"), |
| 529 | }, |
| 530 | }, |
| 531 | |
| 532 | { } /* terminating entry */ |
| 533 | }; |
| 534 | |
Linus Torvalds | c9354c8 | 2009-11-02 09:29:55 -0800 | [diff] [blame] | 535 | /* |
| 536 | * Lid events. Note the use of 'modeset_on_lid': |
| 537 | * - we set it on lid close, and reset it on open |
| 538 | * - we use it as a "only once" bit (ie we ignore |
| 539 | * duplicate events where it was already properly |
| 540 | * set/reset) |
| 541 | * - the suspend/resume paths will also set it to |
| 542 | * zero, since they restore the mode ("lid open"). |
| 543 | */ |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 544 | static int intel_lid_notify(struct notifier_block *nb, unsigned long val, |
| 545 | void *unused) |
| 546 | { |
| 547 | struct drm_i915_private *dev_priv = |
| 548 | container_of(nb, struct drm_i915_private, lid_notifier); |
| 549 | struct drm_device *dev = dev_priv->dev; |
Zhao Yakui | a256537 | 2009-12-11 09:26:11 +0800 | [diff] [blame] | 550 | struct drm_connector *connector = dev_priv->int_lvds_connector; |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 551 | |
Zhao Yakui | a256537 | 2009-12-11 09:26:11 +0800 | [diff] [blame] | 552 | /* |
| 553 | * check and update the status of LVDS connector after receiving |
| 554 | * the LID nofication event. |
| 555 | */ |
| 556 | if (connector) |
| 557 | connector->status = connector->funcs->detect(connector); |
Thomas Bächler | 0544edf | 2010-07-02 10:44:23 +0200 | [diff] [blame] | 558 | /* Don't force modeset on machines where it causes a GPU lockup */ |
| 559 | if (dmi_check_system(intel_no_modeset_on_lid)) |
| 560 | return NOTIFY_OK; |
Linus Torvalds | c9354c8 | 2009-11-02 09:29:55 -0800 | [diff] [blame] | 561 | if (!acpi_lid_open()) { |
| 562 | dev_priv->modeset_on_lid = 1; |
| 563 | return NOTIFY_OK; |
Jesse Barnes | 06891e2 | 2009-09-14 10:58:48 -0700 | [diff] [blame] | 564 | } |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 565 | |
Linus Torvalds | c9354c8 | 2009-11-02 09:29:55 -0800 | [diff] [blame] | 566 | if (!dev_priv->modeset_on_lid) |
| 567 | return NOTIFY_OK; |
| 568 | |
| 569 | dev_priv->modeset_on_lid = 0; |
| 570 | |
| 571 | mutex_lock(&dev->mode_config.mutex); |
| 572 | drm_helper_resume_force_mode(dev); |
| 573 | mutex_unlock(&dev->mode_config.mutex); |
Jesse Barnes | 0632419 | 2009-09-10 15:28:05 -0700 | [diff] [blame] | 574 | |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 575 | return NOTIFY_OK; |
| 576 | } |
| 577 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 578 | /** |
| 579 | * intel_lvds_destroy - unregister and free LVDS structures |
| 580 | * @connector: connector to free |
| 581 | * |
| 582 | * Unregister the DDC bus for this connector then free the driver private |
| 583 | * structure. |
| 584 | */ |
| 585 | static void intel_lvds_destroy(struct drm_connector *connector) |
| 586 | { |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 587 | struct drm_device *dev = connector->dev; |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 588 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 589 | |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 590 | if (dev_priv->lid_notifier.notifier_call) |
| 591 | acpi_lid_notifier_unregister(&dev_priv->lid_notifier); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 592 | drm_sysfs_connector_remove(connector); |
| 593 | drm_connector_cleanup(connector); |
| 594 | kfree(connector); |
| 595 | } |
| 596 | |
Jesse Barnes | 335041e | 2009-01-22 22:22:06 +1000 | [diff] [blame] | 597 | static int intel_lvds_set_property(struct drm_connector *connector, |
| 598 | struct drm_property *property, |
| 599 | uint64_t value) |
| 600 | { |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 601 | struct drm_device *dev = connector->dev; |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 602 | |
| 603 | if (property == dev->mode_config.scaling_mode_property && |
| 604 | connector->encoder) { |
| 605 | struct drm_crtc *crtc = connector->encoder->crtc; |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 606 | struct drm_encoder *encoder = connector->encoder; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 607 | struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder); |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 608 | |
Jesse Barnes | 53bd838 | 2009-07-01 10:04:40 -0700 | [diff] [blame] | 609 | if (value == DRM_MODE_SCALE_NONE) { |
| 610 | DRM_DEBUG_KMS("no scaling not supported\n"); |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 611 | return 0; |
| 612 | } |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 613 | if (intel_lvds->fitting_mode == value) { |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 614 | /* the LVDS scaling property is not changed */ |
| 615 | return 0; |
| 616 | } |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 617 | intel_lvds->fitting_mode = value; |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 618 | if (crtc && crtc->enabled) { |
| 619 | /* |
| 620 | * If the CRTC is enabled, the display will be changed |
| 621 | * according to the new panel fitting mode. |
| 622 | */ |
| 623 | drm_crtc_helper_set_mode(crtc, &crtc->mode, |
| 624 | crtc->x, crtc->y, crtc->fb); |
| 625 | } |
| 626 | } |
| 627 | |
Jesse Barnes | 335041e | 2009-01-22 22:22:06 +1000 | [diff] [blame] | 628 | return 0; |
| 629 | } |
| 630 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 631 | static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = { |
| 632 | .dpms = intel_lvds_dpms, |
| 633 | .mode_fixup = intel_lvds_mode_fixup, |
| 634 | .prepare = intel_lvds_prepare, |
| 635 | .mode_set = intel_lvds_mode_set, |
| 636 | .commit = intel_lvds_commit, |
| 637 | }; |
| 638 | |
| 639 | static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = { |
| 640 | .get_modes = intel_lvds_get_modes, |
| 641 | .mode_valid = intel_lvds_mode_valid, |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 642 | .best_encoder = intel_attached_encoder, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 643 | }; |
| 644 | |
| 645 | static const struct drm_connector_funcs intel_lvds_connector_funcs = { |
Keith Packard | c9fb15f | 2009-05-30 20:42:28 -0700 | [diff] [blame] | 646 | .dpms = drm_helper_connector_dpms, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 647 | .detect = intel_lvds_detect, |
| 648 | .fill_modes = drm_helper_probe_single_connector_modes, |
Jesse Barnes | 335041e | 2009-01-22 22:22:06 +1000 | [diff] [blame] | 649 | .set_property = intel_lvds_set_property, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 650 | .destroy = intel_lvds_destroy, |
| 651 | }; |
| 652 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 653 | static const struct drm_encoder_funcs intel_lvds_enc_funcs = { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 654 | .destroy = intel_encoder_destroy, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 655 | }; |
| 656 | |
Jarod Wilson | 425d244 | 2009-05-05 10:00:25 -0400 | [diff] [blame] | 657 | static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id) |
| 658 | { |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 659 | DRM_DEBUG_KMS("Skipping LVDS initialization for %s\n", id->ident); |
Jarod Wilson | 425d244 | 2009-05-05 10:00:25 -0400 | [diff] [blame] | 660 | return 1; |
| 661 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 662 | |
Jarod Wilson | 425d244 | 2009-05-05 10:00:25 -0400 | [diff] [blame] | 663 | /* These systems claim to have LVDS, but really don't */ |
Jaswinder Singh Rajput | 93c05f2 | 2009-06-04 09:41:19 +1000 | [diff] [blame] | 664 | static const struct dmi_system_id intel_no_lvds[] = { |
Jarod Wilson | 425d244 | 2009-05-05 10:00:25 -0400 | [diff] [blame] | 665 | { |
| 666 | .callback = intel_no_lvds_dmi_callback, |
| 667 | .ident = "Apple Mac Mini (Core series)", |
| 668 | .matches = { |
Keith Packard | 98acd46 | 2009-06-14 12:31:58 -0700 | [diff] [blame] | 669 | DMI_MATCH(DMI_SYS_VENDOR, "Apple"), |
Jarod Wilson | 425d244 | 2009-05-05 10:00:25 -0400 | [diff] [blame] | 670 | DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"), |
| 671 | }, |
| 672 | }, |
| 673 | { |
| 674 | .callback = intel_no_lvds_dmi_callback, |
| 675 | .ident = "Apple Mac Mini (Core 2 series)", |
| 676 | .matches = { |
Keith Packard | 98acd46 | 2009-06-14 12:31:58 -0700 | [diff] [blame] | 677 | DMI_MATCH(DMI_SYS_VENDOR, "Apple"), |
Jarod Wilson | 425d244 | 2009-05-05 10:00:25 -0400 | [diff] [blame] | 678 | DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"), |
| 679 | }, |
| 680 | }, |
| 681 | { |
| 682 | .callback = intel_no_lvds_dmi_callback, |
| 683 | .ident = "MSI IM-945GSE-A", |
| 684 | .matches = { |
| 685 | DMI_MATCH(DMI_SYS_VENDOR, "MSI"), |
| 686 | DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"), |
| 687 | }, |
| 688 | }, |
| 689 | { |
| 690 | .callback = intel_no_lvds_dmi_callback, |
| 691 | .ident = "Dell Studio Hybrid", |
| 692 | .matches = { |
| 693 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 694 | DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"), |
| 695 | }, |
| 696 | }, |
Jarod Wilson | 70aa96c | 2009-05-27 17:20:39 -0400 | [diff] [blame] | 697 | { |
| 698 | .callback = intel_no_lvds_dmi_callback, |
| 699 | .ident = "AOpen Mini PC", |
| 700 | .matches = { |
| 701 | DMI_MATCH(DMI_SYS_VENDOR, "AOpen"), |
| 702 | DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"), |
| 703 | }, |
| 704 | }, |
Michael Cousin | fa0864b | 2009-06-05 21:16:22 +0200 | [diff] [blame] | 705 | { |
| 706 | .callback = intel_no_lvds_dmi_callback, |
Tormod Volden | ed8c754 | 2009-07-13 22:26:48 +0200 | [diff] [blame] | 707 | .ident = "AOpen Mini PC MP915", |
| 708 | .matches = { |
| 709 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), |
| 710 | DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"), |
| 711 | }, |
| 712 | }, |
| 713 | { |
| 714 | .callback = intel_no_lvds_dmi_callback, |
Michael Cousin | fa0864b | 2009-06-05 21:16:22 +0200 | [diff] [blame] | 715 | .ident = "Aopen i945GTt-VFA", |
| 716 | .matches = { |
| 717 | DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"), |
| 718 | }, |
| 719 | }, |
Stefan Bader | 9875557 | 2010-03-29 17:53:12 +0200 | [diff] [blame] | 720 | { |
| 721 | .callback = intel_no_lvds_dmi_callback, |
| 722 | .ident = "Clientron U800", |
| 723 | .matches = { |
| 724 | DMI_MATCH(DMI_SYS_VENDOR, "Clientron"), |
| 725 | DMI_MATCH(DMI_PRODUCT_NAME, "U800"), |
| 726 | }, |
| 727 | }, |
Jarod Wilson | 425d244 | 2009-05-05 10:00:25 -0400 | [diff] [blame] | 728 | |
| 729 | { } /* terminating entry */ |
| 730 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 731 | |
| 732 | /** |
Zhao Yakui | 18f9ed1 | 2009-11-20 03:24:16 +0000 | [diff] [blame] | 733 | * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID |
| 734 | * @dev: drm device |
| 735 | * @connector: LVDS connector |
| 736 | * |
| 737 | * Find the reduced downclock for LVDS in EDID. |
| 738 | */ |
| 739 | static void intel_find_lvds_downclock(struct drm_device *dev, |
| 740 | struct drm_connector *connector) |
| 741 | { |
| 742 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 743 | struct drm_display_mode *scan, *panel_fixed_mode; |
| 744 | int temp_downclock; |
| 745 | |
| 746 | panel_fixed_mode = dev_priv->panel_fixed_mode; |
| 747 | temp_downclock = panel_fixed_mode->clock; |
| 748 | |
| 749 | mutex_lock(&dev->mode_config.mutex); |
| 750 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 751 | /* |
| 752 | * If one mode has the same resolution with the fixed_panel |
| 753 | * mode while they have the different refresh rate, it means |
| 754 | * that the reduced downclock is found for the LVDS. In such |
| 755 | * case we can set the different FPx0/1 to dynamically select |
| 756 | * between low and high frequency. |
| 757 | */ |
| 758 | if (scan->hdisplay == panel_fixed_mode->hdisplay && |
| 759 | scan->hsync_start == panel_fixed_mode->hsync_start && |
| 760 | scan->hsync_end == panel_fixed_mode->hsync_end && |
| 761 | scan->htotal == panel_fixed_mode->htotal && |
| 762 | scan->vdisplay == panel_fixed_mode->vdisplay && |
| 763 | scan->vsync_start == panel_fixed_mode->vsync_start && |
| 764 | scan->vsync_end == panel_fixed_mode->vsync_end && |
| 765 | scan->vtotal == panel_fixed_mode->vtotal) { |
| 766 | if (scan->clock < temp_downclock) { |
| 767 | /* |
| 768 | * The downclock is already found. But we |
| 769 | * expect to find the lower downclock. |
| 770 | */ |
| 771 | temp_downclock = scan->clock; |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | mutex_unlock(&dev->mode_config.mutex); |
Jesse Barnes | 3381434 | 2010-01-14 20:48:02 +0000 | [diff] [blame] | 776 | if (temp_downclock < panel_fixed_mode->clock && |
| 777 | i915_lvds_downclock) { |
Zhao Yakui | 18f9ed1 | 2009-11-20 03:24:16 +0000 | [diff] [blame] | 778 | /* We found the downclock for LVDS. */ |
| 779 | dev_priv->lvds_downclock_avail = 1; |
| 780 | dev_priv->lvds_downclock = temp_downclock; |
| 781 | DRM_DEBUG_KMS("LVDS downclock is found in EDID. " |
| 782 | "Normal clock %dKhz, downclock %dKhz\n", |
| 783 | panel_fixed_mode->clock, temp_downclock); |
| 784 | } |
| 785 | return; |
| 786 | } |
| 787 | |
Zhao Yakui | 7cf4f69 | 2009-11-24 09:48:47 +0800 | [diff] [blame] | 788 | /* |
| 789 | * Enumerate the child dev array parsed from VBT to check whether |
| 790 | * the LVDS is present. |
| 791 | * If it is present, return 1. |
| 792 | * If it is not present, return false. |
| 793 | * If no child dev is parsed from VBT, it assumes that the LVDS is present. |
| 794 | * Note: The addin_offset should also be checked for LVDS panel. |
| 795 | * Only when it is non-zero, it is assumed that it is present. |
| 796 | */ |
Zhao Yakui | 6e36595 | 2009-12-02 10:03:34 +0800 | [diff] [blame] | 797 | static int lvds_is_present_in_vbt(struct drm_device *dev) |
Zhao Yakui | 7cf4f69 | 2009-11-24 09:48:47 +0800 | [diff] [blame] | 798 | { |
| 799 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 800 | struct child_device_config *p_child; |
| 801 | int i, ret; |
| 802 | |
| 803 | if (!dev_priv->child_dev_num) |
| 804 | return 1; |
| 805 | |
| 806 | ret = 0; |
| 807 | for (i = 0; i < dev_priv->child_dev_num; i++) { |
| 808 | p_child = dev_priv->child_dev + i; |
| 809 | /* |
| 810 | * If the device type is not LFP, continue. |
| 811 | * If the device type is 0x22, it is also regarded as LFP. |
| 812 | */ |
| 813 | if (p_child->device_type != DEVICE_TYPE_INT_LFP && |
| 814 | p_child->device_type != DEVICE_TYPE_LFP) |
| 815 | continue; |
| 816 | |
| 817 | /* The addin_offset should be checked. Only when it is |
| 818 | * non-zero, it is regarded as present. |
| 819 | */ |
| 820 | if (p_child->addin_offset) { |
| 821 | ret = 1; |
| 822 | break; |
| 823 | } |
| 824 | } |
| 825 | return ret; |
| 826 | } |
| 827 | |
Zhao Yakui | 18f9ed1 | 2009-11-20 03:24:16 +0000 | [diff] [blame] | 828 | /** |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 829 | * intel_lvds_init - setup LVDS connectors on this device |
| 830 | * @dev: drm device |
| 831 | * |
| 832 | * Create the connector, register the LVDS DDC bus, and try to figure out what |
| 833 | * modes we can display on the LVDS panel (if present). |
| 834 | */ |
| 835 | void intel_lvds_init(struct drm_device *dev) |
| 836 | { |
| 837 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 838 | struct intel_lvds *intel_lvds; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 839 | struct intel_encoder *intel_encoder; |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 840 | struct intel_connector *intel_connector; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 841 | struct drm_connector *connector; |
| 842 | struct drm_encoder *encoder; |
| 843 | struct drm_display_mode *scan; /* *modes, *bios_mode; */ |
| 844 | struct drm_crtc *crtc; |
| 845 | u32 lvds; |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 846 | int pipe, gpio = GPIOC; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 847 | |
Jarod Wilson | 425d244 | 2009-05-05 10:00:25 -0400 | [diff] [blame] | 848 | /* Skip init on machines we know falsely report LVDS */ |
| 849 | if (dmi_check_system(intel_no_lvds)) |
Paul Collins | 565dcd4 | 2009-02-04 23:05:41 +1300 | [diff] [blame] | 850 | return; |
Paul Collins | 565dcd4 | 2009-02-04 23:05:41 +1300 | [diff] [blame] | 851 | |
Matthew Garrett | 11ba159 | 2009-12-15 13:55:24 -0500 | [diff] [blame] | 852 | if (!lvds_is_present_in_vbt(dev)) { |
| 853 | DRM_DEBUG_KMS("LVDS is not present in VBT\n"); |
Zhao Yakui | e99da35 | 2009-06-26 09:46:18 +0800 | [diff] [blame] | 854 | return; |
Zhao Yakui | 7cf4f69 | 2009-11-24 09:48:47 +0800 | [diff] [blame] | 855 | } |
Zhao Yakui | e99da35 | 2009-06-26 09:46:18 +0800 | [diff] [blame] | 856 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 857 | if (HAS_PCH_SPLIT(dev)) { |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 858 | if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0) |
| 859 | return; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 860 | if (dev_priv->edp_support) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 861 | DRM_DEBUG_KMS("disable LVDS for eDP support\n"); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 862 | return; |
| 863 | } |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 864 | gpio = PCH_GPIOC; |
| 865 | } |
| 866 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 867 | intel_lvds = kzalloc(sizeof(struct intel_lvds), GFP_KERNEL); |
| 868 | if (!intel_lvds) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 869 | return; |
| 870 | } |
| 871 | |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 872 | intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); |
| 873 | if (!intel_connector) { |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 874 | kfree(intel_lvds); |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 875 | return; |
| 876 | } |
| 877 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 878 | intel_encoder = &intel_lvds->base; |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 879 | encoder = &intel_encoder->enc; |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 880 | connector = &intel_connector->base; |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 881 | drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 882 | DRM_MODE_CONNECTOR_LVDS); |
| 883 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 884 | drm_encoder_init(dev, &intel_encoder->enc, &intel_lvds_enc_funcs, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 885 | DRM_MODE_ENCODER_LVDS); |
| 886 | |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 887 | drm_mode_connector_attach_encoder(&intel_connector->base, &intel_encoder->enc); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 888 | intel_encoder->type = INTEL_OUTPUT_LVDS; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 889 | |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 890 | intel_encoder->clone_mask = (1 << INTEL_LVDS_CLONE_BIT); |
| 891 | intel_encoder->crtc_mask = (1 << 1); |
Adam Jackson | 0f3ee80 | 2010-03-31 11:41:51 -0400 | [diff] [blame] | 892 | if (IS_I965G(dev)) |
| 893 | intel_encoder->crtc_mask |= (1 << 0); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 894 | drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs); |
| 895 | drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs); |
| 896 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; |
| 897 | connector->interlace_allowed = false; |
| 898 | connector->doublescan_allowed = false; |
| 899 | |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 900 | /* create the scaling mode property */ |
| 901 | drm_mode_create_scaling_mode_property(dev); |
| 902 | /* |
| 903 | * the initial panel fitting mode will be FULL_SCREEN. |
| 904 | */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 905 | |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 906 | drm_connector_attach_property(&intel_connector->base, |
Zhao Yakui | 3fbe18d | 2009-06-22 15:31:25 +0800 | [diff] [blame] | 907 | dev->mode_config.scaling_mode_property, |
Jesse Barnes | dd1ea37 | 2010-06-24 11:05:10 -0700 | [diff] [blame] | 908 | DRM_MODE_SCALE_ASPECT); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 909 | intel_lvds->fitting_mode = DRM_MODE_SCALE_ASPECT; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 910 | /* |
| 911 | * LVDS discovery: |
| 912 | * 1) check for EDID on DDC |
| 913 | * 2) check for VBT data |
| 914 | * 3) check to see if LVDS is already on |
| 915 | * if none of the above, no panel |
| 916 | * 4) make sure lid is open |
| 917 | * if closed, act like it's not there for now |
| 918 | */ |
| 919 | |
| 920 | /* Set up the DDC bus. */ |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 921 | intel_encoder->ddc_bus = intel_i2c_create(dev, gpio, "LVDSDDC_C"); |
| 922 | if (!intel_encoder->ddc_bus) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 923 | dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration " |
| 924 | "failed.\n"); |
| 925 | goto failed; |
| 926 | } |
| 927 | |
| 928 | /* |
| 929 | * Attempt to get the fixed panel mode from DDC. Assume that the |
| 930 | * preferred mode is the right one. |
| 931 | */ |
Zhao Yakui | bfac4d6 | 2010-04-07 17:11:22 +0800 | [diff] [blame] | 932 | dev_priv->lvds_edid_good = true; |
| 933 | |
Zhenyu Wang | 335af9a | 2010-03-30 14:39:31 +0800 | [diff] [blame] | 934 | if (!intel_ddc_get_modes(connector, intel_encoder->ddc_bus)) |
Zhao Yakui | bfac4d6 | 2010-04-07 17:11:22 +0800 | [diff] [blame] | 935 | dev_priv->lvds_edid_good = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 936 | |
| 937 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 938 | mutex_lock(&dev->mode_config.mutex); |
| 939 | if (scan->type & DRM_MODE_TYPE_PREFERRED) { |
| 940 | dev_priv->panel_fixed_mode = |
| 941 | drm_mode_duplicate(dev, scan); |
| 942 | mutex_unlock(&dev->mode_config.mutex); |
Zhao Yakui | 18f9ed1 | 2009-11-20 03:24:16 +0000 | [diff] [blame] | 943 | intel_find_lvds_downclock(dev, connector); |
Paul Collins | 565dcd4 | 2009-02-04 23:05:41 +1300 | [diff] [blame] | 944 | goto out; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 945 | } |
| 946 | mutex_unlock(&dev->mode_config.mutex); |
| 947 | } |
| 948 | |
| 949 | /* Failed to get EDID, what about VBT? */ |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 950 | if (dev_priv->lfp_lvds_vbt_mode) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 951 | mutex_lock(&dev->mode_config.mutex); |
| 952 | dev_priv->panel_fixed_mode = |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 953 | drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 954 | mutex_unlock(&dev->mode_config.mutex); |
Jesse Barnes | e285f3c | 2009-01-14 10:53:36 -0800 | [diff] [blame] | 955 | if (dev_priv->panel_fixed_mode) { |
| 956 | dev_priv->panel_fixed_mode->type |= |
| 957 | DRM_MODE_TYPE_PREFERRED; |
Jesse Barnes | e285f3c | 2009-01-14 10:53:36 -0800 | [diff] [blame] | 958 | goto out; |
| 959 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /* |
| 963 | * If we didn't get EDID, try checking if the panel is already turned |
| 964 | * on. If so, assume that whatever is currently programmed is the |
| 965 | * correct mode. |
| 966 | */ |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 967 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 968 | /* Ironlake: FIXME if still fail, not try pipe mode now */ |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 969 | if (HAS_PCH_SPLIT(dev)) |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 970 | goto failed; |
| 971 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 972 | lvds = I915_READ(LVDS); |
| 973 | pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0; |
| 974 | crtc = intel_get_crtc_from_pipe(dev, pipe); |
| 975 | |
| 976 | if (crtc && (lvds & LVDS_PORT_EN)) { |
| 977 | dev_priv->panel_fixed_mode = intel_crtc_mode_get(dev, crtc); |
| 978 | if (dev_priv->panel_fixed_mode) { |
| 979 | dev_priv->panel_fixed_mode->type |= |
| 980 | DRM_MODE_TYPE_PREFERRED; |
Paul Collins | 565dcd4 | 2009-02-04 23:05:41 +1300 | [diff] [blame] | 981 | goto out; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | |
| 985 | /* If we still don't have a mode after all that, give up. */ |
| 986 | if (!dev_priv->panel_fixed_mode) |
| 987 | goto failed; |
| 988 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 989 | out: |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 990 | if (HAS_PCH_SPLIT(dev)) { |
Zhenyu Wang | 541998a | 2009-06-05 15:38:44 +0800 | [diff] [blame] | 991 | u32 pwm; |
| 992 | /* make sure PWM is enabled */ |
| 993 | pwm = I915_READ(BLC_PWM_CPU_CTL2); |
| 994 | pwm |= (PWM_ENABLE | PWM_PIPE_B); |
| 995 | I915_WRITE(BLC_PWM_CPU_CTL2, pwm); |
| 996 | |
| 997 | pwm = I915_READ(BLC_PWM_PCH_CTL1); |
| 998 | pwm |= PWM_PCH_ENABLE; |
| 999 | I915_WRITE(BLC_PWM_PCH_CTL1, pwm); |
| 1000 | } |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 1001 | dev_priv->lid_notifier.notifier_call = intel_lid_notify; |
| 1002 | if (acpi_lid_notifier_register(&dev_priv->lid_notifier)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 1003 | DRM_DEBUG_KMS("lid notifier registration failed\n"); |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 1004 | dev_priv->lid_notifier.notifier_call = NULL; |
| 1005 | } |
Zhao Yakui | a256537 | 2009-12-11 09:26:11 +0800 | [diff] [blame] | 1006 | /* keep the LVDS connector */ |
| 1007 | dev_priv->int_lvds_connector = connector; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1008 | drm_sysfs_connector_add(connector); |
| 1009 | return; |
| 1010 | |
| 1011 | failed: |
Zhao Yakui | 8a4c47f | 2009-07-20 13:48:04 +0800 | [diff] [blame] | 1012 | DRM_DEBUG_KMS("No LVDS modes found, disabling.\n"); |
Eric Anholt | 21d40d3 | 2010-03-25 11:11:14 -0700 | [diff] [blame] | 1013 | if (intel_encoder->ddc_bus) |
| 1014 | intel_i2c_destroy(intel_encoder->ddc_bus); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1015 | drm_connector_cleanup(connector); |
Shaohua Li | 1991bdf | 2009-11-17 17:19:23 +0800 | [diff] [blame] | 1016 | drm_encoder_cleanup(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 1017 | kfree(intel_lvds); |
Zhenyu Wang | bb8a356 | 2010-03-29 16:40:50 +0800 | [diff] [blame] | 1018 | kfree(intel_connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1019 | } |