1 1.1 riastrad /* $NetBSD: intel_lvds.c,v 1.2 2021/12/18 23:45:30 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2006-2007 Intel Corporation 5 1.1 riastrad * Copyright (c) 2006 Dave Airlie <airlied (at) linux.ie> 6 1.1 riastrad * 7 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 8 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 9 1.1 riastrad * to deal in the Software without restriction, including without limitation 10 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 12 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 13 1.1 riastrad * 14 1.1 riastrad * The above copyright notice and this permission notice (including the next 15 1.1 riastrad * paragraph) shall be included in all copies or substantial portions of the 16 1.1 riastrad * Software. 17 1.1 riastrad * 18 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 1.1 riastrad * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 1.1 riastrad * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 1.1 riastrad * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 1.1 riastrad * DEALINGS IN THE SOFTWARE. 25 1.1 riastrad * 26 1.1 riastrad * Authors: 27 1.1 riastrad * Eric Anholt <eric (at) anholt.net> 28 1.1 riastrad * Dave Airlie <airlied (at) linux.ie> 29 1.1 riastrad * Jesse Barnes <jesse.barnes (at) intel.com> 30 1.1 riastrad */ 31 1.1 riastrad 32 1.1 riastrad #include <sys/cdefs.h> 33 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: intel_lvds.c,v 1.2 2021/12/18 23:45:30 riastradh Exp $"); 34 1.1 riastrad 35 1.1 riastrad #include <acpi/button.h> 36 1.1 riastrad #include <linux/acpi.h> 37 1.1 riastrad #include <linux/dmi.h> 38 1.1 riastrad #include <linux/i2c.h> 39 1.1 riastrad #include <linux/slab.h> 40 1.1 riastrad #include <linux/vga_switcheroo.h> 41 1.1 riastrad 42 1.1 riastrad #include <drm/drm_atomic_helper.h> 43 1.1 riastrad #include <drm/drm_crtc.h> 44 1.1 riastrad #include <drm/drm_edid.h> 45 1.1 riastrad #include <drm/i915_drm.h> 46 1.1 riastrad 47 1.1 riastrad #include "i915_drv.h" 48 1.1 riastrad #include "intel_atomic.h" 49 1.1 riastrad #include "intel_connector.h" 50 1.1 riastrad #include "intel_display_types.h" 51 1.1 riastrad #include "intel_gmbus.h" 52 1.1 riastrad #include "intel_lvds.h" 53 1.1 riastrad #include "intel_panel.h" 54 1.1 riastrad 55 1.1 riastrad /* Private structure for the integrated LVDS support */ 56 1.1 riastrad struct intel_lvds_pps { 57 1.1 riastrad /* 100us units */ 58 1.1 riastrad int t1_t2; 59 1.1 riastrad int t3; 60 1.1 riastrad int t4; 61 1.1 riastrad int t5; 62 1.1 riastrad int tx; 63 1.1 riastrad 64 1.1 riastrad int divider; 65 1.1 riastrad 66 1.1 riastrad int port; 67 1.1 riastrad bool powerdown_on_reset; 68 1.1 riastrad }; 69 1.1 riastrad 70 1.1 riastrad struct intel_lvds_encoder { 71 1.1 riastrad struct intel_encoder base; 72 1.1 riastrad 73 1.1 riastrad bool is_dual_link; 74 1.1 riastrad i915_reg_t reg; 75 1.1 riastrad u32 a3_power; 76 1.1 riastrad 77 1.1 riastrad struct intel_lvds_pps init_pps; 78 1.1 riastrad u32 init_lvds_val; 79 1.1 riastrad 80 1.1 riastrad struct intel_connector *attached_connector; 81 1.1 riastrad }; 82 1.1 riastrad 83 1.1 riastrad static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder) 84 1.1 riastrad { 85 1.1 riastrad return container_of(encoder, struct intel_lvds_encoder, base.base); 86 1.1 riastrad } 87 1.1 riastrad 88 1.1 riastrad bool intel_lvds_port_enabled(struct drm_i915_private *dev_priv, 89 1.1 riastrad i915_reg_t lvds_reg, enum pipe *pipe) 90 1.1 riastrad { 91 1.1 riastrad u32 val; 92 1.1 riastrad 93 1.1 riastrad val = I915_READ(lvds_reg); 94 1.1 riastrad 95 1.1 riastrad /* asserts want to know the pipe even if the port is disabled */ 96 1.1 riastrad if (HAS_PCH_CPT(dev_priv)) 97 1.1 riastrad *pipe = (val & LVDS_PIPE_SEL_MASK_CPT) >> LVDS_PIPE_SEL_SHIFT_CPT; 98 1.1 riastrad else 99 1.1 riastrad *pipe = (val & LVDS_PIPE_SEL_MASK) >> LVDS_PIPE_SEL_SHIFT; 100 1.1 riastrad 101 1.1 riastrad return val & LVDS_PORT_EN; 102 1.1 riastrad } 103 1.1 riastrad 104 1.1 riastrad static bool intel_lvds_get_hw_state(struct intel_encoder *encoder, 105 1.1 riastrad enum pipe *pipe) 106 1.1 riastrad { 107 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 108 1.1 riastrad struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base); 109 1.1 riastrad intel_wakeref_t wakeref; 110 1.1 riastrad bool ret; 111 1.1 riastrad 112 1.1 riastrad wakeref = intel_display_power_get_if_enabled(dev_priv, 113 1.1 riastrad encoder->power_domain); 114 1.1 riastrad if (!wakeref) 115 1.1 riastrad return false; 116 1.1 riastrad 117 1.1 riastrad ret = intel_lvds_port_enabled(dev_priv, lvds_encoder->reg, pipe); 118 1.1 riastrad 119 1.1 riastrad intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 120 1.1 riastrad 121 1.1 riastrad return ret; 122 1.1 riastrad } 123 1.1 riastrad 124 1.1 riastrad static void intel_lvds_get_config(struct intel_encoder *encoder, 125 1.1 riastrad struct intel_crtc_state *pipe_config) 126 1.1 riastrad { 127 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 128 1.1 riastrad struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base); 129 1.1 riastrad u32 tmp, flags = 0; 130 1.1 riastrad 131 1.1 riastrad pipe_config->output_types |= BIT(INTEL_OUTPUT_LVDS); 132 1.1 riastrad 133 1.1 riastrad tmp = I915_READ(lvds_encoder->reg); 134 1.1 riastrad if (tmp & LVDS_HSYNC_POLARITY) 135 1.1 riastrad flags |= DRM_MODE_FLAG_NHSYNC; 136 1.1 riastrad else 137 1.1 riastrad flags |= DRM_MODE_FLAG_PHSYNC; 138 1.1 riastrad if (tmp & LVDS_VSYNC_POLARITY) 139 1.1 riastrad flags |= DRM_MODE_FLAG_NVSYNC; 140 1.1 riastrad else 141 1.1 riastrad flags |= DRM_MODE_FLAG_PVSYNC; 142 1.1 riastrad 143 1.1 riastrad pipe_config->hw.adjusted_mode.flags |= flags; 144 1.1 riastrad 145 1.1 riastrad if (INTEL_GEN(dev_priv) < 5) 146 1.1 riastrad pipe_config->gmch_pfit.lvds_border_bits = 147 1.1 riastrad tmp & LVDS_BORDER_ENABLE; 148 1.1 riastrad 149 1.1 riastrad /* gen2/3 store dither state in pfit control, needs to match */ 150 1.1 riastrad if (INTEL_GEN(dev_priv) < 4) { 151 1.1 riastrad tmp = I915_READ(PFIT_CONTROL); 152 1.1 riastrad 153 1.1 riastrad pipe_config->gmch_pfit.control |= tmp & PANEL_8TO6_DITHER_ENABLE; 154 1.1 riastrad } 155 1.1 riastrad 156 1.1 riastrad pipe_config->hw.adjusted_mode.crtc_clock = pipe_config->port_clock; 157 1.1 riastrad } 158 1.1 riastrad 159 1.1 riastrad static void intel_lvds_pps_get_hw_state(struct drm_i915_private *dev_priv, 160 1.1 riastrad struct intel_lvds_pps *pps) 161 1.1 riastrad { 162 1.1 riastrad u32 val; 163 1.1 riastrad 164 1.1 riastrad pps->powerdown_on_reset = I915_READ(PP_CONTROL(0)) & PANEL_POWER_RESET; 165 1.1 riastrad 166 1.1 riastrad val = I915_READ(PP_ON_DELAYS(0)); 167 1.1 riastrad pps->port = REG_FIELD_GET(PANEL_PORT_SELECT_MASK, val); 168 1.1 riastrad pps->t1_t2 = REG_FIELD_GET(PANEL_POWER_UP_DELAY_MASK, val); 169 1.1 riastrad pps->t5 = REG_FIELD_GET(PANEL_LIGHT_ON_DELAY_MASK, val); 170 1.1 riastrad 171 1.1 riastrad val = I915_READ(PP_OFF_DELAYS(0)); 172 1.1 riastrad pps->t3 = REG_FIELD_GET(PANEL_POWER_DOWN_DELAY_MASK, val); 173 1.1 riastrad pps->tx = REG_FIELD_GET(PANEL_LIGHT_OFF_DELAY_MASK, val); 174 1.1 riastrad 175 1.1 riastrad val = I915_READ(PP_DIVISOR(0)); 176 1.1 riastrad pps->divider = REG_FIELD_GET(PP_REFERENCE_DIVIDER_MASK, val); 177 1.1 riastrad val = REG_FIELD_GET(PANEL_POWER_CYCLE_DELAY_MASK, val); 178 1.1 riastrad /* 179 1.1 riastrad * Remove the BSpec specified +1 (100ms) offset that accounts for a 180 1.1 riastrad * too short power-cycle delay due to the asynchronous programming of 181 1.1 riastrad * the register. 182 1.1 riastrad */ 183 1.1 riastrad if (val) 184 1.1 riastrad val--; 185 1.1 riastrad /* Convert from 100ms to 100us units */ 186 1.1 riastrad pps->t4 = val * 1000; 187 1.1 riastrad 188 1.1 riastrad if (INTEL_GEN(dev_priv) <= 4 && 189 1.1 riastrad pps->t1_t2 == 0 && pps->t5 == 0 && pps->t3 == 0 && pps->tx == 0) { 190 1.1 riastrad DRM_DEBUG_KMS("Panel power timings uninitialized, " 191 1.1 riastrad "setting defaults\n"); 192 1.1 riastrad /* Set T2 to 40ms and T5 to 200ms in 100 usec units */ 193 1.1 riastrad pps->t1_t2 = 40 * 10; 194 1.1 riastrad pps->t5 = 200 * 10; 195 1.1 riastrad /* Set T3 to 35ms and Tx to 200ms in 100 usec units */ 196 1.1 riastrad pps->t3 = 35 * 10; 197 1.1 riastrad pps->tx = 200 * 10; 198 1.1 riastrad } 199 1.1 riastrad 200 1.1 riastrad DRM_DEBUG_DRIVER("LVDS PPS:t1+t2 %d t3 %d t4 %d t5 %d tx %d " 201 1.1 riastrad "divider %d port %d powerdown_on_reset %d\n", 202 1.1 riastrad pps->t1_t2, pps->t3, pps->t4, pps->t5, pps->tx, 203 1.1 riastrad pps->divider, pps->port, pps->powerdown_on_reset); 204 1.1 riastrad } 205 1.1 riastrad 206 1.1 riastrad static void intel_lvds_pps_init_hw(struct drm_i915_private *dev_priv, 207 1.1 riastrad struct intel_lvds_pps *pps) 208 1.1 riastrad { 209 1.1 riastrad u32 val; 210 1.1 riastrad 211 1.1 riastrad val = I915_READ(PP_CONTROL(0)); 212 1.1 riastrad WARN_ON((val & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS); 213 1.1 riastrad if (pps->powerdown_on_reset) 214 1.1 riastrad val |= PANEL_POWER_RESET; 215 1.1 riastrad I915_WRITE(PP_CONTROL(0), val); 216 1.1 riastrad 217 1.1 riastrad I915_WRITE(PP_ON_DELAYS(0), 218 1.1 riastrad REG_FIELD_PREP(PANEL_PORT_SELECT_MASK, pps->port) | 219 1.1 riastrad REG_FIELD_PREP(PANEL_POWER_UP_DELAY_MASK, pps->t1_t2) | 220 1.1 riastrad REG_FIELD_PREP(PANEL_LIGHT_ON_DELAY_MASK, pps->t5)); 221 1.1 riastrad 222 1.1 riastrad I915_WRITE(PP_OFF_DELAYS(0), 223 1.1 riastrad REG_FIELD_PREP(PANEL_POWER_DOWN_DELAY_MASK, pps->t3) | 224 1.1 riastrad REG_FIELD_PREP(PANEL_LIGHT_OFF_DELAY_MASK, pps->tx)); 225 1.1 riastrad 226 1.1 riastrad I915_WRITE(PP_DIVISOR(0), 227 1.1 riastrad REG_FIELD_PREP(PP_REFERENCE_DIVIDER_MASK, pps->divider) | 228 1.1 riastrad REG_FIELD_PREP(PANEL_POWER_CYCLE_DELAY_MASK, 229 1.1 riastrad DIV_ROUND_UP(pps->t4, 1000) + 1)); 230 1.1 riastrad } 231 1.1 riastrad 232 1.1 riastrad static void intel_pre_enable_lvds(struct intel_encoder *encoder, 233 1.1 riastrad const struct intel_crtc_state *pipe_config, 234 1.1 riastrad const struct drm_connector_state *conn_state) 235 1.1 riastrad { 236 1.1 riastrad struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base); 237 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 238 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 239 1.1 riastrad const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 240 1.1 riastrad enum pipe pipe = crtc->pipe; 241 1.1 riastrad u32 temp; 242 1.1 riastrad 243 1.1 riastrad if (HAS_PCH_SPLIT(dev_priv)) { 244 1.1 riastrad assert_fdi_rx_pll_disabled(dev_priv, pipe); 245 1.1 riastrad assert_shared_dpll_disabled(dev_priv, 246 1.1 riastrad pipe_config->shared_dpll); 247 1.1 riastrad } else { 248 1.1 riastrad assert_pll_disabled(dev_priv, pipe); 249 1.1 riastrad } 250 1.1 riastrad 251 1.1 riastrad intel_lvds_pps_init_hw(dev_priv, &lvds_encoder->init_pps); 252 1.1 riastrad 253 1.1 riastrad temp = lvds_encoder->init_lvds_val; 254 1.1 riastrad temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP; 255 1.1 riastrad 256 1.1 riastrad if (HAS_PCH_CPT(dev_priv)) { 257 1.1 riastrad temp &= ~LVDS_PIPE_SEL_MASK_CPT; 258 1.1 riastrad temp |= LVDS_PIPE_SEL_CPT(pipe); 259 1.1 riastrad } else { 260 1.1 riastrad temp &= ~LVDS_PIPE_SEL_MASK; 261 1.1 riastrad temp |= LVDS_PIPE_SEL(pipe); 262 1.1 riastrad } 263 1.1 riastrad 264 1.1 riastrad /* set the corresponsding LVDS_BORDER bit */ 265 1.1 riastrad temp &= ~LVDS_BORDER_ENABLE; 266 1.1 riastrad temp |= pipe_config->gmch_pfit.lvds_border_bits; 267 1.1 riastrad 268 1.1 riastrad /* 269 1.1 riastrad * Set the B0-B3 data pairs corresponding to whether we're going to 270 1.1 riastrad * set the DPLLs for dual-channel mode or not. 271 1.1 riastrad */ 272 1.1 riastrad if (lvds_encoder->is_dual_link) 273 1.1 riastrad temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP; 274 1.1 riastrad else 275 1.1 riastrad temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP); 276 1.1 riastrad 277 1.1 riastrad /* 278 1.1 riastrad * It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP) 279 1.1 riastrad * appropriately here, but we need to look more thoroughly into how 280 1.1 riastrad * panels behave in the two modes. For now, let's just maintain the 281 1.1 riastrad * value we got from the BIOS. 282 1.1 riastrad */ 283 1.1 riastrad temp &= ~LVDS_A3_POWER_MASK; 284 1.1 riastrad temp |= lvds_encoder->a3_power; 285 1.1 riastrad 286 1.1 riastrad /* 287 1.1 riastrad * Set the dithering flag on LVDS as needed, note that there is no 288 1.1 riastrad * special lvds dither control bit on pch-split platforms, dithering is 289 1.1 riastrad * only controlled through the PIPECONF reg. 290 1.1 riastrad */ 291 1.1 riastrad if (IS_GEN(dev_priv, 4)) { 292 1.1 riastrad /* 293 1.1 riastrad * Bspec wording suggests that LVDS port dithering only exists 294 1.1 riastrad * for 18bpp panels. 295 1.1 riastrad */ 296 1.1 riastrad if (pipe_config->dither && pipe_config->pipe_bpp == 18) 297 1.1 riastrad temp |= LVDS_ENABLE_DITHER; 298 1.1 riastrad else 299 1.1 riastrad temp &= ~LVDS_ENABLE_DITHER; 300 1.1 riastrad } 301 1.1 riastrad temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY); 302 1.1 riastrad if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC) 303 1.1 riastrad temp |= LVDS_HSYNC_POLARITY; 304 1.1 riastrad if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC) 305 1.1 riastrad temp |= LVDS_VSYNC_POLARITY; 306 1.1 riastrad 307 1.1 riastrad I915_WRITE(lvds_encoder->reg, temp); 308 1.1 riastrad } 309 1.1 riastrad 310 1.1 riastrad /* 311 1.1 riastrad * Sets the power state for the panel. 312 1.1 riastrad */ 313 1.1 riastrad static void intel_enable_lvds(struct intel_encoder *encoder, 314 1.1 riastrad const struct intel_crtc_state *pipe_config, 315 1.1 riastrad const struct drm_connector_state *conn_state) 316 1.1 riastrad { 317 1.1 riastrad struct drm_device *dev = encoder->base.dev; 318 1.1 riastrad struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base); 319 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 320 1.1 riastrad 321 1.1 riastrad I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN); 322 1.1 riastrad 323 1.1 riastrad I915_WRITE(PP_CONTROL(0), I915_READ(PP_CONTROL(0)) | PANEL_POWER_ON); 324 1.1 riastrad POSTING_READ(lvds_encoder->reg); 325 1.1 riastrad 326 1.1 riastrad if (intel_de_wait_for_set(dev_priv, PP_STATUS(0), PP_ON, 5000)) 327 1.1 riastrad DRM_ERROR("timed out waiting for panel to power on\n"); 328 1.1 riastrad 329 1.1 riastrad intel_panel_enable_backlight(pipe_config, conn_state); 330 1.1 riastrad } 331 1.1 riastrad 332 1.1 riastrad static void intel_disable_lvds(struct intel_encoder *encoder, 333 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 334 1.1 riastrad const struct drm_connector_state *old_conn_state) 335 1.1 riastrad { 336 1.1 riastrad struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base); 337 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 338 1.1 riastrad 339 1.1 riastrad I915_WRITE(PP_CONTROL(0), I915_READ(PP_CONTROL(0)) & ~PANEL_POWER_ON); 340 1.1 riastrad if (intel_de_wait_for_clear(dev_priv, PP_STATUS(0), PP_ON, 1000)) 341 1.1 riastrad DRM_ERROR("timed out waiting for panel to power off\n"); 342 1.1 riastrad 343 1.1 riastrad I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN); 344 1.1 riastrad POSTING_READ(lvds_encoder->reg); 345 1.1 riastrad } 346 1.1 riastrad 347 1.1 riastrad static void gmch_disable_lvds(struct intel_encoder *encoder, 348 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 349 1.1 riastrad const struct drm_connector_state *old_conn_state) 350 1.1 riastrad 351 1.1 riastrad { 352 1.1 riastrad intel_panel_disable_backlight(old_conn_state); 353 1.1 riastrad 354 1.1 riastrad intel_disable_lvds(encoder, old_crtc_state, old_conn_state); 355 1.1 riastrad } 356 1.1 riastrad 357 1.1 riastrad static void pch_disable_lvds(struct intel_encoder *encoder, 358 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 359 1.1 riastrad const struct drm_connector_state *old_conn_state) 360 1.1 riastrad { 361 1.1 riastrad intel_panel_disable_backlight(old_conn_state); 362 1.1 riastrad } 363 1.1 riastrad 364 1.1 riastrad static void pch_post_disable_lvds(struct intel_encoder *encoder, 365 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 366 1.1 riastrad const struct drm_connector_state *old_conn_state) 367 1.1 riastrad { 368 1.1 riastrad intel_disable_lvds(encoder, old_crtc_state, old_conn_state); 369 1.1 riastrad } 370 1.1 riastrad 371 1.1 riastrad static enum drm_mode_status 372 1.1 riastrad intel_lvds_mode_valid(struct drm_connector *connector, 373 1.1 riastrad struct drm_display_mode *mode) 374 1.1 riastrad { 375 1.1 riastrad struct intel_connector *intel_connector = to_intel_connector(connector); 376 1.1 riastrad struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode; 377 1.1 riastrad int max_pixclk = to_i915(connector->dev)->max_dotclk_freq; 378 1.1 riastrad 379 1.1 riastrad if (mode->flags & DRM_MODE_FLAG_DBLSCAN) 380 1.1 riastrad return MODE_NO_DBLESCAN; 381 1.1 riastrad if (mode->hdisplay > fixed_mode->hdisplay) 382 1.1 riastrad return MODE_PANEL; 383 1.1 riastrad if (mode->vdisplay > fixed_mode->vdisplay) 384 1.1 riastrad return MODE_PANEL; 385 1.1 riastrad if (fixed_mode->clock > max_pixclk) 386 1.1 riastrad return MODE_CLOCK_HIGH; 387 1.1 riastrad 388 1.1 riastrad return MODE_OK; 389 1.1 riastrad } 390 1.1 riastrad 391 1.1 riastrad static int intel_lvds_compute_config(struct intel_encoder *intel_encoder, 392 1.1 riastrad struct intel_crtc_state *pipe_config, 393 1.1 riastrad struct drm_connector_state *conn_state) 394 1.1 riastrad { 395 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); 396 1.1 riastrad struct intel_lvds_encoder *lvds_encoder = 397 1.1 riastrad to_lvds_encoder(&intel_encoder->base); 398 1.1 riastrad struct intel_connector *intel_connector = 399 1.1 riastrad lvds_encoder->attached_connector; 400 1.1 riastrad struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 401 1.1 riastrad struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc); 402 1.1 riastrad unsigned int lvds_bpp; 403 1.1 riastrad 404 1.1 riastrad /* Should never happen!! */ 405 1.1 riastrad if (INTEL_GEN(dev_priv) < 4 && intel_crtc->pipe == 0) { 406 1.1 riastrad DRM_ERROR("Can't support LVDS on pipe A\n"); 407 1.1 riastrad return -EINVAL; 408 1.1 riastrad } 409 1.1 riastrad 410 1.1 riastrad if (lvds_encoder->a3_power == LVDS_A3_POWER_UP) 411 1.1 riastrad lvds_bpp = 8*3; 412 1.1 riastrad else 413 1.1 riastrad lvds_bpp = 6*3; 414 1.1 riastrad 415 1.1 riastrad if (lvds_bpp != pipe_config->pipe_bpp && !pipe_config->bw_constrained) { 416 1.1 riastrad DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n", 417 1.1 riastrad pipe_config->pipe_bpp, lvds_bpp); 418 1.1 riastrad pipe_config->pipe_bpp = lvds_bpp; 419 1.1 riastrad } 420 1.1 riastrad 421 1.1 riastrad pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 422 1.1 riastrad 423 1.1 riastrad /* 424 1.1 riastrad * We have timings from the BIOS for the panel, put them in 425 1.1 riastrad * to the adjusted mode. The CRTC will be set up for this mode, 426 1.1 riastrad * with the panel scaling set up to source from the H/VDisplay 427 1.1 riastrad * of the original mode. 428 1.1 riastrad */ 429 1.1 riastrad intel_fixed_panel_mode(intel_connector->panel.fixed_mode, 430 1.1 riastrad adjusted_mode); 431 1.1 riastrad 432 1.1 riastrad if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN) 433 1.1 riastrad return -EINVAL; 434 1.1 riastrad 435 1.1 riastrad if (HAS_PCH_SPLIT(dev_priv)) { 436 1.1 riastrad pipe_config->has_pch_encoder = true; 437 1.1 riastrad 438 1.1 riastrad intel_pch_panel_fitting(intel_crtc, pipe_config, 439 1.1 riastrad conn_state->scaling_mode); 440 1.1 riastrad } else { 441 1.1 riastrad intel_gmch_panel_fitting(intel_crtc, pipe_config, 442 1.1 riastrad conn_state->scaling_mode); 443 1.1 riastrad 444 1.1 riastrad } 445 1.1 riastrad 446 1.1 riastrad /* 447 1.1 riastrad * XXX: It would be nice to support lower refresh rates on the 448 1.1 riastrad * panels to reduce power consumption, and perhaps match the 449 1.1 riastrad * user's requested refresh rate. 450 1.1 riastrad */ 451 1.1 riastrad 452 1.1 riastrad return 0; 453 1.1 riastrad } 454 1.1 riastrad 455 1.1 riastrad static enum drm_connector_status 456 1.1 riastrad intel_lvds_detect(struct drm_connector *connector, bool force) 457 1.1 riastrad { 458 1.1 riastrad return connector_status_connected; 459 1.1 riastrad } 460 1.1 riastrad 461 1.1 riastrad /* 462 1.1 riastrad * Return the list of DDC modes if available, or the BIOS fixed mode otherwise. 463 1.1 riastrad */ 464 1.1 riastrad static int intel_lvds_get_modes(struct drm_connector *connector) 465 1.1 riastrad { 466 1.1 riastrad struct intel_connector *intel_connector = to_intel_connector(connector); 467 1.1 riastrad struct drm_device *dev = connector->dev; 468 1.1 riastrad struct drm_display_mode *mode; 469 1.1 riastrad 470 1.1 riastrad /* use cached edid if we have one */ 471 1.1 riastrad if (!IS_ERR_OR_NULL(intel_connector->edid)) 472 1.1 riastrad return drm_add_edid_modes(connector, intel_connector->edid); 473 1.1 riastrad 474 1.1 riastrad mode = drm_mode_duplicate(dev, intel_connector->panel.fixed_mode); 475 1.1 riastrad if (mode == NULL) 476 1.1 riastrad return 0; 477 1.1 riastrad 478 1.1 riastrad drm_mode_probed_add(connector, mode); 479 1.1 riastrad return 1; 480 1.1 riastrad } 481 1.1 riastrad 482 1.1 riastrad static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = { 483 1.1 riastrad .get_modes = intel_lvds_get_modes, 484 1.1 riastrad .mode_valid = intel_lvds_mode_valid, 485 1.1 riastrad .atomic_check = intel_digital_connector_atomic_check, 486 1.1 riastrad }; 487 1.1 riastrad 488 1.1 riastrad static const struct drm_connector_funcs intel_lvds_connector_funcs = { 489 1.1 riastrad .detect = intel_lvds_detect, 490 1.1 riastrad .fill_modes = drm_helper_probe_single_connector_modes, 491 1.1 riastrad .atomic_get_property = intel_digital_connector_atomic_get_property, 492 1.1 riastrad .atomic_set_property = intel_digital_connector_atomic_set_property, 493 1.1 riastrad .late_register = intel_connector_register, 494 1.1 riastrad .early_unregister = intel_connector_unregister, 495 1.1 riastrad .destroy = intel_connector_destroy, 496 1.1 riastrad .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 497 1.1 riastrad .atomic_duplicate_state = intel_digital_connector_duplicate_state, 498 1.1 riastrad }; 499 1.1 riastrad 500 1.1 riastrad static const struct drm_encoder_funcs intel_lvds_enc_funcs = { 501 1.1 riastrad .destroy = intel_encoder_destroy, 502 1.1 riastrad }; 503 1.1 riastrad 504 1.1 riastrad static int intel_no_lvds_dmi_callback(const struct dmi_system_id *id) 505 1.1 riastrad { 506 1.1 riastrad DRM_INFO("Skipping LVDS initialization for %s\n", id->ident); 507 1.1 riastrad return 1; 508 1.1 riastrad } 509 1.1 riastrad 510 1.1 riastrad /* These systems claim to have LVDS, but really don't */ 511 1.1 riastrad static const struct dmi_system_id intel_no_lvds[] = { 512 1.1 riastrad { 513 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 514 1.1 riastrad .ident = "Apple Mac Mini (Core series)", 515 1.1 riastrad .matches = { 516 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Apple"), 517 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"), 518 1.1 riastrad }, 519 1.1 riastrad }, 520 1.1 riastrad { 521 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 522 1.1 riastrad .ident = "Apple Mac Mini (Core 2 series)", 523 1.1 riastrad .matches = { 524 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Apple"), 525 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"), 526 1.1 riastrad }, 527 1.1 riastrad }, 528 1.1 riastrad { 529 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 530 1.1 riastrad .ident = "MSI IM-945GSE-A", 531 1.1 riastrad .matches = { 532 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "MSI"), 533 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"), 534 1.1 riastrad }, 535 1.1 riastrad }, 536 1.1 riastrad { 537 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 538 1.1 riastrad .ident = "Dell Studio Hybrid", 539 1.1 riastrad .matches = { 540 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 541 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"), 542 1.1 riastrad }, 543 1.1 riastrad }, 544 1.1 riastrad { 545 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 546 1.1 riastrad .ident = "Dell OptiPlex FX170", 547 1.1 riastrad .matches = { 548 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 549 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"), 550 1.1 riastrad }, 551 1.1 riastrad }, 552 1.1 riastrad { 553 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 554 1.1 riastrad .ident = "AOpen Mini PC", 555 1.1 riastrad .matches = { 556 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "AOpen"), 557 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"), 558 1.1 riastrad }, 559 1.1 riastrad }, 560 1.1 riastrad { 561 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 562 1.1 riastrad .ident = "AOpen Mini PC MP915", 563 1.1 riastrad .matches = { 564 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), 565 1.1 riastrad DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"), 566 1.1 riastrad }, 567 1.1 riastrad }, 568 1.1 riastrad { 569 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 570 1.1 riastrad .ident = "AOpen i915GMm-HFS", 571 1.1 riastrad .matches = { 572 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), 573 1.1 riastrad DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), 574 1.1 riastrad }, 575 1.1 riastrad }, 576 1.1 riastrad { 577 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 578 1.1 riastrad .ident = "AOpen i45GMx-I", 579 1.1 riastrad .matches = { 580 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), 581 1.1 riastrad DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"), 582 1.1 riastrad }, 583 1.1 riastrad }, 584 1.1 riastrad { 585 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 586 1.1 riastrad .ident = "Aopen i945GTt-VFA", 587 1.1 riastrad .matches = { 588 1.1 riastrad DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"), 589 1.1 riastrad }, 590 1.1 riastrad }, 591 1.1 riastrad { 592 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 593 1.1 riastrad .ident = "Clientron U800", 594 1.1 riastrad .matches = { 595 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Clientron"), 596 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "U800"), 597 1.1 riastrad }, 598 1.1 riastrad }, 599 1.1 riastrad { 600 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 601 1.1 riastrad .ident = "Clientron E830", 602 1.1 riastrad .matches = { 603 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Clientron"), 604 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "E830"), 605 1.1 riastrad }, 606 1.1 riastrad }, 607 1.1 riastrad { 608 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 609 1.1 riastrad .ident = "Asus EeeBox PC EB1007", 610 1.1 riastrad .matches = { 611 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."), 612 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"), 613 1.1 riastrad }, 614 1.1 riastrad }, 615 1.1 riastrad { 616 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 617 1.1 riastrad .ident = "Asus AT5NM10T-I", 618 1.1 riastrad .matches = { 619 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), 620 1.1 riastrad DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"), 621 1.1 riastrad }, 622 1.1 riastrad }, 623 1.1 riastrad { 624 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 625 1.1 riastrad .ident = "Hewlett-Packard HP t5740", 626 1.1 riastrad .matches = { 627 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"), 628 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, " t5740"), 629 1.1 riastrad }, 630 1.1 riastrad }, 631 1.1 riastrad { 632 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 633 1.1 riastrad .ident = "Hewlett-Packard t5745", 634 1.1 riastrad .matches = { 635 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"), 636 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"), 637 1.1 riastrad }, 638 1.1 riastrad }, 639 1.1 riastrad { 640 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 641 1.1 riastrad .ident = "Hewlett-Packard st5747", 642 1.1 riastrad .matches = { 643 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"), 644 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"), 645 1.1 riastrad }, 646 1.1 riastrad }, 647 1.1 riastrad { 648 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 649 1.1 riastrad .ident = "MSI Wind Box DC500", 650 1.1 riastrad .matches = { 651 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"), 652 1.1 riastrad DMI_MATCH(DMI_BOARD_NAME, "MS-7469"), 653 1.1 riastrad }, 654 1.1 riastrad }, 655 1.1 riastrad { 656 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 657 1.1 riastrad .ident = "Gigabyte GA-D525TUD", 658 1.1 riastrad .matches = { 659 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), 660 1.1 riastrad DMI_MATCH(DMI_BOARD_NAME, "D525TUD"), 661 1.1 riastrad }, 662 1.1 riastrad }, 663 1.1 riastrad { 664 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 665 1.1 riastrad .ident = "Supermicro X7SPA-H", 666 1.1 riastrad .matches = { 667 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"), 668 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"), 669 1.1 riastrad }, 670 1.1 riastrad }, 671 1.1 riastrad { 672 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 673 1.1 riastrad .ident = "Fujitsu Esprimo Q900", 674 1.1 riastrad .matches = { 675 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), 676 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"), 677 1.1 riastrad }, 678 1.1 riastrad }, 679 1.1 riastrad { 680 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 681 1.1 riastrad .ident = "Intel D410PT", 682 1.1 riastrad .matches = { 683 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "Intel"), 684 1.1 riastrad DMI_MATCH(DMI_BOARD_NAME, "D410PT"), 685 1.1 riastrad }, 686 1.1 riastrad }, 687 1.1 riastrad { 688 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 689 1.1 riastrad .ident = "Intel D425KT", 690 1.1 riastrad .matches = { 691 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "Intel"), 692 1.1 riastrad DMI_EXACT_MATCH(DMI_BOARD_NAME, "D425KT"), 693 1.1 riastrad }, 694 1.1 riastrad }, 695 1.1 riastrad { 696 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 697 1.1 riastrad .ident = "Intel D510MO", 698 1.1 riastrad .matches = { 699 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "Intel"), 700 1.1 riastrad DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"), 701 1.1 riastrad }, 702 1.1 riastrad }, 703 1.1 riastrad { 704 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 705 1.1 riastrad .ident = "Intel D525MW", 706 1.1 riastrad .matches = { 707 1.1 riastrad DMI_MATCH(DMI_BOARD_VENDOR, "Intel"), 708 1.1 riastrad DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"), 709 1.1 riastrad }, 710 1.1 riastrad }, 711 1.1 riastrad { 712 1.1 riastrad .callback = intel_no_lvds_dmi_callback, 713 1.1 riastrad .ident = "Radiant P845", 714 1.1 riastrad .matches = { 715 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Radiant Systems Inc"), 716 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "P845"), 717 1.1 riastrad }, 718 1.1 riastrad }, 719 1.1 riastrad 720 1.1 riastrad { } /* terminating entry */ 721 1.1 riastrad }; 722 1.1 riastrad 723 1.1 riastrad static int intel_dual_link_lvds_callback(const struct dmi_system_id *id) 724 1.1 riastrad { 725 1.1 riastrad DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident); 726 1.1 riastrad return 1; 727 1.1 riastrad } 728 1.1 riastrad 729 1.1 riastrad static const struct dmi_system_id intel_dual_link_lvds[] = { 730 1.1 riastrad { 731 1.1 riastrad .callback = intel_dual_link_lvds_callback, 732 1.1 riastrad .ident = "Apple MacBook Pro 15\" (2010)", 733 1.1 riastrad .matches = { 734 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 735 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6,2"), 736 1.1 riastrad }, 737 1.1 riastrad }, 738 1.1 riastrad { 739 1.1 riastrad .callback = intel_dual_link_lvds_callback, 740 1.1 riastrad .ident = "Apple MacBook Pro 15\" (2011)", 741 1.1 riastrad .matches = { 742 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 743 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"), 744 1.1 riastrad }, 745 1.1 riastrad }, 746 1.1 riastrad { 747 1.1 riastrad .callback = intel_dual_link_lvds_callback, 748 1.1 riastrad .ident = "Apple MacBook Pro 15\" (2012)", 749 1.1 riastrad .matches = { 750 1.1 riastrad DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 751 1.1 riastrad DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,1"), 752 1.1 riastrad }, 753 1.1 riastrad }, 754 1.1 riastrad { } /* terminating entry */ 755 1.1 riastrad }; 756 1.1 riastrad 757 1.1 riastrad struct intel_encoder *intel_get_lvds_encoder(struct drm_i915_private *dev_priv) 758 1.1 riastrad { 759 1.1 riastrad struct intel_encoder *encoder; 760 1.1 riastrad 761 1.1 riastrad for_each_intel_encoder(&dev_priv->drm, encoder) { 762 1.1 riastrad if (encoder->type == INTEL_OUTPUT_LVDS) 763 1.1 riastrad return encoder; 764 1.1 riastrad } 765 1.1 riastrad 766 1.1 riastrad return NULL; 767 1.1 riastrad } 768 1.1 riastrad 769 1.1 riastrad bool intel_is_dual_link_lvds(struct drm_i915_private *dev_priv) 770 1.1 riastrad { 771 1.1 riastrad struct intel_encoder *encoder = intel_get_lvds_encoder(dev_priv); 772 1.1 riastrad 773 1.1 riastrad return encoder && to_lvds_encoder(&encoder->base)->is_dual_link; 774 1.1 riastrad } 775 1.1 riastrad 776 1.1 riastrad static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder) 777 1.1 riastrad { 778 1.1 riastrad struct drm_device *dev = lvds_encoder->base.base.dev; 779 1.1 riastrad unsigned int val; 780 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 781 1.1 riastrad 782 1.1 riastrad /* use the module option value if specified */ 783 1.1 riastrad if (i915_modparams.lvds_channel_mode > 0) 784 1.1 riastrad return i915_modparams.lvds_channel_mode == 2; 785 1.1 riastrad 786 1.1 riastrad /* single channel LVDS is limited to 112 MHz */ 787 1.1 riastrad if (lvds_encoder->attached_connector->panel.fixed_mode->clock > 112999) 788 1.1 riastrad return true; 789 1.1 riastrad 790 1.1 riastrad if (dmi_check_system(intel_dual_link_lvds)) 791 1.1 riastrad return true; 792 1.1 riastrad 793 1.1 riastrad /* 794 1.1 riastrad * BIOS should set the proper LVDS register value at boot, but 795 1.1 riastrad * in reality, it doesn't set the value when the lid is closed; 796 1.1 riastrad * we need to check "the value to be set" in VBT when LVDS 797 1.1 riastrad * register is uninitialized. 798 1.1 riastrad */ 799 1.1 riastrad val = I915_READ(lvds_encoder->reg); 800 1.1 riastrad if (HAS_PCH_CPT(dev_priv)) 801 1.1 riastrad val &= ~(LVDS_DETECTED | LVDS_PIPE_SEL_MASK_CPT); 802 1.1 riastrad else 803 1.1 riastrad val &= ~(LVDS_DETECTED | LVDS_PIPE_SEL_MASK); 804 1.1 riastrad if (val == 0) 805 1.1 riastrad val = dev_priv->vbt.bios_lvds_val; 806 1.1 riastrad 807 1.1 riastrad return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP; 808 1.1 riastrad } 809 1.1 riastrad 810 1.1 riastrad /** 811 1.1 riastrad * intel_lvds_init - setup LVDS connectors on this device 812 1.1 riastrad * @dev_priv: i915 device 813 1.1 riastrad * 814 1.1 riastrad * Create the connector, register the LVDS DDC bus, and try to figure out what 815 1.1 riastrad * modes we can display on the LVDS panel (if present). 816 1.1 riastrad */ 817 1.1 riastrad void intel_lvds_init(struct drm_i915_private *dev_priv) 818 1.1 riastrad { 819 1.1 riastrad struct drm_device *dev = &dev_priv->drm; 820 1.1 riastrad struct intel_lvds_encoder *lvds_encoder; 821 1.1 riastrad struct intel_encoder *intel_encoder; 822 1.1 riastrad struct intel_connector *intel_connector; 823 1.1 riastrad struct drm_connector *connector; 824 1.1 riastrad struct drm_encoder *encoder; 825 1.1 riastrad struct drm_display_mode *fixed_mode = NULL; 826 1.1 riastrad struct drm_display_mode *downclock_mode = NULL; 827 1.1 riastrad struct edid *edid; 828 1.1 riastrad i915_reg_t lvds_reg; 829 1.1 riastrad u32 lvds; 830 1.1 riastrad u8 pin; 831 1.1 riastrad u32 allowed_scalers; 832 1.1 riastrad 833 1.1 riastrad /* Skip init on machines we know falsely report LVDS */ 834 1.1 riastrad if (dmi_check_system(intel_no_lvds)) { 835 1.1 riastrad WARN(!dev_priv->vbt.int_lvds_support, 836 1.1 riastrad "Useless DMI match. Internal LVDS support disabled by VBT\n"); 837 1.1 riastrad return; 838 1.1 riastrad } 839 1.1 riastrad 840 1.1 riastrad if (!dev_priv->vbt.int_lvds_support) { 841 1.1 riastrad DRM_DEBUG_KMS("Internal LVDS support disabled by VBT\n"); 842 1.1 riastrad return; 843 1.1 riastrad } 844 1.1 riastrad 845 1.1 riastrad if (HAS_PCH_SPLIT(dev_priv)) 846 1.1 riastrad lvds_reg = PCH_LVDS; 847 1.1 riastrad else 848 1.1 riastrad lvds_reg = LVDS; 849 1.1 riastrad 850 1.1 riastrad lvds = I915_READ(lvds_reg); 851 1.1 riastrad 852 1.1 riastrad if (HAS_PCH_SPLIT(dev_priv)) { 853 1.1 riastrad if ((lvds & LVDS_DETECTED) == 0) 854 1.1 riastrad return; 855 1.1 riastrad } 856 1.1 riastrad 857 1.1 riastrad pin = GMBUS_PIN_PANEL; 858 1.1 riastrad if (!intel_bios_is_lvds_present(dev_priv, &pin)) { 859 1.1 riastrad if ((lvds & LVDS_PORT_EN) == 0) { 860 1.1 riastrad DRM_DEBUG_KMS("LVDS is not present in VBT\n"); 861 1.1 riastrad return; 862 1.1 riastrad } 863 1.1 riastrad DRM_DEBUG_KMS("LVDS is not present in VBT, but enabled anyway\n"); 864 1.1 riastrad } 865 1.1 riastrad 866 1.1 riastrad lvds_encoder = kzalloc(sizeof(*lvds_encoder), GFP_KERNEL); 867 1.1 riastrad if (!lvds_encoder) 868 1.1 riastrad return; 869 1.1 riastrad 870 1.1 riastrad intel_connector = intel_connector_alloc(); 871 1.1 riastrad if (!intel_connector) { 872 1.1 riastrad kfree(lvds_encoder); 873 1.1 riastrad return; 874 1.1 riastrad } 875 1.1 riastrad 876 1.1 riastrad lvds_encoder->attached_connector = intel_connector; 877 1.1 riastrad 878 1.1 riastrad intel_encoder = &lvds_encoder->base; 879 1.1 riastrad encoder = &intel_encoder->base; 880 1.1 riastrad connector = &intel_connector->base; 881 1.1 riastrad drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs, 882 1.1 riastrad DRM_MODE_CONNECTOR_LVDS); 883 1.1 riastrad 884 1.1 riastrad drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs, 885 1.1 riastrad DRM_MODE_ENCODER_LVDS, "LVDS"); 886 1.1 riastrad 887 1.1 riastrad intel_encoder->enable = intel_enable_lvds; 888 1.1 riastrad intel_encoder->pre_enable = intel_pre_enable_lvds; 889 1.1 riastrad intel_encoder->compute_config = intel_lvds_compute_config; 890 1.1 riastrad if (HAS_PCH_SPLIT(dev_priv)) { 891 1.1 riastrad intel_encoder->disable = pch_disable_lvds; 892 1.1 riastrad intel_encoder->post_disable = pch_post_disable_lvds; 893 1.1 riastrad } else { 894 1.1 riastrad intel_encoder->disable = gmch_disable_lvds; 895 1.1 riastrad } 896 1.1 riastrad intel_encoder->get_hw_state = intel_lvds_get_hw_state; 897 1.1 riastrad intel_encoder->get_config = intel_lvds_get_config; 898 1.1 riastrad intel_encoder->update_pipe = intel_panel_update_backlight; 899 1.1 riastrad intel_connector->get_hw_state = intel_connector_get_hw_state; 900 1.1 riastrad 901 1.1 riastrad intel_connector_attach_encoder(intel_connector, intel_encoder); 902 1.1 riastrad 903 1.1 riastrad intel_encoder->type = INTEL_OUTPUT_LVDS; 904 1.1 riastrad intel_encoder->power_domain = POWER_DOMAIN_PORT_OTHER; 905 1.1 riastrad intel_encoder->port = PORT_NONE; 906 1.1 riastrad intel_encoder->cloneable = 0; 907 1.1 riastrad if (INTEL_GEN(dev_priv) < 4) 908 1.1 riastrad intel_encoder->pipe_mask = BIT(PIPE_B); 909 1.1 riastrad else 910 1.1 riastrad intel_encoder->pipe_mask = ~0; 911 1.1 riastrad 912 1.1 riastrad drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs); 913 1.1 riastrad connector->display_info.subpixel_order = SubPixelHorizontalRGB; 914 1.1 riastrad connector->interlace_allowed = false; 915 1.1 riastrad connector->doublescan_allowed = false; 916 1.1 riastrad 917 1.1 riastrad lvds_encoder->reg = lvds_reg; 918 1.1 riastrad 919 1.1 riastrad /* create the scaling mode property */ 920 1.1 riastrad allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT); 921 1.1 riastrad allowed_scalers |= BIT(DRM_MODE_SCALE_FULLSCREEN); 922 1.1 riastrad allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER); 923 1.1 riastrad drm_connector_attach_scaling_mode_property(connector, allowed_scalers); 924 1.1 riastrad connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT; 925 1.1 riastrad 926 1.1 riastrad intel_lvds_pps_get_hw_state(dev_priv, &lvds_encoder->init_pps); 927 1.1 riastrad lvds_encoder->init_lvds_val = lvds; 928 1.1 riastrad 929 1.1 riastrad /* 930 1.1 riastrad * LVDS discovery: 931 1.1 riastrad * 1) check for EDID on DDC 932 1.1 riastrad * 2) check for VBT data 933 1.1 riastrad * 3) check to see if LVDS is already on 934 1.1 riastrad * if none of the above, no panel 935 1.1 riastrad */ 936 1.1 riastrad 937 1.1 riastrad /* 938 1.1 riastrad * Attempt to get the fixed panel mode from DDC. Assume that the 939 1.1 riastrad * preferred mode is the right one. 940 1.1 riastrad */ 941 1.1 riastrad mutex_lock(&dev->mode_config.mutex); 942 1.1 riastrad if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC) 943 1.1 riastrad edid = drm_get_edid_switcheroo(connector, 944 1.1 riastrad intel_gmbus_get_adapter(dev_priv, pin)); 945 1.1 riastrad else 946 1.1 riastrad edid = drm_get_edid(connector, 947 1.1 riastrad intel_gmbus_get_adapter(dev_priv, pin)); 948 1.1 riastrad if (edid) { 949 1.1 riastrad if (drm_add_edid_modes(connector, edid)) { 950 1.1 riastrad drm_connector_update_edid_property(connector, 951 1.1 riastrad edid); 952 1.1 riastrad } else { 953 1.1 riastrad kfree(edid); 954 1.1 riastrad edid = ERR_PTR(-EINVAL); 955 1.1 riastrad } 956 1.1 riastrad } else { 957 1.1 riastrad edid = ERR_PTR(-ENOENT); 958 1.1 riastrad } 959 1.1 riastrad intel_connector->edid = edid; 960 1.1 riastrad 961 1.1 riastrad fixed_mode = intel_panel_edid_fixed_mode(intel_connector); 962 1.1 riastrad if (fixed_mode) 963 1.1 riastrad goto out; 964 1.1 riastrad 965 1.1 riastrad /* Failed to get EDID, what about VBT? */ 966 1.1 riastrad fixed_mode = intel_panel_vbt_fixed_mode(intel_connector); 967 1.1 riastrad if (fixed_mode) 968 1.1 riastrad goto out; 969 1.1 riastrad 970 1.1 riastrad /* 971 1.1 riastrad * If we didn't get EDID, try checking if the panel is already turned 972 1.1 riastrad * on. If so, assume that whatever is currently programmed is the 973 1.1 riastrad * correct mode. 974 1.1 riastrad */ 975 1.1 riastrad fixed_mode = intel_encoder_current_mode(intel_encoder); 976 1.1 riastrad if (fixed_mode) { 977 1.1 riastrad DRM_DEBUG_KMS("using current (BIOS) mode: "); 978 1.1 riastrad drm_mode_debug_printmodeline(fixed_mode); 979 1.1 riastrad fixed_mode->type |= DRM_MODE_TYPE_PREFERRED; 980 1.1 riastrad } 981 1.1 riastrad 982 1.1 riastrad /* If we still don't have a mode after all that, give up. */ 983 1.1 riastrad if (!fixed_mode) 984 1.1 riastrad goto failed; 985 1.1 riastrad 986 1.1 riastrad out: 987 1.1 riastrad mutex_unlock(&dev->mode_config.mutex); 988 1.1 riastrad 989 1.1 riastrad intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode); 990 1.1 riastrad intel_panel_setup_backlight(connector, INVALID_PIPE); 991 1.1 riastrad 992 1.1 riastrad lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder); 993 1.1 riastrad DRM_DEBUG_KMS("detected %s-link lvds configuration\n", 994 1.1 riastrad lvds_encoder->is_dual_link ? "dual" : "single"); 995 1.1 riastrad 996 1.1 riastrad lvds_encoder->a3_power = lvds & LVDS_A3_POWER_MASK; 997 1.1 riastrad 998 1.1 riastrad return; 999 1.1 riastrad 1000 1.1 riastrad failed: 1001 1.1 riastrad mutex_unlock(&dev->mode_config.mutex); 1002 1.1 riastrad 1003 1.1 riastrad DRM_DEBUG_KMS("No LVDS modes found, disabling.\n"); 1004 1.1 riastrad drm_connector_cleanup(connector); 1005 1.1 riastrad drm_encoder_cleanup(encoder); 1006 1.1 riastrad kfree(lvds_encoder); 1007 1.1 riastrad intel_connector_free(intel_connector); 1008 1.1 riastrad return; 1009 1.1 riastrad } 1010