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