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